Example usage for com.vaadin.ui Button setData

List of usage examples for com.vaadin.ui Button setData

Introduction

In this page you can find the example usage for com.vaadin.ui Button setData.

Prototype

public void setData(Object data) 

Source Link

Document

Sets the data object, that can be used for any application specific data.

Usage

From source file:org.s23m.cell.editor.semanticdomain.ui.components.layout.ImpactAnalysisFormLayout.java

License:Mozilla Public License

private void createPagebar(final List<Set> dependentInstances, final Panel searchResultPanel,
        final int resultSize) {
    int numPages = resultSize / PAGE_SIZE;
    if (resultSize % PAGE_SIZE > 0) {
        numPages++;//w w  w .  j  av a2  s .  com
    }
    final HorizontalLayout hl = new HorizontalLayout();
    for (int n = 0; n < numPages; n++) {
        final Button linkBtn = new Button("" + (n + 1));
        linkBtn.setData(n);
        linkBtn.setStyleName("link");
        linkBtn.setWidth("10px");
        linkBtn.addListener(new Button.ClickListener() {
            public void buttonClick(final Button.ClickEvent event) {
                //reset pageIndex
                pageIndex = (Integer) linkBtn.getData();
                //rebuild page
                rebuildPage(dependentInstances, searchResultPanel, pageIndex);
            }
        });
        hl.addComponent(linkBtn);
    }
    searchResultPanel.addComponent(hl);
}

From source file:org.s23m.cell.editor.semanticdomain.ui.components.MultitabPanel.java

License:Mozilla Public License

private void createPagebar(final Panel searchResultPanel, final int resultSize) {
    int numPages = resultSize / PAGE_SIZE;
    if (resultSize % PAGE_SIZE > 0) {
        numPages++;//w w  w.jav  a  2  s  . c om
    }
    final HorizontalLayout hl = new HorizontalLayout();
    for (int n = 0; n < numPages; n++) {
        final Button linkBtn = new Button("" + (n + 1));
        linkBtn.setData(n);
        linkBtn.setStyleName("link");
        linkBtn.setWidth("15px");
        linkBtn.addListener(new Button.ClickListener() {
            public void buttonClick(final Button.ClickEvent event) {
                //reset pageIndex
                pageIndex = (Integer) linkBtn.getData();
                //rebuild page
                rebuildPage(searchResultPanel, pageIndex);
            }
        });
        hl.addComponent(linkBtn);
    }
    searchResultPanel.addComponent(hl);
}

From source file:org.sensorhub.ui.GenericConfigForm.java

License:Mozilla Public License

protected void addChangeModuleButton(final ComponentContainer parentForm, final String propId,
        final ComplexProperty prop, final Class<?> objectType) {
    final Button chgButton = new Button("Modify");
    //chgButton.addStyleName(STYLE_QUIET);
    chgButton.addStyleName(STYLE_SMALL);
    chgButton.addStyleName(STYLE_SECTION_BUTTONS);
    chgButton.setIcon(REFRESH_ICON);/*  w  w  w  .ja  v a2s  . c om*/

    chgButton.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            // show popup to select among available module types
            ModuleTypeSelectionPopup popup = new ModuleTypeSelectionPopup(objectType,
                    new ModuleTypeSelectionCallback() {
                        public void configSelected(Class<?> moduleType, ModuleConfig config) {
                            // regenerate form
                            config.id = null;
                            config.name = null;
                            MyBeanItem<Object> newItem = new MyBeanItem<Object>(config, propId + ".");
                            prop.setValue(newItem);
                            IModuleConfigForm newForm = AdminUI.getInstance().generateForm(config.getClass());
                            newForm.build(propId, prop);
                            ((VerticalLayout) newForm).addComponent(chgButton, 0);

                            // replace old form in UI
                            allForms.add(newForm);
                            allForms.remove((IModuleConfigForm) chgButton.getData());
                            replaceComponent((Component) chgButton.getData(), newForm);
                            chgButton.setData(newForm);
                        }
                    });
            popup.setModal(true);
            AdminUI.getInstance().addWindow(popup);
        }
    });

    chgButton.setData(parentForm);
    ((VerticalLayout) parentForm).addComponent(chgButton, 0);
}

From source file:org.sensorhub.ui.GenericConfigForm.java

License:Mozilla Public License

protected void addChangeObjectButton(final ComponentContainer parentForm, final String propId,
        final ComplexProperty prop, final Map<String, Class<?>> typeList) {
    final Button chgButton = new Button("Modify");
    //chgButton.addStyleName(STYLE_QUIET);
    chgButton.addStyleName(STYLE_SMALL);
    chgButton.addStyleName(STYLE_SECTION_BUTTONS);
    chgButton.setIcon(REFRESH_ICON);//w  ww  . j  a va  2 s.c  om

    chgButton.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            // show popup to select among available module types
            ObjectTypeSelectionPopup popup = new ObjectTypeSelectionPopup("Select Type", typeList,
                    new ObjectTypeSelectionCallback() {
                        public void typeSelected(Class<?> objectType) {
                            try {
                                // regenerate form
                                MyBeanItem<Object> newItem = new MyBeanItem<Object>(objectType.newInstance(),
                                        propId + ".");
                                prop.setValue(newItem);
                                IModuleConfigForm newForm = AdminUI.getInstance().generateForm(objectType);
                                newForm.build(propId, prop);
                                ((VerticalLayout) newForm).addComponent(chgButton, 0);

                                // replace old form in UI
                                allForms.add(newForm);
                                allForms.remove((IModuleConfigForm) chgButton.getData());
                                replaceComponent((Component) chgButton.getData(), newForm);
                                chgButton.setData(newForm);
                            } catch (Exception e) {
                                Notification.show("Error", e.getMessage(), Notification.Type.ERROR_MESSAGE);
                            }
                        }
                    });
            popup.setModal(true);
            AdminUI.getInstance().addWindow(popup);
        }
    });
    chgButton.setData(parentForm);
    ((VerticalLayout) parentForm).addComponent(chgButton, 0);
}

From source file:org.vaadin.dialogs.DefaultConfirmDialogFactory.java

License:Mozilla Public License

public ConfirmDialog create(final String caption, final String message, final String okCaption,
        final String cancelCaption) {

    // Create a confirm dialog
    final ConfirmDialog confirm = new ConfirmDialog();
    confirm.setCaption(caption != null ? caption : DEFAULT_CAPTION);

    // Close listener implementation
    confirm.addListener(new Window.CloseListener() {

        private static final long serialVersionUID = 1971800928047045825L;

        public void windowClose(CloseEvent ce) {

            // Only process if still enabled
            if (confirm.isEnabled()) {
                confirm.setEnabled(false); // avoid double processing
                confirm.setConfirmed(false);
                if (confirm.getListener() != null) {
                    confirm.getListener().onClose(confirm);
                }/* ww  w .jav a2 s .c  o  m*/
            }
        }
    });

    // Create content
    VerticalLayout c = (VerticalLayout) confirm.getContent();
    c.setSizeFull();
    c.setSpacing(true);

    // Panel for scrolling lengthty messages.
    Panel scroll = new Panel(new VerticalLayout());
    scroll.setScrollable(true);
    c.addComponent(scroll);
    scroll.setWidth("100%");
    scroll.setHeight("100%");
    scroll.setStyleName(Reindeer.PANEL_LIGHT);
    c.setExpandRatio(scroll, 1f);

    // Always HTML, but escape
    Label text = new Label("", Label.CONTENT_RAW);
    scroll.addComponent(text);
    confirm.setMessageLabel(text);
    confirm.setMessage(message);

    HorizontalLayout buttons = new HorizontalLayout();
    c.addComponent(buttons);
    buttons.setSpacing(true);

    buttons.setHeight(format(BUTTON_HEIGHT) + "em");
    buttons.setWidth("100%");
    Label spacerLeft = new Label("");
    buttons.addComponent(spacerLeft);
    spacerLeft.setWidth("100%");
    buttons.setExpandRatio(spacerLeft, 1f);

    final Button cancel = new Button(cancelCaption != null ? cancelCaption : DEFAULT_CANCEL_CAPTION);
    cancel.setData(false);
    cancel.setClickShortcut(KeyCode.ESCAPE, null);
    buttons.addComponent(cancel);

    confirm.setCancelButton(cancel);

    final Button ok = new Button(okCaption != null ? okCaption : DEFAULT_OK_CAPTION);
    ok.setData(true);
    ok.setClickShortcut(KeyCode.ENTER, null);
    ok.focus();
    buttons.addComponent(ok);
    confirm.setOkButton(ok);

    Label spacerRight = new Label("");
    buttons.addComponent(spacerRight);
    spacerRight.setWidth("100%");
    buttons.setExpandRatio(spacerRight, 1f);
    // Create a listener for buttons
    Button.ClickListener cb = new Button.ClickListener() {
        private static final long serialVersionUID = 3525060915814334881L;

        public void buttonClick(ClickEvent event) {
            // Copy the button date to window for passing through either
            // "OK" or "CANCEL". Only process id still enabled.
            if (confirm.isEnabled()) {
                confirm.setEnabled(false); // Avoid double processing

                confirm.setConfirmed(event.getButton() == ok);

                // We need to cast this way, because of the backward
                // compatibility issue in 6.4 series.
                Component parent = confirm.getParent();
                if (parent instanceof Window) {
                    try {
                        Method m = Window.class.getDeclaredMethod("removeWindow", Window.class);
                        m.invoke(parent, confirm);
                    } catch (Exception e) {
                        throw new RuntimeException(
                                "Failed to remove confirmation dialog from the parent window.", e);
                    }
                }

                // This has to be invoked as the window.close
                // event is not fired when removed.
                if (confirm.getListener() != null) {
                    confirm.getListener().onClose(confirm);
                }
            }

        }

    };
    cancel.addListener(cb);
    ok.addListener(cb);

    // Approximate the size of the dialog
    double[] dim = getDialogDimensions(message, ConfirmDialog.CONTENT_TEXT_WITH_NEWLINES);
    confirm.setWidth(format(dim[0]) + "em");
    confirm.setHeight(format(dim[1]) + "em");
    confirm.setResizable(false);

    return confirm;
}

From source file:rs.pupin.jpo.esta_ld.EstaLdComponent.java

private void refreshDimensions() {
    // clean everything just in case
    dimLayout.removeAllComponents();//from www  . j av a2s.  c  om
    geoDimension = null;
    timeDimension = null;
    measures = null;
    btnGeo = null;
    boxGeo = null;
    dimNames = null;
    dimValues = null;

    if (selectDataSet.getValue() == null)
        return;

    //        VerticalLayout lLayout = new VerticalLayout();
    //        lLayout.setSizeUndefined();
    //        lLayout.setSpacing(true);
    //        lLayout.setDebugId("dim-btn-layout");
    //        dimLayout.addComponent(lLayout);
    //        VerticalLayout rLayout = new VerticalLayout();
    //        rLayout.setSizeUndefined();
    //        rLayout.setSpacing(true);
    //        rLayout.setWidth("100%");
    //        dimLayout.addComponent(rLayout);
    //        dimLayout.setExpandRatio(rLayout, 2.0f);

    final DataSet ds = (DataSet) selectDataSet.getValue();
    measures = ds.getStructure().getMeasures();
    StringBuilder builderMeasures = new StringBuilder();
    StringBuilder builderMeasureNames = new StringBuilder();
    for (Measure m : measures) {
        builderMeasures.append(", '");
        builderMeasures.append(m.getUri());
        builderMeasures.append("'");
        if (m.getLabel() != null) {
            builderMeasureNames.append(", '");
            builderMeasureNames.append(m.getLabel());
            builderMeasureNames.append("'");
        } else {
            builderMeasureNames.append(", undefined");
        }
    }
    builderMeasureNames.replace(0, 2, "[").append("]");
    builderMeasures.replace(0, 2, "javaSetMeasures([");
    builderMeasures.append("], ").append(builderMeasureNames.toString()).append(")");
    getWindow().executeJavaScript(builderMeasures.toString());
    measName = new Button("Measure");
    //        measName.setSizeUndefined();
    //        measName.setWidth("100%");
    measName.setHeight(CONTENT_ELEM_HEIGHT);
    measName.setWidth(CONTENT_ELEM_WIDTH);
    measName.addStyleName("dim-name");
    measName.addStyleName("unselectable");
    measValues = new ComboBox(null, measures);
    measValues.setImmediate(true);
    measValues.setSizeUndefined();
    measValues.setWidth("100%");
    measValues.setHeight(CONTENT_ELEM_HEIGHT);
    measValues.addStyleName("dim-value");
    measValues.setNullSelectionAllowed(false);
    measValues.select(measures.iterator().next());
    measValues.addListener(dimListener);
    //        measValues.addListener(new Property.ValueChangeListener() {
    //            public void valueChange(Property.ValueChangeEvent event) {
    //                Measure m = (Measure)event.getProperty().getValue();
    //                // put measure in
    //            }
    //        });
    int rowIndex = 0;
    int columnIndex = 0;
    dimLayout.addComponent(measName, columnIndex, rowIndex);
    columnIndex++;
    //        dimLayout.setExpandRatio(measName, 2.0f);
    dimLayout.addComponent(measValues, columnIndex, rowIndex, columnIndex + 1, rowIndex);
    columnIndex += 2;
    //        dimLayout.setComponentAlignment(measValues, Alignment.BOTTOM_LEFT);
    LinkedList<Dimension> dimsForShow = new LinkedList<Dimension>();
    for (Dimension dim : ds.getStructure().getDimensions()) {
        if (dim.isGeoDimension())
            geoDimension = dim;
        else if (dim.isTimeDimension()) {
            timeDimension = dim;
            dimsForShow.addFirst(dim);
        } else
            dimsForShow.add(dim);
    }
    dimNames = new Button[dimsForShow.size()];
    dimAggregIndicators = new Label[dimsForShow.size()];
    dimValues = new ComboBox[dimsForShow.size()];
    int i = 0;

    StringBuilder builderPossibleValues = new StringBuilder();
    boolean firstPass = true;

    for (Dimension dim : dimsForShow) {
        // add dimension pick
        // first create a button to represent dimension name
        final Button btnName = new Button(dim.toString());
        //            btnName.setSizeUndefined();
        //            btnName.setWidth("100%");
        btnName.setHeight(CONTENT_ELEM_HEIGHT);
        btnName.setWidth(CONTENT_ELEM_WIDTH);
        btnName.setData(dim);
        btnName.addStyleName("dim-name");
        if (firstPass) {
            btnName.addStyleName("selected");
            firstPass = false;
        }
        btnName.addListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent event) {
                if (btnName.getStyleName().contains("selected")) {
                    btnName.removeStyleName("selected");
                } else {
                    btnName.addStyleName("selected");
                }
                freeDimensionsChanged();
            }
        });
        dimNames[i] = btnName;

        final Label btnAggreg = new Label("<span>&Sigma;</span>", Label.CONTENT_XHTML);
        btnAggreg.setWidth("30px");
        btnAggreg.setHeight(CONTENT_ELEM_HEIGHT);
        btnAggreg.setData(dim);
        btnAggreg.addStyleName("dim-name");
        btnAggreg.addStyleName("dim-aggreg");
        // this will have to go to the layout listener
        //            btnAggreg.addListener(new Button.ClickListener() {
        //                public void buttonClick(Button.ClickEvent event) {
        //                    if (btnAggreg.getStyleName().contains("selected")) {
        //                        btnAggreg.removeStyleName("selected");
        //                    } else {
        //                        btnAggreg.addStyleName("selected");
        //                        aggregDimensionsChanged();
        //                    }
        //                }
        //            });
        dimAggregIndicators[i] = btnAggreg;

        // create a combo box for picking dimension value
        Collection<Value> vals = ds.getValuesForDimension(dim);
        Collection<ValueWrapper> valsWrapped = new LinkedList<ValueWrapper>();
        for (Value v : vals)
            valsWrapped.add(new ValueWrapper(v));
        builderPossibleValues.append(",").append(stringifyCollection(vals));
        ComboBox boxValue = new ComboBox(null, valsWrapped);
        boxValue.setImmediate(true);
        boxValue.setNullSelectionAllowed(false);
        if (valsWrapped.iterator().hasNext())
            boxValue.select(valsWrapped.iterator().next());
        else
            boxValue.setEnabled(false);
        boxValue.setSizeUndefined();
        boxValue.setWidth("100%");
        boxValue.setHeight(CONTENT_ELEM_HEIGHT);
        boxValue.addStyleName("dim-value");
        boxValue.addListener(dimListener);
        dimValues[i] = boxValue;

        // put them in a horizontal layout and add to the view
        //            HorizontalLayout layout = new HorizontalLayout();
        //            layout.setSizeUndefined();
        //            layout.setWidth("100%");
        //            layout.setSpacing(true);
        //            dimLayout.addComponent(layout);
        //            dimLayout.setExpandRatio(layout, 2.0f);
        //            layout.addComponent(btnName);
        //            layout.addComponent(boxValue);
        //            layout.setExpandRatio(boxValue, 2.0f);

        //            lLayout.addComponent(btnName);
        //            lLayout.setExpandRatio(btnName, 2.0f);
        //            rLayout.addComponent(boxValue);
        //            rLayout.setComponentAlignment(boxValue, Alignment.BOTTOM_LEFT);
        dimLayout.addComponent(btnName, columnIndex, rowIndex);
        if (++columnIndex == 6) {
            columnIndex = 0;
            rowIndex++;
            dimLayout.setRows(rowIndex + 1);
        }
        dimLayout.addComponent(btnAggreg, columnIndex, rowIndex);
        if (++columnIndex == 6) {
            columnIndex = 0;
            rowIndex++;
            dimLayout.setRows(rowIndex + 1);
        }
        dimLayout.addComponent(boxValue, columnIndex, rowIndex);
        if (++columnIndex == 6) {
            columnIndex = 0;
            rowIndex++;
            dimLayout.setRows(rowIndex + 1);
        }
        i++;
    }

    if (timeDimension != null)
        getWindow().executeJavaScript("javaSetHasTimeDimension(true)");
    else
        getWindow().executeJavaScript("javaSetHasTimeDimension(false)");

    if (geoDimension != null) {
        btnGeo = new Button(geoDimension.toString());
        //            btnGeo.setSizeUndefined();
        //            btnGeo.setWidth("100%");
        btnGeo.setHeight(CONTENT_ELEM_HEIGHT);
        btnGeo.setWidth(CONTENT_ELEM_WIDTH);
        btnGeo.setData(geoDimension);
        btnGeo.addStyleName("dim-name");
        btnGeo.addStyleName("geo-name");
        btnGeo.addListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent event) {
                if (btnGeo.getStyleName().contains("selected")) {
                    btnGeo.removeStyleName("selected");
                } else {
                    btnGeo.addStyleName("selected");
                }
                freeDimensionsChanged();
            }
        });

        btnAggregGeo = new Label("<span>&Sigma;</span>", Label.CONTENT_XHTML);
        btnAggregGeo.setHeight(CONTENT_ELEM_HEIGHT);
        btnAggregGeo.setData(geoDimension);
        btnAggregGeo.addStyleName("dim-name");
        btnAggregGeo.addStyleName("dim-aggreg");

        StringBuilder builder = new StringBuilder();
        Collection<Value> posVals = ds.getValuesForDimension(geoDimension);
        Collection<ValueWrapper> posValsWrapped = new LinkedList<ValueWrapper>();
        for (Value v : posVals)
            posValsWrapped.add(new ValueWrapper(v));
        Value selectedVal = posVals.iterator().next();
        String selectedValString = "";
        if (selectedVal instanceof URI) {
            selectedValString = "<" + selectedVal.stringValue() + ">";
        } else {
            selectedValString = "\"" + selectedVal.stringValue() + "\"";
            URI dataType = ((Literal) selectedVal).getDatatype();
            if (dataType != null && !dataType.stringValue().contains("string")) {
                selectedValString += "^^<" + dataType.stringValue() + ">";
            }
        }
        builder.append("javaSetGeoAll('").append(geoDimension.getUri());
        builder.append("',").append(stringifyCollection(posVals));
        builder.append(",'").append(selectedValString).append("',true)");
        boxGeo = new ComboBox(null, posValsWrapped);
        boxGeo.setData(posVals);
        boxGeo.setImmediate(true);
        boxGeo.setNullSelectionAllowed(false);
        boxGeo.select(posValsWrapped.iterator().next());
        boxGeo.setSizeUndefined();
        boxGeo.setWidth("100%");
        boxGeo.setHeight(CONTENT_ELEM_HEIGHT);
        boxGeo.addStyleName("geo-value");
        boxGeo.addListener(geoListener);
        //            lLayout.addComponent(btnGeo);
        //            lLayout.setExpandRatio(btnGeo, 2.0f);
        //            rLayout.addComponent(boxGeo);
        //            rLayout.setComponentAlignment(boxGeo, Alignment.BOTTOM_LEFT);
        dimLayout.addComponent(btnGeo, columnIndex, rowIndex);
        columnIndex++;
        dimLayout.addComponent(btnAggregGeo, columnIndex, rowIndex);
        columnIndex++;
        dimLayout.addComponent(boxGeo, columnIndex, rowIndex);
        columnIndex++;

        getWindow().executeJavaScript(builder.toString());
    } else {
        getWindow().executeJavaScript("javaSetGeoAll('',[],'',true)");
    }
    // TODO cover the case where there is more than 1 geo dimension

    builderPossibleValues.replace(0, 1, "javaSetPossibleValues([");
    builderPossibleValues.append("])");
    getWindow().executeJavaScript(builderPossibleValues.toString());
    if (dimsForShow.isEmpty()) {
        if (geoDimension != null)
            getWindow().executeJavaScript("javaSetGeoFree(true)");
        else
            getWindow().executeJavaScript("javaSetGeoFree(false)");
        getWindow().executeJavaScript("javaSetFreeDimensions([], true)");
    } else {
        getWindow().executeJavaScript("javaSetGeoFree(false)");
        getWindow().executeJavaScript("javaSetFreeDimensions([0], true)");
    }
    dimListener.valueChange(null);
    getWindow().executeJavaScript("setTimeout(expandDimNameButtons(),200)");
}

From source file:songstock.web.extensions.shoppingcart.ShoppingCartController.java

License:Open Source License

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void contributeUITo(Component component, Object data) throws Exception {
    if (component instanceof Table) {
        Table table = (Table) component;
        table.addContainerProperty(UI_CONTRIBUTION, Button.class, null);
        if (data instanceof List) {
            List itemIds = (List) data;
            for (Object itemId : itemIds) {
                Button buttonAddToCart = new Button("Add to Cart");
                buttonAddToCart.setData(itemId);
                buttonAddToCart.addClickListener(new ClickListener() {

                    private static final long serialVersionUID = 1L;

                    @Override/*from   w w w.j  a va  2  s  .  co  m*/
                    public void buttonClick(ClickEvent event) {
                        ShoppingCartController.getInstance().addItem(event.getButton().getData());
                    }
                });
                Property p = table.getItem(itemId).getItemProperty(UI_CONTRIBUTION);
                IUser user = Registry.get(SongStockUI.USER);
                if (user == null)
                    buttonAddToCart.setEnabled(false);
                else
                    buttonAddToCart.setEnabled(true);
                p.setValue(buttonAddToCart);
            }
        } else {
            throw new Exception("Data type not supported");
        }
    } else {
        throw new Exception("Component type not supported");
    }

}

From source file:ui.helper.LanguageArea.java

public LanguageArea(Integer userId, String language) {
    setStyleName("menu-language");
    Set<String> languages = ServiceLocator.findLifetimeService().getUserLanguages(userId);
    languages.add(ServiceLocator.findLifetimeService().getMotherLanguage(userId));
    for (String lang : languages) {
        if (lang.length() > 0) {
            Button e = new LifetimeButtonLink(lang, LifetimeUtils.getFlag(lang));
            e.setData(lang);
            e.setSizeUndefined();//from w  w  w.  j  a v  a 2  s .c om
            e.addClickListener(this);
            addComponent(e);
            if (language.equalsIgnoreCase(lang)) {
                selected = e;
                selected.setStyleName("button-selected");
            }
        }
    }
}

From source file:uicomponents.PoolingTable.java

License:Open Source License

private boolean moveSampleToPool(Table source, Object itemId) {
    boolean added = false;
    final Integer id = (Integer) source.getItem(itemId).getItemProperty("ID").getValue();
    String name = (String) source.getItem(itemId).getItemProperty("Secondary Name").getValue();
    String labID = (String) source.getItem(itemId).getItemProperty("Lab ID").getValue();
    final List<Object> row = new ArrayList<Object>();
    row.add(id);/*from  w w w . j a  va2s .c  om*/
    row.add(name);
    row.add(labID);
    for (String label : labels) {
        String value = (String) source.getItem(itemId).getItemProperty(label).getValue();
        row.add(value);
    }
    if (!poolIDs.contains(id)) {
        added = true;
        poolIDs.add(id);
        Button delete = new Button();
        Styles.iconButton(delete, FontAwesome.UNDO);
        delete.setData(itemId);
        delete.addClickListener(new Button.ClickListener() {
            /**
            * 
            */
            private static final long serialVersionUID = 5414603256990177472L;

            @Override
            public void buttonClick(ClickEvent event) {
                Integer iid = (Integer) event.getButton().getData();
                poolIDs.remove(id);
                poolTable.removeItem(iid);
                resizeTable();
                int newNumUsed = usedTimes.get(id) - 1;
                if (newNumUsed == 0) {
                    usedTimes.remove(id);
                    used.removeItem(iid);
                    all.addItem(row.toArray(), iid);
                    all.sort(new Object[] { "ID" }, new boolean[] { true });
                } else
                    usedTimes.put(id, newNumUsed);
            }
        });
        poolTable.addItem(new Object[] { id, name, labID, delete }, itemId);
        if (usedTimes.containsKey(id)) {
            int newNumUsed = usedTimes.get(id) + 1;
            usedTimes.put(id, newNumUsed);
        } else {
            usedTimes.put(id, 1);
            all.removeItem(itemId);
            used.addItem(row.toArray(), itemId);
            used.sort(new Object[] { "ID" }, new boolean[] { true });
        }
    }
    return added;
}

From source file:uicomponents.SummaryTable.java

License:Open Source License

public void initTable(List<AOpenbisSample> samples, LabelingMethod labelingMethod) {
    if (labelingMethod != null) {
        this.labelingMethod = labelingMethod;
        isotopes = true;//from   www  . j  a v a 2 s . co m
    }
    table.setStyleName(Styles.tableTheme);
    // table.addContainerProperty("ID", String.class, null);
    // table.setColumnWidth("ID", 35);
    table.addContainerProperty("Secondary Name", TextField.class, null);
    table.addContainerProperty("External DB ID", TextField.class, null);
    table.setColumnWidth("External DB ID", 106);
    table.setImmediate(true);
    table.setCaption(samples.size() + " " + name);

    if (isotopes)
        table.addContainerProperty(labelingMethod.getName(), ComboBox.class, null);

    List<String> factorLabels = new ArrayList<String>();
    int maxCols = 0;
    AOpenbisSample mostInformative = samples.get(0);
    for (AOpenbisSample s : samples) {
        int size = s.getFactors().size();
        if (size > maxCols) {
            maxCols = size;
            mostInformative = s;
        }
    }
    List<Property> factors = mostInformative.getFactors();
    for (int i = 0; i < factors.size(); i++) {
        String l = factors.get(i).getLabel();

        int j = 2;
        while (factorLabels.contains(l)) {
            l = factors.get(i).getLabel() + " (" + Integer.toString(j) + ")";
            j++;
        }
        factorLabels.add(l);
        table.addContainerProperty(l, String.class, null);
    }

    table.addContainerProperty("Customize", Button.class, null);
    table.setColumnWidth("Customize", 85);

    List<String> reagents = null;
    if (isotopes)
        reagents = labelingMethod.getReagents();
    int i = -1;
    for (AOpenbisSample s : samples) {
        i++;
        // AOpenbisSample s = samples.get(i);
        // Obje id = Integer.toString(i);
        // map.put(id, s);

        // The Table item identifier for the row.
        // Integer itemId = new Integer(i);

        // Create a button and handle its click.
        Button delete = new Button();
        Styles.iconButton(delete, FontAwesome.TRASH_O);
        // delete.setWidth("15px");
        // delete.setHeight("30px");
        delete.setData(s);
        delete.addClickListener(new Button.ClickListener() {
            /**
             * 
             */
            private static final long serialVersionUID = 5414603256990177472L;

            @Override
            public void buttonClick(ClickEvent event) {
                Button b = event.getButton();
                Object iid = b.getData();
                TextField secNameField = (TextField) table.getItem(iid).getItemProperty("Secondary Name")
                        .getValue();
                TextField extIDField = (TextField) table.getItem(iid).getItemProperty("External DB ID")
                        .getValue();
                if (secNameField.getValue().equals("DELETED")) {
                    secNameField.setReadOnly(false);
                    extIDField.setReadOnly(false);

                    // String id = (String) table.getItem(iid).getItemProperty("ID").getValue();
                    secNameField.setValue(s.getQ_SECONDARY_NAME());
                    extIDField.setValue(s.getQ_EXTERNALDB_ID());

                    b.setIcon(FontAwesome.TRASH_O);
                } else {
                    secNameField.setValue("DELETED");
                    secNameField.setReadOnly(true);
                    extIDField.setValue("DELETED");
                    extIDField.setReadOnly(true);
                    b.setIcon(FontAwesome.UNDO);
                }
            }
        });

        // Create the table row.
        List<Object> row = new ArrayList<Object>();

        TextField secNameField = new StandardTextField();
        secNameField.setImmediate(true);
        String secName = "";
        if (s.getQ_SECONDARY_NAME() != null)
            secName = s.getQ_SECONDARY_NAME();
        secNameField.setValue(secName);
        row.add(secNameField);

        TextField extIDField = new StandardTextField();
        extIDField.setWidth("95px");
        extIDField.setImmediate(true);
        String extID = "";
        if (s.getQ_EXTERNALDB_ID() != null)
            extID = s.getQ_EXTERNALDB_ID();
        extIDField.setValue(extID);
        row.add(extIDField);

        if (isotopes) {
            ComboBox cb = new ComboBox();
            cb.setImmediate(true);
            cb.addItems(reagents);
            cb.select(reagents.get(i % reagents.size()));
            row.add(cb);
        }
        int missing = maxCols - s.getFactors().size();
        for (Property f : s.getFactors()) {
            String v = f.getValue();
            if (f.hasUnit())
                v += " " + f.getUnit();
            row.add(v);
        }
        for (int j = 0; j < missing; j++)
            row.add("");
        row.add(delete);
        table.addItem(row.toArray(new Object[row.size()]), s);
    }
}