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:
022: import javax.swing.JOptionPane;
023:
024: import org.columba.api.gui.frame.IFrameMediator;
025: import org.columba.calendar.base.api.IActivity;
026: import org.columba.calendar.model.api.IEvent;
027: import org.columba.calendar.model.api.IEventInfo;
028: import org.columba.calendar.store.CalendarStoreFactory;
029: import org.columba.calendar.store.api.ICalendarStore;
030: import org.columba.calendar.store.api.StoreException;
031: import org.columba.calendar.ui.calendar.api.ActivitySelectionChangedEvent;
032: import org.columba.calendar.ui.calendar.api.IActivitySelectionChangedListener;
033: import org.columba.calendar.ui.calendar.api.ICalendarView;
034: import org.columba.calendar.ui.dialog.EditEventDialog;
035: import org.columba.calendar.ui.frame.api.ICalendarMediator;
036: import org.columba.core.gui.action.AbstractColumbaAction;
037: import org.columba.core.gui.frame.FrameManager;
038:
039: /**
040: * Edit activity.
041: *
042: * @author fdietz
043: *
044: */
045:
046: public class EditActivityAction extends AbstractColumbaAction implements
047: IActivitySelectionChangedListener {
048:
049: public EditActivityAction(IFrameMediator frameMediator) {
050: super (frameMediator, "Edit Activity");
051:
052: putValue(AbstractColumbaAction.TOOLBAR_NAME, "Edit");
053: setShowToolBarText(true);
054:
055: // putValue(AbstractColumbaAction.LARGE_ICON, ResourceLoader
056: // .getImageIcon("new_appointment-32.png"));
057: // putValue(AbstractColumbaAction.SMALL_ICON, ResourceLoader
058: // .getImageIcon("new_appointment.png"));
059: setEnabled(false);
060:
061: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
062: m.getCalendarView().addSelectionChangedListener(this );
063: }
064:
065: public void actionPerformed(ActionEvent e) {
066: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
067:
068: ICalendarView c = m.getCalendarView();
069:
070: IActivity activity = c.getSelectedActivity();
071:
072: String id = (String) activity.getId();
073:
074: ICalendarStore store = CalendarStoreFactory.getInstance()
075: .getLocaleStore();
076:
077: // retrieve event from store
078: try {
079: IEventInfo model = (IEventInfo) store.get(id);
080:
081: EditEventDialog dialog = new EditEventDialog(m
082: .getContainer().getFrame(), model);
083: if (dialog.success()) {
084: IEventInfo updatedModel = dialog.getModel();
085:
086: // update store
087: store.modify(id, updatedModel);
088: }
089:
090: } catch (StoreException e1) {
091: JOptionPane.showMessageDialog(FrameManager.getInstance()
092: .getActiveFrame(), e1.getMessage());
093: e1.printStackTrace();
094: }
095:
096: }
097:
098: public void selectionChanged(ActivitySelectionChangedEvent event) {
099:
100: if (event.getSelection().length == 0)
101: setEnabled(false);
102: else
103: setEnabled(true);
104:
105: }
106:
107: }
|