diff options
author | jmisinco | 2012-01-18 23:19:31 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2012-01-18 23:19:31 +0000 |
commit | fbb5b673cc03fdbf488109d94fdda17e186724a3 (patch) | |
tree | 3e53ea173c809d1dded66a6feea89be11190e38a | |
parent | 95e89dc3155e51ce2af79abd52cdd41803957d28 (diff) | |
download | org.eclipse.osee-fbb5b673cc03fdbf488109d94fdda17e186724a3.tar.gz org.eclipse.osee-fbb5b673cc03fdbf488109d94fdda17e186724a3.tar.xz org.eclipse.osee-fbb5b673cc03fdbf488109d94fdda17e186724a3.zip |
refactor[ats_86NTF]: Increase performance of FindInWorkspaceOperation
2 files changed, 67 insertions, 44 deletions
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/FindInWorkspaceOperation.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/FindInWorkspaceOperation.java index 7cf6c6346bb..d2510bcef5f 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/FindInWorkspaceOperation.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/FindInWorkspaceOperation.java @@ -39,16 +39,21 @@ import org.eclipse.osee.framework.ui.skynet.internal.Activator; */ public class FindInWorkspaceOperation extends AbstractOperation { + public static interface FindInWorkspaceCollector { + + void onResource(IResource resource); + + void onNotFound(Artifact artifact); + } + private final List<Artifact> artifacts; - private final List<IResource> matches; - private final List<Artifact> notMatched; + private final FindInWorkspaceCollector collector; final static Pattern objectIdPattern = Pattern.compile("ObjectId\\(\"(.*)?\""); - public FindInWorkspaceOperation(List<Artifact> artifacts, List<IResource> matches, List<Artifact> notMatched) { + public FindInWorkspaceOperation(List<Artifact> artifacts, FindInWorkspaceCollector collector) { super("Find In Workspace", Activator.PLUGIN_ID); this.artifacts = artifacts; - this.matches = matches; - this.notMatched = notMatched; + this.collector = collector; } private Map<String, Artifact> getGuidMap() { @@ -85,7 +90,7 @@ public class FindInWorkspaceOperation extends AbstractOperation { String uuid = matcher.group(1); if (guids.containsKey(uuid)) { monitor.worked(1); - matches.add(unit.getResource()); + collector.onResource(unit.getResource()); guids.remove(uuid); if (guids.isEmpty()) { subMonitor.setCanceled(true); @@ -104,7 +109,7 @@ public class FindInWorkspaceOperation extends AbstractOperation { } for (Artifact artifact : guids.values()) { - notMatched.add(artifact); + collector.onNotFound(artifact); } } } diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/JavaRenderer.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/JavaRenderer.java index 66b98441843..12ee2469e4b 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/JavaRenderer.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/JavaRenderer.java @@ -20,6 +20,7 @@ import java.util.List; import org.eclipse.core.commands.Command; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.filesystem.IFileSystem; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.jobs.IJobChangeEvent; @@ -35,11 +36,11 @@ import org.eclipse.osee.framework.core.exception.OseeExceptions; import org.eclipse.osee.framework.core.operation.IOperation; import org.eclipse.osee.framework.core.operation.Operations; import org.eclipse.osee.framework.jdk.core.util.Collections; -import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.framework.skynet.core.types.IArtifact; import org.eclipse.osee.framework.ui.plugin.util.AWorkbench; import org.eclipse.osee.framework.ui.skynet.FindInWorkspaceOperation; +import org.eclipse.osee.framework.ui.skynet.FindInWorkspaceOperation.FindInWorkspaceCollector; import org.eclipse.osee.framework.ui.skynet.FrameworkImage; import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.osee.framework.ui.swt.ImageManager; @@ -95,58 +96,62 @@ public class JavaRenderer extends FileSystemRenderer { @Override public void open(final List<Artifact> artifacts, PresentationType presentationType) { - final List<IResource> matches = new LinkedList<IResource>(); final List<Artifact> notMatched = new LinkedList<Artifact>(); + final StringBuffer findErrorMessage = new StringBuffer(); - IOperation op = new FindInWorkspaceOperation(artifacts, matches, notMatched); - Operations.executeAsJob(op, true, Job.LONG, new JobChangeAdapter() { + FindInWorkspaceCollector collector = new FindInWorkspaceCollector() { + + @Override + public void onResource(final IResource resource) { + Displays.ensureInDisplayThread(new Runnable() { + @Override + public void run() { + IFileSystem fs = EFS.getLocalFileSystem(); + + IPath fullPath = resource.getLocation(); + final File fileToOpen = fullPath.toFile(); + if (fileToOpen != null && fileToOpen.exists() && fileToOpen.isFile()) { + try { + IFileStore fileStore = fs.getStore(fileToOpen.toURI()); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + IDE.openEditorOnFileStore(page, fileStore); + } catch (PartInitException e) { + findErrorMessage.append(e.toString()); + } + } + } + }); + } @Override + public void onNotFound(Artifact artifact) { + notMatched.add(artifact); + } + }; + IOperation op = new FindInWorkspaceOperation(artifacts, collector); + Operations.executeAsJob(op, true, Job.LONG, new JobChangeAdapter() { + @Override public void done(IJobChangeEvent event) { - super.done(event); if (event.getResult().isOK()) { Displays.ensureInDisplayThread(new Runnable() { - @Override public void run() { - String errorMsg = ""; - if (matches.isEmpty()) { - errorMsg = - String.format("Unable to find test scripts for: [%s] in the workspace.\n", - Collections.toString(",", notMatched)); - } else { - for (IResource resource : matches) { - IPath fullPath = resource.getLocation(); - final File fileToOpen = fullPath.toFile(); - if (fileToOpen != null && fileToOpen.exists() && fileToOpen.isFile()) { - try { - IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI()); - IWorkbenchPage page = - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IDE.openEditorOnFileStore(page, fileStore); - } catch (PartInitException e) { - errorMsg = e.toString(); - } - } else { - errorMsg += String.format("Unable to find: [%s] in the workspace.\n", fullPath); - } - } - if (!notMatched.isEmpty()) { - errorMsg += - String.format("Unable to scripts for: [%s] in the workspace.\n", - Collections.toString(",", notMatched)); - } + StringBuilder builder = new StringBuilder(); + builder.append(findErrorMessage); + if (!notMatched.isEmpty()) { + builder.append(String.format("Unable to scripts for: [%s] in the workspace.\n", + Collections.toString(",", notMatched))); } - if (Strings.isValid(errorMsg)) { + + if (builder.length() > 0) { Shell shell = AWorkbench.getActiveShell(); - MessageDialog.openError(shell, getName(), errorMsg); + MessageDialog.openError(shell, getName(), builder.toString()); } } }); } } }); - } @Override @@ -168,7 +173,20 @@ public class JavaRenderer extends FileSystemRenderer { public InputStream getRenderInputStream(PresentationType presentationType, List<Artifact> artifacts) throws OseeCoreException { final List<IResource> matches = new LinkedList<IResource>(); final List<Artifact> notMatched = new LinkedList<Artifact>(); - IOperation op = new FindInWorkspaceOperation(artifacts.subList(0, 1), matches, notMatched); + + FindInWorkspaceCollector collector = new FindInWorkspaceCollector() { + + @Override + public void onResource(IResource resource) { + matches.add(resource); + } + + @Override + public void onNotFound(Artifact artifact) { + notMatched.add(artifact); + } + }; + IOperation op = new FindInWorkspaceOperation(artifacts.subList(0, 1), collector); Operations.executeWorkAndCheckStatus(op); for (IResource resource : matches) { IPath fullPath = resource.getLocation(); |