commonsrc.ingenias.editor.ObjectTreeMenuEntries Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
The INGENIAS Meta-Editor core. It is a set of facilities to generate an editor from a detailed xml description
/**
* Copyright (C) 2010 Jorge J. Gomez-Sanz
*
* 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;
import ingenias.editor.entities.Entity;
import ingenias.editor.utils.DialogWindows;
import ingenias.exception.NotInitialised;
import ingenias.exception.NullEntity;
import ingenias.generator.browser.Browser;
import ingenias.generator.browser.BrowserImp;
import ingenias.generator.browser.Graph;
import ingenias.generator.browser.GraphEntity;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.util.Enumeration;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import org.jgraph.JGraph;
public class ObjectTreeMenuEntries {
private IDEState ids;
private GUIResources resources;
private Browser browser;
public ObjectTreeMenuEntries(IDEState ids, GUIResources resources){
this.ids=ids;
this.resources=resources;
browser=new BrowserImp(ids);
}
public JPopupMenu menuObjectTree(MouseEvent me1) {
JPopupMenu menu = new JPopupMenu();
final MouseEvent me = me1;
final TreePath tp = ids.om.arbolObjetos.getSelectionPath();
final TreePath[] tps = ids.om.arbolObjetos.getSelectionPaths();
if (tp != null && ids.gm.getModel(tp.getPath()) == null) {
JGraph jg = ids.gm.getCurrent();
final javax.swing.tree.DefaultMutableTreeNode dmtn =
(javax.swing.tree.DefaultMutableTreeNode) tp.getLastPathComponent();
if (dmtn != null && dmtn.getUserObject()instanceof Entity) {
Entity entity=(Entity) dmtn.getUserObject();
// Edit
menu.add(
new AbstractAction("Add to current graph") {
public void actionPerformed(ActionEvent e) {
Entity sel = (Entity) dmtn.getUserObject();
ids.editor.insertDuplicated(new Point(0, 0), sel);
ids.otherChange();
}
});
menu.add(
new AbstractAction("Edit") {
public void actionPerformed(ActionEvent e) {
Entity sel = (Entity) dmtn.getUserObject();
ingenias.editor.editiondialog.GeneralEditionFrame jf = new ingenias.editor.editiondialog.GeneralEditionFrame(ids.editor,
ids.om,ids.gm, resources.getMainFrame(),
"Edit " + sel.getId(), sel);
jf.setLocation(DialogWindows.getCenter(jf.getSize(),resources.getMainFrame()));
jf.pack();
jf.setVisible(true);
if (jf.getStatus()==jf.ACCEPTED){
ids.om.reload();
resources.getArbolObjetos().invalidate();
resources.getMainFrame().repaint();
ids.setChanged(true);
resources.setUnChanged();
}
}
});
menu.add(
new AbstractAction("Remove") {
public void actionPerformed(ActionEvent e) {
for (int k=0;k");
Graph[] graphs=browser.getGraphs();
for (int k=0;k"+graphs[k].getName()+"");
}
} catch (NullEntity e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
result.append("");
resources.getSearchDiagramPanel().setText(result.toString());
resources.focusSearchPane();
}
}
});
} else {
menu.add(
new AbstractAction("Expand") {
public void actionPerformed(ActionEvent e){
Enumeration enumNodes=dmtn.depthFirstEnumeration();
while (enumNodes.hasMoreElements()){
DefaultMutableTreeNode next=enumNodes.nextElement();
resources.getArbolObjetos().expandPath(new TreePath(next.getPath()));
}
}
});
}
}
return menu;
}
}