下面列出了怎么用org.eclipse.ui.internal.WorkbenchWindow的API类实例代码及写法,或者点击链接到github查看源代码。
private void setMessage(String imageIconKey, String message, Object... args) {
IStatusLineManager statusLineManager = null;
if (editor == null) {
WorkbenchWindow window = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow();
statusLineManager = window.getActionBars().getStatusLineManager();
} else {
statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
}
if (statusLineManager != null) {
if (message == null) {
statusLineManager.setMessage(null);
} else {
statusLineManager.setMessage(Activator.getImage(imageIconKey), format(message, args));
}
}
}
public static void install() {
WorkbenchHelper.runInUI("Install GAML Search", 0, m -> {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window instanceof WorkbenchWindow) {
final MTrimBar topTrim = ((WorkbenchWindow) window).getTopTrim();
for (final MTrimElement element : topTrim.getChildren()) {
if ("SearchField".equals(element.getElementId())) {
final Composite parent = ((Control) element.getWidget()).getParent();
final Control old = (Control) element.getWidget();
WorkbenchHelper.runInUI("Disposing old search control", 500, m2 -> old.dispose());
element.setWidget(GamlSearchField.installOn(parent));
parent.layout(true, true);
parent.update();
break;
}
}
}
});
}
public static void setCoolBarVisibility(boolean visible)
{
IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
if (activeWorkbenchWindow instanceof WorkbenchWindow)
{
WorkbenchWindow workbenchWindow = (WorkbenchWindow) activeWorkbenchWindow;
workbenchWindow.setCoolBarVisible(visible);
workbenchWindow.setPerspectiveBarVisible(visible);
// Try to force a refresh of the text on the action
IWorkbenchPart activePart = getActivePart();
if (activePart != null)
{
ICommandService cmdService = (ICommandService) activePart.getSite().getService(ICommandService.class);
cmdService.refreshElements("org.eclipse.ui.ToggleCoolbarAction", null); //$NON-NLS-1$
}
}
}
/**
* THis method sets the main menu contribution 'Mendeley' to visible
*/
private void updateMenuContribution() {
if(window instanceof WorkbenchWindow) {
MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
//you'll need to find the id for the item
String mainMenuId = "de.tudresden.slr.model.mendeley.menus.mainMenu";
IContributionItem item = menuManager.find(mainMenuId);
item.update();
if (item != null) {
// clean old one
item.setVisible(true);
// refresh menu gui
menuManager.update();
}
}
}
public static void showBottomTray(final WorkbenchWindow window, final Boolean show) {
final MUIElement trimStatus = getTrimStatus(window);
if ( trimStatus != null ) {
// toggle statusbar visibility
trimStatus.setVisible(show);
}
}
public static boolean getCoolBarVisibility()
{
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench != null)
{
IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
if (activeWorkbenchWindow instanceof WorkbenchWindow)
{
return ((WorkbenchWindow) activeWorkbenchWindow).getCoolBarVisible();
}
}
return true;
}
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindowChecked(event);
if (activeWorkbenchWindow instanceof WorkbenchWindow) {
WorkbenchWindow window = (WorkbenchWindow) activeWorkbenchWindow;
window.toggleToolbarVisibility();
}
ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
commandService.refreshElements(event.getCommand().getId(), null);
return null;
}
@SuppressWarnings("rawtypes")
public void updateElement(final UIElement element, Map parameters) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
final IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow instanceof WorkbenchWindow) {
WorkbenchWindow window = (WorkbenchWindow) activeWorkbenchWindow;
boolean coolbarVisible = window.getCoolBarVisible();
element.setIcon(coolbarVisible ? Activator.getImageDescriptor("icons/enabled_co.png") : Activator
.getImageDescriptor("icons/disabled_co.png"));
}
}
});
}
@SuppressWarnings("restriction")
public PluginConfigManage() {
pluginXmlLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation()
.append(PluginConstants.PC_pluginConfigLocation).toOSString();
WorkbenchWindow window = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow();
parentManager = window.getMenuBarManager();
shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
}
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindowChecked(event);
if (activeWorkbenchWindow instanceof WorkbenchWindow) {
WorkbenchWindow window = (WorkbenchWindow) activeWorkbenchWindow;
window.toggleToolbarVisibility();
}
ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
commandService.refreshElements(event.getCommand().getId(), null);
return null;
}
@SuppressWarnings("rawtypes")
public void updateElement(final UIElement element, Map parameters) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
final IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow instanceof WorkbenchWindow) {
WorkbenchWindow window = (WorkbenchWindow) activeWorkbenchWindow;
boolean coolbarVisible = window.getCoolBarVisible();
element.setIcon(coolbarVisible ? Activator.getImageDescriptor("icons/enabled_co.png") : Activator
.getImageDescriptor("icons/disabled_co.png"));
}
}
});
}
@SuppressWarnings("restriction")
public PluginConfigManage() {
pluginXmlLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation()
.append(PluginConstants.PC_pluginConfigLocation).toOSString();
WorkbenchWindow window = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow();
parentManager = window.getMenuBarManager();
shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
}
/**
* Insert text from kill ring entry into the most recently activated text editor
*
* @param text - the text from the kill ring entry
*/
// @SuppressWarnings("restriction") // for cast to internal org.eclipse.ui.internal.WorkbenchWindow
private void insertFromBrowseRing(String text) {
// insert into most recently active editor
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
RecentEditor recent = getRecentEditor();
// use widget to avoid unpleasant scrolling side effects of IRewriteTarget
Control widget = MarkUtils.getTextWidget(recent.editor);
if (recent.editor != null) {
try {
// cache for ancillary computations
setThisEditor(recent.editor);
// reduce the amount of unnecessary work
if (window instanceof WorkbenchWindow) {
((WorkbenchWindow) window).largeUpdateStart();
}
widget.setRedraw(false);
recent.page.activate(recent.epart);
insertText(recent.editor.getDocumentProvider().getDocument(recent.editor.getEditorInput()),
(ITextSelection)recent.editor.getSelectionProvider().getSelection(), text);
} catch (Exception e) {
} finally {
widget.setRedraw(true);
setThisEditor(null);
if (window instanceof WorkbenchWindow) {
((WorkbenchWindow) window).largeUpdateEnd();
}
}
} else {
beep();
}
}
@Override
public Shell getShell() {
// Compatibility: This method should not be used outside the UI
// thread... but since this condition
// was not always in the JavaDoc, we still try to return our best guess
// about the shell if it is
// called from the wrong thread.
final Display currentDisplay = Display.getCurrent();
if (currentDisplay == null) {
// Uncomment this to locate places that try to access the shell from
// a background thread
// WorkbenchPlugin.log(new Exception("Error:
// IWorkbenchSite.getShell() was called outside the UI thread. Fix
// this code.")); //$NON-NLS-1$
final IWorkbenchWindow workbenchWindow = getWorkbenchWindow();
if (workbenchWindow != null) {
return workbenchWindow.getShell();
}
return null;
}
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
MWindow window = null;
if (activeWorkbenchWindow != null) {
window = ((WorkbenchWindow) activeWorkbenchWindow).getModel();
final Control control = (Control) window.getWidget();
if (control != null && !control.isDisposed()) {
return control.getShell();
}
}
// likely means the part has been destroyed, return the parent window's
// shell, we don't just arbitrarily return the workbench window's shell
// because we may be in a detached window
return window == null ? getWorkbenchWindow().getShell() : (Shell) window.getWidget();
}
public Object execute(ExecutionEvent event) throws ExecutionException {
MWindow model = ((WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow()).getModel();
EModelService modelService = model.getContext().get(EModelService.class);
MToolControl bonitaCoolBar = (MToolControl) modelService.find(
"BonitaCoolbar", model);
if(bonitaCoolBar != null){
CoolbarToolControl coolbarControl = (CoolbarToolControl) bonitaCoolBar.getObject();
coolbarControl.maximizeCoolbar();
}
return null;
}
public Object execute(ExecutionEvent event) throws ExecutionException {
MWindow model = ((WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow()).getModel();
EModelService modelService = model.getContext().get(EModelService.class);
MToolControl bonitaCoolBar = (MToolControl) modelService.find(
"BonitaCoolbar", model);
if(bonitaCoolBar != null){
CoolbarToolControl coolbarControl = (CoolbarToolControl) bonitaCoolBar.getObject();
coolbarControl.minimizeCoolbar();
}
return null;
}
public static void refreshMainMenu() {
IWorkbenchWindow w = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
WorkbenchWindow ww = (WorkbenchWindow)w;
IMenuService service = (IMenuService)w.getService(IMenuService.class);
service.populateContributionManager((ContributionManager)ww.getActionBars().getMenuManager(), MenuUtil.MAIN_MENU);
}
public static IMenuManager getWorkbenchMenuManager() {
IWorkbenchWindow w = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
WorkbenchWindow ww = (WorkbenchWindow)w;
return ww.getActionBars().getMenuManager();
}
private static MUIElement getTrimStatus(final WorkbenchWindow window) {
final EModelService modelService = window.getService(EModelService.class);
final MUIElement searchRoot = window.getModel();
return modelService.find(BOTTOM_TRIM_ID, searchRoot);
}
@SuppressWarnings("restriction")
public PluginConfigManage(String pluginXmlLocation) {
this.pluginXmlLocation = pluginXmlLocation;
WorkbenchWindow window = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow();
parentManager = window.getMenuBarManager();
}
@SuppressWarnings("restriction")
public PluginConfigManage(String pluginXmlLocation) {
this.pluginXmlLocation = pluginXmlLocation;
WorkbenchWindow window = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow();
parentManager = window.getMenuBarManager();
}
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
eclipseContext = ((WorkbenchWindow) getEditorSite().getWorkbenchWindow()).getModel().getContext();
editorContributions = createEditorContributions();
}
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
context = ((WorkbenchWindow) getEditorSite().getWorkbenchWindow()).getModel().getContext();
ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
}
protected static MWindow getMWindow() {
Workbench workbench = (Workbench) PlatformUI.getWorkbench();
WorkbenchWindow activeWorkbenchWindow = (WorkbenchWindow) workbench.getActiveWorkbenchWindow();
return activeWorkbenchWindow.getModel();
}