/** * 增加子项 * * @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); } } }
/** * 删除子项 * * @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(); }
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; }
public MenuItemElementFigure(LfwElementObjWithGraph ele) { super(ele); menuObj = (MenuElementObj) ele; setTypeLabText("<<子菜单>>"); setBackgroundColor(bgColor); menuObj.setFigure(this); if (null != menuObj.getMenuItem().getId()) setTitleText(menuObj.getMenuItem().getId(), menuObj.getMenuItem().getId()); else setTitleText("", ""); addItems(); markError(menuObj.validate()); // 设置大小和位置 Point point = menuObj.getLocation(); dimen = menuObj.getSize(); this.height += 3 * LINE_HEIGHT; setBounds( new Rectangle( point.x, point.y, dimen.width, dimen.height < this.height ? this.height : dimen.height)); }
/** 刷新图像 */ public void refresh() { IFigure title = (IFigure) getTitleFigure().getChildren().get(1); getTitleFigure().remove(title); setTitleText(menuObj.getMenuItem().getId(), menuObj.getMenuItem().getId()); refreshItems(); }