Search in sources :

Example 61 with XSDConcreteComponent

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

the class XSDComplexTypeDefinitionAdapter method getActions.

public String[] getActions(Object object) {
    List list = new ArrayList();
    Object schema = getEditorSchema();
    XSDComplexTypeDefinition complexType = getXSDComplexTypeDefinition();
    Object contentType = getContentType();
    XSDDerivationMethod derivation = complexType.getDerivationMethod();
    if (contentType instanceof XSDSimpleTypeDefinition) {
        List fields = getFields();
        boolean hasSimpleContentAttributes = false;
        for (Iterator iterator = fields.iterator(); iterator.hasNext(); ) {
            Object field = iterator.next();
            // We have attributes, so we need to add the compartment for housing the attributes
            if (field instanceof XSDAttributeDeclarationAdapter) {
                hasSimpleContentAttributes = true;
                break;
            }
        }
        if (hasSimpleContentAttributes || XSDDerivationMethod.EXTENSION_LITERAL.equals(derivation)) {
            list.add(AddXSDAttributeDeclarationAction.ID);
        } else if (XSDDerivationMethod.RESTRICTION_LITERAL.equals(derivation)) {
            list.add(AddXSDEnumerationFacetAction.ID);
        }
        list.add(BaseSelectionAction.SEPARATOR_ID);
        list.add(SetBaseTypeAction.ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
        list.add(DeleteAction.ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
    } else {
        list.add(AddXSDElementAction.ID);
        list.add(AddXSDElementAction.REF_ID);
        list.add(AddXSDAnyElementAction.ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
        list.add(AddXSDAttributeDeclarationAction.ID);
        list.add(AddXSDAttributeDeclarationAction.REF_ID);
        list.add(AddXSDAttributeGroupDefinitionAction.REF_ID);
        list.add(AddXSDAnyAttributeAction.ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
        list.add(AddXSDModelGroupAction.SEQUENCE_ID);
        list.add(AddXSDModelGroupAction.CHOICE_ID);
        list.add(AddXSDModelGroupAction.ALL_ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
        list.add(DeleteAction.ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
        list.add(SetBaseTypeAction.ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
    }
    if (complexType.getSchema() == schema) {
        XSDConcreteComponent container = complexType.getContainer();
        if (container == schema || container instanceof XSDRedefine) {
            list.add(SetInputToGraphView.ID);
        }
    } else {
        list.add(OpenInNewEditor.ID);
    }
    list.add(BaseSelectionAction.SEPARATOR_ID);
    list.add(ShowPropertiesViewAction.ID);
    String[] result = new String[list.size()];
    list.toArray(result);
    return result;
}
Also used : XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) XSDDerivationMethod(org.eclipse.xsd.XSDDerivationMethod) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition)

Example 62 with XSDConcreteComponent

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

the class InternalXSDMultiPageEditor method createNavigationLocation.

public INavigationLocation createNavigationLocation() {
    if (getActivePage() == DESIGN_PAGE_INDEX) {
        try {
            RootEditPart rootEditPart = graphicalViewer.getRootEditPart();
            EditPart editPart = rootEditPart.getContents();
            if (editPart instanceof RootContentEditPart) {
                RootContentEditPart rootContentEditPart = (RootContentEditPart) editPart;
                Object input = rootContentEditPart.getInput();
                if (input instanceof Adapter) {
                    XSDConcreteComponent concreteComponent = (XSDConcreteComponent) ((Adapter) input).getTarget();
                    Object object = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getAdapter(ProductCustomizationProvider.class);
                    if (object instanceof ProductCustomizationProvider) {
                        ProductCustomizationProvider productCustomizationProvider = (ProductCustomizationProvider) object;
                        if (productCustomizationProvider != null) {
                            return productCustomizationProvider.getNavigationLocation(this, concreteComponent, rootContentEditPart);
                        }
                    }
                    return new DesignViewNavigationLocation(this, concreteComponent);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    } else {
        return new MultiPageEditorTextSelectionNavigationLocation(getTextEditor(), true);
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) DesignViewNavigationLocation(org.eclipse.wst.xsd.ui.internal.navigation.DesignViewNavigationLocation) RootEditPart(org.eclipse.gef.RootEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) RootContentEditPart(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.RootContentEditPart) EObject(org.eclipse.emf.ecore.EObject) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) XSDRedefineAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDRedefineAdapter) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) CategoryAdapter(org.eclipse.wst.xsd.ui.internal.adapters.CategoryAdapter) XSDModelAdapter(org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) RedefineCategoryAdapter(org.eclipse.wst.xsd.ui.internal.adapters.RedefineCategoryAdapter) RootContentEditPart(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.RootContentEditPart) ProductCustomizationProvider(org.eclipse.wst.xsd.ui.internal.adt.editor.ProductCustomizationProvider) MultiPageEditorTextSelectionNavigationLocation(org.eclipse.wst.xsd.ui.internal.navigation.MultiPageEditorTextSelectionNavigationLocation) RootEditPart(org.eclipse.gef.RootEditPart)

Example 63 with XSDConcreteComponent

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

the class XSDAttributeReferenceEditManager method modifyComponentReference.

public void modifyComponentReference(Object referencingObject, ComponentSpecification referencedComponent) {
    XSDAttributeDeclaration concreteComponent = null;
    if (referencingObject instanceof Adapter) {
        Adapter adapter = (Adapter) referencingObject;
        if (adapter.getTarget() instanceof XSDAttributeDeclaration) {
            concreteComponent = (XSDAttributeDeclaration) adapter.getTarget();
        }
    } else if (referencingObject instanceof XSDConcreteComponent) {
        concreteComponent = (XSDAttributeDeclaration) referencingObject;
    }
    if (concreteComponent != null) {
        if (referencedComponent.isNew()) {
            XSDAttributeDeclaration attributeDec = null;
            if (referencedComponent.getMetaName() == IXSDSearchConstants.ATTRIBUTE_META_NAME) {
                AddXSDAttributeDeclarationCommand command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, concreteComponent.getSchema());
                command.setNameToAdd(referencedComponent.getName());
                command.execute();
                attributeDec = (XSDAttributeDeclaration) command.getAddedComponent();
            }
            if (attributeDec != null) {
                Command command = new UpdateAttributeReferenceCommand(Messages._UI_ACTION_UPDATE_ATTRIBUTE_REFERENCE, concreteComponent, attributeDec);
                command.execute();
            }
            XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
        } else {
            Command command = new UpdateAttributeReferenceAndManagerDirectivesCommand(concreteComponent, referencedComponent.getName(), referencedComponent.getQualifier(), referencedComponent.getFile());
            command.setLabel(Messages._UI_ACTION_UPDATE_ATTRIBUTE_REFERENCE);
            command.execute();
        }
    }
}
Also used : AddXSDAttributeDeclarationCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAttributeDeclarationCommand) UpdateAttributeReferenceCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeReferenceCommand) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) UpdateAttributeReferenceAndManagerDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeReferenceAndManagerDirectivesCommand) UpdateAttributeReferenceCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeReferenceCommand) Command(org.eclipse.gef.commands.Command) AddXSDAttributeDeclarationCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAttributeDeclarationCommand) Adapter(org.eclipse.emf.common.notify.Adapter) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) UpdateAttributeReferenceAndManagerDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeReferenceAndManagerDirectivesCommand)

Example 64 with XSDConcreteComponent

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

the class XSDModelReconcileAdapter method handleNodeChanged.

protected void handleNodeChanged(Node node) {
    try {
        if (!shouldReconcileModelFor(node)) {
            return;
        }
    } catch (Exception e) {
    }
    if (node instanceof Element) {
        Element element = (Element) node;
        if (delayedReconciler.shouldDelay(schema)) {
            delayedReconciler.elementChanged(element, schema);
        } else {
            XSDConcreteComponent concreteComponent = schema.getCorrespondingComponent(node);
            concreteComponent.elementChanged(element);
        }
    } else if (node instanceof Document) {
        // The document changed so we may need to fix up the
        // definition's root element
        Document document = (Document) node;
        Element schemaElement = document.getDocumentElement();
        if (schemaElement != null && schemaElement != schema.getElement()) {
            // 
            if (schemaElement.getLocalName().equals(XSDConstants.SCHEMA_ELEMENT_TAG)) {
                // System.out.println("****** Setting new schema");
                schema.setElement(schemaElement);
            }
        } else if (schemaElement != null) {
            // handle the case where the definition element's content has changed
            // TODO (cs) do we really need to handle this case?
            schema.elementChanged(schemaElement);
        } else if (schemaElement == null) {
            // otherwise the statements below don't get run
            try {
                schema.getContents().clear();
            } catch (NullPointerException e) {
            // workaround
            }
            // See comment above for https://bugs.eclipse.org/bugs/show_bug.cgi?id=203291
            try {
                schema.getIncorporatedVersions().clear();
            } catch (Exception e) {
            }
            try {
                schema.getElementDeclarations().clear();
            } catch (Exception e) {
            }
            try {
                schema.getTypeDefinitions().clear();
            } catch (Exception e) {
            }
            try {
                schema.getAttributeDeclarations().clear();
            } catch (Exception e) {
            }
            try {
                schema.getModelGroupDefinitions().clear();
            } catch (Exception e) {
            }
            try {
                schema.getAttributeGroupDefinitions().clear();
            } catch (Exception e) {
            }
            try {
                schema.setTargetNamespace(null);
            } catch (Exception e) {
            }
            try {
                schema.reset();
            } catch (Exception e) {
            }
            schema.setElement(null);
        }
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 65 with XSDConcreteComponent

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

the class XSDElementDragAndDropCommand method getElement.

/*
   * (non-Javadoc)
   * @see org.eclipse.wst.xsd.ui.internal.commands.BaseDragAndDropCommand#getElement()
   */
protected Element getElement() {
    XSDElementDeclarationAdapter adapter = (XSDElementDeclarationAdapter) itemToDrag.getModel();
    XSDElementDeclaration target = (XSDElementDeclaration) adapter.getTarget();
    XSDConcreteComponent parent = (XSDConcreteComponent) target.eContainer();
    return parent.getElement();
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter)

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