Search in sources :

Example 1 with ExtensibleAddExtensionCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleAddExtensionCommand in project webtools.sourceediting by eclipse.

the class ExtensionsSchemasRegistry method getAllExtensionsSchemasContribution.

private List getAllExtensionsSchemasContribution(String id) {
    IConfigurationElement[] asiPropertiesList = Platform.getExtensionRegistry().getConfigurationElementsFor(id);
    boolean hasASIProperties = (asiPropertiesList != null) && (asiPropertiesList.length > 0);
    if (hasASIProperties) {
        for (int i = 0; i < asiPropertiesList.length; i++) {
            IConfigurationElement asiPropertiesElement = asiPropertiesList[i];
            String elementName = asiPropertiesElement.getName();
            if ("category".equals(elementName)) {
                String description = asiPropertiesElement.getAttribute(DESCRIPTION);
                String displayName = asiPropertiesElement.getAttribute(DISPLAYNAME);
                String namespaceURI = asiPropertiesElement.getAttribute(NAMESPACEURI);
                String xsdFileURL = asiPropertiesElement.getAttribute(XSDFILEURL);
                String labelProviderClass = asiPropertiesElement.getAttribute(LABELPROVIDER);
                String addCommandClass = asiPropertiesElement.getAttribute(ADD_COMMAND_CLASS);
                String deleteCommandClass = asiPropertiesElement.getAttribute(DELETE_COMMAND_CLASS);
                if (displayName == null) {
                    // a display name.
                    continue;
                }
                if (xsdFileURL == null) {
                    xsdFileURL = locateFileUsingCatalog(namespaceURI);
                }
                SpecificationForExtensionsSchema extensionsSchemaSpec = createEntry();
                extensionsSchemaSpec.setDescription(description);
                extensionsSchemaSpec.setDisplayName(displayName);
                extensionsSchemaSpec.setNamespaceURI(namespaceURI);
                extensionsSchemaSpec.setDefautSchema();
                String pluginId = asiPropertiesElement.getDeclaringExtension().getContributor().getName();
                if (labelProviderClass != null) {
                    ILabelProvider labelProvider = null;
                    try {
                        Class theClass = Platform.getBundle(pluginId).loadClass(labelProviderClass);
                        if (theClass != null) {
                            labelProvider = (ILabelProvider) theClass.newInstance();
                            if (labelProvider != null) {
                                extensionsSchemaSpec.setLabelProvider(labelProvider);
                            }
                        }
                    } catch (Exception e) {
                    }
                }
                if (addCommandClass != null) {
                    try {
                        ExtensibleAddExtensionCommand addCommand = (ExtensibleAddExtensionCommand) asiPropertiesElement.createExecutableExtension(ADD_COMMAND_CLASS);
                        if (addCommand != null) {
                            extensionsSchemaSpec.setExtensibleAddExtensionCommand(addCommand);
                        }
                    } catch (Exception e) {
                    }
                }
                if (deleteCommandClass != null) {
                    try {
                        ExtensibleRemoveExtensionNodeCommand deleteCommand = (ExtensibleRemoveExtensionNodeCommand) asiPropertiesElement.createExecutableExtension(DELETE_COMMAND_CLASS);
                        if (deleteCommand != null) {
                            extensionsSchemaSpec.setExtensibleRemoveExtensionNodeCommand(deleteCommand);
                        }
                    } catch (Exception e) {
                    }
                }
                // $NON-NLS-1$
                extensionsSchemaSpec.setLocation(LOCATION_PREFIX + pluginId + "/" + xsdFileURL);
                nsURIProperties.add(extensionsSchemaSpec);
            } else if ("categoryProvider".equals(elementName)) {
                String categoryProviderClass = asiPropertiesElement.getAttribute(CATEGORY_PROVIDER_CLASS);
                if (categoryProviderClass != null) {
                    try {
                        CategoryProvider categoryProvider = (CategoryProvider) asiPropertiesElement.createExecutableExtension(CATEGORY_PROVIDER_CLASS);
                        if (categoryProvider != null) {
                            categoryProviderList.add(categoryProvider);
                        }
                    } catch (Exception e) {
                    }
                }
            }
        }
    }
    return nsURIProperties;
}
Also used : ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) ExtensibleAddExtensionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleAddExtensionCommand) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) ExtensibleRemoveExtensionNodeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleRemoveExtensionNodeCommand)

Example 2 with ExtensibleAddExtensionCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleAddExtensionCommand in project webtools.sourceediting by eclipse.

the class ExtensionsSection method getAddExtensionCommand.

protected AddExtensionCommand getAddExtensionCommand(Object o) {
    AddExtensionCommand addExtensionCommand = null;
    if (o instanceof XSDElementDeclaration) {
        XSDElementDeclaration element = (XSDElementDeclaration) o;
        ExtensibleAddExtensionCommand extensibleAddExtensionCommand = getExtensionsSchemasRegistry().getAddExtensionCommand(element.getTargetNamespace());
        if (extensibleAddExtensionCommand != null) {
            extensibleAddExtensionCommand.setInputs((XSDConcreteComponent) input, element);
            addExtensionCommand = extensibleAddExtensionCommand;
        } else {
            addExtensionCommand = new AddExtensionElementCommand(Messages._UI_ACTION_ADD_APPINFO_ELEMENT, (XSDConcreteComponent) input, element);
        }
    } else if (o instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration attribute = (XSDAttributeDeclaration) o;
        addExtensionCommand = new AddExtensionAttributeCommand(Messages._UI_ACTION_ADD_APPINFO_ATTRIBUTE, (XSDConcreteComponent) input, attribute);
    }
    return addExtensionCommand;
}
Also used : AddExtensionElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionElementCommand) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) AddExtensionAttributeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionAttributeCommand) ExtensibleAddExtensionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleAddExtensionCommand) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) ExtensibleAddExtensionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleAddExtensionCommand) AddExtensionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionCommand)

Aggregations

ExtensibleAddExtensionCommand (org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleAddExtensionCommand)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 AddExtensionAttributeCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionAttributeCommand)1 AddExtensionCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionCommand)1 AddExtensionElementCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionElementCommand)1 ExtensibleRemoveExtensionNodeCommand (org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleRemoveExtensionNodeCommand)1 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)1 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)1 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)1