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.awt.event.ActionListener;
022: import java.util.Enumeration;
023: import java.util.Hashtable;
024:
025: import javax.swing.JMenuItem;
026:
027: import org.columba.api.gui.frame.IFrameMediator;
028: import org.columba.calendar.base.api.IActivity;
029: import org.columba.calendar.base.api.ICalendarItem;
030: import org.columba.calendar.command.CalendarCommandReference;
031: import org.columba.calendar.command.MoveEventCommand;
032: import org.columba.calendar.config.Config;
033: import org.columba.calendar.config.api.ICalendarList;
034: import org.columba.calendar.store.CalendarStoreFactory;
035: import org.columba.calendar.store.api.ICalendarStore;
036: import org.columba.calendar.ui.calendar.api.ActivitySelectionChangedEvent;
037: import org.columba.calendar.ui.calendar.api.IActivitySelectionChangedListener;
038: import org.columba.calendar.ui.frame.api.ICalendarMediator;
039: import org.columba.core.command.Command;
040: import org.columba.core.command.CommandProcessor;
041: import org.columba.core.gui.menu.IMenu;
042:
043: public class MoveActivityMenu extends IMenu implements
044: IActivitySelectionChangedListener {
045:
046: private Hashtable<String, JMenuItem> table = new Hashtable<String, JMenuItem>();
047:
048: public MoveActivityMenu(IFrameMediator controller) {
049: super (controller, "Move", "MoveActivity");
050:
051: ICalendarList list = Config.getInstance().getCalendarList();
052: Enumeration<ICalendarItem> e = list.getElements();
053: while (e.hasMoreElements()) {
054: final ICalendarItem calendarItem = e.nextElement();
055: JMenuItem item = new JMenuItem(calendarItem.getId());
056: table.put(calendarItem.getId(), item);
057:
058: item.addActionListener(new ActionListener() {
059: public void actionPerformed(ActionEvent e) {
060: /**
061: * move activity
062: */
063:
064: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
065:
066: IActivity activity = m.getCalendarView()
067: .getSelectedActivity();
068:
069: ICalendarStore store = CalendarStoreFactory
070: .getInstance().getLocaleStore();
071:
072: Command command = new MoveEventCommand(
073: new CalendarCommandReference(store,
074: calendarItem, activity));
075:
076: CommandProcessor.getInstance().addOp(command);
077:
078: }
079: });
080:
081: add(item);
082: }
083:
084: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
085: m.getCalendarView().addSelectionChangedListener(this );
086: }
087:
088: public void selectionChanged(ActivitySelectionChangedEvent event) {
089: if (event.getSelection().length == 0)
090: setEnabled(false);
091: else {
092:
093: setEnabled(true);
094:
095: // enable all menuitems
096: Enumeration<JMenuItem> e = table.elements();
097: while (e.hasMoreElements()) {
098: JMenuItem m = e.nextElement();
099: m.setEnabled(true);
100: }
101:
102: // retrieve selected activity
103: IActivity activity = event.getSelection()[0];
104: // activity belongs to calendar id ?
105: String calendarId = activity.getCalendarId();
106:
107: // disable this calendar's id
108: JMenuItem menuItem = table.get(calendarId);
109: menuItem.setEnabled(false);
110: }
111:
112: }
113: }
|