Browse Source

renamed layout interface to container, fixed paintable unregistering in table

svn changeset:2341/svn branch:trunk
tags/6.7.0.beta1
Matti Tahvonen 16 years ago
parent
commit
642dcb2da9

+ 76
- 62
src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java View File

@@ -45,17 +45,17 @@ public class ApplicationConnection implements FocusListener {
private final WidgetSet widgetSet;

private IContextMenu contextMenu = null;
private IView view = new IView();
public ApplicationConnection(WidgetSet widgetSet) {
this.widgetSet = widgetSet;
appUri = getAppUri();

if (isDebugMode()) {
console = new DebugConsole();
console = new DebugConsole();
} else {
console = new NullConsole();
console = new NullConsole();
}

makeUidlRequest("repaintAll=1");
@@ -75,17 +75,18 @@ public class ApplicationConnection implements FocusListener {
}-*/;

private native String getAppUri()/*-{
return $wnd.itmtk.appUri;
}-*/;
return $wnd.itmtk.appUri;
}-*/;

private native String getPathInfo()/*-{
return $wnd.itmtk.pathInfo;
}-*/;
return $wnd.itmtk.pathInfo;
}-*/;

private void makeUidlRequest(String requestData) {
console.log("Making UIDL Request with params: " + requestData);
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, appUri
+ "/UIDL" + getPathInfo() + "?requestId=" + (Math.random()) + "&" + requestData);
+ "/UIDL" + getPathInfo() + "?requestId=" + (Math.random())
+ "&" + requestData);
try {
rb.sendRequest(requestData, new RequestCallback() {
public void onError(Request request, Throwable exception) {
@@ -120,29 +121,29 @@ public class ApplicationConnection implements FocusListener {
return;
}
// Handle redirect
JSONObject redirect = (JSONObject) ((JSONObject) json)
.get("redirect");
JSONObject redirect = (JSONObject) ((JSONObject) json).get("redirect");
if (redirect != null) {
JSONString url = (JSONString)redirect.get("url");
if (url!=null) {
JSONString url = (JSONString) redirect.get("url");
if (url != null) {
console.log("redirecting to " + url.stringValue());
redirect(url.stringValue());
return;
}
}
// Store resources
JSONObject resources = (JSONObject) ((JSONObject) json)
.get("resources");
for (Iterator i = resources.keySet().iterator(); i.hasNext();) {
String key = (String) i.next();
resourcesMap.put(key, ((JSONString)resources.get(key)).stringValue());
resourcesMap.put(key, ((JSONString) resources.get(key))
.stringValue());
}
// Store locale data
if(((JSONObject)json).containsKey("locales")) {
if (((JSONObject) json).containsKey("locales")) {
JSONArray l = (JSONArray) ((JSONObject) json).get("locales");
for(int i=0; i < l.size(); i++)
for (int i = 0; i < l.size(); i++)
LocaleService.addLocale((JSONObject) l.get(i));
}

@@ -175,10 +176,10 @@ public class ApplicationConnection implements FocusListener {
e.printStackTrace();
}
}
if(((JSONObject) json).containsKey("meta")) {
if (((JSONObject) json).containsKey("meta")) {
JSONObject meta = ((JSONObject) json).get("meta").isObject();
if(meta.containsKey("focus")) {
if (meta.containsKey("focus")) {
String focusPid = meta.get("focus").isString().stringValue();
Paintable toBeFocused = this.getPaintable(focusPid);
if (toBeFocused instanceof HasFocus) {
@@ -187,43 +188,51 @@ public class ApplicationConnection implements FocusListener {
}
}
}
long prosessingTime = (new Date().getTime()) - start.getTime();
console.log(" Processing time was " + String.valueOf(prosessingTime)
+ "ms for " + jsonText.length() + " characters of JSON");
console.log("Referenced paintables: " + idToPaintable.size());

}
// Redirect browser
private static native void redirect(String url)/*-{
$wnd.location = url;
}-*/;

// Redirect browser
private static native void redirect(String url)/*-{
$wnd.location = url;
}-*/;

public void registerPaintable(String id, Paintable paintable) {
idToPaintable.put(id, paintable);
paintableToId.put(paintable, id);
}
public void unregisterPaintable(Paintable p) {
idToPaintable.remove(paintableToId.get(p));
paintableToId.remove(p);
if (p instanceof HasWidgets) {
HasWidgets container = (HasWidgets) p;
Iterator it = container.iterator();
while(it.hasNext()) {
Widget w = (Widget) it.next();
if (w instanceof Paintable) {
this.unregisterPaintable((Paintable) w);
}
}
unregisterChildPaintables((HasWidgets) p);
}
}

public void unregisterChildPaintables(HasWidgets container) {
Iterator it = container.iterator();
while(it.hasNext()) {
Widget w = (Widget) it.next();
if (w instanceof Paintable) {
this.unregisterPaintable((Paintable) w);
}
if (w instanceof HasWidgets) {
unregisterChildPaintables((HasWidgets) w);
}
}
}

/**
* Returns Paintable element by its id
* @param id Paintable ID
*
* @param id
* Paintable ID
*/
public Paintable getPaintable(String id) {
return (Paintable) idToPaintable.get(id);
@@ -249,7 +258,8 @@ public class ApplicationConnection implements FocusListener {

req.append("changes=");
for (int i = 0; i < pendingVariables.size(); i++) {
if (i>0) req.append("\u0001");
if (i > 0)
req.append("\u0001");
req.append(pendingVariables.get(i));
}

@@ -269,22 +279,26 @@ public class ApplicationConnection implements FocusListener {

public void updateVariable(String paintableId, String variableName,
int newValue, boolean immediate) {
addVariableToQueue(paintableId, variableName, "" + newValue, immediate, 'i');
addVariableToQueue(paintableId, variableName, "" + newValue, immediate,
'i');
}
public void updateVariable(String paintableId, String variableName,
long newValue, boolean immediate) {
addVariableToQueue(paintableId, variableName, "" + newValue, immediate, 'l');
addVariableToQueue(paintableId, variableName, "" + newValue, immediate,
'l');
}
public void updateVariable(String paintableId, String variableName,
float newValue, boolean immediate) {
addVariableToQueue(paintableId, variableName, "" + newValue, immediate, 'f');
addVariableToQueue(paintableId, variableName, "" + newValue, immediate,
'f');
}
public void updateVariable(String paintableId, String variableName,
double newValue, boolean immediate) {
addVariableToQueue(paintableId, variableName, "" + newValue, immediate, 'd');
addVariableToQueue(paintableId, variableName, "" + newValue, immediate,
'd');
}

public void updateVariable(String paintableId, String variableName,
@@ -301,16 +315,16 @@ public class ApplicationConnection implements FocusListener {
buf.append(",");
buf.append(escapeString(values[i].toString()));
}
addVariableToQueue(paintableId, variableName,
buf.toString(), immediate, 'a');
addVariableToQueue(paintableId, variableName, buf.toString(),
immediate, 'a');
}

public static Layout getParentLayout(Widget component) {
public static Container getParentLayout(Widget component) {
Widget parent = component.getParent();
while (parent != null && !(parent instanceof Layout))
while (parent != null && !(parent instanceof Container))
parent = parent.getParent();
if (parent != null && ((Layout) parent).hasChildComponent(component))
return (Layout) parent;
if (parent != null && ((Container) parent).hasChildComponent(component))
return (Container) parent;
return null;
}

@@ -356,7 +370,7 @@ public class ApplicationConnection implements FocusListener {

// Switch to correct implementation if needed
if (!widgetSet.isCorrectImplementation(component, uidl)) {
Layout parent = getParentLayout(component);
Container parent = getParentLayout(component);
if (parent != null) {
Widget w = widgetSet.createWidget(uidl);
parent.replaceChildComponent(component, w);
@@ -369,7 +383,7 @@ public class ApplicationConnection implements FocusListener {
// Set captions
// TODO Manage Error messages
if (manageCaption) {
Layout parent = getParentLayout(component);
Container parent = getParentLayout(component);
if (parent != null)
parent.updateCaption((Paintable) component, uidl);
}
@@ -386,7 +400,7 @@ public class ApplicationConnection implements FocusListener {
boolean enabled = true;
if (uidl.hasAttribute("disabled"))
enabled = !uidl.getBooleanAttribute("disabled");
if(!enabled)
if (!enabled)
component.addStyleName("i-disabled");
else
component.removeStyleName("i-disabled");
@@ -395,9 +409,9 @@ public class ApplicationConnection implements FocusListener {
component.setVisible(visible);
if (!visible)
return true;
// add additional styles as css classes
if(uidl.hasAttribute("style"))
if (uidl.hasAttribute("style"))
component.addStyleName(uidl.getStringAttribute("style"));

return false;
@@ -423,18 +437,18 @@ public class ApplicationConnection implements FocusListener {
registerPaintable(id, (Paintable) w);
return w;
}
public String getResource(String name) {
return (String) resourcesMap.get(name);
}
/**
* Singleton method to get instance of app's context menu.
*
* @return IContextMenu object
*/
public IContextMenu getContextMenu() {
if(contextMenu == null) {
if (contextMenu == null) {
contextMenu = new IContextMenu();
}
return contextMenu;
@@ -442,11 +456,11 @@ public class ApplicationConnection implements FocusListener {

public void onFocus(Widget sender) {
// TODO Auto-generated method stub
}

public void onLostFocus(Widget sender) {
// TODO Auto-generated method stub
}
}

src/com/itmill/toolkit/terminal/gwt/client/Layout.java → src/com/itmill/toolkit/terminal/gwt/client/Container.java View File

@@ -2,15 +2,15 @@ package com.itmill.toolkit.terminal.gwt.client;

import com.google.gwt.user.client.ui.Widget;

public interface Layout extends Paintable {
public interface Container extends Paintable {

/**
* Replace child of this layout with another component.
*
* Each layout must be able to switch children. To to this, one must just
* give references to a current and new child. Note that the Layout is not
* responsible for registering paintable into ApplicationConnection, but it is responsible
* is for unregistering it.
* responsible for registering Paintable into ApplicationConnection, but it
* is responsible is for unregistering it.
*
* @param oldComponent
* Child to be replaced
@@ -44,5 +44,5 @@ public interface Layout extends Paintable {
* UIDL of the child component.
*/
void updateCaption(Paintable component, UIDL uidl);
}

+ 2
- 2
src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java View File

@@ -10,7 +10,7 @@ import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Caption;
import com.itmill.toolkit.terminal.gwt.client.CaptionWrapper;
import com.itmill.toolkit.terminal.gwt.client.Layout;
import com.itmill.toolkit.terminal.gwt.client.Container;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;

@@ -20,7 +20,7 @@ import com.itmill.toolkit.terminal.gwt.client.UIDL;
* @author IT Mill
*
*/
public class ICustomLayout extends ComplexPanel implements Paintable, Layout {
public class ICustomLayout extends ComplexPanel implements Paintable, Container {

/** Location-name to containing element in DOM map */
private HashMap locationToElement = new HashMap();

+ 3
- 3
src/com/itmill/toolkit/terminal/gwt/client/ui/IForm.java View File

@@ -3,7 +3,7 @@ package com.itmill.toolkit.terminal.gwt.client.ui;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Layout;
import com.itmill.toolkit.terminal.gwt.client.Container;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
@@ -11,7 +11,7 @@ public class IForm extends SimplePanel implements Paintable {
public static final String CLASSNAME = "i-form";
private Layout lo;
private Container lo;
private ApplicationConnection client;
@@ -24,7 +24,7 @@ public class IForm extends SimplePanel implements Paintable {
this.client = client;
UIDL layoutUidl = uidl.getChildUIDL(0);
if(lo == null) {
lo = (Layout) client.getWidget(layoutUidl);
lo = (Container) client.getWidget(layoutUidl);
setWidget((Widget) lo);
}
lo.updateFromUIDL(layoutUidl, client);

+ 2
- 2
src/com/itmill/toolkit/terminal/gwt/client/ui/IFormLayout.java View File

@@ -7,14 +7,14 @@ import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Caption;
import com.itmill.toolkit.terminal.gwt.client.Layout;
import com.itmill.toolkit.terminal.gwt.client.Container;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;

/**
* Two col Layout that places caption on left col and field on right col
*/
public class IFormLayout extends FlexTable implements Layout {
public class IFormLayout extends FlexTable implements Container {
HashMap componentToCaption = new HashMap();
private ApplicationConnection client;

+ 2
- 2
src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java View File

@@ -8,11 +8,11 @@ import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.CaptionWrapper;
import com.itmill.toolkit.terminal.gwt.client.Layout;
import com.itmill.toolkit.terminal.gwt.client.Container;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;

public class IGridLayout extends FlexTable implements Paintable, Layout {
public class IGridLayout extends FlexTable implements Paintable, Container {
/** Widget to captionwrapper map */
private HashMap widgetToCaptionWrapper = new HashMap();

+ 2
- 2
src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java View File

@@ -11,7 +11,7 @@ import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Caption;
import com.itmill.toolkit.terminal.gwt.client.Layout;
import com.itmill.toolkit.terminal.gwt.client.Container;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;

@@ -20,7 +20,7 @@ import com.itmill.toolkit.terminal.gwt.client.UIDL;
* Use either vertical or horizontal subclass.
* @author IT Mill Ltd
*/
public abstract class IOrderedLayout extends ComplexPanel implements Layout {
public abstract class IOrderedLayout extends ComplexPanel implements Container {
public static final String CLASSNAME = "i-orderedlayout";


+ 23
- 5
src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java View File

@@ -36,9 +36,9 @@ import com.itmill.toolkit.terminal.gwt.client.ui.IScrollTable.IScrollTableBody.I
* reordering and hiding columns.
*
* ScrollPanel contains IScrollTableBody object which handles content. To save
* some bandwidth and to improve clients responsiviness with loads of data, in
* IScrollTableBody all rows are not necessarely rendered. There are "spacer" in
* IScrollTableBody to use the exact same space as unrendered rows would use.
* some bandwidth and to improve clients responsiveness with loads of data, in
* IScrollTableBody all rows are not necessary rendered. There are "spacer" in
* IScrollTableBody to use the exact same space as non-rendered rows would use.
* This way we can use seamlessly traditional scrollbars and scrolling to fetch
* more rows instead of "paging".
*
@@ -49,7 +49,7 @@ import com.itmill.toolkit.terminal.gwt.client.ui.IScrollTable.IScrollTableBody.I
*
* TODO implement unregistering for child componts in Cells
*/
public class IScrollTable extends Composite implements Paintable, ITable,
public class IScrollTable extends Composite implements ITable,
ScrollListener {

public static final String CLASSNAME = "i-table";
@@ -109,13 +109,14 @@ public class IScrollTable extends Composite implements Paintable, ITable,
private String[] visibleColOrder;
private boolean initialContentReceived = false;
private Element scrollPositionElement;
private FlowPanel panel;

public IScrollTable() {

bodyContainer.addScrollListener(this);
bodyContainer.setStyleName(CLASSNAME + "-body");

FlowPanel panel = new FlowPanel();
panel = new FlowPanel();
panel.setStyleName(CLASSNAME);
panel.add(tHead);
panel.add(bodyContainer);
@@ -1589,6 +1590,7 @@ public class IScrollTable extends Composite implements Paintable, ITable,
}
IScrollTableRow toBeRemoved = (IScrollTableRow) renderedRows
.get(index);
client.unregisterChildPaintables(toBeRemoved);
DOM.removeChild(tBody, toBeRemoved.getElement());
this.orphan(toBeRemoved);
renderedRows.remove(index);
@@ -1885,4 +1887,20 @@ public class IScrollTable extends Composite implements Paintable, ITable,
selectedRowKeys.clear();

}

public void add(Widget w) {
throw new UnsupportedOperationException("ITable can contain only rows created by itself.");
}

public void clear() {
panel.clear();
}

public Iterator iterator() {
return panel.iterator();
}

public boolean remove(Widget w) {
return panel.remove(w);
}
}

+ 4
- 2
src/com/itmill/toolkit/terminal/gwt/client/ui/ITable.java View File

@@ -1,8 +1,10 @@
package com.itmill.toolkit.terminal.gwt.client.ui;

public interface ITable {
import com.google.gwt.user.client.ui.HasWidgets;
import com.itmill.toolkit.terminal.gwt.client.Paintable;

public interface ITable extends HasWidgets, Paintable {
final int SELECT_MODE_NONE = 0;
final int SELECT_MODE_SINGLE = 1;
final int SELECT_MODE_MULTI = 2;

}

+ 132
- 103
src/com/itmill/toolkit/terminal/gwt/client/ui/ITablePaging.java View File

@@ -23,50 +23,54 @@ import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;

public class ITablePaging extends Composite implements ITable, Paintable, ClickListener {
/**
* TODO make this work (just an early prototype). We may want to have paging
* style table which will be much lighter than IScrollTable is.
*/
public class ITablePaging extends Composite implements ITable, Paintable,
ClickListener {

private Grid tBody = new Grid();
private Button nextPage = new Button("&gt;");
private Button prevPage = new Button("&lt;");
private Button firstPage = new Button("&lt;&lt;");
private Button lastPage = new Button("&gt;&gt;");

private int pageLength = 15;
private boolean rowHeaders = false;
private Map columnOrder = new HashMap();
private ApplicationConnection client;
private String id;
private boolean immediate = false;
private int selectMode = ITable.SELECT_MODE_NONE;
private Vector selectedRowKeys = new Vector();
private int totalRows;

private HashMap columnWidths = new HashMap();
private HashMap visibleColumns = new HashMap();
private int rows;

private int firstRow;
private boolean sortAscending = true;
private HorizontalPanel pager;
public HashMap rowKeysToTableRows = new HashMap();
public ITablePaging() {

tBody.setStyleName("itable-tbody");
VerticalPanel panel = new VerticalPanel();
pager = new HorizontalPanel();
pager.add(firstPage);
firstPage.addClickListener(this);
@@ -79,7 +83,7 @@ public class ITablePaging extends Composite implements ITable, Paintable, ClickL

panel.add(pager);
panel.add(tBody);
initWidget(panel);
}

@@ -94,56 +98,56 @@ public class ITablePaging extends Composite implements ITable, Paintable, ClickL
this.pageLength = uidl.getIntAttribute("pagelength");
this.firstRow = uidl.getIntAttribute("firstrow");
this.rows = uidl.getIntAttribute("rows");
if(uidl.hasAttribute("selectmode")) {
if(uidl.getStringAttribute("selectmode").equals("multi"))
if (uidl.hasAttribute("selectmode")) {
if (uidl.getStringAttribute("selectmode").equals("multi"))
selectMode = ITable.SELECT_MODE_MULTI;
else
selectMode = ITable.SELECT_MODE_SINGLE;
if(uidl.hasAttribute("selected")) {
if (uidl.hasAttribute("selected")) {
Set selectedKeys = uidl.getStringArrayVariableAsSet("selected");
selectedRowKeys.clear();
for(Iterator it = selectedKeys.iterator();it.hasNext();)
for (Iterator it = selectedKeys.iterator(); it.hasNext();)
selectedRowKeys.add((String) it.next());
}
}
if(uidl.hasVariable("sortascending"))
if (uidl.hasVariable("sortascending"))
this.sortAscending = uidl.getBooleanVariable("sortascending");

if(uidl.hasAttribute("rowheaders"))
if (uidl.hasAttribute("rowheaders"))
rowHeaders = true;
UIDL rowData = null;
UIDL visibleColumns = null;
for(Iterator it = uidl.getChildIterator(); it.hasNext();) {
for (Iterator it = uidl.getChildIterator(); it.hasNext();) {
UIDL c = (UIDL) it.next();
if(c.getTag().equals("rows"))
if (c.getTag().equals("rows"))
rowData = c;
else if(c.getTag().equals("actions"))
else if (c.getTag().equals("actions"))
updateActionMap(c);
else if(c.getTag().equals("visiblecolumns"))
else if (c.getTag().equals("visiblecolumns"))
visibleColumns = c;
}
tBody.resize(rows+1, uidl.getIntAttribute("cols") + (rowHeaders ? 1 : 0 ));
tBody.resize(rows + 1, uidl.getIntAttribute("cols")
+ (rowHeaders ? 1 : 0));
updateHeader(visibleColumns);
updateBody(rowData);
updatePager();
}
private void updateHeader(UIDL c) {
Iterator it = c.getChildIterator();
visibleColumns.clear();
int colIndex = (rowHeaders ? 1 : 0);
while(it.hasNext()) {
while (it.hasNext()) {
UIDL col = (UIDL) it.next();
String cid = col.getStringAttribute("cid");
if(!col.hasAttribute("collapsed")) {
tBody.setWidget(0, colIndex,
new HeaderCell(cid,
col.getStringAttribute("caption")));
if (!col.hasAttribute("collapsed")) {
tBody.setWidget(0, colIndex, new HeaderCell(cid, col
.getStringAttribute("caption")));

}
colIndex++;
@@ -152,44 +156,43 @@ public class ITablePaging extends Composite implements ITable, Paintable, ClickL

private void updateActionMap(UIDL c) {
// TODO Auto-generated method stub
}

/**
* Updates row data from uidl. UpdateFromUIDL delegates updating
* tBody to this method.
* Updates row data from uidl. UpdateFromUIDL delegates updating tBody to
* this method.
*
* Updates may be to different part of tBody, depending on update type.
* It can be initial row data, scroll up, scroll down...
* Updates may be to different part of tBody, depending on update type. It
* can be initial row data, scroll up, scroll down...
*
* @param uidl which contains row data
* @param uidl
* which contains row data
*/
private void updateBody(UIDL uidl) {
Iterator it = uidl.getChildIterator();
int curRowIndex = 1;
while(it.hasNext()){
while (it.hasNext()) {
UIDL rowUidl = (UIDL) it.next();
TableRow row = new TableRow(
curRowIndex,
String.valueOf(rowUidl.getIntAttribute("key")),
rowUidl.hasAttribute("selected"));
TableRow row = new TableRow(curRowIndex, String.valueOf(rowUidl
.getIntAttribute("key")), rowUidl.hasAttribute("selected"));
int colIndex = 0;
if(rowHeaders) {
tBody.setWidget(curRowIndex, colIndex,
new BodyCell(row, rowUidl.getStringAttribute("caption")));
if (rowHeaders) {
tBody.setWidget(curRowIndex, colIndex, new BodyCell(row,
rowUidl.getStringAttribute("caption")));
colIndex++;
}
Iterator cells = rowUidl.getChildIterator();
while(cells.hasNext()) {
while (cells.hasNext()) {
Object cell = cells.next();
if (cell instanceof String) {
tBody.setWidget(curRowIndex, colIndex,
new BodyCell(row, (String) cell));
tBody.setWidget(curRowIndex, colIndex, new BodyCell(row,
(String) cell));
} else {
Widget cellContent = client.getWidget((UIDL) cell);
BodyCell bodyCell = new BodyCell(row);
bodyCell.setWidget(cellContent);
Widget cellContent = client.getWidget((UIDL) cell);
BodyCell bodyCell = new BodyCell(row);
bodyCell.setWidget(cellContent);
tBody.setWidget(curRowIndex, colIndex, bodyCell);
}
colIndex++;
@@ -197,20 +200,20 @@ public class ITablePaging extends Composite implements ITable, Paintable, ClickL
curRowIndex++;
}
}
private void updatePager() {
if(pageLength == 0) {
if (pageLength == 0) {
pager.setVisible(false);
return;
}
if(isFirstPage()) {
if (isFirstPage()) {
firstPage.setEnabled(false);
prevPage.setEnabled(false);
} else {
firstPage.setEnabled(true);
prevPage.setEnabled(true);
}
if(hasNextPage()) {
if (hasNextPage()) {
nextPage.setEnabled(true);
lastPage.setEnabled(true);
} else {
@@ -221,41 +224,44 @@ public class ITablePaging extends Composite implements ITable, Paintable, ClickL
}

private boolean hasNextPage() {
if(firstRow + rows + 1 > totalRows)
if (firstRow + rows + 1 > totalRows)
return false;
return true;
}

private boolean isFirstPage() {
if(firstRow == 0)
if (firstRow == 0)
return true;
return false;
}

public void onClick(Widget sender) {
if (sender instanceof Button) {
if(sender == firstPage)
if (sender == firstPage)
client.updateVariable(this.id, "firstvisible", 0, true);
else if(sender == nextPage)
client.updateVariable(this.id, "firstvisible", firstRow + pageLength, true);
else if(sender == prevPage) {
else if (sender == nextPage)
client.updateVariable(this.id, "firstvisible", firstRow
+ pageLength, true);
else if (sender == prevPage) {
int newFirst = firstRow - pageLength;
if(newFirst < 0)
if (newFirst < 0)
newFirst = 0;
client.updateVariable(this.id, "firstvisible", newFirst, true);
} else if (sender == lastPage) {
client.updateVariable(this.id, "firstvisible", totalRows - pageLength, true);
client.updateVariable(this.id, "firstvisible", totalRows
- pageLength, true);
}
}
if (sender instanceof HeaderCell) {
HeaderCell hCell = (HeaderCell) sender;
client.updateVariable(this.id, "sortcolumn", hCell.getCid(), false);
client.updateVariable(this.id, "sortascending", ( sortAscending ? false : true ), true);
client.updateVariable(this.id, "sortascending",
(sortAscending ? false : true), true);
}
}

private class HeaderCell extends HTML {
private String cid;

public String getCid() {
@@ -276,22 +282,22 @@ public class ITablePaging extends Composite implements ITable, Paintable, ClickL
DOM.setStyleAttribute(getElement(), "font-weight", "bold");
}
}
/**
* Abstraction of table cell content. In needs to know on which row it
* is in case of context click.
* Abstraction of table cell content. In needs to know on which row it is in
* case of context click.
*
* @author mattitahvonen
*/
public class BodyCell extends SimplePanel {
private TableRow row;
public BodyCell(TableRow row) {
super();
this.sinkEvents(Event.BUTTON_LEFT | Event.BUTTON_RIGHT);
this.row = row;
}
public BodyCell(TableRow row2, String textContent) {
super();
this.sinkEvents(Event.BUTTON_LEFT | Event.BUTTON_RIGHT);
@@ -308,7 +314,7 @@ public class ITablePaging extends Composite implements ITable, Paintable, ClickL
DOM.eventCancelBubble(event, true);
break;
case Event.BUTTON_LEFT:
if(ITablePaging.this.selectMode > ITable.SELECT_MODE_NONE)
if (ITablePaging.this.selectMode > ITable.SELECT_MODE_NONE)
row.toggleSelected();
break;
default:
@@ -317,9 +323,9 @@ public class ITablePaging extends Composite implements ITable, Paintable, ClickL
super.onBrowserEvent(event);
}
}
private class TableRow {
private String key;
private int rowIndex;
private boolean selected = false;
@@ -332,50 +338,53 @@ public class ITablePaging extends Composite implements ITable, Paintable, ClickL
}

/**
* This method is used to set row status. Does not change value on server.
* This method is used to set row status. Does not change value on
* server.
*
* @param selected
*/
public void setSelected(boolean sel) {
this.selected = sel;
if(selected) {
if (selected) {
selectedRowKeys.add(key);
DOM.setStyleAttribute(
ITablePaging.this.tBody.getRowFormatter().getElement(rowIndex),
"background", "yellow");
DOM.setStyleAttribute(ITablePaging.this.tBody.getRowFormatter()
.getElement(rowIndex), "background", "yellow");

} else {
selectedRowKeys.remove(key);
DOM.setStyleAttribute(
ITablePaging.this.tBody.getRowFormatter().getElement(rowIndex),
"background", "transparent");
DOM.setStyleAttribute(ITablePaging.this.tBody.getRowFormatter()
.getElement(rowIndex), "background", "transparent");
}
}

public void setContextMenuOptions(HashMap options) {
}
/**
* Toggles rows select state. Also updates state to server according to tables immediate flag.
*
* Toggles rows select state. Also updates state to server according to
* tables immediate flag.
*
*/
public void toggleSelected() {
if(selected) {
if (selected) {
setSelected(false);
} else {
if(ITablePaging.this.selectMode == ITable.SELECT_MODE_SINGLE) {
if (ITablePaging.this.selectMode == ITable.SELECT_MODE_SINGLE) {
ITablePaging.this.deselectAll();
}
setSelected(true);
}
client.updateVariable(id, "selected", selectedRowKeys.toArray(), immediate);
client.updateVariable(id, "selected", selectedRowKeys.toArray(),
immediate);
}
/**
* Shows context menu for this row.
*
* @param event Event which triggered context menu. Correct place for context menu can be determined with it.
* @param event
* Event which triggered context menu. Correct place for
* context menu can be determined with it.
*/
public void showContextMenu(Event event) {
System.out.println("TODO: Show context menu");
@@ -386,10 +395,30 @@ public class ITablePaging extends Composite implements ITable, Paintable, ClickL
Object[] keys = selectedRowKeys.toArray();
for (int i = 0; i < keys.length; i++) {
TableRow tableRow = (TableRow) rowKeysToTableRows.get(keys[i]);
if(tableRow != null)
if (tableRow != null)
tableRow.setSelected(false);
}
// still ensure all selects are removed from
// still ensure all selects are removed from
selectedRowKeys.clear();
}

public void add(Widget w) {
// TODO Auto-generated method stub

}

public void clear() {
// TODO Auto-generated method stub

}

public Iterator iterator() {
// TODO Auto-generated method stub
return null;
}

public boolean remove(Widget w) {
// TODO Auto-generated method stub
return false;
}
}

Loading…
Cancel
Save