Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'cdo/bundles/org.eclipse.papyrus.cdo.uml.search.ui/src/org/eclipse/papyrus/cdo/uml/search/internal/ui/scope/CDOScopeProvider.java')
-rwxr-xr-xcdo/bundles/org.eclipse.papyrus.cdo.uml.search.ui/src/org/eclipse/papyrus/cdo/uml/search/internal/ui/scope/CDOScopeProvider.java107
1 files changed, 107 insertions, 0 deletions
diff --git a/cdo/bundles/org.eclipse.papyrus.cdo.uml.search.ui/src/org/eclipse/papyrus/cdo/uml/search/internal/ui/scope/CDOScopeProvider.java b/cdo/bundles/org.eclipse.papyrus.cdo.uml.search.ui/src/org/eclipse/papyrus/cdo/uml/search/internal/ui/scope/CDOScopeProvider.java
new file mode 100755
index 00000000..ea2fcb2d
--- /dev/null
+++ b/cdo/bundles/org.eclipse.papyrus.cdo.uml.search.ui/src/org/eclipse/papyrus/cdo/uml/search/internal/ui/scope/CDOScopeProvider.java
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2017 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ * Eike Stepper (CEA) - bug 466520
+ *****************************************************************************/
+package org.eclipse.papyrus.cdo.uml.search.internal.ui.scope;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
+import org.eclipse.emf.cdo.eresource.CDOResourceNode;
+import org.eclipse.emf.cdo.explorer.CDOExplorerUtil;
+import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
+import org.eclipse.emf.cdo.util.CDOURIUtil;
+import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.cdo.internal.core.CDOUtils;
+import org.eclipse.papyrus.views.search.scope.IScopeProvider;
+import org.eclipse.uml2.uml.resource.UMLResource;
+
+import com.google.common.collect.Lists;
+
+
+/**
+ * A scope provider for CDO model repositories.
+ */
+public class CDOScopeProvider implements IScopeProvider {
+
+ public CDOScopeProvider() {
+ super();
+ }
+
+ /**
+ * Gets the URIs of the root resource (implying the repository in its entirety) of all repositories that are currently connected.
+ */
+ @Override
+ public Collection<URI> getScope() {
+ Collection<URI> result;
+
+ CDOCheckout[] repos = CDOExplorerUtil.getCheckoutManager().getCheckouts();
+ if (repos.length == 0) {
+ result = Collections.emptyList();
+ } else {
+ result = Lists.newArrayListWithCapacity(repos.length);
+ for (CDOCheckout next : repos) {
+ if (next.isOpen()) {
+ CDOView view = next.getView();
+ if (view != null) {
+ result.add(view.getRootResource().getURI());
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public Collection<URI> getScope(Object selected) {
+ Collection<URI> result;
+
+ // try to get the contextual resource node
+ CDOResourceNode node = CDOUtils.adapt(selected, CDOResourceNode.class);
+ if (node == null) {
+ EObject obj = CDOUtils.adapt(selected, EObject.class);
+ if (obj != null) {
+ node = CDOUtils.adapt(obj.eResource(), CDOResource.class);
+ }
+ }
+
+ if (node == null) {
+ result = Collections.emptyList();
+ } else {
+ URI uri = node.getURI();
+ if (!node.isRoot() && (node instanceof CDOResource)) {
+ // ensure that we search the UML resource, not the notation or di
+ uri = uri.trimFileExtension().appendFileExtension(UMLResource.FILE_EXTENSION);
+
+ if (!uri.equals(node.getURI())) {
+ // does the UML resource exist? If not, don't try to search it
+ String path = CDOURIUtil.extractResourcePath(uri);
+ if (!node.cdoView().hasResource(path)) {
+ uri = null;
+ }
+ }
+ } else if ((node instanceof CDOResourceFolder) && !uri.hasTrailingPathSeparator()) {
+ uri = uri.appendSegment(""); //$NON-NLS-1$
+ }
+
+ result = (uri == null) ? Collections.<URI> emptyList() : Collections.singletonList(uri);
+ }
+
+ return result;
+ }
+}

Back to the top