Example usage for com.vaadin.ui Button addClickListener

List of usage examples for com.vaadin.ui Button addClickListener

Introduction

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

Prototype

public Registration addClickListener(ClickListener listener) 

Source Link

Document

Adds the button click listener.

Usage

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

License:Open Source License

/**
 * Instantiates a new monitors settings.
 *
 * @param settingsDialog the settings dialog
 * @param systemID the system id//  w w  w  .  j a v  a  2 s . com
 * @param systemType the system type
 */
MonitorsSettings(SettingsDialog settingsDialog, String systemID, String systemType) {
    this.settingsDialog = settingsDialog;
    this.systemID = systemID;
    this.systemType = systemType;

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

    HorizontalLayout selectLayout = new HorizontalLayout();
    addComponent(selectLayout);
    selectLayout.setSizeFull();
    selectLayout.setSpacing(true);

    Monitors.reloadMonitors();
    monitorsAll = Monitors.getMonitorsList(systemType);

    select = new ListSelect("Monitors");
    select.setImmediate(true);
    for (MonitorRecord monitor : monitorsAll.values()) {
        String id = monitor.getID();
        select.addItem(id);
        select.setItemCaption(id, monitor.getName());
    }
    select.setNullSelectionAllowed(false);
    selectLayout.addComponent(select);
    select.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {
            String monitorID = (String) event.getProperty().getValue();
            displayMonitorRecord(monitorID);
            MonitorRecord monitor = monitorsAll.get(monitorID);
            if (monitor != null) {
                String monitorType = monitor.getType();

                for (Monitors.EditableMonitorType editable : EditableMonitorType.values()) {
                    if (editable.name().equals(monitorType)) {
                        editMonitor.setEnabled(true);
                        break;
                    }
                }
            }
        }
    });

    selectLayout.addLayoutClickListener(new LayoutClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void layoutClick(LayoutClickEvent event) {

            Component child;
            if (event.isDoubleClick() && (child = event.getChildComponent()) != null
                    && (child instanceof ListSelect)) {
                // Get the child component which was double-clicked
                ListSelect select = (ListSelect) child;
                String monitorID = (String) select.getValue();
                MonitorRecord monitor = monitorsAll.get(monitorID);
                String monitorType = monitor.getType();
                for (Monitors.EditableMonitorType editable : EditableMonitorType.values()) {
                    if (editable.name().equals(monitorType)) {
                        editMonitor(monitor);
                        break;
                    }
                }
            }
        }
    });

    monitorLayout = new FormLayout();
    selectLayout.addComponent(monitorLayout);
    selectLayout.setExpandRatio(monitorLayout, 1.0f);
    monitorLayout.setSpacing(false);

    id.setCaption("ID:");
    monitorLayout.addComponent(id);
    name.setCaption("Name:");
    monitorLayout.addComponent(name);
    description.setCaption("Description:");
    monitorLayout.addComponent(description);
    unit.setCaption("Unit:");
    monitorLayout.addComponent(unit);
    // type.setCaption("Type:");
    // monitorLayout.addComponent(type);
    delta.setCaption("Is Delta:");
    monitorLayout.addComponent(delta);
    average.setCaption("Is Average:");
    monitorLayout.addComponent(average);
    chartType.setCaption("Chart Type:");
    monitorLayout.addComponent(chartType);
    interval.setCaption("Interval:");
    monitorLayout.addComponent(interval);
    sql.setCaption("Statement:");
    monitorLayout.addComponent(sql);

    HorizontalLayout selectButtons = new HorizontalLayout();
    selectButtons.setSizeFull();
    addComponent(selectButtons);
    selectButtons.setSpacing(true);

    Button addMonitor = new Button("Add...");
    selectButtons.addComponent(addMonitor);
    selectButtons.setComponentAlignment(addMonitor, Alignment.MIDDLE_LEFT);
    addMonitor.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            addMonitor();
        }
    });

    deleteMonitor = new Button("Delete");
    deleteMonitor.setEnabled(false);
    selectButtons.addComponent(deleteMonitor);
    selectButtons.setComponentAlignment(deleteMonitor, Alignment.MIDDLE_LEFT);
    deleteMonitor.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            String monitorID = (String) select.getValue();
            if (monitorID != null) {
                deleteMonitor(monitorsAll.get(monitorID));
            }
        }
    });

    editMonitor = new Button("Edit...");
    editMonitor.setEnabled(false);
    selectButtons.addComponent(editMonitor);
    selectButtons.setComponentAlignment(editMonitor, Alignment.MIDDLE_CENTER);
    selectButtons.setExpandRatio(editMonitor, 1.0f);
    editMonitor.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            String monitorID = (String) select.getValue();
            if (monitorID != null) {
                editMonitor(monitorsAll.get(monitorID));
            }
        }
    });

}

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

License:Open Source License

/**
 * Monitor form.// w w  w . j  a  va  2 s . com
 *
 * @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

/**
 * Save node./*from w  w  w  .j  a  v  a2s  . c om*/
 *
 * @param okButtonCaption the ok button caption
 */
private void saveNode(final String okButtonCaption) {

    final Button okButton = new Button(okButtonCaption);
    final 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) {
            windowClose(null);
        }
    });

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

        public void buttonClick(ClickEvent event) {
            if (nodeForm.validateNode()) {
                if (nodeInfo.save()) {
                    if (button != null) {
                        button.setName(nodeInfo.getName());
                        button.setDescription(nodeInfo.ToolTip());
                        if (button.isSelected()) {
                            TabbedPanel tabbedPanel = VaadinSession.getCurrent()
                                    .getAttribute(TabbedPanel.class);
                            tabbedPanel.refresh();
                        }
                    } else {
                        OverviewPanel overviewPanel = VaadinSession.getCurrent()
                                .getAttribute(OverviewPanel.class);
                        overviewPanel.refresh();
                    }
                    windowClose(null);

                    if (nodeForm.runConnect) {
                        UserObject userObject = VaadinSession.getCurrent().getAttribute(UserObject.class);
                        String userID = userObject.getUserID();
                        APIrestful api = new APIrestful();
                        String password = nodeForm.connectPassword.getValue();
                        String sshkey = nodeForm.connectKey.getValue();
                        if (!password.isEmpty() || !sshkey.isEmpty()) {
                            Map<String, String> params = new HashMap<String, String>();
                            Encryption encryption = new Encryption();
                            if (nodeForm.usePassword) {
                                params.put(ParametersLayout.PARAM_CONNECT_ROOTPASSWORD,
                                        encryption.encrypt(password, APIrestful.getKey()));
                            } else {
                                params.put(ParametersLayout.PARAM_CONNECT_SSHKEY,
                                        encryption.encrypt(sshkey, APIrestful.getKey()));
                            }
                            TaskRun taskRun = new TaskRun(nodeInfo.getParentID(), nodeInfo.getID(), userID,
                                    "connect", params, null);
                        }
                    }
                }
            }

        }
    });

    buttonsBar.addComponent(okButton);
    buttonsBar.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);

}

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

License:Open Source License

/**
 * Instantiates a new overview panel.//from   www  . j a v a  2  s  .c om
 */
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.PanelInfo.java

License:Open Source License

/**
 * Creates the charts layout./*from  w  w w.j  a  va  2s.co m*/
 */
private void createChartsLayout() {

    chartsLayout = new VerticalLayout();
    chartsLayout.addStyleName("chartsLayout");
    chartsLayout.setHeight("100%");
    chartsLayout.setSpacing(true);
    addComponent(chartsLayout);

    final HorizontalLayout chartsHeaderLayout = new HorizontalLayout();
    chartsHeaderLayout.setStyleName("panelHeaderLayout");
    chartsHeaderLayout.setWidth("100%");
    chartsHeaderLayout.setSpacing(true);
    chartsHeaderLayout.setMargin(new MarginInfo(false, true, false, true));
    chartsLayout.addComponent(chartsHeaderLayout);

    chartControls = new ChartControls();
    chartControls.addIntervalSelectionListener(chartIntervalListener);
    chartControls.addThemeSelectionListener(chartThemeListener);
    chartsHeaderLayout.addComponent(chartControls);
    chartsHeaderLayout.setComponentAlignment(chartControls, Alignment.MIDDLE_LEFT);

    final HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setSpacing(true);
    chartsHeaderLayout.addComponent(buttonsLayout);
    chartsHeaderLayout.setComponentAlignment(buttonsLayout, Alignment.MIDDLE_RIGHT);

    SettingsDialog settingsDialog = new SettingsDialog("Edit Monitors...", "Monitors");
    final Button editMonitorsButton = settingsDialog.getButton();
    editMonitorsButton.setVisible(false);
    buttonsLayout.addComponent(editMonitorsButton);

    final Button addChartButton = new Button("Add Chart...");
    addChartButton.setVisible(false);
    buttonsLayout.addComponent(addChartButton);
    addChartButton.addClickListener(new Button.ClickListener() {

        public void buttonClick(ClickEvent event) {
            new ChartsDialog(chartsArrayLayout, 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);
            chartsArrayLayout.setDragMode(LayoutDragMode.CLONE);
            chartsArrayLayout.setEditable(true);
            chartsHeaderLayout.setStyleName("panelHeaderLayout-editable");
            editMonitorsButton.setVisible(true);
            addChartButton.setVisible(true);
            OverviewPanel overviewPanel = getSession().getAttribute(OverviewPanel.class);
            overviewPanel.setEnabled(false);

        }
    });

    saveButton.addClickListener(new Button.ClickListener() {

        public void buttonClick(ClickEvent event) {
            buttonsLayout.replaceComponent(saveButton, editButton);
            chartsArrayLayout.setDragMode(LayoutDragMode.NONE);
            chartsArrayLayout.setEditable(false);
            chartsHeaderLayout.setStyleName("panelHeaderLayout");
            editMonitorsButton.setVisible(false);
            addChartButton.setVisible(false);
            OverviewPanel overviewPanel = getSession().getAttribute(OverviewPanel.class);
            overviewPanel.setEnabled(true);
            refresh();
        }
    });

    final Button expandButton = new NativeButton();
    expandButton.setStyleName("expandButton");
    expandButton.setDescription("Expand/Reduce viewing area");
    buttonsLayout.addComponent(expandButton);
    buttonsLayout.setComponentAlignment(expandButton, Alignment.MIDDLE_CENTER);
    expandButton.addClickListener(new Button.ClickListener() {

        public void buttonClick(ClickEvent event) {
            isExpanded = !isExpanded;

            AnimatorProxy proxy = getSession().getAttribute(AnimatorProxy.class);
            proxy.addListener(new AnimationListener() {
                public void onAnimation(AnimationEvent event) {
                    Component component = event.getComponent();
                    component.setVisible(isExpanded ? false : true);
                }
            });
            //            OverviewPanel overviewPanel = getSession().getAttribute(OverviewPanel.class);
            //            if (!isExpanded) {
            //               overviewPanel.setVisible(isExpanded ? false : true);
            //            }
            //            proxy.animate(overviewPanel, isExpanded ? AnimType.ROLL_UP_CLOSE : AnimType.ROLL_DOWN_OPEN).setDuration(500).setDelay(100);
            //
            //            TopPanel topPanel = getSession().getAttribute(TopPanel.class);
            //            if (!isExpanded) {
            //               topPanel.setVisible(isExpanded ? false : true);
            //            }
            //            proxy.animate(topPanel, isExpanded ? AnimType.ROLL_UP_CLOSE : AnimType.ROLL_DOWN_OPEN).setDuration(500).setDelay(100);

            VerticalLayout topMid = getSession().getAttribute(VerticalLayout.class);
            if (!isExpanded) {
                topMid.setVisible(isExpanded ? false : true);
            }
            proxy.animate(topMid, isExpanded ? AnimType.ROLL_UP_CLOSE : AnimType.ROLL_DOWN_OPEN)
                    .setDuration(500).setDelay(100);

            expandButton.setStyleName(isExpanded ? "contractButton" : "expandButton");
        }
    });

    chartsPanel = new Panel();
    chartsPanel.setSizeFull();
    chartsPanel.addStyleName(Runo.PANEL_LIGHT);
    chartsLayout.addComponent(chartsPanel);
    chartsLayout.setExpandRatio(chartsPanel, 1.0f);

}

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

License:Open Source License

/**
 * Add user.//  ww  w  .j a  v  a2  s. c  o  m
 */
private void inputUser() {

    final Button finishedButton = new Button("Add User");

    final UserObject user = new UserObject();
    final UserForm userForm = new UserForm(null, user, "Add User to the System", finishedButton);
    wrapper.replaceComponent(currentForm, userForm);
    currentForm = userForm;

    buttonsBar.addComponent(finishedButton);
    buttonsBar.setComponentAlignment(finishedButton, Alignment.MIDDLE_RIGHT);

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

        public void buttonClick(ClickEvent event) {
            if (userForm.validateUser() && user.set()) {
                VaadinSession.getCurrent().setAttribute(UserObject.class, user);
                nextForm();
            }
        }
    });

}

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

License:Open Source License

/**
 * Save system.//from   ww w .java  2s .  c o m
 *
 * @param okButtonCaption the ok button caption
 */
private void saveSystem(final String okButtonCaption) {

    commitButton.setCaption(okButtonCaption);
    final 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) {
            windowClose(null);
        }
    });

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

        public void buttonClick(ClickEvent event) {
            if (systemForm.validateSystem()) {
                if (systemRecord.save()) {
                    if (button != null) {
                        button.setName(systemRecord.getName());
                        button.setDescription(systemRecord.ToolTip());
                        if (button.isSelected()) {
                            TabbedPanel tabbedPanel = VaadinSession.getCurrent()
                                    .getAttribute(TabbedPanel.class);
                            tabbedPanel.refresh();
                        }
                    } else {
                        OverviewPanel overviewPanel = VaadinSession.getCurrent()
                                .getAttribute(OverviewPanel.class);
                        overviewPanel.refresh();
                    }
                    windowClose(null);
                }
            }

        }
    });

    buttonsBar.addComponent(commitButton);
    buttonsBar.setComponentAlignment(commitButton, Alignment.MIDDLE_RIGHT);

}

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

License:Open Source License

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

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

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

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

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

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

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

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

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

}

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

License:Open Source License

/**
 * Save user.//  w  w w.  j a  v  a2s  .c o m
 *
 * @param commitButtonCaption the commit button caption
 */
private void saveUser(final String commitButtonCaption) {

    final 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) {
            windowClose(null);
        }
    });

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

        public void buttonClick(ClickEvent event) {
            if (userForm.validateUser()) {
                boolean success = userInfo.setUser(userObject);
                if (success) {
                    if (isAdding) {
                        usersSettings.addToSelect(userObject.getUserID());
                    } else {
                        usersSettings.updateUserName(userObject.getUserID());
                    }
                    windowClose(null);
                } else {
                    return;
                }

            }

        }
    });

    buttonsBar.addComponent(commitButton);
    buttonsBar.setComponentAlignment(commitButton, Alignment.MIDDLE_RIGHT);

}

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

License:Open Source License

/**
 * Instantiates a new users settings./*  w w w .j  a v a2  s. c  o  m*/
 */
UsersSettings() {
    addStyleName("usersTab");
    setSizeFull();
    setSpacing(true);
    setMargin(true);

    UserObject currentUser = VaadinSession.getCurrent().getAttribute(UserObject.class);
    currentUserID = currentUser.getUserID();

    HorizontalLayout usersLayout = new HorizontalLayout();
    addComponent(usersLayout);
    usersLayout.setSizeFull();
    usersLayout.setSpacing(true);

    // make sure we're working with current info
    userInfo = new UserInfo(null);
    VaadinSession.getCurrent().setAttribute(UserInfo.class, userInfo);

    select = new ListSelect("Users");
    select.setImmediate(true);
    for (UserObject user : userInfo.getUsersList().values()) {
        String id = user.getUserID();
        select.addItem(id);
        if (id.equals(currentUserID)) {
            select.select(id);
            userName.setValue(user.getName());
            selectedUserID = id;
        }
    }
    select.setNullSelectionAllowed(false);
    select.setWidth("14em");
    usersLayout.addComponent(select);
    select.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {

            selectedUserID = (String) event.getProperty().getValue();

            if (selectedUserID == null || selectedUserID.equals(currentUserID)) {
                removeUser.setEnabled(false);
            } else {
                removeUser.setEnabled(true);
            }

            if (selectedUserID == null) {
                editUser.setEnabled(false);
                userName.setEnabled(false);
                userName.setValue("");
            } else {
                editUser.setEnabled(true);
                userName.setValue(userInfo.findNameByID(selectedUserID));
                userName.setEnabled(true);
            }
        }
    });

    usersLayout.addLayoutClickListener(new LayoutClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void layoutClick(LayoutClickEvent event) {

            Component child;
            if (event.isDoubleClick() && (child = event.getChildComponent()) != null
                    && (child instanceof ListSelect)) {
                // Get the child component which was double-clicked
                ListSelect select = (ListSelect) child;
                String userID = (String) select.getValue();
                new UserDialog(userInfo, userInfo.getUsersList().get(selectedUserID), thisObject);
            }
        }
    });

    userLayout = new FormLayout();
    usersLayout.addComponent(userLayout);
    usersLayout.setExpandRatio(userLayout, 1.0f);
    userLayout.setSpacing(false);

    userName.setCaption("Full Name:");
    userLayout.addComponent(userName);

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

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

        public void buttonClick(ClickEvent event) {
            new UserDialog(userInfo, null, thisObject);
        }
    });
    userButtonsLayout.addComponent(addUser);
    userButtonsLayout.setComponentAlignment(addUser, Alignment.MIDDLE_LEFT);

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

        public void buttonClick(ClickEvent event) {
            removeUser(event);
        }
    });
    userButtonsLayout.addComponent(removeUser);
    userButtonsLayout.setComponentAlignment(removeUser, Alignment.MIDDLE_LEFT);

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

        public void buttonClick(ClickEvent event) {
            new UserDialog(userInfo, userInfo.getUsersList().get(selectedUserID), thisObject);
        }
    });
    userButtonsLayout.addComponent(editUser);
    userButtonsLayout.setComponentAlignment(editUser, Alignment.MIDDLE_CENTER);

}