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

Commit

Permalink
added projects to the properties view, with manifest/description and …
Browse files Browse the repository at this point in the history
…staging status info

fixed windows staging issue using local and irods folders
  • Loading branch information
gregjan committed Jul 18, 2012
1 parent d1c5b44 commit e1a21ef
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 4 deletions.
12 changes: 12 additions & 0 deletions workbench_plugin/plugin.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1468,6 +1468,11 @@
id="workbench_plugin.propertyTabMdSecContent" id="workbench_plugin.propertyTabMdSecContent"
label="Metadata Content"> label="Metadata Content">
</propertyTab> </propertyTab>
<propertyTab
category="description"
id="workbench_plugin.propertyTabGeneral"
label="General">
</propertyTab>
</propertyTabs> </propertyTabs>
</extension> </extension>
<extension <extension
Expand Down Expand Up @@ -1516,6 +1521,13 @@
id="workbench_plugin.propertySectionOriginalVolumeSection" id="workbench_plugin.propertySectionOriginalVolumeSection"
tab="workbench_plugin.propertyTabStorageProperties"> tab="workbench_plugin.propertyTabStorageProperties">
</propertySection> </propertySection>
<propertySection
class="unc.lib.cdr.workbench.views.MetsProjectNaturePropertiesSection"
enablesFor="1"
filter="unc.lib.cdr.workbench.views.HasMetsProjectNatureFilter"
id="workbench_plugin.propertySectionProject"
tab="workbench_plugin.propertyTabGeneral">
</propertySection>
</propertySections> </propertySections>
</extension> </extension>
<extension <extension
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ public IFileStore getStageLocation() {
.append(this.getOriginalStub().getVolumeHash()).toString(); .append(this.getOriginalStub().getVolumeHash()).toString();
IPath stagePath = stageBasePath.append(stubSegment).append(relStubPath); IPath stagePath = stageBasePath.append(stubSegment).append(relStubPath);
LOG.debug("stagePath: "+stagePath); LOG.debug("stagePath: "+stagePath);
String sps = stagePath.toFile().toURI().getPath(); String sps = stagePath.toString();
if(!sps.startsWith("/")) {
sps = "/"+sps;
}
LOG.debug("sps: "+sps); LOG.debug("sps: "+sps);
try { try {
URI stageLoc = new URI(stageBase.getScheme(), stageBase.getUserInfo(), stageBase.getHost(), URI stageLoc = new URI(stageBase.getScheme(), stageBase.getUserInfo(), stageBase.getHost(),
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@


import gov.loc.mets.DivType; import gov.loc.mets.DivType;
import gov.loc.mets.DocumentRoot; import gov.loc.mets.DocumentRoot;
import gov.loc.mets.FLocatType;
import gov.loc.mets.FptrType;
import gov.loc.mets.MetsType1; import gov.loc.mets.MetsType1;
import gov.loc.mets.util.METSConstants;
import gov.loc.mets.util.METSUtils;
import gov.loc.mods.mods.presentation.URIFragmentEditorInput; import gov.loc.mods.mods.presentation.URIFragmentEditorInput;


import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
Expand All @@ -29,6 +33,7 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException;


import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.filesystem.IFileStore;
Expand All @@ -48,6 +53,7 @@
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.emf.common.command.CommandStack; import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
Expand All @@ -66,9 +72,8 @@


public class MetsProjectNature implements IProjectNature { public class MetsProjectNature implements IProjectNature {


@SuppressWarnings("unused")
private static final Logger LOG = LoggerFactory.getLogger(MetsProjectNature.class); private static final Logger LOG = LoggerFactory.getLogger(MetsProjectNature.class);

public static final String ORIGINALS_FOLDER_NAME = ".originals"; public static final String ORIGINALS_FOLDER_NAME = ".originals";
// public static final String STAGE_FOLDER_NAME = ".stage"; // public static final String STAGE_FOLDER_NAME = ".stage";


Expand Down Expand Up @@ -357,7 +362,7 @@ public static MetsProjectNature get(IProject prog) {
* @param stageURI * @param stageURI
*/ */
public static void setStagingBase(java.net.URI stageURI, IProject project) { public static void setStagingBase(java.net.URI stageURI, IProject project) {
LOG.debug("setting stageURI to: "+stageURI); LOG.debug("setting stageURI to: " + stageURI);
IEclipsePreferences projectNode = new ProjectScope(project).getNode(Activator.PLUGIN_ID); IEclipsePreferences projectNode = new ProjectScope(project).getNode(Activator.PLUGIN_ID);
projectNode.put(STAGING_BASE_URI_KEY, stageURI.toString()); projectNode.put(STAGING_BASE_URI_KEY, stageURI.toString());
} }
Expand Down Expand Up @@ -414,4 +419,68 @@ public static EObject getModel(URIFragmentEditorInput in) {
return n.getEditingDomain().getResourceSet().getResources().get(0).getEObject(in.getFragmentID()); return n.getEditingDomain().getResourceSet().getResources().get(0).getEObject(in.getFragmentID());
} }


public String getDescriptionStatus() {
int numOfFiles = 0;
int numOfContainers = 0;
int numDescribed = 0;
TreeIterator<EObject> iter = METSUtils.findBagDiv(getMets()).eAllContents();
try {
for (EObject eo = iter.next(); iter.hasNext(); eo = iter.next()) {
if(eo instanceof DivType) {
DivType d = (DivType)eo;
if(METSConstants.Div_File.equals(d.getTYPE())) {
numOfFiles++;
} else {
numOfContainers++;
}
if(d.getDmdSec() != null && d.getDmdSec().size() > 0) {
numDescribed++;
}
}
}
} catch (NoSuchElementException ignored) {
}
StringBuilder result = new StringBuilder().append(numOfFiles);
if(numOfFiles > 1) {
result.append(" files and ");
} else {
result.append(" file and ");
}
result.append(numOfContainers);
if(numOfContainers > 1 || numOfContainers == 0) {
result.append(" other objects. ");
} else {
result.append(" other object. ");
}
return result.append(numDescribed).append(" are described.").toString();
}

public String getStagingStatus() {
int numOfFiles = 0;
int numStaged = 0;
DivType bag = METSUtils.findBagDiv(getMets());
for(TreeIterator<EObject> iter = bag.eAllContents(); iter.hasNext();) {
EObject next = iter.next();
if(next != null && next instanceof FptrType) {
numOfFiles++;
FptrType fptr = (FptrType)next;
OriginalFileStore original = MetsProjectNature.getOriginal((DivType)fptr.eContainer());
if(original != null) {
FLocatType loc = original.getStagingLocatorType();
if(loc != null) {
numStaged++;
}
}
}
}
StringBuilder result = new StringBuilder().append(numStaged)
.append(" out of ").append(numOfFiles);
if(numOfFiles > 1 || numOfFiles == 0) {
result.append(" files staged");
} else {
result.append(" file staged");
}
return result.toString();
}

} }
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,24 @@
package unc.lib.cdr.workbench.views;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.IFilter;

import unc.lib.cdr.workbench.project.MetsProjectNature;

public class HasMetsProjectNatureFilter implements IFilter {

@Override
public boolean select(Object toTest) {
if(toTest instanceof IProject) {
IProject test = (IProject)toTest;
try {
return (test.isOpen() && test.hasNature(MetsProjectNature.NATURE_ID));
} catch (CoreException e) {
return false;
}
}
return false;
}

}
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,169 @@
package unc.lib.cdr.workbench.views;

import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.NumberFormat;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import unc.lib.cdr.workbench.project.MetsProjectNature;

public class MetsProjectNaturePropertiesSection extends AbstractPropertySection {

@SuppressWarnings("unused")
private static final Logger LOG = LoggerFactory.getLogger(MetsProjectNaturePropertiesSection.class);

IProject project = null;
MetsProjectNature nature = null;

Group stagingGroup = null;
Text stagingBaseText = null;
Text stagingStatusText = null;

Group metsGroup = null;
Text manifestText = null;
Text describedStatusText = null;


public MetsProjectNaturePropertiesSection() {
// TODO Auto-generated constructor stub
}

/**
* @see org.eclipse.ui.views.properties.tabbed.ISection#setInput(org.eclipse.ui.IWorkbenchPart,
* org.eclipse.jface.viewers.ISelection)
*/
@Override
public void setInput(IWorkbenchPart part, ISelection s) {
super.setInput(part, s);
Assert.isTrue(s instanceof IStructuredSelection);
Object fs = ((IStructuredSelection) s).getFirstElement();
if (fs instanceof IProject) {
this.project = (IProject)fs;
this.nature = MetsProjectNature.get(project);
}
Assert.isTrue(this.nature != null);
}

/**
* @see org.eclipse.ui.views.properties.tabbed.ISection#shouldUseExtraSpace()
*/
@Override
public boolean shouldUseExtraSpace() {
return false;
}

@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
Composite outer = getWidgetFactory().createFlatFormComposite(parent);
outer.setLayout(new GridLayout());
metsGroup = getWidgetFactory().createGroup(outer, "METS Manifest");
metsGroup.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false));
FormLayout layout = new FormLayout();
metsGroup.setLayout(layout);

FormData data;

int secondTab = 150;

CLabel l1 = getWidgetFactory().createCLabel(metsGroup, "Location");
data = new FormData();
data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE);
data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
l1.setLayoutData(data);

data = new FormData();
data.left = new FormAttachment(0, secondTab);
data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
manifestText = getWidgetFactory().createText(metsGroup, "", SWT.READ_ONLY);
manifestText.setLayoutData(data);

CLabel l2 = getWidgetFactory().createCLabel(metsGroup, "Status");
data = new FormData();
data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE);
data.top = new FormAttachment(l1, ITabbedPropertyConstants.VSPACE);
l2.setLayoutData(data);

describedStatusText = getWidgetFactory().createText(metsGroup, "", SWT.READ_ONLY);
data = new FormData();
data.left = new FormAttachment(0, secondTab);
data.top = new FormAttachment(l1, ITabbedPropertyConstants.VSPACE);
describedStatusText.setLayoutData(data);

stagingGroup = getWidgetFactory().createGroup(outer, "Staging");
stagingGroup.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false));
FormLayout layout2 = new FormLayout();
stagingGroup.setLayout(layout2);

CLabel sl = getWidgetFactory().createCLabel(stagingGroup, "Location");
data = new FormData();
data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE);
data.top = new FormAttachment(l2, ITabbedPropertyConstants.VSPACE);
sl.setLayoutData(data);

data = new FormData();
data.left = new FormAttachment(0, secondTab);
data.top = new FormAttachment(l2, ITabbedPropertyConstants.VSPACE);
stagingBaseText = getWidgetFactory().createText(stagingGroup, "", SWT.READ_ONLY);
stagingBaseText.setLayoutData(data);

CLabel hl = getWidgetFactory().createCLabel(stagingGroup, "Status");
data = new FormData();
data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE);
data.top = new FormAttachment(sl, ITabbedPropertyConstants.VSPACE);
hl.setLayoutData(data);

// TODO add a refresh status button

data = new FormData();
data.left = new FormAttachment(0, secondTab);
data.top = new FormAttachment(sl, ITabbedPropertyConstants.VSPACE);
stagingStatusText = getWidgetFactory().createText(stagingGroup, "", SWT.READ_ONLY);
stagingStatusText.setLayoutData(data);

manifestText.pack();
describedStatusText.pack();
stagingBaseText.pack();
stagingStatusText.pack();
metsGroup.pack();
stagingGroup.pack();
}

@Override
public void refresh() {
manifestText.setText(nature.getMetsResource().getURI().toFileString());
describedStatusText.setText(nature.getDescriptionStatus());
stagingBaseText.setText(nature.getStagingBase().toString());
stagingStatusText.setText(nature.getStagingStatus());

manifestText.pack();
describedStatusText.pack();
stagingBaseText.pack();
stagingStatusText.pack();
metsGroup.pack();
stagingGroup.pack();
}

}

0 comments on commit e1a21ef

Please sign in to comment.