private SessionDataDto defineCurrentSession(CellDoubleClickEvent event) { String sessionId = treeGrid.getColumnModel().getColumn(event.getCellIndex()).getHeader().asString(); String sessionData_id = sessionId.substring(sessionId.indexOf(' ') + 1); SessionDataDto currentSession = null; for (SessionDataDto sessionDataDto : SessionComparisonPanel.this.chosenSessions) { if (sessionDataDto.getSessionId().equals(sessionData_id)) { currentSession = sessionDataDto; break; } } return currentSession; }
// // to make columns fit 100% width if grid created not on Summary Tab public void refresh() { treeGrid.getView().refresh(true); }
private void init(Set<SessionDataDto> chosenSessions, int width) { int colWidth = calculateWidth(chosenSessions.size(), width); treeStore.clear(); List<ColumnConfig<TreeItem, ?>> columns = new ArrayList<ColumnConfig<TreeItem, ?>>(); // sort sessions by number sessionId SortedSet<SessionDataDto> sortedSet = new TreeSet<SessionDataDto>( new Comparator<SessionDataDto>() { @Override public int compare(SessionDataDto o, SessionDataDto o2) { return (Long.parseLong(o.getSessionId()) - Long.parseLong(o2.getSessionId())) > 0 ? 1 : -1; } }); sortedSet.addAll(chosenSessions); ColumnConfig<TreeItem, String> nameColumn = new ColumnConfig<TreeItem, String>( new MapValueProvider(NAME), (int) (colWidth * METRIC_COLUMN_WIDTH_FACTOR)); nameColumn.setHeader(METRIC); nameColumn.setSortable(false); nameColumn.setMenuDisabled(true); columns.add(nameColumn); for (SessionDataDto session : sortedSet) { ColumnConfig<TreeItem, String> column = new ColumnConfig<TreeItem, String>( new MapValueProvider(SESSION_HEADER + session.getSessionId())); column.setHeader(SESSION_HEADER + session.getSessionId()); column.setWidth(colWidth); column.setSortable(false); column.setCell( new AbstractCell<String>() { @Override public void render(Context context, String value, SafeHtmlBuilder sb) { if (value != null) { sb.appendHtmlConstant(value); } } }); column.setMenuDisabled(true); column.setColumnTextStyle( new SafeStyles() { @Override public String asString() { return WHITE_SPACE_NORMAL; } }); columns.add(column); } ColumnModel<TreeItem> cm = new ColumnModel<TreeItem>(columns); treeGrid = new NoIconsTreeGrid(treeStore, cm, nameColumn); treeGrid.addBeforeCollapseHandler( new BeforeCollapseItemEvent.BeforeCollapseItemHandler<TreeItem>() { @Override public void onBeforeCollapse(BeforeCollapseItemEvent<TreeItem> event) { event.setCancelled(true); } }); treeGrid.setAutoExpand(true); treeGrid.getView().setStripeRows(true); treeGrid.setMinColumnWidth(MIN_COLUMN_WIDTH); treeGrid.setAllowTextSelection(true); treeGrid.getView().setForceFit(true); treeStore.addStoreAddHandler( new StoreAddEvent.StoreAddHandler<TreeItem>() { @Override public void onAdd(StoreAddEvent<TreeItem> event) { for (TreeItem item : event.getItems()) { treeGrid.setExpanded(item, true); } } }); if (webClientProperties.isUserCommentEditAvailable()) { treeGrid.addCellDoubleClickHandler( new CellDoubleClickEvent.CellDoubleClickHandler() { @Override public void onCellClick(CellDoubleClickEvent event) { TreeItem item = treeGrid.findNode(treeGrid.getTreeView().getRow(event.getRowIndex())).getModel(); if (item.getKey().equals(USER_COMMENT) && event.getCellIndex() > 0) { SessionDataDto currentSession = defineCurrentSession(event); userCommentBox.popUp( currentSession, item.get(SESSION_HEADER + currentSession.getSessionId()), item); } } }); } if (webClientProperties.isTagsAvailable()) { treeGrid.addCellDoubleClickHandler( new CellDoubleClickEvent.CellDoubleClickHandler() { @Override public void onCellClick(CellDoubleClickEvent event) { TreeItem item = treeGrid.findNode(treeGrid.getTreeView().getRow(event.getRowIndex())).getModel(); if (item.getKey().equals(SESSION_TAGS) && event.getCellIndex() > 0) { SessionDataDto currentSession = defineCurrentSession(event); if (allTagsLoadComplete) tagBox.popUpForEdit(currentSession, item, allTags); } } }); } add(treeGrid); }