Search in sources :

Example 91 with XSDElementDeclaration

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

the class XSDElementDeclarationAdvancedSection method doHandleEvent.

public void doHandleEvent(Event e) {
    if (e.widget == substGroupCombo) {
        if (e.type == SWT.Traverse) {
            if (e.detail == SWT.TRAVERSE_ARROW_NEXT || e.detail == SWT.TRAVERSE_ARROW_PREVIOUS) {
                isTraversing = true;
                return;
            }
        }
        XSDElementDeclaration eleDec = (XSDElementDeclaration) input;
        String value = substGroupCombo.getText();
        String oldValue = eleDec.getElement().getAttribute(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE);
        if (oldValue == null)
            oldValue = EMPTY;
        if (value.equals(oldValue))
            return;
        UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE, value, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP);
        command.setDeleteIfEmpty(true);
        getCommandStack().execute(command);
    }
}
Also used : UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration)

Example 92 with XSDElementDeclaration

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

the class XSDElementDeclarationAdvancedSection method handleWidgetSelection.

private void handleWidgetSelection(SelectionEvent e) {
    if (e.widget == blockCombo) {
        XSDElementDeclaration eleDec = (XSDElementDeclaration) input;
        String value = blockCombo.getText();
        UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.BLOCK_ATTRIBUTE, value, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_BLOCK);
        command.setDeleteIfEmpty(true);
        getCommandStack().execute(command);
    } else if (e.widget == finalCombo) {
        XSDElementDeclaration eleDec = (XSDElementDeclaration) input;
        String value = finalCombo.getText();
        UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.FINAL_ATTRIBUTE, value, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_FINAL);
        command.setDeleteIfEmpty(true);
        getCommandStack().execute(command);
    } else if (e.widget == abstractCombo) {
        XSDElementDeclaration eleDec = (XSDElementDeclaration) input;
        String value = abstractCombo.getText();
        UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.ABSTRACT_ATTRIBUTE, value, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_ABSTRACT);
        command.setDeleteIfEmpty(true);
        getCommandStack().execute(command);
    } else if (e.widget == substGroupCombo) {
        IEditorPart editor = getActiveEditor();
        if (editor == null)
            return;
        ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDSubstitutionGroupEditManager.class);
        String selection = substGroupCombo.getText();
        ComponentSpecification newValue;
        IComponentDialog dialog = null;
        if (selection.equals(Messages._UI_COMBO_BROWSE)) {
            dialog = manager.getBrowseDialog();
        } else if (selection.equals(Messages._UI_COMBO_NEW)) {
            dialog = manager.getNewDialog();
        }
        if (dialog != null) {
            if (dialog.createAndOpen() == Window.OK) {
                newValue = dialog.getSelectedComponent();
                manager.modifyComponentReference(input, newValue);
            } else {
                substGroupCombo.setText("");
            }
        } else // use the value from selected quickPick item
        {
            newValue = getComponentSpecFromQuickPickForValue(selection, manager);
            if (newValue != null)
                manager.modifyComponentReference(input, newValue);
        }
    } else if (e.widget == nillableCombo) {
        XSDElementDeclaration eleDec = (XSDElementDeclaration) input;
        String value = nillableCombo.getText();
        UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.NILLABLE_ATTRIBUTE, value, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_NILLABLE);
        command.setDeleteIfEmpty(true);
        getCommandStack().execute(command);
    }
}
Also used : IComponentDialog(org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ComponentReferenceEditManager(org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager) IEditorPart(org.eclipse.ui.IEditorPart)

Example 93 with XSDElementDeclaration

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

the class XSDElementDeclarationAdvancedSection method refresh.

public void refresh() {
    super.refresh();
    fillSubstitutionGroupCombo();
    setListenerEnabled(false);
    try {
        if (input instanceof XSDElementDeclaration) {
            XSDElementDeclaration eleDec = (XSDElementDeclaration) input;
            composite.setEnabled(!isReadOnly);
            if (// global element
            eleDec.getContainer() instanceof XSDSchema) {
                abstractCombo.setEnabled(true);
                finalCombo.setEnabled(true);
                substGroupCombo.setEnabled(true);
                nillableCombo.setEnabled(true);
            } else {
                abstractCombo.setEnabled(false);
                finalCombo.setEnabled(false);
                substGroupCombo.setEnabled(false);
                // Nillable when used in a local element declaration can't be set on
                // on elements that use @ref.
                nillableCombo.setEnabled(!eleDec.isElementDeclarationReference());
            }
            Element element = eleDec.getElement();
            if (element.hasAttribute(XSDConstants.BLOCK_ATTRIBUTE)) {
                String blockAttValue = element.getAttribute(XSDConstants.BLOCK_ATTRIBUTE);
                blockCombo.setText(blockAttValue);
            } else {
                blockCombo.setText(EMPTY);
            }
            // should show the value dynamically
            if (element.hasAttribute(XSDConstants.NILLABLE_ATTRIBUTE)) {
                String attrValue = element.getAttribute(XSDConstants.NILLABLE_ATTRIBUTE);
                nillableCombo.setText(attrValue);
            } else {
                nillableCombo.setText(EMPTY);
            }
            if (element.hasAttribute(XSDConstants.FINAL_ATTRIBUTE)) {
                String finalAttValue = element.getAttribute(XSDConstants.FINAL_ATTRIBUTE);
                finalCombo.setText(finalAttValue);
            } else {
                finalCombo.setText(EMPTY);
            }
            if (element.hasAttribute(XSDConstants.ABSTRACT_ATTRIBUTE)) {
                abstractCombo.setText(element.getAttribute(XSDConstants.ABSTRACT_ATTRIBUTE));
            } else
                abstractCombo.setText(EMPTY);
            if (element.hasAttribute(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE)) {
                substGroupCombo.setText(element.getAttribute(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE));
            } else {
                substGroupCombo.setText(EMPTY);
            }
        }
    } catch (Exception e) {
    }
    setListenerEnabled(true);
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Element(org.w3c.dom.Element) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 94 with XSDElementDeclaration

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

the class XSDCommonUIUtils method getInputXSDAnnotation.

public static XSDAnnotation getInputXSDAnnotation(XSDConcreteComponent input, boolean createIfNotExist) {
    XSDAnnotation xsdAnnotation = null;
    XSDFactory factory = XSDFactory.eINSTANCE;
    if (input instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration xsdComp = (XSDAttributeDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDAttributeGroupDefinition) {
        XSDAttributeGroupDefinition xsdComp = (XSDAttributeGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDElementDeclaration) {
        XSDElementDeclaration xsdComp = (XSDElementDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDNotationDeclaration) {
        XSDNotationDeclaration xsdComp = (XSDNotationDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDXPathDefinition) {
        XSDXPathDefinition xsdComp = (XSDXPathDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroup) {
        XSDModelGroup xsdComp = (XSDModelGroup) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroupDefinition) {
        XSDModelGroupDefinition xsdComp = (XSDModelGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDIdentityConstraintDefinition) {
        XSDIdentityConstraintDefinition xsdComp = (XSDIdentityConstraintDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDWildcard) {
        XSDWildcard xsdComp = (XSDWildcard) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDSchema) {
        XSDSchema xsdComp = (XSDSchema) input;
        List list = xsdComp.getAnnotations();
        if (list.size() > 0) {
            xsdAnnotation = (XSDAnnotation) list.get(0);
        } else {
            if (createIfNotExist && xsdAnnotation == null) {
                xsdAnnotation = factory.createXSDAnnotation();
                if (xsdComp.getContents() != null) {
                    xsdComp.getContents().add(0, xsdAnnotation);
                }
            }
        }
        return xsdAnnotation;
    } else if (input instanceof XSDFacet) {
        XSDFacet xsdComp = (XSDFacet) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDTypeDefinition) {
        XSDTypeDefinition xsdComp = (XSDTypeDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDInclude) {
        XSDInclude xsdComp = (XSDInclude) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDImport) {
        XSDImport xsdComp = (XSDImport) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDRedefine) {
        XSDRedefine xsdComp = (XSDRedefine) input;
        List contents = xsdComp.getContents();
        for (int i = 0; i < contents.size(); i++) {
            Object content = contents.get(i);
            if (content instanceof XSDAnnotation) {
                xsdAnnotation = (XSDAnnotation) content;
                break;
            }
        }
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            contents.add(0, xsdAnnotation);
        }
        return xsdAnnotation;
    } else if (input instanceof XSDAnnotation) {
        xsdAnnotation = (XSDAnnotation) input;
    }
    if (createIfNotExist) {
        formatAnnotation(xsdAnnotation);
    }
    return xsdAnnotation;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDNotationDeclaration(org.eclipse.xsd.XSDNotationDeclaration) XSDFacet(org.eclipse.xsd.XSDFacet) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDImport(org.eclipse.xsd.XSDImport) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDInclude(org.eclipse.xsd.XSDInclude)

Example 95 with XSDElementDeclaration

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

the class AddXSDModelGroupCommand method getOwner.

private XSDConcreteComponent getOwner() {
    XSDConcreteComponent owner = null;
    if (parent instanceof XSDElementDeclaration) {
        XSDElementDeclaration ed = (XSDElementDeclaration) parent;
        if (ed.getTypeDefinition() != null) {
            if (ed.getAnonymousTypeDefinition() == null) {
                ed.setTypeDefinition(null);
                XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
                ed.setAnonymousTypeDefinition(td);
                owner = ed.getTypeDefinition();
            } else {
                XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
                ed.setAnonymousTypeDefinition(td);
                owner = td;
            }
        } else if (ed.getAnonymousTypeDefinition() == null) {
            XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
            ed.setAnonymousTypeDefinition(td);
            owner = td;
        } else if (ed.getAnonymousTypeDefinition() instanceof XSDComplexTypeDefinition) {
            owner = ed.getAnonymousTypeDefinition();
        } else if (ed.getAnonymousTypeDefinition() instanceof XSDSimpleTypeDefinition) {
            XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
            ed.setAnonymousTypeDefinition(td);
            owner = td;
        }
    } else if (parent instanceof XSDModelGroup) {
        newModelGroup = createModelGroup();
        ((XSDModelGroup) parent).getContents().add(newModelGroup.getContainer());
    } else if (parent instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition ct = (XSDComplexTypeDefinition) parent;
        owner = parent;
        if (ct.getContent() instanceof XSDParticle) {
            XSDParticle particle = (XSDParticle) ct.getContent();
            if (particle.getContent() instanceof XSDModelGroup) {
                owner = null;
                newModelGroup = createModelGroup();
                XSDModelGroup newParent = (XSDModelGroup) particle.getContent();
                newParent.getContents().add(newModelGroup.getContainer());
            }
        }
    } else if (parent instanceof XSDModelGroupDefinition) {
        XSDModelGroupDefinition modelGroupDefinition = (XSDModelGroupDefinition) parent;
        owner = null;
        newModelGroup = createModelGroup();
        if (modelGroupDefinition.getModelGroup() != null) {
            XSDModelGroup newParent = modelGroupDefinition.getModelGroup();
            newParent.getContents().add(newModelGroup.getContainer());
        } else {
            modelGroupDefinition.setModelGroup(newModelGroup);
        }
    }
    return owner;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)222 XSDParticle (org.eclipse.xsd.XSDParticle)103 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)93 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)87 ArrayList (java.util.ArrayList)60 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)57 XSDSchema (org.eclipse.xsd.XSDSchema)48 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)47 Test (org.junit.Test)44 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)38 XSDFactory (org.eclipse.xsd.XSDFactory)37 XSDTerm (org.eclipse.xsd.XSDTerm)32 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)30 EList (org.eclipse.emf.common.util.EList)29 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)28 Iterator (java.util.Iterator)27 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)21 Element (org.w3c.dom.Element)21