1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.view.datasource.e4.handler;
|
11
|
|
12
|
import javax.inject.Named;
|
13
|
|
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.e4.core.di.annotations.CanExecute;
|
19
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
20
|
import org.eclipse.jface.dialogs.MessageDialog;
|
21
|
import org.eclipse.swt.SWT;
|
22
|
import org.eclipse.swt.widgets.Shell;
|
23
|
import org.eclipse.ui.progress.IProgressConstants;
|
24
|
|
25
|
import eu.etaxonomy.cdm.config.ICdmSource;
|
26
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
27
|
import eu.etaxonomy.cdm.database.update.CdmUpdater;
|
28
|
import eu.etaxonomy.cdm.database.update.SchemaUpdateResult;
|
29
|
import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter;
|
30
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
31
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
32
|
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
|
33
|
import eu.etaxonomy.taxeditor.view.datasource.e4.CdmDataSourceViewPartE4;
|
34
|
|
35
|
/**
|
36
|
*
|
37
|
* @author pplitzner
|
38
|
* @date 22.08.2017
|
39
|
*
|
40
|
*/
|
41
|
public class UpdateDataSourceHandlerE4 extends AbstractDataSourceHandlerE4 {
|
42
|
|
43
|
/** {@inheritDoc} */
|
44
|
@Override
|
45
|
public boolean specificExecute(CdmDataSourceViewPartE4 dataSourceViewPart,
|
46
|
CdmMetaDataAwareDataSourceContainer container, Shell shell) {
|
47
|
if(! MessageDialog.open(MessageDialog.CONFIRM, shell, "Update Datasource", "WARNING!\n\n" +
|
48
|
"This will change your data base structure! Be sure you have an up-to-date backup of your data before running the update! \n\n " +
|
49
|
"Are you sure you want to update the datasource?", SWT.NONE)){
|
50
|
return false;
|
51
|
}
|
52
|
Job job = new Job("Updating datasource " + container.getCdmSource().getName()){
|
53
|
|
54
|
@Override
|
55
|
protected IStatus run(IProgressMonitor monitor) {
|
56
|
CdmUpdater updater = new CdmUpdater();
|
57
|
IStatus status = null;
|
58
|
ICdmSource cdmSource = container.getCdmSource();
|
59
|
//FIXME:Remoting we need another updater for ICdmRemoteSource
|
60
|
if(cdmSource instanceof ICdmDataSource) {
|
61
|
try{
|
62
|
SchemaUpdateResult result = updater.updateToCurrentVersion(
|
63
|
(ICdmDataSource)cdmSource, CdmProgressMonitorAdapter.CreateMonitor(monitor));
|
64
|
if(result.isSuccess()){
|
65
|
sync.asyncExec(()->{
|
66
|
if(dataSourceViewPart!= null){
|
67
|
container.getMetaDataFromDataSource();
|
68
|
dataSourceViewPart.getViewer().update(new CdmMetaDataAwareDataSourceContainer[]{container}, null);
|
69
|
}
|
70
|
}
|
71
|
);
|
72
|
status = Status.OK_STATUS;
|
73
|
}else{
|
74
|
throw new RuntimeException("An error occurred during the update.");
|
75
|
}
|
76
|
}catch(Exception e){
|
77
|
status = new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, e.getMessage(), e);
|
78
|
MessagingUtils.errorDialog("Could not complete updater", updater, status.getMessage(), status.getPlugin(), e, true);
|
79
|
}
|
80
|
}
|
81
|
|
82
|
return status;
|
83
|
}
|
84
|
|
85
|
};
|
86
|
|
87
|
job.setPriority(Job.BUILD);
|
88
|
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
89
|
job.schedule();
|
90
|
|
91
|
return true;
|
92
|
}
|
93
|
|
94
|
|
95
|
@CanExecute
|
96
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container){
|
97
|
return container.isDataSourceCompatible();
|
98
|
}
|
99
|
}
|