Example usage for com.vaadin.ui HorizontalLayout setSizeFull

List of usage examples for com.vaadin.ui HorizontalLayout setSizeFull

Introduction

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

Prototype

@Override
    public void setSizeFull() 

Source Link

Usage

From source file:com.peergreen.example.webconsole.extensions.ConfirmDialogExtension.java

License:Open Source License

public ConfirmDialogExtension() {
    setSizeFull();/*from  w  ww.  ja v a  2  s.c om*/
    setSpacing(true);
    setMargin(true);

    Link showCodeSource = new Link("Show code source",
            new ExternalResource(GitHubClassURL.getURL(ConfirmDialogExtension.class)));
    showCodeSource.setTargetName("_blank");
    addComponent(showCodeSource);
    setComponentAlignment(showCodeSource, Alignment.TOP_RIGHT);

    Label title = new Label("Drag and drop components from a panel to another");
    title.addStyleName("h1");
    addComponent(title);
    setComponentAlignment(title, Alignment.MIDDLE_CENTER);

    HorizontalLayout row = new HorizontalLayout();
    row.setSizeFull();
    row.setSpacing(true);
    row.setMargin(true);

    VerticalLayout leftPanel = new VerticalLayout();
    leftPanel.setSpacing(true);
    leftPanel.addStyleName("dashed-area");
    leftPanel.addComponent(getDraggableComponent(new Label("Label")));
    leftPanel.addComponent(getDraggableComponent(new Button("Button")));
    DragAndDropWrapper leftPanelWrapper = new DragAndDropWrapper(leftPanel);
    row.addComponent(leftPanelWrapper);
    row.setComponentAlignment(leftPanelWrapper, Alignment.TOP_LEFT);

    VerticalLayout rightPanel = new VerticalLayout();
    rightPanel.setSpacing(true);
    rightPanel.addStyleName("dashed-area");
    DragAndDropWrapper rightPanelWrapper = new DragAndDropWrapper(rightPanel);
    row.addComponent(rightPanelWrapper);
    row.setComponentAlignment(rightPanelWrapper, Alignment.TOP_RIGHT);

    leftPanelWrapper.setDropHandler(new ConfirmDialogExtensionDropHandler(rightPanel, leftPanel));
    rightPanelWrapper.setDropHandler(new ConfirmDialogExtensionDropHandler(leftPanel, rightPanel));

    addComponent(row);
    setExpandRatio(row, 1.5f);
}

From source file:com.peergreen.webconsole.core.exception.ExceptionView.java

License:Open Source License

public ExceptionView(Exception ex) {

    setSizeFull();/*from   w  ww  .j  ava  2  s.com*/
    addStyleName("dashboard-view");

    HorizontalLayout top = new HorizontalLayout();
    top.setWidth("100%");
    top.setSpacing(true);
    top.addStyleName("toolbar");
    addComponent(top);
    final Label title = new Label("Oops ! A problem occurred when drawing this view");
    title.setSizeUndefined();
    title.addStyleName("h1");
    top.addComponent(title);
    top.setComponentAlignment(title, Alignment.MIDDLE_LEFT);
    top.setExpandRatio(title, 1);

    HorizontalLayout row = new HorizontalLayout();
    row.setSizeFull();
    row.setMargin(new MarginInfo(true, true, false, true));
    row.setSpacing(true);
    addComponent(row);
    setExpandRatio(row, 1.5f);

    Table t = new Table();
    t.setCaption("Stack trace");
    t.addContainerProperty("<p style=\"display:none\">Stack</p>", String.class, null);
    t.setWidth("100%");
    t.setImmediate(true);
    t.addStyleName("plain");
    t.addStyleName("borderless");
    t.setSortEnabled(false);
    t.setImmediate(true);
    t.setSizeFull();

    int i = 1;
    t.addItem(new Object[] { ex.toString() }, i++);
    for (StackTraceElement element : ex.getStackTrace()) {
        t.addItem(new Object[] { element.toString() }, i++);
    }
    CssLayout panel = new CssLayout();
    panel.addStyleName("layout-panel");
    panel.setSizeFull();

    panel.addComponent(t);

    row.addComponent(panel);
}

From source file:com.peergreen.webconsole.scope.deployment.internal.deploymentplan.DeploymentPlanPanel.java

License:Open Source License

@PostConstruct
public void init() {
    setSizeFull();/*from   w w  w . j  a  v  a 2s. co m*/

    TreeTable table = new TreeTable();

    VerticalLayout mainContent = new VerticalLayout();
    mainContent.setSpacing(true);
    mainContent.setMargin(true);
    mainContent.setStyleName("deployable-style");
    mainContent.setSizeFull();

    setContent(mainContent);

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

    // Deployment Plan name
    Label deploymentPlanNameLabel = new Label("Plan");
    toolBar.addComponent(deploymentPlanNameLabel);
    toolBar.setExpandRatio(deploymentPlanNameLabel, 1);

    deploymentPlanName = new TextField();
    deploymentPlanName.setInputPrompt(getDefaultName());
    deploymentPlanName.setWidth("100%");
    toolBar.addComponent(deploymentPlanName);
    toolBar.setComponentAlignment(deploymentPlanName, Alignment.TOP_LEFT);
    toolBar.setExpandRatio(deploymentPlanName, 3);

    error = new Label("", ContentMode.HTML);
    error.addStyleName("error");
    error.setSizeUndefined();
    error.addStyleName("light");
    error.addStyleName("v-animate-reveal");
    error.setVisible(false);
    toolBar.addComponent(error);
    toolBar.setComponentAlignment(error, Alignment.TOP_RIGHT);
    toolBar.setExpandRatio(error, 1);
    mainContent.addComponent(toolBar);
    mainContent.setComponentAlignment(toolBar, Alignment.TOP_LEFT);
    mainContent.setExpandRatio(toolBar, 1);

    VerticalLayout deploymentPlanContainer = new VerticalLayout();
    DragAndDropWrapper deploymentPlanContainerWrapper = new DragAndDropWrapper(deploymentPlanContainer);
    DropHandler deploymentPlanDropHandler = new DeploymentDropHandler(deploymentViewManager, this,
            notifierService);
    deploymentPlanContainerWrapper.setDropHandler(deploymentPlanDropHandler);
    deploymentPlanContainerWrapper.setSizeFull();
    mainContent.addComponent(deploymentPlanContainerWrapper);
    mainContent.setExpandRatio(deploymentPlanContainerWrapper, 10);

    container.addContainerProperty(TREE_ITEM_ID, String.class, null);
    table.setSizeFull();
    table.setImmediate(true);
    table.setMultiSelect(true);
    table.setSelectable(true);
    table.setContainerDataSource(container);
    table.setDragMode(Table.TableDragMode.MULTIROW);
    table.setItemCaptionPropertyId(TREE_ITEM_ID);
    table.setCellStyleGenerator(new ItemStyle(DeployableContainerType.DEPLOYED));
    table.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
    table.setDropHandler(new OrderedContainerDropHandler(table, deploymentPlanDropHandler));
    table.addShortcutListener(new ShortcutListener("Delete", ShortcutAction.KeyCode.DELETE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            Table table = (Table) target;
            Collection<DeployableEntry> deployableEntries = (Collection<DeployableEntry>) table.getValue();
            for (DeployableEntry deployableEntry : deployableEntries) {
                removeDeployable(deployableEntry);
            }
        }
    });
    deploymentPlanContainer.addComponent(table);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setSizeFull();
    footer.setSpacing(true);
    footer.setMargin(true);
    footer.addStyleName("footer");
    footer.setWidth("100%");

    deployIt = new CheckBox("Deploy this deployment plan");
    footer.addComponent(deployIt);
    footer.setComponentAlignment(deployIt, Alignment.TOP_LEFT);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.setMargin(true);
    Button cancel = new Button("Cancel");
    cancel.addClickListener(new CancelButtonListener());
    Button create = new Button("Create");
    create.addClickListener(new CreateButtonListener());
    create.addStyleName("wide");
    create.addStyleName("default");
    buttons.addComponent(cancel);
    buttons.addComponent(create);
    footer.addComponent(buttons);
    footer.setComponentAlignment(buttons, Alignment.TOP_RIGHT);

    mainContent.addComponent(footer);
    mainContent.setComponentAlignment(footer, Alignment.BOTTOM_RIGHT);
    mainContent.setExpandRatio(footer, 1);
}

From source file:com.peergreen.webconsole.scope.home.HomeScope.java

License:Open Source License

public HomeScope() {
    setSizeFull();/*from w ww. ja va2 s .  c  o m*/
    addStyleName("dashboard-view");

    HorizontalLayout top = new HorizontalLayout();
    top.setWidth("100%");
    top.setSpacing(true);
    addComponent(top);
    Label title = new Label("Welcome to Peergreen Administration Console");
    title.addStyleName("h1");
    top.addComponent(title);
    top.setComponentAlignment(title, Alignment.MIDDLE_LEFT);
    top.setExpandRatio(title, 1);

    HorizontalLayout row1 = new HorizontalLayout();
    row1.setSizeFull();
    row1.setMargin(new MarginInfo(true, true, true, true));
    row1.setSpacing(true);
    row1.addStyleName("row");
    addComponent(row1);
    setExpandRatio(row1, 4);

    HorizontalLayout row2 = new HorizontalLayout();
    row2.setSizeFull();
    row2.setMargin(new MarginInfo(true, true, true, true));
    row2.setSpacing(true);
    row2.addStyleName("row");
    addComponent(row2);
    setExpandRatio(row2, 4);

    topLeftFrame = new FrameView();
    row1.addComponent(topLeftFrame);

    topRightFrame = new FrameView();
    row1.addComponent(topRightFrame);

    bottomLeftFrame = new FrameView();
    row2.addComponent(bottomLeftFrame);

    bottomRightFrame = new FrameView();
    row2.addComponent(bottomRightFrame);
}

From source file:com.purebred.core.view.MainEntryPoint.java

License:Open Source License

@PostConstruct
@Override/*w  ww  .  j  av a  2  s . c om*/
public void postConstruct() {
    super.postConstruct();

    labelDepot.putEntityLabel(getEntityType().getName(), getEntityCaption());

    HorizontalLayout searchAndLogout = new HorizontalLayout();
    searchAndLogout.setSizeFull();
    searchAndLogout.addComponent(getSearchForm());

    logoutButton = new Button(null);
    logoutButton.setDescription(uiMessageSource.getMessage("mainApplication.logout"));
    logoutButton.setSizeUndefined();
    logoutButton.addStyleName("borderless");
    logoutButton.setIcon(new ThemeResource("icons/16/logout.png"));

    searchAndLogout.addComponent(logoutButton);
    searchAndLogout.setComponentAlignment(logoutButton, Alignment.TOP_RIGHT);

    addComponent(searchAndLogout);
    addComponent(getResults());
}

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

License:Open Source License

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

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

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

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

    UI.getCurrent().addWindow(dialogWindow);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

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

License:Open Source License

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

From source file:com.skysql.manager.ui.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 .  c om
 * @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  ww .ja va 2s  . c  o  m*/
 *
 * @param monitor the monitor
 * @param title the title
 * @param description the description
 * @param button the button
 */
public void monitorForm(final MonitorRecord monitor, String title, String description, String button) {
    final TextField monitorName = new TextField("Monitor Name");
    final TextField monitorDescription = new TextField("Description");
    final TextField monitorUnit = new TextField("Measurement Unit");
    final TextArea monitorSQL = new TextArea("SQL Statement");
    final CheckBox monitorDelta = new CheckBox("Is Delta");
    final CheckBox monitorAverage = new CheckBox("Is Average");
    final NativeSelect validationTarget = new NativeSelect("Validate SQL on");
    final NativeSelect monitorInterval = new NativeSelect("Sampling interval");
    final NativeSelect monitorChartType = new NativeSelect("Default display");

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

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

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

    String value;

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

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

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

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

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

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

    }

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

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

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

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

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

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

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

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

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

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

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

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

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

        public void buttonClick(ClickEvent event) {
            form.discard();
            secondaryDialog.close();
        }
    });

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

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

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

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

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

}

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

License:Open Source License

/**
 * Instantiates a new users settings.//  w  w w .  j a v  a2s .co 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);

}