
ingenias.editor.panels.MetamodelPanel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ingened Show documentation
Show all versions of ingened Show documentation
Meta-language editor built over INGENME. It is the most basic editor to be used in the rest of projects
The 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.panels;
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.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.URL;
import java.util.Map;
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.events.*;
import ingenias.exception.InvalidEntity;
import ingenias.editor.*;
public class MetamodelPanel extends JGraph {
public MetamodelPanel(MetamodelDataEntity mde,
String nombre, Model
m, BasicMarqueeHandler mh) {
super(m, mh);
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 static 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("MetaObjectTypeWrapper");
entities.add("MetaDiagramTypeWrapper");
return entities;
}
public DefaultGraphCell createCell(String entity) throws InvalidEntity{
if (entity.equalsIgnoreCase("MetaObject")) {
ingenias.editor.entities.MetaObject nentity=new ingenias.editor.entities.MetaObject(((Model)getModel()).getNewId("MetaObject"));
DefaultGraphCell vertex = new
MetaObjectCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("MetaDiagram")) {
ingenias.editor.entities.MetaDiagram nentity=new ingenias.editor.entities.MetaDiagram(((Model)getModel()).getNewId("MetaDiagram"));
DefaultGraphCell vertex = new
MetaDiagramCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("MetaRelationship")) {
ingenias.editor.entities.MetaRelationship nentity=new ingenias.editor.entities.MetaRelationship(((Model)getModel()).getNewId("MetaRelationship"));
DefaultGraphCell vertex = new
MetaRelationshipCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("MetaRole")) {
ingenias.editor.entities.MetaRole nentity=new ingenias.editor.entities.MetaRole(((Model)getModel()).getNewId("MetaRole"));
DefaultGraphCell vertex = new
MetaRoleCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("VisualRepresentation")) {
ingenias.editor.entities.VisualRepresentation nentity=new ingenias.editor.entities.VisualRepresentation(((Model)getModel()).getNewId("VisualRepresentation"));
DefaultGraphCell vertex = new
VisualRepresentationCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("BasicRepresentation")) {
ingenias.editor.entities.BasicRepresentation nentity=new ingenias.editor.entities.BasicRepresentation(((Model)getModel()).getNewId("BasicRepresentation"));
DefaultGraphCell vertex = new
BasicRepresentationCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("PropertyField")) {
ingenias.editor.entities.PropertyField nentity=new ingenias.editor.entities.PropertyField(((Model)getModel()).getNewId("PropertyField"));
DefaultGraphCell vertex = new
PropertyFieldCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("UMLComment")) {
ingenias.editor.entities.UMLComment nentity=new ingenias.editor.entities.UMLComment(((Model)getModel()).getNewId("UMLComment"));
DefaultGraphCell vertex = new
UMLCommentCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("PreferredOrder")) {
ingenias.editor.entities.PreferredOrder nentity=new ingenias.editor.entities.PreferredOrder(((Model)getModel()).getNewId("PreferredOrder"));
DefaultGraphCell vertex = new
PreferredOrderCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("Documentation")) {
ingenias.editor.entities.Documentation nentity=new ingenias.editor.entities.Documentation(((Model)getModel()).getNewId("Documentation"));
DefaultGraphCell vertex = new
DocumentationCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("PropertyOrder")) {
ingenias.editor.entities.PropertyOrder nentity=new ingenias.editor.entities.PropertyOrder(((Model)getModel()).getNewId("PropertyOrder"));
DefaultGraphCell vertex = new
PropertyOrderCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("ExternalTypeWrapper")) {
ingenias.editor.entities.ExternalTypeWrapper nentity=new ingenias.editor.entities.ExternalTypeWrapper(((Model)getModel()).getNewId("ExternalTypeWrapper"));
DefaultGraphCell vertex = new
ExternalTypeWrapperCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("MetaObjectTypeWrapper")) {
ingenias.editor.entities.MetaObjectTypeWrapper nentity=new ingenias.editor.entities.MetaObjectTypeWrapper(((Model)getModel()).getNewId("MetaObjectTypeWrapper"));
DefaultGraphCell vertex = new
MetaObjectTypeWrapperCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("MetaDiagramTypeWrapper")) {
ingenias.editor.entities.MetaDiagramTypeWrapper nentity=new ingenias.editor.entities.MetaDiagramTypeWrapper(((Model)getModel()).getNewId("MetaDiagramTypeWrapper"));
DefaultGraphCell vertex = new
MetaDiagramTypeWrapperCell(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("MetaObjectTypeWrapper")) {
return MetaObjectTypeWrapperView.getSize((ingenias.editor.entities.MetaObjectTypeWrapper)entity);
}
else
if (entity.getType().equalsIgnoreCase("MetaDiagramTypeWrapper")) {
return MetaDiagramTypeWrapperView.getSize((ingenias.editor.entities.MetaDiagramTypeWrapper)entity);
}
else
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
// 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);
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
// Construct Vertex with no Label
DefaultGraphCell vertex = null;
Dimension size = null;
if (entity.getClass().equals(ingenias.editor.entities.MetaObject.class)) {
vertex = new MetaObjectCell( (ingenias.editor.entities.MetaObject) entity);
// Default Size for the new Vertex with the new entity within
size = MetaObjectView.getSize((ingenias.editor.entities.MetaObject) entity);
}
else
if (entity.getClass().equals(ingenias.editor.entities.MetaDiagram.class)) {
vertex = new MetaDiagramCell( (ingenias.editor.entities.MetaDiagram) entity);
// Default Size for the new Vertex with the new entity within
size = MetaDiagramView.getSize((ingenias.editor.entities.MetaDiagram) entity);
}
else
if (entity.getClass().equals(ingenias.editor.entities.MetaRelationship.class)) {
vertex = new MetaRelationshipCell( (ingenias.editor.entities.MetaRelationship) entity);
// Default Size for the new Vertex with the new entity within
size = MetaRelationshipView.getSize((ingenias.editor.entities.MetaRelationship) entity);
}
else
if (entity.getClass().equals(ingenias.editor.entities.MetaRole.class)) {
vertex = new MetaRoleCell( (ingenias.editor.entities.MetaRole) entity);
// Default Size for the new Vertex with the new entity within
size = MetaRoleView.getSize((ingenias.editor.entities.MetaRole) entity);
}
else
if (entity.getClass().equals(ingenias.editor.entities.VisualRepresentation.class)) {
vertex = new VisualRepresentationCell( (ingenias.editor.entities.VisualRepresentation) entity);
// Default Size for the new Vertex with the new entity within
size = VisualRepresentationView.getSize((ingenias.editor.entities.VisualRepresentation) entity);
}
else
if (entity.getClass().equals(ingenias.editor.entities.BasicRepresentation.class)) {
vertex = new BasicRepresentationCell( (ingenias.editor.entities.BasicRepresentation) entity);
// Default Size for the new Vertex with the new entity within
size = BasicRepresentationView.getSize((ingenias.editor.entities.BasicRepresentation) entity);
}
else
if (entity.getClass().equals(ingenias.editor.entities.PropertyField.class)) {
vertex = new PropertyFieldCell( (ingenias.editor.entities.PropertyField) entity);
// Default Size for the new Vertex with the new entity within
size = PropertyFieldView.getSize((ingenias.editor.entities.PropertyField) entity);
}
else
if (entity.getClass().equals(ingenias.editor.entities.UMLComment.class)) {
vertex = new UMLCommentCell( (ingenias.editor.entities.UMLComment) entity);
// Default Size for the new Vertex with the new entity within
size = UMLCommentView.getSize((ingenias.editor.entities.UMLComment) entity);
}
else
if (entity.getClass().equals(ingenias.editor.entities.PreferredOrder.class)) {
vertex = new PreferredOrderCell( (ingenias.editor.entities.PreferredOrder) entity);
// Default Size for the new Vertex with the new entity within
size = PreferredOrderView.getSize((ingenias.editor.entities.PreferredOrder) entity);
}
else
if (entity.getClass().equals(ingenias.editor.entities.Documentation.class)) {
vertex = new DocumentationCell( (ingenias.editor.entities.Documentation) entity);
// Default Size for the new Vertex with the new entity within
size = DocumentationView.getSize((ingenias.editor.entities.Documentation) entity);
}
else
if (entity.getClass().equals(ingenias.editor.entities.PropertyOrder.class)) {
vertex = new PropertyOrderCell( (ingenias.editor.entities.PropertyOrder) entity);
// Default Size for the new Vertex with the new entity within
size = PropertyOrderView.getSize((ingenias.editor.entities.PropertyOrder) entity);
}
else
if (entity.getClass().equals(ingenias.editor.entities.ExternalTypeWrapper.class)) {
vertex = new ExternalTypeWrapperCell( (ingenias.editor.entities.ExternalTypeWrapper) entity);
// Default Size for the new Vertex with the new entity within
size = ExternalTypeWrapperView.getSize((ingenias.editor.entities.ExternalTypeWrapper) entity);
}
else
if (entity.getClass().equals(ingenias.editor.entities.MetaObjectTypeWrapper.class)) {
vertex = new MetaObjectTypeWrapperCell( (ingenias.editor.entities.MetaObjectTypeWrapper) entity);
// Default Size for the new Vertex with the new entity within
size = MetaObjectTypeWrapperView.getSize((ingenias.editor.entities.MetaObjectTypeWrapper) entity);
}
else
if (entity.getClass().equals(ingenias.editor.entities.MetaDiagramTypeWrapper.class)) {
vertex = new MetaDiagramTypeWrapperCell( (ingenias.editor.entities.MetaDiagramTypeWrapper) entity);
// Default Size for the new Vertex with the new entity within
size = MetaDiagramTypeWrapperView.getSize((ingenias.editor.entities.MetaDiagramTypeWrapper) entity);
}
else
{}; // Just in case there is no allowed entity in the diagram
if (vertex == null) {
System.err.println(
"Object not allowed in Metamodel diagram :"+
entity.getId()+":"+entity.getClass().getName()+
this.getClass().getName()); }
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);
}
return vertex;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy