1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.io;
|
10
|
|
11
|
import java.util.List;
|
12
|
|
13
|
import org.apache.commons.lang3.StringUtils;
|
14
|
import org.eclipse.core.runtime.jobs.Job;
|
15
|
import org.eclipse.swt.widgets.Display;
|
16
|
import org.eclipse.ui.PlatformUI;
|
17
|
import org.eclipse.ui.progress.IProgressConstants;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
20
|
import eu.etaxonomy.cdm.common.IoResultBase;
|
21
|
import eu.etaxonomy.cdm.io.common.ExportResult;
|
22
|
import eu.etaxonomy.cdm.io.common.IIoConfigurator;
|
23
|
import eu.etaxonomy.cdm.io.common.ImportResult;
|
24
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
25
|
import eu.etaxonomy.taxeditor.ui.dialog.ReportTextDialog;
|
26
|
|
27
|
/**
|
28
|
* @author n.hoffmann
|
29
|
* @created Sep 11, 2009
|
30
|
*/
|
31
|
public abstract class AbstractIOManager<CONFIGURATOR extends IIoConfigurator> {
|
32
|
|
33
|
protected ICdmRepository applicationConfiguration;
|
34
|
|
35
|
public static enum TYPE {
|
36
|
Jaxb, Tcs, Excel_Taxa, Endnote, Sdd, Abcd, SpecimenCdmExcel, Excel_Name, SpecimenSearch, Gbif, Excel_Distribution, Ris, OWL
|
37
|
}
|
38
|
|
39
|
protected AbstractIOManager(
|
40
|
ICdmRepository applicationConfiguration) {
|
41
|
this.applicationConfiguration = applicationConfiguration;
|
42
|
}
|
43
|
//
|
44
|
// /**
|
45
|
// * Starts the IO process
|
46
|
// *
|
47
|
// * @param configurator
|
48
|
// * a CONFIGURATOR object.
|
49
|
// */
|
50
|
// public void run(final CONFIGURATOR configurator) {
|
51
|
// // create job
|
52
|
// Job job = createIOJob(configurator);
|
53
|
// run(job);
|
54
|
// }
|
55
|
|
56
|
public void run(Job job) {
|
57
|
// configure the job
|
58
|
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
59
|
job.setUser(true);
|
60
|
// schedule job
|
61
|
job.schedule();
|
62
|
}
|
63
|
|
64
|
// /**
|
65
|
// * <p>
|
66
|
// * createIOJob
|
67
|
// * </p>
|
68
|
// *
|
69
|
// * @param configurator
|
70
|
// * a CONFIGURATOR object.
|
71
|
// * @return a {@link org.eclipse.core.runtime.jobs.Job} object.
|
72
|
// */
|
73
|
// protected abstract Job createIOJob(CONFIGURATOR configurator);
|
74
|
|
75
|
/**
|
76
|
* @param configurator
|
77
|
* @param display
|
78
|
* @param importResult
|
79
|
*/
|
80
|
protected void showResult(String importName, final Display display,
|
81
|
IoResultBase ioResult, String successMessage) {
|
82
|
StringBuffer reportTextTemp = ioResult.createReport();
|
83
|
final StringBuffer reportText;
|
84
|
if (StringUtils.isBlank(reportTextTemp.toString()) && ioResult instanceof ImportResult){
|
85
|
reportTextTemp.append(successMessage);
|
86
|
//TODO: this is a workaround because the abcd import writes the report in the report part...
|
87
|
ImportResult importResult = (ImportResult)ioResult;
|
88
|
if (!importResult.getReports().isEmpty() && importResult.getReports().get(0) != null){
|
89
|
reportTextTemp = new StringBuffer();
|
90
|
if(importResult!=null){
|
91
|
List<byte[]> reports = importResult.getReports();
|
92
|
for (byte[] bs : reports) {
|
93
|
if (bs != null){ reportTextTemp.append(new String(bs));}
|
94
|
}
|
95
|
}
|
96
|
}
|
97
|
}
|
98
|
reportText = reportTextTemp;
|
99
|
if (StringUtils.isBlank(reportText.toString()) && ioResult instanceof ExportResult ){ reportText.append("The Export was succesfull.");}
|
100
|
display.asyncExec(new Runnable() {
|
101
|
|
102
|
@Override
|
103
|
public void run() {
|
104
|
// display reports with possibility to save
|
105
|
ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
|
106
|
dialog.setTitle(importName+" Report");
|
107
|
dialog.setReportText(reportText.toString());
|
108
|
dialog.open();
|
109
|
CdmStore.getContextManager().notifyContextRefresh();
|
110
|
}
|
111
|
});
|
112
|
}
|
113
|
|
114
|
}
|