List of usage examples for com.vaadin.ui ComboBox addValueChangeListener
@Override
public Registration addValueChangeListener(HasValue.ValueChangeListener<T> listener)
From source file:rs.pupin.jpo.validation.gui.constraints.Provenance.java
@Override public void generateGUI() { rootLayout.removeAllComponents();/*from w w w.j av a2 s . c o m*/ final String[] metaProps = new String[] { "rdfs:label", "rdfs:comment", "dct:title", "dct:description", "dct:issued", "dct:modified", "dct:subject", "dct:publisher", "dct:licence" }; final Label label = new Label( "It is recommended to mark datasets with metadata tu support discovery, presentation and processing. Choose a dataset below and check the values for recommended core set of metadata", Label.CONTENT_TEXT); rootLayout.addComponent(label); Iterator<BindingSet> res = icQuery.getResults(); if (res == null) { label.setValue("ERROR"); return; } final HashMap<String, ArrayList<Value>> map = new HashMap<String, ArrayList<Value>>(); while (res.hasNext()) { BindingSet set = res.next(); String ds = set.getValue("ds").stringValue(); ArrayList<Value> values = new ArrayList<Value>(9); values.add(set.getValue("label")); values.add(set.getValue("comment")); values.add(set.getValue("title")); values.add(set.getValue("description")); values.add(set.getValue("issued")); values.add(set.getValue("modified")); values.add(set.getValue("subject")); values.add(set.getValue("publisher")); values.add(set.getValue("licence")); map.put(ds, values); } final ComboBox combo = new ComboBox("Choose dataset", map.keySet()); combo.setWidth("100%"); combo.setNullSelectionAllowed(false); combo.setImmediate(true); rootLayout.addComponent(combo); final Table table = new Table("Metadata of the chosen dataset"); table.setWidth("100%"); table.addContainerProperty("Property", String.class, null); table.addContainerProperty("Value", Value.class, null); rootLayout.addComponent(table); Button editInOW = new Button("Edit in OntoWiki"); rootLayout.addComponent(editInOW); rootLayout.setExpandRatio(editInOW, 2.0f); editInOW.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { // TODO do something here } }); combo.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { ArrayList<Value> list = map.get((String) event.getProperty().getValue()); table.removeAllItems(); for (int i = 0; i < metaProps.length; i++) { table.addItem(new Object[] { metaProps[i], list.get(i) }, i); } } }); }
From source file:uicomponents.MSSampleMultiplicationTable.java
License:Open Source License
public void setAnalyteSamples(List<AOpenbisSample> proteins, HashMap<Integer, Integer> tableIdToFractions, boolean peptides) { sampleTable.removeAllItems();//from w w w . ja v a 2s. c om tableIdToParent = new HashMap<String, AOpenbisSample>(); enzymeMap = new HashMap<String, List<String>>(); int i = 0; for (AOpenbisSample s : proteins) { i++; // multiply by number of fractions for (int j = 1; j <= tableIdToFractions.get(i); j++) { boolean complexRow = sampleTable.size() == 0; // the first row contains a combobox with // added // button to copy // its selection to the whole column String parentID = Integer.toString(i); String fractionID = Integer.toString(j); String id = parentID + "-" + fractionID; tableIdToParent.put(id, s); List<Object> row = new ArrayList<Object>(); Label sample = new Label(s.getQ_SECONDARY_NAME() + "<br>" + s.getQ_EXTERNALDB_ID(), Label.CONTENT_XHTML); row.add(sample); Label num = new Label(fractionID); row.add(num); TextField secNameInput = generateTableTextInput("200px"); secNameInput.setValue(s.getQ_SECONDARY_NAME() + " " + type + " #" + fractionID); row.add(secNameInput); TextField extIdInput = generateTableTextInput("95px"); row.add(extIdInput); ComboBox processBox = generateTableBox(new ArrayList<String>(Arrays.asList("None", "Measure")), "95px"); if (!peptides) { processBox.addItem("Digest"); processBox.addItem("Both"); } processBox.setNullSelectionAllowed(false); processBox.select("None"); if (complexRow) row.add(createComplexCellComponent(processBox, "Process", id)); else row.add(processBox); processBox.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { checkFractionMeasured(); } }); Collections.sort(enzymes); ComboBox enzymeBox = generateTableBox(enzymes, "105px"); enzymeBox.removeAllItems(); enzymeBox.addItem("[Multiple]"); enzymeBox.addItems(enzymes); enzymeBox.setEnabled(false); enzymeBox.setFilteringMode(FilteringMode.CONTAINS); if (complexRow) row.add(createComplexCellComponent(enzymeBox, "Enzyme", id)); else row.add(enzymeBox); final String rowNum = id; enzymeBox.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { Object newVal = enzymeBox.getValue(); if (newVal.equals("[Multiple]")) createEnzymeSelectionWindow(rowNum); else if (!newVal.equals("Custom")) enzymeBox.removeItem("Custom"); } }); sampleTable.addItem(row.toArray(new Object[row.size()]), id); processBox.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { String value = (String) processBox.getValue(); boolean enableEnzyme = value.equals("Digest") || value.equals("Both"); parseBoxRow(id, "Enzyme").setEnabled(enableEnzyme); // boolean enableMS = value.equals("Measure") || value.equals("Both"); // parseBoxRow(item, "Chr. Type").setEnabled(enableMS); // parseBoxRow(item, "LCMS Method").setEnabled(enableMS); // parseBoxRow(item, "MS Device").setEnabled(enableMS); } }); } } int pagelength = 0; for (int n : tableIdToFractions.values()) { pagelength += n; } sampleTable.setPageLength(pagelength); this.setVisible(pagelength > 0); checkFractionMeasured(); }
From source file:uicomponents.ProjectInformationComponent.java
License:Open Source License
public void addInfoCompleteListener(ValueChangeListener infoCompleteListener) { ComboBox b = (ComboBox) projectBox.getInnerComponent(); b.addValueChangeListener(infoCompleteListener); piBox.addValueChangeListener(infoCompleteListener); contactBox.addValueChangeListener(infoCompleteListener); managerBox.addValueChangeListener(infoCompleteListener); expName.addValueChangeListener(infoCompleteListener); project.addValueChangeListener(infoCompleteListener); projectDescription.addValueChangeListener(infoCompleteListener); }
From source file:views.MetadataUploadView.java
License:Open Source License
protected boolean parseTSV(File file) throws IOException { for (Table t : sampleTables) { t.removeAllItems();/*from ww w.j a v a 2 s.co m*/ sheet.removeComponent(t); } removeComponent(sheet); addComponent(sheet); sheet.addSelectedTabChangeListener(new SelectedTabChangeListener() { @Override public void selectedTabChange(SelectedTabChangeEvent event) { reactToTableChange(); } }); sampleTables.clear(); CSVParser parser = new CSVParserBuilder().withIgnoreQuotations(true).withSeparator('\t').build(); CSVReader reader = new CSVReaderBuilder(new FileReader(file)).withCSVParser(parser).build(); String error = ""; ArrayList<String[]> data = new ArrayList<String[]>(); String[] nextLine; int rowID = 0; while ((nextLine = reader.readNext()) != null) { rowID++; if (data.isEmpty() || nextLine.length == data.get(0).length) { data.add(nextLine); } else { error = "Wrong number of columns in row " + rowID + " Please make sure every row fits the header row."; Styles.notification("Parsing Error", error, NotificationType.ERROR); reader.close(); return false; } } reader.close(); String[] header = data.get(0); data.remove(0); int barcodeCol = -1; String projectCode = ""; for (int j = 0; j < header.length; j++) { String word = data.get(0)[j]; if ((Functions.isQbicBarcode(word) || word.contains("ENTITY-")) && barcodeCol == -1) { barcodeCol = j; barcodeColName = header[barcodeCol]; projectCode = word.substring(0, 5); } } if (barcodeCol == -1) { error = "No barcode column found. Make sure one column contains QBiC Barcodes to map your information to existing samples!"; Styles.notification("File Incomplete", error, NotificationType.ERROR); return false; } if (barcodeCol != 0) { header[barcodeCol] = header[0]; header[0] = barcodeColName; for (String[] d : data) { String bc = d[barcodeCol]; d[barcodeCol] = d[0]; d[0] = bc; } barcodeCol = 0; } List<Sample> projectSamples = openbis.getSamplesWithParentsAndChildrenOfProjectBySearchService(projectCode); codesToSamples = new HashMap<String, Sample>(); Map<String, List<String>> sampleTypeToAttributes = new HashMap<String, List<String>>(); Map<String, DataTypeCode> propertyToType = new HashMap<String, DataTypeCode>(); for (Sample s : projectSamples) { String space = s.getSpaceCode(); // don't add samples the user should not be able to see if (allowedSpaces.contains(space)) codesToSamples.put(s.getCode(), s); } propNameToCode = new HashMap<String, String>(); codesInTSV = new ArrayList<String>(); for (int i = 0; i < data.size(); i++) { String bc = data.get(i)[barcodeCol]; if (!codesToSamples.containsKey(bc)) { // if samples don't exist or user doesn't have rights to see them, show error Styles.notification("Sample not found!", "Sample with code " + bc + " was not found in the Database.", NotificationType.ERROR); return false; } String type = codesToSamples.get(bc).getSampleTypeCode(); if (!sampleTypeToAttributes.containsKey(type)) { List<PropertyType> props = openbis.listPropertiesForType(openbis.getSampleTypeByString(type)); List<String> propertyNames = new ArrayList<String>(); for (PropertyType p : props) { String propName = p.getLabel(); String propCode = p.getCode(); propNameToCode.put(propName, propCode); DataTypeCode dataType = p.getDataType(); switch (dataType) { case CONTROLLEDVOCABULARY:// TODO properties without mapping? if (propToVocabulary.containsKey(propCode)) { propertyToType.put(propName, dataType); propertyNames.add(propName); } break; case MATERIAL: break; case TIMESTAMP: break; case XML: break; default: propertyToType.put(propName, dataType); propertyNames.add(propName); } } sampleTypeToAttributes.put(type, propertyNames); } codesInTSV.add(bc); } for (String type : sampleTypeToAttributes.keySet()) { Set<String> options = new HashSet<String>(); options.addAll(customProperties); options.addAll(sampleTypeToAttributes.get(type)); // options.removeAll(hiddenProperties); Table sampleTable = new Table(type + " Samples"); sampleTable.setWidth("100%"); sampleTable.setStyleName(Styles.tableTheme); sampleTable.addContainerProperty(header[barcodeCol], String.class, null); for (int i = 0; i < header.length; i++) { if (i != barcodeCol) { sampleTable.addContainerProperty(header[i], Component.class, null); } } List<Object> row = new ArrayList<Object>(); row.add("Properties -->"); for (int i = 1; i < header.length; i++) { // if (i != barcodeCol) { String headline = header[i]; ComboBox attributeOptions = new ComboBox("", options); attributeOptions.setStyleName(Styles.boxTheme); attributeOptions.setImmediate(true); attributeOptions.setInputPrompt("<Select Attribute>"); attributeOptions.setWidth("100%"); attributeOptions.setFilteringMode(FilteringMode.CONTAINS); attributeOptions.setNullSelectionAllowed(false); attributeOptions.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { List<Object> toRemove = new ArrayList<Object>(); for (Object item : attributeOptions.getItemIds()) { String val = item.toString(); if (val.startsWith("Condition: ") || val.startsWith("Property: ")) if (!attributeOptions.getValue().equals(item)) toRemove.add(item); } for (Object item : toRemove) { attributeOptions.removeItem(item); } if (attributeOptions.getValue() != null) { String selectedProperty = (String) attributeOptions.getValue(); if (selectedProperty.equals("[Experimental Condition]") || selectedProperty.equals("[Other Property]")) createConditionWindow(attributeOptions); else { if (selectedProperty.equals("IGNORE (removes column)")) { sampleTable.removeContainerProperty(headline); reactToTableChange(); } else { DataTypeCode dType = propertyToType.get(selectedProperty); if (dType != null) { switch (dType) { case CONTROLLEDVOCABULARY: createVocabularySelectWindow(attributeOptions, selectedProperty, collectLabelsInCol(headline));// TODO ? break; case REAL: case INTEGER: checkForNumberConsistency(headline, dType); reactToTableChange(); break; default: reactToTableChange(); break; } } else { reactToTableChange(); } } } } } }); row.add(attributeOptions); // } else { // row.add("Properties -->"); // } } sampleTable.addItem(row.toArray(), -1); for (int i = 0; i < codesInTSV.size(); i++) { String thisType = codesToSamples.get(codesInTSV.get(i)).getSampleTypeCode(); if (thisType.equals(type)) { row = new ArrayList<Object>(); row.add(codesInTSV.get(i)); for (int j = 0; j < header.length; j++) { if (j != barcodeCol) { row.add(new Label(data.get(i)[j])); } } sampleTable.addItem(row.toArray(), i); } } sheet.addTab(sampleTable); sampleTables.add(sampleTable); sampleTable.setPageLength(Math.min(20, sampleTable.size())); styleTable(sampleTable); reactToTableChange(); } addComponent(send); return true; }
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);//from w w w . j a v a2 s. c o m 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); }