/*
* 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.eclipse.gmf.examples.taipan.gmf.editor.part;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.gmf.examples.taipan.gmf.editor.edit.parts.AquatoryEditPart;
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.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
/**
* @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();
Resource resource = TaiPanDiagramEditorUtil.openModel(myShell, Messages.TaiPanCreateShortcutAction_OpenModelTitle, mySelectedElement.getEditingDomain());
if (resource == null || resource.getContents().isEmpty()) {
return;
}
ShortcutCreationWizard wizard = new ShortcutCreationWizard((EObject) resource.getContents().get(0), view, mySelectedElement.getEditingDomain());
wizard.setWindowTitle(Messages.TaiPanCreateShortcutAction_CreateShortcutTitle);
TaiPanDiagramEditorUtil.runWizard(myShell, wizard, "CreateShortcut"); //$NON-NLS-1$
}
}