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