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