diff options
author | Jonatan Kronqvist <jonatan.kronqvist@itmill.com> | 2011-04-28 07:58:02 +0000 |
---|---|---|
committer | Jonatan Kronqvist <jonatan.kronqvist@itmill.com> | 2011-04-28 07:58:02 +0000 |
commit | cf96b13b6365a1704e5520a9ddec3206f6d71f0f (patch) | |
tree | 9de05101263484659a242485ff2c1720f714b78b /src | |
parent | 000dc3bcb31921939ccfe334a1ed461c3cb9ff05 (diff) | |
download | vaadin-framework-cf96b13b6365a1704e5520a9ddec3206f6d71f0f.tar.gz vaadin-framework-cf96b13b6365a1704e5520a9ddec3206f6d71f0f.zip |
Review fixes for #6697 - Don't fire column resize events for all columns. Naming of constants.
svn changeset:18521/svn branch:6.6
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java | 22 | ||||
-rw-r--r-- | src/com/vaadin/ui/Table.java | 84 |
2 files changed, 50 insertions, 56 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index 801062a7ef..da2c1a0b5b 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -103,6 +103,7 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, VHasDropHandler, FocusHandler, BlurHandler, Focusable, ActionOwner { private static final String ROW_HEADER_COLUMN_KEY = "0"; + public static final String CLASSNAME = "v-table"; public static final String CLASSNAME_SELECTION_FOCUS = CLASSNAME + "-focus"; @@ -504,20 +505,19 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, } /** - * Non-immediate variable update of column resize events for a bunch of + * Non-immediate variable update of column widths for a collection of * columns. * * @param columns * the columns to trigger the events for. */ - private void enqueueColumnResizeEventsForColumns( - Collection<HeaderCell> columns) { + private void sendColumnWidthUpdates(Collection<HeaderCell> columns) { String[] newSizes = new String[columns.size()]; int ix = 0; for (HeaderCell cell : columns) { newSizes[ix++] = cell.getColKey() + ":" + cell.getWidth(); } - client.updateVariable(paintableId, "columnResizeEvents", newSizes, + client.updateVariable(paintableId, "columnWidthUpdates", newSizes, false); } @@ -2498,7 +2498,6 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, public void updateCellsFromUIDL(UIDL uidl) { Iterator<?> it = uidl.getChildIterator(); HashSet<String> updated = new HashSet<String>(); - updated.add(ROW_HEADER_COLUMN_KEY); while (it.hasNext()) { final UIDL col = (UIDL) it.next(); final String cid = col.getStringAttribute("cid"); @@ -2866,7 +2865,7 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, ArrayList<HeaderCell> columns = new ArrayList<HeaderCell>( availableCells.values()); columns.remove(source); - enqueueColumnResizeEventsForColumns(columns); + sendColumnWidthUpdates(columns); forceRealignColumnHeaders(); } } @@ -3296,7 +3295,6 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, public void updateCellsFromUIDL(UIDL uidl) { Iterator<?> columnIterator = uidl.getChildIterator(); HashSet<String> updated = new HashSet<String>(); - updated.add(ROW_HEADER_COLUMN_KEY); while (columnIterator.hasNext()) { final UIDL col = (UIDL) columnIterator.next(); final String cid = col.getStringAttribute("cid"); @@ -5024,14 +5022,14 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, } }; - + private void forceRealignColumnHeaders() { if (BrowserInfo.get().isIE()) { /* - * IE does not fire onscroll event if scroll position is - * reverted to 0 due to the content element size growth. Ensure - * headers are in sync with content manually. Safe to use null - * event as we don't actually use the event object in listener. + * IE does not fire onscroll event if scroll position is reverted to + * 0 due to the content element size growth. Ensure headers are in + * sync with content manually. Safe to use null event as we don't + * actually use the event object in listener. */ onScroll(null); } diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index 4d4293e655..a76153f772 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -202,8 +202,8 @@ public class Table extends AbstractSelect implements Action.Container, */ private static final double CACHE_RATE_DEFAULT = 2; - private static final String ROW_HEADER_COLUMN_ID = "0"; - private static final Object MAGIC_ROW_HEADER_ID = new Object(); + private static final String ROW_HEADER_COLUMN_KEY = "0"; + private static final Object ROW_HEADER_FAKE_PROPERTY_ID = new Object(); /* Private table extensions to Select */ @@ -736,7 +736,7 @@ public class Table extends AbstractSelect implements Action.Container, if (propertyId == null) { // Since propertyId is null, this is the row header. Use the magic // id to store the width of the row header. - propertyId = MAGIC_ROW_HEADER_ID; + propertyId = ROW_HEADER_FAKE_PROPERTY_ID; } if (width < 0) { columnWidths.remove(propertyId); @@ -808,7 +808,7 @@ public class Table extends AbstractSelect implements Action.Container, if (propertyId == null) { // Since propertyId is null, this is the row header. Use the magic // id to retrieve the width of the row header. - propertyId = MAGIC_ROW_HEADER_ID; + propertyId = ROW_HEADER_FAKE_PROPERTY_ID; } final Object width = columnWidths.get(propertyId); if (width == null || !(width instanceof Integer)) { @@ -1998,7 +1998,9 @@ public class Table extends AbstractSelect implements Action.Container, handleClickEvent(variables); - handleColumnResizeEvents(variables); + handleColumnResizeEvent(variables); + + handleColumnWidthUpdates(variables); disableContentRefreshing(); @@ -2222,47 +2224,26 @@ public class Table extends AbstractSelect implements Action.Container, * * @param variables */ - private void handleColumnResizeEvents(Map<String, Object> variables) { - if (variables.containsKey("columnResizeEvents")) { - handleMultipleColumnResizeEvents(variables); - } + private void handleColumnResizeEvent(Map<String, Object> variables) { if (variables.containsKey("columnResizeEventColumn")) { - handleSingleColumnResizeEvent(variables); - } - } - - private void handleSingleColumnResizeEvent(Map<String, Object> variables) { - Object cid = variables.get("columnResizeEventColumn"); - Object propertyId = null; - if (cid != null) { - propertyId = columnIdMap.get(cid.toString()); - - Object prev = variables.get("columnResizeEventPrev"); - int previousWidth = -1; - if (prev != null) { - previousWidth = Integer.valueOf(prev.toString()); - } - - Object curr = variables.get("columnResizeEventCurr"); - int currentWidth = -1; - if (curr != null) { - currentWidth = Integer.valueOf(curr.toString()); - } + Object cid = variables.get("columnResizeEventColumn"); + Object propertyId = null; + if (cid != null) { + propertyId = columnIdMap.get(cid.toString()); - fireColumnResizeEvent(propertyId, previousWidth, currentWidth); - } - } + Object prev = variables.get("columnResizeEventPrev"); + int previousWidth = -1; + if (prev != null) { + previousWidth = Integer.valueOf(prev.toString()); + } - private void handleMultipleColumnResizeEvents(Map<String, Object> variables) { - String[] events = (String[]) variables.get("columnResizeEvents"); - for (String str : events) { - String[] eventDetails = str.split(":"); - Object propertyId = columnIdMap.get(eventDetails[0]); - if (propertyId != null) { - int curWidth = Integer.valueOf(eventDetails[1]); - int prevWidth = getColumnWidth(propertyId); + Object curr = variables.get("columnResizeEventCurr"); + int currentWidth = -1; + if (curr != null) { + currentWidth = Integer.valueOf(curr.toString()); + } - fireColumnResizeEvent(propertyId, prevWidth, curWidth); + fireColumnResizeEvent(propertyId, previousWidth, currentWidth); } } } @@ -2280,6 +2261,21 @@ public class Table extends AbstractSelect implements Action.Container, currentWidth)); } + private void handleColumnWidthUpdates(Map<String, Object> variables) { + if (variables.containsKey("columnWidthUpdates")) { + String[] events = (String[]) variables.get("columnWidthUpdates"); + for (String str : events) { + String[] eventDetails = str.split(":"); + Object propertyId = columnIdMap.get(eventDetails[0]); + if (propertyId == null) { + propertyId = ROW_HEADER_FAKE_PROPERTY_ID; + } + int width = Integer.valueOf(eventDetails[1]); + setColumnWidth(propertyId, width); + } + } + } + /** * Go to mode where content updates are not done. This is due we want to * bypass expensive content for some reason (like when we know we may have @@ -2575,8 +2571,8 @@ public class Table extends AbstractSelect implements Action.Container, target.startTag("visiblecolumns"); if (rowHeadersAreEnabled()) { target.startTag("column"); - target.addAttribute("cid", ROW_HEADER_COLUMN_ID); - paintColumnWidth(target, MAGIC_ROW_HEADER_ID); + target.addAttribute("cid", ROW_HEADER_COLUMN_KEY); + paintColumnWidth(target, ROW_HEADER_FAKE_PROPERTY_ID); target.endTag("column"); } int i = 0; |