| /* |
| * Copyright (c) 2006 Borland Software Corporation |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Dmitry Stadnik (Borland) - initial API and implementation |
| */ |
| package org.eclipse.gmf.map.editor.navigator; |
| |
| import org.eclipse.gmf.map.editor.edit.parts.MappingEditPart; |
| |
| import org.eclipse.gmf.map.editor.part.GMFMapDiagramEditor; |
| import org.eclipse.gmf.map.editor.part.GMFMapDiagramEditorPlugin; |
| import org.eclipse.gmf.map.editor.part.GMFMapVisualIDRegistry; |
| |
| import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorInput; |
| |
| import org.eclipse.gmf.runtime.notation.Diagram; |
| |
| import org.eclipse.jface.action.Action; |
| import org.eclipse.jface.action.IMenuManager; |
| |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| |
| import org.eclipse.ui.IActionBars; |
| import org.eclipse.ui.IWorkbenchPage; |
| import org.eclipse.ui.PartInitException; |
| |
| import org.eclipse.ui.navigator.CommonActionProvider; |
| import org.eclipse.ui.navigator.ICommonActionConstants; |
| import org.eclipse.ui.navigator.ICommonActionExtensionSite; |
| import org.eclipse.ui.navigator.ICommonMenuConstants; |
| import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; |
| |
| /** |
| * @generated |
| */ |
| public class GMFMapNavigatorActionProvider extends CommonActionProvider { |
| |
| /** |
| * @generated |
| */ |
| private boolean myContribute; |
| |
| /** |
| * @generated |
| */ |
| private OpenDiagramAction myOpenDiagramAction; |
| |
| /** |
| * @generated |
| */ |
| public void init(ICommonActionExtensionSite aSite) { |
| super.init(aSite); |
| if (aSite.getViewSite() instanceof ICommonViewerWorkbenchSite) { |
| myContribute = true; |
| makeActions((ICommonViewerWorkbenchSite) aSite.getViewSite()); |
| } else { |
| myContribute = false; |
| } |
| } |
| |
| /** |
| * @generated |
| */ |
| private void makeActions(ICommonViewerWorkbenchSite viewerSite) { |
| myOpenDiagramAction = new OpenDiagramAction(viewerSite); |
| } |
| |
| /** |
| * @generated |
| */ |
| public void fillActionBars(IActionBars actionBars) { |
| if (!myContribute) { |
| return; |
| } |
| IStructuredSelection selection = (IStructuredSelection) getContext().getSelection(); |
| myOpenDiagramAction.selectionChanged(selection); |
| if (myOpenDiagramAction.isEnabled()) { |
| actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, myOpenDiagramAction); |
| } |
| } |
| |
| /** |
| * @generated |
| */ |
| public void fillContextMenu(IMenuManager menu) { |
| /* if (!myContribute || getContext().getSelection().isEmpty()) { |
| return; |
| } |
| |
| IStructuredSelection selection = (IStructuredSelection) getContext().getSelection(); |
| |
| myOpenDiagramAction.selectionChanged(selection); |
| if (myOpenDiagramAction.isEnabled()) { |
| menu.insertAfter(ICommonMenuConstants.GROUP_OPEN, myOpenDiagramAction); |
| }*/ |
| } |
| |
| /** |
| * @generated |
| */ |
| private class OpenDiagramAction extends Action { |
| |
| /** |
| * @generated |
| */ |
| private Diagram myDiagram; |
| |
| /** |
| * @generated |
| */ |
| private ICommonViewerWorkbenchSite myViewerSite; |
| |
| /** |
| * @generated |
| */ |
| public OpenDiagramAction(ICommonViewerWorkbenchSite viewerSite) { |
| super("Open Diagram"); |
| myViewerSite = viewerSite; |
| } |
| |
| /** |
| * @generated |
| */ |
| public final void selectionChanged(IStructuredSelection selection) { |
| myDiagram = null; |
| if (selection.size() == 1) { |
| Object selectedElement = selection.getFirstElement(); |
| if (selectedElement instanceof GMFMapNavigatorItem) { |
| selectedElement = ((GMFMapNavigatorItem) selectedElement).getView(); |
| } |
| if (selectedElement instanceof Diagram) { |
| Diagram diagram = (Diagram) selectedElement; |
| if (MappingEditPart.MODEL_ID.equals(GMFMapVisualIDRegistry.getModelID(diagram))) { |
| myDiagram = diagram; |
| } |
| } |
| } |
| setEnabled(myDiagram != null); |
| } |
| |
| /** |
| * @generated |
| */ |
| public void run() { |
| if (myDiagram == null) { |
| return; |
| } |
| DiagramEditorInput editorInput = new DiagramEditorInput(myDiagram); |
| IWorkbenchPage page = myViewerSite.getPage(); |
| try { |
| page.openEditor(editorInput, GMFMapDiagramEditor.ID); |
| } catch (PartInitException e) { |
| GMFMapDiagramEditorPlugin.getInstance().logError("Exception while openning diagram", e); |
| } |
| } |
| |
| } |
| |
| } |