Example usage for com.vaadin.ui Label setValue

List of usage examples for com.vaadin.ui Label setValue

Introduction

In this page you can find the example usage for com.vaadin.ui Label setValue.

Prototype

public void setValue(String value) 

Source Link

Document

Sets the text to be shown in the label.

Usage

From source file:eu.maxschuster.vaadin.signaturefield.demo.DemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    getPage().setTitle(pageTitle);//from w  w w  .  j  a  v a  2  s  . c  o m

    final VerticalLayout margin = new VerticalLayout();
    setContent(margin);

    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setWidth("658px");
    margin.addComponent(layout);
    margin.setComponentAlignment(layout, Alignment.TOP_CENTER);

    final Label header1 = new Label(pageTitle);
    header1.addStyleName("h1");
    header1.setSizeUndefined();
    layout.addComponent(header1);
    layout.setComponentAlignment(header1, Alignment.TOP_CENTER);

    final TabSheet tabSheet = new TabSheet();
    tabSheet.setWidth("100%");
    layout.addComponent(tabSheet);
    layout.setComponentAlignment(tabSheet, Alignment.TOP_CENTER);

    final Panel signaturePanel = new Panel();
    signaturePanel.addStyleName("signature-panel");
    signaturePanel.setWidth("100%");
    tabSheet.addTab(signaturePanel, "Demo");

    final VerticalLayout signatureLayout = new VerticalLayout();
    signatureLayout.setMargin(true);
    signatureLayout.setSpacing(true);
    signatureLayout.setSizeFull();
    signaturePanel.setContent(signatureLayout);

    final SignatureField signatureField = new SignatureField();
    signatureField.setWidth("100%");
    signatureField.setHeight("318px");
    signatureField.setPenColor(Color.ULTRAMARINE);
    signatureField.setBackgroundColor("white");
    signatureField.setConverter(new StringToDataUrlConverter());
    signatureField.setPropertyDataSource(dataUrlProperty);
    signatureField.setVelocityFilterWeight(0.7);
    signatureLayout.addComponent(signatureField);
    signatureLayout.setComponentAlignment(signatureField, Alignment.MIDDLE_CENTER);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");
    signatureLayout.addComponent(buttonLayout);

    final Button clearButton = new Button("Clear", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            signatureField.clear();
        }
    });
    buttonLayout.addComponent(clearButton);
    buttonLayout.setComponentAlignment(clearButton, Alignment.MIDDLE_LEFT);

    final Label message = new Label("Sign above");
    message.setSizeUndefined();
    buttonLayout.addComponent(message);
    buttonLayout.setComponentAlignment(message, Alignment.MIDDLE_CENTER);

    final ButtonLink saveButtonLink = new ButtonLink("Save", null);
    saveButtonLink.setTargetName("_blank");
    buttonLayout.addComponent(saveButtonLink);
    buttonLayout.setComponentAlignment(saveButtonLink, Alignment.MIDDLE_RIGHT);

    final Panel optionsPanel = new Panel();
    optionsPanel.setSizeFull();
    tabSheet.addTab(optionsPanel, "Options");

    final FormLayout optionsLayout = new FormLayout();
    optionsLayout.setMargin(true);
    optionsLayout.setSpacing(true);
    optionsPanel.setContent(optionsLayout);

    final ComboBox mimeTypeComboBox = new ComboBox(null, mimeTypeContainer);
    optionsLayout.addComponent(mimeTypeComboBox);
    mimeTypeComboBox.setItemCaptionPropertyId("mimeType");
    mimeTypeComboBox.setNullSelectionAllowed(false);
    mimeTypeComboBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            MimeType mimeType = (MimeType) event.getProperty().getValue();
            signatureField.setMimeType(mimeType);
        }
    });
    mimeTypeComboBox.setValue(MimeType.PNG);
    mimeTypeComboBox.setCaption("Result MIME-Type");

    final CheckBox immediateCheckBox = new CheckBox("immediate", false);
    optionsLayout.addComponent(immediateCheckBox);
    immediateCheckBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean immediate = (Boolean) event.getProperty().getValue();
            signatureField.setImmediate(immediate);
        }
    });

    final CheckBox readOnlyCheckBox = new CheckBox("readOnly", false);
    optionsLayout.addComponent(readOnlyCheckBox);
    readOnlyCheckBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean readOnly = (Boolean) event.getProperty().getValue();
            signatureField.setReadOnly(readOnly);
            mimeTypeComboBox.setReadOnly(readOnly);
            clearButton.setEnabled(!readOnly);
        }
    });

    final CheckBox requiredCheckBox = new CheckBox("required (causes bug that clears field)", false);
    optionsLayout.addComponent(requiredCheckBox);
    requiredCheckBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean required = (Boolean) event.getProperty().getValue();
            signatureField.setRequired(required);
        }
    });

    final CheckBox clearButtonEnabledButton = new CheckBox("clearButtonEnabled", false);
    optionsLayout.addComponent(clearButtonEnabledButton);
    clearButtonEnabledButton.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean clearButtonEnabled = (Boolean) event.getProperty().getValue();
            signatureField.setClearButtonEnabled(clearButtonEnabled);
        }
    });

    final Panel resultPanel = new Panel("Results:");
    resultPanel.setWidth("100%");
    layout.addComponent(resultPanel);

    final VerticalLayout resultLayout = new VerticalLayout();
    resultLayout.setMargin(true);
    resultPanel.setContent(resultLayout);

    final Image stringPreviewImage = new Image("String preview image:");
    stringPreviewImage.setWidth("500px");
    resultLayout.addComponent(stringPreviewImage);

    final Image dataUrlPreviewImage = new Image("DataURL preview image:");
    dataUrlPreviewImage.setWidth("500px");
    resultLayout.addComponent(dataUrlPreviewImage);

    final TextArea textArea = new TextArea("DataURL:");
    textArea.setWidth("100%");
    textArea.setHeight("300px");
    resultLayout.addComponent(textArea);

    final Label emptyLabel = new Label();
    emptyLabel.setCaption("Is Empty:");
    emptyLabel.setValue(String.valueOf(signatureField.isEmpty()));
    resultLayout.addComponent(emptyLabel);

    signatureField.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            String signature = (String) event.getProperty().getValue();
            stringPreviewImage.setSource(signature != null ? new ExternalResource(signature) : null);
            textArea.setValue(signature);
            emptyLabel.setValue(String.valueOf(signatureField.isEmpty()));
        }
    });
    dataUrlProperty.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            try {
                final DataUrl signature = (DataUrl) event.getProperty().getValue();
                dataUrlPreviewImage.setSource(
                        signature != null ? new ExternalResource(serializer.serialize(signature)) : null);
                StreamResource streamResource = null;
                if (signature != null) {
                    StreamSource streamSource = new StreamSource() {

                        @Override
                        public InputStream getStream() {
                            return new ByteArrayInputStream(signature.getData());
                        }
                    };
                    MimeType mimeType = MimeType.valueOfMimeType(signature.getMimeType());
                    String extension = null;

                    switch (mimeType) {
                    case JPEG:
                        extension = "jpg";
                        break;
                    case PNG:
                        extension = "png";
                        break;
                    }

                    streamResource = new StreamResource(streamSource, "signature." + extension);
                    streamResource.setMIMEType(signature.getMimeType());
                    streamResource.setCacheTime(0);
                }
                saveButtonLink.setResource(streamResource);
            } catch (MalformedURLException e) {
                logger.error(e.getMessage(), e);
            }
        }
    });
}

From source file:facs.components.BookAdmin.java

License:Open Source License

public BookAdmin(User user) {

    Date dNow = new Date();
    SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss");
    System.out.println(ft.format(dNow) + "  INFO  Calendar Admin accessed! - User: "
            + LiferayAndVaadinUtils.getUser().getScreenName());

    Label infoLabel = new Label(
            DBManager.getDatabaseInstance().getUserNameByUserID(LiferayAndVaadinUtils.getUser().getScreenName())
                    + "  " + LiferayAndVaadinUtils.getUser().getScreenName());
    infoLabel.addStyleName("h4");

    String buttonRefreshTitle = "Refresh";
    Button refresh = new Button(buttonRefreshTitle);
    refresh.setIcon(FontAwesome.REFRESH);
    refresh.setSizeFull();/*  w  w w.j av  a  2  s. c  o m*/
    refresh.setDescription("Click here to reload the data from the database!");
    refresh.addStyleName(ValoTheme.BUTTON_FRIENDLY);

    String buttonUpdateTitle = "Update";
    Button updateUser = new Button(buttonUpdateTitle);
    updateUser.setIcon(FontAwesome.WRENCH);
    updateUser.setSizeFull();
    updateUser.setDescription("Click here to update your user role and group!");

    userDevice = new ListSelect("Select a device");
    userDevice.addItems(DBManager.getDatabaseInstance().getDeviceNames());
    userDevice.setRows(6);
    userDevice.setNullSelectionAllowed(false);
    userDevice.setSizeFull();
    userDevice.setImmediate(true);
    /*
     * userDevice.addValueChangeListener(e -> Notification.show("Device:",
     * String.valueOf(e.getProperty().getValue()), Type.TRAY_NOTIFICATION));
     */
    userGroup = new ListSelect("Select a user group");
    userGroup.addItems(DBManager.getDatabaseInstance().getUserGroups());
    userGroup.setRows(6);
    userGroup.setNullSelectionAllowed(false);
    userGroup.setSizeFull();
    userGroup.setImmediate(true);
    /*
     * userGroup.addValueChangeListener(e -> Notification.show("User Group:",
     * String.valueOf(e.getProperty().getValue()), Type.TRAY_NOTIFICATION));
     */
    userRole = new ListSelect("Select a user role");
    userRole.addItems(DBManager.getDatabaseInstance().getUserRoles());
    userRole.setRows(6);
    userRole.setNullSelectionAllowed(false);
    userRole.setSizeFull();
    userRole.setImmediate(true);
    /*
     * userRole.addValueChangeListener(e -> Notification.show("User Role:",
     * String.valueOf(e.getProperty().getValue()), Type.TRAY_NOTIFICATION));
     */
    refresh.addClickListener(new ClickListener() {
        private static final long serialVersionUID = -3610721151565496269L;

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

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

        @Override
        public void buttonClick(ClickEvent event) {
            try {
                if (userDevice.getValue().equals(null) || userRole.getValue().equals(null)
                        || userGroup.getValue().equals(null)) {
                    showErrorNotification("Something's missing!",
                            "Please make sure that you selected a Device, a Role and a Group! Each list has to have one highligthed option.'.");
                    // System.out.println("Device: "+userDevice.getValue()+" Group: "+userGroup.getValue()+" Role: "+userRole.getValue());
                } else {
                    DBManager.getDatabaseInstance().getShitDone(
                            DBManager.getDatabaseInstance().getUserRoleIDbyDesc(userRole.getValue().toString()),
                            DBManager.getDatabaseInstance()
                                    .getUserIDbyLDAPID(LiferayAndVaadinUtils.getUser().getScreenName()),
                            DBManager.getDatabaseInstance()
                                    .getDeviceIDByName(userDevice.getValue().toString()));

                    DBManager.getDatabaseInstance().getShitDoneAgain(
                            DBManager.getDatabaseInstance()
                                    .getUserGroupIDByName(userGroup.getValue().toString()),
                            LiferayAndVaadinUtils.getUser().getScreenName());

                }
            } catch (Exception e) {
                showErrorNotification("Something's missing!",
                        "Please make sure that you selected a Device, a Role and a Group! Each list has to have one highligthed option.'.");
            }
            refreshDataSources();
        }
    });

    // only admins are allowed to see the admin panel ;)
    if (!DBManager.getDatabaseInstance()
            .getUserAdminPanelAccessByLDAPId(LiferayAndVaadinUtils.getUser().getScreenName()).equals("1")) {
        VerticalLayout errorLayout = new VerticalLayout();
        infoLabel.setValue("ACCESS DENIED");
        errorLayout.addComponent(infoLabel);
        showErrorNotification("Access Denied!",
                "Sorry, you're not allowed to see anything here, at least your username told us so. Do you need assistance? Please contact 'info@qbic.uni-tuebingen.de'.");
        setCompositionRoot(errorLayout);
        return;
    }

    this.setCaption("Admin");

    final TabSheet bookAdmin = new TabSheet();
    bookAdmin.addStyleName(ValoTheme.TABSHEET_FRAMED);
    bookAdmin.addStyleName(ValoTheme.TABSHEET_EQUAL_WIDTH_TABS);

    ArrayList<String> deviceNames = new ArrayList<String>();
    deviceNames = DBManager.getDatabaseInstance().getDeviceNames();

    bookAdmin.addTab(awaitingRequestsGrid());

    for (int i = 0; i < deviceNames.size(); i++) {
        bookAdmin.addTab(newDeviceGrid(deviceNames.get(i)));
    }

    bookAdmin.addTab(deletedBookingsGrid());

    bookAdmin.addSelectedTabChangeListener(new SelectedTabChangeListener() {

        /**
         * 
         */
        private static final long serialVersionUID = 8987818794404251063L;

        @Override
        public void selectedTabChange(SelectedTabChangeEvent event) {
            userDevice.select(bookAdmin.getSelectedTab().getCaption());
            userRole.select(DBManager.getDatabaseInstance()
                    .getUserGroupDescriptionByLDAPId(LiferayAndVaadinUtils.getUser().getScreenName(), DBManager
                            .getDatabaseInstance().getDeviceIDByName(bookAdmin.getSelectedTab().getCaption())));
            userGroup.select(DBManager.getDatabaseInstance()
                    .getUserRoleNameByLDAPId(LiferayAndVaadinUtils.getUser().getScreenName()));

        }
    });

    gridLayout.setWidth("100%");

    // add components to the grid layout
    // gridLayout.addComponent(infoLabel, 0, 0, 3, 0);
    gridLayout.addComponent(bookAdmin, 0, 1, 5, 1);
    gridLayout.addComponent(refresh, 0, 2);
    gridLayout.addComponent(userDevice, 0, 4, 1, 4);
    gridLayout.addComponent(userRole, 2, 4, 3, 4);
    gridLayout.addComponent(userGroup, 4, 4, 5, 4);
    gridLayout.addComponent(updateUser, 0, 5, 5, 5);
    gridLayout.setSizeFull();

    gridLayout.setSpacing(true);
    setCompositionRoot(gridLayout);

    /*
     * JavaScript to update the Grid try { JDBCConnectionPool connectionPool = new
     * SimpleJDBCConnectionPool("com.mysql.jdbc.Driver",
     * "jdbc:mysql://localhost:8889/facs_facility", "facs", "facs"); QueryDelegate qd = new
     * FreeformQuery("select * from facs_facility", connectionPool, "id"); final SQLContainer c =
     * new SQLContainer(qd); bookAdmin.setContainerDataSource(c); }
     * 
     * JavaScript.getCurrent().execute("setInterval(function(){refreshTable();},5000);");
     * JavaScript.getCurrent().addFunction("refreshTable", new JavaScriptFunction() {
     * 
     * @Override public void call(JsonArray arguments) { // TODO Auto-generated method stub
     * 
     * } });
     */

}

From source file:facs.components.Booking.java

License:Open Source License

public Booking(final BookingModel bookingModel, Date referenceDate) {

    String[] sayHello = { "Kon'nichiwa", "Hello", "Halo", "Hiya", "Hej", "Hallo", "Hola", "Grezi", "Servus",
            "Merhaba", "Bonjour", "Ahoj", "Moi", "Ciao", "Buongiorno" };

    this.bookingModel = bookingModel;
    this.referenceDate = referenceDate;

    Label infoLabel = new Label();
    infoLabel.addStyleName("h4");

    Label selectDeviceLabel = new Label();
    selectDeviceLabel.addStyleName("h4");
    selectDeviceLabel.setValue("Please Select a Device");

    final Label versionLabel = new Label();
    versionLabel.addStyleName("h4");
    versionLabel.setValue("Version 0.1.160727");

    // showSuccessfulNotification(sayHello[(int) (Math.random() * sayHello.length)] + ", "
    // + bookingModel.userName() + "!", "");

    Date dNow = new Date();
    SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss");
    System.out.println(ft.format(dNow) + "  INFO  Calendar initiated! - User: " + bookingModel.getLDAP() + " "
            + versionLabel);/*from  w  ww  .  ja  v  a2 s  .  c om*/

    // only users who are allowed to book devices will be able to do so
    if (bookingModel.isNotAllowed()) {
        VerticalLayout errorLayout = new VerticalLayout();
        infoLabel.setValue("ACCESS DENIED");
        errorLayout.addComponent(infoLabel);
        showErrorNotification("Access Denied!",
                "Sorry, you're not allowed to see anything here, at least your username told us so. Do you need assistance? Please contact 'info@qbic.uni-tuebingen.de'.");
        setCompositionRoot(errorLayout);
        return;
    }

    Panel book = new Panel();
    book.addStyleName(ValoTheme.PANEL_BORDERLESS);

    DBManager.getDatabaseInstance();
    db = Database.Instance;
    db.userLogin(bookingModel.getLDAP());
    selectedDevice = initCalendars(bookingModel.getDevicesNames());

    selectedService = new NativeSelect("Please select a service:");
    selectedService.setDescription("Please select the service you would like to receive!");

    selectedKostenstelle = new NativeSelect("Please select konstenstelle:");
    selectedKostenstelle.setDescription("Please select the Kostenstelle you would like to use!");

    selectedDevice.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 8153818693511960689L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            versionLabel.setValue(db.getUserRoleDescByLDAPId(bookingModel.getLDAP(), getCurrentDevice()));

            selectedKostenstelle.setVisible(true);

            if (bookMap.containsKey(getCurrentDevice())) {
                cal.removeAllComponents();
                setCalendar();

                if (selectedDevice.getValue().equals("Aria")) {
                    selectedService.removeAllItems();
                    selectedService.addItems("Full Service", "Partial Service", "Self Service");
                    selectedService.setValue("Full Service");
                    selectedService.setVisible(true);
                } else if (selectedDevice.getValue().equals("Mac")) {
                    selectedService.removeAllItems();
                    selectedService.addItems("Self", "Service");
                    selectedService.setValue("Service");
                    selectedService.setVisible(true);
                } else {
                    selectedService.setValue(null);
                    selectedService.setVisible(false);
                }

            } else {

                bookMap.put(getCurrentDevice(), initCal(bookingModel, getCurrentDevice()));
                cal.removeAllComponents();
                setCalendar();

                if (selectedDevice.getValue().equals("Aria")) {
                    selectedService.removeAllItems();
                    selectedService.addItems("Full Service", "Partial Service", "Self Service");
                    selectedService.setValue("Full Service");
                    selectedService.setVisible(true);
                } else if (selectedDevice.getValue().equals("Mac")) {
                    selectedService.removeAllItems();
                    selectedService.addItems("Self", "Service");
                    selectedService.setValue("Service");
                    selectedService.setVisible(true);
                } else {
                    selectedService.setValue(null);
                    selectedService.setVisible(false);
                }
            }
        }
    });

    if (bookingModel.getProject().isEmpty()) {
        infoLabel.setValue(bookingModel.userName() + "  Kostenstelle: " + bookingModel.getKostenstelle()
                + "  Institute: " + bookingModel.getInstitute());

    } else {
        infoLabel.setValue(bookingModel.userName() + "  Kostenstelle: " + bookingModel.getKostenstelle()
                + "  Project: " + bookingModel.getProject() + "  Institute: "
                + bookingModel.getInstitute());
    }

    // bookDeviceLayout.addComponent(infoLabel);
    cal.setLocale(Locale.getDefault());
    cal.setImmediate(true);
    selectedService.setImmediate(true);
    cal.setSizeFull();

    String submitTitle = "Book";
    Button submit = new Button(submitTitle);
    submit.setIcon(FontAwesome.CALENDAR);
    submit.setDescription("Please select a device and a time frame at first then click 'BOOK'!");
    submit.setSizeFull();

    // submit.setVisible(false);

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

        @Override
        public void buttonClick(ClickEvent event) {
            submit(bookingModel.getLDAP(), getCurrentDevice());
            newEvents.clear();
            refreshDataSources();
        }
    });

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

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

        @Override
        public void buttonClick(ClickEvent event) {

            refreshDataSources();

        }
    });

    gridLayout.setWidth("100%");
    // add components to the grid layout
    gridLayout.addComponent(infoLabel, 0, 4, 3, 4);
    gridLayout.addComponent(versionLabel, 4, 4, 5, 4);

    // gridLayout.addComponent(selectDeviceLabel,0,1);
    gridLayout.addComponent(selectedDevice, 0, 0);
    gridLayout.addComponent(selectedService, 1, 0);
    gridLayout.addComponent(selectedKostenstelle, 2, 0);
    selectedService.setVisible(false);

    gridLayout.addComponent(cal, 0, 2, 5, 2);

    gridLayout.addComponent(refresh, 0, 3);
    gridLayout.addComponent(submit, 1, 3, 5, 3);

    // gridLayout.addComponent(myBookings(), 0, 5, 5, 5);

    gridLayout.setMargin(true);
    gridLayout.setSpacing(true);
    gridLayout.setSizeFull();

    book.setContent(gridLayout);

    booking = new TabSheet();

    booking.addStyleName(ValoTheme.TABSHEET_FRAMED);
    booking.addTab(book).setCaption("Calendar");
    booking.addTab(myNext24HoursBookings()).setCaption("Next 24 Hours");
    booking.addTab(myUpcomingBookings()).setCaption("Upcoming");
    booking.addTab(myPastBookings()).setCaption("Past Bookings");
    // booking.addTab(myUpcomingBookingsSQLContainer()).setCaption("Test");
    setCompositionRoot(booking);

}

From source file:facs.ui.BookAdminUI.java

License:Open Source License

private Component errorView() {
    Label label = new Label();
    label.addStyleName(ValoTheme.LABEL_FAILURE);
    label.setIcon(FontAwesome.FROWN_O);//from ww w  .  ja  v  a  2s.  co m
    label.setValue(
            "Initialization has failed! Are you logged out? Please try to login! If the problem continues please contact info@qbic.uni-tuebingen.de");
    return label;
}

From source file:fi.racetrace.adminpanel.ui.columngenerator.TrailLengthGC.java

License:Open Source License

@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
    Component c = null;// w w w.j a  v a  2 s .c  o m

    if (source.isEditable() && itemId.equals(source.getValue())) {

        VerticalLayout vl = new VerticalLayout();
        c = vl;
        final SessionDevice sessionDevice = (SessionDevice) itemId;

        Slider slider = new Slider(0, 60 * 20);
        vl.addComponent(slider);

        final Label label = new Label(formatSeconds(sessionDevice.getTrailLength()));
        vl.addComponent(label);

        slider.setPropertyDataSource(new BeanItem<SessionDevice>(sessionDevice).getItemProperty("trailLength"));
        slider.setWidth(100, Unit.PERCENTAGE);
        slider.addValueChangeListener(new ValueChangeListener() {

            @Override
            public void valueChange(ValueChangeEvent event) {
                Double length = Double.parseDouble(event.getProperty().getValue().toString());
                label.setValue(formatSeconds(length));
                // sessionDevice.setTrailLength(length);
            }
        });
    } else {
        Label l = new Label(formatSeconds(((SessionDevice) itemId).getTrailLength()));
        c = l;
    }
    return c;
}

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

License:Open Source License

public static void modifyAccount(final Main main) {

    final Database database = main.getDatabase();

    FormLayout content = new FormLayout();
    content.setSizeFull();/*from   w ww . ja  v a  2 s.c  om*/

    final Label l = new Label(main.account.getId(database));
    l.setCaption("Kyttjn nimi:");
    l.setWidth("100%");
    content.addComponent(l);

    final TextField tf = new TextField();
    tf.setWidth("100%");
    tf.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    tf.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS);
    tf.setCaption("Kyttjn nimi:");
    tf.setId("loginUsernameField");
    tf.setValue(main.account.getText(database));
    content.addComponent(tf);

    final TextField tf2 = new TextField();
    tf2.setWidth("100%");
    tf2.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    tf2.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS);
    tf2.setCaption("Shkpostiosoite:");
    tf2.setId("loginUsernameField");
    tf2.setValue(main.account.getEmail());
    content.addComponent(tf2);

    final PasswordField pf = new PasswordField();
    pf.setCaption("Vanha salasana:");
    pf.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    pf.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS);
    pf.setWidth("100%");
    pf.setId("loginPasswordField");
    content.addComponent(pf);

    final PasswordField pf2 = new PasswordField();
    pf2.setCaption("Uusi salasana:");
    pf2.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    pf2.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS);
    pf2.setWidth("100%");
    pf2.setId("loginPasswordField");
    content.addComponent(pf2);

    final PasswordField pf3 = new PasswordField();
    pf3.setCaption("Uusi salasana uudestaan:");
    pf3.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    pf3.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS);
    pf3.setWidth("100%");
    pf3.setId("loginPasswordField");
    content.addComponent(pf3);

    final Label err = new Label("Vr kyttjtunnus tai salasana");
    err.addStyleName(ValoTheme.LABEL_FAILURE);
    err.addStyleName(ValoTheme.LABEL_TINY);
    err.setVisible(false);
    content.addComponent(err);

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

    Button apply = new Button("Tee muutokset");

    buttons.addComponent(apply);

    final Window dialog = Dialogs.makeDialog(main, "450px", "480px", "Kyttjtilin asetukset", "Poistu",
            content, buttons);
    apply.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = 1992235622970234624L;

        public void buttonClick(ClickEvent event) {

            String valueHash = Utils.hash(pf.getValue());
            if (!valueHash.equals(main.account.getHash())) {
                err.setValue("Vr salasana");
                err.setVisible(true);
                return;
            }

            if (pf2.isEmpty()) {
                err.setValue("Tyhj salasana ei kelpaa");
                err.setVisible(true);
                return;
            }

            if (!pf2.getValue().equals(pf3.getValue())) {
                err.setValue("Uudet salasanat eivt tsm");
                err.setVisible(true);
                return;
            }

            main.account.text = tf.getValue();
            main.account.email = tf2.getValue();
            main.account.hash = Utils.hash(pf2.getValue());

            Updates.update(main, true);

            main.removeWindow(dialog);

        }

    });

}

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 www .  j  av 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.widget.Indicator.java

License:Open Source License

public static Label makeHistory(Database database, Indicator indicator, boolean forecast) {

    Label ta2 = new Label("Historia");
    ta2.setContentMode(ContentMode.HTML);
    ta2.setWidth("100%");
    ta2.setHeight("100%");

    StringBuilder sb = new StringBuilder();
    sb.append("<b>Historia</b><br><br>");

    for (Map.Entry<Date, TimeSeriesEntry> entry : indicator.values.list()) {
        TimeSeriesEntry tse = entry.getValue();
        Account account = tse.getAccount();
        Date date = entry.getKey();
        String user = account != null ? account.getId(database) : "Jrjestelm";
        sb.append("<b>");
        sb.append(user);/*from  w  w w. ja v  a 2  s. c o  m*/
        sb.append("</b> pivitti ");
        sb.append(forecast ? " ennustetta" : " toteumaa");
        sb.append(" <b>");
        sb.append(Utils.describeDate(date));
        sb.append("</b><br><hr>");
        sb.append("&nbsp;Uusi arvo on <b>");
        sb.append(forecast ? tse.getForecast() : tse.getValue() + " " + indicator.getUnitAndComment());
        sb.append("</b><br>");
        String comment = tse.getComment();
        if (comment != null)
            sb.append("<p>" + tse.getComment() + "</p>");
        sb.append("<br>");
    }

    ta2.setValue(sb.toString());
    return ta2;

}

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

License:Open Source License

@Override
public Runnable getEditor(VerticalLayout layout, final Main main, final Meter meter) {

    Indicator indicator = meter.getPossibleIndicator(main.getDatabase());
    String unit = indicator.getUnit();

    final ComboBox combo = new ComboBox("Valitse mittarin mritystapa");
    combo.addItem(State.INCREASE3);
    combo.addItem(State.DECREASE3);
    combo.addItem(State.INCREASE2);
    combo.addItem(State.DECREASE2);
    combo.setInvalidAllowed(false);/*from  w w w.j a  v  a  2s .co  m*/
    combo.setNullSelectionAllowed(false);
    combo.setWidth("100%");
    combo.addStyleName(ValoTheme.COMBOBOX_TINY);
    layout.addComponent(combo);
    layout.setComponentAlignment(combo, Alignment.TOP_CENTER);
    layout.setExpandRatio(combo, 0.0f);

    final VerticalLayout vl1 = new VerticalLayout();
    vl1.setHeight("50px");
    vl1.setWidth("100%");
    vl1.setStyleName("redBlock");
    layout.addComponent(vl1);
    layout.setComponentAlignment(vl1, Alignment.TOP_CENTER);
    layout.setExpandRatio(vl1, 0.0f);
    final Label l1 = new Label(" > " + df.format(greenLimit.doubleValue()) + " " + unit);
    l1.setSizeUndefined();
    l1.addStyleName(ValoTheme.LABEL_LARGE);
    vl1.addComponent(l1);
    vl1.setComponentAlignment(l1, Alignment.MIDDLE_CENTER);

    HorizontalLayout hl1 = new HorizontalLayout();
    hl1.setSpacing(true);
    layout.addComponent(hl1);
    layout.setComponentAlignment(hl1, Alignment.TOP_LEFT);

    final TextField tf1 = new TextField();
    tf1.setValue(df.format(greenLimit.doubleValue()));
    tf1.setWidth("150px");
    tf1.setCaption("Suurempi raja-arvo");
    tf1.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tf1.setValidationVisible(true);
    hl1.addComponent(tf1);

    Label unit1 = new Label();
    unit1.setSizeUndefined();
    unit1.setCaption("");
    unit1.setValue(unit);
    hl1.addComponent(unit1);
    hl1.setComponentAlignment(unit1, Alignment.MIDDLE_LEFT);

    final VerticalLayout vl2 = new VerticalLayout();
    vl2.setHeight("50px");
    vl2.setWidth("100%");
    vl2.addStyleName("yellowBlock");
    layout.addComponent(vl2);
    layout.setComponentAlignment(vl2, Alignment.TOP_CENTER);
    layout.setExpandRatio(vl2, 0.0f);
    final Label l2 = new Label();
    l2.setSizeUndefined();
    l2.addStyleName(ValoTheme.LABEL_LARGE);
    vl2.addComponent(l2);
    vl2.setComponentAlignment(l2, Alignment.MIDDLE_CENTER);

    HorizontalLayout hl2 = new HorizontalLayout();
    hl2.setSpacing(true);
    layout.addComponent(hl2);
    layout.setComponentAlignment(hl2, Alignment.TOP_LEFT);

    final TextField tf2 = new TextField();
    tf2.setWidth("150px");
    tf2.setCaption("Pienempi raja-arvo");
    tf2.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tf2.setValidationVisible(true);
    hl2.addComponent(tf2);
    hl2.setComponentAlignment(tf2, Alignment.TOP_CENTER);

    Label unit2 = new Label();
    unit2.setSizeUndefined();
    unit2.setCaption("");
    unit2.setValue("" + unit);
    hl2.addComponent(unit2);
    hl2.setComponentAlignment(unit2, Alignment.MIDDLE_LEFT);

    final VerticalLayout vl3 = new VerticalLayout();
    vl3.setHeight("50px");
    vl3.setWidth("100%");
    vl3.addStyleName("greenBlock");
    layout.addComponent(vl3);
    layout.setComponentAlignment(vl3, Alignment.TOP_CENTER);
    layout.setExpandRatio(vl3, 0.0f);
    final Label l3 = new Label();
    l3.setSizeUndefined();
    l3.addStyleName(ValoTheme.LABEL_LARGE);
    vl3.addComponent(l3);
    vl3.setComponentAlignment(l3, Alignment.MIDDLE_CENTER);

    applyValues(main, meter, combo, vl1, l1, vl2, l2, vl3, l3, tf1, tf2);

    combo.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 8396168732300003038L;

        @Override
        public void valueChange(ValueChangeEvent event) {

            if (inApply)
                return;

            State currentState = getState();

            if (currentState.equals(combo.getValue()))
                return;

            if (State.DECREASE3.equals(combo.getValue())) {
                makeThree = true;
                if (State.INCREASE3.equals(currentState)) {
                    swap();
                } else if (State.INCREASE2.equals(currentState)) {
                    redLimit = greenLimit;
                    greenLimit = null;
                }
            } else if (State.INCREASE3.equals(combo.getValue())) {
                makeThree = true;
                if (State.DECREASE3.equals(currentState)) {
                    swap();
                } else if (State.DECREASE2.equals(currentState)) {
                    greenLimit = redLimit;
                    redLimit = null;
                }
            } else if (State.INCREASE2.equals(combo.getValue())) {
                if (State.DECREASE3.equals(currentState)) {
                    greenLimit = redLimit;
                } else if (State.DECREASE2.equals(currentState)) {
                    greenLimit = redLimit;
                }
                redLimit = null;
                makeThree = false;
            } else if (State.DECREASE2.equals(combo.getValue())) {
                if (State.INCREASE3.equals(currentState)) {
                    redLimit = greenLimit;
                } else if (State.INCREASE2.equals(currentState)) {
                    redLimit = greenLimit;
                }
                greenLimit = null;
                makeThree = false;
            }

            updateMakeThree();

            applyValues(main, meter, combo, vl1, l1, vl2, l2, vl3, l3, tf1, tf2);

        }

    });

    tf1.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = -5484608577999300097L;

        @Override
        public void valueChange(ValueChangeEvent event) {

            if (inApply)
                return;

            if (State.DECREASE3.equals(combo.getValue())) {
                if (makeThree)
                    greenLimit = redLimit;
                redLimit = new BigDecimal(tf1.getValue());
            } else if (State.INCREASE3.equals(combo.getValue())) {
                if (makeThree)
                    redLimit = greenLimit;
                greenLimit = new BigDecimal(tf1.getValue());
            } else if (State.INCREASE2.equals(combo.getValue())) {
                greenLimit = new BigDecimal(tf1.getValue());
            } else if (State.DECREASE2.equals(combo.getValue())) {
                redLimit = new BigDecimal(tf1.getValue());
            }

            updateMakeThree();

            applyValues(main, meter, combo, vl1, l1, vl2, l2, vl3, l3, tf1, tf2);

        }

    });

    tf2.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 5825320869230527588L;

        @Override
        public void valueChange(ValueChangeEvent event) {

            if (inApply)
                return;

            // This should not happen!
            if (State.INCREASE2.equals(combo.getValue()) || State.DECREASE2.equals(combo.getValue()))
                return;

            if (State.DECREASE3.equals(combo.getValue())) {
                greenLimit = new BigDecimal(tf2.getValue());
            } else if (State.INCREASE3.equals(combo.getValue())) {
                redLimit = new BigDecimal(tf2.getValue());
            }

            updateMakeThree();

            applyValues(main, meter, combo, vl1, l1, vl2, l2, vl3, l3, tf1, tf2);

        }

    });

    return null;

}

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

License:Open Source License

private void applyValues(Main main, Meter meter, ComboBox combo, VerticalLayout vl1, Label l1,
        VerticalLayout vl2, Label l2, VerticalLayout vl3, Label l3, TextField tf1, TextField tf2) {

    inApply = true;//from w  ww . j  a v a  2s . c om

    Indicator indicator = meter.getPossibleIndicator(main.getDatabase());
    String unit = indicator.getUnit();

    combo.select(getState());

    final double highDouble = getHighLimit().doubleValue();
    final double lowDouble = getLowLimit().doubleValue();

    String highLimit = df.format(highDouble);
    String lowLimit = df.format(lowDouble);

    tf1.setValue(highLimit);
    l1.setValue(highLimit + " < arvo " + unit);

    if (isIncrease()) {
        vl1.setStyleName("greenBlock");
    } else {
        vl1.setStyleName("redBlock");
    }

    tf1.removeAllValidators();
    tf1.addValidator(new Validator() {

        private static final long serialVersionUID = 5929569929930454714L;

        @Override
        public void validate(Object value) throws InvalidValueException {
            try {
                double d = Double.parseDouble((String) value);
                if (d < lowDouble)
                    throw new InvalidValueException("Value is too small");
            } catch (NumberFormatException e) {
                throw new InvalidValueException(e.getMessage());
            }
        }

    });

    if (isTwo()) {

        l3.setVisible(false);
        vl3.setVisible(false);
        tf2.setVisible(false);
        tf1.setCaption("Raja-arvo");

        if (isIncrease()) {
            vl2.setStyleName("redBlock");
        } else {
            vl2.setStyleName("greenBlock");
        }

        l2.setValue("arvo < " + lowLimit + " " + unit);

    } else {

        vl3.setVisible(true);
        l3.setVisible(true);
        tf2.setVisible(true);
        tf1.setCaption("Suurempi raja-arvo");
        tf2.setCaption("Pienempi raja-arvo");
        vl2.setStyleName("yellowBlock");

        l2.setValue(lowLimit + " < arvo < " + highLimit + " " + unit);
        l3.setValue("arvo < " + lowLimit + " " + unit);
        tf2.setValue(lowLimit);

        if (isIncrease()) {
            vl3.setStyleName("redBlock");
        } else {
            vl3.setStyleName("greenBlock");
        }

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

            private static final long serialVersionUID = 5929569929930454714L;

            @Override
            public void validate(Object value) throws InvalidValueException {
                try {
                    double d = Double.parseDouble((String) value);
                    if (d > highDouble)
                        throw new InvalidValueException("Value is too large");
                } catch (NumberFormatException e) {
                    throw new InvalidValueException(e.getMessage());
                }
            }

        });

    }

    inApply = false;

}