### Eclipse Workspace Patch 1.0 #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 18 Jan 2007 16:42:59 -0000 @@ -67,4 +67,25 @@ + + + + + + + + + + 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 18 Jan 2007 16:42:59 -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 18 Jan 2007 16:42:59 -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.11 diff -u -r1.11 MANIFEST.MF --- META-INF/MANIFEST.MF 17 Jan 2007 19:30:51 -0000 1.11 +++ META-INF/MANIFEST.MF 18 Jan 2007 16:42:59 -0000 @@ -17,7 +17,8 @@ org.eclipse.gmf.graphdef.edit;bundle-version="[2.0.0,3.0.0)", org.eclipse.gmf.tooldef.edit;bundle-version="[2.0.0,3.0.0)", org.eclipse.gmf.map.edit;bundle-version="[2.0.0,3.0.0)", - org.eclipse.emf.codegen.ecore.ui;bundle-version="[2.3.0,3.0.0)" + org.eclipse.emf.codegen.ecore.ui;bundle-version="[2.3.0,3.0.0)", + org.eclipse.emf.importer;bundle-version="[2.3.0,3.0.0)" Eclipse-LazyStart: true Export-Package: org.eclipse.gmf.internal.bridge.resolver;x-internal:=true, org.eclipse.gmf.internal.bridge.ui;x-friends:="org.eclipse.gmf.bridge.ui.dashboard,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("MergingIdentifierDispenser was not found in org.eclipse.gmf.bridge.trace bundle", e)); //$NON-NLS-1$ + } catch (InstantiationException e) { + Plugin.log(Plugin.createError("MergingIdentifierDispenser was not instantiated", e)); //$NON-NLS-1$ + } catch (IllegalAccessException e) { + Plugin.log(Plugin.createError("IllegalAccessException while instantiating MergingIdentifierDispenser", e)); //$NON-NLS-1$ + } catch (ClassCastException ex) { + Plugin.log(Plugin.createError("MergingIdentifierDispenser was not instantiated", 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,35 @@ +StaleGenModelDetector_stale=Resource {0} is newer ({1,date}) than genmodel ({2,date}) +GenModelDetector_e_not_found=Can't find genmodel +GenModelDetector_e_save=Can't save created genmodel +GenModelDetector_e_no_genmodelaccess=Need to apply GenModelAccess first +GenModelConfigurationPage_btn_new_wizard=New EMF Model ... +ValidationHelper_task_validate=Validating ... +ValidationHelper_e_marker_creation=Marker creation failure +TransformToGenModelOperation_e_map_load_cancelled=Mapping model loading was interrupted +TransformToGenModelOperation_task_load=Loading ... +TransformToGenModelOperation_task_validate=Validating ... +TransformToGenModelOperation_e_mapping_invalid=Invalid Mapping Model +TransformToGenModelWizard_e_generator_creation=Errors while creating generator model +TransformToGenModelWizard_e_operation_cancelled=Operation cancelled +TransformToGenModelOperation_e_genmodel_load_cancelled=GenModel loading was interrupted +TransformToGenModelOperation_task_detect=Detecting ... +TransformToGenModelWizard_title_mapmodel=Select Mapping Model +TransformToGenModelWizard_descr_mapmodel=Load Mapping Model +TransformToGenModelWizard_title_genmodel=Select GenModel +TransformToGenModelWizard_descr_genmodel=Load GenModel or create new one +TransformToGenModelOperation_e_genmodel_load=Failed to load GenModel +TransformToGenModelOperation_task_generate=Generating ... +TransformToGenModelOperation_task_reconcile=Reconciling ... +TransformToGenModelOperation_task_save=Saving ... +TransformToGenModelWizard_title_options=Specify transformation options +TransformToGenModelWizard_title_gmfgen=GMFGen Model +TransformToGenModelWizard_title_wizard=Create generator model +TransformToGenModelWizard_descr_options=Specify transformation options +TransformToGenModelWizard_descr_gmfgen=Create a new GMFGen Model +ViewmapProducerWizardPage_btn_mapmode=Use IMapMode +ViewmapProducerWizardPage_btn_runtime=Utilize enhanced features of GMF runtime +ViewmapProducerWizardPage_btn_rcp=Generate RCP Application +ViewmapProducerWizardPage_i_not_recommended=It is not recommended to use IMapMode for pure-GEF diagram editors +GenModelConfigurationPage_btn_create_default=Default GenModel... +GenModelConfigurationPage_btn_refresh_stale=Refresh stale GenModel... +GMFGenNewFileCreationPage_e_filename=The file name must end in ".{0}" 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,97 @@ +/** + * 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 org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.gmf.internal.bridge.transform.messages"; //$NON-NLS-1$ + + public static String GenModelConfigurationPage_btn_create_default; + + public static String GenModelConfigurationPage_btn_new_wizard; + + public static String GenModelConfigurationPage_btn_refresh_stale; + + public static String GenModelDetector_e_no_genmodelaccess; + + public static String GenModelDetector_e_not_found; + + public static String GenModelDetector_e_save; + + public static String GMFGenNewFileCreationPage_e_filename; + + public static String StaleGenModelDetector_stale; + + public static String TransformToGenModelOperation_e_genmodel_load; + + public static String TransformToGenModelOperation_e_genmodel_load_cancelled; + + public static String TransformToGenModelOperation_e_map_load_cancelled; + + public static String TransformToGenModelOperation_e_mapping_invalid; + + public static String TransformToGenModelOperation_task_detect; + + public static String TransformToGenModelOperation_task_generate; + + public static String TransformToGenModelOperation_task_load; + + public static String TransformToGenModelOperation_task_reconcile; + + public static String TransformToGenModelOperation_task_save; + + public static String TransformToGenModelOperation_task_validate; + + public static String TransformToGenModelWizard_descr_genmodel; + + public static String TransformToGenModelWizard_descr_gmfgen; + + public static String TransformToGenModelWizard_descr_mapmodel; + + public static String TransformToGenModelWizard_descr_options; + + public static String TransformToGenModelWizard_e_generator_creation; + + public static String TransformToGenModelWizard_e_operation_cancelled; + + public static String TransformToGenModelWizard_title_genmodel; + + public static String TransformToGenModelWizard_title_gmfgen; + + public static String TransformToGenModelWizard_title_mapmodel; + + public static String TransformToGenModelWizard_title_options; + + public static String TransformToGenModelWizard_title_wizard; + + public static String ValidationHelper_e_marker_creation; + + public static String ValidationHelper_task_validate; + + public static String ViewmapProducerWizardPage_btn_mapmode; + + public static String ViewmapProducerWizardPage_btn_rcp; + + public static String ViewmapProducerWizardPage_btn_runtime; + + public static String ViewmapProducerWizardPage_i_not_recommended; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + // + } +} 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 ecoreURIs = new HashSet(); + 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.StaleGenModelDetector_stale; + 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.ViewmapProducerWizardPage_btn_mapmode); + useMapModeButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_CENTER)); + useRuntimeFiguresButton = new Button(result, SWT.CHECK); + useRuntimeFiguresButton.setText(Messages.ViewmapProducerWizardPage_btn_runtime); + useRuntimeFiguresButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_CENTER)); + generateRCPButton = new Button(result, SWT.CHECK); + generateRCPButton.setText(Messages.ViewmapProducerWizardPage_btn_rcp); + 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.ViewmapProducerWizardPage_i_not_recommended); + } + } + 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. + *

+ * 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 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. + *

+ * If null, the default is + * resource-problem-marker 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 getDiagnostic2MarkerMap() { + if(diagnostic2Marker == null) { + diagnostic2Marker = new LinkedHashMap(); + } + return diagnostic2Marker; + } + } + + /** + * Diagnostic to marker map data holder class. + *

+ * Note: The map iterators respect the order of marker creation. + */ + public static class DiagnosticMarkerMap { + private Map map; + + /** + * Constraint diagnostic marker from the given map data. + * @param markerMap map data to be encapsulated by the resulting object. + */ + DiagnosticMarkerMap(LinkedHashMap markerMap) { + this.map = Collections.unmodifiableMap(markerMap); + } + + /** + * Gets the map data for this diagnostic marker map. + * @return read-only map object + */ + public Map getMap() { + return map; + } + } + + /** + * No instances, just an utility class. + */ + private ValidationHelper() { + super(); + } + + + /** + * Indicates whether the severiti of the given diagnostic matches the given + * bitmask.

+ * Note that a diagnostic with severity OK will never match; + * use isOK instead to detect a diagnostic with a severity of OK. + * + * @param diagnostic a diagnostic to test for severity match + * @param severityBitMask a mask formed by bitwise or'ing severity mask constants + * (ERROR, WARNING, INFO, CANCEL) + * + * @return true if there is at least one match, false 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 true if this diagnostic has severity + * OK, and false otherwise + */ + public static boolean isOK(Diagnostic diagnostic) { + return diagnostic.getSeverity() == Diagnostic.OK; + } + + /** + * Validates the given EObject and its all contents. + *

+ * If the EMF basic validation results in Diagnostic.CANCEL + * 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 true this operation produces validation + * problems markers provided that eObject.eResource() represents + * a file existing in the workspace. If true no + * attempt to create markers is performed. + * + * @param progressMonitor + * the progress monitor to track validation progress, or + * null if no progress monitoring is required. + * The implementation creates {@link SubProgressMonitor} as + * a sub-task of the given parent progressMonitor + * 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.ValidationHelper_task_validate); + + 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 EObject and its all contents. + *

+ * This method is progress monitoring ignorant shorthand of {@link #validate(EObject, boolean, IProgressMonitor)} + * + * @param createMarkers + * if true this operation produces validation + * problems markers provided that eObject.eResource() represents + * a file existing in the workspace. If true 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 null 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.ValidationHelper_e_marker_creation, e); + Plugin.log(status); + } + DiagnosticMarkerMap markerMap = new DiagnosticMarkerMap(markerHelper.getDiagnostic2MarkerMap()); + + List data = diagnostic.getData() != null ? (List)diagnostic.getData() : Collections.emptyList(); + data = new ArrayList(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/GMFGenNewFileCreationPage.java =================================================================== RCS file: src/org/eclipse/gmf/internal/bridge/transform/GMFGenNewFileCreationPage.java diff -N src/org/eclipse/gmf/internal/bridge/transform/GMFGenNewFileCreationPage.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/internal/bridge/transform/GMFGenNewFileCreationPage.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,41 @@ +package org.eclipse.gmf.internal.bridge.transform; + +import java.text.MessageFormat; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.dialogs.WizardNewFileCreationPage; + +public class GMFGenNewFileCreationPage extends WizardNewFileCreationPage { + + static final String EXT_GMFGEN = "gmfgen"; //$NON-NLS-1$ + + public GMFGenNewFileCreationPage(String pageId, IStructuredSelection selection) { + super(pageId, selection); + } + + protected boolean validatePage() { + if (super.validatePage()) { + // Make sure the file ends in ".gmfgen". + // + String enteredExt = new Path(getFileName()).getFileExtension(); + if (enteredExt == null || !enteredExt.equals(EXT_GMFGEN)) { + String pattern = Messages.GMFGenNewFileCreationPage_e_filename; + setErrorMessage(MessageFormat.format(pattern, new Object [] { EXT_GMFGEN })); + return false; + } + else { + return true; + } + } + else { + return false; + } + } + + public IFile getModelFile() { + return ResourcesPlugin.getWorkspace().getRoot().getFile(getContainerFullPath().append(getFileName())); + } +} 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,231 @@ +/** + * 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.IStatus; +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 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.GenModelConfigurationPage_btn_new_wizard); + setButtonLayoutData(createWizardBtn); + + createDefaultBtn = new Button(createComposite, SWT.PUSH); + createDefaultBtn.setText(Messages.GenModelConfigurationPage_btn_create_default); + setButtonLayoutData(createDefaultBtn); + + refreshStaleBtn = new Button(createComposite, SWT.PUSH); + refreshStaleBtn.setText(Messages.GenModelConfigurationPage_btn_refresh_stale); + setButtonLayoutData(refreshStaleBtn); + + SelectionAdapter selectionAdapter = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + handleSelection(e.widget); + } + }; + createWizardBtn.addSelectionListener(selectionAdapter); + createDefaultBtn.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 (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()); + } + IStatus stale = getOperation().getStaleGenmodelStatus(); + if (stale != null && !stale.isOK()) { + setStatusMessage(stale); + refreshStaleBtn.setEnabled((getURI() != null)); + } else { + refreshStaleBtn.setEnabled(false); + } + } + + @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 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 @@ +#Wed Jan 17 18:24:51 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 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.GenModelDetector_e_not_found, null); + } + } + + 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 findEPackages(Mapping mapping) { + Collection packages = new HashSet(); + 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.GenModelDetector_e_save, ex); + throw new CoreException(error); + } + } + + public GenModel get(ResourceSet resSet) { + if (myGMAccess == null) { + throw new IllegalStateException(Messages.GenModelDetector_e_no_genmodelaccess); + } + 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,71 @@ +/** + * 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.core.runtime.IStatus; +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; + + +class MapModelConfigurationPage extends ModelConfigurationPage { + + private static final String FILE_EXT_GMFMAP = "gmfmap"; //$NON-NLS-1$ + + MapModelConfigurationPage(String pageId, ResourceLocationProvider rlp, ResourceSet resourceSet) { + super(pageId, rlp, resourceSet); + } + + protected String getModelFileExtension() { + return FILE_EXT_GMFMAP; + } + + @Override + protected void initControls() { + super.initControls(); + TransformToGenModelWizard wizard = (TransformToGenModelWizard) getWizard(); + IFile target = wizard.getTargetFile(); + getOperation().setGenURI(URI.createPlatformResourceURI(target.getFullPath().toString(), true)); + } + + @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(); + } + + /* (non-Javadoc) + * @see org.eclipse.gmf.internal.common.ui.ModelSelectionPage#resourceChanged() + */ + @Override + protected void resourceChanged() { + super.resourceChanged(); + IStatus load = getOperation().getLoadMappingStatus(); + if (load != null) { + if ((load.getSeverity() == IStatus.WARNING) || (load.getSeverity() == IStatus.INFO) ) { + setStatusMessage(load); + } + } + } +} 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,354 @@ +/** + * 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; + + private IStatus myLoadMapmodelStatus; + private IStatus myStaleGenmodelStatus; + + 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; + } + + IStatus getLoadMappingStatus() { + return this.myLoadMapmodelStatus; + } + + IStatus getStaleGenmodelStatus() { + return this.myStaleGenmodelStatus; + } + + 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(); + String cancelMessage = Messages.TransformToGenModelOperation_e_map_load_cancelled; + monitor.beginTask("", 100); //$NON-NLS-1$ + subTask(monitor, 0, Messages.TransformToGenModelOperation_task_load, cancelMessage); + ModelLoadHelper loadHelper = new ModelLoadHelper(rs, uri); + IStatus loadStatus = loadHelper.getStatus(); + if (!loadStatus.isOK()) { + throw new CoreException(loadStatus); + } + subTask(monitor, 20, Messages.TransformToGenModelOperation_task_validate, cancelMessage); + final Mapping content = (Mapping) loadHelper.getContentsRoot(); + Diagnostic mapIsValid = ValidationHelper.validate(content, true, monitor); + monitor.worked(60); + IStatus mapStatus = getFirst(mapIsValid); + if (Diagnostic.CANCEL == mapStatus.getSeverity()) { + throw new CoreException(Plugin.createCancel(cancelMessage)); + } else if(Diagnostic.ERROR == mapStatus.getSeverity()) { + throw new CoreException(mapStatus); + } else { + setMapping(content); + this.myLoadMapmodelStatus = mapStatus; + 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.TransformToGenModelOperation_e_mapping_invalid, e); + throw new CoreException(error); + } + } + + GenModel loadGenModel(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(); + String cancelMessage = Messages.TransformToGenModelOperation_e_genmodel_load_cancelled; + monitor.beginTask("", 100); //$NON-NLS-1$ + monitor.subTask(Messages.TransformToGenModelOperation_task_detect); + 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); + } + subTask(monitor, 30, Messages.TransformToGenModelOperation_task_load, cancelMessage); + GenModel genModel = gmd.get(rs); + subTask(monitor, 40, Messages.TransformToGenModelOperation_task_validate, cancelMessage); + StaleGenModelDetector staleDetector = new StaleGenModelDetector(genModel); + IStatus stale = staleDetector.detect(); + this.myGenModel = genModel; + this.myStaleGenmodelStatus = stale; + return genModel; + + } catch (CoreException e) { + throw e; + } catch (Exception e) { + IStatus error = Plugin.createError(Messages.TransformToGenModelOperation_e_genmodel_load, e); + throw new CoreException(error); + } finally { + if (monitor != null) { + monitor.done(); + } + } + } + + 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.TransformToGenModelOperation_task_generate); + GenEditorGenerator genEditor = t.process(getMapping(), new SubProgressMonitor(monitor, 20)); + if (monitor.isCanceled()) { + return Status.CANCEL_STATUS; + } + monitor.subTask(Messages.TransformToGenModelOperation_task_reconcile); + if (Plugin.needsReconcile()) { + reconcile(rs, genEditor); + } + monitor.worked(20); + if (monitor.isCanceled()) { + return Status.CANCEL_STATUS; + } + monitor.subTask(Messages.TransformToGenModelOperation_task_save); + save(rs, genEditor); + monitor.worked(20); + if (monitor.isCanceled()) { + return Status.CANCEL_STATUS; + } + monitor.subTask(Messages.TransformToGenModelOperation_task_validate); + 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); + myLoadMapmodelStatus = null; + myStaleGenmodelStatus = null; + } + + private IStatus getFirst(Diagnostic d) { + if (d == null) { + return Status.OK_STATUS; + } + List 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 saveOptions = new HashMap(); + 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); + } + + private static void subTask(IProgressMonitor monitor, int ticks, String name, String cancelMessage) throws CoreException{ + if (monitor == null) { + return; + } + if (monitor.isCanceled()) { + IStatus cancel = Plugin.createCancel(cancelMessage); + throw new CoreException(cancel); + } + if (ticks > 0) { + monitor.worked(ticks); + } + if (name != null) { + monitor.subTask(name); + } + } +} 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,164 @@ +/** + * 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.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.Wizard; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWizard; + + +public class TransformToGenModelWizard extends Wizard implements IWorkbenchWizard { + + private static final String PAGE_ID_GMFGEN = "gmfgen"; //$NON-NLS-1$ + 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$ + + private IStructuredSelection mySelection; + + private GMFGenNewFileCreationPage newFileCreationPage; + private MapModelConfigurationPage mapModelPage; + private GenModelConfigurationPage genModelPage; + private ViewmapProducerWizardPage transformOptionPage; + + private TransformToGenModelOperation myOperation; + + ResourceSet resourceSet; + + @Override + public void addPages() { + super.addPages(); + + final String defaultName = "My"; //$NON-NLS-1$ + newFileCreationPage = new GMFGenNewFileCreationPage(PAGE_ID_GMFGEN, mySelection); + newFileCreationPage.setTitle(Messages.TransformToGenModelWizard_title_gmfgen); + newFileCreationPage.setDescription(Messages.TransformToGenModelWizard_descr_gmfgen); + newFileCreationPage.setFileName(WizardUtil.getDefaultFileName(mySelection, defaultName, GMFGenNewFileCreationPage.EXT_GMFGEN)); + addPage(newFileCreationPage); + + resourceSet = new ResourceSetImpl(); + ResourceLocationProvider rlp = new ResourceLocationProvider(mySelection); + mapModelPage = new MapModelConfigurationPage(PAGE_ID_GMFMAP, rlp, resourceSet); + mapModelPage.setTitle(Messages.TransformToGenModelWizard_title_mapmodel); + mapModelPage.setDescription(Messages.TransformToGenModelWizard_descr_mapmodel); + mapModelPage.setPageComplete(false); + mapModelPage.setModelRequired(true); + addPage(mapModelPage); + + genModelPage = new GenModelConfigurationPage(PAGE_ID_GENMODEL, rlp, resourceSet); + genModelPage.setTitle(Messages.TransformToGenModelWizard_title_genmodel); + genModelPage.setDescription(Messages.TransformToGenModelWizard_descr_genmodel); + genModelPage.setPageComplete(false); + genModelPage.setModelRequired(true); + addPage(genModelPage); + + transformOptionPage = new ViewmapProducerWizardPage(PAGE_ID_TRANSFORM); + transformOptionPage.setTitle(Messages.TransformToGenModelWizard_title_options); + transformOptionPage.setDescription(Messages.TransformToGenModelWizard_descr_options); + transformOptionPage.setPageComplete(false); + addPage(transformOptionPage); + + } + + public void init(IWorkbench workbench, IStructuredSelection selection) { + this.mySelection = selection; + setWindowTitle(Messages.TransformToGenModelWizard_title_wizard); + setNeedsProgressMonitor(true); + IFile mapFile = (IFile) selection.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.TransformToGenModelWizard_e_generator_creation; + } + } + return false; + } catch (InterruptedException ex){ + setErrorMessage(Messages.TransformToGenModelWizard_e_operation_cancelled); + 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,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.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.gmf.internal.bridge.ui.Plugin; + + +public class TransformOptions extends AbstractPreferenceInitializer { + + 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 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 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 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.putBoolean(PREF_GENERATE_RCP, false); + node.putBoolean(PREF_USE_MAP_MODE, true); + node.putBoolean(PREF_USE_RUNTIME_FIGURES, true); + + } + + 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,59 @@ +/* + * 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.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); + wd.open(); + } + + 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,114 @@ +/** + * 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.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +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.jface.dialogs.IMessageProvider; +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(); + setStatusMessage(Status.OK_STATUS); + 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); + setStatusMessage(Status.OK_STATUS); + } catch (InvocationTargetException e) { + Throwable target = e.getTargetException(); + if (target instanceof CoreException) { + CoreException ce = (CoreException) target; + setStatusMessage(ce.getStatus()); + } + setStatusMessage(Plugin.createError(target.getMessage(), target)); + } catch (InterruptedException e) { + setStatusMessage(Status.CANCEL_STATUS); + } + 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(); + } + } + } + + void setStatusMessage(IStatus status) { + if (status == null || status.isOK()) { + setMessage(null); + setErrorMessage(null); + } else if (IStatus.INFO == status.getSeverity()) { + setMessage(status.getMessage(), IMessageProvider.INFORMATION); + setErrorMessage(null); + } else if (IStatus.WARNING == status.getSeverity()) { + setMessage(status.getMessage(), IMessageProvider.WARNING); + setErrorMessage(null); + } else if (IStatus.ERROR == status.getSeverity()) { + setMessage(null); + setErrorMessage(status.getMessage()); + } else if (IStatus.CANCEL == status.getSeverity()) { + setMessage(null); + setErrorMessage(status.getMessage()); + } + } + +}