From d3c338c1d58e521ab859fb11bbff192cef94a87f Mon Sep 17 00:00:00 2001
From: Kevin Kassin <KK@Medion-PC>
Date: Sun, 30 Jul 2017 19:34:16 +0200
Subject: [PATCH] #Commit 30.7 19:30

a double click on a realtionship now activates the edit feature for it
---
 .../iorm/ui/multipage/MultipageEditor.java    |  6 ++--
 .../ui/providers/ToolBehaviorProvider.java    | 25 +++++++++++++--
 .../org/framed/iorm/ui/util/GeneralUtil.java  | 32 +++++++++++++++++--
 3 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/multipage/MultipageEditor.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/multipage/MultipageEditor.java
index ba5d160f..de82c4f7 100644
--- a/org.framed.iorm.ui/src/org/framed/iorm/ui/multipage/MultipageEditor.java
+++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/multipage/MultipageEditor.java
@@ -35,6 +35,7 @@ import org.framed.iorm.ui.subeditors.FRaMEDFeatureEditor;
 import org.framed.iorm.ui.subeditors.FRaMEDTextViewer;
 import org.framed.iorm.ui.util.DiagramUtil;
 import org.framed.iorm.ui.util.EditorInputUtil;
+import org.framed.iorm.ui.util.GeneralUtil;
 import org.framed.iorm.ui.util.PropertyUtil;
 import org.framed.iorm.ui.providers.DiagramTypeProvider; //*import for javadoc link
 import org.framed.iorm.ui.providers.ToolBehaviorProvider;
@@ -298,10 +299,7 @@ public class MultipageEditor extends FormEditor implements ISelectionListener, I
 		//Step 4 
 		ICreateFeature createModelFeature = null;
 		ICreateFeature[] createFeatures = editorDiagram.getDiagramTypeProvider().getFeatureProvider().getCreateFeatures();
-		for(int i = 0; i<createFeatures.length; i++) {
-			if(createFeatures[i].getCreateName().equals(MODEL_FEATURE_NAME)) 
-				createModelFeature = createFeatures[i];
-		}
+		createModelFeature = (ICreateFeature) GeneralUtil.findFeatureByName(createFeatures, MODEL_FEATURE_NAME);
 		if(createModelFeature != null) {
 			CreateContext createContext = new CreateContext();
 			if(createModelFeature.canCreate(createContext)) createModelFeature.create(createContext);
diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/ToolBehaviorProvider.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/ToolBehaviorProvider.java
index 1b80366f..6f140413 100644
--- a/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/ToolBehaviorProvider.java
+++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/ToolBehaviorProvider.java
@@ -8,7 +8,9 @@ import org.eclipse.graphiti.dt.IDiagramTypeProvider;
 import org.eclipse.graphiti.features.ICreateConnectionFeature;
 import org.eclipse.graphiti.features.ICreateFeature;
 import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.IDoubleClickContext;
 import org.eclipse.graphiti.features.context.IPictogramElementContext;
+import org.eclipse.graphiti.features.custom.ICustomFeature;
 import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
 import org.eclipse.graphiti.mm.pictograms.Diagram;
 import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
@@ -28,11 +30,13 @@ import org.framed.iorm.ui.palette.FeaturePaletteDescriptor;
 import org.framed.iorm.ui.palette.PaletteView;
 import org.framed.iorm.ui.palette.ViewVisibility;
 import org.framed.iorm.ui.util.DiagramUtil;
+import org.framed.iorm.ui.util.GeneralUtil;
 import org.framed.iorm.ui.util.PropertyUtil;
 import org.framed.iorm.ui.providers.FeatureProvider; //*import for javadoc link
 import org.framed.iorm.model.Relation;
 import org.framed.iorm.model.Type;
 import org.framed.iorm.ui.exceptions.FeatureHasNoPaletteDescriptorException;
+import org.framed.iorm.ui.graphitifeatures.EditRelationshipFeature;
 import org.framed.iorm.ui.graphitifeatures.StepInFeature; //*import for javadoc link
 import org.framed.iorm.ui.graphitifeatures.StepInNewTabFeature; //*import for javadoc link
 import org.framed.iorm.ui.graphitifeatures.StepOutFeature; //*import for javadoc link
@@ -155,9 +159,8 @@ public class ToolBehaviorProvider extends DefaultToolBehaviorProvider{
 		//Step 1
 		if(customContext.getPictogramElements().length == 1) {
 			PictogramElement pictogramElement = customContext.getPictogramElements()[0];
-			if(pictogramElement.getLink() != null &&
-			   pictogramElement.getLink().getBusinessObjects().size() == 1) {
-				EObject businessObject = pictogramElement.getLink().getBusinessObjects().get(0);
+			EObject businessObject = GeneralUtil.getBusinessObjectIfExactlyOne(pictogramElement);
+			if(businessObject != null) {
 				//Step 2
 				for(int i = 0; i < superContextEntries.length; i++) {
 					switch(superContextEntries[i].getText()) {
@@ -325,5 +328,21 @@ public class ToolBehaviorProvider extends DefaultToolBehaviorProvider{
 			default:
 				break;
 	}	}	}
+	
+	/**
+	 * enables the edit features for relationships and fulfillments when double clicking such a relation
+	 */
+	@Override
+	public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) {
+		if(context.getPictogramElements().length == 1) {
+			PictogramElement pictogramElement = context.getPictogramElements()[0];
+			EObject businessObject = GeneralUtil.getBusinessObjectIfExactlyOne(pictogramElement);
+			if(businessObject instanceof Relation &&
+			   ((Relation) businessObject).getType() == Type.RELATIONSHIP) {
+				ICustomFeature[] customFeatures = getFeatureProvider().getCustomFeatures(context);
+				return (ICustomFeature) GeneralUtil.findFeatureByName(customFeatures, EDIT_RELATIONSHIP_FEATURE_NAME);
+		}	}
+		return null;
+	}	
 }
 
diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/util/GeneralUtil.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/util/GeneralUtil.java
index 866b5f28..6369a920 100644
--- a/org.framed.iorm.ui/src/org/framed/iorm/ui/util/GeneralUtil.java
+++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/util/GeneralUtil.java
@@ -4,6 +4,7 @@ import java.util.List;
 
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.emf.ecore.EObject;
+import org.eclipse.graphiti.features.IFeature;
 import org.eclipse.graphiti.features.IMappingProvider; //*import for javadoc link
 import org.eclipse.graphiti.features.context.ICreateContext;
 import org.eclipse.graphiti.features.context.impl.AddContext;
@@ -106,7 +107,7 @@ public class GeneralUtil {
 	}
 	
 	/**
-	 * Similiar to the contains operation of lists this method offers a comparison using the equal operation
+	 * Similar to the contains operation of lists this method offers a comparison using the equal operation
 	 * of strings to search for equal string in a list of strings.
 	 * @param list the list to search an equal string in
 	 * @param stringToCheckAgainst the string to search an equal one for
@@ -117,7 +118,7 @@ public class GeneralUtil {
 			if(string.equals(stringToCheckAgainst)) return true;
 		return false;
 	}
-	
+		
 	/**
 	 * returns the first linked business object of a pictogram
 	 * <p>
@@ -131,4 +132,31 @@ public class GeneralUtil {
 	public static EObject getBusinessObjectForPictogramElement(PictogramElement pictogramElement) {
 		return pictogramElement.getLink().getBusinessObjects().get(0);
 	}
+	
+	/**
+	 * return a linked business object for a pictogram element if there is exactly one business object linked 
+	 * @param pictogramElement the element to get the linked business object for
+	 * @return the one linked business object if or null 
+	 */
+	public static EObject getBusinessObjectIfExactlyOne(PictogramElement pictogramElement) {
+		if(pictogramElement.getLink() != null &&
+		   pictogramElement.getLink().getBusinessObjects().size() == 1) {
+			return getBusinessObjectForPictogramElement(pictogramElement);
+		}	
+		return null;
+	}		
+	
+	/**
+	 * find the a feature by its name in an array of features
+	 * @param array the array with features to search in
+	 * @param featureName the name of the feature to find
+	 * @return the found feature or null if it was not found
+	 */
+	public static IFeature findFeatureByName(IFeature[] array, String featureName) {
+		for(int i = 0; i<array.length; i++) {
+			if(array[i].getName().equals(featureName)) 
+				return array[i];
+		}	
+		return null;
+	}	
 }
-- 
GitLab