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) {
}
}
}
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();
}
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);
}
}
Aggregations