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");
}-*/;
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) {
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));
}
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) {
}
}
}
-
+
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);
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));
}
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,
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;
}
// 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);
// Set captions
// TODO Manage Error messages
if (manageCaption) {
- Layout parent = getParentLayout(component);
+ Container parent = getParentLayout(component);
if (parent != null)
parent.updateCaption((Paintable) component, uidl);
}
boolean enabled = true;
if (uidl.hasAttribute("disabled"))
enabled = !uidl.getBooleanAttribute("disabled");
- if(!enabled)
+ if (!enabled)
component.addStyleName("i-disabled");
else
component.removeStyleName("i-disabled");
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;
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;
public void onFocus(Widget sender) {
// TODO Auto-generated method stub
-
+
}
public void onLostFocus(Widget sender) {
// TODO Auto-generated method stub
-
+
}
}
--- /dev/null
+package com.itmill.toolkit.terminal.gwt.client;
+
+import com.google.gwt.user.client.ui.Widget;
+
+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.
+ *
+ * @param oldComponent
+ * Child to be replaced
+ * @param newComponent
+ * Child that replaces the oldComponent
+ */
+ void replaceChildComponent(Widget oldComponent, Widget newComponent);
+
+ /**
+ * Is a given component child of this layout.
+ *
+ * @param component
+ * Component to test.
+ * @return true iff component is a child of this layout.
+ */
+ boolean hasChildComponent(Widget component);
+
+ /**
+ * Update child components caption, description and error message.
+ *
+ * <p>
+ * Each component is responsible for maintaining its caption, description
+ * and error message. In most cases components doesn't want to do that and
+ * those elements reside outside of the component. Because of this layouts
+ * must provide service for it's childen to show those elements for them.
+ * </p>
+ *
+ * @param component
+ * Child component for which service is requested.
+ * @param uidl
+ * UIDL of the child component.
+ */
+ void updateCaption(Paintable component, UIDL uidl);
+
+}
+++ /dev/null
-package com.itmill.toolkit.terminal.gwt.client;
-
-import com.google.gwt.user.client.ui.Widget;
-
-public interface Layout 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.
- *
- * @param oldComponent
- * Child to be replaced
- * @param newComponent
- * Child that replaces the oldComponent
- */
- void replaceChildComponent(Widget oldComponent, Widget newComponent);
-
- /**
- * Is a given component child of this layout.
- *
- * @param component
- * Component to test.
- * @return true iff component is a child of this layout.
- */
- boolean hasChildComponent(Widget component);
-
- /**
- * Update child components caption, description and error message.
- *
- * <p>
- * Each component is responsible for maintaining its caption, description
- * and error message. In most cases components doesn't want to do that and
- * those elements reside outside of the component. Because of this layouts
- * must provide service for it's childen to show those elements for them.
- * </p>
- *
- * @param component
- * Child component for which service is requested.
- * @param uidl
- * UIDL of the child component.
- */
- void updateCaption(Paintable component, UIDL uidl);
-
-}
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;
* @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();
import com.google.gwt.user.client.ui.SimplePanel;\r
import com.google.gwt.user.client.ui.Widget;\r
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;\r
-import com.itmill.toolkit.terminal.gwt.client.Layout;\r
+import com.itmill.toolkit.terminal.gwt.client.Container;\r
import com.itmill.toolkit.terminal.gwt.client.Paintable;\r
import com.itmill.toolkit.terminal.gwt.client.UIDL;\r
\r
\r
public static final String CLASSNAME = "i-form";\r
\r
- private Layout lo;\r
+ private Container lo;\r
\r
private ApplicationConnection client;\r
\r
this.client = client;\r
UIDL layoutUidl = uidl.getChildUIDL(0);\r
if(lo == null) {\r
- lo = (Layout) client.getWidget(layoutUidl);\r
+ lo = (Container) client.getWidget(layoutUidl);\r
setWidget((Widget) lo);\r
}\r
lo.updateFromUIDL(layoutUidl, client);\r
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;
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();
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;
* 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";
* 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".
*
*
* 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";
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);
}
IScrollTableRow toBeRemoved = (IScrollTableRow) renderedRows
.get(index);
+ client.unregisterChildPaintables(toBeRemoved);
DOM.removeChild(tBody, toBeRemoved.getElement());
this.orphan(toBeRemoved);
renderedRows.remove(index);
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);
+ }
}
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;
-
}
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(">");
private Button prevPage = new Button("<");
private Button firstPage = new Button("<<");
private Button lastPage = new Button(">>");
-
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);
panel.add(pager);
panel.add(tBody);
-
+
initWidget(panel);
}
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++;
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++;
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 {
}
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() {
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);
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:
super.onBrowserEvent(event);
}
}
-
+
private class TableRow {
-
+
private String key;
private int rowIndex;
private boolean selected = false;
}
/**
- * 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");
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;
+ }
}