Skip to content
This repository
Browse code

added a "Capture by File Extension" function, prompts with checkboxes…

… of extensions found in selection (recursive)

made sure finished button is enabled after initial location pick in link originals wizard
  • Loading branch information...
commit 05196eee2109fa70f01f7a20537a1bd653f279ab 1 parent b96b604
Gregory Jansen gregjan authored
35 workbench_plugin/plugin.xml
@@ -73,6 +73,11 @@
73 73 defaultHandler="unc.lib.cdr.workbench.capture.CaptureHandler"
74 74 id="cdr-workbench.commandCaptureObject"
75 75 name="Capture Object">
  76 + <commandParameter
  77 + id="workbench_plugin.commandParameterCaptureFilter"
  78 + name="filterExtensions"
  79 + optional="true">
  80 + </commandParameter>
76 81 </command>
77 82 <command
78 83 defaultHandler="unc.lib.cdr.workbench.capture.LinkOriginalsHandler"
@@ -431,6 +436,36 @@
431 436 </visibleWhen>
432 437 </command>
433 438 <command
  439 + commandId="cdr-workbench.commandCaptureObject"
  440 + label="Capture by File Extension..."
  441 + style="push">
  442 + <visibleWhen
  443 + checkEnabled="false">
  444 + <with
  445 + variable="activeMenuSelection">
  446 + <and>
  447 + <test
  448 + property="workbench_plugin.selection.siblingOriginals">
  449 + </test>
  450 + <iterate
  451 + ifEmpty="false">
  452 + <and>
  453 + <or>
  454 + <instanceof
  455 + value="unc.lib.cdr.workbench.originals.OriginalFileStore">
  456 + </instanceof>
  457 + </or>
  458 + </and>
  459 + </iterate>
  460 + </and>
  461 + </with>
  462 + </visibleWhen>
  463 + <parameter
  464 + name="workbench_plugin.commandParameterCaptureFilter"
  465 + value="true">
  466 + </parameter>
  467 + </command>
  468 + <command
434 469 commandId="cdr-workbench.commandOpenCopySystemEditor"
435 470 label="Open a Copy"
436 471 style="push">
16 workbench_plugin/src/main/java/unc/lib/cdr/workbench/capture/CaptureHandler.java
@@ -16,13 +16,16 @@
16 16 package unc.lib.cdr.workbench.capture;
17 17
18 18 import java.util.ArrayList;
  19 +import java.util.HashSet;
19 20 import java.util.List;
  21 +import java.util.Set;
20 22
21 23 import org.eclipse.core.commands.AbstractHandler;
22 24 import org.eclipse.core.commands.ExecutionEvent;
23 25 import org.eclipse.core.commands.ExecutionException;
24 26 import org.eclipse.jface.viewers.ISelectionProvider;
25 27 import org.eclipse.jface.viewers.IStructuredSelection;
  28 +import org.eclipse.jface.window.Window;
26 29 import org.eclipse.swt.widgets.Shell;
27 30 import org.eclipse.ui.IWorkbenchPart;
28 31 import org.eclipse.ui.handlers.HandlerUtil;
@@ -48,8 +51,21 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
48 51 ISelectionProvider sp = HandlerUtil.getActiveSite(event).getSelectionProvider();
49 52 IStructuredSelection s = (IStructuredSelection) sp.getSelection();
50 53 toCapture.addAll(s.toList());
  54 +
51 55
52 56 CaptureJob job = new CaptureJob("Capturing " + Integer.toString(toCapture.size()) + " items...", toCapture);
  57 +
  58 + String filter = event.getParameter("workbench_plugin.commandParameterCaptureFilter");
  59 + if("true".equals(filter)) {
  60 + SelectFileExtensionsDialog dialog = new SelectFileExtensionsDialog(HandlerUtil.getActiveShell(event), toCapture);
  61 + dialog.create();
  62 + if (dialog.open() == Window.OK) {
  63 + job.setIncludedFileExtensions(dialog.getSelectedFileExtensions());
  64 + } else {
  65 + return null;
  66 + }
  67 + }
  68 +
53 69 IWorkbenchPart part = HandlerUtil.getActivePart(event);
54 70 if (part != null) {
55 71 IWorkbenchSiteProgressService siteService = (IWorkbenchSiteProgressService) part.getSite().getAdapter(
29 workbench_plugin/src/main/java/unc/lib/cdr/workbench/capture/CaptureJob.java
@@ -23,7 +23,6 @@
23 23 import gov.loc.mets.MetsType;
24 24 import gov.loc.mets.util.METSConstants;
25 25 import gov.loc.mets.util.METSUtils;
26   -import irods.efs.plugin.Activator;
27 26
28 27 import java.text.Collator;
29 28 import java.util.ArrayList;
@@ -33,13 +32,14 @@
33 32 import java.util.HashMap;
34 33 import java.util.List;
35 34 import java.util.Map;
  35 +import java.util.Set;
36 36 import java.util.UUID;
  37 +import java.util.regex.Pattern;
37 38
38 39 import org.eclipse.core.filesystem.EFS;
39 40 import org.eclipse.core.filesystem.IFileInfo;
40 41 import org.eclipse.core.filesystem.IFileStore;
41 42 import org.eclipse.core.resources.IProject;
42   -import org.eclipse.core.resources.IncrementalProjectBuilder;
43 43 import org.eclipse.core.runtime.CoreException;
44 44 import org.eclipse.core.runtime.IProgressMonitor;
45 45 import org.eclipse.core.runtime.IStatus;
@@ -60,6 +60,15 @@
60 60 public class CaptureJob extends Job {
61 61 private IProject project = null;
62 62 private List<OriginalFileStore> items;
  63 + private Set<String> includedFileExtensions = null;
  64 + public Set<String> getIncludedFileExtensions() {
  65 + return includedFileExtensions;
  66 + }
  67 +
  68 + public void setIncludedFileExtensions(Set<String> includedFileExtensions) {
  69 + this.includedFileExtensions = includedFileExtensions;
  70 + }
  71 +
63 72 private DivType topDestination = null;
64 73 private DivType insertBefore = null;
65 74 private MetsProjectNature mpn = null;
@@ -227,12 +236,16 @@ protected IStatus run(IProgressMonitor monitor) {
227 236 DivType d = r.getMetsDivType();
228 237 boolean newDiv = false;
229 238 if (d == null) {
230   - newDiv = true;
231   - d = makeDiv(r);
232   - result.put(r, d);
233   - // dest.getDiv().add(d);
234   - } else {
235   - System.out.println("previously captured: " + d);
  239 + String ext = "";
  240 + String[] parts = r.getName().split(Pattern.quote("."));
  241 + if(parts.length > 1) {
  242 + ext = parts[parts.length-1];
  243 + }
  244 + if(r.fetchInfo().isDirectory() || this.includedFileExtensions == null || this.includedFileExtensions.contains(ext)) {
  245 + newDiv = true;
  246 + d = makeDiv(r);
  247 + result.put(r, d);
  248 + }
236 249 }
237 250 IProgressMonitor mon = new NullProgressMonitor();
238 251 if (r.fetchInfo().isDirectory()) {
10 workbench_plugin/src/main/java/unc/lib/cdr/workbench/capture/PickOriginalLocationsPage.java
@@ -42,6 +42,8 @@
42 42 import org.eclipse.jface.viewers.CheckboxTreeViewer;
43 43 import org.eclipse.jface.viewers.ICheckStateListener;
44 44 import org.eclipse.jface.viewers.IStructuredSelection;
  45 +import org.eclipse.jface.viewers.TreePath;
  46 +import org.eclipse.jface.viewers.TreeSelection;
45 47 import org.eclipse.jface.viewers.ViewerComparator;
46 48 import org.eclipse.jface.wizard.WizardPage;
47 49 import org.eclipse.swt.SWT;
@@ -477,7 +479,7 @@ private boolean determinePageCompletion() {
477 479 setErrorMessage(validLocationMessage);
478 480 return false;
479 481 }
480   - if (this.fileTreeViewer.getSelection().isEmpty()) {
  482 + if (this.fileTreeViewer.getCheckedElements().length < 1) {
481 483 setErrorMessage("Please select originals to link in the folder tree.");
482 484 return false;
483 485 }
@@ -544,6 +546,7 @@ private void selectFirstCheckbox() {
544 546 FileStoreProvider.Root root = (FileStoreProvider.Root) this.fileTreeViewer.getInput();
545 547 if (root.roots != null && root.roots.length > 0) {
546 548 this.fileTreeViewer.setChecked(root.roots[0], true);
  549 + //this.fileTreeViewer.setSelection(new TreeSelection(new TreePath(new Object[] {root, root.roots[0]})));
547 550 }
548 551 }
549 552 }
@@ -636,6 +639,7 @@ private void updateFileTree() throws URISyntaxException, CoreException {
636 639 if (!base.equals(this.fileTreeViewer.getInput())) {
637 640 this.fileTreeViewer.setInput(new FileStoreProvider.Root(base));
638 641 this.preStageSuffixLabel.setText(base.getName());
  642 + selectFirstCheckbox();
639 643 }
640 644 }
641 645 }
@@ -662,7 +666,7 @@ private void updateFromLocationField() {
662 666 * @return
663 667 */
664 668 public boolean finish() {
665   - List<URI> selected = getSelectedLocations();
  669 + List<URI> selected = getCheckedLocations();
666 670 URI prestageBase = null;
667 671 try {
668 672 if (this.preStagedButton.getSelection()) {
@@ -691,7 +695,7 @@ public boolean finish() {
691 695 * @return
692 696 *
693 697 */
694   - private List<URI> getSelectedLocations() {
  698 + private List<URI> getCheckedLocations() {
695 699 List<URI> result = new ArrayList<URI>();
696 700 for (Object o : this.fileTreeViewer.getCheckedElements()) {
697 701 result.add(((IFileStore) o).toURI());
140 workbench_plugin/src/main/java/unc/lib/cdr/workbench/capture/SelectFileExtensionsDialog.java
... ... @@ -0,0 +1,140 @@
  1 +package unc.lib.cdr.workbench.capture;
  2 +
  3 +import java.util.HashSet;
  4 +import java.util.List;
  5 +import java.util.Set;
  6 +import java.util.regex.Pattern;
  7 +
  8 +import org.eclipse.core.filesystem.EFS;
  9 +import org.eclipse.core.filesystem.IFileStore;
  10 +import org.eclipse.core.runtime.CoreException;
  11 +import org.eclipse.core.runtime.IProgressMonitor;
  12 +import org.eclipse.core.runtime.IStatus;
  13 +import org.eclipse.core.runtime.NullProgressMonitor;
  14 +import org.eclipse.core.runtime.Status;
  15 +import org.eclipse.core.runtime.jobs.Job;
  16 +import org.eclipse.jface.dialogs.IMessageProvider;
  17 +import org.eclipse.jface.dialogs.TitleAreaDialog;
  18 +import org.eclipse.jface.viewers.CheckboxTableViewer;
  19 +import org.eclipse.jface.viewers.IStructuredContentProvider;
  20 +import org.eclipse.jface.viewers.Viewer;
  21 +import org.eclipse.jface.viewers.ViewerSorter;
  22 +import org.eclipse.swt.SWT;
  23 +import org.eclipse.swt.layout.GridData;
  24 +import org.eclipse.swt.layout.GridLayout;
  25 +import org.eclipse.swt.widgets.Composite;
  26 +import org.eclipse.swt.widgets.Control;
  27 +import org.eclipse.swt.widgets.Label;
  28 +import org.eclipse.swt.widgets.Shell;
  29 +
  30 +import unc.lib.cdr.workbench.originals.OriginalFileStore;
  31 +
  32 +public class SelectFileExtensionsDialog extends TitleAreaDialog {
  33 +
  34 + public SelectFileExtensionsDialog(Shell parentShell, List<OriginalFileStore> tocapture) {
  35 + super(parentShell);
  36 + this.tocapture = tocapture;
  37 + }
  38 +
  39 + @Override
  40 + public void create() {
  41 + super.create();
  42 + // Set the title
  43 + setTitle("Select File Extensions");
  44 + // Set the message
  45 + setMessage("Looking for file extensions..", IMessageProvider.INFORMATION);
  46 + }
  47 +
  48 + Set<String> fileExtensions = new HashSet<String>();
  49 + Set<String> selectedExtensions = new HashSet<String>();
  50 + List<OriginalFileStore> tocapture = null;
  51 +
  52 + public Set<String> getSelectedFileExtensions() {
  53 + return this.selectedExtensions;
  54 + }
  55 +
  56 + @Override
  57 + protected void okPressed() {
  58 + Object[] checked = this.extCheckBox.getCheckedElements();
  59 + for(Object o : checked) {
  60 + this.selectedExtensions.add((String)o);
  61 + }
  62 + super.okPressed();
  63 + }
  64 +
  65 + CheckboxTableViewer extCheckBox = null;
  66 +
  67 + @Override
  68 + protected Control createDialogArea(Composite parent) {
  69 + GridLayout layout = new GridLayout();
  70 + layout.numColumns = 1;
  71 + // layout.horizontalAlignment = GridData.FILL;
  72 + parent.setLayout(layout);
  73 +
  74 + // The text fields will grow with the size of the dialog
  75 + GridData gridData = new GridData();
  76 + gridData.grabExcessHorizontalSpace = true;
  77 + gridData.horizontalAlignment = GridData.FILL;
  78 +
  79 + Label label1 = new Label(parent, SWT.NONE);
  80 + label1.setText("Select file extensions to capture");
  81 +
  82 + extCheckBox = CheckboxTableViewer.newCheckList(parent, SWT.BORDER);
  83 + extCheckBox.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
  84 + extCheckBox.setContentProvider(new ExtContentProvider());
  85 + extCheckBox.setSorter(new ViewerSorter());
  86 +
  87 + Job findExtensions = new Job("Finding file extensions") {
  88 + IProgressMonitor mon = new NullProgressMonitor();
  89 + @Override
  90 + protected IStatus run(IProgressMonitor monitor) {
  91 + visit(tocapture.toArray(new IFileStore[] {}));
  92 + return Status.OK_STATUS;
  93 + }
  94 + private void visit(IFileStore[] ofs) {
  95 + for(final IFileStore s : ofs) {
  96 + boolean isdir = s.fetchInfo().isDirectory();
  97 + if(isdir) {
  98 + IFileStore[] children = null;
  99 + try {
  100 + children = s.childStores(EFS.NONE, mon);
  101 + } catch(CoreException e) {
  102 + }
  103 + if(children != null && children.length > 0) {
  104 + visit(children);
  105 + }
  106 + } else {
  107 + getShell().getDisplay().asyncExec(new Runnable() {
  108 + @Override
  109 + public void run() {
  110 + String ext = null;
  111 + String[] parts = s.getName().split(Pattern.quote("."));
  112 + if(parts.length > 1) ext = parts[parts.length-1];
  113 + final boolean added = fileExtensions.add(ext);
  114 + if(added) extCheckBox.add(ext);
  115 + }});
  116 + }
  117 + }
  118 + }
  119 + };
  120 + findExtensions.setPriority(Job.INTERACTIVE);
  121 + findExtensions.schedule();
  122 + return parent;
  123 + }
  124 +
  125 + public void addExtensionToTable(String ext) {
  126 + this.extCheckBox.add(ext);
  127 + }
  128 +
  129 + class ExtContentProvider implements IStructuredContentProvider {
  130 + public Object[] getElements(Object arg0) {
  131 + return fileExtensions.toArray();
  132 + }
  133 + @Override
  134 + public void dispose() {
  135 + }
  136 + @Override
  137 + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
  138 + }
  139 + }
  140 +}

0 comments on commit 05196ee

Please sign in to comment.
Something went wrong with that request. Please try again.