Search in sources :

Example 31 with XSDConcreteComponent

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

the class AddXSDModelGroupCommand method execute.

public void execute() {
    try {
        beginRecording(parent.getElement());
        XSDConcreteComponent owner = getOwner();
        if (owner != null) {
            XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
            newModelGroup = createModelGroup();
            particle.setContent(newModelGroup);
            XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) owner;
            ctd.setContent(particle);
        }
        formatChild(parent.getElement());
    } finally {
        endRecording();
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 32 with XSDConcreteComponent

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

the class MakeAnonymousTypeGlobalAction method canEnable.

private boolean canEnable(XSDConcreteComponent xsdComponent) {
    if (xsdComponent instanceof XSDComplexTypeDefinition) {
        fSelectedComponent = (XSDComplexTypeDefinition) xsdComponent;
        isComplexType = true;
        XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) xsdComponent;
        XSDConcreteComponent parent = typeDef.getContainer();
        if (parent instanceof XSDElementDeclaration) {
            fParentName = ((XSDElementDeclaration) parent).getName();
            return true;
        }
    } else if (xsdComponent instanceof XSDSimpleTypeDefinition) {
        fSelectedComponent = (XSDSimpleTypeDefinition) xsdComponent;
        isComplexType = false;
        XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComponent;
        XSDConcreteComponent parent = typeDef.getContainer();
        if (parent instanceof XSDElementDeclaration) {
            fParentName = ((XSDElementDeclaration) parent).getName();
            return true;
        } else if (parent instanceof XSDAttributeDeclaration) {
            fParentName = ((XSDAttributeDeclaration) parent).getName();
            return true;
        }
    }
    return false;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 33 with XSDConcreteComponent

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

the class XSDAttributeDragAndDropCommand method doDrop.

protected void doDrop(List siblings, GraphicalEditPart movingEditPart) {
    commonSetup(siblings, movingEditPart);
    if ((previousRefComponent instanceof XSDAttributeDeclaration || previousRefComponent instanceof XSDWildcard) && (nextRefComponent instanceof XSDAttributeDeclaration || nextRefComponent instanceof XSDWildcard)) {
        XSDConcreteComponent parent = previousRefComponent.getContainer().getContainer();
        if (closerSibling == BELOW_IS_CLOSER) {
            parent = nextRefComponent.getContainer().getContainer();
        }
        action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
    } else if (previousRefComponent == null && (nextRefComponent instanceof XSDAttributeDeclaration || nextRefComponent instanceof XSDWildcard)) {
        XSDConcreteComponent parent = nextRefComponent.getContainer().getContainer();
        if (closerSibling == ABOVE_IS_CLOSER) {
            if (leftSiblingEditPart == null) {
                action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
            } else if (parentEditPart != null) {
                action = new MoveXSDAttributeAction(parentEditPart.getXSDConcreteComponent(), xsdComponentToDrag, previousRefComponent, nextRefComponent);
            }
        } else {
            action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
        }
    } else if (previousRefComponent instanceof XSDAttributeDeclaration && nextRefComponent == null) {
        XSDConcreteComponent parent = previousRefComponent.getContainer().getContainer();
        if (closerSibling == ABOVE_IS_CLOSER) {
            action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
        } else {
            if (rightSiblingEditPart == null) {
                action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
            } else {
                action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
            }
        }
    }
    if (action != null)
        canExecute = action.canMove();
}
Also used : MoveXSDAttributeAction(org.eclipse.wst.xsd.ui.internal.actions.MoveXSDAttributeAction) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 34 with XSDConcreteComponent

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

the class XSDBaseFieldEditPart method refreshIcon.

protected void refreshIcon() {
    IFieldFigure figure = getFieldFigure();
    // our model implements ITreeElement
    if (getModel() instanceof XSDBaseAdapter) {
        Image image = ((XSDBaseAdapter) getModel()).getImage();
        boolean isReadOnly = ((XSDBaseAdapter) getModel()).isReadOnly();
        figure.getNameLabel().setIcon(image);
        if (image != null) {
            XSDConcreteComponent comp = (XSDConcreteComponent) ((XSDBaseAdapter) getModel()).getTarget();
            figure.getNameLabel().setIcon(XSDCommonUIUtils.getUpdatedImage(comp, image, isReadOnly));
        }
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IFieldFigure(org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure) Image(org.eclipse.swt.graphics.Image)

Example 35 with XSDConcreteComponent

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

the class OpenOnSelectionHelper method openOnSelection.

public boolean openOnSelection() {
    List selectedNodes = null;
    ISelection selection = textEditor.getSelectionProvider().getSelection();
    if (selection instanceof IStructuredSelection) {
        selectedNodes = ((IStructuredSelection) selection).toList();
    }
    if (selectedNodes != null && !selectedNodes.isEmpty()) {
        for (Iterator i = selectedNodes.iterator(); i.hasNext(); ) {
            Object obj = i.next();
            if (xsdSchema != null) {
                XSDConcreteComponent xsdComp = xsdSchema.getCorrespondingComponent((Node) obj);
                XSDConcreteComponent objectToReveal = null;
                if (xsdComp instanceof XSDElementDeclaration) {
                    XSDElementDeclaration elementDecl = (XSDElementDeclaration) xsdComp;
                    if (elementDecl.isElementDeclarationReference()) {
                        objectToReveal = elementDecl.getResolvedElementDeclaration();
                    } else {
                        XSDConcreteComponent typeDef = null;
                        if (elementDecl.getAnonymousTypeDefinition() == null) {
                            typeDef = elementDecl.getTypeDefinition();
                        }
                        XSDConcreteComponent subGroupAffiliation = elementDecl.getSubstitutionGroupAffiliation();
                        if (typeDef != null && subGroupAffiliation != null) {
                            // then jump to that, otherwise just go to the typeDef.
                            if (obj instanceof Attr && ((Attr) obj).getLocalName().equals(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE)) {
                                objectToReveal = subGroupAffiliation;
                            } else {
                                // if we fail, set the substitution group as the object to reveal as a backup plan.
                                if (revealObject(typeDef)) {
                                    return true;
                                } else {
                                    objectToReveal = subGroupAffiliation;
                                }
                            }
                        } else {
                            // one or more of these is null.  If the typeDef is non-null, use it.  Otherwise
                            // try and use the substitution group
                            objectToReveal = typeDef != null ? typeDef : subGroupAffiliation;
                        }
                    }
                } else if (xsdComp instanceof XSDModelGroupDefinition) {
                    XSDModelGroupDefinition elementDecl = (XSDModelGroupDefinition) xsdComp;
                    if (elementDecl.isModelGroupDefinitionReference()) {
                        objectToReveal = elementDecl.getResolvedModelGroupDefinition();
                    }
                } else if (xsdComp instanceof XSDAttributeDeclaration) {
                    XSDAttributeDeclaration attrDecl = (XSDAttributeDeclaration) xsdComp;
                    if (attrDecl.isAttributeDeclarationReference()) {
                        objectToReveal = attrDecl.getResolvedAttributeDeclaration();
                    } else if (attrDecl.getAnonymousTypeDefinition() == null) {
                        objectToReveal = attrDecl.getTypeDefinition();
                    }
                } else if (xsdComp instanceof XSDAttributeGroupDefinition) {
                    XSDAttributeGroupDefinition attrGroupDef = (XSDAttributeGroupDefinition) xsdComp;
                    if (attrGroupDef.isAttributeGroupDefinitionReference()) {
                        objectToReveal = attrGroupDef.getResolvedAttributeGroupDefinition();
                    }
                } else if (xsdComp instanceof XSDIdentityConstraintDefinition) {
                    XSDIdentityConstraintDefinition idConstraintDef = (XSDIdentityConstraintDefinition) xsdComp;
                    if (idConstraintDef.getReferencedKey() != null) {
                        objectToReveal = idConstraintDef.getReferencedKey();
                    }
                } else if (xsdComp instanceof XSDSimpleTypeDefinition) {
                    XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComp;
                    objectToReveal = typeDef.getItemTypeDefinition();
                    if (objectToReveal == null) {
                        // if itemType attribute is not set, then check for memberType
                        List memberTypes = typeDef.getMemberTypeDefinitions();
                        if (memberTypes != null && memberTypes.size() > 0) {
                            objectToReveal = (XSDConcreteComponent) memberTypes.get(0);
                        }
                    }
                } else if (xsdComp instanceof XSDTypeDefinition) {
                    XSDTypeDefinition typeDef = (XSDTypeDefinition) xsdComp;
                    objectToReveal = typeDef.getBaseType();
                } else if (xsdComp instanceof XSDSchemaDirective) {
                    XSDSchemaDirective directive = (XSDSchemaDirective) xsdComp;
                    // String schemaLocation = URIHelper.removePlatformResourceProtocol(directive.getResolvedSchema().getSchemaLocation());
                    // openXSDEditor(schemaLocation);
                    // return false;
                    objectToReveal = directive.getResolvedSchema();
                }
                // now reveal the object if this isn't null
                if (objectToReveal != null) {
                    return revealObject(objectToReveal);
                }
            }
        }
    }
    return false;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Attr(org.w3c.dom.Attr) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

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