diff options
16 files changed, 663 insertions, 407 deletions
diff --git a/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/resource/CDOAwareTransactionalEditingDomain.java b/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/resource/CDOAwareTransactionalEditingDomain.java index c1583658bb6..926c6c3079a 100644 --- a/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/resource/CDOAwareTransactionalEditingDomain.java +++ b/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/resource/CDOAwareTransactionalEditingDomain.java @@ -9,6 +9,8 @@ * Contributors: * CEA LIST - Initial API and implementation * Christian W. Damus (CEA) - bug 323802 + * Christian W. Damus (CEA) - bug 415639 + * *****************************************************************************/ package org.eclipse.papyrus.cdo.core.resource; @@ -52,6 +54,9 @@ public class CDOAwareTransactionalEditingDomain extends PapyrusROTransactionalEd if(!NotificationFilter.READ.matches(notification)) { // Check whether we are modifying a read-only object assertNotReadOnly(notification.getNotifier()); + } else { + // Maybe we resolved a cross-resource containment proxy + handleCrossResourceContainmentProxy(notification); } } }; diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ControlledResourceTracker.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ControlledResourceTracker.java index 34212fe77d5..32375407dee 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ControlledResourceTracker.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ControlledResourceTracker.java @@ -40,9 +40,9 @@ import org.eclipse.emf.transaction.util.TransactionUtil; */ class ControlledResourceTracker extends AdapterImpl implements TransactionalEditingDomainListener { - private Map<URI, URI> unitMap = new HashMap<URI, URI>(); + private volatile Map<URI, URI> unitMap = new HashMap<URI, URI>(); - private Map<URI, URI> pending; + private volatile Map<URI, URI> pending; /** * Obtains the single tracker instance associated with the specified editing {@code domain}. @@ -188,6 +188,21 @@ class ControlledResourceTracker extends AdapterImpl implements TransactionalEdit } } + /** + * Discover an existing parent-unit relationship from a cross-resource-contained object. + * + * @param crossResourceContained + * an object that is in the contents list of a resource and also has a container + */ + protected void handleCrossResourceContainment(InternalEObject crossResourceContained) { + URI resourceURI = crossResourceContained.eIsProxy() ? crossResourceContained.eProxyURI().trimFragment() : crossResourceContained.eDirectResource().getURI(); + EObject container = crossResourceContained.eInternalContainer(); + URI parentURI = container.eIsProxy() ? ((InternalEObject)container).eProxyURI().trimFragment() : container.eResource().getURI(); + if(parentURI != null) { + map(resourceURI, parentURI); + } + } + @Override public void notifyChanged(Notification msg) { Object notifier = msg.getNotifier(); diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/PapyrusROTransactionalEditingDomain.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/PapyrusROTransactionalEditingDomain.java index e7d1365fa11..94d581f26e3 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/PapyrusROTransactionalEditingDomain.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/PapyrusROTransactionalEditingDomain.java @@ -13,6 +13,7 @@ * Christian W. Damus (CEA) - bug 323802
* Christian W. Damus (CEA) - bug 429826
* Christian W. Damus (CEA) - bug 422257
+ * Christian W. Damus (CEA) - bug 415639
*
*****************************************************************************/
package org.eclipse.papyrus.infra.emf.readonly;
@@ -36,6 +37,8 @@ import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.transaction.NotificationFilter;
@@ -97,10 +100,25 @@ public class PapyrusROTransactionalEditingDomain extends TransactionalEditingDom if(!NotificationFilter.READ.matches(notification)) {
// Check whether we are modifying a read-only object
assertNotReadOnly(notification.getNotifier());
+ } else {
+ // Maybe we resolved a cross-resource containment proxy
+ handleCrossResourceContainmentProxy(notification);
}
}
};
}
+
+ protected void handleCrossResourceContainmentProxy(Notification notification) {
+ if(notification.getEventType() == Notification.RESOLVE) {
+ EReference reference = (EReference)notification.getFeature();
+ if(reference.isContainment()) {
+ InternalEObject newValue = (InternalEObject)notification.getNewValue();
+ if(newValue.eDirectResource() != null) {
+ ControlledResourceTracker.getInstance(this).handleCrossResourceContainment(newValue);
+ }
+ }
+ }
+ }
protected void assertNotReadOnly(Object object) {
InternalTransaction tx = getActiveTransaction();
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/util/LoadingUtils.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/util/LoadingUtils.java index b72d2528e05..fb751e16898 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/util/LoadingUtils.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/util/LoadingUtils.java @@ -1,371 +1,401 @@ -/*****************************************************************************
- * Copyright (c) 2011 Atos Origin.
- *
- *
- * 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:
- * Vincent Hemery (Atos) vincent.hemery@atos.net - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.services.resourceloading.util;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.InternalEObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.util.EditPartUtilities;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
-import org.eclipse.papyrus.infra.services.resourceloading.Activator;
-import org.eclipse.papyrus.infra.services.resourceloading.Messages;
-import org.eclipse.papyrus.infra.widgets.toolbox.notification.Type;
-import org.eclipse.papyrus.infra.widgets.toolbox.notification.builders.NotificationBuilder;
-import org.eclipse.papyrus.uml.tools.model.UmlModel;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * This class provides utility methods for model loading
- *
- * @author vhemery
- */
-public class LoadingUtils {
-
- /**
- * Load corresponding resources in model set for all its existing models.
- *
- * @param modelSet
- * the model set
- * @param uriWithoutFileExtension
- * path of resources to load without file extension
- */
- public static void loadResourcesInModelSet(ModelSet modelSet, URI uriWithoutFileExtension) {
- // initiate progress dialog
- ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
- dialog.open();
- IProgressMonitor monitor = dialog.getProgressMonitor();
-
- IEditorPart editor = getEditor();
- if(editor instanceof IMultiDiagramEditor) {
- IMultiDiagramEditor core = (IMultiDiagramEditor)editor;
- try {
- IPageManager pageMngr = core.getServicesRegistry().getService(IPageManager.class);
- List<Object> allPages = pageMngr.allPages();
- // mark progress
- monitor.beginTask(Messages.LoadingUtils_RefreshPagesTask, allPages.size());
- // the uri is added after getting all the pages. If it is done before, the eobjects are resolved
- NotificationBuilder error = NotificationBuilder.createAsyncPopup(Messages.LoadingUtils_ErrorTitle, String.format(Messages.LoadingUtils_ErrorMessage, uriWithoutFileExtension.toString())).setType(Type.ERROR).setDelay(2000);
- for(Object o : allPages) {
- // refresh pages to display proxy diagrams
- if(o instanceof EObject) {
- EObject eobject = (EObject)o;
- if(eobject.eIsProxy()) {
- InternalEObject internal = (InternalEObject)eobject;
- URI uriProxy = internal.eProxyURI();
- URI trimFragment = uriProxy.trimFragment();
- if(uriWithoutFileExtension.equals(trimFragment.trimFileExtension())) {
- try {
- Resource r = modelSet.getResource(trimFragment, true);
- if(r != null) {
- EObject newEObject = r.getEObject(uriProxy.fragment());
- if(pageMngr.isOpen(newEObject)) {
- pageMngr.selectPage(newEObject);
- }
- } else {
- error.run();
- }
- } catch (Exception e) {
- error.run();
- Activator.logError(e);
- }
- }
- }
- }
- // mark progress
- monitor.worked(1);
- }
- Set<String> extensions = getExtensions(modelSet);
- // mark progress
- monitor.beginTask(Messages.LoadingUtils_LoadModelsTask, extensions.size());
- for(String s : extensions) {
- try {
- URI uriToLoad = uriWithoutFileExtension.appendFileExtension(s);
- Resource r = modelSet.getResource(uriToLoad, true);
- if(r == null) {
- error.run();
- }
- } catch (Exception re) {
- error.run();
- Activator.logError(re);
- }
- // mark progress
- monitor.worked(1);
- }
- } catch (ServiceException e) {
- Activator.logError(e);
- }
- }
- // mark progress
- monitor.done();
- dialog.close();
- }
-
- /**
- * Unload corresponding resources from model set for all its existing models.
- *
- * @param modelSet
- * the model set
- * @param uriWithoutFileExtension
- * path of resources to unload without file extension
- */
- public static void unloadResourcesFromModelSet(ModelSet modelSet, URI uriWithoutFileExtension) {
- unloadResourcesFromModelSet(modelSet, uriWithoutFileExtension, false);
- }
-
- /**
- * Unload corresponding resources from model set for all its existing models.
- *
- * @param modelSet
- * the model set
- * @param uriWithoutFileExtension
- * path of resources to unload without file extension
- * @param refreshDiagramsWithProxies
- * true if we must refresh necessary diagrams, false to skip it.
- */
- public static void unloadResourcesFromModelSet(ModelSet modelSet, URI uriWithoutFileExtension, boolean refreshDiagramsWithProxies) {
- // initiate progress dialog
- ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
- dialog.open();
- IProgressMonitor monitor = dialog.getProgressMonitor();
-
- IEditorPart editor = getEditor();
- if(editor instanceof IMultiDiagramEditor) {
- IMultiDiagramEditor core = (IMultiDiagramEditor)editor;
- try {
- IPageManager pageMngr = core.getServicesRegistry().getService(IPageManager.class);
- List<Object> allPages = pageMngr.allPages();
- List<URI> pagesURIToOpen = new ArrayList<URI>(allPages.size());
- List<URI> pagesURIToRefresh = new ArrayList<URI>(allPages.size());
- if(refreshDiagramsWithProxies) {
- // mark progress
- monitor.beginTask(Messages.LoadingUtils_RefreshPagesTask, allPages.size());
- for(Object o : allPages) {
- // refresh pages to cancel display of proxified elements
- if(o instanceof EObject) {
- EObject eobject = (EObject)o;
- if(!eobject.eIsProxy()) {
- URI trimFragment = eobject.eResource().getURI();
- String frag = eobject.eResource().getURIFragment(eobject);
- if(uriWithoutFileExtension.equals(trimFragment.trimFileExtension())) {
- // diagram was in unloaded resource. Refresh it.
- if(pageMngr.isOpen(eobject)) {
- pageMngr.closePage(eobject);
- pagesURIToOpen.add(trimFragment.appendFragment(frag));
- }
- } else if(pageMngr.isOpen(eobject)) {
- // diagram is still loaded but may display proxified elements
- pagesURIToRefresh.add(trimFragment.appendFragment(frag));
- }
- }
- }
- // mark progress
- monitor.worked(1);
- }
- }
- // mark progress
- monitor.beginTask(Messages.LoadingUtils_UnloadModelsTask, modelSet.getResources().size());
-
- // Use the platform string of a normalized URI for comparison below, see bug 372326
- // (registered libraries in the model set have different URIs - e.g. due to a pathmap -
- // although they point to the same location).
- // TODO: Use a single detection mechanism in ResourceUpdateService and here
- String unloadPlatformString;
- if(uriWithoutFileExtension.isPlatform()) {
- unloadPlatformString = uriWithoutFileExtension.toPlatformString(true);
- } else {
- unloadPlatformString = URI.decode(uriWithoutFileExtension.toString());
- }
- //URIConverter uriConverter = modelSet.getURIConverter();
- // unload resource
- for(Resource res : new ArrayList<Resource>(modelSet.getResources())) {
- URI normalizedURI = res.getURI();
- String platformString;
- if(normalizedURI.isPlatform()) {
- platformString = normalizedURI.trimFileExtension().toPlatformString(true);
- } else {
- platformString = URI.decode(normalizedURI.trimFileExtension().toString());
- }
-
- if((platformString != null) && platformString.equals(unloadPlatformString)) {
- // unload this resource
- modelSet.getResources().remove(res);
- res.unload();
- res.eAdapters().clear();
- }
- // mark progress
- monitor.worked(1);
- }
- // // mark progress
- // monitor.beginTask("Resolve", 1);
- // EcoreUtil.resolveAll(modelSet);
- // monitor.worked(1);
-
- if(refreshDiagramsWithProxies) {
- // mark progress
- monitor.beginTask(Messages.LoadingUtils_RefreshPagesTask, allPages.size());
- // reopen pages from proxies and refresh necessary pages
- for(Object page : allPages) {
- if(page instanceof EObject) {
- EObject eobject = (EObject)page;
- if(eobject.eIsProxy()) {
- // reopen page from proxy if needed
- InternalEObject internal = (InternalEObject)eobject;
- URI uriProxy = internal.eProxyURI();
- if(pagesURIToOpen.contains(uriProxy)) {
- pageMngr.openPage(eobject);
- }
- } else if(eobject instanceof Diagram) {
- // refresh page's diagram if needed
- Diagram diag = ((Diagram)eobject);
- if(pageMngr.isOpen(diag)) {
-
- IDiagramGraphicalViewer graphicalViewer = (IDiagramGraphicalViewer)core.getAdapter(IDiagramGraphicalViewer.class);
- if(graphicalViewer == null) {
- continue;
- }
-
- Object part = graphicalViewer.getEditPartRegistry().get(diag);
- if(part instanceof GraphicalEditPart) {
- // refresh nodes
- for(Object child : EditPartUtilities.getAllChildren((GraphicalEditPart)part)) {
- if(child instanceof EditPart) {
- ((EditPart)child).refresh();
- }
- }
- // refresh edges
- for(Object child : EditPartUtilities.getAllNestedConnectionEditParts((GraphicalEditPart)part)) {
- if(child instanceof EditPart) {
- ((EditPart)child).refresh();
- }
- }
- }
- }
- }
- }
- // mark progress
- monitor.worked(1);
- }
- }
- } catch (ServiceException e) {
- Activator.logError(e);
- }
- }
- // mark progress
- monitor.done();
- dialog.close();
- }
-
- /**
- * Common extensions
- * TODO get rid of listing all model's extensions and find a way to deduce them from model set. Then, delete this attribute.
- *
- * @see #getExtensions(ModelSet)
- */
- private static final Set<String> COMMON_EXTENSIONS = new HashSet<String>();
- static {
- COMMON_EXTENSIONS.add(UmlModel.UML_FILE_EXTENSION);
- COMMON_EXTENSIONS.add(NotationModel.NOTATION_FILE_EXTENSION);
- COMMON_EXTENSIONS.add(DiModel.DI_FILE_EXTENSION);
- }
-
- /**
- * Get list of file extensions existing for this model set
- *
- * @param modelSet
- * model set to find common extensions for
- * @return extensions list to explore
- */
- private static Set<String> getExtensions(ModelSet modelSet) {
- return COMMON_EXTENSIONS;
- }
-
- /**
- * Get currently opened editor
- *
- * @return editor
- */
- public static IEditorPart getEditor() {
- IEditorPart editor = null;
- IWorkbench workbench = PlatformUI.getWorkbench();
- if(workbench != null) {
- IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
- if(activeWorkbenchWindow != null) {
- IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
- if(activePage != null) {
- editor = activePage.getActiveEditor();
- }
- }
- }
- return editor;
- }
-
- /**
- * Get File from a URI
- *
- * @param uri
- * the URI to transform
- * @return the corresponding file
- */
- public static IFile getFile(URI uri) {
- IPath path = getPath(uri);
- if(path != null) {
- return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
- }
- return null;
- }
-
- /**
- * Get Path from a URI
- *
- * @param uri
- * the URI to transform
- * @return the corresponding path
- */
- public static IPath getPath(URI uri) {
- String scheme = uri.scheme();
- IPath path = null;
- if("platform".equals(scheme)) { //$NON-NLS-1$
- path = Path.fromPortableString(uri.toPlatformString(true));
- } else if("file".equals(scheme)) { //$NON-NLS-1$
- path = Path.fromPortableString(uri.toFileString());
- }
- return path;
- }
-}
+/***************************************************************************** + * Copyright (c) 2011, 2014 Atos Origin, CEA, and others. + * + * + * 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: + * Vincent Hemery (Atos) vincent.hemery@atos.net - Initial API and implementation + * Christian W. Damus (CEA) - bug 415639 + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.services.resourceloading.util; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.InternalEObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.util.EditPartUtilities; +import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel; +import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.core.utils.TransactionHelper; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel; +import org.eclipse.papyrus.infra.services.resourceloading.Activator; +import org.eclipse.papyrus.infra.services.resourceloading.Messages; +import org.eclipse.papyrus.infra.widgets.toolbox.notification.Type; +import org.eclipse.papyrus.infra.widgets.toolbox.notification.builders.NotificationBuilder; +import org.eclipse.papyrus.uml.tools.model.UmlModel; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.progress.IWorkbenchSiteProgressService; +import org.eclipse.ui.statushandlers.StatusManager; + +/** + * This class provides utility methods for model loading + * + * @author vhemery + */ +public class LoadingUtils { + + /** + * Load corresponding resources in model set for all its existing models. + * + * @param modelSet + * the model set + * @param uriWithoutFileExtension + * path of resources to load without file extension + */ + public static void loadResourcesInModelSet(final ModelSet modelSet, final URI uriWithoutFileExtension) { + final IEditorPart editor = getEditor(); + if(editor instanceof IMultiDiagramEditor) { + // This must be created on the UI thread + final NotificationBuilder error = NotificationBuilder.createAsyncPopup(Messages.LoadingUtils_ErrorTitle, String.format(Messages.LoadingUtils_ErrorMessage, uriWithoutFileExtension.toString())).setType(Type.ERROR).setDelay(2000); + + runInEditingDomain(modelSet.getTransactionalEditingDomain(), editor, new IRunnableWithProgress() { + + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + IMultiDiagramEditor core = (IMultiDiagramEditor)editor; + try { + IPageManager pageMngr = core.getServicesRegistry().getService(IPageManager.class); + List<Object> allPages = pageMngr.allPages(); + // mark progress + monitor.beginTask(Messages.LoadingUtils_RefreshPagesTask, allPages.size()); + // the uri is added after getting all the pages. If it is done before, the eobjects are resolved + for(Object o : allPages) { + // refresh pages to display proxy diagrams + if(o instanceof EObject) { + EObject eobject = (EObject)o; + if(eobject.eIsProxy()) { + InternalEObject internal = (InternalEObject)eobject; + URI uriProxy = internal.eProxyURI(); + URI trimFragment = uriProxy.trimFragment(); + if(uriWithoutFileExtension.equals(trimFragment.trimFileExtension())) { + try { + Resource r = modelSet.getResource(trimFragment, true); + if(r != null) { + EObject newEObject = r.getEObject(uriProxy.fragment()); + if(pageMngr.isOpen(newEObject)) { + pageMngr.selectPage(newEObject); + } + } else { + error.run(); + } + } catch (Exception e) { + error.run(); + Activator.logError(e); + } + } + } + } + // mark progress + monitor.worked(1); + } + Set<String> extensions = getExtensions(modelSet); + // mark progress + monitor.beginTask(Messages.LoadingUtils_LoadModelsTask, extensions.size()); + for(String s : extensions) { + try { + URI uriToLoad = uriWithoutFileExtension.appendFileExtension(s); + Resource r = modelSet.getResource(uriToLoad, true); + if(r == null) { + error.run(); + } + } catch (Exception re) { + error.run(); + Activator.logError(re); + } + // mark progress + monitor.worked(1); + } + } catch (ServiceException e) { + Activator.logError(e); + } + } finally { + // mark progress + monitor.done(); + } + } + }); + } + } + + /** + * Unload corresponding resources from model set for all its existing models. + * + * @param modelSet + * the model set + * @param uriWithoutFileExtension + * path of resources to unload without file extension + */ + public static void unloadResourcesFromModelSet(ModelSet modelSet, URI uriWithoutFileExtension) { + unloadResourcesFromModelSet(modelSet, uriWithoutFileExtension, false); + } + + /** + * Unload corresponding resources from model set for all its existing models. + * + * @param modelSet + * the model set + * @param uriWithoutFileExtension + * path of resources to unload without file extension + * @param refreshDiagramsWithProxies + * true if we must refresh necessary diagrams, false to skip it. + */ + public static void unloadResourcesFromModelSet(final ModelSet modelSet, final URI uriWithoutFileExtension, final boolean refreshDiagramsWithProxies) { + final IEditorPart editor = getEditor(); + if(editor instanceof IMultiDiagramEditor) { + runInEditingDomain(modelSet.getTransactionalEditingDomain(), editor, new IRunnableWithProgress() { + + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + + try { + IMultiDiagramEditor core = (IMultiDiagramEditor)editor; + try { + IPageManager pageMngr = core.getServicesRegistry().getService(IPageManager.class); + List<Object> allPages = pageMngr.allPages(); + List<URI> pagesURIToOpen = new ArrayList<URI>(allPages.size()); + List<URI> pagesURIToRefresh = new ArrayList<URI>(allPages.size()); + if(refreshDiagramsWithProxies) { + // mark progress + monitor.beginTask(Messages.LoadingUtils_RefreshPagesTask, allPages.size()); + for(Object o : allPages) { + // refresh pages to cancel display of proxified elements + if(o instanceof EObject) { + EObject eobject = (EObject)o; + if(!eobject.eIsProxy()) { + URI trimFragment = eobject.eResource().getURI(); + String frag = eobject.eResource().getURIFragment(eobject); + if(uriWithoutFileExtension.equals(trimFragment.trimFileExtension())) { + // diagram was in unloaded resource. Refresh it. + if(pageMngr.isOpen(eobject)) { + pageMngr.closePage(eobject); + pagesURIToOpen.add(trimFragment.appendFragment(frag)); + } + } else if(pageMngr.isOpen(eobject)) { + // diagram is still loaded but may display proxified elements + pagesURIToRefresh.add(trimFragment.appendFragment(frag)); + } + } + } + // mark progress + monitor.worked(1); + } + } + // mark progress + monitor.beginTask(Messages.LoadingUtils_UnloadModelsTask, modelSet.getResources().size()); + + // Use the platform string of a normalized URI for comparison below, see bug 372326 + // (registered libraries in the model set have different URIs - e.g. due to a pathmap - + // although they point to the same location). + // TODO: Use a single detection mechanism in ResourceUpdateService and here + String unloadPlatformString; + if(uriWithoutFileExtension.isPlatform()) { + unloadPlatformString = uriWithoutFileExtension.toPlatformString(true); + } else { + unloadPlatformString = URI.decode(uriWithoutFileExtension.toString()); + } + //URIConverter uriConverter = modelSet.getURIConverter(); + // unload resource + for(Resource res : new ArrayList<Resource>(modelSet.getResources())) { + URI normalizedURI = res.getURI(); + String platformString; + if(normalizedURI.isPlatform()) { + platformString = normalizedURI.trimFileExtension().toPlatformString(true); + } else { + platformString = URI.decode(normalizedURI.trimFileExtension().toString()); + } + + if((platformString != null) && platformString.equals(unloadPlatformString)) { + // unload this resource + res.unload(); + // there is no need to remove it from the resource set (which inevitably + // causes ConcurrentModificationExceptions!), especially as we may be + // loading it again (the editor is still open) + } + // mark progress + monitor.worked(1); + } + // // mark progress + // monitor.beginTask("Resolve", 1); + // EcoreUtil.resolveAll(modelSet); + // monitor.worked(1); + + if(refreshDiagramsWithProxies) { + // mark progress + monitor.beginTask(Messages.LoadingUtils_RefreshPagesTask, allPages.size()); + // reopen pages from proxies and refresh necessary pages + for(Object page : allPages) { + if(page instanceof EObject) { + EObject eobject = (EObject)page; + if(eobject.eIsProxy()) { + // reopen page from proxy if needed + InternalEObject internal = (InternalEObject)eobject; + URI uriProxy = internal.eProxyURI(); + if(pagesURIToOpen.contains(uriProxy)) { + pageMngr.openPage(eobject); + } + } else if(eobject instanceof Diagram) { + // refresh page's diagram if needed + Diagram diag = ((Diagram)eobject); + if(pageMngr.isOpen(diag)) { + + IDiagramGraphicalViewer graphicalViewer = (IDiagramGraphicalViewer)core.getAdapter(IDiagramGraphicalViewer.class); + if(graphicalViewer == null) { + continue; + } + + Object part = graphicalViewer.getEditPartRegistry().get(diag); + if(part instanceof GraphicalEditPart) { + // refresh nodes + for(Object child : EditPartUtilities.getAllChildren((GraphicalEditPart)part)) { + if(child instanceof EditPart) { + ((EditPart)child).refresh(); + } + } + // refresh edges + for(Object child : EditPartUtilities.getAllNestedConnectionEditParts((GraphicalEditPart)part)) { + if(child instanceof EditPart) { + ((EditPart)child).refresh(); + } + } + } + } + } + } + // mark progress + monitor.worked(1); + } + } + } catch (ServiceException e) { + Activator.logError(e); + } + } finally { + // mark progress + monitor.done(); + } + } + }); + } + } + + static void runInEditingDomain(TransactionalEditingDomain domain, IEditorPart editorContext, IRunnableWithProgress operation) { + final IWorkbenchSiteProgressService progress = (IWorkbenchSiteProgressService)editorContext.getSite().getService(IWorkbenchSiteProgressService.class); + + try { + progress.incrementBusy(); + progress.busyCursorWhile(TransactionHelper.createPrivilegedRunnableWithProgress(domain, operation)); + } catch (InterruptedException e) { + Activator.log.error(e); + } catch (InvocationTargetException e) { + StatusManager.getManager().handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to manage controlled resources.", e.getTargetException()), StatusManager.SHOW); + } finally { + progress.decrementBusy(); + } + } + + /** + * Common extensions + * TODO get rid of listing all model's extensions and find a way to deduce them from model set. Then, delete this attribute. + * + * @see #getExtensions(ModelSet) + */ + private static final Set<String> COMMON_EXTENSIONS = new HashSet<String>(); + static { + COMMON_EXTENSIONS.add(UmlModel.UML_FILE_EXTENSION); + COMMON_EXTENSIONS.add(NotationModel.NOTATION_FILE_EXTENSION); + COMMON_EXTENSIONS.add(DiModel.DI_FILE_EXTENSION); + } + + /** + * Get list of file extensions existing for this model set + * + * @param modelSet + * model set to find common extensions for + * @return extensions list to explore + */ + private static Set<String> getExtensions(ModelSet modelSet) { + return COMMON_EXTENSIONS; + } + + /** + * Get currently opened editor + * + * @return editor + */ + public static IEditorPart getEditor() { + IEditorPart editor = null; + IWorkbench workbench = PlatformUI.getWorkbench(); + if(workbench != null) { + IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); + if(activeWorkbenchWindow != null) { + IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); + if(activePage != null) { + editor = activePage.getActiveEditor(); + } + } + } + return editor; + } + + /** + * Get File from a URI + * + * @param uri + * the URI to transform + * @return the corresponding file + */ + public static IFile getFile(URI uri) { + IPath path = getPath(uri); + if(path != null) { + return ResourcesPlugin.getWorkspace().getRoot().getFile(path); + } + return null; + } + + /** + * Get Path from a URI + * + * @param uri + * the URI to transform + * @return the corresponding path + */ + public static IPath getPath(URI uri) { + String scheme = uri.scheme(); + IPath path = null; + if("platform".equals(scheme)) { //$NON-NLS-1$ + path = Path.fromPortableString(uri.toPlatformString(true)); + } else if("file".equals(scheme)) { //$NON-NLS-1$ + path = Path.fromPortableString(uri.toFileString()); + } + return path; + } +} diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ChildRuleItemProvider.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ChildRuleItemProvider.java index de82545a503..8beeab490eb 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ChildRuleItemProvider.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ChildRuleItemProvider.java @@ -16,6 +16,7 @@ package org.eclipse.papyrus.infra.viewpoints.configuration.provider; import java.util.Collection; import java.util.List; + import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EStructuralFeature; @@ -25,6 +26,8 @@ import org.eclipse.emf.edit.provider.ViewerNotification; import org.eclipse.papyrus.infra.viewpoints.configuration.ChildRule; import org.eclipse.papyrus.infra.viewpoints.configuration.ConfigurationFactory; import org.eclipse.papyrus.infra.viewpoints.configuration.ConfigurationPackage; +import org.eclipse.papyrus.infra.viewpoints.configuration.EClassPropertyDescriptor; +import org.eclipse.papyrus.infra.viewpoints.configuration.StereotypePropertyDescriptor; /** * This is the item provider adapter for a {@link org.eclipse.papyrus.infra.viewpoints.configuration.ChildRule} object. @@ -66,11 +69,12 @@ public class ChildRuleItemProvider * This adds a property descriptor for the Element feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> - * @generated + * + * @generated NOT */ protected void addElementPropertyDescriptor(Object object) { itemPropertyDescriptors.add - (createItemPropertyDescriptor + (new EClassPropertyDescriptor(createItemPropertyDescriptor (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ChildRule_element_feature"), @@ -81,18 +85,19 @@ public class ChildRuleItemProvider true, null, null, - null)); + null))); } /** * This adds a property descriptor for the Stereotypes feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> - * @generated + * + * @generated NOT */ protected void addStereotypesPropertyDescriptor(Object object) { itemPropertyDescriptors.add - (createItemPropertyDescriptor + (new StereotypePropertyDescriptor(createItemPropertyDescriptor (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ChildRule_stereotypes_feature"), @@ -103,18 +108,18 @@ public class ChildRuleItemProvider true, null, null, - null)); + null))); } /** * This adds a property descriptor for the Origin feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> - * @generated + * @generated NOT */ protected void addOriginPropertyDescriptor(Object object) { itemPropertyDescriptors.add - (createItemPropertyDescriptor + (new EClassPropertyDescriptor(createItemPropertyDescriptor (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ChildRule_origin_feature"), @@ -125,7 +130,7 @@ public class ChildRuleItemProvider true, null, null, - null)); + null))); } /** diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ModelAutoCreateItemProvider.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ModelAutoCreateItemProvider.java index 15c6018072a..d4b9825577e 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ModelAutoCreateItemProvider.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ModelAutoCreateItemProvider.java @@ -16,6 +16,7 @@ package org.eclipse.papyrus.infra.viewpoints.configuration.provider; import java.util.Collection; import java.util.List; + import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.util.ResourceLocator; @@ -32,7 +33,9 @@ import org.eclipse.emf.edit.provider.ITreeItemContentProvider; import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; import org.eclipse.emf.edit.provider.ItemProviderAdapter; import org.eclipse.emf.edit.provider.ViewerNotification; +import org.eclipse.papyrus.infra.viewpoints.configuration.ComplexTypePropertyDescriptor; import org.eclipse.papyrus.infra.viewpoints.configuration.ConfigurationPackage; +import org.eclipse.papyrus.infra.viewpoints.configuration.EReferencePropertyDescriptor; import org.eclipse.papyrus.infra.viewpoints.configuration.ModelAutoCreate; /** @@ -81,11 +84,11 @@ public class ModelAutoCreateItemProvider * This adds a property descriptor for the Feature feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> - * @generated + * @generated NOT */ protected void addFeaturePropertyDescriptor(Object object) { itemPropertyDescriptors.add - (createItemPropertyDescriptor + (new EReferencePropertyDescriptor(createItemPropertyDescriptor (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ModelAutoCreate_feature_feature"), @@ -96,7 +99,7 @@ public class ModelAutoCreateItemProvider true, null, null, - null)); + null))); } /** @@ -125,11 +128,11 @@ public class ModelAutoCreateItemProvider * This adds a property descriptor for the Creation Type feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> - * @generated + * @generated NOT */ protected void addCreationTypePropertyDescriptor(Object object) { itemPropertyDescriptors.add - (createItemPropertyDescriptor + (new ComplexTypePropertyDescriptor(createItemPropertyDescriptor (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ModelAutoCreate_creationType_feature"), @@ -140,7 +143,7 @@ public class ModelAutoCreateItemProvider false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, - null)); + null))); } /** diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ModelRuleItemProvider.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ModelRuleItemProvider.java index ed4836601e7..9743aaa3e79 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ModelRuleItemProvider.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/ModelRuleItemProvider.java @@ -16,6 +16,7 @@ package org.eclipse.papyrus.infra.viewpoints.configuration.provider; import java.util.Collection; import java.util.List; + import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EStructuralFeature; @@ -28,6 +29,7 @@ import org.eclipse.papyrus.infra.constraints.ConstraintsPackage; import org.eclipse.papyrus.infra.viewpoints.configuration.ConfigurationPackage; import org.eclipse.papyrus.infra.viewpoints.configuration.EClassPropertyDescriptor; import org.eclipse.papyrus.infra.viewpoints.configuration.ModelRule; +import org.eclipse.papyrus.infra.viewpoints.configuration.StereotypePropertyDescriptor; /** * This is the item provider adapter for a {@link org.eclipse.papyrus.infra.viewpoints.configuration.ModelRule} object. @@ -92,6 +94,8 @@ public class ModelRuleItemProvider * This adds a property descriptor for the Element feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> + * + * @generated NOT */ protected void addElementPropertyDescriptor(Object object) { itemPropertyDescriptors.add @@ -113,11 +117,12 @@ public class ModelRuleItemProvider * This adds a property descriptor for the Stereotypes feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> - * @generated + * + * @generated NOT */ protected void addStereotypesPropertyDescriptor(Object object) { itemPropertyDescriptors.add - (createItemPropertyDescriptor + (new StereotypePropertyDescriptor(createItemPropertyDescriptor (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ModelRule_stereotypes_feature"), @@ -128,7 +133,7 @@ public class ModelRuleItemProvider true, null, null, - null)); + null))); } /** diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/OwningRuleItemProvider.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/OwningRuleItemProvider.java index fdd7b03d19e..013515a8c0d 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/OwningRuleItemProvider.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/OwningRuleItemProvider.java @@ -16,6 +16,7 @@ package org.eclipse.papyrus.infra.viewpoints.configuration.provider; import java.util.Collection; import java.util.List; + import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EStructuralFeature; @@ -27,6 +28,7 @@ import org.eclipse.papyrus.infra.viewpoints.configuration.ConfigurationFactory; import org.eclipse.papyrus.infra.viewpoints.configuration.ConfigurationPackage; import org.eclipse.papyrus.infra.viewpoints.configuration.EClassPropertyDescriptor; import org.eclipse.papyrus.infra.viewpoints.configuration.OwningRule; +import org.eclipse.papyrus.infra.viewpoints.configuration.StereotypePropertyDescriptor; /** * This is the item provider adapter for a {@link org.eclipse.papyrus.infra.viewpoints.configuration.OwningRule} object. @@ -67,6 +69,8 @@ public class OwningRuleItemProvider * This adds a property descriptor for the Element feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> + * + * @generated NOT */ protected void addElementPropertyDescriptor(Object object) { itemPropertyDescriptors.add @@ -88,11 +92,12 @@ public class OwningRuleItemProvider * This adds a property descriptor for the Stereotypes feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> - * @generated + * + * @generated NOT */ protected void addStereotypesPropertyDescriptor(Object object) { itemPropertyDescriptors.add - (createItemPropertyDescriptor + (new StereotypePropertyDescriptor(createItemPropertyDescriptor (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_OwningRule_stereotypes_feature"), @@ -103,7 +108,7 @@ public class OwningRuleItemProvider true, null, null, - null)); + null))); } /** diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PapyrusConfigurationItemProvider.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PapyrusConfigurationItemProvider.java index 2edd687661e..012102451f7 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PapyrusConfigurationItemProvider.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PapyrusConfigurationItemProvider.java @@ -16,6 +16,7 @@ package org.eclipse.papyrus.infra.viewpoints.configuration.provider; import java.util.Collection; import java.util.List; + import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.util.ResourceLocator; @@ -93,6 +94,8 @@ public class PapyrusConfigurationItemProvider * This adds a property descriptor for the Metamodel feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> + * + * @generated NOT */ protected void addMetamodelPropertyDescriptor(Object object) { itemPropertyDescriptors.add diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PapyrusViewItemProvider.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PapyrusViewItemProvider.java index 1233345e985..83864b65f72 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PapyrusViewItemProvider.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PapyrusViewItemProvider.java @@ -16,6 +16,7 @@ package org.eclipse.papyrus.infra.viewpoints.configuration.provider; import java.util.Collection; import java.util.List; + import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.util.ResourceLocator; @@ -29,6 +30,7 @@ import org.eclipse.papyrus.infra.viewpoints.configuration.ConfigurationFactory; import org.eclipse.papyrus.infra.viewpoints.configuration.ConfigurationPackage; import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusView; import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusViewpoint; +import org.eclipse.papyrus.infra.viewpoints.configuration.ProfilePropertyDescriptor; import org.eclipse.papyrus.infra.viewpoints.iso42010.provider.ModelKindItemProvider; /** @@ -117,11 +119,12 @@ public class PapyrusViewItemProvider * This adds a property descriptor for the Profiles feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> - * @generated + * + * @generated NOT */ protected void addProfilesPropertyDescriptor(Object object) { itemPropertyDescriptors.add - (createItemPropertyDescriptor + (new ProfilePropertyDescriptor(createItemPropertyDescriptor (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_PapyrusView_profiles_feature"), @@ -132,7 +135,7 @@ public class PapyrusViewItemProvider true, null, null, - null)); + null))); } /** diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PathElementItemProvider.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PathElementItemProvider.java index 8e1442ce439..82ffea1e57f 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PathElementItemProvider.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.configuration.edit/src/org/eclipse/papyrus/infra/viewpoints/configuration/provider/PathElementItemProvider.java @@ -81,6 +81,8 @@ public class PathElementItemProvider * This adds a property descriptor for the Feature feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> + * + * @generated NOT */ protected void addFeaturePropertyDescriptor(Object object) { itemPropertyDescriptors.add diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/LoadResourceHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/LoadResourceHandler.java index a76235344e9..edf1120a072 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/LoadResourceHandler.java +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/LoadResourceHandler.java @@ -1,5 +1,5 @@ /*****************************************************************************
- * Copyright (c) 2011 Atos.
+ * Copyright (c) 2011, 2014 Atos, CEA, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@ *
* Contributors:
* Vincent Hemery (Atos) vincent.hemery@atos.net - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 415639
*
*****************************************************************************/
package org.eclipse.papyrus.views.modelexplorer.resourceloading.handler;
@@ -20,6 +21,7 @@ import org.eclipse.emf.common.command.AbstractCommand; import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.common.command.AbstractCommand.NonDirtying;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
@@ -47,7 +49,10 @@ public class LoadResourceHandler extends AbstractCommandHandler { List<EObject> selection = getSelectedElements();
if(editingDomain != null && editingDomain.getResourceSet() instanceof ModelSet && selection.size() > 0) {
final ModelSet set = (ModelSet)editingDomain.getResourceSet();
- CompoundCommand command = new CompoundCommand();
+ class NonDirtyingCompound extends CompoundCommand implements NonDirtying {
+ // Empty
+ }
+ CompoundCommand command = new NonDirtyingCompound();
List<URI> handledURI = new ArrayList<URI>();
for(EObject sel : selection) {
if(sel.eIsProxy()) {
@@ -56,7 +61,7 @@ public class LoadResourceHandler extends AbstractCommandHandler { final URI uriTrim = uriProxy.trimFragment().trimFileExtension();
if(!handledURI.contains(uriTrim)) {
handledURI.add(uriTrim);
- Command cmd = new AbstractCommand() {
+ class LoadCommand extends AbstractCommand implements NonDirtying {
public void redo() {
LoadingUtils.loadResourcesInModelSet(set, uriTrim);
@@ -71,7 +76,7 @@ public class LoadResourceHandler extends AbstractCommandHandler { return true;
}
};
- command.append(cmd);
+ command.append(new LoadCommand());
}
}
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/Messages.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/Messages.java new file mode 100644 index 00000000000..200c2052859 --- /dev/null +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/Messages.java @@ -0,0 +1,36 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST and others. + * + * 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: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.views.modelexplorer.resourceloading.handler; + +import org.eclipse.osgi.util.NLS; + +class Messages extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.papyrus.views.modelexplorer.resourceloading.handler.messages"; //$NON-NLS-1$ + + public static String UnloadResourceHandler_0; + + public static String UnloadResourceHandler_1; + + public static String UnloadResourceHandler_2; + + public static String UnloadResourceHandler_3; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/UnloadResourceHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/UnloadResourceHandler.java index bbbd3bb9de7..4711a7427e8 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/UnloadResourceHandler.java +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/UnloadResourceHandler.java @@ -1,5 +1,5 @@ /*****************************************************************************
- * Copyright (c) 2011 Atos.
+ * Copyright (c) 2011, 2014 Atos, CEA, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,29 +9,46 @@ *
* Contributors:
* Vincent Hemery (Atos) vincent.hemery@atos.net - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 415639
*
*****************************************************************************/
package org.eclipse.papyrus.views.modelexplorer.resourceloading.handler;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.common.command.AbstractCommand.NonDirtying;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
import org.eclipse.papyrus.infra.services.resourceloading.util.LoadingUtils;
import org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler;
+import org.eclipse.papyrus.views.modelexplorer.resourceloading.Activator;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.progress.IProgressService;
+import org.eclipse.ui.statushandlers.IStatusAdapterConstants;
+import org.eclipse.ui.statushandlers.StatusAdapter;
+import org.eclipse.ui.statushandlers.StatusManager;
/**
* Handler for the load resource action.
@@ -50,17 +67,36 @@ public class UnloadResourceHandler extends AbstractCommandHandler { List<EObject> selection = getSelectedElements();
if(editingDomain != null && editingDomain.getResourceSet() instanceof ModelSet && selection.size() > 0) {
final ModelSet set = (ModelSet)editingDomain.getResourceSet();
- CompoundCommand command = new CompoundCommand();
+
+ class NonDirtyingCompound extends CompoundCommand implements NonDirtying {
+ // Empty
+ }
+ CompoundCommand command = new NonDirtyingCompound();
+
+ final IEditorPart editor = getEditor();
+ SaveIfNecessaryCommand save = null;
+ if(editor.isDirty()) {
+ // First, a command to save if necessary
+ save = new SaveIfNecessaryCommand(editor);
+ command.append(save);
+ }
+
List<URI> handledURI = new ArrayList<URI>();
// ensure main URI is never unloaded
URI mainURI = SashModelUtils.getSashModel(set).getResourceURI().trimFileExtension();
handledURI.add(mainURI);
for(EObject sel : selection) {
if(!sel.eIsProxy()) {
- final URI uriTrim = sel.eResource().getURI().trimFileExtension();
+ final Resource resource = sel.eResource();
+ final URI uriTrim = resource.getURI().trimFileExtension();
if(!handledURI.contains(uriTrim)) {
handledURI.add(uriTrim);
- Command cmd = new AbstractCommand() {
+
+ if((save != null) && set.shouldSave(resource)) {
+ save.setNeedsSave(true);
+ }
+
+ class UnloadCommand extends AbstractCommand implements NonDirtying {
public void redo() {
LoadingUtils.unloadResourcesFromModelSet(set, uriTrim);
@@ -75,7 +111,7 @@ public class UnloadResourceHandler extends AbstractCommandHandler { return true;
}
};
- command.append(cmd);
+ command.append(new UnloadCommand());
}
}
}
@@ -114,4 +150,74 @@ public class UnloadResourceHandler extends AbstractCommandHandler { return null;
}
+ private static class SaveIfNecessaryCommand extends AbstractCommand implements NonDirtying {
+
+ private final IEditorPart editor;
+
+ private boolean needsSave;
+
+ SaveIfNecessaryCommand(IEditorPart editor) {
+ super();
+
+ this.editor = editor;
+ }
+
+ @Override
+ protected boolean prepare() {
+ return true;
+ }
+
+ void setNeedsSave(boolean needsSave) {
+ this.needsSave = needsSave;
+ }
+
+ boolean needsSave() {
+ return needsSave;
+ }
+
+ public void execute() {
+ if(needsSave()) {
+ if(promptToSave()) {
+ save();
+ } else {
+ // Safely cancel the entire composite
+ throw new OperationCanceledException();
+ }
+ }
+ }
+
+ @Override
+ public void undo() {
+ // Pass
+ }
+
+ public void redo() {
+ // Pass
+ }
+
+ boolean promptToSave() {
+ final Shell parent = editor.getEditorSite().getShell();
+ final int yesIndex = 0;
+ MessageDialog dlg = new MessageDialog(parent, Messages.UnloadResourceHandler_0, null, Messages.UnloadResourceHandler_1, MessageDialog.WARNING, new String[]{ IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, yesIndex);
+ return dlg.open() == yesIndex;
+ }
+
+ void save() {
+ IProgressService progress = (IProgressService)editor.getSite().getService(IProgressService.class);
+
+ try {
+ progress.busyCursorWhile(new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ editor.doSave(monitor);
+ }
+ });
+ } catch (Exception e) {
+ StatusAdapter status = new StatusAdapter(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.UnloadResourceHandler_2));
+ status.setProperty(IStatusAdapterConstants.TIMESTAMP_PROPERTY, System.currentTimeMillis());
+ status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, Messages.UnloadResourceHandler_3);
+ StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW);
+ }
+ }
+ }
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/messages.properties b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/messages.properties new file mode 100644 index 00000000000..fef41c18d22 --- /dev/null +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.resourceloading/src/org/eclipse/papyrus/views/modelexplorer/resourceloading/handler/messages.properties @@ -0,0 +1,15 @@ +# +# Copyright (c) 2014 CEA LIST and others. +# +# 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: +# CEA LIST - Initial API and implementation +# +UnloadResourceHandler_0=Save Before Unload +UnloadResourceHandler_1=The resource being unloaded has unsaved changes. They must be saved, first. Proceed with unload? +UnloadResourceHandler_2=Failed to save editor +UnloadResourceHandler_3=Save Before Unload diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/META-INF/MANIFEST.MF index f95c35a2132..7d8e1aa6a80 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/META-INF/MANIFEST.MF +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/META-INF/MANIFEST.MF @@ -15,7 +15,7 @@ Require-Bundle: org.eclipse.ui, org.junit;bundle-version="4.10.0",
org.eclipse.papyrus.junit.utils;bundle-version="1.0.0",
org.eclipse.gmf.tooling.runtime,
- org.eclipse.papyrus.uml.service.types,
+ org.eclipse.papyrus.uml.service.types;bundle-version="1.0.0",
org.eclipse.uml2.uml.editor
Export-Package: org.eclipse.papyrus.uml.diagram.activity.tests
Bundle-Vendor: %providerName
|