Example usage for com.vaadin.ui Alignment BOTTOM_CENTER

List of usage examples for com.vaadin.ui Alignment BOTTOM_CENTER

Introduction

In this page you can find the example usage for com.vaadin.ui Alignment BOTTOM_CENTER.

Prototype

Alignment BOTTOM_CENTER

To view the source code for com.vaadin.ui Alignment BOTTOM_CENTER.

Click Source Link

Usage

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

License:Open Source License

private static void updateProperties(final Main main) {

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

    boolean canWrite = main.canWrite(base);

    main.propertyCells = new ArrayList<List<String>>();

    main.properties.removeAllComponents();
    main.properties.setId("map");

    if (base == null)
        return;/*from   w  ww .  j  av a 2  s  .  co m*/

    Property.updateProperties(main, base, canWrite);

    Indicator.updateIndicators(main, base, canWrite);

    Meter.updateMeters(main, canWrite);

    Tag.updateRelatedTags(main, canWrite);

    Tag.updateMonitoredTags(main, canWrite);

    final Button palaa = new Button("Palaa takaisin", new Button.ClickListener() {

        private static final long serialVersionUID = -6097534468072862126L;

        public void buttonClick(ClickEvent event) {
            main.applyFragment(main.backFragment, true);
        }

    });

    main.properties.addComponent(palaa);
    main.properties.setComponentAlignment(palaa, Alignment.BOTTOM_CENTER);

}

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

License:Open Source License

private static void updateQueryGrid(final Main main, final FilterState state) {

    main.gridPanelLayout.removeAllComponents();
    main.gridPanelLayout.setMargin(false);

    final List<String> keys = state.reportColumns;
    if (keys.isEmpty()) {
        Label l = new Label("Kysely ei tuottanut yhtn tulosta.");
        l.addStyleName(ValoTheme.LABEL_BOLD);
        l.addStyleName(ValoTheme.LABEL_HUGE);
        main.gridPanelLayout.addComponent(l);
        return;/*from   w  w  w  .  j  a v  a  2s.  c o  m*/
    }

    final IndexedContainer container = new IndexedContainer();

    for (String key : keys) {
        container.addContainerProperty(key, String.class, "");
    }

    rows: for (Map<String, ReportCell> map : state.report) {
        Object item = container.addItem();
        for (String key : keys)
            if (map.get(key) == null)
                continue rows;

        for (Map.Entry<String, ReportCell> entry : map.entrySet()) {
            @SuppressWarnings("unchecked")
            com.vaadin.data.Property<String> p = container.getContainerProperty(item, entry.getKey());
            p.setValue(entry.getValue().get());
        }

    }

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

    final TextField filter = new TextField();
    filter.addStyleName(ValoTheme.TEXTFIELD_TINY);
    filter.setInputPrompt("rajaa hakutuloksia - kirjoitetun sanan tulee lyty rivin teksteist");
    filter.setWidth("100%");

    final Image clipboard = new Image();
    clipboard.setSource(new ThemeResource("page_white_excel.png"));
    clipboard.setHeight("24px");
    clipboard.setWidth("24px");

    hl.addComponent(filter);
    hl.setExpandRatio(filter, 1.0f);
    hl.setComponentAlignment(filter, Alignment.BOTTOM_CENTER);
    hl.addComponent(clipboard);
    hl.setComponentAlignment(clipboard, Alignment.BOTTOM_CENTER);
    hl.setExpandRatio(clipboard, 0.0f);

    main.gridPanelLayout.addComponent(hl);
    main.gridPanelLayout.setExpandRatio(hl, 0f);

    filter.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 3033918399018888150L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            container.removeAllContainerFilters();
            container.addContainerFilter(new QueryFilter(filter.getValue(), true, false));
        }
    });

    AbsoluteLayout abs = new AbsoluteLayout();
    abs.setSizeFull();

    final Grid queryGrid = new Grid(container);
    queryGrid.setSelectionMode(SelectionMode.NONE);
    queryGrid.setHeightMode(HeightMode.CSS);
    queryGrid.setHeight("100%");
    queryGrid.setWidth("100%");

    for (String key : keys) {
        Column col = queryGrid.getColumn(key);
        col.setExpandRatio(1);
    }

    abs.addComponent(queryGrid);

    OnDemandFileDownloader dl = new OnDemandFileDownloader(new OnDemandStreamSource() {

        private static final long serialVersionUID = 981769438054780731L;

        File f;
        Date date = new Date();

        @Override
        public InputStream getStream() {

            String uuid = UUID.randomUUID().toString();
            File printing = new File(Main.baseDirectory(), "printing");
            f = new File(printing, uuid + ".xlsx");

            Workbook w = new XSSFWorkbook();
            Sheet sheet = w.createSheet("Sheet1");
            Row header = sheet.createRow(0);
            for (int i = 0; i < keys.size(); i++) {
                Cell cell = header.createCell(i);
                cell.setCellValue(keys.get(i));
            }

            int row = 1;
            rows: for (Map<String, ReportCell> map : state.report) {
                for (String key : keys)
                    if (map.get(key) == null)
                        continue rows;

                Row r = sheet.createRow(row++);
                int column = 0;
                for (int i = 0; i < keys.size(); i++) {
                    Cell cell = r.createCell(column++);
                    ReportCell rc = map.get(keys.get(i));
                    cell.setCellValue(rc.getLong());
                }

            }

            try {
                FileOutputStream s = new FileOutputStream(f);
                w.write(s);
                s.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                return new FileInputStream(f);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }

            throw new IllegalStateException();

        }

        @Override
        public void onRequest() {
            // TODO Auto-generated method stub

        }

        @Override
        public long getFileSize() {
            return f.length();
        }

        @Override
        public String getFileName() {
            return "Strategiakartta_" + Utils.dateString(date) + ".xlsx";
        }

    });

    dl.getResource().setCacheTime(0);
    dl.extend(clipboard);

    main.gridPanelLayout.addComponent(abs);
    main.gridPanelLayout.setExpandRatio(abs, 1f);

}

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

License:Open Source License

public static void manage(final Main main) {

    final Database database = main.getDatabase();

    VerticalLayout content = new VerticalLayout();
    content.setSizeFull();//from   w  w w .j  a  va  2 s. c om
    content.setSpacing(true);

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

    final ComboBox users = new ComboBox();
    users.setWidth("100%");
    users.setNullSelectionAllowed(false);
    users.addStyleName(ValoTheme.COMBOBOX_SMALL);
    users.setCaption("Valitse kyttj:");

    final Map<String, Account> accountMap = new HashMap<String, Account>();
    makeAccountCombo(main, accountMap, users);

    for (Account a : Account.enumerate(database)) {
        accountMap.put(a.getId(database), a);
        users.addItem(a.getId(database));
        users.select(a.getId(database));
    }

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

    users.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 5036991262418844060L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            users.removeValueChangeListener(this);
            makeAccountCombo(main, accountMap, users);
            makeAccountTable(database, users, accountMap, table);
            users.addValueChangeListener(this);
        }

    });

    final TextField tf = new TextField();

    Validator nameValidator = 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 (accountMap.containsKey(s))
                throw new InvalidValueException("Nimi on jo kytss");
        }

    };

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

        private static final long serialVersionUID = -6053708137324681886L;

        public void buttonClick(ClickEvent event) {

            if (!tf.isValid())
                return;

            String pass = Long.toString(Math.abs(UUID.randomUUID().getLeastSignificantBits()), 36);
            Account.create(database, tf.getValue(), "", Utils.hash(pass));

            Updates.update(main, true);

            makeAccountCombo(main, accountMap, users);
            makeAccountTable(database, users, accountMap, table);

            Dialogs.infoDialog(main, "Uusi kyttj '" + tf.getValue() + "' luotu",
                    "Kyttjn salasana on " + pass + "", null);

        }

    });
    save.addStyleName(ValoTheme.BUTTON_SMALL);

    final Button remove = new Button("Poista", new Button.ClickListener() {

        private static final long serialVersionUID = -5359199320445328801L;

        public void buttonClick(ClickEvent event) {

            Object selection = users.getValue();
            Account state = accountMap.get(selection);

            // System cannot be removed
            if ("System".equals(state.getId(database)))
                return;

            state.remove(database);

            Updates.update(main, true);

            makeAccountCombo(main, accountMap, users);
            makeAccountTable(database, users, accountMap, table);

        }

    });
    remove.addStyleName(ValoTheme.BUTTON_SMALL);

    tf.setWidth("100%");
    tf.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    tf.setCaption("Luo uusi kyttj nimell:");
    tf.setValue(findFreshUserName(nameValidator));
    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(nameValidator);
    if (!tf.isValid())
        save.setEnabled(false);

    hl1.addComponent(users);
    hl1.setExpandRatio(users, 1.0f);
    hl1.setComponentAlignment(users, Alignment.BOTTOM_CENTER);

    hl1.addComponent(tf);
    hl1.setExpandRatio(tf, 1.0f);
    hl1.setComponentAlignment(tf, Alignment.BOTTOM_CENTER);

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

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

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

    table.addContainerProperty("Kartta", String.class, null);
    table.addContainerProperty("Oikeus", String.class, null);
    table.addContainerProperty("Laajuus", String.class, null);

    table.setWidth("100%");
    table.setHeight("100%");
    table.setNullSelectionAllowed(true);
    table.setMultiSelect(true);
    table.setCaption("Kyttjn oikeudet");

    makeAccountTable(database, users, accountMap, table);

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

    final Button removeRights = new Button("Poista valitut rivit", new Button.ClickListener() {

        private static final long serialVersionUID = 4699670345358079045L;

        public void buttonClick(ClickEvent event) {

            Object user = users.getValue();
            Account state = accountMap.get(user);

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

            List<Right> toRemove = new ArrayList<Right>();

            for (Object s : sel) {
                Integer index = (Integer) s;
                toRemove.add(state.rights.get(index - 1));
            }

            for (Right r : toRemove)
                state.rights.remove(r);

            Updates.update(main, true);

            makeAccountTable(database, users, accountMap, table);

        }

    });
    removeRights.addStyleName(ValoTheme.BUTTON_SMALL);

    table.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1188285609779556446L;

        @Override
        public void valueChange(ValueChangeEvent event) {

            Object selection = table.getValue();
            Collection<?> sel = (Collection<?>) selection;
            if (sel.isEmpty())
                removeRights.setEnabled(false);
            else
                removeRights.setEnabled(true);

        }

    });

    final ComboBox mapSelect = new ComboBox();
    mapSelect.setWidth("100%");
    mapSelect.setNullSelectionAllowed(false);
    mapSelect.addStyleName(ValoTheme.COMBOBOX_SMALL);
    mapSelect.setCaption("Valitse kartta:");
    for (Strategiakartta a : Strategiakartta.enumerate(database)) {
        mapSelect.addItem(a.uuid);
        mapSelect.setItemCaption(a.uuid, a.getText(database));
        mapSelect.select(a.uuid);
    }

    final ComboBox rightSelect = new ComboBox();
    rightSelect.setWidth("100px");
    rightSelect.setNullSelectionAllowed(false);
    rightSelect.addStyleName(ValoTheme.COMBOBOX_SMALL);
    rightSelect.setCaption("Valitse oikeus:");
    rightSelect.addItem("Muokkaus");
    rightSelect.addItem("Luku");
    rightSelect.select("Luku");

    final ComboBox propagateSelect = new ComboBox();
    propagateSelect.setWidth("130px");
    propagateSelect.setNullSelectionAllowed(false);
    propagateSelect.addStyleName(ValoTheme.COMBOBOX_SMALL);
    propagateSelect.setCaption("Valitse laajuus:");
    propagateSelect.addItem(VALITTU_KARTTA);
    propagateSelect.addItem(ALATASON_KARTAT);
    propagateSelect.select(VALITTU_KARTTA);

    final Button addRight = new Button("Lis rivi", new Button.ClickListener() {

        private static final long serialVersionUID = -4841787792917761055L;

        public void buttonClick(ClickEvent event) {

            Object user = users.getValue();
            Account state = accountMap.get(user);

            String mapUUID = (String) mapSelect.getValue();
            Strategiakartta map = database.find(mapUUID);
            String right = (String) rightSelect.getValue();
            String propagate = (String) propagateSelect.getValue();

            Right r = new Right(map, right.equals("Muokkaus"), propagate.equals(ALATASON_KARTAT));
            state.rights.add(r);

            Updates.update(main, true);

            makeAccountTable(database, users, accountMap, table);

        }

    });
    addRight.addStyleName(ValoTheme.BUTTON_SMALL);

    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()) {
                removeRights.setEnabled(true);
            } else {
                removeRights.setEnabled(false);
            }

        }

    });

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

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

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

    hl2.addComponent(mapSelect);
    hl2.setComponentAlignment(mapSelect, Alignment.BOTTOM_LEFT);
    hl2.setExpandRatio(mapSelect, 1.0f);

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

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

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

    final VerticalLayout vl = new VerticalLayout();

    final Panel p = new Panel();
    p.setWidth("100%");
    p.setHeight("200px");
    p.setContent(vl);

    final TimeConfiguration tc = TimeConfiguration.getInstance(database);

    final TextField tf2 = new TextField();
    tf2.setWidth("200px");
    tf2.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    tf2.setCaption("Strategiakartan mritysaika:");
    tf2.setValue(tc.getRange());
    tf2.setCursorPosition(tf.getValue().length());
    tf2.setValidationVisible(true);
    tf2.setInvalidCommitted(true);
    tf2.setImmediate(true);
    tf2.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = -8274588731607481635L;

        @Override
        public void textChange(TextChangeEvent event) {
            tf2.setValue(event.getText());
            try {
                tf2.validate();
                tc.setRange(event.getText());
                updateYears(database, vl);
                Updates.update(main, true);
            } catch (InvalidValueException e) {
                return;
            }
        }

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

        private static final long serialVersionUID = -4779239111120669168L;

        @Override
        public void validate(Object value) throws InvalidValueException {
            String s = (String) value;
            TimeInterval ti = TimeInterval.parse(s);
            long start = ti.startYear;
            long end = ti.endYear;
            if (start < 2015)
                throw new InvalidValueException("Alkuvuosi ei voi olla aikaisempi kuin 2015.");
            if (end > 2025)
                throw new InvalidValueException("Pttymisvuosi ei voi olla myhisempi kuin 2025.");
            if (end - start > 9)
                throw new InvalidValueException("Strategiakartta ei tue yli 10 vuoden tarkasteluja.");
        }

    });

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

    updateYears(database, vl);

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

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

    Dialogs.makeDialog(main, main.dialogWidth(), main.dialogHeight(0.8), "Hallinnoi strategiakarttaa", "Sulje",
            content, buttons);

}

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

License:Open Source License

public static void setUserMeter(final Main main, final Base base, final Meter m) {

    final Database database = main.getDatabase();

    final Window subwindow = new Window("Aseta mittarin arvo", new VerticalLayout());
    subwindow.setModal(true);//from  w ww  .  j a v a 2  s  .  c o  m
    subwindow.setWidth("350px");
    subwindow.setResizable(false);

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

    String caption = m.getCaption(database);
    if (caption != null && !caption.isEmpty()) {
        final Label header = new Label(caption);
        header.addStyleName(ValoTheme.LABEL_LARGE);
        winLayout.addComponent(header);
    }

    final Indicator indicator = m.getPossibleIndicator(database);
    if (indicator == null)
        return;

    Datatype dt = indicator.getDatatype(database);
    if (!(dt instanceof EnumerationDatatype))
        return;

    final Label l = new Label("Selite: " + indicator.getValueShortComment());

    AbstractField<?> forecastField = dt.getEditor(main, base, indicator, true, new CommentCallback() {

        @Override
        public void runWithComment(String shortComment, String comment) {
            l.setValue("Selite: " + indicator.getValueShortComment());
        }

        @Override
        public void canceled() {
        }

    });
    forecastField.setWidth("100%");
    forecastField.setCaption("Ennuste");
    winLayout.addComponent(forecastField);

    AbstractField<?> currentField = dt.getEditor(main, base, indicator, false, new CommentCallback() {

        @Override
        public void runWithComment(String shortComment, String comment) {
            l.setValue("Selite: " + indicator.getValueShortComment());
        }

        @Override
        public void canceled() {
        }

    });
    currentField.setWidth("100%");
    currentField.setCaption("Toteuma");
    winLayout.addComponent(currentField);

    winLayout.addComponent(l);

    l.setWidth("100%");
    winLayout.setComponentAlignment(l, Alignment.BOTTOM_CENTER);

    HorizontalLayout hl = new HorizontalLayout();
    winLayout.addComponent(hl);
    winLayout.setComponentAlignment(hl, Alignment.BOTTOM_CENTER);

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

        private static final long serialVersionUID = 1364802814012491490L;

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

    });

    Button define = new Button("Mrit", new Button.ClickListener() {

        private static final long serialVersionUID = 1364802814012491490L;

        public void buttonClick(ClickEvent event) {
            Meter.editMeter(main, base, m);
        }

    });

    hl.addComponent(ok);
    hl.setComponentAlignment(ok, Alignment.BOTTOM_LEFT);
    hl.addComponent(define);
    hl.setComponentAlignment(define, Alignment.BOTTOM_LEFT);

    main.addWindow(subwindow);

}

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  ww w. j a va  2  s .  c o 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.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);/*from ww w .  j  ava  2  s  .  c  om*/

        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 void updateMeters(final Main main, boolean canWrite) {

    if (main.getUIState().currentItem instanceof Strategiakartta)
        return;//from ww w  .  j av a2 s  .c  om

    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.Tag.java

License:Open Source License

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

    final Database database = main.getDatabase();

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

    Collection<Tag> tags = base.getRelatedTags(database);
    if (!tags.isEmpty() || canWrite) {

        HorizontalLayout tagHeader = new HorizontalLayout();
        tagHeader.setSpacing(true);//  w  w  w.j a v a 2s .c om

        Label header2 = new Label("Aihetunnisteet");
        header2.setHeight("32px");
        header2.addStyleName(ValoTheme.LABEL_HUGE);
        header2.addStyleName(ValoTheme.LABEL_BOLD);
        tagHeader.addComponent(header2);
        tagHeader.setComponentAlignment(header2, Alignment.BOTTOM_CENTER);

        if (canWrite) {
            final Image editTags = new Image("", new ThemeResource("tag_blue_edit.png"));
            editTags.setHeight("24px");
            editTags.setWidth("24px");
            editTags.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = -6140867347404571880L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Utils.loseFocus(editTags);
                    Utils.editTags(main, "Muokkaa aihetunnisteita", main.getUIState().currentItem);
                }

            });
            tagHeader.addComponent(editTags);
            tagHeader.setComponentAlignment(editTags, Alignment.BOTTOM_CENTER);
        }

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

        HorizontalLayout divider = new HorizontalLayout();
        main.properties.addComponent(divider);
        main.properties.setComponentAlignment(divider, Alignment.MIDDLE_CENTER);

        VerticalLayout left = new VerticalLayout();
        left.setSpacing(true);
        left.setWidth("400px");
        left.setMargin(true);
        divider.addComponent(left);
        VerticalLayout right = new VerticalLayout();
        right.setSpacing(true);
        right.setWidth("400px");
        right.setMargin(true);
        divider.addComponent(right);

        Set<Tag> monitoredTags = getMonitoredTags(database, base);

        int i = 0;
        for (final Tag tag : tags) {

            final boolean monitor = base.hasMonitorTag(database, tag);
            String tagId = tag.getId(database);

            HorizontalLayout hl = new HorizontalLayout();
            hl.setSpacing(true);
            hl.setHeight("37px");

            Button tagButton = Utils.tagButton(database, "list", tagId, i++);
            left.addComponent(tagButton);
            left.setComponentAlignment(tagButton, Alignment.MIDDLE_RIGHT);

            if (canWrite) {
                Button b = new Button();
                b.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                b.setIcon(FontAwesome.TIMES_CIRCLE);
                b.addClickListener(new ClickListener() {

                    private static final long serialVersionUID = -4473258383318654850L;

                    @Override
                    public void buttonClick(ClickEvent event) {
                        base.removeRelatedTags(database, tag);
                        Utils.loseFocus(main.properties);
                        Updates.update(main, true);
                    }

                });
                hl.addComponent(b);
                hl.setComponentAlignment(b, Alignment.MIDDLE_LEFT);
            }

            if (base instanceof Strategiakartta) {

                Button tagButton2 = new Button();
                tagButton2.setCaption(monitor ? "Seurataan toteutuksessa" : "Ei seurata toteutuksessa");
                tagButton2.addStyleName(monitor ? "greenButton" : "redButton");
                tagButton2.addStyleName(ValoTheme.BUTTON_SMALL);
                tagButton2.setWidth("200px");
                if (canWrite) {
                    tagButton2.addClickListener(new ClickListener() {

                        private static final long serialVersionUID = -1769769368034323594L;

                        @Override
                        public void buttonClick(ClickEvent event) {
                            if (monitor) {
                                base.removeMonitorTags(database, tag);
                            } else {
                                base.assertMonitorTags(database, tag);
                            }
                            Utils.loseFocus(main.properties);
                            Updates.update(main, true);
                        }

                    });
                    tagButton2.setEnabled(true);
                } else {
                    tagButton2.setEnabled(false);
                }

                hl.addComponent(tagButton2);
                hl.setComponentAlignment(tagButton2, Alignment.MIDDLE_LEFT);

            } else {

                if (monitoredTags.contains(tag)) {
                    Label l = new Label(" toteuttaa seurattavaa aihetta ");
                    hl.addComponent(l);
                    hl.setComponentAlignment(l, Alignment.MIDDLE_LEFT);
                }

            }

            right.addComponent(hl);
            right.setComponentAlignment(hl, Alignment.MIDDLE_LEFT);

        }

    }

}

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

License:Open Source License

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

    final Database database = main.getDatabase();

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

    if (!(base instanceof Tavoite || base instanceof Painopiste))
        return;/*from   ww w. j ava  2  s .com*/

    Set<Tag> monitoredTags = getMonitoredTags(database, base);
    monitoredTags.removeAll(base.getRelatedTags(database));
    Map<String, Base> implementors = new HashMap<String, Base>();
    for (Base impl : Utils.getImplementationSet(database, base)) {
        for (Tag i : impl.getRelatedTags(database)) {
            if (monitoredTags.contains(i)) {
                implementors.put(i.uuid, impl);
            }
        }
    }

    if (!monitoredTags.isEmpty() || canWrite) {

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

        Label header2 = new Label("Seurattavat aihetunnisteet");
        header2.setHeight("32px");
        header2.addStyleName(ValoTheme.LABEL_HUGE);
        header2.addStyleName(ValoTheme.LABEL_BOLD);
        tagHeader.addComponent(header2);
        tagHeader.setComponentAlignment(header2, Alignment.BOTTOM_CENTER);

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

        HorizontalLayout divider = new HorizontalLayout();
        main.properties.addComponent(divider);
        main.properties.setComponentAlignment(divider, Alignment.MIDDLE_CENTER);

        VerticalLayout left = new VerticalLayout();
        left.setSpacing(true);
        left.setWidth("400px");
        left.setMargin(true);
        divider.addComponent(left);
        VerticalLayout right = new VerticalLayout();
        right.setSpacing(true);
        right.setWidth("400px");
        right.setMargin(true);
        divider.addComponent(right);

        int i = 0;
        for (final Tag tag : monitoredTags) {

            String tagId = tag.getId(database);

            HorizontalLayout hl = new HorizontalLayout();
            hl.setSpacing(true);
            hl.setHeight("37px");

            Button tagButton = Utils.tagButton(database, "inferred", tagId, i++);
            left.addComponent(tagButton);
            left.setComponentAlignment(tagButton, Alignment.MIDDLE_RIGHT);

            Base implementor = implementors.get(tag.uuid);
            if (implementor != null) {

                String desc = implementor.getId(database);
                if (desc.isEmpty())
                    desc = implementor.getText(database);

                Label tagLabel = new Label("Toteutetaan ylemmll tasolla: " + desc);
                hl.addComponent(tagLabel);
                hl.setComponentAlignment(tagLabel, Alignment.MIDDLE_LEFT);

            } else {

                Button tagButton2 = new Button();
                tagButton2.setCaption("Merkitse toteuttajaksi");
                tagButton2.addStyleName("redButton");
                tagButton2.addStyleName(ValoTheme.BUTTON_SMALL);
                tagButton2.setWidth("200px");
                if (canWrite) {
                    tagButton2.addClickListener(new ClickListener() {

                        private static final long serialVersionUID = -1769769368034323594L;

                        @Override
                        public void buttonClick(ClickEvent event) {
                            base.assertRelatedTags(database, tag);
                            Utils.loseFocus(main.properties);
                            Updates.update(main, true);
                        }

                    });
                    tagButton2.setEnabled(true);
                } else {
                    tagButton2.setEnabled(false);
                }
                hl.addComponent(tagButton2);
                hl.setComponentAlignment(tagButton2, Alignment.MIDDLE_LEFT);

            }

            right.addComponent(hl);
            right.setComponentAlignment(hl, Alignment.MIDDLE_LEFT);

        }

    }

}

From source file:foo.MyVaadinApplication.java

License:Apache License

/**
 * Initializes the main layout of the page
 * /*from w ww .  ja  v  a  2  s . c  o m*/
 * @return initialized main layout of the page
 */
private VerticalLayout initLayout() {
    VerticalLayout v = new VerticalLayout();
    v.setStyleName(Reindeer.LAYOUT_BLUE);
    v.setSpacing(false);

    Panel topBanner = initTopBanner();
    v.addComponent(topBanner);
    v.setComponentAlignment(topBanner, Alignment.TOP_CENTER);

    Panel middlePanel = initMiddlePanel();
    v.addComponent(middlePanel);
    v.setComponentAlignment(middlePanel, Alignment.MIDDLE_CENTER);

    Panel bottomBanner = initBottomBanner();
    v.addComponent(bottomBanner);
    v.setComponentAlignment(bottomBanner, Alignment.BOTTOM_CENTER);
    return v;
}