From cc0d743a0f6718448fb34e8ba18abe2a5f8abf65 Mon Sep 17 00:00:00 2001
From: Kevin Kassin <KK@Medion-PC>
Date: Tue, 1 Aug 2017 23:22:20 +0200
Subject: [PATCH] #Commit 1.8

Warning if there are unsaved changes in another multipage editor now has
a save all option,
attribute and operations text now shrink and expand with when layouting
types
---
 .../AbstractStepInFeature.java                | 20 -------------------
 .../ui/graphitifeatures/StepInFeature.java    |  2 +-
 .../iorm/ui/multipage/MultipageEditor.java    | 15 ++++++++++++--
 .../shapes/CompartmentTypePattern.java        | 14 ++++++++-----
 .../ui/pattern/shapes/DataTypePattern.java    |  8 ++++++--
 .../ui/pattern/shapes/NaturalTypePattern.java |  8 ++++++--
 .../ui/pattern/shapes/RoleTypePattern.java    |  8 ++++++--
 7 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/graphitifeatures/AbstractStepInFeature.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/graphitifeatures/AbstractStepInFeature.java
index d33f8f02..ff4f09d9 100644
--- a/org.framed.iorm.ui/src/org/framed/iorm/ui/graphitifeatures/AbstractStepInFeature.java
+++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/graphitifeatures/AbstractStepInFeature.java
@@ -1,11 +1,9 @@
 package org.framed.iorm.ui.graphitifeatures;
 
-import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.graphiti.features.IFeatureProvider;
 import org.eclipse.graphiti.features.context.ICustomContext;
 import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
 import org.eclipse.graphiti.mm.pictograms.Shape;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.PlatformUI;
 import org.framed.iorm.ui.literals.IdentifierLiterals;
 import org.framed.iorm.ui.multipage.MultipageEditor;
@@ -74,24 +72,6 @@ public abstract class AbstractStepInFeature extends AbstractCustomFeature {
 		return false;
 	}
 	
-	/**
-	 * manages to close a given multipage editor at the next reasonable opportunity usind the operation 
-	 * {@link Display#asyncExec}
-	 * <p>
-	 * It also saves the multipage editor before closing it to clean up the dirty state of the whole workbench.
-	 * @param multipageEditorToClose
-	 */
-	public static void closeMultipageEditorWhenPossible(MultipageEditor multipageEditorToClose) {
-		Display display = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay();
-		display.asyncExec(new Runnable() {
-			@Override
-			public void run() {
-				multipageEditorToClose.getDiagramEditor().doSave(new NullProgressMonitor());
-				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(multipageEditorToClose, false);
-			}
-		});
-	}
-
 	/**
 	 * to be overriden in subclasses
 	 */
diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/graphitifeatures/StepInFeature.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/graphitifeatures/StepInFeature.java
index 5a3cca2d..04bea31e 100644
--- a/org.framed.iorm.ui/src/org/framed/iorm/ui/graphitifeatures/StepInFeature.java
+++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/graphitifeatures/StepInFeature.java
@@ -62,7 +62,7 @@ public class StepInFeature extends AbstractStepInFeature {
 		//Step 1
 		MultipageEditor multipageEditorToClose = 
 				(MultipageEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
-		closeMultipageEditorWhenPossible(multipageEditorToClose);
+		GeneralUtil.closeMultipageEditorWhenPossible(multipageEditorToClose);
 		//Step 2
 		ContainerShape typeBodyShape = (ContainerShape) context.getPictogramElements()[0];
 		Type type = null;
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 de82c4f7..644a6dc3 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
@@ -11,6 +11,7 @@ import org.eclipse.graphiti.mm.pictograms.Diagram;
 import org.eclipse.graphiti.ui.editor.DiagramEditorInput;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.IEditorInput;
@@ -413,8 +414,18 @@ public class MultipageEditor extends FormEditor implements ISelectionListener, I
 					}
 					if(unsavedChangesInOtherMultipageEditors) {	
 						Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
-						MessageDialog.openInformation(shell, MESSAGE_UNSAVED_CHANGES_IN_OTHER_MULTIPAGE_EDITORS_TITLE, MESSAGE_UNSAVED_CHANGES_IN_OTHER_MULTIPAGE_EDITORS_TEXT);
-					}	
+						MessageDialog dialog = new MessageDialog(shell, 
+								MESSAGE_UNSAVED_CHANGES_IN_OTHER_MULTIPAGE_EDITORS_TITLE, null,
+								MESSAGE_UNSAVED_CHANGES_IN_OTHER_MULTIPAGE_EDITORS_TEXT, MessageDialog.ERROR, 
+								new String[] {"Save All", "OK"}, 0);
+						int result = dialog.open();
+						if(result == 0) {
+							Display display = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay();
+							display.asyncExec(new Runnable() {
+								@Override
+								public void run() {
+									PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().saveAllEditors(false);
+					}	});	}	}	
 					activeWorkbenchPart = (MultipageEditor) part;
 	}	}	} 	}
 		
diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/CompartmentTypePattern.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/CompartmentTypePattern.java
index 56ae018e..dd2f39a0 100644
--- a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/CompartmentTypePattern.java
+++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/CompartmentTypePattern.java
@@ -587,7 +587,7 @@ public class CompartmentTypePattern extends FRaMEDShapePattern implements IPatte
 	 * If its not clear what the different shapes means, see {@link #add} for reference.
 	 */
 	@Override
-	public boolean layout(ILayoutContext layoutContext) {	
+	public boolean layout(ILayoutContext layoutContext) {
 		boolean layoutChanged = false;
 		int newHeight, newWidth, newY;
 		Shape indicatorDotsShapeToDelete;
@@ -650,7 +650,9 @@ public class CompartmentTypePattern extends FRaMEDShapePattern implements IPatte
 			           	EList<Shape> attributes = attributeContainerShape.getChildren();
 			            //set place of attributes
 			            for(int m = 0; m<attributes.size(); m++) {
-			            	attributeContainerShape.getChildren().get(m).getGraphicsAlgorithm().setY(newY+m*HEIGHT_OPERATION_SHAPE);
+			            	Text attributeText = (Text) attributeContainerShape.getChildren().get(m).getGraphicsAlgorithm();
+			            	attributeText.setY(newY+m*HEIGHT_OPERATION_SHAPE);
+			            	attributeText.setWidth(newWidth);
 		            	}
 			            //set all attributes visible
 			            indicatorDotsShapeToDelete = null;
@@ -691,7 +693,9 @@ public class CompartmentTypePattern extends FRaMEDShapePattern implements IPatte
 			        	EList<Shape> operations = operationContainerShape.getChildren();
 			            //set place of attributes
 			            for(int m = 0; m<operations.size(); m++) {
-			            	operationContainerShape.getChildren().get(m).getGraphicsAlgorithm().setY(newY+m*HEIGHT_OPERATION_SHAPE);
+			            	Text operationText = (Text) operationContainerShape.getChildren().get(m).getGraphicsAlgorithm();
+			            	operationText.setY(newY+m*HEIGHT_OPERATION_SHAPE);
+			            	operationText.setWidth(newWidth);
 		            	}
 			            //set all operations visible
 						indicatorDotsShapeToDelete = null;
@@ -760,7 +764,7 @@ public class CompartmentTypePattern extends FRaMEDShapePattern implements IPatte
 			            	PropertyUtil.setShape_IdValue(indicatorDotsShape, SHAPE_ID_COMPARTMENTTYPE_INDICATOR_DOTS); 
 			           	}
 			           	layoutChanged = true; 
-		}	}	}	}        
+		}	}	}	}  
 	    return layoutChanged;
 	}
 	
@@ -953,7 +957,7 @@ public class CompartmentTypePattern extends FRaMEDShapePattern implements IPatte
 		}
 		return super.canResizeShape(resizeContext);
 	}
-		
+			
 	//delete feature
 	//~~~~~~~~~~~~~~
 	/**
diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/DataTypePattern.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/DataTypePattern.java
index e8f7c142..17abbf42 100644
--- a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/DataTypePattern.java
+++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/DataTypePattern.java
@@ -602,7 +602,9 @@ public class DataTypePattern extends FRaMEDShapePattern implements IPattern {
 			           EList<Shape> attributes = attributeContainerShape.getChildren();
 			           //set place of attributes
 				       for(int m = 0; m<attributes.size(); m++) {
-				    	   attributeContainerShape.getChildren().get(m).getGraphicsAlgorithm().setY(newY+m*HEIGHT_OPERATION_SHAPE);
+				    	   Text attributeText = (Text) attributeContainerShape.getChildren().get(m).getGraphicsAlgorithm();
+			            	attributeText.setY(newY+m*HEIGHT_OPERATION_SHAPE);
+			            	attributeText.setWidth(newWidth);
 				       }
 			           //set all attributes visible
 			           indicatorDotsShapeToDelete = null;
@@ -643,7 +645,9 @@ public class DataTypePattern extends FRaMEDShapePattern implements IPattern {
 			           EList<Shape> operations = operationContainerShape.getChildren();
 			           //set place of operations
 				       for(int m = 0; m<operations.size(); m++) {
-				    	   operationContainerShape.getChildren().get(m).getGraphicsAlgorithm().setY(newY+m*HEIGHT_OPERATION_SHAPE);
+				    	   Text operationText = (Text) operationContainerShape.getChildren().get(m).getGraphicsAlgorithm();
+				    	   operationText.setY(newY+m*HEIGHT_OPERATION_SHAPE);
+				    	   operationText.setWidth(newWidth);
 				       }
 				       //set all operations visible
 				       indicatorDotsShapeToDelete = null;
diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/NaturalTypePattern.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/NaturalTypePattern.java
index 75969512..91a4b722 100644
--- a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/NaturalTypePattern.java
+++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/NaturalTypePattern.java
@@ -594,7 +594,9 @@ public class NaturalTypePattern extends FRaMEDShapePattern implements IPattern {
 		            	EList<Shape> attributes = attributeContainerShape.getChildren();
 		            	//set places of attributes
 		            	for(int m = 0; m<attributes.size(); m++) {
-		            		attributeContainerShape.getChildren().get(m).getGraphicsAlgorithm().setY(newY+m*HEIGHT_OPERATION_SHAPE);
+		            		Text attributeText = (Text) attributeContainerShape.getChildren().get(m).getGraphicsAlgorithm();
+			            	attributeText.setY(newY+m*HEIGHT_OPERATION_SHAPE);
+			            	attributeText.setWidth(newWidth);
 	            		}   	
 		            	//set all attributes visible and delete indicator dots
 		            	indicatorDotsShapeToDelete = null;
@@ -635,7 +637,9 @@ public class NaturalTypePattern extends FRaMEDShapePattern implements IPattern {
 		            	EList<Shape> operations = operationContainerShape.getChildren();
 		            	//set place of operations
 		            	for(int m = 0; m<operations.size(); m++) {
-		            		operationContainerShape.getChildren().get(m).getGraphicsAlgorithm().setY(newY+m*HEIGHT_OPERATION_SHAPE);
+		            		Text operationText = (Text) operationContainerShape.getChildren().get(m).getGraphicsAlgorithm();
+			            	operationText.setY(newY+m*HEIGHT_OPERATION_SHAPE);
+			            	operationText.setWidth(newWidth);
 	            		}
 		            	//set all operations visible
 					    indicatorDotsShapeToDelete = null;
diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/RoleTypePattern.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/RoleTypePattern.java
index 01633dd2..8e648bc8 100644
--- a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/RoleTypePattern.java
+++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/RoleTypePattern.java
@@ -618,7 +618,9 @@ public class RoleTypePattern extends FRaMEDShapePattern implements IPattern {
 			            EList<Shape> attributes = attributeContainerShape.getChildren();
 			            //set places of attributes
 			            for(int m = 0; m<attributes.size(); m++) {
-			            	attributeContainerShape.getChildren().get(m).getGraphicsAlgorithm().setY(newY+m*HEIGHT_OPERATION_SHAPE);
+			            	Text attributeText = (Text) attributeContainerShape.getChildren().get(m).getGraphicsAlgorithm();
+			            	attributeText.setY(newY+m*HEIGHT_OPERATION_SHAPE);
+			            	attributeText.setWidth(newWidth);
 		            	}   	
 			            //set all attributes visible and delete indicator dots
 			            indicatorDotsShapeToDelete = null;
@@ -659,7 +661,9 @@ public class RoleTypePattern extends FRaMEDShapePattern implements IPattern {
 			            EList<Shape> operations = operationContainerShape.getChildren();
 			            //set place of operations
 			            for(int m = 0; m<operations.size(); m++) {
-			            	operationContainerShape.getChildren().get(m).getGraphicsAlgorithm().setY(newY+m*HEIGHT_OPERATION_SHAPE);
+			            	Text operationText = (Text) operationContainerShape.getChildren().get(m).getGraphicsAlgorithm();
+			            	operationText.setY(newY+m*HEIGHT_OPERATION_SHAPE);
+			            	operationText.setWidth(newWidth);
 		            	}
 			            //set all operations visible
 						indicatorDotsShapeToDelete = null;
-- 
GitLab