Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/bridge/ui/dashboard/DashboardFacade.java5
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/bridge/ui/dashboard/DashboardState.java168
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/internal/bridge/ui/dashboard/DashboardMediator.java179
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/internal/bridge/ui/dashboard/DashboardPersistence.java52
-rw-r--r--plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/dashboard/GenerateDEAction.java23
-rw-r--r--plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/popup/actions/ExecuteLiteTemplatesOperation.java30
-rw-r--r--plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/popup/actions/ExecuteTemplatesAction.java14
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/plugin.xml11
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/dashboard/GenerateDEAction.java23
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/dashboard/GenerateGMAction.java40
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/ExecuteTemplatesAction.java172
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/ExecuteTemplatesOperation.java221
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/TransformToGenModel.java368
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/TransformToGenModelOperation.java455
-rw-r--r--plugins/org.eclipse.gmf.common/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/URIUtil.java38
16 files changed, 1063 insertions, 738 deletions
diff --git a/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/bridge/ui/dashboard/DashboardFacade.java b/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/bridge/ui/dashboard/DashboardFacade.java
index 11ee0d5a2..234cd5241 100644
--- a/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/bridge/ui/dashboard/DashboardFacade.java
+++ b/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/bridge/ui/dashboard/DashboardFacade.java
@@ -11,7 +11,6 @@
*/
package org.eclipse.gmf.bridge.ui.dashboard;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
/**
@@ -39,10 +38,6 @@ public interface DashboardFacade {
public IProject getProject();
- public IFile getFile(String fileName);
-
- public String getName(IFile file);
-
public void updateStatus();
public boolean isStrict();
diff --git a/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/bridge/ui/dashboard/DashboardState.java b/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/bridge/ui/dashboard/DashboardState.java
index 8b2974f27..c9ea0dbd5 100644
--- a/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/bridge/ui/dashboard/DashboardState.java
+++ b/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/bridge/ui/dashboard/DashboardState.java
@@ -11,24 +11,128 @@
*/
package org.eclipse.gmf.bridge.ui.dashboard;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.ui.IMemento;
+
/**
* EXPERIMENTAL
*
* @author dstadnik
*/
-public class DashboardState {
+public final class DashboardState {
+
+ private static final String DM_KEY = "domainModel"; //$NON-NLS-1$
+
+ private static final String DGM_KEY = "domainGenerationModel"; //$NON-NLS-1$
+
+ private static final String GDM_KEY = "graphicalDefinitionModel"; //$NON-NLS-1$
+
+ private static final String TDM_KEY = "toolingDefinitionModel"; //$NON-NLS-1$
+
+ private static final String MM_KEY = "mappingModel"; //$NON-NLS-1$
+
+ private static final String GM_KEY = "generationModel"; //$NON-NLS-1$
+
+ private URI dm;
+
+ private URI dgm;
+
+ private URI gdm;
+
+ private URI tdm;
+
+ private URI mm;
+
+ private URI gm;
+
+ public DashboardState() {
+ }
+
+ public DashboardState(IMemento memento) {
+ if (memento != null) {
+ read(memento);
+ }
+ }
+
+ public URI getDM() {
+ return dm;
+ }
+
+ public URI getDGM() {
+ return dgm;
+ }
+
+ public URI getGDM() {
+ return gdm;
+ }
+
+ public URI getTDM() {
+ return tdm;
+ }
+
+ public URI getMM() {
+ return mm;
+ }
+
+ public URI getGM() {
+ return gm;
+ }
+
+ public void setDM(URI uri) {
+ dm = uri;
+ }
+
+ public void setDGM(URI uri) {
+ dgm = uri;
+ }
+
+ public void setGDM(URI uri) {
+ gdm = uri;
+ }
+
+ public void setTDM(URI uri) {
+ tdm = uri;
+ }
+
+ public void setMM(URI uri) {
+ mm = uri;
+ }
- public String dmFileName;
+ public void setGM(URI uri) {
+ gm = uri;
+ }
- public String dgmFileName;
+ public void setDM(IFile file) {
+ dm = getURI(file);
+ }
- public String gdmFileName;
+ public void setDGM(IFile file) {
+ dgm = getURI(file);
+ }
- public String tdmFileName;
+ public void setGDM(IFile file) {
+ gdm = getURI(file);
+ }
- public String mmFileName;
+ public void setTDM(IFile file) {
+ tdm = getURI(file);
+ }
- public String gmFileName;
+ public void setMM(IFile file) {
+ mm = getURI(file);
+ }
+
+ public void setGM(IFile file) {
+ gm = getURI(file);
+ }
+
+ private static URI getURI(IFile file) {
+ if (file == null) {
+ return null;
+ }
+ return URI.createPlatformResourceURI(file.getFullPath().toString());
+ }
public int getModelsCount() {
return 6;
@@ -36,24 +140,62 @@ public class DashboardState {
public int getSpecifiedModelsCount() {
int count = 0;
- if (dmFileName != null) {
+ if (dm != null) {
count++;
}
- if (dgmFileName != null) {
+ if (dgm != null) {
count++;
}
- if (gdmFileName != null) {
+ if (gdm != null) {
count++;
}
- if (tdmFileName != null) {
+ if (tdm != null) {
count++;
}
- if (mmFileName != null) {
+ if (mm != null) {
count++;
}
- if (gmFileName != null) {
+ if (gm != null) {
count++;
}
return count;
}
+
+ private void read(IMemento memento) {
+ dm = read(memento, DM_KEY);
+ dgm = read(memento, DGM_KEY);
+ gdm = read(memento, GDM_KEY);
+ tdm = read(memento, TDM_KEY);
+ mm = read(memento, MM_KEY);
+ gm = read(memento, GM_KEY);
+ }
+
+ private static URI read(IMemento memento, String key) {
+ String s = memento.getString(key);
+ if (s == null) {
+ return null;
+ }
+ try {
+ return URI.createURI(s);
+ } catch (IllegalArgumentException e) {
+ }
+ return null;
+ }
+
+ public void write(IMemento memento) {
+ write(memento, DM_KEY, dm);
+ write(memento, DGM_KEY, dgm);
+ write(memento, GDM_KEY, gdm);
+ write(memento, TDM_KEY, tdm);
+ write(memento, MM_KEY, mm);
+ write(memento, GM_KEY, gm);
+ }
+
+ private static void write(IMemento memento, String key, URI uri) {
+ String s = null;
+ if (uri != null) {
+ s = uri.toString();
+ }
+ memento.putString(key, s);
+ }
}
diff --git a/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/internal/bridge/ui/dashboard/DashboardMediator.java b/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/internal/bridge/ui/dashboard/DashboardMediator.java
index ab90b49d7..a7d4389be 100644
--- a/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/internal/bridge/ui/dashboard/DashboardMediator.java
+++ b/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/internal/bridge/ui/dashboard/DashboardMediator.java
@@ -21,8 +21,8 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
import org.eclipse.draw2d.IFigure;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.presentation.EcoreModelWizard;
import org.eclipse.emf.importer.ui.EMFModelWizard;
import org.eclipse.emf.importer.ui.GenModelReloadActionDelegate;
@@ -36,6 +36,7 @@ import org.eclipse.gmf.internal.bridge.wizards.GMFGraphSimpleModelWizard;
import org.eclipse.gmf.internal.bridge.wizards.GMFToolSimpleModelWizard;
import org.eclipse.gmf.internal.bridge.wizards.NewGMFMapModelWizard;
import org.eclipse.gmf.internal.bridge.wizards.WizardOperationMode;
+import org.eclipse.gmf.internal.common.URIUtil;
import org.eclipse.gmf.internal.common.ui.FileSelector;
import org.eclipse.gmf.mappings.presentation.GMFMapModelWizard;
import org.eclipse.gmf.tooldef.presentation.GMFToolModelWizard;
@@ -157,17 +158,6 @@ public class DashboardMediator implements DashboardFacade {
return linkFigure;
}
- public IFile getFile(String fileName) {
- return project.getFile(new Path(fileName));
- }
-
- public String getName(IFile file) {
- if (file == null) {
- return null;
- }
- return file.getProjectRelativePath().toString();
- }
-
public IProject getProject() {
return project;
}
@@ -194,17 +184,18 @@ public class DashboardMediator implements DashboardFacade {
double done = (double) state.getSpecifiedModelsCount() / state.getModelsCount();
view.getStatusLine(1).setText(MessageFormat.format(Messages.DashboardMediator_Progress, new Object[] { new Double(done) }));
}
- setModelName(view.getDGMFigure(), state.dgmFileName);
- setModelName(view.getGDMFigure(), state.gdmFileName);
- setModelName(view.getDMFigure(), state.dmFileName);
- setModelName(view.getTDMFigure(), state.tdmFileName);
- setModelName(view.getMMFigure(), state.mmFileName);
- setModelName(view.getGMFigure(), state.gmFileName);
+ setModelName(view.getDGMFigure(), state.getDGM());
+ setModelName(view.getGDMFigure(), state.getGDM());
+ setModelName(view.getDMFigure(), state.getDM());
+ setModelName(view.getTDMFigure(), state.getTDM());
+ setModelName(view.getMMFigure(), state.getMM());
+ setModelName(view.getGMFigure(), state.getGM());
view.repaint(); // update hyperlinks
}
- protected void setModelName(ModelFigure figure, String name) {
- figure.setName(name);
+ protected void setModelName(ModelFigure figure, URI uri) {
+ figure.setName(uri == null ? null : uri.lastSegment());
+ figure.setFullName(uri == null ? null : uri.toString());
}
protected abstract class SelectFileAction implements DashboardAction {
@@ -217,21 +208,20 @@ public class DashboardMediator implements DashboardFacade {
}
public void run() {
- IFile file = null;
- String fileName = getFileName();
- if (fileName != null) {
- file = getFile(fileName);
- }
+ IFile file = getURI() == null ? null : URIUtil.getFile(getURI());
file = FileSelector.selectFile(shell, getFigure().getDescription(), project, file, getFileExtension());
- setFileName(getName(file));
+ if (file == null) {
+ return;
+ }
+ setURI(URI.createPlatformResourceURI(file.getFullPath().toString()));
updateStatus();
}
protected abstract ModelFigure getFigure();
- protected abstract String getFileName();
+ protected abstract URI getURI();
- protected abstract void setFileName(String fileName);
+ protected abstract void setURI(URI uri);
protected abstract String getFileExtension();
}
@@ -242,25 +232,25 @@ public class DashboardMediator implements DashboardFacade {
}
public boolean isEnabled() {
- return project != null && getFileName() != null;
+ return project != null && getURI() != null;
}
public void run() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
- IFile modelFile = getFile(getFileName());
+ IFile modelFile = URIUtil.getFile(getURI());
try {
String fileName = modelFile.getFullPath().toString();
String editorId = workbench.getEditorRegistry().getDefaultEditor(fileName).getId();
page.openEditor(new FileEditorInput(modelFile), editorId);
} catch (PartInitException pie) {
- String msg = MessageFormat.format(Messages.DashboardMediator_FailToOpen, new Object[] { getFileName() });
+ String msg = MessageFormat.format(Messages.DashboardMediator_FailToOpen, new Object[] { getURI() });
MessageDialog.openError(workbenchWindow.getShell(), msg, pie.getMessage());
}
}
- protected abstract String getFileName();
+ protected abstract URI getURI();
}
protected abstract class RunWizardAction implements DashboardAction {
@@ -295,20 +285,23 @@ public class DashboardMediator implements DashboardFacade {
protected IStructuredSelection getSelection() {
List<IFile> selection = new ArrayList<IFile>();
- addFile(selection, state.dmFileName);
- addFile(selection, state.dgmFileName);
- addFile(selection, state.gdmFileName);
- addFile(selection, state.tdmFileName);
- addFile(selection, state.mmFileName);
- addFile(selection, state.gmFileName);
+ addFile(selection, state.getDM());
+ addFile(selection, state.getDGM());
+ addFile(selection, state.getGDM());
+ addFile(selection, state.getTDM());
+ addFile(selection, state.getMM());
+ addFile(selection, state.getGM());
return new StructuredSelection(selection);
}
- protected void addFile(List<IFile> files, String name) {
- if (name == null) {
+ protected void addFile(List<IFile> files, URI uri) {
+ if (uri == null) {
return;
}
- files.add(project.getFile(name));
+ IFile file = URIUtil.getFile(uri);
+ if (file != null) {
+ files.add(file);
+ }
}
protected abstract IWizard createWizard();
@@ -323,12 +316,12 @@ public class DashboardMediator implements DashboardFacade {
return DashboardMediator.this.view.getDGMFigure();
}
- protected String getFileName() {
- return state.dgmFileName;
+ protected URI getURI() {
+ return state.getDGM();
}
- protected void setFileName(String fileName) {
- state.dgmFileName = fileName;
+ protected void setURI(URI uri) {
+ state.setDGM(uri);
}
protected String getFileExtension() {
@@ -342,12 +335,12 @@ public class DashboardMediator implements DashboardFacade {
return DashboardMediator.this.view.getGDMFigure();
}
- protected String getFileName() {
- return state.gdmFileName;
+ protected URI getURI() {
+ return state.getGDM();
}
- protected void setFileName(String fileName) {
- state.gdmFileName = fileName;
+ protected void setURI(URI uri) {
+ state.setGDM(uri);
}
protected String getFileExtension() {
@@ -361,12 +354,12 @@ public class DashboardMediator implements DashboardFacade {
return DashboardMediator.this.view.getDMFigure();
}
- protected String getFileName() {
- return state.dmFileName;
+ protected URI getURI() {
+ return state.getDM();
}
- protected void setFileName(String fileName) {
- state.dmFileName = fileName;
+ protected void setURI(URI uri) {
+ state.setDM(uri);
}
protected String getFileExtension() {
@@ -380,12 +373,12 @@ public class DashboardMediator implements DashboardFacade {
return DashboardMediator.this.view.getTDMFigure();
}
- protected String getFileName() {
- return state.tdmFileName;
+ protected URI getURI() {
+ return state.getTDM();
}
- protected void setFileName(String fileName) {
- state.tdmFileName = fileName;
+ protected void setURI(URI uri) {
+ state.setTDM(uri);
}
protected String getFileExtension() {
@@ -399,12 +392,12 @@ public class DashboardMediator implements DashboardFacade {
return DashboardMediator.this.view.getMMFigure();
}
- protected String getFileName() {
- return state.mmFileName;
+ protected URI getURI() {
+ return state.getMM();
}
- protected void setFileName(String fileName) {
- state.mmFileName = fileName;
+ protected void setURI(URI uri) {
+ state.setMM(uri);
}
protected String getFileExtension() {
@@ -418,12 +411,12 @@ public class DashboardMediator implements DashboardFacade {
return DashboardMediator.this.view.getGMFigure();
}
- protected String getFileName() {
- return state.gmFileName;
+ protected URI getURI() {
+ return state.getDM();
}
- protected void setFileName(String fileName) {
- state.gmFileName = fileName;
+ protected void setURI(URI uri) {
+ state.setDM(uri);
}
protected String getFileExtension() {
@@ -433,43 +426,43 @@ public class DashboardMediator implements DashboardFacade {
private class EditDGMAction extends EditFileAction {
- protected String getFileName() {
- return state.dgmFileName;
+ protected URI getURI() {
+ return state.getDGM();
}
}
private class EditGDMAction extends EditFileAction {
- protected String getFileName() {
- return state.gdmFileName;
+ protected URI getURI() {
+ return state.getGDM();
}
}
private class EditDMAction extends EditFileAction {
- protected String getFileName() {
- return state.dmFileName;
+ protected URI getURI() {
+ return state.getDM();
}
}
private class EditTDMAction extends EditFileAction {
- protected String getFileName() {
- return state.tdmFileName;
+ protected URI getURI() {
+ return state.getTDM();
}
}
private class EditMMAction extends EditFileAction {
- protected String getFileName() {
- return state.mmFileName;
+ protected URI getURI() {
+ return state.getMM();
}
}
private class EditGMAction extends EditFileAction {
- protected String getFileName() {
- return state.gmFileName;
+ protected URI getURI() {
+ return state.getGM();
}
}
@@ -481,7 +474,7 @@ public class DashboardMediator implements DashboardFacade {
protected void wizardFinished(IWizard wizard) {
IFile file = ((GMFGraphModelWizard) wizard).getModelFile();
- state.gdmFileName = getName(file);
+ state.setGDM(file);
updateStatus();
}
}
@@ -494,7 +487,7 @@ public class DashboardMediator implements DashboardFacade {
protected void wizardFinished(IWizard wizard) {
IFile file = ((EcoreModelWizard) wizard).getModelFile();
- state.dmFileName = getName(file);
+ state.setDM(file);
updateStatus();
}
}
@@ -507,7 +500,7 @@ public class DashboardMediator implements DashboardFacade {
protected void wizardFinished(IWizard wizard) {
IFile file = ((GMFToolModelWizard) wizard).getModelFile();
- state.tdmFileName = getName(file);
+ state.setTDM(file);
updateStatus();
}
}
@@ -520,7 +513,7 @@ public class DashboardMediator implements DashboardFacade {
protected void wizardFinished(IWizard wizard) {
IFile file = ((GMFMapModelWizard) wizard).getModelFile();
- state.mmFileName = getName(file);
+ state.setMM(file);
updateStatus();
}
}
@@ -533,7 +526,7 @@ public class DashboardMediator implements DashboardFacade {
protected void wizardFinished(IWizard wizard) {
IFile file = ((GMFGenModelWizard) wizard).getModelFile();
- state.gmFileName = getName(file);
+ state.setGM(file);
updateStatus();
}
}
@@ -544,11 +537,11 @@ public class DashboardMediator implements DashboardFacade {
}
public boolean isEnabled() {
- return state.dgmFileName != null;
+ return state.getDGM() != null;
}
public void run() {
- IFile file = getFile(state.dgmFileName);
+ IFile file = URIUtil.getFile(state.getDGM());
GenModelReloadActionDelegate action = new GenModelReloadActionDelegate();
IAction uiAction = new Action() {
};
@@ -561,7 +554,7 @@ public class DashboardMediator implements DashboardFacade {
private class DeriveDGMAction extends RunWizardAction {
public boolean isEnabled() {
- return super.isEnabled() && state.dmFileName != null;
+ return super.isEnabled() && state.getDM() != null;
}
protected IWizard createWizard() {
@@ -570,12 +563,12 @@ public class DashboardMediator implements DashboardFacade {
protected void wizardFinished(IWizard wizard) {
IFile file = ((OpenEMFModelWizard) wizard).getModelFile();
- state.dgmFileName = getName(file);
+ state.setDGM(file);
updateStatus();
}
protected IStructuredSelection getSelection() {
- return new StructuredSelection(getFile(state.dmFileName));
+ return new StructuredSelection(URIUtil.getFile(state.getDM()));
}
}
@@ -590,7 +583,7 @@ public class DashboardMediator implements DashboardFacade {
private class DeriveGDMAction extends RunWizardAction {
public boolean isEnabled() {
- return super.isEnabled() && state.dmFileName != null;
+ return super.isEnabled() && state.getDM() != null;
}
protected IWizard createWizard() {
@@ -601,7 +594,7 @@ public class DashboardMediator implements DashboardFacade {
protected void wizardFinished(IWizard wizard) {
IFile file = ((GMFGraphSimpleModelWizard) wizard).getModelFile();
- state.gdmFileName = getName(file);
+ state.setGDM(file);
updateStatus();
}
}
@@ -609,7 +602,7 @@ public class DashboardMediator implements DashboardFacade {
private class DeriveTDMAction extends RunWizardAction {
public boolean isEnabled() {
- return super.isEnabled() && state.dmFileName != null;
+ return super.isEnabled() && state.getDM() != null;
}
protected IWizard createWizard() {
@@ -620,7 +613,7 @@ public class DashboardMediator implements DashboardFacade {
protected void wizardFinished(IWizard wizard) {
IFile file = ((GMFToolSimpleModelWizard) wizard).getModelFile();
- state.tdmFileName = getName(file);
+ state.setTDM(file);
updateStatus();
}
}
@@ -628,7 +621,7 @@ public class DashboardMediator implements DashboardFacade {
private class CombineMMAction extends RunWizardAction {
public boolean isEnabled() {
- return project != null && state.gdmFileName != null && state.dmFileName != null && state.tdmFileName != null;
+ return project != null && state.getGDM() != null && state.getDM() != null && state.getTDM() != null;
}
protected IWizard createWizard() {
@@ -637,7 +630,7 @@ public class DashboardMediator implements DashboardFacade {
protected void wizardFinished(IWizard wizard) {
IFile file = ((NewGMFMapModelWizard) wizard).getModelFile();
- state.mmFileName = getName(file);
+ state.setMM(file);
updateStatus();
}
}
diff --git a/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/internal/bridge/ui/dashboard/DashboardPersistence.java b/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/internal/bridge/ui/dashboard/DashboardPersistence.java
index aad33c481..3dd7d6274 100644
--- a/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/internal/bridge/ui/dashboard/DashboardPersistence.java
+++ b/plugins/org.eclipse.gmf.bridge.ui.dashboard/src/org/eclipse/gmf/internal/bridge/ui/dashboard/DashboardPersistence.java
@@ -12,7 +12,6 @@
package org.eclipse.gmf.internal.bridge.ui.dashboard;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import org.eclipse.core.resources.IProject;
@@ -29,23 +28,9 @@ public class DashboardPersistence {
private static final String PROJECT_KEY = "project"; //$NON-NLS-1$
- private static final String DM_KEY = "domainModel"; //$NON-NLS-1$
-
- private static final String DGM_KEY = "domainGenerationModel"; //$NON-NLS-1$
-
- private static final String GDM_KEY = "graphicalDefinitionModel"; //$NON-NLS-1$
-
- private static final String TDM_KEY = "toolingDefinitionModel"; //$NON-NLS-1$
-
- private static final String MM_KEY = "mappingModel"; //$NON-NLS-1$
-
- private static final String GM_KEY = "generationModel"; //$NON-NLS-1$
-
public static Map<IProject, DashboardState> read(IMemento memento) {
Map<IProject, DashboardState> states = new HashMap<IProject, DashboardState>();
- IMemento[] stateMementos = memento.getChildren(DS_ELEMENT);
- for (int i = 0; i < stateMementos.length; i++) {
- IMemento stateMemento = stateMementos[i];
+ for (IMemento stateMemento : memento.getChildren(DS_ELEMENT)) {
String projectName = stateMemento.getString(PROJECT_KEY);
if (projectName == null) {
continue;
@@ -54,42 +39,17 @@ public class DashboardPersistence {
if (!project.exists()) {
continue;
}
- DashboardState state = new DashboardState();
- state.dmFileName = stateMemento.getString(DM_KEY);
- state.dgmFileName = stateMemento.getString(DGM_KEY);
- state.gdmFileName = stateMemento.getString(GDM_KEY);
- state.tdmFileName = stateMemento.getString(TDM_KEY);
- state.mmFileName = stateMemento.getString(MM_KEY);
- state.gmFileName = stateMemento.getString(GM_KEY);
- states.put(project, state);
+ states.put(project, new DashboardState(stateMemento));
}
return states;
}
- public static void write(IMemento memento, Map states) {
- for (Iterator it = states.keySet().iterator(); it.hasNext();) {
- IProject project = (IProject) it.next();
- DashboardState state = (DashboardState) states.get(project);
+ public static void write(IMemento memento, Map<IProject, DashboardState> states) {
+ for (IProject project : states.keySet()) {
+ DashboardState state = states.get(project);
IMemento stateMemento = memento.createChild(DS_ELEMENT);
stateMemento.putString(PROJECT_KEY, project.getName());
- if (state.dmFileName != null) {
- stateMemento.putString(DM_KEY, state.dmFileName);
- }
- if (state.dgmFileName != null) {
- stateMemento.putString(DGM_KEY, state.dgmFileName);
- }
- if (state.gdmFileName != null) {
- stateMemento.putString(GDM_KEY, state.gdmFileName);
- }
- if (state.tdmFileName != null) {
- stateMemento.putString(TDM_KEY, state.tdmFileName);
- }
- if (state.mmFileName != null) {
- stateMemento.putString(MM_KEY, state.mmFileName);
- }
- if (state.gmFileName != null) {
- stateMemento.putString(GM_KEY, state.gmFileName);
- }
+ state.write(stateMemento);
}
}
}
diff --git a/plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/dashboard/GenerateDEAction.java b/plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/dashboard/GenerateDEAction.java
index 30d128e98..8dcb2bcbd 100644
--- a/plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/dashboard/GenerateDEAction.java
+++ b/plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/dashboard/GenerateDEAction.java
@@ -11,16 +11,10 @@
*/
package org.eclipse.gmf.internal.codegen.lite.dashboard;
-import org.eclipse.core.resources.IFile;
import org.eclipse.gmf.bridge.ui.dashboard.DashboardAction;
import org.eclipse.gmf.bridge.ui.dashboard.DashboardFacade;
import org.eclipse.gmf.bridge.ui.dashboard.DashboardState;
-import org.eclipse.gmf.internal.codegen.lite.popup.actions.ExecuteTemplatesAction;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.gmf.internal.codegen.lite.popup.actions.ExecuteLiteTemplatesOperation;
/**
* @author dstadnik
@@ -36,21 +30,16 @@ public class GenerateDEAction implements DashboardAction {
public boolean isEnabled() {
DashboardState state = context.getState();
if (context.isStrict()) {
- if (state.dmFileName == null || state.dgmFileName == null) {
+ if (state.getDM() == null || state.getDGM() == null) {
return false;
}
}
- return context.getProject() != null && state.gmFileName != null;
+ return context.getProject() != null && state.getGM() != null;
}
public void run() {
- IFile file = context.getFile(context.getState().gmFileName);
- ExecuteTemplatesAction action = new ExecuteTemplatesAction();
- IAction uiAction = new Action() {
- };
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- action.setActivePart(uiAction, window.getPartService().getActivePart());
- action.selectionChanged(uiAction, new StructuredSelection(file));
- action.run(uiAction);
+ ExecuteLiteTemplatesOperation op = new ExecuteLiteTemplatesOperation();
+ op.setGenModelURI(context.getState().getGM());
+ op.run();
}
}
diff --git a/plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/popup/actions/ExecuteLiteTemplatesOperation.java b/plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/popup/actions/ExecuteLiteTemplatesOperation.java
new file mode 100644
index 000000000..81b5b5a93
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/popup/actions/ExecuteLiteTemplatesOperation.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006 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.internal.codegen.lite.popup.actions;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.gmf.internal.codegen.lite.Generator;
+import org.eclipse.gmf.internal.codegen.popup.actions.ExecuteTemplatesOperation;
+
+/**
+ * @author dstadnik
+ */
+public class ExecuteLiteTemplatesOperation extends ExecuteTemplatesOperation {
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ Generator g = new Generator(getGenModel());
+ g.run(monitor);
+ myRunStatus = g.getRunStatus();
+ }
+}
diff --git a/plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/popup/actions/ExecuteTemplatesAction.java b/plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/popup/actions/ExecuteTemplatesAction.java
index 733a52a29..7a62d408f 100644
--- a/plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/popup/actions/ExecuteTemplatesAction.java
+++ b/plugins/org.eclipse.gmf.codegen.lite.ui/src/org/eclipse/gmf/internal/codegen/lite/popup/actions/ExecuteTemplatesAction.java
@@ -11,16 +11,14 @@
*/
package org.eclipse.gmf.internal.codegen.lite.popup.actions;
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.gmf.internal.codegen.lite.Generator;
+import org.eclipse.gmf.internal.codegen.popup.actions.ExecuteTemplatesOperation;
+/**
+ * @author artem
+ */
public class ExecuteTemplatesAction extends org.eclipse.gmf.internal.codegen.popup.actions.ExecuteTemplatesAction {
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- Generator g = new Generator(getGenModel());
- g.run(monitor);
- myRunStatus = g.getRunStatus();
+ protected ExecuteTemplatesOperation createOperation() {
+ return new ExecuteLiteTemplatesOperation();
}
}
diff --git a/plugins/org.eclipse.gmf.codegen.ui/plugin.xml b/plugins/org.eclipse.gmf.codegen.ui/plugin.xml
index 8d44d9e16..c463c1034 100644
--- a/plugins/org.eclipse.gmf.codegen.ui/plugin.xml
+++ b/plugins/org.eclipse.gmf.codegen.ui/plugin.xml
@@ -6,15 +6,16 @@
point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
- id="gmf.codegen.ui.contribution1"
+ id="gmf.codegen.ui.transformToGenModelFile"
nameFilter="*.gmfmap"
objectClass="org.eclipse.core.resources.IFile">
<action
class="org.eclipse.gmf.internal.codegen.popup.actions.TransformToGenModel"
enablesFor="1"
- id="gmf.codegen.ui.step1Action"
+ id="gmf.codegen.ui.transformToGenModelFileAction"
label="%transform.action"
- menubarPath="additions"/>
+ menubarPath="additions">
+ </action>
<!-- action
class="org.eclipse.gmf.internal.codegen.popup.actions.CreateSpecificDiagramRunTimeModelAction"
enablesFor="1"
@@ -24,7 +25,7 @@
</objectContribution>
<objectContribution
adaptable="true"
- id="gmf.codegen.ui.contribution2"
+ id="gmf.codegen.ui.executeTemplates"
nameFilter="*.gmfgen"
objectClass="org.eclipse.core.resources.IFile">
<action
@@ -32,7 +33,7 @@
class="org.eclipse.gmf.internal.codegen.popup.actions.ExecuteTemplatesAction"
menubarPath="additions"
enablesFor="1"
- id="gmf.codegen.ui.step2Action">
+ id="gmf.codegen.ui.executeTemplatesAction">
</action>
</objectContribution>
<objectContribution
diff --git a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/dashboard/GenerateDEAction.java b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/dashboard/GenerateDEAction.java
index fd56ca2c1..811588870 100644
--- a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/dashboard/GenerateDEAction.java
+++ b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/dashboard/GenerateDEAction.java
@@ -11,16 +11,10 @@
*/
package org.eclipse.gmf.internal.codegen.dashboard;
-import org.eclipse.core.resources.IFile;
import org.eclipse.gmf.bridge.ui.dashboard.DashboardAction;
import org.eclipse.gmf.bridge.ui.dashboard.DashboardFacade;
import org.eclipse.gmf.bridge.ui.dashboard.DashboardState;
-import org.eclipse.gmf.internal.codegen.popup.actions.ExecuteTemplatesAction;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.gmf.internal.codegen.popup.actions.ExecuteTemplatesOperation;
/**
* @author dstadnik
@@ -36,21 +30,16 @@ public class GenerateDEAction implements DashboardAction {
public boolean isEnabled() {
DashboardState state = context.getState();
if (context.isStrict()) {
- if (state.dmFileName == null || state.dgmFileName == null) {
+ if (state.getDM() == null || state.getDGM() == null) {
return false;
}
}
- return context.getProject() != null && state.gmFileName != null;
+ return context.getProject() != null && state.getGM() != null;
}
public void run() {
- IFile file = context.getFile(context.getState().gmFileName);
- ExecuteTemplatesAction action = new ExecuteTemplatesAction();
- IAction uiAction = new Action() {
- };
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- action.setActivePart(uiAction, window.getPartService().getActivePart());
- action.selectionChanged(uiAction, new StructuredSelection(file));
- action.run(uiAction);
+ ExecuteTemplatesOperation op = new ExecuteTemplatesOperation();
+ op.setGenModelURI(context.getState().getGM());
+ op.run();
}
}
diff --git a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/dashboard/GenerateGMAction.java b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/dashboard/GenerateGMAction.java
index 6b26368a6..e80c5fe85 100644
--- a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/dashboard/GenerateGMAction.java
+++ b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/dashboard/GenerateGMAction.java
@@ -11,16 +11,11 @@
*/
package org.eclipse.gmf.internal.codegen.dashboard;
-import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.gmf.bridge.ui.dashboard.DashboardAction;
import org.eclipse.gmf.bridge.ui.dashboard.DashboardFacade;
import org.eclipse.gmf.bridge.ui.dashboard.DashboardState;
-import org.eclipse.gmf.internal.codegen.popup.actions.TransformToGenModel;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.gmf.internal.codegen.popup.actions.TransformToGenModelOperation;
/**
* @author dstadnik
@@ -36,25 +31,30 @@ public class GenerateGMAction implements DashboardAction {
public boolean isEnabled() {
DashboardState state = context.getState();
if (context.isStrict()) {
- if (state.dmFileName == null || state.dgmFileName == null || state.tdmFileName == null) {
+ if (state.getDM() == null || state.getDGM() == null || state.getTDM() == null) {
return false;
}
}
- return context.getProject() != null && state.mmFileName != null;
+ return context.getProject() != null && state.getMM() != null;
}
public void run() {
DashboardState state = context.getState();
- IFile file = context.getFile(state.mmFileName);
- TransformToGenModel action = new TransformToGenModel();
- IAction uiAction = new Action() {
- };
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- action.setActivePart(uiAction, window.getPartService().getActivePart());
- action.selectionChanged(uiAction, new StructuredSelection(file));
- action.run(uiAction);
- IFile gfile = action.getGenModelFile();
- state.gmFileName = context.getName(gfile);
- context.updateStatus();
+ URI mm = state.getMM();
+ URI gm = state.getGM();
+ if (gm == null) {
+ gm = mm.trimFileExtension().appendFileExtension("gmfgen"); //$NON-NLS-1$
+ state.setGM(gm);
+ }
+ try {
+ TransformToGenModelOperation op = new TransformToGenModelOperation();
+ op.setUseRuntimeFigures(Boolean.TRUE);
+ op.setUseMapMode(Boolean.TRUE);
+ op.setMapModelURI(mm);
+ op.setGenModelURI(gm);
+ op.run();
+ } finally {
+ context.updateStatus();
+ }
}
}
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 626b84cfc..daa4f4ea7 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
@@ -11,30 +11,9 @@
*/
package org.eclipse.gmf.internal.codegen.popup.actions;
-import java.lang.reflect.InvocationTargetException;
-
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-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.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.ecore.util.Diagnostician;
-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;
-import org.eclipse.jface.dialogs.MessageDialogWithToggle;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
@@ -46,162 +25,33 @@ import org.eclipse.ui.IWorkbenchPart;
*
* @author artem
*/
-public class ExecuteTemplatesAction implements IObjectActionDelegate, IRunnableWithProgress {
-
- private static final String ASK_OK = "ask_ok";
+public class ExecuteTemplatesAction implements IObjectActionDelegate {
- private IFile mySelection;
+ private IFile gmFile;
private IWorkbenchPart myPart;
- protected IStatus myRunStatus;
- private GenEditorGenerator myGenModel;
-
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
myPart = targetPart;
}
- // TODO Jobs
- public void run(IAction action) {
- try {
- IStatus loadStatus = loadGenModel();
- if(!canProcessGMFGenModel(loadStatus, action)) {
- return;
- }
-
- assert getGenModel() != null;
- IStatus isGenModelValid = validateGenModel();
- if (!isGenModelValid.isOK()) {
- final String[] buttons = new String[] {IDialogConstants.PROCEED_LABEL, IDialogConstants.CANCEL_LABEL };
- final int[] buttonIDs = new int[] {IDialogConstants.PROCEED_ID, IDialogConstants.CANCEL_ID };
- final String msg = CodeGenUIPlugin.getBundleString("generatecode.badsrc");
- ErrorDialogEx dlg = new ErrorDialogEx(getShell(), action.getText(), msg, isGenModelValid, buttons, buttonIDs, 0);
- if (dlg.open() == IDialogConstants.CANCEL_ID) {
- return;
- }
- }
-
- doRunWithStatus();
-
- if (getRunStatus().isOK()) {
- if (!MessageDialogWithToggle.ALWAYS.equals(getPreferences().getString(ASK_OK))) {
- MessageDialogWithToggle.openInformation(getShell(), action.getText(), CodeGenUIPlugin.getBundleString("generatecode.ok"), CodeGenUIPlugin.getBundleString("generatecode.neveragain"), false, getPreferences(), ASK_OK);
- }
- } else if (myRunStatus.matches(IStatus.ERROR)) {
- CodeGenUIPlugin.getDefault().getLog().log(getRunStatus());
- ErrorDialog.openError(getShell(), action.getText(), CodeGenUIPlugin.getBundleString("generatecode.err"), getRunStatus());
- } else if (myRunStatus.matches(IStatus.WARNING)) {
- ErrorDialog.openError(getShell(), action.getText(), CodeGenUIPlugin.getBundleString("generatecode.warn"), getRunStatus());
- } else if (myRunStatus.matches(IStatus.INFO)) {
- ErrorDialog.openError(getShell(), action.getText(), CodeGenUIPlugin.getBundleString("generatecode.info"), getRunStatus());
- }
- } catch (InterruptedException ex) {
- // presumably, user canceled the operation, don't bother him with additional messages
- } finally {
- unloadGenModel();
- }
- }
-
- /**
- * 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 {
- myRunStatus = Status.CANCEL_STATUS;
- try {
- new ProgressMonitorDialog(getShell()).run(true, true, this);
- } catch (InvocationTargetException ex) {
- Throwable targetException = ex.getTargetException();
- if (targetException instanceof CoreException) {
- myRunStatus = ((CoreException)targetException).getStatus();
- } else {
- myRunStatus = new Status(IStatus.ERROR, CodeGenUIPlugin.getPluginID(), 0, "Exception occurred while generating code", targetException);
- }
- }
- }
-
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- Generator g = new Generator(getGenModel(), CodeGenUIPlugin.getDefault().getEmitters(getGenModel()));
- g.run(monitor);
- myRunStatus = g.getRunStatus();
- }
-
public void selectionChanged(IAction action, ISelection selection) {
- mySelection = null;
- action.setEnabled(false);
- if (selection instanceof IStructuredSelection == false) {
- return;
- }
- mySelection = (IFile) ((IStructuredSelection) selection).getFirstElement();
- action.setEnabled(true);
- }
-
- private IStatus getRunStatus() {
- return myRunStatus;
- }
-
- protected final GenEditorGenerator getGenModel() {
- return myGenModel;
+ gmFile = (IFile) ((IStructuredSelection) selection).getFirstElement();
}
- private IStatus loadGenModel() {
- URI selected = URI.createPlatformResourceURI(mySelection.getFullPath().toString());
- ResourceSet srcResSet = new ResourceSetImpl();
- ModelLoadHelper loadHelper = new ModelLoadHelper(srcResSet, selected);
- Object root = loadHelper.getContentsRoot();
- if (root instanceof GenDiagram) {
- myGenModel = ((GenDiagram) root).getEditorGen();
- } else if (root instanceof GenEditorGenerator) {
- myGenModel = (GenEditorGenerator) root;
- }
- if (myGenModel != null && myGenModel.getDomainGenModel() != null) {
- myGenModel.getDomainGenModel().reconcile();
- }
- return loadHelper.getStatus();
- }
-
- private void unloadGenModel() {
- if (myGenModel != null && myGenModel.eResource() != null) {
- myGenModel.eResource().unload();
- }
- myGenModel = null;
+ public void run(IAction action) {
+ ExecuteTemplatesOperation op = createOperation();
+ op.setName(action.getText());
+ op.setShell(getShell());
+ op.setGenModelURI(URI.createPlatformResourceURI(gmFile.getFullPath().toString()));
+ op.run();
}
- private IStatus validateGenModel() {
- return BasicDiagnostic.toIStatus(Diagnostician.INSTANCE.validate(getGenModel()));
+ protected ExecuteTemplatesOperation createOperation() {
+ return new ExecuteTemplatesOperation();
}
private Shell getShell() {
return myPart.getSite().getShell();
}
-
- private static IPreferenceStore getPreferences() {
- return CodeGenUIPlugin.getDefault().getPreferenceStore();
- }
}
diff --git a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/ExecuteTemplatesOperation.java b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/ExecuteTemplatesOperation.java
new file mode 100644
index 000000000..770f857f1
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/ExecuteTemplatesOperation.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 2006 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.internal.codegen.popup.actions;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+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.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.Diagnostician;
+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.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @author dstadnik
+ */
+public class ExecuteTemplatesOperation implements IRunnableWithProgress {
+
+ private static final String ASK_OK = "ask_ok"; //$NON-NLS-1$
+
+ private String name;
+
+ private Shell shell;
+
+ private URI genModelURI;
+
+ protected IStatus myRunStatus;
+
+ private GenEditorGenerator myGenModel;
+
+ public String getName() {
+ if (name == null) {
+ return "Execute Templates"; //$NON-NLS-1$
+ }
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Shell getShell() {
+ if (shell == null) {
+ return Display.getDefault().getActiveShell();
+ }
+ return shell;
+ }
+
+ public void setShell(Shell shell) {
+ this.shell = shell;
+ }
+
+ public URI getGenModelURI() {
+ return genModelURI;
+ }
+
+ public void setGenModelURI(URI uri) {
+ genModelURI = uri;
+ }
+
+ // TODO Jobs
+ public void run() {
+ if (getGenModelURI() == null) {
+ return;
+ }
+ try {
+ IStatus loadStatus = loadGenModel();
+ if (!canProcessGMFGenModel(loadStatus)) {
+ return;
+ }
+
+ assert getGenModel() != null;
+ IStatus isGenModelValid = validateGenModel();
+ if (!isGenModelValid.isOK()) {
+ final String[] buttons = new String[] { IDialogConstants.PROCEED_LABEL, IDialogConstants.CANCEL_LABEL };
+ final int[] buttonIDs = new int[] { IDialogConstants.PROCEED_ID, IDialogConstants.CANCEL_ID };
+ final String msg = CodeGenUIPlugin.getBundleString("generatecode.badsrc"); //$NON-NLS-1$
+ ErrorDialogEx dlg = new ErrorDialogEx(getShell(), getName(), msg, isGenModelValid, buttons, buttonIDs, 0);
+ if (dlg.open() == IDialogConstants.CANCEL_ID) {
+ return;
+ }
+ }
+
+ doRunWithStatus();
+
+ if (getRunStatus().isOK()) {
+ if (!MessageDialogWithToggle.ALWAYS.equals(getPreferences().getString(ASK_OK))) {
+ String okMsg = CodeGenUIPlugin.getBundleString("generatecode.ok"); //$NON-NLS-1$
+ String neverMsg = CodeGenUIPlugin.getBundleString("generatecode.neveragain"); //$NON-NLS-1$
+ MessageDialogWithToggle.openInformation(getShell(), getName(), okMsg, neverMsg, false, getPreferences(), ASK_OK);
+ }
+ } else if (myRunStatus.matches(IStatus.ERROR)) {
+ CodeGenUIPlugin.getDefault().getLog().log(getRunStatus());
+ ErrorDialog.openError(getShell(), getName(), CodeGenUIPlugin.getBundleString("generatecode.err"), getRunStatus()); //$NON-NLS-1$
+ } else if (myRunStatus.matches(IStatus.WARNING)) {
+ ErrorDialog.openError(getShell(), getName(), CodeGenUIPlugin.getBundleString("generatecode.warn"), getRunStatus()); //$NON-NLS-1$
+ } else if (myRunStatus.matches(IStatus.INFO)) {
+ ErrorDialog.openError(getShell(), getName(), CodeGenUIPlugin.getBundleString("generatecode.info"), getRunStatus()); //$NON-NLS-1$
+ }
+ } catch (InterruptedException ex) {
+ // presumably, user canceled the operation, don't bother him with additional messages
+ } finally {
+ unloadGenModel();
+ }
+ }
+
+ /**
+ * 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) {
+ 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(), getName(), 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 {
+ myRunStatus = Status.CANCEL_STATUS;
+ try {
+ new ProgressMonitorDialog(getShell()).run(true, true, this);
+ } catch (InvocationTargetException ex) {
+ Throwable targetException = ex.getTargetException();
+ if (targetException instanceof CoreException) {
+ myRunStatus = ((CoreException) targetException).getStatus();
+ } else {
+ myRunStatus = new Status(IStatus.ERROR, CodeGenUIPlugin.getPluginID(), 0, "Exception occurred while generating code", targetException);
+ }
+ }
+ }
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ Generator g = new Generator(getGenModel(), CodeGenUIPlugin.getDefault().getEmitters(getGenModel()));
+ g.run(monitor);
+ myRunStatus = g.getRunStatus();
+ }
+
+ private IStatus getRunStatus() {
+ return myRunStatus;
+ }
+
+ protected final GenEditorGenerator getGenModel() {
+ return myGenModel;
+ }
+
+ private IStatus loadGenModel() {
+ ResourceSet srcResSet = new ResourceSetImpl();
+ ModelLoadHelper loadHelper = new ModelLoadHelper(srcResSet, getGenModelURI());
+ Object root = loadHelper.getContentsRoot();
+ if (root instanceof GenDiagram) {
+ myGenModel = ((GenDiagram) root).getEditorGen();
+ } else if (root instanceof GenEditorGenerator) {
+ myGenModel = (GenEditorGenerator) root;
+ }
+ if (myGenModel != null && myGenModel.getDomainGenModel() != null) {
+ myGenModel.getDomainGenModel().reconcile();
+ }
+ return loadHelper.getStatus();
+ }
+
+ private void unloadGenModel() {
+ if (myGenModel != null && myGenModel.eResource() != null) {
+ myGenModel.eResource().unload();
+ }
+ myGenModel = null;
+ }
+
+ private IStatus validateGenModel() {
+ return BasicDiagnostic.toIStatus(Diagnostician.INSTANCE.validate(getGenModel()));
+ }
+
+ private static IPreferenceStore getPreferences() {
+ return CodeGenUIPlugin.getDefault().getPreferenceStore();
+ }
+}
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 bf8c1a33b..97987f848 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
@@ -11,90 +11,40 @@
*/
package org.eclipse.gmf.internal.codegen.popup.actions;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
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.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
-import org.eclipse.emf.common.util.BasicDiagnostic;
-import org.eclipse.emf.common.util.Diagnostic;
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.xmi.XMIResource;
-import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
-import org.eclipse.gmf.gmfgraph.util.RuntimeFQNSwitch;
-import org.eclipse.gmf.graphdef.codegen.MapModeCodeGenStrategy;
-import org.eclipse.gmf.internal.bridge.VisualIdentifierDispenser;
-import org.eclipse.gmf.internal.bridge.genmodel.BasicDiagramRunTimeModelHelper;
-import org.eclipse.gmf.internal.bridge.genmodel.DiagramGenModelTransformer;
-import org.eclipse.gmf.internal.bridge.genmodel.DiagramRunTimeModelHelper;
-import org.eclipse.gmf.internal.bridge.genmodel.GenModelProducer;
-import org.eclipse.gmf.internal.bridge.genmodel.InnerClassViewmapProducer;
-import org.eclipse.gmf.internal.bridge.genmodel.SpecificDiagramRunTimeModelHelper;
-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;
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.dialogs.MessageDialogWithToggle;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.preference.IPreferenceStore;
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 org.eclipse.ui.progress.IProgressService;
/**
* .gmfmap to .gmfgen
+ *
* @author artem
*/
public class TransformToGenModel implements IObjectActionDelegate {
- private static final String ASK_WARN = "ask_warn";
- private IFile myMapFile;
private IWorkbenchPart myPart;
- private IFile myDestFile;
- private static final Boolean THERE_IS_NO_SPECIFIC_RT = Boolean.TRUE;
- private ResourceSet myResourceSet;
+ private IFile myMapFile;
+
+ private IFile myDestFile;
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
myPart = targetPart;
}
- protected ResourceSet getResourceSet() {
- if (myResourceSet == null) {
- myResourceSet = new ResourceSetImpl();
- }
- return myResourceSet;
- }
-
- protected void forgetResourceSet() {
- myResourceSet = null;
+ public void selectionChanged(IAction action, ISelection selection) {
+ myMapFile = (IFile) ((IStructuredSelection) selection).getFirstElement();
}
public void run(IAction action) {
@@ -102,284 +52,23 @@ public class TransformToGenModel implements IObjectActionDelegate {
if (myDestFile == null) {
return;
}
- ModelLoadHelper loadHelper = new ModelLoadHelper(getResourceSet(), getMapModelURI());
- if(!canProcessMappingModel(loadHelper, action)) {
- return;
- }
-
- final Mapping mapping = (Mapping) loadHelper.getContentsRoot();
- IStatus mapIsValid = validate(mapping);
- if (mapIsValid.matches(IStatus.CANCEL)) {
- return;
- }
- if (mapIsValid.matches(IStatus.ERROR)) {
- final String[] buttons = new String[] {IDialogConstants.PROCEED_LABEL, IDialogConstants.CANCEL_LABEL };
- final int[] buttonIDs = new int[] {IDialogConstants.PROCEED_ID, IDialogConstants.CANCEL_ID };
- final String msg = CodeGenUIPlugin.getBundleString("transform.err");
- ErrorDialogEx dlg = new ErrorDialogEx(getShell(), action.getText(), msg, mapIsValid, buttons, buttonIDs, 0);
- if (dlg.open() == IDialogConstants.CANCEL_ID) {
- return;
- }
- } else if ((mapIsValid.matches(IStatus.INFO | IStatus.WARNING))) {
- if (!MessageDialogWithToggle.ALWAYS.equals(getPreferences().getString(ASK_WARN))) {
- if (MessageDialogWithToggle.OK != MessageDialogWithToggle.openOkCancelConfirm(getShell(), action.getText(), CodeGenUIPlugin.getBundleString("transform.warn"), CodeGenUIPlugin.getBundleString("transform.neverwarn"), false, getPreferences(), ASK_WARN).getReturnCode()) {
- return;
- }
- }
- }
-
- final GenModelDetector gmDetector = new GenModelDetector(myMapFile);
- final IStatus findStatus = gmDetector.find(getShell(), mapping);
- if (findStatus.getSeverity() == IStatus.CANCEL) {
- return;
- }
- GenModel domainGenModel = null;
- if (findStatus.isOK()) {
- domainGenModel = gmDetector.get(getResourceSet());
- }
-
- if (domainGenModel != null) {
- StaleGenModelDetector staleDetector = new StaleGenModelDetector(domainGenModel);
- if (staleDetector.isStale()) {
- if (staleDetector.queryUser(getShell()).getSeverity() == IStatus.CANCEL) {
- return;
- }
- domainGenModel = staleDetector.refresh();
- }
- }
-
- final DiagramRunTimeModelHelper drtModelHelper = detectRunTimeModel();
-
- final ViewmapProducer viewmapProducer = detectViewmapProducer(getShell());
- if (viewmapProducer == null) {
- return;
- }
-
- final VisualIdentifierDispenserProvider idDispenser = getVisualIdDispenser();
- idDispenser.acquire();
-
- GenModelProducer t = createGenModelProducer(domainGenModel, drtModelHelper, viewmapProducer, idDispenser.get());
-
- final Job transformJob = createTransformJob(mapping, action.getText(), t);
- transformJob.schedule();
- try {
- transformJob.join();
- if (transformJob.getResult().getSeverity() != IStatus.CANCEL) {
- idDispenser.release();
- }
- } catch (InterruptedException ex) {
- }
- forgetResourceSet();
- }
-
- /**
- * Job should not be async
- */
- private Job createTransformJob(final Mapping mapping, String title, final GenModelProducer t) {
- //final ISchedulingRule rule = MultiRule.combine(myMapFile, myDestFile);
- return new Job(title) {
- {
- setUser(true);
- setPriority(SHORT);
- //setRule(rule); // <crmcsi$8mi$1@www.eclipse.org>
- }
-
- protected IStatus run(IProgressMonitor monitor) {
- monitor.beginTask(getName(), 4);
- try {
- GenEditorGenerator genEditor = t.process(mapping, new SubProgressMonitor(monitor, 1));
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
-
- if (CodeGenUIPlugin.needsReconcile()) {
- reconcile(genEditor);
- }
- monitor.worked(1);
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
-
- save(genEditor);
- monitor.worked(1);
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
-
- return validate(genEditor);
- } catch (IOException ex) {
- return CodeGenUIPlugin.createError(ex.getMessage(), ex);
- } catch (IllegalArgumentException ex) {
- return CodeGenUIPlugin.createError(ex.getMessage(), ex);
- } finally {
- monitor.done();
- }
- }
-
- private IStatus validate(GenEditorGenerator genBurdern) {
- Diagnostic d = ValidationHelper.validate(genBurdern, true);
- if (d.getSeverity() == Diagnostic.OK) {
- return Status.OK_STATUS;
- }
- if ((d.getSeverity() & Diagnostic.CANCEL) != 0) {
- return Status.CANCEL_STATUS;
- } else {
- return BasicDiagnostic.toIStatus(d);
- }
- }
- @SuppressWarnings("unchecked")
- private void save(GenEditorGenerator genBurdern) throws IOException {
- Resource dgmmRes = getResourceSet().createResource(getGenModelURI());
- dgmmRes.getContents().add(genBurdern);
- dgmmRes.save(getSaveOptions());
- }
- protected Map getSaveOptions() {
- HashMap<String, Object> saveOptions = new HashMap<String, Object>();
- saveOptions.put(XMIResource.OPTION_ENCODING, "UTF-8");
- return saveOptions;
- }
- private void reconcile(GenEditorGenerator genBurdern) {
- GenEditorGenerator old = null;
- Resource resource = null;
- try {
- resource = getResourceSet().getResource(getGenModelURI(), true);
- List contents = resource.getContents();
- if (!contents.isEmpty() && contents.get(0) instanceof GenEditorGenerator){
- old = (GenEditorGenerator)contents.get(0);
- }
- if (old != null){
- new Reconciler(new GMFGenConfig()).reconcileTree(genBurdern, old);
- }
- } catch (RuntimeException e){
- old = null;
- } finally {
- if (resource != null){
- resource.unload();
- }
- }
- }
- };
- }
-
- private GenModelProducer createGenModelProducer(GenModel domainGenModel, final DiagramRunTimeModelHelper drtModelHelper, final ViewmapProducer viewmapProducer, final VisualIdentifierDispenser idDespenser) {
- final DiagramGenModelTransformer t = new DiagramGenModelTransformer(drtModelHelper, new GenModelNamingMediatorImpl(), viewmapProducer, idDespenser);
- if (domainGenModel != null) {
- t.setEMFGenModel(domainGenModel);
- }
- return new GenModelProducer() {
- public GenEditorGenerator process(Mapping mapping, IProgressMonitor progress) {
- progress.beginTask(null, 1);
- try {
- t.transform(mapping);
- return t.getResult();
- } finally {
- progress.done();
- }
- }
- };
- }
-
- /**
- * 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 VisualIdentifierDispenserProvider getVisualIdDispenser() {
- return new VisualIdentifierDispenserProvider(getGenModelURI());
- }
-
- private ViewmapProducer detectViewmapProducer(Shell shell) {
- if (!checkLiteOptionPresent()) {
- MapModeCodeGenStrategy strategy;
- final String msg = "Would you like to use IMapMode?";
- if (MessageDialog.openQuestion(shell, "Create Generator Model", msg)) {
- strategy = new MapModeCodeGenStrategy.RuntimeUnspecifiedMapMode();
- } else {
- strategy = new MapModeCodeGenStrategy.StaticIdentityMapMode();
- }
- return new InnerClassViewmapProducer(new RuntimeFQNSwitch(), strategy);
- }
- FigureGeneratorOptionsDialog dlg = new FigureGeneratorOptionsDialog(shell, "Create Generator Model", true, true);
- if (dlg.open() != IDialogConstants.OK_ID) {
- return null;
- }
- return new InnerClassViewmapProducer(dlg.getFigureQualifiedNameSwitch(), dlg.getMapModeCodeGenStrategy());
- }
-
- private static boolean checkLiteOptionPresent() {
- return Platform.getBundle("org.eclipse.gmf.codegen.lite") != null;
- }
-
- private DiagramRunTimeModelHelper detectRunTimeModel() {
- DiagramRunTimeModelHelper drtModelHelper = null;
- URI specificRTGenModelURI = decideOnRunTimeModel();
- if (specificRTGenModelURI != null) {
- Resource drtGenModelRes = getResourceSet().getResource(specificRTGenModelURI, true);
- if (drtGenModelRes != null) {
- GenModel drtGenModel = (GenModel) drtGenModelRes.getContents().get(0);
- drtModelHelper = new SpecificDiagramRunTimeModelHelper(drtGenModel);
- }
- }
- if (drtModelHelper == null) {
- drtModelHelper = new BasicDiagramRunTimeModelHelper();
- }
- return drtModelHelper;
- }
-
- private IStatus validate(final Mapping mapping) {
- IProgressService progressService = myPart.getSite().getWorkbenchWindow().getWorkbench().getProgressService();
- final Diagnostic[] result = new Diagnostic[1];
- try {
- progressService.run(false, true, new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- result[0] = ValidationHelper.validate(mapping, true, monitor);
- monitor.done();
- }
- });
- if (result[0] == null) {
- return Status.CANCEL_STATUS;
- }
- return BasicDiagnostic.toIStatus(result[0]);
- } catch (InvocationTargetException ex) {
- return Status.CANCEL_STATUS;
- } catch (InterruptedException ex) {
- return Status.CANCEL_STATUS;
- }
- }
-
- public void selectionChanged(IAction action, ISelection selection) {
- myMapFile = (IFile) ((IStructuredSelection) selection).getFirstElement();
+ TransformToGenModelOperation op = new TransformToGenModelOperation();
+ op.setName(action.getText());
+ op.setShell(getShell());
+ op.setMapModelURI(URI.createPlatformResourceURI(myMapFile.getFullPath().toString()));
+ op.setGenModelURI(URI.createPlatformResourceURI(myDestFile.getFullPath().toString()));
+ op.setUseRuntimeFigures(Boolean.TRUE);
+ op.setUseMapMode(Boolean.TRUE);
+ op.run();
}
private void initDestinationFile() {
myDestFile = null;
- final IPath destPath = myMapFile.getFullPath().removeFileExtension().addFileExtension("gmfgen");
+ final IPath destPath = myMapFile.getFullPath().removeFileExtension().addFileExtension("gmfgen"); //$NON-NLS-1$
final IPath destLocation = destPath.removeLastSegments(1);
final String defFileName = destPath.lastSegment();
InputDialog dlg = new InputDialog(getShell(), "Target model file", "Please specify name of the file to save diagram genmodel to", defFileName, new IInputValidator() {
+
public String isValid(String newText) {
IStatus s = ResourcesPlugin.getWorkspace().validatePath(destLocation.append(newText).toOSString(), IResource.FILE);
return s.isOK() ? null : s.getMessage();
@@ -395,32 +84,7 @@ public class TransformToGenModel implements IObjectActionDelegate {
return myDestFile;
}
- URI getMapModelURI() {
- return URI.createPlatformResourceURI(myMapFile.getFullPath().toString());
- }
-
- URI getGenModelURI() {
- return URI.createPlatformResourceURI(myDestFile.getFullPath().toString());
- }
-
private Shell getShell() {
return myPart.getSite().getShell();
}
-
- private URI decideOnRunTimeModel() {
- if (THERE_IS_NO_SPECIFIC_RT.booleanValue()) {
- return null;
- }
- IPath p = myMapFile.getFullPath();
- String defValue = p.removeLastSegments(1).append(p.removeFileExtension().lastSegment() + "-drt").addFileExtension("genmodel").toString();
- InputDialog dlg = new InputDialog(getShell(), "Diagram RunTime Model", "Please specify path to genmodel file that describes specific diagram runtime model, or press Cancel if you don't need one", defValue, null);
- if (dlg.open() == InputDialog.OK) {
- return URI.createPlatformResourceURI(dlg.getValue());
- }
- return null;
- }
-
- private static IPreferenceStore getPreferences() {
- return CodeGenUIPlugin.getDefault().getPreferenceStore();
- }
}
diff --git a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/TransformToGenModelOperation.java b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/TransformToGenModelOperation.java
new file mode 100644
index 000000000..68fdceb2e
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/TransformToGenModelOperation.java
@@ -0,0 +1,455 @@
+/*
+ * Copyright (c) 2006 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.internal.codegen.popup.actions;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.Diagnostic;
+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.xmi.XMIResource;
+import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
+import org.eclipse.gmf.gmfgraph.util.FigureQualifiedNameSwitch;
+import org.eclipse.gmf.gmfgraph.util.RuntimeFQNSwitch;
+import org.eclipse.gmf.gmfgraph.util.RuntimeLiteFQNSwitch;
+import org.eclipse.gmf.graphdef.codegen.MapModeCodeGenStrategy;
+import org.eclipse.gmf.internal.bridge.VisualIdentifierDispenser;
+import org.eclipse.gmf.internal.bridge.genmodel.BasicDiagramRunTimeModelHelper;
+import org.eclipse.gmf.internal.bridge.genmodel.DiagramGenModelTransformer;
+import org.eclipse.gmf.internal.bridge.genmodel.DiagramRunTimeModelHelper;
+import org.eclipse.gmf.internal.bridge.genmodel.GenModelProducer;
+import org.eclipse.gmf.internal.bridge.genmodel.InnerClassViewmapProducer;
+import org.eclipse.gmf.internal.bridge.genmodel.SpecificDiagramRunTimeModelHelper;
+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.URIUtil;
+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;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.progress.IProgressService;
+
+/**
+ * @author dstadnik
+ */
+public class TransformToGenModelOperation {
+
+ private static final String ASK_WARN = "ask_warn"; //$NON-NLS-1$
+
+ private static final Boolean THERE_IS_NO_SPECIFIC_RT = Boolean.TRUE;
+
+ private String name;
+
+ private Shell shell;
+
+ private URI mapModelURI;
+
+ private URI genModelURI;
+
+ private Boolean useRuntimeFigures;
+
+ private Boolean useMapMode;
+
+ private ResourceSet myResourceSet;
+
+ public String getName() {
+ if (name == null) {
+ return "Transform Model"; //$NON-NLS-1$
+ }
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Shell getShell() {
+ if (shell == null) {
+ return Display.getDefault().getActiveShell();
+ }
+ return shell;
+ }
+
+ public void setShell(Shell shell) {
+ this.shell = shell;
+ }
+
+ public URI getMapModelURI() {
+ return mapModelURI;
+ }
+
+ public void setMapModelURI(URI uri) {
+ mapModelURI = uri;
+ }
+
+ public URI getGenModelURI() {
+ return genModelURI;
+ }
+
+ public void setGenModelURI(URI uri) {
+ genModelURI = uri;
+ }
+
+ public Boolean getUseMapMode() {
+ return useMapMode;
+ }
+
+ public void setUseMapMode(Boolean useMapMode) {
+ this.useMapMode = useMapMode;
+ }
+
+ public Boolean getUseRuntimeFigures() {
+ return useRuntimeFigures;
+ }
+
+ public void setUseRuntimeFigures(Boolean useRuntimeFigures) {
+ this.useRuntimeFigures = useRuntimeFigures;
+ }
+
+ protected ResourceSet getResourceSet() {
+ if (myResourceSet == null) {
+ myResourceSet = new ResourceSetImpl();
+ }
+ return myResourceSet;
+ }
+
+ protected void forgetResourceSet() {
+ myResourceSet = null;
+ }
+
+ public void run() {
+ ModelLoadHelper loadHelper = new ModelLoadHelper(getResourceSet(), getMapModelURI());
+ if (!canProcessMappingModel(loadHelper)) {
+ return;
+ }
+
+ final Mapping mapping = (Mapping) loadHelper.getContentsRoot();
+ IStatus mapIsValid = validate(mapping);
+ if (mapIsValid.matches(IStatus.CANCEL)) {
+ return;
+ }
+ if (mapIsValid.matches(IStatus.ERROR)) {
+ final String[] buttons = new String[] { IDialogConstants.PROCEED_LABEL, IDialogConstants.CANCEL_LABEL };
+ final int[] buttonIDs = new int[] { IDialogConstants.PROCEED_ID, IDialogConstants.CANCEL_ID };
+ final String msg = CodeGenUIPlugin.getBundleString("transform.err"); //$NON-NLS-1$
+ ErrorDialogEx dlg = new ErrorDialogEx(getShell(), getName(), msg, mapIsValid, buttons, buttonIDs, 0);
+ if (dlg.open() == IDialogConstants.CANCEL_ID) {
+ return;
+ }
+ } else if ((mapIsValid.matches(IStatus.INFO | IStatus.WARNING))) {
+ if (!MessageDialogWithToggle.ALWAYS.equals(getPreferences().getString(ASK_WARN))) {
+ String warn = CodeGenUIPlugin.getBundleString("transform.warn"); //$NON-NLS-1$
+ String nwarn = CodeGenUIPlugin.getBundleString("transform.neverwarn"); //$NON-NLS-1$
+ if (MessageDialogWithToggle.OK != MessageDialogWithToggle.openOkCancelConfirm(getShell(), getName(), warn, nwarn, false, getPreferences(), ASK_WARN).getReturnCode()) {
+ return;
+ }
+ }
+ }
+
+ IFile mapFile = URIUtil.getFile(getMapModelURI());
+ if (mapFile == null) {
+ // TODO : GenModelDetector should work without file handle
+ return;
+ }
+ final GenModelDetector gmDetector = new GenModelDetector(mapFile);
+ final IStatus findStatus = gmDetector.find(getShell(), mapping);
+ if (findStatus.getSeverity() == IStatus.CANCEL) {
+ return;
+ }
+ GenModel domainGenModel = null;
+ if (findStatus.isOK()) {
+ domainGenModel = gmDetector.get(getResourceSet());
+ }
+
+ if (domainGenModel != null) {
+ StaleGenModelDetector staleDetector = new StaleGenModelDetector(domainGenModel);
+ if (staleDetector.isStale()) {
+ if (staleDetector.queryUser(getShell()).getSeverity() == IStatus.CANCEL) {
+ return;
+ }
+ domainGenModel = staleDetector.refresh();
+ }
+ }
+
+ final DiagramRunTimeModelHelper drtModelHelper = detectRunTimeModel();
+
+ final ViewmapProducer viewmapProducer = detectViewmapProducer(getShell());
+ if (viewmapProducer == null) {
+ return;
+ }
+
+ final VisualIdentifierDispenserProvider idDispenser = getVisualIdDispenser();
+ idDispenser.acquire();
+
+ GenModelProducer t = createGenModelProducer(domainGenModel, drtModelHelper, viewmapProducer, idDispenser.get());
+
+ final Job transformJob = createTransformJob(mapping, getName(), t);
+ transformJob.schedule();
+ try {
+ transformJob.join();
+ if (transformJob.getResult().getSeverity() != IStatus.CANCEL) {
+ idDispenser.release();
+ }
+ } catch (InterruptedException ex) {
+ }
+ forgetResourceSet();
+ }
+
+ /**
+ * Job should not be async
+ */
+ private Job createTransformJob(final Mapping mapping, String title, final GenModelProducer t) {
+ // final ISchedulingRule rule = MultiRule.combine(myMapFile, myDestFile);
+ return new Job(title) {
+
+ {
+ setUser(true);
+ setPriority(SHORT);
+ // setRule(rule); // <crmcsi$8mi$1@www.eclipse.org>
+ }
+
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask(getName(), 4);
+ try {
+ GenEditorGenerator genEditor = t.process(mapping, new SubProgressMonitor(monitor, 1));
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ if (CodeGenUIPlugin.needsReconcile()) {
+ reconcile(genEditor);
+ }
+ monitor.worked(1);
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ save(genEditor);
+ monitor.worked(1);
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ return validate(genEditor);
+ } catch (IOException ex) {
+ return CodeGenUIPlugin.createError(ex.getMessage(), ex);
+ } catch (IllegalArgumentException ex) {
+ return CodeGenUIPlugin.createError(ex.getMessage(), ex);
+ } finally {
+ monitor.done();
+ }
+ }
+
+ private IStatus validate(GenEditorGenerator genBurdern) {
+ Diagnostic d = ValidationHelper.validate(genBurdern, true);
+ if (d.getSeverity() == Diagnostic.OK) {
+ return Status.OK_STATUS;
+ }
+ if ((d.getSeverity() & Diagnostic.CANCEL) != 0) {
+ return Status.CANCEL_STATUS;
+ } else {
+ return BasicDiagnostic.toIStatus(d);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void save(GenEditorGenerator genBurdern) throws IOException {
+ Resource dgmmRes = getResourceSet().createResource(getGenModelURI());
+ dgmmRes.getContents().add(genBurdern);
+ dgmmRes.save(getSaveOptions());
+ }
+
+ protected Map getSaveOptions() {
+ HashMap<String, Object> saveOptions = new HashMap<String, Object>();
+ saveOptions.put(XMIResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
+ return saveOptions;
+ }
+
+ private void reconcile(GenEditorGenerator genBurdern) {
+ GenEditorGenerator old = null;
+ Resource resource = null;
+ try {
+ resource = getResourceSet().getResource(getGenModelURI(), true);
+ List contents = resource.getContents();
+ if (!contents.isEmpty() && contents.get(0) instanceof GenEditorGenerator) {
+ old = (GenEditorGenerator) contents.get(0);
+ }
+ if (old != null) {
+ new Reconciler(new GMFGenConfig()).reconcileTree(genBurdern, old);
+ }
+ } catch (RuntimeException e) {
+ old = null;
+ } finally {
+ if (resource != null) {
+ resource.unload();
+ }
+ }
+ }
+ };
+ }
+
+ private GenModelProducer createGenModelProducer(GenModel domainGenModel, final DiagramRunTimeModelHelper drtModelHelper, final ViewmapProducer viewmapProducer, final VisualIdentifierDispenser idDespenser) {
+ final DiagramGenModelTransformer t = new DiagramGenModelTransformer(drtModelHelper, new GenModelNamingMediatorImpl(), viewmapProducer, idDespenser);
+ if (domainGenModel != null) {
+ t.setEMFGenModel(domainGenModel);
+ }
+ return new GenModelProducer() {
+
+ public GenEditorGenerator process(Mapping mapping, IProgressMonitor progress) {
+ progress.beginTask(null, 1);
+ try {
+ t.transform(mapping);
+ return t.getResult();
+ } finally {
+ progress.done();
+ }
+ }
+ };
+ }
+
+ /**
+ * 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) {
+ 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(), getName(), CodeGenUIPlugin.getBundleString("transform.err"), loadHelper.getStatus(), buttons, buttonIDs, 0); //$NON-NLS-1$
+ if (dlg.open() == IDialogConstants.CANCEL_ID) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private VisualIdentifierDispenserProvider getVisualIdDispenser() {
+ return new VisualIdentifierDispenserProvider(getGenModelURI());
+ }
+
+ private ViewmapProducer detectViewmapProducer(Shell shell) {
+ if (getUseRuntimeFigures() != null && getUseMapMode() != null) {
+ // allow to run without dialogs
+ FigureQualifiedNameSwitch fSwitch = getUseRuntimeFigures().booleanValue() ? new RuntimeFQNSwitch() : new RuntimeLiteFQNSwitch();
+ MapModeCodeGenStrategy mmStrategy = getUseMapMode().booleanValue() ? new MapModeCodeGenStrategy.RuntimeUnspecifiedMapMode() : new MapModeCodeGenStrategy.StaticIdentityMapMode();
+ return new InnerClassViewmapProducer(fSwitch, mmStrategy);
+ }
+ if (!checkLiteOptionPresent()) {
+ MapModeCodeGenStrategy strategy;
+ final String msg = "Would you like to use IMapMode?";
+ if (MessageDialog.openQuestion(shell, "Create Generator Model", msg)) {
+ strategy = new MapModeCodeGenStrategy.RuntimeUnspecifiedMapMode();
+ } else {
+ strategy = new MapModeCodeGenStrategy.StaticIdentityMapMode();
+ }
+ return new InnerClassViewmapProducer(new RuntimeFQNSwitch(), strategy);
+ }
+ FigureGeneratorOptionsDialog dlg = new FigureGeneratorOptionsDialog(shell, "Create Generator Model", getUseRuntimeFigures() == null ? true : getUseRuntimeFigures().booleanValue(), getUseMapMode() == null ? true : getUseMapMode().booleanValue());
+ if (dlg.open() != IDialogConstants.OK_ID) {
+ return null;
+ }
+ return new InnerClassViewmapProducer(dlg.getFigureQualifiedNameSwitch(), dlg.getMapModeCodeGenStrategy());
+ }
+
+ private static boolean checkLiteOptionPresent() {
+ return Platform.getBundle("org.eclipse.gmf.codegen.lite") != null; //$NON-NLS-1$
+ }
+
+ private DiagramRunTimeModelHelper detectRunTimeModel() {
+ DiagramRunTimeModelHelper drtModelHelper = null;
+ URI specificRTGenModelURI = decideOnRunTimeModel();
+ if (specificRTGenModelURI != null) {
+ Resource drtGenModelRes = getResourceSet().getResource(specificRTGenModelURI, true);
+ if (drtGenModelRes != null) {
+ GenModel drtGenModel = (GenModel) drtGenModelRes.getContents().get(0);
+ drtModelHelper = new SpecificDiagramRunTimeModelHelper(drtGenModel);
+ }
+ }
+ if (drtModelHelper == null) {
+ drtModelHelper = new BasicDiagramRunTimeModelHelper();
+ }
+ return drtModelHelper;
+ }
+
+ private IStatus validate(final Mapping mapping) {
+ IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
+ final Diagnostic[] result = new Diagnostic[1];
+ try {
+ progressService.run(false, true, new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ result[0] = ValidationHelper.validate(mapping, true, monitor);
+ monitor.done();
+ }
+ });
+ if (result[0] == null) {
+ return Status.CANCEL_STATUS;
+ }
+ return BasicDiagnostic.toIStatus(result[0]);
+ } catch (InvocationTargetException ex) {
+ return Status.CANCEL_STATUS;
+ } catch (InterruptedException ex) {
+ return Status.CANCEL_STATUS;
+ }
+ }
+
+ private URI decideOnRunTimeModel() {
+ if (THERE_IS_NO_SPECIFIC_RT.booleanValue()) {
+ return null;
+ }
+ // IPath p = myMapFile.getFullPath();
+ // String defValue = p.removeLastSegments(1).append(p.removeFileExtension().lastSegment() + "-drt").addFileExtension("genmodel").toString();
+ InputDialog dlg = new InputDialog(getShell(), "Diagram RunTime Model", "Please specify path to genmodel file that describes specific diagram runtime model, or press Cancel if you don't need one", null, null);
+ if (dlg.open() == InputDialog.OK) {
+ return URI.createPlatformResourceURI(dlg.getValue());
+ }
+ return null;
+ }
+
+ private static IPreferenceStore getPreferences() {
+ return CodeGenUIPlugin.getDefault().getPreferenceStore();
+ }
+}
diff --git a/plugins/org.eclipse.gmf.common/META-INF/MANIFEST.MF b/plugins/org.eclipse.gmf.common/META-INF/MANIFEST.MF
index d746ebcac..279e04a1d 100644
--- a/plugins/org.eclipse.gmf.common/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.gmf.common/META-INF/MANIFEST.MF
@@ -7,7 +7,7 @@ Bundle-Localization: plugin
Export-Package: org.eclipse.gmf.common,
org.eclipse.gmf.common.codegen,
org.eclipse.gmf.internal.codegen.dispatch;x-friends:="org.eclipse.gmf.codegen,org.eclipse.gmf.graphdef.codegen,org.eclipse.gmf.codegen.lite",
- org.eclipse.gmf.internal.common;x-friends:="org.eclipse.gmf.codegen.edit,org.eclipse.gmf.graphdef.edit,org.eclipse.gmf.map.edit,org.eclipse.gmf.tooldef.edit,org.eclipse.gmf.bridge.trace,org.eclipse.gmf.bridge.ui,org.eclipse.gmf.bridge,org.eclipse.gmf.tests",
+ org.eclipse.gmf.internal.common;x-friends:="org.eclipse.gmf.codegen.edit,org.eclipse.gmf.graphdef.edit,org.eclipse.gmf.map.edit,org.eclipse.gmf.tooldef.edit,org.eclipse.gmf.bridge.trace,org.eclipse.gmf.bridge.ui,org.eclipse.gmf.bridge,org.eclipse.gmf.tests,org.eclipse.gmf.bridge.ui.dashboard,org.eclipse.gmf.codegen.ui,org.eclipse.gmf.codegen.lite.ui",
org.eclipse.gmf.internal.common.codegen;x-friends:="org.eclipse.gmf.codegen,org.eclipse.gmf.graphdef.codegen,org.eclipse.gmf.bridge,org.eclipse.gmf.codegen.lite,org.eclipse.gmf.tests,org.eclipse.gmf.codegen.ui,org.eclipse.gmf.codegen.lite.ui,org.eclipse.gmf.tests.lite,org.eclipse.gmf.graphdef.codegen.ui",
org.eclipse.gmf.internal.common.migrate;x-friends:="org.eclipse.gmf.codegen.ui,org.eclipse.gmf.tests,org.eclipse.gmf.codegen,org.eclipse.gmf.map",
org.eclipse.gmf.internal.common.reconcile;x-friends:="org.eclipse.gmf.codegen.ui,org.eclipse.gmf.tests",
diff --git a/plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/URIUtil.java b/plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/URIUtil.java
new file mode 100644
index 000000000..88c06a1b6
--- /dev/null
+++ b/plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/URIUtil.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2006 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.internal.common;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+
+/**
+ * @author dstadnik
+ */
+public class URIUtil {
+
+ private URIUtil() {
+ }
+
+ public static IFile getFile(URI uri) {
+ if (uri.toString().startsWith("platform:/resource")) { //$NON-NLS-1$
+ String path = uri.toString().substring("platform:/resource".length()); //$NON-NLS-1$
+ IResource workspaceResource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(path));
+ if (workspaceResource instanceof IFile) {
+ return (IFile) workspaceResource;
+ }
+ }
+ return null;
+ }
+}

Back to the top