Commits

Anonymous committed 5576e41

Solved the problem with new XML edges and added context for arcs

Comments (0)

Files changed (8)

src/nl/tudelft/lime/constants/LimeMessages.java

     public static final String PropertyDescriptor_Boolean_True = "True";
     public static final String PropertyDescriptor_Component_Type_Label = "Type";
     public static final String PropertyDescriptor_Component_Ret_Label = "Ret";
+    public static final String PropertyDescriptor_Label_Context_Label = "Context";    
     public static final String PropertyDescriptor_Name_Label = "Name";
     public static final String PropertyDescriptor_Port_Const_Label = "Const";
     public static final String PropertyDescriptor_Port_Constp_Label = "Constp";

src/nl/tudelft/lime/constants/SystemSettings.java

     public static final String PropertyDescriptor_Port_Const_ID = "PortConstID";
     public static final String PropertyDescriptor_Port_Constp_ID = "PortConstpID";
     public static final String PropertyDescriptor_Location_ID = "LocationID";
+    public static final String PropertyDescriptor_Label_Context_ID = "LocationID";
     public static final String PropertyDescriptor_Port_Restrict_ID = "RestrictID";
     public static final String PropertyDescriptor_Port_Size_ID = "PortSizeID";
     public static final String PropertyDescriptor_Port_Static_ID = "StaticID";

src/nl/tudelft/lime/model/LimeLabel.java

 package nl.tudelft.lime.model;
 
+import java.io.IOException;
+
 import nl.tudelft.lime.constants.LimeMessages;
 import nl.tudelft.lime.constants.SystemSettings;
 
 import org.eclipse.draw2d.geometry.Dimension;
-
 import org.eclipse.swt.graphics.Image;
-
-import java.io.IOException;
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+import org.eclipse.ui.views.properties.TextPropertyDescriptor;
 
 
 public class LimeLabel extends LimeSubpart {
             SystemSettings.Label_Normal_Icon_Path);
     private static int count;
     private String text = LimeMessages.LimePlugin_Tool_CreationTool_LimeLabel;
+    public static final String Property_ID_Label_Context = SystemSettings.PropertyDescriptor_Label_Context_ID;
+    public static final String LABEL_DEFAULT_CONTEXT = "iterative";
+    private String context = LABEL_DEFAULT_CONTEXT;
+    protected static IPropertyDescriptor[] newDescriptors = null;
 
+    static {
+        PropertyDescriptor contextProp = new TextPropertyDescriptor(Property_ID_Label_Context,
+                LimeMessages.PropertyDescriptor_Label_Context_Label);
+
+        int length = 0;
+
+        if (descriptors != null) {
+            length = descriptors.length;
+        }
+
+        newDescriptors = new IPropertyDescriptor[length + 1];
+
+        //copy super properties
+        for (int i = 0; i < length; i++)
+            newDescriptors[i] = descriptors[i];
+
+        //add componentspecific properties
+        newDescriptors[length] = contextProp;
+    }
+    
+    public IPropertyDescriptor[] getPropertyDescriptors() {
+        return newDescriptors;
+    }
+    
     public LimeLabel() {
         super();
     }
     private void readObject(java.io.ObjectInputStream s)
         throws IOException, ClassNotFoundException {
         s.defaultReadObject();
+    
     }
-
+    /** (non-Javadoc)
+     * @see nl.tudelft.lime.model.LimeSubpart#setPropertyValue(java.lang.Object, java.lang.Object)
+     */
+    @Override
+    public void setPropertyValue(Object id, Object value) {
+        if (Property_ID_Label_Context.equals(id)) {
+            setContext((String) value);
+        } else {
+            super.setPropertyValue(id, value);
+        }
+    }
+    
+    public Object getPropertyValue(Object propName) {
+        if (Property_ID_Label_Context.equals(propName)) {
+            return getContext();
+        }
+        return super.getPropertyValue(propName);
+    }
+    
     public void setSize(Dimension d) {
         //d.height = -1;
         super.setSize(d);
     public String getDefaultName() {
         return LimeMessages.LimePlugin_Tool_CreationTool_LimeLabel;
     }
+
+	public String getContext() {
+		return context;
+	}
+
+	public void setContext(String context) {
+		this.context = context;
+	}
+    
 }

src/nl/tudelft/lime/model/commands/AddCommand.java

                 !(parent instanceof LimeComponent)) {
             return false;
         }
-
-        //and each component can at most have one label (code fragment)
-        if (child instanceof LimeLabel) {
-            List<LimeElement> children = parent.getChildren();
-
-            for (LimeElement child : children)
-                if (child instanceof LimeLabel) {
-                    return false;
-                }
-        }
-
         return true;
     }
 

src/nl/tudelft/lime/model/commands/CreateCommand.java

                 !(parent instanceof LimeComponent)) {
             return false;
         }
-
-        //and each component can at most have one label (code fragment)
-        if (child instanceof LimeLabel) {
-            List<LimeElement> children = parent.getChildren();
-
-            for (LimeElement child : children)
-                if (child instanceof LimeLabel) {
-                    return false;
-                }
-        }
-
         return true;
     }
 

src/nl/tudelft/lime/model/component/LimeComponent.java

 package nl.tudelft.lime.model.component;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import nl.tudelft.lime.constants.LimeMessages;
 import nl.tudelft.lime.constants.SystemSettings;
 import nl.tudelft.lime.model.LimeDiagram;
      * contents of that label
      * @return code fragment for a component
      */
-	public String getCodeFragment() {
+	public List<LimeLabel> getCodeFragments() {
+		List<LimeLabel> codeFragments = new ArrayList<LimeLabel>();
 		for (LimeElement child :children){
 			if (child instanceof LimeLabel){
-				return ((LimeLabel)child).getLabelContents();
+				codeFragments.add(((LimeLabel)child));
 			}
 		}
-		return "";
+		return codeFragments;
 	}
 }

src/nl/tudelft/lime/model/port/Port.java

     public static final String Property_ID_PORT_VOLATILE = SystemSettings.PropertyDescriptor_Port_Volatile_ID;
     public static final String Property_ID_PORT_VOLATILEP = SystemSettings.PropertyDescriptor_Port_VolatileP_ID;
     static final long serialVersionUID = 1;
-    public static final String PORT_SIZE_DEFAULT_VALUE = "1";
+    public static final String PORT_SIZE_DEFAULT_VALUE = "[1]";
     public static String CONNECTION_TERMINAL = "A"; //$NON-NLS-1$
                                                     //if you want to use another terminal for output
                                                     //public static String TERMINAL_B = "B"; //$NON-NLS-1$

src/nl/tudelft/lime/xml/XMLFactory.java

     private static final String DUMMY_INTER_ARCS_TAG = "dummyInterArcs";
     private static final String DUMMY_ASSOCIATIONS_TAG = "dummyAssociations";
     private static final String DUMMY_ROOT_ARCS_TAG = "dummy-root-arcs";
+    private static final String DUMMY_ROOT_ASSOCIATIONS_TAG = "dummy-root-associations";
 
     //hardcoded tags (TODO: they should be moved to SystemSettings) 
     private static final String XLINK_TYPE_ATTRIBUTE = "xlink:type";
     private static final String XLINK_HREF_ATTRIBUTE = "xlink:href";
     private static final String XLINK_TO_ATTRIBUTE = "to";
     private static final String XLINK_FROM_ATTRIBUTE = "from";
+    private static final String BOUND_TO_TAG = "bound-to";
     private static final String CODE_TAG = "code";
+    private static final String CONTEXT_ATTRIBUTE_TAG = "context";
     private static final String ENDPOINT_TAG = "endpoint";
     private static final String EDGE_TAG = "edge";
     private static final String EDGES_TAG = "edges";
 
                         if (fromElement != null) {
                             fromOutput = fromElement.elementText(ID_TAG) + ":" +
-                                fromElement.element(PORT_ID_TAG).getText();
+                                fromElement.elementText(PORT_ID_TAG);
                         } else {
                             fromElement = arcElement.element(FROM_TAG);
                             fromOutput = fromElement.element(NODE_TAG)
 
                         if (toElement != null) {
                             toInput = toElement.elementText(ID_TAG) + ":" +
-                                toElement.element(PORT_ID_TAG).getText();
+                                toElement.elementText(PORT_ID_TAG);
                         } else {
                             toElement = arcElement.element(TO_TAG);
                             toInput = toElement.element(NODE_TAG)
                     metaElement.attribute("id").getValue()
                                    .equals(META_TAG_CODE_ID)) {
                 //create a label and make it as a child of this component
-                LimeLabel codeFragment = new LimeLabel();
-                codeFragment.setLabelContents((String) metaElement.element(
-                        CODE_TAG).getData());
-                ((LimeComponent) subpart).addChild(codeFragment);
+                List<Element> codeElements = metaElement.elements(CODE_TAG);
+                
+                for (Element codeElement : codeElements){
+                    LimeLabel codeFragment = new LimeLabel();
+	                codeFragment.setLabelContents((String) codeElement.getData());
+	                codeFragment.setContext((String) codeElement.attributeValue(CONTEXT_ATTRIBUTE_TAG));
+	                ((LimeComponent) subpart).addChild(codeFragment);
+                }
             }
             //if it is an unknown tag
             else {
 
             //this variable is used to keep arcs and associations and add them when all the
             //child elements are added
-            Element rootArcsAndAssociations = new DefaultElement(DUMMY_ROOT_ARCS_TAG);
+            Element rootArcs = new DefaultElement(DUMMY_ROOT_ARCS_TAG);
+            Element rootAssociations = new DefaultElement(DUMMY_ROOT_ASSOCIATIONS_TAG);
             Element rootArcsToBePulledUp = new DefaultElement(DUMMY_INTRA_ARCS_TAG);
 
             for (LimeElement element : children) {
                     // but based on the XML examples, we have to keep it as this
                     // way
                     for (Element arc : (List<Element>) dummyArc.elements())
-                        rootArcsAndAssociations.add(arc.createCopy());
+                        rootArcs.add(arc.createCopy());
 
                     item.remove(dummyArc);
                 }
                     // but based on the XML samples of LIME, we have to treat them in this
                     // way
                     for (Element arc : (List<Element>) dummyAssociation.elements())
-                        rootArcsAndAssociations.add(arc.createCopy());
+                        rootAssociations.add(arc.createCopy());
 
                     item.remove(dummyAssociation);
                 }
             }
 
             //edges and associations should be added after all the child nodes are added
-
-            //first the edges
-            //and then the associations
-            if (rootArcsAndAssociations.elements().size() != 0) {
-                for (Element element : (List<Element>) rootArcsAndAssociations.elements()) {
-                    root.add(element.createCopy());
+            //first the associations - add the associations which correspond to this component
+            if (rootAssociations.elements().size() != 0) {
+                for (Element element : (List<Element>) rootAssociations.elements()) {
+                		root.add(element.createCopy());
                 }
-
-                rootArcsAndAssociations.clearContent();
+                rootAssociations.clearContent();
+            }
+            //second the edges - add the arcs which correspond to this component
+            if (rootArcs.elements().size() != 0) {
+            	Element edgesElement = new DefaultElement(EDGES_TAG);
+                for (Element element : (List<Element>) rootArcs.elements()) {
+                		edgesElement.add(element.createCopy());
+                }
+            	root.add(edgesElement);
+                rootArcs.clearContent();
             }
 
             if (rootArcsToBePulledUp.elements().size() != 0) {
             fromPortIdElement.setText(source.getRevisedName());
             fromNodeIdElement.setText(parentName);
 
-            fromNodeIdElement.add(fromPortIdElement);
+            fromElement.add(fromPortIdElement);
             fromElement.add(fromNodeIdElement);
 
             // II. adding 'to' node
             toPortIdElement.setText(target.getRevisedName());
             toNodeIdElement.setText(parentName);
 
-            toNodeIdElement.add(toPortIdElement);
+            toElement.add(toPortIdElement);
             toElement.add(toNodeIdElement);
 
             arcElement.add(fromElement);
         // <bound-to xlink:type='arc' xlink:from='w11a_r_source:in'
         // xlink:to='w11a_r_source:process:in'></bound-to>
         for (Association association : associations) {
-            Element associationElement = new DefaultElement("bound-to");
+            Element associationElement = new DefaultElement(BOUND_TO_TAG);
 
             associationElement.add(new DefaultAttribute(XLINK_TYPE_ATTRIBUTE,
                     "arc"));
     private static void addComponentAttributes(Element root,
         LimeComponent component) {
         //adding code fragment
-        String codeFragment = component.getCodeFragment();
+        List<LimeLabel> codeFragments = component.getCodeFragments();
 
-        if (!codeFragment.equals("")) {
-            DefaultElement metaCode = new DefaultElement(META_TAG);
-            metaCode.add(new DefaultAttribute("id", META_TAG_CODE_ID));
-
-            DefaultElement codeFragmentElement = new DefaultElement(CODE_TAG);
-            metaCode.add(codeFragmentElement);
-
-            codeFragmentElement.add(new DefaultCDATA(codeFragment));
-            root.add(metaCode);
+        if (codeFragments.size() != 0){
+        	for (LimeLabel codeFragment : codeFragments){
+	            DefaultElement metaCode = new DefaultElement(META_TAG);
+	            metaCode.add(new DefaultAttribute(ID_ATTRIBUTE, META_TAG_CODE_ID));
+	
+	            DefaultElement codeFragmentElement = new DefaultElement(CODE_TAG);
+	            metaCode.add(codeFragmentElement);
+	
+	            codeFragmentElement.add(new DefaultCDATA(codeFragment.getLabelContents()));
+	            codeFragmentElement.add(new DefaultAttribute(CONTEXT_ATTRIBUTE_TAG, codeFragment.getContext()));
+	            root.add(metaCode);
+        	}
         }
 
         //adding component return type