01: package net.sourceforge.squirrel_sql.plugins.graph;
02:
03: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
04: import net.sourceforge.squirrel_sql.client.session.action.ISessionAction;
05: import net.sourceforge.squirrel_sql.client.session.ISession;
06: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.ObjectTreeNode;
07: import net.sourceforge.squirrel_sql.client.IApplication;
08: import net.sourceforge.squirrel_sql.fw.util.Resources;
09: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
10:
11: import java.awt.event.ActionEvent;
12: import java.awt.*;
13: import java.util.Vector;
14:
15: public class AddToGraphAction extends SquirrelAction implements
16: ISessionAction {
17:
18: /**
19: * Current session.
20: */
21: protected ISession _session;
22:
23: /**
24: * Current plugin.
25: */
26: protected final GraphPlugin _plugin;
27:
28: public AddToGraphAction(IApplication app, Resources rsrc,
29: GraphPlugin plugin) {
30: super (app, rsrc);
31: _plugin = plugin;
32: }
33:
34: public void actionPerformed(ActionEvent evt) {
35: if (_session != null) {
36: ObjectTreeNode[] selectedNodes = _session.getSessionSheet()
37: .getObjectTreePanel().getSelectedNodes();
38:
39: Point[] refCascadeIndent = new Point[1];
40: GraphController toAddTo = null;
41:
42: for (int i = 0; i < selectedNodes.length; i++) {
43: if (selectedNodes[i].getDatabaseObjectType() == DatabaseObjectType.TABLE)
44: ;
45: {
46: if (null == toAddTo) {
47: GraphController[] controllers = _plugin
48: .getGraphControllers(_session);
49: if (0 == controllers.length) {
50: toAddTo = _plugin
51: .createNewGraphControllerForSession(_session);
52: } else {
53: GraphSelectionDialogController dlg = new GraphSelectionDialogController(
54: controllers, _session
55: .getApplication()
56: .getMainFrame());
57: dlg.doModal();
58:
59: if (false == dlg.isOK()) {
60: return;
61: }
62: if (null == dlg.getSelectedController()) {
63: toAddTo = _plugin
64: .createNewGraphControllerForSession(_session);
65: } else {
66: toAddTo = dlg.getSelectedController();
67: }
68: }
69: }
70:
71: toAddTo
72: .addTable(selectedNodes[i],
73: refCascadeIndent);
74: }
75:
76: }
77: }
78: }
79:
80: /**
81: * Set the current session.
82: *
83: * @param session The current session.
84: */
85: public void setSession(ISession session) {
86: _session = session;
87: }
88: }
|