Example usage for com.vaadin.ui Embedded addStyleName

List of usage examples for com.vaadin.ui Embedded addStyleName

Introduction

In this page you can find the example usage for com.vaadin.ui Embedded addStyleName.

Prototype

@Override
    public void addStyleName(String style) 

Source Link

Usage

From source file:com.klwork.explorer.ui.user.UserEventsPanel.java

License:Apache License

protected void addTaskEventPicture(final org.activiti.engine.task.Event taskEvent, GridLayout eventGrid) {
    if (taskEvent.getUserId() == null) {
        return;/*from w w  w.  ja va2  s.co m*/
    }
    final Picture userPicture = identityService.getUserPicture(taskEvent.getUserId());
    Embedded authorPicture = null;

    if (userPicture != null) {
        StreamResource imageresource = new StreamResource(new StreamSource() {
            private static final long serialVersionUID = 1L;

            public InputStream getStream() {
                return userPicture.getInputStream();
            }
        }, "event_" + taskEvent.getUserId() + "."
                + Constants.MIMETYPE_EXTENSION_MAPPING.get(userPicture.getMimeType()));
        authorPicture = new Embedded(null, imageresource);
    } else {
        authorPicture = new Embedded(null, Images.USER_50);
    }

    authorPicture.setType(Embedded.TYPE_IMAGE);
    authorPicture.setHeight("48px");
    authorPicture.setWidth("48px");
    authorPicture.addStyleName(ExplorerLayout.STYLE_TASK_EVENT_PICTURE);
    eventGrid.addComponent(authorPicture);
}

From source file:com.klwork.explorer.ui.util.ThemeImageColumnGenerator.java

License:Apache License

public Component generateCell(Table source, Object itemId, Object columnId) {
    Embedded embedded = new Embedded(null, image);

    if (clickListener != null) {
        embedded.addStyleName(ExplorerLayout.STYLE_CLICKABLE);
        embedded.setData(itemId);//from  w  w  w  .j  a  v a  2s.  c  o  m
        embedded.addListener(clickListener);
    }

    return embedded;
}

From source file:com.skysql.manager.ui.ChartPreviewLayout.java

License:Open Source License

/**
 * Instantiates a new chart preview layout.
 *
 * @param userChart the user chart/*from  w  ww .  jav a2 s  .  com*/
 * @param time the time
 * @param interval the interval
 */
public ChartPreviewLayout(final UserChart userChart, String time, String interval) {
    this.userChart = userChart;
    this.time = time;
    this.interval = interval;

    addStyleName("ChartPreviewLayout");
    setSpacing(true);
    setMargin(true);

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

    Embedded info = new Embedded(null, new ThemeResource("img/info.png"));
    info.addStyleName("infoButton");
    String infoText = "<table border=0 cellspacing=3 cellpadding=0 summary=\"\">\n"
            + "     <tr bgcolor=\"#ccccff\">" + "         <th align=left>Field"
            + "         <th align=left>Description" + "     <tr>" + "         <td><code>Title</code>"
            + "         <td>Name of the Chart" + "     <tr bgcolor=\"#eeeeff\">"
            + "         <td><code>Description</code>" + "         <td>Description of the Chart " + "     <tr>"
            + "         <td nowrap><code>Measurement Unit</code>"
            + "         <td>Unit of measurement for the data returned by the monitor, used as caption for the vertical axis of the chart"
            + "     <tr bgcolor=\"#eeeeff\">" + "         <td><code>Type</code>"
            + "         <td>Chart type (LineChart, AreaChart)" + "     <tr>"
            + "         <td><code>Points</code>" + "         <td>Number of data points displayed";
    infoText += " </table>" + " </blockquote>";
    info.setDescription(infoText);
    formDescription.addComponent(info);

    final Label monitorsLabel = new Label("Display as Chart");
    monitorsLabel.setStyleName("dialogLabel");
    formDescription.addComponent(monitorsLabel);
    formDescription.setComponentAlignment(monitorsLabel, Alignment.MIDDLE_LEFT);

    addComponent(formDescription);
    setComponentAlignment(formDescription, Alignment.TOP_CENTER);

    HorizontalLayout chartInfo = new HorizontalLayout();
    chartInfo.setSpacing(true);
    addComponent(chartInfo);
    setComponentAlignment(chartInfo, Alignment.MIDDLE_CENTER);

    FormLayout formLayout = new FormLayout();
    chartInfo.addComponent(formLayout);

    chartName = new TextField("Title");
    chartName.setImmediate(true);
    formLayout.addComponent(chartName);

    chartDescription = new TextField("Description");
    chartDescription.setWidth("25em");
    chartDescription.setImmediate(true);
    formLayout.addComponent(chartDescription);

    chartUnit = new TextField("Measurement Unit");
    chartUnit.setImmediate(true);
    formLayout.addComponent(chartUnit);

    chartSelectType = new NativeSelect("Type");
    chartSelectType.setImmediate(true);
    for (UserChart.ChartType type : UserChart.ChartType.values()) {
        chartSelectType.addItem(type.name());
    }
    chartSelectType.setNullSelectionAllowed(false);
    formLayout.addComponent(chartSelectType);

    selectCount = new NativeSelect("Points");
    selectCount.setImmediate(true);
    for (int points : UserChart.chartPoints()) {
        selectCount.addItem(points);
        selectCount.setItemCaption(points, String.valueOf(points));
    }
    selectCount.setNullSelectionAllowed(false);
    formLayout.addComponent(selectCount);

    updateChartInfo(userChart.getName(), userChart.getDescription(), userChart.getUnit(), userChart.getType(),
            userChart.getPoints());

    chartName.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {

            String chartName = (String) (event.getProperty()).getValue();
            userChart.setName(chartName);
            refreshChart();

        }
    });

    chartDescription.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {

            String value = (String) (event.getProperty()).getValue();
            userChart.setDescription(value);
            refreshChart();

        }
    });

    chartUnit.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {

            String value = (String) (event.getProperty()).getValue();
            userChart.setUnit(value);
            refreshChart();

        }
    });

    chartSelectType.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {

            String value = (String) (event.getProperty()).getValue();
            userChart.setType(value);
            refreshChart();

        }
    });

    selectCount.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {

            int points = (Integer) (event.getProperty()).getValue();
            userChart.setPoints(points);
            refreshChart();

        }
    });

    chartLayout = drawChart();
    addComponent(chartLayout);

}

From source file:com.skysql.manager.ui.components.ScriptingProgressLayout.java

License:Open Source License

/**
 * Sets the error info./*from  w w w  . j  a  v a  2  s . c o  m*/
 *
 * @param msg the new error info
 */
public void setErrorInfo(String msg) {
    Embedded info = new Embedded(null, new ThemeResource("img/alert.png"));
    info.addStyleName("infoButton");
    info.setDescription(msg);
    resultLayout.addComponent(info);
    resultLayout.setComponentAlignment(info, Alignment.MIDDLE_CENTER);
}

From source file:com.skysql.manager.ui.GeneralSettings.java

License:Open Source License

/**
 * Time layout.//w w  w. j  av a  2s .  c o  m
 *
 * @return the vertical layout
 */
private VerticalLayout timeLayout() {

    VerticalLayout layout = new VerticalLayout();
    layout.setWidth("100%");
    layout.setSpacing(true);
    layout.setMargin(new MarginInfo(false, true, false, true));

    HorizontalLayout titleLayout = new HorizontalLayout();
    titleLayout.setSpacing(true);
    layout.addComponent(titleLayout);

    final Label title = new Label("<h3>Date & Time Presentation</h3>", ContentMode.HTML);
    title.setSizeUndefined();
    titleLayout.addComponent(title);

    Embedded info = new Embedded(null, new ThemeResource("img/info.png"));
    info.addStyleName("infoButton");
    info.setDescription(
            "Determines if date & time stamps are displayed in the originally recorded format or adjusted to the local timezone.<br/>The format can be customized by using the following Java 6 SimpleDateFormat patterns:"
                    + "</blockquote>"
                    + " <table border=0 cellspacing=3 cellpadding=0 summary=\"Chart shows pattern letters, date/time component, presentation, and examples.\">\n"
                    + "     <tr bgcolor=\"#ccccff\">\n" + "         <th align=left>Letter\n"
                    + "         <th align=left>Date or Time Component\n"
                    + "         <th align=left>Presentation\n" + "         <th align=left>Examples\n"
                    + "     <tr>\n" + "         <td><code>G</code>\n" + "         <td>Era designator\n"
                    + "         <td><a href=\"#text\">Text</a>\n" + "         <td><code>AD</code>\n"
                    + "     <tr bgcolor=\"#eeeeff\">\n" + "         <td><code>y</code>\n"
                    + "         <td>Year\n" + "         <td><a href=\"#year\">Year</a>\n"
                    + "         <td><code>1996</code>; <code>96</code>\n" + "     <tr>\n"
                    + "         <td><code>M</code>\n" + "         <td>Month in year\n"
                    + "         <td><a href=\"#month\">Month</a>\n"
                    + "         <td><code>July</code>; <code>Jul</code>; <code>07</code>\n"
                    + "     <tr bgcolor=\"#eeeeff\">\n" + "         <td><code>w</code>\n"
                    + "         <td>Week in year\n" + "         <td><a href=\"#number\">Number</a>\n"
                    + "         <td><code>27</code>\n" + "     <tr>\n" + "         <td><code>W</code>\n"
                    + "         <td>Week in month\n" + "         <td><a href=\"#number\">Number</a>\n"
                    + "         <td><code>2</code>\n" + "     <tr bgcolor=\"#eeeeff\">\n"
                    + "         <td><code>D</code>\n" + "         <td>Day in year\n"
                    + "         <td><a href=\"#number\">Number</a>\n" + "         <td><code>189</code>\n"
                    + "     <tr>\n" + "         <td><code>d</code>\n" + "         <td>Day in month\n"
                    + "         <td><a href=\"#number\">Number</a>\n" + "         <td><code>10</code>\n"
                    + "     <tr bgcolor=\"#eeeeff\">\n" + "         <td><code>F</code>\n"
                    + "         <td>Day of week in month\n" + "         <td><a href=\"#number\">Number</a>\n"
                    + "         <td><code>2</code>\n" + "     <tr>\n" + "         <td><code>E</code>\n"
                    + "         <td>Day in week\n" + "         <td><a href=\"#text\">Text</a>\n"
                    + "         <td><code>Tuesday</code>; <code>Tue</code>\n"
                    + "     <tr bgcolor=\"#eeeeff\">\n" + "         <td><code>a</code>\n"
                    + "         <td>Am/pm marker\n" + "         <td><a href=\"#text\">Text</a>\n"
                    + "         <td><code>PM</code>\n" + "     <tr>\n" + "         <td><code>H</code>\n"
                    + "         <td>Hour in day (0-23)\n" + "         <td><a href=\"#number\">Number</a>\n"
                    + "         <td><code>0</code>\n" + "     <tr bgcolor=\"#eeeeff\">\n"
                    + "         <td><code>k</code>\n" + "         <td>Hour in day (1-24)\n"
                    + "         <td><a href=\"#number\">Number</a>\n" + "         <td><code>24</code>\n"
                    + "     <tr>\n" + "         <td><code>K</code>\n" + "         <td>Hour in am/pm (0-11)\n"
                    + "         <td><a href=\"#number\">Number</a>\n" + "         <td><code>0</code>\n"
                    + "     <tr bgcolor=\"#eeeeff\">\n" + "         <td><code>h</code>\n"
                    + "         <td>Hour in am/pm (1-12)\n" + "         <td><a href=\"#number\">Number</a>\n"
                    + "         <td><code>12</code>\n" + "     <tr>\n" + "         <td><code>m</code>\n"
                    + "         <td>Minute in hour\n" + "         <td><a href=\"#number\">Number</a>\n"
                    + "         <td><code>30</code>\n" + "     <tr bgcolor=\"#eeeeff\">\n"
                    + "         <td><code>s</code>\n" + "         <td>Second in minute\n"
                    + "         <td><a href=\"#number\">Number</a>\n" + "         <td><code>55</code>\n"
                    + "     <tr>\n" + "         <td><code>S</code>\n" + "         <td>Millisecond\n"
                    + "         <td><a href=\"#number\">Number</a>\n" + "         <td><code>978</code>\n"
                    + "     <tr bgcolor=\"#eeeeff\">\n" + "         <td><code>z</code>\n"
                    + "         <td>Time zone\n" + "         <td><a href=\"#timezone\">General time zone</a>\n"
                    + "         <td><code>Pacific Standard Time</code>; <code>PST</code>; <code>GMT-08:00</code>\n"
                    + "     <tr>\n" + "         <td><code>Z</code>\n" + "         <td>Time zone\n"
                    + "         <td><a href=\"#rfc822timezone\">RFC 822 time zone</a>\n"
                    + "         <td><code>-0800</code>\n" + " </table>\n" + " </blockquote>\n" + "");
    titleLayout.addComponent(info);
    titleLayout.setComponentAlignment(info, Alignment.MIDDLE_CENTER);

    final DateConversion dateConversion = VaadinSession.getCurrent().getAttribute(DateConversion.class);

    OptionGroup option = new OptionGroup("Display options");
    option.addItem(false);
    option.setItemCaption(false, "Show time in UTC/GMT");
    option.addItem(true);
    option.setItemCaption(true, "Adjust to local timezone (" + dateConversion.getClientTZname() + ")");

    String propertyTimeAdjust = userObject.getProperty(UserObject.PROPERTY_TIME_ADJUST);
    option.select(propertyTimeAdjust == null ? DEFAULT_TIME_ADJUST : Boolean.valueOf(propertyTimeAdjust));
    option.setNullSelectionAllowed(false);
    option.setHtmlContentAllowed(true);
    option.setImmediate(true);
    layout.addComponent(option);

    final HorizontalLayout defaultLayout = new HorizontalLayout();
    defaultLayout.setSpacing(true);
    layout.addComponent(defaultLayout);

    final Form form = new Form();
    form.setFooter(null);
    final TextField timeFormat = new TextField("Format");
    form.addField("timeFormat", timeFormat);
    defaultLayout.addComponent(form);

    option.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            boolean value = (Boolean) event.getProperty().getValue();
            dateConversion.setAdjustedToLocal(value);
            userObject.setProperty(UserObject.PROPERTY_TIME_ADJUST, String.valueOf(value));
            settingsDialog.setRefresh(true);
            if (value == false) {
                timeFormat.removeAllValidators();
                timeFormat.setComponentError(null);
                form.setComponentError(null);
                form.setValidationVisible(false);
                settingsDialog.setClose(true);
            } else {
                timeFormat.addValidator(new TimeFormatValidator());
                timeFormat.setInputPrompt(DateConversion.DEFAULT_TIME_FORMAT);
                //timeFormat.setClickShortcut(KeyCode.ENTER);
            }
        }
    });

    String propertyTimeFormat = userObject.getProperty(UserObject.PROPERTY_TIME_FORMAT);
    propertyTimeFormat = (propertyTimeFormat == null ? DateConversion.DEFAULT_TIME_FORMAT
            : String.valueOf(propertyTimeFormat));

    timeFormat.setColumns(16);
    timeFormat.setValue(propertyTimeFormat);
    timeFormat.setImmediate(true);
    timeFormat.setRequired(true);
    timeFormat.setRequiredError("Format cannot be empty.");
    timeFormat.addValidator(new TimeFormatValidator());

    timeFormat.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            String value = (String) event.getProperty().getValue();
            try {
                form.setComponentError(null);
                form.commit();
                timeFormat.setComponentError(null);
                form.setValidationVisible(false);
                dateConversion.setFormat(value);
                userObject.setProperty(UserObject.PROPERTY_TIME_FORMAT, value);
                settingsDialog.setClose(true);
                settingsDialog.setRefresh(true);
            } catch (InvalidValueException e) {
                settingsDialog.setClose(false);
                timeFormat.setComponentError(new UserError("Invalid Format (Java SimpleDateFormat)."));
                timeFormat.focus();
            }
        }
    });

    Button defaultButton = new Button("Restore Default");
    defaultLayout.addComponent(defaultButton);
    defaultLayout.setComponentAlignment(defaultButton, Alignment.MIDDLE_LEFT);
    defaultButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(Button.ClickEvent event) {
            timeFormat.setValue(DateConversion.DEFAULT_TIME_FORMAT);
        }
    });

    return layout;
}

From source file:com.skysql.manager.ui.NodeForm.java

License:Open Source License

/**
 * Instantiates a new node form./*ww w . j a  v a  2 s .  c  o m*/
 *
 * @param node the node
 * @param description the description
 */
NodeForm(final NodeInfo node, String description) {
    this.node = node;

    setMargin(new MarginInfo(true, true, false, true));
    setSpacing(false);

    isGalera = node.getSystemType().equals(SystemTypes.Type.galera.name());

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

    Embedded info = new Embedded(null, new ThemeResource("img/info.png"));
    info.addStyleName("infoButton");
    String infoText = "<table border=0 cellspacing=3 cellpadding=0 summary=\"\">\n"
            + "     <tr bgcolor=\"#ccccff\">" + "         <th align=left>Field"
            + "         <th align=left>Description" + "     <tr>" + "         <td><code>Name</code>"
            + "         <td>Name of the Node" + "     <tr bgcolor=\"#eeeeff\">"
            + "         <td><code>Hostname</code>"
            + "         <td>In some systems, a hostname that identifies the node" + "     <tr>"
            + "         <td><code>Instance ID</code>"
            + "         <td>The instance ID field is for information only and is not used within the Manager"
            + "     <tr bgcolor=\"#eeeeff\">" + "         <td><code>Public IP</code>"
            + "         <td>In some systems, the public IP address of the node" + "     <tr>"
            + "         <td><code>Private IP</code>"
            + "         <td>The IP address that accesses the node internally to the manager";

    if (!isGalera) {
        infoText += "     <tr bgcolor=\"#eeeeff\">" + "         <td><code>Database Username</code>"
                + "         <td>Node system override for database user name" + "     <tr>"
                + "         <td><code>Database Password</code>"
                + "         <td>Node system override for database password" + "     <tr bgcolor=\"#eeeeff\">"
                + "         <td><code>Replication Username</code>"
                + "         <td>Node system override for replication user name" + "     <tr>"
                + "         <td><code>Replication Password</code>"
                + "         <td>Node system override for replication password";

    }
    infoText += " </table>" + " </blockquote>";
    info.setDescription(infoText);

    formDescription.addComponent(info);
    Label labelDescription = new Label(description);
    formDescription.addComponent(labelDescription);
    formDescription.setComponentAlignment(labelDescription, Alignment.MIDDLE_LEFT);
    addComponent(formDescription);

    addComponent(form);
    form.setImmediate(false);
    form.setFooter(null);
    form.setDescription(null);

    String value;
    if ((value = node.getName()) != null) {
        name.setValue(value);
    }
    form.addField("name", name);
    name.focus();
    name.setImmediate(true);
    name.addValidator(new NodeNameValidator(node.getName()));

    if ((value = node.getHostname()) != null) {
        hostname.setValue(value);
    }
    form.addField("hostname", hostname);

    if ((value = node.getInstanceID()) != null) {
        instanceID.setValue(value);
    }
    form.addField("instanceID", instanceID);

    if ((value = node.getPublicIP()) != null) {
        publicIP.setValue(value);
    }
    form.addField("publicIP", publicIP);

    if ((value = node.getPrivateIP()) != null) {
        privateIP.setValue(value);
    }
    form.addField("privateIP", privateIP);
    privateIP.setRequired(true);
    privateIP.setRequiredError("Private IP is a required field");

    if (!isGalera) {
        if ((value = node.getDBUsername()) != null) {
            dbUsername.setValue(value);
        }
        form.addField("dbusername", dbUsername);
        dbUsername.setRequired(true);
        dbUsername.setImmediate(false);
        dbUsername.setRequiredError("Database Username is a required field");
        dbUsername.addValidator(new UserNotRootValidator(dbUsername.getCaption()));

        if ((value = node.getDBPassword()) != null) {
            dbPassword.setValue(value);
        }
        form.addField("dbpassword", dbPassword);
        dbPassword.setRequired(true);
        dbPassword.setImmediate(false);
        dbPassword.setRequiredError("Database Password is a required field");

        if ((value = node.getDBPassword()) != null) {
            dbPassword2.setValue(value);
        }
        form.addField("dbpassword2", dbPassword2);
        dbPassword2.setRequired(true);
        dbPassword2.setImmediate(true);
        dbPassword2.setRequiredError("Confirm Password is a required field");
        dbPassword2.addValidator(new Password2Validator(dbPassword));

        if ((value = node.getRepUsername()) != null) {
            repUsername.setValue(value);
        }
        form.addField("repusername", repUsername);
        repUsername.setRequired(true);
        repUsername.setImmediate(false);
        repUsername.setRequiredError("Replication Username is a required field");
        repUsername.addValidator(new UserNotRootValidator(repUsername.getCaption()));

        if ((value = node.getRepPassword()) != null) {
            repPassword.setValue(value);
        }
        form.addField("reppassword", repPassword);
        repPassword.setRequired(true);
        repPassword.setImmediate(false);
        repPassword.setRequiredError("Replication Password is a required field");

        if ((value = node.getRepPassword()) != null) {
            repPassword2.setValue(value);
        }
        form.addField("reppassword2", repPassword2);
        repPassword2.setRequired(true);
        repPassword2.setImmediate(true);
        repPassword2.setRequiredError("Confirm Password is a required field");
        repPassword2.addValidator(new Password2Validator(repPassword));
    }

    if (node.getID() == null) {
        Layout layout = form.getLayout();

        {
            Label spacer = new Label();
            spacer.setWidth("40px");
            layout.addComponent(spacer);
        }

        HorizontalLayout optionLayout = new HorizontalLayout();
        optionLayout.addStyleName("formInfoLayout");
        optionLayout.setSpacing(true);
        optionLayout.setSizeUndefined();
        layout.addComponent(optionLayout);

        Label padding = new Label("\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0");
        optionLayout.addComponent(padding);

        Embedded info2 = new Embedded(null, new ThemeResource("img/info.png"));
        info2.addStyleName("infoButton");
        info2.setDescription(connectionInfo);
        optionLayout.addComponent(info2);

        final Validator validator = new Password2Validator(connectPassword);

        final OptionGroup connectOption = new OptionGroup("Connection options");
        connectOption.setSizeUndefined();
        connectOption.addItem(false);
        connectOption.setItemCaption(false, "Node is not available, user will run connect later");
        connectOption.addItem(true);
        connectOption.setItemCaption(true, "Node is available now, connect automatically");
        connectOption.setImmediate(true);
        connectOption.addValueChangeListener(new Property.ValueChangeListener() {
            private static final long serialVersionUID = 0x4C656F6E6172646FL;

            @Override
            public void valueChange(ValueChangeEvent event) {
                runConnect = (Boolean) event.getProperty().getValue();
                passwordOption.setVisible(runConnect);
                connectPassword.setRequired(runConnect && usePassword);
                connectPassword2.setRequired(runConnect && usePassword);
                connectKey.setRequired(runConnect && !usePassword);
                if (!runConnect) {
                    connectPassword.setVisible(false);
                    connectPassword2.setVisible(false);
                    connectPassword2.removeValidator(validator);
                    connectKey.setVisible(false);
                } else {
                    if (usePassword) {
                        connectPassword.setVisible(true);
                        connectPassword2.setVisible(true);
                        connectPassword2.addValidator(validator);
                    } else {
                        connectKey.setVisible(true);
                    }
                }
                form.setComponentError(null);
                form.setValidationVisible(false);
            }
        });
        optionLayout.addComponent(connectOption);
        optionLayout.setComponentAlignment(connectOption, Alignment.MIDDLE_LEFT);
        connectOption.select(true);

        passwordOption.addItem(true);
        passwordOption.setItemCaption(true, "Authenticate with root user");
        passwordOption.addItem(false);
        passwordOption.setItemCaption(false, "Authenticate with SSH Key");
        passwordOption.setImmediate(true);
        passwordOption.addValueChangeListener(new Property.ValueChangeListener() {
            private static final long serialVersionUID = 0x4C656F6E6172646FL;

            @Override
            public void valueChange(ValueChangeEvent event) {
                usePassword = (Boolean) event.getProperty().getValue();
                if (usePassword) {
                    connectPassword2.addValidator(validator);
                } else {
                    connectPassword2.removeValidator(validator);
                }
                connectPassword.setVisible(usePassword);
                connectPassword.setRequired(usePassword);
                connectPassword2.setVisible(usePassword);
                connectPassword2.setRequired(usePassword);
                connectKey.setVisible(!usePassword);
                connectKey.setRequired(!usePassword);
                form.setComponentError(null);
                form.setValidationVisible(false);
            }
        });
        layout.addComponent(passwordOption);
        passwordOption.select(false);

        form.addField("connectPassword", connectPassword);
        connectPassword.setImmediate(false);
        connectPassword.setRequiredError("Root Password is a required field");

        form.addField("connectPassword2", connectPassword2);
        connectPassword2.setImmediate(true);
        connectPassword2.setRequiredError("Confirm Password is a required field");

        form.addField("connectKey", connectKey);
        connectKey.setStyleName("sshkey");
        connectKey.setColumns(41);
        connectKey.setRequiredError("SSH Key is a required field");
    }

}

From source file:com.skysql.manager.ui.PanelControl.java

License:Open Source License

/**
 * Asynch refresh./*from  ww  w .j  a va2  s . com*/
 *
 * @param updaterThread the updater thread
 */
private void asynchRefresh(final UpdaterThread updaterThread) {

    ManagerUI managerUI = getSession().getAttribute(ManagerUI.class);

    nodeInfo = (NodeInfo) getSession().getAttribute(ClusterComponent.class);
    final String newNodeID = nodeInfo.getID();

    final UserInfo userInfo = (UserInfo) getSession().getAttribute(UserInfo.class);

    TaskRecord taskRecord = nodeInfo.getTask();
    final String taskID = (taskRecord != null && taskRecord.getState().equals("running")) ? taskRecord.getID()
            : null;

    // update command history section
    TaskInfo taskInfo = new TaskInfo(null, nodeInfo.getParentID(), nodeInfo.getID());
    final ArrayList<TaskRecord> tasksList = taskInfo.getTasksList();

    managerUI.access(new Runnable() {
        @Override
        public void run() {
            // Here the UI is locked and can be updated

            ManagerUI.log("PanelControl access run() - taskID: " + taskID);

            RunningTask runningTask = nodeInfo.getCommandTask();

            DateConversion dateConversion = getSession().getAttribute(DateConversion.class);
            boolean adjust = dateConversion.isAdjustedToLocal();
            String format = dateConversion.getFormat();

            if (!newNodeID.equals(lastNodeID) || (tasksList != null && tasksList.size() != oldTasksCount)
                    || adjust != updaterThread.adjust || !format.equals(updaterThread.format)) {

                updaterThread.adjust = adjust;
                updaterThread.format = format;

                logsTable.removeAllItems();

                if (tasksList != null) {

                    oldTasksCount = tasksList.size();
                    firstObject = null;
                    for (TaskRecord taskRecord : tasksList) {
                        Embedded info = null;
                        if (taskRecord.getState().equals(CommandStates.States.error.name())) {
                            info = new Embedded(null, new ThemeResource("img/alert.png"));
                            info.addStyleName("infoButton");
                            info.setDescription(taskRecord.getError());
                        }
                        Object itemID = logsTable.addItem(new Object[] { taskRecord.getCommand(),
                                CommandStates.getDescriptions().get(taskRecord.getState()), info,
                                dateConversion.adjust(taskRecord.getStart()),
                                dateConversion.adjust(taskRecord.getEnd()), taskRecord.getSteps(),
                                taskRecord.getParams(), taskRecord.getUserID() }, taskRecord.getID());
                        if (firstObject == null) {
                            firstObject = itemID;
                        }

                    }
                }
            } else if (tasksList.size() > 0 && firstObject != null) {
                // update top of the list with last task info
                TaskRecord taskRecord = tasksList.get(0);
                Embedded info = null;
                if (taskRecord.getState().equals(CommandStates.States.error.name())) {
                    info = new Embedded(null, new ThemeResource("img/alert.png"));
                    info.addStyleName("infoButton");
                    info.setDescription(taskRecord.getError());
                }
                Item tableRow = logsTable.getItem(firstObject);
                tableRow.getItemProperty("State")
                        .setValue(CommandStates.getDescriptions().get(taskRecord.getState()));
                tableRow.getItemProperty("Info").setValue(info);
                tableRow.getItemProperty("Completed").setValue(dateConversion.adjust(taskRecord.getEnd()));
            }

            // task is running although it was not started by us
            if (taskID != null && runningTask == null) {
                runningTask = new RunningTask(null, nodeInfo, commandSelect);
                runningTask.addRefreshListener(refreshListener);
            }

            if (!newNodeID.equals(lastNodeID)) {
                commandSelect.removeAllItems();
                nodeInfo.updateCommands();
            }
            if (nodeInfo.getCommands() == null || nodeInfo.getCommands().getNames().isEmpty()) {
                commandSelect.removeAllItems();
                oldcommands = null;
                placeholderLabel.setValue("No Command is currently available on this node");
            } else {
                placeholderLabel.setValue("No Command is currently running on this node");
                String commands[] = new String[nodeInfo.getCommands().getNames().keySet().size()];
                nodeInfo.getCommands().getNames().keySet().toArray(commands);
                if (!newNodeID.equals(lastNodeID) || !Arrays.equals(commands, oldcommands)) {
                    oldcommands = commands;
                    commandSelect.removeValueChangeListener(commandListener);

                    // rebuild list of commands with what node is accepting
                    commandSelect.removeAllItems();
                    if ((commands != null) && (commands.length != 0)) {
                        for (String command : commands) {
                            commandSelect.addItem(command);
                        }
                    }

                    commandSelect.addValueChangeListener(commandListener);
                }

                commandSelect.removeValueChangeListener(commandListener);
                String selected = (runningTask != null) ? runningTask.getCommand() : null;
                commandSelect.select(selected);
                commandSelect.addValueChangeListener(commandListener);

            }
            commandSelect.setEnabled(taskID != null ? false : true);

            if (runningTask != null) {
                VerticalLayout newScriptingLayout = runningTask.getLayout();
                newLayout.replaceComponent(runningContainerLayout, newScriptingLayout);
                runningContainerLayout = newScriptingLayout;
            } else if (runningContainerLayout != placeholderLayout) {
                newLayout.replaceComponent(runningContainerLayout, placeholderLayout);
                newLayout.setComponentAlignment(placeholderLayout, Alignment.MIDDLE_CENTER);
                runningContainerLayout = placeholderLayout;
            }

            lastNodeID = newNodeID;
        }
    });

}

From source file:com.skysql.manager.ui.SystemForm.java

License:Open Source License

/**
 * Instantiates a new system form.//from  w ww. ja v a2s  .  c om
 *
 * @param system the system
 * @param description the description
 * @param commitButton the commit button
 */
SystemForm(final SystemRecord system, String description, final Button commitButton) {
    this.system = system;

    setMargin(new MarginInfo(true, true, false, true));
    setSpacing(false);

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

    Embedded info = new Embedded(null, new ThemeResource("img/info.png"));
    info.addStyleName("infoButton");
    String infoText = "<table border=0 cellspacing=3 cellpadding=0 summary=\"\">\n"
            + "     <tr bgcolor=\"#ccccff\">" + "         <th align=left>Field"
            + "         <th align=left>Description" + "     <tr>" + "         <td><code>Name</code>"
            + "         <td>Name of the system" + "     <tr bgcolor=\"#eeeeff\">"
            + "         <td><code>Type</code>" + "         <td>Type of the system e.g. aws or galera"
            + "     <tr>" + "         <td><code>Database Username</code>"
            + "         <td>System default for database user name" + "     <tr bgcolor=\"#eeeeff\">"
            + "         <td><code>Database Password</code>"
            + "         <td>System default for database password" + "     <tr>"
            + "         <td><code>Replication Username</code>"
            + "         <td>System default for replication user name" + "     <tr bgcolor=\"#eeeeff\">"
            + "         <td><code>Replication Password</code>"
            + "         <td>System default for replication password" + " </table>" + " </blockquote>";
    info.setDescription(infoText);

    formDescription.addComponent(info);
    Label labelDescription = new Label(description);
    formDescription.addComponent(labelDescription);
    formDescription.setComponentAlignment(labelDescription, Alignment.MIDDLE_LEFT);
    addComponent(formDescription);

    addComponent(form);
    form.setImmediate(false);
    form.setFooter(null);
    form.setDescription(null);

    String value;
    if ((value = system.getName()) != null) {
        name.setValue(value);
    }
    form.addField("name", name);
    name.focus();
    name.setImmediate(true);
    name.addValidator(new SystemNameValidator(system.getName()));

    for (String systemType : SystemTypes.getList().keySet()) {
        this.systemType.addItem(systemType);
    }
    systemType.select(system.getSystemType() != null ? system.getSystemType() : SystemTypes.DEFAULT_SYSTEMTYPE);
    systemType.setNullSelectionAllowed(false);
    systemType.setEnabled(false);
    form.addField("systemType", systemType);

    if ((value = system.getDBUsername()) != null) {
        dbUsername.setValue(value);
    } else {
        dbUsername.setValue("skysql");
    }
    form.addField("dbusername", dbUsername);
    dbUsername.setRequired(true);
    dbUsername.setImmediate(true);
    dbUsername.setRequiredError("Database Username is a required field");
    dbUsername.addValidator(new UserNotRootValidator(dbUsername.getCaption()));

    if ((value = system.getDBPassword()) != null) {
        dbPassword.setValue(value);
    }
    form.addField("dbpassword", dbPassword);
    dbPassword.setRequired(true);
    dbPassword.setImmediate(false);
    dbPassword.setRequiredError("Database Password is a required field");

    if ((value = system.getDBPassword()) != null) {
        dbPassword2.setValue(value);
    }
    form.addField("dbpassword2", dbPassword2);
    dbPassword2.setRequired(true);
    dbPassword2.setImmediate(true);
    dbPassword2.setRequiredError("Confirm Password is a required field");
    dbPassword2.addValidator(new Password2Validator(dbPassword));

    if ((value = system.getRepUsername()) != null) {
        repUsername.setValue(value);
    } else {
        repUsername.setValue("repluser");
    }
    form.addField("repusername", repUsername);
    repUsername.setRequired(true);
    repUsername.setImmediate(true);
    repUsername.setRequiredError("Replication Username is a required field");
    repUsername.addValidator(new UserNotRootValidator(repUsername.getCaption()));
    repUsername.addValidator(new UserDifferentValidator(dbUsername));

    if ((value = system.getRepPassword()) != null) {
        repPassword.setValue(value);
    }
    form.addField("reppassword", repPassword);
    repPassword.setRequired(true);
    repPassword.setImmediate(true);
    repPassword.setRequiredError("Replication Password is a required field");
    repPassword.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {
            commitButton.setClickShortcut(KeyCode.ENTER);
        }
    });

    if ((value = system.getRepPassword()) != null) {
        repPassword2.setValue(value);
    }
    form.addField("reppassword2", repPassword2);
    repPassword2.setRequired(true);
    repPassword2.setImmediate(true);
    repPassword2.setRequiredError("Confirm Password is a required field");
    repPassword2.addValidator(new Password2Validator(repPassword));
    repPassword2.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {
            commitButton.focus();
        }
    });

}

From source file:edu.nps.moves.mmowgli.components.CardTable.java

License:Open Source License

@SuppressWarnings("unused")
private Component orig_buildGenAuthorColumn(Card card) {
    // IE7 can't handle fanciness:
    if (Mmowgli2UI.getGlobals().isIE7()) {
        return new Label(card.getAuthorName()); //.getAuthor().getUserName());
    }//  w  w w .  j a  va2 s. c  o  m

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

    User auth = card.getAuthor();

    if (auth.getAvatar() != null) {
        Embedded avatar = new Embedded(null,
                Mmowgli2UI.getGlobals().getMediaLocator().locate(auth.getAvatar().getMedia(), 32));
        avatar.setWidth("24px");
        avatar.setHeight("24px");
        hl.addComponent(avatar);
        hl.setComponentAlignment(avatar, Alignment.MIDDLE_LEFT);
        avatar.addStyleName("m-cursor-pointer");
    }
    IDButton uButt = new IDButton(auth.getUserName(), SHOWUSERPROFILECLICK, auth.getId());
    uButt.addStyleName(BaseTheme.BUTTON_LINK);
    uButt.setWidth(8.0f, Unit.EM);

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

    return hl;
}

From source file:edu.nps.moves.mmowgli.modules.administration.AbstractGameBuilderPanel.java

License:Open Source License

@Override
public void initGui() {
    String title = getTitle();/*from  w  w  w . j  a v a  2 s.c o m*/
    if (title != null) {
        Label titleLab;
        addComponent(titleLab = new Label(title));
        titleLab.addStyleName("m-centeralign");
    }
    Embedded e = this.getImage();
    if (e != null) {
        e.setWidth("800px"); // "930px");
        e.setHeight("400px"); // "465px");
        e.addStyleName("m-greyborder3");
        addComponent(e);
        setComponentAlignment(e, Alignment.MIDDLE_CENTER);
    }

    if (lines.size() > 0) {
        grid.setColumns(3);
        String heading = getHeading();
        Component footer = getFooter();
        int nRows = lines.size() + (heading != null ? 1 : 0) + (footer != null ? 1 : 0);
        grid.setRows(nRows);
        int rowOffst = 0;

        if (heading != null) {
            grid.addComponent(makeLabel(heading), 0, 0, 2, 0);
            rowOffst = 1;
        }
        for (int r = 0; r < lines.size(); r++) {
            EditLine edLine = lines.get(r);
            if (edLine.ta != null)
                edLine.ta.setDescription(edLine.tooltip);

            if (edLine.isSeparator()) {
                addSeparator(grid, r + rowOffst);
                continue;
            }
            if (edLine.justComponent()) {
                addLineComponent(grid, r + rowOffst, edLine.ta);
                continue;
            }
            Label textLab = new HtmlLabel(edLine.name);
            textLab.setDescription(edLine.tooltip);
            textLab.addStyleName("m-font-bold14");
            textLab.setWidth(getColumn1WidthString());
            grid.addComponent(textLab, 0, r + rowOffst); // c0,r0,c1,r1

            Label fieldLab = new Label(edLine.info);
            fieldLab.setDescription(edLine.tooltip);
            fieldLab.addStyleName("m-italic");
            fieldLab.setWidth(getColumn2WidthString());
            grid.addComponent(fieldLab, 1, r + rowOffst);

            if (edLine.ta instanceof TextArea) {
                TextArea ta = (TextArea) edLine.ta;
                ta.setDescription(edLine.tooltip);
                ta.setImmediate(true);
                ta.setWidth("100%");

                if (edLine.fieldName != null && autoSave)
                    ta.addValueChangeListener(new IndivListener(edLine, updatesOK,
                            edLine.fieldClass == null ? String.class : edLine.fieldClass));
                grid.addComponent(ta, 2, r + rowOffst);
            } else if (edLine.ta instanceof CheckBox) {
                CheckBox cb = (CheckBox) edLine.ta;
                cb.setDescription(edLine.tooltip);
                cb.setImmediate(true);

                if (edLine.fieldName != null && autoSave)
                    cb.addValueChangeListener(new IndivListener(edLine, updatesOK, boolean.class));
                grid.addComponent(cb, 2, r + rowOffst);
            } else if (edLine.ta instanceof Component) {
                grid.addComponent(edLine.ta, 2, r + rowOffst);
            }
        }
        if (footer != null) {
            int frow = lines.size() + rowOffst;
            grid.addComponent(footer, 0, frow, 2, frow);
        }
        grid.setWidth("99%");
        grid.setHeight("100%");

        addComponent(grid);
        grid.setColumnExpandRatio(2, 1.0f);

        if (showTestButton) {
            Button testButt = new Button(getTextButtonText(), new ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                @MmowgliCodeEntry
                @HibernateOpened
                @HibernateClosed
                public void buttonClick(ClickEvent event) {
                    HSess.init();
                    testButtonClickedTL(event);
                    HSess.close();
                }
            });
            addComponent(testButt);
            setComponentAlignment(testButt, Alignment.MIDDLE_CENTER);
        }
    }
}