Example usage for com.vaadin.ui Alignment MIDDLE_CENTER

List of usage examples for com.vaadin.ui Alignment MIDDLE_CENTER

Introduction

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

Prototype

Alignment MIDDLE_CENTER

To view the source code for com.vaadin.ui Alignment MIDDLE_CENTER.

Click Source Link

Usage

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

License:Open Source License

/**
 * Instantiates a new charts dialog.//from   ww w  .j  a  va  2  s .  com
 *
 * @param chartsLayout the charts layout
 * @param chartButton the chart button
 */
public ChartsDialog(final ChartsLayout chartsLayout, final ChartButton chartButton) {

    this.chartButton = chartButton;
    this.chartsLayout = chartsLayout;

    dialogWindow = new ModalWindow("Monitors to Chart mapping", "775px");

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

    UI.getCurrent().addWindow(dialogWindow);

    newUserChart = (chartButton != null) ? new UserChart((UserChart) chartButton.getData()) : newUserChart();

    ArrayList<String> monitorIDs = newUserChart.getMonitorIDs();
    MonitorsLayout monitorsLayout = new MonitorsLayout(monitorIDs);
    wrapper.addComponent(monitorsLayout);

    VerticalLayout separator = new VerticalLayout();
    separator.setSizeFull();
    Embedded rightArrow = new Embedded(null, new ThemeResource("img/right_arrow.png"));
    separator.addComponent(rightArrow);
    separator.setComponentAlignment(rightArrow, Alignment.MIDDLE_CENTER);
    wrapper.addComponent(separator);

    ChartPreviewLayout chartPreviewLayout = new ChartPreviewLayout(newUserChart, chartsLayout.getTime(),
            chartsLayout.getInterval());
    wrapper.addComponent(chartPreviewLayout);
    monitorsLayout.addChartPreview(chartPreviewLayout);

    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) {
            dialogWindow.close();
        }
    });

    Button okButton = new Button(chartButton != null ? "Save Changes" : "Add Chart");
    okButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            try {
                ChartButton newChartButton = new ChartButton(newUserChart);
                newChartButton.setChartsLayout(chartsLayout);
                newChartButton.setEditable(true);
                if (chartButton != null) {
                    chartsLayout.replaceComponent(chartButton, newChartButton);
                } else {
                    chartsLayout.addComponent(newChartButton);
                }

            } catch (Exception e) {
                ManagerUI.error(e.getMessage());
            }

            dialogWindow.close();
        }
    });
    buttonsBar.addComponent(okButton);
    buttonsBar.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);

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

}

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

License:Open Source License

/**
 * Instantiates a new backup scheduled layout.
 *///from   w  ww  .  ja  va  2s . c om
public BackupScheduledLayout() {

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

    HorizontalLayout scheduleRow = new HorizontalLayout();
    scheduleRow.setSpacing(true);
    addComponent(scheduleRow);

    final Label scheduleLabel = new Label("Schedule backups using the");
    scheduleLabel.setSizeUndefined();
    scheduleRow.addComponent(scheduleLabel);
    scheduleRow.setComponentAlignment(scheduleLabel, Alignment.MIDDLE_LEFT);

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

        public void buttonClick(Button.ClickEvent event) {
            if (schedule == null) {
                schedule = getSchedule();
            }
            new CalendarDialog(schedule, thisLayout);
        }
    });
    scheduleRow.addComponent(calendarButton);
    scheduleRow.setComponentAlignment(calendarButton, Alignment.MIDDLE_LEFT);

    final Label immediateLabel = new Label(
            "(To run an immediate backup, select a node first then switch to the Control panel)");
    immediateLabel.setSizeUndefined();
    scheduleRow.addComponent(immediateLabel);
    scheduleRow.setComponentAlignment(immediateLabel, Alignment.MIDDLE_CENTER);

    scheduledTable = new Table("Next Scheduled Backups");
    scheduledTable.setPageLength(5);
    // Start time, node
    scheduledTable.addContainerProperty("Start", String.class, null);
    scheduledTable.addContainerProperty("Node", String.class, null);
    scheduledTable.addContainerProperty("Level", String.class, null);
    scheduledTable.addContainerProperty("User", String.class, null);
    addComponent(scheduledTable);
    setComponentAlignment(scheduledTable, Alignment.MIDDLE_LEFT);

}

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

License:Open Source License

/**
 * Instantiates a new backup sets layout.
 *///from www .  j  a  va 2 s  .c  om
public BackupSetsLayout() {

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

    backupsTable = new Table("Existing Backup Sets");
    backupsTable.setPageLength(10);
    backupsTable.addContainerProperty("ID", String.class, null);
    backupsTable.addContainerProperty("Started", String.class, null);
    backupsTable.addContainerProperty("Completed", String.class, null);
    backupsTable.addContainerProperty("Restored", String.class, null);
    backupsTable.addContainerProperty("Level", String.class, null);
    backupsTable.addContainerProperty("Parent", String.class, null);
    backupsTable.addContainerProperty("Node", String.class, null);
    backupsTable.addContainerProperty("Size", String.class, null);
    backupsTable.addContainerProperty("Storage", String.class, null);
    backupsTable.addContainerProperty("State", String.class, null);
    backupsTable.addContainerProperty("Log", Link.class, null);

    addComponent(backupsTable);
    setComponentAlignment(backupsTable, Alignment.MIDDLE_CENTER);

}

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

License:Open Source License

/**
 * Instantiates a new component button.//w w  w .j av a  2  s .c  om
 *
 * @param componentInfo the component info
 */
public ComponentButton(ClusterComponent componentInfo) {
    thisButton = this;
    this.componentInfo = componentInfo;

    addStyleName("componentButton");

    componentInfo.setButton(this);
    setData(componentInfo);

    setHeight(COMPONENT_HEIGHT + 4, Unit.PIXELS);
    float componentWidth = (componentInfo.getType() == ClusterComponent.CCType.system) ? SYSTEM_WIDTH
            : NODE_WIDTH;
    setWidth(componentWidth + 8, Unit.PIXELS);

    imageLayout = new VerticalLayout();
    imageLayout.setHeight(COMPONENT_HEIGHT + 4, Unit.PIXELS);
    imageLayout.setWidth(componentWidth, Unit.PIXELS);
    //imageLayout.setMargin(new MarginInfo(true, true, false, true));
    imageLayout.setImmediate(true);

    if (componentInfo.getParentID() != null) {
        String icon = null;
        switch (componentInfo.getType()) {
        case system:
            icon = "system";
            break;

        case node:
            icon = NodeStates.getNodeIcon(componentInfo.getSystemType(), componentInfo.getState());
            break;

        default:
            // unknown component type
            break;
        }
        imageLayout.addStyleName(icon);
        //imageLayout.addStyleName(componentInfo.getType().toString());

        commandLabel = new Label();
        commandLabel.setSizeUndefined();
        imageLayout.addComponent(commandLabel);
        imageLayout.setComponentAlignment(commandLabel, Alignment.TOP_LEFT);
        //imageLayout.setExpandRatio(commandLabel, 1.0f);
        //            NodeInfo nodeInfo = (NodeInfo) componentInfo;
        //            TaskRecord taskRecord = nodeInfo.getTask();
        //            setCommandLabel(taskRecord);

        Label padding = new Label("");
        imageLayout.addComponent(padding);
        imageLayout.setComponentAlignment(padding, Alignment.MIDDLE_CENTER);

        HorizontalLayout iconsStrip = new HorizontalLayout();
        iconsStrip.addStyleName("componentInfo");
        iconsStrip.setWidth(componentInfo.getType() == ClusterComponent.CCType.node ? "60px" : "76px");
        imageLayout.addComponent(iconsStrip);
        imageLayout.setComponentAlignment(iconsStrip, Alignment.MIDDLE_CENTER);

        info = new Embedded(null, new ThemeResource("img/info.png"));
        iconsStrip.addComponent(info);
        iconsStrip.setComponentAlignment(info, Alignment.MIDDLE_LEFT);

        alert = new Embedded();
        alert.setVisible(false);
        iconsStrip.addComponent(alert);
        iconsStrip.setComponentAlignment(alert, Alignment.MIDDLE_RIGHT);

        nameLabel = new Label(componentInfo.getName());
        nameLabel.setStyleName("componentName");
        nameLabel.setSizeUndefined();
        imageLayout.addComponent(nameLabel);
        imageLayout.setComponentAlignment(nameLabel, Alignment.BOTTOM_CENTER);

    }
    addComponent(imageLayout);
    setComponentAlignment(imageLayout, Alignment.TOP_CENTER);
    setExpandRatio(imageLayout, 1.0f);

}

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

License:Open Source License

/**
 * Placeholder layout.//from   w ww .  j av  a  2 s .co m
 *
 * @param message the message
 */
public void placeholderLayout(String message) {

    if (placeholderLayout == null) {
        removeAllComponents();
        components = null;
    } else {
        removeComponent(placeholderLayout);
    }

    if (message != null) {
        this.message = message;
    } else {
        message = this.message;
    }

    placeholderLayout = new VerticalLayout();
    placeholderLayout.addStyleName("placeholderLayout");
    placeholderLayout.setHeight(ComponentButton.COMPONENT_HEIGHT, Unit.PIXELS);

    Label placeholderLabel = new Label("No " + message + " available");
    placeholderLabel.addStyleName("instructions");
    placeholderLabel.setSizeUndefined();
    placeholderLayout.addComponent(placeholderLabel);
    placeholderLayout.setComponentAlignment(placeholderLabel, Alignment.MIDDLE_CENTER);

    Label placeholderLabel2 = new Label(
            isEditable ? "Press \"Add...\" to add new " + message + ", then \"Done\" when finished"
                    : "Press \"Edit\" to begin adding " + message);
    placeholderLabel2.addStyleName("instructions");
    placeholderLabel2.setSizeUndefined();
    placeholderLayout.addComponent(placeholderLabel2);
    placeholderLayout.setComponentAlignment(placeholderLabel2, Alignment.MIDDLE_CENTER);

    addComponent(placeholderLayout);
    setComponentAlignment(placeholderLayout, Alignment.MIDDLE_CENTER);

    setStyleName(getStyleName().replace("network", ""));

}

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

License:Open Source License

/**
 * Refresh./*from   w w  w  .j a v  a  2s .co  m*/
 *
 * @param updaterThread the updater thread
 * @param parentSystemRecord the parent system record
 */
public synchronized void refresh(final OverviewPanel.UpdaterThread updaterThread,
        final SystemRecord parentSystemRecord) {

    VaadinSession session = getSession();
    if (session == null) {
        session = VaadinSession.getCurrent();
    }
    if (session == null) {
        return;
    }
    ManagerUI managerUI = session.getAttribute(ManagerUI.class);
    SystemInfo systemInfo = session.getAttribute(SystemInfo.class);
    OverviewPanel overviewPanel = session.getAttribute(OverviewPanel.class);

    if (parentSystemRecord == null) {
        systemID = null;
        placeholderLayout("Systems");
        return;
    } else if (parentSystemRecord.getNodes().length == 0) {
        placeholderLayout("Components");
        return;
    } else {
        if (placeholderLayout != null) {
            removeComponent(placeholderLayout);
            placeholderLayout = null;

            addStyleName("network");
        }
    }

    String[] newComponents = parentSystemRecord.getNodes();
    if (!parentSystemRecord.getID().equals(systemID)
            || (newComponents != null && !Arrays.equals(newComponents, components))) {
        systemID = parentSystemRecord.getID();
        components = newComponents;

        ManagerUI.log("Reload Components");

        String currentSelectedID = null;
        CCType currentSelectedType = null;
        ClusterComponent currentClusterComponent = session.getAttribute(ClusterComponent.class);
        if (currentClusterComponent != null) {
            currentSelectedID = currentClusterComponent.getID();
            currentSelectedType = currentClusterComponent.getType();
        }

        session.lock();
        try {

            // Here the UI is locked and can be updated
            ManagerUI.log("NodesLayout access run() removeall");
            removeAllComponents();

            ArrayList<ComponentButton> newButtons = new ArrayList<ComponentButton>();
            for (String componentID : parentSystemRecord.getNodes()) {

                final ClusterComponent clusterComponent;
                if (parentSystemRecord.getParentID() == null) {
                    // this is the ROOT record, where "nodes" is really the flat list of systems
                    clusterComponent = systemInfo.getSystemRecord(componentID);
                } else {
                    // this is a normal System record
                    clusterComponent = new NodeInfo(parentSystemRecord.getID(),
                            parentSystemRecord.getSystemType());
                    clusterComponent.setID(componentID);
                }

                //               if (updaterThread.flagged) {
                //                  ManagerUI.log("NodesLayout - flagged is set while adding nodes");
                //                  return;
                //               }

                ComponentButton button = clusterComponent.getButton();
                if (button == null) {
                    ManagerUI.log("NodesLayout access run() button not in component");
                    button = findButton(clusterComponent);
                }
                if (button == null) {
                    ManagerUI.log("NodesLayout access run() button not found");
                    button = new ComponentButton(clusterComponent);
                }
                addComponent(button);
                setComponentAlignment(button, Alignment.MIDDLE_CENTER);
                button.setEditable(isEditable);
                if (clusterComponent.getID().equals(currentSelectedID)
                        && clusterComponent.getType().equals(currentSelectedType) && !button.isSelected()) {
                    overviewPanel.clickLayout(button, true);
                }
                newButtons.add(button);
            }
            buttons = newButtons;
        } finally {
            session.unlock();
        }

    }

    //      if (updaterThread.flagged) {
    //         ManagerUI.log("NodesLayout - flagged is set after removeall");
    //         return;
    //      }

    ManagerUI.log("NodesLayout - before for loop - buttons: " + buttons.size());

    for (final ComponentButton button : buttons) {
        final ClusterComponent currentComponent = (ClusterComponent) button.getData();

        final ClusterComponent newComponent;

        switch (currentComponent.getType()) {
        case system:
            newComponent = systemInfo.updateSystem(currentComponent.getID());
            break;

        case node:
            NodeInfo nodeInfo = (NodeInfo) currentComponent;
            newComponent = new NodeInfo(nodeInfo.getParentID(), nodeInfo.getSystemType(), nodeInfo.getID());
            break;

        default:
            continue;
        }

        //         if (updaterThread.flagged) {
        //            ManagerUI.log("NodesLayout - flagged is set before run() ");
        //            return;
        //         }

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

                ManagerUI.log("NodesLayout access run() button " + newComponent.getName());

                String newName = newComponent.getName();
                if (newName != null && !newName.equals(currentComponent.getName())) {
                    button.setName(newName);
                    currentComponent.setName(newName);
                }

                String newState = newComponent.getState();
                currentComponent.setState(newState);

                String toolTip = null;
                switch (newComponent.getType()) {
                case system:
                    toolTip = ((SystemRecord) newComponent).ToolTip();
                    break;
                case node:
                    MonitorLatest monitorLatest = newComponent.getMonitorLatest();
                    String newCapacity = monitorLatest.getData().get(MonitorNames.capacity.name());
                    button.setIcon(currentComponent.getType().toString(), newState, newCapacity);

                    NodeInfo nodeInfo = (NodeInfo) newComponent;
                    toolTip = nodeInfo.ToolTip();
                    // carry over RunningTask(s)
                    nodeInfo.setCommandTask(((NodeInfo) currentComponent).getCommandTask());
                    button.setCommandLabel(nodeInfo.getTask());
                    break;
                default:
                    toolTip = "Unknown component type";
                    ManagerUI.error(toolTip);
                    break;
                }
                button.setDescription(toolTip);
                button.setData(newComponent);
                if (button.isSelected()) {
                    getSession().setAttribute(ClusterComponent.class, newComponent);
                }
            }
        });

    } // for all nodes

}

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

License:Open Source License

/**
 * Instantiates a new parameters layout.
 *
 * @param runningTask the running task/*from   w w  w  .  j av a2 s.co  m*/
 * @param nodeInfo the node info
 * @param commandEnum the command enum
 */
public ParametersLayout(final RunningTask runningTask, final NodeInfo nodeInfo, Commands.Command commandEnum) {
    this.runningTask = runningTask;

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

    params = new HashMap<String, String>();
    runningTask.selectParameter(params);

    switch (commandEnum) {
    case backup:
        backupLevel = new OptionGroup("Backup Level");
        backupLevel.setImmediate(true);
        backupLevel.addItem(BackupRecord.BACKUP_TYPE_FULL);
        backupLevel.setItemCaption(BackupRecord.BACKUP_TYPE_FULL, "Full");
        backupLevel.addItem(BackupRecord.BACKUP_TYPE_INCREMENTAL);
        backupLevel.setItemCaption(BackupRecord.BACKUP_TYPE_INCREMENTAL, "Incremental");
        addComponent(backupLevel);
        setComponentAlignment(backupLevel, Alignment.MIDDLE_LEFT);
        backupLevel.addValueChangeListener(new ValueChangeListener() {
            private static final long serialVersionUID = 0x4C656F6E6172646FL;

            public void valueChange(ValueChangeEvent event) {
                String level = (String) event.getProperty().getValue();
                params.put(PARAM_BACKUP_TYPE, level);
                if (level.equals(BackupRecord.BACKUP_TYPE_INCREMENTAL)) {
                    addComponent(prevBackupsLayout);
                    selectPrevBackup.select(firstItem);
                } else {
                    params.remove(PARAM_BACKUP_PARENT);
                    if (getComponentIndex(prevBackupsLayout) != -1) {
                        removeComponent(prevBackupsLayout);
                    }
                }
            }
        });

        backupLevel.setValue(BackupRecord.BACKUP_TYPE_FULL);
        isParameterReady = true;

    case restore:
        VerticalLayout restoreLayout = new VerticalLayout();
        restoreLayout.setSpacing(true);

        if (commandEnum == Command.restore) {
            addComponent(restoreLayout);
            FormLayout formLayout = new FormLayout();
            //formLayout.setMargin(new MarginInfo(false, false, true, false));
            formLayout.setMargin(false);
            restoreLayout.addComponent(formLayout);

            final NativeSelect selectSystem;
            selectSystem = new NativeSelect("Backups from");
            selectSystem.setImmediate(true);
            selectSystem.setNullSelectionAllowed(false);
            SystemInfo systemInfo = VaadinSession.getCurrent().getAttribute(SystemInfo.class);
            for (SystemRecord systemRecord : systemInfo.getSystemsMap().values()) {
                if (!systemRecord.getID().equals(SystemInfo.SYSTEM_ROOT)) {
                    selectSystem.addItem(systemRecord.getID());
                    selectSystem.setItemCaption(systemRecord.getID(), systemRecord.getName());
                }
            }
            selectSystem.select(systemInfo.getCurrentID());
            formLayout.addComponent(selectSystem);
            selectSystem.addValueChangeListener(new ValueChangeListener() {
                private static final long serialVersionUID = 0x4C656F6E6172646FL;

                public void valueChange(ValueChangeEvent event) {
                    String systemID = (String) event.getProperty().getValue();
                    Backups backups = new Backups(systemID, null);
                    backupsList = backups.getBackupsList();
                    selectPrevBackup.removeAllItems();
                    firstItem = null;
                    if (backupsList != null && backupsList.size() > 0) {
                        Collection<BackupRecord> set = backupsList.values();
                        Iterator<BackupRecord> iter = set.iterator();
                        while (iter.hasNext()) {
                            BackupRecord backupRecord = iter.next();
                            String backupID = backupRecord.getID();
                            selectPrevBackup.addItem(backupID);
                            selectPrevBackup.setItemCaption(backupID,
                                    "ID: " + backupID + ", " + backupRecord.getStarted());
                            if (firstItem == null) {
                                firstItem = backupID;
                                selectPrevBackup.select(firstItem);
                            }
                        }
                        runningTask.getControlsLayout().enableControls(true, Controls.Run);
                    } else {
                        if (backupInfoLayout != null) {
                            displayBackupInfo(backupInfoLayout, new BackupRecord());
                        }
                        runningTask.getControlsLayout().enableControls(false, Controls.Run);
                    }
                }
            });
        }
        prevBackupsLayout = new HorizontalLayout();
        restoreLayout.addComponent(prevBackupsLayout);

        selectPrevBackup = (commandEnum == Command.backup) ? new ListSelect("Backups") : new ListSelect();
        selectPrevBackup.setImmediate(true);
        selectPrevBackup.setNullSelectionAllowed(false);
        selectPrevBackup.setRows(8); // Show a few items and a scrollbar if there are more
        selectPrevBackup.setWidth("20em");
        prevBackupsLayout.addComponent(selectPrevBackup);
        final Backups backups = new Backups(nodeInfo.getParentID(), null);
        //*** this is for when we only want backups from a specific node
        // backupsList = backups.getBackupsForNode(nodeInfo.getID());
        backupsList = backups.getBackupsList();
        if (backupsList != null && backupsList.size() > 0) {
            Collection<BackupRecord> set = backupsList.values();
            Iterator<BackupRecord> iter = set.iterator();
            while (iter.hasNext()) {
                BackupRecord backupRecord = iter.next();
                selectPrevBackup.addItem(backupRecord.getID());
                selectPrevBackup.setItemCaption(backupRecord.getID(),
                        "ID: " + backupRecord.getID() + ", " + backupRecord.getStarted());
                if (firstItem == null) {
                    firstItem = backupRecord.getID();
                }
            }

            backupInfoLayout = new VerticalLayout();
            backupInfoLayout.setSpacing(false);
            backupInfoLayout.setMargin(new MarginInfo(false, true, false, true));
            prevBackupsLayout.addComponent(backupInfoLayout);
            prevBackupsLayout.setComponentAlignment(backupInfoLayout, Alignment.MIDDLE_CENTER);

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

                public void valueChange(ValueChangeEvent event) {
                    String backupID = (String) event.getProperty().getValue();
                    if (backupID == null) {
                        isParameterReady = false;
                        runningTask.getControlsLayout().enableControls(isParameterReady, Controls.Run);
                        return;
                    }
                    BackupRecord backupRecord = backupsList.get(backupID);
                    displayBackupInfo(backupInfoLayout, backupRecord);
                    if (backupLevel != null) {
                        // we're doing a backup
                        params.put(PARAM_BACKUP_PARENT, backupRecord.getID());
                    } else {
                        // we're doing a restore
                        params.put(PARAM_BACKUP_ID, backupRecord.getID());
                    }
                    isParameterReady = true;
                    ScriptingControlsLayout controlsLayout = runningTask.getControlsLayout();
                    if (controlsLayout != null) {
                        controlsLayout.enableControls(isParameterReady, Controls.Run);
                    }
                }
            });

            // final DisplayBackupRecord displayRecord = new
            // DisplayBackupRecord(parameterLayout);

            if (commandEnum == Command.restore) {
                restoreLayout.addComponent(prevBackupsLayout);
                selectPrevBackup.select(firstItem);
            }

        } else {
            // no previous backups
            if (commandEnum == Command.backup) {
                backupLevel.setEnabled(false);
                isParameterReady = true;
            } else if (commandEnum == Command.restore) {
                //runningTask.getControlsLayout().enableControls(false, Controls.run);
            }
        }
        break;

    case connect:
        VerticalLayout connectLayout = new VerticalLayout();
        addComponent(connectLayout);

        final Validator validator = new Password2Validator(connectPassword);

        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);
                boolean isValid;
                if (runningTask.getControlsLayout() != null) {
                    if (usePassword) {
                        isValid = connectPassword.isValid();
                    } else {
                        isValid = connectKey.isValid();
                    }
                    if (isValid) {
                        connectParamsListener.valueChange(null);
                    } else {
                        form.setComponentError(null);
                        form.setValidationVisible(false);
                        runningTask.getControlsLayout().enableControls(false, Controls.Run);
                    }
                }
            }
        });
        connectLayout.addComponent(passwordOption);
        passwordOption.select(false);

        connectLayout.addComponent(form);
        form.setImmediate(true);
        form.setFooter(null);
        Layout layout = form.getLayout();

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

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

        form.addField("connectKey", connectKey);
        connectKey.setStyleName("sshkey");
        connectKey.setColumns(41);
        connectKey.setImmediate(true);
        connectKey.setRequiredError("SSH Key is a required field");
        connectKey.addValueChangeListener(connectParamsListener);
        break;

    default:
        isParameterReady = true;
        break;

    }

}

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

License:Open Source License

/**
 * Instantiates a new scripting controls layout.
 *
 * @param runningTask the running task/*from ww w. j  ava 2 s  .  co m*/
 * @param controls the controls
 */
public ScriptingControlsLayout(final RunningTask runningTask, Controls[] controls) {

    addStyleName("scriptingControlsLayout");
    setSizeUndefined();
    setSpacing(true);
    setMargin(true);

    for (Controls control : controls) {
        final Button button = new Button(control.name());
        button.setImmediate(true);
        button.setEnabled(false);
        button.setData(control);
        addComponent(button);
        setComponentAlignment(button, Alignment.MIDDLE_CENTER);
        ctrlButtons.put(control.name(), button);
        button.addClickListener(new Button.ClickListener() {
            private static final long serialVersionUID = 0x4C656F6E6172646FL;

            public void buttonClick(ClickEvent event) {
                event.getButton().setEnabled(false);
                runningTask.controlClicked((Controls) event.getButton().getData());
            }
        });
    }

}

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

License:Open Source License

/**
 * Instantiates a new scripting progress layout.
 *
 * @param runningTask the running task//from   ww  w.  jav  a 2 s.  co m
 * @param observerMode the observer mode
 */
public ScriptingProgressLayout(final RunningTask runningTask, boolean observerMode) {
    this.runningTask = runningTask;
    this.observerMode = observerMode;

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

    progressLayout = new VerticalLayout();
    progressLayout.setSpacing(true);
    addComponent(progressLayout);

    scriptLabel = new Label("");
    scriptLabel.addStyleName("instructions");
    progressLayout.addComponent(scriptLabel);
    progressLayout.setComponentAlignment(scriptLabel, Alignment.TOP_CENTER);

    progressIconsLayout = new HorizontalLayout();
    progressIconsLayout.addStyleName("progressIconsLayout");
    progressLayout.addComponent(progressIconsLayout);
    progressLayout.setComponentAlignment(progressIconsLayout, Alignment.MIDDLE_CENTER);

    progressLabel = new Label("");
    progressLabel.setImmediate(true);
    progressLayout.addComponent(progressLabel);
    progressLayout.setComponentAlignment(progressLabel, Alignment.BOTTOM_CENTER);

    resultLayout = new VerticalLayout();
    resultLayout.addStyleName("scriptingResultsLayout");
    resultLayout.setSizeFull();
    resultLayout.setSpacing(true);
    resultLayout.setMargin(true);
    addComponent(resultLayout);
    //setComponentAlignment(resultLayout, Alignment.MIDDLE_LEFT);

    resultLabel = new Label(observerMode ? "Running" : "Has not run yet", ContentMode.HTML);
    resultLabel.addStyleName("instructions");
    resultLabel.setImmediate(true);
    resultLayout.addComponent(resultLabel);
    resultLayout.setComponentAlignment(resultLabel, Alignment.MIDDLE_CENTER);

}

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

License:Open Source License

/**
 * Sets the error info.//from   ww  w .j  av  a  2 s.  com
 *
 * @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);
}