01: package net.sourceforge.squirrel_sql.plugins.favs;
02:
03: /*
04: * Copyright (C) 2001 Colin Bell
05: * colbell@users.sourceforge.net
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21: import javax.swing.tree.TreePath;
22:
23: import net.sourceforge.squirrel_sql.client.IApplication;
24: import net.sourceforge.squirrel_sql.fw.util.StringManager;
25: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
26:
27: public class NewSavedQueriesFolderCommand {
28:
29: private static final StringManager s_stringMgr = StringManagerFactory
30: .getStringManager(NewSavedQueriesFolderCommand.class);
31:
32: @SuppressWarnings("unused")
33: private IApplication _app;
34: private QueryTree _tree;
35: private TreePath _path;
36:
37: public NewSavedQueriesFolderCommand(IApplication app,
38: QueryTree tree, TreePath path)
39: throws IllegalArgumentException {
40: super ();
41: if (app == null) {
42: throw new IllegalArgumentException(
43: "Null IApplication passed");
44: }
45: if (tree == null) {
46: throw new IllegalArgumentException("Null QueryTree passed");
47: }
48: //if (path == null) {
49: // throw new IllegalArgumentException("Null TreePath passed");
50: //}
51:
52: _app = app;
53: _tree = tree;
54: _path = path;
55: }
56:
57: public void execute() {
58: FolderNode rootNode = (FolderNode) _tree.getModel().getRoot();
59: FolderNode parentNode = null;
60: if (_path == null) {
61: parentNode = rootNode;
62: } else {
63: Object obj = _path.getLastPathComponent();
64: if (obj == null) {
65: parentNode = rootNode;
66: } else if (obj instanceof FolderNode) {
67: parentNode = (FolderNode) obj;
68: }
69: }
70: if (parentNode != null) {
71: // i18n[favs.newFolder=New Folder]
72: final Folder folder = new Folder(null, s_stringMgr
73: .getString("favs.newFolder")); // ?? i18n
74: final FolderNode newNode = new FolderNode(folder);
75: parentNode.getFolder().addSubFolder(folder);
76: parentNode.add(newNode);
77: _tree.getTypedModel().nodeStructureChanged(parentNode);
78:
79: TreePath newNodePath = null;
80: if (_path != null) {
81: newNodePath = _path.pathByAddingChild(newNode);
82: } else {
83: newNodePath = new TreePath(new FolderNode[] { rootNode,
84: newNode });
85: }
86: if (newNodePath != null) {
87: _tree.makeVisible(newNodePath);
88: _tree.expandPath(newNodePath);
89: _tree.startEditingAtPath(newNodePath);
90: }
91: }
92: }
93: }
|