001: package newprocess.diagram.navigator;
002:
003: import newprocess.diagram.edit.parts.ProcessEditPart;
004:
005: import newprocess.diagram.part.New_processDiagramEditor;
006: import newprocess.diagram.part.New_processDiagramEditorPlugin;
007: import newprocess.diagram.part.New_processVisualIDRegistry;
008:
009: import org.eclipse.core.runtime.IAdaptable;
010:
011: import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorInput;
012:
013: import org.eclipse.gmf.runtime.notation.Diagram;
014: import org.eclipse.gmf.runtime.notation.View;
015:
016: import org.eclipse.jface.action.Action;
017: import org.eclipse.jface.action.IMenuManager;
018:
019: import org.eclipse.jface.viewers.IStructuredSelection;
020:
021: import org.eclipse.ui.IActionBars;
022: import org.eclipse.ui.IWorkbenchPage;
023: import org.eclipse.ui.PartInitException;
024:
025: import org.eclipse.ui.navigator.CommonActionProvider;
026: import org.eclipse.ui.navigator.ICommonActionConstants;
027: import org.eclipse.ui.navigator.ICommonActionExtensionSite;
028: import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
029:
030: /**
031: * @generated
032: */
033: public class New_processNavigatorActionProvider extends
034: CommonActionProvider {
035:
036: /**
037: * @generated
038: */
039: private boolean myContribute;
040:
041: /**
042: * @generated
043: */
044: private OpenDiagramAction myOpenDiagramAction;
045:
046: /**
047: * @generated
048: */
049: public void init(ICommonActionExtensionSite aSite) {
050: super .init(aSite);
051: if (aSite.getViewSite() instanceof ICommonViewerWorkbenchSite) {
052: myContribute = true;
053: makeActions((ICommonViewerWorkbenchSite) aSite
054: .getViewSite());
055: } else {
056: myContribute = false;
057: }
058: }
059:
060: /**
061: * @generated
062: */
063: private void makeActions(ICommonViewerWorkbenchSite viewerSite) {
064: myOpenDiagramAction = new OpenDiagramAction(viewerSite);
065: }
066:
067: /**
068: * @generated
069: */
070: public void fillActionBars(IActionBars actionBars) {
071: if (!myContribute) {
072: return;
073: }
074: IStructuredSelection selection = (IStructuredSelection) getContext()
075: .getSelection();
076: myOpenDiagramAction.selectionChanged(selection);
077: if (myOpenDiagramAction.isEnabled()) {
078: actionBars.setGlobalActionHandler(
079: ICommonActionConstants.OPEN, myOpenDiagramAction);
080: }
081: }
082:
083: /**
084: * @generated
085: */
086: public void fillContextMenu(IMenuManager menu) {
087: }
088:
089: /**
090: * @generated
091: */
092: private class OpenDiagramAction extends Action {
093:
094: /**
095: * @generated
096: */
097: private Diagram myDiagram;
098:
099: /**
100: * @generated
101: */
102: private ICommonViewerWorkbenchSite myViewerSite;
103:
104: /**
105: * @generated
106: */
107: public OpenDiagramAction(ICommonViewerWorkbenchSite viewerSite) {
108: super ("Open Diagram");
109: myViewerSite = viewerSite;
110: }
111:
112: /**
113: * @generated
114: */
115: public final void selectionChanged(
116: IStructuredSelection selection) {
117: myDiagram = null;
118: if (selection.size() == 1) {
119: Object selectedElement = selection.getFirstElement();
120: if (selectedElement instanceof New_processNavigatorItem) {
121: selectedElement = ((New_processNavigatorItem) selectedElement)
122: .getView();
123: } else if (selectedElement instanceof IAdaptable) {
124: selectedElement = ((IAdaptable) selectedElement)
125: .getAdapter(View.class);
126: }
127: if (selectedElement instanceof Diagram) {
128: Diagram diagram = (Diagram) selectedElement;
129: if (ProcessEditPart.MODEL_ID
130: .equals(New_processVisualIDRegistry
131: .getModelID(diagram))) {
132: myDiagram = diagram;
133: }
134: }
135: }
136: setEnabled(myDiagram != null);
137: }
138:
139: /**
140: * @generated
141: */
142: public void run() {
143: if (myDiagram == null) {
144: return;
145: }
146: DiagramEditorInput editorInput = new DiagramEditorInput(
147: myDiagram);
148: IWorkbenchPage page = myViewerSite.getPage();
149: try {
150: page.openEditor(editorInput,
151: New_processDiagramEditor.ID);
152: } catch (PartInitException e) {
153: New_processDiagramEditorPlugin.getInstance().logError(
154: "Exception while openning diagram", e);
155: }
156: }
157:
158: }
159:
160: }
|