Search in sources :

Example 1 with AddXSDElementCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand in project webtools.sourceediting by eclipse.

the class XSDSubstitutionGroupEditManager method modifyComponentReference.

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 UpdateAttributeValueCommand(concreteComponent.getElement(), XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE, elementDec.getQName(concreteComponent.getSchema()), org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP);
                command.execute();
            }
        } else {
            Command command = new UpdateAttributeValueCommand(concreteComponent.getElement(), XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE, ((XSDElementDeclaration) component.getObject()).getQName(concreteComponent.getSchema()), org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP);
            command.execute();
        }
        XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
    }
}
Also used : AddXSDElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) 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)

Example 2 with AddXSDElementCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand in project webtools.sourceediting by eclipse.

the class AddXSDElementAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
    }
    AddXSDElementCommand command = null;
    if (selection instanceof XSDComplexTypeDefinition) {
        command = new AddXSDElementCommand(getText(), (XSDComplexTypeDefinition) selection);
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDModelGroupDefinition) {
        command = new AddXSDElementCommand(getText(), (XSDModelGroupDefinition) selection);
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDSchema) {
        command = new AddXSDElementCommand(getText(), (XSDSchema) selection);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDModelGroup) {
        XSDModelGroup modelGroup = (XSDModelGroup) selection;
        XSDConcreteComponent component = modelGroup.getContainer();
        XSDComplexTypeDefinition ct = null;
        while (component != null) {
            if (component instanceof XSDComplexTypeDefinition) {
                ct = (XSDComplexTypeDefinition) component;
                break;
            }
            component = component.getContainer();
        }
        if (ct != null) {
            command = new AddXSDElementCommand(getText(), (XSDModelGroup) selection, ct);
        } else {
            command = new AddXSDElementCommand(getText(), (XSDModelGroup) selection);
        }
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDElementDeclaration || selection instanceof XSDAttributeUse) {
        XSDConcreteComponent xsdConcreteComponent = (XSDConcreteComponent) selection;
        XSDConcreteComponent parent = null;
        XSDComplexTypeDefinition ct = null;
        XSDModelGroupDefinition group = null;
        XSDModelGroupImpl ctGroup = null;
        for (parent = xsdConcreteComponent.getContainer(); parent != null; ) {
            if (parent instanceof XSDComplexTypeDefinition) {
                ct = (XSDComplexTypeDefinition) parent;
                break;
            } else if (parent instanceof XSDModelGroupDefinition) {
                group = (XSDModelGroupDefinition) parent;
                break;
            } else if (parent instanceof XSDModelGroupImpl) {
                ctGroup = (XSDModelGroupImpl) parent;
                break;
            }
            parent = parent.getContainer();
        }
        if (ct != null) {
            command = new AddXSDElementCommand(getText(), ct);
            command.setReference(isReference);
            getCommandStack().execute(command);
        } else if (ctGroup != null) {
            XSDElementDeclaration sel = (XSDElementDeclaration) selection;
            int index = ctGroup.getContents().indexOf(sel.eContainer());
            command = new AddXSDElementCommand(getText(), ctGroup, getId(), index);
            command.setReference(isReference);
            getCommandStack().execute(command);
        } else if (group != null) {
            command = new AddXSDElementCommand(getText(), group);
            command.setReference(isReference);
            getCommandStack().execute(command);
        }
    }
    if (command != null) {
        addedComponent = command.getAddedComponent();
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
        selectAddedComponent(adapter);
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) Adapter(org.eclipse.emf.common.notify.Adapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AddXSDElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSchema(org.eclipse.xsd.XSDSchema) XSDModelGroupImpl(org.eclipse.xsd.impl.XSDModelGroupImpl)

Example 3 with AddXSDElementCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand 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)

Aggregations

Adapter (org.eclipse.emf.common.notify.Adapter)3 AddXSDElementCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand)3 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)3 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)3 Command (org.eclipse.gef.commands.Command)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)1 UpdateAttributeValueCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand)1 UpdateElementReferenceAndManageDirectivesCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateElementReferenceAndManageDirectivesCommand)1 UpdateElementReferenceCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateElementReferenceCommand)1 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)1 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)1 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)1 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)1 XSDSchema (org.eclipse.xsd.XSDSchema)1 XSDModelGroupImpl (org.eclipse.xsd.impl.XSDModelGroupImpl)1