Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2018-04-18 10:19:03 -0400
committerNicolas FAUVERGUE2018-05-22 11:59:19 -0400
commit9714b7607b138a564456b44221a927faeece9b6e (patch)
tree24baf74e72ae28f54feeccd99f161749910ca76c /plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse
parent35f5a0c41fc41805277fbebfc3a090077e9fd562 (diff)
downloadorg.eclipse.papyrus-9714b7607b138a564456b44221a927faeece9b6e.tar.gz
org.eclipse.papyrus-9714b7607b138a564456b44221a927faeece9b6e.tar.xz
org.eclipse.papyrus-9714b7607b138a564456b44221a927faeece9b6e.zip
Bug 533701: [Sequence Diagram] Stereotype or Shape Compartments should
not be displayed in CombinedFragments https://bugs.eclipse.org/bugs/show_bug.cgi?id=533701 Add 2 services, to support filtering generic Papyrus IViewProviders and IEditPolicyProviders. Also add a simple contribution for the Sequence Diagram, to disable Symbols compartments. Change-Id: I0d6e1af0ad4395daf3170409b5735df36dd02d46 Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/internal/service/EditPolicyProviderServiceImpl.java41
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/internal/service/ViewProviderServiceImpl.java40
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomAbstractViewProvider.java12
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomEditPolicyProvider.java6
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ExternalReferenceEditPolicyProvider.java4
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/EditPolicyProviderService.java77
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/EditPolicyProviderTester.java39
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/ProviderServiceUtil.java130
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/ViewProviderService.java78
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/ViewProviderTester.java39
10 files changed, 464 insertions, 2 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/internal/service/EditPolicyProviderServiceImpl.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/internal/service/EditPolicyProviderServiceImpl.java
new file mode 100644
index 00000000000..ad13bf561cc
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/internal/service/EditPolicyProviderServiceImpl.java
@@ -0,0 +1,41 @@
+/*****************************************************************************
+ * Copyright (c) 2018 EclipseSource and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * EclipseSource - Initial API and implementation (Bug 533701)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.internal.service;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
+import org.eclipse.papyrus.infra.gmfdiag.common.service.EditPolicyProviderService;
+import org.eclipse.papyrus.infra.gmfdiag.common.service.EditPolicyProviderTester;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import com.google.common.base.Predicates;
+
+@Component
+public class EditPolicyProviderServiceImpl implements EditPolicyProviderService {
+
+ private Set<EditPolicyProviderTester> testers = new HashSet<>();
+
+ @Override
+ public boolean isEnabled(IEditPolicyProvider provider, EditPart editPart) {
+ return testers.stream().map(tester -> tester.isEnabled(provider, editPart)).noneMatch(Predicates.equalTo(Boolean.FALSE));
+ }
+
+ @Reference
+ public void registerTester(EditPolicyProviderTester tester) {
+ testers.add(tester);
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/internal/service/ViewProviderServiceImpl.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/internal/service/ViewProviderServiceImpl.java
new file mode 100644
index 00000000000..64b6ed738ae
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/internal/service/ViewProviderServiceImpl.java
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * Copyright (c) 2018 EclipseSource and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * EclipseSource - Initial API and implementation (Bug 533701)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.internal.service;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.gmf.runtime.diagram.core.providers.IViewProvider;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.service.ViewProviderService;
+import org.eclipse.papyrus.infra.gmfdiag.common.service.ViewProviderTester;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+@Component
+public class ViewProviderServiceImpl implements ViewProviderService {
+
+ private Set<ViewProviderTester> testers = new HashSet<>();
+
+ @Override
+ public boolean isEnabled(IViewProvider provider, View view) {
+ return testers.stream().map(tester -> tester.isEnabled(provider, view)).reduce(true, Boolean::logicalAnd);
+ }
+
+ @Reference
+ public void registerTester(ViewProviderTester tester) {
+ testers.add(tester);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomAbstractViewProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomAbstractViewProvider.java
index eb02c910275..055aa16e510 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomAbstractViewProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomAbstractViewProvider.java
@@ -24,6 +24,7 @@ import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.service.ProviderServiceUtil;
import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
/**
@@ -61,6 +62,9 @@ public abstract class CustomAbstractViewProvider extends AbstractViewProvider {
*/
@Override
protected boolean provides(CreateViewForKindOperation op) {
+ if (!ProviderServiceUtil.isEnabled(this, op.getContainerView())) {
+ return false;
+ }
if (!isRelevantDiagram(op.getContainerView().getDiagram())) {
return false;
}
@@ -81,6 +85,9 @@ public abstract class CustomAbstractViewProvider extends AbstractViewProvider {
*/
@Override
protected boolean provides(CreateEdgeViewOperation operation) {
+ if (!ProviderServiceUtil.isEnabled(this, operation.getContainerView())) {
+ return false;
+ }
if (!isRelevantDiagram(operation.getContainerView().getDiagram())) {
return false;
}
@@ -93,6 +100,9 @@ public abstract class CustomAbstractViewProvider extends AbstractViewProvider {
*/
@Override
protected boolean provides(CreateNodeViewOperation operation) {
+ if (!ProviderServiceUtil.isEnabled(this, operation.getContainerView())) {
+ return false;
+ }
if (!isRelevantDiagram(operation.getContainerView().getDiagram())) {
return false;
}
@@ -138,7 +148,7 @@ public abstract class CustomAbstractViewProvider extends AbstractViewProvider {
/**
* This method is used to know id the diagram is conform to type, it may be a prototype view, or a generatedDiagram
- *
+ *
* @param diagram
* @return
*/
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomEditPolicyProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomEditPolicyProvider.java
index d3d717f2201..b3923d22860 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomEditPolicyProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomEditPolicyProvider.java
@@ -23,6 +23,7 @@ import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.HighlightEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.service.ProviderServiceUtil;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
/**
@@ -70,8 +71,11 @@ public class CustomEditPolicyProvider implements IEditPolicyProvider {
* {@inheritDoc}
*/
@Override
- public boolean provides(IOperation operation) {
+ public boolean provides(IOperation operation) {
CreateEditPoliciesOperation epOperation = (CreateEditPoliciesOperation) operation;
+ if (!ProviderServiceUtil.isEnabled(this, epOperation.getEditPart())) {
+ return false;
+ }
try {
EditPart editPart = epOperation.getEditPart();
if (!(editPart instanceof GraphicalEditPart)) {
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ExternalReferenceEditPolicyProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ExternalReferenceEditPolicyProvider.java
index 39dd468c4b0..df832001fad 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ExternalReferenceEditPolicyProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ExternalReferenceEditPolicyProvider.java
@@ -19,6 +19,7 @@ import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvide
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalReferenceEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.service.ProviderServiceUtil;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
/**
@@ -35,6 +36,9 @@ public class ExternalReferenceEditPolicyProvider extends AbstractProvider implem
public boolean provides(IOperation operation) {
if (operation instanceof CreateEditPoliciesOperation) {
CreateEditPoliciesOperation createOperation = (CreateEditPoliciesOperation) operation;
+ if (!ProviderServiceUtil.isEnabled(this, createOperation.getEditPart())) {
+ return false;
+ }
try {
if (ServiceUtilsForEditPart.getInstance().getServiceRegistry(createOperation.getEditPart()) != null) {
return createOperation.getEditPart().getModel() instanceof Node;
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/EditPolicyProviderService.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/EditPolicyProviderService.java
new file mode 100644
index 00000000000..ed026605c72
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/EditPolicyProviderService.java
@@ -0,0 +1,77 @@
+/*****************************************************************************
+ * Copyright (c) 2018 EclipseSource and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * EclipseSource - Initial API and implementation (Bug 533701)
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.service;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
+import org.eclipse.papyrus.infra.core.services.IServiceFactory;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * <p>
+ * A service used to increase the control diagrams have over the {@link IEditPolicyProvider}
+ * that should be enabled in that diagram. All generic Papyrus {@link IEditPolicyProvider} are expected to use this
+ * service before deciding if they should indeed be enabled.
+ * </p>
+ * <p>
+ * Note that this service is here to provide an additional pre-check to determine if a
+ * provider is allowed to work in a specific diagram. However, this service knows nothing
+ * about the internal requirements/dependencies of a specific provider, and should not
+ * <strong>replace</strong> the {@link IEditPolicyProvider#provides(org.eclipse.gmf.runtime.common.core.service.IOperation)}
+ * method (i.e. the actual provider is still expected to run its own checks, in addition
+ * to calling this service).
+ * </p>
+ *
+ * @since 3.100
+ */
+public interface EditPolicyProviderService {
+
+ /**
+ * Tests whether the given provider is allowed in the context of that edit part
+ *
+ * @param provider
+ * @param editPart
+ * @return
+ */
+ boolean isEnabled(IEditPolicyProvider provider, EditPart editPart);
+
+ public static class Factory implements IServiceFactory {
+
+ @Override
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+ // Nothing
+ }
+
+ @Override
+ public void startService() throws ServiceException {
+ // Nothing
+ }
+
+ @Override
+ public void disposeService() throws ServiceException {
+ // Nothing
+ }
+
+ @Override
+ public EditPolicyProviderService createServiceInstance() throws ServiceException {
+ BundleContext bundleContext = FrameworkUtil.getBundle(Factory.class).getBundleContext();
+ ServiceReference<EditPolicyProviderService> serviceReference = bundleContext.getServiceReference(EditPolicyProviderService.class);
+ return bundleContext.getService(serviceReference);
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/EditPolicyProviderTester.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/EditPolicyProviderTester.java
new file mode 100644
index 00000000000..7bfd7ad94dc
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/EditPolicyProviderTester.java
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * Copyright (c) 2018 EclipseSource and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * EclipseSource - Initial API and implementation (Bug 533701)
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.service;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
+
+/**
+ * <p>
+ * A contribution to the {@link EditPolicyProviderService}
+ * </p>
+ *
+ * @since 3.100
+ */
+public interface EditPolicyProviderTester {
+
+ /**
+ * Tests whether the given provider is allowed in the context of that edit part
+ *
+ * @param provider
+ * @param editPart
+ * @return
+ * <code>false</code> if this tester explicitly rejects this provider in the context of that edit part;
+ * <code>true</code> otherwise.
+ */
+ boolean isEnabled(IEditPolicyProvider provider, EditPart editPart);
+}
+
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/ProviderServiceUtil.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/ProviderServiceUtil.java
new file mode 100644
index 00000000000..adbbcde0f5e
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/ProviderServiceUtil.java
@@ -0,0 +1,130 @@
+/*****************************************************************************
+ * Copyright (c) 2018 EclipseSource and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * EclipseSource - Initial API and implementation (Bug 533701)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.service;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.core.providers.IViewProvider;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
+
+/**
+ * <p>
+ * Utility methods to use the {@link ViewProviderService} and {@link EditPolicyProviderService}
+ * </p>
+ *
+ * @since 3.100
+ */
+public class ProviderServiceUtil {
+
+ /**
+ * <p>
+ * Tests if the given edit part is a Papyrus Edit Part, by testing if a Papyrus {@link ServicesRegistry}
+ * is present.
+ * </p>
+ *
+ * @param editPart
+ * The edit part to test
+ * @return
+ * <code>true</code> if this edit part is part of a Papyrus environment (Using a Papyrus {@link ServicesRegistry}), <code>false</code> otherwise
+ */
+ public static boolean isPapyrusPart(EditPart editPart) {
+ try {
+ return ServiceUtilsForEditPart.getInstance().getServiceRegistry(editPart) != null;
+ } catch (Exception ex) {
+ // Ignore & return
+ return false;
+ }
+ }
+
+ /**
+ * <p>
+ * Tests if the given View is a Papyrus View, by testing if a Papyrus {@link ServicesRegistry}
+ * is present.
+ * </p>
+ *
+ * @param view
+ * The view to test
+ * @return
+ * <code>true</code> if this view is part of a Papyrus environment (Using a Papyrus {@link ServicesRegistry}), <code>false</code> otherwise
+ */
+ public static boolean isPapyrusView(View view) {
+ try {
+ return ServiceUtilsForEObject.getInstance().getServiceRegistry(view) != null;
+ } catch (Exception ex) {
+ // Ignore & return
+ return false;
+ }
+ }
+
+ /**
+ * <p>
+ * Helper method to use the {@link ViewProviderService}.
+ * </p>
+ * <p>
+ * This methods verifies that the edit part is a Papyrus Edit Part (Via {@link #isPapyrusPart(EditPart)}),
+ * and then calls {@link ViewProviderService#isEnabled(IViewProvider, EditPart)}
+ * </p>
+ *
+ * @param provider
+ * @param editPart
+ * @return
+ *
+ * @see ViewProviderService#isEnabled(IViewProvider, EditPart)
+ */
+ public static boolean isEnabled(IViewProvider provider, View view) {
+ if (isPapyrusView(view)) {
+ try {
+ ViewProviderService service = ServiceUtilsForEObject.getInstance().getService(ViewProviderService.class, view);
+ return service.isEnabled(provider, view);
+ } catch (Exception ex) {
+ // Ignore & return
+ return false;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * <p>
+ * Helper method to use the {@link EditPolicyProviderService}.
+ * </p>
+ * <p>
+ * This methods verifies that the edit part is a Papyrus Edit Part (Via {@link #isPapyrusPart(EditPart)}),
+ * and then calls {@link EditPolicyProviderService#isEnabled(IEditPolicyProvider, EditPart)}
+ * </p>
+ *
+ * @param provider
+ * @param editPart
+ * @return
+ *
+ * @see {@link EditPolicyProviderService#isEnabled(IEditPolicyProvider, EditPart)}
+ */
+ public static boolean isEnabled(IEditPolicyProvider provider, EditPart editPart) {
+ if (isPapyrusPart(editPart)) {
+ try {
+ EditPolicyProviderService service = ServiceUtilsForEditPart.getInstance().getService(EditPolicyProviderService.class, editPart);
+ return service.isEnabled(provider, editPart);
+ } catch (Exception ex) {
+ // Ignore & return
+ return false;
+ }
+ }
+
+ return false;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/ViewProviderService.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/ViewProviderService.java
new file mode 100644
index 00000000000..7a16c39b72b
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/ViewProviderService.java
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * Copyright (c) 2018 EclipseSource and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * EclipseSource - Initial API and implementation (Bug 533701)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.service;
+
+import org.eclipse.gmf.runtime.diagram.core.providers.IViewProvider;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.services.IServiceFactory;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * <p>
+ * A service used to increase the control diagrams have over the {@link IViewProvider}
+ * that should be enabled in that diagram. All generic Papyrus {@link IViewProvider} are expected to use this
+ * service before deciding if they should indeed be enabled.
+ * </p>
+ * <p>
+ * Note that this service is here to provide an additional pre-check to determine if a
+ * provider is allowed to work in a specific diagram. However, this service knows nothing
+ * about the internal requirements/dependencies of a specific provider, and should not
+ * <strong>replace</strong> the {@link IViewProvider#provides(org.eclipse.gmf.runtime.common.core.service.IOperation)}
+ * method (i.e. the actual provider is still expected to run its own checks, in addition
+ * to calling this service).
+ * </p>
+ *
+ * @since 3.100
+ */
+public interface ViewProviderService {
+ /**
+ * Tests whether the given provider is allowed in the context of that view
+ *
+ * @param provider
+ * @param view
+ * @return
+ */
+ boolean isEnabled(IViewProvider provider, View view);
+
+
+
+ public static class Factory implements IServiceFactory {
+
+ @Override
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+ // Nothing
+ }
+
+ @Override
+ public void startService() throws ServiceException {
+ // Nothing
+ }
+
+ @Override
+ public void disposeService() throws ServiceException {
+ // Nothing
+ }
+
+ @Override
+ public ViewProviderService createServiceInstance() throws ServiceException {
+ BundleContext bundleContext = FrameworkUtil.getBundle(Factory.class).getBundleContext();
+ ServiceReference<ViewProviderService> serviceReference = bundleContext.getServiceReference(ViewProviderService.class);
+ return bundleContext.getService(serviceReference);
+ }
+
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/ViewProviderTester.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/ViewProviderTester.java
new file mode 100644
index 00000000000..f2928331534
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/ViewProviderTester.java
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * Copyright (c) 2018 EclipseSource and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * EclipseSource - Initial API and implementation (Bug 533701)
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.service;
+
+import org.eclipse.gmf.runtime.diagram.core.providers.IViewProvider;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * <p>
+ * A contribution to the {@link ViewProviderService}
+ * </p>
+ *
+ * @since 3.100
+ */
+public interface ViewProviderTester {
+
+ /**
+ * Tests whether the given provider is allowed in the context of that edit part
+ *
+ * @param provider
+ * @param editPart
+ * @return
+ * <code>false</code> if this tester explicitly rejects this provider in the context of that edit part;
+ * <code>true</code> otherwise.
+ */
+ boolean isEnabled(IViewProvider provider, View view);
+}
+

Back to the top