KickJava   Java API By Example, From Geeks To Geeks.

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


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.ImportCalendarCommand;
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  * Import all calendar events into selected calendar.
43  * <p>
44  * User is prompted with an open file dialog to select one or multiple iCal
45  * file.
46  *
47  * @author fdietz
48  *
49  */

50 public class ImportCalendarAction extends AbstractColumbaAction implements
51         ICalendarSelectionChangedListener {
52
53     public ImportCalendarAction(IFrameMediator frameMediator) {
54         super(frameMediator, "Import Calendar");
55
56         setEnabled(false);
57
58         ICalendarMediator m = (ICalendarMediator) getFrameMediator();
59         ICalendarListView list = m.getListView();
60
61         list.addSelectionChangedListener(this);
62
63     }
64
65     public void actionPerformed(ActionEvent JavaDoc e) {
66         ICalendarMediator m = (ICalendarMediator) getFrameMediator();
67         ICalendarListView list = m.getListView();
68
69         // get selected calendar id
70
ICalendarItem calendar = list.getSelected();
71
72         if (calendar == null) {
73             JOptionPane.showMessageDialog(FrameManager.getInstance()
74                     .getActiveFrame(),
75                     "No calendar for import selected.");
76             return;
77         }
78
79         JFileChooser JavaDoc fc = new JFileChooser JavaDoc();
80         fc.setMultiSelectionEnabled(true);
81         fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
82         fc.setFileHidingEnabled(false);
83
84         if (fc.showOpenDialog(frameMediator.getContainer().getFrame()) == JFileChooser.APPROVE_OPTION) {
85             File JavaDoc[] sourceFiles = fc.getSelectedFiles();
86
87             if (sourceFiles.length >= 1) {
88                 ICalendarStore store = CalendarStoreFactory.getInstance()
89                         .getLocaleStore();
90
91                 Command command = new ImportCalendarCommand(
92                         new CalendarCommandReference(store, calendar), sourceFiles);
93
94                 CommandProcessor.getInstance().addOp(command);
95
96             }
97         }
98     }
99
100     public void selectionChanged(CalendarSelectionChangedEvent event) {
101         if (event.getSelection() != null)
102             setEnabled(true);
103         else
104             setEnabled(false);
105
106     }
107 }
108
Popular Tags