Search in sources :

Example 76 with XSDConcreteComponent

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

the class XSDElementReferenceEditManager method modifyComponentReference.

// TODO not changed yet
public void modifyComponentReference(Object referencingObject, ComponentSpecification component) {
    XSDElementDeclaration concreteComponent = null;
    if (referencingObject instanceof Adapter) {
        Adapter adapter = (Adapter) referencingObject;
        if (adapter.getTarget() instanceof XSDElementDeclaration) {
            concreteComponent = (XSDElementDeclaration) adapter.getTarget();
        }
    } else if (referencingObject instanceof XSDConcreteComponent) {
        concreteComponent = (XSDElementDeclaration) referencingObject;
    }
    if (concreteComponent != null) {
        if (component.isNew()) {
            XSDElementDeclaration elementDec = null;
            if (component.getMetaName() == IXSDSearchConstants.ELEMENT_META_NAME) {
                AddXSDElementCommand command = new AddXSDElementCommand(Messages._UI_ACTION_ADD_ELEMENT, concreteComponent.getSchema());
                command.setNameToAdd(component.getName());
                command.execute();
                elementDec = (XSDElementDeclaration) command.getAddedComponent();
            }
            if (elementDec != null) {
                Command command = new UpdateElementReferenceCommand(Messages._UI_ACTION_UPDATE_ELEMENT_REFERENCE, concreteComponent, elementDec);
                command.execute();
            }
            XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
        } else {
            Command command = new UpdateElementReferenceAndManageDirectivesCommand(concreteComponent, component.getName(), component.getQualifier(), component.getFile());
            command.setLabel(Messages._UI_ACTION_UPDATE_ELEMENT_REFERENCE);
            command.execute();
        }
    }
}
Also used : UpdateElementReferenceCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateElementReferenceCommand) AddXSDElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) UpdateElementReferenceCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateElementReferenceCommand) UpdateElementReferenceAndManageDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateElementReferenceAndManageDirectivesCommand) Command(org.eclipse.gef.commands.Command) AddXSDElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Adapter(org.eclipse.emf.common.notify.Adapter) UpdateElementReferenceAndManageDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateElementReferenceAndManageDirectivesCommand)

Example 77 with XSDConcreteComponent

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

the class XSDTabbedPropertySheetPage method selectionChanged.

/* (non-Javadoc)
   * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
   */
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    Object selected = ((IStructuredSelection) selection).getFirstElement();
    if (selected instanceof XSDBaseAdapter) {
        XSDBaseAdapter adapter = (XSDBaseAdapter) selected;
        if (oldSelection != null) {
            oldSelection.unregisterListener(this);
            if (oldSelection instanceof XSDElementDeclarationAdapter) {
                XSDElementDeclaration elem = (XSDElementDeclaration) ((XSDElementDeclarationAdapter) oldSelection).getTarget();
                if (elem.getContainer() != null) {
                    Adapter adap = XSDAdapterFactory.getInstance().adapt(elem.getContainer());
                    if (adap instanceof XSDParticleAdapter) {
                        XSDParticleAdapter particleAdapter = (XSDParticleAdapter) adap;
                        particleAdapter.unregisterListener(this);
                    }
                }
                if (elem.isElementDeclarationReference()) {
                    XSDElementDeclarationAdapter resolvedElementAdapter = (XSDElementDeclarationAdapter) XSDAdapterFactory.getInstance().adapt(elem.getResolvedElementDeclaration());
                    resolvedElementAdapter.unregisterListener(this);
                }
            }
        }
        if (adapter instanceof XSDElementDeclarationAdapter) {
            XSDElementDeclaration elem = (XSDElementDeclaration) ((XSDElementDeclarationAdapter) adapter).getTarget();
            Adapter adap = XSDAdapterFactory.getInstance().adapt(elem.getContainer());
            if (adap instanceof XSDParticleAdapter) {
                XSDParticleAdapter particleAdapter = (XSDParticleAdapter) adap;
                particleAdapter.registerListener(this);
            }
            if (elem.isElementDeclarationReference()) {
                XSDElementDeclarationAdapter resolvedElementAdapter = (XSDElementDeclarationAdapter) XSDAdapterFactory.getInstance().adapt(elem.getResolvedElementDeclaration());
                resolvedElementAdapter.registerListener(this);
            }
        } else if (adapter instanceof XSDAttributeUseAdapter) {
            XSDAttributeUseAdapter attributeUse = (XSDAttributeUseAdapter) adapter;
            XSDAttributeUse xsdAttrUse = (XSDAttributeUse) attributeUse.getTarget();
            adapter = (XSDBaseAdapter) XSDAdapterFactory.getInstance().adapt(xsdAttrUse.getAttributeDeclaration());
        }
        adapter.registerListener(this);
        oldSelection = adapter;
        Object model = adapter.getTarget();
        if (xsdModelAdapter != null && xsdModelAdapter.getModelReconcileAdapter() != null) {
            xsdModelAdapter.getModelReconcileAdapter().removeListener(internalNodeAdapter);
        }
        Element element = ((XSDConcreteComponent) adapter.getTarget()).getElement();
        if (element != null) {
            xsdModelAdapter = XSDModelAdapter.lookupOrCreateModelAdapter(element.getOwnerDocument());
        }
        if (xsdModelAdapter != null && xsdModelAdapter.getModelReconcileAdapter() != null) {
            xsdModelAdapter.getModelReconcileAdapter().addListener(internalNodeAdapter);
        }
        if (model instanceof XSDConcreteComponent) {
            selection = new StructuredSelection(model);
        }
        super.selectionChanged(part, selection);
        return;
    }
    super.selectionChanged(part, selection);
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Element(org.w3c.dom.Element) XSDParticleAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDParticleAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDParticleAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDParticleAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) XSDModelAdapter(org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDAttributeUseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeUseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter) XSDAttributeUseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeUseAdapter)

Example 78 with XSDConcreteComponent

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

the class XSDComponentDescriptionProvider method getFile.

public IFile getFile(Object component) {
    IFile result = null;
    if (component instanceof ComponentSpecification) {
        result = ((ComponentSpecification) component).getFile();
    } else if (component instanceof SearchMatch) {
        result = ((SearchMatch) component).getFile();
    } else if (component instanceof XSDConcreteComponent) {
        XSDConcreteComponent concreteComponent = (XSDConcreteComponent) component;
        XSDSchema schema = concreteComponent.getSchema();
        if (schema != null) {
            // TODO (cs) revisit and test more
            // 
            String location = schema.getSchemaLocation();
            String platformResource = "platform:/resource";
            if (location != null && location.startsWith(platformResource)) {
                Path path = new Path(location.substring(platformResource.length()));
                result = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
            }
        }
    }
    return result;
}
Also used : Path(org.eclipse.core.runtime.Path) SearchMatch(org.eclipse.wst.common.core.search.SearchMatch) IFile(org.eclipse.core.resources.IFile) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 79 with XSDConcreteComponent

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

the class MoveXSDAttributeAction method moveUnderXSDAttributeGroupDefinition.

protected void moveUnderXSDAttributeGroupDefinition(XSDAttributeGroupDefinition parentGroup) {
    int originalIndex = 0;
    for (Iterator iterator = parentGroup.getContents().iterator(); iterator.hasNext(); ) {
        XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
        if (attributeGroupContent instanceof XSDAttributeUse) {
            XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
            if (attribute == selected) {
                parentGroup.getContents().remove(attribute.getContainer());
                break;
            }
        }
        originalIndex++;
    }
    int index = 0;
    boolean addedBack = false;
    if (insertType == INSERT_DIRECT) {
        XSDConcreteComponent container = selected.getContainer();
        if (container != null) {
            if (insertAtEnd)
                ((XSDAttributeGroupDefinition) parentComponent).getResolvedAttributeGroupDefinition().getContents().add(container);
            else
                ((XSDAttributeGroupDefinition) parentComponent).getResolvedAttributeGroupDefinition().getContents().add(0, container);
            addedBack = true;
        }
        return;
    }
    List attributeGroupContents = parentGroup.getContents();
    for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext(); ) {
        XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
        if (attributeGroupContent instanceof XSDAttributeUse) {
            XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
            if (insertType == INSERT_BEFORE) {
                if (attribute == nextRefComponent) {
                    parentGroup.getContents().add(index, selected.getContainer());
                    addedBack = true;
                    break;
                }
                if (selected == nextRefComponent && originalIndex == index) {
                    parentGroup.getContents().add(index, selected.getContainer());
                    addedBack = true;
                    break;
                }
            } else if (insertType == INSERT_AFTER) {
                if (attribute == previousRefComponent) {
                    parentGroup.getContents().add(index + 1, selected.getContainer());
                    addedBack = true;
                    break;
                }
                if (selected == previousRefComponent && originalIndex == index) {
                    parentGroup.getContents().add(index, selected.getContainer());
                    addedBack = true;
                    break;
                }
            }
        }
        index++;
    }
    if (attributeGroupContents.size() == 0) {
        parentGroup.getContents().add(selected.getContainer());
        addedBack = true;
    }
    if (!addedBack) {
        parentGroup.getContents().add(originalIndex, selected.getContainer());
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Iterator(java.util.Iterator) List(java.util.List) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDAttributeGroupContent(org.eclipse.xsd.XSDAttributeGroupContent)

Example 80 with XSDConcreteComponent

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

the class ExtensionsSection method getAddExtensionCommand.

protected AddExtensionCommand getAddExtensionCommand(Object o) {
    AddExtensionCommand addExtensionCommand = null;
    if (o instanceof XSDElementDeclaration) {
        XSDElementDeclaration element = (XSDElementDeclaration) o;
        ExtensibleAddExtensionCommand extensibleAddExtensionCommand = getExtensionsSchemasRegistry().getAddExtensionCommand(element.getTargetNamespace());
        if (extensibleAddExtensionCommand != null) {
            extensibleAddExtensionCommand.setInputs((XSDConcreteComponent) input, element);
            addExtensionCommand = extensibleAddExtensionCommand;
        } else {
            addExtensionCommand = new AddExtensionElementCommand(Messages._UI_ACTION_ADD_APPINFO_ELEMENT, (XSDConcreteComponent) input, element);
        }
    } else if (o instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration attribute = (XSDAttributeDeclaration) o;
        addExtensionCommand = new AddExtensionAttributeCommand(Messages._UI_ACTION_ADD_APPINFO_ATTRIBUTE, (XSDConcreteComponent) input, attribute);
    }
    return addExtensionCommand;
}
Also used : AddExtensionElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionElementCommand) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) AddExtensionAttributeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionAttributeCommand) ExtensibleAddExtensionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleAddExtensionCommand) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) ExtensibleAddExtensionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleAddExtensionCommand) AddExtensionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionCommand)

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