001: package org.columba.core.gui.globalactions;
002:
003: import java.awt.event.ActionEvent;
004: import java.util.Iterator;
005:
006: import javax.swing.AbstractAction;
007: import javax.swing.JMenuItem;
008:
009: import org.columba.api.gui.frame.IDock;
010: import org.columba.api.gui.frame.IDockable;
011: import org.columba.api.gui.frame.IFrameMediator;
012: import org.columba.api.gui.frame.event.FrameEvent;
013: import org.columba.core.gui.frame.DefaultFrameController;
014: import org.columba.core.gui.frame.FrameMediatorAdapter;
015: import org.columba.core.gui.menu.IMenu;
016: import org.flexdock.docking.Dockable;
017: import org.flexdock.docking.DockingManager;
018:
019: /**
020: * Menu in "View->Hide/Show" shows all dockables for the current frame mediator.
021: * A listener is used to update the submenu in case the frame mediator is
022: * changed.
023: *
024: * @author fdietz
025: */
026: public class ShowHideViewSubmenu extends IMenu {
027:
028: public ShowHideViewSubmenu(IFrameMediator controller) {
029: super (controller, "Show/Hide View",
030: ((DefaultFrameController) controller).getViewItem()
031: .get("id"));
032:
033: // register for change of the frame mediator
034: controller.addListener(new MyListener());
035:
036: if (getMenuComponentCount() == 0)
037: setEnabled(false);
038: else
039: setEnabled(true);
040: }
041:
042: class DisplayAction extends AbstractAction {
043: String id;
044:
045: DisplayAction(String id, String name) {
046: this .id = id;
047:
048: putValue(AbstractAction.NAME, name);
049: }
050:
051: public void actionPerformed(ActionEvent e) {
052: Dockable dockable = DockingManager.getDockable(id);
053: DockingManager.display(dockable);
054: }
055: }
056:
057: /**
058: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
059: */
060: public void actionPerformed(ActionEvent arg0) {
061:
062: }
063:
064: /**
065: * Listener checks if a workspace switch happened and replaces all the
066: * Hide/Show menuentries.
067: *
068: * @author fdietz
069: */
070: class MyListener extends FrameMediatorAdapter {
071:
072: MyListener() {
073:
074: }
075:
076: /**
077: * @see org.columba.core.gui.frame.FrameMediatorAdapter#switchedComponent(org.columba.api.gui.frame.event.FrameEvent)
078: */
079: @Override
080: public void switchedComponent(FrameEvent event) {
081: IFrameMediator mediator = getFrameMediator();
082:
083: // check if mediator supports docking
084: if (mediator instanceof IDock) {
085: Iterator<IDockable> it = ((IDock) mediator)
086: .getDockableIterator();
087: while (it.hasNext()) {
088: IDockable dockable = it.next();
089:
090: DisplayAction action = new DisplayAction(dockable
091: .getId(), dockable.resolveName());
092: add(new JMenuItem(action));
093: }
094: }
095:
096: if (getMenuComponentCount() == 0)
097: setEnabled(false);
098: else
099: setEnabled(true);
100: }
101: }
102:
103: }
|