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

ingenias.editor.models.MetamodelModelJGraph Maven / Gradle / Ivy

Go to download

Meta-language editor built over INGENME. It is the most basic editor to be used in the rest of projects

There is a newer version: 1.0.9
Show newest version


/** 
 * Copyright (C) 2010  Jorge J. Gomez-Sanz over original code from Ruben Fuentes and Juan Pavon
 * 
 *   Modifications over original code from jgraph.sourceforge.net
 * 
 * This file is part of the INGENME tool. INGENME is an open source meta-editor
 * which produces customized editors for user-defined modeling languages
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation version 3 of the License
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see 
 **/
 

package ingenias.editor.models;

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.util.Map;
import java.util.Hashtable;
import java.awt.Point;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.Hashtable;


import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.URL;
import java.util.*;
import java.util.Hashtable;
import java.util.ArrayList;
import javax.swing.event.UndoableEditEvent;
import org.jgraph.JGraph;
import org.jgraph.graph.*;
import org.jgraph.event.*;
import java.util.Vector;
import org.jgraph.JGraph;
import org.jgraph.graph.*;
import org.jgraph.event.*;
import org.jgraph.plaf.basic.*;
import ingenias.editor.entities.*;
import ingenias.editor.cell.*;
import ingenias.editor.rendererxml.*;
import ingenias.editor.events.*;
import ingenias.exception.InvalidEntity;
import ingenias.editor.*;
import java.util.concurrent.TimeUnit;

public class MetamodelModelJGraph extends ModelJGraph {

  private Preferences prefs;
  
 

  public MetamodelModelJGraph(MetamodelDataEntity mde, 
                               String nombre, ObjectManager om, Model
                               m, BasicMarqueeHandler mh, Preferences prefs) {
    super(mde, nombre, m, mh,om);
    this.prefs=prefs;
    
			 
				  ToolTipManager.sharedInstance().registerComponent(this);
				  this.getModel().addGraphModelListener(
				  new ChangeNARYEdgeLocation(this));
				  this.getModel().addGraphModelListener(
				  new ChangeEntityLocation(this));			  
				  
		
    this.getGraphLayoutCache().setFactory(new ingenias.editor.cellfactories.MetamodelCellViewFactory());

  }


  //
  // Adding Tooltips
  //

  // Return Cell Label as a Tooltip
  public String getToolTipText(MouseEvent e) {
    if (e != null) {
      // Fetch Cell under Mousepointer
      Object c = getFirstCellForLocation(e.getX(), e.getY());
      if (c != null) {

        // Convert Cell to String and Return
        return convertValueToString(c);
      }
    }
    return null;
  }





  public JToolBar getPaleta() {
    return toolbar;

  }

  protected void creaToolBar() {
    if (toolbar==null){
    toolbar = new FilteredJToolBar("Metamodel");
    toolbar.setFloatable(false);
    ImageIcon undoIcon = null;
    JButton jb = null;


   if (true){
    Image img_MetaObject =
        ImageLoader.getImage("images/mmetaobj.gif");
    undoIcon = new ImageIcon(img_MetaObject);
    Action MetaObject=
        new AbstractAction("MetaObject", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "MetaObject");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    MetaObject.setEnabled(true);
    jb = new JButton(MetaObject){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("MetaObject");	
    jb.setToolTipText("MetaObject:"+new MetaObject("").getHelpDesc()+"\n\n"+new MetaObject("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

   if (true){
    Image img_MetaDiagram =
        ImageLoader.getImage("images/mmetadiagram.gif");
    undoIcon = new ImageIcon(img_MetaDiagram);
    Action MetaDiagram=
        new AbstractAction("MetaDiagram", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "MetaDiagram");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    MetaDiagram.setEnabled(true);
    jb = new JButton(MetaDiagram){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("MetaDiagram");	
    jb.setToolTipText("MetaDiagram:"+new MetaDiagram("").getHelpDesc()+"\n\n"+new MetaDiagram("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

   if (true){
    Image img_MetaRelationship =
        ImageLoader.getImage("images/mmetarel.gif");
    undoIcon = new ImageIcon(img_MetaRelationship);
    Action MetaRelationship=
        new AbstractAction("MetaRelationship", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "MetaRelationship");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    MetaRelationship.setEnabled(true);
    jb = new JButton(MetaRelationship){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("MetaRelationship");	
    jb.setToolTipText("MetaRelationship:"+new MetaRelationship("").getHelpDesc()+"\n\n"+new MetaRelationship("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

   if (true){
    Image img_MetaRole =
        ImageLoader.getImage("images/mmetarol.gif");
    undoIcon = new ImageIcon(img_MetaRole);
    Action MetaRole=
        new AbstractAction("MetaRole", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "MetaRole");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    MetaRole.setEnabled(true);
    jb = new JButton(MetaRole){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("MetaRole");	
    jb.setToolTipText("MetaRole:"+new MetaRole("").getHelpDesc()+"\n\n"+new MetaRole("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

   if (true){
    Image img_VisualRepresentation =
        ImageLoader.getImage("images/visualrepr.gif");
    undoIcon = new ImageIcon(img_VisualRepresentation);
    Action VisualRepresentation=
        new AbstractAction("VisualRepresentation", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "VisualRepresentation");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    VisualRepresentation.setEnabled(true);
    jb = new JButton(VisualRepresentation){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("VisualRepresentation");	
    jb.setToolTipText("VisualRepresentation:"+new VisualRepresentation("").getHelpDesc()+"\n\n"+new VisualRepresentation("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

   if (true){
    Image img_BasicRepresentation =
        ImageLoader.getImage("images/basvisualrepr.gif");
    undoIcon = new ImageIcon(img_BasicRepresentation);
    Action BasicRepresentation=
        new AbstractAction("BasicRepresentation", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "BasicRepresentation");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    BasicRepresentation.setEnabled(true);
    jb = new JButton(BasicRepresentation){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("BasicRepresentation");	
    jb.setToolTipText("BasicRepresentation:"+new BasicRepresentation("").getHelpDesc()+"\n\n"+new BasicRepresentation("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

   if (true){
    Image img_PropertyField =
        ImageLoader.getImage("images/mproperty.gif");
    undoIcon = new ImageIcon(img_PropertyField);
    Action PropertyField=
        new AbstractAction("PropertyField", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "PropertyField");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    PropertyField.setEnabled(true);
    jb = new JButton(PropertyField){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("PropertyField");	
    jb.setToolTipText("PropertyField:"+new PropertyField("").getHelpDesc()+"\n\n"+new PropertyField("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

   if (true){
    Image img_UMLComment =
        ImageLoader.getImage("images/mumlcomment.gif");
    undoIcon = new ImageIcon(img_UMLComment);
    Action UMLComment=
        new AbstractAction("UMLComment", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "UMLComment");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    UMLComment.setEnabled(true);
    jb = new JButton(UMLComment){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("UMLComment");	
    jb.setToolTipText("UMLComment:"+new UMLComment("").getHelpDesc()+"\n\n"+new UMLComment("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

   if (true){
    Image img_PreferredOrder =
        ImageLoader.getImage("images/mproperty.gif");
    undoIcon = new ImageIcon(img_PreferredOrder);
    Action PreferredOrder=
        new AbstractAction("PreferredOrder", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "PreferredOrder");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    PreferredOrder.setEnabled(true);
    jb = new JButton(PreferredOrder){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("PreferredOrder");	
    jb.setToolTipText("PreferredOrder:"+new PreferredOrder("").getHelpDesc()+"\n\n"+new PreferredOrder("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

   if (true){
    Image img_Documentation =
        ImageLoader.getImage("images/mproperty.gif");
    undoIcon = new ImageIcon(img_Documentation);
    Action Documentation=
        new AbstractAction("Documentation", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "Documentation");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    Documentation.setEnabled(true);
    jb = new JButton(Documentation){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("Documentation");	
    jb.setToolTipText("Documentation:"+new Documentation("").getHelpDesc()+"\n\n"+new Documentation("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

   if (false){
    Image img_PropertyOrder =
        ImageLoader.getImage("");
    undoIcon = new ImageIcon(img_PropertyOrder);
    Action PropertyOrder=
        new AbstractAction("PropertyOrder", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "PropertyOrder");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    PropertyOrder.setEnabled(true);
    jb = new JButton(PropertyOrder){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("PropertyOrder");	
    jb.setToolTipText("PropertyOrder:"+new PropertyOrder("").getHelpDesc()+"\n\n"+new PropertyOrder("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

   if (false){
    Image img_ExternalTypeWrapper =
        ImageLoader.getImage("");
    undoIcon = new ImageIcon(img_ExternalTypeWrapper);
    Action ExternalTypeWrapper=
        new AbstractAction("ExternalTypeWrapper", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "ExternalTypeWrapper");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    ExternalTypeWrapper.setEnabled(true);
    jb = new JButton(ExternalTypeWrapper){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("ExternalTypeWrapper");	
    jb.setToolTipText("ExternalTypeWrapper:"+new ExternalTypeWrapper("").getHelpDesc()+"\n\n"+new ExternalTypeWrapper("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

   if (false){
    Image img_MetaDiagramTypeWrapper =
        ImageLoader.getImage("");
    undoIcon = new ImageIcon(img_MetaDiagramTypeWrapper);
    Action MetaDiagramTypeWrapper=
        new AbstractAction("MetaDiagramTypeWrapper", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "MetaDiagramTypeWrapper");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    MetaDiagramTypeWrapper.setEnabled(true);
    jb = new JButton(MetaDiagramTypeWrapper){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("MetaDiagramTypeWrapper");	
    jb.setToolTipText("MetaDiagramTypeWrapper:"+new MetaDiagramTypeWrapper("").getHelpDesc()+"\n\n"+new MetaDiagramTypeWrapper("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

   if (false){
    Image img_MetaObjectTypeWrapper =
        ImageLoader.getImage("");
    undoIcon = new ImageIcon(img_MetaObjectTypeWrapper);
    Action MetaObjectTypeWrapper=
        new AbstractAction("MetaObjectTypeWrapper", undoIcon) {
      public void actionPerformed(ActionEvent e) {
       try{
        insert(new Point(getVisibleRect().x,getVisibleRect().y), "MetaObjectTypeWrapper");
	} catch (InvalidEntity e1) {			
		e1.printStackTrace();
	}
      }
    };
    MetaObjectTypeWrapper.setEnabled(true);
    jb = new JButton(MetaObjectTypeWrapper){
					@Override
					public JToolTip createToolTip() {
						return new ingenias.editor.editiondialog.JMultiLineToolTip();
					}
				};
    jb.setText("");
    jb.setName("MetaObjectTypeWrapper");	
    jb.setToolTipText("MetaObjectTypeWrapper:"+new MetaObjectTypeWrapper("").getHelpDesc()+"\n\n"+new MetaObjectTypeWrapper("").getHelpRecom());
    jb.addMouseListener(new MouseAdapter() {
				    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
				    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
				    @Override
				    public void mouseEntered(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
				    }
				 
				    @Override
				    public void mouseExited(MouseEvent me) {
				        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
				    }
				});
    toolbar.add(jb);
    }

    }

  }

  public Vector getAllowedRelationships(){
   Vector relationships=new   Vector();


          relationships.add("UMLAnnotatedElement");

          relationships.add("Has");

          relationships.add("InheritsO");

          relationships.add("InheritsR");

          relationships.add("Contains");

          relationships.add("VisualizedAs");

          relationships.add("PlayedBy");

          relationships.add("AssociationEnd");

          relationships.add("BinaryRel");

          relationships.add("PropsOrderedAs");

          relationships.add("IsDocumentedBy");

          relationships.add("HasMO");

   return relationships;
  }

  public  Vector getAllowedEntities(){
   Vector entities=new   Vector();


 entities.add("MetaObject");

 entities.add("MetaDiagram");

 entities.add("MetaRelationship");

 entities.add("MetaRole");

 entities.add("VisualRepresentation");

 entities.add("BasicRepresentation");

 entities.add("PropertyField");

 entities.add("UMLComment");

 entities.add("PreferredOrder");

 entities.add("Documentation");

 entities.add("PropertyOrder");

 entities.add("ExternalTypeWrapper");

 entities.add("MetaDiagramTypeWrapper");

 entities.add("MetaObjectTypeWrapper");

   return entities;
  }

  // Gets the name of the possible relationships for the selected GraphCells.
  // A relationship can be binary (DefaultEdge) or n-ary (NAryEdge).
  // The requested action is slightly different depending on selected items.
  // According to the number of Edges in selected, the action can be:
  // 0 => Propose a relationship between selected according included classes.
  // 1 and it is NAryEdge => The class of that NAryEdge if it is possible according implements java.io.Serializable
  //      current cardinality and included classes..
  // other cases => Error, no relationships are allowed.
  public Object[] getPossibleRelationships(GraphCell[] selected) {
    // Possible relationships initialization.
    Vector v = new Vector();

    // Search for NAryEdges in selected.
    int nAryEdgesNum = 0;
    int edgesNum = 0;
    NAryEdge selectedEdge = null;
    for (int i = 0; i < selected.length; i++) {
      if (selected[i] instanceof NAryEdge) {
        nAryEdgesNum++;
        selectedEdge = (NAryEdge) selected[i];
      }
      else if (selected[i] instanceof DefaultEdge) {
        edgesNum++;

        // Connections are only possible with two or more elements and without binary edges.
      }
    }
    if (selected.length >= 2 && edgesNum == 0) {

      // The number of NAryEdges is considered.
      if (nAryEdgesNum == 0) {
        // acceptConnection methods only admits vertex parameters.
        // Binary relationships.

        // N-ary relationships. Sometimes they can be also binary.
        if (UMLAnnotatedElementEdge.acceptConnection(this.getModel(), selected)) {
          v.add("UMLAnnotatedElement");
	  }

        // N-ary relationships. Sometimes they can be also binary.
        if (HasEdge.acceptConnection(this.getModel(), selected)) {
          v.add("Has");
	  }

        // N-ary relationships. Sometimes they can be also binary.
        if (InheritsOEdge.acceptConnection(this.getModel(), selected)) {
          v.add("InheritsO");
	  }

        // N-ary relationships. Sometimes they can be also binary.
        if (InheritsREdge.acceptConnection(this.getModel(), selected)) {
          v.add("InheritsR");
	  }

        // N-ary relationships. Sometimes they can be also binary.
        if (ContainsEdge.acceptConnection(this.getModel(), selected)) {
          v.add("Contains");
	  }

        // N-ary relationships. Sometimes they can be also binary.
        if (VisualizedAsEdge.acceptConnection(this.getModel(), selected)) {
          v.add("VisualizedAs");
	  }

        // N-ary relationships. Sometimes they can be also binary.
        if (PlayedByEdge.acceptConnection(this.getModel(), selected)) {
          v.add("PlayedBy");
	  }

        // N-ary relationships. Sometimes they can be also binary.
        if (AssociationEndEdge.acceptConnection(this.getModel(), selected)) {
          v.add("AssociationEnd");
	  }

        // N-ary relationships. Sometimes they can be also binary.
        if (BinaryRelEdge.acceptConnection(this.getModel(), selected)) {
          v.add("BinaryRel");
	  }

        // N-ary relationships. Sometimes they can be also binary.
        if (PropsOrderedAsEdge.acceptConnection(this.getModel(), selected)) {
          v.add("PropsOrderedAs");
	  }

        // N-ary relationships. Sometimes they can be also binary.
        if (IsDocumentedByEdge.acceptConnection(this.getModel(), selected)) {
          v.add("IsDocumentedBy");
	  }

        // N-ary relationships. Sometimes they can be also binary.
        if (HasMOEdge.acceptConnection(this.getModel(), selected)) {
          v.add("HasMO");
	  }

      }
      else if (nAryEdgesNum == 1) {

        if (selectedEdge instanceof UMLAnnotatedElementEdge &&
        (UMLAnnotatedElementEdge.acceptConnection(this.getModel(), selected))) {
          v.add("UMLAnnotatedElement");
        }

        if (selectedEdge instanceof HasEdge &&
        (HasEdge.acceptConnection(this.getModel(), selected))) {
          v.add("Has");
        }

        if (selectedEdge instanceof InheritsOEdge &&
        (InheritsOEdge.acceptConnection(this.getModel(), selected))) {
          v.add("InheritsO");
        }

        if (selectedEdge instanceof InheritsREdge &&
        (InheritsREdge.acceptConnection(this.getModel(), selected))) {
          v.add("InheritsR");
        }

        if (selectedEdge instanceof ContainsEdge &&
        (ContainsEdge.acceptConnection(this.getModel(), selected))) {
          v.add("Contains");
        }

        if (selectedEdge instanceof VisualizedAsEdge &&
        (VisualizedAsEdge.acceptConnection(this.getModel(), selected))) {
          v.add("VisualizedAs");
        }

        if (selectedEdge instanceof PlayedByEdge &&
        (PlayedByEdge.acceptConnection(this.getModel(), selected))) {
          v.add("PlayedBy");
        }

        if (selectedEdge instanceof AssociationEndEdge &&
        (AssociationEndEdge.acceptConnection(this.getModel(), selected))) {
          v.add("AssociationEnd");
        }

        if (selectedEdge instanceof BinaryRelEdge &&
        (BinaryRelEdge.acceptConnection(this.getModel(), selected))) {
          v.add("BinaryRel");
        }

        if (selectedEdge instanceof PropsOrderedAsEdge &&
        (PropsOrderedAsEdge.acceptConnection(this.getModel(), selected))) {
          v.add("PropsOrderedAs");
        }

        if (selectedEdge instanceof IsDocumentedByEdge &&
        (IsDocumentedByEdge.acceptConnection(this.getModel(), selected))) {
          v.add("IsDocumentedBy");
        }

        if (selectedEdge instanceof HasMOEdge &&
        (HasMOEdge.acceptConnection(this.getModel(), selected))) {
          v.add("HasMO");
        }

      }
    }

    return v.toArray();
  }

  public DefaultGraphCell getInstanciaNRelacion(String relacion,
                                                GraphCell[] selected) {

    // Search for NAryEdges in selected.
    int nAryEdgesNum = 0;
    int edgesNum = 0;
    NAryEdge selectedEdge = null;
    for (int i = 0; i < selected.length; i++) {
      if (selected[i] instanceof NAryEdge) {
        nAryEdgesNum++;
        selectedEdge = (NAryEdge) selected[i];
      }
      else if (selected[i] instanceof DefaultEdge) {
        edgesNum++;

      }
    }
    if (nAryEdgesNum <= 1 && edgesNum == 0) {

      if (relacion.equalsIgnoreCase("UMLAnnotatedElement")) {
        // ResponsibleNEdge already exists.
        if (nAryEdgesNum == 1 && selectedEdge instanceof UMLAnnotatedElementEdge) {
          return selectedEdge;
        }
        // There is no NAryEdges in selected.
        else if (nAryEdgesNum == 0) {
          return new UMLAnnotatedElementEdge(new ingenias.editor.entities.UMLAnnotatedElement(getMJGraph().getNewId()));
        }
      }

      if (relacion.equalsIgnoreCase("Has")) {
        // ResponsibleNEdge already exists.
        if (nAryEdgesNum == 1 && selectedEdge instanceof HasEdge) {
          return selectedEdge;
        }
        // There is no NAryEdges in selected.
        else if (nAryEdgesNum == 0) {
          return new HasEdge(new ingenias.editor.entities.Has(getMJGraph().getNewId()));
        }
      }

      if (relacion.equalsIgnoreCase("InheritsO")) {
        // ResponsibleNEdge already exists.
        if (nAryEdgesNum == 1 && selectedEdge instanceof InheritsOEdge) {
          return selectedEdge;
        }
        // There is no NAryEdges in selected.
        else if (nAryEdgesNum == 0) {
          return new InheritsOEdge(new ingenias.editor.entities.InheritsO(getMJGraph().getNewId()));
        }
      }

      if (relacion.equalsIgnoreCase("InheritsR")) {
        // ResponsibleNEdge already exists.
        if (nAryEdgesNum == 1 && selectedEdge instanceof InheritsREdge) {
          return selectedEdge;
        }
        // There is no NAryEdges in selected.
        else if (nAryEdgesNum == 0) {
          return new InheritsREdge(new ingenias.editor.entities.InheritsR(getMJGraph().getNewId()));
        }
      }

      if (relacion.equalsIgnoreCase("Contains")) {
        // ResponsibleNEdge already exists.
        if (nAryEdgesNum == 1 && selectedEdge instanceof ContainsEdge) {
          return selectedEdge;
        }
        // There is no NAryEdges in selected.
        else if (nAryEdgesNum == 0) {
          return new ContainsEdge(new ingenias.editor.entities.Contains(getMJGraph().getNewId()));
        }
      }

      if (relacion.equalsIgnoreCase("VisualizedAs")) {
        // ResponsibleNEdge already exists.
        if (nAryEdgesNum == 1 && selectedEdge instanceof VisualizedAsEdge) {
          return selectedEdge;
        }
        // There is no NAryEdges in selected.
        else if (nAryEdgesNum == 0) {
          return new VisualizedAsEdge(new ingenias.editor.entities.VisualizedAs(getMJGraph().getNewId()));
        }
      }

      if (relacion.equalsIgnoreCase("PlayedBy")) {
        // ResponsibleNEdge already exists.
        if (nAryEdgesNum == 1 && selectedEdge instanceof PlayedByEdge) {
          return selectedEdge;
        }
        // There is no NAryEdges in selected.
        else if (nAryEdgesNum == 0) {
          return new PlayedByEdge(new ingenias.editor.entities.PlayedBy(getMJGraph().getNewId()));
        }
      }

      if (relacion.equalsIgnoreCase("AssociationEnd")) {
        // ResponsibleNEdge already exists.
        if (nAryEdgesNum == 1 && selectedEdge instanceof AssociationEndEdge) {
          return selectedEdge;
        }
        // There is no NAryEdges in selected.
        else if (nAryEdgesNum == 0) {
          return new AssociationEndEdge(new ingenias.editor.entities.AssociationEnd(getMJGraph().getNewId()));
        }
      }

      if (relacion.equalsIgnoreCase("BinaryRel")) {
        // ResponsibleNEdge already exists.
        if (nAryEdgesNum == 1 && selectedEdge instanceof BinaryRelEdge) {
          return selectedEdge;
        }
        // There is no NAryEdges in selected.
        else if (nAryEdgesNum == 0) {
          return new BinaryRelEdge(new ingenias.editor.entities.BinaryRel(getMJGraph().getNewId()));
        }
      }

      if (relacion.equalsIgnoreCase("PropsOrderedAs")) {
        // ResponsibleNEdge already exists.
        if (nAryEdgesNum == 1 && selectedEdge instanceof PropsOrderedAsEdge) {
          return selectedEdge;
        }
        // There is no NAryEdges in selected.
        else if (nAryEdgesNum == 0) {
          return new PropsOrderedAsEdge(new ingenias.editor.entities.PropsOrderedAs(getMJGraph().getNewId()));
        }
      }

      if (relacion.equalsIgnoreCase("IsDocumentedBy")) {
        // ResponsibleNEdge already exists.
        if (nAryEdgesNum == 1 && selectedEdge instanceof IsDocumentedByEdge) {
          return selectedEdge;
        }
        // There is no NAryEdges in selected.
        else if (nAryEdgesNum == 0) {
          return new IsDocumentedByEdge(new ingenias.editor.entities.IsDocumentedBy(getMJGraph().getNewId()));
        }
      }

      if (relacion.equalsIgnoreCase("HasMO")) {
        // ResponsibleNEdge already exists.
        if (nAryEdgesNum == 1 && selectedEdge instanceof HasMOEdge) {
          return selectedEdge;
        }
        // There is no NAryEdges in selected.
        else if (nAryEdgesNum == 0) {
          return new HasMOEdge(new ingenias.editor.entities.HasMO(getMJGraph().getNewId()));
        }
      }

    }

    return null;
  }
  
  public DefaultGraphCell createCell(String entity) throws InvalidEntity{
  
    if (entity.equalsIgnoreCase("MetaObject")) {
    MetaObject nentity=getOM().createMetaObject(getMJGraph().getNewId("MetaObject"));
      DefaultGraphCell vertex = new
          MetaObjectCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("MetaDiagram")) {
    MetaDiagram nentity=getOM().createMetaDiagram(getMJGraph().getNewId("MetaDiagram"));
      DefaultGraphCell vertex = new
          MetaDiagramCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("MetaRelationship")) {
    MetaRelationship nentity=getOM().createMetaRelationship(getMJGraph().getNewId("MetaRelationship"));
      DefaultGraphCell vertex = new
          MetaRelationshipCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("MetaRole")) {
    MetaRole nentity=getOM().createMetaRole(getMJGraph().getNewId("MetaRole"));
      DefaultGraphCell vertex = new
          MetaRoleCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("VisualRepresentation")) {
    VisualRepresentation nentity=getOM().createVisualRepresentation(getMJGraph().getNewId("VisualRepresentation"));
      DefaultGraphCell vertex = new
          VisualRepresentationCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("BasicRepresentation")) {
    BasicRepresentation nentity=getOM().createBasicRepresentation(getMJGraph().getNewId("BasicRepresentation"));
      DefaultGraphCell vertex = new
          BasicRepresentationCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("PropertyField")) {
    PropertyField nentity=getOM().createPropertyField(getMJGraph().getNewId("PropertyField"));
      DefaultGraphCell vertex = new
          PropertyFieldCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("UMLComment")) {
    UMLComment nentity=getOM().createUMLComment(getMJGraph().getNewId("UMLComment"));
      DefaultGraphCell vertex = new
          UMLCommentCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("PreferredOrder")) {
    PreferredOrder nentity=getOM().createPreferredOrder(getMJGraph().getNewId("PreferredOrder"));
      DefaultGraphCell vertex = new
          PreferredOrderCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("Documentation")) {
    Documentation nentity=getOM().createDocumentation(getMJGraph().getNewId("Documentation"));
      DefaultGraphCell vertex = new
          DocumentationCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("PropertyOrder")) {
    PropertyOrder nentity=getOM().createPropertyOrder(getMJGraph().getNewId("PropertyOrder"));
      DefaultGraphCell vertex = new
          PropertyOrderCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("ExternalTypeWrapper")) {
    ExternalTypeWrapper nentity=getOM().createExternalTypeWrapper(getMJGraph().getNewId("ExternalTypeWrapper"));
      DefaultGraphCell vertex = new
          ExternalTypeWrapperCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("MetaDiagramTypeWrapper")) {
    MetaDiagramTypeWrapper nentity=getOM().createMetaDiagramTypeWrapper(getMJGraph().getNewId("MetaDiagramTypeWrapper"));
      DefaultGraphCell vertex = new
          MetaDiagramTypeWrapperCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("MetaObjectTypeWrapper")) {
    MetaObjectTypeWrapper nentity=getOM().createMetaObjectTypeWrapper(getMJGraph().getNewId("MetaObjectTypeWrapper"));
      DefaultGraphCell vertex = new
          MetaObjectTypeWrapperCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

	  throw new ingenias.exception.InvalidEntity("Entity type "+entity+" is not allowed in this diagram"); 
  }
  
  public Dimension getDefaultSize(Entity entity) throws InvalidEntity{
    
    if (entity.getType().equalsIgnoreCase("MetaObject")) {
      return MetaObjectView.getSize((ingenias.editor.entities.MetaObject)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("MetaDiagram")) {
      return MetaDiagramView.getSize((ingenias.editor.entities.MetaDiagram)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("MetaRelationship")) {
      return MetaRelationshipView.getSize((ingenias.editor.entities.MetaRelationship)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("MetaRole")) {
      return MetaRoleView.getSize((ingenias.editor.entities.MetaRole)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("VisualRepresentation")) {
      return VisualRepresentationView.getSize((ingenias.editor.entities.VisualRepresentation)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("BasicRepresentation")) {
      return BasicRepresentationView.getSize((ingenias.editor.entities.BasicRepresentation)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("PropertyField")) {
      return PropertyFieldView.getSize((ingenias.editor.entities.PropertyField)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("UMLComment")) {
      return UMLCommentView.getSize((ingenias.editor.entities.UMLComment)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("PreferredOrder")) {
      return PreferredOrderView.getSize((ingenias.editor.entities.PreferredOrder)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("Documentation")) {
      return DocumentationView.getSize((ingenias.editor.entities.Documentation)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("PropertyOrder")) {
      return PropertyOrderView.getSize((ingenias.editor.entities.PropertyOrder)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("ExternalTypeWrapper")) {
      return ExternalTypeWrapperView.getSize((ingenias.editor.entities.ExternalTypeWrapper)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("MetaDiagramTypeWrapper")) {
      return MetaDiagramTypeWrapperView.getSize((ingenias.editor.entities.MetaDiagramTypeWrapper)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("MetaObjectTypeWrapper")) {
      return MetaObjectTypeWrapperView.getSize((ingenias.editor.entities.MetaObjectTypeWrapper)entity);      
    }
    else


      if (entity.getType().equalsIgnoreCase("UMLAnnotatedElement")) {
      	return UMLAnnotatedElementView.getSize((ingenias.editor.entities.UMLAnnotatedElement)entity);
      }

      if (entity.getType().equalsIgnoreCase("Has")) {
      	return HasView.getSize((ingenias.editor.entities.Has)entity);
      }

      if (entity.getType().equalsIgnoreCase("InheritsO")) {
      	return InheritsOView.getSize((ingenias.editor.entities.InheritsO)entity);
      }

      if (entity.getType().equalsIgnoreCase("InheritsR")) {
      	return InheritsRView.getSize((ingenias.editor.entities.InheritsR)entity);
      }

      if (entity.getType().equalsIgnoreCase("Contains")) {
      	return ContainsView.getSize((ingenias.editor.entities.Contains)entity);
      }

      if (entity.getType().equalsIgnoreCase("VisualizedAs")) {
      	return VisualizedAsView.getSize((ingenias.editor.entities.VisualizedAs)entity);
      }

      if (entity.getType().equalsIgnoreCase("PlayedBy")) {
      	return PlayedByView.getSize((ingenias.editor.entities.PlayedBy)entity);
      }

      if (entity.getType().equalsIgnoreCase("AssociationEnd")) {
      	return AssociationEndView.getSize((ingenias.editor.entities.AssociationEnd)entity);
      }

      if (entity.getType().equalsIgnoreCase("BinaryRel")) {
      	return BinaryRelView.getSize((ingenias.editor.entities.BinaryRel)entity);
      }

      if (entity.getType().equalsIgnoreCase("PropsOrderedAs")) {
      	return PropsOrderedAsView.getSize((ingenias.editor.entities.PropsOrderedAs)entity);
      }

      if (entity.getType().equalsIgnoreCase("IsDocumentedBy")) {
      	return IsDocumentedByView.getSize((ingenias.editor.entities.IsDocumentedBy)entity);
      }

      if (entity.getType().equalsIgnoreCase("HasMO")) {
      	return HasMOView.getSize((ingenias.editor.entities.HasMO)entity);
      }

    throw new ingenias.exception.InvalidEntity("Entity type "+entity+" is not allowed in this diagram"); 
	    
  }

  public DefaultGraphCell insert(Point point, String entity) throws InvalidEntity {
  // CellView information is not available after creating the cell.

    // Create a Map that holds the attributes for the Vertex
    Map map = new Hashtable();
    // Snap the Point to the Grid
    point = convert(this.snap(new Point(point)));

    // Construct Vertex with no Label
    DefaultGraphCell vertex;
    Dimension size;

    vertex=this.createCell(entity);
    size=this.getDefaultSize((Entity)vertex.getUserObject());



    // Add a Bounds Attribute to the Map
    GraphConstants.setBounds(map, new Rectangle(point, size));

    // Construct a Map from cells to Maps (for insert)
    Hashtable attributes = new Hashtable();
    // Associate the Vertex with its Attributes
    attributes.put(vertex, map);
    // Insert the Vertex and its Attributes
    this.getModel().insert(new Object[] {vertex},attributes
                           , null, null, null);

	Entity newEntity=(Entity) vertex.getUserObject();
	if (prefs.getModelingLanguage()==Preferences.ModelingLanguage.UML)
		newEntity.getPrefs(null).setView(ViewPreferences.ViewType.UML);
	if (prefs.getModelingLanguage()==Preferences.ModelingLanguage.INGENIAS)
		newEntity.getPrefs(null).setView(ViewPreferences.ViewType.INGENIAS);

	getGraphLayoutCache().setVisible(vertex,true);// makes the cell visible because
      // the graphlayoutcache has partial set to true

    return vertex;
  }

  


public DefaultGraphCell insertDuplicated(Point point, ingenias.editor.entities.Entity
                               entity) {
    // CellView information is not available after creating the cell.

    // Create a Map that holds the attributes for the Vertex
    Map map =new Hashtable();
    // Snap the Point to the Grid
    point = convert(this.snap(new Point(point)));
   

    // Construct Vertex with no Label
    DefaultGraphCell vertex = null;
    Dimension size = null;


    if (entity.getClass().equals(MetaObject.class)) {
      vertex = new MetaObjectCell( (MetaObject) entity);
      // Default Size for the new Vertex with the new entity within
      size = MetaObjectView.getSize((MetaObject) entity);
      
    }
    else

    if (entity.getClass().equals(MetaDiagram.class)) {
      vertex = new MetaDiagramCell( (MetaDiagram) entity);
      // Default Size for the new Vertex with the new entity within
      size = MetaDiagramView.getSize((MetaDiagram) entity);
      
    }
    else

    if (entity.getClass().equals(MetaRelationship.class)) {
      vertex = new MetaRelationshipCell( (MetaRelationship) entity);
      // Default Size for the new Vertex with the new entity within
      size = MetaRelationshipView.getSize((MetaRelationship) entity);
      
    }
    else

    if (entity.getClass().equals(MetaRole.class)) {
      vertex = new MetaRoleCell( (MetaRole) entity);
      // Default Size for the new Vertex with the new entity within
      size = MetaRoleView.getSize((MetaRole) entity);
      
    }
    else

    if (entity.getClass().equals(VisualRepresentation.class)) {
      vertex = new VisualRepresentationCell( (VisualRepresentation) entity);
      // Default Size for the new Vertex with the new entity within
      size = VisualRepresentationView.getSize((VisualRepresentation) entity);
      
    }
    else

    if (entity.getClass().equals(BasicRepresentation.class)) {
      vertex = new BasicRepresentationCell( (BasicRepresentation) entity);
      // Default Size for the new Vertex with the new entity within
      size = BasicRepresentationView.getSize((BasicRepresentation) entity);
      
    }
    else

    if (entity.getClass().equals(PropertyField.class)) {
      vertex = new PropertyFieldCell( (PropertyField) entity);
      // Default Size for the new Vertex with the new entity within
      size = PropertyFieldView.getSize((PropertyField) entity);
      
    }
    else

    if (entity.getClass().equals(UMLComment.class)) {
      vertex = new UMLCommentCell( (UMLComment) entity);
      // Default Size for the new Vertex with the new entity within
      size = UMLCommentView.getSize((UMLComment) entity);
      
    }
    else

    if (entity.getClass().equals(PreferredOrder.class)) {
      vertex = new PreferredOrderCell( (PreferredOrder) entity);
      // Default Size for the new Vertex with the new entity within
      size = PreferredOrderView.getSize((PreferredOrder) entity);
      
    }
    else

    if (entity.getClass().equals(Documentation.class)) {
      vertex = new DocumentationCell( (Documentation) entity);
      // Default Size for the new Vertex with the new entity within
      size = DocumentationView.getSize((Documentation) entity);
      
    }
    else

    if (entity.getClass().equals(PropertyOrder.class)) {
      vertex = new PropertyOrderCell( (PropertyOrder) entity);
      // Default Size for the new Vertex with the new entity within
      size = PropertyOrderView.getSize((PropertyOrder) entity);
      
    }
    else

    if (entity.getClass().equals(ExternalTypeWrapper.class)) {
      vertex = new ExternalTypeWrapperCell( (ExternalTypeWrapper) entity);
      // Default Size for the new Vertex with the new entity within
      size = ExternalTypeWrapperView.getSize((ExternalTypeWrapper) entity);
      
    }
    else

    if (entity.getClass().equals(MetaDiagramTypeWrapper.class)) {
      vertex = new MetaDiagramTypeWrapperCell( (MetaDiagramTypeWrapper) entity);
      // Default Size for the new Vertex with the new entity within
      size = MetaDiagramTypeWrapperView.getSize((MetaDiagramTypeWrapper) entity);
      
    }
    else

    if (entity.getClass().equals(MetaObjectTypeWrapper.class)) {
      vertex = new MetaObjectTypeWrapperCell( (MetaObjectTypeWrapper) entity);
      // Default Size for the new Vertex with the new entity within
      size = MetaObjectTypeWrapperView.getSize((MetaObjectTypeWrapper) entity);
      
    }
    else

   {}; // Just in case there is no allowed entity in the diagram

    if (vertex == null) {
JOptionPane.showMessageDialog(this,
		 "Object not allowed in this diagram "+this.getID()+":"+ 
		 entity.getId()+":"+entity.getClass().getName()+
		 this.getClass().getName(),"Warning", JOptionPane.WARNING_MESSAGE);    }
    else {

      // Add a Bounds Attribute to the Map
      GraphConstants.setBounds(map, new Rectangle(point, size));

      // Construct a Map from cells to Maps (for insert)
      Hashtable attributes = new Hashtable();
      // Associate the Vertex with its Attributes
      attributes.put(vertex, map);
      // Insert the Vertex and its Attributes
      this.getModel().insert(new Object[] {vertex},attributes
                             , null, null, null);
      getGraphLayoutCache().setVisible(vertex,true);// makes the cell visible because
      // the graphlayoutcache has partial set to true  
        // waits for the cellview to be created
		boolean created=false;
		VertexView vv=null;
		while (!created){
			CellView[] cellviews = this.getGraphLayoutCache().getCellViews();
			for (CellView cv:cellviews){
				if (cv.getCell()==vertex){
					// created!
					created=true;
					vv=(VertexView)cv;
				}
			}
			try {
				Thread.currentThread().sleep(10);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		// This should be used when the corresponding view for the entity has containers!
		// It can be known by inspecting its renderer. To get it, a cellview is needed,
		// but the cellview is created after a while via succesive callbacks to
		// the view factories

		if (!ListenerContainer.evaluate((CompositeRenderer) vv.getRenderer(),entity,null).isEmpty()){
			// there are container renderers that need new cells corresponding to children to
			// be inserted

						Hashtable renderers = ListenerContainer.evaluate((CompositeRenderer) vv.getRenderer(),entity,null);
			for (String field:renderers.keySet()){
				Method obtainenumeration;
				try {
					obtainenumeration = entity.getClass().getMethod("get"+field+"Elements");
					Enumeration  enom=(Enumeration) obtainenumeration.invoke(entity,new Object[]{});
					while (enom.hasMoreElements()){
						DefaultGraphCell child=this.insertDuplicated(new Point(40,10), enom.nextElement());
						try {
							getListenerContainer().setParent(child,vertex);
						} catch (WrongParent e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					} 
				} catch (SecurityException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (NoSuchMethodException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				}
							
		}
		
                             
    }
   return vertex;

  }


 public synchronized JGraph cloneJGraph(IDEState ids){

		

		 MetamodelModelJGraph jg=new  MetamodelModelJGraph(
				(MetamodelDataEntity) this.mde,name, ids.om,
				new Model(ids),new BasicMarqueeHandler(),ids.prefs); 

		this.setSelectionCells(getGraphLayoutCache().getCells(false,true,false,false));
		Action copyaction =new EventRedirectorForGraphCopy(this,this.getTransferHandler().getCopyAction(),null	); 			
		Action pasteaction =new EventRedirectorPasteForGraphCopy(jg,jg.getTransferHandler().getPasteAction(),null	);
		copyaction.actionPerformed(new ActionEvent(this,0,"hello"));		
		pasteaction.actionPerformed(new ActionEvent(this,0,"hello"));
		jg.invalidate();
		jg.doLayout();
		
		return jg;

	}


  public String toString() {
    return this.getID();
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy