Search in sources :

Example 11 with XSDBaseAdapter

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

the class DeleteAction method run.

public void run() {
    for (Iterator i = ((IStructuredSelection) getSelection()).iterator(); i.hasNext(); ) {
        Object selection = i.next();
        Command command = null;
        boolean doSetInput = false;
        boolean doSetModelAsInput = false;
        IADTObject topLevelContainer = null;
        IModel model = null;
        if (selection instanceof IGraphElement) {
            IGraphElement xsdObj = (IGraphElement) selection;
            if (xsdObj instanceof XSDBaseAdapter) {
                XSDBaseAdapter baseAdapter = (XSDBaseAdapter) xsdObj;
                // is null and the read only check cannot be completed
                if (baseAdapter == null || baseAdapter.isReadOnly()) {
                    continue;
                }
                topLevelContainer = xsdObj.getTopContainer();
                if (topLevelContainer == selection) {
                    doSetInput = true;
                    doSetModelAsInput = true;
                }
                command = xsdObj.getDeleteCommand();
                model = xsdObj.getModel();
            }
        }
        if (command != null) {
            IWorkbench workbench = PlatformUI.getWorkbench();
            if (workbench != null) {
                IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
                if (workbenchWindow != null && workbenchWindow.getActivePage() != null) {
                    IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
                    if (editorPart != null) {
                        Object viewer = editorPart.getAdapter(GraphicalViewer.class);
                        if (viewer instanceof DesignViewGraphicalViewer) {
                            Object input = ((DesignViewGraphicalViewer) viewer).getInput();
                            if (input != selection) {
                                // Bug 86218 : Don't switch to top level view if the object we're deleting
                                // is not the input to the viewer
                                doSetInput = false;
                            }
                        }
                    }
                }
            }
            command.execute();
            if (doSetInput) {
                if (model != null && doSetModelAsInput)
                    provider.setSelection(new StructuredSelection(model));
                else if (topLevelContainer != null && !doSetModelAsInput)
                    provider.setSelection(new StructuredSelection(topLevelContainer));
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IModel(org.eclipse.wst.xsd.ui.internal.adt.facade.IModel) IGraphElement(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IGraphElement) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbench(org.eclipse.ui.IWorkbench) DesignViewGraphicalViewer(org.eclipse.wst.xsd.ui.internal.adt.design.DesignViewGraphicalViewer) Command(org.eclipse.gef.commands.Command) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) Iterator(java.util.Iterator) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject)

Example 12 with XSDBaseAdapter

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

the class BaseDirectEditAction method getSelection.

/* (non-Javadoc)
	   * @see org.eclipse.gef.ui.actions.SelectionAction#getSelection()
	   */
protected ISelection getSelection() {
    // always get selection from selection provider first
    if (provider != null) {
        Object selection = provider.getSelection();
        if (selection instanceof StructuredSelection) {
            Object object = ((StructuredSelection) selection).getFirstElement();
            if (object instanceof XSDBaseAdapter) {
                // We need to return an EditPart as the selection.
                IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
                Object graphicalViewer = editor.getAdapter(GraphicalViewer.class);
                if (graphicalViewer instanceof AbstractEditPartViewer) {
                    AbstractEditPartViewer viewer = (AbstractEditPartViewer) graphicalViewer;
                    EditPart editPart = (EditPart) viewer.getEditPartRegistry().get(object);
                    return new StructuredSelection(editPart);
                }
            }
        }
    }
    return super.getSelection();
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) EditPart(org.eclipse.gef.EditPart) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) AbstractEditPartViewer(org.eclipse.gef.ui.parts.AbstractEditPartViewer) IEditorPart(org.eclipse.ui.IEditorPart)

Example 13 with XSDBaseAdapter

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

the class ModelGroupEditPart method getModelChildren.

protected List getModelChildren() {
    // XSDModelGroupAdapter modelGroupAdapter = (XSDModelGroupAdapter)getModel();
    // ArrayList ch = new ArrayList();
    // ITreeElement [] tree = modelGroupAdapter.getChildren();
    // int length = tree.length;
    // for (int i = 0; i < length; i++)
    // {
    // ch.add(tree[i]);
    // }
    List list = new ArrayList();
    XSDModelGroup xsdModelGroup = getXSDModelGroup();
    for (Iterator i = xsdModelGroup.getContents().iterator(); i.hasNext(); ) {
        XSDParticle next = (XSDParticle) i.next();
        if (next.getContent() instanceof XSDElementDeclaration) {
            XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) next.getContent();
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(elementDeclaration);
            list.add(new TargetConnectionSpaceFiller((XSDBaseAdapter) adapter));
        }
        if (next.getContent() instanceof XSDModelGroupDefinition) {
            XSDModelGroupDefinition def = (XSDModelGroupDefinition) next.getContent();
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(def);
            list.add(adapter);
        } else if (next.getTerm() instanceof XSDModelGroup) {
            XSDModelGroup modelGroup = (XSDModelGroup) next.getTerm();
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(modelGroup);
            list.add(adapter);
        } else if (next.getTerm() instanceof XSDWildcard) {
            XSDWildcard wildCard = (XSDWildcard) next.getTerm();
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(wildCard);
            list.add(new TargetConnectionSpaceFiller((XSDBaseAdapter) adapter));
        }
    }
    if (list.size() == 0)
        list.add(new TargetConnectionSpaceFiller(null));
    return list;
// return ch;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDWildcard(org.eclipse.xsd.XSDWildcard) ArrayList(java.util.ArrayList) List(java.util.List) Adapter(org.eclipse.emf.common.notify.Adapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDModelGroupAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupAdapter) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) TargetConnectionSpaceFiller(org.eclipse.wst.xsd.ui.internal.design.editparts.model.TargetConnectionSpaceFiller) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 14 with XSDBaseAdapter

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

the class TopLevelComponentEditPart method doEditName.

public void doEditName(boolean addFromDesign) {
    if (!addFromDesign)
        return;
    // removeFeedback();
    Object object = ((XSDBaseAdapter) getModel()).getTarget();
    if (object instanceof XSDNamedComponent) {
        Point p = label.getLocation();
        TopLevelNameDirectEditManager manager = new TopLevelNameDirectEditManager(TopLevelComponentEditPart.this, new TopLevelComponentLabelCellEditorLocator(TopLevelComponentEditPart.this, p), (XSDNamedComponent) object);
        NameUpdateCommandWrapper wrapper = new NameUpdateCommandWrapper();
        adtDirectEditPolicy.setUpdateCommand(wrapper);
        manager.show();
    }
}
Also used : TopLevelNameDirectEditManager(org.eclipse.wst.xsd.ui.internal.design.editpolicies.TopLevelNameDirectEditManager) XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) TopLevelComponentLabelCellEditorLocator(org.eclipse.wst.xsd.ui.internal.design.editpolicies.TopLevelComponentLabelCellEditorLocator) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) Point(org.eclipse.draw2d.geometry.Point)

Example 15 with XSDBaseAdapter

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

the class XSDBaseFieldEditPart method refreshIcon.

protected void refreshIcon() {
    IFieldFigure figure = getFieldFigure();
    // our model implements ITreeElement
    if (getModel() instanceof XSDBaseAdapter) {
        Image image = ((XSDBaseAdapter) getModel()).getImage();
        boolean isReadOnly = ((XSDBaseAdapter) getModel()).isReadOnly();
        figure.getNameLabel().setIcon(image);
        if (image != null) {
            XSDConcreteComponent comp = (XSDConcreteComponent) ((XSDBaseAdapter) getModel()).getTarget();
            figure.getNameLabel().setIcon(XSDCommonUIUtils.getUpdatedImage(comp, image, isReadOnly));
        }
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IFieldFigure(org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure) Image(org.eclipse.swt.graphics.Image)

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