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 41911 Details for
Bug 140032
Performance: TreeViewer::getSelection() is expensive and could easily be cached
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
cache the AbstractTreeViewer selection
getSelection.patch (text/plain), 4.63 KB, created by
Yasser Lulu
on 2006-05-18 13:26:08 EDT
(
hide
)
Description:
cache the AbstractTreeViewer selection
Filename:
MIME Type:
Creator:
Yasser Lulu
Created:
2006-05-18 13:26:08 EDT
Size:
4.63 KB
patch
obsolete
>Index: src/org/eclipse/jface/viewers/AbstractTreeViewer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTreeViewer.java,v >retrieving revision 1.91 >diff -u -r1.91 AbstractTreeViewer.java >--- src/org/eclipse/jface/viewers/AbstractTreeViewer.java 11 May 2006 05:18:15 -0000 1.91 >+++ src/org/eclipse/jface/viewers/AbstractTreeViewer.java 18 May 2006 17:27:53 -0000 >@@ -23,6 +23,7 @@ > import org.eclipse.jface.util.SafeRunnable; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.BusyIndicator; >+import org.eclipse.swt.events.DisposeEvent; > import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.events.SelectionListener; > import org.eclipse.swt.events.TreeEvent; >@@ -77,6 +78,8 @@ > * @see #setAutoExpandLevel > */ > private int expandToLevel = 0; >+ >+ protected ISelection currentTreeSelection; > > /** > * Safe runnable used to update an item. >@@ -1210,7 +1213,7 @@ > > } > else { >- selection = getSelection(); >+ selection = doGetSelection(); > updateSelection(selection); > } > fireDoubleClick(new DoubleClickEvent(this, selection)); >@@ -2239,6 +2242,9 @@ > if (reveal && newSelection.size() > 0) { > showItem((Item) newSelection.get(0)); > } >+ >+ //update currentSelection >+ currentTreeSelection = doGetSelection(); > } > > /** >@@ -2546,30 +2552,71 @@ > item = getParentItem(item); > } > return new TreePath(segments.toArray()); >- } >- >- /** >- * This implementation of getSelection() returns an instance of >- * ITreeSelection. >- * >- * @since 3.2 >- */ >- public ISelection getSelection() { >- Control control = getControl(); >- if (control == null || control.isDisposed()) { >- return TreeSelection.EMPTY; >- } >- Widget[] items = getSelection(getControl()); >- ArrayList list = new ArrayList(items.length); >- for (int i = 0; i < items.length; i++) { >- Widget item = items[i]; >- if (item.getData() != null) { >- list.add(getTreePathFromItem((Item) item)); >- } >- } >- return new TreeSelection((TreePath[]) list.toArray(new TreePath[list >- .size()]), getComparer()); >- } >+ } >+ >+ protected void updateSelection(ISelection selection) { >+ currentTreeSelection = selection; >+ super.updateSelection(selection); >+ } >+ >+ /** >+ * This implementation of getSelection() returns an instance of >+ * ITreeSelection. >+ * >+ * @since 3.2 >+ */ >+ public ISelection getSelection() { >+ Control control = getControl(); >+ if (control == null || control.isDisposed() || currentTreeSelection == null) { >+ return TreeSelection.EMPTY; >+ } >+ return currentTreeSelection; >+ } >+ >+ protected ISelection doGetSelection() { >+ Control control = getControl(); >+ if (control == null || control.isDisposed()) { >+ return TreeSelection.EMPTY; >+ } >+ Widget[] items = getSelection(getControl()); >+ ArrayList list = new ArrayList(items.length); >+ for (int i = 0; i < items.length; i++) { >+ Widget item = items[i]; >+ if (item.getData() != null) { >+ list.add(getTreePathFromItem((Item) item)); >+ } >+ } >+ return new TreeSelection((TreePath[]) list.toArray(new TreePath[list >+ .size()]), getComparer()); >+ } >+ >+ protected void handleSelect(SelectionEvent event) { >+ // handle case where an earlier selection listener disposed the control. >+ Control control = getControl(); >+ if (control != null && !control.isDisposed()) { >+ updateSelection(doGetSelection()); >+ } >+ } >+ >+ >+ protected void handlePostSelect(SelectionEvent e) { >+ currentTreeSelection = doGetSelection(); >+ SelectionChangedEvent event = new SelectionChangedEvent(this, currentTreeSelection); >+ firePostSelectionChanged(event); >+ } >+ >+ protected void handleOpen(SelectionEvent event) { >+ Control control = getControl(); >+ if (control != null && !control.isDisposed()) { >+ currentTreeSelection = doGetSelection(); >+ fireOpen(new OpenEvent(this, currentTreeSelection)); >+ } >+ } >+ >+ protected void handleDispose(DisposeEvent event) { >+ super.handleDispose(event); >+ currentTreeSelection = null; >+ } > > protected void setSelectionToWidget(ISelection selection, boolean reveal) { > if(selection instanceof ITreeSelection) {
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 140032
:
41911
|
43143