Java Code Examples for org.eclipse.ui.IWorkbenchWindow#getWorkbench()

The following examples show how to use org.eclipse.ui.IWorkbenchWindow#getWorkbench() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InitializeConfigurationsHandler.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Shell shell = HandlerUtil.getActiveShell(event);

    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    final IWorkbench workbench;
    if (workbenchWindow != null) {
        workbench = workbenchWindow.getWorkbench();
    } else {
        workbench = null;
    }
    GenconfEditorLauncher.openNewGenerationWizard(workbench, shell, (IStructuredSelection) selection);

    return null;
}
 
Example 2
Source File: PerspectiveUtil.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public static void switchToModelingPerspective(IWorkbenchWindow window) {
	IPreferenceStore prefs = UIPluginActivator.getDefault()
			.getPreferenceStore();
	boolean hide = prefs.getBoolean(AUTO_SWITCH_PERSPECTIVE);
	IWorkbenchPage page = window.getActivePage();
	if (!hide) {
		IWorkbench workbench = window.getWorkbench();
		IPerspectiveRegistry registry = workbench.getPerspectiveRegistry();
		IPerspectiveDescriptor descriptor = registry
				.findPerspectiveWithId(IYakinduSctPerspectives.ID_PERSPECTIVE_SCT_MODELING);
		if ((page != null) && (page.getPerspective() != descriptor)) {
			MessageDialogWithToggle dialog = MessageDialogWithToggle
					.openYesNoQuestion(
							window.getShell(),
							"Confirm Perspective Switch",
							"This kind of editor is associated with the YAKINDU Modeling perspective. Do you want to switch to this perspective now?",
							"Do not offer to switch perspective in the future",
							hide, prefs, AUTO_SWITCH_PERSPECTIVE);
			if (dialog.getReturnCode() == 2)
				page.setPerspective(descriptor);
			hide = dialog.getToggleState();
			prefs.setValue(AUTO_SWITCH_PERSPECTIVE, hide);
			try {
				InstanceScope.INSTANCE.getNode(UIPluginActivator.PLUGIN_ID)
						.flush();
			} catch (BackingStoreException e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example 3
Source File: All.java    From EasyShell with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // get resource type
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    ActionDelegate action = EditorPropertyTester.getActionExactResourceType(activePart,
            ResourceType.resourceTypeFileOrDirectory);
    if (action != null) {
        // load the preferences
        list = getMenuDataList(action.getCommonResourceType());
        if (list.size() > 0) {
            IWorkbenchWindow workbenchWindow = activePart.getSite().getWorkbenchWindow();
            if (list.size() == 1) {
                Utils.executeCommand(workbenchWindow.getWorkbench(), list.get(0), false);
            } else {
                // create and open a new dialog
                // close the old dialog
                if (dialog != null) {
                    dialog.close();
                    dialog = null;
                }
                if (usePopup) {
                    dialog = new ExecuteCommandPopup(workbenchWindow.getShell(), workbenchWindow.getWorkbench(),
                            list, getTitle());
                } else {
                    dialog = new ExecuteCommandDialog(workbenchWindow.getShell(), workbenchWindow.getWorkbench(),
                            list, getTitle());
                }
                dialog.open();
            }
        }
    }
    return null;
}