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
/**
* 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("MetaDiagramTypeWrapper");
entities.add("MetaObjectTypeWrapper");
return entities;
}
public DefaultGraphCell createCell(String entity) throws InvalidEntity{
if (entity.equalsIgnoreCase("MetaObject")) {
MetaObject nentity=new 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")) {
MetaDiagram nentity=new 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")) {
MetaRelationship nentity=new 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")) {
MetaRole nentity=new 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")) {
VisualRepresentation nentity=new 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")) {
BasicRepresentation nentity=new 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")) {
PropertyField nentity=new 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")) {
UMLComment nentity=new 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")) {
PreferredOrder nentity=new 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")) {
Documentation nentity=new 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")) {
PropertyOrder nentity=new 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")) {
ExternalTypeWrapper nentity=new 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("MetaDiagramTypeWrapper")) {
MetaDiagramTypeWrapper nentity=new MetaDiagramTypeWrapper(((Model)getModel()).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=new MetaObjectTypeWrapper(((Model)getModel()).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((MetaObject)entity);
}
else
if (entity.getType().equalsIgnoreCase("MetaDiagram")) {
return MetaDiagramView.getSize((MetaDiagram)entity);
}
else
if (entity.getType().equalsIgnoreCase("MetaRelationship")) {
return MetaRelationshipView.getSize((MetaRelationship)entity);
}
else
if (entity.getType().equalsIgnoreCase("MetaRole")) {
return MetaRoleView.getSize((MetaRole)entity);
}
else
if (entity.getType().equalsIgnoreCase("VisualRepresentation")) {
return VisualRepresentationView.getSize((VisualRepresentation)entity);
}
else
if (entity.getType().equalsIgnoreCase("BasicRepresentation")) {
return BasicRepresentationView.getSize((BasicRepresentation)entity);
}
else
if (entity.getType().equalsIgnoreCase("PropertyField")) {
return PropertyFieldView.getSize((PropertyField)entity);
}
else
if (entity.getType().equalsIgnoreCase("UMLComment")) {
return UMLCommentView.getSize((UMLComment)entity);
}
else
if (entity.getType().equalsIgnoreCase("PreferredOrder")) {
return PreferredOrderView.getSize((PreferredOrder)entity);
}
else
if (entity.getType().equalsIgnoreCase("Documentation")) {
return DocumentationView.getSize((Documentation)entity);
}
else
if (entity.getType().equalsIgnoreCase("PropertyOrder")) {
return PropertyOrderView.getSize((PropertyOrder)entity);
}
else
if (entity.getType().equalsIgnoreCase("ExternalTypeWrapper")) {
return ExternalTypeWrapperView.getSize((ExternalTypeWrapper)entity);
}
else
if (entity.getType().equalsIgnoreCase("MetaDiagramTypeWrapper")) {
return MetaDiagramTypeWrapperView.getSize((MetaDiagramTypeWrapper)entity);
}
else
if (entity.getType().equalsIgnoreCase("MetaObjectTypeWrapper")) {
return MetaObjectTypeWrapperView.getSize((MetaObjectTypeWrapper)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(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) {
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