1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.io;
|
12
|
|
13
|
import org.eclipse.core.runtime.Assert;
|
14
|
import org.eclipse.core.runtime.IProgressMonitor;
|
15
|
import org.eclipse.core.runtime.IStatus;
|
16
|
import org.eclipse.core.runtime.Status;
|
17
|
import org.eclipse.core.runtime.jobs.Job;
|
18
|
import org.eclipse.swt.widgets.Display;
|
19
|
import org.eclipse.ui.IWorkbenchPart;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
|
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.common.IIoConfigurator;
|
26
|
import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator;
|
27
|
import eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator;
|
28
|
import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter;
|
29
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
30
|
|
31
|
/**
|
32
|
* <p>
|
33
|
* ExportHandler class.
|
34
|
* </p>
|
35
|
*
|
36
|
* @author n.hoffmann
|
37
|
* @created Sep 11, 2009
|
38
|
* @version 1.0
|
39
|
*/
|
40
|
public class ExportManager extends AbstractIOManager<IExportConfigurator> {
|
41
|
|
42
|
/**
|
43
|
*
|
44
|
* @param applicationConfiguration
|
45
|
*/
|
46
|
private ExportManager(ICdmApplicationConfiguration applicationConfiguration) {
|
47
|
super(applicationConfiguration);
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* <p>
|
52
|
* NewInstance
|
53
|
* </p>
|
54
|
*
|
55
|
* @param applicationConfiguration
|
56
|
* a
|
57
|
* {@link eu.etaxonomy.cdm.api.application.CdmApplicationController}
|
58
|
* object.
|
59
|
* @return a {@link eu.etaxonomy.taxeditor.io.ExportManager} object.
|
60
|
*/
|
61
|
public static ExportManager NewInstance(
|
62
|
ICdmApplicationConfiguration applicationConfiguration) {
|
63
|
return new ExportManager(applicationConfiguration);
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* <p>
|
68
|
* createIOJob
|
69
|
* </p>
|
70
|
*
|
71
|
* @param configurator
|
72
|
* a {@link eu.etaxonomy.cdm.io.common.IExportConfigurator}
|
73
|
* object.
|
74
|
* @return a {@link org.eclipse.core.runtime.jobs.Job} object.
|
75
|
*/
|
76
|
@Override
|
77
|
protected Job createIOJob(final IExportConfigurator configurator) {
|
78
|
|
79
|
Assert.isNotNull(configurator, "Configuration may not be null");
|
80
|
|
81
|
final Display display = Display.getCurrent();
|
82
|
|
83
|
Job job = new Job("Export: " + configurator.getClass().getSimpleName()) {
|
84
|
@Override
|
85
|
protected IStatus run(IProgressMonitor monitor) {
|
86
|
monitor.beginTask(
|
87
|
"Exporting database. This will take some time.", 100);
|
88
|
monitor.worked(10);
|
89
|
|
90
|
display.asyncExec(new Runnable() {
|
91
|
|
92
|
@Override
|
93
|
public void run() {
|
94
|
// terminate any open transactions
|
95
|
IConversationEnabled activePart = (IConversationEnabled) StoreUtil
|
96
|
.getActivePage().getActivePart();
|
97
|
activePart.getConversationHolder().commit(false);
|
98
|
}
|
99
|
});
|
100
|
|
101
|
monitor.worked(10);
|
102
|
|
103
|
CdmDefaultExport<IExportConfigurator> exporter = new CdmDefaultExport<IExportConfigurator>();
|
104
|
configurator.setProgressMonitor(CdmProgressMonitorAdapter
|
105
|
.CreateSubMonitor(monitor, 80));
|
106
|
exporter.setCdmAppController(applicationConfiguration);
|
107
|
monitor.worked(10);
|
108
|
|
109
|
try {
|
110
|
exporter.invoke(configurator);
|
111
|
monitor.worked(60);
|
112
|
} catch (RuntimeException e) {
|
113
|
StoreUtil.errorDialog("Error exporting data", this,
|
114
|
"An error occured while"
|
115
|
+ "exporting to destination '"
|
116
|
+ configurator.getDestinationNameString()
|
117
|
+ "'.\n"
|
118
|
+ "Please check error log for details.", e);
|
119
|
}
|
120
|
|
121
|
display.asyncExec(new Runnable() {
|
122
|
|
123
|
@Override
|
124
|
public void run() {
|
125
|
IWorkbenchPart activePart = StoreUtil.getActivePage()
|
126
|
.getActivePart();
|
127
|
if (activePart instanceof IConversationEnabled) {
|
128
|
// terminate any open transactions
|
129
|
IConversationEnabled conversationEnabled = (IConversationEnabled) activePart;
|
130
|
// restarting transaction and committing it to
|
131
|
// trigger
|
132
|
// change listener
|
133
|
// TODO verify correct behaviour
|
134
|
conversationEnabled.getConversationHolder()
|
135
|
.startTransaction();
|
136
|
conversationEnabled.getConversationHolder()
|
137
|
.commit();
|
138
|
}
|
139
|
}
|
140
|
});
|
141
|
monitor.worked(10);
|
142
|
|
143
|
return Status.OK_STATUS;
|
144
|
}
|
145
|
};
|
146
|
|
147
|
return job;
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* @param jaxb
|
152
|
* @return
|
153
|
*/
|
154
|
private IIoConfigurator getConfigurator(TYPE type) {
|
155
|
Assert.isNotNull(type, "Type should not be null");
|
156
|
|
157
|
switch (type) {
|
158
|
case Jaxb:
|
159
|
return JaxbExportConfigurator.NewInstance(null, null);
|
160
|
case Sdd:
|
161
|
return SDDExportConfigurator.NewInstance(null, null, null);
|
162
|
default:
|
163
|
StoreUtil.notImplementedMessage(this);
|
164
|
throw new IllegalArgumentException("Export not supported yet");
|
165
|
}
|
166
|
}
|
167
|
|
168
|
/**
|
169
|
* <p>
|
170
|
* JaxbConfigurator
|
171
|
* </p>
|
172
|
*
|
173
|
* @return a {@link eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator} object.
|
174
|
*/
|
175
|
public final JaxbExportConfigurator JaxbConfigurator() {
|
176
|
return (JaxbExportConfigurator) getConfigurator(TYPE.Jaxb);
|
177
|
}
|
178
|
|
179
|
/**
|
180
|
* <p>
|
181
|
* SddConfigurator
|
182
|
* </p>
|
183
|
*
|
184
|
* @return a {@link eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator}
|
185
|
* object.
|
186
|
*/
|
187
|
public final SDDExportConfigurator SddConfigurator() {
|
188
|
return (SDDExportConfigurator) getConfigurator(TYPE.Sdd);
|
189
|
}
|
190
|
|
191
|
}
|