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.handler;
|
11
|
|
12
|
import org.eclipse.core.commands.ExecutionEvent;
|
13
|
import org.eclipse.core.runtime.IProgressMonitor;
|
14
|
import org.eclipse.core.runtime.IStatus;
|
15
|
import org.eclipse.core.runtime.jobs.Job;
|
16
|
import org.eclipse.jface.dialogs.MessageDialog;
|
17
|
import org.eclipse.swt.SWT;
|
18
|
import org.eclipse.swt.widgets.Display;
|
19
|
import org.eclipse.ui.handlers.HandlerUtil;
|
20
|
import org.eclipse.ui.progress.IProgressConstants;
|
21
|
|
22
|
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
|
23
|
|
24
|
/**
|
25
|
* <p>UpdateDataSourceHandler class.</p>
|
26
|
*
|
27
|
* @author n.hoffmann
|
28
|
* @created Sep 22, 2010
|
29
|
* @version 1.0
|
30
|
*/
|
31
|
public class UpdateDataSourceHandler extends AbstractDataSourceHandler {
|
32
|
|
33
|
/* (non-Javadoc)
|
34
|
* @see eu.etaxonomy.taxeditor.datasource.handler.AbstractDataSourceHandler#specificExecute(org.eclipse.core.commands.ExecutionEvent)
|
35
|
*/
|
36
|
/** {@inheritDoc} */
|
37
|
@Override
|
38
|
public boolean specificExecute(ExecutionEvent event) {
|
39
|
final CdmMetaDataAwareDataSourceContainer container = getSelectedDataSourceContainer(event);
|
40
|
|
41
|
final Display display = Display.getCurrent();
|
42
|
if(! MessageDialog.open(MessageDialog.CONFIRM, HandlerUtil.getActiveShell(event), "Update Datasource", "WARNING!\n\n" +
|
43
|
"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 " +
|
44
|
"Are you sure you want to update the datasource?", SWT.NONE)){
|
45
|
return false;
|
46
|
}
|
47
|
Job job = new Job("Updating datasource " + container.getCdmSource().getName()){
|
48
|
|
49
|
@Override
|
50
|
protected IStatus run(IProgressMonitor monitor) {
|
51
|
// CdmUpdater updater = new CdmUpdater();
|
52
|
IStatus status = null;
|
53
|
// ICdmSource cdmSource = container.getCdmSource();
|
54
|
// //FIXME:Remoting we need another updater for ICdmRemoteSource
|
55
|
// if(cdmSource instanceof ICdmDataSource) {
|
56
|
// try{
|
57
|
// SchemaUpdateResult result = updater.updateToCurrentVersion(
|
58
|
// (ICdmDataSource)cdmSource, CdmProgressMonitorAdapter.CreateMonitor(monitor));
|
59
|
// if(result.isSuccess()){
|
60
|
// display.asyncExec(new Runnable(){
|
61
|
//
|
62
|
// @Override
|
63
|
// public void run() {
|
64
|
//
|
65
|
// CdmDataSourceViewPart view = (CdmDataSourceViewPart) StoreUtil.getView(CdmDataSourceViewPart.ID, false);
|
66
|
// if(view != null){
|
67
|
// container.getMetaDataFromDataSource();
|
68
|
// view.getViewer().update(new CdmMetaDataAwareDataSourceContainer[]{container}, null);
|
69
|
// }
|
70
|
//
|
71
|
// }
|
72
|
// });
|
73
|
// status = Status.OK_STATUS;
|
74
|
// }else{
|
75
|
// throw new RuntimeException("An error occurred during the update.");
|
76
|
// }
|
77
|
// }catch(Exception e){
|
78
|
// status = new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, e.getMessage(), e);
|
79
|
// MessagingUtils.errorDialog("Could not complete updater", updater, status.getMessage(), status.getPlugin(), e, true);
|
80
|
// }
|
81
|
// }
|
82
|
|
83
|
return status;
|
84
|
}
|
85
|
|
86
|
};
|
87
|
|
88
|
job.setPriority(Job.BUILD);
|
89
|
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
90
|
job.schedule();
|
91
|
|
92
|
return false;
|
93
|
}
|
94
|
}
|