Search in sources :

Example 6 with XSDBaseAdapter

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

the class XSDBaseAction method calculateEnabled.

protected boolean calculateEnabled() {
    if (getWorkbenchPart() instanceof IEditorPart) {
        IEditorPart owningEditor = (IEditorPart) getWorkbenchPart();
        Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
        if (selection instanceof XSDBaseAdapter) {
            selection = ((XSDBaseAdapter) selection).getTarget();
        }
        XSDSchema xsdSchema = null;
        if (selection instanceof XSDConcreteComponent) {
            xsdSchema = ((XSDConcreteComponent) selection).getSchema();
        }
        if (xsdSchema != null && xsdSchema == owningEditor.getAdapter(XSDSchema.class)) {
            return true;
        }
    }
    return false;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 7 with XSDBaseAdapter

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

the class AddXSDEnumerationFacetAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
        int index = -1;
        AddEnumerationsCommand command = null;
        XSDSimpleTypeDefinition st = null;
        if (selection instanceof XSDSimpleTypeDefinition) {
            st = (XSDSimpleTypeDefinition) selection;
            command = new AddEnumerationsCommand(getText(), st);
        } else if (selection instanceof XSDEnumerationFacet) {
            st = ((XSDEnumerationFacet) selection).getSimpleTypeDefinition();
            index = st.getFacetContents().indexOf(selection);
            doDirectEdit = true;
            command = new AddEnumerationsCommand(getText(), st, getId(), index);
        } else if (// Support for Complex Type's simple Content with enumerations
        selection instanceof XSDComplexTypeDefinition) {
            st = (XSDSimpleTypeDefinition) ((XSDComplexTypeDefinition) selection).getContent();
            command = new AddEnumerationsCommand(getText(), st);
        } else // null
        {
            return;
        }
        List enumList = st.getEnumerationFacets();
        // $NON-NLS-1$
        String newName = XSDCommonUIUtils.createUniqueEnumerationValue("value", enumList);
        command.setValue(newName);
        getCommandStack().execute(command);
        addedComponent = command.getAddedComponent();
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
        selectAddedComponent(adapter);
    }
}
Also used : XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) List(java.util.List) XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) 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) AddEnumerationsCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddEnumerationsCommand)

Example 8 with XSDBaseAdapter

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

the class DeleteXSDConcreteComponentAction method run.

public void run() {
    for (Iterator i = ((IStructuredSelection) getSelection()).iterator(); i.hasNext(); ) {
        Object selection = i.next();
        boolean doReselect = false;
        if (selection instanceof XSDBaseAdapter) {
            selection = ((XSDBaseAdapter) selection).getTarget();
        }
        if (selection instanceof XSDConcreteComponent) {
            XSDConcreteComponent xsdComponent = (XSDConcreteComponent) selection;
            XSDSchema model = xsdComponent.getSchema();
            doReselect = xsdComponent.eContainer() instanceof XSDSchema;
            DeleteCommand command = new DeleteCommand(getText(), xsdComponent);
            getCommandStack().execute(command);
            if (model != null && doReselect) {
                Adapter adapter = XSDAdapterFactory.getInstance().adapt(model);
                if (adapter != null)
                    provider.setSelection(new StructuredSelection(adapter));
            }
        }
    }
}
Also used : DeleteCommand(org.eclipse.wst.xsd.ui.internal.common.commands.DeleteCommand) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) 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)

Example 9 with XSDBaseAdapter

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

the class SetBaseTypeAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
        boolean complexType = selection instanceof XSDComplexTypeDefinition;
        boolean simpleType = selection instanceof XSDSimpleTypeDefinition;
        if (complexType || simpleType) {
            if (getWorkbenchPart() instanceof IEditorPart) {
                IEditorPart editor = (IEditorPart) getWorkbenchPart();
                ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDComplexTypeBaseTypeEditManager.class);
                ComponentSpecification newValue;
                IComponentDialog dialog = null;
                dialog = manager.getBrowseDialog();
                if (dialog != null) {
                    if (simpleType) {
                        ((XSDSearchListDialogDelegate) dialog).showComplexTypes(false);
                    }
                    if (dialog.createAndOpen() == Window.OK) {
                        newValue = dialog.getSelectedComponent();
                        manager.modifyComponentReference(selection, newValue);
                    }
                }
            }
        }
    }
}
Also used : IComponentDialog(org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog) XSDComplexTypeBaseTypeEditManager(org.eclipse.wst.xsd.ui.internal.editor.XSDComplexTypeBaseTypeEditManager) ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) ComponentReferenceEditManager(org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSearchListDialogDelegate(org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate)

Example 10 with XSDBaseAdapter

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

the class SetTypeAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        Object target = ((XSDBaseAdapter) selection).getTarget();
        if (target instanceof XSDConcreteComponent) {
            command = new SetTypeCommand(Messages._UI_ACTION_SET_TYPE, getId(), (XSDConcreteComponent) target);
            command.setAdapter((XSDBaseAdapter) selection);
            getCommandStack().execute(command);
        }
    }
}
Also used : SetTypeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.SetTypeCommand) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

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