我第一次使用 JFace MasterDetailsPart 时遇到了一些麻烦。未显示详细信息页面 - 当我选择一个新项目时,该事件不会被触发。我找不到任何好的示例或教程,即使是 JavaDoc 也无法帮助我。
detailspart 只是实现了 IDetailsPart 和 SYSOUT 初始化时的消息(显示),但未显示 Label:这是 DetailsPart-Code:
public class Einzelansicht implements IDetailsPage{
public Einzelansicht() {
// TODO Auto-generated constructor stub
}
@Override
public void commit(boolean arg0) {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public void initialize(IManagedForm arg0) {
System.out.println("initialize");
}
@Override
public boolean isDirty() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isStale() {
// TODO Auto-generated method stub
return false;
}
@Override
public void refresh() {
// TODO Auto-generated method stub
}
@Override
public void setFocus() {
// TODO Auto-generated method stub
}
@Override
public boolean setFormInput(Object arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public void selectionChanged(IFormPart arg0, ISelection arg1) {
System.out.println("!!");
}
@Override
public void createContents(Composite arg0) {
arg0.setLayout(new GridLayout());
Label label = new Label(arg0, 0);
label.setText("Einzel");
}
}
我想,这很简单,这里没有什么特别的东西应该失败。现在我的 MasterDetailsBlock:
public class BlockZwei extends MasterDetailsBlock {
private FormToolkit toolkit;
private IManagedForm form;
/**
* Create the master details block.
*/
public BlockZwei() {
// Create the master details block
}
/**
* Create contents of the master details block.
*
* @param managedForm
* @param parent
*/
@Override
protected void createMasterPart(final IManagedForm managedForm,
Composite parent) {
toolkit = managedForm.getToolkit();
//
form = managedForm;
final TableViewer tableViewer = new TableViewer(parent);
ArrayContentProvider arrayContent = ArrayContentProvider.getInstance();
tableViewer.setContentProvider(arrayContent);
String[] strings = new String[] { "Eins", "Zwei" };
tableViewer.setInput(strings);
tableViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent arg0) {
managedForm.fireSelectionChanged(detailsPart, arg0.getSelection());
}
});
}
/**
* Register the pages.
*
* @param part
*/
@Override
protected void registerPages(DetailsPart part) {
part.registerPage(Einzelansicht.class, new Einzelansicht());
}
如您所见,我为选择注册了一个侦听器,据我了解,该事件应该在详细信息页面上触发一个事件。最后但同样重要的是,我与 MDB 的 ViewPart
public class View extends ViewPart {
public static final String ID = "EclipseRCPStinkt.view";
/**
* This is a callback that will allow us to create the viewer and initialize
* it.
*/
public void createPartControl(Composite parent) {
ManagedForm managed = new ManagedForm(parent);
BlockZwei block = new BlockZwei();
block.createContent(managed);
managed.refresh();
}
/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
}
}
我是不是忘记打电话了?我真的找不到我的错误