我创建了一个包含两个编辑器页面的编辑器。我为属性测试人员添加了两个页面的工具栏项目。在第一页,物业测试人员工作正常。但是,如果我打开编辑器,选择第二页并选择树项,属性测试人员将无法正常工作。手动要求评估财产测试人员不起作用。在第一页上选择另一个视图或树项后,属性测试人员也可以在第二页上正常工作。有什么问题?这是编辑器的一个例子:
public class MyEditor extends FormEditor {
@Override
protected void addPages() {
try {
addPage(new MyPage(this));
addPage(new MyPage(this));
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public boolean isSaveAsAllowed() {
return false;
}
@Override
public void doSave(IProgressMonitor monitor) {
// nothing to do
}
@Override
public void doSaveAs() {
// nothing to do
}
}
class MyPage extends FormPage {
private static final String TOOLBAR_URI = "toolbar:my.page";
public MyPage(final FormEditor editor) {
super(editor, MyPage.class.getName(), "Test");
}
@Override
protected void createFormContent(final IManagedForm managedForm) {
final ScrolledForm form = managedForm.getForm();
final ToolBarManager toolbarManager = (ToolBarManager) form.getToolBarManager();
final IMenuService menuService = (IMenuService) getSite().getService(IMenuService.class);
menuService.populateContributionManager(toolbarManager, TOOLBAR_URI);
final Composite body = managedForm.getForm().getBody();
body.setLayout(new GridLayout());
final TreeViewer treeViewer = new TreeViewer(body);
treeViewer.setContentProvider(new MyContentProvider());
treeViewer.setLabelProvider(new ColumnLabelProvider());
treeViewer.setInput(Arrays.asList(new String[] { "A", "B", "C" }));
getSite().setSelectionProvider(treeViewer);
}
}
class MyContentProvider implements ITreeContentProvider {
@Override
public Object[] getElements(final Object inputElement) {
return ((List<String>) inputElement).toArray();
}
@Override
public Object[] getChildren(final Object parentElement) {
return new Object[] {};
}
@Override
public Object getParent(final Object element) {
return null;
}
@Override
public boolean hasChildren(final Object element) {
return false;
}
@Override
public void dispose() {
// nothing to do
}
@Override
public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
// nothing to do
}
}
处理程序:
<handler
class="EditHandler"
commandId="myEdit">
<activeWhen>
<with
variable="selection">
<test
property="my.active">
</test>
</with>
</activeWhen>
</handler>
物业测试员注册:
<propertyTester
class="MyPropertyTester"
id="MyPropertyTester"
namespace="my"
properties="active"
type="java.lang.Object">
</propertyTester>
物业测试员:
public class MyPropertyTester extends PropertyTester {
public static final String ID = MyPropertyTester.class.getName();
public static final String ACTIVE = "active";
@Override
public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
if (receiver instanceof IStructuredSelection) {
final IStructuredSelection selection = (IStructuredSelection) receiver;
if (selection.size() == 1) {
return isMatch(property);
}
}
return false;
}
private static boolean isMatch(final String property) {
if (ACTIVE.equals(property)) {
return true;
}
return false;
}
}
答案 0 :(得分:0)
我&#34;修复&#34;它通过编辑页面上的黑客改变:
@Override
protected void pageChange(int newPageIndex) {
List<IWorkbenchPart> views = ... // find all opened IWorkbenchPart
if (!views.isEmpty()) {
views.get(0).setFocus();
this.setFocus();
}
super.pageChange(newPageIndex);
}