All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ingenias.editor.utils.DiagramManipulation Maven / Gradle / Ivy

There is a newer version: 1.0.11
Show newest version
package ingenias.editor.utils;

import ingenias.editor.IDEState;
import ingenias.editor.ModelJGraph;
import ingenias.editor.entities.Entity;
import ingenias.exception.InvalidAttribute;
import ingenias.exception.InvalidEntity;
import ingenias.exception.NotFound;
import ingenias.exception.NullEntity;
import ingenias.generator.browser.AttributedElement;
import ingenias.generator.browser.Browser;
import ingenias.generator.browser.BrowserImp;
import ingenias.generator.browser.Graph;
import ingenias.generator.browser.GraphAttribute;
import ingenias.generator.browser.GraphAttributeFactory;
import ingenias.generator.browser.GraphAttributeImp;
import ingenias.generator.browser.GraphCollectionImp;
import ingenias.generator.browser.GraphEntity;
import ingenias.generator.browser.GraphEntityFactory;
import ingenias.generator.browser.GraphEntityImp;
import ingenias.generator.browser.GraphRelationship;
import ingenias.generator.browser.GraphRelationshipFactory;
import ingenias.generator.browser.GraphRole;
import ingenias.generator.browser.GraphRoleImp;
import ingenias.generator.browser.RelationshipFactory;

import java.util.Hashtable;
import java.util.List;
import java.util.Vector;

import javax.swing.tree.MutableTreeNode;

import org.jgraph.graph.DefaultGraphCell;

public class DiagramManipulation {
	
	
	public static void moveRelsFromTo(DefaultGraphCell from, DefaultGraphCell to, ModelJGraph mjg, IDEState state){
		List childrenFrom = from.getChildren();
		Vector copyChildren=new Vector(childrenFrom);
		for (Object child:copyChildren){
			to.add((MutableTreeNode) child);
		}
		mjg.refresh();
		/*
	
		try {
			
			
			GraphEntityImp oldEntity=new GraphEntityImp((Entity) from.getUserObject(),mjg,state);
			GraphEntityImp newEntity=new GraphEntityImp((Entity) to.getUserObject(),mjg,state);
			DiagramManipulation.replaceInOneDiagram(new GraphEntityFactory(state),
						new GraphRelationshipFactory(state),
						new GraphAttributeFactory(state),
						oldEntity,
						newEntity,
						new BrowserImp(state));
		} catch (NullEntity e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NotFound e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidEntity e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidAttribute e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		
	}
	
	
	public static void replace(DefaultGraphCell from, DefaultGraphCell to, ModelJGraph mjg, IDEState state){
		try {
			GraphEntityImp oldEntity=new GraphEntityImp((Entity) from.getUserObject(),mjg,state);
			GraphEntityImp newEntity=new GraphEntityImp((Entity) to.getUserObject(),mjg,state);
			DiagramManipulation.replace(new GraphEntityFactory(state),
						new GraphRelationshipFactory(state),
						new GraphAttributeFactory(state),
						oldEntity,
						newEntity,
						new BrowserImp(state));
		} catch (NullEntity e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NotFound e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidEntity e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidAttribute e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	


	public static void replace(GraphEntity oldEntity, 
			GraphEntity newEntity,
			AttributedElement source,GraphAttributeFactory gaf) throws NullEntity, InvalidAttribute {
		GraphAttribute[] attrs = source.getAllAttrs();		
		for (GraphAttribute attr:attrs){
			if (attr.isCollectionValue()){
				if (attr.getCollectionValue()!=null){
					GraphCollectionImp colectionValue = (GraphCollectionImp)attr.getCollectionValue();
					for (int k=0;k rels = ent.getAllRelationships();
			replaceEntityInRelationships(gef, rf, gaf, oldEntity, newEntity,
					browser, rels);			
		}
	}
	

	public static void replaceInOneDiagram(
			GraphEntityFactory gef, 
			GraphRelationshipFactory rf, 
			GraphAttributeFactory gaf, 
			GraphEntity oldEntity, GraphEntity newEntity,
			Browser browser) throws NullEntity, NotFound, InvalidEntity, InvalidAttribute {
		
			GraphRelationship[] rels = oldEntity.getRelationships();
			Vector grels=new Vector();
			for (GraphRelationship rel:rels)
				grels.add(rel);
			replaceEntityInRelationships(gef, rf, gaf, oldEntity, newEntity,
					browser, grels);			
		
	}



	private static void replaceEntityInRelationships(GraphEntityFactory gef,
			GraphRelationshipFactory rf, GraphAttributeFactory gaf,
			GraphEntity oldEntity, GraphEntity newEntity, Browser browser,
			Vector rels) throws NullEntity,
			InvalidAttribute, InvalidEntity, NotFound {
		for (GraphRelationship rel:rels){
			replace(oldEntity,newEntity,rel,gaf);
			GraphRole[] roles = rel.getRoles();				
			for (GraphRole role:roles){
				if (role.getPlayer().getID().equals(oldEntity.getID())){
					((GraphRoleImp)role).setPlayer(newEntity.getEntity());
					Graph diagram = rel.getGraph();						
					gef.reuseEntity(newEntity.getID(),diagram);
					GraphRole[] rolesRel = rel.getRoles();
					String[] rolePlayers=new String[rolesRel.length];
					String replacedRole="";
					for (int k=0;k> assignments = null;
					assignments = 
							rf.getPossibleRoleAssignment(rel.getType(), 
									rolePlayers, diagram, browser);	
					
					boolean found=false;
					int k=0;
					Hashtable selectedAssignment=null;
					for (Hashtable assignment:assignments){
						boolean allCorrect=true;
						for (int j=0;j0 ||
					gat.isSimpleValue() && gat.getSimpleValue()!=null && 
					!gat.getSimpleValue().equals("") && !gat.getName().equalsIgnoreCase("id") &&
					!gat.getName().equalsIgnoreCase("type")
					)								
			gaf.setAttribute(newElement, gat);		

				
		}
	};

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy