| 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 | 16 | public ActionSetsBuilder() { |
| 58 | 16 | this.service = UrumaServiceUtil.getService(); |
| 59 | 16 | } |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
public Extension[] buildExtension() { |
| 65 | 0 | this.menuCount = 0; |
| 66 | 0 | this.actionCount = 0; |
| 67 | |
|
| 68 | 0 | return new Extension[] { setupActionSets() }; |
| 69 | |
} |
| 70 | |
|
| 71 | |
protected Extension setupActionSets() { |
| 72 | 0 | Extension extension = ExtensionFactory |
| 73 | |
.createExtension(ExtensionPoints.ACTIONSETS); |
| 74 | |
|
| 75 | 0 | ActionSetElement actionSet = createActionSet(); |
| 76 | |
|
| 77 | 0 | WorkbenchComponent workbenchComponent = service.getWorkbenchComponent(); |
| 78 | 0 | for (MenuComponent menu : workbenchComponent.getMenus()) { |
| 79 | 0 | List<UIElement> children = menu.getChildren(); |
| 80 | 0 | for (UIElement child : children) { |
| 81 | 0 | if (child instanceof MenuComponent) { |
| 82 | 0 | setupMenu(actionSet, (MenuComponent) child, null); |
| 83 | |
} |
| 84 | |
} |
| 85 | 0 | } |
| 86 | |
|
| 87 | 0 | extension.addElement(actionSet); |
| 88 | |
|
| 89 | 0 | return extension; |
| 90 | |
} |
| 91 | |
|
| 92 | |
protected ActionSetElement createActionSet() { |
| 93 | 0 | ActionSetElement actionSet = new ActionSetElement(); |
| 94 | 0 | actionSet.id = service.getPluginId() + ".actionSet"; |
| 95 | 0 | actionSet.label = service.getPluginId() + "'s actionSet."; |
| 96 | 0 | return actionSet; |
| 97 | |
} |
| 98 | |
|
| 99 | |
protected void setupMenu(final ActionSetElement actionSet, |
| 100 | |
final MenuComponent menuComponent, final String parentPath) { |
| 101 | 0 | ActionSetsMenuElement menu = new ActionSetsMenuElement(menuComponent); |
| 102 | |
|
| 103 | |
|
| 104 | 0 | String id = menuComponent.getId(); |
| 105 | 0 | if (StringUtil.isEmpty(id)) { |
| 106 | 0 | id = AUTO_MENU_ID_PREFIX + menuCount++; |
| 107 | |
} |
| 108 | 0 | menu.id = service.createRcpId(id); |
| 109 | |
|
| 110 | 0 | String path = ((parentPath != null) ? parentPath + SLASH : NULL_STRING) |
| 111 | |
+ menu.id; |
| 112 | 0 | menu.path = path + SLASH + URUMA_MENU; |
| 113 | 0 | actionSet.addElement(menu); |
| 114 | |
|
| 115 | 0 | List<UIElement> children = menuComponent.getChildren(); |
| 116 | 0 | for (UIElement child : children) { |
| 117 | 0 | if (child instanceof MenuComponent) { |
| 118 | 0 | setupMenu(actionSet, (MenuComponent) child, path); |
| 119 | 0 | } else if (child instanceof MenuItemComponent) { |
| 120 | 0 | setupMenuItem(actionSet, (MenuItemComponent) child, path); |
| 121 | |
} |
| 122 | |
} |
| 123 | 0 | } |
| 124 | |
|
| 125 | |
protected void setupMenuItem(final ActionSetElement actionSet, |
| 126 | |
final MenuItemComponent menuItem, final String parentPath) { |
| 127 | 0 | ActionElement action = new ActionElement(menuItem); |
| 128 | |
|
| 129 | |
|
| 130 | 0 | String id = menuItem.getId(); |
| 131 | 0 | if (StringUtil.isEmpty(id)) { |
| 132 | 0 | id = AUTO_ACTION_ID_PREFIX + actionCount++; |
| 133 | |
} |
| 134 | 0 | action.id = service.createRcpId(id); |
| 135 | |
|
| 136 | 0 | action.menubarPath = ((parentPath != null) ? (parentPath + SLASH) |
| 137 | |
: NULL_STRING) |
| 138 | |
+ ADDITIONS; |
| 139 | |
|
| 140 | 0 | actionSet.addElement(action); |
| 141 | 0 | } |
| 142 | |
} |