Search in sources :

Example 1 with BaseCommand

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
            }
        }
    }
}
Also used : BaseCommand(org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand) Command(org.eclipse.gef.commands.Command) Adapter(org.eclipse.emf.common.notify.Adapter) IField(org.eclipse.wst.xsd.ui.internal.adt.facade.IField) IComplexType(org.eclipse.wst.xsd.ui.internal.adt.facade.IComplexType)

Example 2 with BaseCommand

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));
        }
    }
}
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)2 BaseCommand (org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand)2 Command (org.eclipse.gef.commands.Command)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 IComplexType (org.eclipse.wst.xsd.ui.internal.adt.facade.IComplexType)1 IField (org.eclipse.wst.xsd.ui.internal.adt.facade.IField)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 XSDSchema (org.eclipse.xsd.XSDSchema)1