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 java.awt.Frame;
22: import java.text.MessageFormat;
23:
24: import javax.swing.tree.TreeNode;
25: import javax.swing.tree.TreePath;
26:
27: import net.sourceforge.squirrel_sql.fw.gui.Dialogs;
28: import net.sourceforge.squirrel_sql.fw.util.StringManager;
29: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
30:
31: public class DeleteSavedQueriesFolderCommand {
32:
33: private static final StringManager s_stringMgr = StringManagerFactory
34: .getStringManager(DeleteSavedQueriesFolderCommand.class);
35:
36: /**
37: * This interface defines locale specific strings. This should be
38: * replaced with a property file.
39: */
40: private static class i18n {
41:
42: // i18n[favs.deletelFolder=Are you sure to want to delete the folder \"{0}\" and all of its contents?]
43: static String MSG_CONFIRM = s_stringMgr
44: .getString("favs.deletelFolder");
45: }
46:
47: private Frame _frame;
48: private QueryTree _tree;
49: private TreePath _path;
50:
51: public DeleteSavedQueriesFolderCommand(Frame frame, QueryTree tree,
52: TreePath path) {
53: super ();
54: _frame = frame;
55: _tree = tree;
56: _path = path;
57: }
58:
59: public void execute() {
60: if (_path != null) {
61: Object obj = _path.getLastPathComponent();
62: if (obj instanceof FolderNode) {
63: FolderNode nodeToDelete = (FolderNode) obj;
64: Object[] args = { nodeToDelete.getName() };
65: String msg = MessageFormat.format(i18n.MSG_CONFIRM,
66: args);
67: if (Dialogs.showYesNo(_frame, msg)) {
68: TreeNode parentNode = nodeToDelete.getParent();
69: if (parentNode instanceof FolderNode) {
70: FolderNode parentFolder = (FolderNode) parentNode;
71: parentFolder.remove(nodeToDelete);
72: parentFolder.getFolder().removeSubFolder(
73: nodeToDelete.getFolder());
74: _tree.getTypedModel().nodeStructureChanged(
75: parentFolder);
76: }
77: }
78: }
79: }
80: }
81: }
|