List of usage examples for com.vaadin.ui Tree setSizeFull
@Override public void setSizeFull()
From source file:com.klwork.explorer.ui.AbstractTreePage.java
License:Apache License
@Override protected AbstractSelect createSelectComponent() { Tree tree = createTree(); tree.setSizeFull(); return tree; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.RiskManagementComponent.java
License:Apache License
public RiskManagementComponent(Project p) { setSplitPosition(25, Unit.PERCENTAGE); setLocked(true);/* w ww .j av a 2s .c om*/ Tree tree = new Tree("Test"); tree.setSizeFull(); tree.addItem(p); tree.setItemCaption(p, p.getName()); p.getFmeaList().forEach(fmea -> { tree.addItem(fmea); tree.setItemCaption(fmea, fmea.getName()); tree.setParent(fmea, p); }); TreeTable ttable = new TreeTable("FMEA"); ttable.addContainerProperty("Name", String.class, null); ttable.addContainerProperty("Hazard", String.class, null); ttable.addContainerProperty("Failure Mode", String.class, null); ttable.addContainerProperty("Cause", String.class, null); ttable.setSizeFull(); tree.addItemClickListener(event -> { if (event.getItem() != null) { Item clicked = event.getItem(); tree.select(event.getItemId()); } if (tree.getValue() != null && tree.getValue() instanceof Fmea) { Fmea fmea = (Fmea) tree.getValue(); fmea.getRiskCategoryList().forEach(rc -> { ttable.addGeneratedColumn(rc.getName(), (Table source, Object itemId, Object columnId) -> { if (itemId instanceof String) { String id = (String) itemId; if (id.startsWith("hazard")) { //We have one of our entries StringTokenizer st = new StringTokenizer(id.substring(id.indexOf("-") + 1), "-"); FailureModeHasCauseHasRiskCategoryJpaController c = new FailureModeHasCauseHasRiskCategoryJpaController( DataBaseManager.getEntityManagerFactory()); FailureModeHasCauseHasRiskCategory fmhchrc = c .findFailureModeHasCauseHasRiskCategory( new FailureModeHasCauseHasRiskCategoryPK( Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), rc.getId())); if (fmhchrc != null) { RiskCategory cat = fmhchrc.getRiskCategory(); if (cat.getCategoryEquation() != null && !cat.getCategoryEquation().trim().isEmpty()) { //Calculate based on equation Double result = Tool.evaluateEquation(fmhchrc); //Update record if result changed LOG.log(Level.FINE, "Result: {0}", result); if (result != fmhchrc.getCategoryValue()) { try { fmhchrc.setCategoryValue(result); c.edit(fmhchrc); } catch (Exception ex) { Exceptions.printStackTrace(ex); return new Label("Error!"); } } } //Return result in label. return new Label("" + fmhchrc.getCategoryValue()); } } } return new Label(); }); }); ttable.removeAllItems(); fmea.getRiskItemList().forEach(item -> { ttable.addItem(new Object[] { item.getDescription(), null, null, null }, item.getRiskItemPK().getId()); item.getRiskItemHasHazardList().forEach(rihh -> { rihh.getHazardHasFailureModeList().forEach(hhfm -> { hhfm.getFailureModeHasCauseList().forEach(fmhc -> { String hkey = "hazard-" + item.getRiskItemPK().getId() + "-" + fmea.getFmeaPK().getId() + "-" + fmea.getFmeaPK().getProjectId() + "-" + rihh.getHazard().getId() + "-" + hhfm.getFailureMode().getId() + "-" + fmhc.getCause().getId(); ttable.addItem( new Object[] { null, rihh.getHazard().getName(), hhfm.getFailureMode().getName(), fmhc.getCause().getDescription() }, hkey); ttable.setParent(hkey, item.getRiskItemPK().getId()); //No children ttable.setChildrenAllowed(hkey, false); }); }); }); }); } }); ContextMenu contextMenu = new ContextMenu(tree, true); tree.addItemClickListener((ItemClickEvent event) -> { if (event.getButton() == MouseButton.RIGHT) { contextMenu.removeItems(); } }); setFirstComponent(tree); setSecondComponent(ttable); setSizeFull(); }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI.java
License:Apache License
private void createTree() { tree = new ProjectTreeComponent(); // Set the tree in drag source mode tree.setDragMode(TreeDragMode.NODE); // Allow the tree to receive drag drops and handle them tree.setDropHandler(new DropHandler() { @Override/*from w w w . ja v a 2s .c om*/ public AcceptCriterion getAcceptCriterion() { TreeDropCriterion criterion = new TreeDropCriterion() { @Override protected Set<Object> getAllowedItemIds(DragAndDropEvent dragEvent, Tree tree) { HashSet<Object> allowed = new HashSet<>(); tree.getItemIds().stream() .filter((itemId) -> (itemId instanceof Step) || (itemId instanceof Requirement)) .forEachOrdered((itemId) -> { allowed.add(itemId); }); return allowed; } }; return criterion; } @Override public void drop(DragAndDropEvent event) { // Wrapper for the object that is dragged Transferable t = event.getTransferable(); // Make sure the drag source is the same tree if (t.getSourceComponent() != tree) { return; } TreeTargetDetails target = (TreeTargetDetails) event.getTargetDetails(); // Get ids of the dragged item and the target item Object sourceItemId = t.getData("itemId"); Object targetItemId = target.getItemIdOver(); LOG.log(Level.INFO, "Source: {0}", sourceItemId); LOG.log(Level.INFO, "Target: {0}", targetItemId); // On which side of the target the item was dropped VerticalDropLocation location = target.getDropLocation(); HierarchicalContainer container = (HierarchicalContainer) tree.getContainerDataSource(); if (null != location) // Drop right on an item -> make it a child { switch (location) { case MIDDLE: if (tree.areChildrenAllowed(targetItemId)) { tree.setParent(sourceItemId, targetItemId); } break; case TOP: { boolean valid = false; //for Steps we need to update the sequence number if (sourceItemId instanceof Step && targetItemId instanceof Step) { Step targetItem = (Step) targetItemId; Step sourceItem = (Step) sourceItemId; StepJpaController stepController = new StepJpaController( DataBaseManager.getEntityManagerFactory()); if (targetItem.getTestCase().equals(sourceItem.getTestCase())) { //Same Test Case, just re-arrange LOG.info("Same Test Case!"); SortedMap<Integer, Step> map = new TreeMap<>(); targetItem.getTestCase().getStepList().forEach((s) -> { map.put(s.getStepSequence(), s); }); //Now swap the two that switched swapValues(map, sourceItem.getStepSequence(), targetItem.getStepSequence()); //Now update the sequence numbers int count = 0; for (Entry<Integer, Step> entry : map.entrySet()) { entry.getValue().setStepSequence(++count); try { stepController.edit(entry.getValue()); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); } } valid = true; } else { //Diferent Test Case LOG.info("Different Test Case!"); // //Remove from source test case // SortedMap<Integer, Step> map = new TreeMap<>(); // sourceItem.getTestCase().getStepList().forEach((s) -> { // map.put(s.getStepSequence(), s); // }); // //Now swap the two that switched // //First we remove the one from the source Test Case // Step removed = map.remove(sourceItem.getStepSequence() - 1); // sourceItem.getTestCase().getStepList().remove(removed); // removed.setTestCase(targetItem.getTestCase()); // try { // stepController.edit(removed); // tcController.edit(sourceItem.getTestCase()); // } catch (NonexistentEntityException ex) { // LOG.log(Level.SEVERE, null, ex); // } catch (Exception ex) { // LOG.log(Level.SEVERE, null, ex); // } // //Now update the sequence numbers // int count = 0; // for (Entry<Integer, Step> entry : map.entrySet()) { // entry.getValue().setStepSequence(++count); // try { // stepController.edit(entry.getValue()); // } catch (Exception ex) { // LOG.log(Level.SEVERE, null, ex); // } // } // //And add it to the target test Case // SortedMap<Integer, Step> map2 = new TreeMap<>(); // targetItem.getTestCase().getStepList().forEach((s) -> { // map2.put(s.getStepSequence(), s); // }); // map2.put(targetItem.getStepSequence() - 1, removed); // count = 0; // for (Entry<Integer, Step> entry : map2.entrySet()) { // entry.getValue().setStepSequence(++count); // try { // stepController.edit(entry.getValue()); // } catch (Exception ex) { // LOG.log(Level.SEVERE, null, ex); // } // } // //Add it to the Test Case // targetItem.getTestCase().getStepList().add(removed); } } if (valid) { // Drop at the top of a subtree -> make it previous Object parentId = container.getParent(targetItemId); container.setParent(sourceItemId, parentId); container.moveAfterSibling(sourceItemId, targetItemId); container.moveAfterSibling(targetItemId, sourceItemId); buildProjectTree(targetItemId); updateScreen(); } break; } case BOTTOM: { // Drop below another item -> make it next Object parentId = container.getParent(targetItemId); container.setParent(sourceItemId, parentId); container.moveAfterSibling(sourceItemId, targetItemId); break; } default: break; } } } }); tree.addValueChangeListener((Property.ValueChangeEvent event) -> { displayObject(tree.getValue()); }); //Select item on right click as well tree.addItemClickListener((ItemClickEvent event) -> { if (event.getSource() == tree && event.getButton() == MouseButton.RIGHT) { if (event.getItem() != null) { Item clicked = event.getItem(); tree.select(event.getItemId()); } } }); ContextMenu contextMenu = new ContextMenu(tree, true); tree.addItemClickListener((ItemClickEvent event) -> { if (event.getButton() == MouseButton.RIGHT) { contextMenu.removeItems(); if (tree.getValue() instanceof Project) { createProjectMenu(contextMenu); } else if (tree.getValue() instanceof Requirement) { createRequirementMenu(contextMenu); } else if (tree.getValue() instanceof RequirementSpec) { createRequirementSpecMenu(contextMenu); } else if (tree.getValue() instanceof RequirementSpecNode) { createRequirementSpecNodeMenu(contextMenu); } else if (tree.getValue() instanceof TestProject) { createTestProjectMenu(contextMenu); } else if (tree.getValue() instanceof Step) { createStepMenu(contextMenu); } else if (tree.getValue() instanceof TestCase) { createTestCaseMenu(contextMenu); } else if (tree.getValue() instanceof String) { String val = (String) tree.getValue(); if (val.startsWith("tce")) { createTestExecutionMenu(contextMenu); } else if (val.startsWith("executions")) { createExecutionsMenu(contextMenu); } else { //We are at the root createRootMenu(contextMenu); } } else if (tree.getValue() instanceof TestPlan) { createTestPlanMenu(contextMenu); } else if (tree.getValue() instanceof TestCaseExecution) { createTestCaseExecutionPlanMenu(contextMenu); } else if (tree.getValue() instanceof Baseline) { // createBaselineMenu(contextMenu); } } }); tree.setImmediate(true); tree.expandItem(projTreeRoot); tree.setSizeFull(); updateProjectList(); }
From source file:org.ow2.sirocco.cloudmanager.MyUI.java
License:Open Source License
Tree createLeftMenu() { final Tree resourceTree = new Tree("Root"); resourceTree.setStyleName("myTree"); resourceTree.setImmediate(true);/*from w w w .j av a 2 s. c o m*/ resourceTree.setSizeFull(); resourceTree.addItem(MyUI.PROVIDERS_MENU_ITEM_ID); resourceTree.setItemIcon(MyUI.PROVIDERS_MENU_ITEM_ID, new ThemeResource("img/cloud.png")); resourceTree.setChildrenAllowed(MyUI.PROVIDERS_MENU_ITEM_ID, false); // resourceTree.addItem(MyUI.COMPUTE_MENU_ITEM_ID); resourceTree.addItem(MyUI.INSTANCES_MENU_ITEM_ID); resourceTree.setItemIcon(MyUI.INSTANCES_MENU_ITEM_ID, new ThemeResource("img/server.png")); resourceTree.setChildrenAllowed(MyUI.INSTANCES_MENU_ITEM_ID, false); // resourceTree.setParent(MyUI.INSTANCES_MENU_ITEM_ID, MyUI.COMPUTE_MENU_ITEM_ID); resourceTree.addItem(MyUI.IMAGES_MENU_ITEM_ID); resourceTree.setItemIcon(MyUI.IMAGES_MENU_ITEM_ID, new ThemeResource("img/image.png")); resourceTree.setItemCaption(MyUI.IMAGES_MENU_ITEM_ID, " Images"); resourceTree.setChildrenAllowed(MyUI.IMAGES_MENU_ITEM_ID, false); // resourceTree.setParent(MyUI.IMAGES_MENU_ITEM_ID, MyUI.COMPUTE_MENU_ITEM_ID); // resourceTree.addItem(MyUI.STORAGE_MENU_ITEM_ID); resourceTree.addItem(MyUI.VOLUMES_MENU_ITEM_ID); resourceTree.setItemIcon(MyUI.VOLUMES_MENU_ITEM_ID, new ThemeResource("img/disk.png")); resourceTree.setItemCaption(MyUI.VOLUMES_MENU_ITEM_ID, " Volumes"); resourceTree.setChildrenAllowed(MyUI.VOLUMES_MENU_ITEM_ID, false); // resourceTree.setParent(MyUI.VOLUMES_MENU_ITEM_ID, MyUI.STORAGE_MENU_ITEM_ID); // resourceTree.addItem(MyUI.NETWORKING_MENU_ITEM_ID); resourceTree.addItem(MyUI.NETWORKS_MENU_ITEM_ID); resourceTree.setItemIcon(MyUI.NETWORKS_MENU_ITEM_ID, new ThemeResource("img/network.png")); resourceTree.setChildrenAllowed(MyUI.NETWORKS_MENU_ITEM_ID, false); // resourceTree.setParent(MyUI.NETWORKS_MENU_ITEM_ID, MyUI.NETWORKING_MENU_ITEM_ID); resourceTree.addItem(MyUI.ADDRESSES_MENU_ITEM_ID); resourceTree.setItemIcon(MyUI.ADDRESSES_MENU_ITEM_ID, new ThemeResource("img/ip-icon.png")); resourceTree.setChildrenAllowed(MyUI.ADDRESSES_MENU_ITEM_ID, false); resourceTree.addItem(MyUI.SECURITY_GROUP_MENU_ITEM_ID); resourceTree.setItemIcon(MyUI.SECURITY_GROUP_MENU_ITEM_ID, new ThemeResource("img/secgroup.png")); resourceTree.setChildrenAllowed(MyUI.SECURITY_GROUP_MENU_ITEM_ID, false); // resourceTree.addItem(MyUI.SECURITY_MENU_ITEM_ID); resourceTree.addItem(MyUI.KEYPAIRS_MENU_ITEM_ID); resourceTree.setItemIcon(MyUI.KEYPAIRS_MENU_ITEM_ID, new ThemeResource("img/key.png")); resourceTree.setChildrenAllowed(MyUI.KEYPAIRS_MENU_ITEM_ID, false); // resourceTree.setParent(MyUI.KEYPAIRS_MENU_ITEM_ID, MyUI.SECURITY_MENU_ITEM_ID); // resourceTree.expandItemsRecursively(MyUI.COMPUTE_MENU_ITEM_ID); // resourceTree.expandItemsRecursively(MyUI.STORAGE_MENU_ITEM_ID); // resourceTree.expandItemsRecursively(MyUI.NETWORKING_MENU_ITEM_ID); // resourceTree.expandItemsRecursively(MyUI.SECURITY_MENU_ITEM_ID); resourceTree.select(MyUI.INSTANCES_MENU_ITEM_ID); resourceTree.addValueChangeListener(new ValueChangeListener() { Object previous = null; @Override public void valueChange(final ValueChangeEvent event) { if (resourceTree.getValue() != null) { if (resourceTree.hasChildren(resourceTree.getValue())) { resourceTree.setValue(this.previous); } else { this.previous = resourceTree.getValue(); switch ((String) resourceTree.getValue()) { case PROVIDERS_MENU_ITEM_ID: MyUI.this.inventoryContainer.replaceComponent( MyUI.this.inventoryContainer.getComponent(0), MyUI.this.providerView); break; case INSTANCES_MENU_ITEM_ID: MyUI.this.inventoryContainer.replaceComponent( MyUI.this.inventoryContainer.getComponent(0), MyUI.this.machineView); break; case IMAGES_MENU_ITEM_ID: MyUI.this.inventoryContainer.replaceComponent( MyUI.this.inventoryContainer.getComponent(0), MyUI.this.machineImageView); break; case VOLUMES_MENU_ITEM_ID: MyUI.this.inventoryContainer.replaceComponent( MyUI.this.inventoryContainer.getComponent(0), MyUI.this.volumeView); break; case NETWORKS_MENU_ITEM_ID: MyUI.this.inventoryContainer.replaceComponent( MyUI.this.inventoryContainer.getComponent(0), MyUI.this.networkView); break; case ADDRESSES_MENU_ITEM_ID: MyUI.this.inventoryContainer.replaceComponent( MyUI.this.inventoryContainer.getComponent(0), MyUI.this.addressView); break; case SECURITY_GROUP_MENU_ITEM_ID: MyUI.this.inventoryContainer.replaceComponent( MyUI.this.inventoryContainer.getComponent(0), MyUI.this.secGroupView); break; case KEYPAIRS_MENU_ITEM_ID: MyUI.this.inventoryContainer.replaceComponent( MyUI.this.inventoryContainer.getComponent(0), MyUI.this.keyPairView); break; } } } } }); return resourceTree; }