From ba486486324005e29408451c09a4e3e9c9f13229 Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Thu, 16 May 2013 14:52:23 -0400 Subject: [PATCH] tmf: fix import trace wizard changing trace types after directory Change-Id: I20af2fc56cb58ba8caebf5af13acf5b16ad7eb00 Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/13280 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann IP-Clean: Bernd Hufmann Tested-by: Bernd Hufmann --- .../importtrace/BatchImportTraceWizard.java | 7 ++- .../ImportTraceContentProvider.java | 48 ++++++++++++++++--- .../ImportTraceWizardScanPage.java | 24 ++++++++-- 3 files changed, 67 insertions(+), 12 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java index df6b799016..94838cb861 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java @@ -83,13 +83,13 @@ public class BatchImportTraceWizard extends ImportTraceWizard { // ------------------ private IWizardPage fSelectDirectoriesPage; - private IWizardPage fScanPage; + private ImportTraceWizardScanPage fScanPage; private IWizardPage fSelectTypePage; private final List fTraceTypesToScan = new ArrayList(); private final Set fParentFilesToScan = new HashSet(); - private ImportTraceContentProvider fScannedTraces = new ImportTraceContentProvider(); + private ImportTraceContentProvider fScannedTraces = new ImportTraceContentProvider(fTraceTypesToScan, fParentFilesToScan); private final Map fResults = new HashMap(); private boolean fOverwrite = true; @@ -561,6 +561,7 @@ public class BatchImportTraceWizard extends ImportTraceWizard { updateScanQueue(pm, filesToScan, added); } catch (InterruptedException e) { } + } /* @@ -619,12 +620,14 @@ public class BatchImportTraceWizard extends ImportTraceWizard { fTracesToScan.put(tv); monitor.subTask(tv.getTraceToScan()); if (monitor.isCanceled()) { + fScanPage.refresh(); return CANCEL_STATUS; } } } } } + fScanPage.refresh(); return Status.OK_STATUS; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceContentProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceContentProvider.java index bd3a43e3ad..3870c4dd94 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceContentProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceContentProvider.java @@ -13,8 +13,11 @@ package org.eclipse.linuxtools.tmf.ui.project.wizards.importtrace; import java.io.File; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; @@ -32,8 +35,16 @@ import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType; */ class ImportTraceContentProvider implements ITreeContentProvider { - final Map fTraceTypes = new HashMap(); - final Map> fTraceFiles = new HashMap>(); + private final Map fTraceTypes = new HashMap(); + private final Map> fTraceFiles = new HashMap>(); + private final List fTraceTypesToScan; + private final Set fParentFilesToScan; + + public ImportTraceContentProvider(List traceTypesToScan, Set parentFilesToScan) { + fTraceTypesToScan = traceTypesToScan; + fParentFilesToScan = parentFilesToScan; + } + /** * Add a trace candidate to display * @@ -48,7 +59,7 @@ class ImportTraceContentProvider implements ITreeContentProvider { fTraceFiles.put(category, new TreeSet()); } final FileAndName traceFile = new FileAndName(traceToOpen, traceToOpen.getName()); - traceFile.setTraceTypeId( category ); + traceFile.setTraceTypeId(category); final Set categorySet = fTraceFiles.get(category); categorySet.add(traceFile); } @@ -80,7 +91,18 @@ class ImportTraceContentProvider implements ITreeContentProvider { @Override public synchronized Object[] getElements(Object inputElement) { - return fTraceTypes.keySet().toArray(new String[fTraceTypes.size()]); + List candidates = new ArrayList(); + + for (String candidate : fTraceTypesToScan) { + for (Entry entry : fTraceTypes.entrySet()) { + if (entry.getValue().equals(candidate)) { + candidates.add(entry.getKey()); + break; + } + } + + } + return candidates.toArray(new String[candidates.size()]); } @Override @@ -88,7 +110,18 @@ class ImportTraceContentProvider implements ITreeContentProvider { if (parentElement instanceof String) { final Set children = fTraceFiles.get(fTraceTypes.get(parentElement)); if (children != null) { - return children.toArray(new FileAndName[0]); + Set candidates = new TreeSet(); + for (FileAndName child : children) { + for (String parent : fParentFilesToScan) { + // this is going to be slow, but less slow than UI + // display and should not be done for more than 10k + // elements. + if (child.getFile().getAbsolutePath().startsWith(parent)) { + candidates.add(child); + } + } + } + return candidates.toArray(new FileAndName[0]); } } return null; @@ -132,11 +165,12 @@ class ImportTraceContentProvider implements ITreeContentProvider { /** * Gets the number of traces to import + * * @return the number of traces to import */ public synchronized int getSize() { - int tot = 0 ; - for( String s : fTraceFiles.keySet() ){ + int tot = 0; + for (String s : fTraceFiles.keySet()) { tot += fTraceFiles.get(s).size(); } return tot; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardScanPage.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardScanPage.java index 7da2a5f647..4983d91563 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardScanPage.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardScanPage.java @@ -65,7 +65,6 @@ public class ImportTraceWizardScanPage extends AbstractImportTraceWizardPage { private static final int MAX_TRACES = 65536; private CheckboxTreeViewer traceTypeViewer; - // private int position = 0; final ScanRunnable fRunnable = new ScanRunnable("Scan job"); //$NON-NLS-1$ final private BlockingQueue fTracesToScan = new ArrayBlockingQueue(MAX_TRACES); private volatile boolean fCanRun = true; @@ -158,6 +157,7 @@ public class ImportTraceWizardScanPage extends AbstractImportTraceWizardPage { init(); getBatchWizard().setTracesToScan(fTracesToScan); getBatchWizard().setTraceFolder(fTargetFolder); + fRunnable.schedule(); setErrorMessage(Messages.ImportTraceWizardScanPageSelectAtleastOne); } @@ -354,12 +354,12 @@ public class ImportTraceWizardScanPage extends AbstractImportTraceWizardPage { private final class ScanRunnable extends Job { + private IProgressMonitor fMonitor; + public ScanRunnable(String name) { super(name); } - private IProgressMonitor fMonitor; - private synchronized IProgressMonitor getMonitor() { return fMonitor; } @@ -371,6 +371,7 @@ public class ImportTraceWizardScanPage extends AbstractImportTraceWizardPage { control.getDisplay().syncExec(new Runnable() { @Override public void run() { + // monitor gets overwritten here so it's necessary to save it in a field. fMonitor = SubMonitor.convert(getMonitor()); getMonitor().setTaskName(Messages.ImportTraceWizardPageScanScanning + ' '); ((SubMonitor) getMonitor()).setWorkRemaining(IProgressMonitor.UNKNOWN); @@ -445,4 +446,21 @@ public class ImportTraceWizardScanPage extends AbstractImportTraceWizardPage { return Status.OK_STATUS; } } + + /** + * Refresh the view and the corresponding model. + */ + public void refresh() { + final Control control = traceTypeViewer.getControl(); + if (!control.isDisposed()) { + control.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (!control.isDisposed()) { + traceTypeViewer.refresh(); + } + } + }); + } + } } -- 2.34.1