KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > tree > command > CreateAndSelectSubFolderCommand


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//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 JavaDoc;
21 import javax.swing.tree.TreeNode JavaDoc;
22 import javax.swing.tree.TreePath JavaDoc;
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 JavaDoc tree;
43
44     private IMailFolder childFolder;
45
46     public CreateAndSelectSubFolderCommand(JTree JavaDoc 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 JavaDoc {
58         if (success) {
59             /*
60              * MailInterface.treeModel.nodeStructureChanged(parentFolder);
61              */

62
63             // select node in JTree
64
TreeNode JavaDoc[] nodes = childFolder.getPath();
65             tree.setSelectionPath(new TreePath JavaDoc(nodes));
66         }
67     }
68
69     /**
70      * @see org.columba.api.command.Command#execute(Worker)
71      */

72     public void execute(IWorkerStatusController worker) throws Exception JavaDoc {
73         parentFolder = (IMailFolder) ((IMailFolderCommandReference) getReference())
74                 .getSourceFolder();
75
76         String JavaDoc name = ((IMailFolderCommandReference) getReference())
77                 .getFolderName();
78
79         try {
80             childFolder = FolderFactory.getInstance().createDefaultChild(
81                     parentFolder, name);
82
83             // if folder creation failed
84
// -> don't update tree ui
85
if (childFolder == null) {
86                 success = false;
87             }
88         } catch (Exception JavaDoc ex) {
89             success = false;
90             throw ex;
91         }
92     }
93 }
Popular Tags