Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 57078 Details for
Bug 167325
[Viewers]ViewerCell and ViewerRow should provide API to find neighbors
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Extracted from Mega-Patch in151295
clipboard61432.txt (text/plain), 13.58 KB, created by
Thomas Schindl
on 2007-01-18 08:47:17 EST
(
hide
)
Description:
Extracted from Mega-Patch in151295
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2007-01-18 08:47:17 EST
Size:
13.58 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jface >Index: src/org/eclipse/jface/viewers/EditingSupport.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/EditingSupport.java,v >retrieving revision 1.4 >diff -u -r1.4 EditingSupport.java >--- src/org/eclipse/jface/viewers/EditingSupport.java 30 Nov 2006 18:53:06 -0000 1.4 >+++ src/org/eclipse/jface/viewers/EditingSupport.java 18 Jan 2007 13:36:03 -0000 >@@ -16,8 +16,6 @@ > import org.eclipse.core.runtime.Assert; > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.TraverseEvent; >-import org.eclipse.swt.graphics.Point; >-import org.eclipse.swt.graphics.Rectangle; > > /** > * EditingSupport is the abstract superclass of the support for cell editing. >@@ -184,9 +182,9 @@ > ViewerRow newRow = null; > > if (above) { >- newRow = getRowAbove(row, viewer); >+ newRow = row.getNeighbor(ViewerRow.ABOVE, false); > } else { >- newRow = getRowBelow(row, viewer); >+ newRow = row.getNeighbor(ViewerRow.BELOW,false); > } > > if (newRow != null) { >@@ -228,7 +226,7 @@ > startIndex); > } > } else if ((getTabingStyle() & TABING_MOVE_TO_ROW_NEIGHBOR) == TABING_MOVE_TO_ROW_NEIGHBOR) { >- ViewerRow rowAbove = getRowAbove(row, viewer); >+ ViewerRow rowAbove = row.getNeighbor(ViewerRow.ABOVE,false); > if (rowAbove != null) { > rv = searchPreviousCell(rowAbove, viewer, rowAbove > .getColumnCount(), startIndex); >@@ -261,7 +259,7 @@ > rv = searchNextCell(row, viewer, -1, startIndex); > } > } else if ((getTabingStyle() & TABING_MOVE_TO_ROW_NEIGHBOR) == TABING_MOVE_TO_ROW_NEIGHBOR) { >- ViewerRow rowBelow = getRowBelow(row, viewer); >+ ViewerRow rowBelow = row.getNeighbor(ViewerRow.BELOW,false); > if (rowBelow != null) { > rv = searchNextCell(rowBelow, viewer, -1, startIndex); > } >@@ -270,23 +268,6 @@ > > return rv; > } >- >- private ViewerRow getRowAbove(ViewerRow row, ColumnViewer viewer) { >- // TODO maybe there's a better solution maybe we should provide an >- // API in ViewerColumn >- // to find row above/below itself? >- Rectangle r = row.getBounds(); >- return viewer.getViewerRow(new Point(r.x, r.y - 2)); >- } >- >- private ViewerRow getRowBelow(ViewerRow row, ColumnViewer viewer) { >- // TODO maybe there's a better solution maybe we should provide an >- // API in ViewerColumn >- // to find row above/below itself? >- Rectangle r = row.getBounds(); >- return viewer.getViewerRow(new Point(r.x, >- r.y + r.height + 2)); >- } > > /** > * @return the viewer this editing support works for >Index: src/org/eclipse/jface/viewers/TableViewerRow.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerRow.java,v >retrieving revision 1.3 >diff -u -r1.3 TableViewerRow.java >--- src/org/eclipse/jface/viewers/TableViewerRow.java 5 Sep 2006 20:51:25 -0000 1.3 >+++ src/org/eclipse/jface/viewers/TableViewerRow.java 18 Jan 2007 13:36:03 -0000 >@@ -146,4 +146,39 @@ > return item.getParent(); > } > >+ public ViewerRow getNeighbor(int direction, boolean sameLevel) { >+ if( direction == ViewerRow.ABOVE ) { >+ return getRowAbove(sameLevel); >+ } else if( direction == ViewerRow.BELOW ) { >+ return getRowBelow(sameLevel); >+ } else { >+ throw new IllegalArgumentException("The given direction argument is not known!"); //$NON-NLS-1$ >+ } >+ } >+ >+ >+ private ViewerRow getRowAbove(boolean sameLevel) { >+ int index = item.getParent().indexOf(item) - 1; >+ >+ if( index >= 0 ) { >+ return (ViewerRow)item.getParent().getItem(index).getData(ViewerRow.ROWPART_KEY); >+ } >+ >+ return null; >+ } >+ >+ private ViewerRow getRowBelow(boolean sameLevel) { >+ int index = item.getParent().indexOf(item) + 1; >+ >+ if( index < item.getParent().getItemCount() ) { >+ TableItem tmp = item.getParent().getItem(index); >+ //TODO NULL can happen in case of VIRTUAL => How do we deal with that >+ if( tmp != null ) { >+ return (ViewerRow)tmp.getData(ViewerRow.ROWPART_KEY); >+ } >+ } >+ >+ return null; >+ } >+ > } >Index: src/org/eclipse/jface/viewers/TreeViewerRow.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewerRow.java,v >retrieving revision 1.3 >diff -u -r1.3 TreeViewerRow.java >--- src/org/eclipse/jface/viewers/TreeViewerRow.java 5 Sep 2006 20:51:25 -0000 1.3 >+++ src/org/eclipse/jface/viewers/TreeViewerRow.java 18 Jan 2007 13:36:03 -0000 >@@ -18,6 +18,7 @@ > import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Item; >+import org.eclipse.swt.widgets.Tree; > import org.eclipse.swt.widgets.TreeItem; > > /** >@@ -58,7 +59,7 @@ > * @see org.eclipse.jface.viewers.ViewerRow#getColumnCount() > */ > public int getColumnCount() { >- return item.getParent().getItemCount(); >+ return item.getParent().getColumnCount(); > } > > /* (non-Javadoc) >@@ -144,4 +145,154 @@ > public Control getControl() { > return item.getParent(); > } >+ >+ >+ public ViewerRow getNeighbor(int direction, boolean sameLevel) { >+ if( direction == ViewerRow.ABOVE ) { >+ return getRowAbove(sameLevel); >+ } else if( direction == ViewerRow.BELOW ) { >+ return getRowBelow(sameLevel); >+ } else { >+ throw new IllegalArgumentException("The given direction argument is not known!"); //$NON-NLS-1$ >+ } >+ } >+ >+ private ViewerRow getRowBelow(boolean sameLevel) { >+ Tree tree = item.getParent(); >+ >+ // This means we have top-level item >+ if( item.getParentItem() == null ) { >+ if( sameLevel || ! item.getExpanded() ) { >+ int index = tree.indexOf(item) + 1; >+ >+ if( index < tree.getItemCount() ) { >+ return (ViewerRow)tree.getItem(index).getData(ViewerRow.ROWPART_KEY); >+ } >+ } else if( item.getExpanded() && item.getItemCount() > 0 ) { >+ return (ViewerRow)item.getItem(0).getData(ViewerRow.ROWPART_KEY); >+ } >+ } else { >+ if( sameLevel || ! item.getExpanded() ) { >+ TreeItem parentItem = item.getParentItem(); >+ >+ int nextIndex = parentItem.indexOf(item) + 1; >+ int totalIndex = parentItem.getItemCount(); >+ >+ TreeItem itemAfter; >+ >+ // This would mean that it was the last item >+ if( nextIndex == totalIndex ) { >+ itemAfter = findNextItem( parentItem ); >+ } else { >+ itemAfter = parentItem.getItem(nextIndex); >+ } >+ >+ if( itemAfter != null ) { >+ return (ViewerRow) itemAfter.getData(ViewerRow.ROWPART_KEY); >+ } >+ >+ } else if( item.getExpanded() && item.getItemCount() > 0 ) { >+ return (ViewerRow)item.getItem(0).getData(ViewerRow.ROWPART_KEY); >+ } >+ } >+ >+ return null; >+ } >+ >+ private ViewerRow getRowAbove(boolean sameLevel) { >+ Tree tree = item.getParent(); >+ >+ // This means we have top-level item >+ if( item.getParentItem() == null ) { >+ int index = tree.indexOf(item) - 1; >+ TreeItem nextTopItem = null; >+ >+ if( index >= 0 ) { >+ nextTopItem = tree.getItem(index); >+ } >+ >+ if( nextTopItem != null ) { >+ if( sameLevel ) { >+ return (ViewerRow)nextTopItem.getData(ViewerRow.ROWPART_KEY); >+ } >+ >+ return (ViewerRow) findLastVisibleItem(nextTopItem).getData(ViewerRow.ROWPART_KEY); >+ } >+ } else { >+ TreeItem parentItem = item.getParentItem(); >+ int previousIndex = parentItem.indexOf(item) - 1; >+ >+ TreeItem itemBefore; >+ if( previousIndex >= 0 ) { >+ if( sameLevel ) { >+ itemBefore = parentItem.getItem(previousIndex); >+ } else { >+ itemBefore = findLowestLeave(parentItem.getItem(previousIndex)); >+ } >+ } else { >+ itemBefore = parentItem; >+ } >+ >+ if( itemBefore != null ) { >+ return (ViewerRow) itemBefore.getData(ViewerRow.ROWPART_KEY); >+ } >+ } >+ >+ return null; >+ } >+ >+ private TreeItem findLastVisibleItem(TreeItem parentItem) { >+ TreeItem rv = parentItem; >+ >+ if( rv.getExpanded() && rv.getItemCount() > 0 ) { >+ rv = findLastVisibleItem(rv.getItem(rv.getItemCount()-1)); >+ } >+ >+ return rv; >+ } >+ >+ private TreeItem findLowestLeave(TreeItem item) { >+ TreeItem rv = item; >+ >+ if( rv.getExpanded() && rv.getItemCount() > 0 ) { >+ rv = findLowestLeave(rv.getItem(rv.getItemCount()-1)); >+ } >+ >+ return rv; >+ } >+ >+ private TreeItem findNextItem(TreeItem item) { >+ TreeItem rv = null; >+ Tree tree = item.getParent(); >+ TreeItem parentItem = item.getParentItem(); >+ >+ int nextIndex; >+ int totalItems; >+ >+ if( parentItem == null ) { >+ nextIndex = tree.indexOf(item) + 1; >+ totalItems = tree.getItemCount(); >+ } else { >+ nextIndex = parentItem.indexOf(item) + 1; >+ totalItems = parentItem.getItemCount(); >+ } >+ >+ // This is once more the last item in the tree >+ // Search on >+ if( nextIndex == totalItems ) { >+ if( item.getParentItem() != null ) { >+ rv = findNextItem(item.getParentItem()); >+ } >+ } else { >+ if( parentItem == null ) { >+ rv = tree.getItem(nextIndex); >+ } else { >+ rv = parentItem.getItem(nextIndex); >+ } >+ } >+ >+ return rv; >+ } >+ >+ > } >Index: src/org/eclipse/jface/viewers/ViewerCell.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerCell.java,v >retrieving revision 1.4 >diff -u -r1.4 ViewerCell.java >--- src/org/eclipse/jface/viewers/ViewerCell.java 6 Sep 2006 19:16:09 -0000 1.4 >+++ src/org/eclipse/jface/viewers/ViewerCell.java 18 Jan 2007 13:36:03 -0000 >@@ -34,6 +34,26 @@ > private ViewerRow row; > > /** >+ * The direction pointing to the row above the current cell >+ */ >+ public static int ABOVE = 1; >+ >+ /** >+ * The direction pointing to the row below the current cell >+ */ >+ public static int BELOW = 1 << 1; >+ >+ /** >+ * The direction pointing to the left of the current cell >+ */ >+ public static int LEFT = 1 << 2; >+ >+ /** >+ * The direction pointing to the right of the current cell >+ */ >+ public static int RIGHT = 1 << 3; >+ >+ /** > * Create a new instance of the receiver on the row. > * > * @param row >@@ -177,4 +197,63 @@ > public Control getControl() { > return row.getControl(); > } >+ >+ /** >+ * This method provides access to all cells who are neighbors of the >+ * current-cell by passing the appropriate coordinadate constant. You can >+ * even access cell e.g. to the upper-left of the current cell by passing a >+ * bitmask like {@link #ABOVE} | {@link #LEFT} >+ * >+ * @param directionMask >+ * the direction mask used to identify the requested cell >+ * @param sameLevel >+ * should we stay at the samelevel (this only has an effect for >+ * viewers organized as trees) >+ * @return the cell or <code>null</code> >+ */ >+ public ViewerCell getNeighbor(int directionMask, boolean sameLevel) { >+ ViewerRow row; >+ int columnIndex; >+ >+ if ((directionMask & ABOVE) == ABOVE) { >+ row = this.row.getNeighbor(ViewerRow.ABOVE, sameLevel); >+ } else if ((directionMask & BELOW) == BELOW) { >+ row = this.row.getNeighbor(ViewerRow.BELOW, sameLevel); >+ } else { >+ row = this.row; >+ } >+ >+ if (row != null) { >+ if ((directionMask & LEFT) == LEFT) { >+ columnIndex = getColumnIndex() - 1; >+ } else if ((directionMask & RIGHT) == RIGHT) { >+ columnIndex = getColumnIndex() + 1; >+ } else { >+ columnIndex = getColumnIndex(); >+ } >+ >+ if (columnIndex >= 0 && columnIndex < row.getColumnCount()) { >+ return row.getCell(columnIndex); >+ } >+ } >+ >+ return null; >+ } >+ >+ public boolean equals(Object obj) { >+ if( obj == null || !(obj instanceof ViewerCell) ) { >+ return false; >+ } >+ >+ ViewerCell cell = (ViewerCell) obj; >+ >+ return cell.getColumnIndex() == getColumnIndex() && cell.getItem() == getItem(); >+ } >+ >+ /** >+ * @return the row >+ */ >+ public ViewerRow getViewerRow() { >+ return row; >+ } > } >Index: src/org/eclipse/jface/viewers/ViewerRow.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerRow.java,v >retrieving revision 1.7 >diff -u -r1.7 ViewerRow.java >--- src/org/eclipse/jface/viewers/ViewerRow.java 20 Dec 2006 20:22:07 -0000 1.7 >+++ src/org/eclipse/jface/viewers/ViewerRow.java 18 Jan 2007 13:36:03 -0000 >@@ -39,6 +39,16 @@ > public static final String ROWPART_KEY = Policy.JFACE + ".ROWPART"; //$NON-NLS-1$ > > /** >+ * the cell above the current one >+ */ >+ public static final int ABOVE = 1; >+ >+ /** >+ * the cell below the current one; >+ */ >+ public static final int BELOW = 2; >+ >+ /** > * Create a new instance of the receiver. > * > * @param item >@@ -164,7 +174,6 @@ > */ > public ViewerCell getCell(Point point) { > int index = getColumnIndex(point); >- > return getCell(index); > } > >@@ -176,12 +185,12 @@ > */ > public int getColumnIndex(Point point) { > int count = getColumnCount(); >- >+ > // If there are no columns the column-index is 0 >- if( count == 0 ) { >+ if (count == 0) { > return 0; > } >- >+ > for (int i = 0; i < count; i++) { > if (getBounds(i).contains(point)) { > return i; >@@ -212,4 +221,16 @@ > */ > public abstract Control getControl(); > >+ /** >+ * Get the neighbor of the row >+ * >+ * @param direction >+ * the direction {@link #BELOW} or {@link #ABOVE} >+ * >+ * @param sameLevel >+ * search at the samelevel >+ * @return the row above or <code>null</code> >+ */ >+ public abstract ViewerRow getNeighbor(int direction, boolean sameLevel); >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 167325
:
55449
|
55916
|
56191
| 57078