Example usage for com.vaadin.ui Button setDescription

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

Introduction

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

Prototype

public void setDescription(String description) 

Source Link

Document

Sets the component's description.

Usage

From source file:org.ikasan.dashboard.ui.mappingconfiguration.component.MappingConfigurationConfigurationValuesTable.java

License:BSD License

/**
 * Method to add a record to the component.
 * /*from  w w  w.j av  a2  s.c  o  m*/
 * @throws MappingConfigurationServiceException
 */
public void addNewRecord() throws MappingConfigurationServiceException {
    Long sourceSystemGroupId = null;

    if (this.mappingConfiguration.getNumberOfParams() > 1) {
        sourceSystemGroupId = this.mappingConfigurationService.getNextSequenceNumber();
    }
    TargetConfigurationValue targetConfigurationValue = new TargetConfigurationValue();
    targetConfigurationValue.setTargetSystemValue("Add targetSystemValue");

    this.mappingConfigurationService.saveTargetConfigurationValue(targetConfigurationValue);

    VerticalLayout tableCellLayout = new VerticalLayout();

    SourceConfigurationValue sourceConfigurationValue = null;
    final Button deleteButton = new Button("Delete");

    ArrayList<SourceConfigurationValue> sourceConfigurationValues = new ArrayList<SourceConfigurationValue>();

    for (int i = 0; i < this.mappingConfiguration.getNumberOfParams(); i++) {
        sourceConfigurationValue = new SourceConfigurationValue();
        sourceConfigurationValue.setSourceSystemValue("Add source system value");
        sourceConfigurationValue.setSourceConfigGroupId(sourceSystemGroupId);
        sourceConfigurationValue.setTargetConfigurationValue(targetConfigurationValue);
        sourceConfigurationValue.setMappingConfigurationId(this.mappingConfiguration.getId());

        sourceConfigurationValues.add(sourceConfigurationValue);

        this.mappingConfiguration.getSourceConfigurationValues().add(sourceConfigurationValue);

        BeanItem<SourceConfigurationValue> item = new BeanItem<SourceConfigurationValue>(
                sourceConfigurationValue);
        final TextField tf = new TextField(item.getItemProperty("sourceSystemValue"));

        tableCellLayout.addComponent(tf);
        tf.setReadOnly(true);
        tf.setWidth(300, Unit.PIXELS);
    }

    BeanItem<TargetConfigurationValue> targetConfigurationItem = new BeanItem<TargetConfigurationValue>(
            targetConfigurationValue);
    final TextField targetConfigurationTextField = new TextField(
            targetConfigurationItem.getItemProperty("targetSystemValue"));
    targetConfigurationTextField.setReadOnly(true);
    targetConfigurationTextField.setWidth(300, Unit.PIXELS);

    final DeleteRowAction action = new DeleteRowAction(sourceConfigurationValues, this.mappingConfiguration,
            this, this.mappingConfigurationService, this.systemEventService);

    deleteButton.setIcon(VaadinIcons.TRASH);
    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    deleteButton.setDescription("Delete this record");
    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    deleteButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            IkasanMessageDialog dialog = new IkasanMessageDialog("Delete record",
                    "This mapping configuration record will be permanently removed. "
                            + "Are you sure you wish to proceed?.",
                    action);

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

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

    if (authentication != null
            && (authentication.hasGrantedAuthority(SecurityConstants.ALL_AUTHORITY)
                    || authentication.hasGrantedAuthority(SecurityConstants.EDIT_MAPPING_AUTHORITY))
            || authentication.canAccessLinkedItem(PolicyLinkTypeConstants.MAPPING_CONFIGURATION_LINK_TYPE,
                    mappingConfiguration.getId())) {
        deleteButton.setVisible(true);
    } else {
        deleteButton.setVisible(false);
    }

    Item item = this.container.addItemAt(0, sourceConfigurationValue);
    Property<Layout> sourceProperty = item.getItemProperty("Source Configuration Value");
    sourceProperty.setValue(tableCellLayout);
    Property<TextField> targetProperty = item.getItemProperty("Target Configuration Value");
    targetProperty.setValue(targetConfigurationTextField);
    Property<Button> deleteProperty = item.getItemProperty("Delete");
    deleteProperty.setValue(deleteButton);

    this.mappingConfigurationService.saveMappingConfiguration(mappingConfiguration);

    this.setEditable(true);

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

    logger.info("User: " + principal.getName()
            + " added new mapping configuration value for Mapping Configuration " + this.mappingConfiguration);

    systemEventService.logSystemEvent(MappingConfigurationConstants.MAPPING_CONFIGURATION_SERVICE,
            "Added new mapping configuration value for Mapping Configuration: " + this.mappingConfiguration,
            principal.getName());
}

From source file:org.ikasan.dashboard.ui.mappingconfiguration.component.MappingConfigurationConfigurationValuesTable.java

License:BSD License

/**
 * Method to help populate the table with values associated with the MappingConfiguration.
 * //from   www  .  j  a  v a  2 s  .  c om
 * @param mappingConfiguration
 */
public void populateTable(final MappingConfiguration mappingConfiguration) {
    this.mappingConfiguration = mappingConfiguration;

    Set<SourceConfigurationValue> sourceConfigurationValues = mappingConfiguration
            .getSourceConfigurationValues();

    super.removeAllItems();

    Iterator<SourceConfigurationValue> sourceConfigurationValueItr = sourceConfigurationValues.iterator();

    ArrayList<SourceConfigurationValue> usedSourceConfigurationValues = new ArrayList<SourceConfigurationValue>();

    ArrayList<SourceConfigurationValue> groupedSourceSystemValues = new ArrayList<SourceConfigurationValue>();

    while (sourceConfigurationValueItr.hasNext()) {
        SourceConfigurationValue value = sourceConfigurationValueItr.next();

        VerticalLayout tableCellLayout = new VerticalLayout();

        for (int i = 0; i < this.mappingConfiguration.getNumberOfParams(); i++) {
            if (!usedSourceConfigurationValues.contains(value)) {
                groupedSourceSystemValues.add(value);

                BeanItem<SourceConfigurationValue> item = new BeanItem<SourceConfigurationValue>(value);
                final TextField tf = new TextField(item.getItemProperty("sourceSystemValue"));
                tf.setWidth(300, Unit.PIXELS);

                tableCellLayout.addComponent(tf);
                tf.setReadOnly(true);
                usedSourceConfigurationValues.add(value);

                Iterator<SourceConfigurationValue> partnerSourceConfigurationValueItr = sourceConfigurationValues
                        .iterator();

                while (partnerSourceConfigurationValueItr.hasNext()) {
                    SourceConfigurationValue partnerSourceConfigurationValue = partnerSourceConfigurationValueItr
                            .next();

                    if (partnerSourceConfigurationValue.getSourceConfigGroupId() != null
                            && !usedSourceConfigurationValues.contains(partnerSourceConfigurationValue)
                            && partnerSourceConfigurationValue.getId().compareTo(value.getId()) != 0
                            && partnerSourceConfigurationValue.getSourceConfigGroupId()
                                    .compareTo(value.getSourceConfigGroupId()) == 0) {
                        groupedSourceSystemValues.add(partnerSourceConfigurationValue);
                        item = new BeanItem<SourceConfigurationValue>(partnerSourceConfigurationValue);
                        final TextField stf = new TextField(item.getItemProperty("sourceSystemValue"));
                        stf.setWidth(300, Unit.PIXELS);

                        tableCellLayout.addComponent(stf);
                        stf.setReadOnly(true);
                        usedSourceConfigurationValues.add(partnerSourceConfigurationValue);
                    }
                }

                TargetConfigurationValue targetConfigurationValue = value.getTargetConfigurationValue();
                BeanItem<TargetConfigurationValue> targetConfigurationItem = new BeanItem<TargetConfigurationValue>(
                        targetConfigurationValue);
                final TextField targetConfigurationTextField = new TextField(
                        targetConfigurationItem.getItemProperty("targetSystemValue"));
                targetConfigurationTextField.setReadOnly(true);
                targetConfigurationTextField.setWidth(300, Unit.PIXELS);

                final DeleteRowAction action = new DeleteRowAction(groupedSourceSystemValues,
                        this.mappingConfiguration, this, this.mappingConfigurationService,
                        this.systemEventService);

                final Button deleteButton = new Button("Delete");
                deleteButton.setData(value);
                deleteButton.setIcon(VaadinIcons.TRASH);
                deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
                deleteButton.setDescription("Delete this record");
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                deleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        IkasanMessageDialog dialog = new IkasanMessageDialog("Delete record",
                                "This mapping configuration record will be permanently removed. "
                                        + "Are you sure you wish to proceed?.",
                                action);

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

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

                if (authentication != null
                        && (authentication.hasGrantedAuthority(SecurityConstants.ALL_AUTHORITY)
                                || authentication.hasGrantedAuthority(SecurityConstants.EDIT_MAPPING_AUTHORITY))
                        || authentication.canAccessLinkedItem(
                                PolicyLinkTypeConstants.MAPPING_CONFIGURATION_LINK_TYPE,
                                mappingConfiguration.getId())) {
                    deleteButton.setVisible(true);
                } else {
                    deleteButton.setVisible(false);
                }

                this.addItem(new Object[] { tableCellLayout, targetConfigurationTextField, deleteButton },
                        value);

                groupedSourceSystemValues = new ArrayList<SourceConfigurationValue>();
            }
        }

    }
}

From source file:org.ikasan.dashboard.ui.mappingconfiguration.listener.MappingSearchButtonClickListener.java

License:BSD License

@Override
public void buttonClick(ClickEvent event) {
    saveRequiredMonitor.manageSaveRequired("searchResultsPanel");

    String clientName = null;//w ww  .j a  v a  2s .c o m
    if (this.clientComboBox.getValue() != null) {
        clientName = ((ConfigurationServiceClient) this.clientComboBox.getValue()).getName();
    }

    String typeName = null;
    if (this.typeComboBox.getValue() != null) {
        typeName = ((ConfigurationType) this.typeComboBox.getValue()).getName();
    }

    String sourceContextName = null;
    if (this.sourceContextComboBox.getValue() != null) {
        sourceContextName = ((ConfigurationContext) this.sourceContextComboBox.getValue()).getName();
    }

    String targetContextName = null;
    if (this.targetContextComboBox.getValue() != null) {
        targetContextName = ((ConfigurationContext) this.targetContextComboBox.getValue()).getName();
    }

    List<MappingConfigurationLite> mappingConfigurations = this.mappingConfigurationService
            .getMappingConfigurationLites(clientName, typeName, sourceContextName, targetContextName);

    this.searchResultsTable.removeAllItems();

    for (MappingConfigurationLite mappingConfiguration : mappingConfigurations) {
        final DeleteMappingConfigurationAction action = new DeleteMappingConfigurationAction(
                mappingConfiguration.getId(), this.searchResultsTable, this.mappingConfigurationService,
                this.systemEventService);

        final Button deleteButton = new Button();
        deleteButton.setIcon(VaadinIcons.TRASH);
        deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
        deleteButton.setDescription("Delete this mapping configuration");
        deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
        deleteButton.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                IkasanMessageDialog dialog = new IkasanMessageDialog("Delete record",
                        "This mapping configuration record will be permanently removed. "
                                + "Are you sure you wish to proceed?.",
                        action);

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

        this.visibilityGroup.registerComponent(SecurityConstants.ALL_AUTHORITY, deleteButton);
        this.searchResultsTable.addItem(
                new Object[] { mappingConfiguration.getConfigurationServiceClient().getName(),
                        mappingConfiguration.getConfigurationType().getName(),
                        mappingConfiguration.getSourceContext().getName(),
                        mappingConfiguration.getTargetContext().getName(), deleteButton },
                mappingConfiguration.getId());
    }

}

From source file:org.ikasan.dashboard.ui.mappingconfiguration.panel.MappingConfigurationPanel.java

License:BSD License

/**
 * Helper method to initialise this object.
 *///ww w. jav  a 2s  .c  o m
@SuppressWarnings("serial")
protected void init() {
    layout = new GridLayout(5, 6);
    layout.setSpacing(true);
    layout.setMargin(true);
    layout.setWidth("100%");

    this.addStyleName(ValoTheme.PANEL_BORDERLESS);

    paramQueriesLayout = new VerticalLayout();

    toolBarLayout = new HorizontalLayout();
    toolBarLayout.setWidth("100%");

    Button linkButton = new Button();

    linkButton.setIcon(VaadinIcons.REPLY_ALL);
    linkButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    linkButton.setDescription("Return to search results");
    linkButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

    linkButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            Navigator navigator = new Navigator(UI.getCurrent(), menuLayout.getContentContainer());

            for (IkasanUIView view : topLevelNavigator.getIkasanViews()) {
                navigator.addView(view.getPath(), view.getView());
            }

            saveRequiredMonitor.manageSaveRequired("mappingView");

            navigator = new Navigator(UI.getCurrent(), mappingNavigator.getContainer());

            for (IkasanUIView view : mappingNavigator.getIkasanViews()) {
                navigator.addView(view.getPath(), view.getView());
            }
        }
    });

    toolBarLayout.addComponent(linkButton);
    toolBarLayout.setExpandRatio(linkButton, 0.865f);

    this.editButton.setIcon(VaadinIcons.EDIT);
    this.editButton.setDescription("Edit the mapping configuration");
    this.editButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.editButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    this.editButton.setVisible(false);
    this.editButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            setEditable(true);
            mappingConfigurationFunctionalGroup.editButtonPressed();
        }
    });

    toolBarLayout.addComponent(this.editButton);
    toolBarLayout.setExpandRatio(this.editButton, 0.045f);

    this.saveButton.setIcon(VaadinIcons.HARDDRIVE);
    this.saveButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.saveButton.setDescription("Save the mapping configuration");
    this.saveButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    this.saveButton.setVisible(false);
    this.saveButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                logger.info("Save button clicked!!");
                save();
                setEditable(false);
                Notification.show("Changes Saved!", "", Notification.Type.HUMANIZED_MESSAGE);
                mappingConfigurationFunctionalGroup.saveOrCancelButtonPressed();
            } catch (InvalidValueException e) {
                // We can ignore this one as we have already dealt with the
                // validation messages using the validation framework.
            } catch (Exception e) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);

                Notification.show("Cauget exception trying to save a Mapping Configuration!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);
            }
        }
    });

    toolBarLayout.addComponent(this.saveButton);
    toolBarLayout.setExpandRatio(this.saveButton, 0.045f);

    this.cancelButton.setIcon(VaadinIcons.CLOSE_CIRCLE);
    this.cancelButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.cancelButton.setDescription("Cancel the current edit");
    this.cancelButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    this.cancelButton.setVisible(false);
    this.cancelButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            setEditable(false);
            mappingConfigurationFunctionalGroup.saveOrCancelButtonPressed();

            Navigator navigator = new Navigator(UI.getCurrent(), menuLayout.getContentContainer());

            for (IkasanUIView view : topLevelNavigator.getIkasanViews()) {
                navigator.addView(view.getPath(), view.getView());
            }

            saveRequiredMonitor.manageSaveRequired("mappingView");

            navigator = new Navigator(UI.getCurrent(), mappingNavigator.getContainer());

            for (IkasanUIView view : mappingNavigator.getIkasanViews()) {
                navigator.addView(view.getPath(), view.getView());
            }
        }
    });

    toolBarLayout.addComponent(this.cancelButton);
    toolBarLayout.setExpandRatio(this.cancelButton, 0.045f);

    FileDownloader fd = new FileDownloader(this.getMappingConfigurationExportStream());
    fd.extend(exportMappingConfigurationButton);

    this.exportMappingConfigurationButton.setIcon(VaadinIcons.DOWNLOAD_ALT);
    this.exportMappingConfigurationButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.exportMappingConfigurationButton.setDescription("Export the current mapping configuration");
    this.exportMappingConfigurationButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    toolBarLayout.addComponent(this.exportMappingConfigurationButton);
    toolBarLayout.setExpandRatio(this.exportMappingConfigurationButton, 0.045f);

    final GridLayout contentLayout = new GridLayout(1, 2);
    contentLayout.setWidth("100%");

    contentLayout.addComponent(toolBarLayout);
    contentLayout.addComponent(createMappingConfigurationForm());

    VerticalSplitPanel vpanel = new VerticalSplitPanel(contentLayout, createTableLayout(false));
    vpanel.setStyleName(ValoTheme.SPLITPANEL_LARGE);

    paramQueriesLayout.setSpacing(true);

    Label configValueLabels = new Label("Source Configuration Value Queries:");
    layout.addComponent(configValueLabels, 2, 2, 3, 2);
    Panel queryParamsPanel = new Panel();
    queryParamsPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    queryParamsPanel.setHeight(100, Unit.PIXELS);
    queryParamsPanel.setWidth(100, Unit.PERCENTAGE);
    queryParamsPanel.setContent(paramQueriesLayout);
    this.layout.addComponent(queryParamsPanel, 2, 3, 3, 5);

    vpanel.setSplitPosition(325, Unit.PIXELS);
    this.setContent(vpanel);
    this.setSizeFull();
}

From source file:org.ikasan.dashboard.ui.mappingconfiguration.panel.NewMappingConfigurationPanel.java

License:BSD License

/**
 * Helper method to initialise this object.
 *///from w  w  w.  j av a  2  s .c  o  m
@SuppressWarnings("serial")
protected void init() {
    layout = new GridLayout(5, 6);
    layout.setSpacing(true);
    layout.setMargin(true);
    layout.setWidth("100%");

    this.addStyleName(ValoTheme.PANEL_BORDERLESS);

    this.parameterQueryTextFields = new ArrayList<TextField>();

    this.typeComboBox.setReadOnly(false);
    this.clientComboBox.setReadOnly(false);
    this.sourceContextComboBox.setReadOnly(false);
    this.targetContextComboBox.setReadOnly(false);
    super.clientComboBox.unselect(super.clientComboBox.getValue());
    super.sourceContextComboBox.unselect(super.sourceContextComboBox.getValue());
    super.targetContextComboBox.unselect(super.targetContextComboBox.getValue());
    super.typeComboBox.unselect(super.typeComboBox.getValue());

    super.mappingConfigurationFunctionalGroup.editButtonPressed();

    super.mappingConfiguration = new MappingConfiguration();
    this.mappingConfigurationConfigurationValuesTable.populateTable(mappingConfiguration);

    HorizontalLayout toolBarLayout = new HorizontalLayout();
    toolBarLayout.setWidth("100%");

    Label spacerLabel = new Label("");
    toolBarLayout.addComponent(spacerLabel);
    toolBarLayout.setExpandRatio(spacerLabel, 0.865f);

    this.editButton.setIcon(VaadinIcons.EDIT);
    this.editButton.setDescription("Edit the mapping configuration");
    this.editButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.editButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

    toolBarLayout.addComponent(editButton);
    toolBarLayout.setExpandRatio(editButton, 0.045f);

    this.saveButton.setIcon(VaadinIcons.HARDDRIVE);
    this.saveButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.saveButton.setDescription("Save the mapping configuration");
    this.saveButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

    toolBarLayout.addComponent(saveButton);
    toolBarLayout.setExpandRatio(saveButton, 0.045f);

    this.cancelButton.setIcon(VaadinIcons.CLOSE_CIRCLE);
    this.cancelButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    this.cancelButton.setDescription("Cancel the current edit");
    this.cancelButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

    toolBarLayout.addComponent(this.cancelButton);
    toolBarLayout.setExpandRatio(this.cancelButton, 0.045f);

    final VerticalLayout contentLayout = new VerticalLayout();

    contentLayout.addComponent(toolBarLayout);
    contentLayout.addComponent(createMappingConfigurationForm());

    VerticalSplitPanel vpanel = new VerticalSplitPanel(contentLayout, createTableLayout(false));
    vpanel.setStyleName(ValoTheme.SPLITPANEL_LARGE);

    Button addParametersButton = new Button();
    addParametersButton.setIcon(VaadinIcons.FORM);
    addParametersButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    addParametersButton.setDescription(
            "Add new key location queries. The number of fields created corresponds to the number of query parameters.");
    addParametersButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

    addParametersButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            addParamQueryFields();
        }
    });

    paramQueriesLayout.removeAllComponents();
    //        paramQueriesLayout.addComponent(addParametersButton);
    paramQueriesLayout.setSpacing(true);

    Label configValueLabels = new Label("Source Configuration Value Queries:");
    layout.addComponent(configValueLabels, 2, 2);
    layout.addComponent(addParametersButton, 3, 2);

    Panel queryParamsPanel = new Panel();
    queryParamsPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    queryParamsPanel.setHeight(140, Unit.PIXELS);
    queryParamsPanel.setWidth(100, Unit.PERCENTAGE);
    queryParamsPanel.setContent(paramQueriesLayout);
    this.layout.addComponent(queryParamsPanel, 2, 3, 3, 5);

    vpanel.setSplitPosition(325, Unit.PIXELS);
    this.setContent(vpanel);
    this.setSizeFull();

}

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

License:BSD License

public Layout createBusinessStreamLayout() {
    this.businessStreamTable = new Table();
    this.businessStreamTable.addContainerProperty("Server Name", String.class, null);
    this.businessStreamTable.addContainerProperty("Module Name", String.class, null);
    this.businessStreamTable.addContainerProperty("Flow Name", String.class, null);
    this.businessStreamTable.addContainerProperty("", Button.class, null);
    this.businessStreamTable.setWidth("100%");
    this.businessStreamTable.setHeight(600, Unit.PIXELS);
    this.businessStreamTable.setCellStyleGenerator(new IkasanSmallCellStyleGenerator());
    this.businessStreamTable.setDragMode(TableDragMode.ROW);
    this.businessStreamTable.setDropHandler(new DropHandler() {
        @Override//from w  w  w  .  j a va2s .  co  m
        public void drop(final DragAndDropEvent dropEvent) {
            final IkasanAuthentication authentication = (IkasanAuthentication) VaadinService.getCurrentRequest()
                    .getWrappedSession().getAttribute(DashboardSessionValueConstants.USER);

            if (authentication != null
                    && (!authentication.hasGrantedAuthority(SecurityConstants.ALL_AUTHORITY) && !authentication
                            .hasGrantedAuthority(SecurityConstants.MODIFY_BUSINESS_STREAM_AUTHORITY))) {
                Notification.show("You do not have the privilege to modify a business stream.");
                return;
            }

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

            if (t.getItemId() instanceof Flow) {
                final Flow flow = (Flow) t.getItemId();

                final BusinessStream businessStream = (BusinessStream) businessStreamCombo.getValue();
                BusinessStreamFlowKey key = new BusinessStreamFlowKey();
                key.setBusinessStreamId(businessStream.getId());
                key.setFlowId(flow.getId());
                final BusinessStreamFlow businessStreamFlow = new BusinessStreamFlow(key);
                businessStreamFlow.setFlow(flow);
                businessStreamFlow.setOrder(businessStreamTable.getItemIds().size());

                if (!businessStream.getFlows().contains(businessStreamFlow)) {
                    businessStream.getFlows().add(businessStreamFlow);

                    topologyService.saveBusinessStream(businessStream);

                    Button deleteButton = new Button();
                    Resource deleteIcon = VaadinIcons.TRASH;
                    deleteButton.setIcon(deleteIcon);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.setDescription("Delete the flow from the business stream.");

                    deleteButton.setData(businessStreamFlow);

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            businessStream.getFlows().remove(businessStreamFlow);

                            topologyService.deleteBusinessStreamFlow(businessStreamFlow);
                            topologyService.saveBusinessStream(businessStream);

                            businessStreamTable.removeItem(businessStreamFlow.getFlow());
                        }
                    });

                    businessStreamTable
                            .addItem(
                                    new Object[] { flow.getModule().getServer().getName(),
                                            flow.getModule().getName(), flow.getName(), deleteButton },
                                    businessStreamFlow);
                }
            } else if (t.getItemId() instanceof Module) {
                final Module sourceContainer = (Module) t.getItemId();

                for (Flow flow : sourceContainer.getFlows()) {

                    final BusinessStream businessStream = (BusinessStream) businessStreamCombo.getValue();
                    BusinessStreamFlowKey key = new BusinessStreamFlowKey();
                    key.setBusinessStreamId(businessStream.getId());
                    key.setFlowId(flow.getId());
                    final BusinessStreamFlow businessStreamFlow = new BusinessStreamFlow(key);
                    businessStreamFlow.setFlow(flow);
                    businessStreamFlow.setOrder(businessStreamTable.getItemIds().size());

                    if (!businessStream.getFlows().contains(businessStreamFlow)) {
                        businessStream.getFlows().add(businessStreamFlow);

                        topologyService.saveBusinessStream(businessStream);

                        Button deleteButton = new Button();
                        Resource deleteIcon = VaadinIcons.TRASH;

                        deleteButton.setIcon(deleteIcon);
                        deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
                        deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                        deleteButton.setDescription("Delete the flow from the business stream.");
                        deleteButton.setData(businessStreamFlow);

                        // Add the delete functionality to each role that is added
                        deleteButton.addClickListener(new Button.ClickListener() {
                            public void buttonClick(ClickEvent event) {
                                businessStream.getFlows().remove(businessStreamFlow);

                                topologyService.deleteBusinessStreamFlow(businessStreamFlow);
                                topologyService.saveBusinessStream(businessStream);

                                businessStreamTable.removeItem(businessStreamFlow.getFlow());
                            }
                        });

                        businessStreamTable.addItem(
                                new Object[] { flow.getModule().getServer().getName(),
                                        flow.getModule().getName(), flow.getName(), deleteButton },
                                businessStreamFlow);
                    }
                }
            } else {
                Notification.show("Only modules or flows can be dragged to this table.");
            }
        }

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

    GridLayout layout = new GridLayout(1, 6);
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setSizeFull();

    Label tableDropHintLabel = new Label();
    tableDropHintLabel.setCaptionAsHtml(true);
    tableDropHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " Drag modules or flows from the topology tree to the table below to build a business stream.");
    tableDropHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    tableDropHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);

    layout.addComponent(tableDropHintLabel);

    GridLayout controlsLayout = new GridLayout(3, 3);
    controlsLayout.setColumnExpandRatio(0, .05f);
    controlsLayout.setColumnExpandRatio(1, .65f);
    controlsLayout.setColumnExpandRatio(2, .3f);

    controlsLayout.setWidth("100%");
    controlsLayout.setSpacing(true);

    Label newBusinessStreamLabel = new Label("New Business Stream:");
    newBusinessStreamLabel.setSizeUndefined();
    controlsLayout.addComponent(newBusinessStreamLabel, 0, 0);
    controlsLayout.setComponentAlignment(newBusinessStreamLabel, Alignment.MIDDLE_RIGHT);

    Button newButton = new Button();
    newButton.setIcon(VaadinIcons.PLUS);
    newButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    newButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    newButton.setDescription("Create a new business stream.");
    newButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            final NewBusinessStreamWindow newBusinessStreamWindow = new NewBusinessStreamWindow();
            UI.getCurrent().addWindow(newBusinessStreamWindow);

            newBusinessStreamWindow.addCloseListener(new Window.CloseListener() {
                // inline close-listener
                public void windowClose(CloseEvent e) {
                    topologyService.saveBusinessStream(newBusinessStreamWindow.getBusinessStream());

                    businessStreamCombo.addItem(newBusinessStreamWindow.getBusinessStream());
                    businessStreamCombo.setItemCaption(newBusinessStreamWindow.getBusinessStream(),
                            newBusinessStreamWindow.getBusinessStream().getName());

                    businessStreamCombo.select(newBusinessStreamWindow.getBusinessStream());

                    businessStreamTable.removeAllItems();
                }
            });
        }
    });

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

    if (authentication != null && (!authentication.hasGrantedAuthority(SecurityConstants.ALL_AUTHORITY)
            && !authentication.hasGrantedAuthority(SecurityConstants.CREATE_BUSINESS_STREAM_AUTHORITY))) {
        newButton.setVisible(false);
    }

    controlsLayout.addComponent(newButton, 1, 0);

    Label businessStreamLabel = new Label("Business Stream:");
    businessStreamLabel.setSizeUndefined();

    final TextArea descriptionTextArea = new TextArea();
    descriptionTextArea.setReadOnly(true);

    this.businessStreamCombo.addValueChangeListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            if (event.getProperty() != null && event.getProperty().getValue() != null) {
                final BusinessStream businessStream = (BusinessStream) event.getProperty().getValue();

                descriptionTextArea.setReadOnly(false);
                descriptionTextArea.setValue(businessStream.getDescription());
                descriptionTextArea.setReadOnly(true);

                businessStreamTable.removeAllItems();

                for (final BusinessStreamFlow businessStreamFlow : businessStream.getFlows()) {
                    logger.info("Adding flow: " + businessStreamFlow);
                    Button deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.setDescription("Delete the flow from the business stream.");

                    // Add the delete functionality to each role that is added
                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            businessStream.getFlows().remove(businessStreamFlow);

                            topologyService.deleteBusinessStreamFlow(businessStreamFlow);
                            topologyService.saveBusinessStream(businessStream);

                            businessStreamTable.removeItem(businessStreamFlow.getFlow());
                        }
                    });

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

                    if (authentication != null
                            && (!authentication.hasGrantedAuthority(SecurityConstants.ALL_AUTHORITY)
                                    && !authentication.hasGrantedAuthority(
                                            SecurityConstants.MODIFY_BUSINESS_STREAM_AUTHORITY))) {
                        deleteButton.setVisible(false);
                    }

                    businessStreamTable.addItem(
                            new Object[] { businessStreamFlow.getFlow().getModule().getServer().getName(),
                                    businessStreamFlow.getFlow().getName(),
                                    businessStreamFlow.getFlow().getName(), deleteButton },
                            businessStreamFlow);
                }
            }
        }
    });
    businessStreamCombo.setWidth("100%");

    controlsLayout.addComponent(businessStreamLabel, 0, 1);
    controlsLayout.setComponentAlignment(businessStreamLabel, Alignment.MIDDLE_RIGHT);
    controlsLayout.addComponent(businessStreamCombo, 1, 1);

    Button deleteButton = new Button();
    deleteButton.setIcon(VaadinIcons.TRASH);
    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    deleteButton.setDescription("Delete the selected business stream.");
    deleteButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            Collection<BusinessStreamFlow> businessStreamFlows = (Collection<BusinessStreamFlow>) businessStreamTable
                    .getItemIds();

            for (BusinessStreamFlow businessStreamFlow : businessStreamFlows) {
                topologyService.deleteBusinessStreamFlow(businessStreamFlow);
            }

            BusinessStream businessStream = (BusinessStream) businessStreamCombo.getValue();

            topologyService.deleteBusinessStream(businessStream);

            businessStreamTable.removeAllItems();

            List<BusinessStream> businessStreams = topologyService.getAllBusinessStreams();

            businessStreamCombo.removeItem(businessStream);

            descriptionTextArea.setValue("");
        }
    });

    if (authentication != null && (!authentication.hasGrantedAuthority(SecurityConstants.ALL_AUTHORITY)
            && !authentication.hasGrantedAuthority(SecurityConstants.DELETE_BUSINESS_STREAM_AUTHORITY))) {
        deleteButton.setVisible(false);
    }

    controlsLayout.addComponent(deleteButton, 2, 1);

    Label descriptionLabel = new Label("Description:");
    descriptionLabel.setSizeUndefined();

    descriptionTextArea.setRows(4);
    descriptionTextArea.setWidth("100%");
    controlsLayout.addComponent(descriptionLabel, 0, 2);
    controlsLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT);
    controlsLayout.addComponent(descriptionTextArea, 1, 2);

    layout.addComponent(controlsLayout);
    layout.addComponent(this.businessStreamTable);

    return layout;
}

From source file:org.jdal.vaadin.ui.FormUtils.java

License:Apache License

/**
 * Build a new Button from Button Listener
 * @param buttonListener/*from  w ww  .  ja v  a2s  .  c om*/
 * @return a new Button
 */
public static Button newButton(ButtonListener buttonListener) {
    Button b = new Button(buttonListener.getCaption(), buttonListener);
    b.setIcon(buttonListener.getIcon());
    b.setDescription(buttonListener.getDescription());
    return b;
}

From source file:org.lucidj.iconlist.renderer.IconListRenderer.java

License:Apache License

private void button_caption_wrap(Button b) {
    String caption = b.getCaption();
    int wrap_len = 12;

    if (caption.length() > wrap_len) {
        String[] words = caption.split("\\s");
        String twoliner = "";
        int space_left = 0;
        int lines = 0;
        caption = "";

        // Simple greedy wrapping
        for (String word : words) {
            int len = word.length();

            if (len + 1 > space_left) {
                if (lines++ == 2) {
                    twoliner = caption + "\u2026"; // Unicode ellipsis
                }/*www. j  a  v a2  s .  c  om*/
                caption += caption.isEmpty() ? word : "<br/>" + word;
                space_left = wrap_len - len;
            } else {
                caption += " " + word;
                space_left -= len + 1;
            }
        }
        b.setCaptionAsHtml(true);
        b.setCaption(twoliner.isEmpty() ? caption : twoliner);
    }
    b.setDescription(caption);
}

From source file:org.opencms.ui.apps.CmsDefaultAppButtonProvider.java

License:Open Source License

/**
 * Creates a properly styled button for the given app.<p>
 *
 * @param cms the cms context/*from ww  w . j a va 2  s  .co m*/
 * @param appConfig the app configuration
 * @param locale the locale
 *
 * @return the button component
 */
public static Component createAppButton(CmsObject cms, final I_CmsWorkplaceAppConfiguration appConfig,
        Locale locale) {

    Button button = createAppIconButton(appConfig, locale);
    button.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            if ((appConfig instanceof I_CmsHasAppLaunchCommand)
                    && (((I_CmsHasAppLaunchCommand) appConfig).getAppLaunchCommand() != null)) {
                ((I_CmsHasAppLaunchCommand) appConfig).getAppLaunchCommand().run();
            } else {
                CmsAppWorkplaceUi ui = (CmsAppWorkplaceUi) A_CmsUI.get();
                ui.showApp(appConfig);
            }
        }
    });
    CmsAppVisibilityStatus status = appConfig.getVisibility(cms);
    if (!status.isActive()) {
        button.setEnabled(false);
        button.setDescription(status.getHelpText());
    } else {
        String helpText = appConfig.getHelpText(locale);
        button.setDescription(helpText);
    }
    return button;
}

From source file:org.opencms.ui.apps.CmsDefaultAppButtonProvider.java

License:Open Source License

/**
 * Creates an icon button.<p>//from   w w w  . java2  s .  co m
 *
 * @param name the name
 * @param description the description
 * @param icon the icon
 * @param buttonStyle the button style
 *
 * @return the created button
 */
public static Button createIconButton(String name, String description, Resource icon, String buttonStyle) {

    Button button = new Button(name);
    button.setIcon(icon, name);
    button.setDescription(description);
    button.addStyleName(OpenCmsTheme.APP_BUTTON);
    button.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    button.addStyleName(ValoTheme.BUTTON_ICON_ALIGN_TOP);
    button.addStyleName(buttonStyle);
    return button;
}