From 2e73bf0cd20b015eb16f2d810ef86a53b3eb3a44 Mon Sep 17 00:00:00 2001
From: Andrea Enrici <andrea.enrici@nokia.com>
Date: Fri, 13 Jun 2014 17:08:49 +0000
Subject: [PATCH] Added JDialogAttribute as dialog windonw to add attributes to
 an instance

---
 src/ui/tmlsd/TMLSDControllerInstance.java | 48 ++++++++++--
 src/ui/tmlsd/TMLSDInstance.java           | 67 +++--------------
 src/ui/tmlsd/TMLSDStorageInstance.java    | 89 ++++++++++++++++++++++-
 src/ui/tmlsd/TMLSDTransferInstance.java   | 48 ++++++++++--
 4 files changed, 175 insertions(+), 77 deletions(-)

diff --git a/src/ui/tmlsd/TMLSDControllerInstance.java b/src/ui/tmlsd/TMLSDControllerInstance.java
index 2f22a5f06a..7bc09934fd 100755
--- a/src/ui/tmlsd/TMLSDControllerInstance.java
+++ b/src/ui/tmlsd/TMLSDControllerInstance.java
@@ -91,28 +91,41 @@ public class TMLSDControllerInstance extends TMLSDInstance implements SwallowTGC
         myImageIcon = IconManager.imgic500;
 	}
     
-	@Override public boolean editOndoubleClick( JFrame frame ) {
+	public boolean editOndoubleClick(JFrame frame) {
 			
-			String oldValue = name;
+		String oldValue = name;
 		
-			JDialogSDInstance jdsdi = new JDialogSDInstance( frame, name, isActor, "Controller attributes" );
+		/*	JDialogSDInstance jdsdi = new JDialogSDInstance(frame, name, isActor, "Instance attributes");
       jdsdi.setSize(300, 250);
       GraphicLib.centerOnParent(jdsdi);
       jdsdi.show(); // blocked until dialog has been closed
-		
+		*/
+		JDialogAttribute jda = new JDialogAttribute( myAttributes, null, frame, "Setting attributes of " + this.name, "Attribute" );
+    setJDialogOptions( jda );
+    jda.setSize( 650, 375 );
+    GraphicLib.centerOnParent( jda );
+    jda.setVisible( true ); // blocked until dialog has been closed
+    //makeValue();
+    //if (oldValue.equals(value)) {
+	    //return false;
+    //}
+		/*rescaled = true;
+		return true;
+    }*/
 		
      	String text = getName() + ": ";
       if(hasFather() ) {
         text = getTopLevelName() + " / " + text;
       }
 		
-			if( jdsdi.hasBeenUpdated() ) {
+			/*if( jdsdi.hasBeenUpdated() ) {
 				isActor = jdsdi.isAnActor();
 				String s = jdsdi.getInstanceName();
 				if( s != null ) {
 					s = s.trim();
-				}
+				}*/
 			
+			String s = this.name;
 			if ((s != null) && (s.length() > 0) && (!s.equals(oldValue))) {
 				if (!TAttribute.isAValidId(s, false, false)) {
 					JOptionPane.showMessageDialog( frame,
@@ -138,9 +151,28 @@ public class TMLSDControllerInstance extends TMLSDInstance implements SwallowTGC
 				}
 				return true;
 			}
+			return false;
 		}
-        return false;
-    }
+/*        return false;
+    }*/
+	
+	protected void setJDialogOptions( JDialogAttribute jda ) {
+		
+		jda.addAccess(TAttribute.getStringAccess(TAttribute.PUBLIC));
+		jda.addAccess(TAttribute.getStringAccess(TAttribute.PRIVATE));
+		jda.addType(TAttribute.getStringType(TAttribute.NATURAL), true);
+		jda.addType(TAttribute.getStringType(TAttribute.BOOLEAN), true);
+		
+/*		Vector<String> records = ( (TMLComponentTaskDiagramPanel )(tdp)).getAllRecords(this);
+		for( String s: records ) {
+			jda.addType(s, false);
+		}*/
+		
+		jda.enableInitialValue(true);
+		jda.enableRTLOTOSKeyword(true);
+		jda.enableJavaKeyword(false);
+		jda.enableTMLKeyword(false);
+	}
 
 	@Override public int getType() {
 		return TGComponentManager.TMLSD_CONTROLLER_INSTANCE;
diff --git a/src/ui/tmlsd/TMLSDInstance.java b/src/ui/tmlsd/TMLSDInstance.java
index fe3acf5209..77a018b33d 100755
--- a/src/ui/tmlsd/TMLSDInstance.java
+++ b/src/ui/tmlsd/TMLSDInstance.java
@@ -51,6 +51,7 @@ import java.awt.*;
 import javax.swing.*;
 import org.w3c.dom.*;
 import java.awt.event.*;
+import java.util.*;
 
 import myutil.*;
 import ui.*;
@@ -58,7 +59,7 @@ import ui.window.*;
 
 import tmltranslator.tmlcp.*;
 
-//Abstract class, getType() is abstract
+//Abstract class, getType() and editOndoubleClick( JFrame ) are abstract
 public abstract class TMLSDInstance extends TGCWithInternalComponent implements SwallowTGComponent {
 
     //protected int lineLength = 5;
@@ -69,6 +70,7 @@ public abstract class TMLSDInstance extends TGCWithInternalComponent implements
 		protected boolean isActor;
 		protected static int heightActor = 30;
 		protected static int widthActor = 16;
+		protected Vector myAttributes;
 	
     
     public TMLSDInstance(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp)  {
@@ -82,22 +84,16 @@ public abstract class TMLSDInstance extends TGCWithInternalComponent implements
         maxWidth = 10;
         minHeight = 250;
         maxHeight = 1500;
-        
-        
         makeTGConnectingPoints();
         //addTGConnectingPointsComment();
-        
         nbInternalTGComponent = 0;
-        
         moveable = true;
         editable = true;
         removable = true;
         userResizable = true;
-        
         value = "Instance name";
         name = "instance";
-				isActor = false;
-        
+				myAttributes = new Vector();
         myImageIcon = IconManager.imgic500;
 	}
     
@@ -175,56 +171,7 @@ public abstract class TMLSDInstance extends TGCWithInternalComponent implements
         
     }
     
-    public boolean editOndoubleClick(JFrame frame) {
-			
-			String oldValue = name;
-		
-			JDialogSDInstance jdsdi = new JDialogSDInstance(frame, name, isActor, "Instance attributes");
-      jdsdi.setSize(300, 250);
-      GraphicLib.centerOnParent(jdsdi);
-      jdsdi.show(); // blocked until dialog has been closed
-		
-		
-     	String text = getName() + ": ";
-      if(hasFather() ) {
-        text = getTopLevelName() + " / " + text;
-      }
-		
-			if( jdsdi.hasBeenUpdated() ) {
-				isActor = jdsdi.isAnActor();
-				String s = jdsdi.getInstanceName();
-				if( s != null ) {
-					s = s.trim();
-				}
-			
-			if ((s != null) && (s.length() > 0) && (!s.equals(oldValue))) {
-				if (!TAttribute.isAValidId(s, false, false)) {
-					JOptionPane.showMessageDialog( frame,
-						"Could not change the name of the instance: the new name is not a valid name",
-						"Error", JOptionPane.INFORMATION_MESSAGE );
-					return false;
-				}
-				setName(s);
-				TraceManager.addDev( Integer.toString( connectingPoint.length ) );
-        for( int i = 0; i < connectingPoint.length; i++ ) {
-				//for each connecting point connected to something
-					if( connectingPoint[i].getReferenceToConnector() != null )	{
-						TGConnectorMessageAsyncTMLSD connector = (TGConnectorMessageAsyncTMLSD) connectingPoint[i].getReferenceToConnector();
-						if( connectingPoint[i].isSource() )	{
-							connector.setStartName(s);
-							TraceManager.addDev( connector.getConnectorName() );
-						}
-						else	{
-							connector.setEndName(s);
-							TraceManager.addDev( connector.getConnectorName() );
-						}
-					}
-				}
-				return true;
-			}
-		}
-        return false;
-    }
+	public abstract boolean editOndoubleClick( JFrame frame );
 	
 	public boolean acceptSwallowedTGComponent(TGComponent tgc) {
 		 if ((tgc instanceof TMLSDActionState)) {
@@ -473,4 +420,8 @@ public abstract class TMLSDInstance extends TGCWithInternalComponent implements
 	public TGConnectingPoint[] getConnectingPoint()	{
 		return connectingPoint;
 	}
+
+	public Vector getAttributes()	{
+		return myAttributes;
+	}
 }
diff --git a/src/ui/tmlsd/TMLSDStorageInstance.java b/src/ui/tmlsd/TMLSDStorageInstance.java
index 83258dc78c..6480dbb8ca 100755
--- a/src/ui/tmlsd/TMLSDStorageInstance.java
+++ b/src/ui/tmlsd/TMLSDStorageInstance.java
@@ -51,6 +51,7 @@ import java.awt.*;
 import javax.swing.*;
 import org.w3c.dom.*;
 import java.awt.event.*;
+import java.util.*;
 
 import myutil.*;
 import ui.*;
@@ -59,7 +60,7 @@ import ui.window.*;
 import tmltranslator.tmlcp.*;
 
 public class TMLSDStorageInstance extends TMLSDInstance implements SwallowTGComponent {
-
+	
     public TMLSDStorageInstance( int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos,
 																	TGComponent _father, TDiagramPanel _tdp )  {
         super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp);
@@ -91,7 +92,7 @@ public class TMLSDStorageInstance extends TMLSDInstance implements SwallowTGComp
         myImageIcon = IconManager.imgic500;
 	}
     
-    @Override public boolean editOndoubleClick(JFrame frame) {
+/*    @Override public boolean editOndoubleClick(JFrame frame) {
 			
 			String oldValue = name;
 		
@@ -139,7 +140,89 @@ public class TMLSDStorageInstance extends TMLSDInstance implements SwallowTGComp
 			}
 		}
         return false;
-    }
+    }*/
+	public boolean editOndoubleClick(JFrame frame) {
+			
+		String oldValue = name;
+		
+		/*	JDialogSDInstance jdsdi = new JDialogSDInstance(frame, name, isActor, "Instance attributes");
+      jdsdi.setSize(300, 250);
+      GraphicLib.centerOnParent(jdsdi);
+      jdsdi.show(); // blocked until dialog has been closed
+		*/
+		JDialogAttribute jda = new JDialogAttribute( myAttributes, null, frame, "Setting attributes of " + this.name, "Attribute" );
+    setJDialogOptions( jda );
+    jda.setSize( 650, 375 );
+    GraphicLib.centerOnParent( jda );
+    jda.setVisible( true ); // blocked until dialog has been closed
+    //makeValue();
+    //if (oldValue.equals(value)) {
+	    //return false;
+    //}
+		/*rescaled = true;
+		return true;
+    }*/
+		
+     	String text = getName() + ": ";
+      if(hasFather() ) {
+        text = getTopLevelName() + " / " + text;
+      }
+		
+			/*if( jdsdi.hasBeenUpdated() ) {
+				isActor = jdsdi.isAnActor();
+				String s = jdsdi.getInstanceName();
+				if( s != null ) {
+					s = s.trim();
+				}*/
+			
+			String s = this.name;
+			if ((s != null) && (s.length() > 0) && (!s.equals(oldValue))) {
+				if (!TAttribute.isAValidId(s, false, false)) {
+					JOptionPane.showMessageDialog( frame,
+						"Could not change the name of the instance: the new name is not a valid name",
+						"Error", JOptionPane.INFORMATION_MESSAGE );
+					return false;
+				}
+				setName(s);
+				TraceManager.addDev( Integer.toString( connectingPoint.length ) );
+        for( int i = 0; i < connectingPoint.length; i++ ) {
+				//for each connecting point connected to something
+					if( connectingPoint[i].getReferenceToConnector() != null )	{
+						TGConnectorMessageAsyncTMLSD connector = (TGConnectorMessageAsyncTMLSD) connectingPoint[i].getReferenceToConnector();
+						if( connectingPoint[i].isSource() )	{
+							connector.setStartName(s);
+							TraceManager.addDev( connector.getConnectorName() );
+						}
+						else	{
+							connector.setEndName(s);
+							TraceManager.addDev( connector.getConnectorName() );
+						}
+					}
+				}
+				return true;
+			}
+			return false;
+		}
+/*        return false;
+    }*/
+	
+	protected void setJDialogOptions( JDialogAttribute jda ) {
+		
+		jda.addAccess(TAttribute.getStringAccess(TAttribute.PUBLIC));
+		jda.addAccess(TAttribute.getStringAccess(TAttribute.PRIVATE));
+		jda.addType(TAttribute.getStringType(TAttribute.NATURAL), true);
+		jda.addType(TAttribute.getStringType(TAttribute.BOOLEAN), true);
+		
+/*		Vector<String> records = ( (TMLComponentTaskDiagramPanel )(tdp)).getAllRecords(this);
+		for( String s: records ) {
+			jda.addType(s, false);
+		}*/
+		
+		jda.enableInitialValue(true);
+		jda.enableRTLOTOSKeyword(true);
+		jda.enableJavaKeyword(false);
+		jda.enableTMLKeyword(false);
+	}
 
 	@Override public int getType() {
 		return TGComponentManager.TMLSD_STORAGE_INSTANCE;
diff --git a/src/ui/tmlsd/TMLSDTransferInstance.java b/src/ui/tmlsd/TMLSDTransferInstance.java
index b3fbf39192..b35233ff86 100755
--- a/src/ui/tmlsd/TMLSDTransferInstance.java
+++ b/src/ui/tmlsd/TMLSDTransferInstance.java
@@ -91,28 +91,41 @@ public class TMLSDTransferInstance extends TMLSDInstance implements SwallowTGCom
         myImageIcon = IconManager.imgic500;
 	}
     
-	@Override public boolean editOndoubleClick( JFrame frame ) {
+	public boolean editOndoubleClick(JFrame frame) {
 			
-			String oldValue = name;
+		String oldValue = name;
 		
-			JDialogSDInstance jdsdi = new JDialogSDInstance(frame, name, isActor, "Transfer attributes");
+		/*	JDialogSDInstance jdsdi = new JDialogSDInstance(frame, name, isActor, "Instance attributes");
       jdsdi.setSize(300, 250);
       GraphicLib.centerOnParent(jdsdi);
       jdsdi.show(); // blocked until dialog has been closed
-		
+		*/
+		JDialogAttribute jda = new JDialogAttribute( myAttributes, null, frame, "Setting attributes of " + this.name, "Attribute" );
+    setJDialogOptions( jda );
+    jda.setSize( 650, 375 );
+    GraphicLib.centerOnParent( jda );
+    jda.setVisible( true ); // blocked until dialog has been closed
+    //makeValue();
+    //if (oldValue.equals(value)) {
+	    //return false;
+    //}
+		/*rescaled = true;
+		return true;
+    }*/
 		
      	String text = getName() + ": ";
       if(hasFather() ) {
         text = getTopLevelName() + " / " + text;
       }
 		
-			if( jdsdi.hasBeenUpdated() ) {
+			/*if( jdsdi.hasBeenUpdated() ) {
 				isActor = jdsdi.isAnActor();
 				String s = jdsdi.getInstanceName();
 				if( s != null ) {
 					s = s.trim();
-				}
+				}*/
 			
+			String s = this.name;
 			if ((s != null) && (s.length() > 0) && (!s.equals(oldValue))) {
 				if (!TAttribute.isAValidId(s, false, false)) {
 					JOptionPane.showMessageDialog( frame,
@@ -138,9 +151,28 @@ public class TMLSDTransferInstance extends TMLSDInstance implements SwallowTGCom
 				}
 				return true;
 			}
+			return false;
 		}
-        return false;
-    }
+/*        return false;
+    }*/
+	
+	protected void setJDialogOptions( JDialogAttribute jda ) {
+		
+		jda.addAccess(TAttribute.getStringAccess(TAttribute.PUBLIC));
+		jda.addAccess(TAttribute.getStringAccess(TAttribute.PRIVATE));
+		jda.addType(TAttribute.getStringType(TAttribute.NATURAL), true);
+		jda.addType(TAttribute.getStringType(TAttribute.BOOLEAN), true);
+		
+/*		Vector<String> records = ( (TMLComponentTaskDiagramPanel )(tdp)).getAllRecords(this);
+		for( String s: records ) {
+			jda.addType(s, false);
+		}*/
+		
+		jda.enableInitialValue(true);
+		jda.enableRTLOTOSKeyword(true);
+		jda.enableJavaKeyword(false);
+		jda.enableTMLKeyword(false);
+	}
 
 	@Override public int getType() {
 		return TGComponentManager.TMLSD_TRANSFER_INSTANCE;
-- 
GitLab