I'm a beginner in RCP just started building RCP application today.I want to a GUI component like a Button ,comboBox,Checkbox in a Editor .I've managed to add a editor in Extensions and create a class for it.I have written the code to create a label in creatPartControl but it does not work..I get a black window.Should I add the editor in perspective like this
我是RCP的初学者,刚刚开始构建RCP应用程序。我想在编辑器中使用一个GUI组件,如Button,comboBox,Checkbox。我已经设法在Extensions中添加一个编辑器并为它创建一个类。我有编写代码以在creatPartControl中创建标签,但它不起作用..我得到一个黑色的窗口。我应该像这样添加编辑器的透视图
layout.addStandaloneView(Editor.id, true, IPageLayout.TOP,0.7f,
layout.getEditorArea());
layout.addStandaloneView(View.ID, true, IPageLayout.BOTTOM,0.4f,
layout.getEditorArea());
Please help me resolve this issue.If possible please give an eg on how to add a editor and create a label and a button in it. Thank you for your help in advance code in my Editor.java content in createPartControl()
请帮我解决这个问题。如果可能,请举例说明如何添加编辑器并在其中创建标签和按钮。感谢您在createPartControl()中的Editor.java内容中提前获得的帮助。
parent.setLayout(new GridLayout());
Button b=new Button(parent,SWT.TOGGLE);
b.setText("Hello ");
Label label1 = new Label(parent, SWT.NONE);
label1.setText("First Name");
package com.hello;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
public class Editor extends EditorPart {
public static final String ID = "TestApplication.editor3";
public Editor() {
// TODO Auto-generated constructor stub
}
@Override
public void doSave(IProgressMonitor monitor) {
// TODO Auto-generated method stub
}
@Override
public void doSaveAs() {
// TODO Auto-generated method stub
}
@Override
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
// TODO Auto-generated method stub
}
@Override
public boolean isDirty() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isSaveAsAllowed() {
// TODO Auto-generated method stub
return false;
}
@Override
public void createPartControl(Composite parent) {
Label label = new Label(parent, SWT.NONE);
label.setText("sssssss");
}
@Override
public void setFocus() {
// TODO Auto-generated method stub
}
}
2 个解决方案
#1
0
You are not correctly initializing the editor and it causes problems when opening the editor. Fill up your init()
method like below and see if this helps:
您没有正确初始化编辑器,它在打开编辑器时会导致问题。像下面一样填写你的init()方法,看看这是否有帮助:
@Override
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
setSite(site);
setInput(input);
}
#2
0
It's been a few years since I worked on an Eclipse editor. Here's a screen capture of the editor so you can see I did more than add a Button.
自从我在Eclipse编辑器上工作已经有几年了。这是编辑器的屏幕截图,所以你可以看到我做的不仅仅是添加一个Button。
- I extended the Viewer class to create the GUI of the editor.
- I extended the EditorPart class to create the functionality of the editor.
我扩展了Viewer类来创建编辑器的GUI。
我扩展了EditorPart类以创建编辑器的功能。
Because of the kind of editor I was building, I had to create my own version of Canvas and my own version of IDocument.
由于我正在构建的编辑器,我必须创建自己的Canvas版本和我自己的IDocument版本。
#1
0
You are not correctly initializing the editor and it causes problems when opening the editor. Fill up your init()
method like below and see if this helps:
您没有正确初始化编辑器,它在打开编辑器时会导致问题。像下面一样填写你的init()方法,看看这是否有帮助:
@Override
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
setSite(site);
setInput(input);
}
#2
0
It's been a few years since I worked on an Eclipse editor. Here's a screen capture of the editor so you can see I did more than add a Button.
自从我在Eclipse编辑器上工作已经有几年了。这是编辑器的屏幕截图,所以你可以看到我做的不仅仅是添加一个Button。
- I extended the Viewer class to create the GUI of the editor.
- I extended the EditorPart class to create the functionality of the editor.
我扩展了Viewer类来创建编辑器的GUI。
我扩展了EditorPart类以创建编辑器的功能。
Because of the kind of editor I was building, I had to create my own version of Canvas and my own version of IDocument.
由于我正在构建的编辑器,我必须创建自己的Canvas版本和我自己的IDocument版本。