3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.io
;
13 import java
.lang
.reflect
.InvocationTargetException
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.core
.runtime
.Assert
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.jface
.dialogs
.ProgressMonitorDialog
;
19 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
21 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
22 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
23 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultExport
;
24 import eu
.etaxonomy
.cdm
.io
.common
.IExportConfigurator
;
25 import eu
.etaxonomy
.cdm
.io
.jaxb
.JaxbExportConfigurator
;
26 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
30 * @created Sep 11, 2009
33 public class ExportHandler
extends AbstractIOHandler
{
34 private static final Logger logger
= Logger
35 .getLogger(ExportHandler
.class);
39 * @param applicationController
41 private ExportHandler(CdmApplicationController applicationController
){
42 super(applicationController
);
47 * @param applicationController
50 public static ExportHandler
NewInstance(CdmApplicationController applicationController
){
51 return new ExportHandler(applicationController
);
55 * Starts the export process
59 public void run(final IExportConfigurator configurator
){
60 ProgressMonitorDialog dialog
= new ProgressMonitorDialog(StoreUtil
.getShell());
63 dialog
.run(false, true, new IRunnableWithProgress() {
67 * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
69 public void run(IProgressMonitor monitor
)
70 throws InvocationTargetException
, InterruptedException
{
71 doExport(monitor
, configurator
);
74 }catch (InvocationTargetException e
) {
76 throw new RuntimeException(e
);
77 } catch (InterruptedException e
) {
79 throw new RuntimeException(e
);
89 private void doExport(IProgressMonitor monitor
, IExportConfigurator configurator
){
91 Assert
.isNotNull(configurator
, "Configuration may not be null");
93 monitor
.beginTask("Exporting database. This will take some time.", 100);
96 // terminate any open transactions
97 IConversationEnabled activePart
= (IConversationEnabled
) StoreUtil
.getActivePage().getActivePart();
98 activePart
.getConversationHolder().commit(false);
101 CdmDefaultExport
<IExportConfigurator
> exporter
= new CdmDefaultExport
<IExportConfigurator
>();
103 exporter
.setCdmAppController(applicationController
);
107 exporter
.invoke(configurator
);
109 }catch(RuntimeException e
){
110 StoreUtil
.errorDialog("Error exporting data", "An error occured while" +
111 "exporting to destination '" + configurator
.getDestinationNameString() + "'.\n" +
112 "Please check error log for details.");
113 logger
.error("Error exporting data", e
);
116 // restarting transaction and committing it to trigger change listener
117 // TODO verify correct behaviour
118 activePart
.getConversationHolder().startTransaction();
119 activePart
.getConversationHolder().commit();
127 private JaxbExportConfigurator
getConfigurator(TYPE type
) {
128 Assert
.isNotNull(type
, "Type should not be null");
132 return JaxbExportConfigurator
.NewInstance(null, null);
134 StoreUtil
.notImplementedMessage();
135 throw new IllegalArgumentException("Export not supported yet");
143 public final JaxbExportConfigurator
JaxbConfigurator() { return (JaxbExportConfigurator
) getConfigurator(TYPE
.Jaxb
); }