Search in sources :

Example 1 with AddXSDAttributeDeclarationCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAttributeDeclarationCommand 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 2 with AddXSDAttributeDeclarationCommand

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

the class AddXSDAttributeDeclarationAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
        if (selection instanceof XSDAttributeDeclaration) {
            selection = ((XSDAttributeDeclaration) selection).getContainer();
        }
    }
    AddXSDAttributeDeclarationCommand command = null;
    if (selection instanceof XSDComplexTypeDefinition) {
        command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDComplexTypeDefinition) selection);
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDAttributeUse) {
        XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) selection;
        XSDConcreteComponent parent = null;
        XSDComplexTypeDefinition ct = null;
        XSDAttributeGroupDefinition group = null;
        for (parent = xsdAttributeUse.getContainer(); parent != null; ) {
            if (parent instanceof XSDComplexTypeDefinition) {
                ct = (XSDComplexTypeDefinition) parent;
                break;
            } else if (parent instanceof XSDAttributeGroupDefinition) {
                group = (XSDAttributeGroupDefinition) parent;
                break;
            }
            parent = parent.getContainer();
        }
        if (ct != null) {
            XSDAttributeUse sel = (XSDAttributeUse) selection;
            int index = ct.getAttributeContents().indexOf(sel);
            command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, ct, getId(), index);
            command.setReference(isReference);
            getCommandStack().execute(command);
        } else if (group != null) {
            XSDAttributeUse sel = (XSDAttributeUse) selection;
            int index = group.eContents().indexOf(sel);
            command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, group, getId(), index);
            command.setReference(isReference);
            getCommandStack().execute(command);
        }
    } else if (selection instanceof XSDAttributeGroupDefinition) {
        command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDAttributeGroupDefinition) selection);
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDSchema) {
        command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDSchema) selection);
        getCommandStack().execute(command);
    }
    if (command != null) {
        addedComponent = command.getAddedComponent();
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
        selectAddedComponent(adapter);
    }
}
Also used : AddXSDAttributeDeclarationCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAttributeDeclarationCommand) XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

Adapter (org.eclipse.emf.common.notify.Adapter)2 AddXSDAttributeDeclarationCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAttributeDeclarationCommand)2 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)2 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)2 Command (org.eclipse.gef.commands.Command)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)1 UpdateAttributeReferenceAndManagerDirectivesCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeReferenceAndManagerDirectivesCommand)1 UpdateAttributeReferenceCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeReferenceCommand)1 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)1 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)1 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)1 XSDSchema (org.eclipse.xsd.XSDSchema)1