List of usage examples for com.vaadin.ui Tree.CollapseListener Tree.CollapseListener
Tree.CollapseListener
From source file:com.esofthead.mycollab.module.project.view.assignments.gantt.GanttTreeTable.java
License:Open Source License
public GanttTreeTable(final GanttExt gantt) { super();/*from w ww . ja va2 s . c o m*/ this.gantt = gantt; this.setWidth("800px"); this.setBuffered(true); beanContainer = gantt.getBeanContainer(); this.setContainerDataSource(beanContainer); this.setVisibleColumns("ganttIndex", "name", "startDate", "endDate", "duration", "percentageComplete", "predecessors", "assignUser"); this.setColumnHeader("ganttIndex", ""); this.setColumnWidth("ganttIndex", 25); this.setColumnHeader("name", "Task"); this.setColumnExpandRatio("name", 1.0f); this.setHierarchyColumn("name"); this.setColumnHeader("startDate", "Start"); this.setColumnWidth("startDate", 90); this.setColumnHeader("endDate", "End"); this.setColumnWidth("endDate", 90); this.setColumnHeader("duration", "Duration"); this.setColumnWidth("duration", 65); this.setColumnHeader("predecessors", "Predecessors"); this.setColumnWidth("predecessors", 100); this.setColumnHeader("percentageComplete", "% Complete"); this.setColumnWidth("percentageComplete", 75); this.setColumnHeader("assignUser", "Assignee"); this.setColumnWidth("assignUser", 80); this.setColumnCollapsingAllowed(true); this.setColumnCollapsed("assignUser", true); this.setEditable(true); this.setNullSelectionAllowed(false); this.addGeneratedColumn("ganttIndex", new ColumnGenerator() { @Override public Object generateCell(Table table, Object itemId, Object columnId) { GanttItemWrapper item = (GanttItemWrapper) itemId; return new ELabel("" + item.getGanttIndex()).withStyleName(ValoTheme.LABEL_SMALL); } }); this.setTableFieldFactory(new TableFieldFactory() { @Override public Field<?> createField(Container container, Object itemId, final Object propertyId, Component uiContext) { Field field = null; final GanttItemWrapper ganttItem = (GanttItemWrapper) itemId; if ("name".equals(propertyId)) { field = new AssignmentNameCellField(ganttItem.getType()); } else if ("percentageComplete".equals(propertyId)) { field = new TextField(); ((TextField) field).setNullRepresentation("0"); ((TextField) field).setImmediate(true); field.addStyleName(ValoTheme.TEXTFIELD_SMALL); if (ganttItem.hasSubTasks() || ganttItem.isMilestone()) { field.setEnabled(false); ((TextField) field).setDescription("Because this row has sub-tasks, this cell " + "is a summary value and can not be edited directly. You can edit cells " + "beneath this row to change its value"); } } else if ("startDate".equals(propertyId) || "endDate".equals(propertyId)) { field = new DateField(); field.addStyleName(ValoTheme.DATEFIELD_SMALL); ((DateField) field).setConverter(new LocalDateConverter()); ((DateField) field).setImmediate(true); if (ganttItem.hasSubTasks()) { field.setEnabled(false); ((DateField) field).setDescription("Because this row has sub-tasks, this cell " + "is a summary value and can not be edited directly. You can edit cells " + "beneath this row to change its value"); } } else if ("assignUser".equals(propertyId)) { field = new ProjectMemberSelectionField(); } else if ("predecessors".equals(propertyId)) { field = new DefaultViewField(""); ((DefaultViewField) field).setConverter(new PredecessorConverter()); return field; } else if ("duration".equals(propertyId)) { field = new TextField(); ((TextField) field).setConverter(new HumanTimeConverter()); field.addStyleName(ValoTheme.TEXTFIELD_SMALL); if (ganttItem.hasSubTasks()) { field.setEnabled(false); ((TextField) field).setDescription("Because this row has sub-tasks, this cell " + "is a summary value and can not be edited directly. You can edit cells " + "beneath this row to change its value"); } } if (field != null) { field.setBuffered(true); field.setWidth("100%"); if (ganttItem.isMilestone()) { if (!CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.MILESTONES)) { field.setEnabled(false); ((AbstractComponent) field).setDescription( AppContext.getMessage(GenericI18Enum.NOTIFICATION_NO_PERMISSION_DO_TASK)); } } else if (ganttItem.isTask()) { if (!CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS)) { field.setEnabled(false); ((AbstractComponent) field).setDescription( AppContext.getMessage(GenericI18Enum.NOTIFICATION_NO_PERMISSION_DO_TASK)); } } else if (ganttItem.isBug()) { if (!CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.BUGS)) { field.setEnabled(false); ((AbstractComponent) field).setDescription( AppContext.getMessage(GenericI18Enum.NOTIFICATION_NO_PERMISSION_DO_TASK)); } } else { throw new MyCollabException( "Do not support gantt item type " + ganttItem.getTask().getType()); } if (field instanceof FieldEvents.BlurNotifier) { ((FieldEvents.BlurNotifier) field).addBlurListener(new FieldEvents.BlurListener() { @Override public void blur(FieldEvents.BlurEvent event) { Object o = event.getSource(); if (o instanceof Field) { Field f = (Field) o; if (f.isModified()) { f.commit(); EventBusFactory.getInstance().post(new GanttEvent.AddGanttItemUpdateToQueue( GanttTreeTable.this, ganttItem)); GanttTreeTable.this.refreshRowCache(); } } } }); } } return field; } }); this.addExpandListener(new Tree.ExpandListener() { @Override public void nodeExpand(Tree.ExpandEvent expandEvent) { GanttItemWrapper item = (GanttItemWrapper) expandEvent.getItemId(); List<GanttItemWrapper> subTasks = item.subTasks(); insertSubSteps(item, subTasks); } }); this.addCollapseListener(new Tree.CollapseListener() { @Override public void nodeCollapse(Tree.CollapseEvent collapseEvent) { GanttItemWrapper item = (GanttItemWrapper) collapseEvent.getItemId(); List<GanttItemWrapper> subTasks = item.subTasks(); removeSubSteps(item, subTasks); } }); this.setCellStyleGenerator(new CellStyleGenerator() { @Override public String getStyle(Table source, Object itemId, Object propertyId) { GanttItemWrapper item = (GanttItemWrapper) itemId; if (item.isMilestone()) { return "root"; } else if (item.isTask()) { return ""; } return ""; } }); final GanttContextMenu contextMenu = new GanttContextMenu(); contextMenu.setAsContextMenuOf(this); contextMenu.setOpenAutomatically(false); ContextMenu.ContextMenuOpenedListener.TableListener tableListener = new ContextMenu.ContextMenuOpenedListener.TableListener() { public void onContextMenuOpenFromRow(ContextMenu.ContextMenuOpenedOnTableRowEvent event) { GanttItemWrapper item = (GanttItemWrapper) event.getItemId(); contextMenu.displayContextMenu(item); contextMenu.open(GanttTreeTable.this); } public void onContextMenuOpenFromHeader(ContextMenu.ContextMenuOpenedOnTableHeaderEvent event) { } public void onContextMenuOpenFromFooter(ContextMenu.ContextMenuOpenedOnTableFooterEvent event) { } }; contextMenu.addContextMenuTableListener(tableListener); gantt.setVerticalScrollDelegateTarget(this); this.setPageLength(currentPageLength); }
From source file:com.haulmont.cuba.web.app.folders.CubaFoldersPane.java
License:Apache License
protected void collapseItemInTree(Tree tree, final String foldersCollapse) { String s = userSettingService.loadSetting(foldersCollapse); List<UUID> idFolders = strToIds(s); //noinspection unchecked, RedundantCast for (AbstractSearchFolder folder : (Collection<AbstractSearchFolder>) tree.getItemIds()) { if (idFolders.contains(folder.getId())) { tree.collapseItem(folder);/*from w w w . j av a 2 s .co m*/ } } tree.addExpandListener(new Tree.ExpandListener() { @Override public void nodeExpand(Tree.ExpandEvent event) { if (event.getItemId() instanceof AbstractSearchFolder) { UUID uuid = ((AbstractSearchFolder) event.getItemId()).getId(); String str = userSettingService.loadSetting(foldersCollapse); userSettingService.saveSetting(foldersCollapse, removeIdInStr(str, uuid)); } } }); tree.addCollapseListener(new Tree.CollapseListener() { @Override public void nodeCollapse(Tree.CollapseEvent event) { if (event.getItemId() instanceof AbstractSearchFolder) { UUID uuid = ((AbstractSearchFolder) event.getItemId()).getId(); String str = userSettingService.loadSetting(foldersCollapse); userSettingService.saveSetting(foldersCollapse, addIdInStr(str, uuid)); } } }); }
From source file:com.haulmont.cuba.web.app.folders.CubaFoldersPane.java
License:Apache License
protected Component createAppFoldersPane() { List<AppFolder> appFolders = foldersService.loadAppFolders(); if (appFolders.isEmpty()) return null; appFoldersTree = new CubaTree(); appFoldersTree.setCubaId("appFoldersTree"); appFoldersTree.setSelectable(true);/* w w w. ja va 2 s.c om*/ appFoldersTree.setItemStyleGenerator(new FolderTreeStyleProvider()); appFoldersTree.addShortcutListener( new ShortcutListener("applyAppFolder", ShortcutAction.KeyCode.ENTER, (int[]) null) { @Override public void handleAction(Object sender, Object target) { if (target == appFoldersTree) { AbstractSearchFolder folder = (AbstractSearchFolder) appFoldersTree.getValue(); if (folder != null) { openFolder(folder); } } } }); appFoldersTree.addExpandListener(new Tree.ExpandListener() { @Override public void nodeExpand(Tree.ExpandEvent event) { AppFolder folder = (AppFolder) event.getItemId(); if (StringUtils.isBlank(folder.getQuantityScript())) { folder.setQuantity(null); folder.setItemStyle(null); setFolderTreeItemCaption(appFoldersTree, folder); } } }); appFoldersTree.addCollapseListener(new Tree.CollapseListener() { @Override public void nodeCollapse(Tree.CollapseEvent event) { AppFolder folder = (AppFolder) event.getItemId(); if (StringUtils.isBlank(folder.getQuantityScript())) { reloadSingleParentFolder(folder, null); setFolderTreeItemCaption(appFoldersTree, folder); } } }); appFoldersRoot = messages.getMainMessage("folders.appFoldersRoot"); fillTree(appFoldersTree, appFolders, isNeedRootAppFolder() ? appFoldersRoot : null); appFoldersTree.addItemClickListener(new FolderClickListener()); appFoldersTree.addActionHandler(new AppFolderActionsHandler()); for (Object itemId : appFoldersTree.rootItemIds()) { appFoldersTree.expandItemsRecursively(itemId); } return appFoldersTree; }
From source file:com.mycollab.module.file.view.AbstractResourceMovingWindow.java
License:Open Source License
private void constructBody() { MVerticalLayout contentLayout = new MVerticalLayout(); new Restrain(contentLayout).setMaxHeight("600px"); this.setContent(contentLayout); folderTree = new Tree(); folderTree.setMultiSelect(false);/* w w w.j a va2 s .c o m*/ folderTree.setSelectable(true); folderTree.setImmediate(true); folderTree.setSizeFull(); folderTree.addExpandListener(expandEvent -> { final Folder expandFolder = (Folder) expandEvent.getItemId(); // load externalResource if currentExpandFolder is rootFolder if (baseFolder.getPath().equals(expandFolder.getPath())) { List<ExternalDrive> externalDrives = externalDriveService .getExternalDrivesOfUser(UserUIContext.getUsername()); for (ExternalDrive externalDrive : externalDrives) { ExternalFolder externalMapFolder = new ExternalFolder("/"); externalMapFolder.setStorageName(externalDrive.getStoragename()); externalMapFolder.setExternalDrive(externalDrive); externalMapFolder.setName(externalDrive.getFoldername()); Calendar cal = GregorianCalendar.getInstance(); cal.setTime(externalDrive.getCreatedtime()); externalMapFolder.setCreated(cal); expandFolder.addChild(externalMapFolder); folderTree.addItem(externalMapFolder); folderTree.setItemIcon(externalMapFolder, FontAwesome.DROPBOX); folderTree.setItemCaption(externalMapFolder, externalMapFolder.getName()); folderTree.setParent(externalMapFolder, expandFolder); } } if (expandFolder instanceof ExternalFolder) { List<ExternalFolder> subFolders = externalResourceService .getSubFolders(((ExternalFolder) expandFolder).getExternalDrive(), expandFolder.getPath()); for (final Folder subFolder : subFolders) { expandFolder.addChild(subFolder); folderTree.addItem(subFolder); folderTree.setItemIcon(subFolder, FontAwesome.DROPBOX); folderTree.setItemCaption(subFolder, subFolder.getName()); folderTree.setParent(subFolder, expandFolder); } } else { final List<Folder> subFolders = resourceService.getSubFolders(expandFolder.getPath()); folderTree.setItemIcon(expandFolder, FontAwesome.FOLDER_OPEN); if (subFolders != null) { for (final Folder subFolder : subFolders) { String subFolderName = subFolder.getName(); if (!subFolderName.startsWith(".")) { expandFolder.addChild(subFolder); folderTree.addItem(subFolder); folderTree.setItemIcon(subFolder, FontAwesome.FOLDER); folderTree.setItemCaption(subFolder, subFolderName); folderTree.setParent(subFolder, expandFolder); } } } } }); folderTree.addCollapseListener(new Tree.CollapseListener() { private static final long serialVersionUID = 1L; @Override public void nodeCollapse(final CollapseEvent event) { final Folder collapseFolder = (Folder) event.getItemId(); if (collapseFolder instanceof ExternalFolder) { folderTree.setItemIcon(collapseFolder, FontAwesome.DROPBOX); } else { folderTree.setItemIcon(collapseFolder, FontAwesome.FOLDER); } collapseFolder.getChilds().forEach(this::recursiveRemoveSubItem); } private void recursiveRemoveSubItem(Folder collapseFolder) { List<Folder> childFolders = collapseFolder.getChilds(); if (childFolders.size() > 0) { childFolders.forEach(this::recursiveRemoveSubItem); folderTree.removeItem(collapseFolder); } else { folderTree.removeItem(collapseFolder); } } }); folderTree.addItemClickListener(itemClickEvent -> baseFolder = (Folder) itemClickEvent.getItemId()); CssLayout treeWrapper = new CssLayout(folderTree); treeWrapper.setSizeFull(); contentLayout.addComponent(treeWrapper); displayFiles(); MButton moveBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.ACTION_MOVE), clickEvent -> { if (!CollectionUtils.isEmpty(movedResources)) { boolean checkingFail = false; for (Resource res : movedResources) { try { resourceMover.moveResource(res, baseFolder, UserUIContext.getUsername(), MyCollabUI.getAccountId()); } catch (Exception e) { checkingFail = true; LOG.error("Error", e); } } close(); displayAfterMoveSuccess(baseFolder, checkingFail); } }).withIcon(FontAwesome.ARROWS).withStyleName(WebThemes.BUTTON_ACTION); MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL), clickEvent -> close()).withStyleName(WebThemes.BUTTON_OPTION); MHorizontalLayout controlGroupBtnLayout = new MHorizontalLayout(cancelBtn, moveBtn); contentLayout.with(controlGroupBtnLayout).withAlign(controlGroupBtnLayout, Alignment.MIDDLE_RIGHT); }
From source file:com.mycollab.module.file.view.components.AbstractResourceMovingWindow.java
License:Open Source License
private void constructBody() { MVerticalLayout contentLayout = new MVerticalLayout(); new Restrain(contentLayout).setMaxHeight("600px"); this.setContent(contentLayout); folderTree = new Tree(); folderTree.setMultiSelect(false);//from w w w . jav a 2s . com folderTree.setSelectable(true); folderTree.setImmediate(true); folderTree.setSizeFull(); folderTree.addExpandListener(new Tree.ExpandListener() { private static final long serialVersionUID = 1L; @Override public void nodeExpand(final ExpandEvent event) { final Folder expandFolder = (Folder) event.getItemId(); // load externalResource if currentExpandFolder is rootFolder if (baseFolder.getPath().equals(expandFolder.getPath())) { List<ExternalDrive> externalDrives = externalDriveService .getExternalDrivesOfUser(AppContext.getUsername()); for (ExternalDrive externalDrive : externalDrives) { ExternalFolder externalMapFolder = new ExternalFolder("/"); externalMapFolder.setStorageName(externalDrive.getStoragename()); externalMapFolder.setExternalDrive(externalDrive); externalMapFolder.setName(externalDrive.getFoldername()); Calendar cal = GregorianCalendar.getInstance(); cal.setTime(externalDrive.getCreatedtime()); externalMapFolder.setCreated(cal); expandFolder.addChild(externalMapFolder); folderTree.addItem(externalMapFolder); folderTree.setItemIcon(externalMapFolder, FontAwesome.DROPBOX); folderTree.setItemCaption(externalMapFolder, externalMapFolder.getName()); folderTree.setParent(externalMapFolder, expandFolder); } } if (expandFolder instanceof ExternalFolder) { List<ExternalFolder> subFolders = externalResourceService.getSubFolders( ((ExternalFolder) expandFolder).getExternalDrive(), expandFolder.getPath()); for (final Folder subFolder : subFolders) { expandFolder.addChild(subFolder); folderTree.addItem(subFolder); folderTree.setItemIcon(subFolder, FontAwesome.DROPBOX); folderTree.setItemCaption(subFolder, subFolder.getName()); folderTree.setParent(subFolder, expandFolder); } } else { final List<Folder> subFolders = resourceService.getSubFolders(expandFolder.getPath()); folderTree.setItemIcon(expandFolder, FontAwesome.FOLDER_OPEN); if (subFolders != null) { for (final Folder subFolder : subFolders) { String subFolderName = subFolder.getName(); if (!subFolderName.startsWith(".")) { expandFolder.addChild(subFolder); folderTree.addItem(subFolder); folderTree.setItemIcon(subFolder, FontAwesome.FOLDER); folderTree.setItemCaption(subFolder, subFolderName); folderTree.setParent(subFolder, expandFolder); } } } } } }); folderTree.addCollapseListener(new Tree.CollapseListener() { private static final long serialVersionUID = 1L; @Override public void nodeCollapse(final CollapseEvent event) { final Folder collapseFolder = (Folder) event.getItemId(); if (collapseFolder instanceof ExternalFolder) { folderTree.setItemIcon(collapseFolder, FontAwesome.DROPBOX); } else { folderTree.setItemIcon(collapseFolder, FontAwesome.FOLDER); } for (Folder folder : collapseFolder.getChilds()) { recursiveRemoveSubItem(folder); } } private void recursiveRemoveSubItem(Folder collapseFolder) { List<Folder> childFolders = collapseFolder.getChilds(); if (childFolders.size() > 0) { for (Folder subFolder : childFolders) { recursiveRemoveSubItem(subFolder); } folderTree.removeItem(collapseFolder); } else { folderTree.removeItem(collapseFolder); } } }); folderTree.addItemClickListener(new ItemClickEvent.ItemClickListener() { private static final long serialVersionUID = 1L; @Override public void itemClick(final ItemClickEvent event) { baseFolder = (Folder) event.getItemId(); } }); CssLayout treeWrapper = new CssLayout(folderTree); treeWrapper.setSizeFull(); contentLayout.addComponent(treeWrapper); displayFiles(); MHorizontalLayout controlGroupBtnLayout = new MHorizontalLayout(); Button moveBtn = new Button("Move", new ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { if (!CollectionUtils.isEmpty(movedResources)) { boolean checkingFail = false; for (Resource res : movedResources) { try { resourceMover.moveResource(res, baseFolder, AppContext.getUsername(), AppContext.getAccountId()); } catch (Exception e) { checkingFail = true; LOG.error("Error", e); } } close(); displayAfterMoveSuccess(baseFolder, checkingFail); } } }); moveBtn.setIcon(FontAwesome.ARROWS); moveBtn.addStyleName(UIConstants.BUTTON_ACTION); Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { close(); } }); cancelBtn.addStyleName(UIConstants.BUTTON_OPTION); controlGroupBtnLayout.with(cancelBtn, moveBtn); contentLayout.with(controlGroupBtnLayout).withAlign(controlGroupBtnLayout, Alignment.MIDDLE_RIGHT); }