Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorradvorak2006-08-31 14:22:42 +0000
committerradvorak2006-08-31 14:22:42 +0000
commit8421e67dfd05da1866a3f773fd9bbd90efa405d0 (patch)
tree1cfef15b8562c712e5d0bd7ae9bc2243bd4321c2 /plugins/org.eclipse.gmf.codegen.ui
parent3de17a2df09a3101d23a921921cae77ddf247112 (diff)
downloadorg.eclipse.gmf-tooling-8421e67dfd05da1866a3f773fd9bbd90efa405d0.tar.gz
org.eclipse.gmf-tooling-8421e67dfd05da1866a3f773fd9bbd90efa405d0.tar.xz
org.eclipse.gmf-tooling-8421e67dfd05da1866a3f773fd9bbd90efa405d0.zip
#154698 Support migration of GMF tooling models in case of backward incomatible changes
- adding migration action, save model loading to generate actions
Diffstat (limited to 'plugins/org.eclipse.gmf.codegen.ui')
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/ExecuteTemplatesAction.java42
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/Messages.java38
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/MigrateModelAction.java126
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/TransformToGenModel.java39
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/messages.properties6
5 files changed, 242 insertions, 9 deletions
diff --git a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/ExecuteTemplatesAction.java b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/ExecuteTemplatesAction.java
index d1fcd0224..626b84cfc 100644
--- a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/ExecuteTemplatesAction.java
+++ b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/ExecuteTemplatesAction.java
@@ -20,7 +20,6 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.URI;
-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.util.Diagnostician;
@@ -28,6 +27,7 @@ import org.eclipse.gmf.codegen.gmfgen.GenDiagram;
import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
import org.eclipse.gmf.codegen.util.Generator;
import org.eclipse.gmf.internal.codegen.CodeGenUIPlugin;
+import org.eclipse.gmf.internal.common.migrate.ModelLoadHelper;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
@@ -64,7 +64,11 @@ public class ExecuteTemplatesAction implements IObjectActionDelegate, IRunnableW
// TODO Jobs
public void run(IAction action) {
try {
- loadGenModel();
+ IStatus loadStatus = loadGenModel();
+ if(!canProcessGMFGenModel(loadStatus, action)) {
+ return;
+ }
+
assert getGenModel() != null;
IStatus isGenModelValid = validateGenModel();
if (!isGenModelValid.isOK()) {
@@ -99,6 +103,33 @@ public class ExecuteTemplatesAction implements IObjectActionDelegate, IRunnableW
}
/**
+ * Checks if loaded gmfgen model can be processed further.<p>
+ * Note: Must be called after {@link #loadGenModel()}.
+ * @param loadStatus the result status of loading the gmfgen model
+ * @param action the action in execution
+ * @return <code>true</code> if gmfgen model is available with OK status or in case of load problems,
+ * user decided to proceed, <code>false</code> otherwise.
+ */
+ private boolean canProcessGMFGenModel(IStatus loadStatus, IAction action) {
+ if(!loadStatus.isOK()) {
+ String[] buttons = new String[] {IDialogConstants.PROCEED_LABEL, IDialogConstants.CANCEL_LABEL };
+ int[] buttonIDs = new int[] {IDialogConstants.PROCEED_ID, IDialogConstants.CANCEL_ID };
+ if(myGenModel == null) {
+ // we cannot proceed further as there is no gmfgen, allow only cancel
+ buttons = new String[] { buttons[1] };
+ buttonIDs = new int[] { buttonIDs[1] };
+ }
+ ErrorDialogEx dlg = new ErrorDialogEx(getShell(), action.getText(),
+ CodeGenUIPlugin.getBundleString("generatecode.badsrc"), //$NON-NLS-1$
+ loadStatus, buttons, buttonIDs, 0);
+ if (dlg.open() == IDialogConstants.CANCEL_ID) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
* @return
*/
private void doRunWithStatus() throws InterruptedException {
@@ -139,11 +170,11 @@ public class ExecuteTemplatesAction implements IObjectActionDelegate, IRunnableW
return myGenModel;
}
- private void loadGenModel() {
+ private IStatus loadGenModel() {
URI selected = URI.createPlatformResourceURI(mySelection.getFullPath().toString());
ResourceSet srcResSet = new ResourceSetImpl();
- Resource srcRes = srcResSet.getResource(selected, true);
- Object root = srcRes.getContents().get(0);
+ ModelLoadHelper loadHelper = new ModelLoadHelper(srcResSet, selected);
+ Object root = loadHelper.getContentsRoot();
if (root instanceof GenDiagram) {
myGenModel = ((GenDiagram) root).getEditorGen();
} else if (root instanceof GenEditorGenerator) {
@@ -152,6 +183,7 @@ public class ExecuteTemplatesAction implements IObjectActionDelegate, IRunnableW
if (myGenModel != null && myGenModel.getDomainGenModel() != null) {
myGenModel.getDomainGenModel().reconcile();
}
+ return loadHelper.getStatus();
}
private void unloadGenModel() {
diff --git a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/Messages.java b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/Messages.java
new file mode 100644
index 000000000..62af6e786
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/Messages.java
@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2006 Eclipse.org
+ *
+ * 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: dvorak - initial API and implementation
+ */
+package org.eclipse.gmf.internal.codegen.popup.actions;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.gmf.internal.codegen.popup.actions.messages"; //$NON-NLS-1$
+
+ public static String migration_confirmModelOverwriteMessage;
+
+ public static String migration_confirmModelOverwriteTitle;
+
+ public static String migration_modelDestinationFileTitle;
+
+ public static String migration_specifyFileNameLabel;
+
+ public static String migration_destinationModelSaveError;
+
+ public static String migration_problemsDetectedTitle;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/MigrateModelAction.java b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/MigrateModelAction.java
new file mode 100644
index 000000000..55ef1fafb
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/MigrateModelAction.java
@@ -0,0 +1,126 @@
+/**
+ * Copyright (c) 2006 Eclipse.org
+ *
+ * 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: dvorak - initial API and implementation
+ */
+package org.eclipse.gmf.internal.codegen.popup.actions;
+
+import java.util.Collections;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.internal.common.migrate.MigrationUtil;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * Performs migration of the model contained in the file selection to the latest
+ * version of it metamodel.
+ */
+public class MigrateModelAction implements IObjectActionDelegate {
+
+ private IFile fileSelection;
+ private IWorkbenchPart wrkbenchPart;
+
+
+ public MigrateModelAction() {
+ super();
+ }
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ wrkbenchPart = targetPart;
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ this.fileSelection = null;
+ action.setEnabled(false);
+ if (selection instanceof IStructuredSelection == false) {
+ return;
+ }
+ this.fileSelection = (IFile) ((IStructuredSelection) selection).getFirstElement();
+ action.setEnabled(true);
+ }
+
+ public void run(IAction action) {
+ final IFile modelFile = this.fileSelection;
+ URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString());
+ Resource resource = MigrationUtil.migrateModel(fileURI);
+ if (resource == null) {
+ return;
+ }
+
+ if (!resource.getErrors().isEmpty() || !resource.getWarnings().isEmpty()) {
+ IStatus loadStatus = BasicDiagnostic.toIStatus(EcoreUtil.computeDiagnostic(resource, true));
+ openErrorDialog(action.getText(), Messages.migration_problemsDetectedTitle, loadStatus);
+ return;
+ }
+ String modelExtension = modelFile.getFileExtension();
+ final IPath destPath = modelFile.getFullPath().removeFileExtension().addFileExtension(modelExtension);
+ InputDialog dlg = new InputDialog(getShell(), Messages.migration_modelDestinationFileTitle,
+ Messages.migration_specifyFileNameLabel, destPath.lastSegment(), new IInputValidator() {
+
+ public String isValid(String newText) {
+ IStatus fileNameStatus = ResourcesPlugin.getWorkspace().validateName(newText, IResource.FILE);
+ return fileNameStatus.isOK() ? null : fileNameStatus.getMessage();
+ }
+ });
+
+ if (dlg.open() != Window.OK) {
+ return;
+ }
+
+ String destFileName = dlg.getValue();
+ if (fileSelection.getParent().findMember(destFileName) != null) {
+ boolean overwrite = MessageDialog.openQuestion(getShell(), Messages.migration_confirmModelOverwriteTitle,
+ NLS.bind(Messages.migration_confirmModelOverwriteMessage, destFileName));
+ if (!overwrite) {
+ return;
+ }
+ }
+
+ URI migratedURI = fileURI.trimSegments(1).appendSegment(destFileName);
+ resource.setURI(migratedURI);
+ IStatus saveStatus = Status.OK_STATUS;
+ try {
+ resource.save(Collections.EMPTY_MAP);
+ } catch (Exception e) {
+ saveStatus = BasicDiagnostic.toIStatus(BasicDiagnostic.toDiagnostic(e));
+ }
+
+ openErrorDialog(action.getText(), Messages.migration_destinationModelSaveError, saveStatus);
+ }
+
+ private void openErrorDialog(String title, String message, IStatus errorStatus) {
+ final String[] buttons = new String[] { IDialogConstants.OK_LABEL };
+ final int[] buttonIDs = new int[] { IDialogConstants.OK_ID };
+ ErrorDialogEx dlg = new ErrorDialogEx(getShell(), title, message, errorStatus, buttons, buttonIDs, 0);
+ dlg.open();
+ }
+
+ private Shell getShell() {
+ return wrkbenchPart.getSite().getShell();
+ }
+}
diff --git a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/TransformToGenModel.java b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/TransformToGenModel.java
index 660943848..c63dff3b4 100644
--- a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/TransformToGenModel.java
+++ b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/TransformToGenModel.java
@@ -57,6 +57,7 @@ import org.eclipse.gmf.internal.bridge.genmodel.ViewmapProducer;
import org.eclipse.gmf.internal.bridge.naming.gen.GenModelNamingMediatorImpl;
import org.eclipse.gmf.internal.codegen.CodeGenUIPlugin;
import org.eclipse.gmf.internal.codegen.GMFGenConfig;
+import org.eclipse.gmf.internal.common.migrate.ModelLoadHelper;
import org.eclipse.gmf.internal.common.reconcile.Reconciler;
import org.eclipse.gmf.internal.graphdef.codegen.ui.FigureGeneratorOptionsDialog;
import org.eclipse.gmf.mappings.Mapping;
@@ -91,17 +92,19 @@ public class TransformToGenModel implements IObjectActionDelegate {
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
myPart = targetPart;
}
-
+
public void run(IAction action) {
initDestinationFile();
if (myDestFile == null) {
return;
}
final ResourceSet resSet = new ResourceSetImpl();
+ ModelLoadHelper loadHelper = new ModelLoadHelper(resSet, getMapModelURI());
+ if(!canProcessMappingModel(loadHelper, action)) {
+ return;
+ }
- Resource mapRes = resSet.getResource(getMapModelURI(), true);
- final Mapping mapping = (Mapping) mapRes.getContents().get(0);
-
+ final Mapping mapping = (Mapping) loadHelper.getContentsRoot();
IStatus mapIsValid = validate(mapping);
if (mapIsValid.matches(IStatus.CANCEL)) {
return;
@@ -233,6 +236,34 @@ public class TransformToGenModel implements IObjectActionDelegate {
}.schedule();
}
+ /**
+ * Checks if loaded mapping model can be processed further
+ *
+ * @param loadHelper helper used to load the mapping model
+ * @param action the action in execution
+ * @return <code>true</code> if mapping model is available with OK status or in case of
+ * load problems, user decided to proceed. Returns <code>false</code> otherwise.
+ */
+ private boolean canProcessMappingModel(ModelLoadHelper loadHelper, IAction action) {
+ if(!loadHelper.getStatus().isOK()) {
+ String[] buttons = new String[] {IDialogConstants.PROCEED_LABEL, IDialogConstants.CANCEL_LABEL };
+ int[] buttonIDs = new int[] {IDialogConstants.PROCEED_ID, IDialogConstants.CANCEL_ID };
+
+ if(!(loadHelper.getContentsRoot() instanceof Mapping)) {
+ // we cannot proceed further as there is no mapping, allow only cancel
+ buttons = new String[] { buttons[1] };
+ buttonIDs = new int[] { buttonIDs[1] };
+ }
+ ErrorDialogEx dlg = new ErrorDialogEx(getShell(), action.getText(),
+ CodeGenUIPlugin.getBundleString("transform.err"),
+ loadHelper.getStatus(), buttons, buttonIDs, 0);
+ if (dlg.open() == IDialogConstants.CANCEL_ID) {
+ return false;
+ }
+ }
+ return true;
+ }
+
private VisualIdentifierDispenser getVisualIdDespenser(ResourceSet resSet) {
Bundle tracePluginBundle = Platform.getBundle("org.eclipse.gmf.bridge.trace");
if (tracePluginBundle != null) {
diff --git a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/messages.properties b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/messages.properties
new file mode 100644
index 000000000..3e5634f7a
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/messages.properties
@@ -0,0 +1,6 @@
+migration_problemsDetectedTitle=Model migration problems detected
+migration_modelDestinationFileTitle=Model migration destination file
+migration_specifyFileNameLabel=Specify file name
+migration_confirmModelOverwriteTitle=Confirm migrated model overwrite
+migration_confirmModelOverwriteMessage=Do you want to overwrite existing ''{0}''
+migration_destinationModelSaveError=Error while saving migrated model to ''{0}''

Back to the top