1 26 package org.objectweb.util.explorer.parser.lib; 27 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 import org.objectweb.util.explorer.core.common.api.ExplorerConstants; 32 import org.objectweb.util.explorer.core.menu.api.AcceleratorDescription; 33 import org.objectweb.util.explorer.core.menu.api.ItemDescription; 34 import org.objectweb.util.explorer.core.menu.api.MenuDescription; 35 import org.objectweb.util.explorer.core.menu.api.MnemonicDescription; 36 import org.objectweb.util.explorer.core.menu.lib.BasicAcceleratorDescription; 37 import org.objectweb.util.explorer.core.menu.lib.BasicItemDescription; 38 import org.objectweb.util.explorer.core.menu.lib.BasicMenuDescription; 39 import org.objectweb.util.explorer.core.menu.lib.BasicMnemonicDescription; 40 import org.objectweb.util.explorer.explorerConfig.Accelerator; 41 import org.objectweb.util.explorer.explorerConfig.Item; 42 import org.objectweb.util.explorer.explorerConfig.Menu; 43 import org.objectweb.util.explorer.explorerConfig.Mnemonic; 44 import org.objectweb.util.explorer.explorerConfig.Node; 45 46 54 public class MenuManager 55 extends AbstractNodeParser 56 { 57 58 64 70 76 82 protected AcceleratorDescription getAcceleratorDescription(Accelerator accelerator){ 83 AcceleratorDescription acceleratorDesc = null; 84 if(accelerator!=null){ 85 acceleratorDesc = new BasicAcceleratorDescription(); 86 acceleratorDesc.setAcceleratorCharacter(accelerator.getXmlchar().charAt(0)); 87 acceleratorDesc.setCtrlKey(accelerator.getCtrl().equals("true")); 88 acceleratorDesc.setAltKey(accelerator.getAlt().equals("true")); 89 acceleratorDesc.setShiftKey(accelerator.getShift().equals("true")); 90 acceleratorDesc.setMetaKey(accelerator.getMeta().equals("true")); 91 } 92 return acceleratorDesc; 93 } 94 95 101 protected MnemonicDescription getMnemonicDescription(Mnemonic mnemonic){ 102 MnemonicDescription mnemonicDesc = null; 103 if(mnemonicDesc!=null){ 104 mnemonicDesc = new BasicMnemonicDescription(); 105 mnemonicDesc.setMnemonicCharacter(mnemonic.getXmlchar().charAt(0)); 106 } 107 return mnemonicDesc; 108 } 109 110 116 protected ItemDescription getItemDescription(Item item){ 117 ItemDescription itemDesc = null; 118 if(item!=null){ 119 itemDesc = new BasicItemDescription(); 120 itemDesc.setLabel(item.getLabel()); 121 itemDesc.setTreeChildVisible(item.getTreeChildVisible().equals("true")); 122 itemDesc.setTypeChildVisible(item.getTypeChildVisible().equals("true")); 123 itemDesc.setCodeDescription(ParserUtils.getCodeDescription(item.getCode())); 124 itemDesc.setIconDescription(ParserUtils.getIconDescription(item.getIcon())); 125 itemDesc.setMnemonicDescription(getMnemonicDescription(item.getMnemonic())); 126 itemDesc.setAcceleratorDescription(getAcceleratorDescription(item.getAccelerator())); 127 } 128 return itemDesc; 129 } 130 131 136 protected void feedMenuDescription(List elements, MenuDescription menuDesc){ 137 if(elements!=null && !elements.isEmpty()){ 138 Iterator it = elements.iterator(); 139 while(it.hasNext()){ 140 menuDesc.addMenuElement(getItemDescription((Item)it.next())); 141 } 142 } 143 } 144 145 151 protected MenuDescription getMenuDescription(Menu menu){ 152 MenuDescription menuDesc = null; 153 if(menu!=null){ 154 menuDesc = new BasicMenuDescription(); 155 menuDesc.setInheritTreeMenu(menu.getInheritTreeMenu().equals("true")); 156 menuDesc.setInheritTypeMenu(menu.getInheritTypeMenu().equals("true")); 157 feedMenuDescription(menu.getItemList(), menuDesc); 158 } 159 return menuDesc; 160 } 161 162 168 171 public void parseNode(Object key, Node node) { 172 MenuDescription menuDesc = getMenuDescription(node.getMenu()); 173 if(menuDesc!=null){ 174 getFeeder().feed(ExplorerConstants.MENU_PROPERTY, key, menuDesc); 175 } 176 } 177 178 } 179 180 181 | Popular Tags |