Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org')
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/Activator.java64
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/IsCollabPropertyTest.java60
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/MatchingURIObject.java78
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/RefreshHelper.java181
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/security/CollabReadOnlyHandler.java93
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/security/PreCommitReadOnlyHandler.java139
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/stategies/AbstractResourceBaseStrategy.java43
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/stategies/PapyrusCurrentResource.java60
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/stategies/PapyrusSelectionAllContent.java81
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/ICollabColors.java20
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/AbstractCollabHandler.java55
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/CommitHandler.java153
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/LockAction.java163
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/RevertHandler.java139
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/UnlockAction.java179
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/UpdateHandler.java121
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/dialogs/CommitDialog.java134
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/dialogs/PreviewDialog.java279
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/items/LockStrategyItemProvider.java73
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/items/UnlockStrategyItemProvider.java72
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/providers/ExtensivePartitionNameLabelProvider.java217
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/utils/PapyrusResourceUtils.java30
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/utils/UIUtils.java291
23 files changed, 2725 insertions, 0 deletions
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/Activator.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/Activator.java
new file mode 100644
index 00000000000..0cb8df7707f
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/Activator.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle.
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ /** The Constant PLUGIN_ID. */
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.team.collaborative.core.integration.papyrus"; //$NON-NLS-1$
+
+ // The shared instance
+ /** The plugin. */
+ private static Activator plugin;
+
+ /**
+ * The constructor.
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance.
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/IsCollabPropertyTest.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/IsCollabPropertyTest.java
new file mode 100644
index 00000000000..13874006ebd
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/IsCollabPropertyTest.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.team.collaborative.core.utils.CollabUtils;
+
+
+/**
+ * Tester to check if the selection belong to a collaborative model.
+ *
+ * @author adaussy
+ */
+public class IsCollabPropertyTest extends PropertyTester {
+
+ /** The Constant IS_COLLAB_PROPERTY. */
+ private static final String IS_COLLAB_PROPERTY = "isCollab";
+
+ /**
+ * Instantiates a new checks if is collab property test.
+ */
+ public IsCollabPropertyTest() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
+ */
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if(IS_COLLAB_PROPERTY.equals(property)) {
+ if(receiver instanceof ISelection) {
+ ISelection selection = (ISelection)receiver;
+ if(selection instanceof IStructuredSelection) {
+ IStructuredSelection structurSelection = (IStructuredSelection)selection;
+ Object first = structurSelection.getFirstElement();
+ EObject eObject = EMFHelper.getEObject(first);
+ if(eObject != null) {
+ return CollabUtils.isCollab(eObject);
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/MatchingURIObject.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/MatchingURIObject.java
new file mode 100644
index 00000000000..3a7270d47c1
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/MatchingURIObject.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
+import org.eclipse.papyrus.team.collaborative.core.IExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.utils.ExtendedURIUtil;
+import org.eclipse.uml2.uml.Element;
+
+import com.google.common.base.Predicate;
+
+
+/**
+ * The Class MatchingURIObject.
+ * Predicate that will return true if the EObject belong to the set of {@link IExtendedURI}
+ */
+public class MatchingURIObject implements Predicate<EObject> {
+
+ private Set<IExtendedURI> uris;
+
+ public MatchingURIObject(Set<IExtendedURI> uris) {
+ super();
+ this.uris = uris;
+ }
+
+ public boolean apply(EObject input) {
+ List<EObject> objectToTEObjects = new ArrayList<EObject>();
+ objectToTEObjects.add(input);
+ objectToTEObjects.addAll(NotationUtils.getLoadedAssociatedDiagrams(input));
+ for(IExtendedURI extendedURI : uris) {
+ for(EObject o : objectToTEObjects) {
+ boolean contained = ExtendedURIUtil.isIncluded(o, extendedURI);
+
+ if(contained) {
+ return contained;
+ }
+ }
+ }
+ return false;
+ }
+
+
+ protected EObject getSemanticObject(EObject eObject) {
+ EObject result = null;
+ if(eObject instanceof Element) {
+ result = eObject;
+ } else if(eObject instanceof View) {
+ //Handle view
+ result = ((View)eObject).getElement();
+ } else {
+ //Handle setereotype
+ Element baseElement = org.eclipse.uml2.uml.util.UMLUtil.getBaseElement(eObject);
+ if(baseElement != null) {
+ result = baseElement;
+ }
+ //TODO handle tab
+ }
+ return result;
+ }
+
+
+
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/RefreshHelper.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/RefreshHelper.java
new file mode 100644
index 00000000000..ded9888b3d7
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/RefreshHelper.java
@@ -0,0 +1,181 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos.
+ * 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:
+ * Olivier Melois <a href="mailto:olivier.melois@atos.net"> - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.AbstractCommand;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView;
+import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IViewReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Helper used to store method for refreshin model explorer view
+ *
+ * @author omelois
+ *
+ */
+public final class RefreshHelper {
+
+
+ private RefreshHelper() {
+ }
+
+
+ /**
+ * Runnable that will be used to refresh the model explorer view
+ *
+ * @author adaussy
+ *
+ */
+ public static final class RefreshModelExplorerRunnable implements Runnable {
+
+ private final Collection<EObject> elementsToRefresh;
+
+ private static final int TIME_TO_REFRESH_MODEL_EXPLORER = 100;
+
+ /**
+ * @param elementsToRefresh
+ * Element to Refresh
+ */
+ public RefreshModelExplorerRunnable(Collection<EObject> elementsToRefresh) {
+ this.elementsToRefresh = elementsToRefresh;
+ }
+
+ public void run() {
+
+ try {
+ Thread.sleep(TIME_TO_REFRESH_MODEL_EXPLORER);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ if(elementsToRefresh != null) {
+ IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ if(activePage != null) {
+ IViewReference viewRef = activePage.findViewReference(ModelExplorerPageBookView.VIEW_ID);
+ if(viewRef != null && viewRef.getView(false) instanceof ModelExplorerView) {
+ ModelExplorerView modelExplorerView = (ModelExplorerView)viewRef.getView(false);
+ modelExplorerView.refresh();
+// Set<Object> alreadyRefreshed = new HashSet<Object>();
+// if(view != null) {
+// for(EObject elementToRefresh : elementsToRefresh) {
+//
+// view.refreshObject(elementToRefresh, alreadyRefreshed);
+// alreadyRefreshed.add(elementToRefresh);
+// }
+// }
+ }
+ }
+// IViewReference[] viewReferences = activePage.getViewReferences();
+// for(IViewReference viewRef : viewReferences) {
+// if(viewRef.getId().equals(ModelExplorerPageBookView.VIEW_ID));
+// }
+
+ }
+ }
+ }
+
+ protected static final String ELEMENTS_TO_REFRESH_KEY = "elementsToRefresh"; //$NON-NLS-1$
+
+ /**
+ * Get the model explorer refresh command
+ *
+ * @param request
+ * IEditCommandRequest which implies refresh
+ * @return
+ */
+ public static ICommand getRefreshCommand(final IEditCommandRequest request) {
+ return new AbstractCommand("Refresh") //$NON-NLS-1$
+ {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ refreshPostMove(request);
+ return CommandResult.newOKCommandResult();
+ }
+
+ @Override
+ protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ refreshPostMove(request);
+ return CommandResult.newOKCommandResult();
+ }
+
+ @Override
+ protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ refreshPostMove(request);
+ return CommandResult.newOKCommandResult();
+ }
+ };
+ }
+
+ /**
+ * Function to asynchronously refresh the model explorer after moving a breakdown element.
+ *
+ * @param request
+ */
+ private static void refreshPostMove(final IEditCommandRequest request) {
+ @SuppressWarnings("unchecked")
+ final Set<EObject> elementsToRefresh = (Set<EObject>)request.getParameter(ELEMENTS_TO_REFRESH_KEY);
+
+ refreshModelExplorer(elementsToRefresh);
+ }
+
+ public static void refreshModelExplorer(Collection<EObject> elementsToRefresh) {
+ if(elementsToRefresh != null && !(elementsToRefresh.isEmpty())) {
+ Display.getDefault().asyncExec(new RefreshModelExplorerRunnable(elementsToRefresh));
+ }
+ }
+
+ /**
+ * Adds an element to the list of elements that should be refreshed, in the request.
+ *
+ * @param element
+ * Element you want to refresh
+ * @param request
+ * Request in which the information about a refresh will be added
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public static void addElementToRefresh(EObject element, IEditCommandRequest request) {
+ Object elementsToRefresh = request.getParameter(ELEMENTS_TO_REFRESH_KEY);
+ if(elementsToRefresh == null) {
+ elementsToRefresh = new HashSet<EObject>();
+ request.getParameters().put(ELEMENTS_TO_REFRESH_KEY, elementsToRefresh);
+ }
+ if(elementsToRefresh instanceof Set<?>) {
+ ((Set)elementsToRefresh).add(element);
+ }
+ }
+
+ /**
+ * Checks whether a request has elements to refresh;
+ *
+ * @param request
+ * Request in which the information about a refresh will be added
+ * @return
+ */
+ public static boolean hasElementsToRefresh(IEditCommandRequest request) {
+ Object elementsToRefresh = request.getParameter(ELEMENTS_TO_REFRESH_KEY);
+ return elementsToRefresh instanceof Set<?> && (!((Set<?>)elementsToRefresh).isEmpty());
+ }
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/security/CollabReadOnlyHandler.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/security/CollabReadOnlyHandler.java
new file mode 100644
index 00000000000..8af6a52911d
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/security/CollabReadOnlyHandler.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.security;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edit.domain.EditingDomain;
+//import org.eclipse.papyrus.infra.emf.readonly.IReadOnlyHandler;
+import org.eclipse.papyrus.infra.core.resource.IReadOnlyHandler;
+import org.eclipse.papyrus.infra.emf.readonly.AbstractReadOnlyHandler;
+import org.eclipse.papyrus.team.collaborative.core.ICollaborativeManager;
+import org.eclipse.papyrus.team.collaborative.core.IExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.participants.locker.ILocker;
+import org.eclipse.papyrus.team.collaborative.core.utils.CollabFunctionsFactory;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.actions.LockAction;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
+
+/**
+ * The Class CollabReadOnlyHandler.
+ * This read only handler implement {@link IReadOnlyHandler} using the collaborative framework
+ */
+public class CollabReadOnlyHandler extends AbstractReadOnlyHandler {
+
+ public CollabReadOnlyHandler(EditingDomain editingDomain) {
+ super(editingDomain);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.readonly.IReadOnlyHandler#isReadOnly(org.eclipse.emf.common.util.URI[], org.eclipse.emf.edit.domain.EditingDomain)
+ */
+ public Optional<Boolean> anyReadOnly(URI[] uris) {
+ if(uris != null && uris.length > 0 && getEditingDomain() != null) {
+ ArrayList<URI> urisList = Lists.newArrayList(uris);
+ Collection<IExtendedURI> extendedURICollection = Collections2.transform(urisList, CollabFunctionsFactory.getURIToExtendedURIWithContainment());
+ HashSet<IExtendedURI> extendURISet = Sets.newHashSet(extendedURICollection);
+ ResourceSet resourceSet = getEditingDomain().getResourceSet();
+ if(ICollaborativeManager.INSTANCE.isCollab(extendURISet, resourceSet)) {
+ ILocker locker;
+ locker = ICollaborativeManager.INSTANCE.getLocker(extendURISet, resourceSet);
+ if(locker == null) {
+ return Optional.absent();
+ }
+ for(IExtendedURI extendURI : locker.getExtendedSet()) {
+ if(!locker.isLocked(extendURI).isOK()) {
+ return Optional.of(true);
+ }
+ }
+ }
+ }
+ return Optional.absent();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.readonly.IReadOnlyHandler#enableWrite(org.eclipse.emf.common.util.URI[], org.eclipse.emf.edit.domain.EditingDomain)
+ */
+ public Optional<Boolean> makeWritable(URI[] uris) {
+ ArrayList<URI> urisList = Lists.newArrayList(uris);
+ Collection<IExtendedURI> extendedURICollection = Collections2.transform(urisList, CollabFunctionsFactory.getURIToExtendedURIWithContainment());
+ HashSet<IExtendedURI> extendedURISet = Sets.newHashSet(extendedURICollection);
+ ResourceSet resourceSet = getEditingDomain().getResourceSet();
+ if(ICollaborativeManager.INSTANCE.isCollab(extendedURISet, resourceSet)) {
+ IStatus status = LockAction.doSafeLock(resourceSet, extendedURISet, true);
+ if(!status.isOK()) {
+ return Optional.absent();
+ }
+ return Optional.of(true);
+ }
+ return Optional.absent();
+ }
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/security/PreCommitReadOnlyHandler.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/security/PreCommitReadOnlyHandler.java
new file mode 100644
index 00000000000..7ff8b5335be
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/security/PreCommitReadOnlyHandler.java
@@ -0,0 +1,139 @@
+package org.eclipse.papyrus.team.collaborative.strategy.security;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.NotificationFilter;
+import org.eclipse.emf.transaction.ResourceSetChangeEvent;
+import org.eclipse.emf.transaction.ResourceSetListenerImpl;
+import org.eclipse.emf.transaction.RollbackException;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.resource.IModelSetSnippet;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
+import org.eclipse.papyrus.team.collaborative.core.ICollaborativeManager;
+import org.eclipse.papyrus.team.collaborative.core.IExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.participants.locker.ILocker;
+import org.eclipse.papyrus.team.collaborative.core.utils.CollabFunctionsFactory;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.actions.LockAction;
+import org.eclipse.papyrus.team.collaborative.strategy.utils.UIUtils;
+
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Sets;
+
+
+/**
+ * This model snippet will register a new {@link ResourceSetListener} that will provide a new security on modifed resources.
+ * Each time a resource will be set to modified this listener will check that the resources has been locked. If the resources is not lock then it will
+ * try to rollback the current transaction
+ *
+ * @author adaussy
+ *
+ */
+public class PreCommitReadOnlyHandler implements IModelSetSnippet {
+
+ /**
+ * This {@link ResourceSetListener} will listen each time a resource is modified to check that it has been locked or will ask for lock
+ *
+ * @author adaussy
+ *
+ */
+ private static class ResourceSetListener extends ResourceSetListenerImpl {
+
+ @Override
+ public boolean isPostcommitOnly() {
+ return false;
+ }
+
+ @Override
+ public boolean isPrecommitOnly() {
+ return true;
+ }
+
+ @Override
+ public boolean isAggregatePrecommitListener() {
+ return false;
+ }
+
+ /**
+ * Filter only IS_MODIFIED notification
+ */
+ private static NotificationFilter filter = NotificationFilter.createFeatureFilter(Resource.class, Resource.RESOURCE__IS_MODIFIED);
+
+ @Override
+ public NotificationFilter getFilter() {
+ return filter;
+ }
+
+
+ @Override
+ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
+ final Set<Resource> resourceToTest = new HashSet<Resource>();
+ for(Notification n : event.getNotifications()) {
+ if(n.getNewBooleanValue()) {
+ Resource resource = (Resource)n.getNotifier();
+ //Filtered out any DI resource. Those resource are not collaborative resources
+ if(!DiModel.MODEL_FILE_EXTENSION.equals(resource.getURI().fileExtension())) {
+ resourceToTest.add(resource);
+ }
+ }
+ }
+ if(!resourceToTest.isEmpty()) {
+ TransactionalEditingDomain editingDomain = event.getEditingDomain();
+ ResourceSet resourceSet = editingDomain.getResourceSet();
+ HashSet<IExtendedURI> uriToTest = Sets.newHashSet(Collections2.transform(resourceToTest, CollabFunctionsFactory.getResourceToExtendedURIWithContainment()));
+ if(ICollaborativeManager.INSTANCE.isCollab(uriToTest, resourceSet)) {
+ Set<IExtendedURI> uriToLock = new HashSet<IExtendedURI>();
+ ILocker locker = ICollaborativeManager.INSTANCE.getLocker(uriToTest, resourceSet);
+ if(locker == null) {
+ return null;
+ }
+ for(IExtendedURI extendURI : locker.getExtendedSet()) {
+ if(!locker.isLocked(extendURI).isOK()) {
+ uriToLock.add(extendURI);
+ }
+ }
+ if(!uriToLock.isEmpty()) {
+ final IStatus status = LockAction.doSafeLock(resourceSet, uriToLock, true);
+ if(!status.isOK()) {
+ UIUtils.errorDialog(status, "Unable to lock");
+ throw new RollbackException(status);
+
+ }
+ }
+ }
+ }
+ return null;
+ }
+ }
+
+ public PreCommitReadOnlyHandler() {
+ }
+
+
+ private WeakHashMap<EditingDomain, ResourceSetListener> link = new WeakHashMap<EditingDomain, PreCommitReadOnlyHandler.ResourceSetListener>();
+
+ public void start(ModelSet modelsManager) {
+ TransactionalEditingDomain transactionalEditingDomain = modelsManager.getTransactionalEditingDomain();
+ ResourceSetListener listener = new ResourceSetListener();
+ link.put(transactionalEditingDomain, listener);
+ transactionalEditingDomain.addResourceSetListener(listener);
+
+ }
+
+ public void dispose(ModelSet modelsManager) {
+ TransactionalEditingDomain transactionalEditingDomain = modelsManager.getTransactionalEditingDomain();
+ transactionalEditingDomain.removeResourceSetListener(link.get(transactionalEditingDomain));
+
+ }
+
+
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/stategies/AbstractResourceBaseStrategy.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/stategies/AbstractResourceBaseStrategy.java
new file mode 100644
index 00000000000..37f18bb978c
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/stategies/AbstractResourceBaseStrategy.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.stategies;
+
+import java.util.Collection;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.papyrus.team.collaborative.core.strategy.AbstractLockingStrategy;
+import org.eclipse.papyrus.team.collaborative.strategy.utils.PapyrusResourceUtils;
+
+
+/**
+ * The Class AbstractResourceBaseStrategy.
+ * Abstract class for strategy based on resources
+ * TODO remove this class after release
+ */
+public abstract class AbstractResourceBaseStrategy extends AbstractLockingStrategy {
+
+
+
+ /**
+ * Add all satellite resources (uml,di,notation).
+ *
+ * @param ressourceSet
+ * the ressource set
+ * @param uris
+ * the uris
+ * @param uri
+ * the uri
+ */
+ protected void addExtraResources(ResourceSet ressourceSet, Collection<URI> uris, URI uri) {
+ PapyrusResourceUtils.addExtraResources(ressourceSet, uris, uri);
+ }
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/stategies/PapyrusCurrentResource.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/stategies/PapyrusCurrentResource.java
new file mode 100644
index 00000000000..e155365316a
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/stategies/PapyrusCurrentResource.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.stategies;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.papyrus.team.collaborative.core.IExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.utils.CollabFunctionsFactory;
+import org.eclipse.papyrus.team.collaborative.core.utils.ModelsUtil;
+
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Sets;
+
+
+/**
+ * Strategy that will lock the current triplet resource of the selection (uml,di,notation).
+ *
+ * @author adaussy
+ */
+public class PapyrusCurrentResource extends AbstractResourceBaseStrategy {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.team.collaborative.core.strategy.ILockingStrategy#getBusinessObject(java.util.Collection)
+ */
+ public Set<IExtendedURI> getBusinessObject(Collection<EObject> eOjbects) {
+ if(!eOjbects.isEmpty()) {
+ ResourceSet ressourceSet = eOjbects.iterator().next().eResource().getResourceSet();
+ Collection<URI> uris = new HashSet<URI>();
+ for(EObject o : ModelsUtil.getRoots(eOjbects)) {
+ URI uri = o.eResource().getURI();
+ if(!uris.contains(uri)) {
+ uris.add(uri);
+ addExtraResources(ressourceSet, uris, uri);
+ }
+ }
+ return Sets.newHashSet(Collections2.transform(uris, CollabFunctionsFactory.getURIToExtendedURI()));
+ }
+ return Collections.emptySet();
+ }
+
+
+
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/stategies/PapyrusSelectionAllContent.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/stategies/PapyrusSelectionAllContent.java
new file mode 100644
index 00000000000..0285e5d8b0a
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/stategies/PapyrusSelectionAllContent.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.stategies;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.papyrus.team.collaborative.core.IExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.utils.CollabFunctionsFactory;
+import org.eclipse.papyrus.team.collaborative.core.utils.ModelsUtil;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Sets;
+
+
+/**
+ * Locking strategy that will lock all resources which contains element contained by the selection.
+ *
+ * @author adaussy
+ */
+public class PapyrusSelectionAllContent extends AbstractResourceBaseStrategy {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.team.collaborative.core.strategy.ILockingStrategy#getBusinessObject(java.util.Collection)
+ */
+ public Set<IExtendedURI> getBusinessObject(Collection<EObject> eOjbects) {
+ if(!eOjbects.isEmpty()) {
+ ResourceSet ressourceSet = eOjbects.iterator().next().eResource().getResourceSet();
+ Collection<URI> uris = new HashSet<URI>();
+ for(EObject o : ModelsUtil.getRoots(eOjbects)) {
+ URI uri = o.eResource().getURI();
+ if(!uris.contains(uri)) {
+ uris.add(uri);
+ addExtraResources(ressourceSet, uris, uri);
+ }
+ Predicate<Resource> semanticResourcePredicate = new Predicate<Resource>() {
+
+ public boolean apply(Resource input) {
+ return "uml".equals(input.getURI().fileExtension());
+ }
+ };
+ //Add all resource that contains at least one descendant of a selected resource
+ for(Resource r : Collections2.filter(ressourceSet.getResources(), semanticResourcePredicate)) {
+ for(EObject potentialDescedant : r.getContents()) {
+ if(EcoreUtil.isAncestor(o, potentialDescedant)) {
+ URI childResourceURI = r.getURI();
+ if(!uris.contains(childResourceURI)) {
+ uris.add(childResourceURI);
+ addExtraResources(ressourceSet, uris, childResourceURI);
+ continue;
+ }
+ }
+ }
+ }
+ }
+ return Sets.newHashSet(Collections2.transform(uris, CollabFunctionsFactory.getURIToExtendedURIWithContainment()));
+ }
+ return Collections.emptySet();
+ }
+
+
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/ICollabColors.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/ICollabColors.java
new file mode 100644
index 00000000000..5689efbe888
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/ICollabColors.java
@@ -0,0 +1,20 @@
+package org.eclipse.papyrus.team.collaborative.strategy.ui;
+
+import org.eclipse.papyrus.team.collaborative.strategy.utils.UIUtils;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+
+
+public interface ICollabColors {
+
+ public static final Color COMMIT_COLLOR = UIUtils.RESOURCE_MANAGER.createColor(new RGB(255, 65, 72));
+
+ public static final Color UPDATE_COLLOR = UIUtils.RESOURCE_MANAGER.createColor(new RGB(133, 255, 161));
+
+ public static final Color REVERT_COLLOR = UIUtils.RESOURCE_MANAGER.createColor(new RGB(255, 215, 78));
+
+ public static final Color UNLOCK_COLLOR = UIUtils.RESOURCE_MANAGER.createColor(new RGB(172, 209, 62));
+
+ public static final Color LOCK_COLLOR = UIUtils.RESOURCE_MANAGER.createColor(new RGB(232, 132, 59));
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/AbstractCollabHandler.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/AbstractCollabHandler.java
new file mode 100644
index 00000000000..7b2e3f7511c
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/AbstractCollabHandler.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.ui.actions;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.team.collaborative.core.utils.CollabUtils;
+import org.eclipse.papyrus.team.collaborative.strategy.utils.UIUtils;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * Abstract class for Collaborative handler which are enable only if the project is collaborative.
+ *
+ * @author adaussy
+ */
+public abstract class AbstractCollabHandler extends AbstractHandler {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+ */
+ @Override
+ public boolean isEnabled() {
+ EObject firstSelection = UIUtils.getFirstSelection();
+ if(firstSelection != null) {
+ return CollabUtils.isCollab(firstSelection);
+ }
+ return false;
+ }
+
+ protected ResourceSet getResourceSet() {
+ IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ if(editor instanceof CoreMultiDiagramEditor) {
+ CoreMultiDiagramEditor papyrusEditor = (CoreMultiDiagramEditor)editor;
+ return papyrusEditor.getEditingDomain().getResourceSet();
+ } else {
+ return null;
+ }
+ }
+
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/CommitHandler.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/CommitHandler.java
new file mode 100644
index 00000000000..1b98f502369
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/CommitHandler.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.ui.actions;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.papyrus.team.collaborative.core.ExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.ICollaborativeManager;
+import org.eclipse.papyrus.team.collaborative.core.IExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.participants.version.ICommitter;
+import org.eclipse.papyrus.team.collaborative.core.reports.CollabStatus;
+import org.eclipse.papyrus.team.collaborative.strategy.MatchingURIObject;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.ICollabColors;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.dialogs.CommitDialog;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.dialogs.PreviewDialog;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.providers.ExtensivePartitionNameLabelProvider;
+import org.eclipse.papyrus.team.collaborative.strategy.utils.UIUtils;
+import org.eclipse.swt.widgets.Display;
+
+
+/**
+ * Handler use to deal with Commit action
+ * The commit action will be performed on all the current model
+ *
+ * @author adaussy
+ */
+public class CommitHandler extends AbstractCollabHandler {
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ //Check that everything is commit
+ if(!UIUtils.saveAllDirtyEditor().isOK()) {
+ return null;
+ }
+ ResourceSet resourceSet = getResourceSet();
+ if(resourceSet == null) {
+ UIUtils.errorDialog(CollabStatus.createErrorStatus("unable to retreive the resource set"), "Collaboratibe error");
+ return null;
+ }
+ Set<IExtendedURI> uris = new HashSet<IExtendedURI>();
+ for(Resource r : resourceSet.getResources()) {
+ IFile file = WorkspaceSynchronizer.getFile(r);
+ if(file != null && file.exists()) {
+ uris.add(new ExtendedURI(r.getURI()));
+ }
+ }
+ IStatus status = doCommit(uris, resourceSet, true, null);
+ if(!status.isOK() && status.getCode() == Status.ERROR) {
+ UIUtils.errorDialog(status, "Error");
+ }
+ return null;
+
+
+ }
+
+ /**
+ * Do commit action
+ *
+ * @param uris
+ * the uris to commit
+ * @param resourceSet
+ * the resource set
+ * @param isPreview
+ * Set to true if the used to be given preview
+ * @param message
+ * the message used for the commit operation
+ * @return the {@link IStatus} of the operation
+ */
+ public static IStatus doCommit(Set<IExtendedURI> uris, ResourceSet resourceSet, boolean isPreview, String message) {
+ ICommitter committer = ICollaborativeManager.INSTANCE.getCommitter(uris, resourceSet);
+ if(committer == null) {
+ return CollabStatus.createErrorStatus("Unable to get a ICommitter for uris\n" + uris);
+ }
+ Set<IExtendedURI> toBeCommitted = committer.getExtendedSet();
+ IStatus status = doCommitFromBuilder(resourceSet, committer, toBeCommitted, isPreview, message);
+ if(!status.isOK()) {
+ return status;
+ }
+ return Status.OK_STATUS;
+
+ }
+
+ /**
+ * Do commit from builder using a already created {@link ICommitter}
+ *
+ * @param resourceSet
+ * the resource set
+ * @param committer
+ * the {@link ICommitter} to use
+ * @param toBeCommitted
+ * {@link IExtendedURI} of what is about to be committed
+ * @param isPreview
+ * Set to true if the user has to be given preview
+ * @param message
+ * the message
+ * @return the i status
+ * @throws CollabException
+ * the collab exception
+ */
+ public static IStatus doCommitFromBuilder(ResourceSet resourceSet, ICommitter committer, Set<IExtendedURI> toBeCommitted, boolean isPreview, String message) {
+ if(isPreview || message == null) {
+ ExtensivePartitionNameLabelProvider labelProvider = new ExtensivePartitionNameLabelProvider(new MatchingURIObject(toBeCommitted),UIUtils.getModelExplorerLavelProvider());
+ labelProvider.setColor(ICollabColors.COMMIT_COLLOR);
+ CommitDialog commitDialog = new CommitDialog(Display.getDefault().getActiveShell(), labelProvider, "Commit Dialog", "Element in red will be committed");
+ Collection<EObject> objectsToReveal = UIUtils.getLeafSemanticElement(toBeCommitted, resourceSet);
+ if(objectsToReveal != null && !objectsToReveal.isEmpty()) {
+ commitDialog.setObjectsToReveal(objectsToReveal);
+ }
+ if(commitDialog.open() == PreviewDialog.OK) {
+ message = commitDialog.getCommitMessage();
+ } else {
+ return Status.CANCEL_STATUS;
+ }
+ }
+
+ //Keep lock force to true. This shall be improve later
+ IStatus commitStatus = committer.commit(message, true);
+ UIUtils.refreshModelExplorer(toBeCommitted, resourceSet);
+ if(!commitStatus.isOK()) {
+ return commitStatus;
+ }
+ return Status.OK_STATUS;
+ }
+
+
+
+
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/LockAction.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/LockAction.java
new file mode 100644
index 00000000000..4860df8317e
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/LockAction.java
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.ui.actions;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.papyrus.team.collaborative.core.ICollaborativeManager;
+import org.eclipse.papyrus.team.collaborative.core.IExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.participants.locker.ILocker;
+import org.eclipse.papyrus.team.collaborative.core.participants.version.IUpdater;
+import org.eclipse.papyrus.team.collaborative.core.reports.CollabStatus;
+import org.eclipse.papyrus.team.collaborative.core.strategy.ILockingStrategy;
+import org.eclipse.papyrus.team.collaborative.core.strategy.ILockingStrategy.Descriptor;
+import org.eclipse.papyrus.team.collaborative.strategy.MatchingURIObject;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.ICollabColors;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.dialogs.PreviewDialog;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.providers.ExtensivePartitionNameLabelProvider;
+import org.eclipse.papyrus.team.collaborative.strategy.utils.UIUtils;
+import org.eclipse.swt.widgets.Display;
+
+
+/**
+ * The Class LockAction.
+ */
+public class LockAction extends Action {
+
+ /** The strategy. */
+ protected ILockingStrategy.Descriptor strategy;
+
+ /**
+ * Instantiates a new lock action.
+ *
+ * @param strategy
+ * the strategy
+ */
+ public LockAction(Descriptor strategy) {
+ super();
+ this.strategy = strategy;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ super.run();
+ Collection<EObject> selection = UIUtils.getSelection();
+ if(!selection.isEmpty()) {
+ IStatus status = doLock(selection, strategy);
+ if(!status.isOK()) {
+ UIUtils.errorDialog(status, "Unable to lock");
+ }
+ }
+ return;
+ }
+
+
+ /**
+ * Do lock action
+ *
+ * @param selection
+ * the selection
+ * @param strategy
+ * the strategy the selected {@link ILockingStrategy.Descriptor}
+ * @return the i status
+ */
+ public static IStatus doLock(Collection<EObject> selection, ILockingStrategy.Descriptor strategy) {
+ EObject eObject = selection.iterator().next();
+ ResourceSet resourceSet = eObject.eResource().getResourceSet();
+ //Execute the strategy to define the functional object to lock
+ Set<IExtendedURI> objectToLock = strategy.getStrategy().getBusinessObject(selection);
+ return doSafeLock(resourceSet, objectToLock, true);
+ }
+
+
+ /**
+ * Do lock action
+ *
+ * @param resourceSet
+ * the resource set
+ * @param objectToLock
+ * the {@link IExtendedURI} about to be locked
+ * @param usePreview
+ * Set to true if the user has to be given preview
+ * @return the {@link IStatus} of the operation
+ */
+ public static IStatus doSafeLock(ResourceSet resourceSet, Set<IExtendedURI> objectToLock, boolean usePreview) {
+ //Check that everything is up to date
+ IUpdater updater = ICollaborativeManager.INSTANCE.getUpdater(objectToLock, resourceSet);
+ if(updater == null) {
+ UIUtils.errorDialog(CollabStatus.createErrorStatus("Unable to find a updater"), "Unable to find a updater");
+ return CollabStatus.createErrorStatus("Unable to find a updater");
+ }
+ if(!updater.getExtendedSet().isEmpty()) {
+ if(MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Need update", "You need to update those elements in order to perform a lock")) {
+ IStatus status = UpdateHandler.doUpdateFromUpdater(resourceSet, updater, true);
+ if(!status.isOK()) {
+ UIUtils.errorDialog(status, "Error");
+ }
+ resourceSet = UIUtils.getCurrentResourceSet();
+ } else {
+ return CollabStatus.CANCEL_STATUS;
+ }
+ }
+
+ return doUnlock(resourceSet, objectToLock, usePreview);
+
+ }
+
+ protected static IStatus doUnlock(ResourceSet resourceSet, Set<IExtendedURI> objectToLock, boolean usePreview) {
+ ILocker locker = ICollaborativeManager.INSTANCE.getLocker(objectToLock, resourceSet);
+ if(locker == null) {
+ UIUtils.errorDialog(CollabStatus.createErrorStatus("Unable to find a locker"), "Unable to lock");
+ return CollabStatus.createErrorStatus("Unable to find a locker");
+ }
+
+ Set<IExtendedURI> needsLock = locker.getExtendedSet();
+ if(usePreview) {
+ //Check if the lock can be taken
+ ExtensivePartitionNameLabelProvider labelProvider = new ExtensivePartitionNameLabelProvider(new MatchingURIObject(needsLock),UIUtils.getModelExplorerLavelProvider());
+ labelProvider.setColor(ICollabColors.LOCK_COLLOR);
+ PreviewDialog previewDialog = new PreviewDialog(Display.getDefault().getActiveShell(), labelProvider, "Lock Preview", "Element in orange will be locked");
+ Collection<EObject> objectsToReveal = UIUtils.getLeafSemanticElement(needsLock, resourceSet);
+ if(objectsToReveal != null && !objectsToReveal.isEmpty()) {
+ previewDialog.setObjectsToReveal(objectsToReveal);
+ }
+ if(previewDialog.open() != PreviewDialog.OK) {
+ return CollabStatus.CANCEL_STATUS;
+ }
+ }
+ IStatus status = locker.lock();
+ UIUtils.refreshModelExplorer(needsLock, resourceSet);
+ return status;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.Action#getText()
+ */
+ @Override
+ public String getText() {
+ return strategy.getName();
+ }
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/RevertHandler.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/RevertHandler.java
new file mode 100644
index 00000000000..65eafd52834
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/RevertHandler.java
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.ui.actions;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.papyrus.team.collaborative.core.ExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.ICollaborativeManager;
+import org.eclipse.papyrus.team.collaborative.core.IExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.participants.version.IReverter;
+import org.eclipse.papyrus.team.collaborative.core.reports.CollabStatus;
+import org.eclipse.papyrus.team.collaborative.strategy.MatchingURIObject;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.ICollabColors;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.dialogs.PreviewDialog;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.providers.ExtensivePartitionNameLabelProvider;
+import org.eclipse.papyrus.team.collaborative.strategy.utils.UIUtils;
+import org.eclipse.swt.widgets.Display;
+
+
+// TODO: Auto-generated Javadoc
+/**
+ * Handler use for Revert action
+ * The revert action will be performe on all the current model.
+ *
+ * @author adaussy
+ */
+public class RevertHandler extends AbstractCollabHandler {
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ //Check that everything is commit
+ if(!UIUtils.saveAllDirtyEditor().isOK()) {
+ return null;
+ }
+ ResourceSet resourceSet = getResourceSet();
+ if(resourceSet == null) {
+ UIUtils.errorDialog(CollabStatus.createErrorStatus("unable to retreive the resource set"), "Collaboratibe error");
+ return null;
+ }
+ Set<IExtendedURI> uris = new HashSet<IExtendedURI>();
+ for(Resource r : resourceSet.getResources()) {
+ IFile file = WorkspaceSynchronizer.getFile(r);
+ if(file != null && file.exists()) {
+ uris.add(new ExtendedURI(r.getURI()));
+ }
+ }
+ IStatus status = doRevert(uris, resourceSet);
+ if(!status.isOK() && status.getCode() == Status.ERROR) {
+ UIUtils.errorDialog(status, "Error");
+ }
+
+ return null;
+
+ }
+
+ /**
+ * Do revert action
+ *
+ * @param uris
+ * the uris about to be reverted
+ * @param resourceSet
+ * the resource set
+ * @return the {@link IStatus} of the operation
+ * @throws CollabException
+ * the collab exception
+ */
+ public static IStatus doRevert(Set<IExtendedURI> uris, ResourceSet resourceSet) {
+
+ IReverter reverter = ICollaborativeManager.INSTANCE.getReverter(uris, resourceSet);
+ if(reverter == null) {
+ CollabStatus errorStatus = CollabStatus.createErrorStatus("Unable to find a reverter");
+ return errorStatus;
+ }
+
+ Set<IExtendedURI> toBeCommitted = reverter.getExtendedSet();
+ IStatus status = doRevertFromBuilder(resourceSet, reverter, toBeCommitted);
+ return status;
+
+ }
+
+ /**
+ * Do revert using an existing {@link IReverter}s
+ *
+ * @param resourceSet
+ * the resource set
+ * @param reverter
+ * the reverter
+ * @param toBeReverted
+ * the {@link IExtendedURI} about to be reverted
+ * @return the {@link IStatus} of the operation
+ * @throws CollabException
+ * the collab exception
+ */
+ public static IStatus doRevertFromBuilder(ResourceSet resourceSet, IReverter reverter, Set<IExtendedURI> toBeReverted) {
+ ExtensivePartitionNameLabelProvider labelProvider = new ExtensivePartitionNameLabelProvider(new MatchingURIObject(toBeReverted),UIUtils.getModelExplorerLavelProvider());
+ labelProvider.setColor(ICollabColors.REVERT_COLLOR);
+ PreviewDialog revertDialog = new PreviewDialog(Display.getDefault().getActiveShell(), labelProvider, "Revert Dialog", "Element in yellow will be reverted");
+ Collection<EObject> objectsToReveal = UIUtils.getLeafSemanticElement(toBeReverted, resourceSet);
+ if(objectsToReveal != null && !objectsToReveal.isEmpty()) {
+ revertDialog.setObjectsToReveal(objectsToReveal);
+ }
+ if(revertDialog.open() == PreviewDialog.OK) {
+
+ //Keep lock force to true. This shall be improve later
+ IStatus commitStatus = reverter.revert();
+ UIUtils.refreshModelExplorer(toBeReverted, resourceSet);
+ UIUtils.reloadEditor();
+ return commitStatus;
+ } else {
+ return Status.CANCEL_STATUS;
+ }
+ }
+
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/UnlockAction.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/UnlockAction.java
new file mode 100644
index 00000000000..44eaa08ea6d
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/UnlockAction.java
@@ -0,0 +1,179 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.ui.actions;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.papyrus.team.collaborative.core.ICollaborativeManager;
+import org.eclipse.papyrus.team.collaborative.core.IExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.participants.locker.IUnlocker;
+import org.eclipse.papyrus.team.collaborative.core.participants.version.ICommitter;
+import org.eclipse.papyrus.team.collaborative.core.reports.CollabStatus;
+import org.eclipse.papyrus.team.collaborative.core.strategy.ILockingStrategy;
+import org.eclipse.papyrus.team.collaborative.core.strategy.ILockingStrategy.Descriptor;
+import org.eclipse.papyrus.team.collaborative.strategy.MatchingURIObject;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.ICollabColors;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.dialogs.PreviewDialog;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.providers.ExtensivePartitionNameLabelProvider;
+import org.eclipse.papyrus.team.collaborative.strategy.utils.UIUtils;
+import org.eclipse.swt.widgets.Display;
+
+
+/**
+ * Handler for the Unlock action in Papyrus
+ */
+public class UnlockAction extends Action {
+
+ /** The strategy. */
+ protected ILockingStrategy.Descriptor strategy;
+
+ /**
+ * Instantiates a new unlock action.
+ *
+ * @param strategy
+ * the strategy
+ */
+ public UnlockAction(Descriptor strategy) {
+ super();
+ this.strategy = strategy;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ if(!UIUtils.saveAllDirtyEditor().isOK()) {
+ return;
+ }
+ Collection<EObject> selection = UIUtils.getSelection();
+ if(!selection.isEmpty()) {
+ IStatus status = doSafeUnlock(selection, strategy);
+ if(!status.isOK()) {
+ UIUtils.errorDialog(status, "Error during Unlock");
+ }
+ }
+ super.run();
+ }
+
+ /**
+ * Do unlock.
+ *
+ * @param selection
+ * The {@link EObject} selected by the user
+ * @param strategy
+ * the strategy use to compute the business object set to unlock
+ * @throws CollabException
+ * the collab exception
+ */
+ public static IStatus doSafeUnlock(Collection<EObject> selection, ILockingStrategy.Descriptor strategy) {
+ EObject firstSelectedObject = selection.iterator().next();
+ ResourceSet resourceSet = firstSelectedObject.eResource().getResourceSet();
+
+ //Execute the strategy to define the functional object to lock
+ Set<IExtendedURI> objectToLock = strategy.getStrategy().getBusinessObject(selection);
+ //First check there no modification uncommitted
+ ICommitter committer = ICollaborativeManager.INSTANCE.getCommitter(objectToLock, resourceSet);
+ if(committer == null) {
+ return CollabStatus.createErrorStatus("Unable to find an Committer");
+ }
+
+ IStatus preventUnlockingWithUntrackedModification = preventUnlockingWithUntrackedModification(resourceSet, objectToLock, committer, firstSelectedObject);
+ if(!preventUnlockingWithUntrackedModification.isOK()) {
+ return preventUnlockingWithUntrackedModification;
+ }
+ //Reset the resourceSet because the editor may have been reloaded
+ resourceSet = UIUtils.getCurrentResourceSet();
+
+ IUnlocker unlocker = ICollaborativeManager.INSTANCE.getUnlocker(objectToLock, resourceSet);
+ if(unlocker == null) {
+ return CollabStatus.createErrorStatus("Unable to find a unlocker for:\n " + objectToLock);
+ }
+ return doUnlock(resourceSet, unlocker);
+ }
+
+ protected static IStatus doUnlock(ResourceSet resourceSet, IUnlocker unlocker) {
+ Set<IExtendedURI> needUnlock = unlocker.getExtendedSet();
+ //Check if the lock can be taken
+ ExtensivePartitionNameLabelProvider labelProvider = new ExtensivePartitionNameLabelProvider(new MatchingURIObject(needUnlock),UIUtils.getModelExplorerLavelProvider());
+ labelProvider.setColor(ICollabColors.UNLOCK_COLLOR);
+ PreviewDialog unlockPreviewDialog = new PreviewDialog(Display.getDefault().getActiveShell(), labelProvider, "Unlock Preview", "Element in green will be unlocked");
+ Collection<EObject> objectsToReveal = UIUtils.getLeafSemanticElement(needUnlock, resourceSet);
+ if(objectsToReveal != null && !objectsToReveal.isEmpty()) {
+ unlockPreviewDialog.setObjectsToReveal(objectsToReveal);
+ }
+ if(unlockPreviewDialog.open() == PreviewDialog.OK) {
+ IStatus lockResult = unlocker.unlock();
+ UIUtils.refreshModelExplorer(needUnlock, resourceSet);
+ return lockResult;
+ } else {
+ return CollabStatus.CANCEL_STATUS;
+ }
+ }
+
+
+ /**
+ * Prevent unlocking with untracked modification.
+ *
+ * @param resourceSet
+ * the resource set
+ * @param objectToLock
+ * the object to lock
+ * @param committer
+ * the committer
+ * @param selected
+ * the selected
+ * @return the i status
+ */
+ private static IStatus preventUnlockingWithUntrackedModification(ResourceSet resourceSet, Set<IExtendedURI> objectToLock, ICommitter committer, EObject selected) {
+ Set<IExtendedURI> committableResource = committer.getExtendedSet();
+ if(!committableResource.isEmpty()) {
+ //The user shall either commit or revert it's changes
+ MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Modification in progess", null, "You have untrackted modification. You either have to commit it or revert it(Everything will be lost) to release the lock", MessageDialog.WARNING, new String[]{ "Commit", "Revert" }, 0);
+ int dialogResult = dialog.open();
+ if(dialogResult == 0) {
+ //then commit
+ return CommitHandler.doCommitFromBuilder(resourceSet, committer, committableResource, true, null);
+ } else if(dialogResult == 1) {
+ //then revert
+ return RevertHandler.doRevert(committableResource, resourceSet);
+ } else {
+ //cancel
+ return Status.CANCEL_STATUS;
+ }
+ }
+ return Status.OK_STATUS;
+ }
+
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.Action#getText()
+ */
+ @Override
+ public String getText() {
+ return strategy.getName();
+ }
+
+
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/UpdateHandler.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/UpdateHandler.java
new file mode 100644
index 00000000000..66d2a7ace19
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/actions/UpdateHandler.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.ui.actions;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.papyrus.team.collaborative.core.ExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.ICollaborativeManager;
+import org.eclipse.papyrus.team.collaborative.core.IExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.participants.version.IUpdater;
+import org.eclipse.papyrus.team.collaborative.core.reports.CollabStatus;
+import org.eclipse.papyrus.team.collaborative.strategy.MatchingURIObject;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.ICollabColors;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.dialogs.PreviewDialog;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.providers.ExtensivePartitionNameLabelProvider;
+import org.eclipse.papyrus.team.collaborative.strategy.utils.UIUtils;
+import org.eclipse.swt.widgets.Display;
+
+
+/**
+ * Handler for Update action in Papyrus
+ * The update will be performed in all the current model
+ */
+public class UpdateHandler extends AbstractCollabHandler {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ if(!UIUtils.saveAllDirtyEditor().isOK()) {
+ return null;
+ }
+ ResourceSet resourceSet = getResourceSet();
+ if(resourceSet == null) {
+ UIUtils.errorDialog(CollabStatus.createErrorStatus("unable to retreive the resource set"), "Collaboratibe error");
+ return null;
+ }
+ Set<IExtendedURI> uris = new HashSet<IExtendedURI>();
+ for(Resource r : resourceSet.getResources()) {
+ IFile file = WorkspaceSynchronizer.getFile(r);
+ if(file != null && file.exists()) {
+ uris.add(new ExtendedURI(r.getURI()));
+ }
+ }
+ IStatus status = doUpdate(uris, resourceSet, true);
+ if(!status.isOK()) {
+ UIUtils.errorDialog(status, "Error");
+ }
+ return null;
+
+ }
+
+ /**
+ * Do update action
+ *
+ * @param uris
+ * the {@link IExtendedURI} to update
+ * @param resourceSet
+ * the resource set
+ * @throws CollabException
+ * the collab exception
+ */
+ public static IStatus doUpdate(Set<IExtendedURI> uris, ResourceSet resourceSet, boolean preview) {
+ IUpdater updater = ICollaborativeManager.INSTANCE.getUpdater(uris, resourceSet);
+ if(updater == null) {
+ return CollabStatus.createErrorStatus("Unable to find an Updater for: \n" + uris);
+ }
+ return doUpdateFromUpdater(resourceSet, updater, preview);
+
+ }
+
+ public static IStatus doUpdateFromUpdater(ResourceSet resourceSet, IUpdater updater, boolean preview) {
+ Set<IExtendedURI> toUpdate = updater.getExtendedSet();
+ if(!toUpdate.isEmpty()) {
+ if(preview) {
+ ExtensivePartitionNameLabelProvider labelProvider = new ExtensivePartitionNameLabelProvider(new MatchingURIObject(toUpdate),UIUtils.getModelExplorerLavelProvider());
+ labelProvider.setColor(ICollabColors.UPDATE_COLLOR);
+ PreviewDialog previewDialog = new PreviewDialog(Display.getDefault().getActiveShell(), labelProvider, "Update Preview", "Element in light green will be updated");
+ Collection<EObject> objectsToReveal = UIUtils.getLeafSemanticElement(toUpdate, resourceSet);
+ if(objectsToReveal != null && !objectsToReveal.isEmpty()) {
+ previewDialog.setObjectsToReveal(objectsToReveal);
+ }
+ if(previewDialog.open() != PreviewDialog.OK) {
+ return CollabStatus.createErrorStatus("Canceled by user");
+ }
+ }
+ IStatus updateStatus = updater.update();
+ UIUtils.reloadEditor();
+ return updateStatus;
+ } else {
+ MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Nothing to do", "Nothing to update");
+ return Status.OK_STATUS;
+ }
+ }
+
+
+
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/dialogs/CommitDialog.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/dialogs/CommitDialog.java
new file mode 100644
index 00000000000..5c2233e9a94
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/dialogs/CommitDialog.java
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.ui.dialogs;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+
+/**
+ * Dialog used to gather inforamtion before commit
+ */
+public class CommitDialog extends PreviewDialog {
+
+ /** The toolkit. */
+ private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
+
+ /** The message value text. */
+ private Text messageValueText;
+
+ /**
+ * Instantiates a new commit dialog.
+ *
+ * @param parentShell
+ * the parent shell
+ * @param labelProvider
+ * the label provider
+ * @param title
+ * the title
+ * @param message
+ * the message
+ */
+ public CommitDialog(Shell parentShell, ILabelProvider labelProvider, String title, String message) {
+ super(parentShell, labelProvider, title, message);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.team.collaborative.core.integration.papyrus.ui.dialogs.PreviewDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Control result = super.createDialogArea(parent);
+ commitComposite((Composite)result, SWT.BORDER);
+ return result;
+
+ }
+
+ /** The message. */
+ protected String message = "";
+
+ /** The keep lock. */
+ protected boolean keepLock = false;
+
+ /**
+ * Commit composite.
+ *
+ * @param parent
+ * the parent
+ * @param style
+ * the style
+ * @return the composite
+ */
+ public Composite commitComposite(Composite parent, int style) {
+ Composite commitComposite = new Composite(parent, style);
+ commitComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ toolkit.adapt(commitComposite);
+ toolkit.paintBordersFor(commitComposite);
+ commitComposite.setLayout(new GridLayout(1, false));
+
+ Label lblMessage = new Label(commitComposite, SWT.NONE);
+ toolkit.adapt(lblMessage, true, true);
+ lblMessage.setText("Message:");
+
+ messageValueText = new Text(commitComposite, SWT.BORDER);
+ messageValueText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ messageValueText.addModifyListener(new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ message = messageValueText.getMessage();
+
+ }
+ });
+ toolkit.adapt(messageValueText, true, true);
+
+ Composite composite = new Composite(commitComposite, SWT.NONE);
+ toolkit.adapt(composite);
+ toolkit.paintBordersFor(composite);
+ composite.setLayout(new GridLayout(1, false));
+ return commitComposite;
+ }
+
+
+ /**
+ * Gets the commit message.
+ *
+ * @return the commit message
+ */
+ public String getCommitMessage() {
+ return message;
+ }
+
+
+ /**
+ * Checks if is keep lock.
+ *
+ * @return true, if is keep lock
+ */
+ public boolean isKeepLock() {
+ return keepLock;
+ }
+
+
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/dialogs/PreviewDialog.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/dialogs/PreviewDialog.java
new file mode 100644
index 00000000000..66c130333a6
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/dialogs/PreviewDialog.java
@@ -0,0 +1,279 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.ui.dialogs;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForWorkbenchPage;
+import org.eclipse.papyrus.uml.tools.providers.SemanticUMLContentProvider;
+import org.eclipse.papyrus.views.modelexplorer.CustomCommonViewer;
+import org.eclipse.papyrus.views.modelexplorer.matching.IMatchingItem;
+import org.eclipse.papyrus.views.modelexplorer.matching.ModelElementItemMatchingItem;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+
+
+/**
+ * The Class PreviewDialog.
+ * The preview dialog is a generic dialog use to display feedback to the user using specific {@link ILabelProvider}
+ */
+public class PreviewDialog extends TitleAreaDialog {
+
+
+ /** The title. */
+ private String title;
+
+ /** The message. */
+ private String message;
+
+ /** The label provider. */
+ private ILabelProvider labelProvider;
+
+ /** The tree viewer. */
+ private TreeViewer treeViewer;
+
+ /** The objects to reveal. */
+ private Collection<EObject> objectsToReveal;
+
+
+
+ /**
+ * Sets the objects to reveal.
+ *
+ * @param objectToReveal
+ * the new objects to reveal
+ */
+ public void setObjectsToReveal(Collection<EObject> objectToReveal) {
+ this.objectsToReveal = objectToReveal;
+ }
+
+ /**
+ * Create contents of the dialog.
+ *
+ * @param parent
+ * the parent
+ * @return the control
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ setMessage(message);
+ setTitle(title);
+ Composite area = (Composite)super.createDialogArea(parent);
+ Composite container = new Composite(area, SWT.NONE);
+ container.setLayout(new FillLayout(SWT.HORIZONTAL));
+ container.setLayoutData(new GridData(GridData.FILL_BOTH));
+ treeViewer = new CustomCommonViewer("org.eclipse.papyrus.modelexplorer.modelexplorer", container, SWT.BORDER);
+ treeViewer.setContentProvider(new SemanticUMLContentProvider() {
+
+// @Override
+// protected static EObject[] getRoots(ResourceSet root) {
+// if(root instanceof ModelSet) {
+// ModelSet modelSet = (ModelSet)root;
+// UmlModel umlModel = (UmlUtils.getUmlModel(modelSet));
+//
+// if(umlModel == null)
+// return null;
+//
+// EList<EObject> contents = umlModel.getResource().getContents();
+// ArrayList<EObject> result = new ArrayList<EObject>();
+// Iterator<EObject> iterator = contents.iterator();
+// while(iterator.hasNext()) {
+// EObject eObject = (EObject)iterator.next();
+// //Shall be improved
+// if(eObject.eClass().getEPackage().getNsURI().contains("uml")) {
+// result.add(eObject);
+// }
+// }
+// }
+// return result.toArray(new EObject[result.size()]);
+// }
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ //Remove duplicate
+ Object[] superChildren = super.getChildren(parentElement);
+
+ List<Object> result = new ArrayList<Object>();
+ for(int i = 0; i < superChildren.length; i++) {
+ Object c = superChildren[i];
+ if(!result.contains(c)) {
+ result.add(c);
+ }
+ }
+ return result.toArray(new Object[result.size()]);
+ }
+ });
+ treeViewer.setLabelProvider(labelProvider);
+
+ try {
+ IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ ServicesRegistry serviceRegistry = ServiceUtilsForWorkbenchPage.getInstance().getServiceRegistry(activePage);
+ treeViewer.setInput(serviceRegistry);
+ if(objectsToReveal != null) {
+ reveal(objectsToReveal);
+ }
+ } catch (ServiceException e) {
+ e.printStackTrace();
+ }
+
+ return area;
+ }
+
+ /**
+ * Create contents of the button bar.
+ *
+ * @param parent
+ * the parent
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+ }
+
+ /**
+ * Return the initial size of the dialog.
+ *
+ * @return the initial size
+ */
+ @Override
+ protected Point getInitialSize() {
+ return new Point(600, 600);
+ }
+
+ /**
+ * Create the dialog.
+ *
+ * @param parentShell
+ * the parent shell
+ * @param labelProvider
+ * the label provider
+ * @param title
+ * the title
+ * @param message
+ * the message
+ */
+ public PreviewDialog(Shell parentShell, ILabelProvider labelProvider, String title, String message) {
+ super(parentShell);
+ setShellStyle(SWT.SHELL_TRIM);
+ setHelpAvailable(false);
+ this.title = title;
+ this.message = message;
+ this.labelProvider = labelProvider;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.window.Window#open()
+ */
+ @Override
+ public int open() {
+ int result = super.open();
+ return result;
+ }
+
+
+
+ /**
+ * Reveal.
+ *
+ * @param elementList
+ * the element list
+ */
+ public void reveal(Iterable<?> elementList) {
+ ArrayList<IMatchingItem> matchingItemsToSelect = new ArrayList<IMatchingItem>();
+ // filter out non EMF objects
+ Iterable<EObject> list = Iterables.transform(Iterables.filter(elementList, EObject.class), new Function<Object, EObject>() {
+
+ public EObject apply(Object from) {
+ return (EObject)from;
+ }
+ });
+
+ for(EObject currentEObject : list) {
+ //TODO The custom ModelExplorer Revealer feature has not yet been backported.
+ //See bug 426360. For now, we only reveal the given EObjects.
+ //EObject itemToSelect = ModelExplorerRevealerManager.getTargetObjectToRegveal(currentEObject);
+ matchingItemsToSelect.add(new ModelElementItemMatchingItem(currentEObject));
+
+ // Does the content provider exist?
+ // if(treeViewer.getContentProvider() != null) {
+
+ /*
+ * reveal the ancestors tree using expandToLevel on each of them
+ * in the good order. This is a lot faster than going through the whole tree
+ * using getChildren of the ContentProvider since our Viewer uses a Hashtable
+ * to keep track of the revealed elements.
+ *
+ * However we need to use a dedicated MatchingItem to do the matching,
+ * and a specific comparer in our viewer so than the equals of MatchingItem is
+ * used in priority.
+ *
+ * Please refer to MatchingItem for more infos.
+ */
+ //for(IMatchingItem item : ModelExplorerRevealerManager.getChainToReveal(itemToSelect)) {
+ // treeViewer.expandToLevel(item, 1);
+ //}
+ //}
+ }
+ treeViewer.expandToLevel(new StructuredSelection(matchingItemsToSelect), TreeViewer.ALL_LEVELS);
+ }
+
+ /**
+ * Select reveal.
+ *
+ * @param selection
+ * the selection
+ */
+ public void selectReveal(ISelection selection) {
+ if(treeViewer != null) {
+ treeViewer.setSelection(selection, true);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.core.ui.IRevealSemanticElement#revealSemanticElement(java.util.List)
+ */
+ /**
+ * Reveal semantic element.
+ *
+ * @param elementList
+ * the element list
+ */
+ public void revealSemanticElement(List<?> elementList) {
+ reveal(elementList);
+ }
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/items/LockStrategyItemProvider.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/items/LockStrategyItemProvider.java
new file mode 100644
index 00000000000..5fbce1747e7
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/items/LockStrategyItemProvider.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.ui.items;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.papyrus.team.collaborative.core.ICollaborativeManager;
+import org.eclipse.papyrus.team.collaborative.core.strategy.ILockingStrategy;
+import org.eclipse.papyrus.team.collaborative.core.utils.CollabUtils;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.actions.LockAction;
+import org.eclipse.papyrus.team.collaborative.strategy.utils.UIUtils;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+
+
+/**
+ * Item provider which fill the menu with all lock strategy.
+ *
+ * @author adaussy
+ */
+public class LockStrategyItemProvider extends org.eclipse.ui.actions.CompoundContributionItem {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
+ */
+ @Override
+ protected IContributionItem[] getContributionItems() {
+ if(isEnabled()) {
+ Collection<ActionContributionItem> contribution = Collections2.transform(ICollaborativeManager.INSTANCE.getStrategies().values(), new Function<ILockingStrategy.Descriptor, ActionContributionItem>() {
+
+ public ActionContributionItem apply(final ILockingStrategy.Descriptor from) {
+
+ Action action = new LockAction(from);
+ ActionContributionItem actionContributionItem = new ActionContributionItem(action);
+ return actionContributionItem;
+ }
+ });
+ return contribution.toArray(new IContributionItem[contribution.size()]);
+ }
+
+ return new IContributionItem[0];
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.ContributionItem#isEnabled()
+ */
+ public boolean isEnabled() {
+ EObject firstSelection = UIUtils.getFirstSelection();
+ if(firstSelection != null) {
+ return CollabUtils.isCollab(firstSelection);
+ }
+ return false;
+ }
+
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/items/UnlockStrategyItemProvider.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/items/UnlockStrategyItemProvider.java
new file mode 100644
index 00000000000..7facfd2584d
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/items/UnlockStrategyItemProvider.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.ui.items;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.papyrus.team.collaborative.core.ICollaborativeManager;
+import org.eclipse.papyrus.team.collaborative.core.strategy.ILockingStrategy;
+import org.eclipse.papyrus.team.collaborative.core.utils.CollabUtils;
+import org.eclipse.papyrus.team.collaborative.strategy.ui.actions.UnlockAction;
+import org.eclipse.papyrus.team.collaborative.strategy.utils.UIUtils;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+
+
+/**
+ * Item provider which fill the menu with all unlock strategy.
+ */
+public class UnlockStrategyItemProvider extends org.eclipse.ui.actions.CompoundContributionItem {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
+ */
+ @Override
+ protected IContributionItem[] getContributionItems() {
+ if(isEnabled()) {
+ Collection<ActionContributionItem> contribution = Collections2.transform(ICollaborativeManager.INSTANCE.getStrategies().values(), new Function<ILockingStrategy.Descriptor, ActionContributionItem>() {
+
+ public ActionContributionItem apply(final ILockingStrategy.Descriptor from) {
+
+ Action action = new UnlockAction(from);
+ ActionContributionItem actionContributionItem = new ActionContributionItem(action);
+ return actionContributionItem;
+ }
+ });
+
+
+ return contribution.toArray(new IContributionItem[contribution.size()]);
+ }
+
+ return new IContributionItem[0];
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.ContributionItem#isEnabled()
+ */
+ public boolean isEnabled() {
+ EObject firstSelection = UIUtils.getFirstSelection();
+ if(firstSelection != null) {
+ return CollabUtils.isCollab(firstSelection);
+ }
+ return false;
+ }
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/providers/ExtensivePartitionNameLabelProvider.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/providers/ExtensivePartitionNameLabelProvider.java
new file mode 100644
index 00000000000..4926945c839
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/ui/providers/ExtensivePartitionNameLabelProvider.java
@@ -0,0 +1,217 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.ui.providers;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.facet.infra.browser.uicore.internal.model.ModelElementItem;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IFontProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+
+import com.google.common.base.Predicate;
+
+
+/**
+ * The Class ExtensiveLabelProvider. {@link ILabelProvider} that extend the one use by the model explorer view.
+ * This label provider can customize label and color of display object using predicate
+ */
+public class ExtensivePartitionNameLabelProvider implements IFontProvider, IColorProvider, ILabelProvider {
+
+
+ private ILabelProvider internal;
+
+
+ /** The color. */
+ private Color color;
+
+ /** The font. */
+ private Font font;
+
+ /** The predicate. */
+ private Predicate<EObject> predicate;
+
+ /**
+ * Instantiates a new extensive label provider.
+ *
+ * @param predicate
+ * the predicate
+ */
+ public ExtensivePartitionNameLabelProvider(Predicate<EObject> predicate, ILabelProvider internal) {
+ super();
+ this.predicate = predicate;
+ this.internal = internal;
+ }
+
+ public ExtensivePartitionNameLabelProvider(ILabelProvider internal) {
+ super();
+ this.predicate = null;
+ this.internal = internal;
+ }
+
+
+ /**
+ * Sets the color.
+ *
+ * @param color
+ * the new color
+ */
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+
+ /**
+ * Sets the font.
+ *
+ * @param font
+ * the new font
+ */
+ public void setFont(Font font) {
+ this.font = font;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.modelexplorer.MoDiscoLabelProvider#getText(java.lang.Object)
+ */
+ public String getText(Object element) {
+ String superText = internal.getText(element);
+ if(element instanceof ModelElementItem) {
+ ModelElementItem elem = (ModelElementItem)element;
+ EObject eObject = elem.getEObject();
+ if(eObject != null) {
+ String partitionName = getPartitionName(eObject);
+ if(partitionName != null) {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(partitionName);
+ stringBuilder.append(superText);
+ superText = stringBuilder.toString();
+ }
+ }
+ }
+ return superText;
+ }
+
+ private static final String CLOSING_BRACKET = "] ";
+
+ private static final String OPEN_BRACKET = "[";
+
+
+ /**
+ * Gets the partition name.
+ *
+ * @param eObject
+ * the e object
+ * @return the partition name
+ */
+ protected String getPartitionName(EObject eObject) {
+ Resource resource = eObject.eResource();
+ if(resource != null) {
+ URI uri = resource.getURI().trimFileExtension();
+ String partitionName = uri.segment(uri.segmentCount() - 1);
+ StringBuilder builder = new StringBuilder(OPEN_BRACKET);
+ builder.append(partitionName);
+ builder.append(CLOSING_BRACKET);
+ return builder.toString();
+ }
+ return null;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.facet.infra.browser.uicore.CustomizableModelLabelProvider#getFont(java.lang.Object)
+ */
+ @SuppressWarnings("restriction")
+ public Font getFont(Object element) {
+ if(predicate != null) {
+ if(element instanceof ModelElementItem) {
+ ModelElementItem eObject = (ModelElementItem)element;
+ if(font != null) {
+ if(predicate.apply(eObject.getEObject())) {
+ return font;
+ }
+ }
+ }
+ }
+ if(internal instanceof IFontProvider) {
+ return ((IFontProvider)internal).getFont(element);
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.facet.infra.browser.uicore.CustomizableModelLabelProvider#getForeground(java.lang.Object)
+ */
+ @SuppressWarnings("restriction")
+ public Color getForeground(Object element) {
+ if(predicate != null) {
+ if(element instanceof ModelElementItem) {
+ ModelElementItem eObject = (ModelElementItem)element;
+ if(color != null) {
+ if(predicate.apply(eObject.getEObject())) {
+ return color;
+ }
+ }
+ }
+ }
+ if(internal instanceof IColorProvider) {
+ return ((IColorProvider)internal).getForeground(element);
+ }
+ return null;
+ }
+
+
+ public void addListener(ILabelProviderListener listener) {
+ internal.addListener(listener);
+
+ }
+
+
+ public void dispose() {
+ internal.dispose();
+
+ }
+
+
+ public boolean isLabelProperty(Object element, String property) {
+ return internal.isLabelProperty(element, property);
+ }
+
+
+ public void removeListener(ILabelProviderListener listener) {
+ internal.removeListener(listener);
+
+ }
+
+
+ public Image getImage(Object element) {
+ return internal.getImage(element);
+ }
+
+
+ public Color getBackground(Object element) {
+ if(internal instanceof IColorProvider) {
+ return ((IColorProvider)internal).getBackground(element);
+ }
+ return null;
+ }
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/utils/PapyrusResourceUtils.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/utils/PapyrusResourceUtils.java
new file mode 100644
index 00000000000..47ca49beb10
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/utils/PapyrusResourceUtils.java
@@ -0,0 +1,30 @@
+package org.eclipse.papyrus.team.collaborative.strategy.utils;
+
+import java.util.Collection;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
+import org.eclipse.papyrus.team.collaborative.core.utils.URIUtils;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+
+
+public class PapyrusResourceUtils {
+
+ private static final String[] FILE_EXTENSIONS = new String[]{ UmlModel.UML_FILE_EXTENSION, NotationModel.NOTATION_FILE_EXTENSION, DiModel.MODEL_FILE_EXTENSION };
+
+
+ public static void addExtraResources(ResourceSet ressourceSet, Collection<URI> uris, URI uri) {
+ String currentExtension = uri.fileExtension();
+ for(String ext : FILE_EXTENSIONS) {
+ if(!ext.equals(currentExtension)) {
+ URI sateliteResource = URIUtils.getSateliteResource(uri, ext);
+ if(URIUtils.isResourceURI(sateliteResource, ressourceSet)) {
+ uris.add(sateliteResource);
+ }
+ }
+ }
+ }
+
+}
diff --git a/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/utils/UIUtils.java b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/utils/UIUtils.java
new file mode 100644
index 00000000000..0a0f6593907
--- /dev/null
+++ b/extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/utils/UIUtils.java
@@ -0,0 +1,291 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Atos
+ * 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:
+ * Arthur Daussy - initial implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.team.collaborative.strategy.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IAdapterManager;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.gmf.runtime.common.ui.dialogs.SaveAllDirtyEditorsDialog;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForWorkbenchPage;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.team.collaborative.core.IExtendedURI;
+import org.eclipse.papyrus.team.collaborative.core.reports.CollabStatus;
+import org.eclipse.papyrus.team.collaborative.core.reports.LogHelper;
+import org.eclipse.papyrus.team.collaborative.core.utils.CollabFunctionsFactory;
+import org.eclipse.papyrus.team.collaborative.core.utils.ModelsUtil;
+import org.eclipse.papyrus.team.collaborative.strategy.Activator;
+import org.eclipse.papyrus.team.collaborative.strategy.RefreshHelper;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+
+
+/**
+ * Utility class for User Interface interactions.
+ *
+ * @author adaussy
+ */
+public class UIUtils {
+
+ /** The resource manager. */
+ public static LocalResourceManager RESOURCE_MANAGER = new LocalResourceManager(JFaceResources.getResources());
+
+ /**
+ * Save all dirty editor.
+ *
+ * @return the {@link IStatus}
+ */
+ public static IStatus saveAllDirtyEditor() {
+ //Force save
+ IEditorPart[] dirtyEditors = SaveAllDirtyEditorsDialog.getDirtyEditors();
+ if(dirtyEditors.length > 0) {
+ SaveAllDirtyEditorsDialog dialog = new SaveAllDirtyEditorsDialog(Display.getDefault().getActiveShell());
+ if(dialog.open() == SaveAllDirtyEditorsDialog.CANCEL) {
+ return Status.CANCEL_STATUS;
+ } else {
+ for(int i = 0; i < dirtyEditors.length; i++) {
+ IEditorPart editorI = dirtyEditors[i];
+ editorI.doSave(new NullProgressMonitor());
+ }
+ }
+ }
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * Gets the current resource set.
+ *
+ * @return the current resource set
+ */
+ public static ResourceSet getCurrentResourceSet() {
+ IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ if(editor instanceof CoreMultiDiagramEditor) {
+ CoreMultiDiagramEditor papyrusEditor = (CoreMultiDiagramEditor)editor;
+ return papyrusEditor.getEditingDomain().getResourceSet();
+ }
+ return null;
+ }
+
+ /**
+ * Return all the leaf from the semantic meta model
+ *
+ * @param uris
+ * Input set for the search of leaf
+ * @param resourceSet
+ * @return
+ */
+ public static Collection<EObject> getLeafSemanticElement(Collection<IExtendedURI> uris, ResourceSet resourceSet) {
+ Collection<IExtendedURI> semanticURIS = Collections2.filter(uris, new Predicate<IExtendedURI>() {
+
+ public boolean apply(IExtendedURI arg0) {
+ return UmlModel.UML_FILE_EXTENSION.equals(arg0.getUri().fileExtension());
+ }
+ });
+ Collection<Collection<EObject>> eObjects = Collections2.transform(semanticURIS, CollabFunctionsFactory.getExtendedURIToEObjects(resourceSet));
+ Set<EObject> semanticElements = new HashSet<EObject>();
+ for(Collection<EObject> eos : eObjects) {
+ semanticElements.addAll(eos);
+ }
+ return ModelsUtil.getRoots(semanticElements);
+ }
+
+ /**
+ * Gets the first selection from the workbench
+ *
+ * @return the first selection
+ */
+ public static EObject getFirstSelection() {
+ Collection<EObject> selection = getSelection();
+ if(selection.isEmpty()) {
+ return null;
+ }
+ return selection.iterator().next();
+ }
+
+ /**
+ * Gets the selection from the workbench
+ *
+ * @return the selection
+ */
+ public static Collection<EObject> getSelection() {
+ ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
+ ISelection selection = selectionService.getSelection();
+ if(selection != null) {
+ if(selection instanceof IStructuredSelection) {
+ List<EObject> result = new ArrayList<EObject>();
+ Iterator<?> ite = ((IStructuredSelection)selection).iterator();
+ while(ite.hasNext()) {
+ Object next = ite.next();
+ EObject eObject = EMFHelper.getEObject(next);
+ if(eObject != null) {
+ result.add(eObject);
+ }
+ }
+ return result;
+ }
+ }
+ return Collections.emptyList();
+ }
+
+ /**
+ * Refresh elements in model explorer view.
+ *
+ * @param uris
+ * {@link IExtendedURI} to refresh
+ * @param resourceSet
+ * the resource set
+ */
+ public static void refreshModelExplorer(Set<IExtendedURI> uris, ResourceSet resourceSet) {
+ for(Collection<EObject> objects : Collections2.transform(uris, CollabFunctionsFactory.getExtendedURIToEObjects(resourceSet))) {
+ RefreshHelper.refreshModelExplorer(objects);
+ }
+ }
+
+ /**
+ * This reload the current editor
+ * WARNING : BE careful after this action the ancient resourceSet will deprecated you may use getCurrentResourceSet() to retrieve the new one.
+ */
+ public static void reloadEditor() {
+ Display.getCurrent().syncExec(new Runnable() {
+
+ public void run() {
+ IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbenchPage page = wb.getActiveWorkbenchWindow().getActivePage();
+ IEditorPart editor = page.getActiveEditor();
+ IEditorInput input = editor.getEditorInput();
+ page.closeEditor(editor, true);
+ try {
+ IEditorDescriptor desc = wb.getEditorRegistry().getDefaultEditor(input.getName());
+ page.openEditor(input, desc.getId(), false);
+ } catch (PartInitException e) {
+ LogHelper.getInstance().logError("Error during reloading", Activator.PLUGIN_ID, e);
+ }
+ }
+ });
+ }
+
+ /**
+ * Display an error dialog using a status.
+ *
+ * @param errorStatus
+ * the error status
+ * @param title
+ * the title
+ */
+ public static void errorDialog(IStatus errorStatus, String title) {
+ ErrorDialog dialog = new ErrorDialog(Display.getDefault().getActiveShell(), title, errorStatus.getMessage(), errorStatus, Status.ERROR);
+ dialog.open();
+ LogHelper.getInstance().logError(errorStatus.getMessage(), Activator.PLUGIN_ID, errorStatus.getException());
+ }
+
+ /**
+ * Error dialog.
+ *
+ * @param throwable
+ * the throwable
+ * @param title
+ * the title
+ * @param message
+ * the message
+ */
+ public static void errorDialog(Throwable throwable, String title, String message) {
+ errorDialog(CollabStatus.createErrorStatus(message, throwable), title);
+ }
+
+ /** The adapter factory. */
+ private static ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+
+ /**
+ * Try to get a correct label from a Object
+ * Handle: {@link EObject} {@link Resource}.
+ *
+ * @param object
+ * the object
+ * @return the label
+ */
+ public static String getLabel(Object object) {
+ if(object instanceof EObject) {
+ EObject eObject = (EObject)object;
+ IItemLabelProvider labelProvider = (IItemLabelProvider)adapterFactory.adapt(eObject, IItemLabelProvider.class);
+ return labelProvider.getText(eObject);
+ } else if(object instanceof Resource) {
+ return "Resouce " + ((Resource)object).getURI();
+ }
+ return object.toString();
+ }
+
+ public static ILabelProvider getModelExplorerLavelProvider() {
+ ILabelProvider labelProvider = getLabelProvider(ModelExplorerView.LABEL_PROVIDER_SERVICE_CONTEXT);
+ if(labelProvider == null) {
+ labelProvider = getLabelProvider();
+ }
+ return labelProvider;
+ }
+
+ public static ILabelProvider getLabelProvider() {
+ return getLabelProvider(null);
+ }
+
+ public static ILabelProvider getLabelProvider(String context) {
+
+ try {
+ IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ ServicesRegistry serviceRegistry = ServiceUtilsForWorkbenchPage.getInstance().getServiceRegistry(activePage);
+ LabelProviderService service = serviceRegistry.getService(LabelProviderService.class);
+ if(context != null) {
+ return service.getLabelProvider(context);
+ } else {
+ return service.getLabelProvider();
+ }
+ } catch (ServiceException e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+}

Back to the top