Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
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
gregjan committed Sep 14, 2012
1 parent b96b604 commit 05196ee
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 11 deletions.
35 changes: 35 additions & 0 deletions workbench_plugin/plugin.xml
Expand Up @@ -73,6 +73,11 @@
defaultHandler="unc.lib.cdr.workbench.capture.CaptureHandler"
id="cdr-workbench.commandCaptureObject"
name="Capture Object">
<commandParameter
id="workbench_plugin.commandParameterCaptureFilter"
name="filterExtensions"
optional="true">
</commandParameter>
</command>
<command
defaultHandler="unc.lib.cdr.workbench.capture.LinkOriginalsHandler"
Expand Down Expand Up @@ -430,6 +435,36 @@
</with>
</visibleWhen>
</command>
<command
commandId="cdr-workbench.commandCaptureObject"
label="Capture by File Extension..."
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="activeMenuSelection">
<and>
<test
property="workbench_plugin.selection.siblingOriginals">
</test>
<iterate
ifEmpty="false">
<and>
<or>
<instanceof
value="unc.lib.cdr.workbench.originals.OriginalFileStore">
</instanceof>
</or>
</and>
</iterate>
</and>
</with>
</visibleWhen>
<parameter
name="workbench_plugin.commandParameterCaptureFilter"
value="true">
</parameter>
</command>
<command
commandId="cdr-workbench.commandOpenCopySystemEditor"
label="Open a Copy"
Expand Down
Expand Up @@ -16,13 +16,16 @@
package unc.lib.cdr.workbench.capture;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;
Expand All @@ -48,8 +51,21 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
ISelectionProvider sp = HandlerUtil.getActiveSite(event).getSelectionProvider();
IStructuredSelection s = (IStructuredSelection) sp.getSelection();
toCapture.addAll(s.toList());


CaptureJob job = new CaptureJob("Capturing " + Integer.toString(toCapture.size()) + " items...", toCapture);

String filter = event.getParameter("workbench_plugin.commandParameterCaptureFilter");
if("true".equals(filter)) {
SelectFileExtensionsDialog dialog = new SelectFileExtensionsDialog(HandlerUtil.getActiveShell(event), toCapture);
dialog.create();
if (dialog.open() == Window.OK) {
job.setIncludedFileExtensions(dialog.getSelectedFileExtensions());
} else {
return null;
}
}

IWorkbenchPart part = HandlerUtil.getActivePart(event);
if (part != null) {
IWorkbenchSiteProgressService siteService = (IWorkbenchSiteProgressService) part.getSite().getAdapter(
Expand Down
Expand Up @@ -23,7 +23,6 @@
import gov.loc.mets.MetsType;
import gov.loc.mets.util.METSConstants;
import gov.loc.mets.util.METSUtils;
import irods.efs.plugin.Activator;

import java.text.Collator;
import java.util.ArrayList;
Expand All @@ -33,13 +32,14 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
Expand All @@ -60,6 +60,15 @@
public class CaptureJob extends Job {
private IProject project = null;
private List<OriginalFileStore> items;
private Set<String> includedFileExtensions = null;
public Set<String> getIncludedFileExtensions() {
return includedFileExtensions;
}

public void setIncludedFileExtensions(Set<String> includedFileExtensions) {
this.includedFileExtensions = includedFileExtensions;
}

private DivType topDestination = null;
private DivType insertBefore = null;
private MetsProjectNature mpn = null;
Expand Down Expand Up @@ -227,12 +236,16 @@ private Map<OriginalFileStore, DivType> captureSiblingList(List<OriginalFileStor
DivType d = r.getMetsDivType();
boolean newDiv = false;
if (d == null) {
newDiv = true;
d = makeDiv(r);
result.put(r, d);
// dest.getDiv().add(d);
} else {
System.out.println("previously captured: " + d);
String ext = "";
String[] parts = r.getName().split(Pattern.quote("."));
if(parts.length > 1) {
ext = parts[parts.length-1];
}
if(r.fetchInfo().isDirectory() || this.includedFileExtensions == null || this.includedFileExtensions.contains(ext)) {
newDiv = true;
d = makeDiv(r);
result.put(r, d);
}
}
IProgressMonitor mon = new NullProgressMonitor();
if (r.fetchInfo().isDirectory()) {
Expand Down
Expand Up @@ -42,6 +42,8 @@
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
Expand Down Expand Up @@ -477,7 +479,7 @@ private boolean determinePageCompletion() {
setErrorMessage(validLocationMessage);
return false;
}
if (this.fileTreeViewer.getSelection().isEmpty()) {
if (this.fileTreeViewer.getCheckedElements().length < 1) {
setErrorMessage("Please select originals to link in the folder tree.");
return false;
}
Expand Down Expand Up @@ -544,6 +546,7 @@ private void selectFirstCheckbox() {
FileStoreProvider.Root root = (FileStoreProvider.Root) this.fileTreeViewer.getInput();
if (root.roots != null && root.roots.length > 0) {
this.fileTreeViewer.setChecked(root.roots[0], true);
//this.fileTreeViewer.setSelection(new TreeSelection(new TreePath(new Object[] {root, root.roots[0]})));
}
}
}
Expand Down Expand Up @@ -636,6 +639,7 @@ private void updateFileTree() throws URISyntaxException, CoreException {
if (!base.equals(this.fileTreeViewer.getInput())) {
this.fileTreeViewer.setInput(new FileStoreProvider.Root(base));
this.preStageSuffixLabel.setText(base.getName());
selectFirstCheckbox();
}
}
}
Expand All @@ -662,7 +666,7 @@ private void updateFromLocationField() {
* @return
*/
public boolean finish() {
List<URI> selected = getSelectedLocations();
List<URI> selected = getCheckedLocations();
URI prestageBase = null;
try {
if (this.preStagedButton.getSelection()) {
Expand Down Expand Up @@ -691,7 +695,7 @@ public boolean finish() {
* @return
*
*/
private List<URI> getSelectedLocations() {
private List<URI> getCheckedLocations() {
List<URI> result = new ArrayList<URI>();
for (Object o : this.fileTreeViewer.getCheckedElements()) {
result.add(((IFileStore) o).toURI());
Expand Down
@@ -0,0 +1,140 @@
package unc.lib.cdr.workbench.capture;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

import unc.lib.cdr.workbench.originals.OriginalFileStore;

public class SelectFileExtensionsDialog extends TitleAreaDialog {

public SelectFileExtensionsDialog(Shell parentShell, List<OriginalFileStore> tocapture) {
super(parentShell);
this.tocapture = tocapture;
}

@Override
public void create() {
super.create();
// Set the title
setTitle("Select File Extensions");
// Set the message
setMessage("Looking for file extensions..", IMessageProvider.INFORMATION);
}

Set<String> fileExtensions = new HashSet<String>();
Set<String> selectedExtensions = new HashSet<String>();
List<OriginalFileStore> tocapture = null;

public Set<String> getSelectedFileExtensions() {
return this.selectedExtensions;
}

@Override
protected void okPressed() {
Object[] checked = this.extCheckBox.getCheckedElements();
for(Object o : checked) {
this.selectedExtensions.add((String)o);
}
super.okPressed();
}

CheckboxTableViewer extCheckBox = null;

@Override
protected Control createDialogArea(Composite parent) {
GridLayout layout = new GridLayout();
layout.numColumns = 1;
// layout.horizontalAlignment = GridData.FILL;
parent.setLayout(layout);

// The text fields will grow with the size of the dialog
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = GridData.FILL;

Label label1 = new Label(parent, SWT.NONE);
label1.setText("Select file extensions to capture");

extCheckBox = CheckboxTableViewer.newCheckList(parent, SWT.BORDER);
extCheckBox.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
extCheckBox.setContentProvider(new ExtContentProvider());
extCheckBox.setSorter(new ViewerSorter());

Job findExtensions = new Job("Finding file extensions") {
IProgressMonitor mon = new NullProgressMonitor();
@Override
protected IStatus run(IProgressMonitor monitor) {
visit(tocapture.toArray(new IFileStore[] {}));
return Status.OK_STATUS;
}
private void visit(IFileStore[] ofs) {
for(final IFileStore s : ofs) {
boolean isdir = s.fetchInfo().isDirectory();
if(isdir) {
IFileStore[] children = null;
try {
children = s.childStores(EFS.NONE, mon);
} catch(CoreException e) {
}
if(children != null && children.length > 0) {
visit(children);
}
} else {
getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
String ext = null;
String[] parts = s.getName().split(Pattern.quote("."));
if(parts.length > 1) ext = parts[parts.length-1];
final boolean added = fileExtensions.add(ext);
if(added) extCheckBox.add(ext);
}});
}
}
}
};
findExtensions.setPriority(Job.INTERACTIVE);
findExtensions.schedule();
return parent;
}

public void addExtensionToTable(String ext) {
this.extCheckBox.add(ext);
}

class ExtContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object arg0) {
return fileExtensions.toArray();
}
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
}
}

0 comments on commit 05196ee

Please sign in to comment.