List of usage examples for com.vaadin.ui Label setValue
public void setValue(String value)
From source file:views.MetadataUploadView.java
License:Open Source License
protected void createVocabularySelectWindow(ComboBox selected, String propName, List<Label> entries) { Window subWindow = new Window(" " + propName); subWindow.setWidth("300px"); VerticalLayout layout = new VerticalLayout(); layout.setMargin(true);/*w ww .j ava 2 s .c om*/ layout.setSpacing(true); // create combobox per unique value for this column to find a mapping to the source vocabulary Map<String, String> entriesToVocabValues = new HashMap<String, String>(); Set<String> uniqueEntries = new HashSet<String>(); // keep these old values in case user chooses different property afterwards List<String> oldEntries = new ArrayList<String>(); ValueChangeListener resetSelectionListener = new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { // reset labels to what they were before for (int i = 0; i < entries.size(); i++) { entries.get(i).setValue(oldEntries.get(i)); } // remove reset listener, it won't be needed until a vocabulary field is selected again selected.removeValueChangeListener(this); } }; selected.addValueChangeListener(resetSelectionListener); List<ComboBox> boxes = new ArrayList<ComboBox>(); Set<String> vocabOptions = propToVocabulary.get(propNameToCode.get(propName)).keySet(); for (Label l : entries) { String val = l.getValue(); oldEntries.add(val); if (!uniqueEntries.contains(val)) { ComboBox b = new ComboBox(val); b.addItems(vocabOptions); b.setNullSelectionAllowed(false); b.setStyleName(Styles.boxTheme); b.setFilteringMode(FilteringMode.CONTAINS); layout.addComponent(b); boxes.add(b); uniqueEntries.add(val); val = StringUtils.capitalize(val); if (vocabOptions.contains(val)) { b.setValue(val); b.setEnabled(false); } } } Button send = new Button("Ok"); send.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { boolean valid = true; for (ComboBox b : boxes) { if (b.getValue() != null) { String newVal = b.getValue().toString(); entriesToVocabValues.put(b.getCaption(), newVal); } else valid = false; } if (valid) { for (Label l : entries) { l.setValue(entriesToVocabValues.get(l.getValue())); } subWindow.close(); // check for collisions now that values have changed reactToTableChange(); } else { String error = "Please select a value for each entry."; Styles.notification("Missing Input", error, NotificationType.DEFAULT); } } }); layout.addComponent(send); subWindow.setContent(layout); // Center it in the browser window subWindow.center(); subWindow.setModal(true); subWindow.setIcon(FontAwesome.FLASK); subWindow.setResizable(false); ProjectwizardUI ui = (ProjectwizardUI) UI.getCurrent(); ui.addWindow(subWindow); }
From source file:views.MetadataUploadView.java
License:Open Source License
private void writeLabelCell(int id, Object propertyId, String text) { Item item = getActiveTable().getItem(id); Label l = (Label) item.getItemProperty(propertyId).getValue(); l.setValue(text); }