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.CopyEventCommand;
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: /**
044: * CopyActivityMenu class
045: * @author fdietz
046: *
047: */
048: public class CopyActivityMenu extends IMenu implements
049: IActivitySelectionChangedListener {
050:
051: /**
052: * serialVersionUID
053: */
054: private static final long serialVersionUID = 7014530206628904351L;
055:
056: private Hashtable<String, JMenuItem> table = new Hashtable<String, JMenuItem>();
057:
058: /**
059: * CopyActivityMenu parameterized constructor
060: * @param controller
061: */
062: public CopyActivityMenu(IFrameMediator controller) {
063: super (controller, "Copy", "CopyActivity");
064:
065: ICalendarList list = Config.getInstance().getCalendarList();
066: Enumeration<ICalendarItem> e = list.getElements();
067: while (e.hasMoreElements()) {
068: final ICalendarItem calendarItem = e.nextElement();
069: JMenuItem item = new JMenuItem(calendarItem.getId());
070: table.put(calendarItem.getId(), item);
071:
072: item.addActionListener(new ActionListener() {
073: public void actionPerformed(ActionEvent e) {
074: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
075:
076: IActivity activity = m.getCalendarView()
077: .getSelectedActivity();
078:
079: // copy activity
080: ICalendarStore store = CalendarStoreFactory
081: .getInstance().getLocaleStore();
082:
083: Command command = new CopyEventCommand(
084: new CalendarCommandReference(store,
085: calendarItem, activity));
086:
087: CommandProcessor.getInstance().addOp(command);
088: }
089: });
090:
091: add(item);
092: }
093:
094: ICalendarMediator m = (ICalendarMediator) getFrameMediator();
095: m.getCalendarView().addSelectionChangedListener(this );
096: }
097:
098: /* (non-Javadoc)
099: * @see org.columba.calendar.ui.calendar.api.IActivitySelectionChangedListener#selectionChanged(org.columba.calendar.ui.calendar.api.ActivitySelectionChangedEvent)
100: */
101: public void selectionChanged(ActivitySelectionChangedEvent event) {
102: if (event.getSelection().length == 0)
103: setEnabled(false);
104: else {
105: setEnabled(true);
106:
107: // enable all menuitems
108: Enumeration<JMenuItem> e = table.elements();
109: while (e.hasMoreElements()) {
110: JMenuItem m = e.nextElement();
111: m.setEnabled(true);
112: }
113:
114: // retrieve selected activity
115: IActivity activity = event.getSelection()[0];
116: // activity belongs to calendar id ?
117: String calendarId = activity.getCalendarId();
118:
119: // disable this calendar's id
120: JMenuItem menuItem = table.get(calendarId);
121: menuItem.setEnabled(false);
122: }
123: }
124: }
|