下面列出了怎么用org.eclipse.ui.internal.WorkbenchPage的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Adds the new wizards to the current perspective displayed in <code>activeWorkbenchWindow</code>, if they've not
* been added already. Adds listeners on the window so that the same is done whenever the user switches perspectives
* in the window.
*
* Note: This method can only be called once the workbench has been started.
*/
private void maybeAddNewWizardActionsToWindow(IWorkbenchWindow activeWorkbenchWindow) {
if (activeWorkbenchWindow == null) {
return;
}
activeWorkbenchWindow.addPerspectiveListener(perspectiveListener);
WorkbenchPage activePage = (WorkbenchPage) activeWorkbenchWindow.getActivePage();
if (activePage == null) {
return;
}
IPerspectiveDescriptor perspectiveDesc = activePage.getPerspective();
maybeAddNewWizardActionsToPerspective(activePage, perspectiveDesc);
}
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
if (activeWorkbenchWindow != null) {
final WorkbenchPage page = (WorkbenchPage) activeWorkbenchWindow.getActivePage();
if (page != null) {
final IPerspectiveDescriptor descriptor = page.getPerspective();
if (descriptor != null) {
final String message =
"Resetting the perspective will reload the current experiment. Do you want to proceed ?";
final boolean result = MessageDialog.open(MessageDialog.QUESTION, activeWorkbenchWindow.getShell(),
"Reset experiment perspective", message, SWT.SHEET);
if (!result) { return null; }
page.resetPerspective();
GAMA.reloadFrontmostExperiment();
}
}
}
return null;
}
/**
* Register to selection service to update button enablement
* Register the Automatic Perspective switch part listener
*/
@Override
public void postWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.addEditorAreaTransfer(EditorInputTransfer.getInstance());
configurer.addEditorAreaTransfer(ResourceTransfer.getInstance());
configurer.addEditorAreaTransfer(FileTransfer.getInstance());
configurer.addEditorAreaTransfer(MarkerTransfer.getInstance());
configurer.configureEditorAreaDropListener(new EditorAreaDropAdapter(
configurer.getWindow()));
final MWindow model = ((WorkbenchPage) window.getActivePage()).getWindowModel();
model.getContext().get(EPartService.class).addPartListener(new AutomaticSwitchPerspectivePartListener());
final Object widget = model.getWidget();
if (widget instanceof Shell) {
((Widget) widget).setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, SWTBotConstants.SWTBOT_ID_MAIN_SHELL);
}
// Replace ObjectActionContributorManager with filtered actions
CustomObjectActionContributorManager.getManager();
}
@Override
protected EvaluationResult evaluate(IEvaluationContext context) {
IWorkbenchWindow window = InternalHandlerUtil.getActiveWorkbenchWindow(context);
// no window? not active
if (window == null)
return EvaluationResult.FALSE;
WorkbenchPage page = (WorkbenchPage) window.getActivePage();
// no page? not active
if (page == null)
return EvaluationResult.FALSE;
// get saveable part
ISaveablePart saveablePart = getSaveablePart(context);
if (saveablePart == null)
return EvaluationResult.FALSE;
if (saveablePart instanceof ISaveablesSource) {
ISaveablesSource modelSource = (ISaveablesSource) saveablePart;
if (SaveableHelper.needsSave(modelSource))
return EvaluationResult.TRUE;
return EvaluationResult.FALSE;
}
if (saveablePart != null && saveablePart.isDirty())
return EvaluationResult.TRUE;
return EvaluationResult.FALSE;
}
public static IEditorReference[] getSortedEditors(IWorkbenchPage page) {
IEditorReference[] result = null;
if (page != null && page instanceof WorkbenchPage) {
result = ((WorkbenchPage) page).getSortedEditors();
}
return result;
}
@Override
public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspectiveDesc) {
maybeAddNewWizardActionsToPerspective((WorkbenchPage) page, perspectiveDesc);
}
/**
* If we haven't added them in the past, add the new wizard actions that this to the perspective which is being
* displayed on the workbench page.
*
* Note: This method can only be called once the workbench has been started.
*/
private void maybeAddNewWizardActionsToPerspective(WorkbenchPage page, IPerspectiveDescriptor desc) {
if (page == null || desc == null) {
return;
}
if (PERSPECTIVES_TO_ADD_WIZARDS_TO.contains(desc.getId())) {
// Perspective perspective = page.findPerspective(desc);
// if (perspective != null) {
// List<String> wizardsToAdd = new ArrayList<String>(
// WIZARDS_TO_ADD_TO_PERSPECTIVES);
//
// // Ignore any wizards we've already tried to add to this perspective.
// // That way we don't re-add any wizards that the user explicitly
// // removed from the New shortcut menu.
// List<String> wizardsAlreadyAdded = GdtPreferences
// .getAddedNewWizardActionsForPerspective(desc.getId());
// wizardsToAdd.removeAll(wizardsAlreadyAdded);
//
// // Get the current set of wizard shortcuts
// List<String> currentWizardShortcuts = new ArrayList<String>(
// Arrays.asList(perspective.getNewWizardShortcuts()));
//
// // Ignore wizards that already have shortcuts in this perspective
// wizardsToAdd.removeAll(currentWizardShortcuts);
//
// // Only update the perspective if there are new wizards to add
// if (!wizardsToAdd.isEmpty()) {
// currentWizardShortcuts.addAll(wizardsToAdd);
//
// // Update the perspective
// perspective.setNewWizardActionIds(new ArrayList<String>(
// currentWizardShortcuts));
// }
//
// // Remember the wizards that we've attempted to add to this perspective
// GdtPreferences.setAddedNewWizardActionsForPerspective(desc.getId(),
// WIZARDS_TO_ADD_TO_PERSPECTIVES);
// } else {
// assert false : "Perspective was activated but not found";
// }
}
}
@Override
public IActionBars getActionBars() {
return new EditorActionBars((WorkbenchPage) getPage(),
(IServiceLocator) PlatformUI.getWorkbench().getService(IServiceLocator.class), GroovyEditor.EDITOR_ID);
}