属性 测试人员无法在第二个编辑器页面上工作
Property tester does not work on second editor page
我创建了一个有两个编辑器页面的编辑器。我为 属性 测试人员的两个页面添加了工具栏项目。在第一页上,属性 测试人员工作正常。但是,如果我打开编辑器,select 第二页和 select 树项,属性 测试器将无法工作。手动请求 属性 测试人员的评估不起作用。 select 在第一页上显示另一个视图或树项目后,属性 测试人员在第二页上也能正常工作。有什么问题?这里有一个编辑器的例子:
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;
}
}
我 "fixed" 它是通过 hack on editor page change:
@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);
}
我创建了一个有两个编辑器页面的编辑器。我为 属性 测试人员的两个页面添加了工具栏项目。在第一页上,属性 测试人员工作正常。但是,如果我打开编辑器,select 第二页和 select 树项,属性 测试器将无法工作。手动请求 属性 测试人员的评估不起作用。 select 在第一页上显示另一个视图或树项目后,属性 测试人员在第二页上也能正常工作。有什么问题?这里有一个编辑器的例子:
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;
}
}
我 "fixed" 它是通过 hack on editor page change:
@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);
}