2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.io
;
12 import java
.util
.List
;
14 import org
.apache
.commons
.lang
.StringUtils
;
15 import org
.eclipse
.core
.runtime
.jobs
.Job
;
16 import org
.eclipse
.swt
.widgets
.Display
;
17 import org
.eclipse
.ui
.PlatformUI
;
18 import org
.eclipse
.ui
.progress
.IProgressConstants
;
20 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
21 import eu
.etaxonomy
.cdm
.common
.IoResultBase
;
22 import eu
.etaxonomy
.cdm
.io
.common
.ExportResult
;
23 import eu
.etaxonomy
.cdm
.io
.common
.IIoConfigurator
;
24 import eu
.etaxonomy
.cdm
.io
.common
.ImportResult
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
26 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.ReportTextDialog
;
30 * Abstract AbstractIOHandler class.
34 * @created Sep 11, 2009
37 public abstract class AbstractIOManager
<CONFIGURATOR
extends IIoConfigurator
> {
39 protected ICdmRepository applicationConfiguration
;
41 public static enum TYPE
{
42 Jaxb
, Tcs
, Excel_Taxa
, Endnote
, Sdd
, Abcd
, SpecimenCdmExcel
, Excel_Name
, SpecimenSearch
, Gbif
, Excel_Distribution
, Ris
47 * Constructor for AbstractIOHandler.
50 * @param applicationController
52 * {@link eu.etaxonomy.cdm.api.application.CdmApplicationController}
54 * @param <CONFIGURATOR>
55 * a CONFIGURATOR object.
57 protected AbstractIOManager(
58 ICdmRepository applicationConfiguration
) {
59 this.applicationConfiguration
= applicationConfiguration
;
63 * Starts the IO process
66 * a CONFIGURATOR object.
68 public void run(final CONFIGURATOR configurator
) {
70 Job job
= createIOJob(configurator
);
74 public void run(Job job
) {
76 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
88 * a CONFIGURATOR object.
89 * @return a {@link org.eclipse.core.runtime.jobs.Job} object.
91 protected abstract Job
createIOJob(CONFIGURATOR configurator
);
98 protected void showResult(String importName
, final Display display
,
99 IoResultBase ioResult
, String successMessage
) {
100 StringBuffer reportTextTemp
= ioResult
.createReport();
101 final StringBuffer reportText
;
102 if (StringUtils
.isBlank(reportTextTemp
.toString()) && ioResult
instanceof ImportResult
){
103 reportTextTemp
.append(successMessage
);
104 //TODO: this is a workaround because the abcd import writes the report in the report part...
105 ImportResult importResult
= (ImportResult
)ioResult
;
106 if (!importResult
.getReports().isEmpty() && importResult
.getReports().get(0) != null){
107 reportTextTemp
= new StringBuffer();
108 if(importResult
!=null){
109 List
<byte[]> reports
= importResult
.getReports();
110 for (byte[] bs
: reports
) {
111 if (bs
!= null){ reportTextTemp
.append(new String(bs
));}
116 reportText
= reportTextTemp
;
117 if (StringUtils
.isBlank(reportText
.toString()) && ioResult
instanceof ExportResult
){ reportText
.append("The Export was succesfull.");}
118 display
.asyncExec(new Runnable() {
122 // display reports with possibility to save
123 ReportTextDialog dialog
= new ReportTextDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
124 dialog
.setTitle(importName
+" Report");
125 dialog
.setReportText(reportText
.toString());
127 CdmStore
.getContextManager().notifyContextRefresh();