aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/scrolltable/IScrollTable.java76
1 files changed, 54 insertions, 22 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 ef54d83106..3a78a1a94e 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
@@ -11,16 +11,14 @@ 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.Composite;
-import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.MouseListener;
import com.google.gwt.user.client.ui.ScrollListener;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
-import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
+import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
import com.itmill.toolkit.terminal.gwt.client.Client;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
@@ -52,7 +50,7 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
private boolean initializedAndAttached = false;
- private FlexTable tHead = new FlexTable();
+ private Grid tHead = new Grid(1,1);
private ScrollPanel bodyContainer = new ScrollPanel();
@@ -145,16 +143,31 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
private void updateHeader(UIDL uidl) {
if(uidl == null)
return;
+ int columnCount = uidl.getChidlCount();
+ if(rowHeaders)
+ columnCount++;
+ tHead.resizeColumns(columnCount);
+
for(Iterator it = uidl.getChildIterator();it.hasNext();) {
UIDL col = (UIDL) it.next();
String cid = col.getStringAttribute("cid");
int colIndex = getColIndexByKey(cid);
- if(colIndex > -1)
- tHead.setWidget(0, colIndex,
- new HeaderCell(cid, col.getStringAttribute("caption")));
+ if(colIndex > -1) {
+ HeaderCell c = (HeaderCell) tHead.getWidget(0, colIndex);
+ if(c != null && c.getColKey().equals(cid)) {
+ c.setText(col.getStringAttribute("caption"));
+ } else {
+ tHead.setWidget(0, colIndex,
+ new HeaderCell(cid, col.getStringAttribute("caption")));
+ }
+ }
+ }
+ if(rowHeaders) {
+ HeaderCell c = (HeaderCell) tHead.getWidget(0, 0);
+ if(c == null) {
+ tHead.setWidget(0, 0, new HeaderCell("0", ""));
+ }
}
- if(rowHeaders)
- tHead.setWidget(0, 0, new HeaderCell("0",""));
}
/**
@@ -191,10 +204,10 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
}
private void setColWidth(int colIndex, int w) {
- String cid = getColKeyByIndex(colIndex);
- ((HeaderCell) tHead.getWidget(0, colIndex)).setWidth(w);
- tHead.getCellFormatter().setWidth(0, colIndex, w + "px");
+ HeaderCell cell = (HeaderCell) tHead.getWidget(0, colIndex);
+ cell.setWidth(w);
tBody.setColWidth(colIndex, w);
+ String cid = cell.getColKey();;
columnWidths.put(cid,new Integer(w));
}
@@ -306,7 +319,7 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
*/
private void initColumnWidths() {
int cols = tHead.getCellCount(0);
- FlexCellFormatter hf = tHead.getFlexCellFormatter();
+ CellFormatter hf = tHead.getCellFormatter();
for (int i = 0; i < cols; i++) {
Element hCell = hf.getElement(0, i);
int hw = DOM.getIntAttribute(hCell, "offsetWidth");
@@ -368,7 +381,6 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
private String cid;
private boolean dragging;
private int dragStartX;
- private int dragStartY;
private int colIndex;
private int originalWidth;
@@ -379,11 +391,13 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
this.cid = colid;
// TODO move these to stylesheet
Element el = DOM.createDiv();
+ DOM.setStyleAttribute(el,"display", "block");
DOM.setStyleAttribute(el, "width", DRAG_WIDGET_WIDTH +"px");
DOM.setStyleAttribute(el,"height", "20px");
+ DOM.setStyleAttribute(el,"cssFloat", "right");
+ DOM.setStyleAttribute(el, "styleFloat", "right");
DOM.setStyleAttribute(el,"background", "brown");
- DOM.setStyleAttribute(el,"float", "right");
- DOM.setStyleAttribute(el,"cursoor", "e-resize");
+ DOM.setStyleAttribute(el,"cursor", "e-resize");
DOM.sinkEvents(el,Event.MOUSEEVENTS);
setElement(el);
}
@@ -420,28 +434,46 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll
}
}
+
+ public String getColKey() {
+ return cid;
+ }
}
- class HeaderCell extends Composite {
+ public class HeaderCell extends Composite {
private DragWidget dragWidget;
private Label text;
private HeaderCell(){};
+ public void setText(String stringAttribute) {
+ text.setText(stringAttribute);
+ }
+ public String getColKey() {
+ return dragWidget.getColKey();
+ }
public HeaderCell(String colId, String headerText) {
- this.dragWidget = new DragWidget(colId);
FlowPanel fp = new FlowPanel();
DOM.setStyleAttribute(fp.getElement(), "white-space", "nowrap");
- DOM.setStyleAttribute(fp.getElement(), "overflow", "hidden");
+
+ this.dragWidget = new DragWidget(colId);
fp.add(dragWidget);
+
text = new Label(headerText);
+ DOM.setStyleAttribute(text.getElement(), "cssFloat", "right");
+ DOM.setStyleAttribute(text.getElement(), "styleFloat", "right");
+ DOM.setStyleAttribute(text.getElement(), "overflow", "hidden");
+ DOM.setStyleAttribute(text.getElement(), "display", "inline");
+ text.setWordWrap(false);
+
fp.add(text);
+
initWidget(fp);
}
public void setWidth(int w) {
- text.setWidth((w - DragWidget.DRAG_WIDGET_WIDTH ) + "px");
- super.setWidth(w + "px");
+ text.setWidth((w - DragWidget.DRAG_WIDGET_WIDTH - 4) + "px");
+ setWidth(w + "px");
}
}
hat the function name should be `com_example_Flot`. This initializer function should initialize the JavaScript part of the component. It is called by the framework with `this` pointing to a connector wrapper providing integration to the framework. For full information about the services provided by the connector wrapper, please read the Javadoc for the `AbstractJavaScriptComponent` class. In this example, the initializer first initializes the `element` variable with a jQuery object for the DOM element of the component. Next, a state change listener is defined by assigning a function to the `onStateChange` field of the connector wrapper. This function will be called whenever the shared state is changed from the server-side code. In the state change listener, the Flot API is used to initialize a graph with the data series from the shared state into the DOM element. The format of the series property in the `FlotState` Java class has been chosen with the Flot API in mind. Flot expects an array of data series where each item is an array of data points where each data point is an array with the x value followed by the y value. This is defined in Java as `List<List<List<Double>>>` and then the framework takes care of the conversion between server-side Java values and client-side JavaScript values. `double[][][]` in Java would give the same JavaScript structure, but it was not used here as it gives less flexibility in the Java code. [source,javascript] .... window.com_example_Flot = function() { var element = $(this.getElement()); this.onStateChange = function() { $.plot(element, this.getState().series); } } .... By implementing a server-side Java class extending `AbstractJavaScriptConnector` and a client-side JavaScript connector initialization function, existing JavaScript component libraries can easily be integrated to Vaadin. The server-side code is almost similar to the code required for a component based on GWT and the client-side code is quite similar to a `ComponentConnector` implemented using GWT.