Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilippe ROLAND2014-03-13 16:23:48 +0000
committerPhilippe ROLAND2014-03-13 16:28:44 +0000
commit0ab46367bebce7c2b9c45970f638b63044ea04a2 (patch)
tree15f0213468c630535c4be430fd206cba25240e90 /extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/security/CollabReadOnlyHandler.java
parent5ea83367dd34acd76edd43bc26b8fd66cd2f5ac9 (diff)
downloadorg.eclipse.papyrus-0ab46367bebce7c2b9c45970f638b63044ea04a2.tar.gz
org.eclipse.papyrus-0ab46367bebce7c2b9c45970f638b63044ea04a2.tar.xz
org.eclipse.papyrus-0ab46367bebce7c2b9c45970f638b63044ea04a2.zip
425560: [Collaborative] Migrate collaborative mode from Indigo to Luna : also moved renamed plugins to the right folders
Diffstat (limited to 'extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/security/CollabReadOnlyHandler.java')
-rw-r--r--extraplugins/team.collaborative/org.eclipse.papyrus.team.collaborative.strategy/src/org/eclipse/papyrus/team/collaborative/strategy/security/CollabReadOnlyHandler.java93
1 files changed, 93 insertions, 0 deletions
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();
+ }
+
+}

Back to the top