Example usage for com.vaadin.ui Embedded Embedded

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

Introduction

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

Prototype

public Embedded(String caption, Resource source) 

Source Link

Document

Creates a new Embedded object whose contents is loaded from given resource.

Usage

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

License:Open Source License

/**
 * Builds the progress.//from   w  w w  .j  a v a2s  .c o m
 *
 * @param taskRecord the task record
 * @param command the command
 * @param steps the steps
 */
public void buildProgress(TaskRecord taskRecord, String command, String steps) {

    VaadinSession session = getSession();
    if (session == null) {
        session = VaadinSession.getCurrent();
    }

    if (observerMode) {
        // String userName = Users.getUserNames().get(taskRecord.getUser());
        String userID = taskRecord.getUserID();
        UserInfo userInfo = (UserInfo) session.getAttribute(UserInfo.class);
        DateConversion dateConversion = session.getAttribute(DateConversion.class);
        setTitle(command + " was started on " + dateConversion.adjust(taskRecord.getStart()) + " by " + userID);
    } else {
        setTitle(command);
    }

    String[] stepIDs;
    try {
        stepIDs = steps.split(",");
    } catch (NullPointerException npe) {
        stepIDs = new String[] {};
    }
    totalSteps = stepIDs.length;
    primitives = new String[totalSteps];
    taskImages = new Embedded[totalSteps];

    // add steps icons
    progressIconsLayout.removeAllComponents();
    for (int index = 0; index < totalSteps; index++) {
        String stepID = stepIDs[index].trim();
        String description = Steps.getDescription(stepID);

        VerticalLayout stepLayout = new VerticalLayout();
        progressIconsLayout.addComponent(stepLayout);
        stepLayout.addStyleName("stepIcons");
        Label name = new Label(stepID);
        stepLayout.addComponent(name);
        stepLayout.setComponentAlignment(name, Alignment.MIDDLE_CENTER);
        Embedded image = new Embedded(null, new ThemeResource("img/scripting/pending.png"));
        image.setImmediate(true);
        image.setDescription(description);
        stepLayout.addComponent(image);
        primitives[index] = stepID;
        taskImages[index] = image;

    }

    setProgress("");

}

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

License:Open Source License

/**
 * Instantiates a new error dialog./*from   w  w  w  .j  av  a2s. c o m*/
 *
 * @param e the exception
 * @param humanizedError the humanized error
 */
public ErrorDialog(Exception e, String humanizedError) {

    if (e != null) {
        ManagerUI.error(e.getMessage());
    }

    dialogWindow = new ModalWindow("An Error has occurred", "775px");
    dialogWindow.setHeight("340px");
    dialogWindow.addCloseListener(this);
    UI current = UI.getCurrent();
    if (current.getContent() == null) {
        current.setContent(new ErrorView(Notification.Type.ERROR_MESSAGE, null));
    }
    current.addWindow(dialogWindow);

    HorizontalLayout wrapper = new HorizontalLayout();
    wrapper.setSizeFull();
    wrapper.setMargin(true);

    VerticalLayout iconLayout = new VerticalLayout();
    iconLayout.setWidth("100px");
    wrapper.addComponent(iconLayout);
    Embedded image = new Embedded(null, new ThemeResource("img/error.png"));
    iconLayout.addComponent(image);

    VerticalLayout textLayout = new VerticalLayout();
    textLayout.setHeight("100%");
    textLayout.setSpacing(true);
    wrapper.addComponent(textLayout);
    wrapper.setExpandRatio(textLayout, 1.0f);

    if (humanizedError != null || e != null) {
        String error = (humanizedError != null) ? humanizedError : e.toString();
        ManagerUI.error(error);
        Label label = new Label(error, ContentMode.HTML);
        label.addStyleName("warning");
        textLayout.addComponent(label);
        textLayout.setComponentAlignment(label, Alignment.TOP_CENTER);
    }

    if (e != null) {
        TextArea stackTrace = new TextArea("Error Log");
        stackTrace.setSizeFull();
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        stackTrace.setValue(sw.toString());
        textLayout.addComponent(stackTrace);
        textLayout.setComponentAlignment(stackTrace, Alignment.TOP_LEFT);
        textLayout.setExpandRatio(stackTrace, 1.0f);
    }

    HorizontalLayout buttonsBar = new HorizontalLayout();
    buttonsBar.setStyleName("buttonsBar");
    buttonsBar.setSizeFull();
    buttonsBar.setSpacing(true);
    buttonsBar.setMargin(true);
    buttonsBar.setHeight("49px");

    Label filler = new Label();
    buttonsBar.addComponent(filler);
    buttonsBar.setExpandRatio(filler, 1.0f);

    Button cancelButton = new Button("Close");
    buttonsBar.addComponent(cancelButton);
    buttonsBar.setComponentAlignment(cancelButton, Alignment.MIDDLE_RIGHT);

    cancelButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            dialogWindow.close();
            //UI.getCurrent().close();
        }
    });

    Button okButton = new Button("Send Error");
    okButton.setEnabled(false);
    okButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            dialogWindow.close();
        }
    });
    buttonsBar.addComponent(okButton);
    buttonsBar.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);

    VerticalLayout windowLayout = (VerticalLayout) dialogWindow.getContent();
    windowLayout.setHeight("100%");
    windowLayout.setSpacing(false);
    windowLayout.setMargin(false);
    windowLayout.addComponent(wrapper);
    windowLayout.setExpandRatio(wrapper, 1.0f);
    windowLayout.addComponent(buttonsBar);

}

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

License:Open Source License

/**
 * Instantiates a new error view./*from w w w. ja  v  a  2s .  co  m*/
 *
 * @param type the notification type
 * @param errorMsg the error msg
 */
public ErrorView(Type type, String errorMsg) {

    addStyleName("loginView");
    setSizeFull();
    setMargin(true);
    setSpacing(true);

    if (errorMsg != null) {
        Notification.show(errorMsg, type);
    }

    Embedded logo = new Embedded(null, new ThemeResource("img/productlogo.png"));
    addComponent(logo);
    setComponentAlignment(logo, Alignment.TOP_CENTER);

    if (type == Notification.Type.ERROR_MESSAGE) {
        Label refreshLabel = new Label("To try again, please refresh/reload the current page.");
        refreshLabel.setSizeUndefined();
        refreshLabel.addStyleName("instructions");
        addComponent(refreshLabel);
        setComponentAlignment(refreshLabel, Alignment.TOP_CENTER);
    }
}

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

License:Open Source License

/**
 * Time layout./*from ww  w .j  a v a  2 s.  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.LoginView.java

License:Open Source License

/**
 * Instantiates a new login view./* w ww .j  ava2  s  .  c  o  m*/
 *
 * @param aboutRecord the about record
 */
public LoginView() {

    setSizeFull();
    setMargin(true);
    setSpacing(true);
    addStyleName("loginView");

    VerticalLayout logoLayout = new VerticalLayout();
    addComponent(logoLayout);
    setComponentAlignment(logoLayout, Alignment.BOTTOM_CENTER);
    setExpandRatio(logoLayout, 1.0f);

    Embedded logo = new Embedded(null, new ThemeResource("img/loginlogo.png"));
    logoLayout.addComponent(logo);
    logoLayout.setComponentAlignment(logo, Alignment.BOTTOM_CENTER);

    Label releaseInfo = new Label("Version " + ManagerUI.GUI_RELEASE);
    releaseInfo.setSizeUndefined();
    releaseInfo.addStyleName("releaseInfo");
    logoLayout.addComponent(releaseInfo);
    logoLayout.setComponentAlignment(releaseInfo, Alignment.TOP_CENTER);

    VerticalLayout spacer = new VerticalLayout();
    spacer.setHeight("20px");
    logoLayout.addComponent(spacer);

    VerticalLayout loginBox = new VerticalLayout();
    loginBox.addStyleName("loginBox");
    loginBox.setSizeUndefined();
    loginBox.setMargin(true);
    loginBox.setSpacing(true);
    addComponent(loginBox);
    setComponentAlignment(loginBox, Alignment.MIDDLE_CENTER);

    VerticalLayout loginFormLayout = new VerticalLayout();
    loginFormLayout.addStyleName("loginForm");
    loginFormLayout.setMargin(true);
    loginFormLayout.setSpacing(true);
    loginBox.addComponent(loginFormLayout);

    // userName.focus();
    userName.setStyleName("loginControl");
    userName.setInputPrompt("Username");
    userName.setImmediate(true);
    userName.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {
            password.focus();
            login.setClickShortcut(KeyCode.ENTER);
        }
    });
    loginFormLayout.addComponent(userName);
    loginFormLayout.setComponentAlignment(userName, Alignment.MIDDLE_CENTER);

    // spacer
    loginFormLayout.addComponent(new Label(""));

    password.setStyleName("loginControl");
    password.setInputPrompt("Password");
    password.setImmediate(true);
    password.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {
            login.focus();
        }
    });
    loginFormLayout.addComponent(password);
    loginFormLayout.setComponentAlignment(password, Alignment.MIDDLE_CENTER);

    // spacer
    loginFormLayout.addComponent(new Label(" "));

    login.setStyleName("loginControl");
    login.setEnabled(false);

    loginFormLayout.addComponent(login);
    loginFormLayout.setComponentAlignment(login, Alignment.BOTTOM_CENTER);

    VerticalLayout filler = new VerticalLayout();
    addComponent(filler);
    setExpandRatio(filler, 1.0f);

    preload();

}

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

License:Open Source License

/**
 * Instantiates a new node form.//from  w w w.ja va2s  . 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 v a  2  s  .c  o  m
 *
 * @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  w  w. j  a  v  a  2  s  .co m
 *
 * @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:com.skysql.manager.ui.TopPanel.java

License:Open Source License

/**
 * Instantiates a new top panel.//w  w  w .  ja va 2 s. c  o m
 */
public TopPanel() {
    setSpacing(true);
    addStyleName("titleLayout");
    setWidth("100%");

    Embedded logo = new Embedded(null, new ThemeResource("img/productlogo.png"));
    addComponent(logo);
    setComponentAlignment(logo, Alignment.BOTTOM_LEFT);

    // LINKS AREA (TOP-RIGHT)
    HorizontalLayout userSettingsLayout = new HorizontalLayout();
    userSettingsLayout.setSizeUndefined();
    userSettingsLayout.setSpacing(true);
    addComponent(userSettingsLayout);
    setComponentAlignment(userSettingsLayout, Alignment.MIDDLE_RIGHT);

    // User icon and name
    VerticalLayout userLayout = new VerticalLayout();
    userSettingsLayout.addComponent(userLayout);
    userSettingsLayout.setComponentAlignment(userLayout, Alignment.BOTTOM_CENTER);

    UserObject userObject = VaadinSession.getCurrent().getAttribute(UserObject.class);
    String name = userObject.getAnyName();
    userName = new Label("Welcome, " + name);
    userName.setSizeUndefined();
    userLayout.addComponent(userName);

    // buttons
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setSizeUndefined();
    buttonsLayout.setSpacing(true);
    userSettingsLayout.addComponent(buttonsLayout);
    userSettingsLayout.setComponentAlignment(buttonsLayout, Alignment.MIDDLE_CENTER);

    // Settings button
    SettingsDialog settingsDialog = new SettingsDialog("Settings");
    Button settingsButton = settingsDialog.getButton();
    buttonsLayout.addComponent(settingsButton);
    buttonsLayout.setComponentAlignment(settingsButton, Alignment.MIDDLE_CENTER);

    // Logout
    Button logoutButton = new Button("Logout");
    logoutButton.setSizeUndefined();
    buttonsLayout.addComponent(logoutButton);
    buttonsLayout.setComponentAlignment(logoutButton, Alignment.MIDDLE_CENTER);
    logoutButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            UI.getCurrent().getPage().setLocation("");
            UI.getCurrent().close();
            getSession().setAttribute(UserObject.class, null);
            getSession().close();
        }
    });

}

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

License:Open Source License

/**
 * Instantiates a new warning window./*from  w w w .  jav  a2s  .c  o m*/
 *
 * @param caption the caption
 * @param message the message
 * @param label the label
 * @param okListener the ok listener
 */
public WarningWindow(String caption, String message, String label, Button.ClickListener okListener) {
    super(caption, "60%");

    HorizontalLayout wrapper = new HorizontalLayout();
    wrapper.setWidth("100%");
    wrapper.setMargin(true);
    VerticalLayout iconLayout = new VerticalLayout();
    iconLayout.setWidth("100px");
    wrapper.addComponent(iconLayout);
    Embedded image = new Embedded(null, new ThemeResource("img/warning.png"));
    iconLayout.addComponent(image);
    VerticalLayout textLayout = new VerticalLayout();
    textLayout.setSizeFull();
    wrapper.addComponent(textLayout);
    wrapper.setExpandRatio(textLayout, 1.0f);

    Label msgLabel = new Label(message);
    msgLabel.addStyleName("warning");
    textLayout.addComponent(msgLabel);
    textLayout.setComponentAlignment(msgLabel, Alignment.MIDDLE_CENTER);

    HorizontalLayout buttonsBar = new HorizontalLayout();
    buttonsBar.setStyleName("buttonsBar");
    buttonsBar.setSizeFull();
    buttonsBar.setSpacing(true);
    buttonsBar.setMargin(true);
    buttonsBar.setHeight("49px");

    Label filler = new Label();
    buttonsBar.addComponent(filler);
    buttonsBar.setExpandRatio(filler, 1.0f);

    Button cancelButton = new Button("Cancel");
    buttonsBar.addComponent(cancelButton);
    buttonsBar.setComponentAlignment(cancelButton, Alignment.MIDDLE_RIGHT);

    cancelButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(Button.ClickEvent event) {
            warningWindow.close();
        }
    });

    Button okButton = new Button(label);
    okButton.addClickListener(okListener);
    buttonsBar.addComponent(okButton);
    buttonsBar.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);

    VerticalLayout windowLayout = (VerticalLayout) this.getContent();
    windowLayout.setSpacing(false);
    windowLayout.setMargin(false);
    windowLayout.addComponent(wrapper);
    windowLayout.addComponent(buttonsBar);

}