aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2007-06-28 10:55:16 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2007-06-28 10:55:16 +0000
commit67254b15d8004ef73e17eaab443a00b4d32d0cd9 (patch)
tree350d132cf9028197d7789d1d5ff4435baf12ae66 /src
parentc7b66c62580296abbbc743b0300378480ac4610e (diff)
downloadvaadin-framework-67254b15d8004ef73e17eaab443a00b4d32d0cd9.tar.gz
vaadin-framework-67254b15d8004ef73e17eaab443a00b4d32d0cd9.zip
scrolling table: ordering implemented
svn changeset:1797/svn branch:trunk
Diffstat (limited to 'src')
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/scrolltable/IScrollTable.java88
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/scrolltable/IScrollTableBody.java6
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/public/component-themes/common/css/common.css12
-rw-r--r--src/com/itmill/toolkit/ui/Table.java2
4 files changed, 91 insertions, 17 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/scrolltable/IScrollTable.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/scrolltable/IScrollTable.java
index 4bb7b08193..cc9a929614 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/scrolltable/IScrollTable.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/scrolltable/IScrollTable.java
@@ -10,6 +10,7 @@ import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Timer;
+import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Grid;
@@ -64,7 +65,9 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
private IScrollTableBody tBody;
private int width = -1;
private int height = -1;
- private int firstvisible;
+ private int firstvisible = 0;
+ private boolean sortAscending;
+ private String sortColumn;
public IScrollTable() {
headerContainer.setStyleName("iscrolltable-header");
@@ -91,7 +94,9 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
this.immediate = uidl.getBooleanAttribute("immediate");
this.totalRows = uidl.getIntAttribute("totalrows");
this.pageLength = uidl.getIntAttribute("pagelength");
- this.firstvisible = uidl.getIntVariable("firstvisible");
+ if(pageLength == 0)
+ pageLength = totalRows;
+ this.firstvisible = uidl.hasVariable("firstvisible") ? uidl.getIntVariable("firstvisible") : 0;
if(uidl.hasAttribute("rowheaders"))
rowHeaders = true;
if(uidl.hasAttribute("width"))
@@ -99,6 +104,11 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
if(uidl.hasAttribute("height"))
width = uidl.getIntAttribute("height");
+ if(uidl.hasVariable("sortascending")) {
+ this.sortAscending = uidl.getBooleanVariable("sortascending");
+ this.sortColumn = uidl.getStringVariable("sortcolumn");
+ }
+
UIDL columnInfo = null;
UIDL rowData = null;
for(Iterator it = uidl.getChildIterator(); it.hasNext();) {
@@ -157,8 +167,15 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
if(c != null && c.getColKey().equals(cid)) {
c.setText(col.getStringAttribute("caption"));
} else {
- tHead.setWidget(0, colIndex,
- new HeaderCell(cid, col.getStringAttribute("caption")));
+ c = new HeaderCell(cid, col.getStringAttribute("caption"));
+ tHead.setWidget(0, colIndex, c );
+ }
+ if(col.hasAttribute("sortable")) {
+ c.setSortable(true);
+ if(cid.equals(sortColumn))
+ c.setSorted(true);
+ else
+ c.setSorted(false);
}
}
}
@@ -231,11 +248,9 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
rowRequestHandler.cancel();
// fix headers horizontal scrolling
- System.out.println("scrolling header to " + scrollLeft);
headerContainer.setHorizontalScrollPosition(scrollLeft);
-
- firstRowInViewPort = (int) Math.ceil( scrollTop / tBody.getRowHeight() );
+ firstRowInViewPort = (int) Math.ceil( scrollTop / (double) tBody.getRowHeight() );
client.console.log("At scrolltop: " + scrollTop + " At row " + firstRowInViewPort);
int postLimit = (int) (firstRowInViewPort + pageLength + pageLength*CACHE_REACT_RATE);
@@ -448,19 +463,28 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
}
}
- public class HeaderCell extends Composite {
+ public class HeaderCell extends Composite implements ClickListener {
private DragWidget dragWidget;
private Label text;
+
+ private boolean sortable = false;
+ private String cid;
private HeaderCell(){};
- public void setText(String stringAttribute) {
- text.setText(stringAttribute);
- }
- public String getColKey() {
- return dragWidget.getColKey();
+
+ public void setSortable(boolean b) {
+ if(b == sortable)
+ return;
+ sortable = b;
+ if(sortable)
+ text.addClickListener(this);
+ else
+ text.removeClickListener(this);
}
+
public HeaderCell(String colId, String headerText) {
+ this.cid = colId;
FlowPanel fp = new FlowPanel();
DOM.setStyleAttribute(fp.getElement(), "white-space", "nowrap");
@@ -483,6 +507,44 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
text.setWidth((w - DragWidget.DRAG_WIDGET_WIDTH - 4) + "px");
setWidth(w + "px");
}
+ public void setText(String stringAttribute) {
+ text.setText(stringAttribute);
+ }
+ public String getColKey() {
+ return dragWidget.getColKey();
+ }
+
+ /**
+ * Listens clicks to headers text. This changes sorting.
+ */
+ public void onClick(Widget sender) {
+ if(sortColumn.equals(cid)) {
+ // just toggle order
+ client.updateVariable(id, "sortascending", !sortAscending, false);
+ } else {
+ // set table scrolled by this column
+ client.updateVariable(id, "sortcolumn", cid, false);
+ }
+ // get also cache columns at the same request
+ bodyContainer.setScrollPosition(0);
+ firstvisible = 0;
+ rowRequestHandler.setReqFirstRow(0);
+ rowRequestHandler.setReqRows((int) (2*pageLength*CACHE_RATE + pageLength));
+ rowRequestHandler.deferRowFetch();
+ }
+
+ private void setSorted(boolean sorted) {
+ if(sorted) {
+ if(sortAscending)
+ this.setStyleName("headerCellAsc");
+ else
+ this.setStyleName("headerCellDesc");
+ } else {
+ this.setStyleName("headerCell");
+ }
+ }
+
+
}
}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/scrolltable/IScrollTableBody.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/scrolltable/IScrollTableBody.java
index 2eb762aaaa..f0249f9648 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/scrolltable/IScrollTableBody.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/scrolltable/IScrollTableBody.java
@@ -103,13 +103,14 @@ public class IScrollTableBody extends Panel {
addRowBeforeFirstRendered(rowArray[i]);
firstRendered--;
}
- } else if (firstIndex > lastRendered || firstIndex + rows < firstRendered) {
+// } else if (firstIndex > lastRendered || firstIndex + rows < firstRendered) {
+ } else if (true) {
// complitely new set of rows
// create one row before truncating row
IScrollTableRow row = createRow((UIDL) it.next());
while(lastRendered + 1 > firstRendered)
unlinkRow(false);
-
+ fixSpacers();
addRow(row);
firstRendered = firstIndex;
this.lastRendered = firstIndex + rows - 1 ;
@@ -117,6 +118,7 @@ public class IScrollTableBody extends Panel {
addRow(createRow((UIDL) it.next()));
fixSpacers();
} else {
+ // sorted or column reordering changed
client.console.log("Bad update" + firstIndex + "/"+ rows);
}
}
diff --git a/src/com/itmill/toolkit/terminal/gwt/public/component-themes/common/css/common.css b/src/com/itmill/toolkit/terminal/gwt/public/component-themes/common/css/common.css
index e0ae7ce99e..96918358ec 100644
--- a/src/com/itmill/toolkit/terminal/gwt/public/component-themes/common/css/common.css
+++ b/src/com/itmill/toolkit/terminal/gwt/public/component-themes/common/css/common.css
@@ -23,15 +23,25 @@ select {
margin:0;
padding:0;
border:0;
- background: yellow;
}
.iscrolltable-header table td {
margin:0;
padding:0;
border:0;
+ background:yellow;
}
+.iscrolltable-header .headerCell {
+}
+.iscrolltable-header .headerCellAsc {
+ height:2px;
+ background: blue;
+}
+.iscrolltable-header .headerCellDesc {
+ height:2px;
+ background: cyan;
+}
.iscrolltable-table {
diff --git a/src/com/itmill/toolkit/ui/Table.java b/src/com/itmill/toolkit/ui/Table.java
index aefe4336c3..c1fdd0586e 100644
--- a/src/com/itmill/toolkit/ui/Table.java
+++ b/src/com/itmill/toolkit/ui/Table.java
@@ -1550,7 +1550,7 @@ public class Table extends Select implements Action.Container,
// The cursors are only shown on pageable table
if (first != 0 || getPageLength() > 0)
- target.addVariable(this, "firstvisible", first + 1);
+ target.addVariable(this, "firstvisible", first);
// Sorting
if (getContainerDataSource() instanceof Container.Sortable) {