Coverage Report - org.seasar.uruma.rcp.configuration.extension.ActionSetsBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionSetsBuilder
7%
3/44
0%
0/20
0
 
 1  
 /*
 2  
  * Copyright 2004-2008 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 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  
  * <code>actionSets</code> 拡張ポイントを生成するための {@link ExtensionBuilder} です。<br />
 38  
  * 
 39  
  * @author y-komori
 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  
      * {@link ActionSetsBuilder} を構築します。<br />
 56  
      */
 57  16
     public ActionSetsBuilder() {
 58  16
         this.service = UrumaServiceUtil.getService();
 59  16
     }
 60  
 
 61  
     /*
 62  
      * @see org.seasar.uruma.rcp.configuration.ExtensionBuilder#buildExtension()
 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  
         // Menu の id が設定されていない場合は自動設定する
 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  
         // MenuItem の id が設定されていない場合は自動設定する
 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  
 }