01: package org.gui4j.component.factory;
02:
03: import java.util.HashMap;
04: import java.util.Iterator;
05: import java.util.List;
06: import java.util.Map;
07:
08: import javax.swing.JMenuItem;
09:
10: import org.dom4j.LElement;
11: import org.gui4j.component.Gui4jJComponent;
12: import org.gui4j.component.Gui4jTree;
13: import org.gui4j.component.Gui4jTreePopupMenuItem;
14: import org.gui4j.core.Gui4jComponentContainer;
15: import org.gui4j.core.definition.Attribute;
16: import org.gui4j.core.definition.AttributeTypeEnumeration;
17: import org.gui4j.util.Filter;
18:
19: public class Gui4jTreePopupMenuItemFactory extends
20: Gui4jPopupMenuItemFactory {
21: public static final String TREE_POPUP_MENUITEM_NAME = "treePopupMenuItem";
22: private static final String COMMAND = "command";
23:
24: private static final Map mCommand;
25:
26: static {
27: mCommand = new HashMap();
28: mCommand.put("collapse",
29: new Integer(Gui4jTree.COMMAND_COLLAPSE));
30: mCommand.put("expand", new Integer(Gui4jTree.COMMAND_EXPAND));
31: mCommand.put("setroot", new Integer(Gui4jTree.COMMAND_SETROOT));
32: mCommand.put("resetroot", new Integer(
33: Gui4jTree.COMMAND_RESETROOT));
34: mCommand.put("collapseall", new Integer(
35: Gui4jTree.COMMAND_COLLAPSE_ALL));
36: mCommand.put("expandall", new Integer(
37: Gui4jTree.COMMAND_EXPAND_ALL));
38: }
39:
40: /* (non-Javadoc)
41: * @see org.gui4j.component.factory.Gui4jJComponentFactory#defineGui4jJComponentBy(org.gui4j.core.Gui4jComponentContainer, java.lang.String, org.dom4j.LElement)
42: */
43: protected Gui4jJComponent defineGui4jJComponentBy(
44: Gui4jComponentContainer gui4jComponentContainer, String id,
45: LElement e) {
46: Class contextType = extractContextType(gui4jComponentContainer,
47: e);
48: int command = getMapValue(gui4jComponentContainer, e, COMMAND,
49: mCommand, Gui4jTree.COMMAND_EXPAND);
50: return new Gui4jTreePopupMenuItem(gui4jComponentContainer,
51: JMenuItem.class, contextType, command, id);
52: }
53:
54: public void addToplevelAttributes(List attrList, Filter filter) {
55: super .addToplevelAttributes(attrList, filter);
56: if (filter == null
57: || filter.takeIt(Gui4jTreePopupMenuItemFactory.class)) {
58: for (Iterator it = attrList.iterator(); it.hasNext();) {
59: Attribute attribute = (Attribute) it.next();
60: if (attribute.getName().equals(ACTIONCOMMAND)) {
61: it.remove();
62: }
63: }
64:
65: attrList.add(new Attribute(COMMAND,
66: new AttributeTypeEnumeration(mCommand), REQUIRED,
67: false));
68: }
69: }
70:
71: /**
72: * @see org.gui4j.core.Gui4jComponentFactory#getName()
73: */
74: public String getName() {
75: return TREE_POPUP_MENUITEM_NAME;
76: }
77:
78: }
|