Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 56787 Details for
Bug 148836
Create "Create generator model..." wizard instead of existing dialog
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
wizard implementation
patch.txt (text/plain), 112.25 KB, created by
Alexander Fedorov
on 2007-01-11 12:18:54 EST
(
hide
)
Description:
wizard implementation
Filename:
MIME Type:
Creator:
Alexander Fedorov
Created:
2007-01-11 12:18:54 EST
Size:
112.25 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.gmf.codegen.edit >Index: src/org/eclipse/gmf/codegen/gmfgen/presentation/GMFGenModelWizard.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.codegen.edit/src/org/eclipse/gmf/codegen/gmfgen/presentation/GMFGenModelWizard.java,v >retrieving revision 1.5 >diff -u -r1.5 GMFGenModelWizard.java >--- src/org/eclipse/gmf/codegen/gmfgen/presentation/GMFGenModelWizard.java 5 Dec 2005 19:45:00 -0000 1.5 >+++ src/org/eclipse/gmf/codegen/gmfgen/presentation/GMFGenModelWizard.java 11 Jan 2007 17:08:49 -0000 >@@ -7,15 +7,8 @@ > package org.eclipse.gmf.codegen.gmfgen.presentation; > > >-import java.util.ArrayList; >-import java.util.Collection; >-import java.util.Collections; > import java.util.HashMap; >-import java.util.Iterator; >-import java.util.List; > import java.util.Map; >-import java.util.MissingResourceException; >-import java.util.StringTokenizer; > > import org.eclipse.core.resources.IContainer; > import org.eclipse.core.resources.IFile; >@@ -26,33 +19,18 @@ > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.Path; > import org.eclipse.emf.common.util.URI; >-import org.eclipse.emf.ecore.EClass; >-import org.eclipse.emf.ecore.EClassifier; > import org.eclipse.emf.ecore.EObject; > import org.eclipse.emf.ecore.resource.Resource; > import org.eclipse.emf.ecore.resource.ResourceSet; > import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; > import org.eclipse.emf.ecore.xmi.XMLResource; > import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry; >-import org.eclipse.gmf.codegen.gmfgen.GMFGenFactory; > import org.eclipse.gmf.codegen.gmfgen.GMFGenPackage; >-import org.eclipse.gmf.codegen.gmfgen.presentation.EditorPlugin; >- >- > import org.eclipse.jface.dialogs.MessageDialog; > import org.eclipse.jface.viewers.ISelection; > import org.eclipse.jface.viewers.IStructuredSelection; > import org.eclipse.jface.viewers.StructuredSelection; > import org.eclipse.jface.wizard.Wizard; >-import org.eclipse.jface.wizard.WizardPage; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.ModifyEvent; >-import org.eclipse.swt.events.ModifyListener; >-import org.eclipse.swt.layout.GridData; >-import org.eclipse.swt.layout.GridLayout; >-import org.eclipse.swt.widgets.Combo; >-import org.eclipse.swt.widgets.Composite; >-import org.eclipse.swt.widgets.Label; > import org.eclipse.ui.INewWizard; > import org.eclipse.ui.IWorkbench; > import org.eclipse.ui.IWorkbenchPage; >@@ -69,26 +47,10 @@ > * This is a simple wizard for creating a new model file. > * <!-- begin-user-doc --> > * <!-- end-user-doc --> >- * @generated >+ * @generated NOT > */ > public class GMFGenModelWizard extends Wizard implements INewWizard { > /** >- * This caches an instance of the model package. >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- protected GMFGenPackage gmfGenPackage = GMFGenPackage.eINSTANCE; >- >- /** >- * This caches an instance of the model factory. >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- protected GMFGenFactory gmfGenFactory = gmfGenPackage.getGMFGenFactory(); >- >- /** > * This is the file creation page. > * <!-- begin-user-doc --> > * <!-- end-user-doc --> >@@ -97,14 +59,6 @@ > protected GMFGenModelWizardNewFileCreationPage newFileCreationPage; > > /** >- * This is the initial object creation page. >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- protected GMFGenModelWizardInitialObjectCreationPage initialObjectCreationPage; >- >- /** > * Remember the selection during initialization for populating the default container. > * <!-- begin-user-doc --> > * <!-- end-user-doc --> >@@ -121,14 +75,6 @@ > protected IWorkbench workbench; > > /** >- * Caches the names of the types that can be created as the root object. >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- protected List initialObjectNames; >- >- /** > * This just records the information. > * <!-- begin-user-doc --> > * <!-- end-user-doc --> >@@ -142,122 +88,26 @@ > } > > /** >- * Returns the names of the types that can be created as the root object. >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- protected Collection getInitialObjectNames() { >- if (initialObjectNames == null) { >- initialObjectNames = new ArrayList(); >- for (Iterator classifiers = gmfGenPackage.getEClassifiers().iterator(); classifiers.hasNext(); ) { >- EClassifier eClassifier = (EClassifier)classifiers.next(); >- if (eClassifier instanceof EClass) { >- EClass eClass = (EClass)eClassifier; >- if (!eClass.isAbstract()) { >- initialObjectNames.add(eClass.getName()); >- } >- } >- } >- Collections.sort(initialObjectNames, java.text.Collator.getInstance()); >- } >- return initialObjectNames; >- } >- >- /** > * Create a new model. > * <!-- begin-user-doc --> > * <!-- end-user-doc --> >- * @generated >+ * @generated NOT > */ > protected EObject createInitialModel() { >- EClass eClass = (EClass)gmfGenPackage.getEClassifier(initialObjectCreationPage.getInitialObjectName()); >- EObject rootObject = gmfGenFactory.create(eClass); >- return rootObject; >+ return GMFGenPackage.eINSTANCE.getGMFGenFactory().createGenEditorGenerator(); > } > > /** > * Do the work after everything is specified. > * <!-- begin-user-doc --> > * <!-- end-user-doc --> >- * @generated >+ * @generated NOT > */ > public boolean performFinish() { > try { >- // Remember the file. >- // > final IFile modelFile = getModelFile(); >- >- // Do the work within an operation. >- // >- WorkspaceModifyOperation operation = >- new WorkspaceModifyOperation() { >- protected void execute(IProgressMonitor progressMonitor) { >- try { >- // Create a resource set >- // >- ResourceSet resourceSet = new ResourceSetImpl(); >- >- // Get the URI of the model file. >- // >- URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString()); >- >- // Create a resource for this file. >- // >- Resource resource = resourceSet.createResource(fileURI); >- >- // Add the initial model object to the contents. >- // >- EObject rootObject = createInitialModel(); >- if (rootObject != null) { >- resource.getContents().add(rootObject); >- } >- >- // Save the contents of the resource to the file system. >- // >- Map options = new HashMap(); >- options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding()); >- resource.save(options); >- } >- catch (Exception exception) { >- EditorPlugin.INSTANCE.log(exception); >- } >- finally { >- progressMonitor.done(); >- } >- } >- }; >- >- getContainer().run(false, false, operation); >- >- // Select the new file resource in the current view. >- // >- IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); >- IWorkbenchPage page = workbenchWindow.getActivePage(); >- final IWorkbenchPart activePart = page.getActivePart(); >- if (activePart instanceof ISetSelectionTarget) { >- final ISelection targetSelection = new StructuredSelection(modelFile); >- getShell().getDisplay().asyncExec >- (new Runnable() { >- public void run() { >- ((ISetSelectionTarget)activePart).selectReveal(targetSelection); >- } >- }); >- } >- >- // Open an editor on the new file. >- // >- try { >- page.openEditor >- (new FileEditorInput(modelFile), >- workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId()); >- } >- catch (PartInitException exception) { >- MessageDialog.openError(workbenchWindow.getShell(), EditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage()); >- return false; >- } >- >- return true; >+ createModelFile(modelFile); >+ return openEditor(modelFile); > } > catch (Exception exception) { > EditorPlugin.INSTANCE.log(exception); >@@ -265,6 +115,81 @@ > } > } > >+ protected boolean openEditor(final IFile modelFile) { >+ // Select the new file resource in the current view. >+ // >+ IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); >+ IWorkbenchPage page = workbenchWindow.getActivePage(); >+ final IWorkbenchPart activePart = page.getActivePart(); >+ if (activePart instanceof ISetSelectionTarget) { >+ final ISelection targetSelection = new StructuredSelection(modelFile); >+ getShell().getDisplay().asyncExec >+ (new Runnable() { >+ public void run() { >+ ((ISetSelectionTarget)activePart).selectReveal(targetSelection); >+ } >+ }); >+ } >+ >+ // Open an editor on the new file. >+ // >+ try { >+ page.openEditor >+ (new FileEditorInput(modelFile), >+ workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId()); >+ } >+ catch (PartInitException exception) { >+ MessageDialog.openError(workbenchWindow.getShell(), EditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage()); >+ return false; >+ } >+ >+ return true; >+ } >+ >+ protected void createModelFile(final IFile modelFile) throws Exception { >+ // Do the work within an operation. >+ // >+ WorkspaceModifyOperation operation = >+ new WorkspaceModifyOperation() { >+ protected void execute(IProgressMonitor progressMonitor) { >+ try { >+ // Create a resource set >+ // >+ ResourceSet resourceSet = new ResourceSetImpl(); >+ >+ // Get the URI of the model file. >+ // >+ URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString()); >+ >+ // Create a resource for this file. >+ // >+ Resource resource = resourceSet.createResource(fileURI); >+ >+ // Add the initial model object to the contents. >+ // >+ EObject rootObject = createInitialModel(); >+ if (rootObject != null) { >+ resource.getContents().add(rootObject); >+ } >+ >+ // Save the contents of the resource to the file system. >+ // >+ Map options = new HashMap(); >+ options.put(XMLResource.OPTION_ENCODING, "UTF-8"); >+ resource.save(options); >+ } >+ catch (Exception exception) { >+ EditorPlugin.INSTANCE.log(exception); >+ } >+ finally { >+ progressMonitor.done(); >+ } >+ } >+ }; >+ >+ getContainer().run(false, false, operation); >+ } >+ > /** > * This is the one page of the wizard. > * <!-- begin-user-doc --> >@@ -318,215 +243,6 @@ > } > > /** >- * This is the page where the type of object to create is selected. >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- public class GMFGenModelWizardInitialObjectCreationPage extends WizardPage { >- /** >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- protected Combo initialObjectField; >- >- /** >- * @generated >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- */ >- protected List encodings; >- >- /** >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- protected Combo encodingField; >- >- /** >- * Pass in the selection. >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- public GMFGenModelWizardInitialObjectCreationPage(String pageId) { >- super(pageId); >- } >- >- /** >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- public void createControl(Composite parent) { >- Composite composite = new Composite(parent, SWT.NONE); >- { >- GridLayout layout = new GridLayout(); >- layout.numColumns = 1; >- layout.verticalSpacing = 12; >- composite.setLayout(layout); >- >- GridData data = new GridData(); >- data.verticalAlignment = GridData.FILL; >- data.grabExcessVerticalSpace = true; >- data.horizontalAlignment = GridData.FILL; >- composite.setLayoutData(data); >- } >- >- Label containerLabel = new Label(composite, SWT.LEFT); >- { >- containerLabel.setText(EditorPlugin.INSTANCE.getString("_UI_ModelObject")); >- >- GridData data = new GridData(); >- data.horizontalAlignment = GridData.FILL; >- containerLabel.setLayoutData(data); >- } >- >- initialObjectField = new Combo(composite, SWT.BORDER); >- { >- GridData data = new GridData(); >- data.horizontalAlignment = GridData.FILL; >- data.grabExcessHorizontalSpace = true; >- initialObjectField.setLayoutData(data); >- } >- >- for (Iterator i = getInitialObjectNames().iterator(); i.hasNext(); ) { >- initialObjectField.add(getLabel((String)i.next())); >- } >- >- if (initialObjectField.getItemCount() == 1) { >- initialObjectField.select(0); >- } >- initialObjectField.addModifyListener(validator); >- >- Label encodingLabel = new Label(composite, SWT.LEFT); >- { >- encodingLabel.setText(EditorPlugin.INSTANCE.getString("_UI_XMLEncoding")); >- >- GridData data = new GridData(); >- data.horizontalAlignment = GridData.FILL; >- encodingLabel.setLayoutData(data); >- } >- encodingField = new Combo(composite, SWT.BORDER); >- { >- GridData data = new GridData(); >- data.horizontalAlignment = GridData.FILL; >- data.grabExcessHorizontalSpace = true; >- encodingField.setLayoutData(data); >- } >- >- for (Iterator i = getEncodings().iterator(); i.hasNext(); ) { >- encodingField.add((String)i.next()); >- } >- >- encodingField.select(0); >- encodingField.addModifyListener(validator); >- >- setPageComplete(validatePage()); >- setControl(composite); >- } >- >- /** >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- protected ModifyListener validator = >- new ModifyListener() { >- public void modifyText(ModifyEvent e) { >- setPageComplete(validatePage()); >- } >- }; >- >- /** >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- protected boolean validatePage() { >- return getInitialObjectName() != null && getEncodings().contains(encodingField.getText()); >- } >- >- /** >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- public void setVisible(boolean visible) { >- super.setVisible(visible); >- if (visible) { >- if (initialObjectField.getItemCount() == 1) { >- initialObjectField.clearSelection(); >- encodingField.setFocus(); >- } >- else { >- encodingField.clearSelection(); >- initialObjectField.setFocus(); >- } >- } >- } >- >- /** >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- public String getInitialObjectName() { >- String label = initialObjectField.getText(); >- >- for (Iterator i = getInitialObjectNames().iterator(); i.hasNext(); ) { >- String name = (String)i.next(); >- if (getLabel(name).equals(label)) { >- return name; >- } >- } >- return null; >- } >- >- /** >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- public String getEncoding() { >- return encodingField.getText(); >- } >- >- /** >- * Returns the label for the specified type name. >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- protected String getLabel(String typeName) { >- try { >- return EditorPlugin.INSTANCE.getString("_UI_" + typeName + "_type"); >- } >- catch(MissingResourceException mre) { >- EditorPlugin.INSTANCE.log(mre); >- } >- return typeName; >- } >- >- /** >- * <!-- begin-user-doc --> >- * <!-- end-user-doc --> >- * @generated >- */ >- protected Collection getEncodings() { >- if (encodings == null) { >- encodings = new ArrayList(); >- for (StringTokenizer stringTokenizer = new StringTokenizer(EditorPlugin.INSTANCE.getString("_UI_XMLEncodingChoices")); stringTokenizer.hasMoreTokens(); ) { >- encodings.add(stringTokenizer.nextToken()); >- } >- } >- return encodings; >- } >- } >- >- /** > * The framework calls this to create the contents of the wizard. > * <!-- begin-user-doc --> > * <!-- end-user-doc --> >@@ -574,10 +290,6 @@ > } > } > } >- initialObjectCreationPage = new GMFGenModelWizardInitialObjectCreationPage("Whatever2"); >- initialObjectCreationPage.setTitle(EditorPlugin.INSTANCE.getString("_UI_GMFGenModelWizard_label")); >- initialObjectCreationPage.setDescription(EditorPlugin.INSTANCE.getString("_UI_Wizard_initial_object_description")); >- addPage(initialObjectCreationPage); > } > > /** >#P org.eclipse.gmf.bridge.ui >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.bridge.ui/plugin.xml,v >retrieving revision 1.7 >diff -u -r1.7 plugin.xml >--- plugin.xml 24 Nov 2006 16:19:41 -0000 1.7 >+++ plugin.xml 11 Jan 2007 17:08:51 -0000 >@@ -67,4 +67,25 @@ > </wizard> > </extension> > >+ <extension >+ point="org.eclipse.ui.popupMenus"> >+ <objectContribution >+ adaptable="true" >+ id="gmf.codegen.ui.transformToGenModelFile" >+ nameFilter="*.gmfmap" >+ objectClass="org.eclipse.core.resources.IFile"> >+ <action >+ class="org.eclipse.gmf.internal.bridge.transform.TransformToGenModelAction" >+ enablesFor="1" >+ id="gmf.bridge.ui.transformToGenModelFileActionExperimental" >+ label="%transform.action.experimental" >+ menubarPath="additions"> >+ </action> >+ </objectContribution> >+ </extension> >+ <extension >+ point="org.eclipse.core.runtime.preferences"> >+ <initializer class="org.eclipse.gmf.internal.bridge.transform.TransformOptions"/> >+ </extension> >+ > </plugin> >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.bridge.ui/plugin.properties,v >retrieving revision 1.8 >diff -u -r1.8 plugin.properties >--- plugin.properties 24 Nov 2006 16:19:41 -0000 1.8 >+++ plugin.properties 11 Jan 2007 17:08:51 -0000 >@@ -31,3 +31,5 @@ > showDashboardPage.name=Show Dashboard > showDashboardPage.desc=Show dashboard view for the created project > showDashboardPage.text=Show dashboard view for the created project >+ >+transform.action.experimental=Create generator model (experimental)... >Index: src/org/eclipse/gmf/internal/bridge/ui/Plugin.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/ui/Plugin.java,v >retrieving revision 1.6 >diff -u -r1.6 Plugin.java >--- src/org/eclipse/gmf/internal/bridge/ui/Plugin.java 15 Sep 2006 12:18:10 -0000 1.6 >+++ src/org/eclipse/gmf/internal/bridge/ui/Plugin.java 11 Jan 2007 17:08:51 -0000 >@@ -59,6 +59,26 @@ > return myContainmentClosure; > } > >+ public static IStatus createStatus(int statusCode, String message, Throwable ex) { >+ return new Status(statusCode, getPluginID(), 0, message, ex); >+ } >+ >+ public static IStatus createError(String message, Throwable ex) { >+ return createStatus(IStatus.ERROR, message, ex); >+ } >+ >+ public static IStatus createWarning(String message) { >+ return createStatus(IStatus.WARNING, message, null); >+ } >+ >+ public static IStatus createInfo(String message) { >+ return createStatus(IStatus.INFO, message, null); >+ } >+ >+ public static IStatus createCancel(String message) { >+ return createStatus(IStatus.CANCEL, message, null); >+ } >+ > public static Plugin getDefault() { > return plugin; > } >@@ -103,7 +123,7 @@ > if (ex instanceof CoreException) { > log((CoreException) ex); > } else { >- log(new Status(IStatus.ERROR, getPluginID(), 0, ex.getMessage(), ex)); >+ log(createError(ex.getMessage(), ex)); > } > } > >@@ -115,6 +135,10 @@ > getDefault().getLog().log(s); > } > >+ public static boolean needsReconcile() { >+ return !Boolean.FALSE.toString().equals(Platform.getDebugOption(getPluginID() + "/reconcile")); >+ } >+ > /** > * Returns an image descriptor for the image file at the given plug-in relative path. > * >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.bridge.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.9 >diff -u -r1.9 MANIFEST.MF >--- META-INF/MANIFEST.MF 10 Nov 2006 19:09:50 -0000 1.9 >+++ META-INF/MANIFEST.MF 11 Jan 2007 17:08:51 -0000 >@@ -17,9 +17,12 @@ > org.eclipse.gmf.graphdef.edit;bundle-version="[1.0.0,2.0.0)", > org.eclipse.gmf.tooldef.edit;bundle-version="[1.0.0,2.0.0)", > org.eclipse.gmf.map.edit;bundle-version="[1.0.0,2.0.0)", >- org.eclipse.emf.codegen.ecore.ui;bundle-version="[2.2.0,3.0.0)" >+ org.eclipse.emf.codegen.ecore.ui;bundle-version="[2.2.0,3.0.0)", >+ org.eclipse.gmf.codegen.edit, >+ org.eclipse.emf.importer > Eclipse-LazyStart: true > Export-Package: org.eclipse.gmf.internal.bridge.resolver;x-internal:=true, >+ org.eclipse.gmf.internal.bridge.transform, > org.eclipse.gmf.internal.bridge.ui;x-friends:="org.eclipse.gmf.bridge.ui.dashboard,org.eclipse.gmf.doc.ui", > org.eclipse.gmf.internal.bridge.wizards;x-friends:="org.eclipse.gmf.bridge.ui.dashboard,org.eclipse.gmf.doc.ui", > org.eclipse.gmf.internal.bridge.wizards.pages;x-friends:="org.eclipse.gmf.doc.ui", >Index: src/org/eclipse/gmf/internal/bridge/transform/VisualIdentifierDispenserProvider.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/VisualIdentifierDispenserProvider.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/VisualIdentifierDispenserProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/VisualIdentifierDispenserProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,61 @@ >+package org.eclipse.gmf.internal.bridge.transform; >+ >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.emf.common.util.URI; >+import org.eclipse.gmf.internal.bridge.NaiveIdentifierDispenser; >+import org.eclipse.gmf.internal.bridge.StatefulVisualIdentifierDispencer; >+import org.eclipse.gmf.internal.bridge.VisualIdentifierDispenser; >+import org.eclipse.gmf.internal.bridge.ui.Plugin; >+import org.osgi.framework.Bundle; >+ >+/** >+ * holds additional logic to pre/post process dispensers >+ */ >+class VisualIdentifierDispenserProvider { >+ private VisualIdentifierDispenser dispenser; >+ private final URI myStateBaseURI; >+ >+ VisualIdentifierDispenserProvider(URI stateBaseURI) { >+ myStateBaseURI = stateBaseURI; >+ } >+ >+ private VisualIdentifierDispenser initialize() { >+ Bundle tracePluginBundle = Platform.getBundle("org.eclipse.gmf.bridge.trace"); //$NON-NLS-1$ >+ if (tracePluginBundle != null) { >+ try { >+ Class despenserClass = tracePluginBundle.loadClass("org.eclipse.gmf.internal.bridge.trace.MergingIdentifierDispenser"); //$NON-NLS-1$ >+ return (VisualIdentifierDispenser) despenserClass.newInstance(); >+ } catch (ClassNotFoundException e) { >+ Plugin.log(Plugin.createError(Messages.getString("VisualIdentifierDispenserProvider.error_not_found"), e)); //$NON-NLS-1$ >+ } catch (InstantiationException e) { >+ Plugin.log(Plugin.createError(Messages.getString("VisualIdentifierDispenserProvider.error_instantiation"), e)); //$NON-NLS-1$ >+ } catch (IllegalAccessException e) { >+ Plugin.log(Plugin.createError(Messages.getString("VisualIdentifierDispenserProvider.error_illegal_access"), e)); //$NON-NLS-1$ >+ } catch (ClassCastException ex) { >+ Plugin.log(Plugin.createError(Messages.getString("VisualIdentifierDispenserProvider.error_instantiation"), ex)); //$NON-NLS-1$ >+ } >+ } >+ return new NaiveIdentifierDispenser(); >+ } >+ >+ public VisualIdentifierDispenser get() { >+ assert dispenser != null; >+ return dispenser; >+ } >+ >+ public void acquire() { >+ assert dispenser == null; >+ dispenser = initialize(); >+ if (dispenser instanceof StatefulVisualIdentifierDispencer) { >+ StatefulVisualIdentifierDispencer statefulDispencer = (StatefulVisualIdentifierDispencer) dispenser; >+ statefulDispencer.loadState(myStateBaseURI); >+ } >+ } >+ >+ public void release() { >+ if (dispenser instanceof StatefulVisualIdentifierDispencer) { >+ ((StatefulVisualIdentifierDispencer) dispenser).saveState(); >+ } >+ dispenser = null; >+ } >+} >Index: src/org/eclipse/gmf/internal/bridge/transform/messages.properties >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/messages.properties >diff -N src/org/eclipse/gmf/internal/bridge/transform/messages.properties >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/messages.properties 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,38 @@ >+StaleGenModelDetector.warning_stale=Resource {0} is newer ({1,date}) than genmodel ({2,date}) >+GenModelDetector.error_cannot_find=Can't find genmodel >+GenModelDetector.error_cannot_save=Can't save created genmodel >+GenModelDetector.error_no_genmodelaccess=Need to apply GenModelAccess first >+GenModelConfigurationPage.btn_new_model=New EMF Model ... >+GenModelConfigurationPage.btn_default_model=Create Default ... >+GenModelConfigurationPage.check_detect_stale=Detect stale Genmodel >+GenModelConfigurationPage.btn_refresh=Refresh ... >+VisualIdentifierDispenserProvider.error_not_found=MergingIdentifierDispenser was not found in org.eclipse.gmf.bridge.trace bundle >+ViewmapProducerWizardPage.btn_use_runtime_figures=&Utilize enhanced features of GMF runtime >+VisualIdentifierDispenserProvider.error_instantiation=MergingIdentifierDispenser was not instantiated >+VisualIdentifierDispenserProvider.error_illegal_access=IllegalAccessException while instantiating MergingIdentifierDispenser >+ValidationHelper.task_validating=Validating... >+ValidationHelper.error_marker_creation=Marker creation failure >+TransformToGenModelOperation.cancel_mapping_model_load=Mapping model loading was interrupted >+TransformToGenModelOperation.task_loading=Loading ... >+TransformToGenModelWizard.title_map_model=Select Mapping Model >+TransformToGenModelWizard.descr_map_model=Load Mapping Model >+TransformToGenModelWizard.title_gen_model=Select GenModel >+TransformToGenModelWizard.descr_gen_model=Load GenModel or create new one >+TransformToGenModelWizard.error_transform=Errors while creating generator model >+TransformToGenModelWizard.cancel_transform=Operation cancelled >+TransformToGenModelOperation.task_validating=Validating ... >+TransformToGenModelOperation.error_invalid_mapping_model=Invalid Mapping Model >+TransformToGenModelOperation.error_load_genmodel=Failed to load GenModel >+TransformToGenModelOperation.task_generating=Generating ... >+TransformToGenModelOperation.task_reconciling=Reconciling ... >+TransformToGenModelOperation.task_saving=Saving ... >+TransformToGenModelWizard.title_options=Specify transformation options >+TransformToGenModelWizard.descr_options=Specify transformation options >+TransformToGenModelWizard.title_wizard=Create generator model >+ViewmapProducerWizardPage.btn_use_map_mode=Use &IMapMode >+ViewmapProducerWizardPage.btn_create_rcp=Generate RCP Application >+ViewmapProducerWizardPage.info_map_mode_for_lite=It is not recommended to use IMapMode for pure-GEF diagram editors >+MapModelConfigurationPage.lbl_severity=Select the severity level for load problems to ignore: >+MapModelConfigurationPage.lbl_info=Info >+MapModelConfigurationPage.lbl_warning=Warning >+MapModelConfigurationPage.lbl_error=Error >Index: src/org/eclipse/gmf/internal/bridge/transform/Messages.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/Messages.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/Messages.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/Messages.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,33 @@ >+/** >+ * Copyright (c) 2007 Borland Software Corporation >+ * >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Alexander Fedorov (Borland) - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.bridge.transform; >+ >+import java.util.MissingResourceException; >+import java.util.ResourceBundle; >+ >+public class Messages { >+ >+ private static final String BUNDLE_NAME = "org.eclipse.gmf.internal.bridge.transform.messages"; //$NON-NLS-1$ >+ >+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); >+ >+ private Messages() { >+ } >+ >+ public static String getString(String key) { >+ try { >+ return RESOURCE_BUNDLE.getString(key); >+ } catch (MissingResourceException e) { >+ return '!' + key + '!'; >+ } >+ } >+} >Index: src/org/eclipse/gmf/internal/bridge/transform/StaleGenModelDetector.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/StaleGenModelDetector.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/StaleGenModelDetector.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/StaleGenModelDetector.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,102 @@ >+/* >+ * 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: >+ * Artem Tikhomirov (Borland) - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.bridge.transform; >+ >+import java.text.MessageFormat; >+import java.util.Date; >+import java.util.HashSet; >+import java.util.Iterator; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.emf.codegen.ecore.genmodel.GenModel; >+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage; >+import org.eclipse.emf.common.util.URI; >+import org.eclipse.gmf.internal.bridge.ui.Plugin; >+ >+/** >+ * @author artem >+ */ >+public class StaleGenModelDetector { >+ >+ private final GenModel myGenModel; >+ >+ public StaleGenModelDetector(GenModel genModel) { >+ assert genModel != null; >+ myGenModel = genModel; >+ } >+ >+ /** >+ * Uses local time stamp to detect staleness, though would be better to use IResource#modificationStamp >+ * to tell whether resource has changed or not >+ * @return warning status if staleness detected, ok otherwise. >+ */ >+ public IStatus detect() { >+ if (myGenModel.eResource() == null) { >+ return Status.OK_STATUS; >+ } >+ URI genModelURI = myGenModel.eResource().getURI(); >+ if (!isFileURI(genModelURI)) { >+ return Status.OK_STATUS; >+ } >+ HashSet<URI> ecoreURIs = new HashSet<URI>(); >+ for (Iterator it = myGenModel.getAllGenAndUsedGenPackagesWithClassifiers().iterator(); it.hasNext();) { >+ GenPackage next = (GenPackage) it.next(); >+ if (next.getEcorePackage().eResource() != null) { >+ final URI uri = next.getEcorePackage().eResource().getURI(); >+ if (isFileURI(uri)) { >+ // check only file uris >+ // though we don't check non-file uris, it's not bad to make sure at least >+ // files are up to date >+ ecoreURIs.add(uri); >+ } >+ } >+ } >+ Date genModelTimeStamp = timestamp(genModelURI); >+ for (URI uri : ecoreURIs) { >+ Date ts = timestamp(uri); >+ /* HACK >+ * @see ModelImporter#saveGenModelAndEPackages >+ * saves both ecore and genmodel files regardless of the fact .ecore was not modified, >+ * hence, we adjust the timestamp to avoid false stale detection >+ */ >+ if (new Date(genModelTimeStamp.getTime() + 3000).before(ts)) { >+ String format = Messages.getString("StaleGenModelDetector.warning_stale"); //$NON-NLS-1$ >+ String msg = MessageFormat.format(format, uri, ts, genModelTimeStamp); >+ return Plugin.createWarning(msg); >+ } >+ } >+ return Status.OK_STATUS; >+ } >+ >+ private static boolean isFileURI(URI uri) { >+ return "platform".equals(uri.scheme()) && "resource".equals(uri.segment(0)); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ >+ private static Date timestamp(URI uri) { >+ IFile f = getFile(uri); >+ if (!f.exists()) { >+ return new Date(0); >+ } >+ return new Date(f.getLocalTimeStamp()); >+ } >+ >+ private static IFile getFile(URI platformFileUri) { >+ IPath p = new Path(platformFileUri.path()).removeFirstSegments(1); >+ return ResourcesPlugin.getWorkspace().getRoot().getFile(p); >+ } >+ >+} >Index: src/org/eclipse/gmf/internal/bridge/transform/ViewmapProducerWizardPage.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/ViewmapProducerWizardPage.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/ViewmapProducerWizardPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/ViewmapProducerWizardPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,133 @@ >+/** >+ * 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: >+ * Alexander Fedorov (Borland) - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.bridge.transform; >+ >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.gmf.internal.bridge.ui.Plugin; >+import org.eclipse.jface.dialogs.Dialog; >+import org.eclipse.jface.dialogs.IMessageProvider; >+import org.eclipse.jface.wizard.WizardPage; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Widget; >+ >+/* >+ * XXX: duplicates functionality of >+ * org.eclipse.gmf.internal.codegen.popup.actions.TransformToGenModelOptionsDialog >+ * and >+ * org.eclipse.gmf.internal.graphdef.codegen.ui.FigureGeneratorOptionsDialog >+ */ >+class ViewmapProducerWizardPage extends WizardPage { >+ >+ private Button generateRCPButton; >+ private Button useMapModeButton; >+ private Button useRuntimeFiguresButton; >+ >+ protected ViewmapProducerWizardPage(String pageName) { >+ super(pageName); >+ } >+ >+ public void createControl(Composite parent) { >+ initializeDialogUnits(parent); >+ >+ Composite composite = new Composite(parent, SWT.NONE); >+ composite.setLayout(new GridLayout()); >+ createControls(composite); >+ initControls(); >+ validatePage(); >+ >+ setControl(composite); >+ Dialog.applyDialogFont(composite); >+ } >+ >+ private void createControls(Composite result) { >+ useMapModeButton = new Button(result, SWT.CHECK); >+ useMapModeButton.setText(Messages.getString("ViewmapProducerWizardPage.btn_use_map_mode")); //$NON-NLS-1$ >+ useMapModeButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_CENTER)); >+ useRuntimeFiguresButton = new Button(result, SWT.CHECK); >+ useRuntimeFiguresButton.setText(Messages.getString("ViewmapProducerWizardPage.btn_use_runtime_figures")); //$NON-NLS-1$ >+ useRuntimeFiguresButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_CENTER)); >+ generateRCPButton = new Button(result, SWT.CHECK); >+ generateRCPButton.setText(Messages.getString("ViewmapProducerWizardPage.btn_create_rcp")); //$NON-NLS-1$ >+ generateRCPButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_CENTER)); >+ SelectionListener selectionListener = new SelectionListener() { >+ public void widgetDefaultSelected(SelectionEvent e) { >+ handleSelection(e.widget); >+ } >+ public void widgetSelected(SelectionEvent e) { >+ handleSelection(e.widget); >+ } >+ }; >+ useMapModeButton.addSelectionListener(selectionListener); >+ useRuntimeFiguresButton.addSelectionListener(selectionListener); >+ generateRCPButton.addSelectionListener(selectionListener); >+ } >+ >+ void handleSelection(Widget w) { >+ if (generateRCPButton.equals(w)){ >+ getOperation().getOptions().setGenerateRCP(generateRCPButton.getSelection()); >+ } else if (useMapModeButton.equals(w)) { >+ getOperation().getOptions().setUseMapMode(useMapModeButton.getSelection()); >+ } else if (useRuntimeFiguresButton.equals(w)) { >+ getOperation().getOptions().setUseRuntimeFigures(useRuntimeFiguresButton.getSelection()); >+ } >+ validatePage(); >+ } >+ >+ private void validatePage() { >+ IStatus checkOptions = checkOptions(); >+ if (checkOptions.isOK()) { >+ setMessage(null); >+ setPageComplete(true); >+ } else { >+ setMessage(checkOptions.getMessage(), IMessageProvider.INFORMATION); >+ setPageComplete(checkOptions.getSeverity() < IStatus.WARNING); >+ } >+ } >+ >+ private IStatus checkOptions() { >+ boolean hasLite = TransformOptions.checkLiteOptionPresent(); >+ if (hasLite) { >+ if (!useRuntimeFiguresButton.getSelection() && useMapModeButton.getSelection()) { >+ return Plugin.createInfo(Messages.getString("ViewmapProducerWizardPage.info_map_mode_for_lite")); //$NON-NLS-1$ >+ } >+ } >+ return Status.OK_STATUS; >+ } >+ >+ private void initControls() { >+ TransformOptions options = getOperation().getOptions(); >+ generateRCPButton.setSelection(options.getGenerateRCP()); >+ boolean hasLite = TransformOptions.checkLiteOptionPresent(); >+ boolean useRuntimeFigures = options.getUseRuntimeFigures(); >+ if (hasLite) { >+ useRuntimeFiguresButton.setEnabled(true); >+ useRuntimeFiguresButton.setSelection(useRuntimeFigures); >+ } else { >+ useRuntimeFiguresButton.setEnabled(false); >+ useRuntimeFiguresButton.setSelection(true); >+ options.setUseRuntimeFigures(true); >+ } >+ useMapModeButton.setSelection(options.getUseMapMode()); >+ } >+ >+ private TransformToGenModelOperation getOperation() { >+ TransformToGenModelWizard wizard = (TransformToGenModelWizard) getWizard(); >+ return wizard.getTransformOperation(); >+ } >+} >Index: src/org/eclipse/gmf/internal/bridge/transform/ValidationHelper.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/ValidationHelper.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/ValidationHelper.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/ValidationHelper.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,397 @@ >+/** >+ * 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.bridge.transform; >+ >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.Iterator; >+import java.util.LinkedHashMap; >+import java.util.List; >+import java.util.Map; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IMarker; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.core.runtime.SubProgressMonitor; >+import org.eclipse.emf.common.ui.MarkerHelper; >+import org.eclipse.emf.common.util.BasicDiagnostic; >+import org.eclipse.emf.common.util.Diagnostic; >+import org.eclipse.emf.common.util.DiagnosticChain; >+import org.eclipse.emf.common.util.URI; >+import org.eclipse.emf.ecore.EClass; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.EValidator; >+import org.eclipse.emf.ecore.resource.Resource; >+import org.eclipse.emf.ecore.util.Diagnostician; >+import org.eclipse.emf.ecore.util.EcoreUtil; >+import org.eclipse.emf.edit.provider.ComposedAdapterFactory; >+import org.eclipse.emf.edit.provider.IItemLabelProvider; >+import org.eclipse.emf.edit.ui.util.EditUIMarkerHelper; >+import org.eclipse.gmf.internal.bridge.ui.Plugin; >+ >+/** >+ * Provides various functinality useful for model validation, for instances >+ * progress monitoring, resource markers creation. >+ */ >+public class ValidationHelper { >+ >+ /** >+ * Enhanced diagnostician class supporting progress monitoring and object >+ * labels. >+ */ >+ private static class SmartDiagnostician extends Diagnostician { >+ >+ private static ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); >+ >+ private IProgressMonitor monitor; >+ >+ /** >+ * Constructs diagnostician with progress monitor. >+ * >+ * @param progressMonitor >+ * non-null progress monitor to track validation progress >+ */ >+ SmartDiagnostician(IProgressMonitor progressMonitor) { >+ this.monitor = progressMonitor; >+ } >+ >+ /* >+ * Utilizes the adapter factory registry to provide labels. >+ */ >+ @Override >+ public String getObjectLabel(EObject eObject) { >+ if (eObject != null) { >+ IItemLabelProvider itemLabelProvider = (IItemLabelProvider) adapterFactory.adapt(eObject, IItemLabelProvider.class); >+ if (itemLabelProvider != null) { >+ return itemLabelProvider.getText(eObject); >+ } >+ } else { >+ return ""; //$NON-NLS-1$ >+ } >+ return super.getObjectLabel(eObject); >+ } >+ >+ /* >+ * Notifies the monitor about the unit of work done. >+ */ >+ @Override >+ public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map context) { >+ if(monitor.isCanceled()) { >+ return true; >+ } >+ >+ monitor.worked(1); >+ return super.validate(eClass, eObject, diagnostics, context); >+ } >+ } >+ >+ /** >+ * Helper class for binding validation diagnostics to corresponding problem >+ * markers. >+ * <p> >+ * This class ensures that markers are managed for both {@link Diagnostic}} >+ * and {@link Resource.Diagnostic} diagnostic types. >+ */ >+ private static class GMFMarkerHelper extends EditUIMarkerHelper { >+ >+ private LinkedHashMap<Diagnostic, IMarker> diagnostic2Marker; >+ private String markerID; >+ >+ /** >+ * Constructs marker helper with default markerID taken from its super-type. >+ */ >+ GMFMarkerHelper() { >+ super(); >+ } >+ >+ /** >+ * Constructs marker helper with given marker ID. >+ * >+ * @param markerID >+ * string ID used as IMarker.TYPE. >+ * <p> >+ * If <code>null</code>, the default is >+ * <code>resource-problem-marker</code> taken from >+ * {@link MarkerHelper#getMarkerID()} >+ */ >+ GMFMarkerHelper(String markerID) { >+ this.markerID = markerID; >+ } >+ >+ public IFile getFileFromDiagnostic(Diagnostic diagnostic) { >+ return getFile(diagnostic); >+ } >+ >+ @Override >+ protected void adjustMarker(IMarker marker, Diagnostic diagnostic, Diagnostic parentDiagnostic) throws CoreException { >+ getDiagnostic2MarkerMap().put(diagnostic, marker); >+ >+ // adjust marker to support IGotoMarker for standard EMF generated editors >+ List data = diagnostic.getData(); >+ if (data != null && !data.isEmpty()) { >+ Object target = data.get(0); >+ if (target instanceof EObject) { >+ marker.setAttribute(EValidator.URI_ATTRIBUTE, EcoreUtil.getURI((EObject) target).toString()); >+ } >+ } >+ >+ super.adjustMarker(marker, diagnostic, parentDiagnostic); >+ } >+ >+ @Override >+ protected IFile getFile(Object datum) { >+ if (datum instanceof EObject) { >+ EObject eObject = (EObject) datum; >+ if(eObject.eResource() != null) { >+ URI uri = eObject.eResource().getURI(); >+ IFile file = getFile(uri); >+ if(file != null) { >+ return file; >+ } >+ } >+ } >+ return super.getFile(datum); >+ } >+ >+ >+ >+ @Override >+ protected String getMarkerID() { >+ return markerID != null ? markerID : super.getMarkerID(); >+ } >+ >+ LinkedHashMap<Diagnostic, IMarker> getDiagnostic2MarkerMap() { >+ if(diagnostic2Marker == null) { >+ diagnostic2Marker = new LinkedHashMap<Diagnostic, IMarker>(); >+ } >+ return diagnostic2Marker; >+ } >+ } >+ >+ /** >+ * Diagnostic to marker map data holder class. >+ * <p> >+ * Note: The map iterators respect the order of marker creation. >+ */ >+ public static class DiagnosticMarkerMap { >+ private Map<Diagnostic, IMarker> map; >+ >+ /** >+ * Constraint diagnostic marker from the given map data. >+ * @param markerMap map data to be encapsulated by the resulting object. >+ */ >+ DiagnosticMarkerMap(LinkedHashMap<Diagnostic, IMarker> markerMap) { >+ this.map = Collections.unmodifiableMap(markerMap); >+ } >+ >+ /** >+ * Gets the map data for this diagnostic marker map. >+ * @return read-only map object >+ */ >+ public Map<Diagnostic, IMarker> getMap() { >+ return map; >+ } >+ } >+ >+ /** >+ * No instances, just an utility class. >+ */ >+ private ValidationHelper() { >+ super(); >+ } >+ >+ >+ /** >+ * Indicates whether the severiti of the given diagnostic matches the given >+ * bitmask.<p> >+ * Note that a diagnostic with severity <code>OK</code> will never match; >+ * use <code>isOK</code> instead to detect a diagnostic with a severity of <code>OK</code>. >+ * >+ * @param diagnostic a diagnostic to test for severity match >+ * @param severityBitMask a mask formed by bitwise or'ing severity mask constants >+ * (<code>ERROR</code>, <code>WARNING</code>, <code>INFO</code>, <code>CANCEL</code>) >+ * >+ * @return <code>true</code> if there is at least one match, <code>false</code> otherwise >+ * >+ * @see Diagnostic#ERROR >+ * @see Diagnostic#WARNING >+ * @see Diagnostic#INFO >+ * @see Diagnostic#CANCEL >+ */ >+ public static boolean matches(Diagnostic diagnostic, int severityBitMask) { >+ return (diagnostic.getSeverity() & severityBitMask) != 0; >+ } >+ >+ /** >+ * Returns whether this diagnostic indicates everything is OK. (neither >+ * info, warning, nor error). >+ * >+ * @return <code>true</code> if this diagnostic has severity >+ * <code>OK</code>, and <code>false</code> otherwise >+ */ >+ public static boolean isOK(Diagnostic diagnostic) { >+ return diagnostic.getSeverity() == Diagnostic.OK; >+ } >+ >+ /** >+ * Validates the given <code>EObject</code> and its all contents. >+ * <p> >+ * If the EMF basic validation results in <code>Diagnostic.CANCEL</code> >+ * severity, no problem markers are created at all. >+ * >+ * The problem markers created by this operation are added as extra-data to >+ * the returned diagnostic and are accessible via >+ * {@link #getDiagnosticMarkerMap(Diagnostic)}. >+ * >+ * @param createMarkers >+ * if <code>true</code> this operation produces validation >+ * problems markers provided that eObject.eResource() represents >+ * a file existing in the workspace. If <code>true</code> no >+ * attempt to create markers is performed. >+ * >+ * @param progressMonitor >+ * the progress monitor to track validation progress, or >+ * <code>null</code> if no progress monitoring is required. >+ * The implementation creates {@link SubProgressMonitor} as >+ * a sub-task of the given parent <code>progressMonitor</code> >+ * allocating 1 tick from the parent. #beginTask and #done operation >+ * on the subprogress monitor is called. >+ * >+ * @return the validation result diagnostic >+ */ >+ public static Diagnostic validate(EObject eObject, boolean createMarkers, IProgressMonitor progressMonitor) { >+ IProgressMonitor monitor = null; >+ try { >+ int count = IProgressMonitor.UNKNOWN; >+ if(progressMonitor != null) { >+ for (Iterator i = eObject.eAllContents(); i.hasNext(); i.next()) { >+ ++count; >+ } >+ } >+ >+ monitor = (progressMonitor != null) ? new SubProgressMonitor(progressMonitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK) : new NullProgressMonitor(); >+ monitor.beginTask("", count); //$NON-NLS-1$ >+ monitor.subTask(Messages.getString("ValidationHelper.task_validating")); //$NON-NLS-1$ >+ >+ Diagnostic validationStatus = new SmartDiagnostician(monitor).validate(eObject); >+ if(validationStatus.getSeverity() == Diagnostic.CANCEL) { >+ return validationStatus; >+ } >+ >+ if(createMarkers) { >+ return createMarkers(validationStatus, EValidator.MARKER); >+ } >+ >+ return validationStatus; >+ >+ } finally { >+ monitor.done(); >+ } >+ } >+ >+ /** >+ * Validates the given <code>EObject</code> and its all contents. >+ * <p> >+ * This method is progress monitoring ignorant shorthand of {@link #validate(EObject, boolean, IProgressMonitor)} >+ * >+ * @param createMarkers >+ * if <code>true</code> this operation produces validation >+ * problems markers provided that eObject.eResource() represents >+ * a file existing in the workspace. If <code>true</code> no >+ * attempt to create markers is performed. >+ * >+ * @return the validation result diagnostic >+ * >+ * @see #validate(EObject, boolean, IProgressMonitor) >+ */ >+ public static Diagnostic validate(EObject eObject, boolean createMarkers) { >+ return validate(eObject, createMarkers, null); >+ } >+ >+ /** >+ * Gets the diagnostic marker map associated with the given validation >+ * diagnostic. >+ * >+ * @param diagnostic >+ * a non-null validation diagnostic which resulted from calling >+ * {@link #validate(EObject, boolean, IProgressMonitor)}} >+ * >+ * @see #validate(EObject, boolean, IProgressMonitor) >+ */ >+ public static DiagnosticMarkerMap getDiagnosticMarkerMap(Diagnostic diagnostic) { >+ List data = (diagnostic.getData() != null) ? diagnostic.getData() : Collections.EMPTY_LIST; >+ for (Iterator it = data.iterator(); it.hasNext();) { >+ Object dataItem = it.next(); >+ if (dataItem instanceof DiagnosticMarkerMap) { >+ return (DiagnosticMarkerMap) dataItem; >+ } >+ } >+ return null; >+ } >+ >+ /** >+ * Extracts the file of the validated model instance referenced by the given >+ * diagnostic. >+ * >+ * @param diagnostic >+ * a non-null validation diagnostic >+ * @return the file object or <code>null</code> in case the resource >+ * associated with the validated object does not represents a file >+ * existing in the workspace. >+ */ >+ public static IFile getFileFromDiagnostic(Diagnostic diagnostic) { >+ return new GMFMarkerHelper(EValidator.MARKER).getFileFromDiagnostic(diagnostic); >+ } >+ >+ /** >+ * Creates resource problem markers {@link Resource.Diagnostic} encapsualted >+ * in the given diagnostic object. >+ * >+ * @param diagnostic >+ * non-null diagnostic eventually containing a hiearchy of >+ * diagnostics for which markers are to be created. >+ * >+ * @see #getDiagnosticMarkerMap(Diagnostic) >+ * @see Resource.Diagnostic >+ */ >+ public static Diagnostic createResourceProblemMarkers(Diagnostic diagnostic) { >+ return createMarkers(diagnostic, null /* resource problem markers*/); >+ } >+ >+ private static Diagnostic createMarkers(Diagnostic diagnostic, String markerID) { >+ GMFMarkerHelper markerHelper = new GMFMarkerHelper(markerID); >+ try { >+ markerHelper.deleteMarkers(diagnostic, false, IResource.DEPTH_ZERO); >+ if(!diagnostic.getChildren().isEmpty() && !isOK(diagnostic)) { >+ markerHelper.createMarkers(diagnostic); >+ } >+ } catch (CoreException e) { >+ IStatus status = Plugin.createError(Messages.getString("ValidationHelper.error_marker_creation"), e); //$NON-NLS-1$ >+ Plugin.log(status); >+ } >+ DiagnosticMarkerMap markerMap = new DiagnosticMarkerMap(markerHelper.getDiagnostic2MarkerMap()); >+ >+ List<Object> data = diagnostic.getData() != null ? (List<Object>)diagnostic.getData() : Collections.emptyList(); >+ data = new ArrayList<Object>(data); >+ data.add(markerMap); >+ >+ BasicDiagnostic result = new BasicDiagnostic( >+ diagnostic.getSource(), diagnostic.getCode(), >+ diagnostic.getMessage(), data.toArray()); >+ >+ result.addAll(diagnostic); >+ return result; >+ } >+} >Index: src/org/eclipse/gmf/internal/bridge/transform/GenModelConfigurationPage.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/GenModelConfigurationPage.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/GenModelConfigurationPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/GenModelConfigurationPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,243 @@ >+/** >+ * 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: >+ * Alexander Fedorov (Borland) - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.bridge.transform; >+ >+import org.eclipse.core.resources.IContainer; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.emf.codegen.ecore.genmodel.GenModel; >+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.importer.ui.EMFModelWizard; >+import org.eclipse.emf.importer.ui.GenModelReloadActionDelegate; >+import org.eclipse.gmf.internal.common.URIUtil; >+import org.eclipse.gmf.internal.common.ui.ResourceLocationProvider; >+import org.eclipse.jface.action.Action; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.jface.window.Window; >+import org.eclipse.jface.wizard.WizardDialog; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.Widget; >+import org.eclipse.ui.PlatformUI; >+ >+ >+class GenModelConfigurationPage extends ModelConfigurationPage { >+ >+ private static final String FILE_EXT_ECORE = "ecore"; //$NON-NLS-1$ >+ private static final String FILE_EXT_GENMODEL = "genmodel"; //$NON-NLS-1$ >+ >+ private Button createWizardBtn; >+ private Button createDefaultBtn; >+ private Button detectStaleBtn; >+ private Button refreshStaleBtn; >+ >+ GenModelConfigurationPage(String pageId, ResourceLocationProvider rlp, ResourceSet resourceSet) { >+ super(pageId, rlp, resourceSet); >+ } >+ >+ protected String getModelFileExtension() { >+ return FILE_EXT_GENMODEL; >+ } >+ >+ @Override >+ protected void createAdditionalControls(Composite parent) { >+ Composite createComposite = new Composite(parent, SWT.NONE); >+ createComposite.setLayout(new GridLayout(2, true)); >+ createComposite.setLayoutData(createGridData()); >+ >+ createWizardBtn = new Button(createComposite, SWT.PUSH); >+ createWizardBtn.setText(Messages.getString("GenModelConfigurationPage.btn_new_model")); //$NON-NLS-1$ >+ createWizardBtn.setLayoutData(new GridData()); >+ >+ createDefaultBtn = new Button(createComposite, SWT.PUSH); >+ createDefaultBtn.setText(Messages.getString("GenModelConfigurationPage.btn_default_model")); //$NON-NLS-1$ >+ createDefaultBtn.setLayoutData(new GridData()); >+ >+ Composite staleComposite = new Composite(parent, SWT.NONE); >+ staleComposite.setLayout(new GridLayout()); >+ staleComposite.setLayoutData(createGridData()); >+ >+ detectStaleBtn = new Button(staleComposite, SWT.CHECK); >+ detectStaleBtn.setText(Messages.getString("GenModelConfigurationPage.check_detect_stale")); //$NON-NLS-1$ >+ detectStaleBtn.setLayoutData(new GridData()); >+ >+ refreshStaleBtn = new Button(staleComposite, SWT.PUSH); >+ refreshStaleBtn.setText(Messages.getString("GenModelConfigurationPage.btn_refresh")); //$NON-NLS-1$ >+ refreshStaleBtn.setLayoutData(new GridData()); >+ >+ SelectionAdapter selectionAdapter = new SelectionAdapter() { >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ handleSelection(e.widget); >+ } >+ }; >+ createWizardBtn.addSelectionListener(selectionAdapter); >+ createDefaultBtn.addSelectionListener(selectionAdapter); >+ detectStaleBtn.addSelectionListener(selectionAdapter); >+ refreshStaleBtn.addSelectionListener(selectionAdapter); >+ } >+ >+ private GridData createGridData() { >+ GridData gd = new GridData(); >+ gd.horizontalAlignment = GridData.FILL; >+ gd.grabExcessHorizontalSpace = true; >+ return gd; >+ } >+ >+ void handleSelection(Widget w) { >+ if (createDefaultBtn.equals(w)){ >+ createDefault(); >+ } else if (createWizardBtn.equals(w)) { >+ launchWizard(); >+ } else if (detectStaleBtn.equals(w)) { >+ handleDetect(detectStaleBtn.getSelection()); >+ } else if (refreshStaleBtn.equals(w)) { >+ refreshGenmodel(); >+ } >+ } >+ >+ @Override >+ protected void initControls() { >+ super.initControls(); >+ if (getURI() == null) { >+ findGenmodel(); >+ } else { >+ updateControls(); >+ } >+ } >+ >+ void findGenmodel() { >+ try { >+ GenModel genModel = getOperation().findGenmodel(getResourceSet()); >+ Resource r = genModel.eResource(); >+ URI genURI = r.getURI(); >+ setURI(genURI); >+ updateURI(); >+ } catch (CoreException e) { >+ setErrorMessage(e.getMessage()); >+ updateControls(); >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.gmf.internal.common.ui.ModelSelectionPage#resourceChanged() >+ */ >+ @Override >+ protected void resourceChanged() { >+ super.resourceChanged(); >+ updateControls(); >+ } >+ >+ private void updateControls() { >+ GenModelDetector gmd = getOperation().getGenModelDetector(); >+ if (gmd!= null) { >+ createDefaultBtn.setEnabled(gmd.canCreateDefault()); >+ } >+ boolean detectStale = getOperation().getOptions().getDetectStaleGenmodel(); >+ detectStaleBtn.setSelection(detectStale); >+ detectStaleBtn.setEnabled(getURI() != null); >+ refreshStaleBtn.setEnabled(detectStaleBtn.isEnabled() && detectStale); >+ } >+ >+ @Override >+ protected Resource doLoadResource(IProgressMonitor monitor) throws CoreException { >+ GenModel genModel = getOperation().loadGenModel(getResourceSet(), getURI(), monitor); >+ return genModel.eResource(); >+ } >+ >+ private void createDefault() { >+ try { >+ TransformToGenModelOperation to = getOperation(); >+ GenModelDetector gmd = to.getGenModelDetector(); >+ URI mapURI = to.getMapURI(); >+ IFile mapFile = URIUtil.getFile(mapURI); >+ String pluginID = mapFile.getProject().getName(); >+ IFile genmodel = gmd.createDefault(pluginID, mapFile); >+ URI genURI = URI.createPlatformResourceURI(genmodel.getFullPath().toString(), true); >+ setURI(genURI); >+ updateURI(); >+ } catch (CoreException e) { >+ setErrorMessage(e.getMessage()); >+ } >+ } >+ >+ private void launchWizard() { >+ URI mapURI = getOperation().getMapURI(); >+ IFile mapFile = URIUtil.getFile(mapURI); >+ IFile genmodel = createWithWizard(getShell(), mapFile); >+ if (genmodel != null) { >+ setURI(URI.createPlatformResourceURI(genmodel.getFullPath().toString(), true)); >+ updateURI(); >+ } >+ } >+ >+ private static IFile createWithWizard(Shell shell, IFile patternResource) { >+ final IFile[] result = new IFile[1]; >+ EMFModelWizard wizard = new EMFModelWizard() { >+ @Override >+ public boolean performFinish() { >+ result[0] = ResourcesPlugin.getWorkspace().getRoot().getFile(genModelContainerPath.append(genModelFileName)); >+ return super.performFinish(); >+ } >+ }; >+ wizard.init(PlatformUI.getWorkbench(), createSelectionForEMFWizard(patternResource)); >+ if (Window.OK == new WizardDialog(shell, wizard).open()) { >+ assert result[0] != null; >+ return result[0]; >+ } >+ return null; >+ } >+ private static StructuredSelection createSelectionForEMFWizard(IFile patternResource) { >+ final IContainer parent = patternResource.getParent(); >+ IFile neighbour = parent.getFile(new Path(patternResource.getName()).removeFileExtension().addFileExtension(FILE_EXT_ECORE)); >+ if (neighbour.exists()) { >+ return new StructuredSelection(neighbour); >+ } else { >+ return new StructuredSelection(patternResource); >+ } >+ } >+ >+ private void handleDetect(boolean selection) { >+ getOperation().getOptions().setDetectStaleGenmodel(selection); >+ updateControls(); >+ } >+ >+ private void refreshGenmodel() { >+ IPath p = new Path(getURI().path()).removeFirstSegments(1); >+ IFile genModelFile = ResourcesPlugin.getWorkspace().getRoot().getFile(p); >+ GenModelReloadActionDelegate action = new GenModelReloadActionDelegate(); >+ IAction uiAction = new Action() { >+ //empty >+ }; >+ action.selectionChanged(uiAction, new StructuredSelection(genModelFile)); >+ action.run(uiAction); >+ updateURI(); >+ } >+ >+ private TransformToGenModelOperation getOperation() { >+ TransformToGenModelWizard wizard = (TransformToGenModelWizard) getWizard(); >+ return wizard.getTransformOperation(); >+ } >+} >Index: .settings/org.eclipse.core.resources.prefs >=================================================================== >RCS file: .settings/org.eclipse.core.resources.prefs >diff -N .settings/org.eclipse.core.resources.prefs >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ .settings/org.eclipse.core.resources.prefs 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,3 @@ >+#Thu Jan 11 19:33:31 MSK 2007 >+eclipse.preferences.version=1 >+encoding//src/org/eclipse/gmf/internal/bridge/transform/messages.properties=8859_1 >Index: src/org/eclipse/gmf/internal/bridge/transform/GenModelDetector.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/GenModelDetector.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/GenModelDetector.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/GenModelDetector.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,154 @@ >+/* >+ * 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: >+ * Artem Tikhomirov (Borland) - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.bridge.transform; >+ >+import java.io.IOException; >+import java.util.Collection; >+import java.util.HashSet; >+import java.util.Iterator; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.emf.codegen.ecore.genmodel.GenModel; >+import org.eclipse.emf.common.util.URI; >+import org.eclipse.emf.ecore.EClass; >+import org.eclipse.emf.ecore.EPackage; >+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.EcoreUtil; >+import org.eclipse.gmf.internal.bridge.genmodel.BasicGenModelAccess; >+import org.eclipse.gmf.internal.bridge.genmodel.DummyGenModel; >+import org.eclipse.gmf.internal.bridge.genmodel.FileGenModelAccess; >+import org.eclipse.gmf.internal.bridge.genmodel.GenModelAccess; >+import org.eclipse.gmf.internal.bridge.ui.Plugin; >+import org.eclipse.gmf.mappings.Mapping; >+ >+/** >+ * Interact with user to retrieve genmodel for the domain model. XXX detect >+ * stale genmodels and reconcile them based on user's decision >+ * >+ * @author artem >+ */ >+public class GenModelDetector { >+ private final Mapping myMapping; >+ private GenModelAccess myGMAccess; >+ private Collection<EPackage> myPackages; >+ >+ public GenModelDetector(Mapping mapping) { >+ assert mapping != null; >+ myMapping = mapping; >+ } >+ >+ public IStatus detect() { >+ myPackages = findEPackages(myMapping); >+ if (myPackages.isEmpty()) { >+ myGMAccess = new GenModelAccess.Adapter(null); >+ return Status.OK_STATUS; >+ } else if (myPackages.size() == 1) { >+ final EPackage solePack = myPackages.iterator().next(); >+ BasicGenModelAccess gma = new BasicGenModelAccess(solePack); >+ gma.initDefault(); >+ return apply(gma); >+ } else { >+ return Plugin.createError(Messages.getString("GenModelDetector.error_cannot_find"), null); //$NON-NLS-1$ >+ } >+ } >+ >+ public IStatus advise(URI genModelURI) { >+ assert genModelURI != null; >+ GenModelAccess gma = new FileGenModelAccess(genModelURI); >+ return apply(gma); >+ } >+ >+ public IStatus advise(IFile workspaceFile) { >+ assert workspaceFile != null; >+ GenModelAccess gma = new FileGenModelAccess(workspaceFile); >+ return apply(gma); >+ } >+ >+ private Collection<EPackage> findEPackages(Mapping mapping) { >+ Collection<EPackage> packages = new HashSet<EPackage>(); >+ for (Iterator it = EcoreUtil.ExternalCrossReferencer.find(mapping).keySet().iterator(); it.hasNext();) { >+ Object next = it.next(); >+ if (next instanceof EClass) { >+ packages.add(((EClass) next).getEPackage()); >+ } >+ } >+ for (Iterator it = packages.iterator(); it.hasNext();) { >+ EPackage next = (EPackage) it.next(); >+ if (next.getESuperPackage() != null && EcoreUtil.isAncestor(packages, next.getESuperPackage())) { >+ it.remove(); >+ } >+ } >+ return packages; >+ } >+ >+ private IStatus apply(GenModelAccess gma) { >+ IStatus load = gma.load(new ResourceSetImpl()); >+ if (load.isOK()) { >+ gma.unload(); >+ myGMAccess = gma; >+ return Status.OK_STATUS; >+ } else { >+ return load; >+ } >+ } >+ >+ private EPackage getPrimaryPackage() { >+ if (myPackages == null || myPackages.size() == 0) { >+ return null; >+ } >+ return myPackages.iterator().next(); >+ } >+ >+ public boolean canCreateDefault() { >+ return myPackages != null && myPackages.size() == 1; >+ } >+ >+ public IFile createDefault(String pluginID, IFile patternResource) throws CoreException { >+ DummyGenModel gma = new DummyGenModel(getPrimaryPackage(), null); >+ gma.setPluginID(pluginID); >+ GenModel model = gma.create(); >+ IPath path = patternResource.getFullPath().removeFileExtension().addFileExtension("genmodel"); //$NON-NLS-1$ >+ Resource res = new ResourceSetImpl().createResource(URI.createPlatformResourceURI(path.toString(), true)); >+ res.getContents().add(model); >+ try { >+ res.save(null); >+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); >+ return file; >+ } catch (IOException ex) { >+ IStatus error = Plugin.createError(Messages.getString("GenModelDetector.error_cannot_save"), ex); //$NON-NLS-1$ >+ throw new CoreException(error); >+ } >+ } >+ >+ public GenModel get(ResourceSet resSet) { >+ if (myGMAccess == null) { >+ throw new IllegalStateException(Messages.getString("GenModelDetector.error_no_genmodelaccess")); //$NON-NLS-1$ >+ } >+ IStatus s = myGMAccess.load(resSet); >+ if (!s.isOK()) { >+ throw new IllegalStateException(s.getMessage()); >+ } >+ return myGMAccess.model(); >+ } >+ >+ public boolean checkState() { >+ return myGMAccess != null; >+ } >+ >+} >Index: src/org/eclipse/gmf/internal/bridge/transform/MapModelConfigurationPage.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/MapModelConfigurationPage.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/MapModelConfigurationPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/MapModelConfigurationPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,99 @@ >+/** >+ * 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: >+ * Alexander Fedorov (Borland) - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.bridge.transform; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.emf.common.util.URI; >+import org.eclipse.emf.ecore.resource.Resource; >+import org.eclipse.emf.ecore.resource.ResourceSet; >+import org.eclipse.gmf.internal.common.ui.ResourceLocationProvider; >+import org.eclipse.gmf.mappings.Mapping; >+import org.eclipse.jface.resource.JFaceResources; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Combo; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Widget; >+ >+ >+class MapModelConfigurationPage extends ModelConfigurationPage { >+ >+ private static final String FILE_EXT_GMFMAP = "gmfmap"; //$NON-NLS-1$ >+ >+ private Combo loadProblemsLevel; >+ >+ MapModelConfigurationPage(String pageId, ResourceLocationProvider rlp, ResourceSet resourceSet) { >+ super(pageId, rlp, resourceSet); >+ } >+ >+ protected String getModelFileExtension() { >+ return FILE_EXT_GMFMAP; >+ } >+ >+ @Override >+ protected void createAdditionalControls(Composite parent) { >+ super.createAdditionalControls(parent); >+ Composite group = new Composite(parent, SWT.NONE); >+ group.setLayout(new GridLayout(2, false)); >+ group.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_CENTER)); >+ Label labelControl= new Label(group, SWT.LEFT); >+ labelControl.setFont(JFaceResources.getDialogFont()); >+ labelControl.setText(Messages.getString("MapModelConfigurationPage.lbl_severity")); //$NON-NLS-1$ >+ loadProblemsLevel = new Combo(group, SWT.READ_ONLY); >+ String[] items = new String[]{Messages.getString("MapModelConfigurationPage.lbl_info"), Messages.getString("MapModelConfigurationPage.lbl_warning"), Messages.getString("MapModelConfigurationPage.lbl_error")}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ loadProblemsLevel.setItems(items); >+ loadProblemsLevel.setFont(JFaceResources.getDialogFont()); >+ >+ SelectionListener selectionListener = new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ handleSelection(e.widget); >+ } >+ }; >+ loadProblemsLevel.addSelectionListener(selectionListener); >+ } >+ >+ void handleSelection(Widget w) { >+ if (loadProblemsLevel.equals(w)){ >+ getOperation().getOptions().setMapdefLoadLevel(loadProblemsLevel.getSelectionIndex()); >+ } >+ } >+ >+ @Override >+ protected void initControls() { >+ super.initControls(); >+ TransformToGenModelWizard wizard = (TransformToGenModelWizard) getWizard(); >+ IFile target = wizard.getTargetFile(); >+ getOperation().setGenURI(URI.createPlatformResourceURI(target.getFullPath().toString(), true)); >+ TransformOptions o = getOperation().getOptions(); >+ loadProblemsLevel.select(o.getMapdefLoadLevel()); >+ } >+ >+ @Override >+ protected Resource doLoadResource(IProgressMonitor monitor) throws CoreException { >+ TransformToGenModelOperation o = getOperation(); >+ o.reset(getURI()); >+ Mapping mapping = o.loadMappingModel(getResourceSet(), getURI(), monitor); >+ return mapping.eResource(); >+ } >+ >+ TransformToGenModelOperation getOperation() { >+ TransformToGenModelWizard wizard = (TransformToGenModelWizard) getWizard(); >+ return wizard.getTransformOperation(); >+ } >+} >Index: src/org/eclipse/gmf/internal/bridge/transform/GMFGenConfig.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/GMFGenConfig.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/GMFGenConfig.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/GMFGenConfig.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,152 @@ >+/* >+ * 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: >+ * Michael Golubev (Borland) - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.bridge.transform; >+ >+import org.eclipse.emf.ecore.EAttribute; >+import org.eclipse.emf.ecore.EClass; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.gmf.codegen.gmfgen.GMFGenPackage; >+import org.eclipse.gmf.codegen.gmfgen.GenChildContainer; >+import org.eclipse.gmf.codegen.gmfgen.GenNode; >+import org.eclipse.gmf.internal.common.reconcile.Copier; >+import org.eclipse.gmf.internal.common.reconcile.DefaultDecisionMaker; >+import org.eclipse.gmf.internal.common.reconcile.Matcher; >+import org.eclipse.gmf.internal.common.reconcile.ReconcilerConfigBase; >+import org.eclipse.gmf.internal.common.reconcile.ReflectiveMatcher; >+import org.eclipse.gmf.internal.common.reconcile.StringPatternDecisionMaker; >+ >+/** >+ * XXX Perhaps, org.eclipse.gmf.codegen/oeg.internal.util would be better place for this class. >+ */ >+public class GMFGenConfig extends ReconcilerConfigBase { >+ private final GMFGenPackage GMFGEN = GMFGenPackage.eINSTANCE; >+ >+ public GMFGenConfig(){ >+ setMatcher(GMFGEN.getGenEditorGenerator(), ALWAYS_MATCH); >+ preserveIfSet(GMFGEN.getGenEditorGenerator(), GMFGEN.getGenEditorGenerator_CopyrightText()); >+ preserveIfSet(GMFGEN.getGenEditorGenerator(), GMFGEN.getGenEditorGenerator_PackageNamePrefix()); >+ preserveIfSet(GMFGEN.getGenEditorGenerator(), GMFGEN.getGenEditorGenerator_DomainFileExtension()); >+ preserveIfSet(GMFGEN.getGenEditorGenerator(), GMFGEN.getGenEditorGenerator_DiagramFileExtension()); >+ preserveIfSet(GMFGEN.getGenEditorGenerator(), GMFGEN.getGenEditorGenerator_SameFileForDiagramAndModel()); >+ preserveIfSet(GMFGEN.getGenEditorGenerator(), GMFGEN.getGenEditorGenerator_ModelID()); >+ preserveIfSet(GMFGEN.getGenEditorGenerator(), GMFGEN.getGenEditorGenerator_DynamicTemplates()); >+ preserveIfSet(GMFGEN.getGenEditorGenerator(), GMFGEN.getGenEditorGenerator_TemplateDirectory()); >+ >+ setMatcher(GMFGEN.getGenPlugin(), ALWAYS_MATCH); //exactly one feature for ALWAYS_MATCH GenEditorGenerator >+ preserveIfSet(GMFGEN.getGenPlugin(), GMFGEN.getGenPlugin_ID()); >+ preserveIfSet(GMFGEN.getGenPlugin(), GMFGEN.getGenPlugin_Name()); >+ preserveIfSet(GMFGEN.getGenPlugin(), GMFGEN.getGenPlugin_Provider()); >+ preserveIfSet(GMFGEN.getGenPlugin(), GMFGEN.getGenPlugin_Version()); >+ preserveIfSet(GMFGEN.getGenPlugin(), GMFGEN.getGenPlugin_ActivatorClassName()); >+ preserveIfSet(GMFGEN.getGenPlugin(), GMFGEN.getGenPlugin_PrintingEnabled()); >+ >+ setMatcher(GMFGEN.getGenEditorView(), ALWAYS_MATCH); //exactly one >+ preserveIfSet(GMFGEN.getGenEditorView(), GMFGEN.getGenEditorView_IconPath()); >+ preserveIfSet(GMFGEN.getGenEditorView(), GMFGEN.getGenEditorView_ClassName()); >+ preserveIfSet(GMFGEN.getGenEditorView(), GMFGEN.getGenEditorView_ID()); >+ >+ setMatcher(GMFGEN.getGenDiagram(), ALWAYS_MATCH); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getShortcuts_ContainsShortcutsTo()); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getShortcuts_ShortcutsProvidedFor()); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getEditorCandies_CreationWizardIconPath()); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getEditorCandies_CreationWizardCategoryID()); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getGenDiagram_Synchronized()); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getBatchValidation_ValidationEnabled()); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getBatchValidation_LiveValidationUIFeedback()); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getBatchValidation_ValidationDecorators()); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getBatchValidation_ValidationDecoratorProviderClassName()); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getBatchValidation_ValidationDecoratorProviderPriority()); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getBatchValidation_ValidationProviderClassName()); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getBatchValidation_ValidationProviderPriority()); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getBatchValidation_MetricProviderPriority()); >+ preserveIfSet(GMFGEN.getGenDiagram(), GMFGEN.getBatchValidation_MetricProviderClassName()); >+ >+ setMatcher(GMFGEN.getGenTopLevelNode(), getGenNodeMatcher()); >+ preserveIfNotByPattern(GMFGEN.getGenTopLevelNode(), GMFGEN.getGenContainerBase_CanonicalEditPolicyClassName(), ".*" + GenChildContainer.CANONICAL_EDIT_POLICY_SUFFIX); //$NON-NLS-1$ >+ preserveIfNotByPattern(GMFGEN.getGenTopLevelNode(), GMFGEN.getGenNode_GraphicalNodeEditPolicyClassName(), ".*" + GenNode.GRAPHICAL_NODE_EDIT_POLICY_SUFFIX); //$NON-NLS-1$ >+ //[155332]preserveIfNotByPattern(GMFGEN.getGenTopLevelNode(), GMFGEN.getGenCommonBase_EditPartClassName(), ".*" + GenCommonBase.EDIT_PART_SUFFIX); >+ preserveIfSet(GMFGEN.getGenTopLevelNode(), GMFGEN.getGenNode_PrimaryDragEditPolicyQualifiedClassName()); >+ >+ setMatcher(GMFGEN.getGenChildNode(), getGenNodeMatcher()); >+ preserveIfNotByPattern(GMFGEN.getGenChildNode(), GMFGEN.getGenContainerBase_CanonicalEditPolicyClassName(), ".*" + GenChildContainer.CANONICAL_EDIT_POLICY_SUFFIX); //$NON-NLS-1$ >+ preserveIfNotByPattern(GMFGEN.getGenChildNode(), GMFGEN.getGenNode_GraphicalNodeEditPolicyClassName(), ".*" + GenNode.GRAPHICAL_NODE_EDIT_POLICY_SUFFIX); //$NON-NLS-1$ >+ //[155332]preserveIfNotByPattern(GMFGEN.getGenChildNode(), GMFGEN.getGenCommonBase_EditPartClassName(), ".*" + GenCommonBase.EDIT_PART_SUFFIX); >+ preserveIfSet(GMFGEN.getGenChildNode(), GMFGEN.getGenNode_PrimaryDragEditPolicyQualifiedClassName()); >+ >+ setMatcher(GMFGEN.getGenChildLabelNode(), getGenNodeMatcher()); >+ preserveIfSet(GMFGEN.getGenChildLabelNode(), GMFGEN.getGenNode_PrimaryDragEditPolicyQualifiedClassName()); >+ >+ setMatcher(GMFGEN.getGenChildSideAffixedNode(), getGenNodeMatcher()); >+ preserveIfSet(GMFGEN.getGenChildSideAffixedNode(), GMFGEN.getGenNode_PrimaryDragEditPolicyQualifiedClassName()); >+ >+ setMatcher(GMFGEN.getGenCompartment(), new ReflectiveMatcher(GMFGEN.getGenCompartment_Title())); >+ preserveIfSet(GMFGEN.getGenCompartment(), GMFGEN.getGenCompartment_ListLayout()); >+ preserveIfSet(GMFGEN.getGenCompartment(), GMFGEN.getGenCompartment_CanCollapse()); >+ preserveIfSet(GMFGEN.getGenCompartment(), GMFGEN.getGenCompartment_HideIfEmpty()); >+ preserveIfSet(GMFGEN.getGenCompartment(), GMFGEN.getGenCompartment_NeedsTitle()); >+ //[155332]preserveIfNotByPattern(GMFGEN.getGenCompartment(), GMFGEN.getGenCommonBase_EditPartClassName(), ".*" + GenCommonBase.EDIT_PART_SUFFIX); >+ >+ //if parent node is matched, then viemap is matched automatically because it is [1] feature. >+ //there are nothing to reconcile for viewmaps, all their properties are derived >+ //we need this only to dig into viewmap attributes >+ setMatcherForAllSubclasses(GMFGEN.getViewmap(), ALWAYS_MATCH); >+ >+ setMatcher(GMFGEN.getDefaultSizeAttributes(), ALWAYS_MATCH); >+ setCopier(GMFGEN.getDefaultSizeAttributes(), Copier.COMPLETE_COPY); >+ preserveIfSet(GMFGEN.getDefaultSizeAttributes(), GMFGEN.getDefaultSizeAttributes_Height()); >+ preserveIfSet(GMFGEN.getDefaultSizeAttributes(), GMFGEN.getDefaultSizeAttributes_Width()); >+ >+ // provided GenCommonBase matched, custom behaviour should be kept as is >+ setMatcher(GMFGEN.getCustomBehaviour(), ALWAYS_MATCH); >+ setCopier(GMFGEN.getCustomBehaviour(), Copier.COMPLETE_COPY); >+ >+ setMatcher(GMFGEN.getMetamodelType(), ALWAYS_MATCH); >+ preserveIfSet(GMFGEN.getMetamodelType(), GMFGEN.getElementType_DisplayName()); >+ preserveIfSet(GMFGEN.getMetamodelType(), GMFGEN.getElementType_DefinedExternally()); >+ >+ setMatcher(GMFGEN.getSpecializationType(), ALWAYS_MATCH); >+ preserveIfSet(GMFGEN.getSpecializationType(), GMFGEN.getElementType_DisplayName()); >+ preserveIfSet(GMFGEN.getSpecializationType(), GMFGEN.getElementType_DefinedExternally()); >+ >+ setMatcher(GMFGEN.getGenPropertySheet(), ALWAYS_MATCH); >+ preserveIfSet(GMFGEN.getGenPropertySheet(), GMFGEN.getGenPropertySheet_ReadOnly()); >+ preserveIfSet(GMFGEN.getGenPropertySheet(), GMFGEN.getGenPropertySheet_NeedsCaption()); >+ preserveIfSet(GMFGEN.getGenPropertySheet(), GMFGEN.getGenPropertySheet_PackageName()); >+ preserveIfSet(GMFGEN.getGenPropertySheet(), GMFGEN.getGenPropertySheet_LabelProviderClassName()); >+ >+ setMatcherForAllSubclasses(GMFGEN.getGenPropertyTab(), new ReflectiveMatcher(GMFGEN.getGenPropertyTab_ID())); >+ preserveIfSet(GMFGEN.getGenStandardPropertyTab(),GMFGEN.getGenPropertyTab_Label()); >+ >+ preserveIfSet(GMFGEN.getGenCustomPropertyTab(),GMFGEN.getGenPropertyTab_Label()); >+ preserveIfSet(GMFGEN.getGenCustomPropertyTab(),GMFGEN.getGenCustomPropertyTab_ClassName()); >+ } >+ >+ private Matcher getGenNodeMatcher(){ >+ //FIXME: use new AttributeMatcher("domainMetaClass") >+ return new ReflectiveMatcher(GMFGenPackage.eINSTANCE.getGenNode(), new ReflectiveMatcher.Reflector(){ >+ public Object reflect(EObject target) { >+ GenNode genNode = (GenNode)target; >+ return genNode.getDomainMetaClass(); >+ } >+ }); >+ } >+ >+ private void preserveIfSet(EClass eClass, EAttribute feature){ >+ //FIXME: only attributes for now, allow references >+ addDecisionMaker(eClass, new DefaultDecisionMaker(feature)); >+ } >+ >+ private void preserveIfNotByPattern(EClass eClass, EAttribute feature, String pattern){ >+ addDecisionMaker(eClass, new StringPatternDecisionMaker(pattern, feature)); >+ } >+ >+} >Index: src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelOperation.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelOperation.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelOperation.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelOperation.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,328 @@ >+/** >+ * 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: >+ * Alexander Fedorov (Borland) - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.bridge.transform; >+ >+import java.io.IOException; >+import java.util.HashMap; >+import java.util.List; >+import java.util.Map; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.SubProgressMonitor; >+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.xmi.XMLResource; >+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.ViewmapProducer; >+import org.eclipse.gmf.internal.bridge.naming.gen.GenModelNamingMediatorImpl; >+import org.eclipse.gmf.internal.bridge.ui.Plugin; >+import org.eclipse.gmf.internal.common.migrate.ModelLoadHelper; >+import org.eclipse.gmf.internal.common.reconcile.Reconciler; >+import org.eclipse.gmf.mappings.Mapping; >+ >+ >+public class TransformToGenModelOperation { >+ >+ private URI myMapModelURI; >+ private URI myGMFGenModelURI; >+ private TransformOptions myOptions; >+ private Mapping myMapping; >+ private GenModelDetector myGMDetector; >+ private GenModel myGenModel; >+ >+ public TransformToGenModelOperation(URI mapURI) { >+ assert mapURI != null; >+ this.myMapModelURI = mapURI; >+ this.myOptions = new TransformOptions(); >+ } >+ >+ public TransformOptions getOptions() { >+ return myOptions; >+ } >+ >+ public URI getMapURI() { >+ return this.myMapModelURI; >+ } >+ >+ public URI getGenURI() { >+ return this.myGMFGenModelURI; >+ } >+ >+ void setGenURI(URI gmfGen) { >+ this.myGMFGenModelURI = gmfGen; >+ } >+ >+ private GenModel getGenModel() { >+ return this.myGenModel; >+ } >+ >+ Mapping getMapping() { >+ return this.myMapping; >+ } >+ >+ private void setMapping(Mapping m) { >+ this.myMapping = m; >+ myGMDetector = null; >+ myGenModel = null; >+ } >+ >+ GenModelDetector getGenModelDetector() { >+ if (myGMDetector == null) { >+ myGMDetector = new GenModelDetector(getMapping()); >+ } >+ return myGMDetector; >+ } >+ >+ Mapping loadMappingModel(ResourceSet rs, URI uri, IProgressMonitor pm) throws CoreException { >+ IProgressMonitor monitor = null; >+ try { >+ monitor = (pm != null) ? new SubProgressMonitor(pm, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK) : new NullProgressMonitor(); >+ IStatus cancel = Plugin.createCancel(Messages.getString("TransformToGenModelOperation.cancel_mapping_model_load")); //$NON-NLS-1$ >+ CoreException cancelled = new CoreException(cancel); >+ >+ monitor.beginTask("", 100); //$NON-NLS-1$ >+ if (monitor.isCanceled()) { >+ throw cancelled; >+ } >+ monitor.subTask(Messages.getString("TransformToGenModelOperation.task_loading")); //$NON-NLS-1$ >+ ModelLoadHelper loadHelper = new ModelLoadHelper(rs, uri); >+ IStatus loadStatus = loadHelper.getStatus(); >+ if (!loadStatus.isOK()) { >+ throw new CoreException(loadStatus); >+ } >+ monitor.worked(20); >+ >+ if (monitor.isCanceled()) { >+ throw cancelled; >+ } >+ monitor.subTask(Messages.getString("TransformToGenModelOperation.task_validating")); //$NON-NLS-1$ >+ final Mapping content = (Mapping) loadHelper.getContentsRoot(); >+ Diagnostic mapIsValid = ValidationHelper.validate(content, true, monitor); >+ int severity = mapIsValid.getSeverity(); >+ monitor.worked(60); >+ if (!getOptions().checkMapdefLoadLevel(mapIsValid)) { >+ if (Diagnostic.CANCEL == severity) { >+ throw cancelled; >+ } else { >+ throw new CoreException(getFirst(mapIsValid)); >+ } >+ } >+ setMapping(content); >+ return content; >+ } finally { >+ monitor.done(); >+ } >+ } >+ >+ GenModel findGenmodel(ResourceSet rs) throws CoreException { >+ try { >+ GenModelDetector gmd = getGenModelDetector(); >+ IStatus detect = gmd.detect(); >+ if (detect.isOK()) { >+ GenModel genModel = gmd.get(rs); >+ this.myGenModel = genModel; >+ return genModel; >+ } >+ throw new CoreException(detect); >+ >+ } catch (CoreException e) { >+ throw e; >+ } catch (Exception e) { >+ IStatus error = Plugin.createError(Messages.getString("TransformToGenModelOperation.error_invalid_mapping_model"), e); //$NON-NLS-1$ >+ throw new CoreException(error); >+ } >+ } >+ >+ GenModel loadGenModel(ResourceSet rs, URI uri, IProgressMonitor pm) throws CoreException { >+ try { >+ GenModelDetector gmd = getGenModelDetector(); >+ IStatus status = Status.OK_STATUS; >+ if (uri == null) { >+ status = gmd.detect(); >+ } else { >+ status = gmd.advise(uri); >+ } >+ if (!status.isOK()) { >+ throw new CoreException(status); >+ } >+ GenModel genModel = gmd.get(rs); >+ if (getOptions().getDetectStaleGenmodel()) { >+ StaleGenModelDetector staleDetector = new StaleGenModelDetector(genModel); >+ IStatus stale = staleDetector.detect(); >+ if (!stale.isOK()) { >+ throw new CoreException(stale); >+ } >+ } >+ this.myGenModel = genModel; >+ return genModel; >+ >+ } catch (CoreException e) { >+ throw e; >+ } catch (Exception e) { >+ IStatus error = Plugin.createError(Messages.getString("TransformToGenModelOperation.error_load_genmodel"), e); //$NON-NLS-1$ >+ throw new CoreException(error); >+ } >+ } >+ >+ IStatus executeTransformation(ResourceSet rs, IProgressMonitor pm) { >+ IProgressMonitor monitor = null; >+ try { >+ monitor = (pm != null) ? new SubProgressMonitor(pm, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK) : new NullProgressMonitor(); >+ monitor.beginTask("", 100); //$NON-NLS-1$ >+ if (monitor.isCanceled()) { >+ return Status.CANCEL_STATUS; >+ } >+ final DiagramRunTimeModelHelper drtModelHelper = detectRunTimeModel(); >+ final ViewmapProducer viewmapProducer = detectTransformationOptions(); >+ final VisualIdentifierDispenserProvider idDispenser = getVisualIdDispenser(); >+ idDispenser.acquire(); >+ >+ GenModelProducer t = createGenModelProducer(getGenModel(), drtModelHelper, viewmapProducer, idDispenser.get()); >+ >+ monitor.subTask(Messages.getString("TransformToGenModelOperation.task_generating")); //$NON-NLS-1$ >+ GenEditorGenerator genEditor = t.process(getMapping(), new SubProgressMonitor(monitor, 20)); >+ if (monitor.isCanceled()) { >+ return Status.CANCEL_STATUS; >+ } >+ monitor.subTask(Messages.getString("TransformToGenModelOperation.task_reconciling")); //$NON-NLS-1$ >+ if (Plugin.needsReconcile()) { >+ reconcile(rs, genEditor); >+ } >+ monitor.worked(20); >+ if (monitor.isCanceled()) { >+ return Status.CANCEL_STATUS; >+ } >+ monitor.subTask(Messages.getString("TransformToGenModelOperation.task_saving")); //$NON-NLS-1$ >+ save(rs, genEditor); >+ monitor.worked(20); >+ if (monitor.isCanceled()) { >+ return Status.CANCEL_STATUS; >+ } >+ monitor.subTask(Messages.getString("TransformToGenModelOperation.task_validating")); //$NON-NLS-1$ >+ return validate(genEditor, monitor); >+ >+ } catch (Exception ex) { >+ return Plugin.createError(ex.getMessage(), ex); >+ } finally { >+ if (monitor != null) { >+ monitor.done(); >+ } >+ } >+ } >+ >+ public void reset(URI uri) { >+ assert uri != null; >+ myMapModelURI = uri; >+ setMapping(null); >+ } >+ >+ private IStatus getFirst(Diagnostic d) { >+ if (d == null) { >+ return Status.OK_STATUS; >+ } >+ List<Diagnostic> children = d.getChildren(); >+ if (children.isEmpty()) { >+ return BasicDiagnostic.toIStatus(d); >+ } else { >+ return BasicDiagnostic.toIStatus(children.get(0)); >+ } >+ } >+ >+ private DiagramRunTimeModelHelper detectRunTimeModel() { >+ return new BasicDiagramRunTimeModelHelper(); >+ } >+ >+ private ViewmapProducer detectTransformationOptions() { >+ FigureQualifiedNameSwitch fSwitch = getOptions().getUseRuntimeFigures() ? new RuntimeFQNSwitch() : new RuntimeLiteFQNSwitch(); >+ MapModeCodeGenStrategy mmStrategy = getOptions().getUseMapMode() ? MapModeCodeGenStrategy.DYNAMIC : MapModeCodeGenStrategy.STATIC; >+ return new InnerClassViewmapProducer(fSwitch, mmStrategy); >+ } >+ >+ private VisualIdentifierDispenserProvider getVisualIdDispenser() { >+ return new VisualIdentifierDispenserProvider(getGenURI()); >+ } >+ >+ private GenModelProducer createGenModelProducer(GenModel domainGenModel, final DiagramRunTimeModelHelper drtModelHelper, final ViewmapProducer viewmapProducer, final VisualIdentifierDispenser idDespenser) { >+ final DiagramGenModelTransformer t = new DiagramGenModelTransformer(drtModelHelper, new GenModelNamingMediatorImpl(), viewmapProducer, idDespenser, getOptions().getGenerateRCP()); >+ 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(); >+ } >+ } >+ }; >+ } >+ >+ private void reconcile(ResourceSet rs, GenEditorGenerator genBurdern) { >+ GenEditorGenerator old = null; >+ Resource resource = null; >+ try { >+ resource = rs.getResource(getGenURI(), 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 void save(ResourceSet rs, GenEditorGenerator genBurdern) throws IOException { >+ Resource dgmmRes = rs.createResource(getGenURI()); >+ dgmmRes.getContents().add(genBurdern); >+ dgmmRes.save(getSaveOptions()); >+ } >+ >+ private Map getSaveOptions() { >+ HashMap<String, Object> saveOptions = new HashMap<String, Object>(); >+ saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$ >+ return saveOptions; >+ } >+ >+ private IStatus validate(GenEditorGenerator genBurdern, IProgressMonitor monitor) { >+ Diagnostic d = ValidationHelper.validate(genBurdern, true, monitor); >+ return getFirst(d); >+ } >+} >Index: src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelWizard.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelWizard.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelWizard.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelWizard.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,160 @@ >+/** >+ * 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: >+ * Alexander Fedorov (Borland) - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.bridge.transform; >+ >+import java.lang.reflect.InvocationTargetException; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+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.gmf.codegen.gmfgen.presentation.EditorPlugin; >+import org.eclipse.gmf.codegen.gmfgen.presentation.GMFGenModelWizard; >+import org.eclipse.gmf.internal.bridge.wizards.WizardUtil; >+import org.eclipse.gmf.internal.common.ui.ResourceLocationProvider; >+import org.eclipse.jface.operation.IRunnableWithProgress; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.wizard.WizardDialog; >+import org.eclipse.jface.wizard.WizardPage; >+import org.eclipse.ui.IWorkbench; >+ >+ >+public class TransformToGenModelWizard extends GMFGenModelWizard { >+ >+ private static final String PAGE_ID_GENMODEL = "genmodel"; //$NON-NLS-1$ >+ private static final String PAGE_ID_GMFMAP = "gmfmap"; //$NON-NLS-1$ >+ private static final String PAGE_ID_TRANSFORM = "transform"; //$NON-NLS-1$ >+ >+ protected MapModelConfigurationPage mapModelPage; >+ protected GenModelConfigurationPage genModelPage; >+ protected ViewmapProducerWizardPage transformOptionPage; >+ >+ private TransformToGenModelOperation myOperation; >+ ResourceSet resourceSet; >+ >+ @Override >+ public void addPages() { >+ super.addPages(); >+ >+ final String defaultName = EditorPlugin.INSTANCE.getString("_UI_GMFGenEditorFilenameDefaultBase"); //$NON-NLS-1$ >+ final String extension = EditorPlugin.INSTANCE.getString("_UI_GMFGenEditorFilenameExtension"); //$NON-NLS-1$ >+ newFileCreationPage.setFileName(WizardUtil.getDefaultFileName(selection, defaultName, extension)); >+ >+ resourceSet = new ResourceSetImpl(); >+ ResourceLocationProvider rlp = new ResourceLocationProvider(selection); >+ mapModelPage = new MapModelConfigurationPage(PAGE_ID_GMFMAP, rlp, resourceSet); >+ mapModelPage.setTitle(Messages.getString("TransformToGenModelWizard.title_map_model")); //$NON-NLS-1$ >+ mapModelPage.setDescription(Messages.getString("TransformToGenModelWizard.descr_map_model")); //$NON-NLS-1$ >+ mapModelPage.setPageComplete(false); >+ mapModelPage.setModelRequired(true); >+ addPage(mapModelPage); >+ >+ genModelPage = new GenModelConfigurationPage(PAGE_ID_GENMODEL, rlp, resourceSet); >+ genModelPage.setTitle(Messages.getString("TransformToGenModelWizard.title_gen_model")); //$NON-NLS-1$ >+ genModelPage.setDescription(Messages.getString("TransformToGenModelWizard.descr_gen_model")); //$NON-NLS-1$ >+ genModelPage.setPageComplete(false); >+ genModelPage.setModelRequired(true); >+ addPage(genModelPage); >+ >+ transformOptionPage = new ViewmapProducerWizardPage(PAGE_ID_TRANSFORM); >+ transformOptionPage.setTitle(Messages.getString("TransformToGenModelWizard.title_options")); //$NON-NLS-1$ >+ transformOptionPage.setDescription(Messages.getString("TransformToGenModelWizard.descr_options")); //$NON-NLS-1$ >+ transformOptionPage.setPageComplete(false); >+ addPage(transformOptionPage); >+ >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.gmf.codegen.gmfgen.presentation.GMFGenModelWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) >+ */ >+ @Override >+ public void init(IWorkbench w, IStructuredSelection ss) { >+ super.init(w, ss); >+ setWindowTitle(Messages.getString("TransformToGenModelWizard.title_wizard")); //$NON-NLS-1$ >+ setNeedsProgressMonitor(true); >+ IFile mapFile = (IFile) ss.getFirstElement(); >+ URI mapURI = URI.createPlatformResourceURI(mapFile.getFullPath().toString(), true); >+ initOperation(mapURI); >+ } >+ >+ void initOperation(URI mapURI) { >+ myOperation = new TransformToGenModelOperation(mapURI); >+ } >+ >+ @Override >+ public boolean performFinish() { >+ try { >+ final IStatus[] s = new IStatus[1]; >+ IRunnableWithProgress iwr = new IRunnableWithProgress() { >+ public void run(IProgressMonitor monitor) { >+ s[0] = getTransformOperation().executeTransformation(resourceSet, monitor); >+ } >+ }; >+ getContainer().run(false, false, iwr); >+ if (s[0].isOK()) { >+ setErrorMessage(null); >+ saveTransformOptions(); >+ return true; >+ } >+ setErrorMessage(s[0].getMessage()); >+ return false; >+ } catch (InvocationTargetException ex) { >+ Throwable targetException = ex.getTargetException(); >+ if (targetException != null && targetException.getMessage() != null) { >+ String message = targetException.getMessage(); >+ if (message == null) { >+ message = Messages.getString("TransformToGenModelWizard.error_transform"); //$NON-NLS-1$ >+ } >+ } >+ return false; >+ } catch (InterruptedException ex){ >+ setErrorMessage(Messages.getString("TransformToGenModelWizard.cancel_transform")); //$NON-NLS-1$ >+ return false; >+ } >+ } >+ >+ private void saveTransformOptions() { >+ if (getTransformOperation() != null) { >+ getTransformOperation().getOptions().flush(); >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.wizard.Wizard#performCancel() >+ */ >+ @Override >+ public boolean performCancel() { >+ if (getTransformOperation() != null) { >+ getTransformOperation().getOptions().reset(); >+ } >+ return super.performCancel(); >+ } >+ >+ TransformToGenModelOperation getTransformOperation() { >+ return myOperation; >+ } >+ >+ IFile getTargetFile() { >+ return newFileCreationPage.getModelFile(); >+ } >+ >+ private void setErrorMessage(String message) { >+ WizardDialog wd = (WizardDialog) getContainer(); >+ WizardPage wp = (WizardPage) wd.getCurrentPage(); >+ if (wp != null) { >+ wp.setErrorMessage(message); >+ } >+ } >+ >+} >Index: src/org/eclipse/gmf/internal/bridge/transform/TransformOptions.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/TransformOptions.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/TransformOptions.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/TransformOptions.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,142 @@ >+/** >+ * 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: >+ * Alexander Fedorov (Borland) - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.bridge.transform; >+ >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Preferences; >+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; >+import org.eclipse.core.runtime.preferences.DefaultScope; >+import org.eclipse.core.runtime.preferences.IEclipsePreferences; >+import org.eclipse.emf.common.util.Diagnostic; >+import org.eclipse.gmf.internal.bridge.ui.Plugin; >+ >+ >+public class TransformOptions extends AbstractPreferenceInitializer { >+ >+ public static final String PREF_MAPDEF_LOAD_LEVEL = "mapdef_load_level"; //$NON-NLS-1$ >+ public static final String PREF_GENMODEL_DETECT_STALE = "genmodel_detect_stale"; //$NON-NLS-1$ >+ public static final String PREF_GENERATE_RCP = "generate_rcp"; //$NON-NLS-1$ >+ public static final String PREF_USE_MAP_MODE = "use_map_mode"; //$NON-NLS-1$ >+ public static final String PREF_USE_RUNTIME_FIGURES = "use_runtime_figures"; //$NON-NLS-1$ >+ >+ private static int VAL_MAPDEF_LOAD_LEVEL_INFO = 0; >+ private static int VAL_MAPDEF_LOAD_LEVEL_WARNING = 1; >+ private static int VAL_MAPDEF_LOAD_LEVEL_ERROR = 2; >+ >+ private Preferences myPreferences; >+ >+ public TransformOptions() { >+ myPreferences = new Preferences(); >+ reset(); >+ } >+ >+ private Preferences getPreferences() { >+ return myPreferences; >+ } >+ >+ public void reset() { >+ Preferences pluginPrefs = Plugin.getDefault().getPluginPreferences(); >+ copyPreferences(pluginPrefs, myPreferences); >+ } >+ >+ public void flush() { >+ Preferences pluginPrefs = Plugin.getDefault().getPluginPreferences(); >+ copyPreferences(myPreferences, pluginPrefs); >+ Plugin.getDefault().savePluginPreferences(); >+ } >+ >+ private void copyPreferences(Preferences source, Preferences target) { >+ String[] propNames = source.propertyNames(); >+ for (int i = 0; i < propNames.length; i++) { >+ String name = propNames[i]; >+ String value = source.getString(name); >+ target.setValue(name, value); >+ } >+ } >+ >+ public boolean checkMapdefLoadLevel(Diagnostic diagnostic) { >+ if (diagnostic == null) { >+ return false; >+ } >+ int severity = diagnostic.getSeverity(); >+ int level = getMapdefLoadLevel(); >+ if (VAL_MAPDEF_LOAD_LEVEL_INFO == level) { >+ return Diagnostic.INFO >= severity; >+ } else if (VAL_MAPDEF_LOAD_LEVEL_WARNING == level) { >+ return Diagnostic.WARNING >= severity; >+ } else if (VAL_MAPDEF_LOAD_LEVEL_ERROR == level) { >+ return Diagnostic.ERROR >= severity; >+ } >+ return Diagnostic.CANCEL == severity; >+ } >+ >+ public int getMapdefLoadLevel() { >+ return getPreferences().getInt(PREF_MAPDEF_LOAD_LEVEL); >+ } >+ >+ public boolean getDetectStaleGenmodel() { >+ return getPreferences().getBoolean(PREF_GENMODEL_DETECT_STALE); >+ } >+ >+ public boolean getGenerateRCP() { >+ return getPreferences().getBoolean(PREF_GENERATE_RCP); >+ } >+ >+ public boolean getUseMapMode() { >+ return getPreferences().getBoolean(PREF_USE_MAP_MODE); >+ } >+ >+ public boolean getUseRuntimeFigures() { >+ return getPreferences().getBoolean(PREF_USE_RUNTIME_FIGURES); >+ } >+ >+ public void setMapdefLoadLevel(int value) { >+ getPreferences().setValue(PREF_MAPDEF_LOAD_LEVEL, value); >+ } >+ >+ public void setDetectStaleGenmodel(boolean value) { >+ getPreferences().setValue(PREF_GENMODEL_DETECT_STALE, value); >+ } >+ >+ public void setGenerateRCP(boolean value) { >+ getPreferences().setValue(PREF_GENERATE_RCP, value); >+ } >+ >+ public void setUseMapMode(boolean value) { >+ getPreferences().setValue(PREF_USE_MAP_MODE, value); >+ } >+ >+ public void setUseRuntimeFigures(boolean value) { >+ getPreferences().setValue(PREF_USE_RUNTIME_FIGURES, value); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() >+ */ >+ @Override >+ public void initializeDefaultPreferences() { >+ DefaultScope scope = new DefaultScope(); >+ IEclipsePreferences node = scope.getNode(Plugin.getPluginID()); >+ node.putInt(PREF_MAPDEF_LOAD_LEVEL, VAL_MAPDEF_LOAD_LEVEL_INFO); >+ node.put(PREF_GENMODEL_DETECT_STALE, Boolean.TRUE.toString()); >+ >+ node.put(PREF_GENERATE_RCP, Boolean.FALSE.toString()); >+ boolean liteOptionPresent = checkLiteOptionPresent(); >+ node.putBoolean(PREF_USE_MAP_MODE, !liteOptionPresent); >+ node.putBoolean(PREF_USE_RUNTIME_FIGURES, !liteOptionPresent); >+ >+ } >+ >+ static boolean checkLiteOptionPresent() { >+ return Platform.getBundle("org.eclipse.gmf.codegen.lite") != null; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelAction.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelAction.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,62 @@ >+/* >+ * Copyright (c) 2005,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: >+ * Artem Tikhomirov (Borland) - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.bridge.transform; >+ >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.window.Window; >+import org.eclipse.jface.wizard.WizardDialog; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.ui.IObjectActionDelegate; >+import org.eclipse.ui.IWorkbenchPart; >+import org.eclipse.ui.PlatformUI; >+ >+/** >+ * .gmfmap to .gmfgen >+ * >+ * @author artem >+ */ >+public class TransformToGenModelAction implements IObjectActionDelegate { >+ >+ private static final int WIZARD_WIDTH = 500; >+ private static final int WIZARD_HEIGHT = 600; >+ >+ private IWorkbenchPart myPart; >+ >+ private IStructuredSelection sselection; >+ >+ public void setActivePart(IAction action, IWorkbenchPart targetPart) { >+ myPart = targetPart; >+ } >+ >+ public void selectionChanged(IAction action, ISelection selection) { >+ final IStructuredSelection structuredSelection = ((IStructuredSelection) selection); >+ sselection = structuredSelection; >+ } >+ >+ public void run(IAction action) { >+ final TransformToGenModelWizard wiz = new TransformToGenModelWizard(); >+ wiz.setWindowTitle(action.getText()); >+ wiz.init(PlatformUI.getWorkbench(), sselection); >+ WizardDialog wd = new WizardDialog(getShell(), wiz); >+ wd.create(); >+ wd.getShell().setSize(WIZARD_WIDTH, WIZARD_HEIGHT); >+ if (wd.open() != Window.OK) { >+ return; >+ } >+ } >+ >+ private Shell getShell() { >+ return myPart.getSite().getShell(); >+ } >+} >Index: src/org/eclipse/gmf/internal/bridge/transform/ModelConfigurationPage.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/bridge/transform/ModelConfigurationPage.java >diff -N src/org/eclipse/gmf/internal/bridge/transform/ModelConfigurationPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/bridge/transform/ModelConfigurationPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,90 @@ >+/** >+ * 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: >+ * Alexander Fedorov (Borland) - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.bridge.transform; >+ >+import java.lang.reflect.InvocationTargetException; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.core.runtime.SubProgressMonitor; >+import org.eclipse.emf.ecore.resource.Resource; >+import org.eclipse.emf.ecore.resource.ResourceSet; >+import org.eclipse.gmf.internal.bridge.ui.Plugin; >+import org.eclipse.gmf.internal.common.ui.ModelSelectionPage; >+import org.eclipse.gmf.internal.common.ui.ResourceLocationProvider; >+import org.eclipse.ui.actions.WorkspaceModifyOperation; >+ >+ >+public class ModelConfigurationPage extends ModelSelectionPage { >+ >+ public ModelConfigurationPage(String pageId, ResourceLocationProvider rlp, ResourceSet resourceSet) { >+ super(pageId, rlp, resourceSet); >+ } >+ >+ @Override >+ protected Resource loadResource() { >+ Resource current = getResource(); >+ if (current != null) { >+ current.getResourceSet().getResources().remove(current); >+ } >+ >+ final Resource[] result = new Resource[1]; >+ WorkspaceModifyOperation initializeOperation = new WorkspaceModifyOperation() >+ { >+ >+ protected void execute(IProgressMonitor progressMonitor) throws CoreException { >+ IProgressMonitor monitor = null; >+ try { >+ monitor = (progressMonitor != null) ? new SubProgressMonitor(progressMonitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK) : new NullProgressMonitor(); >+ setErrorMessage(null); >+ setMessage(null); >+ result[0] = doLoadResource(monitor); >+ } catch (CoreException exception) { >+ throw exception; >+ } catch (Exception exception) { >+ throw new CoreException(Plugin.createError(exception.getMessage(), exception)); >+ } finally { >+ if (monitor != null) { >+ monitor.done(); >+ } >+ } >+ } >+ }; >+ >+ try { >+ getContainer().run(false, false, initializeOperation); >+ setMessage(null); >+ setErrorMessage(null); >+ } catch (InvocationTargetException e) { >+ Throwable target = e.getTargetException(); >+ setErrorMessage(target.getMessage()); >+ } catch (InterruptedException e) { >+ //TODO >+ } >+ return result[0]; >+ } >+ >+ protected Resource doLoadResource(IProgressMonitor monitor) throws CoreException { >+ try { >+ Resource r = super.loadResource(); >+ return r; >+ } catch (Exception e) { >+ throw new CoreException(Plugin.createError(e.getMessage(), e)); >+ } finally { >+ if (monitor != null) { >+ monitor.done(); >+ } >+ } >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 148836
:
56787
|
57018
|
57091
|
57529
|
57530