Search in sources :

Example 21 with XSDBaseAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.

the class BaseFieldEditPart method doEditName.

public void doEditName(boolean addFromDesign) {
    if (!addFromDesign)
        return;
    // removeFeedback();
    Runnable runnable = new Runnable() {

        public void run() {
            Object object = ((XSDBaseAdapter) getModel()).getTarget();
            if (object instanceof XSDNamedComponent) {
                Point p = getNameLabelFigure().getLocation();
                LabelEditManager manager = new LabelEditManager(BaseFieldEditPart.this, new LabelCellEditorLocator(BaseFieldEditPart.this, p));
                NameUpdateCommandWrapper wrapper = new NameUpdateCommandWrapper();
                adtDirectEditPolicy.setUpdateCommand(wrapper);
                manager.show();
            }
        }
    };
    Display.getCurrent().asyncExec(runnable);
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) LabelEditManager(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.LabelEditManager) LabelCellEditorLocator(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.LabelCellEditorLocator) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) Point(org.eclipse.draw2d.geometry.Point)

Example 22 with XSDBaseAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.

the class AddXSDSchemaDirectiveAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
    }
    BaseCommand command = null;
    if (selection instanceof XSDSchema) {
        if (INCLUDE_ID.equals(getId())) {
            command = new AddXSDIncludeCommand(label, (XSDSchema) selection);
        } else if (IMPORT_ID.equals(getId())) {
            command = new AddXSDImportCommand(label, (XSDSchema) selection);
        } else if (REDEFINE_ID.equals(getId())) {
            command = new AddXSDRedefineCommand(label, (XSDSchema) selection);
        }
        getCommandStack().execute(command);
    }
    if (command != null) {
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(command.getAddedComponent());
        if (adapter != null) {
            provider.setSelection(new StructuredSelection(adapter));
            // Automatically open the schema location dialog if the preference is enabled
            if (XSDEditorPlugin.getDefault().getAutomaticallyOpenSchemaLocationDialogSetting()) {
                XSDSchemaDirectiveAdapter xsdSchemaDirectiveAdapter = null;
                if (adapter instanceof XSDSchemaDirectiveAdapter) {
                    xsdSchemaDirectiveAdapter = (XSDSchemaDirectiveAdapter) adapter;
                }
                XSDDirectivesSchemaLocationUpdater.updateSchemaLocation((XSDSchema) selection, xsdSchemaDirectiveAdapter.getTarget(), (command instanceof AddXSDIncludeCommand || command instanceof AddXSDRedefineCommand));
            }
            // The graphical view may deselect, so select again
            provider.setSelection(new StructuredSelection(adapter));
        }
    }
}
Also used : XSDSchemaDirectiveAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter) BaseCommand(org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) AddXSDRedefineCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDRedefineCommand) Adapter(org.eclipse.emf.common.notify.Adapter) XSDSchemaDirectiveAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDSchema(org.eclipse.xsd.XSDSchema) AddXSDIncludeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDIncludeCommand) AddXSDImportCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDImportCommand)

Example 23 with XSDBaseAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.

the class AddXSDAnyAttributeAction method run.

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

Example 24 with XSDBaseAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter 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)

Example 25 with XSDBaseAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter in project webtools.sourceediting by eclipse.

the class AddXSDComplexTypeDefinitionAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
    }
    if (selection instanceof XSDSchema) {
        AddXSDComplexTypeDefinitionCommand command = new AddXSDComplexTypeDefinitionCommand(Messages._UI_ACTION_ADD_COMPLEX_TYPE, (XSDSchema) selection);
        getCommandStack().execute(command);
        addedComponent = command.getAddedComponent();
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
        selectAddedComponent(adapter);
    }
}
Also used : AddXSDComplexTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDComplexTypeDefinitionCommand) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) 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)

Aggregations

XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)33 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)23 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)16 Adapter (org.eclipse.emf.common.notify.Adapter)14 XSDSchema (org.eclipse.xsd.XSDSchema)10 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)9 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)8 IEditorPart (org.eclipse.ui.IEditorPart)6 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)5 Iterator (java.util.Iterator)4 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)4 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)4 List (java.util.List)3 Point (org.eclipse.draw2d.geometry.Point)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)3 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)3 ArrayList (java.util.ArrayList)2 Image (org.eclipse.swt.graphics.Image)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2