Example usage for com.google.gwt.user.cellview.client Column setFieldUpdater

List of usage examples for com.google.gwt.user.cellview.client Column setFieldUpdater

Introduction

In this page you can find the example usage for com.google.gwt.user.cellview.client Column setFieldUpdater.

Prototype

public void setFieldUpdater(FieldUpdater<T, C> fieldUpdater) 

Source Link

Document

Set the FieldUpdater used for updating values in the column.

Usage

From source file:org.rstudio.studio.client.workbench.views.vcs.ChangelistTable.java

License:Open Source License

private void configureTable() {
    final Column<StatusAndPath, Boolean> stagedColumn = new Column<StatusAndPath, Boolean>(
            new TriStateCheckboxCell<StatusAndPath>(selectionModel_)) {
        @Override// w w  w. j  a va 2 s  .c o  m
        public Boolean getValue(StatusAndPath object) {
            return "??".equals(object.getStatus()) ? Boolean.FALSE
                    : object.getStatus().charAt(1) == ' ' ? Boolean.TRUE
                            : object.getStatus().charAt(0) == ' ' ? Boolean.FALSE : null;
        }
    };

    stagedColumn.setHorizontalAlignment(Column.ALIGN_CENTER);
    stagedColumn.setFieldUpdater(new FieldUpdater<StatusAndPath, Boolean>() {
        @Override
        public void update(final int index, final StatusAndPath object, Boolean value) {
            fireEvent(new StageUnstageEvent(!value, getSelectedItems()));
        }
    });
    stagedColumn.setSortable(true);
    sortHandler_.setComparator(stagedColumn, new Comparator<StatusAndPath>() {
        @Override
        public int compare(StatusAndPath a, StatusAndPath b) {
            Boolean a1 = stagedColumn.getValue(a);
            Boolean b1 = stagedColumn.getValue(b);
            int a2 = a1 == null ? 0 : a1 ? -1 : 1;
            int b2 = b1 == null ? 0 : b1 ? -1 : 1;
            return a2 - b2;
        }
    });
    table_.addColumn(stagedColumn, "Staged");
    table_.setColumnWidth(stagedColumn, "46px");

    Column<StatusAndPath, String> statusColumn = new Column<StatusAndPath, String>(
            new TextCell(new StatusRenderer())) {
        @Override
        public String getValue(StatusAndPath object) {
            return object.getStatus();
        }
    };
    statusColumn.setSortable(true);
    statusColumn.setHorizontalAlignment(Column.ALIGN_CENTER);
    table_.addColumn(statusColumn, "Status");
    table_.setColumnWidth(statusColumn, "56px");
    sortHandler_.setComparator(statusColumn, new Comparator<StatusAndPath>() {
        @Override
        public int compare(StatusAndPath a, StatusAndPath b) {
            return a.getStatus().compareTo(b.getStatus());
        }
    });

    TextColumn<StatusAndPath> pathColumn = new TextColumn<StatusAndPath>() {
        @Override
        public String getValue(StatusAndPath object) {
            return object.getPath();
        }
    };
    pathColumn.setSortable(true);
    sortHandler_.setComparator(pathColumn, new Comparator<StatusAndPath>() {
        private String[] splitDirAndName(String path) {
            int index = path.lastIndexOf("/");
            if (index < 0)
                index = path.lastIndexOf("\\");
            if (index < 0)
                return new String[] { "", path };
            else
                return new String[] { path.substring(0, index), path.substring(index + 1) };
        }

        @Override
        public int compare(StatusAndPath a, StatusAndPath b) {
            String[] splitA = splitDirAndName(a.getPath());
            String[] splitB = splitDirAndName(b.getPath());
            int result = splitA[0].compareTo(splitB[0]);
            if (result == 0)
                result = splitA[1].compareTo(splitB[1]);
            return result;
        }
    });
    table_.addColumn(pathColumn, "Path");

    table_.getColumnSortList().push(pathColumn);
}

From source file:org.rstudio.studio.client.workbench.views.vcs.git.GitChangelistTable.java

License:Open Source License

@Override
protected void configureTable() {
    final Column<StatusAndPath, Boolean> stagedColumn = new Column<StatusAndPath, Boolean>(
            new TriStateCheckboxCell<StatusAndPath>(selectionModel_)) {
        @Override//from w ww .ja  v  a  2 s.  c o  m
        public Boolean getValue(StatusAndPath object) {
            return "??".equals(object.getStatus()) ? Boolean.FALSE
                    : object.getStatus().charAt(1) == ' ' ? Boolean.TRUE
                            : object.getStatus().charAt(0) == ' ' ? Boolean.FALSE : null;
        }
    };

    stagedColumn.setHorizontalAlignment(Column.ALIGN_CENTER);
    stagedColumn.setFieldUpdater(new FieldUpdater<StatusAndPath, Boolean>() {
        @Override
        public void update(final int index, final StatusAndPath object, Boolean value) {
            fireEvent(new StageUnstageEvent(!value, getSelectedItems()));
        }
    });
    stagedColumn.setSortable(true);
    sortHandler_.setComparator(stagedColumn, new Comparator<StatusAndPath>() {
        @Override
        public int compare(StatusAndPath a, StatusAndPath b) {
            Boolean a1 = stagedColumn.getValue(a);
            Boolean b1 = stagedColumn.getValue(b);
            int a2 = a1 == null ? 0 : a1 ? -1 : 1;
            int b2 = b1 == null ? 0 : b1 ? -1 : 1;
            return a2 - b2;
        }
    });
    table_.addColumn(stagedColumn, "Staged");
    table_.setColumnWidth(stagedColumn, "46px");

    super.configureTable();
}

From source file:org.ssgwt.client.ui.datagrid.SSDataGrid.java

License:Apache License

/**
 * Add a field that supports multiple selection
 *//*from  w w  w .  jav  a  2  s.  c om*/
public void addMultiSelectField() {
    Cell<Boolean> booleanCell = new CheckboxCell();
    Column<T, Boolean> selectedColumn = new Column<T, Boolean>(booleanCell) {

        /**
         * Get the value of the multi select field
         *
         * @return the selected state of the row
         */
        @Override
        public Boolean getValue(T object) {
            return object.isSelected();
        }

    };
    SelectAllHeader header = new SelectAllHeader();
    header.addEventHandler(new ISelectAllEventHandler() {

        /**
         * Event triggered when the select all button is clicked
         *
         * @param event - The event that was fired
         */
        @Override
        public void onSelectAllEvent(SelectAllEvent event) {
            DataGrid dataGrid = SSDataGrid.this.dataGrid;

            Range rows = dataGrid.getVisibleRange();

            int end = rows.getStart() + rows.getLength();
            int numRecordsDisplayed = rows.getLength();
            if (end > dataGrid.getRowCount()) {
                end = dataGrid.getRowCount();
                numRecordsDisplayed = end % numRecordsDisplayed;
            }

            boolean allSelected = true;
            for (int i = 0; i < numRecordsDisplayed; i++) {
                if (!((T) dataGrid.getVisibleItem(i)).isSelected()) {
                    allSelected = false;
                    break;
                }
            }

            for (int i = 0; i < numRecordsDisplayed; i++) {
                ((T) dataGrid.getVisibleItem(i)).setSelected(!allSelected);
            }
            DataGridRowSelectionChangedEvent<T> eventX = new DataGridRowSelectionChangedEvent<T>(
                    dataGrid.getVisibleItems());

            SSDataGrid.this.fireEvent(eventX);
            refresh();
        }
    });
    dataGrid.addColumn(selectedColumn, header);
    dataGrid.setColumnWidth(selectedColumn, "60px");
    selectedColumn.setFieldUpdater(new FieldUpdater<T, Boolean>() {

        /**
         * Update the selection state
         *
         * @param index - the index of the row to be updated
         * @param object - The object currently being referenced
         * @param value - the selected state of the current row
         */
        @Override
        public void update(int index, T object, Boolean value) {
            object.setSelected(value);
            refresh();
            List<T> selectedRowList = new ArrayList<T>();
            selectedRowList.add(object);
            DataGridRowSelectionChangedEvent<T> eventX = new DataGridRowSelectionChangedEvent<T>(
                    selectedRowList);
            SSDataGrid.this.fireEvent(eventX);
        }
    });
}

From source file:org.switchyard.console.client.ui.application.ApplicationReferencesList.java

License:Apache License

@Override
protected void createColumns(DefaultCellTable<Reference> table, ListDataProvider<Reference> dataProvider) {
    Column<Reference, String> nameColumn = new Column<Reference, String>(new ClickableTextCell()) {
        @Override//from w w w  .  jav  a  2  s  . c  om
        public String getValue(Reference reference) {
            return reference.localName();
        }
    };
    nameColumn.setFieldUpdater(new FieldUpdater<Reference, String>() {
        @Override
        public void update(int index, Reference object, String value) {
            _presenter.onNavigateToReference(object, _application);
        }
    });
    nameColumn.setSortable(true);

    ColumnSortEvent.ListHandler<Reference> sortHandler = new ColumnSortEvent.ListHandler<Reference>(
            dataProvider.getList());
    sortHandler.setComparator(nameColumn, createColumnCommparator(nameColumn));

    table.addColumn(nameColumn, Singleton.MESSAGES.label_name());

    table.addColumnSortHandler(sortHandler);
    table.getColumnSortList().push(nameColumn);
}

From source file:org.switchyard.console.client.ui.application.ApplicationServicesList.java

License:Apache License

@Override
protected void createColumns(DefaultCellTable<Service> table, ListDataProvider<Service> dataProvider) {
    Column<Service, String> nameColumn = new Column<Service, String>(new ClickableTextCell()) {
        @Override//  w  ww  .j  a v  a  2 s  .  c om
        public String getValue(Service service) {
            return service.localName();
        }
    };
    nameColumn.setFieldUpdater(new FieldUpdater<Service, String>() {
        @Override
        public void update(int index, Service object, String value) {
            _presenter.onNavigateToService(object, _application);
        }
    });
    nameColumn.setSortable(true);

    TextColumn<Service> promotesColumn = new TextColumn<Service>() {
        @Override
        public String getValue(Service service) {
            return NameTokens.parseQName(service.getPromotedService())[1];
        }
    };
    promotesColumn.setSortable(true);

    ColumnSortEvent.ListHandler<Service> sortHandler = new ColumnSortEvent.ListHandler<Service>(
            dataProvider.getList());
    sortHandler.setComparator(nameColumn, createColumnCommparator(nameColumn));
    sortHandler.setComparator(promotesColumn, createColumnCommparator(promotesColumn));

    table.addColumn(nameColumn, Singleton.MESSAGES.label_name());
    table.addColumn(promotesColumn, Singleton.MESSAGES.label_promotedService());

    table.addColumnSortHandler(sortHandler);
    table.getColumnSortList().push(nameColumn);
}

From source file:org.switchyard.console.client.ui.application.ComponentServicesList.java

License:Apache License

@Override
protected void createColumns(DefaultCellTable<ComponentService> table,
        ListDataProvider<ComponentService> dataProvider) {
    TextColumn<ComponentService> nameColumn = new TextColumn<ComponentService>() {
        @Override/*  w  w w. j  a va  2 s  .c  o  m*/
        public String getValue(ComponentService service) {
            return service.localName();
        }
    };
    nameColumn.setSortable(true);

    TextColumn<ComponentService> interfaceColumn = new TextColumn<ComponentService>() {
        @Override
        public String getValue(ComponentService service) {
            return service.getInterface();
        }
    };
    interfaceColumn.setSortable(true);

    Column<ComponentService, String> implementationColumn = new Column<ComponentService, String>(
            new ButtonCell()) {
        @Override
        public String getValue(ComponentService dummy) {
            return Singleton.MESSAGES.button_viewDetails();
        }
    };
    implementationColumn.setFieldUpdater(new FieldUpdater<ComponentService, String>() {
        @Override
        public void update(int index, ComponentService service, String value) {
            showDetails(service);
        }
    });
    implementationColumn.setSortable(false);

    ColumnSortEvent.ListHandler<ComponentService> sortHandler = new ColumnSortEvent.ListHandler<ComponentService>(
            dataProvider.getList());
    sortHandler.setComparator(nameColumn, createColumnCommparator(nameColumn));
    sortHandler.setComparator(interfaceColumn, createColumnCommparator(interfaceColumn));
    sortHandler.setComparator(implementationColumn, createColumnCommparator(implementationColumn));

    table.addColumn(nameColumn, Singleton.MESSAGES.label_name());
    table.addColumn(interfaceColumn, Singleton.MESSAGES.label_interface());
    table.addColumn(implementationColumn, Singleton.MESSAGES.label_implementation());

    table.addColumnSortHandler(sortHandler);
    table.getColumnSortList().push(nameColumn);

    createImplementationsDetailsWindow();
}

From source file:org.switchyard.console.client.ui.metrics.ServiceMetricsList.java

License:Apache License

@Override
protected void createColumns(DefaultCellTable<ServiceMetrics> table,
        ListDataProvider<ServiceMetrics> dataProvider) {
    final TextColumn<ServiceMetrics> nameColumn = new TextColumn<ServiceMetrics>() {
        @Override/*from  w  w w .  j  a v  a  2 s. c  om*/
        public String getValue(ServiceMetrics metrics) {
            return metrics.localName();
        }
    };
    nameColumn.setSortable(true);

    final TextColumn<ServiceMetrics> namespaceColumn = new TextColumn<ServiceMetrics>() {
        @Override
        public String getValue(ServiceMetrics service) {
            return service.namespace();
        }
    };
    namespaceColumn.setSortable(true);

    final Column<ServiceMetrics, Number> countColumn = new Column<ServiceMetrics, Number>(new NumberCell()) {
        @Override
        public Number getValue(ServiceMetrics metrics) {
            return metrics.getTotalCount();
        }
    };
    countColumn.setSortable(true);

    final Column<ServiceMetrics, Number> averageTimeColumn = new Column<ServiceMetrics, Number>(
            new NumberCell()) {
        @Override
        public Number getValue(ServiceMetrics metrics) {
            return metrics.getAverageProcessingTime();
        }
    };
    averageTimeColumn.setSortable(true);

    final Column<ServiceMetrics, Double> totalTimePercentageColumn = new Column<ServiceMetrics, Double>(
            new PercentageBarCell()) {
        @Override
        public Double getValue(ServiceMetrics metrics) {
            if (_systemMetrics == null || _systemMetrics.getTotalProcessingTime() == 0) {
                return 0.0;
            }
            return metrics.getTotalProcessingTime() / (double) _systemMetrics.getTotalProcessingTime();
        }
    };
    totalTimePercentageColumn.setSortable(true);

    final Column<ServiceMetrics, Double> faultPercentageColumn = new Column<ServiceMetrics, Double>(
            new PercentageBarCell()) {
        @Override
        public Double getValue(ServiceMetrics metrics) {
            if (_systemMetrics == null || _systemMetrics.getFaultCount() == 0) {
                return 0.0;
            }
            return metrics.getFaultCount() / (double) _systemMetrics.getFaultCount();
        }
    };
    faultPercentageColumn.setSortable(true);

    Column<ServiceMetrics, String> viewDetailsColumn = new Column<ServiceMetrics, String>(new ButtonCell()) {
        @Override
        public String getValue(ServiceMetrics dummy) {
            return Singleton.MESSAGES.button_details();
        }
    };
    viewDetailsColumn.setFieldUpdater(new FieldUpdater<ServiceMetrics, String>() {
        @Override
        public void update(int index, ServiceMetrics metrics, String value) {
            showDetails(metrics);
        }
    });

    Column<ServiceMetrics, String> clearColumn = new Column<ServiceMetrics, String>(new ButtonCell()) {
        @Override
        public String getValue(ServiceMetrics dummy) {
            return Singleton.MESSAGES.label_resetMetrics();
        }
    };
    clearColumn.setFieldUpdater(new FieldUpdater<ServiceMetrics, String>() {
        @Override
        public void update(int index, ServiceMetrics metrics, String value) {
            _presenter.resetMetrics(metrics);
        }
    });

    ColumnSortEvent.ListHandler<ServiceMetrics> sortHandler = new ColumnSortEvent.ListHandler<ServiceMetrics>(
            dataProvider.getList());
    sortHandler.setComparator(nameColumn, createColumnCommparator(nameColumn));
    sortHandler.setComparator(namespaceColumn, createColumnCommparator(namespaceColumn));
    sortHandler.setComparator(countColumn, createNumberColumnCommparator(countColumn));
    sortHandler.setComparator(averageTimeColumn, createNumberColumnCommparator(averageTimeColumn));
    sortHandler.setComparator(totalTimePercentageColumn,
            createNumberColumnCommparator(totalTimePercentageColumn));
    sortHandler.setComparator(faultPercentageColumn, createNumberColumnCommparator(faultPercentageColumn));

    table.addColumn(nameColumn, Singleton.MESSAGES.label_name());
    table.addColumn(namespaceColumn, Singleton.MESSAGES.label_targetNamespace());
    table.addColumn(countColumn, Singleton.MESSAGES.label_messageCount());
    table.addColumn(averageTimeColumn, Singleton.MESSAGES.label_averageTime());
    table.addColumn(totalTimePercentageColumn, Singleton.MESSAGES.label_timePercent());
    table.addColumn(faultPercentageColumn, Singleton.MESSAGES.label_faultPercent());
    table.addColumn(viewDetailsColumn, Singleton.MESSAGES.label_details());
    table.addColumn(clearColumn, Singleton.MESSAGES.label_reset());

    table.addColumnSortHandler(sortHandler);
    table.getColumnSortList().push(averageTimeColumn);
    table.getColumnSortList().push(countColumn);
    table.getColumnSortList().push(faultPercentageColumn);
    table.getColumnSortList().push(namespaceColumn);
    table.getColumnSortList().push(nameColumn);
    // insert twice for descending
    table.getColumnSortList().push(totalTimePercentageColumn);
    table.getColumnSortList().push(totalTimePercentageColumn);
}

From source file:org.switchyard.console.client.ui.service.GatewaysList.java

License:Apache License

@Override
protected void createColumns(DefaultCellTable<Binding> table, ListDataProvider<Binding> dataProvider) {
    TextColumn<Binding> nameColumn = new TextColumn<Binding>() {
        @Override/*from   w  ww . j a  v a2s  .  c  o m*/
        public String getValue(Binding binding) {
            return binding.getName();
        }
    };
    nameColumn.setSortable(true);

    TextColumn<Binding> typeColumn = new TextColumn<Binding>() {
        @Override
        public String getValue(Binding binding) {
            return binding.getType();
        }
    };
    typeColumn.setSortable(true);

    Column<Binding, String> configColumn = new Column<Binding, String>(new ButtonCell()) {
        @Override
        public String getValue(Binding dummy) {
            return Singleton.MESSAGES.button_viewConfiguration();
        }
    };
    configColumn.setFieldUpdater(new FieldUpdater<Binding, String>() {
        @Override
        public void update(int index, Binding binding, String value) {
            showDetails(binding);
        }
    });
    configColumn.setSortable(false);

    Column<Binding, String> statusColumn = new TextColumn<Binding>() {
        @Override
        public String getValue(Binding binding) {
            return binding.getState() == null ? Singleton.MESSAGES.constant_unknown()
                    : binding.getState().toString();
        }
    };

    Column<Binding, String> startStopColumn = new Column<Binding, String>(new ButtonCell()) {
        @Override
        public String getValue(Binding binding) {
            return binding.getState() == null
                    || EnumSet.<State>of(State.NONE, State.STOPPING).contains(binding.getState())
                            ? Singleton.MESSAGES.label_start()
                            : Singleton.MESSAGES.label_stop();
        }
    };
    startStopColumn.setFieldUpdater(new FieldUpdater<Binding, String>() {
        @Override
        public void update(int index, Binding binding, String value) {
            if (EnumSet.<State>of(State.STARTING, State.STARTED).contains(binding.getState())) {
                _presenter.stopGateway(binding);
            } else {
                _presenter.startGateway(binding);
            }
        }
    });

    ColumnSortEvent.ListHandler<Binding> sortHandler = new ColumnSortEvent.ListHandler<Binding>(
            dataProvider.getList());
    sortHandler.setComparator(typeColumn, createColumnCommparator(typeColumn));
    sortHandler.setComparator(nameColumn, createColumnCommparator(nameColumn));

    table.addColumn(nameColumn, Singleton.MESSAGES.label_name());
    table.addColumn(typeColumn, Singleton.MESSAGES.label_type());
    table.addColumn(statusColumn, Singleton.MESSAGES.label_status());
    table.addColumn(startStopColumn, Singleton.MESSAGES.label_startStop());
    table.addColumn(configColumn, Singleton.MESSAGES.label_configuration());

    table.addColumnSortHandler(sortHandler);

    createBindingDetailsWindow();
}

From source file:org.teiid.authoring.client.widgets.ColumnNamesTable.java

License:Apache License

/**
 * Create the panel/*from  www  .j a  v  a 2s .  co m*/
 * @return the panel widget
 */
protected Widget createTablePanel() {
    table = new SimpleTable<CheckableNameTypeRow>();

    // Add Checkbox column
    Column<CheckableNameTypeRow, Boolean> checkboxColumn = new Column<CheckableNameTypeRow, Boolean>(
            new CheckboxCell(true, false)) {
        @Override
        public Boolean getValue(CheckableNameTypeRow object) {
            if (object == null)
                return false;
            return object.isChecked();
        }
    };
    checkboxColumn.setFieldUpdater(new FieldUpdater<CheckableNameTypeRow, Boolean>() {
        public void update(int index, CheckableNameTypeRow object, Boolean value) {
            object.setChecked(value);

            boolean allRowsSame = true;
            List<CheckableNameTypeRow> tableRows = table.getRowData();
            boolean firstState = false;
            for (int i = 0; i < tableRows.size(); i++) {
                CheckableNameTypeRow row = tableRows.get(i);
                if (i == 0) {
                    firstState = row.isChecked();
                } else {
                    boolean thisState = row.isChecked();
                    if (thisState != firstState) {
                        allRowsSame = false;
                        break;
                    }
                }
            }
            if (allRowsSame) {
                cbHeader.setValue(firstState);
            } else {
                cbHeader.setValue(false);
            }
            table.redrawHeaders();
        }
    });

    // Checkbox Header
    cbHeader = createCBHeader(false);

    table.addColumn(checkboxColumn, cbHeader);
    table.setColumnWidth(checkboxColumn, 40, Unit.PX);

    // --------------
    // Name Column
    // --------------
    TextColumn<CheckableNameTypeRow> nameColumn = new TextColumn<CheckableNameTypeRow>() {
        public String getValue(CheckableNameTypeRow row) {
            return row.getName();
        }
    };
    table.addColumn(nameColumn, COLUMN_HEADER_NAME);
    table.setColumnWidth(nameColumn, 350, Unit.PX);

    table.setWidth("395px");
    table.setHeight("200px");

    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.add(table);
    return verticalPanel;
}

From source file:org.teiid.authoring.client.widgets.ServiceNamesTable.java

License:Apache License

/**
 * Create the panel// www . ja v  a  2  s . c  o m
 * @return the panel widget
 */
protected Widget createTablePanel() {
    table = new SimpleTable<ServiceRow>();

    // Add Checkbox column
    Column<ServiceRow, Boolean> checkboxColumn = new Column<ServiceRow, Boolean>(
            new CheckboxCell(true, false)) {
        @Override
        public Boolean getValue(ServiceRow object) {
            if (object == null)
                return false;
            return object.isChecked();
        }
    };
    checkboxColumn.setFieldUpdater(new FieldUpdater<ServiceRow, Boolean>() {
        public void update(int index, ServiceRow object, Boolean value) {
            object.setChecked(value);
        }
    });
    table.addColumn(checkboxColumn, "");
    table.setColumnWidth(checkboxColumn, 40, Unit.PX);

    // --------------
    // Name Column
    // --------------
    TextColumn<ServiceRow> nameColumn = new TextColumn<ServiceRow>() {
        public String getValue(ServiceRow row) {
            return row.getName();
        }
    };
    table.addColumn(nameColumn, COLUMN_HEADER_NAME);
    table.setColumnWidth(nameColumn, 200, Unit.PX);

    // ------------------
    // Visibility Column
    // ------------------
    TextColumn<ServiceRow> visibilityColumn = new TextColumn<ServiceRow>() {
        public String getValue(ServiceRow row) {
            return String.valueOf(row.isVisible());
        }
    };
    table.addColumn(visibilityColumn, COLUMN_HEADER_VISIBILITY);
    table.setColumnWidth(visibilityColumn, 50, Unit.PX);

    table.setWidth("300px");
    table.setHeight("200px");

    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.add(table);
    return verticalPanel;
}