3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.view
.datasource
.handler
;
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
.jface
.dialogs
.MessageDialog
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.widgets
.Display
;
21 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
22 import org
.eclipse
.ui
.progress
.IProgressConstants
;
24 import eu
.etaxonomy
.cdm
.config
.ICdmSource
;
25 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
26 import eu
.etaxonomy
.cdm
.database
.update
.CdmUpdater
;
27 import eu
.etaxonomy
.taxeditor
.model
.CdmProgressMonitorAdapter
;
28 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
29 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
30 import eu
.etaxonomy
.taxeditor
.view
.datasource
.CdmDataSourceViewPart
;
31 import eu
.etaxonomy
.taxeditor
.view
.datasource
.CdmMetaDataAwareDataSourceContainer
;
34 * <p>UpdateDataSourceHandler class.</p>
37 * @created Sep 22, 2010
40 public class UpdateDataSourceHandler
extends AbstractDataSourceHandler
{
43 * @see eu.etaxonomy.taxeditor.datasource.handler.AbstractDataSourceHandler#specificExecute(org.eclipse.core.commands.ExecutionEvent)
47 public boolean specificExecute(ExecutionEvent event
) {
48 final CdmMetaDataAwareDataSourceContainer container
= getSelectedDataSourceContainer(event
);
50 final Display display
= Display
.getCurrent();
51 if(! MessageDialog
.open(MessageDialog
.CONFIRM
, HandlerUtil
.getActiveShell(event
), "Update Datasource", "WARNING!\n\n" +
52 "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 " +
53 "Are you sure you want to update the datasource?", SWT
.NONE
)){
56 Job job
= new Job("Updating datasource " + container
.getCdmSource().getName()){
59 protected IStatus
run(IProgressMonitor monitor
) {
60 CdmUpdater updater
= new CdmUpdater();
61 IStatus status
= null;
62 ICdmSource cdmSource
= container
.getCdmSource();
63 //FIXME:Remoting we need another updater for ICdmRemoteSource
64 if(cdmSource
instanceof ICdmDataSource
) {
66 if(updater
.updateToCurrentVersion((ICdmDataSource
)cdmSource
, CdmProgressMonitorAdapter
.CreateMonitor(monitor
))){
67 display
.asyncExec(new Runnable(){
72 CdmDataSourceViewPart view
= (CdmDataSourceViewPart
) StoreUtil
.getView(CdmDataSourceViewPart
.ID
, false);
74 view
.getViewer().update(new CdmMetaDataAwareDataSourceContainer
[]{container
}, null);
79 status
= Status
.OK_STATUS
;
82 status
= new Status(IStatus
.ERROR
, TaxeditorStorePlugin
.PLUGIN_ID
, e
.getMessage(), e
);
83 StoreUtil
.errorDialog("Could not run updater", getClass(), status
.getMessage());
92 job
.setPriority(Job
.BUILD
);
93 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);