Example usage for com.vaadin.ui.renderers DateRenderer DateRenderer

List of usage examples for com.vaadin.ui.renderers DateRenderer DateRenderer

Introduction

In this page you can find the example usage for com.vaadin.ui.renderers DateRenderer DateRenderer.

Prototype

public DateRenderer(DateFormat dateFormat) throws IllegalArgumentException 

Source Link

Document

Creates a new date renderer.

Usage

From source file:org.jumpmind.metl.ui.views.design.ManageProjectsPanel.java

License:Open Source License

protected Component buildVersionGrid(Project project) {
    context.getConfigurationService().refresh(project);
    List<ProjectVersion> versions = project.getProjectVersions();
    BeanItemContainer<ProjectVersion> versionGridContainer = new BeanItemContainer<>(ProjectVersion.class);
    Grid versionGrid = new Grid();

    VerticalLayout layout = new VerticalLayout();
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setMargin(true);// w w  w.  java  2 s . c  o m
    layout.setSpacing(true);
    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    Button openButton = new Button("Open", (event) -> {
        Collection<Object> selected = versionGrid.getSelectedRows();
        for (Object object : selected) {
            projectNavigator.addProjectVersion(((ProjectVersion) object));
        }
    });
    buttons.addComponent(openButton);
    Button newButton = new Button("New Version", (event) -> newVersion(versionGrid));
    buttons.addComponent(newButton);
    Button editButton = new Button("Edit Version", (event) -> edit(versionGrid));
    buttons.addComponent(editButton);
    Button removeButton = new Button("Remove Version", (event) -> removeVersion(versionGrid));
    buttons.addComponent(removeButton);

    openButton.setEnabled(false);
    newButton.setEnabled(false);
    removeButton.setEnabled(false);
    editButton.setEnabled(false);

    layout.addComponent(buttons);

    versionGrid.setWidth(100, Unit.PERCENTAGE);
    versionGrid.setHeight(3 + (versions.size() * ROW_EM), Unit.EM);
    versionGrid.setEditorEnabled(true);
    versionGrid.setSelectionMode(SelectionMode.MULTI);

    versionGrid.addColumn("versionLabel", String.class).setHeaderCaption("Version").setExpandRatio(2);
    versionGrid.addColumn("description", String.class).setHeaderCaption("Description").setExpandRatio(1);
    versionGrid.addColumn("readOnly", Boolean.class).setHeaderCaption("Read Only").setMaximumWidth(100)
            .setRenderer(new HtmlRenderer(), new StringToBooleanConverter() {
                private static final long serialVersionUID = 1L;

                protected String getTrueString() {
                    return FontAwesome.CHECK.getHtml();
                };

                protected String getFalseString() {
                    return "";
                };
            });
    versionGrid.addColumn("createTime", Date.class).setHeaderCaption("Create Time").setWidth(185)
            .setMaximumWidth(200).setRenderer(new DateRenderer(UiConstants.DATETIME_FORMAT)).setEditable(false);

    versionGrid.setContainerDataSource(versionGridContainer);
    versionGrid.setEditorFieldFactory(new FieldFactory());

    versionGrid.getEditorFieldGroup().addCommitHandler(new FieldGroup.CommitHandler() {

        private static final long serialVersionUID = 1L;

        @Override
        public void preCommit(CommitEvent commitEvent) throws CommitException {
        }

        @Override
        public void postCommit(CommitEvent commitEvent) throws CommitException {
            ProjectVersion item = (ProjectVersion) versionGrid.getEditedItemId();
            IConfigurationService configurationService = context.getConfigurationService();
            configurationService.save(item);
            projectGrid.markAsDirty();
        }
    });

    versionGrid.addSelectionListener((event) -> {
        int numberSelected = versionGrid.getSelectedRows().size();
        boolean currentlyEditing = projectGrid.getEditedItemId() != null;
        boolean selected = numberSelected > 0 && !currentlyEditing;
        openButton.setEnabled(selected);
        newButton.setEnabled(selected);
        removeButton.setEnabled(selected);
        editButton.setEnabled(selected);
    });
    versionGrid.addItemClickListener(new GridClickListener(versionGrid));
    layout.addComponent(versionGrid);
    layout.setExpandRatio(versionGrid, 1);
    layout.addComponent(new Label(" "));
    versionGridContainer.addAll(versions);
    versionGrid.sort("versionLabel", SortDirection.DESCENDING);

    return layout;
}

From source file:org.jumpmind.metl.ui.views.manage.ExecutionRunPanel.java

License:Open Source License

public ExecutionRunPanel(String executionId, ApplicationContext context, TabbedPanel parentTabSheet,
        IFlowRunnable flowRunnable) {/*  www  .ja  v a  2s .  com*/
    this.executionService = context.getExecutionService();
    this.executionId = executionId;
    this.context = context;
    this.parentTabSheet = parentTabSheet;
    this.flowRunnable = flowRunnable;

    Execution execution = executionService.findExecution(executionId);
    this.flow = context.getConfigurationService().findFlow(execution.getFlowId());

    HorizontalLayout topBar = new HorizontalLayout();
    topBar.setMargin(new MarginInfo(true, true, false, true));
    topBar.setWidth(100, Unit.PERCENTAGE);

    HorizontalLayout left = new HorizontalLayout();
    topBar.addComponent(left);

    HorizontalLayout right = new HorizontalLayout();
    right.setSpacing(true);
    topBar.addComponent(right);
    topBar.setComponentAlignment(right, Alignment.MIDDLE_RIGHT);

    Label limitLabel = new Label("Max Log Messages To Show :");
    right.addComponent(limitLabel);
    right.setComponentAlignment(limitLabel, Alignment.MIDDLE_RIGHT);
    limitField = new ImmediateUpdateTextField(null) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void save(String text) {
            Setting setting = context.getUser().findSetting(UserSetting.SETTING_MAX_LOG_MESSAGE_TO_SHOW);
            setting.setValue(Integer.toString(getMaxToShow(text)));
            context.getConfigurationService().save(setting);
        }
    };
    limitField.setWidth("5em");
    limitField.setValue(context.getUser().get(UserSetting.SETTING_MAX_LOG_MESSAGE_TO_SHOW, "1000"));
    right.addComponent(limitField);
    right.setComponentAlignment(limitField, Alignment.MIDDLE_RIGHT);

    showDiagramCheckbox = new CheckBox("Show Diagram");
    showDiagramCheckbox.addValueChangeListener((event) -> {
        if (showDiagramCheckbox.getValue()) {
            showDiagram();
        } else {
            showDetails();
        }
    });
    right.addComponent(showDiagramCheckbox);
    right.setComponentAlignment(showDiagramCheckbox, Alignment.MIDDLE_RIGHT);

    addComponent(topBar);

    ButtonBar buttonBar = new ButtonBar();

    rerunButton = buttonBar.addButton("Rerun", Icons.RUN, event -> rerun());
    rerunButton.setVisible(false);
    removeButton = buttonBar.addButton("Remove", Icons.DELETE, event -> remove());
    removeButton.setVisible(false);
    cancelButton = buttonBar.addButton("Cancel", Icons.CANCEL, event -> cancel());

    addComponent(buttonBar);

    HorizontalLayout header1 = new HorizontalLayout();
    header1.addComponent(new Label("<b>Flow:</b>", ContentMode.HTML));
    header1.addComponent(flowLabel);
    header1.addComponent(new Label("<b>Start:</b>", ContentMode.HTML));
    header1.addComponent(startLabel);
    header1.setSpacing(true);
    header1.setMargin(new MarginInfo(false, true, false, true));
    header1.setWidth("100%");
    addComponent(header1);

    HorizontalLayout header2 = new HorizontalLayout();
    header2.addComponent(new Label("<b>Status:</b>", ContentMode.HTML));
    header2.addComponent(statusLabel);
    header2.addComponent(new Label("<b>End:</b>", ContentMode.HTML));
    header2.addComponent(endLabel);
    header2.setSpacing(true);
    header2.setMargin(new MarginInfo(false, true, true, true));
    header2.setWidth("100%");
    addComponent(header2);

    stepContainer.setBeanIdProperty("id");

    diagramLayout = new VerticalLayout();
    diagramLayout.setWidth(10000, Unit.PIXELS);
    diagramLayout.setHeight(10000, Unit.PIXELS);

    flowPanel = new Panel();
    flowPanel.setSizeFull();
    flowPanel.addStyleName(ValoTheme.PANEL_WELL);

    flowPanel.setContent(diagramLayout);

    stepTable.setContainerDataSource(stepContainer);
    stepTable.setSelectable(true);
    stepTable.setMultiSelect(true);
    stepTable.setImmediate(true);
    stepTable.setSizeFull();
    stepTable.setVisibleColumns(
            new Object[] { "componentName", "threadNumber", "status", "payloadReceived", "messagesReceived",
                    "messagesProduced", "payloadProduced", "startTime", "endTime", "handleDurationString" });
    stepTable.setColumnHeaders(new String[] { "Component Name", "Thread", "Status", "Payload Recvd",
            "Msgs Recvd", "Msgs Sent", "Payload Sent", "Start", "End", "Run Duration" });
    stepTable.setColumnWidth("status", 100);
    stepTable.setColumnWidth("messagesReceived", 100);
    stepTable.setColumnWidth("messagesProduced", 100);
    stepTable.setColumnWidth("payloadReceived", 100);
    stepTable.setColumnWidth("payloadProduced", 100);
    stepTable.setColumnWidth("threadNumber", 100);
    stepTable.setColumnWidth("startTime", 170);
    stepTable.setColumnWidth("endTime", 170);
    stepTable.setColumnExpandRatio("handleDurationString", 1);
    stepTable.addValueChangeListener(event -> {
        @SuppressWarnings("unchecked")
        Set<String> executionStepIds = (Set<String>) event.getProperty().getValue();
        logContainer.removeAllItems();
        List<ExecutionStepLog> logs = executionService.findExecutionStepLogs(executionStepIds, getMaxToShow());
        logContainer.addAll(logs);
    });

    stepTable.addValueChangeListener(event -> {
        @SuppressWarnings("unchecked")
        Set<String> executionStepIds = (Set<String>) event.getProperty().getValue();
        logContainer.removeAllItems();
        List<ExecutionStepLog> logs = executionService.findExecutionStepLogs(executionStepIds, getMaxToShow());
        logContainer.addAll(logs);
    });

    logTable = new Grid();
    logTable.addColumn("level", String.class).setHeaderCaption("Level").setWidth(110).setMaximumWidth(200);
    logTable.addColumn("createTime", Date.class).setHeaderCaption("Time").setWidth(120).setMaximumWidth(200)
            .setRenderer(new DateRenderer(UiConstants.TIME_FORMAT));
    logTable.addColumn("logText", String.class).setHeaderCaption("Message").setExpandRatio(1);
    logTable.setContainerDataSource(logContainer);
    logTable.setSizeFull();
    logTable.addItemClickListener(event -> logTableCellClicked(logTable, event));
    logTable.addSortListener(event -> {
        lastSortOrder = event.getSortOrder();
    });

    HeaderRow filteringHeader = logTable.appendHeaderRow();
    HeaderCell logTextFilterCell = filteringHeader.getCell("logText");
    TextField filterField = new TextField();
    filterField.setInputPrompt("Filter");
    filterField.addStyleName(ValoTheme.TEXTFIELD_TINY);
    filterField.setWidth("100%");

    // Update filter When the filter input is changed
    filterField.addTextChangeListener(change -> {
        // Can't modify filters so need to replace
        logContainer.removeContainerFilters("logText");

        // (Re)create the filter if necessary
        if (!change.getText().isEmpty())
            logContainer.addContainerFilter(new SimpleStringFilter("logText", change.getText(), true, false));
    });
    logTextFilterCell.setComponent(filterField);

    HeaderCell levelFilterCell = filteringHeader.getCell("level");
    ComboBox levelFilter = new ComboBox();
    levelFilter.setWidth(8, Unit.EM);
    levelFilter.setNullSelectionAllowed(true);
    LogLevel[] levels = LogLevel.values();
    for (LogLevel logLevel : levels) {
        levelFilter.addItem(logLevel.name());
    }
    levelFilter.addValueChangeListener(change -> {
        logContainer.removeContainerFilters("level");
        String text = (String) levelFilter.getValue();
        if (isNotBlank(text)) {
            logContainer.addContainerFilter(new SimpleStringFilter("level", text, true, false));
        }
    });
    levelFilterCell.setComponent(levelFilter);

    levelFilter.addStyleName(ValoTheme.COMBOBOX_TINY);

    splitPanel = new VerticalSplitPanel();
    splitPanel.setFirstComponent(flowPanel);
    splitPanel.setSecondComponent(logTable);
    splitPanel.setSplitPosition(50f);
    splitPanel.setSizeFull();
    addComponent(splitPanel);
    setExpandRatio(splitPanel, 1.0f);

    showDiagramCheckbox.setValue(context.getUser().getBoolean(UserSetting.SETTING_SHOW_RUN_DIAGRAM, true));
    if (!showDiagramCheckbox.getValue()) {
        showDetails();
    }

    context.getBackgroundRefresherService().register(this);
}

From source file:org.jumpmind.vaadin.ui.sqlexplorer.SqlHistoryDialog.java

License:Open Source License

public SqlHistoryDialog(ISettingsProvider settingsProvider, QueryPanel queryPanel) {
    super("Sql History");
    this.settingsProvider = settingsProvider;
    this.queryPanel = queryPanel;

    VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setSizeFull();//  ww w  . j  ava  2  s . co  m
    mainLayout.setMargin(true);
    mainLayout.setSpacing(true);
    addComponent(mainLayout, 1);

    final Set<SqlHistory> sqlHistories = new TreeSet<SqlHistory>(settingsProvider.get().getSqlHistory());

    table = new Grid();
    table.setImmediate(true);

    table.addColumn("sqlStatement", String.class).setHeaderCaption("SQL")
            .setConverter(new AbbreviatorConverter(50));

    table.addColumn("lastExecuteTime", Date.class).setHeaderCaption("Time").setWidth(150).setMaximumWidth(200)
            .setRenderer(new DateRenderer("%1$tk:%1$tM:%1$tS:%1$tL"));

    table.addColumn("lastExecuteDuration", Long.class).setHeaderCaption("Duration").setWidth(120)
            .setConverter(new DurationConverter());

    table.addColumn("executeCount", Long.class).setHeaderCaption("Count").setWidth(120);
    table.setEditorEnabled(false);
    table.setSelectionMode(SelectionMode.MULTI);
    table.setRowDescriptionGenerator(new RowDescriptionGenerator() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getDescription(RowReference row) {
            return (String) row.getItemId();
        }
    });
    final BeanContainer<String, SqlHistory> container = new BeanContainer<String, SqlHistory>(SqlHistory.class);
    container.setBeanIdProperty("sqlStatement");

    HeaderRow filteringHeader = table.appendHeaderRow();
    HeaderCell logTextFilterCell = filteringHeader.getCell("sqlStatement");
    TextField filterField = new TextField();
    filterField.setInputPrompt("Filter");
    filterField.addStyleName(ValoTheme.TEXTFIELD_TINY);
    filterField.setWidth("100%");

    // Update filter When the filter input is changed
    filterField.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void textChange(TextChangeEvent event) {
            // Can't modify filters so need to replace
            container.removeContainerFilters("sqlStatement");

            // (Re)create the filter if necessary
            if (!event.getText().isEmpty()) {
                container.addContainerFilter(
                        new SimpleStringFilter("sqlStatement", event.getText(), true, false));
            }

        }
    });
    logTextFilterCell.setComponent(filterField);

    table.setContainerDataSource(container);

    table.addItemClickListener(new ItemClickEvent.ItemClickListener() {

        private static final long serialVersionUID = 1L;

        public void itemClick(ItemClickEvent event) {
            Object object = event.getPropertyId();
            if (object != null && !object.toString().equals("")) {
                if (event.isDoubleClick()) {
                    table.select(event.getItemId());
                    select();
                } else {
                    Object row = event.getItemId();
                    if (!table.getSelectedRows().contains(row)) {
                        table.select(row);
                    } else {
                        table.deselect(row);
                    }
                }
            }
        }
    });

    table.setSizeFull();

    mainLayout.addComponent(table);
    mainLayout.setExpandRatio(table, 1);

    container.addAll(sqlHistories);

    Button cancelButton = new Button("Cancel");
    cancelButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

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

    Button applyButton = CommonUiUtils.createPrimaryButton("Select");
    applyButton.setClickShortcut(KeyCode.ENTER);
    applyButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

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

    addComponent(buildButtonFooter(cancelButton, applyButton));

}