Commits

Anonymous committed 736ae4d

New features: - add and remove are propagated correctly - undo/redu is resolved for instances - top-level component of the instances can be deleted now - instanceOf can be changed for an instance now

Comments (0)

Files changed (6)

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

                 !(parent instanceof LimeComponent)) {
             return false;
         }
+        if (parent instanceof LimeComponent)
+        	return !((LimeComponent)parent).isInstance();
         return true;
     }
 

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

                 !(parent instanceof LimeComponent)) {
             return false;
         }
+        if (parent instanceof LimeComponent)
+        	return !((LimeComponent)parent).isInstance();
         return true;
     }
 

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

 
     @Override
 	public boolean canExecute() {
-    	if 	((child instanceof LimeComponent && ((LimeComponent)child).isInstance()) ||
-    		(parent instanceof LimeComponent && ((LimeComponent)parent).isInstance()))
-    		return false;
-    	
+    	if 	(parent instanceof LimeComponent){
+    		//if child is a component and its father is an instance
+    		return !((LimeComponent)parent).isInstance();
+    	}
     	//if it is an association and its source is a child of an instace then don't 
     	//delete it as well
     	if (child instanceof Association){
 
     protected void primExecute() {
     	//delete all the instances first
+    	
     	for (LimeSubpart kid : child.getInstances()){
     		DeleteCommand kidDeleteCommand = new DeleteCommand();
-    		kidDeleteCommand.instances = child.getInstances();
     		kidDeleteCommand.setChild(kid);
     		kidDeleteCommand.setParent((LimeDiagram)kid.getParent());
     		childDeleteCommands.add(kidDeleteCommand);
     		kidDeleteCommand.execute();
     	}
+    	//clear instances but keep them for future undo
+    	child.getInstances().clear();
         deleteConnections(child);
         detachFromGuides(child);
         index = parent.getChildren().indexOf(child);

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

 		this.componentClass = componentClassString;
     	LimeComponent realComponentClass = findComponentClass(componentClassString);
     	if (realComponentClass != null){
+    		//this is used later for deleting and adding purposes
+    		realComponentClass.addToInstances(this);
 			//first step
 			for (LimeElement child : this.children){
 		        fireChildRemoved(CHILDREN, child);
     public void setPropertyValue(Object id, Object value) {
     	//if it is not instance and the change from UI
     	//or if it is an instance and the change is not from UI then accept the change
+    	if (Property_ID_Component_InstanceOf.equals(id)) {
+	        	//find its parent and set its children
+	        	setComponentClass((String)value);
+        }
     	if ((!instance && changeFromUI) ||
     		(instance && !changeFromUI)){
 	        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);
 		newComponent.location = location;
 		newComponent.size = size;
 		newComponent.name = name;
+		addToInstances(newComponent);
 		return newComponent;
 	}
 	

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

     	//if diagram is in onlyInstances mode set its children property to 
     	//instance mode
     	if (child instanceof LimeComponent){
-    		((LimeComponent) child).setInstance(this.onlyInstances == 1);
+    		//if this is a diagram
+    		if (this.getClass().getSimpleName().equals(LimeDiagram.class.getSimpleName()))
+    			((LimeComponent) child).setInstance(this.onlyInstances == 1);
+    		//if it is a component set its child also to its instance condition
+    		else
+    			((LimeComponent) child).setInstance(((LimeComponent)this).isInstance());
+    		
     		//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);
     		}
     	}
+    	List<LimeSubpart> instances = getInstances();
+    	//for all instances of this add the element
+    	for (LimeSubpart instance :instances){
+    		((LimeDiagram)instance).addChild(child.getCopy(), index);
+    	}
     		
         if (index >= 0) {
             children.add(index, child);

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 nl.tudelft.lime.model.connection.Association;
 
 import org.eclipse.swt.graphics.Image;