Java tutorial
/* * Copyright 2008 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package org.phrasebook.transword.client; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import org.apache.tools.ant.taskdefs.Ant; import org.phrasebook.transword.client.CwAdminTerminBox.NewFEHandler; import org.phrasebook.transword.client.model.Antonym; import org.phrasebook.transword.client.model.Association; import org.phrasebook.transword.client.model.Collocation; import org.phrasebook.transword.client.model.Example; import org.phrasebook.transword.client.model.FixedExpression; import org.phrasebook.transword.client.model.Grammar; import org.phrasebook.transword.client.model.LexNote; import org.phrasebook.transword.client.model.Synonym; import org.phrasebook.transword.shared.services.FixedExpressionServiceAsync; import com.google.gwt.cell.client.FieldUpdater; import com.google.gwt.cell.client.TextCell; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.RunAsyncCallback; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.KeyUpEvent; import com.google.gwt.event.dom.client.KeyUpHandler; import com.google.gwt.i18n.client.Constants; import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.user.cellview.client.Column; import com.google.gwt.user.cellview.client.DataGrid; import com.google.gwt.user.cellview.client.SimplePager; import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler; import com.google.gwt.user.cellview.client.SimplePager.TextLocation; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.CheckBox; import com.google.gwt.user.client.ui.DialogBox; import com.google.gwt.user.client.ui.DockPanel; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.Hidden; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.TextArea; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; import com.google.gwt.view.client.ListDataProvider; import com.google.gwt.view.client.NoSelectionModel; import com.google.gwt.view.client.SelectionChangeEvent; import com.google.gwt.view.client.SelectionModel; /** * Dictionary administration subsystem. */ public class CwDictionaryPanel extends Content { // Data Grid // private ListDataProvider<FixedExpression> dataProvider; public final FilteredListDataProvider<FixedExpression> dataProvider = new FilteredListDataProvider<FixedExpression>( new IFilter<FixedExpression>() { public boolean isValid(FixedExpression value, String filter) { if (filter == null || value == null) return true; if (!meanFlag) { return value.getCoreString().toLowerCase().contains(filter.toLowerCase()) || value.getDefinition_short().contains(filter.toLowerCase()); } else { return value.getDefinition_short().toLowerCase().contains(filter.toLowerCase()); } } }); /** * The main DataGrid. */ private DataGrid<FixedExpression> dataGrid; /** * The pager used to change the range of data. */ private SimplePager pager; private List<FixedExpression> dataList; private final FixedExpressionServiceAsync feService = FixedExpressionServiceAsync.Util.getInstance(); private static final String SERVER_ERROR = "An error occurred while " + "attempting to contact the server. Please check your network " + "connection and try again. The error is : "; /** * The constants used in this Content Widget. */ public static interface CwConstants extends Constants { String cwDictionary(); String cwDictionaryDescription(); String cwUnderstandPhrase(); String cwUsePhrase(); String cwSearchByMeanPhrase(); String cwAddInfo(); } /** * An instance of the constants. */ private final CwConstants constants; /** * Constructor. * * @param constants * the constants */ public CwDictionaryPanel(CwConstants constants) { super(constants.cwDictionary(), constants.cwDictionaryDescription()); this.constants = constants; } final FixedExpression selExpression = new FixedExpression(); final TextBoxAdvanced searchFilter = new TextBoxAdvanced(); final List<FixedExpression> lst = new ArrayList<FixedExpression>(); final NoSelectionModel<FixedExpression> selectionModel = new NoSelectionModel<FixedExpression>(); ListHandler<FixedExpression> sortHandler = null; boolean understandFlag, useFlag, meanFlag, infoFlag; /** * Initialize this example. */ @Override public Widget onInitialize() { final Button understand = new Button(constants.cwUnderstandPhrase()); final Button use = new Button(constants.cwUsePhrase()); final Button mean = new Button(constants.cwSearchByMeanPhrase()); final Button info = new Button(constants.cwAddInfo()); HorizontalPanel sPanel = new HorizontalPanel(); sPanel.setSpacing(5); sPanel.add(searchFilter); searchFilter.addValueChangeHandler(new IStringValueChanged() { public void valueChanged(String newValue) { dataProvider.setFilter(newValue); dataProvider.refresh(); } }); HorizontalPanel hPanel = new HorizontalPanel(); hPanel.setSpacing(5); hPanel.add(understand); hPanel.add(use); hPanel.add(mean); hPanel.add(info); VerticalPanel svPanel = new VerticalPanel(); svPanel.add(sPanel); svPanel.add(hPanel); // Top ToolBar panel DockPanel admin = new DockPanel(); admin.add(svPanel, DockPanel.NORTH); UnderstandHandler handler = new UnderstandHandler(); understand.addClickHandler(handler); MeanHandler mhandler = new MeanHandler(); mean.addClickHandler(mhandler); InfoHandler ihandler = new InfoHandler(); info.addClickHandler(ihandler); UseHandler uhandler = new UseHandler(); use.addClickHandler(uhandler); // DATA GRID OUT // Create a DataGrid. /* * Set a key provider that provides a unique key for each contact. If * key is used to identify contacts when fields (such as the name and * address) change. */ dataGrid = new DataGrid<FixedExpression>(); dataGrid.setWidth("100%"); /* * Do not refresh the headers every time the data is updated. The footer * depends on the current data, so we do not disable auto refresh on the * footer. */ // dataGrid.setAutoHeaderRefreshDisabled(true); // Set the message to display when the table is empty. // Create a Pager to control the table. SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class); pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true); pager.setDisplay(dataGrid); pager.setVisible(true); // dataProvider = new FilteredListDataProvider<FixedExpression>(); dataProvider.setList(new ArrayList<FixedExpression>()); dataGrid.setEmptyTableWidget(new Label("Loading, please wait. There are no fixed expressions yet!")); sortHandler = new ListHandler<FixedExpression>(dataProvider.getList()); dataGrid.addColumnSortHandler(sortHandler); selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { @SuppressWarnings("unchecked") NoSelectionModel<FixedExpression> sel = (NoSelectionModel<FixedExpression>) event.getSource(); selExpression.setCoreString(sel.getLastSelectedObject().getCoreString()); selExpression.setId(sel.getLastSelectedObject().getId()); if (selExpression.getId() != null) { understand.setEnabled(true); } else { understand.setEnabled(false); } } }); dataGrid.setSelectionModel(selectionModel);// , // DefaultSelectionEventManager.<FixedExpression> // createCheckboxManager()); // dataGrid.setSele dataGrid.setVisible(true); // initTableColumns(selectionModel, sortHandler); dataProvider.addDataDisplay(dataGrid); dataGrid.addColumnSortHandler(sortHandler); // dataGrid.add admin.add(dataGrid, DockPanel.CENTER); admin.add(pager, DockPanel.SOUTH); admin.setWidth("100%"); dataGrid.setHeight("450px"); admin.setCellWidth(dataGrid, "100%"); admin.setCellWidth(pager, "100%"); // Timer t = new Timer() { // public void run() { dataList = lst; List<FixedExpression> list2 = dataProvider.getList(); list2.addAll(dataList); dataProvider.refresh(); // } // }; // Schedule the timer to run once in 40 seconds. // t.schedule(10000); return admin; } class UnderstandHandler implements ClickHandler, KeyUpHandler { FixedExpression fe = new FixedExpression(); public void onKeyUp(KeyUpEvent event) { // TODO Auto-generated method stub } public void onClick(ClickEvent event) { // TODO Auto-generated method stub understandFlag = true; useFlag = false; meanFlag = false; infoFlag = false; initTableColumns(selectionModel, sortHandler); String serachString = searchFilter.getText(); final DialogBox dlgBox = new DialogBox(); final HTML serverResponseLabel = new HTML(); final Button clsButton = new Button("Close"); dlgBox.setText("Fixed Expression Result"); dlgBox.setAnimationEnabled(true); // We can set the id of a widget by accessing its // Element clsButton.getElement().setId("closeButton"); VerticalPanel dialogVPanel = new VerticalPanel(); dialogVPanel.addStyleName("dialogVPanel"); dialogVPanel.add(new HTML("<br><b>Server replies:</b>")); dialogVPanel.add(serverResponseLabel); dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); dialogVPanel.add(clsButton); dlgBox.setWidget(dialogVPanel); // Add a handler to close the DialogBox clsButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { dlgBox.hide(); } }); // final List<FixedExpression> lst = new // ArrayList<FixedExpression>(); feService.understandPhrase(serachString, new AsyncCallback<List<FixedExpression>>() { public void onFailure(Throwable caught) { // Show the RPC error message to the dlgBox.setText("Remote Procedure Call - Failure"); serverResponseLabel.addStyleName("serverResponseLabelError"); serverResponseLabel.setHTML(SERVER_ERROR + caught.toString()); dlgBox.center(); clsButton.setFocus(true); } public void onSuccess(List<FixedExpression> list) { lst.clear(); for (FixedExpression f : list) { lst.add(f); } System.out.println("OUT OF" + searchFilter.getText() + lst); Timer t = new Timer() { public void run() { dataList = lst; List<FixedExpression> list2 = dataProvider.getList(); list2.clear(); list2.addAll(dataList); dataProvider.refresh(); } }; t.schedule(3000); dlgBox.setText("Fixed Expression - Add Result"); serverResponseLabel.removeStyleName("Server Response Label Error"); serverResponseLabel.setHTML("OK" + lst.size()); // dlgBox.center(); clsButton.setFocus(true); } }); } } class UseHandler implements ClickHandler, KeyUpHandler { public void onKeyUp(KeyUpEvent event) { // TODO Auto-generated method stub } public void onClick(ClickEvent event) { // TODO Auto-generated method stub String searchString = searchFilter.getText(); understandFlag = false; useFlag = true; meanFlag = false; infoFlag = false; // lst.clear(); // System.out.println("CLMN CNT:"+dataGrid.getColumnCount()); initTableColumns(selectionModel, sortHandler); final DialogBox dlgBox = new DialogBox(); final HTML serverResponseLabel = new HTML(); final Button clsButton = new Button("Close"); dlgBox.setText("Fixed Expression Result"); dlgBox.setAnimationEnabled(true); // We can set the id of a widget by accessing its // Element clsButton.getElement().setId("closeButton"); VerticalPanel dialogVPanel = new VerticalPanel(); dialogVPanel.addStyleName("dialogVPanel"); dialogVPanel.add(new HTML("<br><b>Server replies:</b>")); dialogVPanel.add(serverResponseLabel); dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); dialogVPanel.add(clsButton); dlgBox.setWidget(dialogVPanel); // Add a handler to close the DialogBox clsButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { dlgBox.hide(); } }); feService.usePhrase(searchString, new AsyncCallback<List<FixedExpression>>() { public void onFailure(Throwable caught) { // Show the RPC error message to the dlgBox.setText("Remote Procedure Call - Failure"); serverResponseLabel.addStyleName("serverResponseLabelError"); serverResponseLabel.setHTML(SERVER_ERROR + caught.toString()); dlgBox.center(); clsButton.setFocus(true); } public void onSuccess(List<FixedExpression> list) { lst.clear(); for (FixedExpression f : list) { lst.add(f); } System.out.println("OUT OF" + searchFilter.getText() + lst); Timer t = new Timer() { public void run() { dataList = lst; List<FixedExpression> list2 = dataProvider.getList(); list2.clear(); list2.addAll(dataList); dataProvider.refresh(); } }; t.schedule(3000); dlgBox.setText("Fixed Expression - Add Result"); serverResponseLabel.removeStyleName("Server Response Label Error"); serverResponseLabel.setHTML("OK" + lst.size()); // dlgBox.center(); clsButton.setFocus(true); } }); } } class InfoHandler implements ClickHandler, KeyUpHandler { public void onKeyUp(KeyUpEvent event) { // TODO Auto-generated method stub } public void onClick(ClickEvent event) { // TODO Auto-generated method stub String searchString = searchFilter.getText(); understandFlag = false; useFlag = false; meanFlag = false; infoFlag = true; initTableColumns(selectionModel, sortHandler); final DialogBox dlgBox = new DialogBox(); final HTML serverResponseLabel = new HTML(); final Button clsButton = new Button("Close"); dlgBox.setText("Fixed Expression Result"); dlgBox.setAnimationEnabled(true); // We can set the id of a widget by accessing its // Element clsButton.getElement().setId("closeButton"); VerticalPanel dialogVPanel = new VerticalPanel(); dialogVPanel.addStyleName("dialogVPanel"); dialogVPanel.add(new HTML("<br><b>Server replies:</b>")); dialogVPanel.add(serverResponseLabel); dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); dialogVPanel.add(clsButton); dlgBox.setWidget(dialogVPanel); // Add a handler to close the DialogBox clsButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { dlgBox.hide(); } }); feService.infoPhrase(searchString, new AsyncCallback<List<FixedExpression>>() { public void onFailure(Throwable caught) { // Show the RPC error message to the dlgBox.setText("Remote Procedure Call - Failure"); serverResponseLabel.addStyleName("serverResponseLabelError"); serverResponseLabel.setHTML(SERVER_ERROR + caught.toString()); dlgBox.center(); clsButton.setFocus(true); } public void onSuccess(List<FixedExpression> list) { lst.clear(); for (FixedExpression f : list) { lst.add(f); } System.out.println("OUT OF" + searchFilter.getText() + lst); Timer t = new Timer() { public void run() { dataList = lst; List<FixedExpression> list2 = dataProvider.getList(); list2.clear(); list2.addAll(dataList); dataProvider.refresh(); } }; t.schedule(3000); dlgBox.setText("Fixed Expression - Add Result"); serverResponseLabel.removeStyleName("Server Response Label Error"); serverResponseLabel.setHTML("OK" + lst.size()); // dlgBox.center(); clsButton.setFocus(true); } }); } } class MeanHandler implements ClickHandler, KeyUpHandler { public void onKeyUp(KeyUpEvent event) { // TODO Auto-generated method stub } public void onClick(ClickEvent event) { // TODO Auto-generated method stub String searchString = searchFilter.getText(); understandFlag = false; useFlag = false; meanFlag = true; infoFlag = false; initTableColumns(selectionModel, sortHandler); final DialogBox dlgBox = new DialogBox(); final HTML serverResponseLabel = new HTML(); final Button clsButton = new Button("Close"); dlgBox.setText("Fixed Expression Result"); dlgBox.setAnimationEnabled(true); // We can set the id of a widget by accessing its // Element clsButton.getElement().setId("closeButton"); VerticalPanel dialogVPanel = new VerticalPanel(); dialogVPanel.addStyleName("dialogVPanel"); dialogVPanel.add(new HTML("<br><b>Server replies:</b>")); dialogVPanel.add(serverResponseLabel); dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); dialogVPanel.add(clsButton); dlgBox.setWidget(dialogVPanel); // Add a handler to close the DialogBox clsButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { dlgBox.hide(); } }); feService.meanPhrase(searchString, new AsyncCallback<List<FixedExpression>>() { public void onFailure(Throwable caught) { // Show the RPC error message to the dlgBox.setText("Remote Procedure Call - Failure"); serverResponseLabel.addStyleName("serverResponseLabelError"); serverResponseLabel.setHTML(SERVER_ERROR + caught.toString()); dlgBox.center(); clsButton.setFocus(true); } public void onSuccess(List<FixedExpression> list) { lst.clear(); for (FixedExpression f : list) { lst.add(f); } System.out.println("OUT OF" + searchFilter.getText() + " - " + lst); Timer t = new Timer() { public void run() { dataList = lst; List<FixedExpression> list2 = dataProvider.getList(); list2.clear(); list2.addAll(dataList); System.out.println("OUT OF LIST" + " - " + dataList); dataProvider.refresh(); } }; t.schedule(3000); dlgBox.setText("Fixed Expression - Add Result"); serverResponseLabel.removeStyleName("Server Response Label Error"); serverResponseLabel.setHTML("OK" + lst.size()); // dlgBox.center(); clsButton.setFocus(true); } }); } } // HERE private void initTableColumns(final SelectionModel<FixedExpression> selectionModel, ListHandler<FixedExpression> sortHandler) { int count = dataGrid.getColumnCount(); for (int i = 0; i < count; i++) { dataGrid.removeColumn(0); } // 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); } } @Override protected void asyncOnInitialize(final AsyncCallback<Widget> callback) { GWT.runAsync(CwDictionaryPanel.class, new RunAsyncCallback() { public void onFailure(Throwable caught) { callback.onFailure(caught); } public void onSuccess() { callback.onSuccess(onInitialize()); } }); } }