Search in sources :

Example 1 with AddXSDModelGroupCommand

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

the class AddXSDModelGroupAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        XSDConcreteComponent xsdComponent = (XSDConcreteComponent) ((XSDBaseAdapter) selection).getTarget();
        AddXSDModelGroupCommand command = null;
        if (xsdComponent instanceof XSDElementDeclaration) {
            XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) xsdComponent;
            command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdElementDeclaration, xsdCompositor);
            getCommandStack().execute(command);
        } else if (xsdComponent instanceof XSDModelGroup) {
            XSDModelGroup xsdModelGroup = (XSDModelGroup) xsdComponent;
            command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdModelGroup, xsdCompositor);
            getCommandStack().execute(command);
        } else if (xsdComponent instanceof XSDComplexTypeDefinition || xsdComponent instanceof XSDModelGroupDefinition) {
            command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdComponent, xsdCompositor);
            getCommandStack().execute(command);
        }
        if (command != null) {
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(command.getAddedComponent());
            if (adapter != null)
                provider.setSelection(new StructuredSelection(adapter));
        }
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) AddXSDModelGroupCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDModelGroupCommand) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) 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) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition)

Aggregations

Adapter (org.eclipse.emf.common.notify.Adapter)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)1 AddXSDModelGroupCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDModelGroupCommand)1 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)1 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)1 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)1 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)1 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)1