Search in sources :

Example 1 with AddXSDRedefineCommand

use of org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDRedefineCommand 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)

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 XSDSchemaDirectiveAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter)1 AddXSDImportCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDImportCommand)1 AddXSDIncludeCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDIncludeCommand)1 AddXSDRedefineCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDRedefineCommand)1 BaseCommand (org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand)1 XSDSchema (org.eclipse.xsd.XSDSchema)1