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.datasource.handler;
|
12
|
|
13
|
import org.eclipse.core.commands.ExecutionEvent;
|
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.progress.IProgressConstants;
|
20
|
|
21
|
import eu.etaxonomy.cdm.database.update.CdmUpdater;
|
22
|
import eu.etaxonomy.taxeditor.datasource.view.CdmDataSourceViewPart;
|
23
|
import eu.etaxonomy.taxeditor.datasource.view.CdmMetaDataAwareDataSourceContainer;
|
24
|
import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter;
|
25
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
26
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
27
|
|
28
|
/**
|
29
|
* <p>UpdateDataSourceHandler class.</p>
|
30
|
*
|
31
|
* @author n.hoffmann
|
32
|
* @created Sep 22, 2010
|
33
|
* @version 1.0
|
34
|
*/
|
35
|
public class UpdateDataSourceHandler extends AbstractDataSourceHandler {
|
36
|
|
37
|
/* (non-Javadoc)
|
38
|
* @see eu.etaxonomy.taxeditor.datasource.handler.AbstractDataSourceHandler#specificExecute(org.eclipse.core.commands.ExecutionEvent)
|
39
|
*/
|
40
|
/** {@inheritDoc} */
|
41
|
@Override
|
42
|
public boolean specificExecute(ExecutionEvent event) {
|
43
|
final CdmMetaDataAwareDataSourceContainer container = getSelectedDataSourceContainer(event);
|
44
|
|
45
|
final Display display = Display.getCurrent();
|
46
|
|
47
|
Job job = new Job("Updating datasource " + container.getDataSource().getName()){
|
48
|
|
49
|
@Override
|
50
|
protected IStatus run(IProgressMonitor monitor) {
|
51
|
CdmUpdater updater = new CdmUpdater();
|
52
|
IStatus status = null;
|
53
|
try{
|
54
|
if(updater.updateToCurrentVersion(container.getDataSource(), CdmProgressMonitorAdapter.CreateMonitor(monitor))){
|
55
|
display.asyncExec(new Runnable(){
|
56
|
|
57
|
@Override
|
58
|
public void run() {
|
59
|
|
60
|
CdmDataSourceViewPart view = (CdmDataSourceViewPart) StoreUtil.getView(CdmDataSourceViewPart.ID, false);
|
61
|
if(view != null){
|
62
|
view.getViewer().update(new CdmMetaDataAwareDataSourceContainer[]{container}, null);
|
63
|
}
|
64
|
|
65
|
}
|
66
|
});
|
67
|
status = Status.OK_STATUS;
|
68
|
}
|
69
|
}catch(Exception e){
|
70
|
status = new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, e.getMessage(), e);
|
71
|
StoreUtil.errorDialog("Could not run updater", getClass(), status);
|
72
|
}
|
73
|
|
74
|
|
75
|
return status;
|
76
|
}
|
77
|
|
78
|
};
|
79
|
|
80
|
job.setPriority(Job.BUILD);
|
81
|
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
82
|
job.schedule();
|
83
|
|
84
|
return false;
|
85
|
}
|
86
|
}
|