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.calendar.ui.action;
19:
20: import java.awt.event.ActionEvent;
21: import java.io.File;
22:
23: import javax.swing.JFileChooser;
24: import javax.swing.JOptionPane;
25:
26: import org.columba.api.gui.frame.IFrameMediator;
27: import org.columba.calendar.base.api.ICalendarItem;
28: import org.columba.calendar.command.CalendarCommandReference;
29: import org.columba.calendar.command.ExportCalendarCommand;
30: import org.columba.calendar.store.CalendarStoreFactory;
31: import org.columba.calendar.store.api.ICalendarStore;
32: import org.columba.calendar.ui.frame.api.ICalendarMediator;
33: import org.columba.calendar.ui.list.api.CalendarSelectionChangedEvent;
34: import org.columba.calendar.ui.list.api.ICalendarListView;
35: import org.columba.calendar.ui.list.api.ICalendarSelectionChangedListener;
36: import org.columba.core.command.Command;
37: import org.columba.core.command.CommandProcessor;
38: import org.columba.core.gui.action.AbstractColumbaAction;
39: import org.columba.core.gui.frame.FrameManager;
40:
41: public class ExportCalendarAction extends AbstractColumbaAction
42: implements ICalendarSelectionChangedListener {
43:
44: public ExportCalendarAction(IFrameMediator frameMediator) {
45: super (frameMediator, "Export Calendar");
46:
47: setEnabled(false);
48:
49: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
50: ICalendarListView list = m.getListView();
51:
52: list.addSelectionChangedListener(this );
53: }
54:
55: public void actionPerformed(ActionEvent e) {
56: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
57: ICalendarListView list = m.getListView();
58:
59: // get selected calendar
60: ICalendarItem calendar = list.getSelected();
61:
62: if (calendar == null) {
63: JOptionPane.showMessageDialog(FrameManager.getInstance()
64: .getActiveFrame(),
65: "No calendar for export selected.");
66: return;
67: }
68:
69: JFileChooser fc = new JFileChooser();
70: fc.setMultiSelectionEnabled(false);
71: fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
72: fc.setFileHidingEnabled(false);
73:
74: if (fc.showSaveDialog(frameMediator.getContainer().getFrame()) == JFileChooser.APPROVE_OPTION) {
75: File destFile = fc.getSelectedFile();
76:
77: ICalendarStore store = CalendarStoreFactory.getInstance()
78: .getLocaleStore();
79:
80: Command command = new ExportCalendarCommand(
81: new CalendarCommandReference(store, calendar),
82: destFile);
83:
84: CommandProcessor.getInstance().addOp(command);
85:
86: }
87:
88: }
89:
90: public void selectionChanged(CalendarSelectionChangedEvent event) {
91: if (event.getSelection() != null)
92: setEnabled(true);
93: else
94: setEnabled(false);
95:
96: }
97:
98: }
|