Search in sources :

Example 11 with WorkbenchException

use of org.eclipse.ui.WorkbenchException in project polymap4-core by Polymap4.

the class CommonWizardDescriptor method init.

void init() throws WorkbenchException {
    wizardId = configElement.getAttribute(ATT_WIZARD_ID);
    type = configElement.getAttribute(ATT_TYPE);
    menuGroupId = configElement.getAttribute(ATT_MENU_GROUP_ID);
    if (menuGroupId == null) {
        menuGroupId = DEFAULT_MENU_GROUP_ID;
    }
    /* 
		 * The id defaults to the id of the enclosing navigatorContent extension, if any
		 * If not enclosed, this can be null initially, so it will default to the 
		 * value of the associatedExtensionId
		 *  
		 * Code elsewhere anticipates that this attribute may be null, so there is 
		 * no need to set it to a default non-null value. Indeed, this will cause
		 * incorrect behavior. 
		 * */
    if (id == null) {
        id = configElement.getAttribute(ATT_ASSOCIATED_EXTENSION_ID);
    }
    if (wizardId == null || wizardId.length() == 0) {
        throw new WorkbenchException(// $NON-NLS-1$
        "Missing attribute: " + ATT_WIZARD_ID + // $NON-NLS-1$
        " in common wizard extension: " + configElement.getDeclaringExtension().getNamespaceIdentifier());
    }
    if (type == null || type.length() == 0) {
        throw new WorkbenchException(// $NON-NLS-1$
        "Missing attribute: " + ATT_TYPE + // $NON-NLS-1$
        " in common wizard extension: " + configElement.getDeclaringExtension().getNamespaceIdentifier());
    }
    IConfigurationElement[] children = configElement.getChildren(TAG_ENABLEMENT);
    if (children.length == 1) {
        try {
            enablement = ElementHandler.getDefault().create(ExpressionConverter.getDefault(), children[0]);
        } catch (CoreException e) {
            NavigatorPlugin.log(IStatus.ERROR, 0, e.getMessage(), e);
        }
    } else if (children.length > 1) {
        throw new WorkbenchException(// $NON-NLS-1$
        "More than one element: " + TAG_ENABLEMENT + // $NON-NLS-1$
        " in common wizard extension: " + configElement.getDeclaringExtension().getUniqueIdentifier());
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) WorkbenchException(org.eclipse.ui.WorkbenchException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 12 with WorkbenchException

use of org.eclipse.ui.WorkbenchException in project polymap4-core by Polymap4.

the class NavigatorContentDescriptor method init.

/**
 * Parses the configuration element.
 *
 * @throws WorkbenchException
 *             if the configuration element could not be parsed. Reasons
 *             include:
 *             <ul>
 *             <li>A required attribute is missing.</li>
 *             <li>More elements are define than is allowed.</li>
 *             </ul>
 */
private void init() throws WorkbenchException {
    id = configElement.getAttribute(ATT_ID);
    name = configElement.getAttribute(ATT_NAME);
    String priorityString = configElement.getAttribute(ATT_PRIORITY);
    icon = configElement.getAttribute(ATT_ICON);
    String activeByDefaultString = configElement.getAttribute(ATT_ACTIVE_BY_DEFAULT);
    activeByDefault = (activeByDefaultString != null && activeByDefaultString.length() > 0) ? Boolean.valueOf(activeByDefaultString).booleanValue() : true;
    String providesSaveablesString = configElement.getAttribute(ATT_PROVIDES_SAVEABLES);
    providesSaveables = (providesSaveablesString != null && providesSaveablesString.length() > 0) ? Boolean.valueOf(providesSaveablesString).booleanValue() : false;
    appearsBeforeId = configElement.getAttribute(ATT_APPEARS_BEFORE);
    if (priorityString != null) {
        try {
            Priority p = Priority.get(priorityString);
            priority = p != null ? p.getValue() : Priority.NORMAL_PRIORITY_VALUE;
        } catch (NumberFormatException exception) {
            priority = Priority.NORMAL_PRIORITY_VALUE;
        }
    }
    // We start with this because the sort ExtensionPriorityComparator works
    // from the sequenceNumber
    sequenceNumber = priority;
    String sortOnlyString = configElement.getAttribute(ATT_SORT_ONLY);
    sortOnly = (sortOnlyString != null && sortOnlyString.length() > 0) ? Boolean.valueOf(sortOnlyString).booleanValue() : false;
    if (id == null) {
        throw new WorkbenchException(NLS.bind(CommonNavigatorMessages.Attribute_Missing_Warning, new Object[] { ATT_ID, id, configElement.getDeclaringExtension().getNamespaceIdentifier() }));
    }
    contribution = new IPluginContribution() {

        public String getLocalId() {
            return getId();
        }

        public String getPluginId() {
            return configElement.getDeclaringExtension().getNamespaceIdentifier();
        }
    };
    IConfigurationElement[] children;
    children = configElement.getChildren(TAG_INITIAL_ACTIVATION);
    if (children.length > 0) {
        if (children.length == 1) {
            initialActivation = new CustomAndExpression(children[0]);
        } else {
            throw new WorkbenchException(NLS.bind(CommonNavigatorMessages.Attribute_Missing_Warning, new Object[] { TAG_INITIAL_ACTIVATION, id, configElement.getDeclaringExtension().getNamespaceIdentifier() }));
        }
    }
    if (sortOnly)
        return;
    children = configElement.getChildren(TAG_ENABLEMENT);
    if (children.length == 0) {
        children = configElement.getChildren(TAG_TRIGGER_POINTS);
        if (children.length == 1) {
            enablement = new CustomAndExpression(children[0]);
        } else {
            throw new WorkbenchException(NLS.bind(CommonNavigatorMessages.Attribute_Missing_Warning, new Object[] { TAG_TRIGGER_POINTS, id, configElement.getDeclaringExtension().getNamespaceIdentifier() }));
        }
        children = configElement.getChildren(TAG_POSSIBLE_CHILDREN);
        if (children.length == 1) {
            possibleChildren = new CustomAndExpression(children[0]);
        } else if (children.length > 1) {
            throw new WorkbenchException(NLS.bind(CommonNavigatorMessages.Attribute_Missing_Warning, new Object[] { TAG_POSSIBLE_CHILDREN, id, configElement.getDeclaringExtension().getNamespaceIdentifier() }));
        }
    } else if (children.length == 1) {
        try {
            enablement = ElementHandler.getDefault().create(ExpressionConverter.getDefault(), children[0]);
        } catch (CoreException e) {
            NavigatorPlugin.log(IStatus.ERROR, 0, e.getMessage(), e);
        }
    } else if (children.length > 1) {
        throw new WorkbenchException(NLS.bind(CommonNavigatorMessages.Attribute_Missing_Warning, new Object[] { TAG_ENABLEMENT, id, configElement.getDeclaringExtension().getNamespaceIdentifier() }));
    }
    children = configElement.getChildren(TAG_OVERRIDE);
    if (children.length == 0) {
        overridePolicy = OverridePolicy.get(OverridePolicy.InvokeAlwaysRegardlessOfSuppressedExt_LITERAL);
    } else if (children.length == 1) {
        suppressedExtensionId = children[0].getAttribute(ATT_SUPPRESSED_EXT_ID);
        overridePolicy = OverridePolicy.get(children[0].getAttribute(ATT_POLICY));
    } else if (children.length > 1) {
        throw new WorkbenchException(NLS.bind(CommonNavigatorMessages.Too_many_elements_Warning, new Object[] { TAG_OVERRIDE, id, configElement.getDeclaringExtension().getNamespaceIdentifier() }));
    }
}
Also used : CustomAndExpression(org.eclipse.ui.internal.navigator.CustomAndExpression) CoreException(org.eclipse.core.runtime.CoreException) Priority(org.eclipse.ui.navigator.Priority) IPluginContribution(org.eclipse.ui.IPluginContribution) WorkbenchException(org.eclipse.ui.WorkbenchException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 13 with WorkbenchException

use of org.eclipse.ui.WorkbenchException in project Palladio-Editors-Sirius by PalladioSimulator.

the class NewPalladioProjectWizard method openPalladioPerspective.

private void openPalladioPerspective() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    try {
        workbench.showPerspective(PERSPECTIVE_ID, window);
    } catch (WorkbenchException e) {
        MessageDialog.openError(getShell(), "Error", "Could not open Palladio Perspective");
        e.printStackTrace();
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkbenchException(org.eclipse.ui.WorkbenchException)

Example 14 with WorkbenchException

use of org.eclipse.ui.WorkbenchException in project yamcs-studio by yamcs.

the class EditOPIAction method run.

@Override
public void run() {
    var page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    var shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    IOPIRuntime opiRuntime = OPIShell.getOPIShellForShell(shell);
    if (opiRuntime == null) {
        // if the selected object isn't an OPIShell so grab the
        // OPIView or OPIRunner currently selected
        var part = page.getActivePart();
        if (part instanceof IOPIRuntime) {
            opiRuntime = (IOPIRuntime) part;
        }
    }
    IWorkbenchWindow targetWindow = null;
    for (var window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
        if (window.getActivePage().getPerspective().getId().equals(OPIEditorPerspective.ID)) {
            targetWindow = window;
        }
    }
    if (targetWindow == null) {
        try {
            targetWindow = PlatformUI.getWorkbench().openWorkbenchWindow(OPIEditorPerspective.ID, null);
        } catch (WorkbenchException e) {
            throw new RuntimeException(e);
        }
    }
    targetWindow.getShell().setActive();
    if (opiRuntime != null) {
        var path = opiRuntime.getDisplayModel().getOpiFilePath();
        page = targetWindow.getActivePage();
        if (page != null) {
            try {
                var editorInput = ResourceUtil.editorInputFromPath(path);
                page.openEditor(editorInput, OPI_EDITOR_ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
            } catch (PartInitException e) {
                ErrorHandlerUtil.handleError("Failed to open current OPI in editor", e);
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IOPIRuntime(org.csstudio.opibuilder.runmode.IOPIRuntime) PartInitException(org.eclipse.ui.PartInitException) WorkbenchException(org.eclipse.ui.WorkbenchException)

Example 15 with WorkbenchException

use of org.eclipse.ui.WorkbenchException in project tdi-studio-se by Talend.

the class OpenDiagramAction method getSelectedObject.

private ISelection getSelectedObject() {
    if (params == null) {
        return getSelection();
    } else {
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (null == workbenchWindow) {
            return null;
        }
        IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
        if (null == workbenchPage) {
            return null;
        }
        IPerspectiveDescriptor currentPerspective = workbenchPage.getPerspective();
        if (!IBrandingConfiguration.PERSPECTIVE_DI_ID.equals(currentPerspective.getId())) {
            // show di perspective
            try {
                workbenchWindow.getWorkbench().showPerspective(IBrandingConfiguration.PERSPECTIVE_DI_ID, workbenchWindow);
                workbenchPage = workbenchWindow.getActivePage();
            } catch (WorkbenchException e) {
                ExceptionHandler.process(e);
                return null;
            }
        }
        RepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(params.getProperty("nodeId"), false);
        IRepositoryView viewPart = getViewPart();
        if (repositoryNode != null && viewPart != null) {
            RepositoryNodeUtilities.expandParentNode(viewPart, repositoryNode);
            return new StructuredSelection(repositoryNode);
        }
        return null;
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) WorkbenchException(org.eclipse.ui.WorkbenchException) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryView(org.talend.repository.ui.views.IRepositoryView)

Aggregations

WorkbenchException (org.eclipse.ui.WorkbenchException)37 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)16 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)15 IPerspectiveDescriptor (org.eclipse.ui.IPerspectiveDescriptor)11 IMemento (org.eclipse.ui.IMemento)7 IOException (java.io.IOException)6 IWorkbench (org.eclipse.ui.IWorkbench)5 IRepositoryView (org.talend.repository.ui.views.IRepositoryView)5 StringReader (java.io.StringReader)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 CoreException (org.eclipse.core.runtime.CoreException)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)3 RepositoryNode (org.talend.repository.model.RepositoryNode)3 ProcessExplorerView (com.centurylink.mdw.plugin.designer.views.ProcessExplorerView)2 BufferedReader (java.io.BufferedReader)2