/** * 增加子项 * * @param signal */ public void addItem(MenuItem menuItem) { MenuItem currentMenuItem = menuObj.getMenuItem(); int index = 0; if (null != currentMenuItem.getChildList()) index = currentMenuItem.getChildList().size(); currentMenuItem.addMenuItem(menuItem); MenuItemLabel label = new MenuItemLabel(menuItem); addToContent(label, index); addItemLabelListener(label); this.height += LINE_HEIGHT; resizeHeight(); }
/** 显示所有子项 */ private void addItems() { MenuItem menuItem = menuObj.getMenuItem(); List<MenuItem> itemList = menuItem.getChildList(); if (itemList != null) { Iterator<MenuItem> it = itemList.iterator(); while (it.hasNext()) { MenuItem item = it.next(); MenuItemLabel label = new MenuItemLabel(item); addToContent(label); this.height += LINE_HEIGHT; addItemLabelListener(label); } } }
protected Control createDialogArea(Composite parent) { Composite container = new Composite(parent, SWT.NONE); container.setLayout(new GridLayout(4, false)); container.setLayoutData(new GridData(GridData.FILL_BOTH)); new Label(container, SWT.NONE).setText("触发项:"); sourceItemCombo = new Combo(container, SWT.READ_ONLY); sourceItemCombo.setLayoutData(createGridData(135, 1)); sourceItemCombo.add(SELECT_SENTENCE); sourceItemCombo.select(0); // 构造选项列表 sourceItem = target.getMenuItem(); List<MenuItem> sourceItemList = getUnusedItemList(); for (int i = 0, n = sourceItemList.size(); i < n; i++) { sourceItemCombo.add(sourceItemList.get(i).getText()); sourceItemCombo.setData(sourceItemList.get(i).getText(), sourceItemList.get(i)); } if (null != sourceItem.getText()) sourceItemCombo.select(sourceItemCombo.indexOf(sourceItem.getText())); return container; }
/** * 创建新的MenuItem * * @param item * @param paramPanels * @param packageName * @param classPrefix */ private void createNewMenuItems( MenuItem item, Map<DefaultItem, MenuItemParamPanel> paramPanels, String sourceFolder, String packageName, String classPrefix) { for (DefaultItem defaultItem : paramPanels.keySet()) { MenuItem menuItem = defaultItem.generateMenuItem(); // 设置ID String id = ""; if (null != item) { // id = item.getId() + menuItem.getId(); id = menuItem.getId(); item.addMenuItem(menuItem); } else { // id = menuObj.getMenuItem().getId() + menuItem.getId(); id = menuItem.getId(); } // menuItem.setId(id); String listenerId = "menu_item_" + id + "_listener"; String genClazz = classPrefix + defaultItem .getSuperClazz() .substring(defaultItem.getSuperClazz().lastIndexOf('.') + 1); JsListenerConf listener = paramPanels .get(defaultItem) .generateListener(sourceFolder, packageName, genClazz, defaultItem, listenerId); menuItem.addListener(listener); addItem(menuItem); } }
/** * 删除子项 * * @param label */ public void deleteItem(MenuItemLabel label) { MenuItem item = (MenuItem) label.getEditableObj(); MenuItem currentMenuItem = menuObj.getMenuItem(); if (currentMenuItem.getChildList().contains(item)) { currentMenuItem.getChildList().remove(item); // 删除相关连接 MenubarEditor editor = MenubarEditor.getActiveMenubarEditor(); MenubarConnector connector = editor.getConnector(item.getId()); if (null != connector) { editor.removeConnector(item.getId()); connector.disConnect(); } } getContentFigure().remove(label); this.height -= LINE_HEIGHT; resizeHeight(); }