Example usage for com.vaadin.ui Button setEnabled

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

Introduction

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

Prototype

@Override
    public void setEnabled(boolean enabled) 

Source Link

Usage

From source file:facs.components.Statistics.java

License:Open Source License

private Component newMatchedGrid() {

    Button createInvoiceMatched = new Button("Create Invoice");
    Button downloadInvoiceMatched = new Button("Download Invoice");

    String buttonRefreshTitle = "Refresh";
    Button refreshMatched = new Button(buttonRefreshTitle);
    refreshMatched.setIcon(FontAwesome.REFRESH);
    refreshMatched.setDescription("Click here to reload the data from the database!");
    refreshMatched.addStyleName(ValoTheme.BUTTON_FRIENDLY);

    createInvoiceMatched.setEnabled(false);
    downloadInvoiceMatched.setEnabled(false);

    Grid matchedGrid;//from   www  . j  a  v a 2 s.  co m

    refreshMatched.addClickListener(new ClickListener() {
        private static final long serialVersionUID = -3610721151565496269L;

        @Override
        public void buttonClick(ClickEvent event) {
            refreshDataSources();

        }
    });

    IndexedContainer mcontainer = getEmptyContainer();

    GeneratedPropertyContainer mpc = new GeneratedPropertyContainer(mcontainer);

    VerticalLayout matchedLayout = new VerticalLayout();

    matchedGrid = new Grid(mpc);

    setRenderers(matchedGrid);
    fillMatchedRows(matchedGrid);

    // compute total costs
    float totalCosts = 0.0f;
    for (Object itemId : mpc.getItemIds())
        totalCosts += ((Number) mpc.getContainerProperty(itemId, costCaption).getValue()).floatValue();

    // compute total time in milliseconds
    long total = 0;
    for (Object itemId : mpc.getItemIds()) {
        long s = ((Date) mpc.getContainerProperty(itemId, startCaption).getValue()).getTime();
        long e = ((Date) mpc.getContainerProperty(itemId, endCaption).getValue()).getTime();
        total += e - s;
    }

    // set footer to contain total cost and time in hours:minutes
    FooterRow footer = matchedGrid.appendFooterRow();
    FooterCell footerCellCost = footer.getCell(costCaption);
    footerCellCost.setText(String.format("%1$.2f  total", totalCosts));

    FooterCell footerCellEnd = footer.getCell(endCaption);
    footerCellEnd.setText(Formatter.toHoursAndMinutes(total)); // "%1$.0f hours"

    // Set up a filter for all columns
    HeaderRow filterRow = matchedGrid.appendHeaderRow();
    addRowFilter(filterRow, deviceCaption, mcontainer, footer, mpc);
    addRowFilter(filterRow, kostenstelleCaption, mcontainer, footer, mpc);

    matchedLayout.setMargin(true);
    matchedLayout.setSpacing(true);

    // devicesGrid.setWidth("100%");
    matchedGrid.setSizeFull();
    matchedGrid.setSelectionMode(SelectionMode.SINGLE);
    matchedLayout.addComponent(matchedGrid);

    matchedGrid.setSelectionMode(SelectionMode.SINGLE);
    matchedGrid.addSelectionListener(new SelectionListener() {

        /**
         * 
         */
        private static final long serialVersionUID = -2683274060620429050L;

        @Override
        public void select(SelectionEvent event) {
            // Notification.show("Select row: " + grid.getSelectedRow() + " Name: "
            // + gpcontainer.getContainerProperty(grid.getSelectedRow(), nameCaption).getValue());
            downloadInvoiceMatched.setEnabled(false);
            ReceiverPI = (String) mpc.getContainerProperty(matchedGrid.getSelectedRow(), nameCaption)
                    .getValue();
            createInvoiceMatched.setEnabled(true);
        }
    });
    createInvoiceMatched.addClickListener(new ClickListener() {

        private File bill;
        private FileDownloader fileDownloader;

        @Override
        public void buttonClick(ClickEvent event) {
            String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();

            Paths.get(basepath, "WEB-INF/billingTemplates");

            // System.out.println("Basepath: " + basepath);

            try {

                int setUserId = DBManager.getDatabaseInstance().findUserByFullName(ReceiverPI);

                if (setUserId > 0) {

                    Billing billing = new Billing(Paths.get(basepath, "WEB-INF/billingTemplates").toFile(),
                            "Angebot.tex");

                    UserBean user = setUserId > 0 ? DBManager.getDatabaseInstance().getUserById(setUserId)
                            : null;

                    billing.setReceiverPI(ReceiverPI);
                    billing.setReceiverInstitution(user.getInstitute());
                    billing.setReceiverStreet(user.getStreet());
                    billing.setReceiverPostalCode(user.getPostcode());
                    billing.setReceiverCity(user.getCity());

                    billing.setSenderName("Dr. rer. nat. Stella Autenrieth");
                    billing.setSenderFunction("Leiterin");
                    billing.setSenderPostalCode("72076");
                    billing.setSenderCity("Tbingen");
                    billing.setSenderStreet("Otfried-Mller-Strae 10");
                    billing.setSenderPhone("+49 (0) 7071 29-83156");
                    billing.setSenderEmail("stella.autenrieth@med.uni-tuebingen.de");
                    billing.setSenderUrl("www.medizin.uni-tuebingen.de");
                    billing.setSenderFaculty("Medizinischen Fakultt");

                    if (user.getKostenstelle() != null)
                        billing.setProjectDescription("Kostenstelle: " + user.getKostenstelle());
                    else
                        billing.setProjectDescription("Keine kostenstelle verfgbar.");

                    billing.setProjectShortDescription("Dieses Angebot beinhaltet jede Menge Extras.");

                    if (user.getProject() != null)
                        billing.setProjectNumber("Kostenstelle: " + user.getKostenstelle());
                    else
                        billing.setProjectNumber("Keine project nummer verfgbar.");

                    float cost = ((Number) mpc.getContainerProperty(matchedGrid.getSelectedRow(), costCaption)
                            .getValue()).floatValue();
                    long s = ((Date) mpc.getContainerProperty(matchedGrid.getSelectedRow(), startCaption)
                            .getValue()).getTime();
                    long e = ((Date) mpc.getContainerProperty(matchedGrid.getSelectedRow(), endCaption)
                            .getValue()).getTime();
                    long timeFrame = e - s;
                    Date start = ((Date) mpc.getContainerProperty(matchedGrid.getSelectedRow(), startCaption)
                            .getValue());
                    SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy");
                    String date = ft.format(start);
                    String description = "No Description is Available";
                    String time_frame = Formatter.toHoursAndMinutes(timeFrame);

                    ArrayList<CostEntry> entries = new ArrayList<CostEntry>();
                    entries.add(billing.new CostEntry(date, time_frame, description, cost));
                    billing.setCostEntries(entries);

                    float totalCosts = 0.0f;

                    totalCosts = ((Number) mpc.getContainerProperty(matchedGrid.getSelectedRow(), costCaption)
                            .getValue()).floatValue();

                    billing.setTotalCost(String.format("%1$.2f", totalCosts));

                    bill = billing.createPdf();
                    // System.out.println(bill.getAbsolutePath());
                    if (fileDownloader != null)
                        downloadInvoiceMatched.removeExtension(fileDownloader);
                    fileDownloader = new FileDownloader(new FileResource(bill));
                    fileDownloader.extend(downloadInvoiceMatched);
                    downloadInvoiceMatched.setEnabled(true);
                    showSuccessfulNotification("Congratulations!",
                            "Invoice is created and available for download.");
                    downloadInvoiceMatched.setEnabled(true);
                } else {
                    createInvoiceMatched.setEnabled(false);
                    downloadInvoiceMatched.setEnabled(false);
                    showErrorNotification("No such user found!",
                            "An error occured while trying to create the invoice. The common problem occurs to be: this no such user in the database.");
                }
            }

            catch (Exception e) {
                showErrorNotification("What the heck!",
                        "An error occured while trying to create the invoice. The common problem occurs to be: this no such user or it can not run program 'pdflatex'.");
                e.printStackTrace();
            }

        }

    });

    matchedLayout.addComponent(refreshMatched);
    matchedLayout.addComponent(createInvoiceMatched);
    matchedLayout.addComponent(downloadInvoiceMatched);

    return matchedLayout;
}

From source file:fi.csc.pathway.TutkaUI.java

License:Creative Commons License

/**
 * Pohjelma, joka luo kyttliittymn./*from w  w  w.j  a  v  a  2s .  c  om*/
 */
@Override
protected void init(VaadinRequest request) {
    final String portletContextName = getPortletContextName(request);
    final VerticalLayout vasenpalkki = new VerticalLayout();
    final HorizontalLayout layout = new HorizontalLayout(); //main
    final HorizontalLayout karttapalkki = new HorizontalLayout();
    final HorizontalLayout lkmnext = new HorizontalLayout();
    final Label hr = new Label("  ____________________", ContentMode.HTML);
    final Label aika = new Label("Time", ContentMode.HTML);
    final Label lkm = new Label("0", ContentMode.HTML);
    final Button next = new Button("Next");
    final OptionGroup tyyppi = new OptionGroup("Type");
    final OptionGroup tutka = new OptionGroup("Radar");
    final OptionGroup kulma = new OptionGroup("Angle");
    final OptionGroup krjet = new OptionGroup("Min vertices");
    final Googlekartta gma = new Googlekartta(aika, tutka, kulma, tyyppi, krjet, portletContextName, lkm);
    final Tutkat tutkat = new Tutkat();
    final PopupDateField enddate = new PopupDateField("To:");
    final PopupDateField startdate = new PopupDateField("From:");
    final GoogleMap oldComponent = gma.getOrigMap();
    final GridLayout parametrit = new GridLayout(2, 2);
    tutkat.alusta(tutka, krjet, oldComponent);
    parametrit.addComponent(tutka);
    parametrit.addComponent(krjet);
    Ilmiot ilmio = new Ilmiot(tyyppi, tutka);
    kulma.addItem("1.5");
    kulma.addItem("0.7");
    kulma.addItem(Tutkat.LOW); //luostolla ei ole matalampaa kuin 0.7
    kulma.setValue("1.5");
    parametrit.addComponent(kulma);
    parametrit.addComponent(ilmio.getTyyppi());
    vasenpalkki.addComponent(parametrit);
    Tarkista tarkista = new Tarkista(enddate, startdate);
    vasenpalkki.addComponent(tarkista.getstartdate());
    vasenpalkki.addComponent(tarkista.getenddate());
    next.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = -8146345475859196611L;

        public void buttonClick(ClickEvent event) {
            if (gma.updateMap()) {
                next.setEnabled(false);
            }
        }
    });
    final Button button = new Button("Query");
    button.addClickListener(new Button.ClickListener() {
        //Component oldC = oldComponent;
        private static final long serialVersionUID = -8146345475859196612L;

        public void buttonClick(ClickEvent event) {
            if (gma.getMap(startdate.getValue(), enddate.getValue(), tutka.getValue())) {
                // tm ei ole kaunista, mutta uudelleen lisminen ei haittaa
                vasenpalkki.addComponent(hr);
                vasenpalkki.addComponent(aika);
                lkmnext.addComponent(lkm);
                next.setEnabled(true);
                lkmnext.addComponent(next);
                vasenpalkki.addComponent(lkmnext);
            }
        }
    });
    vasenpalkki.addComponent(button);
    layout.addComponent(vasenpalkki);
    karttapalkki.setHeight(600, Sizeable.Unit.PIXELS);
    karttapalkki.addComponent(oldComponent);
    layout.addComponent(karttapalkki);
    layout.setMargin(true);
    setContent(layout);
}

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();//w w  w.j  a  v a2s.  c o m
    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 saveCurrentState(final Main main) {

    VerticalLayout content = new VerticalLayout();
    content.setSizeFull();// w  ww . ja v  a2  s  .  c om

    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 print(final Main main) {

    VerticalLayout content = new VerticalLayout();

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);//from   w w  w  .java2 s  .  c  om

    final Button ok = new Button("Lataa");
    ok.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 5350320436995864012L;

        @Override
        public void buttonClick(ClickEvent event) {
            ok.setEnabled(false);
        }

    });
    buttons.addComponent(ok);

    final String svgText = main.pdf.svg;

    final OnDemandFileDownloader dl = new OnDemandFileDownloader(new OnDemandStreamSource() {

        private static final long serialVersionUID = -3866190768030858133L;
        File temp;
        Date date = new Date();

        @Override
        public InputStream getStream() {

            String uuid = UUID.randomUUID().toString();

            File printing = new File(Main.baseDirectory(), "printing");

            temp = new File(printing, uuid + ".pdf");

            if (svgText != null) {

                File htmlFile = new File(printing, uuid + ".html");
                File script = new File(printing, uuid + ".js");

                try {

                    String html = PhantomJSDriver.printHtml(svgText,
                            Main.getAppFile("print.html").getParentFile().getAbsolutePath());
                    Files.write(htmlFile.toPath(), html.getBytes(Charset.forName("UTF-8")));

                    String browserUrl = htmlFile.toURI().toURL().toString();

                    String printCommand = PhantomJSDriver.printCommand(browserUrl, temp.getAbsolutePath());

                    Files.write(script.toPath(), printCommand.getBytes());

                    PhantomJSDriver.execute(script);

                    return new FileInputStream(temp);

                } catch (IOException e) {
                    e.printStackTrace();
                }

            }

            throw new IllegalStateException();

        }

        @Override
        public void onRequest() {
        }

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

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

    });

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

    final Window dialog = Dialogs.makeDialog(main, "420px", "135px", "Haluatko ladata kartan PDF-muodossa?",
            "Sulje", content, buttons);

}

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

License:Open Source License

public static Button tagButton(final Database database, String prefix, String tag, final int index) {

    Tag t = database.getOrCreateTag(tag);

    Styles styles = Page.getCurrent().getStyles();

    styles.add(".fi_semantum_strategia div.v-button." + prefix + "tag" + index
            + " { opacity: 1.0; box-shadow:none; color: #000000; background-image: linear-gradient(" + t.color
            + " 0%, " + t.color + " 100%); }");

    Button tagButton = new Button();
    tagButton.setEnabled(false);
    tagButton.setCaption(tag);/* ww w  .j a v  a  2s.  co m*/
    tagButton.addStyleName(prefix + "tag" + index);

    return tagButton;

}

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();/*from w  w  w . ja  v a 2 s .  c  o  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.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   w  ww .j  a  v a 2  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.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 a2s  .  c  o  m

        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;/*w  w  w .j  av a2 s .  c om*/

    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);

        }

    }

}