1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-16 21:45:22 +02:00

[187739] [refresh] Sub Directories are collapsed when Parent Directory is Refreshed on Remote Systems

This commit is contained in:
David McKnight 2008-08-19 20:18:26 +00:00
parent 7a4766a5fb
commit 14c810b1ac
3 changed files with 256 additions and 48 deletions

View file

@ -0,0 +1,77 @@
/********************************************************************************
* Copyright (c) 2008 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight.
*
* Contributors:
* David McKnight (IBM) - [187739] [refresh] Sub Directories are collapsed when Parent Directory is Refreshed on Remote Systems
********************************************************************************/
package org.eclipse.rse.internal.ui.view;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.rse.core.filters.ISystemFilterReference;
import org.eclipse.rse.core.model.IRSECallback;
import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.ui.view.ContextObject;
public class ContextObjectWithViewer extends ContextObject {
private Viewer _viewer;
private IRSECallback _callback;
public ContextObjectWithViewer(Object modelObject, Viewer viewer){
super(modelObject);
_viewer = viewer;
}
public ContextObjectWithViewer(Object modelObject, ISubSystem subsystem, Viewer viewer){
super(modelObject, subsystem);
_viewer = viewer;
}
public ContextObjectWithViewer(Object modelObject, ISubSystem subsystem, ISystemFilterReference filterReference, Viewer viewer){
super(modelObject, subsystem, filterReference);
_viewer = viewer;
}
public ContextObjectWithViewer(Object modelObject, Viewer viewer, IRSECallback callback){
super(modelObject);
_viewer = viewer;
_callback = callback;
}
public ContextObjectWithViewer(Object modelObject, ISubSystem subsystem, Viewer viewer, IRSECallback callback){
super(modelObject, subsystem);
_viewer = viewer;
_callback = callback;
}
public ContextObjectWithViewer(Object modelObject, ISubSystem subsystem, ISystemFilterReference filterReference, Viewer viewer, IRSECallback callback){
super(modelObject, subsystem, filterReference);
_viewer = viewer;
_callback = callback;
}
public Viewer getViewer()
{
return _viewer;
}
public IRSECallback getCallback()
{
return _callback;
}
public void setCallback(IRSECallback callback){
_callback = callback;
}
public void setViewer(Viewer viewer){
_viewer = viewer;
}
}

View file

@ -61,6 +61,7 @@
* David McKnight (IBM) - [236874] NPE upon selecting an item that is not associated with subsystem * David McKnight (IBM) - [236874] NPE upon selecting an item that is not associated with subsystem
* David McKnight (IBM) - [238363] Performance improvement for refresh in system view. * David McKnight (IBM) - [238363] Performance improvement for refresh in system view.
* David McKnight (IBM) - [241722] New -> File doesn't select the newly created file * David McKnight (IBM) - [241722] New -> File doesn't select the newly created file
* David McKnight (IBM) - [187739] [refresh] Sub Directories are collapsed when Parent Directory is Refreshed on Remote Systems
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.internal.ui.view; package org.eclipse.rse.internal.ui.view;
@ -130,6 +131,7 @@ import org.eclipse.rse.core.filters.ISystemFilterReference;
import org.eclipse.rse.core.filters.ISystemFilterString; import org.eclipse.rse.core.filters.ISystemFilterString;
import org.eclipse.rse.core.filters.ISystemFilterStringReference; import org.eclipse.rse.core.filters.ISystemFilterStringReference;
import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.IRSECallback;
import org.eclipse.rse.core.model.ISystemContainer; import org.eclipse.rse.core.model.ISystemContainer;
import org.eclipse.rse.core.model.ISystemMessageObject; import org.eclipse.rse.core.model.ISystemMessageObject;
import org.eclipse.rse.core.model.ISystemRegistry; import org.eclipse.rse.core.model.ISystemRegistry;
@ -173,7 +175,6 @@ import org.eclipse.rse.ui.model.ISystemShellProvider;
import org.eclipse.rse.ui.model.SystemRemoteElementResourceSet; import org.eclipse.rse.ui.model.SystemRemoteElementResourceSet;
import org.eclipse.rse.ui.model.SystemResourceChangeEventUI; import org.eclipse.rse.ui.model.SystemResourceChangeEventUI;
import org.eclipse.rse.ui.view.AbstractSystemViewAdapter; import org.eclipse.rse.ui.view.AbstractSystemViewAdapter;
import org.eclipse.rse.ui.view.ContextObject;
import org.eclipse.rse.ui.view.IContextObject; import org.eclipse.rse.ui.view.IContextObject;
import org.eclipse.rse.ui.view.ISystemRemoteElementAdapter; import org.eclipse.rse.ui.view.ISystemRemoteElementAdapter;
import org.eclipse.rse.ui.view.ISystemSelectAllTarget; import org.eclipse.rse.ui.view.ISystemSelectAllTarget;
@ -232,6 +233,88 @@ public class SystemView extends SafeTreeViewer
ISelectionChangedListener, ITreeViewerListener ISelectionChangedListener, ITreeViewerListener
{ {
// for deferred queries
class ExpandRemoteObjects implements IRSECallback {
private List _toExpand;
public ExpandRemoteObjects(List toExpand){
_toExpand = toExpand;
}
public void done(IStatus status, Object result) {
if (Display.getCurrent() != null){ // on main thread
execute();
}
else {
// need to run this code on main thread
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable()
{
public void run() {
execute();
}
});
}
}
private void execute()
{
// expand each previously expanded sub-node, recursively
for (int idx = 0; idx < _toExpand.size(); idx++) {
ExpandedItem itemToExpand = (ExpandedItem) _toExpand.get(idx);
if (itemToExpand.isRemote()) {
// find remote item based on its original name and unchanged root parent
Item item = null;
item = findFirstRemoteItemReference(itemToExpand.remoteName, itemToExpand.subsystem, itemToExpand.parentItem);
// if found, re-expand it
if (item != null) {
IRSECallback callback = getCallbackForSubChildren(itemToExpand, _toExpand);
createChildren(item, callback);
((TreeItem) item).setExpanded(true);
}
} else if (itemToExpand.data!=null) {
setExpandedState(itemToExpand.data, true);
}
}
}
private IRSECallback getCallbackForSubChildren(ExpandedItem remoteParent, List itemsToExpand){
List subChildren = new ArrayList();
String parentName = remoteParent.remoteName;
Object parent = remoteParent.data;
String absoluteParentName = remoteParent.remoteAdapter.getAbsoluteName(parent);
for (int i = 0; i < itemsToExpand.size(); i++){
ExpandedItem itemToExpand = (ExpandedItem) itemsToExpand.get(i);
if (parentName.equals(itemToExpand.remoteName)){
// same item
}
else if (itemToExpand.remoteName.startsWith(parentName)){
// child item
subChildren.add(itemToExpand);
}
else {
// some objects might need explicit comparison
Object object = itemToExpand.data;
ISystemRemoteElementAdapter adapter = itemToExpand.remoteAdapter;
String childParentName = adapter.getAbsoluteParentName(object);
if (absoluteParentName.equals(childParentName)){
subChildren.add(itemToExpand);
}
}
}
if (subChildren.size() > 0){
return new ExpandRemoteObjects(subChildren);
}
else {
return null;
}
}
}
protected Shell shell; // shell hosting this viewer: TODO can be removed protected Shell shell; // shell hosting this viewer: TODO can be removed
protected ISystemViewInputProvider inputProvider; // who is supplying our tree root elements? protected ISystemViewInputProvider inputProvider; // who is supplying our tree root elements?
protected ISystemViewInputProvider previousInputProvider; // who is supplying our tree root elements? protected ISystemViewInputProvider previousInputProvider; // who is supplying our tree root elements?
@ -3177,6 +3260,9 @@ public class SystemView extends SafeTreeViewer
TreeItem matchedItem = (TreeItem)match; TreeItem matchedItem = (TreeItem)match;
Object data = matchedItem.getData(); Object data = matchedItem.getData();
boolean wasExpanded = matchedItem.getExpanded(); boolean wasExpanded = matchedItem.getExpanded();
smartRefresh(new TreeItem[] { matchedItem }); // refresh the remote object smartRefresh(new TreeItem[] { matchedItem }); // refresh the remote object
if (firstSelection && // for now, we just select the first binary occurrence we find if (firstSelection && // for now, we just select the first binary occurrence we find
(data == remoteObject)) // same binary object as given? (data == remoteObject)) // same binary object as given?
@ -3194,6 +3280,7 @@ public class SystemView extends SafeTreeViewer
createChildren(matchedItem); createChildren(matchedItem);
setExpanded(matchedItem, true); setExpanded(matchedItem, true);
} }
// todo: handle cumulative selections. // todo: handle cumulative selections.
// STEP 4: If requested, select the kids in the newly refreshed object. // STEP 4: If requested, select the kids in the newly refreshed object.
// If the same binary object appears multiple times, select the kids in the first occurrence. // If the same binary object appears multiple times, select the kids in the first occurrence.
@ -3330,7 +3417,20 @@ public class SystemView extends SafeTreeViewer
protected void internalRefreshStruct(Widget widget, Object element, boolean updateLabels) { protected void internalRefreshStruct(Widget widget, Object element, boolean updateLabels) {
if (widget instanceof TreeItem) if (widget instanceof TreeItem)
{ {
IContextObject contextObject = getContextObject((TreeItem)widget); ContextObjectWithViewer contextObject = (ContextObjectWithViewer)getContextObject((TreeItem)widget);
IRSECallback callback = null;
ArrayList expandedChildren = new ArrayList();
if (widget instanceof TreeItem){
TreeItem currItem = (TreeItem)widget;
gatherExpandedChildren(currItem, currItem, expandedChildren);
}
if (expandedChildren.size() > 0){
callback = new ExpandRemoteObjects(expandedChildren);
contextObject.setCallback(callback);
}
internalRSERefreshStruct(widget, contextObject, updateLabels); internalRSERefreshStruct(widget, contextObject, updateLabels);
} }
else else
@ -3649,7 +3749,12 @@ public class SystemView extends SafeTreeViewer
ourInternalRefresh(currItem, currItem.getData(), true, true); // dispose of children, update plus ourInternalRefresh(currItem, currItem.getData(), true, true); // dispose of children, update plus
if (wasExpanded[idx]) { if (wasExpanded[idx]) {
createChildren(currItem); // re-expand
IRSECallback callback = new ExpandRemoteObjects(expandedChildren);
createChildren(currItem, callback); // re-expand
currItem.setExpanded(true); currItem.setExpanded(true);
} else // hmm, item was not expanded so just flush its memory } else // hmm, item was not expanded so just flush its memory
{ {
@ -3657,6 +3762,7 @@ public class SystemView extends SafeTreeViewer
} }
} }
// for non-deferred queries
// 2. expand each previously expanded sub-node, recursively // 2. expand each previously expanded sub-node, recursively
for (int idx = 0; idx < expandedChildren.size(); idx++) { for (int idx = 0; idx < expandedChildren.size(); idx++) {
@ -3664,17 +3770,10 @@ public class SystemView extends SafeTreeViewer
if (itemToExpand.isRemote()) { if (itemToExpand.isRemote()) {
// find remote item based on its original name and unchanged root parent // find remote item based on its original name and unchanged root parent
Item item = null; Item item = null;
//if (itemToExpand.parentItem != null)
//item = (Item)recursiveFindRemoteItem(itemToExpand.parentItem, itemToExpand.remoteName, itemToExpand.subsystem);
//else
//item = (Item)findRemoteItem(itemToExpand.remoteName, itemToExpand.subsystem);
//************************************************************/// // for deferred queries, we handle this via a callback
// FIXME!!
// TODO
// DKM - problem here is that if a query is in progress, then we won't find it until the deferred query completes
item = findFirstRemoteItemReference(itemToExpand.remoteName, itemToExpand.subsystem, itemToExpand.parentItem); item = findFirstRemoteItemReference(itemToExpand.remoteName, itemToExpand.subsystem, itemToExpand.parentItem);
//************************************************************///
// if found, re-expand it // if found, re-expand it
if (item != null) { if (item != null) {
//setExpanded(item, true); //setExpanded(item, true);
@ -3696,16 +3795,9 @@ public class SystemView extends SafeTreeViewer
smartRefresh(element, true); smartRefresh(element, true);
} }
/**
* Do an intelligent refresh of the given element. Can be null for full refresh
*/ protected ArrayList getExpandedChildren(TreeItem[] roots){
protected void smartRefresh(Object element, boolean forceRemote) {
if ((element == null) || (element == getInput())) {
// fullRefresh
Tree tree = getTree();
TreeItem[] roots = tree.getItems();
boolean anyExpanded = false;
areAnyRemote = false; // set in ExpandedItem constructor
ArrayList expandedChildren = new ArrayList(); ArrayList expandedChildren = new ArrayList();
for (int idx = 0; idx < roots.length; idx++) { for (int idx = 0; idx < roots.length; idx++) {
TreeItem currItem = roots[idx]; TreeItem currItem = roots[idx];
@ -3717,13 +3809,27 @@ public class SystemView extends SafeTreeViewer
setExpandedState(data, false); setExpandedState(data, false);
} }
else { else {
//setExpanded(roots[idx], false);
expandedChildren.add(new ExpandedItem(null, currItem)); expandedChildren.add(new ExpandedItem(null, currItem));
}
}
}
return expandedChildren;
}
/**
* Do an intelligent refresh of the given element. Can be null for full refresh
*/
protected void smartRefresh(Object element, boolean forceRemote) {
if ((element == null) || (element == getInput())) {
// fullRefresh
Tree tree = getTree();
TreeItem[] roots = tree.getItems();
boolean anyExpanded = false;
areAnyRemote = false; // set in ExpandedItem constructor
ArrayList expandedChildren = getExpandedChildren(roots);
if (expandedChildren.size() > 0)
anyExpanded = true; anyExpanded = true;
//gatherExpandedChildren(currItem, currItem, expandedChildren);
}
}
}
if (!anyExpanded) if (!anyExpanded)
super.refresh(); super.refresh();
else { else {
@ -6105,13 +6211,14 @@ public class SystemView extends SafeTreeViewer
public void add(Object parentElementOrTreePath, Object[] childElements) { public void add(Object parentElementOrTreePath, Object[] childElements) {
assertElementsNotNull(childElements); assertElementsNotNull(childElements);
IContextObject contextObject = null;
ISystemFilterReference originalFilter = null; ISystemFilterReference originalFilter = null;
if (parentElementOrTreePath instanceof IContextObject) if (parentElementOrTreePath instanceof IContextObject)
{ {
IContextObject context = (IContextObject)parentElementOrTreePath; contextObject = (IContextObject)parentElementOrTreePath;
originalFilter = context.getFilterReference(); originalFilter = contextObject.getFilterReference();
parentElementOrTreePath = context.getModelObject(); parentElementOrTreePath = contextObject.getModelObject();
} }
List matches = new Vector(); List matches = new Vector();
@ -6178,8 +6285,8 @@ public class SystemView extends SafeTreeViewer
Object[] newChildren = null; Object[] newChildren = null;
if (match instanceof TreeItem) if (match instanceof TreeItem)
{ {
IContextObject contextObject = getContextObject((TreeItem)match); IContextObject context = getContextObject((TreeItem)match);
newChildren = adapter.getChildren(contextObject, new NullProgressMonitor()); newChildren = adapter.getChildren(context, new NullProgressMonitor());
internalAdd(match, parentElementOrTreePath, newChildren); internalAdd(match, parentElementOrTreePath, newChildren);
} }
} }
@ -6236,7 +6343,14 @@ public class SystemView extends SafeTreeViewer
} }
} }
// for bug 187739
if (contextObject instanceof ContextObjectWithViewer) {
ContextObjectWithViewer ctx = (ContextObjectWithViewer)contextObject;
IRSECallback cb = ctx.getCallback();
if (cb!=null) {
cb.done(Status.OK_STATUS, childElements);
}
}
} }
@ -6320,18 +6434,18 @@ public class SystemView extends SafeTreeViewer
ISystemFilterReference filterReference = getContainingFilterReference(item); ISystemFilterReference filterReference = getContainingFilterReference(item);
if (filterReference != null) if (filterReference != null)
{ {
return new ContextObject(data, filterReference.getSubSystem(), filterReference); return new ContextObjectWithViewer(data, filterReference.getSubSystem(), filterReference, this);
} }
else else
{ {
ISubSystem subSystem = getContainingSubSystem(item); ISubSystem subSystem = getContainingSubSystem(item);
if (subSystem != null) if (subSystem != null)
{ {
return new ContextObject(data, subSystem); return new ContextObjectWithViewer(data, subSystem, this);
} }
else else
{ {
return new ContextObject(data); return new ContextObjectWithViewer(data, this);
} }
} }
} }
@ -6365,10 +6479,9 @@ public class SystemView extends SafeTreeViewer
} }
/** /**
* Overridden so that we can pass a wrapper IContextObject into the provider to get children instead * For bug 187739
* of the model object, itself
*/ */
protected void createChildren(final Widget widget) protected void createChildren(final Widget widget, IRSECallback callback)
{ {
if (widget instanceof TreeItem) if (widget instanceof TreeItem)
{ {
@ -6379,6 +6492,7 @@ public class SystemView extends SafeTreeViewer
return; // children already there! return; // children already there!
} }
} }
final IRSECallback cb = callback;
BusyIndicator.showWhile(widget.getDisplay(), new Runnable() { BusyIndicator.showWhile(widget.getDisplay(), new Runnable() {
public void run() { public void run() {
@ -6399,6 +6513,10 @@ public class SystemView extends SafeTreeViewer
if (d != null) if (d != null)
{ {
Object parentElement = getContextObject((TreeItem)widget); Object parentElement = getContextObject((TreeItem)widget);
if (cb != null && parentElement instanceof ContextObjectWithViewer){
((ContextObjectWithViewer)parentElement).setCallback(cb);
}
Object[] children = getSortedChildren(parentElement); Object[] children = getSortedChildren(parentElement);
if (children != null) if (children != null)
{ {
@ -6418,6 +6536,15 @@ public class SystemView extends SafeTreeViewer
} }
} }
/**
* Overridden so that we can pass a wrapper IContextObject into the provider to get children instead
* of the model object, itself
*/
protected void createChildren(final Widget widget)
{
createChildren(widget, null);
}
/** /**
* Override to pass context into hasChildren() * Override to pass context into hasChildren()
* *

View file

@ -10,7 +10,7 @@
* component that contains this file: David McKnight. * component that contains this file: David McKnight.
* *
* Contributors: * Contributors:
* {Name} (company) - description of contribution. * David McKnight (IBM) - [187739] [refresh] Sub Directories are collapsed when Parent Directory is Refreshed on Remote Systems
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.ui.view; package org.eclipse.rse.ui.view;
@ -26,6 +26,10 @@ import org.eclipse.rse.core.subsystems.ISubSystem;
* Context objects are created transiently and are only used to aid in providing filter information * Context objects are created transiently and are only used to aid in providing filter information
* during a query. * during a query.
* *
* @noimplement - Extending or implementing this interface in client code is
strongly discouraged, may break your code in a future major release,
and will likely lead to degradation of RSE behavior.
*
*/ */
public interface IContextObject public interface IContextObject
{ {