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); }
public void updateTreeItems(TreeItem treeItem, List<FileWrapper> list) { if (treeItem == null) treeItem = trtmRoot; int index = 0, numberOfChildren = treeItem.getChildCount(); int newIndex = 0, numberOfNewChildren = list.size(); while (newIndex < numberOfNewChildren && index < numberOfChildren) { FileWrapper fileWrapper = list.get(newIndex); if (fileWrapper.getKind() != FileType.DIR) { break; } TreeItem child = treeItem.getChild(index); int diff = child.getText().compareTo(fileWrapper.getName()); if (diff < 0) { treeItem.removeItem(child); } else if (diff > 0) { TreeItem trtmNewItem = new TreeItem(); treeItem.insertItem(index, trtmNewItem); trtmNewItem.setText(fileWrapper.getName()); index++; numberOfChildren++; newIndex++; presenter.getFiles(trtmNewItem, getPath(trtmNewItem)); } else { index++; newIndex++; presenter.getFiles(child, getPath(child)); } } while (newIndex < numberOfNewChildren) { FileWrapper fileWrapper = list.get(newIndex++); if (fileWrapper.getKind() != FileType.DIR) { break; } TreeItem trtmNewItem = new TreeItem(); treeItem.addItem(trtmNewItem); trtmNewItem.setText(fileWrapper.getName()); presenter.getFiles(trtmNewItem, getPath(trtmNewItem)); } while (index < numberOfChildren) { treeItem.removeItem(treeItem.getChild(index)); numberOfChildren--; } }
/** Initialize the menu */ private void intiMenu() { removeAll(); // Item 1 sub-tree TreeItem item1 = new TreeItem(); item1.setText(SafeHtmlUtils.htmlEscape(CATEGORY_MENU)); item1.setUserObject(CATEGORY_MENU); addItem(item1); }
private void loadItem(VariableSerializable[] vars) { for (int j = 0; j < vars.length; j++) { // Do not include variables with subset_variable="true" used to denote "selector" // variables in in-situ data sets like SOCAT // TODO and for now no variables with character string values // if ( Util.keep(vars[j].getDSID(), vars[j].getName()) && Util.keep(vars[j].getDSID(), // vars[j].getAttributes()) ) { TreeItem item = new TreeItem(); item.setText(vars[j].getName()); item.setUserObject(vars[j]); currentlySelected.addItem(item); // } } }
private void addTreeItem(JSONObject jsonObject, int index) { Node node = new Node( jsonObject.get("id").isString().stringValue(), jsonObject.get("leaf").isBoolean().booleanValue(), jsonObject.get("text").isString().stringValue()); if (node.getText() != null) { TreeItem item = new TreeItem(); item.setText(node.getText()); item.setUserObject(node); if (!node.isLeaf()) item.addItem(""); // Temporarily add an item so we can expand this node treeItem.addItem(item); } }
public void onSuccess(Object result) { CategorySerializable[] cats = (CategorySerializable[]) result; if (cats != null && cats.length > 0) { if (currentlySelected == null) { for (int i = 0; i < cats.length; i++) { CategorySerializable cat = cats[i]; String children = cat.getAttributes().get("children"); boolean empty = false; if (children != null && children.equals("none")) empty = true; if (applyFilters(cat) && !empty) { TreeItem item = new TreeItem(); item.addItem( new SafeHtmlBuilder().appendEscaped(DatasetWidget.LOADING).toSafeHtml()); InnerItem inner = new InnerItem(cat); item.setWidget(inner); item.setUserObject(cat); addItem(item); } } } else { for (int i = 0; i < cats.length; i++) { CategorySerializable cat = cats[i]; if (cat.isCategoryChildren()) { String name = cat.getName(); TreeItem item; if (i == 0) { item = currentlySelected.getChild(0); } else { item = new TreeItem(); } item.addItem( new SafeHtmlBuilder().appendEscaped(DatasetWidget.LOADING).toSafeHtml()); InnerItem inner = new InnerItem(cat); item.setWidget(inner); item.setUserObject(cat); if (i > 0) { currentlySelected.addItem(item); } } else if (cat.isVariableChildren()) { // Must have variable children... TreeItem item = currentlySelected.getChild(0); if (cat.hasMultipleDatasets()) { DatasetSerializable[] dses = cat.getDatasetSerializableArray(); DatasetSerializable ds = dses[0]; VariableSerializable[] vars = ds.getVariablesSerializable(); currentlySelected.removeItems(); for (int j = 0; j < dses.length; j++) { ds = dses[j]; vars = ds.getVariablesSerializable(); loadItem(vars); } } else { DatasetSerializable ds = cat.getDatasetSerializable(); VariableSerializable[] vars = ds.getVariablesSerializable(); currentlySelected.removeItems(); loadItem(vars); } } } } } else { // A category was selected, but it came back empty... if (currentlySelected != null) { TreeItem item = currentlySelected.getChild(0); item.setText("No data sets found."); } } if (saveSelection != null) { currentlySelected = saveSelection; saveSelection = null; } }
public ExplorerViewImpl() { checkBoxList = new ArrayList<CheckBox>(); selectedFileSet = new TreeSet<String>(); clickHandlerStopPropagation = new ClickHandler() { public void onClick(ClickEvent event) { event.stopPropagation(); } }; DockPanel dockPanel = new DockPanel(); dockPanel.setWidth("100%"); viewPanel = new SimplePanel(dockPanel); initWidget(viewPanel); MenuBar menuBar = new MenuBar(false); dockPanel.add(menuBar, DockPanel.NORTH); menuBar.setHeight("30px"); MenuBar mnbrFile = new MenuBar(true); MenuItem mntmFile = new MenuItem("File", false, mnbrFile); menuBar.addItem(mntmFile); mntmMakeDirectory = new MenuItem( "Make Directory", false, new Command() { public void execute() { new FileDialogBox(presenter, Operation.MAKE_DIRECTORY).center(); } }); mnbrFile.addItem(mntmMakeDirectory); mntmUploadFile = new MenuItem( "Upload", false, new Command() { public void execute() { new FileDialogBox(presenter, Operation.UPLOAD).center(); } }); mnbrFile.addItem(mntmUploadFile); mntmDownloadFile = new MenuItem( "Download", false, new Command() { public void execute() { presenter.downloadFiles(selectedFileSet); } }); mnbrFile.addItem(mntmDownloadFile); mntmDownloadFile.setEnabled(false); mntmDeleteFile = new MenuItem( "Delete", false, new Command() { public void execute() {} }); mnbrFile.addItem(mntmDeleteFile); mntmDeleteFile.setEnabled(false); mntmRenameFile = new MenuItem( "Rename", false, new Command() { public void execute() {} }); mnbrFile.addItem(mntmRenameFile); mntmRenameFile.setEnabled(false); MenuItemSeparator misFile = new MenuItemSeparator(); mnbrFile.addSeparator(misFile); MenuItem mntmCloseVolume = new MenuItem( "Close volume", false, new Command() { public void execute() { presenter.closeVolume(); } }); mnbrFile.addItem(mntmCloseVolume); MenuBar mnbrHelp = new MenuBar(true); MenuItem mntmHelp = new MenuItem("Help", false, mnbrHelp); menuBar.addItem(mntmHelp); MenuItem mntmAbout = new MenuItem( "About", false, new Command() { public void execute() { Window.alert(""); } }); mnbrHelp.addItem(mntmAbout); flowPanel = new FlowPanel(); explorerScrollPanel = new ScrollPanel(flowPanel); dockPanel.add(explorerScrollPanel, DockPanel.CENTER); explorerScrollPanel.sinkEvents(Event.ONCLICK); explorerScrollPanel.addHandler( new ClickHandler() { public void onClick(ClickEvent event) { setAllCheckBoxFalse(); } }, ClickEvent.getType()); explorerScrollPanel.sinkEvents(Event.ONCONTEXTMENU); explorerScrollPanel.addHandler( new ContextMenuHandler() { public void onContextMenu(ContextMenuEvent event) { event.preventDefault(); event.stopPropagation(); FileContextMenu fileContextMenu = new FileContextMenu(presenter, ContextMenuType.BACKGROUND); fileContextMenu.setPopupPosition( event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY()); fileContextMenu.show(); setAllCheckBoxFalse(); } }, ContextMenuEvent.getType()); Tree tree = new Tree(); treeScrollPanel = new ScrollPanel(tree); dockPanel.add(treeScrollPanel, DockPanel.WEST); treeScrollPanel.setWidth("120px"); resizeScrollPanel(); Window.addResizeHandler( new ResizeHandler() { public void onResize(ResizeEvent event) { resizeScrollPanel(); } }); tree.setAnimationEnabled(true); // tree.addOpenHandler(new OpenHandler<TreeItem>() { // public void onOpen(OpenEvent<TreeItem> event) { // TreeItem trtmTarget = event.getTarget(); // String path = getPath(trtmTarget); // for (int i = 0; i < trtmTarget.getChildCount(); i++) { // TreeItem trtmChild = trtmTarget.getChild(i); // String childPath = path + trtmChild.getText(); // presenter.getFiles(trtmChild, childPath); // } // } // }); tree.addSelectionHandler( new SelectionHandler<TreeItem>() { public void onSelection(SelectionEvent<TreeItem> event) { TreeItem selectedItem = event.getSelectedItem(); String path = getPath(selectedItem); selectedItem.setState(true, true); presenter.changeDirectory(path); } }); trtmRoot = new TreeItem(); trtmSelectedItem = trtmRoot; tree.addItem(trtmRoot); trtmRoot.setText("/"); }