From b3b23b3c5e2e1587fec182e610bf83560467f2a1 Mon Sep 17 00:00:00 2001 From: Jean Michel-Lemieux Date: Wed, 5 Jun 2002 16:30:05 +0000 Subject: Bug 18349: TM: IRemoteTargetResource - cache getSize, getModification Bug 18903: Assertion failure while creating new site in site explorer Added progress monitoring support into model elements and hooked the site explorer into the workbench's progress monitor. --- .../internal/ui/target/MappingSelectionPage.java | 2 +- .../internal/ui/target/RemoteResourceElement.java | 53 +++++++++------------- .../team/internal/ui/target/SiteElement.java | 6 +++ .../team/internal/ui/target/SiteExplorerView.java | 49 ++++++++++++-------- .../team/internal/ui/target/SiteRootsElement.java | 23 +++------- .../team/internal/ui/target/SiteSelectionPage.java | 2 +- 6 files changed, 68 insertions(+), 67 deletions(-) (limited to 'bundles') diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/MappingSelectionPage.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/MappingSelectionPage.java index 3e4fce861..8d3865f9c 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/MappingSelectionPage.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/MappingSelectionPage.java @@ -175,7 +175,7 @@ public class MappingSelectionPage extends TargetWizardPage { private void setViewerInput() { if(this.site == null || viewer == null) return; - viewer.setInput(new SiteRootsElement(new Site[] {site})); + viewer.setInput(new SiteRootsElement(new Site[] {site}, getContainer())); } /** diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/RemoteResourceElement.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/RemoteResourceElement.java index 83b3c50ce..d7d474b71 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/RemoteResourceElement.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/RemoteResourceElement.java @@ -16,6 +16,8 @@ import java.util.List; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.action.IStatusLineManager; +import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.operation.ModalContext; import org.eclipse.jface.resource.ImageDescriptor; @@ -49,14 +51,18 @@ public class RemoteResourceElement implements IWorkbenchAdapter, IAdaptable { private int size = 0; private String lastModified = null; - // embeded progress monitoring support - private Shell shell; - private IProgressMonitor monitor; + // context in which to perform long-running operations + private IRunnableContext runContext; public RemoteResourceElement(IRemoteTargetResource remote) { this.remote = remote; } + public RemoteResourceElement(IRemoteTargetResource remote, IRunnableContext runContext) { + this(remote); + this.runContext = runContext; + } + public IRemoteTargetResource getRemoteResource() { return remote; } @@ -72,26 +78,23 @@ public class RemoteResourceElement implements IWorkbenchAdapter, IAdaptable { IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { - monitor.beginTask(null, 100); + // progress for fetching remote children is always unknown + // let's not bother even trying to guess. + monitor.beginTask(null, IProgressMonitor.UNKNOWN); if(children == null) { setCachedChildren(remote.members(Policy.subMonitorFor(monitor, 50))); } List remoteElements = new ArrayList(); for (int i = 0; i < children.length; i++) { IRemoteTargetResource child = (IRemoteTargetResource)children[i]; - RemoteResourceElement element = new RemoteResourceElement(child); - - // setup progress monitors - element.setShell(shell); - element.setProgressMonitor(monitor); - - // decide which children to return based on filter settings - element.setLastModified(child.getLastModified(Policy.subMonitorFor(monitor, 25))); + RemoteResourceElement element = new RemoteResourceElement(child, runContext); + // cache size and last modified + element.setLastModified(child.getLastModified(Policy.subMonitorFor(monitor, 25))); element.setSize(child.getSize(Policy.subMonitorFor(monitor, 25))); remoteElements.add(element); - } - result[0] = (RemoteResourceElement[])remoteElements.toArray(new RemoteResourceElement[remoteElements.size()]); + } + result[0] = (RemoteResourceElement[])remoteElements.toArray(new RemoteResourceElement[remoteElements.size()]); } catch (TeamException e) { throw new InvocationTargetException(e); } finally { @@ -100,7 +103,11 @@ public class RemoteResourceElement implements IWorkbenchAdapter, IAdaptable { } }; - TeamUIPlugin.runWithProgress(null, true /*cancelable*/, runnable); + if(runContext == null) { + TeamUIPlugin.runWithProgress(null, true /*cancelable*/, runnable); + } else { + runContext.run(true, true, runnable); + } } catch (InterruptedException e) { return new Object[0]; } catch (InvocationTargetException e) { @@ -155,22 +162,6 @@ public class RemoteResourceElement implements IWorkbenchAdapter, IAdaptable { this.remote = remote; } - public void setShell(Shell shell) { - this.shell = shell; - } - - public void setProgressMonitor(IProgressMonitor monitor) { - this.monitor = monitor; - } - - public Shell getShell() { - return shell; - } - - public IProgressMonitor getProgressMonitor() { - return monitor; - } - public String getLastModified() { return lastModified; } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteElement.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteElement.java index 91f37eaed..84d27d820 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteElement.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteElement.java @@ -15,6 +15,7 @@ import java.lang.reflect.InvocationTargetException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.ImageDescriptor; @@ -40,6 +41,11 @@ public class SiteElement extends RemoteResourceElement { this.site = site; } + public SiteElement(Site site, IRunnableContext runContext) { + super(null, runContext); + this.site = site; + } + public Site getSite() { return site; } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteExplorerView.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteExplorerView.java index a5fbb287c..aa4ae7e4d 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteExplorerView.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteExplorerView.java @@ -69,6 +69,9 @@ import org.eclipse.ui.part.ViewPart; * Is a view that allows browsing remote target sites. It is modeled after * a file explorer: a tree of folders is show with a table of the folder's * contents. + *

+ * Progress is shown in the main workbench window's status line progress + * monitor.

* * @see Site * @see IRemoteTargetResource @@ -109,8 +112,8 @@ public class SiteExplorerView extends ViewPart implements ISiteListener { // column headings: "Name" "Size" "Modified" private int[][] SORT_ORDERS_BY_COLUMN = { - {NAME, SIZE, MODIFIED}, /* name */ - {SIZE, NAME, MODIFIED}, /* size */ + {NAME}, /* name */ + {SIZE, NAME}, /* size */ {MODIFIED, NAME, SIZE}, /* modified */ }; @@ -155,7 +158,7 @@ public class SiteExplorerView extends ViewPart implements ISiteListener { } protected int compareNames(IRemoteTargetResource resource1, IRemoteTargetResource resource2) { - return collator.compare(resource1.getName(), resource2.getName()); + return resource1.getName().compareTo(resource2.getName()); } /** @@ -328,8 +331,10 @@ public class SiteExplorerView extends ViewPart implements ISiteListener { sash.setWeights(new int[] {33, 67}); TargetManager.addSiteListener(this); - initializeTreeInput(); + + root = new SiteRootsElement(getViewSite().getWorkbenchWindow()); initalizeActions(); + folderTree.setInput(root); } private Shell getShell() { @@ -399,7 +404,7 @@ public class SiteExplorerView extends ViewPart implements ISiteListener { Object currentSelection = selection.getFirstElement(); RemoteResourceElement selectedFolder; - if(selection.isEmpty()) { + if(!selection.isEmpty()) { selectedFolder = getSelectedRemoteFolder(selection)[0]; } else { selectedFolder = (RemoteResourceElement)folderContentsTable.getInput(); @@ -408,9 +413,12 @@ public class SiteExplorerView extends ViewPart implements ISiteListener { IRemoteTargetResource newFolder = CreateNewFolderAction.createDir(shell, selectedFolder.getRemoteResource(), Policy.bind("CreateNewFolderAction.newFolderName")); if (newFolder == null) return; + + // force a refresh selectedFolder.setCachedChildren(null); + + // select the newly added folder RemoteResourceElement newFolderUIElement = new RemoteResourceElement(newFolder); - folderTree.refresh(currentSelection); expandInTreeCurrentSelection(new StructuredSelection(currentSelection), false); folderTree.setSelection(new StructuredSelection(newFolderUIElement)); @@ -459,13 +467,20 @@ public class SiteExplorerView extends ViewPart implements ISiteListener { } /** + * Add the new site to the viewer and make it the current selection. + * * @see ISiteListener#siteAdded(Site) */ public void siteAdded(Site site) { - initializeTreeInput(); + SiteElement element = new SiteElement(site, getViewSite().getWorkbenchWindow()); + folderTree.add(root, element); + folderTree.setSelection(new StructuredSelection(element)); } /** + * Remote the site from the viewer and select the next site in the + * tree. + * * @see ISiteListener#siteRemoved(Site) */ public void siteRemoved(Site site) { @@ -482,11 +497,6 @@ public class SiteExplorerView extends ViewPart implements ISiteListener { } } - private void initializeTreeInput() { - root = new SiteRootsElement(TargetManager.getSites()); - folderTree.setInput(root); - } - /** * Adds the listener that sets the sorter. */ @@ -510,13 +520,16 @@ public class SiteExplorerView extends ViewPart implements ISiteListener { */ public void widgetSelected(SelectionEvent e) { // column selected - need to sort + // only allow sorting on name for now int column = folderContentsTable.getTable().indexOf((TableColumn) e.widget); - FolderListingSorter oldSorter = (FolderListingSorter)folderContentsTable.getSorter(); - if (oldSorter != null && column == oldSorter.getColumnNumber()) { - oldSorter.setReversed(!oldSorter.isReversed()); - folderContentsTable.refresh(); - } else { - folderContentsTable.setSorter(new FolderListingSorter(column)); + if(column == FolderListingSorter.NAME) { + FolderListingSorter oldSorter = (FolderListingSorter)folderContentsTable.getSorter(); + if (oldSorter != null && column == oldSorter.getColumnNumber()) { + oldSorter.setReversed(!oldSorter.isReversed()); + folderContentsTable.refresh(); + } else { + folderContentsTable.setSorter(new FolderListingSorter(column)); + } } } }; diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteRootsElement.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteRootsElement.java index 0074fdbc9..6e166ee77 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteRootsElement.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteRootsElement.java @@ -12,6 +12,7 @@ package org.eclipse.team.internal.ui.target; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.widgets.Shell; import org.eclipse.team.core.target.Site; @@ -25,15 +26,15 @@ public class SiteRootsElement implements IWorkbenchAdapter, IAdaptable { private Site[] sites = null; // progress monitoring support - private IProgressMonitor monitor; - private Shell shell; + private IRunnableContext runContext; - public SiteRootsElement(Site[] sites) { + public SiteRootsElement(Site[] sites, IRunnableContext runContext) { this.sites = sites; + this.runContext = runContext; } - public SiteRootsElement() { - this.sites = null; + public SiteRootsElement(IRunnableContext runContext) { + this(null, runContext); } public ImageDescriptor getImageDescriptor(Object object) { @@ -49,21 +50,11 @@ public class SiteRootsElement implements IWorkbenchAdapter, IAdaptable { } SiteElement[] siteElements = new SiteElement[childSites.length]; for (int i = 0; i < childSites.length; i++) { - siteElements[i] = new SiteElement(childSites[i]); - siteElements[i].setShell(shell); - siteElements[i].setProgressMonitor(monitor); + siteElements[i] = new SiteElement(childSites[i], runContext); } return siteElements; } - public void setProgressMonitor(IProgressMonitor monitor) { - this.monitor = monitor; - } - - public void setShell(Shell shell) { - this.shell = shell; - } - public String getLabel(Object o) { return null; } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteSelectionPage.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteSelectionPage.java index d5cb2ef68..2c64b33d3 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteSelectionPage.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/SiteSelectionPage.java @@ -139,7 +139,7 @@ public class SiteSelectionPage extends TargetWizardPage { */ private void initializeValues() { Site[] sites = TargetManager.getSites(); - table.setInput(new SiteRootsElement()); + table.setInput(new SiteRootsElement(null /* no progress monitoring required */)); if (sites.length == 0) { useNewRepo.setSelection(true); } else { -- cgit v1.2.3