static TreeItem NextItem(Tree tree, TreeItem item) { if (item == null) return null; if (item.getExpanded()) { return item.getItem(0); } else { TreeItem childItem = item; TreeItem parentItem = childItem.getParentItem(); int index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem); int count = parentItem == null ? tree.getItemCount() : parentItem.getItemCount(); while (true) { if (index + 1 < count) { return parentItem == null ? tree.getItem(index + 1) : parentItem.getItem(index + 1); } else { if (parentItem == null) { return null; } else { childItem = parentItem; parentItem = childItem.getParentItem(); index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem); count = parentItem == null ? tree.getItemCount() : parentItem.getItemCount(); } } } } }
/** connet matrix with treeitem reset the texts of the treeitem's children */ private void setWeightTree() { List matrix = new ArrayList(); for (int i = 0; i < matrixText.length; i++) { matrix.add(matrixText[i].getText()); } if (orderMap.containsKey(treeItem)) orderMap.remove(treeItem); orderMap.put(treeItem, matrix); for (int i = 0; i < treeItem.getItemCount(); i++) { String itemName = this.getNameTreeItem(treeItem.getItem(i)); itemName += GUI.PREFIX + matrixText[i].getText() + GUI.SUFFIX; treeItem.getItem(i).setText(itemName); } }
public void testFormalizedComponentNames() { Component_c component = Component_c.ComponentInstance( modelRoot, new ClassQueryInterface_c() { public boolean evaluate(Object candidate) { return ((Component_c) candidate).getName().equals(testDomain.getName()); } }); assertNotNull(component); if (!component.Isformal()) formalizeComponent(component); TreeItem item = ExplorerUtil.findItem(component); TreeItem fileFacade = item.getItem(0); assertTrue( "The file element in Model Explorer was not named correctly for a formal component.", fileFacade.getText().equals(testDomain.getName() + ": Component Diagram")); // open the component diagram CanvasUtilities.openCanvasEditor(component); GraphicalEditor ce = ((ModelEditor) PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .getActiveEditor()) .getGraphicalEditor(); assertTrue( "The opened diagram does not represent the formal contents of the component.", ce.getModel().getRepresents() instanceof Domain_c); assertTrue( "The editor title did not contain component diagram.", ((IEditorPart) ce).getTitle().indexOf("Component Diagram") != -1); }
static TreeItem PreviousItem(Tree tree, TreeItem item) { if (item == null) return null; TreeItem childItem = item; TreeItem parentItem = childItem.getParentItem(); int index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem); if (index == 0) { return parentItem; } else { TreeItem nextItem = parentItem == null ? tree.getItem(index - 1) : parentItem.getItem(index - 1); int count = nextItem.getItemCount(); while (count > 0 && nextItem.getExpanded()) { nextItem = nextItem.getItem(count - 1); count = nextItem.getItemCount(); } return nextItem; } }
/** reset weight value of ffitem */ private void setWeightFFT() { FFItem ffItem = null; String value = null; double weight; for (int i = 0; i < treeItem.getItemCount(); i++) { ffItem = (FFItem) treeItem.getItem(i).getData(); value = weightLabel[i].getText(); weight = Double.parseDouble(value); ffItem.weight = weight; } }
private TreeItem findItem(FileInfo info) { if (info == null) return null; assert info.parent != null; if (info.parent == fRootInfo) { int n = fileTree.getItemCount(); if (info.index >= n) return null; return fileTree.getItem(info.index); } TreeItem i = findItem(info.parent); if (i == null) return null; int n = i.getItemCount(); if (info.index >= n) return null; return i.getItem(info.index); }
protected Control createDialogArea(Composite parent) { int colCount = this.treeItem.getItemCount(); int colLabelCount = colCount + 1; int cL, rL, c, r, i; this.matrixText = new Text[colCount * colCount]; this.weightLabel = new Label[colCount]; final Composite content = new Composite(parent, SWT.NONE); { GridLayout contentLay = new GridLayout(); contentLay.makeColumnsEqualWidth = true; contentLay.marginTop = 50; contentLay.marginRight = 50; contentLay.marginBottom = 50; contentLay.marginLeft = 50; contentLay.numColumns = colLabelCount; contentLay.verticalSpacing = 3; contentLay.horizontalSpacing = 2; content.setLayout(contentLay); } GridData gridCenter = new GridData(GridData.FILL, GridData.FILL, true, true); gridCenter.horizontalAlignment = SWT.CENTER; gridCenter.minimumWidth = 8; for (int iL = 0; iL < colLabelCount * colLabelCount; iL++) { cL = iL % colLabelCount; rL = (iL - cL) / colLabelCount; c = cL - 1; r = rL - 1; if (c >= 0 && r >= 0) { i = r * colCount + c; this.matrixText[i] = new Text(content, SWT.NONE); this.matrixText[i].addVerifyListener( new VerifyListener() { public void verifyText(VerifyEvent e) { if ("0123456789.".indexOf(e.text) >= 0) { e.doit = true; return; } else { try { Double.parseDouble(e.text); e.doit = true; return; } catch (Exception ex) { e.doit = false; return; } } } }); if (this.calcType) { this.matrixText[i].addFocusListener(new SimpleAhpFocusListener(i)); } else this.matrixText[i].addFocusListener(new ComplexAhpFocusListener(i)); // this.matrixText[i].setSize(10,SWT.DEFAULT); // this.matrixText[i].setLayoutData(gridCenter); this.matrixText[i].setText("1.000"); if (this.calcType) { if (r > 0) this.matrixText[i].setEditable(false); } else { if (r > c || r == c) this.matrixText[i].setEditable(false); } } else { if (cL + rL == 0) new Label(content, SWT.NONE); else { String itemName = this.getNameTreeItem(treeItem.getItem(rL + cL - 1)); Label label = new Label(content, SWT.NONE); label.setText(itemName); // label.setLayoutData(gridCenter); } } } new Label(content, SWT.NONE).setText("权重"); for (int res = 0; res < colCount; res++) { this.weightLabel[res] = new Label(content, SWT.NONE); FFItem ffitem = (FFItem) treeItem.getItem(res).getData(); this.weightLabel[res].setText(String.valueOf(ffitem.weight)); } new Label(content, SWT.NONE).setText("判决"); judgeLabel = new Label(content, SWT.NONE); judgeLabel.setText("待验证"); this.setWeightMatrix(); return content; }