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
.model
.MessagingUtils
;
29 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
30 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
31 import eu
.etaxonomy
.taxeditor
.view
.datasource
.CdmDataSourceViewPart
;
32 import eu
.etaxonomy
.taxeditor
.view
.datasource
.CdmMetaDataAwareDataSourceContainer
;
35 * <p>UpdateDataSourceHandler class.</p>
38 * @created Sep 22, 2010
41 public class UpdateDataSourceHandler
extends AbstractDataSourceHandler
{
44 * @see eu.etaxonomy.taxeditor.datasource.handler.AbstractDataSourceHandler#specificExecute(org.eclipse.core.commands.ExecutionEvent)
48 public boolean specificExecute(ExecutionEvent event
) {
49 final CdmMetaDataAwareDataSourceContainer container
= getSelectedDataSourceContainer(event
);
51 final Display display
= Display
.getCurrent();
52 if(! MessageDialog
.open(MessageDialog
.CONFIRM
, HandlerUtil
.getActiveShell(event
), "Update Datasource", "WARNING!\n\n" +
53 "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 " +
54 "Are you sure you want to update the datasource?", SWT
.NONE
)){
57 Job job
= new Job("Updating datasource " + container
.getCdmSource().getName()){
60 protected IStatus
run(IProgressMonitor monitor
) {
61 CdmUpdater updater
= new CdmUpdater();
62 IStatus status
= null;
63 ICdmSource cdmSource
= container
.getCdmSource();
64 //FIXME:Remoting we need another updater for ICdmRemoteSource
65 if(cdmSource
instanceof ICdmDataSource
) {
67 if(updater
.updateToCurrentVersion((ICdmDataSource
)cdmSource
, CdmProgressMonitorAdapter
.CreateMonitor(monitor
))){
68 display
.asyncExec(new Runnable(){
73 CdmDataSourceViewPart view
= (CdmDataSourceViewPart
) StoreUtil
.getView(CdmDataSourceViewPart
.ID
, false);
75 container
.getMetaDataFromDataSource();
76 view
.getViewer().update(new CdmMetaDataAwareDataSourceContainer
[]{container
}, null);
81 status
= Status
.OK_STATUS
;
83 throw new RuntimeException("An error occurred during the update.");
86 status
= new Status(IStatus
.ERROR
, TaxeditorStorePlugin
.PLUGIN_ID
, e
.getMessage(), e
);
87 MessagingUtils
.errorDialog("Could not complete updater", updater
, status
.getMessage(), status
.getPlugin(), e
, true);
96 job
.setPriority(Job
.BUILD
);
97 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);