Example usage for com.vaadin.ui VerticalLayout setMargin

List of usage examples for com.vaadin.ui VerticalLayout setMargin

Introduction

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

Prototype

@Override
    public void setMargin(boolean enabled) 

Source Link

Usage

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

License:Open Source License

/**
 * Instantiates a new error dialog./*from   w w w  .  j  a v  a  2s.co  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.GeneralSettings.java

License:Open Source License

/**
 * Backups layout.//from ww w .j a v  a  2  s  . com
 *
 * @return the vertical layout
 */
private VerticalLayout backupsLayout() {

    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setMargin(true);

    final Label label = new Label("<h2>Backups</h2>", ContentMode.HTML);
    layout.addComponent(label);

    final SystemInfo systemInfo = VaadinSession.getCurrent().getAttribute(SystemInfo.class);
    LinkedHashMap<String, String> properties = systemInfo.getCurrentSystem().getProperties();
    if (properties != null) {
        maxBackupCount = properties.get(SystemInfo.PROPERTY_DEFAULTMAXBACKUPCOUNT);
        maxBackupSize = properties.get(SystemInfo.PROPERTY_DEFAULTMAXBACKUPSIZE);
    }

    NativeSelect selectCount = new NativeSelect("Max number of backups");
    selectCount.setImmediate(true);

    SettingsValues countValues = new SettingsValues(SettingsValues.SETTINGS_MAX_BACKUP_COUNT);
    String[] counts = countValues.getValues();
    for (String value : counts) {
        selectCount.addItem(value);
    }
    selectCount.select(maxBackupCount);
    selectCount.setNullSelectionAllowed(false);
    layout.addComponent(selectCount);
    selectCount.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {
            maxBackupCount = (String) ((NativeSelect) event.getProperty()).getValue();
            systemInfo.setProperty(SystemInfo.PROPERTY_DEFAULTMAXBACKUPCOUNT, maxBackupCount);

        }
    });

    NativeSelect selectSize = new NativeSelect("Max total backup size");
    selectSize.setImmediate(true);
    SettingsValues sizeValues = new SettingsValues(SettingsValues.SETTINGS_MAX_BACKUP_SIZE);
    String[] sizes = sizeValues.getValues();
    for (String value : sizes) {
        selectSize.addItem(value + " GB");
    }
    selectSize.select(maxBackupSize + " GB");
    selectSize.setNullSelectionAllowed(false);
    layout.addComponent(selectSize);
    selectSize.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {
            maxBackupSize = (String) ((NativeSelect) event.getProperty()).getValue();
            String value = maxBackupSize.substring(0, maxBackupSize.indexOf(" GB"));
            systemInfo.setProperty(SystemInfo.PROPERTY_DEFAULTMAXBACKUPSIZE, value);

        }
    });

    return layout;
}

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

License:Open Source License

/**
 * Time layout.//from   w w  w  . j  av  a 2  s  . co 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.GeneralSettings.java

License:Open Source License

/**
 * Commands layout./*from   www .  ja va  2 s  .com*/
 *
 * @return the vertical layout
 */
private VerticalLayout commandsLayout() {

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

    final Label title = new Label("<h3>Commands Execution</h3>", ContentMode.HTML);
    title.setSizeUndefined();
    layout.addComponent(title);

    final Label explanation = new Label(
            "Determines if the command you selected will be executed only if the original steps displayed at the time of selection are still applicable, or if a suitable variation (depending on node state) can be substituted when you press \"Run\".");
    explanation.setSizeFull();
    layout.addComponent(explanation);

    OptionGroup option = new OptionGroup("Select an option");
    option.addItem(false);
    option.setItemCaption(false, "Strict - only original steps");
    option.addItem(true);
    option.setItemCaption(true, "Loose - any variation");

    String propertyCommandExecution = userObject.getProperty(UserObject.PROPERTY_COMMAND_EXECUTION);
    option.select(propertyCommandExecution == null ? DEFAULT_COMMAND_EXECUTION
            : Boolean.valueOf(propertyCommandExecution));
    option.setNullSelectionAllowed(false);
    option.setHtmlContentAllowed(true);
    option.setImmediate(true);
    layout.addComponent(option);

    option.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            Object value = event.getProperty().getValue();
            userObject.setProperty(UserObject.PROPERTY_COMMAND_EXECUTION, String.valueOf(value));
        }
    });

    return layout;
}

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

License:Open Source License

/**
 * Instantiates a new login view.// w w w . j  av a 2s  .com
 *
 * @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.ModalWindow.java

License:Open Source License

/**
 * Instantiates a new modal window./*from w  w  w .ja v  a2s .  c o  m*/
 *
 * @param caption the caption
 * @param width the width
 */
public ModalWindow(String caption, String width) {
    setModal(true);
    if (width != null) {
        setWidth(width);
    }
    center();
    setCaption(caption);
    VerticalLayout layout = new VerticalLayout();
    setContent(layout);
    layout.setSpacing(true);
    layout.setMargin(true);
}

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

License:Open Source License

/**
 * Monitor form./* w w  w. j  av  a 2  s . c o  m*/
 *
 * @param monitor the monitor
 * @param title the title
 * @param description the description
 * @param button the button
 */
public void monitorForm(final MonitorRecord monitor, String title, String description, String button) {
    final TextField monitorName = new TextField("Monitor Name");
    final TextField monitorDescription = new TextField("Description");
    final TextField monitorUnit = new TextField("Measurement Unit");
    final TextArea monitorSQL = new TextArea("SQL Statement");
    final CheckBox monitorDelta = new CheckBox("Is Delta");
    final CheckBox monitorAverage = new CheckBox("Is Average");
    final NativeSelect validationTarget = new NativeSelect("Validate SQL on");
    final NativeSelect monitorInterval = new NativeSelect("Sampling interval");
    final NativeSelect monitorChartType = new NativeSelect("Default display");

    secondaryDialog = new ModalWindow(title, null);
    UI.getCurrent().addWindow(secondaryDialog);
    secondaryDialog.addCloseListener(this);

    final VerticalLayout formContainer = new VerticalLayout();
    formContainer.setMargin(new MarginInfo(true, true, false, true));
    formContainer.setSpacing(false);

    final Form form = new Form();
    formContainer.addComponent(form);
    form.setImmediate(false);
    form.setFooter(null);
    form.setDescription(description);

    String value;

    if ((value = monitor.getName()) != null) {
        monitorName.setValue(value);
    }
    form.addField("monitorName", monitorName);
    form.getField("monitorName").setRequired(true);
    form.getField("monitorName").setRequiredError("Monitor Name is missing");
    monitorName.focus();
    monitorName.setImmediate(true);
    monitorName.addValidator(new MonitorNameValidator(monitor.getName()));

    if ((value = monitor.getDescription()) != null) {
        monitorDescription.setValue(value);
    }
    monitorDescription.setWidth("24em");
    form.addField("monitorDescription", monitorDescription);

    if ((value = monitor.getUnit()) != null) {
        monitorUnit.setValue(value);
    }
    form.addField("monitorUnit", monitorUnit);

    if ((value = monitor.getSql()) != null) {
        monitorSQL.setValue(value);
    }
    monitorSQL.setWidth("24em");
    monitorSQL.addValidator(new SQLValidator());
    form.addField("monitorSQL", monitorSQL);

    final String noValidation = "None - Skip Validation";
    validationTarget.setImmediate(true);
    validationTarget.setNullSelectionAllowed(false);
    validationTarget.addItem(noValidation);
    validationTarget.select(noValidation);
    OverviewPanel overviewPanel = getSession().getAttribute(OverviewPanel.class);
    ArrayList<NodeInfo> nodes = overviewPanel.getNodes();

    if (nodes == null || nodes.isEmpty()) {
        SystemInfo systemInfo = VaadinSession.getCurrent().getAttribute(SystemInfo.class);
        String systemID = systemInfo.getCurrentID();
        String systemType = systemInfo.getCurrentSystem().getSystemType();
        if (systemID.equals(SystemInfo.SYSTEM_ROOT)) {
            ClusterComponent clusterComponent = VaadinSession.getCurrent().getAttribute(ClusterComponent.class);
            systemID = clusterComponent.getID();
            systemType = clusterComponent.getSystemType();
        }
        nodes = new ArrayList<NodeInfo>();
        for (String nodeID : systemInfo.getSystemRecord(systemID).getNodes()) {
            NodeInfo nodeInfo = new NodeInfo(systemID, systemType, nodeID);
            nodes.add(nodeInfo);
        }

    }

    for (NodeInfo node : nodes) {
        validationTarget.addItem(node.getID());
        validationTarget.setItemCaption(node.getID(), node.getName());
    }
    validationTarget.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {
            nodeID = (String) event.getProperty().getValue();
            validateSQL = nodeID.equals(noValidation) ? false : true;
        }

    });
    form.addField("validationTarget", validationTarget);

    monitorDelta.setValue(monitor.isDelta());
    form.addField("monitorDelta", monitorDelta);

    monitorAverage.setValue(monitor.isAverage());
    form.addField("monitorAverage", monitorAverage);

    SettingsValues intervalValues = new SettingsValues(SettingsValues.SETTINGS_MONITOR_INTERVAL);
    String[] intervals = intervalValues.getValues();
    for (String interval : intervals) {
        monitorInterval.addItem(Integer.parseInt(interval));
    }

    Collection<?> validIntervals = monitorInterval.getItemIds();
    if (validIntervals.contains(monitor.getInterval())) {
        monitorInterval.select(monitor.getInterval());
    } else {
        SystemInfo systemInfo = getSession().getAttribute(SystemInfo.class);
        String defaultInterval = systemInfo.getSystemRecord(systemID).getProperties()
                .get(SystemInfo.PROPERTY_DEFAULTMONITORINTERVAL);
        if (defaultInterval != null && validIntervals.contains(Integer.parseInt(defaultInterval))) {
            monitorInterval.select(Integer.parseInt(defaultInterval));
        } else if (!validIntervals.isEmpty()) {
            monitorInterval.select(validIntervals.toArray()[0]);
        } else {
            new ErrorDialog(null, "No set of permissible monitor intervals found");
        }

        monitorInterval.setNullSelectionAllowed(false);
        form.addField("monitorInterval", monitorInterval);
    }

    for (UserChart.ChartType type : UserChart.ChartType.values()) {
        monitorChartType.addItem(type.name());
    }
    monitorChartType
            .select(monitor.getChartType() == null ? UserChart.ChartType.values()[0] : monitor.getChartType());
    monitorChartType.setNullSelectionAllowed(false);
    form.addField("monitorChartType", monitorChartType);

    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(ClickEvent event) {
            form.discard();
            secondaryDialog.close();
        }
    });

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

        public void buttonClick(ClickEvent event) {
            try {
                form.setComponentError(null);
                form.commit();
                monitor.setName(monitorName.getValue());
                monitor.setDescription(monitorDescription.getValue());
                monitor.setUnit(monitorUnit.getValue());
                monitor.setSql(monitorSQL.getValue());
                monitor.setDelta(monitorDelta.getValue());
                monitor.setAverage(monitorAverage.getValue());
                monitor.setInterval((Integer) monitorInterval.getValue());
                monitor.setChartType((String) monitorChartType.getValue());
                String ID;
                if ((ID = monitor.getID()) == null) {
                    if (Monitors.setMonitor(monitor)) {
                        ID = monitor.getID();
                        select.addItem(ID);
                        select.select(ID);
                        Monitors.reloadMonitors();
                        monitorsAll = Monitors.getMonitorsList(systemType);
                    }
                } else {
                    Monitors.setMonitor(monitor);
                    ChartProperties chartProperties = getSession().getAttribute(ChartProperties.class);
                    chartProperties.setDirty(true);
                    settingsDialog.setRefresh(true);
                }

                if (ID != null) {
                    select.setItemCaption(ID, monitor.getName());
                    displayMonitorRecord(ID);
                    secondaryDialog.close();
                }

            } catch (EmptyValueException e) {
                return;
            } catch (InvalidValueException e) {
                return;
            } catch (Exception e) {
                ManagerUI.error(e.getMessage());
                return;
            }
        }
    });
    buttonsBar.addComponent(okButton);
    buttonsBar.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);

    VerticalLayout windowLayout = (VerticalLayout) secondaryDialog.getContent();
    windowLayout.setSpacing(false);
    windowLayout.setMargin(false);
    windowLayout.addComponent(formContainer);
    windowLayout.addComponent(buttonsBar);

}

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

License:Open Source License

/**
 * Instantiates a new node dialog./*w w w.j a  va  2 s.c o  m*/
 *
 * @param nodeInfo the node info
 * @param button the button
 */
public NodeDialog(NodeInfo nodeInfo, ComponentButton button) {
    this.button = button;

    String windowTitle = (nodeInfo != null) ? "Edit Node: " + nodeInfo.getName() : "Add Node";
    dialogWindow = new ModalWindow(windowTitle, (nodeInfo != null) ? "350px" : "650px");
    dialogWindow.addCloseListener(this);
    UI.getCurrent().addWindow(dialogWindow);

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

    if (nodeInfo == null) {
        SystemInfo systemInfo = VaadinSession.getCurrent().getAttribute(SystemInfo.class);
        this.nodeInfo = new NodeInfo(systemInfo.getCurrentID(), systemInfo.getCurrentSystem().getSystemType());
        nodeForm = new NodeForm(this.nodeInfo,
                "Add a Node to the System: " + systemInfo.getCurrentSystem().getName());
        saveNode("Add Node");
    } else {
        this.nodeInfo = nodeInfo;
        nodeForm = new NodeForm(nodeInfo, "Edit an existing Node");
        saveNode("Save Changes");
    }

    VerticalLayout windowLayout = (VerticalLayout) dialogWindow.getContent();
    windowLayout.setSpacing(false);
    windowLayout.setMargin(false);
    windowLayout.addComponent(nodeForm);
    windowLayout.addComponent(buttonsBar);

}

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

License:Open Source License

/**
 * Instantiates a new overview panel.//w  ww . ja va2  s .co  m
 */
public OverviewPanel() {

    HorizontalLayout overviewContainer = new HorizontalLayout();
    overviewContainer.addStyleName("overviewPanel");
    overviewContainer.setWidth("100%");
    setContent(overviewContainer);

    systemInfo = VaadinSession.getCurrent().getAttribute(SystemInfo.class);
    systemRecord = systemInfo.getCurrentSystem();
    systemLayout = new SystemLayout(systemRecord);
    overviewContainer.addComponent(systemLayout);

    VerticalLayout nodesSlot = new VerticalLayout();
    nodesSlot.addStyleName("nodesSlot");
    nodesSlot.setMargin(new MarginInfo(false, false, false, false));
    overviewContainer.addComponent(nodesSlot);
    overviewContainer.setExpandRatio(nodesSlot, 1.0f);

    final HorizontalLayout nodesHeader = new HorizontalLayout();
    nodesHeader.setStyleName("panelHeaderLayout");
    nodesHeader.setWidth("100%");
    nodesSlot.addComponent(nodesHeader);
    nodesLabel = new Label(" ");
    nodesLabel.setSizeUndefined();
    nodesHeader.addComponent(nodesLabel);
    nodesHeader.setComponentAlignment(nodesLabel, Alignment.MIDDLE_CENTER);
    nodesHeader.setExpandRatio(nodesLabel, 1.0f);

    final HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setSpacing(true);
    buttonsLayout.setMargin(new MarginInfo(false, true, false, false));
    nodesHeader.addComponent(buttonsLayout);
    nodesHeader.setComponentAlignment(buttonsLayout, Alignment.MIDDLE_RIGHT);

    addSystemButton = new Button("Add System...");
    addSystemButton.setDescription("Add System");
    addSystemButton.setVisible(false);
    buttonsLayout.addComponent(addSystemButton);
    addSystemButton.addClickListener(new Button.ClickListener() {

        public void buttonClick(ClickEvent event) {
            new SystemDialog(null, null);
        }
    });

    addNodeButton = new Button("Add Node...");
    addNodeButton.setDescription("Add Node to the current System");
    addNodeButton.setVisible(false);
    buttonsLayout.addComponent(addNodeButton);
    addNodeButton.addClickListener(new Button.ClickListener() {

        public void buttonClick(ClickEvent event) {
            new NodeDialog(null, null);
        }
    });

    final Button editButton = new Button("Edit");
    editButton.setDescription("Enter Editing mode");
    final Button saveButton = new Button("Done");
    saveButton.setDescription("Exit Editing mode");
    buttonsLayout.addComponent(editButton);

    editButton.addClickListener(new Button.ClickListener() {

        public void buttonClick(ClickEvent event) {
            buttonsLayout.replaceComponent(editButton, saveButton);
            isEditable = true;
            systemLayout.setEditable(true);
            nodesLayout.setEditable(true);
            nodesHeader.setStyleName("panelHeaderLayout-editable");
            if (systemRecord != null && !SystemInfo.SYSTEM_ROOT.equals(systemRecord.getID())) {
                addNodeButton.setVisible(true);
            } else {
                addSystemButton.setVisible(true);
            }
            if (systemRecord == null || (systemRecord != null && systemRecord.getNodes().length == 0)) {
                nodesLayout.placeholderLayout(null);
            }
        }
    });

    saveButton.addClickListener(new Button.ClickListener() {

        public void buttonClick(ClickEvent event) {
            buttonsLayout.replaceComponent(saveButton, editButton);
            isEditable = false;
            systemLayout.setEditable(false);
            nodesLayout.setEditable(false);
            nodesHeader.setStyleName("panelHeaderLayout");
            if (systemRecord != null && systemRecord.getNodes().length == 0) {
                nodesLayout.placeholderLayout(null);
            }
            addNodeButton.setVisible(false);
            addSystemButton.setVisible(false);
        }
    });

    Panel panel = new Panel();
    panel.setHeight(PANEL_HEIGHT, Unit.PIXELS);
    panel.addStyleName(Runo.PANEL_LIGHT);
    nodesSlot.addComponent(panel);

    nodesLayout = new NodesLayout(systemRecord);
    nodesLayout.addStyleName("nodesLayout");
    nodesLayout.setWidth("100%");
    panel.setContent(nodesLayout);

}

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

License:Open Source License

/**
 * Instantiates a new setup dialog.//from w  w w  .j  a v a2s . co  m
 */
public SetupDialog() {

    dialogWindow = new ModalWindow("Initial System Setup", "350px");
    dialogWindow.addCloseListener(this);
    UI.getCurrent().addWindow(dialogWindow);

    wrapper = new HorizontalLayout();
    wrapper.setWidth("100%");
    wrapper.setMargin(true);

    wrapper.addComponent(currentForm);

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

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

    nextForm();

}