Search in sources :

Example 1 with IPluginContribution

use of org.eclipse.ui.IPluginContribution in project ecf by eclipse.

the class WizardNode method getWizard.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.wizard.IWizardNode#getWizard()
	 */
public IWizard getWizard() {
    if (wizard != null)
        // we've already created it
        return wizard;
    final IWizard[] newWizard = new IWizard[1];
    final IStatus[] statuses = new IStatus[1];
    // Start busy indicator.
    BusyIndicator.showWhile(parentWizardPage.getShell().getDisplay(), new Runnable() {

        public void run() {
            SafeRunner.run(new SafeRunnable() {

                /**
                 * Add the exception details to status is one
                 * happens.
                 */
                public void handleException(Throwable e) {
                    IPluginContribution contribution = (IPluginContribution) wizardElement.getAdapter(IPluginContribution.class);
                    statuses[0] = new // $NON-NLS-1$,
                    Status(// $NON-NLS-1$,
                    IStatus.ERROR, // $NON-NLS-1$,
                    contribution != null ? contribution.getPluginId() : Activator.PLUGIN_ID, // $NON-NLS-1$,
                    IStatus.OK, // $NON-NLS-1$,
                    e.getMessage() == null ? "" : e.getMessage(), e);
                }

                public void run() {
                    try {
                        newWizard[0] = createWizard();
                    // create instance of target wizard
                    } catch (CoreException e) {
                        statuses[0] = e.getStatus();
                    }
                }
            });
        }
    });
    if (statuses[0] != null) {
        // $NON-NLS-1$
        parentWizardPage.setErrorMessage("The selected wizard could not be started.");
        // $NON-NLS-1$
        ErrorDialog.openError(// $NON-NLS-1$
        parentWizardPage.getShell(), // $NON-NLS-1$
        "Problem Opening Wizard", "The selected wizard could not be started.", // $NON-NLS-1$
        statuses[0]);
        return null;
    }
    wizard = newWizard[0];
    return wizard;
}
Also used : SafeRunnable(org.eclipse.jface.util.SafeRunnable) SafeRunnable(org.eclipse.jface.util.SafeRunnable) IPluginContribution(org.eclipse.ui.IPluginContribution)

Example 2 with IPluginContribution

use of org.eclipse.ui.IPluginContribution 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)

Aggregations

IPluginContribution (org.eclipse.ui.IPluginContribution)2 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 SafeRunnable (org.eclipse.jface.util.SafeRunnable)1 WorkbenchException (org.eclipse.ui.WorkbenchException)1 CustomAndExpression (org.eclipse.ui.internal.navigator.CustomAndExpression)1 Priority (org.eclipse.ui.navigator.Priority)1