Commits

Anonymous committed 934bb2d

supporting instantiation (almost complete) associations are not copied correctly

  • Participants
  • Parent commits 7de04a4

Comments (0)

Files changed (8)

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

 import org.eclipse.ui.views.properties.IPropertySource;
 
 
-abstract public class LimeElement implements IPropertySource, Cloneable,
+public class LimeElement implements IPropertySource, Cloneable,
     Serializable {
     public static final String BOUNDS = "BOUNDS"; //$NON-NLS-1$
     public static final String CHILDREN = "Children"; //$NON-NLS-1$
 
     public void update() {
     }
+    /**
+     * Concrete models should write their own copy functions
+     * @return
+     */
+    public LimeSubpart getCopy(){
+    	return null;
+    }
 }

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;
         return this.parent;
     }
 
+    
 }

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

 import nl.tudelft.lime.model.LimeElement;
 import nl.tudelft.lime.model.LimeSubpart;
 import nl.tudelft.lime.model.codefragment.LimeCodeFragment;
+import nl.tudelft.lime.model.connection.Association;
 
 import org.eclipse.ui.views.properties.IPropertyDescriptor;
 import org.eclipse.ui.views.properties.PropertyDescriptor;
 		return componentClass;
 	}
 
+	/**
+	 * If component class is set,
+	 * check if it is the same as before
+	 * if not it has to
+	 * <ul> 
+	 * <li>inform editpart that it should remove previous children from view</li>
+	 * <li>inform editpart that it should add new children from view</li>
+	 * </ul
+	 * @param componentClassString
+	 */
 	public void setComponentClass(String componentClassString) {
 		this.componentClass = componentClassString;
     	LimeComponent realComponentClass = findComponentClass(componentClassString);
     	if (realComponentClass != null){
-    		this.children = realComponentClass.getChildren();
+			//first step
+			for (LimeElement child : this.children){
+				removeChild(child);
+		    }
+			for (LimeElement child : realComponentClass.getChildren()){
+				LimeSubpart newChild = child.getCopy();
+				newChild.setParent(this);
+				addChild(newChild);
+		    }
     		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);
-		
 	}
 	
 
      */
     @Override
     public void setPropertyValue(Object id, Object value) {
-        if (Property_ID_Component_Ret.equals(id)) {
-            setComponentRet((String) value);
-        } else if (Property_ID_Component_Type.equals(id)) {
-            setType((String) value);
-        } else if (Property_ID_Component_InstanceOf.equals(id)) {
-        	//find its parent and set its children
-        	setComponentClass((String)value);
-        }  
-        else {
-            super.setPropertyValue(id, value);
-        }
+    	if (!instance){
+	        if (Property_ID_Component_Ret.equals(id)) {
+	            setComponentRet((String) value);
+	        } else if (Property_ID_Component_Type.equals(id)) {
+	            setType((String) value);
+	        } 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 :
 	public void setComponentClassText(String text) {
 		this.componentClass = text;
 	}
+
+	@Override
+	public LimeSubpart getCopy() {
+		LimeComponent newComponent = new LimeComponent();
+		//use reflection further
+		for (LimeElement child : this.children)
+			newComponent.addChild(child.getCopy());
+		for (Association association : this.getTargetAssociations()){
+		}
+		newComponent.componentRet = componentRet;
+		newComponent.type = type;
+		newComponent.location = location;
+		newComponent.size = size;
+		newComponent.name = name;
+		return newComponent;
+	}
+	
+	
+	
 }

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

 import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
 import org.eclipse.ui.views.properties.IPropertyDescriptor;
 
-
 public class LimeDiagram extends LimeSubpart implements LimeConstants{
     static final long serialVersionUID = 1;
     public static String ID_ROUTER = "router"; //$NON-NLS-1$
         leftRuler = new LimeRuler(false);
         topRuler = new LimeRuler(true);
     }
-
     public List<LimeElement> getChildren() {
         return children;
     }
      * Returns <code>null</code> for this model. Returns
      * normal descriptors for all subclasses.
      *
-     * @return  Array of property descriptors.
+     * @return  Array of prop            
+erty descriptors.
      */
     public IPropertyDescriptor[] getPropertyDescriptors() {
         if (getClass().equals(LimeDiagram.class)) {
                     booleanTypes);
             showInstanceProp.setLabelProvider(new BooleanTypeLabelProvider());
 
-            
             return new IPropertyDescriptor[] { cbd , showInstanceProp};
         }
 
 	public LimeComponent getComponentForName(String componentName) {
 		return componentClassDictionary.get(componentName);
 	}
+
 }

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

 
 import nl.tudelft.lime.constants.LimeMessages;
 import nl.tudelft.lime.constants.SystemSettings;
+import nl.tudelft.lime.model.LimeSubpart;
 
 import org.eclipse.swt.graphics.Image;
 
     public String getNewID() {
         return DEFAULT_NAME + count++;
     }
+
+    @Override
+	public LimeSubpart getCopy() {
+		InputPort newPort = new InputPort();
+		//use reflection further
+		
+		newPort.portConstp = portConstp;
+		newPort.portRestrict = portRestrict;
+		newPort.portSize = portSize;
+		newPort.portStatic = portStatic;
+		newPort.portVolatile = portVolatile;
+		newPort.portVolatilep = portVolatilep;
+		newPort.type = type;
+		newPort.location = location;
+		newPort.size = size;
+		newPort.name = name;
+		return newPort;
+	}
+
 }

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

 
 import nl.tudelft.lime.constants.LimeMessages;
 import nl.tudelft.lime.constants.SystemSettings;
+import nl.tudelft.lime.model.LimeSubpart;
 
 import org.eclipse.swt.graphics.Image;
 
     public Image getIconImage() {
         return Output_Port_Icon;
     }
+
+    @Override
+	public LimeSubpart getCopy() {
+		OutputPort newPort = new OutputPort();
+		//use reflection further
+		
+		newPort.portConstp = portConstp;
+		newPort.portRestrict = portRestrict;
+		newPort.portSize = portSize;
+		newPort.portStatic = portStatic;
+		newPort.portVolatile = portVolatile;
+		newPort.portVolatilep = portVolatilep;
+		newPort.type = type;
+		newPort.location = location;
+		newPort.size = size;
+		newPort.name = name;
+		return newPort;
+	}
+
 }

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

 import nl.tudelft.lime.constants.SystemSettings;
 import nl.tudelft.lime.figures.LimeConstants;
 import nl.tudelft.lime.model.LimeSubpart;
+import nl.tudelft.lime.model.component.LimeComponent;
 import nl.tudelft.lime.model.connection.Arc;
 
 import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
         /*        if (Property_ID_PORT_CONST.equals(id)){
                         setPortConst((String)value);
                 } else */
-        if (Property_ID_PORT_CONSTP.equals(id)) {
-            setPortConstp((Integer) value);
-        } else if (Property_ID_PORT_RESTRICT.equals(id)) {
-            setPortRestrict((Integer) value);
-        } else if (Property_ID_PORT_STATIC.equals(id)) {
-            setPortStatic((Integer) value);
-        } else if (Property_ID_PORT_VOLATILE.equals(id)) {
-            setPortVolatile((Integer) value);
-        } else if (Property_ID_PORT_VOLATILEP.equals(id)) {
-            setPortVolatilep((Integer) value);
-        } else if (Property_ID_PORT_SIZE.equals(id)) {
-            setPortSize((String) value);
-        } else if (Property_ID_PORT_TYPE.equals(id)) {
-            setType((String) value);
-        } else {
-            super.setPropertyValue(id, value);
-        }
+    	//if its parent is an instance it shouldn't be editable
+    	if (!((LimeComponent)this.parent).isInstance()){
+	        if (Property_ID_PORT_CONSTP.equals(id)) {
+	            setPortConstp((Integer) value);
+	        } else if (Property_ID_PORT_RESTRICT.equals(id)) {
+	            setPortRestrict((Integer) value);
+	        } else if (Property_ID_PORT_STATIC.equals(id)) {
+	            setPortStatic((Integer) value);
+	        } else if (Property_ID_PORT_VOLATILE.equals(id)) {
+	            setPortVolatile((Integer) value);
+	        } else if (Property_ID_PORT_VOLATILEP.equals(id)) {
+	            setPortVolatilep((Integer) value);
+	        } else if (Property_ID_PORT_SIZE.equals(id)) {
+	            setPortSize((String) value);
+	        } else if (Property_ID_PORT_TYPE.equals(id)) {
+	            setType((String) value);
+	        } else {
+	            super.setPropertyValue(id, value);
+	        }
+	    }
     }
 
     public void resetPropertyValue(Object id) {

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

                     childSubpart.setParent((LimeDiagram) subpart);
                     boolean isComponentInstance = (childSubpart instanceof LimeComponent) && ((LimeComponent)childSubpart).isInstance(); 
                 	((LimeDiagram) subpart).addChild(childSubpart, isComponentInstance);
+                	if ((subpart instanceof LimeComponent) && 
+                			((LimeComponent) subpart).isInstance() &&
+                			(childSubpart instanceof LimeComponent))
+                			((LimeComponent)childSubpart).setInstance(true);
+                		
                 	if (isComponentInstance){
                 		//this is needed to refresh
                 		LimeComponent component = (LimeComponent) childSubpart;