001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.calendar.ui.action;
019:
020: import java.awt.event.ActionEvent;
021: import java.io.File;
022:
023: import javax.swing.JFileChooser;
024: import javax.swing.JOptionPane;
025:
026: import org.columba.api.gui.frame.IFrameMediator;
027: import org.columba.calendar.base.api.ICalendarItem;
028: import org.columba.calendar.command.CalendarCommandReference;
029: import org.columba.calendar.command.ImportCalendarCommand;
030: import org.columba.calendar.store.CalendarStoreFactory;
031: import org.columba.calendar.store.api.ICalendarStore;
032: import org.columba.calendar.ui.frame.api.ICalendarMediator;
033: import org.columba.calendar.ui.list.api.CalendarSelectionChangedEvent;
034: import org.columba.calendar.ui.list.api.ICalendarListView;
035: import org.columba.calendar.ui.list.api.ICalendarSelectionChangedListener;
036: import org.columba.core.command.Command;
037: import org.columba.core.command.CommandProcessor;
038: import org.columba.core.gui.action.AbstractColumbaAction;
039: import org.columba.core.gui.frame.FrameManager;
040:
041: /**
042: * Import all calendar events into selected calendar.
043: * <p>
044: * User is prompted with an open file dialog to select one or multiple iCal
045: * file.
046: *
047: * @author fdietz
048: *
049: */
050: public class ImportCalendarAction extends AbstractColumbaAction
051: implements ICalendarSelectionChangedListener {
052:
053: public ImportCalendarAction(IFrameMediator frameMediator) {
054: super (frameMediator, "Import Calendar");
055:
056: setEnabled(false);
057:
058: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
059: ICalendarListView list = m.getListView();
060:
061: list.addSelectionChangedListener(this );
062:
063: }
064:
065: public void actionPerformed(ActionEvent e) {
066: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
067: ICalendarListView list = m.getListView();
068:
069: // get selected calendar id
070: ICalendarItem calendar = list.getSelected();
071:
072: if (calendar == null) {
073: JOptionPane.showMessageDialog(FrameManager.getInstance()
074: .getActiveFrame(),
075: "No calendar for import selected.");
076: return;
077: }
078:
079: JFileChooser fc = new JFileChooser();
080: fc.setMultiSelectionEnabled(true);
081: fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
082: fc.setFileHidingEnabled(false);
083:
084: if (fc.showOpenDialog(frameMediator.getContainer().getFrame()) == JFileChooser.APPROVE_OPTION) {
085: File[] sourceFiles = fc.getSelectedFiles();
086:
087: if (sourceFiles.length >= 1) {
088: ICalendarStore store = CalendarStoreFactory
089: .getInstance().getLocaleStore();
090:
091: Command command = new ImportCalendarCommand(
092: new CalendarCommandReference(store, calendar),
093: sourceFiles);
094:
095: CommandProcessor.getInstance().addOp(command);
096:
097: }
098: }
099: }
100:
101: public void selectionChanged(CalendarSelectionChangedEvent event) {
102: if (event.getSelection() != null)
103: setEnabled(true);
104: else
105: setEnabled(false);
106:
107: }
108: }
|