/******************************************************************************* * Copyright (c) 2006-2012 * Software Technology Group, Dresden University of Technology * DevBoost GmbH, Berlin, Amtsgericht Charlottenburg, HRB 140026 * * 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: * Software Technology Group - TU Dresden, Germany; * DevBoost GmbH - Berlin, Germany * - initial API and implementation ******************************************************************************/ /* * Copyright (c) 2006, 2007 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.reuseware.application.taipan.gmf.editor.part; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.operations.OperationHistoryFactory; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.common.util.WrappedException; import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.common.core.command.ICommand; import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand; import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest; import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; import org.reuseware.application.taipan.gmf.editor.edit.commands.TaiPanCreateShortcutDecorationsCommand; import org.reuseware.application.taipan.gmf.editor.edit.parts.AquatoryEditPart; /** * @generated */ public class TaiPanCreateShortcutAction implements IObjectActionDelegate { /** * @generated */ private AquatoryEditPart mySelectedElement; /** * @generated */ private Shell myShell; /** * @generated */ public void setActivePart(IAction action, IWorkbenchPart targetPart) { myShell = targetPart.getSite().getShell(); } /** * @generated */ public void selectionChanged(IAction action, ISelection selection) { mySelectedElement = null; if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; if (structuredSelection.size() == 1 && structuredSelection.getFirstElement() instanceof AquatoryEditPart) { mySelectedElement = (AquatoryEditPart) structuredSelection .getFirstElement(); } } action.setEnabled(isEnabled()); } /** * @generated */ private boolean isEnabled() { return mySelectedElement != null; } /** * @generated */ public void run(IAction action) { final View view = (View) mySelectedElement.getModel(); TaiPanElementChooserDialog elementChooser = new TaiPanElementChooserDialog( myShell, view); int result = elementChooser.open(); if (result != Window.OK) { return; } URI selectedModelElementURI = elementChooser .getSelectedModelElementURI(); final EObject selectedElement; try { selectedElement = mySelectedElement.getEditingDomain() .getResourceSet().getEObject(selectedModelElementURI, true); } catch (WrappedException e) { TaiPanDiagramEditorPlugin .getInstance() .logError( "Exception while loading object: " + selectedModelElementURI.toString(), e); //$NON-NLS-1$ return; } if (selectedElement == null) { return; } CreateViewRequest.ViewDescriptor viewDescriptor = new CreateViewRequest.ViewDescriptor( new EObjectAdapter(selectedElement), Node.class, null, TaiPanDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT); ICommand command = new CreateCommand(mySelectedElement .getEditingDomain(), viewDescriptor, view); command = command.compose(new TaiPanCreateShortcutDecorationsCommand( mySelectedElement.getEditingDomain(), view, viewDescriptor)); try { OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null); } catch (ExecutionException e) { TaiPanDiagramEditorPlugin.getInstance().logError( "Unable to create shortcut", e); //$NON-NLS-1$ } } }