private void buildLessonTree(Response response) { TreeItem item = null; JsArray<LessonCategoryJS> lessonJSArray = JsonUtils.safeEval(response.getText()); for (int i = 0; i < lessonJSArray.length(); i++) { LessonCategoryJS lessonCategoryJS = lessonJSArray.get(i); TreeItem category = new TreeItem(); category.setText(lessonCategoryJS.getName()); JsArray<LessonJS> lessons = lessonCategoryJS.getChildren(); for (int j = 0; j < lessons.length(); j++) { LessonJS lesson = lessons.get(j); TreeItem lessonItem = new TreeItem(); Storage sessionStorage = Storage.getSessionStorageIfSupported(); String lastUrl = sessionStorage.getItem("lastUrl"); lessonItem.setText(lesson.getText()); category.addItem(lessonItem); lessonsTreeMap.put(lessonItem.getText(), lesson); if (lesson.getTechnology().equals(LessonTechnology.GWT.toString())) { addLessonToMap(lesson); } if (lastUrl != null && lastUrl.equals(lesson.getUrl())) { item = lessonItem; lessonPanel.setSelectedLesson(lesson); category.setState(true); } } lessonTree.addItem(category); } lessonTree.setSelectedItem(item); }
@Test public void testPackRespectSubItems() { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("Item 0"); TreeItem subitem = new TreeItem(item, SWT.NONE); subitem.setText("Subitem 0.0"); column.pack(); int columnWidth = column.getWidth(); item.setExpanded(true); column.pack(); assertTrue(column.getWidth() > columnWidth); }
@Test public void testDisposeLast() { TreeColumn column1 = new TreeColumn(tree, SWT.NONE); TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("itemText for column 0"); item.setText(1, "itemText for column 1"); column1.dispose(); assertEquals("", item.getText(1)); assertEquals("itemText for column 0", item.getText()); column.dispose(); assertEquals(0, tree.getColumnCount()); assertEquals(1, tree.getItemCount()); assertEquals("itemText for column 0", item.getText()); }
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new GridLayout()); final Tree tree1 = new Tree(shell, SWT.NONE); new TreeColumn(tree1, SWT.NONE).setWidth(40); final TreeItem treeItem1 = new TreeItem(tree1, SWT.NONE); treeItem1.setText("A"); final TreeItem treeItem12 = new TreeItem(tree1, SWT.NONE); treeItem12.setText("W"); final Tree tree2 = new Tree(shell, SWT.BORDER); new TreeColumn(tree2, SWT.NONE).setWidth(40); final TreeItem treeItem2 = new TreeItem(tree2, SWT.NONE); treeItem2.setText("A"); final TreeItem treeItem22 = new TreeItem(tree2, SWT.NONE); treeItem22.setText("."); final Tree tree3 = new Tree(shell, SWT.V_SCROLL); new TreeColumn(tree3, SWT.NONE).setWidth(40); final TreeItem treeItem3 = new TreeItem(tree3, SWT.NONE); treeItem3.setText("A"); final TreeItem treeItem32 = new TreeItem(tree3, SWT.NONE); treeItem32.setText("ABC"); final Tree tree4 = new Tree(shell, SWT.H_SCROLL); new TreeColumn(tree4, SWT.NONE).setWidth(40); final TreeItem treeItem4 = new TreeItem(tree4, SWT.NONE); treeItem4.setText("."); final TreeItem treeItem42 = new TreeItem(tree4, SWT.NONE); treeItem42.setText("A."); final Tree tree5 = new Tree(shell, SWT.V_SCROLL | SWT.H_SCROLL); new TreeColumn(tree5, SWT.NONE).setWidth(40); final TreeItem treeItem5 = new TreeItem(tree5, SWT.NONE); treeItem5.setText("W"); final TreeItem treeItem52 = new TreeItem(tree5, SWT.NONE); treeItem52.setText("Width"); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); // Display display = new Display (); // Shell shell = new Shell (display); // shell.setLayout(new FillLayout()); // Image imageOpen = new Image(display, TestButton.class.getResourceAsStream("openFolder.gif")); // Image imageClose = new Image(display, // TestButton.class.getResourceAsStream("closedFolder.gif")); // final Tree tree = new Tree (shell, SWT.BORDER | SWT.CHECK); // tree.setSize (100, 100); // shell.setSize (300, 200); // for (int i=0; i<2; i++) { // TreeItem iItem = new TreeItem (tree, 0); // iItem.setText ("TreeItem (0) -" + i); // iItem.setImage(imageOpen); // for (int j=0; j<2; j++) { // TreeItem jItem = new TreeItem (iItem, 0); // jItem.setText ("TreeItem (1) -" + j); // jItem.setImage(imageClose); // for (int k=0; k<3; k++) { // TreeItem kItem = new TreeItem (jItem, 0); // kItem.setText ("TreeItem (2) -" + k); //// for (int l=0; l<2; l++) { //// TreeItem lItem = new TreeItem (kItem, 0); //// lItem.setText ("TreeItem (3) -" + l); //// } // } // } // } // shell.open (); // while (!shell.isDisposed()) { // if (!display.readAndDispatch ()) display.sleep (); // } // imageOpen.dispose(); // imageClose.dispose(); // display.dispose (); }
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Tree tree = new Tree(shell, SWT.FULL_SELECTION | SWT.BORDER); tree.setHeaderVisible(true); TreeColumn column0 = new TreeColumn(tree, SWT.LEFT); column0.setText("Column 0"); TreeColumn column1 = new TreeColumn(tree, SWT.LEFT); column1.setText("Column 1"); TreeColumn column2 = new TreeColumn(tree, SWT.LEFT); column2.setText("Column 2"); for (int i = 0; i < 9; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("item " + i); item.setText(1, "column 1 - " + i); item.setText(2, "column 2 - " + i); for (int j = 0; j < 9; j++) { TreeItem subItem = new TreeItem(item, SWT.NONE); subItem.setText("item " + i + " " + j); subItem.setText(1, "column 1 - " + i + " " + j); subItem.setText(2, "column 2 - " + i + " " + j); for (int k = 0; k < 9; k++) { TreeItem subsubItem = new TreeItem(subItem, SWT.NONE); subsubItem.setText("item " + i + " " + j + " " + k); subsubItem.setText(1, "column 1 - " + i + " " + j + " " + k); subsubItem.setText(2, "column 2 - " + i + " " + j + " " + k); } } } column0.pack(); column1.pack(); column2.pack(); Heartbeat = new Runnable() { @Override public void run() { if (!Tracking || tree.isDisposed()) return; Point cursor = display.getCursorLocation(); cursor = display.map(null, tree, cursor); Scroll(tree, cursor.x, cursor.y); display.timerExec(ScrollSpeed, Heartbeat); } }; Listener listener = new Listener() { @Override public void handleEvent(Event event) { switch (event.type) { case SWT.MouseEnter: Tracking = true; display.timerExec(0, Heartbeat); break; case SWT.MouseExit: Tracking = false; break; } } }; tree.addListener(SWT.MouseEnter, listener); tree.addListener(SWT.MouseExit, listener); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }