1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

[187711] do the queries in jobs to avoid main thread

This commit is contained in:
David McKnight 2008-01-03 18:42:17 +00:00
parent 39ecf75e4d
commit 30555b1db5
8 changed files with 420 additions and 48 deletions

View file

@ -260,6 +260,13 @@ public class FileResources extends NLS
public static String MESSAGE_ERROR_CACHING_REMOTE_FILES;
public static String MESSAGE_SYNCHRONIZING_REMOTE_FILE_CACHE;
// link with editor
public static String MESSAGE_EXPANDING_FOLDER;
public static String MESSAGE_EXPANDING_FILTER;
public static String MESSSAGE_QUERYING_FILE;
static
{
// load message values from bundle file

View file

@ -254,3 +254,11 @@ MESSAGE_ENCODING_NOT_SUPPORTED=The selected encoding is not supported.
#=============================================================
MESSAGE_ERROR_CACHING_REMOTE_FILES=Error Caching Remote Files
MESSAGE_SYNCHRONIZING_REMOTE_FILE_CACHE=Remote File Cache Synchronizing Remote File Cache
#=============================================================
# Link with Editor...
#=============================================================
MESSAGE_EXPANDING_FOLDER=Expanding Folder...
MESSAGE_EXPANDING_FILTER=Expanding Filter...
MESSSAGE_QUERYING_FILE=Querying File...

View file

@ -13,17 +13,30 @@
********************************************************************************/
package org.eclipse.rse.internal.files.ui.actions;
import java.util.Vector;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.internal.ui.view.SystemView;
import org.eclipse.rse.core.filters.ISystemFilterPoolReferenceManager;
import org.eclipse.rse.core.filters.ISystemFilterReference;
import org.eclipse.rse.internal.files.ui.FileResources;
import org.eclipse.rse.internal.ui.view.SystemViewPart;
import org.eclipse.rse.subsystems.files.core.SystemIFileProperties;
import org.eclipse.rse.ui.IViewLinker;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
import org.eclipse.rse.ui.view.ContextObject;
import org.eclipse.rse.ui.view.ISystemEditableRemoteObject;
import org.eclipse.rse.ui.view.ISystemTree;
import org.eclipse.rse.ui.view.ISystemViewElementAdapter;
import org.eclipse.rse.ui.view.IViewLinker;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
@ -33,9 +46,247 @@ import org.eclipse.ui.IViewPart;
public class LinkWithSystemViewAction implements IViewActionDelegate {
/**
* Main thread runnable used to create tree items in system view and look for the target remote file
* item in the tree. If the remote file item is not found, then this indirectly recurses via a new
* LinkFromFolderJob.
*/
private class ShowChildrenInTree implements Runnable
{
private Object _parentObject;
private Object[] _children;
private ISystemTree _systemTree;
private IRemoteFile _targetRemoteFile;
private ISystemFilterReference _filterReference;
public ShowChildrenInTree(Object parentObject, Object[] children, ISystemFilterReference filterReference, ISystemTree systemTree, IRemoteFile targetRemoteFile)
{
_parentObject = parentObject;
_children = children;
_systemTree = systemTree;
_targetRemoteFile = targetRemoteFile;
_filterReference = filterReference;
}
public void run()
{
// make sure the filter is expanded
_systemTree.revealAndExpand(_filterReference.getSubSystem(), _filterReference.getReferencedFilter());
Vector matches = new Vector();
_systemTree.findAllRemoteItemReferences(_parentObject, _parentObject, matches);
if (matches.size() > 0){
TreeItem item = (TreeItem)matches.get(0);
_systemTree.createTreeItems(item, _children);
item.setExpanded(true);
IRemoteFile containingFolder = null;
// is one of these items our remote file?
for (int i = 0; i < item.getItemCount(); i++){
TreeItem childItem = item.getItem(i);
Object data = childItem.getData();
if (data instanceof IRemoteFile){
IRemoteFile childFile = (IRemoteFile)data;
String childPath = childFile.getAbsolutePath();
if (childPath.equals(_targetRemoteFile.getAbsolutePath())){
// select our remote file
_systemTree.getTree().setSelection(childItem);
return; // we're done!
}
else if (_targetRemoteFile.getAbsolutePath().startsWith(childPath)){
containingFolder = childFile; // using this to start a deeper search for the target remote file
}
}
}
// remote file not found so now we have to expand further
if (containingFolder != null){
LinkFromFolderJob job = new LinkFromFolderJob(containingFolder, _filterReference, _targetRemoteFile, _systemTree);
job.schedule();
}
}
}
}
/**
* Job for doing a query on a folder and then using Display.asyncExec() to reveal the results in the tree.
*/
private class LinkFromFolderJob extends Job
{
private IRemoteFileSubSystem _subSystem;
private IRemoteFile _remoteFolder;
private IRemoteFile _targetRemoteFile;
private ISystemTree _systemTree;
private ISystemFilterReference _filterRef;
public LinkFromFolderJob(IRemoteFile remoteFolder, ISystemFilterReference filterRef, IRemoteFile targetRemoteFile, ISystemTree systemTree) {
super(FileResources.MESSAGE_EXPANDING_FOLDER);
_remoteFolder = remoteFolder;
_subSystem = _remoteFolder.getParentRemoteFileSubSystem();
_filterRef = filterRef; // used for context of query
_targetRemoteFile = targetRemoteFile;
_systemTree = systemTree;
}
public IStatus run(IProgressMonitor monitor){
try
{
// get the adapter
ISystemViewElementAdapter adapter = (ISystemViewElementAdapter)((IAdaptable)_remoteFolder).getAdapter(ISystemViewElementAdapter.class);
// get the context
ContextObject contextObject = new ContextObject(_remoteFolder, _subSystem, _filterRef);
// get the children
Object[] children = adapter.getChildren(contextObject, monitor);
if (monitor.isCanceled()){
return Status.CANCEL_STATUS;
}
// put these items in the tree and look for remoteFile
// if we can't find the remote file under this filter, the ShowChildrenInTree will recurse
Display.getDefault().asyncExec(new ShowChildrenInTree(_remoteFolder, children, _filterRef, _systemTree, _targetRemoteFile));
}
catch (Exception e){
}
return Status.OK_STATUS;
}
}
/**
* Job for doing a query on a filter and then using Display.asyncExec() to reveal the results in the tree.
*/
private class LinkFromFilterJob extends Job
{
private IRemoteFileSubSystem _subSystem;
private IRemoteFile _targetRemoteFile;
private ISystemTree _systemTree;
public LinkFromFilterJob(IRemoteFile targetRemoteFile, ISystemTree systemTree) {
super(FileResources.MESSAGE_EXPANDING_FILTER);
_targetRemoteFile = targetRemoteFile;
_subSystem = _targetRemoteFile.getParentRemoteFileSubSystem();
_systemTree = systemTree;
}
public IStatus run(IProgressMonitor monitor){
try
{
// find matching filter reference
ISystemFilterReference ref = findMatchingFilterReference();
if (ref == null)
{
// the object is nowhere to be found!
return Status.OK_STATUS;
}
// get the adapter
ISystemViewElementAdapter adapter = (ISystemViewElementAdapter)((IAdaptable)ref).getAdapter(ISystemViewElementAdapter.class);
// get the context
ContextObject contextObject = new ContextObject(ref, _subSystem, ref);
// get the children
Object[] children = adapter.getChildren(contextObject, monitor);
if (monitor.isCanceled()){
return Status.CANCEL_STATUS;
}
// put these items in the tree and look for remoteFile
// if we can't find the remote file under this filter, the ShowChildrenInTree will recurse
Display.getDefault().asyncExec(new ShowChildrenInTree(ref, children, ref, _systemTree, _targetRemoteFile));
}
catch (Exception e){
}
return Status.OK_STATUS;
}
private ISystemFilterReference findMatchingFilterReference()
{
String remoteObjectName = _targetRemoteFile.getAbsolutePath();
ISystemFilterPoolReferenceManager refmgr = _subSystem.getFilterPoolReferenceManager();
if (refmgr != null)
{
ISystemFilterReference[] refs = refmgr.getSystemFilterReferences(_subSystem);
for (int i = 0; i < refs.length; i++)
{
ISystemFilterReference ref = refs[i];
{
if (_subSystem.doesFilterMatch(ref.getReferencedFilter(), remoteObjectName)){
return ref;
}
else if (_subSystem.doesFilterListContentsOf(ref.getReferencedFilter(),remoteObjectName)){
return ref;
}
else if (_subSystem.doesFilterEncompass(ref.getReferencedFilter(), remoteObjectName)){
return ref;
}
}
}
}
return null;
}
}
/**
* Job for doing a query on a file. After the query it checks for the file in the tree on the main thread. If the item
* is not found, then a search is started from the first matching filter via the LinkFromFilterJob.
*/
private class SelectFileJob extends Job
{
private IRemoteFileSubSystem _subSystem;
private String _path;
private ISystemTree _systemTree;
public SelectFileJob(IRemoteFileSubSystem subSystem, String path, ISystemTree systemTree) {
super(FileResources.MESSSAGE_QUERYING_FILE);
_subSystem = subSystem;
_path = path;
_systemTree = systemTree;
}
public IStatus run(IProgressMonitor monitor){
try
{
// doing query to get the remote file
final IRemoteFile remoteFile = _subSystem.getRemoteFileObject(_path, monitor);
Display.getDefault().asyncExec(new Runnable()
{
public void run()
{
// on main thread, looking for the reference in the tree
TreeItem item = (TreeItem)_systemTree.findFirstRemoteItemReference(remoteFile, null);
if (item != null){
_systemTree.getTree().setSelection(item);
}
else
{
// no reference in the tree so we will search forward from the filter in a job (avoiding query on the main thread)
LinkFromFilterJob job = new LinkFromFilterJob(remoteFile, _systemTree);
job.schedule();
}
}
});
}
catch (Exception e){
}
return Status.OK_STATUS;
}
}
public class ViewLinker implements IViewLinker
{
public void link(IEditorPart editor, SystemView systemView)
public void link(IEditorPart editor, ISystemTree systemTree)
{
IEditorInput input = editor.getEditorInput();
if (input instanceof IFileEditorInput)
@ -46,13 +297,27 @@ public class LinkWithSystemViewAction implements IViewActionDelegate {
IFile file = fileInput.getFile();
SystemIFileProperties properties = new SystemIFileProperties(file);
Object rmtEditable = properties.getRemoteFileObject();
Object remoteObj = null;
ISubSystem subSystem = null;
IRemoteFile remoteObj = null;
IRemoteFileSubSystem subSystem = null;
if (rmtEditable != null && rmtEditable instanceof ISystemEditableRemoteObject)
{
ISystemEditableRemoteObject editable = (ISystemEditableRemoteObject) rmtEditable;
remoteObj = editable.getRemoteObject();
remoteObj = (IRemoteFile)editable.getRemoteObject();
TreeItem item = (TreeItem)systemTree.findFirstRemoteItemReference(remoteObj, null);
if (item != null){
systemTree.getTree().setSelection(item);
}
else
{
subSystem = remoteObj.getParentRemoteFileSubSystem();
// no match, so we will expand from filter
// query matching filter in a job (to avoid main thread)
LinkFromFilterJob job = new LinkFromFilterJob(remoteObj, systemTree);
job.schedule();
}
}
else
{
@ -60,45 +325,30 @@ public class LinkWithSystemViewAction implements IViewActionDelegate {
String path = properties.getRemoteFilePath();
if (subsystemId != null && path != null)
{
subSystem = RSECorePlugin.getTheSystemRegistry().getSubSystem(subsystemId);
subSystem = (IRemoteFileSubSystem)RSECorePlugin.getTheSystemRegistry().getSubSystem(subsystemId);
if (subSystem != null)
{
if (subSystem.isConnected())
{
try
{
remoteObj = subSystem.getObjectWithAbsoluteName(path, new NullProgressMonitor());
}
catch (Exception e)
{
return;
// query for file in a job (to avoid main thread)
SelectFileJob job = new SelectFileJob(subSystem, path, systemTree);
job.schedule();
}
}
}
}
}
if (remoteObj != null)
{
TreeItem item = (TreeItem)systemView.findFirstRemoteItemReference(remoteObj, null);
if (item != null){
systemView.getTree().setSelection(item);
}
else {
// item does not exist in tree
systemView.expandTo(subSystem, remoteObj);
}
}
}
}
}
private SystemViewPart _systemViewPart;
private IAction _action;
private IViewLinker _linker;
public LinkWithSystemViewAction()
{
super();
}
public void init(IViewPart view) {
_systemViewPart = (SystemViewPart)view;
_linker = new ViewLinker();
@ -106,16 +356,16 @@ public class LinkWithSystemViewAction implements IViewActionDelegate {
public void run(IAction action) {
if (_systemViewPart != null){
_systemViewPart.setLinkingEnabled(action.isChecked(), _linker);
boolean isToggled = _systemViewPart.isLinkingEnabled();
_systemViewPart.setLinkingEnabled(!isToggled, _linker);
}
}
public void selectionChanged(IAction action, ISelection selection) {
if (_action == null) {
action.setChecked(_systemViewPart.isLinkingEnabled());
_action= action;
_action.setChecked(_systemViewPart.isLinkingEnabled());
}
}
}

View file

@ -4273,7 +4273,7 @@ public class SystemView extends SafeTreeViewer
* @return the List populated with hits, or <code>null</code> if <code>null</code>
* was passed in as the List to populate and no hits were found.
*/
protected List findAllRemoteItemReferences(Object element, Object elementObject, List matches) {
public List findAllRemoteItemReferences(Object element, Object elementObject, List matches) {
String searchString = null;
ISubSystem subsystem = null;
if (element instanceof String)
@ -5689,7 +5689,11 @@ public class SystemView extends SafeTreeViewer
ISystemViewElementAdapter adapter = getViewAdapter(parentObject);
ISystemViewElementAdapter targetAdapter = getViewAdapter(remoteObject);
if (adapter == null)
{
System.out.println("adapter is null for "+parentObject);
return;
}
ISubSystem ss = adapter.getSubSystem(parentObject);
String parentName = adapter.getAbsoluteName(parentObject);
String remoteObjectName = targetAdapter.getAbsoluteName(remoteObject);
@ -5953,6 +5957,7 @@ public class SystemView extends SafeTreeViewer
public void add(Object parentElementOrTreePath, Object[] childElements) {
assertElementsNotNull(childElements);
ISystemFilterReference originalFilter = null;

View file

@ -14,9 +14,10 @@
* Contributors:
* Kevin Doyle (IBM) - [187553] - Removed code and related methods for toolbar/button bar.
* Martin Oberhuber (Wind River) - [190271] Move ISystemViewInputProvider to Core
* David McKnight (IBM) - [187711] select SystemView APIs exposed by the ISystemTree interface
*******************************************************************************/
package org.eclipse.rse.internal.ui.view;
import java.util.List;
import java.util.Vector;
import org.eclipse.jface.action.ToolBarManager;
@ -24,7 +25,10 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.rse.core.filters.ISystemFilter;
import org.eclipse.rse.core.filters.ISystemFilterReference;
import org.eclipse.rse.core.model.ISystemViewInputProvider;
import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.ui.dialogs.SystemPromptDialog;
import org.eclipse.rse.ui.messages.ISystemMessageLine;
import org.eclipse.rse.ui.view.ISystemLongRunningRequestListener;
@ -42,6 +46,7 @@ import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
/**
@ -470,4 +475,44 @@ public class SystemViewForm extends Composite implements ISystemTree
}
}
/**
* wrapper method to satisfy the ISystemTree interface
*/
public void createTreeItems(TreeItem widget, Object[] children)
{
tree.createTreeItems(widget, children);
}
/**
* wrapper method to satisfy the ISystemTree interface
*/
public List findAllRemoteItemReferences(Object element,
Object elementObject, List matches) {
return tree.findAllRemoteItemReferences(element, elementObject, matches);
}
/**
* wrapper method to satisfy the ISystemTree interface
*/
public Item findFirstRemoteItemReference(Object remoteObject,
Item parentItem) {
return tree.findFirstRemoteItemReference(remoteObject, parentItem);
}
/**
* wrapper method to satisfy the ISystemTree interface
*/
public Tree getTree() {
return tree.getTree();
}
/**
* wrapper method to satisfy the ISystemTree interface
*/
public ISystemFilterReference revealAndExpand(ISubSystem parentSubSystem,
ISystemFilter filter) {
return tree.revealAndExpand(parentSubSystem, filter);
}
}

View file

@ -87,7 +87,6 @@ import org.eclipse.rse.internal.ui.actions.SystemWorkWithProfilesAction;
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
import org.eclipse.rse.ui.ISystemContextMenuConstants;
import org.eclipse.rse.ui.ISystemPreferencesConstants;
import org.eclipse.rse.ui.IViewLinker;
import org.eclipse.rse.ui.RSESystemTypeAdapter;
import org.eclipse.rse.ui.RSEUIPlugin;
import org.eclipse.rse.ui.SystemBasePlugin;
@ -103,6 +102,7 @@ import org.eclipse.rse.ui.view.ContextObject;
import org.eclipse.rse.ui.view.IRSEViewPart;
import org.eclipse.rse.ui.view.ISystemRemoteElementAdapter;
import org.eclipse.rse.ui.view.ISystemViewElementAdapter;
import org.eclipse.rse.ui.view.IViewLinker;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;

View file

@ -11,12 +11,19 @@
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
* David McKnight (IBM) - [187711] Select SystemView APIs exposed by the ISystemTree interface
********************************************************************************/
package org.eclipse.rse.ui.view;
import java.util.List;
import org.eclipse.rse.core.filters.ISystemFilter;
import org.eclipse.rse.core.filters.ISystemFilterReference;
import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
/**
* To drive our GUI we find ourselves adding additional useful methods on top of the
@ -116,4 +123,55 @@ public interface ISystemTree {
* @return true if any of the selected items are expandable but not yet expanded
*/
public boolean areAnySelectedItemsExpandable();
/**
* Find the first binary-match or name-match of a remote object, given its binary object.
* @param remoteObject - The remote object to find.
* @param parentItem - Optionally, the parent item to start the search at
* @return TreeItem hit if found
*/
public Item findFirstRemoteItemReference(Object remoteObject, Item parentItem);
/**
* Expand a given filter, given a subsystem that contains a reference to the filter's pool.
* This will expand down to the filter if needed
* @param parentSubSystem - the subsystem containing a reference to the filter's parent pool
* @param filter - the filter to find, reveal, and expand within the subsystem context
* @return the filter reference to the filter if found and expanded. This is a unique binary address
* within the object's in this tree, so can be used in the viewer methods to affect this particular
* node.
*/
public ISystemFilterReference revealAndExpand(ISubSystem parentSubSystem, ISystemFilter filter);
/**
* Return the Tree widget
* @return tree widget
*/
public Tree getTree();
/**
* Create tree items for the specified children
*
* @param widget the parent item for the items to create
* @param children the children to create items for
*/
public void createTreeItems(TreeItem widget, Object[] children);
/**
* Recursively tries to find a given remote object. Since the object memory object
* for a remote object is not dependable we call getAbsoluteName() on the adapter to
* do the comparisons. Note this does not take into account the parent connection or
* subsystem or filter, hence you must know where to start the search, else you risk
* finding the wrong one.
*
* @param element the remote object to which we want to find a tree item which references it. Can be a string or an object
* @param elementObject the actual remote element to find, for binary matching, optionally for cases when element is a string
* @param matches the List to populate with hits, or <code>null</code> to
* get a new List created and returned with the hits.
* @return the List populated with hits, or <code>null</code> if <code>null</code>
* was passed in as the List to populate and no hits were found.
*/
public List findAllRemoteItemReferences(Object element, Object elementObject, List matches);
}

View file

@ -11,9 +11,8 @@
* Contributors:
* David McKnight (IBM) - [187711] IViewLinker to be API that system view part calls when link with editor
********************************************************************************/
package org.eclipse.rse.ui;
package org.eclipse.rse.ui.view;
import org.eclipse.rse.internal.ui.view.SystemView;
import org.eclipse.ui.IEditorPart;
public interface IViewLinker {
@ -21,7 +20,7 @@ public interface IViewLinker {
/**
* System View part calls link when using Link With Editor. Provider of action supplies this implementation.
* @param editor the active editor
* @param systemView the view to link
* @param systemTree the view to link
*/
public void link(IEditorPart editor, SystemView systemView);
public void link(IEditorPart editor, ISystemTree systemTree);
}