Search in sources :

Example 1 with UpdateElementReferenceAndManageDirectivesCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.UpdateElementReferenceAndManageDirectivesCommand 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)1 Command (org.eclipse.gef.commands.Command)1 AddXSDElementCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand)1 UpdateElementReferenceAndManageDirectivesCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateElementReferenceAndManageDirectivesCommand)1 UpdateElementReferenceCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateElementReferenceCommand)1 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)1 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)1