From 7a3bfdc81f80df873ebff30735926308c0cbeb24 Mon Sep 17 00:00:00 2001 From: Ben Konrath Date: Mon, 7 Mar 2011 16:36:48 +0100 Subject: [PATCH] Add support for horizontal alignment in the LayoutList columns. * TODO: Remove item about horizontal alignment. Add item about improvements to ColumnInfo. * src/main/java/org/glom/web/client/LayoutListView.java: Set horizontal alignment on the columns. Use ColumnInfo RPC object get the column title and horizontal alignment. * src/main/java/org/glom/web/client/OnlineGlom.java: Update LayoutListView creation with ColumnInfo RPC object. * src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java: Create a ColumnInfo object for every LayoutList columnn. Convert the FieldFormatting.HorizontalAlignment to the correct ColumnnInfo.HorizontatlAlignment with the new getColumnInfoHorizontalAlignment helper method. * src/main/java/org/glom/web/shared/ColumnInfo.java: New RPC object to encapsulate column information like alignment and title. This could be used to set the colour instead of on a per cell field basis. * src/main/java/org/glom/web/shared/LayoutListTable.java: Replace column title storage and retrieval with ColumnInfo. --- ChangeLog | 22 +++++++++++++++++ TODO | 4 ++-- .../java/org/glom/web/client/LayoutListView.java | 24 +++++++++++++++---- src/main/java/org/glom/web/client/OnlineGlom.java | 2 +- .../org/glom/web/server/OnlineGlomServiceImpl.java | 25 ++++++++++++++++--- src/main/java/org/glom/web/shared/ColumnInfo.java | 28 ++++++++++++++++++++++ .../java/org/glom/web/shared/LayoutListTable.java | 10 ++++---- 7 files changed, 100 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/glom/web/shared/ColumnInfo.java diff --git a/ChangeLog b/ChangeLog index 3432e3b..eb54c92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2011-03-07 Ben Konrath + + Add support for horizontal alignment in the LayoutList columns. + + * TODO: Remove item about horizontal alignment. Add item about + improvements to ColumnInfo. + * src/main/java/org/glom/web/client/LayoutListView.java: Set horizontal + alignment on the columns. Use ColumnInfo RPC object get the column + title and horizontal alignment. + * src/main/java/org/glom/web/client/OnlineGlom.java: Update + LayoutListView creation with ColumnInfo RPC object. + * src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java: Create + a ColumnInfo object for every LayoutList columnn. Convert the + FieldFormatting.HorizontalAlignment to the correct + ColumnnInfo.HorizontatlAlignment with the new + getColumnInfoHorizontalAlignment helper method. + * src/main/java/org/glom/web/shared/ColumnInfo.java: New RPC object + to encapsulate column information like alignment and title. This + could be used to set the colour instead of on a per cell field basis. + * src/main/java/org/glom/web/shared/LayoutListTable.java: Replace + column title storage and retrieval with ColumnInfo. + 2011-03-04 Ben Konrath Add support for column sorting. diff --git a/TODO b/TODO index 66d813a..a17ac98 100644 --- a/TODO +++ b/TODO @@ -5,8 +5,6 @@ Improvements to LayoutListView: * Implement column width size as specified in the glom file. -* Implement column alignment (automatic, left, right) as specified in the glom file. - * Add support for LayoutItem_Text, LayoutItem_Button and LayoutItem_Image items. * Make width of the CellTable used for the LayoutList consistent between the @@ -22,6 +20,8 @@ Improvements to LayoutListView: isn't coloured. I need to figure out a way to set 'style=background-colour:' on the whole column rather than just the cell. +* Use ColumnInfo rpc object to send text backgound and foreground colours + instead of sending this informaton for each cell. Improvments to LayoutDetailsView: diff --git a/src/main/java/org/glom/web/client/LayoutListView.java b/src/main/java/org/glom/web/client/LayoutListView.java index 341941d..55f0be5 100644 --- a/src/main/java/org/glom/web/client/LayoutListView.java +++ b/src/main/java/org/glom/web/client/LayoutListView.java @@ -21,6 +21,7 @@ package org.glom.web.client; import java.util.ArrayList; +import org.glom.web.shared.ColumnInfo; import org.glom.web.shared.GlomField; import com.google.gwt.cell.client.AbstractCell; @@ -32,9 +33,11 @@ import com.google.gwt.user.cellview.client.Column; import com.google.gwt.user.cellview.client.ColumnSortEvent.AsyncHandler; import com.google.gwt.user.cellview.client.ColumnSortList; import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo; +import com.google.gwt.user.cellview.client.SafeHtmlHeader; import com.google.gwt.user.cellview.client.SimplePager; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.view.client.AsyncDataProvider; import com.google.gwt.view.client.HasData; @@ -80,7 +83,7 @@ public class LayoutListView extends Composite { } } - public LayoutListView(String[] headers, int numRows) { + public LayoutListView(ColumnInfo[] columns, int numRows) { final CellTable table = new CellTable(20); AsyncDataProvider dataProvider = new AsyncDataProvider() { @@ -126,7 +129,8 @@ public class LayoutListView extends Composite { panel.add(table); panel.add(pager); - for (int i = 0; i < headers.length; i++) { + // create instances of GlomFieldColumn to retrieve the GlomField objects + for (int i = 0; i < columns.length; i++) { // create a new column final int j = new Integer(i); GlomFieldColumn column = new GlomFieldColumn() { @@ -137,9 +141,21 @@ public class LayoutListView extends Composite { }; // set column properties and add to cell table + switch (columns[i].getAlignment()) { + case HORIZONTAL_ALIGNMENT_LEFT: + column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); + break; + case HORIZONTAL_ALIGNMENT_RIGHT: + column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); + break; + case HORIZONTAL_ALIGNMENT_AUTO: + default: + // TODO: log warning, this shouldn't happen + column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_DEFAULT); + break; + } column.setSortable(true); - table.addColumn(column, headers[i]); - + table.addColumn(column, new SafeHtmlHeader(SafeHtmlUtils.fromString(columns[i].getHeader()))); } // set row count which is needed for paging diff --git a/src/main/java/org/glom/web/client/OnlineGlom.java b/src/main/java/org/glom/web/client/OnlineGlom.java index a63e5d5..dfc2810 100644 --- a/src/main/java/org/glom/web/client/OnlineGlom.java +++ b/src/main/java/org/glom/web/client/OnlineGlom.java @@ -96,7 +96,7 @@ public class OnlineGlom implements EntryPoint { public void onSuccess(LayoutListTable result) { if (table != null) mainVPanel.remove(table); - table = new LayoutListView(result.getColumnTitles(), result.getNumRows()); + table = new LayoutListView(result.getColumns(), result.getNumRows()); mainVPanel.add(table); Window.setTitle("OnlineGlom - " + documentName + ": " + dropBox.getItemText(dropBox.getSelectedIndex())); } diff --git a/src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java b/src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java index 8efd241..c64825f 100644 --- a/src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java +++ b/src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java @@ -47,6 +47,7 @@ import org.glom.libglom.SortClause; import org.glom.libglom.SortFieldPair; import org.glom.libglom.StringVector; import org.glom.web.client.OnlineGlomService; +import org.glom.web.shared.ColumnInfo; import org.glom.web.shared.GlomDocument; import org.glom.web.shared.GlomField; import org.glom.web.shared.LayoutListTable; @@ -160,17 +161,19 @@ public class OnlineGlomServiceImpl extends RemoteServiceServlet implements Onlin // find the layout list fields int numItems = safeLongToInt(layoutItemsVec.size()); - String[] columnTitles = new String[numItems]; + ColumnInfo[] columns = new ColumnInfo[numItems]; LayoutFieldVector layoutFields = new LayoutFieldVector(); for (int i = 0; i < numItems; i++) { + // TODO add support for other LayoutItems (Text, Image, Button) LayoutItem item = layoutItemsVec.get(i); - columnTitles[i] = item.get_title_or_name(); LayoutItem_Field field = LayoutItem_Field.cast_dynamic(item); if (field != null) { layoutFields.add(field); + FieldFormatting.HorizontalAlignment alignment = field.get_formatting_used_horizontal_alignment(); + columns[i] = new ColumnInfo(item.get_title_or_name(), getColumnInfoHorizontalAlignment(alignment)); } } - tableInfo.setColumnTitles(columnTitles); + tableInfo.setColumns(columns); // get the size of the returned query for the pager // TODO since we're executing a query anyway, maybe we should return the rows that will be displayed on the @@ -399,4 +402,20 @@ public class OnlineGlomServiceImpl extends RemoteServiceServlet implements Onlin return ""; } + /* + * This method converts a FieldFormatting.HorizontalAlignment to the equivalent ColumnInfo.HorizontalAlignment. The + * need for this comes from the fact that the GWT HorizontalAlignment classes can't be used with RPC and there's no + * easy way to use the java-libglom FieldFormatting.HorizontalAlignment enum with RPC. An enum indentical to + * FieldFormatting.HorizontalAlignment is included in the ColumnInfo class. + */ + private ColumnInfo.HorizontalAlignment getColumnInfoHorizontalAlignment( + FieldFormatting.HorizontalAlignment alignment) { + int value = alignment.swigValue(); + ColumnInfo.HorizontalAlignment[] columnInfoValues = ColumnInfo.HorizontalAlignment.class.getEnumConstants(); + if (value < columnInfoValues.length && value >= 0) + return columnInfoValues[value]; + // TODO: log error: value out of range, returning HORIZONTAL_ALIGNMENT_RIGHT + return columnInfoValues[FieldFormatting.HorizontalAlignment.HORIZONTAL_ALIGNMENT_RIGHT.swigValue()]; + } + } \ No newline at end of file diff --git a/src/main/java/org/glom/web/shared/ColumnInfo.java b/src/main/java/org/glom/web/shared/ColumnInfo.java new file mode 100644 index 0000000..69f84b8 --- /dev/null +++ b/src/main/java/org/glom/web/shared/ColumnInfo.java @@ -0,0 +1,28 @@ +package org.glom.web.shared; + +import java.io.Serializable; + +@SuppressWarnings("serial") +public class ColumnInfo implements Serializable { + public enum HorizontalAlignment { + HORIZONTAL_ALIGNMENT_AUTO, HORIZONTAL_ALIGNMENT_LEFT, HORIZONTAL_ALIGNMENT_RIGHT; + } + + private String header; + private HorizontalAlignment alignment; + + public ColumnInfo() { + } + + public ColumnInfo(String header, HorizontalAlignment alignment) { + this.header = header; + this.alignment = alignment; + } + + // @formatter:off + public String getHeader() { return header;} + public void setHeader(String header) { this.header = header; } + public HorizontalAlignment getAlignment() { return alignment;} + public void setAlignment(HorizontalAlignment alignment) { this.alignment = alignment; } + // @formatter:on +} diff --git a/src/main/java/org/glom/web/shared/LayoutListTable.java b/src/main/java/org/glom/web/shared/LayoutListTable.java index 1d2b0b8..fbeeaba 100644 --- a/src/main/java/org/glom/web/shared/LayoutListTable.java +++ b/src/main/java/org/glom/web/shared/LayoutListTable.java @@ -25,16 +25,16 @@ import java.io.Serializable; public class LayoutListTable implements Serializable { private String name; private String title; - private String[] columnTitles; + private ColumnInfo[] columns; private int numRows; public LayoutListTable() { } - public LayoutListTable(String name, String title, String[] columnTitles, int numRows) { + public LayoutListTable(String name, String title, ColumnInfo[] columns, int numRows) { this.name = name; this.title = title; - this.columnTitles = columnTitles; + this.columns = columns; this.numRows = numRows; } @@ -43,8 +43,8 @@ public class LayoutListTable implements Serializable { public void setName(String name) { this.name = name;} public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } - public String[] getColumnTitles() { return columnTitles; } - public void setColumnTitles(String[] columns) { this.columnTitles = columns; } + public ColumnInfo[] getColumns() { return columns; } + public void setColumns(ColumnInfo[] columns) { this.columns = columns; } public int getNumRows() { return numRows; } public void setNumRows(int numRows) { this.numRows = numRows; } // @formatter:on -- 2.1.4