01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18: package org.columba.mail.gui.tree.command;
19:
20: import javax.swing.JTree;
21: import javax.swing.tree.TreeNode;
22: import javax.swing.tree.TreePath;
23:
24: import org.columba.api.command.ICommandReference;
25: import org.columba.api.command.IWorkerStatusController;
26: import org.columba.core.command.Command;
27: import org.columba.core.command.Worker;
28: import org.columba.mail.command.IMailFolderCommandReference;
29: import org.columba.mail.folder.FolderFactory;
30: import org.columba.mail.folder.IMailFolder;
31:
32: /**
33: * @author fdietz
34: *
35: */
36: public class CreateAndSelectSubFolderCommand extends Command {
37:
38: private IMailFolder parentFolder;
39:
40: private boolean success;
41:
42: private JTree tree;
43:
44: private IMailFolder childFolder;
45:
46: public CreateAndSelectSubFolderCommand(JTree tree,
47: ICommandReference reference) {
48: super (reference);
49:
50: success = true;
51: this .tree = tree;
52: }
53:
54: /**
55: * @see org.columba.api.command.Command#updateGUI()
56: */
57: public void updateGUI() throws Exception {
58: if (success) {
59: /*
60: * MailInterface.treeModel.nodeStructureChanged(parentFolder);
61: */
62:
63: // select node in JTree
64: TreeNode[] nodes = childFolder.getPath();
65: tree.setSelectionPath(new TreePath(nodes));
66: }
67: }
68:
69: /**
70: * @see org.columba.api.command.Command#execute(Worker)
71: */
72: public void execute(IWorkerStatusController worker)
73: throws Exception {
74: parentFolder = (IMailFolder) ((IMailFolderCommandReference) getReference())
75: .getSourceFolder();
76:
77: String name = ((IMailFolderCommandReference) getReference())
78: .getFolderName();
79:
80: try {
81: childFolder = FolderFactory.getInstance()
82: .createDefaultChild(parentFolder, name);
83:
84: // if folder creation failed
85: // -> don't update tree ui
86: if (childFolder == null) {
87: success = false;
88: }
89: } catch (Exception ex) {
90: success = false;
91: throw ex;
92: }
93: }
94: }
|