use of org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand in project webtools.sourceediting by eclipse.
the class AddFieldAction method run.
public void run() {
if (getSelectedObjects().size() > 0) {
Object o = getSelectedObjects().get(0);
IComplexType type = null;
if (o instanceof IComplexType) {
type = (IComplexType) o;
} else if (o instanceof IField) {
IField field = (IField) o;
type = field.getContainerType();
}
if (type != null) {
// $NON-NLS-1$
Command command = type.getAddNewFieldCommand("");
if (command != null) {
getCommandStack().execute(command);
Adapter adapter = XSDAdapterFactory.getInstance().adapt(((BaseCommand) command).getAddedComponent());
selectAddedComponent(adapter);
} else {
// TODO ... pop up a command not implemented message
}
}
}
}
use of org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand 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