| 1 |
/** |
| 2 |
* Copyright (c) 2006 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v2.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v20.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM - Initial API and implementation |
| 10 |
*/ |
| 11 |
|
| 12 |
package org.eclipse.emf.cheatsheets.actions; |
| 13 |
|
| 14 |
import org.eclipse.core.runtime.CoreException; |
| 15 |
import org.eclipse.jface.action.Action; |
| 16 |
import org.eclipse.jface.viewers.ISelection; |
| 17 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 18 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 19 |
import org.eclipse.jface.window.Window; |
| 20 |
import org.eclipse.jface.wizard.WizardDialog; |
| 21 |
import org.eclipse.swt.widgets.Shell; |
| 22 |
import org.eclipse.ui.INewWizard; |
| 23 |
import org.eclipse.ui.IWorkbenchWindow; |
| 24 |
import org.eclipse.ui.PlatformUI; |
| 25 |
|
| 26 |
import org.eclipse.emf.cheatsheets.CheatSheetsPlugin; |
| 27 |
|
| 28 |
|
| 29 |
public abstract class AbstractOpenWizardAction extends Action |
| 30 |
{ |
| 31 |
@Override |
| 32 |
public void run() |
| 33 |
{ |
| 34 |
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); |
| 35 |
try |
| 36 |
{ |
| 37 |
INewWizard wizard = createWizard(); |
| 38 |
wizard.init(PlatformUI.getWorkbench(), getSelection()); |
| 39 |
WizardDialog dialog = new WizardDialog(shell, wizard); |
| 40 |
dialog.create(); |
| 41 |
int res = dialog.open(); |
| 42 |
notifyResult(res == Window.OK); |
| 43 |
} |
| 44 |
catch (CoreException e) |
| 45 |
{ |
| 46 |
CheatSheetsPlugin.INSTANCE.log(e); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
abstract protected INewWizard createWizard() throws CoreException; |
| 51 |
|
| 52 |
private IStructuredSelection getSelection() |
| 53 |
{ |
| 54 |
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
| 55 |
if (window != null) |
| 56 |
{ |
| 57 |
ISelection selection = window.getSelectionService().getSelection(); |
| 58 |
if (selection instanceof IStructuredSelection) |
| 59 |
{ |
| 60 |
return (IStructuredSelection)selection; |
| 61 |
} |
| 62 |
} |
| 63 |
return StructuredSelection.EMPTY; |
| 64 |
} |
| 65 |
} |