Commits

af08018  committed 7de04a4

instantiation is now supported

  • Participants
  • Parent commits 8516dea

Comments (0)

Files changed (18)

File src/messages.properties

 PropertyDescriptor_FIFO=FIFO
 PropertyDescriptor_LIFO=LIFO
 PropertyDescriptor_Size=Size
+PropertyDescriptor_Diagram_Instance_Only=Instance mode
+PropertyDescriptor_Boolean_False=False
+PropertyDescriptor_Boolean_True=True
+PropertyDescriptor_Component_Type_Label=Type
+PropertyDescriptor_Component_Ret_Label=Return type
+PropertyDescriptor_Component_InstanceOf_Label=Instance of
+PropertyDescriptor_Label_Context_Label=Context    
+PropertyDescriptor_Name_Label=Name
+PropertyDescriptor_Port_Const_Label=Const
+PropertyDescriptor_Port_Constp_Label=Constp
+PropertyDescriptor_Port_Restrict_Label=Restrict
+PropertyDescriptor_Port_Size_Label=Port Size
+PropertyDescriptor_Port_Static_Label=Static
+PropertyDescriptor_Port_Type_Label=Type
+PropertyDescriptor_Port_Volatile_Label=Volatile
+PropertyDescriptor_Port_VolatileP_Label=Volatilep
+XML_Format_Not_Correct=The XML file used doesn't have the correct format
 
 

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

 
 
 public class LimeMessages extends NLS {
-    public static String AddCommand_Label;
+	public static String AddCommand_Label;
     public static String AlignmentAction_AlignSubmenu_ActionLabelText;
     public static String CellEditorValidator_NotANumberMessage;
     public static String CloneCommand_Label;
     public static String PropertyDescriptor_Diagram_Manual;
     public static String PropertyDescriptor_Diagram_Manhattan;
     public static String PropertyDescriptor_Diagram_ShortestPath;
+	public static String PropertyDescriptor_Diagram_Instance_Only;
     public static String PropertyDescriptor_FIFO;
     public static String PropertyDescriptor_LIFO;
     public static String PropertyDescriptor_Size;
-    public static final String PropertyDescriptor_Boolean_False = "False";
-    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";
-    public static final String PropertyDescriptor_Port_Restrict_Label = "Restrict";
-    public static final String PropertyDescriptor_Port_Size_Label = "Port Size";
-    public static final String PropertyDescriptor_Port_Static_Label = "Static";
-    public static final String PropertyDescriptor_Port_Type_Label = "Type";
-    public static final String PropertyDescriptor_Port_Volatile_Label = "Volatile";
-    public static final String PropertyDescriptor_Port_VolatileP_Label = "Volatilep";
-    public static final String XML_Format_Not_Correct = "The XML file used doesn't have the correct format";
+    public static String PropertyDescriptor_Boolean_False;
+    public static String PropertyDescriptor_Boolean_True;
+    public static String PropertyDescriptor_Component_Type_Label;
+    public static String PropertyDescriptor_Component_Ret_Label;
+    public static String PropertyDescriptor_Component_InstanceOf_Label;
+    public static String PropertyDescriptor_Label_Context_Label;    
+    public static String PropertyDescriptor_Name_Label;
+    public static String PropertyDescriptor_Port_Const_Label;
+    public static String PropertyDescriptor_Port_Constp_Label;
+    public static String PropertyDescriptor_Port_Restrict_Label;
+    public static String PropertyDescriptor_Port_Size_Label;
+    public static String PropertyDescriptor_Port_Static_Label;
+    public static String PropertyDescriptor_Port_Type_Label;
+    public static String PropertyDescriptor_Port_Volatile_Label;
+    public static String PropertyDescriptor_Port_VolatileP_Label;
+    public static String XML_Format_Not_Correct;
 
     static {
         NLS.initializeMessages("messages", LimeMessages.class); //$NON-NLS-1$

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

   public static final String PropertyDescriptor_Port_Volatile_ID = "VolatileID";
   public static final String PropertyDescriptor_Port_VolatileP_ID = "VolatilepID";
   public static final String PropertyDescriptor_Size_ID = "SizeID";
+  public static final String PropertyDescriptor_Diagram_Only_Instances_ID = "OnlyInstancesID";
+  public static final String PropertyDescriptor_Component_InstanceOf_ID = "InstanceOfID";
 
   //Arcs which their endpoints (the two ports which are connected) are inside a component hierarchy are intra_arcs
   public static final String DUMMY_INTRA_ARCS_TAG = "dummyIntraArcs";
   public static final String DUMMY_ROOT_ARCS_TAG = "dummy-root-arcs";
   public static final String DUMMY_ROOT_ASSOCIATIONS_TAG = "dummy-root-associations";
 
+
   //hardcoded tags (TODO: they should be moved to SystemSettings) 
   public static String XLINK_TYPE_ATTRIBUTE;
   public static String XLINK_LABEL_ATTRIBUTE;
   public static String DIMENSION_TAG;
   public static String ID_ATTRIBUTE;
   public static String VALUE_ATTRIBUTE;
+  public static String RET_TAG;
+  public static String STEREOTYPE_TAG;
+
 
   public static String CODE_FRAGMENT_DEFAULT_CONTEXT;
   public static String ARC_DEFAULT_TYPE;
   public static String PORT_DEFAULT_SIZE;
   public static String GXF_TAG;
+  public static String CONSTP_TAG;
+  public static String RESTRICT_TAG;
+  public static String STATIC_TAG;
+  public static String VOLATILE_TAG;
+  public static String VOLATILEP_TAG;
+
   //Normal Icons Path
   public static String Component_Normal_Icon_Path;
   public static String Input_Port_Normal_Icon_Path;

File src/nl/tudelft/lime/edit/editpart/LimeContainerEditPart.java

 
     /**
      * Returns the children of this through the model.
-     *
+     * If LimeDiagram is set in its only instances mode only show components which are instances
+     * otherwise only show the classes
      * @return  Children of this as a List.
      */
     @SuppressWarnings("unchecked")

File src/nl/tudelft/lime/edit/editpart/LimeDiagramEditPart.java

 import nl.tudelft.lime.layout.DelegatingLayoutManager;
 import nl.tudelft.lime.layout.GraphAnimation;
 import nl.tudelft.lime.layout.GraphLayoutManager;
+import nl.tudelft.lime.model.LimeElement;
 import nl.tudelft.lime.model.LimeSubpart;
+import nl.tudelft.lime.model.component.LimeComponent;
 import nl.tudelft.lime.model.component.LimeDiagram;
 
 import org.eclipse.draw2d.Animation;
     }
 
     public void propertyChange(PropertyChangeEvent evt) {
-        if (LimeDiagram.ID_ROUTER.equals(evt.getPropertyName())) {
+        if (LimeDiagram.ID_ROUTER.equals(evt.getPropertyName()) ||
+        	LimeDiagram.Property_ID_DIAGRAM_ONLY_INSTANCES.equals(evt.getPropertyName())) {
             refreshVisuals();
         } else {
             super.propertyChange(evt);
         if ((getViewer().getControl().getStyle() & SWT.MIRRORED) == 0) {
             cLayer.setAntialias(SWT.ON);
         }
-
         if (getLimeDiagram().getConnectionRouter()
                     .equals(LimeDiagram.ROUTER_MANUAL)) {
             AutomaticRouter router = new FanRouter();
         }
 
         Animation.run(400);
+        refreshChildren();
     }
+    
+   
+    /**
+     * Returns the children of this through the model.
+     * If LimeDiagram is set in its only instances mode only show components which are instances
+     * otherwise only show the classes
+     * @return  Children of this as a List.
+     */
+    @SuppressWarnings("unchecked")
+    protected List getModelChildren() {
+    	List<LimeElement> children = getLimeDiagram().getChildren();
+    	List<LimeElement> filteredChildren = new ArrayList<LimeElement>();
+    	boolean onlyInstances = getLimeDiagram().showOnlyInstances() == 1;
+    	for (LimeElement child : children){
+    		//if it is a component but is it is different than the diagram must show hide it
+    		if (!(child instanceof LimeComponent)
+    			|| (onlyInstances == ((LimeComponent) child).isInstance()))
+    			filteredChildren.add(child);
+    	}
+        return filteredChildren;
+    }        
 }

File src/nl/tudelft/lime/edit/policy/ContainerHighlightEditPolicy.java

 package nl.tudelft.lime.edit.policy;
 
 import nl.tudelft.lime.edit.editpart.ComponentEditPart;
-import nl.tudelft.lime.figures.LimeColorConstants;
+import nl.tudelft.lime.figures.LimeConstants;
 
 import org.eclipse.draw2d.IFigure;
 import org.eclipse.gef.EditPart;
     protected void showHighlight() {
         if (revertColor == null) {
             revertColor = getContainerBackground();
-            setContainerBackground(LimeColorConstants.componentWhenHighlighted);
+            setContainerBackground(LimeConstants.componentWhenHighlighted);
         }
     }
 

File src/nl/tudelft/lime/edit/policy/LimeXYLayoutEditPolicy.java

 
 import nl.tudelft.lime.constants.LimeMessages;
 import nl.tudelft.lime.edit.editpart.LimeCodeFragmentEditPart;
-import nl.tudelft.lime.figures.LimeColorConstants;
+import nl.tudelft.lime.figures.LimeConstants;
 import nl.tudelft.lime.figures.codefragment.CodeFragmentFigure;
 import nl.tudelft.lime.figures.component.ComponentFigure;
 import nl.tudelft.lime.model.LimeGuide;
             figure = new RectangleFigure();
             ((RectangleFigure) figure).setXOR(true);
             ((RectangleFigure) figure).setFill(true);
-            figure.setBackgroundColor(LimeColorConstants.ghostFillColor);
+            figure.setBackgroundColor(LimeConstants.ghostFillColor);
             figure.setForegroundColor(ColorConstants.white);
         }
 

File src/nl/tudelft/lime/edit/policy/WhileDraggingEditPolicy.java

 
 import java.util.List;
 
-import nl.tudelft.lime.figures.LimeColorConstants;
+import nl.tudelft.lime.figures.LimeConstants;
 import nl.tudelft.lime.figures.NodeFigure;
 import nl.tudelft.lime.figures.codefragment.CodeFragmentFigure;
 import nl.tudelft.lime.figures.component.ComponentFigure;
             figure = new RectangleFigure();
             ((RectangleFigure) figure).setXOR(true);
             ((RectangleFigure) figure).setFill(true);
-            figure.setBackgroundColor(LimeColorConstants.ghostFillColor);
+            figure.setBackgroundColor(LimeConstants.ghostFillColor);
             figure.setForegroundColor(ColorConstants.white);
         }
 

File src/nl/tudelft/lime/figures/LimeColorConstants.java

-package nl.tudelft.lime.figures;
-
-import org.eclipse.swt.graphics.Color;
-
-
-public interface LimeColorConstants {
-    public final static Color outputPort = new Color(null, 255, 125, 00);
-    public final static Color inputPort = new Color(null, 188, 221, 90);
-    public final static Color componentBorder = new Color(null, 123, 174, 148);
-    public final static Color componentWhenHighlighted = new Color(null, 210,
-            210, 210);
-    public final static Color connectorGreen = new Color(null, 0, 69, 40);
-    public final static Color limeBackgroundBlue = new Color(null, 200, 200, 240);
-    public final static Color black = new Color(null, 0, 0, 0);
-    public final static Color ghostFillColor = new Color(null, 31, 31, 31);
-}

File src/nl/tudelft/lime/figures/LimeConstants.java

+package nl.tudelft.lime.figures;
+
+import nl.tudelft.lime.constants.LimeMessages;
+
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Color;
+
+
+public interface LimeConstants {
+    public final static Color outputPort = new Color(null, 255, 125, 00);
+    public final static Color inputPort = new Color(null, 188, 221, 90);
+    public final static Color componentBorder = new Color(null, 123, 174, 148);
+    public final static Color componentWhenHighlighted = new Color(null, 210,
+            210, 210);
+    public final static Color connectorGreen = new Color(null, 0, 69, 40);
+    public final static Color limeBackgroundBlue = new Color(null, 200, 200, 240);
+    public final static Color black = new Color(null, 0, 0, 0);
+    public final static Color ghostFillColor = new Color(null, 31, 31, 31);
+    public final static String[] booleanTypes = {
+        LimeMessages.PropertyDescriptor_Boolean_False,
+        LimeMessages.PropertyDescriptor_Boolean_True
+    };
+    /**
+     * This is a label provider for the type of the arc
+     * @author mazaninfardi
+     *
+     */
+    public class BooleanTypeLabelProvider extends LabelProvider {
+        public BooleanTypeLabelProvider() {
+            super();
+        }
+
+        public String getText(Object element) {
+            if (element instanceof Integer) {
+                Integer integer = (Integer) element;
+
+                if (integer < booleanTypes.length) {
+                    return booleanTypes[integer];
+                }
+            }
+
+            return super.getText(element);
+        }
+    }
+
+}

File src/nl/tudelft/lime/figures/port/InputPortFigure.java

 package nl.tudelft.lime.figures.port;
 
 import nl.tudelft.lime.figures.FigureUtility;
-import nl.tudelft.lime.figures.LimeColorConstants;
+import nl.tudelft.lime.figures.LimeConstants;
 import nl.tudelft.lime.model.port.Port;
 
 import org.eclipse.draw2d.ChopboxAnchor;
         inputConnectionAnchors.addElement(anchor);
         outputConnectionAnchors.addElement(anchor);
         connectionAnchors.put(Port.CONNECTION_TERMINAL, anchor);
-        setBackgroundColor(LimeColorConstants.inputPort);
+        setBackgroundColor(LimeConstants.inputPort);
     }
 
     /**
             g.setAlpha(150);
         }
 
-        g.setBackgroundColor(LimeColorConstants.inputPort);
+        g.setBackgroundColor(LimeConstants.inputPort);
 
         Rectangle r = getBounds().getCopy();
 

File src/nl/tudelft/lime/figures/port/OutputPortFigure.java

 package nl.tudelft.lime.figures.port;
 
 import nl.tudelft.lime.figures.FigureUtility;
-import nl.tudelft.lime.figures.LimeColorConstants;
+import nl.tudelft.lime.figures.LimeConstants;
 import nl.tudelft.lime.model.port.Port;
 
 import org.eclipse.draw2d.EllipseAnchor;
             g.setAlpha(150);
         }
 
-        g.setBackgroundColor(LimeColorConstants.outputPort);
+        g.setBackgroundColor(LimeConstants.outputPort);
 
         g.fillOval(r);
         r.height--;

File src/nl/tudelft/lime/model/LimeSubpart.java

 import nl.tudelft.lime.constants.SystemSettings;
 import nl.tudelft.lime.model.common.DimensionPropertySource;
 import nl.tudelft.lime.model.common.LocationPropertySource;
+import nl.tudelft.lime.model.component.LimeComponent;
 import nl.tudelft.lime.model.component.LimeDiagram;
 import nl.tudelft.lime.model.connection.Arc;
 import nl.tudelft.lime.model.connection.Association;
     public LimeSubpart getParent() {
         return this.parent;
     }
+
 }

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

 import nl.tudelft.lime.constants.LimeMessages;
 import nl.tudelft.lime.constants.SystemSettings;
 import nl.tudelft.lime.model.LimeElement;
+import nl.tudelft.lime.model.LimeSubpart;
 import nl.tudelft.lime.model.codefragment.LimeCodeFragment;
 
 import org.eclipse.ui.views.properties.IPropertyDescriptor;
     public static String TERMINALS_IN = "2";
     public static final String Property_ID_Component_Type = SystemSettings.PropertyDescriptor_Component_Type_ID;
     public static final String Property_ID_Component_Ret = SystemSettings.PropertyDescriptor_Component_Ret_ID;
+    public static final String Property_ID_Component_InstanceOf = SystemSettings.PropertyDescriptor_Component_InstanceOf_ID;
     private static final String DEFAULT_NAME = LimeMessages.Component_LabelText;
-    protected static IPropertyDescriptor[] newDescriptors = null;
-    //nodes can have embedded code, it can be either editable by the visual part or not
-//    private String embeddedCode = "";
+    protected static IPropertyDescriptor[] normalDescriptors = null;
+    protected static IPropertyDescriptor[] instanceDescriptors = null;
+    private boolean instance;
+    private String componentRet = "";
+    private String componentClass = "";
+    private List<LimeComponent> instances = new ArrayList<LimeComponent>();
+    
 
-
-    static {
+	static {
         PropertyDescriptor componentTypeProp = new TextPropertyDescriptor(Property_ID_Component_Type,
                 LimeMessages.PropertyDescriptor_Component_Type_Label);
 
         PropertyDescriptor componentRetProp = new TextPropertyDescriptor(Property_ID_Component_Ret,
                 LimeMessages.PropertyDescriptor_Component_Ret_Label);
 
+        PropertyDescriptor instanceOfProp = new TextPropertyDescriptor(Property_ID_Component_InstanceOf,
+                LimeMessages.PropertyDescriptor_Component_InstanceOf_Label);
+
         IPropertyDescriptor[] componentDescriptors = new PropertyDescriptor[] {
                 componentTypeProp, componentRetProp
             };
             length = descriptors.length;
         }
 
-        newDescriptors = new IPropertyDescriptor[length +
-            componentDescriptors.length];
+        int normalDescriptorsLength = length + componentDescriptors.length;
 
+        normalDescriptors = new IPropertyDescriptor[normalDescriptorsLength];
+        instanceDescriptors = new IPropertyDescriptor[normalDescriptorsLength + 1];
         //copy super properties
         for (int i = 0; i < length; i++)
-            newDescriptors[i] = descriptors[i];
+            normalDescriptors[i] = descriptors[i];
 
-        //add componentspecific properties
+        //add component specific properties 
         for (int i = 0; i < componentDescriptors.length; i++) {
-            newDescriptors[length + i] = componentDescriptors[i];
+            normalDescriptors[length + i] = componentDescriptors[i];
         }
+        //copy them for instances as well and add instanceOf property
+        for (int i = 0; i < normalDescriptors.length; i++){
+        	instanceDescriptors[i] = normalDescriptors[i];
+        }
+        instanceDescriptors[normalDescriptors.length] = instanceOfProp; 
     }
+	
+    /**
+     * If it is an instance which component is its parent
+     * @return
+     */
+	public String getComponentClass() {
+		return componentClass;
+	}
 
-    private String componentRet = "";
+	public void setComponentClass(String componentClassString) {
+		this.componentClass = componentClassString;
+    	LimeComponent realComponentClass = findComponentClass(componentClassString);
+    	if (realComponentClass != null){
+    		this.children = realComponentClass.getChildren();
+    		realComponentClass.addToInstances(this);
+//    		for (int i = 0; i < this.children.size(); i ++)
+//    			fireChildAdded(CHILDREN, this.children.get(i), new Integer(i));
+    	}
+        firePropertyChange(Property_ID_Component_InstanceOf, null, realComponentClass);
+		
+	}
+	
+
+    /**
+     * Components can be both instances and classes (in LIME definition not Java definition of class and instance)
+     * if it is an instance it can only be added to a diagram in its instance mode 
+     * @return if the component is an instance indeed
+     */
+    public boolean isInstance() {
+		return instance;
+	}
+
+    /**
+     * Components can be both instances and classes (in LIME definition not Java definition of class and instance)
+     * if it is an instance it can only be added to a diagram in its instance mode
+     * @param instance whether it is an instance or not 
+     */
+	public void setInstance(boolean instance) {
+		this.instance = instance;
+	}
+
+
 
     /**
      * TODO: remove this method, I don't exactly know when this one should be called
             return getType();
         } else if (Property_ID_Component_Ret.equals(propName)) {
             return componentRet;
+        } else if (Property_ID_Component_InstanceOf.equals(propName)) {
+            return getComponentClass();
         }
 
         return super.getPropertyValue(propName);
             setComponentRet((String) value);
         } else if (Property_ID_Component_Type.equals(id)) {
             setType((String) value);
-        } else {
+        } else if (Property_ID_Component_InstanceOf.equals(id)) {
+        	//find its parent and set its children
+        	setComponentClass((String)value);
+        }  
+        else {
             super.setPropertyValue(id, value);
         }
     }
+    /**
+     * adds a component to instances of this class... this is used when :
+     * a component class is deleted and all its instances should also be deleted
+     * !!!currently we don't do that because if class is deleted there is no reason to delete
+     * its children!!! but it is possible 
+     * @param limeComponent
+     */
+    private void addToInstances(LimeComponent limeComponent) {
+    	//this method is used if something special should be done
+    	instances.add(limeComponent);
+	}
 
-    public IPropertyDescriptor[] getPropertyDescriptors() {
-        return newDescriptors;
+	private LimeComponent findComponentClass(String componentName) {
+    	LimeSubpart diagram = this;
+    	while (diagram.getParent() != null)
+    		diagram = diagram.getParent();
+    	//when it is the diagram look at its dicitonary if you can find the component
+    	if (!(diagram instanceof LimeDiagram))
+    		return null;
+    	else 
+    		return ((LimeDiagram)diagram).getComponentForName(componentName);
+	}
+
+	public IPropertyDescriptor[] getPropertyDescriptors() {
+    	//if it is an instance then an additional field should be shown
+    	if (isInstance())
+    		return instanceDescriptors; 
+    	else
+    		return normalDescriptors;
     }
 
     @Override
 		}
 		return codeFragments;
 	}
+
+	/**
+	 * This method is needed for further XML configuration
+	 * @param text
+	 */
+	public void setComponentClassText(String text) {
+		this.componentClass = text;
+	}
 }

File src/nl/tudelft/lime/model/component/LimeDiagram.java

 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import nl.tudelft.lime.constants.LimeMessages;
 import nl.tudelft.lime.constants.SystemSettings;
+import nl.tudelft.lime.figures.LimeConstants;
 import nl.tudelft.lime.model.LimeElement;
 import nl.tudelft.lime.model.LimeRuler;
 import nl.tudelft.lime.model.LimeSubpart;
 import org.eclipse.ui.views.properties.IPropertyDescriptor;
 
 
-public class LimeDiagram extends LimeSubpart {
+public class LimeDiagram extends LimeSubpart implements LimeConstants{
     static final long serialVersionUID = 1;
     public static String ID_ROUTER = "router"; //$NON-NLS-1$
     public static Integer ROUTER_MANUAL = new Integer(0);
     public static Integer ROUTER_MANHATTAN = new Integer(1);
     public static Integer ROUTER_SHORTEST_PATH = new Integer(2);
     private static int count;
+    public static final String Property_ID_DIAGRAM_ONLY_INSTANCES = SystemSettings.PropertyDescriptor_Diagram_Only_Instances_ID;
+
     private static Image Lime_ICON = createImage(LimeDiagram.class,
             SystemSettings.Component_Normal_Icon_Path); //$NON-NLS-1$
     protected List<LimeElement> children = new ArrayList<LimeElement>();
     private boolean snapToGeometry = false;
     private boolean gridEnabled = false;
     private double zoom = 1.0;
+    //in the default mode only instances should be visible
+    private Integer onlyInstances = 0;
+    private Map<String, LimeComponent> componentClassDictionary = new HashMap<String, LimeComponent>(); 
+
+    
+    public Integer showOnlyInstances() {
+		return onlyInstances;
+	}
+
+	public void setOnlyInstances(Integer onlyInstances) {
+		Integer oldOnlyInstances = this.onlyInstances;
+		this.onlyInstances = onlyInstances;
+        firePropertyChange(Property_ID_DIAGRAM_ONLY_INSTANCES, oldOnlyInstances, onlyInstances);
+	}
 
     public LimeDiagram() {
         size = new Dimension(-1, -1);
         addChild(child, -1);
     }
 
+    /**
+     * If the element is going to be added via the visual editor it is a bit tricky to put it
+     * in the correct category.
+     * this method resolved this problem
+     * @param child
+     * @param isInstance
+     */
+    public void addChild(LimeElement child, boolean isInstance){
+    	this.onlyInstances = isInstance?1:0;
+    	addChild(child);
+    }
+    
     public void addChild(LimeElement child, int index) {
+    	//if diagram is in onlyInstances mode set its children property to 
+    	//instance mode
+    	if (child instanceof LimeComponent){
+    		((LimeComponent) child).setInstance(this.onlyInstances == 1);
+    		//if it is a component class then add it to dictionary
+    		if (this.onlyInstances != 1 && this.getClass().getSimpleName().equals(LimeDiagram.class.getSimpleName())){
+    			componentClassDictionary.put(((LimeComponent)child).getName(), (LimeComponent)child);
+    		}
+    	}
+    		
         if (index >= 0) {
             children.add(index, child);
         } else {
         return zoom;
     }
 
+    
     /**
      * Returns <code>null</code> for this model. Returns
      * normal descriptors for all subclasses.
                     });
             cbd.setLabelProvider(new ConnectionRouterLabelProvider());
 
-            return new IPropertyDescriptor[] { cbd };
+            ComboBoxPropertyDescriptor showInstanceProp = new ComboBoxPropertyDescriptor(Property_ID_DIAGRAM_ONLY_INSTANCES,
+                    LimeMessages.PropertyDescriptor_Diagram_Instance_Only,
+                    booleanTypes);
+            showInstanceProp.setLabelProvider(new BooleanTypeLabelProvider());
+
+            
+            return new IPropertyDescriptor[] { cbd , showInstanceProp};
         }
 
         return super.getPropertyDescriptors();
     }
 
     public Object getPropertyValue(Object propName) {
-        if (propName.equals(ID_ROUTER)) {
+        if (Property_ID_DIAGRAM_ONLY_INSTANCES.equals(propName)) {
+            return onlyInstances;
+        }
+        else if (propName.equals(ID_ROUTER)) {
             return connectionRouter;
         }
 
     }
 
     public void setPropertyValue(Object id, Object value) {
-        if (ID_ROUTER.equals(id)) {
+        if (Property_ID_DIAGRAM_ONLY_INSTANCES.equals(id)) {
+            setOnlyInstances((Integer) value);
+        }
+        else if (ID_ROUTER.equals(id)) {
             setConnectionRouter((Integer) value);
         } else {
             super.setPropertyValue(id, value);
             return super.getText(element);
         }
     }
+
+	public LimeComponent getComponentForName(String componentName) {
+		return componentClassDictionary.get(componentName);
+	}
 }

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

 
 import nl.tudelft.lime.constants.LimeMessages;
 import nl.tudelft.lime.constants.SystemSettings;
+import nl.tudelft.lime.figures.LimeConstants;
 import nl.tudelft.lime.model.LimeSubpart;
 import nl.tudelft.lime.model.connection.Arc;
 
-import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
 import org.eclipse.ui.views.properties.IPropertyDescriptor;
 import org.eclipse.ui.views.properties.PropertyDescriptor;
  * @author af08018
  *
  */
-public abstract class Port extends LimeSubpart {
+public abstract class Port extends LimeSubpart implements LimeConstants{
     //we define IDs as locals because they are used in several places
     public static final Integer FALSE = 0;
     public static final Integer TRUE = 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$
-    protected static String[] booleanTypes = {
-            LimeMessages.PropertyDescriptor_Boolean_False,
-            LimeMessages.PropertyDescriptor_Boolean_True
-        };
+
     protected static IPropertyDescriptor[] newDescriptors = null;
 
     //aditiional fields for the port
      * @param portSize the portSize to set, it can be a number or a variable
      */
     public void setPortSize(String portSize) {
-        if (portSize.charAt(0) == ' ') {
-            portSize = portSize.substring(1);
-        }
-
-        if (portSize.charAt(portSize.length() - 1) == ' ') {
-            portSize = portSize.substring(0, portSize.length() - 1);
-        }
-
-        if ((portSize.charAt(0) == '[') &&
-                (portSize.charAt(portSize.length() - 1) == ']')) {
-            this.portSize = portSize;
-        } else {
-            this.portSize = "[" + portSize.replaceAll("\\s+", "][") + "]";
-        }
+    	if (portSize == null || portSize.length() == 0)
+    		this.portSize = "";
+    	else{
+	    	if ((portSize.charAt(0) == '[') &&
+	                (portSize.charAt(portSize.length() - 1) == ']')) {
+	            this.portSize = portSize;
+	        } else {
+	            this.portSize = "[" + portSize.replaceAll("\\s+", "][") + "]";
+	        }
+    	}
 
         firePropertyChange(Property_ID_PORT_SIZE, null, portSize);
     }
             this.portVolatilep);
     }
 
-    /**
-     * This is a label provider for the type of the arc
-     * @author mazaninfardi
-     *
-     */
-    private class BooleanTypeLabelProvider extends LabelProvider {
-        public BooleanTypeLabelProvider() {
-            super();
-        }
-
-        public String getText(Object element) {
-            if (element instanceof Integer) {
-                Integer integer = (Integer) element;
-
-                if (integer < booleanTypes.length) {
-                    return booleanTypes[integer];
-                }
-            }
-
-            return super.getText(element);
-        }
-    }
     public static String TERMINAL_OUT = "OUT"; //$NON-NLS-1$
 
     public void removeOutput(Arc w) {

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

                     // add parent child relationship to the items
                     LimeSubpart childSubpart = getDiagram(child);
                     childSubpart.setParent((LimeDiagram) subpart);
-                    ((LimeDiagram) subpart).addChild(childSubpart);
+                    boolean isComponentInstance = (childSubpart instanceof LimeComponent) && ((LimeComponent)childSubpart).isInstance(); 
+                	((LimeDiagram) subpart).addChild(childSubpart, isComponentInstance);
+                	if (isComponentInstance){
+                		//this is needed to refresh
+                		LimeComponent component = (LimeComponent) childSubpart;
+                		component.setComponentClass(component.getComponentClass());
+                	}
+
                 }
 
                 //for port children just add them
     private static void createComponentFromXML(LimeComponent limeComponent,
         Element element) {
         for (Element subElement : (List<Element>) element.elements()) {
-            if (subElement.getName().equals("type")) {
+            if (subElement.getName().equals(SystemSettings.TYPE_TAG)) {
                 limeComponent.setType(subElement.getText());
-            } else if (subElement.getName().equals("ret")) {
+            } else if (subElement.getName().equals(SystemSettings.RET_TAG)) {
                 limeComponent.setComponentRet(subElement.getText());
+            } else if (subElement.getName().equals(SystemSettings.STEREOTYPE_TAG)){
+            	limeComponent.setInstance(true);
+            	//do not set component here, still it is not added to its parent
+            	//we need its parent to find the diagram and find corresponding elemnt
+            	limeComponent.setComponentClassText(subElement.getText());
             }
         }
     }
      */
     @SuppressWarnings("unchecked")
     private static String createPortFromXML(Port port, Element element) {
+    	port.setPortSize("");
         for (Element subElement : (List<Element>) element.elements()) {
             if (subElement.getName().equals(SystemSettings.TYPE_TAG)) {
                 //two cases happen here based on the definition of LIME
                 else {
                     port.setType(subElement.getStringValue());
                 }
-            } else if (subElement.getName().equals("constp")) {
+            } else if (subElement.getName().equals(SystemSettings.CONSTP_TAG)) {
                 port.setPortConstp(Port.TRUE);
-            } else if (subElement.getName().equals("restrict")) {
+            } else if (subElement.getName().equals(SystemSettings.RESTRICT_TAG)) {
                 port.setPortRestrict(Port.TRUE);
-            } else if (subElement.getName().equals("static")) {
+            } else if (subElement.getName().equals(SystemSettings.STATIC_TAG)) {
                 port.setPortStatic(Port.TRUE);
             }
             //if size is not defined it is set as default
             else if (subElement.getName().equals(SystemSettings.SIZE_TAG)) {
-                String elementSize = subElement.getText();
-
-                if (elementSize.startsWith("(") && elementSize.endsWith(")")) {
-                    elementSize = elementSize.substring(1,
-                            elementSize.length() - 1);
-                }
-
-                port.setPortSize(elementSize);
-            } else if (subElement.getName().equals("volatile")) {
+                String elementSize = "[" + subElement.getText()+ "]";
+                //append the text to the other elements
+                port.setPortSize(port.getPortSize() + elementSize);
+            } else if (subElement.getName().equals(SystemSettings.VOLATILE_TAG)) {
                 port.setPortVolatile(Port.TRUE);
-            } else if (subElement.getName().equals("volatilep")) {
+            } else if (subElement.getName().equals(SystemSettings.VOLATILEP_TAG)) {
                 port.setPortVolatilep(Port.TRUE);
             } else if (!isNormalPortTag(subElement.getName())) {
                 port.getPreservedXMLElements().add(subElement.createCopy());
         }
 
         // making portsize acceptable for LIME compiler
-        String portSizeText = port.getPortSize().replaceAll("[\\[\\]]+", " ");
+        String portSizeText = port.getPortSize();
 
-        if (portSizeText.length() != 0) {
-            if (portSizeText.charAt(0) == ' ') {
-                portSizeText = portSizeText.substring(1);
-            }
-
-            if (portSizeText.charAt(portSizeText.length() - 1) == ' ') {
-                portSizeText = portSizeText.substring(0,
-                        portSizeText.length() - 1);
-            }
-
-            if (portSizeText.indexOf(" ") != -1) {
-                portSizeText = "(" + portSizeText + ")";
-            }
+        //ignore the first bracket otherwise it would be treated wrong
+        String[] sizes = portSizeText.substring(1).split("[\\[|\\]]+");
+        for (String size : sizes){
+            root.add(createTextElement(SystemSettings.SIZE_TAG, size));
+        	
         }
-
-        root.add(createTextElement("size", portSizeText));
+//        if (portSizeText.length() != 0) {
+//            if (portSizeText.charAt(0) == ' ') {
+//                portSizeText = portSizeText.substring(1);
+//            }
+//
+//            if (portSizeText.charAt(portSizeText.length() - 1) == ' ') {
+//                portSizeText = portSizeText.substring(0,
+//                        portSizeText.length() - 1);
+//            }
+//
+//            if (portSizeText.indexOf(" ") != -1) {
+//                portSizeText = "(" + portSizeText + ")";
+//            }
+//        }
 
         if (port.getPortConstp()) {
-            root.add(createTextElement("constp", ""));
+            root.add(createTextElement(SystemSettings.CONSTP_TAG, ""));
         }
 
         if (port.getPortRestrict()) {
-            root.add(createTextElement("restrict", ""));
+            root.add(createTextElement(SystemSettings.RESTRICT_TAG, ""));
         }
 
         if (port.getPortStatic()) {
-            root.add(createTextElement("static", ""));
+            root.add(createTextElement(SystemSettings.STATIC_TAG, ""));
         }
 
         if (port.getPortVolatile()) {
-            root.add(createTextElement("volatile", ""));
+            root.add(createTextElement(SystemSettings.VOLATILE_TAG, ""));
         }
 
         if (port.getPortVolatilep()) {
-            root.add(createTextElement("volatilep", ""));
+            root.add(createTextElement(SystemSettings.VOLATILEP_TAG, ""));
         }
     }
 
      */
     private static void addComponentAttributes(Element root,
         LimeComponent component) {
-        //adding code fragment
-        List<LimeCodeFragment> codeFragments = component.getCodeFragments();
-
-        if (codeFragments.size() != 0){
-        	for (LimeCodeFragment codeFragment : codeFragments){
-	            DefaultElement metaCode = new DefaultElement(SystemSettings.META_TAG);
-	            metaCode.add(new DefaultAttribute(SystemSettings.ID_ATTRIBUTE, SystemSettings.META_TAG_CODE_ID));
+    	//if it is an instance component just create simple node infos
+    	//<node xlink:type="resource" id="copy1" xlink:label="copy1"><id>copy1</id>
+    	//<stereo-type>copy</stereo-type>
+    	//</node>
+    	if (component.isInstance()){
+    		root.add(createTextElement(SystemSettings.STEREOTYPE_TAG, component.getComponentClass()));
+    	}
+    	else{
+	    	//adding code fragment
+	        List<LimeCodeFragment> codeFragments = component.getCodeFragments();
 	
-	            DefaultElement codeFragmentElement = new DefaultElement(SystemSettings.CODE_TAG);
-	            metaCode.add(codeFragmentElement);
+	        if (codeFragments.size() != 0){
+	        	for (LimeCodeFragment codeFragment : codeFragments){
+		            DefaultElement metaCode = new DefaultElement(SystemSettings.META_TAG);
+		            metaCode.add(new DefaultAttribute(SystemSettings.ID_ATTRIBUTE, SystemSettings.META_TAG_CODE_ID));
+		
+		            DefaultElement codeFragmentElement = new DefaultElement(SystemSettings.CODE_TAG);
+		            metaCode.add(codeFragmentElement);
+		
+		            codeFragmentElement.add(new DefaultCDATA(codeFragment.getLabelContents()));
+		            codeFragmentElement.add(new DefaultAttribute(SystemSettings.CONTEXT_TAG, codeFragment.getContext()));
+		            
+		            //add location and size
+		            DefaultElement metaVisual = new DefaultElement(SystemSettings.META_TAG);
+		            metaVisual.add(new DefaultAttribute(SystemSettings.ID_ATTRIBUTE, SystemSettings.META_TAG_VISUAL_ID));
+		            metaVisual.add(createDimensionList(SystemSettings.SIZE_TAG, codeFragment.getSizeMap()));
+		            metaVisual.add(createDimensionList(SystemSettings.LOCATION_TAG,
+		                    codeFragment.getLocationMap()));
 	
-	            codeFragmentElement.add(new DefaultCDATA(codeFragment.getLabelContents()));
-	            codeFragmentElement.add(new DefaultAttribute(SystemSettings.CONTEXT_TAG, codeFragment.getContext()));
-	            
-	            //add location and size
-	            DefaultElement metaVisual = new DefaultElement(SystemSettings.META_TAG);
-	            metaVisual.add(new DefaultAttribute(SystemSettings.ID_ATTRIBUTE, SystemSettings.META_TAG_VISUAL_ID));
-	            metaVisual.add(createDimensionList(SystemSettings.SIZE_TAG, codeFragment.getSizeMap()));
-	            metaVisual.add(createDimensionList(SystemSettings.LOCATION_TAG,
-	                    codeFragment.getLocationMap()));
-
-	            codeFragmentElement.add(metaVisual);
-
-	            root.add(metaCode);
-        	}
-        }
-
-        //adding component return type
-        DefaultElement componentRet = createTextElement("ret",
-                component.getComponentRet());
-
-        if (componentRet != null) {
-            root.add(componentRet);
-        }
+		            codeFragmentElement.add(metaVisual);
+	
+		            root.add(metaCode);
+	        	}
+	        }
+	
+	        //adding component return type
+	        DefaultElement componentRet = createTextElement(SystemSettings.RET_TAG,
+	                component.getComponentRet());
+	
+	        if (componentRet != null) {
+	            root.add(componentRet);
+	        }
+    	}
     }
 
     /**

File src/system.properties

 XLINK_FROM_ATTRIBUTE=from
 BOUND_TO_TAG=bound-to
 CODE_TAG=code
+CONSTP_TAG=constp
 CONTEXT_TAG=context
+DIMENSION_TAG=dimension
+EDGE_TAG=edge
+EDGES_TAG=stream
 ENDPOINT_TAG=endpoint
-EDGE_TAG=edge
-EDGES_TAG=edges
-TYPE_TAG=type
+FROM_TAG=from
+FROM_NODE_TAG=from-node
+GXF_TAG=gxf
+GXF_URL=http\://bitbucket.org/pjotr/lime/raw/tip/doc/gxf.dtd
+ID_ATTRIBUTE=id
+ID_TAG=id
+LOCATION_TAG=location
 META_TAG=meta
-NODE_TAG=node
-PORT_TAG=port
-GXF_URL=http\://bitbucket.org/pjotr/lime/raw/tip/doc/gxf.dtd
-ID_TAG=id
-TO_TAG=to
-FROM_TAG=from
-TO_NODE_TAG=to-node
-FROM_NODE_TAG=from-node
-PORT_ID_TAG=port-id
 META_TAG_VISUAL_ID=visual
 META_TAG_CODE_ID=passthrough
+NODE_TAG=node
+PORT_ID_TAG=port-id
+PORT_TAG=port
+RESTRICT_TAG=restrict
+RET_TAG=ret
 SIZE_TAG=size
-LOCATION_TAG=location
-DIMENSION_TAG=dimension
-GXF_TAG=gxf
-ID_ATTRIBUTE=id
+STATIC_TAG=static
+STEREOTYPE_TAG=stereo-type
+TO_TAG=to
+TO_NODE_TAG=to-node
+TYPE_TAG=type
 VALUE_ATTRIBUTE=value
+VOLATILE_TAG=volatile
+VOLATILEP_TAG=volatilep
+
 #Normal Icons Path
 Component_Normal_Icon_Path=/modelicons/normal/component.gif
 Input_Port_Normal_Icon_Path=/modelicons/normal/input.gif