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

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

Introduction

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

Prototype

public void setDefaultSortAscending(boolean isAscending) 

Source Link

Document

Set whether or not the default sort order is ascending.

Usage

From source file:com.anritsu.mcrepositorymanager.client.FilterDBForm.java

public void buildPackageListTable(final CellTable table) {

    table.setPageSize(200);//w w w  .j av a 2 s  .c o  m

    // Attach column sort handler
    ListHandler<McPackage> sortHandler = new ListHandler<McPackage>(dataProvider.getList());
    table.addColumnSortHandler(sortHandler);

    Column<McPackage, String> packageNameColumn = new Column<McPackage, String>(
            new ButtonCell(ButtonType.LINK)) {
        @Override
        public String getValue(McPackage object) {
            return object.getName();
        }
    };
    packageNameColumn.setFieldUpdater(new FieldUpdater<McPackage, String>() {
        @Override
        public void update(int index, McPackage object, String value) {
            Set<String> dependencies = new HashSet();
            for (McPackage p : object.getDependencies()) {
                dependencies.add(p.getName() + "-" + p.getPackageVersion());
            }
            Set<String> dependencyFor = new HashSet<>();
            for (McPackage p : object.getDependencyFor()) {
                dependencyFor.add(p.getName() + "-" + p.getPackageVersion());
            }
            Notify.notify("Dependencies: " + Arrays.toString(dependencies.toArray()) + "\nDependency for: "
                    + Arrays.toString(dependencyFor.toArray()));
        }
    });
    packageNameColumn.setSortable(true);
    packageNameColumn.setDefaultSortAscending(true);
    sortHandler.setComparator(packageNameColumn, new Comparator<McPackage>() {
        @Override
        public int compare(McPackage t1, McPackage t2) {
            return t1.getName().compareTo(t2.getName());
        }
    });

    Column<McPackage, String> packageVersionColumn = new Column<McPackage, String>(
            new ButtonCell(ButtonType.LINK)) {
        @Override
        public String getValue(McPackage object) {
            return object.getPackageVersion();
        }
    };

    packageVersionColumn.setFieldUpdater(new FieldUpdater<McPackage, String>() {
        @Override
        public void update(int index, McPackage object, String value) {
            HTML html = new HTML();
            SafeHtmlBuilder sHtmlBuilder = new SafeHtmlBuilder();

            for (String stringLink : object.getDownloadLinks()) {
                sHtmlBuilder.appendHtmlConstant("<a href='" + stringLink + "'>");
                sHtmlBuilder.appendEscaped(stringLink);
                sHtmlBuilder.appendHtmlConstant("</a><br />");
            }
            html.setHTML(sHtmlBuilder.toSafeHtml());
            downloadLinkModalBody.clear();
            downloadLinkModalBody.add(html);
            downloadLinkModal.show();

        }
    });

    Column<McPackage, String> packageQ7admOutputVersionColumn = new Column<McPackage, String>(
            new ButtonCell(ButtonType.LINK)) {
        @Override
        public String getValue(McPackage object) {
            return object.getQ7admOutputVersion();
        }
    };

    TextColumn<McPackage> packageAvailabilityColumn = new TextColumn<McPackage>() {
        @Override
        public String getValue(McPackage pack) {
            return pack.getAvailability();
        }
    };

    TextColumn<McPackage> packageReleaseDateColumn = new TextColumn<McPackage>() {
        @Override
        public String getValue(McPackage pack) {
            StringBuilder dateFormated = new StringBuilder();
            if (pack.getReleaseDate() != null) {
                String[] releaseDateArray = pack.getReleaseDate().toString().split(" ");
                dateFormated
                        .append(releaseDateArray[2] + "-" + releaseDateArray[1] + "-" + releaseDateArray[5]);
                return dateFormated.toString();
            }
            return "";
        }
    };

    Column<McPackage, String> selectedForDownloadColumn = new Column<McPackage, String>(new ButtonCell()) {
        @Override
        public String getValue(McPackage object) {
            ((ButtonCell) this.getCell()).setEnabled(false);
            if (object.getDownloadLinks().isEmpty()) {
                return "Missing from DB";
            }
            if (object.isMatchFilter()) {
                ((ButtonCell) this.getCell()).setEnabled(true);
            }
            if (object.isDependency()) {
                ((ButtonCell) this.getCell()).setEnabled(false);
            }
            return (object.isAddToRepository()) ? "remove from repository" : "add to repository";
        }
    };

    selectedForDownloadColumn.setFieldUpdater(new FieldUpdater<McPackage, String>() {

        @Override
        public void update(int index, McPackage object, String value) {
            downloadRepositoryArchive.setVisible(false);
            downloadRepositoryArchive.setActive(false);

            repositoryDownloadLink.setVisible(false);
            repositoryDownloadLink.setActive(false);
            object.setAddToRepository(!object.isAddToRepository());

            // Dealing with dependencies
            HashSet<McPackage> pList = new HashSet<>();
            for (McPackage p : dataProvider.getList()) {
                if (p.isAddToRepository() && p.isMatchFilter()) {
                    p.setDependencySolved(false);
                    pList.add(p);
                }
            }
            getService().solveDependencies(pList, solveDependenciesCallback);
            Notify.notify("Package " + object.getName() + " " + value + " : " + object.isAddToRepository());
        }

    });

    table.addColumn(packageNameColumn, "Package Name");
    table.addColumn(packageQ7admOutputVersionColumn, "Installed version");
    table.addColumn(packageVersionColumn, "Package Version");
    table.addColumn(packageAvailabilityColumn, "Availability");
    table.addColumn(packageReleaseDateColumn, "Release Date");
    table.addColumn(selectedForDownloadColumn, "Add to repository");
}

From source file:com.anritsu.mcrepositorymanager.client.ReleaseManagement.java

public void buildPackageListTable(final CellTable table) {
    table.setPageSize(200);/*from   w w w .  ja  v  a 2s .  co m*/

    // Attach a column sort handler 
    ListHandler<RecommendedMcPackage> sortHandler = new ListHandler<RecommendedMcPackage>(
            dataProvider.getList());
    table.addColumnSortHandler(sortHandler);

    // Hide from table
    Column<RecommendedMcPackage, String> hidePackage = new Column<RecommendedMcPackage, String>(
            new ButtonCell(ButtonType.INFO, ButtonSize.EXTRA_SMALL)) {
        @Override
        public String getValue(RecommendedMcPackage object) {
            ((ButtonCell) this.getCell()).setEnabled(object.isShowInTable());
            return "Remove";
        }
    };
    hidePackage.setFieldUpdater(new FieldUpdater<RecommendedMcPackage, String>() {
        @Override
        public void update(int index, RecommendedMcPackage object, String value) {
            object.setShowInTable(false);
            table.redraw();
            getService().removeFromTable(object, removeFromTableCallback);
        }
    });

    // Component Tier
    TextColumn<RecommendedMcPackage> packageTier = new TextColumn<RecommendedMcPackage>() {
        @Override
        public String getValue(RecommendedMcPackage pack) {
            return pack.getTier().replaceAll("Anritsu/MasterClaw/", "");
        }
    };

    // Component Group
    TextColumn<RecommendedMcPackage> packageGroup = new TextColumn<RecommendedMcPackage>() {
        @Override
        public String getValue(RecommendedMcPackage pack) {
            return pack.getGroup();
        }
    };

    // Component name
    Column<RecommendedMcPackage, String> packageName = new Column<RecommendedMcPackage, String>(
            new ButtonCell(ButtonType.LINK)) {
        @Override
        public String getValue(RecommendedMcPackage object) {
            return object.getPackageName();
        }
    };
    packageName.setSortable(true);
    packageName.setDefaultSortAscending(true);
    sortHandler.setComparator(packageName, new Comparator<RecommendedMcPackage>() {
        @Override
        public int compare(RecommendedMcPackage t1, RecommendedMcPackage t2) {
            return t1.getPackageName().compareTo(t2.getPackageName());
        }
    });

    // Component version        
    Column<RecommendedMcPackage, String> packageVersion = new Column<RecommendedMcPackage, String>(
            new DynamicSelectionCell(new ArrayList())) {
        @Override
        public String getValue(RecommendedMcPackage object) {
            ((DynamicSelectionCell) this.getCell()).clear();
            String recommendedVersion = "n\\a";
            if (object.getRecommendedVersion() != null
                    && object.getRecommendedVersion().getPackageVersion() != null
                    && object.getMcVersion().equalsIgnoreCase(mcVersion)) {
                recommendedVersion = object.getRecommendedVersion().getPackageVersion();
            }
            ((DynamicSelectionCell) this.getCell()).addOption(recommendedVersion);
            for (McPackage version : object.getPackageVersions()) {
                String v = version.getPackageVersion();
                if (!v.equalsIgnoreCase(recommendedVersion)) {
                    ((DynamicSelectionCell) this.getCell()).addOption(version.getPackageVersion());
                }

            }
            return recommendedVersion;
        }
    };

    packageVersion.setFieldUpdater(new FieldUpdater<RecommendedMcPackage, String>() {
        @Override
        public void update(int index, RecommendedMcPackage object, String value) {
            object.setPackageInfoModified(true);
            for (McPackage p : object.getPackageVersions()) {
                if (p.getPackageVersion().equalsIgnoreCase(value)) {
                    object.setRecommendedVersion(p);
                }
            }
            table.redrawRow(index);
        }
    });

    // Component availability
    TextColumn<RecommendedMcPackage> packageAvailability = new TextColumn<RecommendedMcPackage>() {
        @Override
        public String getValue(RecommendedMcPackage pack) {
            return pack.getAvailability();
        }
    };
    packageAvailability.setSortable(true);
    sortHandler.setComparator(packageAvailability, new Comparator<RecommendedMcPackage>() {
        @Override
        public int compare(RecommendedMcPackage t1, RecommendedMcPackage t2) {
            return t1.getAvailability().compareTo(t2.getAvailability());
        }
    });

    // Component customers
    TextColumn<RecommendedMcPackage> packageCustomers = new TextColumn<RecommendedMcPackage>() {
        @Override
        public String getValue(RecommendedMcPackage pack) {
            if (pack.getRecommendedVersion() != null
                    && !pack.getRecommendedVersion().getCustomerList().contains("All")) {
                return Arrays.toString(pack.getRecommendedVersion().getCustomerList().toArray());
            }
            return "";
        }
    };

    // Component release date
    TextColumn<RecommendedMcPackage> packageReleaseDate = new TextColumn<RecommendedMcPackage>() {
        @Override
        public String getValue(RecommendedMcPackage pack) {
            StringBuilder dateFormated = new StringBuilder();
            if (pack.getRecommendedVersion() != null && pack.getRecommendedVersion().getReleaseDate() != null) {
                String[] releaseDateArray = pack.getRecommendedVersion().getReleaseDate().toString().split(" ");
                dateFormated.append(releaseDateArray[2]).append(".").append(releaseDateArray[1]).append(".")
                        .append(releaseDateArray[5]);
                return dateFormated.toString();
            }
            return "";
        }
    };

    // Component lessRecommended
    Column<RecommendedMcPackage, Boolean> packageLessRecommended = new Column<RecommendedMcPackage, Boolean>(
            new CheckboxCell(true, false)) {
        @Override
        public Boolean getValue(RecommendedMcPackage pack) {
            if (pack.getRecommendedVersion() != null) {
                return pack.getRecommendedVersion().isLessRecommended();
            }
            return false;
        }
    };
    packageLessRecommended.setFieldUpdater(new FieldUpdater<RecommendedMcPackage, Boolean>() {
        @Override
        public void update(int index, RecommendedMcPackage object, Boolean value) {
            object.setPackageInfoModified(true);
            object.getRecommendedVersion().setLessRecommended(value);
            table.redrawRow(index);
        }

    });

    // Component activity
    TextColumn<RecommendedMcPackage> packageActivity = new TextColumn<RecommendedMcPackage>() {
        @Override
        public String getValue(RecommendedMcPackage pack) {
            if (pack.getRecommendedVersion() != null) {
                Set<String> activitiesSet = new HashSet<String>();
                StringBuilder activities = new StringBuilder();
                for (MCPackageActivities pa : pack.getRecommendedVersion().getActivities()) {
                    if (!pa.getActivityType().equalsIgnoreCase("EPR")) {
                        activitiesSet.add(pa.getActivityType() + pa.getActivityId());
                    }
                }
                for (String s : activitiesSet) {
                    activities.append(s + " ");
                }
                return activities.toString();
            }
            return "";
        }
    };

    // Component notes
    Column<RecommendedMcPackage, String> packageNotes = new Column<RecommendedMcPackage, String>(
            new TextAreaInputCell()) {
        @Override
        public String getValue(RecommendedMcPackage pack) {
            try {
                return pack.getRecommendedVersion().getNotes();
            } catch (Exception exp) {
                return "";
            }

        }
    };
    packageNotes.setFieldUpdater(new FieldUpdater<RecommendedMcPackage, String>() {
        @Override
        public void update(int index, RecommendedMcPackage object, String value) {
            object.setPackageInfoModified(true);
            object.getRecommendedVersion().setNotes(value);
            table.redrawRow(index);
        }
    });

    // Update package
    Column<RecommendedMcPackage, String> updatePackage = new Column<RecommendedMcPackage, String>(
            new ButtonCell(ButtonType.INFO)) {
        @Override
        public String getValue(RecommendedMcPackage object) {
            String result = "Update";
            if (!object.isShowInTable()) {
                result = "Add to table";
                if (object.getRecommendedVersion() != null
                        && !object.getRecommendedVersion().getPackageVersion().equalsIgnoreCase("n\\a")) {
                    ((ButtonCell) this.getCell()).setEnabled(true);
                } else {
                    ((ButtonCell) this.getCell()).setEnabled(false);
                }
                return result;
            } else {
                ((ButtonCell) this.getCell()).setEnabled(object.isPackageInfoModified());
                return result;
            }
        }
    };
    updatePackage.setFieldUpdater(new FieldUpdater<RecommendedMcPackage, String>() {
        @Override
        public void update(int index, RecommendedMcPackage object, String value) {
            object.setRowIndex(index);
            object.setPackageInfoModified(false);
            object.setRecommendedVersionCandidate(false);
            object.setShowInTable(true);
            packageListTable.redraw();
            getService().updateRecommendedVersion(object, updateRecommendedVersionCallback);

        }
    });

    table.addColumn(hidePackage, "Remove");
    table.addColumn(packageTier, "Tier");
    table.addColumn(packageGroup, "Group");
    table.addColumn(packageName, "Package Name");
    table.addColumn(packageVersion, "Recommended version");
    table.addColumn(packageAvailability, "Availability");
    table.addColumn(packageCustomers, "Customers");
    table.addColumn(packageReleaseDate, "Release date");
    table.addColumn(packageLessRecommended, "LR");
    table.addColumn(packageActivity, "Activity");
    table.addColumn(packageNotes, "Notes");
    table.addColumn(updatePackage, "Save changes");
}

From source file:com.gafactory.core.client.ui.grids.BaseListGrid.java

License:Open Source License

public void setDefaultSortingColumn(Column<?, ?> column, boolean isAsc) {
    column.setDefaultSortAscending(isAsc);

    ColumnSortList columnSortList = dataGrid.getColumnSortList();
    columnSortList.push(column);//  w  w w .  ja  va 2  s . c  o  m
    ColumnSortEvent.fire(this, columnSortList);

    loader.addSortInfo(new SortInfoBean(column.getDataStoreName(),
            column.isDefaultSortAscending() ? SortDir.ASC : SortDir.DESC));
}

From source file:com.google.gwt.sample.showcase.client.content.cell.CwCellTable.java

License:Apache License

/**
 * Add the columns to the table./*from www.  j  a  v  a  2 s . co  m*/
 */
@ShowcaseSource
private void initTableColumns(final SelectionModel<ContactInfo> selectionModel,
        ListHandler<ContactInfo> sortHandler) {
    // Checkbox column. This table will uses a checkbox column for selection.
    // Alternatively, you can call cellTable.setSelectionEnabled(true) to enable
    // mouse selection.
    Column<ContactInfo, Boolean> checkColumn = new Column<ContactInfo, Boolean>(new CheckboxCell(true, false)) {
        @Override
        public Boolean getValue(ContactInfo object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    cellTable.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    cellTable.setColumnWidth(checkColumn, 40, Unit.PX);

    // First name.
    Column<ContactInfo, String> firstNameColumn = new Column<ContactInfo, String>(new EditTextCell()) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getFirstName();
        }
    };
    firstNameColumn.setSortable(true);
    sortHandler.setComparator(firstNameColumn, new Comparator<ContactInfo>() {
        public int compare(ContactInfo o1, ContactInfo o2) {
            return o1.getFirstName().compareTo(o2.getFirstName());
        }
    });
    cellTable.addColumn(firstNameColumn, constants.cwCellTableColumnFirstName());
    firstNameColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            // Called when the user changes the value.
            object.setFirstName(value);
            ContactDatabase.get().refreshDisplays();
        }
    });
    cellTable.setColumnWidth(firstNameColumn, 20, Unit.PCT);

    // Last name.
    Column<ContactInfo, String> lastNameColumn = new Column<ContactInfo, String>(new EditTextCell()) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getLastName();
        }
    };
    lastNameColumn.setSortable(true);
    sortHandler.setComparator(lastNameColumn, new Comparator<ContactInfo>() {
        public int compare(ContactInfo o1, ContactInfo o2) {
            return o1.getLastName().compareTo(o2.getLastName());
        }
    });
    cellTable.addColumn(lastNameColumn, constants.cwCellTableColumnLastName());
    lastNameColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            // Called when the user changes the value.
            object.setLastName(value);
            ContactDatabase.get().refreshDisplays();
        }
    });
    cellTable.setColumnWidth(lastNameColumn, 20, Unit.PCT);

    // Category.
    final Category[] categories = ContactDatabase.get().queryCategories();
    List<String> categoryNames = new ArrayList<String>();
    for (Category category : categories) {
        categoryNames.add(category.getDisplayName());
    }
    SelectionCell categoryCell = new SelectionCell(categoryNames);
    Column<ContactInfo, String> categoryColumn = new Column<ContactInfo, String>(categoryCell) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getCategory().getDisplayName();
        }
    };
    cellTable.addColumn(categoryColumn, constants.cwCellTableColumnCategory());
    categoryColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            for (Category category : categories) {
                if (category.getDisplayName().equals(value)) {
                    object.setCategory(category);
                }
            }
            ContactDatabase.get().refreshDisplays();
        }
    });
    cellTable.setColumnWidth(categoryColumn, 130, Unit.PX);

    // Address.
    Column<ContactInfo, String> addressColumn = new Column<ContactInfo, String>(new TextCell()) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getAddress();
        }
    };
    addressColumn.setSortable(true);
    addressColumn.setDefaultSortAscending(false);
    sortHandler.setComparator(addressColumn, new Comparator<ContactInfo>() {
        public int compare(ContactInfo o1, ContactInfo o2) {
            return o1.getAddress().compareTo(o2.getAddress());
        }
    });
    cellTable.addColumn(addressColumn, constants.cwCellTableColumnAddress());
    cellTable.setColumnWidth(addressColumn, 60, Unit.PCT);
}

From source file:org.jbpm.console.ng.ht.client.editors.taskcomments.popup.TaskCommentsPopupViewImpl.java

License:Apache License

private void initTableColumns() {
    // addedBy//from  w  ww.ja v a  2s  .c  o m
    Column<CommentSummary, String> addedByColumn = new Column<CommentSummary, String>(new TextCell()) {
        @Override
        public String getValue(CommentSummary c) {
            // for some reason the username comes in format [User:'<name>'], so parse just the <name>
            int first = c.getAddedBy().indexOf('\'');
            int last = c.getAddedBy().lastIndexOf('\'');
            return c.getAddedBy().substring(first + 1, last);
        }
    };
    addedByColumn.setSortable(false);
    commentsListGrid.addColumn(addedByColumn, constants.Added_By());
    commentsListGrid.setColumnWidth(addedByColumn, "100px");

    // date
    Column<CommentSummary, String> addedAtColumn = new Column<CommentSummary, String>(new TextCell()) {
        @Override
        public String getValue(CommentSummary c) {
            DateTimeFormat format = DateTimeFormat.getFormat("dd/MM/yyyy HH:mm");
            return format.format(c.getAddedAt());
        }
    };
    addedAtColumn.setSortable(true);
    addedAtColumn.setDefaultSortAscending(true);
    commentsListGrid.addColumn(addedAtColumn, constants.At());
    sortHandler.setComparator(addedAtColumn, new Comparator<CommentSummary>() {
        @Override
        public int compare(CommentSummary o1, CommentSummary o2) {
            return o1.getAddedAt().compareTo(o2.getAddedAt());
        }
    });

    // comment text
    Column<CommentSummary, String> commentTextColumn = new Column<CommentSummary, String>(new TextCell()) {
        @Override
        public String getValue(CommentSummary object) {
            return object.getText();
        }
    };
    addedByColumn.setSortable(false);
    commentsListGrid.addColumn(commentTextColumn, constants.Comment());
}

From source file:org.jbpm.console.ng.ht.client.editors.taskcomments.TaskCommentsPopupViewImpl.java

License:Apache License

private void initTableColumns() {
    // addedBy/*from  w  w w  .  j ava  2 s  .c  o m*/
    Column<CommentSummary, String> addedByColumn = new Column<CommentSummary, String>(new TextCell()) {
        @Override
        public String getValue(CommentSummary c) {
            // for some reason the username comes in format [User:'<name>'], so parse just the <name>
            int first = c.getAddedBy().indexOf('\'');
            int last = c.getAddedBy().lastIndexOf('\'');
            return c.getAddedBy().substring(first + 1, last);
        }
    };
    addedByColumn.setSortable(false);
    commentsListGrid.addColumn(addedByColumn, constants.Added_By());
    commentsListGrid.setColumnWidth(addedByColumn, "100px");

    // date
    Column<CommentSummary, String> addedAtColumn = new Column<CommentSummary, String>(new TextCell()) {
        @Override
        public String getValue(CommentSummary c) {
            return c.getAddedAt().toString();
        }
    };
    addedAtColumn.setSortable(true);
    addedAtColumn.setDefaultSortAscending(true);
    commentsListGrid.addColumn(addedAtColumn, constants.At());
    sortHandler.setComparator(addedAtColumn, new Comparator<CommentSummary>() {
        @Override
        public int compare(CommentSummary o1, CommentSummary o2) {
            return o1.getAddedAt().compareTo(o2.getAddedAt());
        }
    });

    // comment text
    Column<CommentSummary, String> commentTextColumn = new Column<CommentSummary, String>(new TextCell()) {
        @Override
        public String getValue(CommentSummary object) {
            return object.getText();
        }
    };
    addedByColumn.setSortable(false);
    commentsListGrid.addColumn(commentTextColumn, constants.Comment());
}

From source file:org.jbpm.console.ng.ht.client.editors.taskcomments.TaskCommentsViewImpl.java

License:Apache License

private void initTableColumns() {
    // addedBy/*from   ww  w .ja v a  2s. c o m*/
    Column<CommentSummary, String> addedByColumn = new Column<CommentSummary, String>(new TextCell()) {
        @Override
        public String getValue(CommentSummary c) {
            // for some reason the username comes in format [User:'<name>'], so parse just the <name>
            int first = c.getAddedBy().indexOf('\'');
            int last = c.getAddedBy().lastIndexOf('\'');
            return c.getAddedBy().substring(first + 1, last);
        }
    };
    addedByColumn.setSortable(false);
    commentsListGrid.addColumn(addedByColumn, constants.Added_By());
    commentsListGrid.setColumnWidth(addedByColumn, 100, Style.Unit.PX);

    // date
    Column<CommentSummary, String> addedAtColumn = new Column<CommentSummary, String>(new TextCell()) {
        @Override
        public String getValue(CommentSummary c) {
            DateTimeFormat format = DateTimeFormat.getFormat("dd/MM/yyyy HH:mm");
            return format.format(c.getAddedAt());
        }
    };
    addedAtColumn.setSortable(true);
    addedAtColumn.setDefaultSortAscending(true);
    commentsListGrid.addColumn(addedAtColumn, constants.At());
    sortHandler.setComparator(addedAtColumn, new Comparator<CommentSummary>() {
        @Override
        public int compare(CommentSummary o1, CommentSummary o2) {
            return o1.getAddedAt().compareTo(o2.getAddedAt());
        }
    });

    // comment text
    Column<CommentSummary, String> commentTextColumn = new Column<CommentSummary, String>(new TextCell()) {
        @Override
        public String getValue(CommentSummary object) {
            return object.getText();
        }
    };
    addedByColumn.setSortable(false);
    commentsListGrid.addColumn(commentTextColumn, constants.Comment());

    List<HasCell<CommentSummary, ?>> cells = new LinkedList<HasCell<CommentSummary, ?>>();

    cells.add(new DeleteCommentActionHasCell(constants.Delete(), new Delegate<CommentSummary>() {
        @Override
        public void execute(CommentSummary comment) {
            presenter.removeTaskComment(comment.getId());
        }
    }));

    CompositeCell<CommentSummary> cell = new CompositeCell<CommentSummary>(cells);
    Column<CommentSummary, CommentSummary> actionsColumn = new Column<CommentSummary, CommentSummary>(cell) {
        @Override
        public CommentSummary getValue(CommentSummary object) {
            return object;
        }
    };
    commentsListGrid.addColumn(actionsColumn, "");
}

From source file:org.jbpm.workbench.ht.client.editors.taskcomments.TaskCommentsViewImpl.java

License:Apache License

private void initTableColumns() {
    // addedBy/*from w  w w .  ja v  a  2  s.c o m*/
    Column<CommentSummary, String> addedByColumn = new Column<CommentSummary, String>(new TextCell()) {
        @Override
        public String getValue(CommentSummary c) {
            return c.getAddedBy();
        }
    };
    addedByColumn.setSortable(false);
    addedByColumn.setDataStoreName(COL_ADDEDBY);
    commentsListGrid.addColumn(addedByColumn, constants.Added_By());

    // date
    Column<CommentSummary, String> addedAtColumn = new Column<CommentSummary, String>(new TextCell()) {
        @Override
        public String getValue(CommentSummary c) {
            return DateUtils.getDateTimeStr(c.getAddedAt());
        }
    };
    addedAtColumn.setSortable(true);
    addedAtColumn.setDataStoreName(COL_ADDEDAT);
    addedAtColumn.setDefaultSortAscending(true);
    commentsListGrid.addColumn(addedAtColumn, constants.At());
    sortHandler.setComparator(addedAtColumn, new Comparator<CommentSummary>() {
        @Override
        public int compare(CommentSummary o1, CommentSummary o2) {
            return o1.getAddedAt().compareTo(o2.getAddedAt());
        }
    });

    // comment text
    Column<CommentSummary, String> commentTextColumn = new Column<CommentSummary, String>(new TextCell()) {
        @Override
        public String getValue(CommentSummary object) {
            return object.getText();
        }
    };
    commentTextColumn.setSortable(false);
    commentTextColumn.setDataStoreName(COL_COMMENT);
    commentsListGrid.addColumn(commentTextColumn, constants.Comment());

    List<HasCell<CommentSummary, ?>> cells = new LinkedList<HasCell<CommentSummary, ?>>();

    cells.add(new DeleteCommentActionHasCell(constants.Delete(), new Delegate<CommentSummary>() {
        @Override
        public void execute(CommentSummary comment) {
            presenter.removeTaskComment(comment.getId());
        }
    }));

    CompositeCell<CommentSummary> cell = new CompositeCell<CommentSummary>(cells);
    Column<CommentSummary, CommentSummary> actionsColumn = new Column<CommentSummary, CommentSummary>(cell) {
        @Override
        public CommentSummary getValue(CommentSummary object) {
            return object;
        }
    };
    actionsColumn.setSortable(false);
    actionsColumn.setDataStoreName(COL_ID_ACTIONS);
    commentsListGrid.addColumn(actionsColumn, "");
}

From source file:ua.oilukraine.client.TabelView.java

/**
 * Add the columns to the table./*from w  w  w . ja v a2 s.  c om*/
 */
private void initTableColumns(final SelectionModel<DebtorsData> selectionModel,
        ColumnSortEvent.ListHandler<DebtorsData> sortHandler) {
    // Checkbox column. This table will uses a checkbox column for selection.
    // Alternatively, you can call cellTable.setSelectionEnabled(true) to enable
    // mouse selection.
    Column<DebtorsData, Boolean> checkColumn = new Column<DebtorsData, Boolean>(new CheckboxCell(true, false)) {
        @Override
        public Boolean getValue(DebtorsData object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    cellTable.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    cellTable.setColumnWidth(checkColumn, 40, Unit.PX);

    // Firm name.
    Column<DebtorsData, String> FirmNameColumn = new Column<DebtorsData, String>(new TextCell()) {
        @Override
        public String getValue(DebtorsData object) {
            return object.getName();
        }
    };
    FirmNameColumn.setSortable(true);
    sortHandler.setComparator(FirmNameColumn, new Comparator<DebtorsData>() {
        @Override
        public int compare(DebtorsData o1, DebtorsData o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    cellTable.addColumn(FirmNameColumn, "");
    //        FirmNameColumn.setFieldUpdater(new FieldUpdater<DebtorsData, String>() {
    //            @Override
    //            public void update(int index, DebtorsData object, String value) {
    //                // Called when the user changes the value.
    //                object.setName(value);
    //                //    ContactDatabase.get().refreshDisplays();
    //            }
    //        });
    cellTable.setColumnWidth(FirmNameColumn, 20, Unit.PCT);

    // OKPO
    Column<DebtorsData, String> okpoColumn = new Column<DebtorsData, String>(new TextCell()) {
        @Override
        public String getValue(DebtorsData object) {
            return object.getOkpo();
        }
    };
    okpoColumn.setSortable(true);
    sortHandler.setComparator(okpoColumn, new Comparator<DebtorsData>() {
        @Override
        public int compare(DebtorsData o1, DebtorsData o2) {
            return o1.getOkpo().compareTo(o2.getOkpo());
        }
    });
    cellTable.addColumn(okpoColumn, "");
    //        okpoColumn.setFieldUpdater(new FieldUpdater<DebtorsData, String>() {
    //            @Override
    //            public void update(int index, DebtorsData object, String value) {
    //                // Called when the user changes the value.
    //                object.setOkpo(value);
    //                //    ContactDatabase.get().refreshDisplays();
    //            }
    //        });
    cellTable.setColumnWidth(okpoColumn, 20, Unit.PCT);

    // Name Buh
    Column<DebtorsData, String> nameBuhColumn = new Column<DebtorsData, String>(new TextCell()) {
        @Override
        public String getValue(DebtorsData object) {
            return object.getName_buh();
        }
    };
    nameBuhColumn.setSortable(true);
    sortHandler.setComparator(nameBuhColumn, new Comparator<DebtorsData>() {
        @Override
        public int compare(DebtorsData o1, DebtorsData o2) {
            return o1.getName_buh().compareTo(o2.getName_buh());
        }
    });
    cellTable.addColumn(nameBuhColumn, "");
    //        okpoColumn.setFieldUpdater(new FieldUpdater<DebtorsData, String>() {
    //            @Override
    //            public void update(int index, DebtorsData object, String value) {
    //                // Called when the user changes the value.
    //                object.setOkpo(value);
    //                //    ContactDatabase.get().refreshDisplays();
    //            }
    //        });
    cellTable.setColumnWidth(nameBuhColumn, 20, Unit.PCT);

    // Phone Work Buh
    Column<DebtorsData, String> phoneWorkBuhColumn = new Column<DebtorsData, String>(new TextCell()) {
        @Override
        public String getValue(DebtorsData object) {
            return object.getPhone_work();
        }
    };
    phoneWorkBuhColumn.setSortable(true);
    sortHandler.setComparator(phoneWorkBuhColumn, new Comparator<DebtorsData>() {
        @Override
        public int compare(DebtorsData o1, DebtorsData o2) {
            return o1.getPhone_work().compareTo(o2.getPhone_work());
        }
    });
    cellTable.addColumn(phoneWorkBuhColumn, " ");
    //        okpoColumn.setFieldUpdater(new FieldUpdater<DebtorsData, String>() {
    //            @Override
    //            public void update(int index, DebtorsData object, String value) {
    //                // Called when the user changes the value.
    //                object.setOkpo(value);
    //                //    ContactDatabase.get().refreshDisplays();
    //            }
    //        });
    cellTable.setColumnWidth(phoneWorkBuhColumn, 20, Unit.PCT);

    // Phone Mob Buh
    Column<DebtorsData, String> phoneMobBuhColumn = new Column<DebtorsData, String>(new TextCell()) {
        @Override
        public String getValue(DebtorsData object) {
            return object.getPhone_mob();
        }
    };
    phoneMobBuhColumn.setSortable(true);
    sortHandler.setComparator(phoneMobBuhColumn, new Comparator<DebtorsData>() {
        @Override
        public int compare(DebtorsData o1, DebtorsData o2) {
            return o1.getPhone_mob().compareTo(o2.getPhone_mob());
        }
    });
    cellTable.addColumn(phoneMobBuhColumn, " ");
    //        okpoColumn.setFieldUpdater(new FieldUpdater<DebtorsData, String>() {
    //            @Override
    //            public void update(int index, DebtorsData object, String value) {
    //                // Called when the user changes the value.
    //                object.setOkpo(value);
    //                //    ContactDatabase.get().refreshDisplays();
    //            }
    //        });
    cellTable.setColumnWidth(phoneMobBuhColumn, 20, Unit.PCT);

    // Date Info
    DateCell dateCell = new DateCell();
    Column<DebtorsData, Date> dateColumn = new Column<DebtorsData, Date>(dateCell) {
        @Override
        public Date getValue(DebtorsData object) {
            return object.getDate_info();
        }
    };
    dateColumn.setSortable(true);
    dateColumn.setDefaultSortAscending(false);
    sortHandler.setComparator(dateColumn, new Comparator<DebtorsData>() {
        @Override
        public int compare(DebtorsData o1, DebtorsData o2) {
            return o1.getDate_info().compareTo(o2.getDate_info());
        }
    });
    cellTable.addColumn(dateColumn, " ");
    dateColumn.setFieldUpdater(new FieldUpdater<DebtorsData, Date>() {
        @Override
        public void update(int index, DebtorsData object, Date value) {
            // Called when the user changes the value.
            object.setDate_info(value);
            //    ContactDatabase.get().refreshDisplays();
        }
    });

    // DatePickerCell.
    DateTimeFormat dateFormat = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_MEDIUM);
    DatePickerCell datePicCell = new DatePickerCell(dateFormat);

    Column<DebtorsData, Date> datePicColumn = new Column<DebtorsData, Date>(datePicCell) {
        @Override
        public Date getValue(DebtorsData object) {
            return object.getDate_info();
        }
    };
    dateColumn.setSortable(true);
    dateColumn.setDefaultSortAscending(false);
    sortHandler.setComparator(dateColumn, new Comparator<DebtorsData>() {
        @Override
        public int compare(DebtorsData o1, DebtorsData o2) {
            return o1.getDate_info().compareTo(o2.getDate_info());
        }
    });
    cellTable.addColumn(dateColumn, "  Pic");

    //        addColumn(new DatePickerCell(dateFormat), "DatePicker", new GetValue<Date>() {
    //            @Override
    //            public Date getValue(ContactInfo contact) {
    //                return contact.getBirthday();
    //            }
    //        }, new FieldUpdater<ContactInfo, Date>() {
    //            @Override
    //            public void update(int index, ContactInfo object, Date value) {
    //                pendingChanges.add(new BirthdayChange(object, value));
    //            }
    //        });
    //        /**
    //         * Add a column with a header.
    //         *
    //         * @param <C> the cell type
    //         * @param cell the cell used to render the column
    //         * @param headerText the header string
    //         * @param getter the value getter for the cell
    //         */
    //    private <C> Column<ContactInfo, C> addColumn(Cell<C> cell, String headerText,
    //            final GetValue<C> getter, FieldUpdater<ContactInfo, C> fieldUpdater) {
    //        Column<ContactInfo, C> column = new Column<ContactInfo, C>(cell) {
    //            @Override
    //            public C getValue(ContactInfo object) {
    //                return getter.getValue(object);
    //            }
    //        };
    //        column.setFieldUpdater(fieldUpdater);
    //        if (cell instanceof AbstractEditableCell<?, ?>) {
    //            editableCells.add((AbstractEditableCell<?, ?>) cell);
    //        }
    //        contactList.addColumn(column, headerText);
    //        return column;
    //    }
    ///////////////////////////////////////////////////////////////////////
    //        // Address.
    //        Column<DebtorsData, String> addressColumn = new Column<DebtorsData, String>(
    //                new TextCell()) {
    //            @Override
    //            public String getValue(DebtorsData object) {
    //                return object.getAddress();
    //            }
    //        };
    //        addressColumn.setSortable(true);
    //        addressColumn.setDefaultSortAscending(false);
    //        sortHandler.setComparator(addressColumn, new Comparator<DebtorsData>() {
    //            @Override
    //            public int compare(DebtorsData o1, DebtorsData o2) {
    //                return o1.getAddress().compareTo(o2.getAddress());
    //            }
    //        });
    //        cellTable.addColumn(addressColumn, constants.cwCellTableColumnAddress());
    //        cellTable.setColumnWidth(addressColumn, 60, Unit.PCT);
    //
    //        ///////////////////////////////////////////////////////////////////////
    //        // Last name.
    //        Column<DebtorsData, String> lastNameColumn = new Column<DebtorsData, String>(
    //                new EditTextCell()) {
    //            @Override
    //            public String getValue(DebtorsData object) {
    //                return object.getLastName();
    //            }
    //        };
    //        lastNameColumn.setSortable(true);
    //        sortHandler.setComparator(lastNameColumn, new Comparator<DebtorsData>() {
    //            @Override
    //            public int compare(DebtorsData o1, DebtorsData o2) {
    //                return o1.getLastName().compareTo(o2.getLastName());
    //            }
    //        });
    //        cellTable.addColumn(lastNameColumn, constants.cwCellTableColumnLastName());
    //        lastNameColumn.setFieldUpdater(new FieldUpdater<DebtorsData, String>() {
    //            @Override
    //            public void update(int index, DebtorsData object, String value) {
    //                // Called when the user changes the value.
    //                object.setLastName(value);
    //                ContactDatabase.get().refreshDisplays();
    //            }
    //        });
    //        cellTable.setColumnWidth(lastNameColumn, 20, Unit.PCT);
    //
    //        // Category.
    //        final Category[] categories = ContactDatabase.get().queryCategories();
    //        List<String> categoryNames = new ArrayList<String>();
    //        for (Category category : categories) {
    //            categoryNames.add(category.getDisplayName());
    //        }
    //        SelectionCell categoryCell = new SelectionCell(categoryNames);
    //        Column<DebtorsData, String> categoryColumn = new Column<DebtorsData, String>(
    //                categoryCell) {
    //            @Override
    //            public String getValue(DebtorsData object) {
    //                return object.getCategory().getDisplayName();
    //            }
    //        };
    //        cellTable.addColumn(categoryColumn, constants.cwCellTableColumnCategory());
    //        categoryColumn.setFieldUpdater(new FieldUpdater<DebtorsData, String>() {
    //            @Override
    //            public void update(int index, DebtorsData object, String value) {
    //                for (Category category : categories) {
    //                    if (category.getDisplayName().equals(value)) {
    //                        object.setCategory(category);
    //                    }
    //                }
    //                ContactDatabase.get().refreshDisplays();
    //            }
    //        });
    //        cellTable.setColumnWidth(categoryColumn, 130, Unit.PX);
    //
    //        // Address.
    //        Column<DebtorsData, String> addressColumn = new Column<DebtorsData, String>(
    //                new TextCell()) {
    //            @Override
    //            public String getValue(DebtorsData object) {
    //                return object.getAddress();
    //            }
    //        };
    //        addressColumn.setSortable(true);
    //        addressColumn.setDefaultSortAscending(false);
    //        sortHandler.setComparator(addressColumn, new Comparator<DebtorsData>() {
    //            @Override
    //            public int compare(DebtorsData o1, DebtorsData o2) {
    //                return o1.getAddress().compareTo(o2.getAddress());
    //            }
    //        });
    //        cellTable.addColumn(addressColumn, constants.cwCellTableColumnAddress());
    //        cellTable.setColumnWidth(addressColumn, 60, Unit.PCT);
}