Search in sources :

Example 1 with AddXSDSimpleTypeDefinitionCommand

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

the class XSDTypeReferenceEditManager method modifyComponentReference.

public void modifyComponentReference(Object referencingObject, ComponentSpecification component) {
    XSDConcreteComponent concreteComponent = null;
    if (referencingObject instanceof Adapter) {
        Adapter adpater = (Adapter) referencingObject;
        if (adpater.getTarget() instanceof XSDConcreteComponent) {
            concreteComponent = (XSDConcreteComponent) adpater.getTarget();
        }
    } else if (referencingObject instanceof XSDConcreteComponent) {
        concreteComponent = (XSDConcreteComponent) referencingObject;
    }
    if (concreteComponent != null) {
        if (component.isNew()) {
            XSDTypeDefinition td = null;
            if (// This means we set to anonymous type
            component.getName() == null && concreteComponent instanceof XSDElementDeclaration) {
                XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
                XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) concreteComponent;
                // with the proper undo descriptions
                if (component.getMetaName() == IXSDSearchConstants.COMPLEX_TYPE_META_NAME) {
                    XSDComplexTypeDefinition complexType = factory.createXSDComplexTypeDefinition();
                    elementDeclaration.setAnonymousTypeDefinition(complexType);
                } else {
                    XSDSimpleTypeDefinition simpleType = factory.createXSDSimpleTypeDefinition();
                    simpleType.setBaseTypeDefinition(// $NON-NLS-1$
                    elementDeclaration.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string"));
                    elementDeclaration.setAnonymousTypeDefinition(simpleType);
                }
                // TODO use external literal string
                elementDeclaration.getElement().removeAttribute("type");
            } else if (component.getMetaName() == IXSDSearchConstants.COMPLEX_TYPE_META_NAME) {
                AddXSDComplexTypeDefinitionCommand command = new AddXSDComplexTypeDefinitionCommand(Messages._UI_ACTION_ADD_COMPLEX_TYPE, concreteComponent.getSchema());
                command.setNameToAdd(component.getName());
                command.execute();
                td = command.getCreatedComplexType();
            } else {
                AddXSDSimpleTypeDefinitionCommand command = new AddXSDSimpleTypeDefinitionCommand(Messages._UI_ACTION_ADD_SIMPLE_TYPE, concreteComponent.getSchema());
                command.setNameToAdd(component.getName());
                command.execute();
                td = command.getCreatedSimpleType();
            }
            if (td != null) {
                Command command = new UpdateTypeReferenceCommand(concreteComponent, td);
                command.setLabel(Messages._UI_ACTION_SET_TYPE);
                command.execute();
            }
            XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
        } else {
            Command command = new UpdateTypeReferenceAndManageDirectivesCommand(concreteComponent, component.getName(), component.getQualifier(), component.getFile());
            command.setLabel(Messages._UI_ACTION_SET_TYPE);
            command.execute();
        }
    }
}
Also used : AddXSDComplexTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDComplexTypeDefinitionCommand) UpdateTypeReferenceAndManageDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceAndManageDirectivesCommand) XSDFactory(org.eclipse.xsd.XSDFactory) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) UpdateTypeReferenceCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceCommand) AddXSDSimpleTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDSimpleTypeDefinitionCommand) AddXSDComplexTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDComplexTypeDefinitionCommand) UpdateTypeReferenceCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceCommand) UpdateTypeReferenceAndManageDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceAndManageDirectivesCommand) Command(org.eclipse.gef.commands.Command) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) AddXSDSimpleTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDSimpleTypeDefinitionCommand) Adapter(org.eclipse.emf.common.notify.Adapter) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 2 with AddXSDSimpleTypeDefinitionCommand

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

the class AddXSDSimpleTypeDefinitionAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
    }
    if (selection instanceof XSDSchema) {
        AddXSDSimpleTypeDefinitionCommand command = new AddXSDSimpleTypeDefinitionCommand(Messages._UI_ACTION_ADD_SIMPLE_TYPE, (XSDSchema) selection);
        getCommandStack().execute(command);
        addedComponent = command.getAddedComponent();
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
        selectAddedComponent(adapter);
    }
}
Also used : XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) AddXSDSimpleTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDSimpleTypeDefinitionCommand) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 3 with AddXSDSimpleTypeDefinitionCommand

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

the class XSDComplexTypeBaseTypeEditManager method modifyComponentReference.

// TODO common this up
public void modifyComponentReference(Object referencingObject, ComponentSpecification component) {
    XSDConcreteComponent concreteComponent = null;
    if (referencingObject instanceof Adapter) {
        Adapter adpater = (Adapter) referencingObject;
        if (adpater.getTarget() instanceof XSDConcreteComponent) {
            concreteComponent = (XSDConcreteComponent) adpater.getTarget();
        }
    } else if (referencingObject instanceof XSDConcreteComponent) {
        concreteComponent = (XSDConcreteComponent) referencingObject;
    }
    if (concreteComponent instanceof XSDComplexTypeDefinition) {
        if (component.isNew()) {
            XSDTypeDefinition td = null;
            if (component.getMetaName() == IXSDSearchConstants.COMPLEX_TYPE_META_NAME) {
                AddXSDComplexTypeDefinitionCommand command = new AddXSDComplexTypeDefinitionCommand(Messages._UI_ACTION_ADD_COMPLEX_TYPE, concreteComponent.getSchema());
                command.setNameToAdd(component.getName());
                command.execute();
                td = command.getCreatedComplexType();
            } else {
                AddXSDSimpleTypeDefinitionCommand command = new AddXSDSimpleTypeDefinitionCommand(Messages._UI_ACTION_ADD_SIMPLE_TYPE, concreteComponent.getSchema());
                command.setNameToAdd(component.getName());
                command.execute();
                td = command.getCreatedSimpleType();
            }
            if (td != null) {
                Command command = new SetBaseTypeCommand(concreteComponent, td);
                command.execute();
            }
            XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
        } else {
            Command command = new SetBaseTypeAndManagerDirectivesCommand(concreteComponent, component.getName(), component.getQualifier(), component.getFile());
            command.setLabel(Messages._UI_ACTION_SET_BASE_TYPE);
            command.execute();
        }
    } else if (concreteComponent instanceof XSDSimpleTypeDefinition) {
        if (component.isNew()) {
            XSDTypeDefinition td = null;
            if (component.getMetaName() == IXSDSearchConstants.SIMPLE_TYPE_META_NAME) {
                AddXSDSimpleTypeDefinitionCommand command = new AddXSDSimpleTypeDefinitionCommand(Messages._UI_ACTION_ADD_SIMPLE_TYPE, concreteComponent.getSchema());
                command.setNameToAdd(component.getName());
                command.execute();
                td = command.getCreatedSimpleType();
            }
            if (td != null) {
                Command command = new SetBaseTypeCommand(concreteComponent, td);
                command.execute();
            }
            XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
        } else {
            Command command = new SetBaseTypeAndManagerDirectivesCommand(concreteComponent, component.getName(), component.getQualifier(), component.getFile());
            command.execute();
        }
    }
}
Also used : AddXSDComplexTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDComplexTypeDefinitionCommand) SetBaseTypeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.SetBaseTypeCommand) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) SetBaseTypeAndManagerDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.SetBaseTypeAndManagerDirectivesCommand) AddXSDComplexTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDComplexTypeDefinitionCommand) SetBaseTypeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.SetBaseTypeCommand) AddXSDSimpleTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDSimpleTypeDefinitionCommand) Command(org.eclipse.gef.commands.Command) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) SetBaseTypeAndManagerDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.SetBaseTypeAndManagerDirectivesCommand) AddXSDSimpleTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDSimpleTypeDefinitionCommand) Adapter(org.eclipse.emf.common.notify.Adapter) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Aggregations

Adapter (org.eclipse.emf.common.notify.Adapter)3 AddXSDSimpleTypeDefinitionCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDSimpleTypeDefinitionCommand)3 Command (org.eclipse.gef.commands.Command)2 AddXSDComplexTypeDefinitionCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDComplexTypeDefinitionCommand)2 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)2 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)2 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)2 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)1 SetBaseTypeAndManagerDirectivesCommand (org.eclipse.wst.xsd.ui.internal.common.commands.SetBaseTypeAndManagerDirectivesCommand)1 SetBaseTypeCommand (org.eclipse.wst.xsd.ui.internal.common.commands.SetBaseTypeCommand)1 UpdateTypeReferenceAndManageDirectivesCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceAndManageDirectivesCommand)1 UpdateTypeReferenceCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceCommand)1 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)1 XSDFactory (org.eclipse.xsd.XSDFactory)1 XSDSchema (org.eclipse.xsd.XSDSchema)1