KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > calendar > ui > action > ExportCalendarAction


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