* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
-
package eu.etaxonomy.taxeditor.model;
import java.io.BufferedWriter;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.AbstractOperation;
import eu.etaxonomy.cdm.io.common.ExportResult;
import eu.etaxonomy.cdm.io.common.ExportResultType;
import eu.etaxonomy.cdm.io.common.ExportType;
-import eu.etaxonomy.cdm.io.common.ImportResult;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.taxon.Synonym;
import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.cdm.model.term.IEnumTerm;
import eu.etaxonomy.taxeditor.event.EventUtility;
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
import eu.etaxonomy.taxeditor.operation.IFeedbackGenerator;
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
-import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
+import eu.etaxonomy.taxeditor.operation.e4.CdmHandlerE4;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
import eu.etaxonomy.taxeditor.ui.dialog.ReportTextDialog;
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
/**
- *
* @author n.hoffmann
* @created 11.05.2009
- * @version 1.0
*/
public abstract class AbstractUtility {
return TaxeditorStorePlugin.getDefault().getWorkbench();
}
+ @SuppressWarnings("unchecked")
public static Object getService(Class api) {
return TaxeditorStorePlugin.getDefault().getWorkbench().getService(api);
}
return Status.OK_STATUS;
}
- public static IStatus executeOperation(final AbstractOperation operation, final RemotingCdmHandlerE4 handler, UISynchronize sync) {
+ public static IStatus executeOperation(final AbstractOperation operation, final CdmHandlerE4 handler, UISynchronize sync) {
return executeOperation_internal(operation, handler, sync);
}
- private static IStatus executeOperation_internal(final AbstractOperation operation, final RemotingCdmHandlerE4 handler,
+ private static IStatus executeOperation_internal(final AbstractOperation operation, final CdmHandlerE4 handler,
UISynchronize sync) {
if (getOperationHistory() == null) {
throw new IllegalArgumentException(
feedbackGenerator,
subMonitor);
} catch (Exception ex) {
- return new Status(Status.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ex);
+ return new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ex);
}
createExportResult(label, urlString, createZip, remotingMonitor);
if(depth>0){
indentString += "- ";
}
- result.put(node.term, indentString + node.term.getMessage());
+ result.put(node.term, indentString + node.term.getLabel());
parseTermTree(node.children, result, depth);
}
}
@Override
public int compareTo(TermNode<T> that) {
- return this.term.getMessage().compareTo(that.term.getMessage());
+ return this.term.getLabel().compareTo(that.term.getLabel());
}
}
final boolean cancelable,
final IPostMoniteredOperationEnabled postOp,
final IFeedbackGenerator feedbackGenerator,
- final boolean showResult) {
+ final boolean showResult,
+ final boolean updateNavigator) {
try{
// get the remoting monitor the first time to make sure that the
}
if (firstRemotingMonitor.isDone()){
createResult(label, showResult, firstRemotingMonitor);
+ Set<Taxon> taxaToUpdate = getTaxaToUpdate(firstRemotingMonitor);
+ updateNameEditors(taxaToUpdate);
return Status.OK_STATUS;
}
Job job = new Job(label) {
-
-
@Override
public IStatus run(IProgressMonitor monitor) {
// run the monitor until the operation is finished
feedbackGenerator,
subMonitor);
} catch (Exception ex) {
- return new Status(Status.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ex);
+ return new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ex);
}
-
// collect reports
// for(String report : remotingMonitor.getResult()) {
createResult(label, showResult, remotingMonitor);
Set<Taxon> taxaToUpdate = getTaxaToUpdate(remotingMonitor);
updateNameEditors(taxaToUpdate);
- if (!taxaToUpdate.isEmpty()){
+ if (!taxaToUpdate.isEmpty() && updateNavigator){
refreshNavigator();
}
return Status.OK_STATUS;
}
-
-
- private Set<Taxon> getTaxaToUpdate(IRemotingProgressMonitor remotingMonitor) {
- Set<Taxon> taxaToUpdate = new HashSet<>();
- if (remotingMonitor.getResult() instanceof UpdateResult){
- for (CdmBase object: ((UpdateResult)remotingMonitor.getResult()).getUpdatedObjects()){
- Taxon taxon = null;
-
- if (object instanceof Taxon){
- taxon = HibernateProxyHelper.deproxy(object, Taxon.class);
-
-
- }else if (object instanceof Synonym){
- Synonym syn = HibernateProxyHelper.deproxy(object, Synonym.class);
- taxon = syn.getAcceptedTaxon();
- }
-
- taxaToUpdate.add(taxon);
- }
- }else if (remotingMonitor.getResult() instanceof ImportResult){
- Map<String, Integer> result = ((ImportResult)remotingMonitor.getResult()).getUpdatedRecords();
- for (Map.Entry<String, Integer> object: result.entrySet()){
- Taxon taxon = null;
- if (object instanceof Taxon){
- taxon = HibernateProxyHelper.deproxy(object, Taxon.class);
- }else if (object instanceof Synonym){
- Synonym syn = HibernateProxyHelper.deproxy(object, Synonym.class);
- taxon = syn.getAcceptedTaxon();
- }
- taxaToUpdate.add(taxon);
- }
-
- }
- return taxaToUpdate;
- }
-
-
-
private void refreshNavigator() {
EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAVIGATOR, true);
-
}
-
-
@Override
protected void canceling() {
CdmStore.getCurrentApplicationConfiguration().getProgressMonitorService().cancel(uuid);
}
return Status.OK_STATUS;
- }
-
+ }
+ private static Set<Taxon> getTaxaToUpdate(IRemotingProgressMonitor remotingMonitor) {
+ Set<Taxon> taxaToUpdate = new HashSet<>();
+ if (remotingMonitor.getResult() instanceof UpdateResult){
+ for (CdmBase object: ((UpdateResult)remotingMonitor.getResult()).getUpdatedObjects()){
+ Taxon taxon = null;
+
+ if (object instanceof Taxon){
+ taxon = HibernateProxyHelper.deproxy(object, Taxon.class);
+ }else if (object instanceof Synonym){
+ Synonym syn = HibernateProxyHelper.deproxy(object, Synonym.class);
+ taxon = syn.getAcceptedTaxon();
+ }else if (object instanceof TaxonNode){
+ taxon = ((TaxonNode)object).getTaxon() != null? ((TaxonNode)object).getTaxon():null;
+ }
+ if (taxon != null){
+ taxaToUpdate.add(taxon);
+ }
+ }
+ }
+ return taxaToUpdate;
+ }
public static void createResult(String label, boolean showResult,
IRemotingProgressMonitor remotingMonitor) {
final StringBuilder reportSb = new StringBuilder();
reportSb.append(o);
}
}
-// }
if(showResult && !StringUtils.isBlank(reportSb.toString()) && reportSb.length() != 0) {
Display.getDefault().asyncExec(new Runnable() {
@Override
}
if (urlString != null){
- ExportDataWrapper data = result.getExportData();
+ ExportDataWrapper<?> data = result.getExportData();
try{
if (result.getExportData().getType().equals(ExportResultType.BYTE_ARRAY)){
byte[] exportData = (byte[])data.getExportData();
String fileEnding = ".csv";
if (createZip){
- File file = new File(urlString+File.separator + sdf.format(cal.getTime())+ ".zip");
+// File file = new File(urlString+File.separator + sdf.format(cal.getTime())+ ".zip");
+ File file = new File(urlString+ ".zip");
FileOutputStream stream = new FileOutputStream(file);
ZipOutputStream zos = new ZipOutputStream(stream);
for (String key: keySet){
}
}
public static void updateNameEditors(Set<Taxon> taxaToUpdate){
- EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, taxaToUpdate);
+ for (Taxon tax: taxaToUpdate){
+ if (tax != null){
+ EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, tax.getUuid());
+ }
+ }
}
-
-
-}
+}
\ No newline at end of file