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

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

Introduction

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

Prototype

public void setSortable(boolean sortable) 

Source Link

Document

Set whether or not the column can be sorted.

Usage

From source file:org.phrasebook.transword.client.CwAdminTerminBox.java

License:Apache License

private void initTableColumns(final SelectionModel<FixedExpression> selectionModel,
        ListHandler<FixedExpression> sortHandler) {

    // Fixed Expression
    Column<FixedExpression, String> fixedExpression = new Column<FixedExpression, String>(new TextCell()) {
        @Override//from  www.j  av  a2  s  . c o m
        public String getValue(FixedExpression object) {
            return object.getCoreString();
        }
    };
    fixedExpression.setSortable(true);
    sortHandler.setComparator(fixedExpression, new Comparator<FixedExpression>() {

        public int compare(FixedExpression o1, FixedExpression o2) {
            return o1.getCoreString().compareTo(o2.getCoreString());
        }
    });
    dataGrid.addColumn(fixedExpression, "Fixed Expression");
    fixedExpression.setFieldUpdater(new FieldUpdater<FixedExpression, String>() {

        public void update(int index, FixedExpression object, String value) {
            // Called when the user changes the value.
            object.setCoreString(value);
            dataProvider.refresh();
        }
    });
    dataGrid.setColumnWidth(fixedExpression, 50, Unit.PCT);

    // Meaning
    Column<FixedExpression, String> meaningColumn = new Column<FixedExpression, String>(new TextCell()) {
        @Override
        public String getValue(FixedExpression object) {
            return object.getDefinition_short();
        }
    };
    meaningColumn.setSortable(true);
    sortHandler.setComparator(meaningColumn, new Comparator<FixedExpression>() {
        public int compare(FixedExpression o1, FixedExpression o2) {
            return o1.getDefinition_short().compareTo(o2.getDefinition_short());
        }
    });
    dataGrid.addColumn(meaningColumn, "Definition");
    meaningColumn.setFieldUpdater(new FieldUpdater<FixedExpression, String>() {
        public void update(int index, FixedExpression object, String value) {
            // Called when the user changes the value.
            object.setDefinition_short(value);
            dataProvider.refresh();
        }
    });
    dataGrid.setColumnWidth(meaningColumn, 20, Unit.PCT);

    // English Translation.
    Column<FixedExpression, String> engColumn = new Column<FixedExpression, String>(new TextCell()) {
        @Override
        public String getValue(FixedExpression object) {
            return object.getEngTranslation();
        }
    };
    engColumn.setSortable(true);
    sortHandler.setComparator(engColumn, new Comparator<FixedExpression>() {
        public int compare(FixedExpression o1, FixedExpression o2) {
            return o1.getEngTranslation().compareTo(o2.getEngTranslation());
        }
    });
    dataGrid.addColumn(engColumn, "In English");
    engColumn.setFieldUpdater(new FieldUpdater<FixedExpression, String>() {
        public void update(int index, FixedExpression object, String value) {
            // Called when the user changes the value.
            object.setEngTranslation(value);
            dataProvider.refresh();
        }
    });
    dataGrid.setColumnWidth(engColumn, 30, Unit.PCT);

    // Usage Style.
    Column<FixedExpression, String> usColumn = new Column<FixedExpression, String>(new TextCell()) {
        @Override
        public String getValue(FixedExpression object) {
            return object.getUsageStyle();
        }
    };
    usColumn.setSortable(true);
    sortHandler.setComparator(usColumn, new Comparator<FixedExpression>() {
        public int compare(FixedExpression o1, FixedExpression o2) {
            return o1.getUsageStyle().compareTo(o2.getUsageStyle());
        }
    });
    dataGrid.addColumn(usColumn, "Usage Style");
    dataGrid.setColumnWidth(usColumn, 20, Unit.PCT);
}

From source file:org.phrasebook.transword.client.CwDictionaryPanel.java

License:Apache License

private void initTableColumns(final SelectionModel<FixedExpression> selectionModel,
        ListHandler<FixedExpression> sortHandler) {

    int count = dataGrid.getColumnCount();
    for (int i = 0; i < count; i++) {
        dataGrid.removeColumn(0);/*from   w  w w .jav a 2s .  com*/
    }
    // Data Grid.
    // Fixed Expression
    Column<FixedExpression, String> fixedExpression = new Column<FixedExpression, String>(new TextCell()) {
        @Override
        public String getValue(FixedExpression object) {
            return object.getCoreString();
        }
    };
    fixedExpression.setSortable(true);
    sortHandler.setComparator(fixedExpression, new Comparator<FixedExpression>() {

        public int compare(FixedExpression o1, FixedExpression o2) {
            return o1.getCoreString().compareTo(o2.getCoreString());
        }
    });
    System.out.println("CLMN CNT:" + dataGrid.getColumnIndex(fixedExpression));
    // if(dataGrid.getColumnIndex(fixedExpression)>0){
    // System.out.println("CLMN CNT:"+dataGrid.getColumnIndex(fixedExpression));
    // dataGrid.removeColumn(fixedExpression);
    // }
    dataGrid.addColumn(fixedExpression, "Fixed Expression");

    fixedExpression.setFieldUpdater(new FieldUpdater<FixedExpression, String>() {

        public void update(int index, FixedExpression object, String value) {
            // Called when the user changes the value.
            object.setCoreString(value);
            dataProvider.refresh();
        }
    });
    dataGrid.setColumnWidth(fixedExpression, 30, Unit.PCT);

    if (!meanFlag) {
        // Meaning
        Column<FixedExpression, String> meaningColumn = new Column<FixedExpression, String>(new TextCell()) {
            @Override
            public String getValue(FixedExpression object) {
                return object.getDefinition_short();
            }
        };
        meaningColumn.setSortable(true);
        sortHandler.setComparator(meaningColumn, new Comparator<FixedExpression>() {
            public int compare(FixedExpression o1, FixedExpression o2) {
                return o1.getDefinition_short().compareTo(o2.getDefinition_short());
            }
        });
        // if(dataGrid.getColumnIndex(meaningColumn)>0){
        // dataGrid.removeColumn(meaningColumn);
        // }
        dataGrid.addColumn(meaningColumn, "Definition");
        meaningColumn.setFieldUpdater(new FieldUpdater<FixedExpression, String>() {
            public void update(int index, FixedExpression object, String value) {
                // Called when the user changes the value.
                object.setDefinition_short(value);
                dataProvider.refresh();
            }
        });
        dataGrid.setColumnWidth(meaningColumn, 20, Unit.PCT);

    }

    // English Translation.
    Column<FixedExpression, String> engColumn = new Column<FixedExpression, String>(new TextCell()) {
        @Override
        public String getValue(FixedExpression object) {
            return object.getEngTranslation();
        }
    };
    engColumn.setSortable(true);
    sortHandler.setComparator(engColumn, new Comparator<FixedExpression>() {
        public int compare(FixedExpression o1, FixedExpression o2) {
            return o1.getEngTranslation().compareTo(o2.getEngTranslation());
        }
    });
    dataGrid.addColumn(engColumn, "In English");
    engColumn.setFieldUpdater(new FieldUpdater<FixedExpression, String>() {
        public void update(int index, FixedExpression object, String value) {
            // Called when the user changes the value.
            object.setEngTranslation(value);
            dataProvider.refresh();
        }
    });
    dataGrid.setColumnWidth(engColumn, 30, Unit.PCT);

    // Grammar Information
    if (!infoFlag) {
        Column<FixedExpression, String> grColumn = new Column<FixedExpression, String>(new TextCell()) {
            @Override
            public String getValue(FixedExpression object) {
                String grammars = "";
                for (Grammar g : object.getGrammars()) {
                    grammars += g.getGrammar() + " ";
                }
                System.out.println(grammars);
                return grammars;
            }
        };
        grColumn.setSortable(true);
        sortHandler.setComparator(grColumn, new Comparator<FixedExpression>() {
            public int compare(FixedExpression o1, FixedExpression o2) {
                String grammars1 = null, grammars2 = null;
                for (Grammar g : o1.getGrammars()) {
                    grammars1 += g.getGrammar();
                }

                for (Grammar g : o1.getGrammars()) {
                    grammars2 += g.getGrammar();
                }
                return grammars1.compareTo(grammars2);
            }
        });
        dataGrid.addColumn(grColumn, "Grammar");
        dataGrid.setColumnWidth(grColumn, 20, Unit.PCT);
    }

    if (useFlag || meanFlag || infoFlag) {
        // Examples
        Column<FixedExpression, String> exColumn = new Column<FixedExpression, String>(new TextCell()) {
            @Override
            public String getValue(FixedExpression object) {
                String examples = "";
                for (Example e : object.getExamples()) {
                    if (!useFlag)
                        examples += e.getExample() + " en:" + e.getEngTranslation() + "\n";
                    else
                        examples += e.getExample() + "\n";

                }
                System.out.println(examples);
                return examples;
            }
        };
        exColumn.setSortable(true);
        sortHandler.setComparator(exColumn, new Comparator<FixedExpression>() {
            public int compare(FixedExpression o1, FixedExpression o2) {
                String ex1 = null, ex2 = null;
                for (Example e : o1.getExamples()) {
                    ex1 += e.getExample();
                }

                for (Example e : o2.getExamples()) {
                    ex2 += e.getExample();
                }
                return ex1.compareTo(ex2);
            }
        });
        dataGrid.addColumn(exColumn, "Example");
        dataGrid.setColumnWidth(exColumn, 20, Unit.PCT);
        // Collocations
        Column<FixedExpression, String> clColumn = new Column<FixedExpression, String>(new TextCell()) {
            @Override
            public String getValue(FixedExpression object) {
                String cols = "";
                for (Collocation c : object.getCollocations()) {
                    if (!useFlag)
                        cols += c.getCollocation() + " en:" + c.getEngTranslation() + "\n";
                    else
                        cols += c.getCollocation() + "\n";

                }
                System.out.println(cols);
                return cols;
            }
        };
        clColumn.setSortable(true);
        sortHandler.setComparator(exColumn, new Comparator<FixedExpression>() {
            public int compare(FixedExpression o1, FixedExpression o2) {
                String c1 = null, c2 = null;
                for (Collocation c : o1.getCollocations()) {
                    c1 += c.getCollocation();
                }

                for (Collocation c : o2.getCollocations()) {
                    c2 += c.getCollocation();
                }
                return c1.compareTo(c2);
            }
        });
        dataGrid.addColumn(clColumn, "Collocation");
        dataGrid.setColumnWidth(clColumn, 20, Unit.PCT);
    }
    if (infoFlag) {
        // Synonyms
        Column<FixedExpression, String> sColumn = new Column<FixedExpression, String>(new TextCell()) {
            @Override
            public String getValue(FixedExpression object) {
                String ss = "";
                for (Synonym s : object.getSynonyms()) {
                    ss += s.getSynonym() + " ";
                }
                System.out.println(ss);
                return ss;
            }
        };
        sColumn.setSortable(true);
        sortHandler.setComparator(sColumn, new Comparator<FixedExpression>() {
            public int compare(FixedExpression o1, FixedExpression o2) {
                String s1 = null, s2 = null;
                for (Synonym s : o1.getSynonyms()) {
                    s1 += s.getSynonym();
                }

                for (Synonym s : o1.getSynonyms()) {
                    s2 += s.getSynonym();
                }
                return s1.compareTo(s2);
            }
        });
        dataGrid.addColumn(sColumn, "Synonym");
        dataGrid.setColumnWidth(sColumn, 20, Unit.PCT);
        // Antonyms
        Column<FixedExpression, String> aColumn = new Column<FixedExpression, String>(new TextCell()) {
            @Override
            public String getValue(FixedExpression object) {
                String as = "";
                for (Antonym a : object.getAntonyms()) {
                    as += a.getAntonym() + " ";
                }
                System.out.println(as);
                return as;
            }
        };
        aColumn.setSortable(true);
        sortHandler.setComparator(aColumn, new Comparator<FixedExpression>() {
            public int compare(FixedExpression o1, FixedExpression o2) {
                String a1 = null, a2 = null;
                for (Antonym a : o1.getAntonyms()) {
                    a1 += a.getAntonym();
                }

                for (Antonym a : o1.getAntonyms()) {
                    a2 += a.getAntonym();
                }
                return a1.compareTo(a2);
            }
        });
        dataGrid.addColumn(aColumn, "Antonym");
        dataGrid.setColumnWidth(aColumn, 20, Unit.PCT);
    }

}

From source file:org.rstudio.core.client.widget.ModifyKeyboardShortcutsWidget.java

License:Open Source License

private Column<KeyboardShortcutEntry, String> editableTextColumn(String name,
        final ValueGetter<KeyboardShortcutEntry> getter) {
    EditTextCell editTextCell = new EditTextCell() {
        @Override/*w  ww .j a v  a 2  s  .co m*/
        public void onBrowserEvent(final Context context, final Element parent, final String value,
                final NativeEvent event, final ValueUpdater<String> updater) {
            // GWT's EditTextCell will reset the text of the cell to the last
            // entered text on an Escape keypress. We don't desire that
            // behaviour (we want to restore the _first_ value presented when
            // the user opened the widget); so instead we just blur the input
            // element (thereby committing the current selection) and ensure
            // that selection has been appropriately reset in an earlier preview
            // handler.
            if (event.getType().equals("keyup") && event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
                parent.getFirstChildElement().blur();
                return;
            }

            super.onBrowserEvent(context, parent, value, event, updater);
        }
    };

    Column<KeyboardShortcutEntry, String> column = new Column<KeyboardShortcutEntry, String>(editTextCell) {
        @Override
        public String getValue(KeyboardShortcutEntry binding) {
            return getter.getValue(binding);
        }
    };

    column.setFieldUpdater(new FieldUpdater<KeyboardShortcutEntry, String>() {
        @Override
        public void update(int index, KeyboardShortcutEntry binding, String value) {
            KeySequence keys = KeySequence.fromShortcutString(value);

            // Differentiate between resetting the key sequence and
            // adding a new key sequence.
            if (keys.equals(binding.getOriginalKeySequence())) {
                changes_.remove(binding);
                binding.restoreOriginalKeySequence();
            } else {
                KeyboardShortcutEntry newBinding = new KeyboardShortcutEntry(binding.getId(), binding.getName(),
                        keys, binding.getCommandType(), true, binding.getContext());

                changes_.put(binding, newBinding);
                binding.setKeySequence(keys);
            }

            table_.setKeyboardSelectedColumn(0);
            updateData(dataProvider_.getList());
        }
    });

    column.setSortable(true);
    table_.addColumn(column, new TextHeader(name));
    return column;
}

From source file:org.rstudio.studio.client.workbench.views.files.ui.FilesList.java

License:Open Source License

private Column<FileSystemItem, ImageResource> addIconColumn(final FileTypeRegistry fileTypeRegistry) {
    Column<FileSystemItem, ImageResource> iconColumn = new Column<FileSystemItem, ImageResource>(
            new ImageResourceCell()) {

        @Override/* w w  w . j  a  v a 2  s .c  o  m*/
        public ImageResource getValue(FileSystemItem object) {
            if (object == parentPath_)
                return FileIconResources.INSTANCE.iconUpFolder();
            else
                return fileTypeRegistry.getIconForFile(object);
        }
    };
    iconColumn.setSortable(true);
    filesCellTable_.addColumn(iconColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    filesCellTable_.setColumnWidth(iconColumn, 20, Unit.PX);

    sortHandler_.setComparator(iconColumn, new FilesListComparator() {
        @Override
        public int doCompare(FileSystemItem arg0, FileSystemItem arg1) {
            if (arg0.isDirectory() && !arg1.isDirectory())
                return 1;
            else if (arg1.isDirectory() && !arg0.isDirectory())
                return -1;
            else
                return arg0.getExtension().compareTo(arg1.getExtension());
        }
    });

    return iconColumn;
}

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 v  a2s.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.common.ChangelistTable.java

License:Open Source License

protected void configureTable() {
    Column<StatusAndPath, String> statusColumn = new Column<StatusAndPath, String>(
            new NotEditingTextCell(getStatusRenderer())) {
        @Override//from   w ww. j  a  va  2  s.  co m
        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());
        }
    });

    Column<StatusAndPath, String> pathColumn = new Column<StatusAndPath, String>(new NotEditingTextCell()) {
        @Override
        public String getValue(StatusAndPath object) {
            String path = object.getPath();
            if (object.isDirectory() && !path.endsWith("/"))
                path = path + "/";
            return path;
        }
    };
    pathColumn.setSortable(true);
    sortHandler_.setComparator(pathColumn, new StatusAndPath.PathComparator());
    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 .  j a  va 2s  .  co  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

/**
 * Adds a column to the end of the table.
 *
 * @param col the column to be added//w w  w  .  j  av a2s.  co m
 */
public void addColumn(Column<T, ?> col) {
    col.setSortable(true);
    dataGrid.addColumn(col);
}

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

License:Apache License

/**
 * Adds a column to the end of the table.
 *
 * This is if T is not yet known/*  w w  w  .ja va2s.  com*/
 *
 * @param col the column to be added
 */
public void addColumnWithNoType(Column col) {
    col.setSortable(true);
    dataGrid.addColumn(col);
}

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

License:Apache License

/**
 * Adds a column to the end of the table with an associated header.
 *
 * @param col the column to be added//from   ww  w  .java2 s .  c  om
 * @param header the associated {@link Header}
 */
public void addColumn(Column<T, ?> col, Header<?> header) {
    col.setSortable(true);
    if (header instanceof FilterSortHeader) {
        ((FilterSortHeader) header).addFilterChangeHandler(this);
    }
    dataGrid.addColumn(col, header);
}