Example usage for com.vaadin.ui Button setVisible

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

Introduction

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

Prototype

@Override
    public void setVisible(boolean visible) 

Source Link

Usage

From source file:org.ikasan.dashboard.ui.topology.component.CategorisedErrorTab.java

License:BSD License

public Layout createCategorisedErrorLayout() {
    this.categorizedErrorOccurenceTable = new FilterTable();
    this.categorizedErrorOccurenceTable.setSizeFull();
    this.categorizedErrorOccurenceTable.addContainerProperty("", Label.class, null);
    this.categorizedErrorOccurenceTable.setColumnExpandRatio("", .03f);
    this.categorizedErrorOccurenceTable.addContainerProperty("Module Name", String.class, null);
    this.categorizedErrorOccurenceTable.setColumnExpandRatio("Module Name", .15f);
    this.categorizedErrorOccurenceTable.addContainerProperty("Flow Name", String.class, null);
    this.categorizedErrorOccurenceTable.setColumnExpandRatio("Flow Name", .18f);
    this.categorizedErrorOccurenceTable.addContainerProperty("Component Name", String.class, null);
    this.categorizedErrorOccurenceTable.setColumnExpandRatio("Component Name", .2f);
    this.categorizedErrorOccurenceTable.addContainerProperty("Error Message", String.class, null);
    this.categorizedErrorOccurenceTable.setColumnExpandRatio("Error Message", .33f);
    this.categorizedErrorOccurenceTable.addContainerProperty("Timestamp", String.class, null);
    this.categorizedErrorOccurenceTable.setColumnExpandRatio("Timestamp", .1f);

    this.categorizedErrorOccurenceTable.addStyleName("wordwrap-table");
    this.categorizedErrorOccurenceTable.addStyleName(ValoTheme.TABLE_NO_STRIPES);

    //      this.categorizedErrorOccurenceTable.setFilterBarVisible(true);

    this.categorizedErrorOccurenceTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override/*ww  w . ja  va2 s. c om*/
        public void itemClick(ItemClickEvent itemClickEvent) {
            CategorisedErrorOccurrence errorOccurrence = (CategorisedErrorOccurrence) itemClickEvent
                    .getItemId();
            CategorisedErrorOccurrenceViewWindow errorOccurrenceViewWindow = new CategorisedErrorOccurrenceViewWindow(
                    errorOccurrence, serialiserFactory);

            UI.getCurrent().addWindow(errorOccurrenceViewWindow);
        }
    });

    this.categorizedErrorOccurenceTable.setCellStyleGenerator(new CustomTable.CellStyleGenerator() {
        @Override
        public String getStyle(CustomTable source, Object itemId, Object propertyId) {

            CategorisedErrorOccurrence categorisedErrorOccurrence = (CategorisedErrorOccurrence) itemId;

            if (propertyId == null) {
                // Styling for row         

                if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.TRIVIAL)) {
                    return "ikasan-green-small";
                } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.MAJOR)) {
                    return "ikasan-green-small";
                } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.CRITICAL)) {
                    return "ikasan-orange-small";
                } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.BLOCKER)) {
                    return "ikasan-red-small";
                }
            }

            if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                    .equals(ErrorCategorisation.TRIVIAL)) {
                return "ikasan-green-small";
            } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                    .equals(ErrorCategorisation.MAJOR)) {
                return "ikasan-green-small";
            } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                    .equals(ErrorCategorisation.CRITICAL)) {
                return "ikasan-orange-small";
            } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                    .equals(ErrorCategorisation.BLOCKER)) {
                return "ikasan-red-small";
            }

            return "ikasan-small";
        }
    });

    Button searchButton = new Button("Search");
    searchButton.setStyleName(ValoTheme.BUTTON_SMALL);
    searchButton.addClickListener(new Button.ClickListener() {
        @SuppressWarnings("unchecked")
        public void buttonClick(ClickEvent event) {
            categorizedErrorOccurenceTable.removeAllItems();

            ArrayList<String> modulesNames = null;

            if (errorOccurenceModules.getItemIds().size() > 0) {
                modulesNames = new ArrayList<String>();
                for (Object module : errorOccurenceModules.getItemIds()) {
                    modulesNames.add(((Module) module).getName());
                }
            }

            ArrayList<String> flowNames = null;

            if (errorOccurenceFlows.getItemIds().size() > 0) {
                flowNames = new ArrayList<String>();
                for (Object flow : errorOccurenceFlows.getItemIds()) {
                    flowNames.add(((Flow) flow).getName());
                }
            }

            ArrayList<String> componentNames = null;

            if (errorOccurenceComponents.getItemIds().size() > 0) {
                componentNames = new ArrayList<String>();
                for (Object component : errorOccurenceComponents.getItemIds()) {
                    componentNames.add(((Component) component).getName());
                }
            }

            if (modulesNames == null && flowNames == null && componentNames == null
                    && !((BusinessStream) businessStreamCombo.getValue()).getName().equals("All")) {
                BusinessStream businessStream = ((BusinessStream) businessStreamCombo.getValue());

                modulesNames = new ArrayList<String>();

                for (BusinessStreamFlow flow : businessStream.getFlows()) {
                    modulesNames.add(flow.getFlow().getModule().getName());
                }
            }

            String errorCategory = null;

            if (errorCategoryCombo != null && errorCategoryCombo.getValue() != null) {
                errorCategory = (String) errorCategoryCombo.getValue();
            }

            List<CategorisedErrorOccurrence> categorisedErrorOccurences = errorCategorisationService
                    .findCategorisedErrorOccurences(modulesNames, flowNames, componentNames, "", "",
                            errorCategory, errorFromDate.getValue(), errorToDate.getValue());

            for (CategorisedErrorOccurrence categorisedErrorOccurrence : categorisedErrorOccurences) {
                ErrorOccurrence errorOccurrence = categorisedErrorOccurrence.getErrorOccurrence();

                Date date = new Date(errorOccurrence.getTimestamp());
                SimpleDateFormat format = new SimpleDateFormat("yyyy MM dd HH:mm:ss");
                String timestamp = format.format(date);

                Label categoryLabel = new Label();

                if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.BLOCKER)) {
                    categoryLabel = new Label(VaadinIcons.BAN.getHtml(), ContentMode.HTML);
                } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.CRITICAL)) {
                    categoryLabel = new Label(VaadinIcons.EXCLAMATION.getHtml(), ContentMode.HTML);
                } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.MAJOR)) {
                    categoryLabel = new Label(VaadinIcons.ARROW_UP.getHtml(), ContentMode.HTML);
                } else if (categorisedErrorOccurrence.getErrorCategorisation().getErrorCategory()
                        .equals(ErrorCategorisation.TRIVIAL)) {
                    categoryLabel = new Label(VaadinIcons.ARROW_DOWN.getHtml(), ContentMode.HTML);
                }

                categorizedErrorOccurenceTable
                        .addItem(
                                new Object[] { categoryLabel, errorOccurrence.getModuleName(),
                                        errorOccurrence.getFlowName(), errorOccurrence.getFlowElementName(),
                                        categorisedErrorOccurrence.getErrorCategorisation()
                                                .getErrorDescription(),
                                        timestamp },
                                categorisedErrorOccurrence);
            }
        }
    });

    Button clearButton = new Button("Clear");
    clearButton.setStyleName(ValoTheme.BUTTON_SMALL);
    clearButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            errorOccurenceModules.removeAllItems();
            errorOccurenceFlows.removeAllItems();
            errorOccurenceComponents.removeAllItems();
        }
    });

    GridLayout layout = new GridLayout(1, 6);
    layout.setMargin(false);
    layout.setHeight(270, Unit.PIXELS);

    GridLayout listSelectLayout = new GridLayout(3, 1);
    listSelectLayout.setSpacing(true);
    listSelectLayout.setSizeFull();

    errorOccurenceModules.setIcon(VaadinIcons.ARCHIVE);
    errorOccurenceModules.addContainerProperty("Module Name", String.class, null);
    errorOccurenceModules.addContainerProperty("", Button.class, null);
    errorOccurenceModules.setSizeFull();
    errorOccurenceModules.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceModules.setDragMode(TableDragMode.ROW);
    errorOccurenceModules.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            final DataBoundTransferable t = (DataBoundTransferable) dropEvent.getTransferable();

            if (t.getItemId() instanceof Module) {
                final Module module = (Module) t.getItemId();
                logger.info("sourceContainer.getText(): " + module.getName());

                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceModules.removeItem(module);
                    }
                });

                errorOccurenceModules.addItem(new Object[] { module.getName(), deleteButton }, module);

                for (final Flow flow : module.getFlows()) {
                    deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            errorOccurenceFlows.removeItem(flow);
                        }
                    });

                    errorOccurenceFlows.addItem(new Object[] { flow.getName(), deleteButton }, flow);

                    for (final Component component : flow.getComponents()) {
                        deleteButton = new Button();
                        deleteButton.setIcon(VaadinIcons.TRASH);
                        deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                        deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                        // Add the delete functionality to each role that is added
                        deleteButton.addClickListener(new Button.ClickListener() {
                            public void buttonClick(ClickEvent event) {
                                errorOccurenceComponents.removeItem(component);
                            }
                        });

                        errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton },
                                component);
                    }
                }
            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });

    listSelectLayout.addComponent(errorOccurenceModules, 0, 0);

    errorOccurenceFlows.setIcon(VaadinIcons.AUTOMATION);
    errorOccurenceFlows.addContainerProperty("Flow Name", String.class, null);
    errorOccurenceFlows.addContainerProperty("", Button.class, null);
    errorOccurenceFlows.setSizeFull();
    errorOccurenceFlows.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceFlows.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            final DataBoundTransferable t = (DataBoundTransferable) dropEvent.getTransferable();

            if (t.getItemId() instanceof Flow) {
                final Flow flow = (Flow) t.getItemId();
                logger.info("sourceContainer.getText(): " + flow.getName());

                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceFlows.removeItem(flow);
                    }
                });

                errorOccurenceFlows.addItem(new Object[] { flow.getName(), deleteButton }, flow);

                for (final Component component : flow.getComponents()) {
                    deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            errorOccurenceComponents.removeItem(component);
                        }
                    });

                    errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton },
                            component);
                }
            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });

    listSelectLayout.addComponent(errorOccurenceFlows, 1, 0);

    errorOccurenceComponents.setIcon(VaadinIcons.COG);
    errorOccurenceComponents.setSizeFull();
    errorOccurenceComponents.addContainerProperty("Component Name", String.class, null);
    errorOccurenceComponents.addContainerProperty("", Button.class, null);
    errorOccurenceComponents.setCellStyleGenerator(new IkasanCellStyleGenerator());
    errorOccurenceComponents.setSizeFull();
    errorOccurenceComponents.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceComponents.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            final DataBoundTransferable t = (DataBoundTransferable) dropEvent.getTransferable();

            if (t.getItemId() instanceof Component) {
                final Component component = (Component) t.getItemId();
                logger.info("sourceContainer.getText(): " + component.getName());

                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceComponents.removeItem(component);
                    }
                });

                errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton }, component);

            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });
    listSelectLayout.addComponent(this.errorOccurenceComponents, 2, 0);

    errorCategoryCombo = new ComboBox("Error Category");
    errorCategoryCombo.setNullSelectionAllowed(true);
    errorCategoryCombo.addItem(ErrorCategorisation.TRIVIAL);
    errorCategoryCombo.setItemIcon(ErrorCategorisation.TRIVIAL, VaadinIcons.ARROW_DOWN);
    errorCategoryCombo.addItem(ErrorCategorisation.MAJOR);
    errorCategoryCombo.setItemIcon(ErrorCategorisation.MAJOR, VaadinIcons.ARROW_UP);
    errorCategoryCombo.addItem(ErrorCategorisation.CRITICAL);
    errorCategoryCombo.setItemIcon(ErrorCategorisation.CRITICAL, VaadinIcons.EXCLAMATION_CIRCLE_O);
    errorCategoryCombo.addItem(ErrorCategorisation.BLOCKER);
    errorCategoryCombo.setItemIcon(ErrorCategorisation.BLOCKER, VaadinIcons.BAN);

    GridLayout dateSelectLayout = new GridLayout(3, 1);
    dateSelectLayout.addComponent(errorCategoryCombo, 2, 0);
    dateSelectLayout.setSizeFull();
    errorFromDate = new PopupDateField("From date");
    errorFromDate.setResolution(Resolution.MINUTE);
    errorFromDate.setValue(this.getMidnightToday());
    dateSelectLayout.addComponent(errorFromDate, 0, 0);
    errorToDate = new PopupDateField("To date");
    errorToDate.setResolution(Resolution.MINUTE);
    errorToDate.setValue(this.getTwentyThreeFixtyNineToday());
    dateSelectLayout.addComponent(errorToDate, 1, 0);

    final VerticalSplitPanel vSplitPanel = new VerticalSplitPanel();
    vSplitPanel.setHeight("95%");

    GridLayout searchLayout = new GridLayout(2, 1);
    searchLayout.setSpacing(true);
    searchLayout.addComponent(searchButton, 0, 0);
    searchLayout.addComponent(clearButton, 1, 0);

    final Button hideFilterButton = new Button();
    hideFilterButton.setIcon(VaadinIcons.MINUS);
    hideFilterButton.setCaption("Hide Filter");
    hideFilterButton.setStyleName(ValoTheme.BUTTON_LINK);
    hideFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);

    final Button showFilterButton = new Button();
    showFilterButton.setIcon(VaadinIcons.PLUS);
    showFilterButton.setCaption("Show Filter");
    showFilterButton.addStyleName(ValoTheme.BUTTON_LINK);
    showFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);
    showFilterButton.setVisible(false);

    final HorizontalLayout hListSelectLayout = new HorizontalLayout();
    hListSelectLayout.setHeight(150, Unit.PIXELS);
    hListSelectLayout.setWidth("100%");
    hListSelectLayout.addComponent(listSelectLayout);

    final HorizontalLayout hDateSelectLayout = new HorizontalLayout();
    hDateSelectLayout.setHeight(40, Unit.PIXELS);
    hDateSelectLayout.setWidth("100%");
    hDateSelectLayout.addComponent(dateSelectLayout);

    final HorizontalLayout hSearchLayout = new HorizontalLayout();
    hSearchLayout.setHeight(30, Unit.PIXELS);
    hSearchLayout.setWidth("100%");
    hSearchLayout.addComponent(searchLayout);
    hSearchLayout.setComponentAlignment(searchLayout, Alignment.MIDDLE_CENTER);

    hideFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(false);
            showFilterButton.setVisible(true);
            splitPosition = vSplitPanel.getSplitPosition();
            splitUnit = vSplitPanel.getSplitPositionUnit();
            vSplitPanel.setSplitPosition(0, Unit.PIXELS);
        }
    });

    showFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(true);
            showFilterButton.setVisible(false);
            vSplitPanel.setSplitPosition(splitPosition, splitUnit);
        }
    });

    GridLayout filterButtonLayout = new GridLayout(2, 1);
    filterButtonLayout.setHeight(25, Unit.PIXELS);
    filterButtonLayout.addComponent(hideFilterButton, 0, 0);
    filterButtonLayout.addComponent(showFilterButton, 1, 0);

    Label filterHintLabel = new Label();
    filterHintLabel.setCaptionAsHtml(true);
    filterHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " Drag items from the topology tree to the tables below in order to narrow your search.");
    filterHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    filterHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);

    layout.addComponent(filterHintLabel);
    layout.addComponent(hListSelectLayout);
    layout.addComponent(hDateSelectLayout);
    layout.addComponent(hSearchLayout);
    layout.setSizeFull();

    Panel filterPanel = new Panel();
    filterPanel.setHeight(300, Unit.PIXELS);
    filterPanel.setWidth("100%");
    filterPanel.setContent(layout);
    filterPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);

    vSplitPanel.setFirstComponent(filterPanel);

    CssLayout hErrorTable = new CssLayout();
    hErrorTable.setSizeFull();
    hErrorTable.addComponent(this.categorizedErrorOccurenceTable);

    vSplitPanel.setSecondComponent(hErrorTable);
    vSplitPanel.setSplitPosition(310, Unit.PIXELS);

    GridLayout wrapper = new GridLayout(1, 2);
    wrapper.setRowExpandRatio(0, .01f);
    wrapper.setRowExpandRatio(1, .99f);
    wrapper.setSizeFull();
    wrapper.addComponent(filterButtonLayout);
    wrapper.setComponentAlignment(filterButtonLayout, Alignment.MIDDLE_RIGHT);
    wrapper.addComponent(vSplitPanel);

    return wrapper;
}

From source file:org.ikasan.dashboard.ui.topology.component.ErrorOccurrenceTab.java

License:BSD License

public Layout createCategorisedErrorLayout() {
    this.errorOccurenceTable = new Table();
    this.errorOccurenceTable.setSizeFull();
    this.errorOccurenceTable.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    this.errorOccurenceTable.addStyleName(ValoTheme.TABLE_SMALL);
    this.errorOccurenceTable.addStyleName("ikasan");
    this.errorOccurenceTable.addContainerProperty("Module Name", String.class, null);
    this.errorOccurenceTable.setColumnExpandRatio("Module Name", .14f);
    this.errorOccurenceTable.addContainerProperty("Flow Name", String.class, null);
    this.errorOccurenceTable.setColumnExpandRatio("Flow Name", .18f);
    this.errorOccurenceTable.addContainerProperty("Component Name", String.class, null);
    this.errorOccurenceTable.setColumnExpandRatio("Component Name", .2f);
    this.errorOccurenceTable.addContainerProperty("Error Message", String.class, null);
    this.errorOccurenceTable.setColumnExpandRatio("Error Message", .33f);
    this.errorOccurenceTable.addContainerProperty("Timestamp", String.class, null);
    this.errorOccurenceTable.setColumnExpandRatio("Timestamp", .1f);

    this.errorOccurenceTable.addStyleName("wordwrap-table");

    this.errorOccurenceTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override// w  w  w  .  j a  va 2s .co  m
        public void itemClick(ItemClickEvent itemClickEvent) {
            ErrorOccurrence errorOccurrence = (ErrorOccurrence) itemClickEvent.getItemId();
            ErrorOccurrenceViewWindow errorOccurrenceViewWindow = new ErrorOccurrenceViewWindow(
                    errorOccurrence);

            UI.getCurrent().addWindow(errorOccurrenceViewWindow);
        }
    });

    Button searchButton = new Button("Search");
    searchButton.setStyleName(ValoTheme.BUTTON_SMALL);
    searchButton.addClickListener(new Button.ClickListener() {
        @SuppressWarnings("unchecked")
        public void buttonClick(ClickEvent event) {
            errorOccurenceTable.removeAllItems();

            ArrayList<String> modulesNames = null;

            if (errorOccurenceModules.getItemIds().size() > 0) {
                modulesNames = new ArrayList<String>();
                for (Object module : errorOccurenceModules.getItemIds()) {
                    modulesNames.add(((Module) module).getName());
                }
            }

            ArrayList<String> flowNames = null;

            if (errorOccurenceFlows.getItemIds().size() > 0) {
                flowNames = new ArrayList<String>();
                for (Object flow : errorOccurenceFlows.getItemIds()) {
                    flowNames.add(((Flow) flow).getName());
                }
            }

            ArrayList<String> componentNames = null;

            if (errorOccurenceComponents.getItemIds().size() > 0) {
                componentNames = new ArrayList<String>();
                for (Object component : errorOccurenceComponents.getItemIds()) {
                    componentNames.add(((Component) component).getName());
                }
            }

            if (modulesNames == null && flowNames == null && componentNames == null
                    && !((BusinessStream) businessStreamCombo.getValue()).getName().equals("All")) {
                BusinessStream businessStream = ((BusinessStream) businessStreamCombo.getValue());

                modulesNames = new ArrayList<String>();

                for (BusinessStreamFlow flow : businessStream.getFlows()) {
                    modulesNames.add(flow.getFlow().getModule().getName());
                }
            }

            List<ErrorOccurrence> errorOccurences = errorReportingService.find(modulesNames, flowNames,
                    componentNames, errorFromDate.getValue(), errorToDate.getValue());

            for (ErrorOccurrence errorOccurrence : errorOccurences) {
                Date date = new Date(errorOccurrence.getTimestamp());
                SimpleDateFormat format = new SimpleDateFormat("yyyy MM dd HH:mm:ss");
                String timestamp = format.format(date);

                errorOccurenceTable.addItem(new Object[] { errorOccurrence.getModuleName(),
                        errorOccurrence.getFlowName(), errorOccurrence.getFlowElementName(),
                        errorOccurrence.getErrorMessage(), timestamp }, errorOccurrence);
            }
        }
    });

    Button clearButton = new Button("Clear");
    clearButton.setStyleName(ValoTheme.BUTTON_SMALL);
    clearButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            errorOccurenceModules.removeAllItems();
            errorOccurenceFlows.removeAllItems();
            errorOccurenceComponents.removeAllItems();
        }
    });

    GridLayout layout = new GridLayout(1, 6);
    layout.setMargin(false);
    layout.setHeight(270, Unit.PIXELS);

    GridLayout listSelectLayout = new GridLayout(3, 1);
    listSelectLayout.setSpacing(true);
    listSelectLayout.setSizeFull();

    errorOccurenceModules.setIcon(VaadinIcons.ARCHIVE);
    errorOccurenceModules.addContainerProperty("Module Name", String.class, null);
    errorOccurenceModules.addContainerProperty("", Button.class, null);
    errorOccurenceModules.setSizeFull();
    errorOccurenceModules.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceModules.setDragMode(TableDragMode.ROW);
    errorOccurenceModules.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            final DataBoundTransferable t = (DataBoundTransferable) dropEvent.getTransferable();

            if (t.getItemId() instanceof Module) {
                final Module module = (Module) t.getItemId();
                logger.info("sourceContainer.getText(): " + module.getName());

                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceModules.removeItem(module);
                    }
                });

                errorOccurenceModules.addItem(new Object[] { module.getName(), deleteButton }, module);

                for (final Flow flow : module.getFlows()) {
                    deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            errorOccurenceFlows.removeItem(flow);
                        }
                    });

                    errorOccurenceFlows.addItem(new Object[] { flow.getName(), deleteButton }, flow);

                    for (final Component component : flow.getComponents()) {
                        deleteButton = new Button();
                        deleteButton.setIcon(VaadinIcons.TRASH);
                        deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                        deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                        // Add the delete functionality to each role that is added
                        deleteButton.addClickListener(new Button.ClickListener() {
                            public void buttonClick(ClickEvent event) {
                                errorOccurenceComponents.removeItem(component);
                            }
                        });

                        errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton },
                                component);
                    }
                }
            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });

    listSelectLayout.addComponent(errorOccurenceModules, 0, 0);

    errorOccurenceFlows.setIcon(VaadinIcons.AUTOMATION);
    errorOccurenceFlows.addContainerProperty("Flow Name", String.class, null);
    errorOccurenceFlows.addContainerProperty("", Button.class, null);
    errorOccurenceFlows.setSizeFull();
    errorOccurenceFlows.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceFlows.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            final DataBoundTransferable t = (DataBoundTransferable) dropEvent.getTransferable();

            if (t.getItemId() instanceof Flow) {
                final Flow flow = (Flow) t.getItemId();
                logger.info("sourceContainer.getText(): " + flow.getName());

                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceFlows.removeItem(flow);
                    }
                });

                errorOccurenceFlows.addItem(new Object[] { flow.getName(), deleteButton }, flow);

                for (final Component component : flow.getComponents()) {
                    deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            errorOccurenceComponents.removeItem(component);
                        }
                    });

                    errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton },
                            component);
                }
            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });

    listSelectLayout.addComponent(errorOccurenceFlows, 1, 0);

    errorOccurenceComponents.setIcon(VaadinIcons.COG);
    errorOccurenceComponents.setSizeFull();
    errorOccurenceComponents.addContainerProperty("Component Name", String.class, null);
    errorOccurenceComponents.addContainerProperty("", Button.class, null);
    errorOccurenceComponents.setCellStyleGenerator(new IkasanCellStyleGenerator());
    errorOccurenceComponents.setSizeFull();
    errorOccurenceComponents.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    errorOccurenceComponents.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            final DataBoundTransferable t = (DataBoundTransferable) dropEvent.getTransferable();

            if (t.getItemId() instanceof Component) {
                final Component component = (Component) t.getItemId();
                logger.info("sourceContainer.getText(): " + component.getName());

                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        errorOccurenceComponents.removeItem(component);
                    }
                });

                errorOccurenceComponents.addItem(new Object[] { component.getName(), deleteButton }, component);

            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });
    listSelectLayout.addComponent(this.errorOccurenceComponents, 2, 0);

    GridLayout dateSelectLayout = new GridLayout(2, 1);

    dateSelectLayout.setSizeFull();
    errorFromDate = new PopupDateField("From date");
    errorFromDate.setResolution(Resolution.MINUTE);
    errorFromDate.setValue(this.getMidnightToday());
    dateSelectLayout.addComponent(errorFromDate, 0, 0);
    errorToDate = new PopupDateField("To date");
    errorToDate.setResolution(Resolution.MINUTE);
    errorToDate.setValue(this.getTwentyThreeFixtyNineToday());
    dateSelectLayout.addComponent(errorToDate, 1, 0);

    final VerticalSplitPanel vSplitPanel = new VerticalSplitPanel();
    vSplitPanel.setHeight("95%");

    GridLayout searchLayout = new GridLayout(2, 1);
    searchLayout.setSpacing(true);
    searchLayout.addComponent(searchButton, 0, 0);
    searchLayout.addComponent(clearButton, 1, 0);

    final Button hideFilterButton = new Button();
    hideFilterButton.setIcon(VaadinIcons.MINUS);
    hideFilterButton.setCaption("Hide Filter");
    hideFilterButton.setStyleName(ValoTheme.BUTTON_LINK);
    hideFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);

    final Button showFilterButton = new Button();
    showFilterButton.setIcon(VaadinIcons.PLUS);
    showFilterButton.setCaption("Show Filter");
    showFilterButton.addStyleName(ValoTheme.BUTTON_LINK);
    showFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);
    showFilterButton.setVisible(false);

    final HorizontalLayout hListSelectLayout = new HorizontalLayout();
    hListSelectLayout.setHeight(150, Unit.PIXELS);
    hListSelectLayout.setWidth("100%");
    hListSelectLayout.addComponent(listSelectLayout);

    final HorizontalLayout hDateSelectLayout = new HorizontalLayout();
    hDateSelectLayout.setHeight(40, Unit.PIXELS);
    hDateSelectLayout.setWidth("100%");
    hDateSelectLayout.addComponent(dateSelectLayout);

    final HorizontalLayout hSearchLayout = new HorizontalLayout();
    hSearchLayout.setHeight(30, Unit.PIXELS);
    hSearchLayout.setWidth("100%");
    hSearchLayout.addComponent(searchLayout);
    hSearchLayout.setComponentAlignment(searchLayout, Alignment.MIDDLE_CENTER);

    hideFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(false);
            showFilterButton.setVisible(true);
            splitPosition = vSplitPanel.getSplitPosition();
            splitUnit = vSplitPanel.getSplitPositionUnit();
            vSplitPanel.setSplitPosition(0, Unit.PIXELS);
        }
    });

    showFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(true);
            showFilterButton.setVisible(false);
            vSplitPanel.setSplitPosition(splitPosition, splitUnit);
        }
    });

    GridLayout filterButtonLayout = new GridLayout(2, 1);
    filterButtonLayout.setHeight(25, Unit.PIXELS);
    filterButtonLayout.addComponent(hideFilterButton, 0, 0);
    filterButtonLayout.addComponent(showFilterButton, 1, 0);

    Label filterHintLabel = new Label();
    filterHintLabel.setCaptionAsHtml(true);
    filterHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " Drag items from the topology tree to the tables below in order to narrow your search.");
    filterHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    filterHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);

    layout.addComponent(filterHintLabel);
    layout.addComponent(hListSelectLayout);
    layout.addComponent(hDateSelectLayout);
    layout.addComponent(hSearchLayout);
    layout.setSizeFull();

    Panel filterPanel = new Panel();
    filterPanel.setHeight(300, Unit.PIXELS);
    filterPanel.setWidth("100%");
    filterPanel.setContent(layout);
    filterPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);

    vSplitPanel.setFirstComponent(filterPanel);

    CssLayout hErrorTable = new CssLayout();
    hErrorTable.setSizeFull();
    hErrorTable.addComponent(this.errorOccurenceTable);

    vSplitPanel.setSecondComponent(hErrorTable);
    vSplitPanel.setSplitPosition(310, Unit.PIXELS);

    GridLayout wrapper = new GridLayout(1, 2);
    wrapper.setRowExpandRatio(0, .01f);
    wrapper.setRowExpandRatio(1, .99f);
    wrapper.setSizeFull();
    wrapper.addComponent(filterButtonLayout);
    wrapper.setComponentAlignment(filterButtonLayout, Alignment.MIDDLE_RIGHT);
    wrapper.addComponent(vSplitPanel);

    return wrapper;
}

From source file:org.ikasan.dashboard.ui.topology.component.ExclusionsTab.java

License:BSD License

public Layout createLayout() {
    this.exclusionsTable = new Table();
    this.exclusionsTable.setSizeFull();
    this.exclusionsTable.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    this.exclusionsTable.addContainerProperty("Module Name", String.class, null);
    this.exclusionsTable.addContainerProperty("Flow Name", String.class, null);
    this.exclusionsTable.addContainerProperty("Timestamp", String.class, null);

    this.exclusionsTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override//from www  .  j av  a2s  .  c  om
        public void itemClick(ItemClickEvent itemClickEvent) {
            ExclusionEvent exclusionEvent = (ExclusionEvent) itemClickEvent.getItemId();
            ErrorOccurrence errorOccurrence = (ErrorOccurrence) errorReportingService
                    .find(exclusionEvent.getErrorUri());
            ExclusionEventAction action = hospitalManagementService
                    .getExclusionEventActionByErrorUri(exclusionEvent.getErrorUri());
            ExclusionEventViewWindow exclusionEventViewWindow = new ExclusionEventViewWindow(exclusionEvent,
                    errorOccurrence, serialiserFactory, action, hospitalManagementService, topologyService);

            exclusionEventViewWindow.addCloseListener(new Window.CloseListener() {
                // inline close-listener
                public void windowClose(CloseEvent e) {
                    refreshExcludedEventsTable();
                }
            });

            UI.getCurrent().addWindow(exclusionEventViewWindow);
        }
    });

    Button searchButton = new Button("Search");
    searchButton.setStyleName(ValoTheme.BUTTON_SMALL);
    searchButton.addClickListener(new Button.ClickListener() {
        @SuppressWarnings("unchecked")
        public void buttonClick(ClickEvent event) {
            exclusionsTable.removeAllItems();

            ArrayList<String> modulesNames = null;

            if (exclusionModules.getItemIds().size() > 0) {
                modulesNames = new ArrayList<String>();
                for (Object module : exclusionModules.getItemIds()) {
                    modulesNames.add(((Module) module).getName());
                }
            }

            ArrayList<String> flowNames = null;

            if (exclusionFlows.getItemIds().size() > 0) {
                flowNames = new ArrayList<String>();
                for (Object flow : exclusionFlows.getItemIds()) {
                    flowNames.add(((Flow) flow).getName());
                }
            }

            if (modulesNames == null && flowNames == null
                    && !((BusinessStream) businessStreamCombo.getValue()).getName().equals("All")) {
                BusinessStream businessStream = ((BusinessStream) businessStreamCombo.getValue());

                modulesNames = new ArrayList<String>();

                for (BusinessStreamFlow flow : businessStream.getFlows()) {
                    modulesNames.add(flow.getFlow().getModule().getName());
                }
            }

            List<ExclusionEvent> exclusionEvents = exclusionManagementService.find(modulesNames, flowNames,
                    fromDate.getValue(), toDate.getValue(), null);

            for (ExclusionEvent exclusionEvent : exclusionEvents) {
                Date date = new Date(exclusionEvent.getTimestamp());
                SimpleDateFormat format = new SimpleDateFormat("yyyy MM dd HH:mm:ss");
                String timestamp = format.format(date);

                exclusionsTable.addItem(new Object[] { exclusionEvent.getModuleName(),
                        exclusionEvent.getFlowName(), timestamp }, exclusionEvent);
            }
        }
    });

    Button clearButton = new Button("Clear");
    clearButton.setStyleName(ValoTheme.BUTTON_SMALL);
    clearButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            exclusionModules.removeAllItems();
            exclusionFlows.removeAllItems();
        }
    });

    GridLayout layout = new GridLayout(1, 6);
    layout.setMargin(false);
    layout.setHeight(270, Unit.PIXELS);

    GridLayout listSelectLayout = new GridLayout(2, 1);
    listSelectLayout.setSpacing(true);
    listSelectLayout.setSizeFull();

    exclusionModules.setIcon(VaadinIcons.ARCHIVE);
    exclusionModules.addContainerProperty("Module Name", String.class, null);
    exclusionModules.addContainerProperty("", Button.class, null);
    exclusionModules.setSizeFull();
    exclusionModules.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    exclusionModules.setDragMode(TableDragMode.ROW);
    exclusionModules.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            final DataBoundTransferable t = (DataBoundTransferable) dropEvent.getTransferable();

            if (t.getItemId() instanceof Module) {
                final Module module = (Module) t.getItemId();
                logger.info("sourceContainer.getText(): " + module.getName());

                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        exclusionModules.removeItem(module);
                    }
                });

                exclusionModules.addItem(new Object[] { module.getName(), deleteButton }, module);

                for (final Flow flow : module.getFlows()) {

                    deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            exclusionFlows.removeItem(flow);
                        }
                    });

                    exclusionFlows.addItem(new Object[] { flow.getName(), deleteButton }, flow);
                }
            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });

    listSelectLayout.addComponent(exclusionModules, 0, 0);

    exclusionFlows.setIcon(VaadinIcons.AUTOMATION);
    exclusionFlows.addContainerProperty("Flow Name", String.class, null);
    exclusionFlows.addContainerProperty("", Button.class, null);
    exclusionFlows.setSizeFull();
    exclusionFlows.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    exclusionFlows.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            final DataBoundTransferable t = (DataBoundTransferable) dropEvent.getTransferable();

            if (t.getItemId() instanceof Flow) {
                final Flow flow = (Flow) t.getItemId();
                logger.info("sourceContainer.getText(): " + flow.getName());

                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        exclusionFlows.removeItem(flow);
                    }
                });

                exclusionFlows.addItem(new Object[] { flow.getName(), deleteButton }, flow);
            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });

    listSelectLayout.addComponent(exclusionFlows, 1, 0);

    GridLayout dateSelectLayout = new GridLayout(2, 1);

    dateSelectLayout.setSizeFull();
    fromDate = new PopupDateField("From date");
    fromDate.setResolution(Resolution.MINUTE);
    fromDate.setValue(this.getMidnightToday());
    dateSelectLayout.addComponent(fromDate, 0, 0);
    toDate = new PopupDateField("To date");
    toDate.setResolution(Resolution.MINUTE);
    toDate.setValue(this.getTwentyThreeFixtyNineToday());
    dateSelectLayout.addComponent(toDate, 1, 0);

    final VerticalSplitPanel vSplitPanel = new VerticalSplitPanel();
    vSplitPanel.setHeight("95%");

    GridLayout searchLayout = new GridLayout(2, 1);
    searchLayout.setSpacing(true);
    searchLayout.addComponent(searchButton, 0, 0);
    searchLayout.addComponent(clearButton, 1, 0);

    final Button hideFilterButton = new Button();
    hideFilterButton.setIcon(VaadinIcons.MINUS);
    hideFilterButton.setCaption("Hide Filter");
    hideFilterButton.setStyleName(ValoTheme.BUTTON_LINK);
    hideFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);

    final Button showFilterButton = new Button();
    showFilterButton.setIcon(VaadinIcons.PLUS);
    showFilterButton.setCaption("Show Filter");
    showFilterButton.addStyleName(ValoTheme.BUTTON_LINK);
    showFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);
    showFilterButton.setVisible(false);

    final HorizontalLayout hListSelectLayout = new HorizontalLayout();
    hListSelectLayout.setHeight(150, Unit.PIXELS);
    hListSelectLayout.setWidth("100%");
    hListSelectLayout.addComponent(listSelectLayout);

    final HorizontalLayout hDateSelectLayout = new HorizontalLayout();
    hDateSelectLayout.setHeight(40, Unit.PIXELS);
    hDateSelectLayout.setWidth("100%");
    hDateSelectLayout.addComponent(dateSelectLayout);

    final HorizontalLayout hSearchLayout = new HorizontalLayout();
    hSearchLayout.setHeight(30, Unit.PIXELS);
    hSearchLayout.setWidth("100%");
    hSearchLayout.addComponent(searchLayout);
    hSearchLayout.setComponentAlignment(searchLayout, Alignment.MIDDLE_CENTER);

    hideFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(false);
            showFilterButton.setVisible(true);
            splitPosition = vSplitPanel.getSplitPosition();
            splitUnit = vSplitPanel.getSplitPositionUnit();
            vSplitPanel.setSplitPosition(0, Unit.PIXELS);
        }
    });

    showFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(true);
            showFilterButton.setVisible(false);
            vSplitPanel.setSplitPosition(splitPosition, splitUnit);
        }
    });

    GridLayout filterButtonLayout = new GridLayout(2, 1);
    filterButtonLayout.setHeight(25, Unit.PIXELS);
    filterButtonLayout.addComponent(hideFilterButton, 0, 0);
    filterButtonLayout.addComponent(showFilterButton, 1, 0);

    Label filterHintLabel = new Label();
    filterHintLabel.setCaptionAsHtml(true);
    filterHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " Drag items from the topology tree to the tables below in order to narrow your search.");
    filterHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    filterHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);

    layout.addComponent(filterHintLabel);
    layout.addComponent(hListSelectLayout);
    layout.addComponent(hDateSelectLayout);
    layout.addComponent(hSearchLayout);
    layout.setSizeFull();

    Panel filterPanel = new Panel();
    filterPanel.setHeight(300, Unit.PIXELS);
    filterPanel.setWidth("100%");
    filterPanel.setContent(layout);
    filterPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);

    vSplitPanel.setFirstComponent(filterPanel);

    CssLayout hErrorTable = new CssLayout();
    hErrorTable.setSizeFull();
    hErrorTable.addComponent(this.exclusionsTable);

    vSplitPanel.setSecondComponent(hErrorTable);
    vSplitPanel.setSplitPosition(310, Unit.PIXELS);

    GridLayout wrapper = new GridLayout(1, 2);
    wrapper.setRowExpandRatio(0, .01f);
    wrapper.setRowExpandRatio(1, .99f);
    wrapper.setSizeFull();
    wrapper.addComponent(filterButtonLayout);
    wrapper.setComponentAlignment(filterButtonLayout, Alignment.MIDDLE_RIGHT);
    wrapper.addComponent(vSplitPanel);

    return wrapper;
}

From source file:org.ikasan.dashboard.ui.topology.component.WiretapTab.java

License:BSD License

public Layout createWiretapLayout() {
    this.wiretapTable = new Table();
    this.wiretapTable.setSizeFull();
    this.wiretapTable.addStyleName(ValoTheme.TABLE_SMALL);
    this.wiretapTable.addStyleName("ikasan");

    this.wiretapTable.addContainerProperty("Module Name", String.class, null);
    this.wiretapTable.addContainerProperty("Flow Name", String.class, null);
    this.wiretapTable.addContainerProperty("Component Name", String.class, null);
    this.wiretapTable.addContainerProperty("Event Id / Payload Id", String.class, null);
    this.wiretapTable.addContainerProperty("Timestamp", String.class, null);
    this.wiretapTable.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());

    this.wiretapTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override//w  w  w  .j  a v  a 2 s  . co m
        public void itemClick(ItemClickEvent itemClickEvent) {
            WiretapEvent<String> wiretapEvent = (WiretapEvent<String>) itemClickEvent.getItemId();
            WiretapPayloadViewWindow wiretapPayloadViewWindow = new WiretapPayloadViewWindow(wiretapEvent);

            UI.getCurrent().addWindow(wiretapPayloadViewWindow);
        }
    });

    final Button searchButton = new Button("Search");
    searchButton.setStyleName(ValoTheme.BUTTON_SMALL);
    searchButton.addClickListener(new Button.ClickListener() {
        @SuppressWarnings("unchecked")
        public void buttonClick(ClickEvent event) {
            ProgressBarWindow pbWindow = new ProgressBarWindow();

            UI.getCurrent().addWindow(pbWindow);

            wiretapTable.removeAllItems();

            HashSet<String> modulesNames = null;

            if (modules.getItemIds().size() > 0) {
                modulesNames = new HashSet<String>();
                for (Object module : modules.getItemIds()) {
                    modulesNames.add(((Module) module).getName());
                }
            }

            HashSet<String> flowNames = null;

            if (flows.getItemIds().size() > 0) {
                flowNames = new HashSet<String>();
                for (Object flow : flows.getItemIds()) {
                    flowNames.add(((Flow) flow).getName());
                }
            }

            HashSet<String> componentNames = null;

            if (components.getItemIds().size() > 0) {
                componentNames = new HashSet<String>();
                for (Object component : components.getItemIds()) {

                    componentNames.add("before " + ((Component) component).getName());
                    componentNames.add("after " + ((Component) component).getName());
                }
            }

            if (modulesNames == null && flowNames == null && componentNames == null
                    && !((BusinessStream) businessStreamCombo.getValue()).getName().equals("All")) {
                BusinessStream businessStream = ((BusinessStream) businessStreamCombo.getValue());

                modulesNames = new HashSet<String>();

                for (BusinessStreamFlow flow : businessStream.getFlows()) {
                    modulesNames.add(flow.getFlow().getModule().getName());
                }
            }

            String errorCategory = null;

            // TODO Need to take a proper look at the wiretap search interface. We do not need to worry about paging search
            // results with Vaadin.
            PagedSearchResult<WiretapEvent> events = wiretapDao.findWiretapEvents(0, 10000, "timestamp", false,
                    modulesNames, flowNames, componentNames, eventId.getValue(), null, fromDate.getValue(),
                    toDate.getValue(), payloadContent.getValue());

            for (WiretapEvent<String> wiretapEvent : events.getPagedResults()) {
                Date date = new Date(wiretapEvent.getTimestamp());
                SimpleDateFormat format = new SimpleDateFormat("yyyy MM dd HH:mm:ss");
                String timestamp = format.format(date);

                wiretapTable
                        .addItem(
                                new Object[] { wiretapEvent.getModuleName(), wiretapEvent.getFlowName(),
                                        wiretapEvent.getComponentName(),
                                        ((WiretapFlowEvent) wiretapEvent).getEventId(), timestamp },
                                wiretapEvent);
            }

            pbWindow.close();
        }
    });

    Button clearButton = new Button("Clear");
    clearButton.setStyleName(ValoTheme.BUTTON_SMALL);
    clearButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            modules.removeAllItems();
            flows.removeAllItems();
            components.removeAllItems();
        }
    });

    GridLayout layout = new GridLayout(1, 6);
    layout.setMargin(false);
    layout.setHeight(270, Unit.PIXELS);

    GridLayout listSelectLayout = new GridLayout(3, 1);
    listSelectLayout.setSpacing(true);
    listSelectLayout.setSizeFull();

    modules.setIcon(VaadinIcons.ARCHIVE);
    modules.addContainerProperty("Module Name", String.class, null);
    modules.addContainerProperty("", Button.class, null);
    modules.setSizeFull();
    modules.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    modules.setDragMode(TableDragMode.ROW);
    modules.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            final DataBoundTransferable t = (DataBoundTransferable) dropEvent.getTransferable();

            if (t.getItemId() instanceof Module) {
                final Module module = (Module) t.getItemId();
                logger.info("sourceContainer.getText(): " + module.getName());

                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        modules.removeItem(module);
                    }
                });

                modules.addItem(new Object[] { module.getName(), deleteButton }, module);

                for (final Flow flow : module.getFlows()) {
                    deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            flows.removeItem(flow);
                        }
                    });

                    flows.addItem(new Object[] { flow.getName(), deleteButton }, flow);

                    for (final Component component : flow.getComponents()) {
                        deleteButton = new Button();
                        deleteButton.setIcon(VaadinIcons.TRASH);
                        deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                        deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                        // Add the delete functionality to each role that is added
                        deleteButton.addClickListener(new Button.ClickListener() {
                            public void buttonClick(ClickEvent event) {
                                components.removeItem(component);
                            }
                        });

                        components.addItem(new Object[] { component.getName(), deleteButton }, component);
                    }
                }
            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });

    listSelectLayout.addComponent(modules, 0, 0);

    flows.setIcon(VaadinIcons.AUTOMATION);
    flows.addContainerProperty("Flow Name", String.class, null);
    flows.addContainerProperty("", Button.class, null);
    flows.setSizeFull();
    flows.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    flows.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            final DataBoundTransferable t = (DataBoundTransferable) dropEvent.getTransferable();

            if (t.getItemId() instanceof Flow) {
                final Flow flow = (Flow) t.getItemId();
                logger.info("sourceContainer.getText(): " + flow.getName());

                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        flows.removeItem(flow);
                    }
                });

                flows.addItem(new Object[] { flow.getName(), deleteButton }, flow);

                for (final Component component : flow.getComponents()) {
                    deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            components.removeItem(component);
                        }
                    });

                    components.addItem(new Object[] { component.getName(), deleteButton }, component);
                }
            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });

    listSelectLayout.addComponent(flows, 1, 0);

    components.setIcon(VaadinIcons.COG);
    components.setSizeFull();
    components.addContainerProperty("Component Name", String.class, null);
    components.addContainerProperty("", Button.class, null);
    components.setCellStyleGenerator(new IkasanCellStyleGenerator());
    components.setSizeFull();
    components.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    components.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            final DataBoundTransferable t = (DataBoundTransferable) dropEvent.getTransferable();

            if (t.getItemId() instanceof Component) {
                final Component component = (Component) t.getItemId();
                logger.info("sourceContainer.getText(): " + component.getName());

                Button deleteButton = new Button();
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);

                // Add the delete functionality to each role that is added
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        components.removeItem(component);
                    }
                });

                components.addItem(new Object[] { component.getName(), deleteButton }, component);

            }

        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });
    listSelectLayout.addComponent(this.components, 2, 0);

    GridLayout dateSelectLayout = new GridLayout(2, 2);
    dateSelectLayout.setColumnExpandRatio(0, 0.25f);
    dateSelectLayout.setColumnExpandRatio(1, 0.75f);
    dateSelectLayout.setSizeFull();
    this.fromDate = new PopupDateField("From date");
    this.fromDate.setResolution(Resolution.MINUTE);
    this.fromDate.setValue(this.getMidnightToday());
    dateSelectLayout.addComponent(this.fromDate, 0, 0);
    this.toDate = new PopupDateField("To date");
    this.toDate.setResolution(Resolution.MINUTE);
    this.toDate.setValue(this.getTwentyThreeFixtyNineToday());
    dateSelectLayout.addComponent(this.toDate, 0, 1);

    this.eventId = new TextField("Event Id");
    this.eventId.setWidth("80%");
    this.payloadContent = new TextField("Payload Content");
    this.payloadContent.setWidth("80%");

    this.eventId.setNullSettingAllowed(true);
    this.payloadContent.setNullSettingAllowed(true);

    dateSelectLayout.addComponent(this.eventId, 1, 0);
    dateSelectLayout.addComponent(this.payloadContent, 1, 1);

    final VerticalSplitPanel vSplitPanel = new VerticalSplitPanel();
    vSplitPanel.setHeight("95%");

    GridLayout searchLayout = new GridLayout(2, 1);
    searchLayout.setSpacing(true);
    searchLayout.addComponent(searchButton, 0, 0);
    searchLayout.addComponent(clearButton, 1, 0);

    final Button hideFilterButton = new Button();
    hideFilterButton.setIcon(VaadinIcons.MINUS);
    hideFilterButton.setCaption("Hide Filter");
    hideFilterButton.setStyleName(ValoTheme.BUTTON_LINK);
    hideFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);

    final Button showFilterButton = new Button();
    showFilterButton.setIcon(VaadinIcons.PLUS);
    showFilterButton.setCaption("Show Filter");
    showFilterButton.addStyleName(ValoTheme.BUTTON_LINK);
    showFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);
    showFilterButton.setVisible(false);

    final HorizontalLayout hListSelectLayout = new HorizontalLayout();
    hListSelectLayout.setHeight(150, Unit.PIXELS);
    hListSelectLayout.setWidth("100%");
    hListSelectLayout.addComponent(listSelectLayout);

    final HorizontalLayout hDateSelectLayout = new HorizontalLayout();
    hDateSelectLayout.setHeight(80, Unit.PIXELS);
    hDateSelectLayout.setWidth("100%");
    hDateSelectLayout.addComponent(dateSelectLayout);

    final HorizontalLayout hSearchLayout = new HorizontalLayout();
    hSearchLayout.setHeight(30, Unit.PIXELS);
    hSearchLayout.setWidth("100%");
    hSearchLayout.addComponent(searchLayout);
    hSearchLayout.setComponentAlignment(searchLayout, Alignment.MIDDLE_CENTER);

    hideFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(false);
            showFilterButton.setVisible(true);
            splitPosition = vSplitPanel.getSplitPosition();
            splitUnit = vSplitPanel.getSplitPositionUnit();
            vSplitPanel.setSplitPosition(0, Unit.PIXELS);
        }
    });

    showFilterButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            hideFilterButton.setVisible(true);
            showFilterButton.setVisible(false);
            vSplitPanel.setSplitPosition(splitPosition, splitUnit);
        }
    });

    GridLayout filterButtonLayout = new GridLayout(2, 1);
    filterButtonLayout.setHeight(25, Unit.PIXELS);
    filterButtonLayout.addComponent(hideFilterButton, 0, 0);
    filterButtonLayout.addComponent(showFilterButton, 1, 0);

    Label filterHintLabel = new Label();
    filterHintLabel.setCaptionAsHtml(true);
    filterHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " Drag items from the topology tree to the tables below in order to narrow your search.");
    filterHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    filterHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);

    layout.addComponent(filterHintLabel);
    layout.addComponent(hListSelectLayout);
    layout.addComponent(hDateSelectLayout);
    layout.addComponent(hSearchLayout);
    layout.setSizeFull();

    Panel filterPanel = new Panel();
    filterPanel.setHeight(340, Unit.PIXELS);
    filterPanel.setWidth("100%");
    filterPanel.setContent(layout);
    filterPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);

    vSplitPanel.setFirstComponent(filterPanel);

    CssLayout hErrorTable = new CssLayout();
    hErrorTable.setSizeFull();
    hErrorTable.addComponent(this.wiretapTable);

    vSplitPanel.setSecondComponent(hErrorTable);
    vSplitPanel.setSplitPosition(350, Unit.PIXELS);

    GridLayout wrapper = new GridLayout(1, 2);
    wrapper.setRowExpandRatio(0, .01f);
    wrapper.setRowExpandRatio(1, .99f);
    wrapper.setSizeFull();
    wrapper.addComponent(filterButtonLayout);
    wrapper.setComponentAlignment(filterButtonLayout, Alignment.MIDDLE_RIGHT);
    wrapper.addComponent(vSplitPanel);

    return wrapper;
}

From source file:org.ikasan.dashboard.ui.topology.window.ExclusionEventViewWindow.java

License:BSD License

protected Panel createExclusionEventDetailsPanel() {
    Panel exclusionEventDetailsPanel = new Panel();
    exclusionEventDetailsPanel.setSizeFull();
    exclusionEventDetailsPanel.setStyleName("dashboard");

    GridLayout layout = new GridLayout(4, 7);
    layout.setSpacing(true);//from  w w w .j ava  2 s .  co  m
    layout.setColumnExpandRatio(0, .10f);
    layout.setColumnExpandRatio(1, .30f);
    layout.setColumnExpandRatio(2, .05f);
    layout.setColumnExpandRatio(3, .30f);

    layout.setWidth("100%");

    Label exclusionEvenDetailsLabel = new Label("Exclusion Event Details");
    exclusionEvenDetailsLabel.setStyleName(ValoTheme.LABEL_HUGE);
    layout.addComponent(exclusionEvenDetailsLabel, 0, 0, 3, 0);

    Label label = new Label("Module Name:");
    label.setSizeUndefined();
    layout.addComponent(label, 0, 1);
    layout.setComponentAlignment(label, Alignment.MIDDLE_RIGHT);

    TextField tf1 = new TextField();
    tf1.setValue(this.exclusionEvent.getModuleName());
    tf1.setReadOnly(true);
    tf1.setWidth("80%");
    layout.addComponent(tf1, 1, 1);

    label = new Label("Flow Name:");
    label.setSizeUndefined();
    layout.addComponent(label, 0, 2);
    layout.setComponentAlignment(label, Alignment.MIDDLE_RIGHT);

    TextField tf2 = new TextField();
    tf2.setValue(this.exclusionEvent.getFlowName());
    tf2.setReadOnly(true);
    tf2.setWidth("80%");
    layout.addComponent(tf2, 1, 2);

    label = new Label("Event Id:");
    label.setSizeUndefined();
    layout.addComponent(label, 0, 3);
    layout.setComponentAlignment(label, Alignment.MIDDLE_RIGHT);

    TextField tf3 = new TextField();
    tf3.setValue(this.errorOccurrence.getEventLifeIdentifier());
    tf3.setReadOnly(true);
    tf3.setWidth("80%");
    layout.addComponent(tf3, 1, 3);

    label = new Label("Date/Time:");
    label.setSizeUndefined();
    layout.addComponent(label, 0, 4);
    layout.setComponentAlignment(label, Alignment.MIDDLE_RIGHT);

    TextField tf4 = new TextField();
    tf4.setValue(new Date(this.exclusionEvent.getTimestamp()).toString());
    tf4.setReadOnly(true);
    tf4.setWidth("80%");
    layout.addComponent(tf4, 1, 4);

    label = new Label("Error URI:");
    label.setSizeUndefined();
    layout.addComponent(label, 0, 5);
    layout.setComponentAlignment(label, Alignment.MIDDLE_RIGHT);

    TextField tf5 = new TextField();
    tf5.setValue(exclusionEvent.getErrorUri());
    tf5.setReadOnly(true);
    tf5.setWidth("80%");
    layout.addComponent(tf5, 1, 5);

    label = new Label("Action:");
    label.setSizeUndefined();
    layout.addComponent(label, 2, 1);
    layout.setComponentAlignment(label, Alignment.MIDDLE_RIGHT);

    final TextField tf6 = new TextField();
    if (this.action != null) {
        tf6.setValue(action.getAction());
    }
    tf6.setReadOnly(true);
    tf6.setWidth("80%");
    layout.addComponent(tf6, 3, 1);

    label = new Label("Actioned By:");
    label.setSizeUndefined();
    layout.addComponent(label, 2, 2);
    layout.setComponentAlignment(label, Alignment.MIDDLE_RIGHT);

    final TextField tf7 = new TextField();
    if (this.action != null) {
        tf7.setValue(action.getActionedBy());
    }
    tf7.setReadOnly(true);
    tf7.setWidth("80%");
    layout.addComponent(tf7, 3, 2);

    label = new Label("Actioned Time:");
    label.setSizeUndefined();
    layout.addComponent(label, 2, 3);
    layout.setComponentAlignment(label, Alignment.MIDDLE_RIGHT);

    final TextField tf8 = new TextField();
    if (this.action != null) {
        tf8.setValue(new Date(action.getTimestamp()).toString());
    }
    tf8.setReadOnly(true);
    tf8.setWidth("80%");
    layout.addComponent(tf8, 3, 3);

    final Button resubmitButton = new Button("Re-submit");
    final Button ignoreButton = new Button("Ignore");

    resubmitButton.addClickListener(new Button.ClickListener() {
        @SuppressWarnings("unchecked")
        public void buttonClick(ClickEvent event) {
            IkasanAuthentication authentication = (IkasanAuthentication) VaadinService.getCurrentRequest()
                    .getWrappedSession().getAttribute(DashboardSessionValueConstants.USER);

            HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(authentication.getName(),
                    (String) authentication.getCredentials());

            ClientConfig clientConfig = new ClientConfig();
            clientConfig.register(feature);

            Client client = ClientBuilder.newClient(clientConfig);

            Module module = topologyService.getModuleByName(exclusionEvent.getModuleName());

            if (module == null) {
                Notification
                        .show("Unable to find server information for module we are attempting to re-submit to: "
                                + exclusionEvent.getModuleName(), Type.ERROR_MESSAGE);

                return;
            }

            Server server = module.getServer();

            String url = "http://" + server.getUrl() + ":" + server.getPort() + module.getContextRoot()
                    + "/rest/resubmission/resubmit/" + exclusionEvent.getModuleName() + "/"
                    + exclusionEvent.getFlowName() + "/" + exclusionEvent.getErrorUri();

            logger.info("Resubmission Url: " + url);

            WebTarget webTarget = client.target(url);
            Response response = webTarget.request()
                    .put(Entity.entity(exclusionEvent.getEvent(), MediaType.APPLICATION_OCTET_STREAM));

            if (response.getStatus() != 200) {
                response.bufferEntity();

                String responseMessage = response.readEntity(String.class);
                Notification.show("An error was received trying to resubmit event: " + responseMessage,
                        Type.ERROR_MESSAGE);
            } else {
                Notification.show("Event resumitted successfully.");
                resubmitButton.setVisible(false);
                ignoreButton.setVisible(false);

                ExclusionEventAction action = hospitalManagementService
                        .getExclusionEventActionByErrorUri(exclusionEvent.getErrorUri());
                tf6.setReadOnly(false);
                tf7.setReadOnly(false);
                tf8.setReadOnly(false);
                tf6.setValue(action.getAction());
                tf7.setValue(action.getActionedBy());
                tf8.setValue(new Date(action.getTimestamp()).toString());
                tf6.setReadOnly(true);
                tf7.setReadOnly(true);
                tf8.setReadOnly(true);
            }
        }
    });

    ignoreButton.addClickListener(new Button.ClickListener() {
        @SuppressWarnings("unchecked")
        public void buttonClick(ClickEvent event) {
            IkasanAuthentication authentication = (IkasanAuthentication) VaadinService.getCurrentRequest()
                    .getWrappedSession().getAttribute(DashboardSessionValueConstants.USER);

            HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(authentication.getName(),
                    (String) authentication.getCredentials());

            ClientConfig clientConfig = new ClientConfig();
            clientConfig.register(feature);

            Client client = ClientBuilder.newClient(clientConfig);

            Module module = topologyService.getModuleByName(exclusionEvent.getModuleName());

            if (module == null) {
                Notification
                        .show("Unable to find server information for module we are submitting the ignore to: "
                                + exclusionEvent.getModuleName(), Type.ERROR_MESSAGE);

                return;
            }

            Server server = module.getServer();

            String url = "http://" + server.getUrl() + ":" + server.getPort() + module.getContextRoot()
                    + "/rest/resubmission/ignore/" + exclusionEvent.getModuleName() + "/"
                    + exclusionEvent.getFlowName() + "/" + exclusionEvent.getErrorUri();

            logger.info("Ignore Url: " + url);

            WebTarget webTarget = client.target(url);
            Response response = webTarget.request()
                    .put(Entity.entity(exclusionEvent.getEvent(), MediaType.APPLICATION_OCTET_STREAM));

            if (response.getStatus() != 200) {
                response.bufferEntity();

                String responseMessage = response.readEntity(String.class);
                Notification.show("An error was received trying to resubmit event: " + responseMessage,
                        Type.ERROR_MESSAGE);
            } else {
                Notification.show("Event ignored successfully.");
                resubmitButton.setVisible(false);
                ignoreButton.setVisible(false);

                ExclusionEventAction action = hospitalManagementService
                        .getExclusionEventActionByErrorUri(exclusionEvent.getErrorUri());
                tf6.setReadOnly(false);
                tf7.setReadOnly(false);
                tf8.setReadOnly(false);
                tf6.setValue(action.getAction());
                tf7.setValue(action.getActionedBy());
                tf8.setValue(new Date(action.getTimestamp()).toString());
                tf6.setReadOnly(true);
                tf7.setReadOnly(true);
                tf8.setReadOnly(true);
            }
        }
    });

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setHeight("100%");
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth(200, Unit.PIXELS);
    buttonLayout.setMargin(true);
    buttonLayout.addComponent(resubmitButton);
    buttonLayout.addComponent(ignoreButton);

    if (this.action == null) {
        layout.addComponent(buttonLayout, 0, 6, 3, 6);
        layout.setComponentAlignment(buttonLayout, Alignment.MIDDLE_CENTER);
    }

    final IkasanAuthentication authentication = (IkasanAuthentication) VaadinService.getCurrentRequest()
            .getWrappedSession().getAttribute(DashboardSessionValueConstants.USER);

    if (authentication != null && (!authentication.hasGrantedAuthority(SecurityConstants.ALL_AUTHORITY)
            && !authentication.hasGrantedAuthority(SecurityConstants.ACTION_EXCLUSIONS_AUTHORITY))) {
        resubmitButton.setVisible(false);
        ignoreButton.setVisible(false);
    }

    AceEditor eventEditor = new AceEditor();
    eventEditor.setCaption("Event Payload");
    logger.info("Setting exclusion event to: " + new String(this.exclusionEvent.getEvent()));
    Object event = this.serialiserFactory.getDefaultSerialiser().deserialise(this.exclusionEvent.getEvent());
    eventEditor.setValue(event.toString());
    eventEditor.setReadOnly(true);
    eventEditor.setMode(AceMode.java);
    eventEditor.setTheme(AceTheme.eclipse);
    eventEditor.setWidth("100%");
    eventEditor.setHeight(600, Unit.PIXELS);

    HorizontalLayout eventEditorLayout = new HorizontalLayout();
    eventEditorLayout.setSizeFull();
    eventEditorLayout.setMargin(true);
    eventEditorLayout.addComponent(eventEditor);

    AceEditor errorEditor = new AceEditor();
    errorEditor.setCaption("Error Details");
    errorEditor.setValue(this.errorOccurrence.getErrorDetail());
    errorEditor.setReadOnly(true);
    errorEditor.setMode(AceMode.xml);
    errorEditor.setTheme(AceTheme.eclipse);
    errorEditor.setWidth("100%");
    errorEditor.setHeight(600, Unit.PIXELS);

    HorizontalLayout errorEditorLayout = new HorizontalLayout();
    errorEditorLayout.setSizeFull();
    errorEditorLayout.setMargin(true);
    errorEditorLayout.addComponent(errorEditor);

    VerticalSplitPanel splitPanel = new VerticalSplitPanel();
    splitPanel.addStyleName(ValoTheme.SPLITPANEL_LARGE);
    splitPanel.setWidth("100%");
    splitPanel.setHeight(800, Unit.PIXELS);

    HorizontalLayout h1 = new HorizontalLayout();
    h1.setSizeFull();
    h1.setMargin(true);
    h1.addComponent(eventEditorLayout);
    splitPanel.setFirstComponent(eventEditorLayout);

    HorizontalLayout h2 = new HorizontalLayout();
    h2.setSizeFull();
    h2.setMargin(true);
    h2.addComponent(errorEditorLayout);
    splitPanel.setSecondComponent(errorEditorLayout);

    HorizontalLayout formLayout = new HorizontalLayout();
    formLayout.setWidth("100%");
    formLayout.setHeight(240, Unit.PIXELS);
    formLayout.addComponent(layout);

    GridLayout wrapperLayout = new GridLayout(1, 4);
    wrapperLayout.setMargin(true);
    wrapperLayout.setWidth("100%");
    wrapperLayout.addComponent(formLayout);
    wrapperLayout.addComponent(splitPanel);

    exclusionEventDetailsPanel.setContent(wrapperLayout);
    return exclusionEventDetailsPanel;
}

From source file:org.jumpmind.vaadin.ui.common.NotifyDialog.java

License:Open Source License

public NotifyDialog(String caption, String text, final Throwable ex, Type type) {
    super(caption);
    setWidth(400, Unit.PIXELS);/*from   w w  w  .j  a  va2  s.  com*/
    setHeight(300, Unit.PIXELS);

    final HorizontalLayout messageArea = new HorizontalLayout();
    messageArea.addStyleName("v-scrollable");
    messageArea.setMargin(true);
    messageArea.setSpacing(true);
    messageArea.setSizeFull();

    text = isNotBlank(text) ? text : (ex != null ? ex.getMessage() : "");
    if (type == Type.ERROR_MESSAGE) {
        setIcon(FontAwesome.BAN);
    }

    final String message = text;

    final Label textLabel = new Label(message, ContentMode.HTML);
    messageArea.addComponent(textLabel);
    messageArea.setExpandRatio(textLabel, 1);

    content.addComponent(messageArea);
    content.setExpandRatio(messageArea, 1);

    final Button detailsButton = new Button("Details");
    detailsButton.setVisible(ex != null);
    detailsButton.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            detailsMode = !detailsMode;
            if (detailsMode) {
                String msg = "<pre>" + ExceptionUtils.getStackTrace(ex).trim() + "</pre>";
                msg = msg.replace("\t", "    ");
                textLabel.setValue(msg);
                detailsButton.setCaption("Message");
                messageArea.setMargin(new MarginInfo(false, false, false, true));
                setHeight(600, Unit.PIXELS);
                setWidth(1000, Unit.PIXELS);
                setPosition(getPositionX() - 300, getPositionY() - 150);
            } else {
                textLabel.setValue(message);
                detailsButton.setCaption("Details");
                messageArea.setMargin(true);
                setWidth(400, Unit.PIXELS);
                setHeight(300, Unit.PIXELS);
                setPosition(getPositionX() + 300, getPositionY() + 150);
            }
        }
    });

    content.addComponent(buildButtonFooter(detailsButton, buildCloseButton()));

}

From source file:org.lucidj.newview.NewView.java

License:Apache License

private Layout form_location_panel() {
    VerticalLayout rolldown = new VerticalLayout();
    rolldown.setCaption("Location");
    rolldown.setSpacing(true);/* ww  w  . j  a va2s  .  co m*/

    HorizontalLayout directory_and_browse = new HorizontalLayout();
    directory_and_browse.setSpacing(true);
    directory_and_browse.setWidth(100, Unit.PERCENTAGE);

    frm_directory = new TextField();
    frm_directory.setValue(projects_dir.toString());
    frm_directory.setWidth(100, Unit.PERCENTAGE);
    directory_and_browse.addComponent(frm_directory);
    Button confirm = new Button("Save");
    confirm.addStyleName(ValoTheme.BUTTON_PRIMARY);
    confirm.setVisible(false);
    directory_and_browse.addComponent(confirm);
    Button change_directory = new Button("Change location...");
    directory_and_browse.addComponent(change_directory);
    directory_and_browse.setExpandRatio(frm_directory, 1.0f);
    rolldown.addComponent(directory_and_browse);

    Path projects_home = securityEngine.getSubject().getDefaultUserDir();
    frm_directories = rendererFactory.newRenderer(projects_home);
    frm_directories.setVisible(false);
    rolldown.addComponent(frm_directories);

    change_directory.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            if (frm_directories.isVisible()) {
                change_directory.setCaption("Change location...");
                frm_directories.setVisible(false);
                confirm.setVisible(false);
            } else {
                change_directory.setCaption("Cancel change");
                frm_directories.setVisible(true);
                confirm.setVisible(true);
            }
        }
    });

    frm_directories.addListener(new Listener() {
        @Override
        public void componentEvent(Event event) {
            if (event instanceof ItemClickEvent) {
                ItemClickEvent itemClickEvent = (ItemClickEvent) event;
                File item_id = ((File) itemClickEvent.getItemId());

                log.info("CLICK item_path={}", item_id);
                frm_directory.setValue(item_id.getPath());
            }
        }
    });

    return (rolldown);
}

From source file:roart.client.MyVaadinUI.java

private void setVisibilities() {
    if ((boolean) getSession().getAttribute("authenticate")) {
        Button login = (Button) getSession().getAttribute("login");
        Button logout = (Button) getSession().getAttribute("logout");
        if (!getSession().getAttribute(Constants.USER).equals(Constants.NONE)) {
            login.setVisible(false);
            logout.setVisible(true);//from   w w w .jav a2s.co  m
        } else {
            logout.setVisible(false);
            login.setVisible(true);
        }
    }
    VerticalLayout cpTab = (VerticalLayout) getSession().getAttribute("controlpanel");
    if (Constants.ADMIN.equals(getSession().getAttribute(Constants.USER))) {
        cpTab.setVisible(true);
        statLabel.setVisible(true);
        ClientRunner.uiset.putIfAbsent(this, "value");
    } else {
        cpTab.setVisible(false);
        statLabel.setVisible(false);
        ClientRunner.uiset.remove(this, "value");
    }
    VerticalLayout sTab = (VerticalLayout) getSession().getAttribute("search");
    if (!Constants.NONE.equals(getSession().getAttribute(Constants.USER))) {
        sTab.setVisible(true);
    } else {
        sTab.setVisible(false);
    }
}

From source file:ru.codeinside.adm.ui.AdminApp.java

License:Mozilla Public License

private Panel createEmailDatesPanel() {
    VerticalLayout emailDates = new VerticalLayout();
    emailDates.setSpacing(true);/*  w  w  w  .ja  va2  s .  co m*/
    emailDates.setMargin(true);
    emailDates.setSizeFull();
    Panel panel2 = new Panel(" ? ??", emailDates);
    panel2.setSizeFull();

    final TextField emailToField = new TextField("e-mail ?:");
    emailToField.setValue(get(API.EMAIL_TO));
    emailToField.setRequired(true);
    emailToField.setReadOnly(true);
    emailToField.addValidator(new EmailValidator("  e-mail ?"));

    final TextField receiverNameField = new TextField("? ?:");
    receiverNameField.setValue(get(API.RECEIVER_NAME));
    receiverNameField.setRequired(true);
    receiverNameField.setReadOnly(true);

    final TextField emailFromField = new TextField("e-mail ?:");
    emailFromField.setValue(get(API.EMAIL_FROM));
    emailFromField.setRequired(true);
    emailFromField.setReadOnly(true);
    emailFromField.addValidator(new EmailValidator("  e-mail ?"));

    final TextField senderLoginField = new TextField(" ?:");
    senderLoginField.setValue(get(API.SENDER_LOGIN));
    senderLoginField.setRequired(true);
    senderLoginField.setReadOnly(true);

    final TextField senderNameField = new TextField("? ?:");
    senderNameField.setValue(get(API.SENDER_NAME));
    senderNameField.setRequired(true);
    senderNameField.setReadOnly(true);

    final PasswordField passwordField = new PasswordField(":");
    passwordField.setValue(API.PASSWORD);
    passwordField.setRequired(true);
    passwordField.setReadOnly(true);

    final TextField hostField = new TextField("SMTP ?:");
    String host = get(API.HOST);
    hostField.setValue(host == null ? "" : host);
    hostField.setRequired(true);
    hostField.setReadOnly(true);

    final TextField portField = new TextField(":");
    String port = get(API.PORT);
    portField.setValue(port == null ? "" : port);
    portField.setRequired(true);
    portField.setReadOnly(true);
    portField.addValidator(new IntegerValidator(" "));

    final CheckBox tls = new CheckBox("? TLS",
            AdminServiceProvider.getBoolProperty(API.TLS));
    tls.setReadOnly(true);

    final Button save = new Button("");
    save.setVisible(false);
    final Button cancel = new Button("");
    cancel.setVisible(false);
    final Button change = new Button("");
    final Button check = new Button("");
    check.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            String emailTo = get(API.EMAIL_TO);
            String receiverName = get(API.RECEIVER_NAME);
            String hostName = get(API.HOST);
            String port = get(API.PORT);
            String senderLogin = get(API.SENDER_LOGIN);
            String password = get(API.PASSWORD);
            String emailFrom = get(API.EMAIL_FROM);
            String senderName = get(API.SENDER_NAME);
            if (emailTo.isEmpty() || receiverName.isEmpty() || hostName.isEmpty() || port.isEmpty()
                    || senderLogin.isEmpty() || password.isEmpty() || emailFrom.isEmpty()
                    || senderName.isEmpty()) {
                check.getWindow().showNotification("? ? ");
                return;
            }
            Email email = new SimpleEmail();
            try {
                email.setSubject("? ?");
                email.setMsg("? ?");
                email.addTo(emailTo, receiverName);
                email.setHostName(hostName);
                email.setSmtpPort(Integer.parseInt(port));
                email.setTLS(AdminServiceProvider.getBoolProperty(API.TLS));
                email.setAuthentication(senderLogin, password);
                email.setFrom(emailFrom, senderName);
                email.setCharset("utf-8");
                email.send();
            } catch (EmailException e) {
                check.getWindow().showNotification(e.getMessage());
                e.printStackTrace();
                return;
            }
            check.getWindow().showNotification("? ? ");
        }
    });
    change.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            emailToField.setReadOnly(false);
            receiverNameField.setReadOnly(false);
            emailFromField.setReadOnly(false);
            senderLoginField.setReadOnly(false);
            senderNameField.setReadOnly(false);
            passwordField.setReadOnly(false);
            hostField.setReadOnly(false);
            portField.setReadOnly(false);
            tls.setReadOnly(false);

            change.setVisible(false);
            check.setVisible(false);
            save.setVisible(true);
            cancel.setVisible(true);
        }
    });
    save.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (StringUtils.isEmpty((String) emailToField.getValue())
                    || StringUtils.isEmpty((String) receiverNameField.getValue())
                    || StringUtils.isEmpty((String) emailFromField.getValue())
                    || StringUtils.isEmpty((String) senderNameField.getValue())
                    || StringUtils.isEmpty((String) senderLoginField.getValue())
                    || StringUtils.isEmpty((String) passwordField.getValue())
                    || StringUtils.isEmpty((String) hostField.getValue()) || portField.getValue() == null) {
                emailToField.getWindow().showNotification(" ?",
                        Window.Notification.TYPE_HUMANIZED_MESSAGE);
                return;
            }
            boolean errors = false;
            try {
                emailToField.validate();
            } catch (Validator.InvalidValueException ignore) {
                errors = true;
            }
            try {
                emailFromField.validate();
            } catch (Validator.InvalidValueException ignore) {
                errors = true;
            }
            try {
                portField.validate();
            } catch (Validator.InvalidValueException ignore) {
                errors = true;
            }
            if (errors) {
                return;
            }
            set(API.EMAIL_TO, emailToField.getValue());
            set(API.RECEIVER_NAME, receiverNameField.getValue());
            set(API.EMAIL_FROM, emailFromField.getValue());
            set(API.SENDER_LOGIN, senderLoginField.getValue());
            set(API.SENDER_NAME, senderNameField.getValue());
            set(API.PASSWORD, passwordField.getValue());
            set(API.HOST, hostField.getValue());
            set(API.PORT, portField.getValue());
            set(API.TLS, tls.getValue());

            emailToField.setReadOnly(true);
            receiverNameField.setReadOnly(true);
            emailFromField.setReadOnly(true);
            senderLoginField.setReadOnly(true);
            senderNameField.setReadOnly(true);
            passwordField.setReadOnly(true);
            hostField.setReadOnly(true);
            portField.setReadOnly(true);
            tls.setReadOnly(true);

            save.setVisible(false);
            cancel.setVisible(false);
            change.setVisible(true);
            check.setVisible(true);
            emailToField.getWindow().showNotification("?? ?",
                    Window.Notification.TYPE_HUMANIZED_MESSAGE);
        }
    });
    cancel.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            emailToField.setValue(get(API.EMAIL_TO));
            receiverNameField.setValue(get(API.RECEIVER_NAME));
            emailFromField.setValue(get(API.EMAIL_FROM));
            senderLoginField.setValue(get(API.SENDER_LOGIN));
            senderNameField.setValue(get(API.SENDER_NAME));
            passwordField.setValue(get(API.PASSWORD));
            hostField.setValue(get(API.HOST));
            portField.setValue(get(API.PORT));
            tls.setValue(AdminServiceProvider.getBoolProperty(API.TLS));

            emailToField.setReadOnly(true);
            receiverNameField.setReadOnly(true);
            emailFromField.setReadOnly(true);
            senderLoginField.setReadOnly(true);
            senderNameField.setReadOnly(true);
            passwordField.setReadOnly(true);
            hostField.setReadOnly(true);
            portField.setReadOnly(true);
            tls.setReadOnly(true);

            save.setVisible(false);
            cancel.setVisible(false);
            change.setVisible(true);
            check.setVisible(true);
        }
    });

    FormLayout fields1 = new FormLayout();
    fields1.setSizeFull();
    fields1.addComponent(senderLoginField);
    fields1.addComponent(passwordField);
    fields1.addComponent(hostField);
    fields1.addComponent(portField);
    fields1.addComponent(tls);

    FormLayout fields2 = new FormLayout();
    fields2.setSizeFull();
    fields2.addComponent(emailToField);
    fields2.addComponent(receiverNameField);
    fields2.addComponent(emailFromField);
    fields2.addComponent(senderNameField);

    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);
    fields.setSizeFull();
    fields.addComponent(fields1);
    fields.addComponent(fields2);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.addComponent(change);
    buttons.addComponent(save);
    buttons.addComponent(cancel);
    buttons.addComponent(check);

    Label label = new Label("?? ");
    label.addStyleName(Reindeer.LABEL_H2);
    emailDates.addComponent(label);
    emailDates.addComponent(fields);
    emailDates.addComponent(buttons);
    emailDates.setExpandRatio(fields, 1f);
    return panel2;
}

From source file:ru.codeinside.adm.ui.AdminApp.java

License:Mozilla Public License

private Panel createMilTaskConfigPanel() {
    VerticalLayout mailConfig = new VerticalLayout();
    mailConfig.setSpacing(true);//from  w  w w  .  jav a  2s .  c  om
    mailConfig.setMargin(true);
    mailConfig.setSizeFull();
    Panel emailTaskPanel = new Panel("?? SMTP ? Email Task", mailConfig);
    emailTaskPanel.setSizeFull();

    final TextField mtDefaultFrom = new TextField("email  :");
    mtDefaultFrom.setValue(get(API.MT_DEFAULT_FROM));
    mtDefaultFrom.setRequired(true);
    mtDefaultFrom.setReadOnly(true);
    mtDefaultFrom.addValidator(new EmailValidator("  e-mail ?"));

    final TextField mtSenderLoginField = new TextField(" ?:");
    mtSenderLoginField.setValue(get(API.MT_SENDER_LOGIN));
    mtSenderLoginField.setRequired(true);
    mtSenderLoginField.setReadOnly(true);

    final PasswordField mtPasswordField = new PasswordField(":");
    mtPasswordField.setValue(API.MT_PASSWORD);
    mtPasswordField.setRequired(true);
    mtPasswordField.setReadOnly(true);

    final TextField mtHostField = new TextField("SMTP ?:");
    String host = get(API.MT_HOST);
    mtHostField.setValue(host == null ? "" : host);
    mtHostField.setRequired(true);
    mtHostField.setReadOnly(true);

    final TextField mtPortField = new TextField(":");
    String port = get(API.MT_PORT);
    mtPortField.setValue(port == null ? "" : port);
    mtPortField.setRequired(true);
    mtPortField.setReadOnly(true);
    mtPortField.addValidator(new IntegerValidator(" "));

    final CheckBox mtTls = new CheckBox("? TLS",
            AdminServiceProvider.getBoolProperty(API.MT_TLS));
    mtTls.setReadOnly(true);

    final Button save = new Button("");
    save.setVisible(false);
    final Button cancel = new Button("");
    cancel.setVisible(false);
    final Button change = new Button("");

    change.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            mtSenderLoginField.setReadOnly(false);
            mtDefaultFrom.setReadOnly(false);
            mtPasswordField.setReadOnly(false);
            mtHostField.setReadOnly(false);
            mtPortField.setReadOnly(false);
            mtTls.setReadOnly(false);

            change.setVisible(false);
            save.setVisible(true);
            cancel.setVisible(true);
        }
    });
    save.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (StringUtils.isEmpty((String) mtSenderLoginField.getValue())
                    || StringUtils.isEmpty((String) mtDefaultFrom.getValue())
                    || StringUtils.isEmpty((String) mtPasswordField.getValue())
                    || StringUtils.isEmpty((String) mtHostField.getValue()) || mtPortField.getValue() == null) {
                mtSenderLoginField.getWindow().showNotification(" ?",
                        Window.Notification.TYPE_HUMANIZED_MESSAGE);
                return;
            }
            boolean errors = false;
            try {
                mtDefaultFrom.validate();
            } catch (Validator.InvalidValueException ignore) {
                errors = true;
            }
            try {
                mtPortField.validate();
            } catch (Validator.InvalidValueException ignore) {
                errors = true;
            }
            if (errors) {
                return;
            }
            set(API.MT_SENDER_LOGIN, mtSenderLoginField.getValue());
            set(API.MT_DEFAULT_FROM, mtDefaultFrom.getValue());
            set(API.MT_PASSWORD, mtPasswordField.getValue());
            set(API.MT_HOST, mtHostField.getValue());
            set(API.MT_PORT, mtPortField.getValue());
            set(API.MT_TLS, mtTls.getValue());

            mtSenderLoginField.setReadOnly(true);
            mtDefaultFrom.setReadOnly(true);
            mtPasswordField.setReadOnly(true);
            mtHostField.setReadOnly(true);
            mtPortField.setReadOnly(true);
            mtTls.setReadOnly(true);

            save.setVisible(false);
            cancel.setVisible(false);
            change.setVisible(true);
            mtSenderLoginField.getWindow().showNotification("?? ?",
                    Window.Notification.TYPE_HUMANIZED_MESSAGE);
        }
    });
    cancel.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            mtSenderLoginField.setValue(get(API.MT_SENDER_LOGIN));
            mtDefaultFrom.setValue(get(API.MT_DEFAULT_FROM));
            mtPasswordField.setValue(get(API.MT_PASSWORD));
            mtHostField.setValue(get(API.MT_HOST));
            mtPortField.setValue(get(API.MT_PORT));
            mtTls.setValue(AdminServiceProvider.getBoolProperty(API.MT_TLS));

            mtSenderLoginField.setReadOnly(true);
            mtDefaultFrom.setReadOnly(true);
            mtPasswordField.setReadOnly(true);
            mtHostField.setReadOnly(true);
            mtPortField.setReadOnly(true);
            mtTls.setReadOnly(true);

            save.setVisible(false);
            cancel.setVisible(false);
            change.setVisible(true);
        }
    });

    FormLayout leftFields = new FormLayout();
    leftFields.setSizeFull();
    leftFields.addComponent(mtSenderLoginField);
    leftFields.addComponent(mtDefaultFrom);
    leftFields.addComponent(mtPasswordField);
    leftFields.addComponent(mtHostField);
    leftFields.addComponent(mtPortField);

    FormLayout rightFields = new FormLayout();
    rightFields.setSizeFull();
    rightFields.addComponent(mtTls);

    HorizontalLayout fieldsLayout = new HorizontalLayout();
    fieldsLayout.setSpacing(true);
    fieldsLayout.setSizeFull();
    fieldsLayout.addComponent(leftFields);
    fieldsLayout.addComponent(rightFields);
    fieldsLayout.setExpandRatio(leftFields, 0.6f);
    fieldsLayout.setExpandRatio(rightFields, 0.4f);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.addComponent(change);
    buttons.addComponent(save);
    buttons.addComponent(cancel);

    Label label = new Label("?? Email Task");
    label.addStyleName(Reindeer.LABEL_H2);
    mailConfig.addComponent(label);
    mailConfig.addComponent(fieldsLayout);
    mailConfig.addComponent(buttons);
    mailConfig.setExpandRatio(fieldsLayout, 1f);
    return emailTaskPanel;
}