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 java.text.MessageFormat;
21:
22: import javax.swing.JOptionPane;
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)
58: throws Exception {
59: parentFolder = (IMailFolder) ((IMailFolderCommandReference) getReference())
60: .getSourceFolder();
61:
62: String name = ((IMailFolderCommandReference) getReference())
63: .getFolderName();
64: String type = ((IMailFolderCommandReference) getReference())
65: .getFolderType();
66:
67: try {
68: if (type == null) {
69: FolderFactory.getInstance().createDefaultChild(
70: parentFolder, name);
71: } else {
72: FolderFactory.getInstance().createChild(parentFolder,
73: name, type);
74: }
75: } catch (FolderCreationException ex) {
76: // show error message
77: JOptionPane.showMessageDialog(FrameManager.getInstance()
78: .getActiveFrame(), MessageFormat.format(
79: MailResourceLoader.getString("dialog", "folder",
80: "error_no_subfolder_allowed"),
81: new String[] { parentFolder.getName() }),
82: MailResourceLoader.getString("dialog", "folder",
83: "error_title"), JOptionPane.ERROR_MESSAGE);
84: }
85: }
86:
87: }
|