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.IActivity;
028: import org.columba.calendar.command.CalendarCommandReference;
029: import org.columba.calendar.command.SaveEventToFileCommand;
030: import org.columba.calendar.store.CalendarStoreFactory;
031: import org.columba.calendar.store.api.ICalendarStore;
032: import org.columba.calendar.ui.calendar.api.ActivitySelectionChangedEvent;
033: import org.columba.calendar.ui.calendar.api.IActivitySelectionChangedListener;
034: import org.columba.calendar.ui.calendar.api.ICalendarView;
035: import org.columba.calendar.ui.frame.api.ICalendarMediator;
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: import org.columba.core.resourceloader.IconKeys;
041: import org.columba.core.resourceloader.ImageLoader;
042:
043: public class SaveAsAction extends AbstractColumbaAction implements
044: IActivitySelectionChangedListener {
045:
046: public SaveAsAction(IFrameMediator frameMediator) {
047: super (frameMediator, "Save As...");
048:
049: setEnabled(false);
050:
051: putValue(AbstractColumbaAction.SMALL_ICON, ImageLoader
052: .getSmallIcon(IconKeys.DOCUMENT_SAVE_AS));
053: putValue(AbstractColumbaAction.LARGE_ICON, ImageLoader
054: .getIcon(IconKeys.DOCUMENT_SAVE_AS));
055:
056: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
057: m.getCalendarView().addSelectionChangedListener(this );
058: }
059:
060: public void actionPerformed(ActionEvent e) {
061: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
062: ICalendarView c = m.getCalendarView();
063: IActivity activity = c.getSelectedActivity();
064:
065: String id = (String) activity.getId();
066:
067: if (id == null) {
068: JOptionPane.showMessageDialog(FrameManager.getInstance()
069: .getActiveFrame(), "No event for export selected.");
070: return;
071: }
072:
073: JFileChooser fc = new JFileChooser();
074: fc.setMultiSelectionEnabled(false);
075: fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
076: fc.setFileHidingEnabled(false);
077:
078: if (fc.showSaveDialog(frameMediator.getContainer().getFrame()) == JFileChooser.APPROVE_OPTION) {
079: File destFile = fc.getSelectedFile();
080:
081: ICalendarStore store = CalendarStoreFactory.getInstance()
082: .getLocaleStore();
083:
084: Command command = new SaveEventToFileCommand(
085: new CalendarCommandReference(store, activity),
086: destFile);
087:
088: CommandProcessor.getInstance().addOp(command);
089:
090: }
091: }
092:
093: public void selectionChanged(ActivitySelectionChangedEvent event) {
094: if (event.getSelection().length == 0)
095: setEnabled(false);
096: else
097: setEnabled(true);
098:
099: }
100: }
|