1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.rcp.configuration.extension;
17
18 import java.util.List;
19
20 import org.seasar.framework.util.StringUtil;
21 import org.seasar.uruma.component.UIElement;
22 import org.seasar.uruma.component.jface.MenuComponent;
23 import org.seasar.uruma.component.jface.MenuItemComponent;
24 import org.seasar.uruma.component.rcp.WorkbenchComponent;
25 import org.seasar.uruma.core.UrumaConstants;
26 import org.seasar.uruma.rcp.UrumaService;
27 import org.seasar.uruma.rcp.configuration.Extension;
28 import org.seasar.uruma.rcp.configuration.ExtensionBuilder;
29 import org.seasar.uruma.rcp.configuration.ExtensionFactory;
30 import org.seasar.uruma.rcp.configuration.ExtensionPoints;
31 import org.seasar.uruma.rcp.configuration.elements.ActionElement;
32 import org.seasar.uruma.rcp.configuration.elements.ActionSetElement;
33 import org.seasar.uruma.rcp.configuration.elements.ActionSetsMenuElement;
34 import org.seasar.uruma.rcp.util.UrumaServiceUtil;
35
36
37
38
39
40
41 public class ActionSetsBuilder implements ExtensionBuilder, UrumaConstants {
42 static final String START_MARKER = "startMarker";
43
44 static final String ADDITIONS = "additions";
45
46 static final String URUMA_MENU = "urumaMenu";
47
48 protected UrumaService service;
49
50 protected int menuCount;
51
52 protected int actionCount;
53
54
55
56
57 public ActionSetsBuilder() {
58 this.service = UrumaServiceUtil.getService();
59 }
60
61
62
63
64 public Extension[] buildExtension() {
65 this.menuCount = 0;
66 this.actionCount = 0;
67
68 return new Extension[] { setupActionSets() };
69 }
70
71 protected Extension setupActionSets() {
72 Extension extension = ExtensionFactory
73 .createExtension(ExtensionPoints.ACTIONSETS);
74
75 ActionSetElement actionSet = createActionSet();
76
77 WorkbenchComponent workbenchComponent = service.getWorkbenchComponent();
78 for (MenuComponent menu : workbenchComponent.getMenus()) {
79 List<UIElement> children = menu.getChildren();
80 for (UIElement child : children) {
81 if (child instanceof MenuComponent) {
82 setupMenu(actionSet, (MenuComponent) child, null);
83 }
84 }
85 }
86
87 extension.addElement(actionSet);
88
89 return extension;
90 }
91
92 protected ActionSetElement createActionSet() {
93 ActionSetElement actionSet = new ActionSetElement();
94 actionSet.id = service.getPluginId() + ".actionSet";
95 actionSet.label = service.getPluginId() + "'s actionSet.";
96 return actionSet;
97 }
98
99 protected void setupMenu(final ActionSetElement actionSet,
100 final MenuComponent menuComponent, final String parentPath) {
101 ActionSetsMenuElement menu = new ActionSetsMenuElement(menuComponent);
102
103
104 String id = menuComponent.getId();
105 if (StringUtil.isEmpty(id)) {
106 id = AUTO_MENU_ID_PREFIX + menuCount++;
107 }
108 menu.id = service.createRcpId(id);
109
110 String path = ((parentPath != null) ? parentPath + SLASH : NULL_STRING)
111 + menu.id;
112 menu.path = path + SLASH + URUMA_MENU;
113 actionSet.addElement(menu);
114
115 List<UIElement> children = menuComponent.getChildren();
116 for (UIElement child : children) {
117 if (child instanceof MenuComponent) {
118 setupMenu(actionSet, (MenuComponent) child, path);
119 } else if (child instanceof MenuItemComponent) {
120 setupMenuItem(actionSet, (MenuItemComponent) child, path);
121 }
122 }
123 }
124
125 protected void setupMenuItem(final ActionSetElement actionSet,
126 final MenuItemComponent menuItem, final String parentPath) {
127 ActionElement action = new ActionElement(menuItem);
128
129
130 String id = menuItem.getId();
131 if (StringUtil.isEmpty(id)) {
132 id = AUTO_ACTION_ID_PREFIX + actionCount++;
133 }
134 action.id = service.createRcpId(id);
135
136 action.menubarPath = ((parentPath != null) ? (parentPath + SLASH)
137 : NULL_STRING)
138 + ADDITIONS;
139
140 actionSet.addElement(action);
141 }
142 }