[英]How to get new window from existing Perspective in Eclipse RCP
我目前是Eclipse RCP / SWT和Jface的新手。 我試圖通過使用按鈕從現有視圖創建一個新的彈出窗口。 它類似於MessageBox,但MessageBox的功能有限,我需要在第二個“外殼” /窗口上使用SWT.graphics。 因此,一旦我獲得第二個窗口,就應該得到一個數字。
現在有兩個問題:
我不知道如何集成我的兩個文件DrawExamples.java
和View.java
以便在View中打開一個窗口。 Java,它從DrawExample.java
獲取繪圖DrawExample.java
。
到目前為止,我的進度:
View.java()
{
public void createPartControl(final Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
// Provide the input to the ContentProvider
viewer.setInput(new String[] {"One", "Two", "Three"});
final FormLayout layout = new FormLayout();
layout.marginHeight = 5;
layout.marginWidth = 5;
//set layout for parent
parent.setLayout(layout);
//create a button or any other widget
Button button2 = new Button(parent, SWT.PUSH);
button2.setText("B2");
button2.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{// I want to generate new Window here. Not a new View like the one i have created above. From the Object of DrawExample Class So that i can keep things modular. Drawing in Once class and windowing in one class.`
});
//create FormData and set each of its sides
FormData formData = new FormData();
formData.top = new FormAttachment(0, 0);
formData.bottom = new FormAttachment(50, 0);
formData.left = new FormAttachment(10, 0);
formData.right = new FormAttachment(60, 0);
//set FormDate for button
button2.setLayoutData(formData);
}
}
DrawExample類。
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class DrawExample {
public static void main(String[] args){
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Drawing Example");
Canvas canvas = new Canvas(shell, SWT.NONE);
canvas.setSize(150, 150);
canvas.setLocation(20, 20);
shell.open();
shell.setSize(200, 220);
GC gc = new GC(canvas);
gc.drawRoundRectangle(11, 11, 89, 44, 25, 15);
gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
gc.fillRoundRectangle(10,10,90,45,25,15);
Font font = new Font(display,"Arial",12,SWT.BOLD | SWT.ITALIC);
//gc.drawText("Hello World",5,5);
gc.setFont(font);
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
gc.drawText("Hello World",10,20,true);
gc.dispose();
font.dispose();
//gc.drawOval(65, 10, 30, 35);
//gc.drawLine(130, 10, 90, 80);
//gc.drawPolygon(new int[] { 20, 70, 45, 90, 70, 70 });
//gc.drawPolyline(new int[] { 10, 120, 70, 100, 100, 130, 130, 75 });
gc.dispose();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
如果要在視圖中生成通用外殼,則始終可以使用以下命令生成一個外殼
Shell=new Shell(getViewSite().getPage().getWorkbenchWindow().getShell());
但是我不認為這是推薦的方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.