Search in sources :

Example 86 with XSDElementDeclaration

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

the class AddXSDElementCommand method execute.

/*
   * (non-Javadoc)
   * 
   * @see org.eclipse.gef.commands.Command#execute()
   */
public void execute() {
    try {
        if (xsdSchema != null) {
            beginRecording(xsdSchema.getElement());
            XSDElementDeclaration element = createGlobalXSDElementDeclaration();
            // $NON-NLS-1$
            Text textNode = xsdSchema.getDocument().createTextNode("\n");
            xsdSchema.getElement().appendChild(textNode);
            xsdSchema.getContents().add(element);
            addedXSDConcreteComponent = element;
        } else if (xsdModelGroupDefinition != null) {
            beginRecording(xsdModelGroupDefinition.getElement());
            if (xsdModelGroup == null) {
                XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
                XSDParticle particle = factory.createXSDParticle();
                xsdModelGroup = factory.createXSDModelGroup();
                xsdModelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
                particle.setContent(xsdModelGroup);
                xsdModelGroupDefinition.setModelGroup(xsdModelGroup);
            }
            xsdSchema = xsdModelGroupDefinition.getSchema();
            if (!isReference) {
                xsdModelGroup.getContents().add(createXSDElementDeclarationForModelGroupDefinitions());
            } else {
                xsdModelGroup.getContents().add(createXSDElementReference());
            }
            formatChild(xsdModelGroupDefinition.getElement());
        } else if (xsdModelGroup != null && (xsdComplexTypeDefinition == null || xsdModelGroupDefinition == null)) {
            xsdSchema = xsdModelGroup.getSchema();
            beginRecording(xsdSchema.getElement());
            if (!isReference) {
                index = getInsertionIndex();
                if (index >= 0 && index < xsdModelGroup.getContents().size()) {
                    xsdModelGroup.getContents().add(index, createXSDElementDeclaration());
                } else {
                    xsdModelGroup.getContents().add(createXSDElementDeclaration());
                }
            } else {
                xsdModelGroup.getContents().add(createXSDElementReference());
            }
            formatChild(xsdModelGroup.getElement());
        } else {
            xsdSchema = xsdComplexTypeDefinition.getSchema();
            beginRecording(xsdSchema.getElement());
            if (xsdModelGroup == null) {
                XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
                XSDParticle particle = factory.createXSDParticle();
                xsdModelGroup = factory.createXSDModelGroup();
                xsdModelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
                particle.setContent(xsdModelGroup);
                xsdComplexTypeDefinition.setContent(particle);
            }
            if (!isReference) {
                xsdModelGroup.getContents().add(createXSDElementDeclarationForComplexType());
            } else {
                xsdModelGroup.getContents().add(createXSDElementReference());
            }
            formatChild(xsdComplexTypeDefinition.getElement());
        }
    } finally {
        endRecording();
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Text(org.w3c.dom.Text) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 87 with XSDElementDeclaration

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

the class XSDElementDeclarationSection method fillTypesCombo.

private void fillTypesCombo() {
    IEditorPart editor = getActiveEditor();
    ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDTypeReferenceEditManager.class);
    if (manager != null) {
        ComponentSpecification[] items = manager.getQuickPicks();
        typeCombo.removeAll();
        typeCombo.add(Messages._UI_COMBO_BROWSE);
        typeCombo.add(Messages._UI_COMBO_NEW);
        for (int i = 0; i < items.length; i++) {
            typeCombo.add(items[i].getName());
        }
        // Add the current Type of this element if needed
        XSDElementDeclaration namedComponent = ((XSDElementDeclaration) input).getResolvedElementDeclaration();
        XSDTypeDefinition td = namedComponent.getType();
        if (td != null) {
            String currentTypeName = td.getQName(xsdSchema);
            if (// anonymous type
            currentTypeName == null)
                currentTypeName = "**Anonymous**";
            ComponentSpecification ret = getComponentSpecFromQuickPickForValue(currentTypeName, manager);
            if (// not in quickPick
            ret == null && currentTypeName != null) {
                typeCombo.add(currentTypeName);
            }
        }
    }
}
Also used : XSDTypeReferenceEditManager(org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager) 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) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 88 with XSDElementDeclaration

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

the class XSDElementDeclarationSection method doHandleEvent.

public void doHandleEvent(Event event) {
    if (event.type == SWT.Traverse) {
        if (event.detail == SWT.TRAVERSE_ARROW_NEXT || event.detail == SWT.TRAVERSE_ARROW_PREVIOUS) {
            isTraversing = true;
            return;
        }
    }
    super.doHandleEvent(event);
    if (event.widget == nameText) {
        String newValue = nameText.getText().trim();
        if (input instanceof XSDElementDeclaration) {
            XSDElementDeclaration namedComponent = ((XSDElementDeclaration) input).getResolvedElementDeclaration();
            if (!validateSection())
                return;
            Command command = null;
            // Make sure an actual name change has taken place
            String oldName = namedComponent.getName();
            if (!newValue.equals(oldName)) {
                command = new UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ACTION_RENAME, namedComponent, newValue);
            }
            if (command != null && getCommandStack() != null) {
                getCommandStack().execute(command);
            }
        // doReferentialIntegrityCheck(namedComponent, newValue);
        }
    }
}
Also used : UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand) UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand) Command(org.eclipse.gef.commands.Command) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration)

Example 89 with XSDElementDeclaration

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

the class XSDElementDeclarationSection method init.

protected void init() {
    if (input instanceof XSDElementDeclaration) {
        XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) input;
        isElementReference = xsdElementDeclaration.isElementDeclarationReference();
        hideHyperLink = !xsdElementDeclaration.isGlobal() || isElementReference;
        typeDefinition = xsdElementDeclaration.getResolvedElementDeclaration().getTypeDefinition();
    }
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration)

Example 90 with XSDElementDeclaration

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

the class XSDFacetSection method updateInput.

private void updateInput() {
    previousPrimitiveType = currentPrimitiveType;
    if (input instanceof XSDFeature) {
        xsdFeature = (XSDFeature) input;
        typeDefinition = xsdFeature.getResolvedFeature().getType();
        XSDTypeDefinition anonymousTypeDefinition = null;
        if (xsdFeature instanceof XSDElementDeclaration) {
            xsdElementDeclaration = (XSDElementDeclaration) xsdFeature;
            anonymousTypeDefinition = xsdElementDeclaration.getResolvedElementDeclaration().getAnonymousTypeDefinition();
        } else if (xsdFeature instanceof XSDAttributeDeclaration) {
            xsdAttributeDeclaration = (XSDAttributeDeclaration) xsdFeature;
            anonymousTypeDefinition = xsdAttributeDeclaration.getResolvedAttributeDeclaration().getAnonymousTypeDefinition();
        }
        if (typeDefinition instanceof XSDSimpleTypeDefinition) {
            xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) typeDefinition;
        }
        if (anonymousTypeDefinition instanceof XSDSimpleTypeDefinition) {
            xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) anonymousTypeDefinition;
        }
        if (xsdSimpleTypeDefinition != null) {
            if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace())) {
                XSDSimpleTypeDefinition basePrimitiveType = xsdSimpleTypeDefinition.getBaseTypeDefinition();
                String basePrimitiveTypeString = basePrimitiveType != null ? basePrimitiveType.getName() : "";
                currentPrimitiveType = basePrimitiveType;
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + basePrimitiveTypeString;
            } else {
                currentPrimitiveType = xsdSimpleTypeDefinition;
                titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName());
            }
        }
    } else if (input instanceof XSDSimpleTypeDefinition) {
        xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) input;
        currentPrimitiveType = xsdSimpleTypeDefinition;
        // $NON-NLS-1$ //$NON-NLS-2$
        titleString = Messages._UI_LABEL_TYPE + (xsdSimpleTypeDefinition.getName() == null ? "(localType)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + xsdSimpleTypeDefinition.getBaseTypeDefinition().getName();
    }
}
Also used : XSDFeature(org.eclipse.xsd.XSDFeature) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

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