List of usage examples for com.vaadin.server FontAwesome COLUMNS
FontAwesome COLUMNS
To view the source code for com.vaadin.server FontAwesome COLUMNS.
Click Source Link
From source file:org.jumpmind.metl.ui.views.design.EditModelPanel.java
License:Open Source License
public EditModelPanel(ApplicationContext context, String modelId, boolean readOnly) { this.context = context; this.model = new Model(modelId); this.readOnly = readOnly; context.getConfigurationService().refresh(model); ButtonBar buttonBar = new ButtonBar(); addComponent(buttonBar);//from ww w .j a v a 2 s .c o m if (!readOnly) { addEntityButton = buttonBar.addButton("Add Entity", FontAwesome.TABLE); addEntityButton.addClickListener(new AddEntityClickListener()); addAttributeButton = buttonBar.addButton("Add Attribute", FontAwesome.COLUMNS); addAttributeButton.addClickListener(new AddAttributeClickListener()); editButton = buttonBar.addButton("Edit", FontAwesome.EDIT); editButton.addClickListener(new EditClickListener()); removeButton = buttonBar.addButton("Remove", FontAwesome.TRASH_O); removeButton.addClickListener(new RemoveClickListener()); importButton = buttonBar.addButton("Import ...", FontAwesome.DOWNLOAD); importButton.addClickListener(new ImportClickListener()); } filterField = buttonBar.addFilter(); filterField.addTextChangeListener(new TextChangeListener() { public void textChange(TextChangeEvent event) { filterField.setValue(event.getText()); treeTable.removeAllItems(); addAll(event.getText(), EditModelPanel.this.model.getModelEntities()); } }); treeTable.setSizeFull(); treeTable.setCacheRate(100); treeTable.setPageLength(100); treeTable.setImmediate(true); treeTable.setSelectable(true); treeTable.setMultiSelect(true); treeTable.addGeneratedColumn("name", new ColumnGenerator() { public Object generateCell(Table source, Object itemId, Object columnId) { final AbstractObject obj = (AbstractObject) itemId; if (lastEditItemIds.contains(itemId) && !readOnly) { ImmediateUpdateTextField t = new ImmediateUpdateTextField(null) { protected void save(String text) { obj.setName(text); EditModelPanel.this.context.getConfigurationService().save(obj); }; }; t.setWidth(100, Unit.PERCENTAGE); t.setValue(obj.getName()); t.focus(); t.selectAll(); return t; } else { return UiUtils.getName(filterField.getValue(), obj.getName()); } } }); treeTable.setColumnHeader("name", "Name"); treeTable.addGeneratedColumn("description", new ColumnGenerator() { public Object generateCell(Table source, Object itemId, Object columnId) { if (itemId instanceof ModelAttribute) { final ModelAttribute obj = (ModelAttribute) itemId; if (lastEditItemIds.contains(itemId) && !readOnly) { ImmediateUpdateTextField t = new ImmediateUpdateTextField(null) { protected void save(String text) { obj.setDescription(text); EditModelPanel.this.context.getConfigurationService().save(obj); }; }; t.setWidth(100, Unit.PERCENTAGE); t.setValue(obj.getDescription()); return t; } else { return UiUtils.getName(filterField.getValue(), obj.getDescription()); } } if (itemId instanceof ModelEntity) { final ModelEntity obj = (ModelEntity) itemId; if (lastEditItemIds.contains(itemId) && !readOnly) { ImmediateUpdateTextField t = new ImmediateUpdateTextField(null) { protected void save(String text) { obj.setDescription(text); EditModelPanel.this.context.getConfigurationService().save(obj); }; }; t.setWidth(100, Unit.PERCENTAGE); t.setValue(obj.getDescription()); return t; } else { return UiUtils.getName(filterField.getValue(), obj.getDescription()); } } else return null; } }); treeTable.setColumnHeader("description", "Description"); treeTable.addGeneratedColumn("type", new ColumnGenerator() { public Object generateCell(Table source, Object itemId, Object columnId) { if (itemId instanceof ModelAttribute) { final ModelAttribute obj = (ModelAttribute) itemId; if (lastEditItemIds.contains(itemId) && !readOnly) { final ComboBox cbox = new ComboBox(); cbox.setNullSelectionAllowed(false); for (DataType dataType : DataType.values()) { cbox.addItem(dataType.name()); } cbox.setValue(obj.getType()); cbox.addValueChangeListener(new ValueChangeListener() { public void valueChange(ValueChangeEvent event) { obj.setType((String) cbox.getValue()); EditModelPanel.this.context.getConfigurationService().save(obj); } }); cbox.addBlurListener(new BlurListener() { public void blur(BlurEvent event) { Collection<?> items = treeTable.getItemIds(); boolean found = false; for (Object item : items) { if (item.equals(obj)) { found = true; } else if (found) { selectOnly(item); editSelectedItem(); break; } } } }); return cbox; } else { return obj.getType(); } } else { return null; } } }); treeTable.setColumnHeader("type", "Type"); treeTable.addGeneratedColumn("pk", new ColumnGenerator() { public Object generateCell(Table source, Object itemId, Object columnId) { if (itemId instanceof ModelAttribute) { final ModelAttribute obj = (ModelAttribute) itemId; if (lastEditItemIds.contains(itemId) && !readOnly) { final CheckBox cbox = new CheckBox(); cbox.setValue(obj.isPk()); cbox.setImmediate(true); cbox.addValueChangeListener(event -> togglePk(obj)); cbox.addBlurListener(new BlurListener() { public void blur(BlurEvent event) { Collection<?> items = treeTable.getItemIds(); boolean found = false; for (Object item : items) { if (item.equals(obj)) { found = true; } else if (found) { selectOnly(item); editSelectedItem(); break; } } } }); return cbox; } else if (obj.isPk()) { return new Label(FontAwesome.KEY.getHtml(), ContentMode.HTML); } } return null; } }); treeTable.setColumnHeader("pk", "PK"); treeTable.setColumnWidth("pk", 40); treeTable.addItemClickListener(new TreeTableItemClickListener()); treeTable.addValueChangeListener(new TreeTableValueChangeListener()); enterKeyListener = new ShortcutListener("Enter", KeyCode.ENTER, null) { public void handleAction(Object sender, Object target) { lastEditItemIds = Collections.emptySet(); treeTable.refreshRowCache(); } }; addComponent(treeTable); setExpandRatio(treeTable, 1.0f); HorizontalLayout hlayout = new HorizontalLayout(); addComponent(hlayout); Button collapseAll = new Button("Collapse All"); collapseAll.addStyleName(ValoTheme.BUTTON_LINK); collapseAll.addStyleName(ValoTheme.BUTTON_SMALL); hlayout.addComponent(collapseAll); collapseAll.addClickListener(new ClickListener() { public void buttonClick(ClickEvent event) { for (Object itemId : treeTable.getItemIds()) { treeTable.setCollapsed(itemId, true); } } }); Button expandAll = new Button("Expand All"); expandAll.addStyleName(ValoTheme.BUTTON_LINK); expandAll.addStyleName(ValoTheme.BUTTON_SMALL); hlayout.addComponent(expandAll); expandAll.addClickListener(new ClickListener() { public void buttonClick(ClickEvent event) { for (Object itemId : treeTable.getItemIds()) { treeTable.setCollapsed(itemId, false); } } }); addAll("", model.getModelEntities()); setButtonsEnabled(); }
From source file:org.jumpmind.metl.ui.views.design.EditModelPanel.java
License:Open Source License
protected void addModelAttribute(ModelEntity entity, ModelAttribute modelAttribute) { treeTable.addItem(modelAttribute);/*from w w w .j a va 2 s . com*/ treeTable.setItemIcon(modelAttribute, FontAwesome.COLUMNS); treeTable.setChildrenAllowed(entity, true); treeTable.setParent(modelAttribute, entity); treeTable.setChildrenAllowed(modelAttribute, false); }