Search in sources :

Example 81 with XSDConcreteComponent

use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.

the class XSDModelGroupDefinitionSection method setInput.

public void setInput(IWorkbenchPart part, ISelection selection) {
    super.setInput(part, selection);
    init();
    relayout();
    if (isReference) {
        TypesHelper helper = new TypesHelper(xsdSchema);
        List items = new ArrayList();
        items = helper.getModelGroups();
        if (input instanceof XSDModelGroupDefinition) {
            XSDModelGroupDefinition group = (XSDModelGroupDefinition) input;
            XSDConcreteComponent parent = group.getContainer();
            while (parent != null) {
                if (parent instanceof XSDModelGroupDefinition) {
                    items.remove(((XSDModelGroupDefinition) parent).getQName());
                    break;
                }
                parent = parent.getContainer();
            }
        }
        // $NON-NLS-1$
        items.add(0, "");
        componentNameCombo.setItems((String[]) items.toArray(new String[0]));
    }
}
Also used : TypesHelper(org.eclipse.wst.xsd.ui.internal.util.TypesHelper) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition)

Example 82 with XSDConcreteComponent

use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.

the class XSDExtensionTreeContentProvider method getElements.

public Object[] getElements(Object inputElement) {
    if (inputElement instanceof XSDConcreteComponent) {
        XSDConcreteComponent component = (XSDConcreteComponent) inputElement;
        List elementsAndAttributes = new ArrayList();
        XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, false);
        if (xsdAnnotation != null) {
            // Added this if statement
            if (xsdAnnotation.getSchema() == component.getSchema()) {
                List appInfoList = xsdAnnotation.getApplicationInformation();
                Element appInfoElement = null;
                if (appInfoList.size() > 0) {
                    appInfoElement = (Element) appInfoList.get(0);
                }
                if (appInfoElement != null) {
                    for (Iterator it = appInfoList.iterator(); it.hasNext(); ) {
                        Object obj = it.next();
                        if (obj instanceof Element) {
                            Element appInfo = (Element) obj;
                            NodeList nodeList = appInfo.getChildNodes();
                            int length = nodeList.getLength();
                            for (int i = 0; i < length; i++) {
                                Node node = nodeList.item(i);
                                if (node instanceof Element) {
                                    elementsAndAttributes.add(node);
                                }
                            }
                        }
                    }
                    /**
                     * Construct attributes list
                     */
                    NamedNodeMap attributes = appInfoElement.getAttributes();
                    if (attributes != null) {
                        // String defaultNamespace =
                        // (String)component.getSchema().getQNamePrefixToNamespaceMap().get("");
                        int length = attributes.getLength();
                        for (int i = 0; i < length; i++) {
                            Node oneAttribute = attributes.item(i);
                            if (!isXmlnsAttribute(oneAttribute)) {
                                String namespace = oneAttribute.getNamespaceURI();
                                boolean isExtension = true;
                                if (namespace == null && oneAttribute.getPrefix() == null) {
                                    isExtension = false;
                                } else if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(namespace)) {
                                    isExtension = true;
                                }
                                if (isExtension) {
                                    elementsAndAttributes.add(oneAttribute);
                                }
                            }
                        }
                    }
                }
            }
        }
        return elementsAndAttributes.toArray();
    }
    return Collections.EMPTY_LIST.toArray();
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) XSDAnnotation(org.eclipse.xsd.XSDAnnotation)

Example 83 with XSDConcreteComponent

use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.

the class MakeLocalElementGlobalCommand method run.

public void run() {
    if (getModelObject() instanceof XSDElementDeclaration) {
        XSDElementDeclaration localElementDeclaration = (XSDElementDeclaration) getModelObject();
        XSDConcreteComponent parent = getParent();
        XSDConcreteComponent container = parent.getContainer();
        // Clone the local element with its content and set it global
        XSDElementDeclaration globalElementDeclaration = (XSDElementDeclaration) localElementDeclaration.cloneConcreteComponent(true, false);
        // The schema may already have a global element declaration with this name. In that case, ensure the name of the newly created
        // element does not collide with an existing one.
        XSDSchema schema = container.getSchema();
        String localElementName = localElementDeclaration.getName();
        XSDElementDeclaration existingGlobalElement = schema.resolveElementDeclaration(localElementName);
        boolean elementExists = existingGlobalElement != null && existingGlobalElement.getSchema() != null;
        if (elementExists) {
            String newElementName = XSDCommonUIUtils.createUniqueElementName(localElementName, schema.getElementDeclarations());
            globalElementDeclaration.setName(newElementName);
        }
        EList schemaContents = schema.getContents();
        schemaContents.add(globalElementDeclaration);
        // Modify the local element to become a reference to the global element.
        localElementDeclaration.setName(null);
        localElementDeclaration.setTypeDefinition(null);
        localElementDeclaration.setAnonymousTypeDefinition(null);
        localElementDeclaration.setResolvedElementDeclaration(globalElementDeclaration);
        XSDModelGroup modelGroup = (XSDModelGroup) container;
        // Format the markup.
        formatChild(modelGroup.getElement());
        formatChild(globalElementDeclaration.getElement());
    }
}
Also used : EList(org.eclipse.emf.common.util.EList) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 84 with XSDConcreteComponent

use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.

the class RenameComponentAction method canEnable.

protected boolean canEnable(XSDConcreteComponent selectedObject) {
    selectedComponent = null;
    if (selectedObject instanceof XSDNamedComponent) {
        selectedComponent = (XSDNamedComponent) selectedObject;
        // if it's element reference, then this action is not appropriate
        if (selectedComponent instanceof XSDElementDeclaration) {
            XSDElementDeclaration element = (XSDElementDeclaration) selectedComponent;
            if (element.isElementDeclarationReference()) {
                selectedComponent = null;
            }
        }
        if (selectedComponent instanceof XSDTypeDefinition) {
            XSDTypeDefinition type = (XSDTypeDefinition) selectedComponent;
            XSDConcreteComponent parent = type.getContainer();
            if (parent instanceof XSDElementDeclaration) {
                XSDElementDeclaration element = (XSDElementDeclaration) parent;
                if (element.getAnonymousTypeDefinition().equals(type)) {
                    selectedComponent = null;
                }
            } else if (parent instanceof XSDAttributeDeclaration) {
                XSDAttributeDeclaration element = (XSDAttributeDeclaration) parent;
                if (element.getAnonymousTypeDefinition().equals(type)) {
                    selectedComponent = null;
                }
            }
        }
    }
    return canRun();
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 85 with XSDConcreteComponent

use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.

the class RefactorEnablementTester method test.

public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }
    IWorkbenchPage activePage = window.getActivePage();
    if (activePage == null) {
        return false;
    }
    IEditorPart editor = activePage.getActiveEditor();
    if (editor == null) {
        return false;
    }
    XSDSchema schema = (XSDSchema) editor.getAdapter(XSDSchema.class);
    if (receiver instanceof IStructuredSelection) {
        IStructuredSelection fStructuredSelection = (IStructuredSelection) receiver;
        receiver = fStructuredSelection.getFirstElement();
        if (receiver instanceof XSDBaseAdapter) {
            receiver = ((XSDBaseAdapter) receiver).getTarget();
        }
        if (receiver instanceof XSDConcreteComponent) {
            return canEnable((XSDConcreteComponent) receiver, schema);
        } else if (receiver instanceof Node) {
            Node node = (Node) receiver;
            if (schema != null) {
                XSDConcreteComponent concreteComponent = schema.getCorrespondingComponent(node);
                return canEnable(concreteComponent, schema);
            }
        }
        return true;
    }
    return false;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Node(org.w3c.dom.Node) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)88 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)30 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)25 XSDSchema (org.eclipse.xsd.XSDSchema)23 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)18 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)18 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)17 Adapter (org.eclipse.emf.common.notify.Adapter)15 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)15 XSDParticle (org.eclipse.xsd.XSDParticle)13 Iterator (java.util.Iterator)12 ArrayList (java.util.ArrayList)11 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)11 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)11 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)11 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)11 List (java.util.List)10 Element (org.w3c.dom.Element)10 IADTObject (org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject)9 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)9