Search in sources :

Example 1 with AbstractEditPartViewer

use of org.eclipse.gef.ui.parts.AbstractEditPartViewer in project webtools.sourceediting by eclipse.

the class BaseSelectionAction method activateDirectEdit.

protected void activateDirectEdit() {
    if (getWorkbenchPart() instanceof IEditorPart) {
        try {
            IEditorPart owningEditor = (IEditorPart) getWorkbenchPart();
            IWorkbench workbench = PlatformUI.getWorkbench();
            IWorkbenchPart part = workbench.getActiveWorkbenchWindow().getActivePage().getActivePart();
            Object object = owningEditor.getAdapter(GraphicalViewer.class);
            if (object instanceof AbstractEditPartViewer) {
                AbstractEditPartViewer viewer = (AbstractEditPartViewer) object;
                Object obj = viewer.getSelectedEditParts().get(0);
                doEdit(obj, part);
            }
        } catch (Exception e) {
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AbstractEditPartViewer(org.eclipse.gef.ui.parts.AbstractEditPartViewer) IEditorPart(org.eclipse.ui.IEditorPart)

Example 2 with AbstractEditPartViewer

use of org.eclipse.gef.ui.parts.AbstractEditPartViewer 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 3 with AbstractEditPartViewer

use of org.eclipse.gef.ui.parts.AbstractEditPartViewer in project webtools.sourceediting by eclipse.

the class CreateElementAction method run.

/*
   * @see IAction#run()
   */
public void run() {
    beginRecording(getDescription());
    final Element child = createAndAddNewChildElement();
    endRecording();
    if (selectionProvider != null) {
        final XSDConcreteComponent comp = xsdSchema.getCorrespondingComponent(child);
        // selectionProvider.setSelection(new StructuredSelection(comp));
        Runnable runnable = new Runnable() {

            public void run() {
                if (comp instanceof XSDAttributeDeclaration) {
                    if (((XSDAttributeDeclaration) comp).getContainer() instanceof XSDAttributeUse) {
                        if (comp.getContainer().getContainer() instanceof XSDAttributeGroupDefinition) {
                            selectionProvider.setSelection(new StructuredSelection(comp.getContainer()));
                        } else if (comp.getContainer().getContainer() instanceof XSDComplexTypeDefinition) {
                            if (XSDDOMHelper.inputEquals(child, XSDConstants.ATTRIBUTE_ELEMENT_TAG, true)) {
                                selectionProvider.setSelection(new StructuredSelection(comp.getContainer()));
                            } else {
                                selectionProvider.setSelection(new StructuredSelection(comp));
                            }
                        } else {
                            selectionProvider.setSelection(new StructuredSelection(comp));
                        }
                    } else {
                        selectionProvider.setSelection(new StructuredSelection(comp));
                    }
                } else {
                    selectionProvider.setSelection(new StructuredSelection(comp));
                }
                if (comp instanceof XSDNamedComponent) {
                    if (sourceContext instanceof AbstractEditPartViewer) {
                    // AbstractEditPartViewer viewer = (AbstractEditPartViewer)sourceContext;
                    // Object obj = viewer.getSelectedEditParts().get(0);
                    // if (obj instanceof GraphicalEditPart)
                    // {
                    // if (obj instanceof ElementDeclarationEditPart)
                    // {
                    // XSDElementDeclaration elem = ((ElementDeclarationEditPart)obj).getXSDElementDeclaration();
                    // if (!elem.isElementDeclarationReference())
                    // {
                    // ((ElementDeclarationEditPart)obj).doEditName();
                    // }
                    // }
                    // else if (obj instanceof ModelGroupDefinitionEditPart)
                    // {
                    // XSDModelGroupDefinition group = ((ModelGroupDefinitionEditPart)obj).getXSDModelGroupDefinition();
                    // if (!group.isModelGroupDefinitionReference())
                    // {
                    // ((ModelGroupDefinitionEditPart)obj).doEditName();
                    // }
                    // }
                    // else if (obj instanceof ComplexTypeDefinitionEditPart)
                    // {
                    // XSDComplexTypeDefinition ct = ((ComplexTypeDefinitionEditPart)obj).getXSDComplexTypeDefinition();
                    // if (ct.getName() != null)
                    // {
                    // ((ComplexTypeDefinitionEditPart)obj).doEditName();
                    // }
                    // }
                    // else if (obj instanceof TopLevelComponentEditPart)
                    // {
                    // ((TopLevelComponentEditPart)obj).doEditName();
                    // }
                    // }
                    }
                }
            }
        };
        Display.getDefault().timerExec(50, runnable);
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Element(org.w3c.dom.Element) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) AbstractEditPartViewer(org.eclipse.gef.ui.parts.AbstractEditPartViewer) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Aggregations

AbstractEditPartViewer (org.eclipse.gef.ui.parts.AbstractEditPartViewer)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 IEditorPart (org.eclipse.ui.IEditorPart)2 EditPart (org.eclipse.gef.EditPart)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)1 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)1 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)1 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)1 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)1 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)1 XSDNamedComponent (org.eclipse.xsd.XSDNamedComponent)1 Element (org.w3c.dom.Element)1