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
.IIoConfigurator
;
23 import eu
.etaxonomy
.cdm
.io
.common
.ImportResult
;
24 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
25 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.ReportTextDialog
;
29 * Abstract AbstractIOHandler class.
33 * @created Sep 11, 2009
36 public abstract class AbstractIOManager
<CONFIGURATOR
extends IIoConfigurator
> {
38 protected ICdmRepository applicationConfiguration
;
40 public static enum TYPE
{
41 Jaxb
, Tcs
, Excel_Taxa
, Endnote
, Sdd
, Abcd
, SpecimenCdmExcel
, Excel_Name
, SpecimenSearch
, Gbif
, Excel_Distribution
, Ris
46 * Constructor for AbstractIOHandler.
49 * @param applicationController
51 * {@link eu.etaxonomy.cdm.api.application.CdmApplicationController}
53 * @param <CONFIGURATOR>
54 * a CONFIGURATOR object.
56 protected AbstractIOManager(
57 ICdmRepository applicationConfiguration
) {
58 this.applicationConfiguration
= applicationConfiguration
;
62 * Starts the IO process
65 * a CONFIGURATOR object.
67 public void run(final CONFIGURATOR configurator
) {
69 Job job
= createIOJob(configurator
);
73 public void run(Job job
) {
75 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
87 * a CONFIGURATOR object.
88 * @return a {@link org.eclipse.core.runtime.jobs.Job} object.
90 protected abstract Job
createIOJob(CONFIGURATOR configurator
);
97 protected void showResult(String importName
, final Display display
,
98 IoResultBase ioResult
) {
99 StringBuffer reportTextTemp
= ioResult
.createReport();
100 final StringBuffer reportText
;
101 if (StringUtils
.isBlank(reportTextTemp
.toString()) && ioResult
instanceof ImportResult
){
102 //reportTextTemp.append("No update result available");
103 //TODO: this is a workaround because the abcd import writes the report in the report part...
104 ImportResult importResult
= (ImportResult
)ioResult
;
105 if (!importResult
.getReports().isEmpty() && importResult
.getReports().get(0) != null){
106 reportTextTemp
= new StringBuffer();
107 if(importResult
!=null){
108 List
<byte[]> reports
= importResult
.getReports();
109 for (byte[] bs
: reports
) {
110 if (bs
!= null){ reportTextTemp
.append(new String(bs
));}
115 reportText
= reportTextTemp
;
116 if (StringUtils
.isBlank(reportText
.toString())){ return;}
117 display
.asyncExec(new Runnable() {
121 // display reports with possibility to save
122 ReportTextDialog dialog
= new ReportTextDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
123 dialog
.setTitle(importName
+" Report");
124 dialog
.setReportText(reportText
.toString());
126 CdmStore
.getContextManager().notifyContextRefresh();