Example usage for com.vaadin.server VaadinSession getCurrent

List of usage examples for com.vaadin.server VaadinSession getCurrent

Introduction

In this page you can find the example usage for com.vaadin.server VaadinSession getCurrent.

Prototype

public static VaadinSession getCurrent() 

Source Link

Document

Gets the currently used session.

Usage

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

License:Open Source License

/**
 * Refresh code./*from ww w  .  ja v a 2s.c  om*/
 *
 * @param chartButton the chart button
 * @param updaterThread the updater thread
 */
public void refreshCode(ChartButton chartButton, UpdaterThread updaterThread) {
    String systemID, nodeID;

    VaadinSession session = getSession();
    if (session == null) {
        session = VaadinSession.getCurrent();
    }
    ManagerUI managerUI = session.getAttribute(ManagerUI.class);
    ClusterComponent componentInfo = session.getAttribute(ClusterComponent.class);

    switch (componentInfo.getType()) {
    case system:
        systemID = componentInfo.getID();
        nodeID = SystemInfo.SYSTEM_NODEID;
        break;

    case node:
        systemID = componentInfo.getParentID();
        nodeID = componentInfo.getID();
        break;

    default:
        return;
    }

    final UserChart userChart = (UserChart) chartButton.getData();
    final Chart chart = chartButton.getChart();
    boolean needsRedraw = false;
    String[] timeStamps = null;
    final Configuration configuration = chart.getConfiguration();

    for (String monitorID : userChart.getMonitorIDs()) {

        if (updaterThread != null && updaterThread.flagged) {
            ManagerUI.log(this.getClass().getName() + " - flagged is set before API call");
            return;
        }

        ManagerUI.log("ChartsLayout - redraw loop MonitorID: " + monitorID);
        final MonitorRecord monitor = Monitors.getMonitor(monitorID);
        if (monitor == null) {
            // monitor was removed from the system: skip
            ManagerUI.log("monitor was removed from the system");
            continue;
        }

        MonitorData monitorData = (MonitorData) userChart.getMonitorData(monitor.getID());
        if (monitorData == null) {
            String method;
            if (UserChart.ChartType.LineChart.name().equals(userChart.getType())) {
                method = MonitorData.METHOD_AVG;
            } else if (UserChart.ChartType.AreaChart.name().equals(userChart.getType())) {
                method = MonitorData.METHOD_MINMAX;
            } else {
                continue; // unknown chart type, skip
            }
            monitorData = new MonitorData(monitor, systemID, nodeID, time, interval, userChart.getPoints(),
                    method);
            needsRedraw = true;
        } else if (monitorData.update(systemID, nodeID, time, interval, userChart.getPoints()) == true) {
            // data in chart needs to be updated
            needsRedraw = true;
        } else {
            continue; // no update needed
        }

        if (timeStamps == null) {
            DateConversion dateConversion = session.getAttribute(DateConversion.class);

            ArrayList<Long> unixTimes = monitorData.getTimeStamps();
            if (unixTimes != null) {
                timeStamps = new String[unixTimes.size()];
                int timeSpacer = unixTimes.size() / 15;
                for (int x = 0; x < unixTimes.size(); x++) {
                    timeStamps[x] = (x % timeSpacer != 0) ? "\u00A0"
                            : dateConversion.stampToString(unixTimes.get(x));
                }
            }
        }

        if (updaterThread != null && updaterThread.flagged) {
            ManagerUI.log("ChartsLayout - flagged is set before UI redraw");
            return;
        }

        final MonitorData finalMonitorData = monitorData;
        final String finalMonitorID = monitorID;

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

                ManagerUI.log("ChartsLayout access run() monitorID: " + finalMonitorID);

                if (UserChart.ChartType.LineChart.name().equals(userChart.getType())) {

                    ListSeries ls = null, testLS;
                    List<Series> lsList = configuration.getSeries();
                    Iterator seriesIter = lsList.iterator();
                    while (seriesIter.hasNext()) {
                        testLS = (ListSeries) seriesIter.next();
                        if (testLS.getName().equals(monitor.getName())) {
                            ls = testLS;
                            break;
                        }
                    }
                    if (ls == null) {
                        ls = new ListSeries(monitor.getName());
                        configuration.addSeries(ls);
                    }

                    userChart.setMonitorData(monitor.getID(), finalMonitorData);

                    ArrayList<Number> avgList = finalMonitorData.getAvgPoints();
                    ls.setData(avgList);

                } else if (UserChart.ChartType.AreaChart.name().equals(userChart.getType())) {

                    RangeSeries rs = null, testRS;
                    List<Series> lsList = configuration.getSeries();
                    Iterator seriesIter = lsList.iterator();
                    while (seriesIter.hasNext()) {
                        testRS = (RangeSeries) seriesIter.next();
                        if (testRS.getName().equals(monitor.getName())) {
                            rs = testRS;
                            break;
                        }
                    }
                    if (rs == null) {
                        rs = new RangeSeries(monitor.getName());
                        configuration.addSeries(rs);
                    }

                    userChart.setMonitorData(monitor.getID(), finalMonitorData);

                    ArrayList<Number> minList = finalMonitorData.getMinPoints();
                    ArrayList<Number> maxList = finalMonitorData.getMaxPoints();

                    if (minList != null && maxList != null && minList.size() > 0 && maxList.size() > 0
                            && minList.size() == maxList.size()) {
                        Object[] minArray = finalMonitorData.getMinPoints().toArray();
                        Object[] maxArray = finalMonitorData.getMaxPoints().toArray();

                        Number[][] dataList = new Number[minList.size()][2];
                        for (int x = 0; x < minList.size(); x++) {
                            dataList[x][0] = (Number) minArray[x];
                            dataList[x][1] = (Number) maxArray[x];
                        }

                        rs.setRangeData(dataList);
                    } else {
                        rs.setRangeData(new Number[0][0]);
                    }

                }

            }
        });

    } // for

    final boolean finalNeedsRedraw = needsRedraw;
    final String[] finalTimeStamps = timeStamps;
    final ChartButton finalChartButton = chartButton;

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

            if (finalNeedsRedraw) {
                ManagerUI.log("ChartsLayout needsRedraw");

                if (finalTimeStamps != null) {
                    XAxis xAxis = configuration.getxAxis();
                    Labels labels = new Labels();
                    labels.setRotation(-45);
                    labels.setAlign(HorizontalAlign.RIGHT);
                    xAxis.setLabels(labels);
                    xAxis.setCategories(finalTimeStamps);
                }

                chart.drawChart(configuration);
                finalChartButton.setVisible(true);
            }

        }
    });

}

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

License:Open Source License

/**
 * Refresh./*from  w  w  w  . j  a v  a  2s.  c  o 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  a  v a  2 s  . c o  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.ScriptingProgressLayout.java

License:Open Source License

/**
 * Builds the progress./*from w  w w  . ja v a  2s.  c om*/
 *
 * @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.components.ScriptingProgressLayout.java

License:Open Source License

/**
 * Asynch refresh.//from w w w . j a  v  a 2  s . c  o m
 *
 * @param updaterThread the updater thread
 */
private void asynchRefresh(final UpdaterThread updaterThread) {

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

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

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

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

            ManagerUI.log(this.getClass().getName() + " access run(): ");

            DateConversion dateConversion = session.getAttribute(DateConversion.class);

            String stateString;
            if ((stateString = taskRecord.getState()) == null) {
                return; // we're waiting for something to happen
            }
            CommandStates.States state = CommandStates.States.valueOf(stateString);
            setResult(CommandStates.getDescriptions().get(state.name()));

            String indexString;
            if ((indexString = taskRecord.getIndex()) == null) {
                return; // we're waiting for something to happen
            }
            int index = (state == States.done) ? totalSteps - 1 : Integer.parseInt(indexString) - 1;

            while (lastProgressIndex < index) {
                taskImages[lastProgressIndex].setSource(new ThemeResource("img/scripting/past.png"));
                lastProgressIndex++;
            }

            if (index >= 0) {
                switch (state) {
                case running:
                    taskImages[index].setSource(new ThemeResource("img/scripting/active.png"));
                    setProgress(taskImages[index].getDescription());
                    break;
                case done:
                    taskImages[index].setSource(new ThemeResource("img/scripting/past.png/"));
                    break;
                case error:
                case missing:
                    taskImages[index].setSource(new ThemeResource("img/scripting/error.png"));
                    break;
                case cancelled:
                case stopped:
                    taskImages[index].setSource(new ThemeResource("img/scripting/error.png"));
                    break;
                default:
                    break;
                }
            }

            setResult(CommandStates.getDescriptions().get(state.name()));

            switch (state) {
            case running:
                break;
            case error:
            case missing:
                setErrorInfo(taskRecord.getError());
            case done:
            case cancelled:
            case stopped:
            default:
                runningTask.close();
                break;

            }
        }
    });

}

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

License:Open Source License

/**
 * Instantiates a new general settings./*from   w  ww  . j  a  v  a  2  s.c o  m*/
 *
 * @param settingsDialog the settings dialog
 */
GeneralSettings(SettingsDialog settingsDialog) {
    this.settingsDialog = settingsDialog;

    addStyleName("generalTab");
    setWidth("458px");
    setSpacing(false);

    VerticalLayout layout = new VerticalLayout();
    layout.setWidth("100%");
    addComponent(layout);

    final Label separator = new Label("<hr>", ContentMode.HTML);

    userObject = VaadinSession.getCurrent().getAttribute(UserObject.class);

    //layout.addComponent(backupsLayout());
    //layout.addComponent(separator);
    layout.addComponent(timeLayout());
    //layout.addComponent(separator);
    //layout.addComponent(commandsLayout());

}

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

License:Open Source License

/**
 * Backups layout.// w w w.j  a v  a 2s . c  om
 *
 * @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./* w ww.j a va2  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.MonitorsSettings.java

License:Open Source License

/**
 * Monitor form.//from w w w  . j  av a  2 s .  c om
 *
 * @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./*from w w  w .jav a  2 s.  com*/
 *
 * @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);

}