KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.text.MessageFormat JavaDoc;
21
22 import javax.swing.JOptionPane 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.core.gui.frame.FrameManager;
29 import org.columba.mail.command.IMailFolderCommandReference;
30 import org.columba.mail.folder.FolderCreationException;
31 import org.columba.mail.folder.FolderFactory;
32 import org.columba.mail.folder.IMailFolder;
33 import org.columba.mail.util.MailResourceLoader;
34
35 /**
36  * Create subfolder command.
37  *
38  * @author Timo Stich (tstich@users.sourceforge.net)
39  * @author fdietz
40  */

41 public class CreateSubFolderCommand extends Command {
42
43     private IMailFolder parentFolder;
44
45     /**
46      * Constructor for CreateSubFolderCommand.
47      *
48      * @param references
49      */

50     public CreateSubFolderCommand(ICommandReference reference) {
51         super(reference);
52     }
53
54     /**
55      * @see org.columba.api.command.Command#execute(Worker)
56      */

57     public void execute(IWorkerStatusController worker) throws Exception JavaDoc {
58         parentFolder = (IMailFolder) ((IMailFolderCommandReference) getReference())
59                 .getSourceFolder();
60
61         String JavaDoc name = ((IMailFolderCommandReference) getReference())
62                 .getFolderName();
63         String JavaDoc type = ((IMailFolderCommandReference) getReference())
64                 .getFolderType();
65
66         try {
67             if (type == null) {
68                 FolderFactory.getInstance()
69                         .createDefaultChild(parentFolder, name);
70             } else {
71                 FolderFactory.getInstance()
72                         .createChild(parentFolder, name, type);
73             }
74         } catch (FolderCreationException ex) {
75             // show error message
76
JOptionPane.showMessageDialog(FrameManager.getInstance()
77                     .getActiveFrame(), MessageFormat.format(
78                     MailResourceLoader.getString("dialog", "folder",
79                             "error_no_subfolder_allowed"),
80                     new String JavaDoc[] { parentFolder.getName() }),
81                     MailResourceLoader.getString("dialog", "folder",
82                             "error_title"), JOptionPane.ERROR_MESSAGE);
83         }
84     }
85
86 }
Popular Tags