KickJava   Java API By Example, From Geeks To Geeks.

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


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.IActivity;
28 import org.columba.calendar.command.CalendarCommandReference;
29 import org.columba.calendar.command.SaveEventToFileCommand;
30 import org.columba.calendar.store.CalendarStoreFactory;
31 import org.columba.calendar.store.api.ICalendarStore;
32 import org.columba.calendar.ui.calendar.api.ActivitySelectionChangedEvent;
33 import org.columba.calendar.ui.calendar.api.IActivitySelectionChangedListener;
34 import org.columba.calendar.ui.calendar.api.ICalendarView;
35 import org.columba.calendar.ui.frame.api.ICalendarMediator;
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 import org.columba.core.resourceloader.IconKeys;
41 import org.columba.core.resourceloader.ImageLoader;
42
43 public class SaveAsAction extends AbstractColumbaAction implements
44         IActivitySelectionChangedListener {
45
46     public SaveAsAction(IFrameMediator frameMediator) {
47         super(frameMediator, "Save As...");
48
49         setEnabled(false);
50
51         putValue(AbstractColumbaAction.SMALL_ICON, ImageLoader.getSmallIcon(IconKeys.DOCUMENT_SAVE_AS));
52         putValue(AbstractColumbaAction.LARGE_ICON, ImageLoader.getIcon(IconKeys.DOCUMENT_SAVE_AS));
53
54         ICalendarMediator m = (ICalendarMediator) getFrameMediator();
55         m.getCalendarView().addSelectionChangedListener(this);
56     }
57
58     public void actionPerformed(ActionEvent JavaDoc e) {
59         ICalendarMediator m = (ICalendarMediator) getFrameMediator();
60         ICalendarView c = m.getCalendarView();
61         IActivity activity = c.getSelectedActivity();
62
63         String JavaDoc id = (String JavaDoc) activity.getId();
64
65         if (id == null) {
66             JOptionPane
67                     .showMessageDialog(FrameManager.getInstance()
68                             .getActiveFrame(), "No event for export selected.");
69             return;
70         }
71
72         JFileChooser JavaDoc fc = new JFileChooser JavaDoc();
73         fc.setMultiSelectionEnabled(false);
74         fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
75         fc.setFileHidingEnabled(false);
76
77         if (fc.showSaveDialog(frameMediator.getContainer().getFrame()) == JFileChooser.APPROVE_OPTION) {
78             File JavaDoc destFile = fc.getSelectedFile();
79
80             ICalendarStore store = CalendarStoreFactory.getInstance()
81                     .getLocaleStore();
82
83             Command command = new SaveEventToFileCommand(
84                     new CalendarCommandReference(store, activity), destFile);
85
86             CommandProcessor.getInstance().addOp(command);
87
88         }
89     }
90
91     public void selectionChanged(ActivitySelectionChangedEvent event) {
92         if (event.getSelection().length == 0)
93             setEnabled(false);
94         else
95             setEnabled(true);
96
97     }
98 }
99
Popular Tags