Example usage for com.vaadin.ui HorizontalLayout setWidth

List of usage examples for com.vaadin.ui HorizontalLayout setWidth

Introduction

In this page you can find the example usage for com.vaadin.ui HorizontalLayout setWidth.

Prototype

@Override
    public void setWidth(String width) 

Source Link

Usage

From source file:fi.semantum.strategia.Utils.java

License:Open Source License

public static void saveCurrentState(final Main main) {

    VerticalLayout content = new VerticalLayout();
    content.setSizeFull();/*from www.  j  ava2  s.  co m*/

    HorizontalLayout hl1 = new HorizontalLayout();
    hl1.setSpacing(true);
    hl1.setWidth("100%");

    final Map<String, UIState> stateMap = new HashMap<String, UIState>();
    for (UIState s : main.account.uiStates)
        stateMap.put(s.name, s);

    final TextField tf = new TextField();

    final Button save = new Button("Tallenna nkym", new Button.ClickListener() {

        private static final long serialVersionUID = 2449606920686729881L;

        public void buttonClick(ClickEvent event) {

            if (!tf.isValid())
                return;

            String name = tf.getValue();

            Page.getCurrent().getJavaScript().execute("doSaveBrowserState('" + name + "');");

        }

    });

    tf.setWidth("100%");
    tf.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    tf.setCaption("Tallenna nykyinen nkym nimell:");
    tf.setValue("Uusi nkym");
    tf.setCursorPosition(tf.getValue().length());
    tf.setValidationVisible(true);
    tf.setInvalidCommitted(true);
    tf.setImmediate(true);
    tf.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = -8274588731607481635L;

        @Override
        public void textChange(TextChangeEvent event) {
            tf.setValue(event.getText());
            try {
                tf.validate();
            } catch (InvalidValueException e) {
                save.setEnabled(false);
                return;
            }
            save.setEnabled(true);
        }

    });
    tf.addValidator(new Validator() {

        private static final long serialVersionUID = -4779239111120669168L;

        @Override
        public void validate(Object value) throws InvalidValueException {
            String s = (String) value;
            if (s.isEmpty())
                throw new InvalidValueException("Nimi ei saa olla tyhj");
            if (stateMap.containsKey(s))
                throw new InvalidValueException("Nimi on jo kytss");
        }

    });
    if (!tf.isValid())
        save.setEnabled(false);

    hl1.addComponent(tf);
    hl1.setExpandRatio(tf, 1.0f);

    hl1.addComponent(save);
    hl1.setExpandRatio(save, 0.0f);
    hl1.setComponentAlignment(save, Alignment.BOTTOM_CENTER);

    content.addComponent(hl1);
    content.setExpandRatio(hl1, 0.0f);

    final ListSelect table = new ListSelect();
    table.setWidth("100%");
    table.setHeight("100%");
    table.setNullSelectionAllowed(true);
    table.setMultiSelect(true);
    table.setCaption("Tallennetut nkymt");
    for (UIState state : main.account.uiStates) {
        table.addItem(state.name);
    }
    content.addComponent(table);
    content.setExpandRatio(table, 1.0f);

    final Button remove = new Button("Poista valitut nkymt");

    table.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 6439090862804667322L;

        @Override
        public void valueChange(ValueChangeEvent event) {

            Object selection = table.getValue();
            Collection<?> selected = (Collection<?>) selection;
            if (!selected.isEmpty()) {
                remove.setEnabled(true);
            } else {
                remove.setEnabled(false);
            }

        }

    });

    remove.setEnabled(false);

    content.addComponent(remove);
    content.setComponentAlignment(remove, Alignment.MIDDLE_LEFT);
    content.setExpandRatio(remove, 0.0f);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.setMargin(false);

    final Window dialog = Dialogs.makeDialog(main, "Nkymien hallinta", "Sulje", content, buttons);

    remove.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = -4680588998085550908L;

        public void buttonClick(ClickEvent event) {

            Object selection = table.getValue();
            Collection<?> selected = (Collection<?>) selection;

            if (!selected.isEmpty()) {

                for (Object o : selected) {
                    UIState state = stateMap.get(o);
                    if (state != null)
                        main.account.uiStates.remove(state);
                }
                Updates.update(main, true);
            }

            main.removeWindow(dialog);

        }

    });

}

From source file:fi.semantum.strategia.Utils.java

License:Open Source License

public static void editTags(final Main main, String title, final Base container) {

    final Database database = main.getDatabase();

    final Window subwindow = new Window(title, new VerticalLayout());
    subwindow.setModal(true);/*from   w  ww.  j ava 2 s.c  o  m*/
    subwindow.setWidth("400px");
    subwindow.setHeight("360px");
    subwindow.setResizable(true);

    VerticalLayout winLayout = (VerticalLayout) subwindow.getContent();
    winLayout.setMargin(true);
    winLayout.setSpacing(true);

    // Add some content; a label and a close-button
    final List<String> tags = new ArrayList<String>();
    for (Tag t : container.getRelatedTags(database))
        tags.add(t.getId(database));

    final CssLayout vl = new CssLayout();
    vl.setCaption("Kytss olevat aihetunnisteet:");
    fillTagEditor(database, vl, tags, Account.canWrite(main, container));
    winLayout.addComponent(vl);

    HorizontalLayout hl = new HorizontalLayout();
    hl.setWidth("100%");
    hl.setSpacing(true);

    final TagCombo combo = new TagCombo();
    final CustomLazyContainer comboContainer = new CustomLazyContainer(database, combo,
            Tag.enumerate(database));
    combo.setWidth("100%");
    combo.setCaption("Uusi aihetunniste:");
    combo.setInputPrompt("valitse listasta tai kirjoita");
    combo.setFilteringMode(FilteringMode.STARTSWITH);
    combo.setTextInputAllowed(true);
    combo.setImmediate(true);
    combo.setNullSelectionAllowed(false);
    combo.setInvalidAllowed(true);
    combo.setInvalidCommitted(true);
    combo.setItemCaptionMode(ItemCaptionMode.PROPERTY);
    combo.setItemCaptionPropertyId("id"); //should set
    combo.setContainerDataSource(comboContainer);

    hl.addComponent(combo);
    hl.setExpandRatio(combo, 1.0f);

    Button add = new Button("Lis", new Button.ClickListener() {

        private static final long serialVersionUID = -2848576385076605664L;

        public void buttonClick(ClickEvent event) {
            String filter = (String) combo.getValue();
            if (filter != null && filter.length() > 0) {
                Tag t = database.getOrCreateTag(filter);
                if (tags.contains(t.getId(database)))
                    return;
                tags.add(t.getId(database));
                fillTagEditor(database, vl, tags, main.account != null);
                combo.clear();
            }
        }
    });
    hl.addComponent(add);
    hl.setComponentAlignment(add, Alignment.BOTTOM_LEFT);
    hl.setExpandRatio(add, 0.0f);

    winLayout.addComponent(hl);

    Button close = new Button("Tallenna", new Button.ClickListener() {

        private static final long serialVersionUID = -451523776456589591L;

        public void buttonClick(ClickEvent event) {
            main.removeWindow(subwindow);
            List<Tag> newTags = new ArrayList<Tag>();
            for (String s : tags)
                newTags.add(database.getOrCreateTag(s));
            container.setRelatedTags(database, newTags);
            Updates.update(main, true);
        }
    });
    Button discard = new Button("Peru muutokset", new Button.ClickListener() {

        private static final long serialVersionUID = -2387057110951581993L;

        public void buttonClick(ClickEvent event) {
            main.removeWindow(subwindow);
        }
    });

    HorizontalLayout hl2 = new HorizontalLayout();
    hl2.setSpacing(true);
    hl2.addComponent(close);
    hl2.addComponent(discard);
    winLayout.addComponent(hl2);
    winLayout.setComponentAlignment(hl2, Alignment.MIDDLE_CENTER);

    main.addWindow(subwindow);

}

From source file:fi.semantum.strategia.widget.Indicator.java

License:Open Source License

public static void manageIndicators(final Main main, final Base base) {

    String currentTime = main.getUIState().time;
    boolean showYears = currentTime.equals(Property.AIKAVALI_KAIKKI);

    final Database database = main.getDatabase();

    VerticalLayout content = new VerticalLayout();
    content.setSizeFull();/*  ww w  .  j av  a 2s . co  m*/
    content.setSpacing(true);

    final Table table = new Table();
    table.setSelectable(true);
    table.setMultiSelect(true);
    table.addStyleName(ValoTheme.TABLE_SMALL);
    table.addStyleName(ValoTheme.TABLE_COMPACT);

    table.addContainerProperty("Indikaattori", Label.class, null);
    if (showYears)
        table.addContainerProperty("Vuosi", String.class, null);

    table.setWidth("100%");
    table.setHeight("100%");
    table.setNullSelectionAllowed(true);

    table.setEditable(false);
    table.setColumnExpandRatio("Indikaattori", 2.0f);
    if (showYears)
        table.setColumnExpandRatio("Vuosi", 0.0f);

    makeIndicatorTable(main, base, table);

    content.addComponent(table);
    content.setExpandRatio(table, 1.0f);

    abstract class IndicatorButtonListener implements Button.ClickListener {

        private static final long serialVersionUID = -7551250112503063540L;

        protected Indicator getPossibleSelection() {
            Object selection = table.getValue();
            Collection<?> selected = (Collection<?>) selection;
            if (selected.size() != 1)
                return null;
            return (Indicator) selected.iterator().next();
        }

        @SuppressWarnings("unchecked")
        protected Collection<Indicator> getSelection() {
            return (Collection<Indicator>) table.getValue();
        }

        protected Map<Base, List<Indicator>> getSelectionByParent(Database database) {
            return indicatorsByParent(database, getSelection());
        }

    }

    final Button removeIndicators = new Button("Poista", new IndicatorButtonListener() {

        private static final long serialVersionUID = -2538054127519468282L;

        public void buttonClick(ClickEvent event) {

            Collection<Indicator> selection = getSelection();
            for (Indicator i : selection) {
                Base owner = i.getOwner(database);
                if (owner == null)
                    continue;
                owner.removeIndicator(i);
            }

            final Set<Base> bases = new HashSet<Base>();
            final Strategiakartta map = database.getMap(base);
            bases.add(map);
            for (Tavoite t : map.tavoitteet) {
                bases.add(t);
                for (Painopiste p : t.painopisteet) {
                    bases.add(p);
                }
            }
            for (Base b : bases) {
                for (Meter meter : b.getMeters(database)) {
                    Indicator indicator = meter.getPossibleIndicator(database);
                    if (selection.contains(indicator)) {
                        b.removeMeter(meter);
                    }
                }
            }

            makeIndicatorTable(main, base, table);

            Updates.update(main, true);

        }

    });
    removeIndicators.addStyleName(ValoTheme.BUTTON_TINY);

    final Button moveUp = new Button("Siirr ylemms", new IndicatorButtonListener() {

        private static final long serialVersionUID = -635232943884881464L;

        public void buttonClick(ClickEvent event) {

            for (Map.Entry<Base, List<Indicator>> entry : getSelectionByParent(database).entrySet()) {
                entry.getKey().moveIndicatorsUp(entry.getValue());
            }

            makeIndicatorTable(main, base, table);
            Updates.update(main, true);

        }

    });
    moveUp.addStyleName(ValoTheme.BUTTON_TINY);

    final Button moveDown = new Button("Siirr alemmas", new IndicatorButtonListener() {

        private static final long serialVersionUID = 2779521990166604444L;

        public void buttonClick(ClickEvent event) {

            for (Map.Entry<Base, List<Indicator>> entry : getSelectionByParent(database).entrySet()) {
                entry.getKey().moveIndicatorsDown(entry.getValue());
            }

            makeIndicatorTable(main, base, table);
            Updates.update(main, true);

        }

    });
    moveDown.addStyleName(ValoTheme.BUTTON_TINY);

    final Button modify = new Button("Mrit");
    modify.addClickListener(new IndicatorButtonListener() {

        private static final long serialVersionUID = 5149432436059288486L;

        public void buttonClick(ClickEvent event) {

            Indicator indicator = getPossibleSelection();
            if (indicator == null)
                return;

            editIndicator(main, base, indicator);

        }

    });
    modify.addStyleName(ValoTheme.BUTTON_TINY);

    final TextField indicatorText = new TextField();
    indicatorText.setWidth("100%");
    indicatorText.addStyleName(ValoTheme.TEXTFIELD_TINY);
    indicatorText.setCaption("Tunniste");

    List<Datatype> types = Datatype.enumerate(database);

    final ComboBox datatypeSelect = new ComboBox();
    datatypeSelect.setWidth("100%");
    datatypeSelect.setNullSelectionAllowed(false);
    datatypeSelect.addStyleName(ValoTheme.COMBOBOX_TINY);
    datatypeSelect.setCaption("Tietotyyppi");
    for (Datatype dt : types)
        datatypeSelect.addItem(dt);

    final Button addIndicator = new Button("Lis ptasolle", new Button.ClickListener() {

        private static final long serialVersionUID = -2395147866745115337L;

        public void buttonClick(ClickEvent event) {

            String text = indicatorText.getValue();
            Object dt = datatypeSelect.getValue();
            if (text.isEmpty() || dt == null || dt.equals(datatypeSelect.getNullSelectionItemId()))
                return;

            base.addIndicator(Indicator.create(database, text, (Datatype) dt));
            makeIndicatorTable(main, base, table);
            Updates.update(main, true);

        }

    });
    addIndicator.addStyleName(ValoTheme.BUTTON_TINY);

    final Button addSubIndicator = new Button("Lis valitun alle", new IndicatorButtonListener() {

        private static final long serialVersionUID = -2395147866745115337L;

        public void buttonClick(ClickEvent event) {

            Indicator indicator = getPossibleSelection();
            if (indicator == null)
                return;

            String text = indicatorText.getValue();
            Object dt = datatypeSelect.getValue();
            if (text.isEmpty() || dt == null || dt.equals(datatypeSelect.getNullSelectionItemId()))
                return;

            indicator.addIndicator(Indicator.create(database, text, (Datatype) dt));
            makeIndicatorTable(main, base, table);

            Updates.update(main, true);

        }

    });
    addSubIndicator.addStyleName(ValoTheme.BUTTON_TINY);

    final Runnable setStates = new Runnable() {

        @Override
        public void run() {

            Object selection = table.getValue();
            Collection<?> selected = (Collection<?>) selection;
            if (!selected.isEmpty()) {
                removeIndicators.setEnabled(true);
                moveUp.setEnabled(true);
                moveDown.setEnabled(true);
                if (selected.size() == 1) {
                    modify.setEnabled(true);
                    addSubIndicator.setEnabled(true);
                } else {
                    addSubIndicator.setEnabled(false);
                    modify.setEnabled(false);
                }
            } else {
                moveUp.setEnabled(false);
                moveDown.setEnabled(false);
                removeIndicators.setEnabled(false);
                addSubIndicator.setEnabled(false);
                modify.setEnabled(false);
            }

        }

    };

    table.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1188285609779556446L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            setStates.run();
        }

    });

    setStates.run();

    HorizontalLayout hl2 = new HorizontalLayout();
    hl2.setSpacing(true);
    hl2.setWidthUndefined();

    hl2.addComponent(modify);
    hl2.setComponentAlignment(modify, Alignment.BOTTOM_LEFT);
    hl2.setExpandRatio(modify, 0.0f);

    hl2.addComponent(removeIndicators);
    hl2.setComponentAlignment(removeIndicators, Alignment.BOTTOM_LEFT);
    hl2.setExpandRatio(removeIndicators, 0.0f);

    hl2.addComponent(moveUp);
    hl2.setComponentAlignment(moveUp, Alignment.TOP_LEFT);
    hl2.setExpandRatio(moveUp, 0.0f);

    hl2.addComponent(moveDown);
    hl2.setComponentAlignment(moveDown, Alignment.TOP_LEFT);
    hl2.setExpandRatio(moveDown, 0.0f);

    HorizontalLayout hl3 = new HorizontalLayout();
    hl3.setSpacing(true);
    hl3.setWidth("100%");

    hl3.addComponent(addIndicator);
    hl3.setComponentAlignment(addIndicator, Alignment.BOTTOM_LEFT);
    hl3.setExpandRatio(addIndicator, 0.0f);

    hl3.addComponent(addSubIndicator);
    hl3.setComponentAlignment(addSubIndicator, Alignment.BOTTOM_LEFT);
    hl3.setExpandRatio(addSubIndicator, 0.0f);

    hl3.addComponent(indicatorText);
    hl3.setComponentAlignment(indicatorText, Alignment.BOTTOM_LEFT);
    hl3.setExpandRatio(indicatorText, 1.0f);

    hl3.addComponent(datatypeSelect);
    hl3.setComponentAlignment(datatypeSelect, Alignment.BOTTOM_LEFT);
    hl3.setExpandRatio(datatypeSelect, 2.0f);

    content.addComponent(hl2);
    content.setComponentAlignment(hl2, Alignment.BOTTOM_LEFT);
    content.setExpandRatio(hl2, 0.0f);

    content.addComponent(hl3);
    content.setComponentAlignment(hl3, Alignment.BOTTOM_LEFT);
    content.setExpandRatio(hl3, 0.0f);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.setMargin(false);

    final Window dialog = Dialogs.makeDialog(main, "650px", "800px", "Hallitse indikaattoreita", "Sulje",
            content, buttons);

}

From source file:fi.semantum.strategia.widget.Indicator.java

License:Open Source License

public static void editIndicator(final Main main, final Base base, final Indicator indicator) {

    final Database database = main.getDatabase();

    VerticalLayout content = new VerticalLayout();
    content.setSizeFull();// ww w.j a  va2  s  .c om
    content.setHeightUndefined();
    content.setSpacing(true);

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    hl.setWidth("100%");
    content.addComponent(hl);
    content.setExpandRatio(hl, 0.0f);

    final TextField tf = new TextField("Tunniste");
    tf.setValue(indicator.getId(database));
    tf.setWidth("100%");
    tf.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    hl.addComponent(tf);
    hl.setComponentAlignment(tf, Alignment.MIDDLE_CENTER);
    hl.setExpandRatio(tf, 2.0f);

    final TextField tf1 = new TextField("Teksti");
    tf1.setValue(indicator.getText(database));
    tf1.setWidth("100%");
    tf1.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    hl.addComponent(tf1);
    hl.setComponentAlignment(tf1, Alignment.MIDDLE_CENTER);
    hl.setExpandRatio(tf1, 2.0f);

    final TextField unit = makeUnit(database, hl, indicator);

    final TextField tf2 = new TextField();
    tf2.setCaption("Voimassaolo");
    tf2.setValue(Utils.getValidity(database, indicator));
    tf2.addStyleName(ValoTheme.TEXTFIELD_TINY);
    tf2.setWidth("100%");
    hl.addComponent(tf2);
    hl.setComponentAlignment(tf2, Alignment.MIDDLE_CENTER);
    hl.setExpandRatio(tf2, 1.0f);

    final TextArea ta = new TextArea("Mritys");
    ta.setValue(indicator.getText(database));
    ta.setWidth("100%");
    ta.setHeight("100px");
    content.addComponent(ta);
    content.setComponentAlignment(ta, Alignment.MIDDLE_CENTER);
    content.setExpandRatio(ta, 0.0f);

    final Label ta2 = makeHistory(database, indicator, main.getUIState().forecastMeters);
    content.addComponent(ta2);
    content.setComponentAlignment(ta2, Alignment.MIDDLE_CENTER);
    content.setExpandRatio(ta2, 1.0f);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.setMargin(false);

    Button ok = new Button("Tallenna", new Button.ClickListener() {

        private static final long serialVersionUID = 1992235622970234624L;

        public void buttonClick(ClickEvent event) {
            indicator.modifyId(main, tf.getValue());
            Utils.modifyValidity(main, indicator, tf2.getValue());
            indicator.modifyText(main, tf1.getValue());
            indicator.modifyDescription(main, ta.getValue());
            if (unit != null) {
                indicator.modifyUnit(main, unit.getValue());
            }
            Updates.update(main, true);
            manageIndicators(main, main.getUIState().currentItem);
        }

    });
    buttons.addComponent(ok);

    Button close = new Button("Sulje");
    buttons.addComponent(close);

    final Window dialog = Dialogs.makeDialog(main, "650px", "800px", "Muokkaa indikaattoria", null, content,
            buttons);
    close.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = 1992235622970234624L;

        public void buttonClick(ClickEvent event) {
            main.removeWindow(dialog);
            manageIndicators(main, main.getUIState().currentItem);
        }

    });

}

From source file:fi.semantum.strategia.widget.Indicator.java

License:Open Source License

public static void updateIndicators(final Main main, final Base base, boolean canWrite) {

    final Database database = main.getDatabase();

    List<IndicatorDescription> descs = new ArrayList<IndicatorDescription>();
    fillIndicatorDescriptions(main, base, "", descs);

    boolean isMap = base instanceof Strategiakartta;

    if (isMap && (!descs.isEmpty() || canWrite)) {

        HorizontalLayout indiHeader = new HorizontalLayout();
        indiHeader.setSpacing(true);/*  w  ww .j  av a 2  s  .  co m*/

        Label header = new Label("Indikaattorit (ennuste)");
        main.propertyCells.add(Utils.excelRow(header.getValue()));
        header.setHeight("32px");
        header.addStyleName(ValoTheme.LABEL_HUGE);
        header.addStyleName(ValoTheme.LABEL_BOLD);
        indiHeader.addComponent(header);
        indiHeader.setComponentAlignment(header, Alignment.BOTTOM_CENTER);

        if (canWrite) {

            final Image editIndicators = new Image(null, new ThemeResource("chart_line_edit.png"));
            editIndicators.setHeight("24px");
            editIndicators.setWidth("24px");
            editIndicators.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 2661060702097338722L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Utils.loseFocus(editIndicators);
                    manageIndicators(main, main.getUIState().currentItem);
                }

            });

            indiHeader.addComponent(editIndicators);
            indiHeader.setComponentAlignment(editIndicators, Alignment.BOTTOM_CENTER);

        }

        main.properties.addComponent(indiHeader);
        main.properties.setComponentAlignment(indiHeader, Alignment.MIDDLE_CENTER);

        VerticalLayout indicators = new VerticalLayout();

        boolean showYears = main.getUIState().time.equals(Property.AIKAVALI_KAIKKI);

        Property time = Property.find(database, Property.AIKAVALI);

        int index = 0;
        for (final IndicatorDescription desc : descs) {

            ArrayList<String> excelRow = new ArrayList<String>();

            Indicator indicator = desc.indicator;

            final HorizontalLayout hl = new HorizontalLayout();
            hl.addStyleName((((index++) & 1) == 0) ? "evenProperty" : "oddProperty");
            hl.setSpacing(true);

            Label l = new Label(desc.caption);
            excelRow.add(l.getValue().replace("%nbsp", ""));
            l.setContentMode(ContentMode.HTML);
            l.setWidth("450px");
            l.addStyleName("propertyName");
            l.setData(desc);
            hl.addComponent(l);
            hl.setComponentAlignment(l, Alignment.MIDDLE_LEFT);

            String value = updateIndicatorValue(main, hl, base, indicator, canWrite);
            excelRow.add(value);

            Label unit = new Label(indicator.getUnit());
            unit.setWidth("100px");
            hl.addComponent(unit);
            hl.setComponentAlignment(unit, Alignment.MIDDLE_LEFT);
            excelRow.add(unit.getValue());

            Label comment = new Label(indicator.getValueShortComment());
            comment.setWidth("150px");
            hl.addComponent(comment);
            hl.setComponentAlignment(comment, Alignment.MIDDLE_LEFT);
            excelRow.add(comment.getValue());

            if (showYears) {

                HorizontalLayout hl2 = new HorizontalLayout();
                hl2.setWidth("70px");
                hl2.setHeight("100%");
                hl.addComponent(hl2);
                hl.setComponentAlignment(hl2, Alignment.MIDDLE_LEFT);

                String years = time.getPropertyValue(indicator);
                if (years == null)
                    years = Property.AIKAVALI_KAIKKI;

                final Label region = new Label(years);
                region.setWidthUndefined();

                excelRow.add(region.getValue());

                hl2.addComponent(region);
                hl2.setComponentAlignment(region, Alignment.MIDDLE_CENTER);

            }

            final Image wiki = new Image();
            wiki.setSource(new ThemeResource("table_edit.png"));
            wiki.setHeight("24px");
            wiki.setWidth("24px");
            wiki.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 2661060702097338722L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Wiki.openWiki(main, desc.indicator);
                }

            });

            hl.addComponent(wiki);
            hl.setComponentAlignment(wiki, Alignment.MIDDLE_CENTER);

            indicators.addComponent(hl);
            indicators.setComponentAlignment(hl, Alignment.MIDDLE_CENTER);

            main.propertyCells.add(excelRow);

        }

        indicators.addLayoutClickListener(new LayoutClickListener() {

            private static final long serialVersionUID = 3295743025581923380L;

            private String extractData(Component c) {
                if (c instanceof AbstractComponent) {
                    Object data = ((AbstractComponent) c).getData();
                    if (data instanceof IndicatorDescription) {
                        IndicatorDescription desc = (IndicatorDescription) data;
                        return desc.indicator.getDescription(database);
                    }
                }
                return null;
            }

            @Override
            public void layoutClick(LayoutClickEvent event) {

                String desc = extractData(event.getClickedComponent());
                if (desc == null)
                    return;

                String content = "<div style=\"width: 700px; border: 2px solid; padding: 5px\">";
                content += "<div style=\"text-align: center; white-space:normal; font-size: 36px; padding: 10px\">"
                        + desc + "</div>";
                content += "</div>";

                Notification n = new Notification(content, Notification.Type.HUMANIZED_MESSAGE);
                n.setHtmlContentAllowed(true);
                n.show(Page.getCurrent());

            }

        });

        main.properties.addComponent(indicators);
        main.properties.setComponentAlignment(indicators, Alignment.MIDDLE_CENTER);

    }

}

From source file:fi.semantum.strategia.widget.Meter.java

License:Open Source License

public static String updateMeterValue(final Main main, HorizontalLayout hl, final Base base, final Meter meter,
        boolean canWrite) {

    final Database database = main.getDatabase();

    HorizontalLayout hl2 = new HorizontalLayout();
    hl2.setWidth("300px");
    hl2.setHeight("100%");
    hl.addComponent(hl2);/*from   ww w.  j av  a 2  s. c  o  m*/
    hl.setComponentAlignment(hl2, Alignment.MIDDLE_LEFT);

    final Indicator i = meter.getPossibleIndicator(database);
    if (i != null) {

        Datatype datatype = i.getDatatype(database);
        if (datatype instanceof EnumerationDatatype) {

            EnumerationDatatype enu = (EnumerationDatatype) datatype;

            Object value = i.getValue();
            AbstractField<?> combo = enu.getEditor(main, base, i, false, null);

            hl2.addComponent(combo);
            hl2.setComponentAlignment(combo, Alignment.MIDDLE_CENTER);

            return value != null ? value.toString() : "null";

        }

    }

    final Label label = new Label(meter.describe(database, main.getUIState().forecastMeters));
    label.setWidthUndefined();

    hl2.addComponent(label);
    hl2.setComponentAlignment(label, Alignment.MIDDLE_CENTER);
    hl2.setExpandRatio(label, 1.0f);

    return label.getValue();

}

From source file:fi.semantum.strategia.widget.Meter.java

License:Open Source License

public static void updateMeters(final Main main, boolean canWrite) {

    if (main.getUIState().currentItem instanceof Strategiakartta)
        return;//from w  ww.  j a v a 2  s.c o  m

    final Database database = main.getDatabase();

    final Base base = main.getUIState().currentItem;

    List<MeterDescription> descs = makeMeterDescriptions(main, base, false);
    if (!descs.isEmpty() || canWrite) {

        HorizontalLayout meterHeader = new HorizontalLayout();
        meterHeader.setSpacing(true);

        Label header = new Label("Mittarit");
        main.propertyCells.add(Utils.excelRow(header.getValue()));
        header.setHeight("32px");
        header.addStyleName(ValoTheme.LABEL_HUGE);
        header.addStyleName(ValoTheme.LABEL_BOLD);
        meterHeader.addComponent(header);
        meterHeader.setComponentAlignment(header, Alignment.BOTTOM_CENTER);

        if (canWrite) {

            final Image editMeters = new Image(null, new ThemeResource("chart_bar_edit.png"));
            editMeters.setHeight("24px");
            editMeters.setWidth("24px");
            editMeters.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 2661060702097338722L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Utils.loseFocus(editMeters);
                    manageMeters(main, main.getUIState().currentItem);
                }

            });

            meterHeader.addComponent(editMeters);
            meterHeader.setComponentAlignment(editMeters, Alignment.BOTTOM_CENTER);

        }

        main.properties.addComponent(meterHeader);
        main.properties.setComponentAlignment(meterHeader, Alignment.MIDDLE_CENTER);

        VerticalLayout meters = new VerticalLayout();

        boolean showYears = main.getUIState().time.equals(Property.AIKAVALI_KAIKKI);

        Property time = Property.find(database, Property.AIKAVALI);

        int index = 0;
        for (final MeterDescription desc : descs) {

            ArrayList<String> excelRow = new ArrayList<String>();

            final Meter meter = desc.meter;

            final HorizontalLayout hl = new HorizontalLayout();
            hl.addStyleName((((index++) & 1) == 0) ? "evenProperty" : "oddProperty");
            hl.setSpacing(true);

            Label l = new Label(desc.caption);
            excelRow.add(l.getValue().replace("%nbsp", ""));
            l.setContentMode(ContentMode.HTML);
            l.setWidth("450px");
            l.addStyleName("propertyName");
            l.setData(desc);
            hl.addComponent(l);
            hl.setComponentAlignment(l, Alignment.MIDDLE_LEFT);

            String value = updateMeterValue(main, hl, base, meter, canWrite);
            excelRow.add(value);

            String shortComment = "";
            Indicator indicator = meter.getPossibleIndicator(database);
            if (indicator != null)
                shortComment = indicator.getValueShortComment();
            Label comment = new Label(shortComment);
            comment.setWidth("150px");
            hl.addComponent(comment);
            hl.setComponentAlignment(comment, Alignment.MIDDLE_LEFT);
            excelRow.add(comment.getValue());

            if (showYears) {

                HorizontalLayout hl2 = new HorizontalLayout();
                hl2.setWidth("70px");
                hl2.setHeight("100%");
                hl.addComponent(hl2);
                hl.setComponentAlignment(hl2, Alignment.MIDDLE_LEFT);

                String years = time.getPropertyValue(meter);
                if (years == null)
                    years = Property.AIKAVALI_KAIKKI;

                final Label region = new Label(years);
                region.setWidthUndefined();

                excelRow.add(region.getValue());

                hl2.addComponent(region);
                hl2.setComponentAlignment(region, Alignment.MIDDLE_CENTER);

            }

            AbsoluteLayout image = new AbsoluteLayout();
            image.setWidth("32px");
            image.setHeight("32px");
            image.addStyleName("meterColor" + index);

            String color = meter.getTrafficColor(database);

            Styles styles = Page.getCurrent().getStyles();
            styles.add(
                    ".fi_semantum_strategia div." + "meterColor" + index + " { background: " + color + "; }");

            hl.addComponent(image);
            hl.setComponentAlignment(image, Alignment.MIDDLE_CENTER);
            hl.setExpandRatio(image, 0.0f);

            meters.addComponent(hl);
            meters.setComponentAlignment(hl, Alignment.MIDDLE_CENTER);

            ThemeResource res = desc.meter.showInMap ? new ThemeResource("zoom.png")
                    : new ThemeResource("zoom_out.png");

            final Image show = new Image();
            show.setSource(res);
            show.setHeight("24px");
            show.setWidth("24px");
            if (canWrite) {
                show.setDescription("Klikkaamalla voit valita, nytetnk mittaria strategiakartassa");
                show.addClickListener(new MouseEvents.ClickListener() {

                    private static final long serialVersionUID = 7156984656942915939L;

                    @Override
                    public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                        desc.meter.setShowInMap(!desc.meter.showInMap);
                        Updates.update(main, true);
                    }

                });
            }

            hl.addComponent(show);
            hl.setComponentAlignment(show, Alignment.MIDDLE_CENTER);

            final Image wiki = new Image();
            wiki.setSource(new ThemeResource("table_edit.png"));
            wiki.setHeight("24px");
            wiki.setWidth("24px");
            wiki.setDescription("Klikkaamalla voit siirty tausta-asiakirjaan");
            wiki.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 7156984656942915939L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Wiki.openWiki(main, desc.meter);
                }

            });

            hl.addComponent(wiki);
            hl.setComponentAlignment(wiki, Alignment.MIDDLE_CENTER);

            if (canWrite) {
                final Button principalButton = new Button();
                if (meter.isPrincipal) {
                    principalButton.setCaption("Poista kokonaisarvio");
                } else {
                    principalButton.setCaption("Aseta kokonaisarvioksi");
                }
                principalButton.setStyleName(ValoTheme.BUTTON_TINY);
                principalButton.addClickListener(new ClickListener() {

                    private static final long serialVersionUID = 8247560202892661226L;

                    @Override
                    public void buttonClick(ClickEvent event) {
                        if (meter.isPrincipal) {
                            meter.isPrincipal = false;
                        } else {
                            for (Meter m : base.getMeters(database))
                                m.isPrincipal = false;
                            meter.isPrincipal = true;
                        }
                        Updates.update(main, true);

                    }

                });
                hl.addComponent(principalButton);
                hl.setComponentAlignment(principalButton, Alignment.MIDDLE_CENTER);
            }

            main.propertyCells.add(excelRow);

        }

        meters.addLayoutClickListener(new LayoutClickListener() {

            private static final long serialVersionUID = 3295743025581923380L;

            private String extractData(Component c) {
                if (c instanceof AbstractComponent) {
                    Object data = ((AbstractComponent) c).getData();
                    if (data instanceof MeterDescription) {
                        MeterDescription desc = (MeterDescription) data;
                        return desc.meter.getDescription(database);
                    }
                }
                return null;
            }

            @Override
            public void layoutClick(LayoutClickEvent event) {

                String desc = extractData(event.getClickedComponent());
                if (desc == null)
                    return;

                String content = "<div style=\"width: 700px; border: 2px solid; padding: 5px\">";
                content += "<div style=\"text-align: center; white-space:normal; font-size: 36px; padding: 10px\">"
                        + desc + "</div>";
                content += "</div>";

                Notification n = new Notification(content, Notification.Type.HUMANIZED_MESSAGE);
                n.setHtmlContentAllowed(true);
                n.show(Page.getCurrent());

            }

        });

        main.properties.addComponent(meters);
        main.properties.setComponentAlignment(meters, Alignment.MIDDLE_CENTER);

    }

}

From source file:fi.semantum.strategia.widget.Meter.java

License:Open Source License

public static void manageMeters(final Main main, final Base base) {

    String currentTime = main.getUIState().time;
    boolean showYears = currentTime.equals(Property.AIKAVALI_KAIKKI);

    final Database database = main.getDatabase();

    VerticalLayout content = new VerticalLayout();
    content.setSizeFull();//from   www . java2 s  .c om
    content.setSpacing(true);

    final Table table = new Table();
    table.setSelectable(true);
    table.setMultiSelect(true);
    table.addStyleName(ValoTheme.TABLE_SMALL);
    table.addStyleName(ValoTheme.TABLE_COMPACT);

    table.addContainerProperty("Mittari", Label.class, null);
    if (showYears)
        table.addContainerProperty("Vuosi", String.class, null);

    table.setWidth("100%");
    table.setHeight("100%");
    table.setNullSelectionAllowed(true);

    table.setEditable(false);
    table.setColumnExpandRatio("Mittari", 2.0f);
    if (showYears)
        table.setColumnExpandRatio("Vuosi", 0.0f);

    makeMeterTable(main, base, table);

    content.addComponent(table);
    content.setExpandRatio(table, 1.0f);

    abstract class MeterButtonListener implements Button.ClickListener {

        private static final long serialVersionUID = -6640950006518632633L;

        protected Meter getPossibleSelection() {
            Object selection = table.getValue();
            Collection<?> selected = (Collection<?>) selection;
            if (selected.size() != 1)
                return null;
            return (Meter) selected.iterator().next();
        }

        @SuppressWarnings("unchecked")
        protected Collection<Meter> getSelection() {
            return (Collection<Meter>) table.getValue();
        }

        protected Map<Base, List<Meter>> getSelectionByParent(Database database) {
            return metersByParent(database, getSelection());
        }

    }

    final Button removeMeters = new Button("Poista", new MeterButtonListener() {

        private static final long serialVersionUID = 2957964892664902859L;

        public void buttonClick(ClickEvent event) {

            for (Meter r : getSelection()) {
                Base owner = r.getOwner(database);
                if (owner != null)
                    owner.removeMeter(r);
            }

            makeMeterTable(main, base, table);
            Updates.update(main, true);

        }

    });
    removeMeters.addStyleName(ValoTheme.BUTTON_TINY);

    final Button moveUp = new Button("Siirr ylemms", new MeterButtonListener() {

        private static final long serialVersionUID = 8434251773337788784L;

        public void buttonClick(ClickEvent event) {

            Map<Base, List<Meter>> sel = getSelectionByParent(database);
            if (sel == null)
                return;

            for (Map.Entry<Base, List<Meter>> entry : sel.entrySet()) {
                entry.getKey().moveMetersUp(entry.getValue());
            }

            makeMeterTable(main, base, table);
            Updates.update(main, true);

        }

    });
    moveUp.addStyleName(ValoTheme.BUTTON_TINY);

    final Button moveDown = new Button("Siirr alemmas", new MeterButtonListener() {

        private static final long serialVersionUID = -5382367112305541842L;

        public void buttonClick(ClickEvent event) {

            for (Map.Entry<Base, List<Meter>> entry : getSelectionByParent(database).entrySet()) {
                entry.getKey().moveMetersDown(entry.getValue());
            }

            makeMeterTable(main, base, table);
            Updates.update(main, true);

        }

    });
    moveDown.addStyleName(ValoTheme.BUTTON_TINY);

    final Button modify = new Button("Mrit");
    modify.addClickListener(new MeterButtonListener() {

        private static final long serialVersionUID = -7109999546516429095L;

        public void buttonClick(ClickEvent event) {

            Meter meter = getPossibleSelection();
            if (meter == null)
                return;

            editMeter(main, base, meter);

        }

    });
    modify.addStyleName(ValoTheme.BUTTON_TINY);

    final ComboBox indicatorSelect = new ComboBox();
    indicatorSelect.setWidth("100%");
    indicatorSelect.setNullSelectionAllowed(false);
    indicatorSelect.addStyleName(ValoTheme.COMBOBOX_TINY);
    indicatorSelect.setCaption("Mrittj");
    final Strategiakartta map = database.getMap(base);

    // Indikaattorit
    for (Indicator i : map.getIndicators(database)) {
        MeterSpec spec = new MeterSpec(database, i);
        indicatorSelect.addItem(spec);
        indicatorSelect.select(spec);
    }
    // Enumeraatiot
    for (Datatype enu : Datatype.enumerate(database)) {
        if (enu instanceof EnumerationDatatype) {
            MeterSpec spec = new MeterSpec(database, enu);
            indicatorSelect.addItem(spec);
            indicatorSelect.select(spec);
        }
    }
    // Sisnrakennetut
    {
        MeterSpec spec = new MeterSpec(database, MeterSpec.IMPLEMENTATION);
        indicatorSelect.addItem(spec);
        indicatorSelect.select(spec);
    }

    indicatorSelect.setTextInputAllowed(false);

    final Button addMeter = new Button("Lis ptasolle", new Button.ClickListener() {

        private static final long serialVersionUID = -5178621686299637238L;

        public void buttonClick(ClickEvent event) {

            MeterSpec spec = (MeterSpec) indicatorSelect.getValue();
            Object source = spec.getSource();
            if (source instanceof Indicator) {
                Indicator ind = (Indicator) source;
                Meter.addIndicatorMeter(main, base, ind, Property.AIKAVALI_KAIKKI);
            } else if (source instanceof EnumerationDatatype) {
                EnumerationDatatype dt = (EnumerationDatatype) source;
                Indicator ind = Indicator.create(database, "Uusi " + dt.getId(database), dt);
                ind.update(main, base, dt.getDefaultValue(), false, "", "Alkuarvo");
                ind.update(main, base, dt.getDefaultForecast(), true, "", "Alkuarvo");
                Meter.addIndicatorMeter(main, base, ind, Property.AIKAVALI_KAIKKI);
            }

            makeMeterTable(main, base, table);
            Updates.update(main, true);

        }

    });
    addMeter.addStyleName(ValoTheme.BUTTON_TINY);

    final Button addSubmeter = new Button("Lis valitun alle", new MeterButtonListener() {

        private static final long serialVersionUID = -1250285092312682737L;

        public void buttonClick(ClickEvent event) {

            Meter meter = getPossibleSelection();
            if (meter == null)
                return;

            MeterSpec spec = (MeterSpec) indicatorSelect.getValue();
            Object source = spec.getSource();
            if (source instanceof Indicator) {
                Indicator ind = (Indicator) source;
                Meter.addIndicatorMeter(main, meter, ind, Property.AIKAVALI_KAIKKI);
            } else if (source instanceof EnumerationDatatype) {
                EnumerationDatatype dt = (EnumerationDatatype) source;
                Indicator ind = Indicator.create(database, "Uusi " + dt.getId(database), dt);
                ind.update(main, base, dt.getDefaultValue(), false, "", "Alkuarvo");
                ind.update(main, base, dt.getDefaultForecast(), true, "", "Alkuarvo");
                Meter.addIndicatorMeter(main, meter, ind, Property.AIKAVALI_KAIKKI);
            }

            makeMeterTable(main, base, table);
            Updates.update(main, true);

        }

    });
    addSubmeter.addStyleName(ValoTheme.BUTTON_TINY);

    final Runnable setStates = new Runnable() {

        @Override
        public void run() {

            Object selection = table.getValue();
            Collection<?> selected = (Collection<?>) selection;
            if (!selected.isEmpty()) {
                removeMeters.setEnabled(true);
                moveUp.setEnabled(true);
                moveDown.setEnabled(true);
                if (selected.size() == 1) {
                    modify.setEnabled(true);
                    addSubmeter.setEnabled(true);
                } else {
                    addSubmeter.setEnabled(false);
                    modify.setEnabled(false);
                }
            } else {
                moveUp.setEnabled(false);
                moveDown.setEnabled(false);
                removeMeters.setEnabled(false);
                addSubmeter.setEnabled(false);
                modify.setEnabled(false);
            }

        }

    };

    table.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 6439090862804667322L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            setStates.run();
        }

    });

    setStates.run();

    HorizontalLayout hl2 = new HorizontalLayout();
    hl2.setSpacing(true);
    hl2.setWidthUndefined();

    hl2.addComponent(modify);
    hl2.setComponentAlignment(modify, Alignment.TOP_LEFT);
    hl2.setExpandRatio(modify, 0.0f);

    hl2.addComponent(removeMeters);
    hl2.setComponentAlignment(removeMeters, Alignment.TOP_LEFT);
    hl2.setExpandRatio(removeMeters, 0.0f);

    hl2.addComponent(moveUp);
    hl2.setComponentAlignment(moveUp, Alignment.TOP_LEFT);
    hl2.setExpandRatio(moveUp, 0.0f);

    hl2.addComponent(moveDown);
    hl2.setComponentAlignment(moveDown, Alignment.TOP_LEFT);
    hl2.setExpandRatio(moveDown, 0.0f);

    HorizontalLayout hl3 = new HorizontalLayout();
    hl3.setSpacing(true);
    hl3.setWidth("100%");

    hl3.addComponent(addMeter);
    hl3.setComponentAlignment(addMeter, Alignment.BOTTOM_LEFT);
    hl3.setExpandRatio(addMeter, 0.0f);

    hl3.addComponent(addSubmeter);
    hl3.setComponentAlignment(addSubmeter, Alignment.BOTTOM_LEFT);
    hl3.setExpandRatio(addSubmeter, 0.0f);

    hl3.addComponent(indicatorSelect);
    hl3.setComponentAlignment(indicatorSelect, Alignment.BOTTOM_LEFT);
    hl3.setExpandRatio(indicatorSelect, 1.0f);

    content.addComponent(hl2);
    content.setComponentAlignment(hl2, Alignment.MIDDLE_CENTER);
    content.setExpandRatio(hl2, 0.0f);

    content.addComponent(hl3);
    content.setComponentAlignment(hl3, Alignment.BOTTOM_LEFT);
    content.setExpandRatio(hl3, 0.0f);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.setMargin(false);

    final Window dialog = Dialogs.makeDialog(main, "450px", "600px", "Hallitse mittareita", "Sulje", content,
            buttons);

}

From source file:fi.semantum.strategia.widget.Meter.java

License:Open Source License

public static void editMeter(final Main main, final Base base, final Meter meter) {

    Database database = main.getDatabase();

    final VerticalLayout content = new VerticalLayout();
    content.setSizeFull();//from   w ww.  j  a v a 2s  . c  o  m
    content.setHeightUndefined();
    content.setSpacing(true);

    HorizontalLayout hl = new HorizontalLayout();
    hl.setWidth("100%");
    hl.setSpacing(true);
    hl.setMargin(false);

    final TextField tf = new TextField();
    tf.setCaption("Lyhytnimi");
    tf.setValue(meter.getId(database));
    tf.addStyleName(ValoTheme.TEXTFIELD_TINY);
    tf.setWidth("100%");

    hl.addComponent(tf);
    hl.setComponentAlignment(tf, Alignment.TOP_CENTER);
    hl.setExpandRatio(tf, 1.0f);

    final TextField tf1 = new TextField();
    tf1.setCaption("Teksti");
    tf1.setValue(meter.getText(database));
    tf1.addStyleName(ValoTheme.TEXTFIELD_TINY);
    tf1.setWidth("100%");

    hl.addComponent(tf1);
    hl.setComponentAlignment(tf1, Alignment.TOP_CENTER);
    hl.setExpandRatio(tf1, 2.0f);

    content.addComponent(hl);
    content.setComponentAlignment(hl, Alignment.TOP_CENTER);
    content.setExpandRatio(hl, 0.0f);

    final TextField tf2 = new TextField();
    tf2.setCaption("Voimassaolo");
    tf2.setValue(Utils.getValidity(database, meter));
    tf2.addStyleName(ValoTheme.TEXTFIELD_TINY);
    tf2.setWidth("100%");

    content.addComponent(tf2);
    content.setComponentAlignment(tf2, Alignment.TOP_CENTER);
    content.setExpandRatio(tf2, 0.0f);

    final TextArea ta = new TextArea();
    ta.setCaption("Mritys");
    ta.setValue(meter.getText(database));
    ta.addStyleName(ValoTheme.TEXTAREA_TINY);
    ta.setHeight("100%");
    ta.setWidth("100%");

    content.addComponent(ta);
    content.setComponentAlignment(ta, Alignment.TOP_CENTER);
    content.setExpandRatio(ta, 1.0f);

    final TrafficValuation valuation = meter.trafficValuation;
    final Runnable onOK = valuation != null ? valuation.getEditor(content, main, meter) : null;

    Indicator indicator = meter.getPossibleIndicator(database);
    if (indicator != null) {
        final Label ta2 = Indicator.makeHistory(database, indicator, main.getUIState().forecastMeters);
        content.addComponent(ta2);
        content.setComponentAlignment(ta2, Alignment.MIDDLE_CENTER);
        content.setExpandRatio(ta2, 1.0f);
    }

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.setMargin(false);

    Button ok = new Button("Tallenna", new Button.ClickListener() {

        private static final long serialVersionUID = 1992235622970234624L;

        public void buttonClick(ClickEvent event) {
            if (onOK != null)
                onOK.run();
            meter.modifyId(main, tf.getValue());
            meter.modifyText(main, tf1.getValue());
            Utils.modifyValidity(main, meter, tf2.getValue());
            meter.modifyDescription(main, ta.getValue());
            Updates.update(main, true);
            manageMeters(main, main.getUIState().currentItem);
        }

    });
    buttons.addComponent(ok);

    Button close = new Button("Sulje");
    buttons.addComponent(close);

    final Window dialog = Dialogs.makeDialog(main, "500px", "800px", "Mrit mittaria", null, content,
            buttons);
    close.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = -8065367213523520602L;

        public void buttonClick(ClickEvent event) {
            main.removeWindow(dialog);
            manageMeters(main, main.getUIState().currentItem);
        }

    });

}

From source file:fi.vtt.RVaadin.RUpload.java

License:Apache License

/**
 * Contruct an upload element for R (implemented as Vaadin CustomComponent).
 * //w ww.  ja va2  s . co  m
 * @param caption
 *            String caption or null
 * @param R
 *            the corresponding RSession to upload the files to
 */
public RUpload(String caption, RContainer R) {

    /* Create the RUpload custom component */
    super.setSizeUndefined();
    root = new Panel(caption);
    root.setWidth("90ex");

    setCompositionRoot(root);

    HorizontalLayout hbox = new HorizontalLayout();
    hbox.setWidth("100%");

    /* Create the Upload component */
    final Upload upload = new Upload("Choose file", this);
    upload.setButtonCaption("Submit");

    /* Listen for events regarding the success of upload. */
    upload.addSucceededListener(this);
    upload.addFailedListener(this);
    hbox.addComponent(upload);

    Label hfill = new Label();
    hbox.addComponent(hfill);
    hbox.setExpandRatio(hfill, 1.0f);

    remove = new Button("Remove", new Button.ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            String current = getSelection();

            if (current != null) {
                /* Delete the file */
                delete(current);

                /* Update the lists and the notification area */
                int i = fileNames.indexOf(current);
                fileNames.remove(i);
                mimeTypes.remove(i);
                uploadedFiles.removeItem(current);

                /* Gray out the button, if this was the last item */
                if (fileNames.isEmpty()) {
                    remove.setEnabled(false);
                }
            }
        }
    });

    hbox.addComponent(remove);
    remove.setEnabled(false);
    hbox.setComponentAlignment(remove, Alignment.BOTTOM_RIGHT);

    /* Notification area for already uploaded files */
    uploadedFiles = new ListSelect("Already submitted files");
    uploadedFiles.setMultiSelect(false);
    uploadedFiles.setNullSelectionAllowed(false);
    uploadedFiles.setHeight("4em");
    uploadedFiles.setWidth("100%");

    // Changed for Vaadin 7, not tested!!
    VerticalLayout vbox = new VerticalLayout();
    vbox.addComponent(hbox);
    vbox.addComponent(uploadedFiles);
    root.setContent(vbox);

    /* Bind the component to the given R session */
    this.R = R;
}