Permalink
Browse files

[InMethod Grid] simplify AppendableDataProviderAdapter & add defaults…

…(via prototype) to reduce Javascript errors

dom.js and script.js - corrections to reduce Property is Undefined errors under strict checking.
DataGrid#insertRow() - increment row counter on insert
AppendableDataProviderAdapter
 - remove newItemCount - use size of the actual object instead.
 - #query - result.setTotalCount() correction
Minor Code formatting
Minor Comment formatting
Added a couple TODO notes
miscl javadoc corrections
  • Loading branch information...
1 parent 51136dd commit 608929cbc17d9ba5ebdc2f62772c5ba90be60b02 =Tom B committed Jul 18, 2012
Showing with 180 additions and 158 deletions.
  1. +9 −12 ...thod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/AppendableDataProviderAdapter.java
  2. +0 −2 ...ent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/column/CheckBoxColumn.java
  3. +8 −5 ...nt/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/common/AbstractGridRow.java
  4. +4 −4 ...method-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/common/AbstractPageableView.java
  5. +0 −2 ...rent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/common/ColumnsHeader.java
  6. +4 −6 ...ethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/common/ColumnsHeaderRepeater.java
  7. +3 −7 ...hod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/common/SortableHeaderLinkPanel.java
  8. +64 −42 jdk-1.6-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/common/res/dom.js
  9. +83 −65 ....6-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/common/res/script.js
  10. +1 −1 ...-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/datagrid/DataGrid.java
  11. +0 −2 ...thod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/toolbar/AbstractHeaderToolbar.java
  12. +0 −1 ...t/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/toolbar/AbstractToolbar.java
  13. +0 −1 ...hod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/toolbar/paging/PagingNavigator.java
  14. +0 −1 ...ethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/toolbar/paging/PagingToolbar.java
  15. +4 −5 jdk-1.6-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/icon/IconImage.java
  16. +0 −2 jdk-1.6-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/icon/PackageIcon.java
@@ -15,37 +15,33 @@
public class AppendableDataProviderAdapter<T>
extends DataProviderAdapter<T> implements IAppendableDataSource<T>
{
- public AppendableDataProviderAdapter(IDataProvider<T> dataProvider)
- { super(dataProvider); }
-
- //do I need this?
- private long _newItemCount = 0;
private long appendIndex;
private List items = null;
+ public AppendableDataProviderAdapter(IDataProvider<T> dataProvider)
+ { super(dataProvider); }
+
public void insertRow(long index, T item)
{
- ++_newItemCount;
if (null == items) { items = new ArrayList(); }
items.add(item);
appendIndex = index;
}
public void deleteRow(long index, T item)
{
- if ( null != items && _newItemCount > 0)
- { if (items.remove(item)){ --_newItemCount; } }
+ if ( null != items && items.size() > 0 )
+ { items.remove(item); }
}
/** {@inheritDoc} */
public void query(IQuery query, IQueryResult<T> result)
{
super.query(query, result);
- if ( _newItemCount > 0 )
+ if ( null != items && items.size() > 0 )
{
- result.setTotalCount(dataProvider.size() + _newItemCount);
//TODO: THERE has GOT to be a better way to handle this
- long longSize = dataProvider.size() + _newItemCount;
+ long longSize = dataProvider.size() + items.size();
int intSize = 0;
if ( longSize > Integer.MAX_VALUE ) { intSize = Integer.MAX_VALUE; }
//TODO: should an error be thrown instead?
@@ -57,11 +53,12 @@ public void query(IQuery query, IQueryResult<T> result)
//for(Object item : items ) { AllItems.add(item); }
//AllItems.addAll(items);
- try { AllItems.addAll((int)appendIndex,items); }
+ try { AllItems.addAll((int)appendIndex, items); }
catch( Exception iob ) //will catch IndexOutOfBounds or ClassCast
{ AllItems.addAll(items); } //add failed for index, add to end
result.setItems(AllItems.iterator());
+ result.setTotalCount(longSize);
}
}
@@ -211,7 +211,6 @@ private HeadPanel(String id)
add(new HeadCheckBoxPanel("checkbox")
{
-
private static final long serialVersionUID = 1L;
@Override
@@ -227,7 +226,6 @@ public boolean isVisible()
// and also for displaying the tooltip
add(new WebMarkupContainer("space")
{
-
private static final long serialVersionUID = 1L;
@Override
@@ -211,9 +211,13 @@ public void onComponentTag(Component component, ComponentTag tag)
{
CharSequence klass = tag.getAttribute("class");
if (klass == null)
- klass = "";
+ {
+ klass = "";
+ }
if (klass.length() > 0)
- klass = klass + " ";
+ {
+ klass = klass + " ";
+ }
klass = klass + getInnerDivClass(column);
tag.put("class", klass);
}
@@ -226,7 +230,7 @@ public boolean isTemporary(Component c)
{
return true;
}
- };
+ }
/**
* Returns the css class of cell component (which is attached to the first div element inside
@@ -264,8 +268,7 @@ protected void onRender()
hide = renderOpenTag(column, i, columns.size(), response, hide);
if (column.isLightWeight(getDefaultRowModel()))
- {
- // for lightweight columns get the renderable instance and render it
+ { // for lightweight columns get the renderable instance and render it
IRenderable<I> renderable = column.newCell(getDefaultRowModel());
if (renderable == null)
{
@@ -173,9 +173,9 @@ public void setCurrentPage(long page)
private long maxFirstItemReached;
/**
- * The actual count of items. This is set by either passing actual count of items to
- * {@link IQueryResult#setTotalCount(int)}, or by passing the {@link IQueryResult#NO_MORE_ITEMS}
- * constant as item count.
+ * The actual count of items. This is set by either passing actual count of items
+ * to {@link IQueryResult#setTotalCount(long)},
+ * or by passing the {@link IQueryResult#NO_MORE_ITEMS} constant as item count.
*/
private long realItemCount = UNKNOWN_COUNT;
@@ -382,7 +382,7 @@ public void setItems(Iterator<? extends T> items)
}
/**
- * @see IQueryResult#setTotalCount(int)
+ * @see IQueryResult#setTotalCount(long)
*/
public void setTotalCount(long count)
{
@@ -35,7 +35,6 @@ public ColumnsHeader(String id)
add(new ColumnsHeaderRepeater<M, I>("header")
{
-
private static final long serialVersionUID = 1L;
@Override
@@ -64,5 +63,4 @@ protected void sortStateChanged(AjaxRequestTarget target)
abstract Collection<IGridColumn<M, I>> getActiveColumns();
abstract int getColumnWidth(IGridColumn<M, I> column);
-
}
@@ -67,8 +67,7 @@ protected void onBeforeRender()
{ // if there is no component for given column, create it
if (column.getSortProperty() == null)
- {
- // for non sortable properties just add the component
+ { // for non sortable properties just add the component
Component component = column.newHeader(componentId);
if (component.getId().equals(componentId) == false)
{
@@ -77,10 +76,9 @@ protected void onBeforeRender()
add(component);
}
else
- {
- // for sortable properties place the component inside SortableHeaderLinkPanel
- SortableHeaderLinkPanel panel = new SortableHeaderLinkPanel(componentId,
- column.getSortProperty())
+ { // for sortable properties place the component inside SortableHeaderLinkPanel
+ SortableHeaderLinkPanel panel =
+ new SortableHeaderLinkPanel(componentId, column.getSortProperty())
{
private static final long serialVersionUID = 1L;
@@ -33,24 +33,20 @@ public SortableHeaderLinkPanel(String id, String sortProperty)
add(new AjaxEventBehavior("click")
{
-
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target)
- {
- // change the direction
+ { // change the direction
IGridSortState.Direction direction = getSortDirection();
if (direction == IGridSortState.Direction.ASC)
- {
- // if the direction is already ascending, switch it to descending
+ { // if the direction is already ascending, switch it to descending
getSortState().setSortState(SortableHeaderLinkPanel.this.sortProperty,
IGridSortState.Direction.DESC);
}
else
- {
- // otherwise set direction to ascending
+ { // otherwise set direction to ascending
getSortState().setSortState(SortableHeaderLinkPanel.this.sortProperty,
IGridSortState.Direction.ASC);
}
@@ -75,13 +75,16 @@ version: 2.7.0
* @requires yahoo, event
*/
Y.Dom = {
- CUSTOM_ATTRIBUTES: (!documentElement.hasAttribute) ? { // IE < 8
- 'for': 'htmlFor',
- 'class': CLASS_NAME
- } : { // w3c
- 'htmlFor': 'for',
- 'className': _CLASS
- },
+ CUSTOM_ATTRIBUTES: (!documentElement.hasAttribute) ?
+ { // IE < 8
+ 'for': 'htmlFor',
+ 'class': CLASS_NAME
+ }
+ :
+ { // w3c
+ 'htmlFor': 'for',
+ 'className': _CLASS
+ },
/**
* Returns an HTMLElement reference.
@@ -139,6 +142,7 @@ version: 2.7.0
} else if (el[CURRENT_STYLE]) {
return Y.Dom.IE_ComputedStyle.get(el, property);
}
+ //TODO: should null or some default value get returned here?
},
/**
@@ -153,39 +157,49 @@ version: 2.7.0
},
// branching at load instead of runtime
- _getStyle: function() {
- if (window[GET_COMPUTED_STYLE]) { // W3C DOM method
- return function(el, property) {
- property = (property === 'float') ? property = 'cssFloat' :
- Y.Dom._toCamel(property);
+ _getStyle: function()
+ {
+ if (window[GET_COMPUTED_STYLE])
+ { // W3C DOM method
+ return function(el, property)
+ {
+ property = (property === 'float') ?
+ property = 'cssFloat' : Y.Dom._toCamel(property);
var value = el.style[property],
computed;
- if (!value) {
+ if (!value)
+ {
computed = el[OWNER_DOCUMENT][DEFAULT_VIEW][GET_COMPUTED_STYLE](el, null);
- if (computed) { // test computed before touching for safari
- value = computed[property];
+ if (computed)
+ { // test computed before touching for safari
+ value = computed[property];
}
}
-
return value;
};
- } else if (documentElement[CURRENT_STYLE]) {
- return function(el, property) {
+ }
+ else if (documentElement[CURRENT_STYLE])
+ {
+ return function(el, property)
+ {
var value;
switch(property) {
case 'opacity' :// IE opacity uses filter
value = 100;
- try { // will error if no DXImageTransform
- value = el.filters['DXImageTransform.Microsoft.Alpha'].opacity;
-
- } catch(e) {
- try { // make sure its in the document
- value = el.filters('alpha').opacity;
- } catch(err) {
+ try
+ { // will error if no DXImageTransform
+ value = el.filters['DXImageTransform.Microsoft.Alpha'].opacity;
+ }
+ catch(e)
+ {
+ try
+ { // make sure its in the document
+ value = el.filters('alpha').opacity;
}
+ catch(err) { }
}
return value / 100;
case 'float': // fix reserved word
@@ -197,6 +211,7 @@ version: 2.7.0
}
};
}
+ //TODO: should null or some default be returned here?
}(),
/**
@@ -436,49 +451,56 @@ version: 2.7.0
noRetry = args.noRetry,
delta = [ // assuming pixels; if not we will have to retry
- parseInt( Y.Dom.getComputedStyle(node, LEFT), 10 ),
- parseInt( Y.Dom.getComputedStyle(node, TOP), 10 )
- ],
+ parseInt( Y.Dom.getComputedStyle(node, LEFT), 10 ),
+ parseInt( Y.Dom.getComputedStyle(node, TOP), 10 )
+ ],
currentXY,
newXY;
- if (pos == 'static') { // default to relative
+ if (pos == 'static')
+ { // default to relative
pos = RELATIVE;
setStyle(node, POSITION, pos);
}
currentXY = Y.Dom._getXY(node);
- if (!xy || currentXY === false) { // has to be part of doc to have xy
- return false;
+ if (!xy || currentXY === false)
+ { // has to be part of doc to have xy
+ return false;
}
- if ( isNaN(delta[0]) ) {// in case of 'auto'
- delta[0] = (pos == RELATIVE) ? 0 : node[OFFSET_LEFT];
+ if ( isNaN(delta[0]) )
+ { // in case of 'auto'
+ delta[0] = (pos == RELATIVE) ? 0 : node[OFFSET_LEFT];
}
- if ( isNaN(delta[1]) ) { // in case of 'auto'
- delta[1] = (pos == RELATIVE) ? 0 : node[OFFSET_TOP];
+ if ( isNaN(delta[1]) )
+ { // in case of 'auto'
+ delta[1] = (pos == RELATIVE) ? 0 : node[OFFSET_TOP];
}
- if (xy[0] !== null) { // from setX
- setStyle(node, LEFT, xy[0] - currentXY[0] + delta[0] + 'px');
+ if (xy[0] !== null)
+ { // from setX
+ setStyle(node, LEFT, xy[0] - currentXY[0] + delta[0] + 'px');
}
- if (xy[1] !== null) { // from setY
- setStyle(node, TOP, xy[1] - currentXY[1] + delta[1] + 'px');
+ if (xy[1] !== null)
+ { // from setY
+ setStyle(node, TOP, xy[1] - currentXY[1] + delta[1] + 'px');
}
- if (!noRetry) {
+ if (!noRetry)
+ {
newXY = Y.Dom._getXY(node);
- // if retry is true, try one more time if we miss
+ // if retry is true, try one more time if we miss
if ( (xy[0] !== null && newXY[0] != xy[0]) ||
(xy[1] !== null && newXY[1] != xy[1]) ) {
Y.Dom._setXY(node, { pos: xy, noRetry: true });
}
}
-
+ //TODO: should we return true here?
},
/**
Oops, something went wrong.

0 comments on commit 608929c

Please sign in to comment.