Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Noyrit2016-01-08 16:48:56 +0000
committerFlorian Noyrit2016-01-11 08:10:11 +0000
commite48ce96928453387a7b1910a943b522dc15e9a10 (patch)
treef216e5447ba310f2e33d55dc22700c3233dcd4a7 /plugins/developer
parent8ee09da96fd8f020b0ec18a7d612f858900fa6e5 (diff)
downloadorg.eclipse.papyrus-e48ce96928453387a7b1910a943b522dc15e9a10.tar.gz
org.eclipse.papyrus-e48ce96928453387a7b1910a943b522dc15e9a10.tar.xz
org.eclipse.papyrus-e48ce96928453387a7b1910a943b522dc15e9a10.zip
[Bug 485430] ElementTypesConfigurations Framework notification facility
Initial contribution Change-Id: I7632844c0aa60f9618022d83232a82b3b145894b
Diffstat (limited to 'plugins/developer')
-rw-r--r--plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/plugin.xml11
-rw-r--r--plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/handlers/GenerateElementTypesConfigurations.java11
-rw-r--r--plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/providers/ElementTypesConfigurationsEventContentProvider.java161
-rw-r--r--plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/providers/ElementTypesConfigurationsEventLabelProvider.java135
-rw-r--r--plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/utils/ElementTypeRegistryUtils.java45
-rw-r--r--plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/utils/ElementTypesConfigurationsEventPrinter.java138
-rw-r--r--plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/utils/NotifierNullEditHelper.java30
-rw-r--r--plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/view/ElementTypesConfigurationsListenerView.java227
8 files changed, 752 insertions, 6 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/plugin.xml b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/plugin.xml
index 9507146b0ad..ff3062d9ba1 100644
--- a/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/plugin.xml
+++ b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/plugin.xml
@@ -109,5 +109,16 @@
restorable="true">
</view>
</extension>
+
+ <extension
+ point="org.eclipse.ui.views">
+ <view
+ category="org.eclipse.papyrus.views.category"
+ class="org.eclipse.papyrus.elementtypesconfigurations.developer.view.ElementTypesConfigurationsListenerView"
+ id="org.eclipse.papyrus.elementtypesconfigurations.developer.elementTypesConfigurationsListenerView"
+ name="ElementTypesConfigurations Listener View"
+ restorable="true">
+ </view>
+ </extension>
</plugin>
diff --git a/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/handlers/GenerateElementTypesConfigurations.java b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/handlers/GenerateElementTypesConfigurations.java
index c2a649d8fd8..b299bff62d6 100644
--- a/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/handlers/GenerateElementTypesConfigurations.java
+++ b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/handlers/GenerateElementTypesConfigurations.java
@@ -74,7 +74,7 @@ public class GenerateElementTypesConfigurations extends AbstractHandler {
e.printStackTrace();
}
} else if (selectedElement instanceof IFile) {
- if (((IFile) selectedElement).getFileExtension().equals("elementtypesconfigurations")) {
+ if ("elementtypesconfigurations".equals(((IFile) selectedElement).getFileExtension())) {
String selectedFilePath = ((IFile) selectedElement).getFullPath().toString();
Resource outputResource = resourceSet.getResource(URI.createURI(selectedFilePath), true);
@@ -118,7 +118,8 @@ public class GenerateElementTypesConfigurations extends AbstractHandler {
Collection<EReference> ambiguousContainments = GenerateElementTypesConfigurationsUtils.findAmbiguousContainments(containmentEReference, possibleContainmentsEReference);
if (!ambiguousContainments.isEmpty()) {
- if (!containsElementType(GenerateElementTypesConfigurationsUtils.getIdentifier(eClass) + GenerateElementTypesConfigurationsUtils.getAsName(containmentEReference, containmentEReference.getEContainingClass()), elementTypeSetConfiguration)) {
+ if (!containsElementType(GenerateElementTypesConfigurationsUtils.getIdentifier(eClass) + GenerateElementTypesConfigurationsUtils.getAsName(containmentEReference, containmentEReference.getEContainingClass()),
+ elementTypeSetConfiguration)) {
SpecializationTypeConfiguration specializationTypeConfiguration = createSpecializationTypeConfiguration(eClass, containmentEReference,
GenerateElementTypesConfigurationsUtils.getAsName(containmentEReference, containmentEReference.getEContainingClass()));
@@ -141,8 +142,7 @@ public class GenerateElementTypesConfigurations extends AbstractHandler {
}
- protected MetamodelTypeConfiguration createMetamodelTypeConfiguration(EClass eClass)
- {
+ protected MetamodelTypeConfiguration createMetamodelTypeConfiguration(EClass eClass) {
MetamodelTypeConfiguration metamodelTypeConfiguration = ElementtypesconfigurationsFactory.eINSTANCE.createMetamodelTypeConfiguration();
metamodelTypeConfiguration.setEClass(eClass);
metamodelTypeConfiguration.setIdentifier(GenerateElementTypesConfigurationsUtils.getIdentifier(eClass));
@@ -160,8 +160,7 @@ public class GenerateElementTypesConfigurations extends AbstractHandler {
return metamodelTypeConfiguration;
}
- protected SpecializationTypeConfiguration createSpecializationTypeConfiguration(EClass eClass, EReference containmentEReference, String asName)
- {
+ protected SpecializationTypeConfiguration createSpecializationTypeConfiguration(EClass eClass, EReference containmentEReference, String asName) {
SpecializationTypeConfiguration specializationTypeConfiguration = ElementtypesconfigurationsFactory.eINSTANCE.createSpecializationTypeConfiguration();
specializationTypeConfiguration.setIdentifier(GenerateElementTypesConfigurationsUtils.getIdentifier(eClass) + asName);
diff --git a/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/providers/ElementTypesConfigurationsEventContentProvider.java b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/providers/ElementTypesConfigurationsEventContentProvider.java
new file mode 100644
index 00000000000..63f6be1b299
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/providers/ElementTypesConfigurationsEventContentProvider.java
@@ -0,0 +1,161 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.elementtypesconfigurations.developer.providers;
+
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.ElementTypesConfigurationsEventsChain;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.AbstractElementTypesConfigurationsEvent;
+
+
+public class ElementTypesConfigurationsEventContentProvider implements ITreeContentProvider {
+
+ /**
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ *
+ * @param viewer
+ * @param oldInput
+ * @param newInput
+ */
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ *
+ * @param inputElement
+ * @return
+ */
+ @Override
+ public Object[] getElements(Object inputElement) {
+ List<ElementTypesConfigurationsEventsChain> result = new ArrayList<ElementTypesConfigurationsEventsChain>();
+ if (inputElement instanceof List<?>) {
+ List<?> inputSet = (List<?>) inputElement;
+ for (Object element : inputSet) {
+ if (element instanceof ElementTypesConfigurationsEventsChain) {
+ result.add((ElementTypesConfigurationsEventsChain) element);
+ }
+ }
+ }
+
+ Collections.sort(result, new Comparator<ElementTypesConfigurationsEventsChain>() {
+
+ @Override
+ public int compare(ElementTypesConfigurationsEventsChain o1, ElementTypesConfigurationsEventsChain o2) {
+ if (o1.getTimestamp() > o2.getTimestamp()) {
+ return -1;
+ }
+ return 1;
+ }
+ });
+
+
+ return result.toArray();
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ *
+ * @param parentElement
+ * @return
+ */
+ @Override
+ public Object[] getChildren(Object parentElement) {
+
+
+ List<Object> result = new ArrayList<Object>();
+ if (parentElement instanceof ElementTypesConfigurationsEventsChain) {
+ ElementTypesConfigurationsEventsChain elementTypesConfigurationsEventsChain = (ElementTypesConfigurationsEventsChain) parentElement;
+
+ List<AbstractElementTypesConfigurationsEvent> adviceRequestConfigurationEvents = elementTypesConfigurationsEventsChain.getAdviceRequestConfigurationEvents();
+ if (!adviceRequestConfigurationEvents.isEmpty()) {
+ result.add(new AbstractMap.SimpleEntry<String, Object>("BeforeAdvicesCommandsEvents", adviceRequestConfigurationEvents));
+ }
+ AbstractElementTypesConfigurationsEvent editHelperRequestConfigurationEvent = elementTypesConfigurationsEventsChain.getEditHelperRequestConfigurationEvent();
+ if (editHelperRequestConfigurationEvent != null) {
+ result.add(editHelperRequestConfigurationEvent);
+ }
+ List<AbstractElementTypesConfigurationsEvent> adviceApprovalEvents = elementTypesConfigurationsEventsChain.getAdviceApprovalEvents();
+ if (!adviceApprovalEvents.isEmpty()) {
+ result.add(new AbstractMap.SimpleEntry<String, Object>("AdviceApprovalEvents", adviceApprovalEvents));
+ }
+ AbstractElementTypesConfigurationsEvent editHelperApprovalEvent = elementTypesConfigurationsEventsChain.getEditHelperApprovalEvent();
+ if (editHelperApprovalEvent != null) {
+ result.add(editHelperApprovalEvent);
+ }
+ List<AbstractElementTypesConfigurationsEvent> beforeAdvicesCommandsEvents = elementTypesConfigurationsEventsChain.getBeforeAdvicesCommandsEvents();
+ if (!beforeAdvicesCommandsEvents.isEmpty()) {
+ result.add(new AbstractMap.SimpleEntry<String, Object>("BeforeAdvicesCommandsEvents", beforeAdvicesCommandsEvents));
+ }
+ AbstractElementTypesConfigurationsEvent editHelperCommandEvent = elementTypesConfigurationsEventsChain.getEditHelperCommandEvent();
+ if (editHelperCommandEvent != null) {
+ result.add(editHelperCommandEvent);
+ }
+ List<AbstractElementTypesConfigurationsEvent> afterAdvicesCommandsEvents = elementTypesConfigurationsEventsChain.getAfterAdvicesCommandsEvents();
+ if (!afterAdvicesCommandsEvents.isEmpty()) {
+ result.add(new AbstractMap.SimpleEntry<String, Object>("AfterAdvicesCommandsEvents", afterAdvicesCommandsEvents));
+ }
+ } else if (parentElement instanceof Map.Entry) {
+ Object value = ((Map.Entry<?, ?>) parentElement).getValue();
+ if (value instanceof Collection) {
+ result.addAll((Collection<?>) value);
+ }
+ }
+ return result.toArray();
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length == 0 ? false : true;
+ }
+
+}
diff --git a/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/providers/ElementTypesConfigurationsEventLabelProvider.java b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/providers/ElementTypesConfigurationsEventLabelProvider.java
new file mode 100644
index 00000000000..eaec0f088c4
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/providers/ElementTypesConfigurationsEventLabelProvider.java
@@ -0,0 +1,135 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.elementtypesconfigurations.developer.providers;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Map;
+
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.ElementTypesConfigurationsEventsChain;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.ElementTypesConfigurationsEventType;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.IElementTypesConfigurationsEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+
+public class ElementTypesConfigurationsEventLabelProvider extends org.eclipse.jface.viewers.LabelProvider implements IColorProvider {
+
+ @Override
+ public Image getImage(Object element) {
+
+ return null;
+ }
+
+ @Override
+ public String getText(Object element) {
+ String result = "";
+ Calendar calendar = Calendar.getInstance();
+ SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd - hh:mm:ss:SSS");
+ if (element instanceof IElementTypesConfigurationsEvent) {
+ calendar.setTimeInMillis(((IElementTypesConfigurationsEvent) element).getTimestamp());
+ result += "[" + formater.format(calendar.getTime()) + "] " + ((IElementTypesConfigurationsEvent) element).getEventName();
+ } else if (element instanceof ElementTypesConfigurationsEventsChain) {
+ calendar.setTimeInMillis(((ElementTypesConfigurationsEventsChain) element).getTimestamp());
+ result += "[" + formater.format(calendar.getTime()) + "] " + ((ElementTypesConfigurationsEventsChain) element).getName();
+ } else if (element instanceof Map.Entry) {
+ result += ((Map.Entry<?, ?>) element).getKey().toString();
+ } else {
+ result += element.toString();
+ }
+ return result;
+ }
+
+ Color yellow = new Color(Display.getCurrent(), new RGB(255, 200, 0));
+ Color green = new Color(Display.getCurrent(), new RGB(0, 128, 0));
+ Color red = new Color(Display.getCurrent(), new RGB(255, 0, 0));
+ Color black = new Color(Display.getCurrent(), new RGB(0, 0, 0));
+ Color blue = new Color(Display.getCurrent(), new RGB(0, 0, 255));
+
+
+ /**
+ * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public Color getForeground(Object element) {
+ if (element instanceof IElementTypesConfigurationsEvent) {
+ if (((IElementTypesConfigurationsEvent) element).getEventType().equals(ElementTypesConfigurationsEventType.Disapproved)) {
+ return red;
+ } else if (((IElementTypesConfigurationsEvent) element).getEventType().equals(ElementTypesConfigurationsEventType.Unexecutable)) {
+ return red;
+ } else if (((IElementTypesConfigurationsEvent) element).getEventType().equals(ElementTypesConfigurationsEventType.Executable)) {
+ return green;
+ } else if (((IElementTypesConfigurationsEvent) element).getEventType().equals(ElementTypesConfigurationsEventType.Approved)) {
+ return green;
+ } else if (((IElementTypesConfigurationsEvent) element).getEventType().equals(ElementTypesConfigurationsEventType.Identity)) {
+ return yellow;
+ } else if (((IElementTypesConfigurationsEvent) element).getEventType().equals(ElementTypesConfigurationsEventType.RequestConfiguration)) {
+ return blue;
+ }
+ } else if (element instanceof Map.Entry) {
+ Object value = ((Map.Entry<?, ?>) element).getValue();
+ if (value instanceof Collection) {
+ return checkWorst((Collection<?>) value, true);
+ }
+ } else if (element instanceof ElementTypesConfigurationsEventsChain) {
+ return checkWorst(((ElementTypesConfigurationsEventsChain) element).getAllEvents(), false);
+ }
+ return black;
+ }
+
+ /**
+ * @param value
+ */
+ private Color checkWorst(Collection<?> value, boolean considerRequestConfiguration) {
+ Color result = green;
+ for (Object object : value) {
+ if (((IElementTypesConfigurationsEvent) object).getEventType().equals(ElementTypesConfigurationsEventType.Disapproved)) {
+ return red;
+ } else if (((IElementTypesConfigurationsEvent) object).getEventType().equals(ElementTypesConfigurationsEventType.Unexecutable)) {
+ return red;
+ } else if (((IElementTypesConfigurationsEvent) object).getEventType().equals(ElementTypesConfigurationsEventType.Identity)) {
+ if (result == green) {
+ result = yellow;
+ }
+ } else if (((IElementTypesConfigurationsEvent) object).getEventType().equals(ElementTypesConfigurationsEventType.RequestConfiguration)) {
+ if (considerRequestConfiguration) {
+ if (result != yellow && result != red) {
+ result = blue;
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public Color getBackground(Object element) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/utils/ElementTypeRegistryUtils.java b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/utils/ElementTypeRegistryUtils.java
new file mode 100644
index 00000000000..16ed6ae5147
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/utils/ElementTypeRegistryUtils.java
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.elementtypesconfigurations.developer.utils;
+
+import java.lang.reflect.Field;
+
+import org.eclipse.gmf.runtime.emf.type.core.MetamodelType;
+import org.eclipse.papyrus.infra.elementtypesconfigurations.Activator;
+
+
+public class ElementTypeRegistryUtils {
+
+
+ static public synchronized Field getNullElementTypeEditHelper() {
+
+ Field declaredField = null;
+ try {
+ declaredField = MetamodelType.class.getDeclaredField("editHelper");
+ } catch (SecurityException e1) {
+ Activator.log.error(e1);
+ return null;
+ } catch (NoSuchFieldException e1) {
+ Activator.log.error(e1);
+ return null;
+ }
+ if (declaredField == null) {
+ Activator.log.error("impossible to find editHelper", null);
+ return null;
+ }
+ declaredField.setAccessible(true);
+
+ return declaredField;
+ }
+
+}
diff --git a/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/utils/ElementTypesConfigurationsEventPrinter.java b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/utils/ElementTypesConfigurationsEventPrinter.java
new file mode 100644
index 00000000000..d285a0a6af7
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/utils/ElementTypesConfigurationsEventPrinter.java
@@ -0,0 +1,138 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.elementtypesconfigurations.developer.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.AdviceApprovedEvent;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.AdviceDisapprovedEvent;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.AdviceRequestConfigurationEvent;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.EditHelperApprovedEvent;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.EditHelperDisapprovedEvent;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.EditHelperRequestConfigurationEvent;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.ExecutableAdviceEvent;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.ExecutableEditHelperEvent;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.IAdviceEvent;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.IElementTypesConfigurationsEvent;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.IdentityAdviceEvent;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.IdentityEditHelperEvent;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.UnexecutableAdviceEvent;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.UnexecutableEditHelperEvent;
+
+public class ElementTypesConfigurationsEventPrinter {
+ public static Map<String, String> getEventDetails(IElementTypesConfigurationsEvent event) {
+ Map<String, String> result = new HashMap<>();
+
+ if (event instanceof AdviceApprovedEvent) {
+ result.put("Approved Advice", ((AdviceApprovedEvent) event).getAdvice().getClass().getName());
+ } else if (event instanceof AdviceDisapprovedEvent) {
+ result.put("Disapprover Advice", ((AdviceDisapprovedEvent) event).getAdvice().getClass().getName());
+ } else if (event instanceof EditHelperApprovedEvent) {
+ result.put("Approver edithelper", ((EditHelperApprovedEvent) event).getEditHelper().getClass().getName());
+ } else if (event instanceof EditHelperDisapprovedEvent) {
+ result.put("Disapprover edithelper", ((EditHelperDisapprovedEvent) event).getEditHelper().getClass().getName());
+ } else if (event instanceof ExecutableAdviceEvent) {
+ result.put("Advice", ((ExecutableAdviceEvent) event).getAdvice().getClass().getName());
+ result.put("Phase ", ((ExecutableAdviceEvent) event).getAdvicePhase().name());
+ result.put("Executable command", ((ExecutableAdviceEvent) event).getCommand().getClass().getName());
+ } else if (event instanceof ExecutableEditHelperEvent) {
+ result.put("Executable command from edithelper", ((ExecutableEditHelperEvent) event).getEditHelper().getClass().getName());
+ result.put("Executable command", ((ExecutableEditHelperEvent) event).getCommand().getClass().getName());
+ } else if (event instanceof IdentityAdviceEvent) {
+ result.put("Identity Advice", ((IdentityAdviceEvent) event).getAdvice().getClass().getName());
+ result.put("Phase ", ((IdentityAdviceEvent) event).getAdvicePhase().name());
+ } else if (event instanceof IdentityEditHelperEvent) {
+ result.put("Identity EditHelper", ((IdentityEditHelperEvent) event).getEditHelper().getClass().getName());
+ } else if (event instanceof UnexecutableAdviceEvent) {
+ result.put("Unexecutable Advice", ((UnexecutableAdviceEvent) event).getAdvice().getClass().getName());
+ result.put("Phase ", ((UnexecutableAdviceEvent) event).getAdvicePhase().name());
+ result.put("Unexecutable command", ((UnexecutableAdviceEvent) event).getCommand().getClass().getName());
+ } else if (event instanceof UnexecutableEditHelperEvent) {
+ result.put("Unexecutable command from edithelper", ((UnexecutableEditHelperEvent) event).getEditHelper().getClass().getName());
+ result.put("Unexecutable command", ((UnexecutableEditHelperEvent) event).getCommand().getClass().getName());
+ } else if (event instanceof AdviceRequestConfigurationEvent) {
+ result.put("RequestConfiguration Advice", ((AdviceRequestConfigurationEvent) event).getAdvice().getClass().getName());
+ } else if (event instanceof EditHelperRequestConfigurationEvent) {
+ result.put("RequestConfiguration EditHelper", ((EditHelperRequestConfigurationEvent) event).getEditHelper().getClass().getName());
+ }
+
+ if (event instanceof IAdviceEvent) {
+ String adviceNames = "";
+ for (IEditHelperAdvice editHelperAdvice : ((IAdviceEvent) event).getAdvices()) {
+ adviceNames += " -" + editHelperAdvice.getClass().getName() + "\n";
+ }
+ result.put("Among the following advices ", adviceNames);
+ }
+
+ return result;
+ }
+
+ public static String printHtmlEvent(Map<String, String> details) {
+
+
+ String html = "<table border=\"1\">";
+ for (String key : details.keySet()) {
+ html += "<tr>";
+ html += "<td><b>" + key + "<b></td>";
+ html += "<td>" + details.get(key) + "</td>";
+ html += "</tr>";
+ }
+ html += "</table>";
+
+ html = html.replaceAll("\\n", "<br>");
+
+ return html;
+ }
+
+ /**
+ * @param req
+ * @return
+ */
+ public static String printHtmRequest(IEditCommandRequest req) {
+ String result = "<ul>";
+ result += "<li><b>Request</b>: " + req + "</li>";
+ result += "<li><b>Label</b>: " + req.getLabel() + "</li>";
+ result += "<li><b>Kind</b>: " + req.getClass().getName() + "</li>";
+ result += "<li><b>ElementsToEdit</b>: " + req.getElementsToEdit() + "</li>";
+ result += "<li><b>Parameters</b>:</li>";
+
+ if (!req.getParameters().keySet().isEmpty()) {
+ result += "<ul>";
+
+ for (Object key : req.getParameters().keySet()) {
+ result += "<li><b>" + key + "</b> <-> " + req.getParameters().get(key) + "</li>";
+ }
+ result += "</ul>";
+ }
+ result += "<li><b>EditHelperContext</b>: " + req.getEditHelperContext() + "</li>";
+
+ if (req instanceof CreateElementRequest) {
+ result += "<li><b>ElementType</b>: " + ((CreateElementRequest) req).getElementType() + "</li>";
+ result += "<li><b>Container</b>: " + ((CreateElementRequest) req).getContainer() + "</li>";
+ result += "<li><b>ContainmentFeature</b>: " + ((CreateElementRequest) req).getContainmentFeature() + "</li>";
+ if (req instanceof CreateRelationshipRequest) {
+ result += "<li><b>Source</b>: " + ((CreateRelationshipRequest) req).getSource() + "</li>";
+ result += "<li><b>Target</b>: " + ((CreateRelationshipRequest) req).getTarget() + "</li>";
+ }
+ }
+ result += "</ul>";
+
+ return result;
+ }
+}
diff --git a/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/utils/NotifierNullEditHelper.java b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/utils/NotifierNullEditHelper.java
new file mode 100644
index 00000000000..1ff2b2cdd8a
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/utils/NotifierNullEditHelper.java
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.elementtypesconfigurations.developer.utils;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.AbstractNotifierEditHelper;
+
+/**
+ * Edit helper for the NullElementType that considers before and after
+ * advice, only.
+ */
+public class NotifierNullEditHelper
+ extends AbstractNotifierEditHelper {
+
+ protected ICommand getInsteadCommand(IEditCommandRequest req) {
+ return null;
+ }
+} \ No newline at end of file
diff --git a/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/view/ElementTypesConfigurationsListenerView.java b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/view/ElementTypesConfigurationsListenerView.java
new file mode 100644
index 00000000000..e17ad196472
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.elementtypesconfigurations.developer/src/org/eclipse/papyrus/elementtypesconfigurations/developer/view/ElementTypesConfigurationsListenerView.java
@@ -0,0 +1,227 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.elementtypesconfigurations.developer.view;
+
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.NullElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.papyrus.elementtypesconfigurations.developer.Activator;
+import org.eclipse.papyrus.elementtypesconfigurations.developer.providers.ElementTypesConfigurationsEventContentProvider;
+import org.eclipse.papyrus.elementtypesconfigurations.developer.providers.ElementTypesConfigurationsEventLabelProvider;
+import org.eclipse.papyrus.elementtypesconfigurations.developer.utils.ElementTypeRegistryUtils;
+import org.eclipse.papyrus.elementtypesconfigurations.developer.utils.ElementTypesConfigurationsEventPrinter;
+import org.eclipse.papyrus.elementtypesconfigurations.developer.utils.NotifierNullEditHelper;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.ElementTypesConfigurationsEventsChain;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.ElementTypesConfigurationsListenersRegistry;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.IElementTypesConfigurationsEventsChainListener;
+import org.eclipse.papyrus.infra.elementtypesconfiguration.notification.events.IElementTypesConfigurationsEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.FilteredTree;
+import org.eclipse.ui.dialogs.PatternFilter;
+import org.eclipse.ui.part.ViewPart;
+
+public class ElementTypesConfigurationsListenerView extends ViewPart {
+
+ IClientContext context = null;
+ FilteredTree tree = null;
+ SashForm sash = null;
+ Browser browser = null;
+ IElementTypesConfigurationsEventsChainListener listener = null;
+ Text limitText = null;
+
+ List<ElementTypesConfigurationsEventsChain> eventsChains = new ArrayList<ElementTypesConfigurationsEventsChain>();
+
+ final private int MAX_SIZE = 1000;
+
+
+ @Override
+ public void createPartControl(Composite parent) {
+ parent.setLayout(new GridLayout(3, true));
+ Button startButton = new Button(parent, SWT.NONE);
+ startButton.setText("Start");
+ startButton.addMouseListener(new MouseAdapter() {
+
+
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ if (!Platform.inDebugMode()) {
+ MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Debug mode", "You must activate debug mode to be able to use this view. ");
+ }
+
+ // Dirty work to force the NullElementType edithelper if in debug mode
+ if (Platform.inDebugMode()) {
+
+ Field nullElementTypeEditHelperField = ElementTypeRegistryUtils.getNullElementTypeEditHelper();
+
+ if (nullElementTypeEditHelperField != null) {
+ // Register fake
+
+ try {
+ nullElementTypeEditHelperField.set(NullElementType.getInstance(), new NotifierNullEditHelper());
+ } catch (IllegalArgumentException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (IllegalAccessException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ } else {
+ Activator.log.warn("Failed to override NullElementType's EditHelper");
+ }
+
+ MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Debug mode", "Be careful, as the platform is in debug mode, the NullElementType's EditHelper has been overriden");
+ }
+
+ if (listener == null) {
+ listener = new IElementTypesConfigurationsEventsChainListener() {
+
+ @Override
+ public void notifyChain(ElementTypesConfigurationsEventsChain chain) {
+ int limit;
+ String text = limitText.getText();
+ try {
+ limit = Integer.parseInt(text);
+ } catch (NumberFormatException e) {
+ limit = MAX_SIZE;
+ }
+ if (eventsChains.size() >= limit) {
+ eventsChains.remove(0);
+ }
+ eventsChains.add(chain);
+ Display.getCurrent().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ tree.getViewer().refresh();
+ }
+ });
+
+ }
+ };
+ ElementTypesConfigurationsListenersRegistry.getInstance().addEventChainListener(listener);
+ }
+ }
+
+ });
+ startButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+
+ Button stopButton = new Button(parent, SWT.NONE);
+ stopButton.setText("Stop");
+ stopButton.addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ ElementTypesConfigurationsListenersRegistry.getInstance().removeEventChainListener(listener);
+ listener = null;
+ }
+
+ });
+ stopButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+
+ Button clearButton = new Button(parent, SWT.NONE);
+ clearButton.setText("Clear");
+ clearButton.addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ eventsChains.clear();
+ tree.getViewer().refresh();
+ browser.setText("");
+ }
+
+ });
+ clearButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+
+ Label label = new Label(parent, SWT.NONE);
+ label.setText("Limit: ");
+
+ limitText = new Text(parent, SWT.BORDER);
+ limitText.setText(MAX_SIZE + "");
+ limitText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
+
+ sash = new SashForm(parent, SWT.HORIZONTAL | SWT.BORDER);
+
+ sash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
+
+ tree = new FilteredTree(sash, SWT.BORDER, new PatternFilter(), true);
+ tree.getViewer().setLabelProvider(new ElementTypesConfigurationsEventLabelProvider());
+ tree.getViewer().setContentProvider(new ElementTypesConfigurationsEventContentProvider());
+ tree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (event.getSelection() instanceof IStructuredSelection) {
+ Object first = ((IStructuredSelection) event.getSelection()).getFirstElement();
+ String result = "";
+ if (first instanceof IElementTypesConfigurationsEvent) {
+
+ Map<String, String> details = ElementTypesConfigurationsEventPrinter.getEventDetails(((IElementTypesConfigurationsEvent) first));
+ result = ElementTypesConfigurationsEventPrinter.printHtmlEvent(details);
+ } else if (first instanceof ElementTypesConfigurationsEventsChain) {
+ IEditCommandRequest req = ((ElementTypesConfigurationsEventsChain) first).getRequest();
+ result = ElementTypesConfigurationsEventPrinter.printHtmRequest(req);
+ }
+ browser.setText(result);
+ }
+
+ }
+ });
+ tree.getViewer().setInput(eventsChains);
+
+ browser = new Browser(sash, SWT.NONE);
+
+
+ sash.setWeights(new int[] { 1, 3 });
+ }
+
+
+
+ @Override
+ public void setFocus() {
+
+ }
+
+ /**
+ * @see org.eclipse.ui.part.WorkbenchPart#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ ElementTypesConfigurationsListenersRegistry.getInstance().removeEventChainListener(listener);
+ super.dispose();
+ }
+
+
+}

Back to the top