summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-11-02 06:38:13 (EDT)
committerEike Stepper2007-11-02 06:38:13 (EDT)
commit193c7bae9efd0bda2feb2c1242a8a5fa1f98b51b (patch)
tree4e23c661a82bdad5b57498533b0dbb9d84109c89
parentedf40764533a86c9545c0e0d468ef5cb613ea654 (diff)
downloadcdo-193c7bae9efd0bda2feb2c1242a8a5fa1f98b51b.zip
cdo-193c7bae9efd0bda2feb2c1242a8a5fa1f98b51b.tar.gz
cdo-193c7bae9efd0bda2feb2c1242a8a5fa1f98b51b.tar.bz2
[208529] Provide Migrator for existing GenModels
https://bugs.eclipse.org/bugs/show_bug.cgi?id=208529
-rw-r--r--plugins/org.eclipse.emf.cdo.migrator/.settings/org.eclipse.jdt.core.prefs2
-rw-r--r--plugins/org.eclipse.emf.cdo.migrator/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.emf.cdo.migrator/plugin.xml23
-rw-r--r--plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/CDOImporter.java66
-rw-r--r--plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/CDOMigrator.java83
-rw-r--r--plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/actions/MigrateAction.java144
-rw-r--r--plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/wizards/CDOImporterWizard.java (renamed from plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/ui/CDOImporterWizard.java)5
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningAction.java6
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningActionDelegate.java82
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SafeActionDelegate.java60
10 files changed, 405 insertions, 69 deletions
diff --git a/plugins/org.eclipse.emf.cdo.migrator/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.emf.cdo.migrator/.settings/org.eclipse.jdt.core.prefs
index 51782ff..bde7b15 100644
--- a/plugins/org.eclipse.emf.cdo.migrator/.settings/org.eclipse.jdt.core.prefs
+++ b/plugins/org.eclipse.emf.cdo.migrator/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,4 @@
-#Sat Jun 30 10:34:06 CEST 2007
+#Fri Nov 02 11:37:44 CET 2007
eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
diff --git a/plugins/org.eclipse.emf.cdo.migrator/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.migrator/META-INF/MANIFEST.MF
index 06b4b6b..d56b6a5 100644
--- a/plugins/org.eclipse.emf.cdo.migrator/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.migrator/META-INF/MANIFEST.MF
@@ -10,7 +10,8 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.3.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.3.0,4.0.0)",
+ org.eclipse.emf.ecore.xmi;bundle-version="[2.3.0,3.0.0)",
org.eclipse.emf.importer;bundle-version="[2.3.0,3.0.0)"
Export-Package: org.eclipse.emf.cdo.migrator;version="0.8.0",
- org.eclipse.emf.cdo.migrator.ui;version="0.8.0"
+ org.eclipse.emf.cdo.migrator.wizards;version="0.8.0"
Eclipse-LazyStart: true
diff --git a/plugins/org.eclipse.emf.cdo.migrator/plugin.xml b/plugins/org.eclipse.emf.cdo.migrator/plugin.xml
index fd84108..ffae4b7 100644
--- a/plugins/org.eclipse.emf.cdo.migrator/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.migrator/plugin.xml
@@ -26,5 +26,28 @@
description="%_UI_CDOImporter_description"
wizard="org.eclipse.emf.cdo.migrator.ui.CDOImporterWizard" />
</extension>
+
+ <extension
+ point="org.eclipse.ui.popupMenus">
+ <objectContribution
+ id="org.eclipse.emf.cdo.migrator.MigrateContribution"
+ objectClass="org.eclipse.core.resources.IFile">
+ <menu
+ id="org.eclipse.emf.cdo.migrator.menu1"
+ label="CDO"
+ path="additions">
+ <separator
+ name="group1">
+ </separator>
+ </menu>
+ <action
+ class="org.eclipse.emf.cdo.migrator.actions.MigrateAction"
+ enablesFor="1"
+ id="org.eclipse.emf.cdo.migrator.MigrateAction"
+ label="Migrate EMF Model"
+ menubarPath="org.eclipse.emf.cdo.migrator.menu1/group1">
+ </action>
+ </objectContribution>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/CDOImporter.java b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/CDOImporter.java
index cb8145d..09f2c6b 100644
--- a/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/CDOImporter.java
+++ b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/CDOImporter.java
@@ -10,18 +10,14 @@
**************************************************************************/
package org.eclipse.emf.cdo.migrator;
-import org.eclipse.emf.codegen.ecore.genmodel.GenDelegationKind;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.common.util.BasicDiagnostic;
-import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.DiagnosticException;
-import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.Monitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.UniqueEList;
-import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.converter.ConverterPlugin;
import org.eclipse.emf.converter.util.ConverterUtil;
import org.eclipse.emf.ecore.EPackage;
@@ -32,28 +28,18 @@ import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.importer.ModelImporter;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
import java.text.MessageFormat;
import java.util.List;
+/**
+ * @author Eike Stepper
+ */
public class CDOImporter extends ModelImporter
{
public static final String IMPORTER_ID = "org.eclipse.emf.importer.cdo";
- public static final String PLUGIN_VARIABLE = "CDO=org.eclipse.emf.cdo";
-
- public static final String ROOT_EXTENDS_CLASS = "org.eclipse.emf.internal.cdo.CDOObjectImpl";
-
- public static final String ROOT_EXTENDS_INTERFACE = "org.eclipse.emf.cdo.CDOObject";
-
- public static final String CDO_MF_CONTENTS = "This is a marker file for bundles with CDO native models.\n";
-
public CDOImporter()
{
}
@@ -128,55 +114,15 @@ public class CDOImporter extends ModelImporter
{
super.adjustGenModel(monitor);
+ GenModel genModel = getGenModel();
URI genModelURI = createFileURI(getGenModelPath().toString());
for (URI uri : getModelLocationURIs())
{
- GenModel genModel = getGenModel();
genModel.getForeignModel().add(makeRelative(uri, genModelURI).toString());
- adjustGenModelCDO(genModel, monitor);
- }
- }
-
- protected void adjustGenModelCDO(GenModel genModel, Monitor monitor)
- {
- genModel.setFeatureDelegation(GenDelegationKind.REFLECTIVE_LITERAL);
- genModel.setRootExtendsClass(ROOT_EXTENDS_CLASS);
- genModel.setRootExtendsInterface(ROOT_EXTENDS_INTERFACE);
-
- EList<String> pluginVariables = genModel.getModelPluginVariables();
- if (!pluginVariables.contains(PLUGIN_VARIABLE))
- {
- pluginVariables.add(PLUGIN_VARIABLE);
}
- String projectName = getModelProjectName();
- IProject project = getWorkspaceRoot().getProject(projectName);
- IFolder folder = project.getFolder("META-INF");
- if (!folder.exists())
- {
- try
- {
- folder.create(true, true, BasicMonitor.toIProgressMonitor(monitor));
- }
- catch (CoreException ex)
- {
- throw new WrappedException(ex);
- }
- }
-
- IFile file = folder.getFile("CDO.MF");
- if (!file.exists())
- {
- try
- {
- InputStream contents = new ByteArrayInputStream(CDO_MF_CONTENTS.getBytes());
- file.create(contents, true, BasicMonitor.toIProgressMonitor(monitor));
- }
- catch (CoreException ex)
- {
- throw new WrappedException(ex);
- }
- }
+ IProject project = getWorkspaceRoot().getProject(getModelProjectName());
+ CDOMigrator.adjustGenModel(genModel, project);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/CDOMigrator.java b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/CDOMigrator.java
new file mode 100644
index 0000000..7033b30
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/CDOMigrator.java
@@ -0,0 +1,83 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.migrator;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenDelegationKind;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.WrappedException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class CDOMigrator
+{
+ public static final String ROOT_EXTENDS_CLASS = "org.eclipse.emf.internal.cdo.CDOObjectImpl";
+
+ public static final String ROOT_EXTENDS_INTERFACE = "org.eclipse.emf.cdo.CDOObject";
+
+ public static final String PLUGIN_VARIABLE = "CDO=org.eclipse.emf.cdo";
+
+ public static final String CDO_MF_CONTENTS = "This is a marker file for bundles with CDO native models.\n";
+
+ private CDOMigrator()
+ {
+ }
+
+ public static void adjustGenModel(GenModel genModel, IProject project)
+ {
+ genModel.setFeatureDelegation(GenDelegationKind.REFLECTIVE_LITERAL);
+ genModel.setRootExtendsClass(ROOT_EXTENDS_CLASS);
+ genModel.setRootExtendsInterface(ROOT_EXTENDS_INTERFACE);
+
+ EList<String> pluginVariables = genModel.getModelPluginVariables();
+ if (!pluginVariables.contains(PLUGIN_VARIABLE))
+ {
+ pluginVariables.add(PLUGIN_VARIABLE);
+ }
+
+ IFolder folder = project.getFolder("META-INF");
+ if (!folder.exists())
+ {
+ try
+ {
+ folder.create(true, true, new NullProgressMonitor());
+ }
+ catch (CoreException ex)
+ {
+ throw new WrappedException(ex);
+ }
+ }
+
+ IFile file = folder.getFile("CDO.MF");
+ if (!file.exists())
+ {
+ try
+ {
+ InputStream contents = new ByteArrayInputStream(CDO_MF_CONTENTS.getBytes());
+ file.create(contents, true, new NullProgressMonitor());
+ }
+ catch (CoreException ex)
+ {
+ throw new WrappedException(ex);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/actions/MigrateAction.java b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/actions/MigrateAction.java
new file mode 100644
index 0000000..3112166
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/actions/MigrateAction.java
@@ -0,0 +1,144 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.migrator.actions;
+
+import org.eclipse.emf.cdo.migrator.CDOMigrator;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+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;
+
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class MigrateAction implements IObjectActionDelegate
+{
+ @SuppressWarnings("unused")
+ private IAction action;
+
+ private ISelection selection;
+
+ public MigrateAction()
+ {
+ }
+
+ public void selectionChanged(IAction action, ISelection selection)
+ {
+ this.action = action;
+ this.selection = selection;
+ }
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart)
+ {
+ this.action = action;
+ }
+
+ public void run(IAction action)
+ {
+ new Job("Migrating EMF model")
+ {
+ @Override
+ protected IStatus run(IProgressMonitor monitor)
+ {
+ try
+ {
+ IFile file = getFile();
+ if (file == null)
+ {
+ MessageDialog.openError(new Shell(), "CDO Migrator", "The selected element is not a *.genmodel file.");
+ }
+ else
+ {
+ GenModel genModel = getGenModel(file);
+ if (genModel == null)
+ {
+ MessageDialog.openError(new Shell(), "CDO Migrator",
+ "The selected file does not contain a generator model.");
+ }
+ else
+ {
+ CDOMigrator.adjustGenModel(genModel, file.getProject());
+ MessageDialog.openInformation(new Shell(), "CDO Migrator",
+ "The selected generator model has been migrated.");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ return new Status(IStatus.ERROR, "org.eclipse.emf.cdo.migrator", "Problem while migrating EMF model", ex);
+ }
+
+ return Status.OK_STATUS;
+ }
+ }.schedule();
+ }
+
+ protected IFile getFile()
+ {
+ if (selection instanceof IStructuredSelection)
+ {
+ Object element = ((IStructuredSelection)selection).getFirstElement();
+ if (element instanceof IFile)
+ {
+ IFile file = (IFile)element;
+ if ("genmodel".equals(file.getFileExtension()))
+ {
+ return file;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ protected GenModel getGenModel(IFile file)
+ {
+ ResourceSet resourceSet = new ResourceSetImpl();
+
+ Map<String, Object> map = resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
+ map.put("*", new XMIResourceFactoryImpl());
+
+ URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), false);
+ Resource resource = resourceSet.getResource(uri, true);
+
+ EList<EObject> contents = resource.getContents();
+ if (!contents.isEmpty())
+ {
+ EObject object = contents.get(0);
+ if (object instanceof GenModel)
+ {
+ return (GenModel)object;
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/ui/CDOImporterWizard.java b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/wizards/CDOImporterWizard.java
index eea3547..20f842b 100644
--- a/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/ui/CDOImporterWizard.java
+++ b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/migrator/wizards/CDOImporterWizard.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.emf.cdo.migrator.ui;
+package org.eclipse.emf.cdo.migrator.wizards;
import org.eclipse.emf.cdo.migrator.CDOImporter;
@@ -17,6 +17,9 @@ import org.eclipse.emf.importer.ui.contribution.base.ModelImporterDetailPage;
import org.eclipse.emf.importer.ui.contribution.base.ModelImporterPackagePage;
import org.eclipse.emf.importer.ui.contribution.base.ModelImporterWizard;
+/**
+ * @author Eike Stepper
+ */
public class CDOImporterWizard extends ModelImporterWizard
{
public CDOImporterWizard()
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningAction.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningAction.java
index ecd0e75..7fee458 100644
--- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningAction.java
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningAction.java
@@ -186,12 +186,6 @@ public abstract class LongRunningAction extends SafeAction
protected abstract void doRun() throws Exception;
- protected IStatus handleException(Exception ex)
- {
- ex.printStackTrace();
- return new Status(IStatus.ERROR, OM.BUNDLE_ID, "An error has occured.", ex);
- }
-
protected final void checkCancelation(IProgressMonitor monitor)
{
if (monitor.isCanceled())
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningActionDelegate.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningActionDelegate.java
new file mode 100644
index 0000000..62506bf
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningActionDelegate.java
@@ -0,0 +1,82 @@
+package org.eclipse.net4j.util.ui.actions;
+
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.om.monitor.MonitorUtil;
+import org.eclipse.net4j.util.om.monitor.MonitoredJob;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class LongRunningActionDelegate extends SafeActionDelegate
+{
+ private int totalWork;
+
+ public LongRunningActionDelegate()
+ {
+ }
+
+ protected final int getTotalWork()
+ {
+ return totalWork;
+ }
+
+ protected final void setTotalWork(int totalWork)
+ {
+ this.totalWork = totalWork;
+ }
+
+ protected final void cancel()
+ {
+ totalWork = 0;
+ }
+
+ @Override
+ protected final void safeRun() throws Exception
+ {
+ totalWork = IProgressMonitor.UNKNOWN;
+ preRun();
+ if (totalWork != 0)
+ {
+ new MonitoredJob(getBundleID(), getText())
+ {
+ @Override
+ protected void run() throws Exception
+ {
+ try
+ {
+ MonitorUtil.begin(totalWork);
+ doRun();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ throw ex;
+ }
+ }
+ }.schedule();
+ }
+ }
+
+ protected void preRun() throws Exception
+ {
+ }
+
+ protected String getBundleID()
+ {
+ return OM.BUNDLE_ID;
+ }
+
+ protected abstract void doRun() throws Exception;
+
+ protected final void checkCancelation(IProgressMonitor monitor)
+ {
+ if (monitor.isCanceled())
+ {
+ throw new OperationCanceledException();
+ }
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SafeActionDelegate.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SafeActionDelegate.java
new file mode 100644
index 0000000..ce3d584
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SafeActionDelegate.java
@@ -0,0 +1,60 @@
+package org.eclipse.net4j.util.ui.actions;
+
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IActionDelegate;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class SafeActionDelegate implements IActionDelegate
+{
+ private IAction action;
+
+ private ISelection selection;
+
+ public SafeActionDelegate()
+ {
+ }
+
+ public IAction getAction()
+ {
+ return action;
+ }
+
+ public ISelection getSelection()
+ {
+ return selection;
+ }
+
+ public void selectionChanged(IAction action, ISelection selection)
+ {
+ this.action = action;
+ this.selection = selection;
+ }
+
+ public void run(IAction action)
+ {
+ this.action = action;
+
+ try
+ {
+ safeRun();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ MessageDialog.openError(null, getText(), ex.getMessage() + "\nSee the Error log for details.");
+ }
+ }
+
+ protected abstract void safeRun() throws Exception;
+
+ protected String getText()
+ {
+ return action == null ? "Error" : action.getText();
+ }
+} \ No newline at end of file