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
.database
.update
.CdmUpdater
;
25 import eu
.etaxonomy
.taxeditor
.model
.CdmProgressMonitorAdapter
;
26 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
27 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
28 import eu
.etaxonomy
.taxeditor
.view
.datasource
.CdmDataSourceViewPart
;
29 import eu
.etaxonomy
.taxeditor
.view
.datasource
.CdmMetaDataAwareDataSourceContainer
;
32 * <p>UpdateDataSourceHandler class.</p>
35 * @created Sep 22, 2010
38 public class UpdateDataSourceHandler
extends AbstractDataSourceHandler
{
41 * @see eu.etaxonomy.taxeditor.datasource.handler.AbstractDataSourceHandler#specificExecute(org.eclipse.core.commands.ExecutionEvent)
45 public boolean specificExecute(ExecutionEvent event
) {
46 final CdmMetaDataAwareDataSourceContainer container
= getSelectedDataSourceContainer(event
);
48 final Display display
= Display
.getCurrent();
49 if(! MessageDialog
.open(MessageDialog
.CONFIRM
, HandlerUtil
.getActiveShell(event
), "Update Datasource", "WARNING!\n\n" +
50 "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 " +
51 "Are you sure you want to update the datasource?", SWT
.NONE
)){
54 Job job
= new Job("Updating datasource " + container
.getDataSource().getName()){
57 protected IStatus
run(IProgressMonitor monitor
) {
58 CdmUpdater updater
= new CdmUpdater();
59 IStatus status
= null;
62 if(updater
.updateToCurrentVersion(container
.getDataSource(), CdmProgressMonitorAdapter
.CreateMonitor(monitor
))){
63 display
.asyncExec(new Runnable(){
68 CdmDataSourceViewPart view
= (CdmDataSourceViewPart
) StoreUtil
.getView(CdmDataSourceViewPart
.ID
, false);
70 view
.getViewer().update(new CdmMetaDataAwareDataSourceContainer
[]{container
}, null);
75 status
= Status
.OK_STATUS
;
78 status
= new Status(IStatus
.ERROR
, TaxeditorStorePlugin
.PLUGIN_ID
, e
.getMessage(), e
);
79 StoreUtil
.errorDialog("Could not run updater", getClass(), status
.getMessage());
88 job
.setPriority(Job
.BUILD
);
89 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);