工具栏偏离预期结果,第一个按钮应该位于最后一个按钮..按钮的其余部分应该显示在菜单栏下方,这是在更改Eclipse版本时发生的,当前我正在使用 蚀月神4.4.2 这条线似乎无济于事
IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.LEFT);
在eclipse 3.7中,将调用openWorkbenchWindow(Workbench.class)之类的函数,并会触发restoreWorkbenchWindow并最终触发诸如rangingToolbar之类的函数
/*
* (non-Javadoc) Method declared on IWorkbench.
*/
public IWorkbenchWindow openWorkbenchWindow(final String perspID,
final IAdaptable input) throws WorkbenchException {
// Run op in busy cursor.
final Object[] result = new Object[1];
BusyIndicator.showWhile(null, new Runnable() {
public void run() {
try {
result[0] = busyOpenWorkbenchWindow(perspID, input);
} catch (WorkbenchException e) {
result[0] = e;
}
}
});
if (result[0] instanceof IWorkbenchWindow) {
return (IWorkbenchWindow) result[0];
} else if (result[0] instanceof WorkbenchException) {
throw (WorkbenchException) result[0];
} else {
throw new WorkbenchException(
WorkbenchMessages.Abnormal_Workbench_Conditi);
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IWorkbench#restoreWorkbenchWindow(org.eclipse.ui.IMemento)
*/
IWorkbenchWindow restoreWorkbenchWindow(IMemento memento)
throws WorkbenchException {
WorkbenchWindow newWindow = newWorkbenchWindow();
newWindow.create();
windowManager.add(newWindow);
// whether the window was opened
boolean opened = false;
try {
newWindow.restoreState(memento, null);
newWindow.fireWindowRestored();
newWindow.open();
opened = true;
} finally {
if (!opened) {
newWindow.close();
}
}
return newWindow;
}
void updatePerspectiveBar() {
// Update each item as the text may have to be shortened.
IContributionItem[] items = perspectiveBar.getItems();
for (int i = 0; i < items.length; i++) {
items[i].update();
}
// make sure the selected item is visible
perspectiveBar.arrangeToolbar();
setCoolItemSize(coolItem);
perspectiveBar.getControl().redraw();
if (getControl() != null)
getControl().pack(true);
}
但是,eclipse 4.4.2不再包含上述功能 功能内容有所不同,并且不再支持restoreWorkbenchWindow。
/*
* (non-Javadoc) Method declared on IWorkbench.
*/
@Override
public IWorkbenchWindow openWorkbenchWindow(String perspectiveId, IAdaptable input)
throws WorkbenchException {
IPerspectiveDescriptor descriptor = getPerspectiveRegistry().findPerspectiveWithId(
perspectiveId);
try {
MWindow window = BasicFactoryImpl.eINSTANCE.createTrimmedWindow();
return openWorkbenchWindow(input, descriptor, window, true);
} catch (InjectionException e) {
throw new WorkbenchException(e.getMessage(), e);
}
}
public WorkbenchWindow openWorkbenchWindow(IAdaptable input, IPerspectiveDescriptor descriptor,
MWindow window, boolean newWindow) {
return (WorkbenchWindow) createWorkbenchWindow(input, descriptor, window, newWindow);
}
有什么建议或方法可以解决我面临的问题吗?谢谢。