Project

General

Profile

Download (2.75 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
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.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.view.datasource.handler;
12

    
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.swt.widgets.Display;
19
import org.eclipse.ui.progress.IProgressConstants;
20

    
21
import eu.etaxonomy.cdm.database.update.CdmUpdater;
22
import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter;
23
import eu.etaxonomy.taxeditor.store.StoreUtil;
24
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
25
import eu.etaxonomy.taxeditor.store.singlesource.widget.DisplayProxy;
26
import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart;
27
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
28

    
29
/**
30
 * <p>UpdateDataSourceHandler class.</p>
31
 *
32
 * @author n.hoffmann
33
 * @created Sep 22, 2010
34
 * @version 1.0
35
 */
36
public class UpdateDataSourceHandler extends AbstractDataSourceHandler {
37
	
38
	/* (non-Javadoc)
39
	 * @see eu.etaxonomy.taxeditor.datasource.handler.AbstractDataSourceHandler#specificExecute(org.eclipse.core.commands.ExecutionEvent)
40
	 */
41
	/** {@inheritDoc} */
42
	@Override
43
	public boolean specificExecute(ExecutionEvent event) {
44
		final CdmMetaDataAwareDataSourceContainer container = getSelectedDataSourceContainer(event);
45
		
46
		final Display display = DisplayProxy.getDefault();
47
		
48
		Job job = new Job("Updating datasource " + container.getDataSource().getName()){
49

    
50
			@Override
51
			protected IStatus run(IProgressMonitor monitor) {
52
				CdmUpdater updater = new CdmUpdater();
53
				IStatus status = null;
54
				try{
55
					if(updater.updateToCurrentVersion(container.getDataSource(), CdmProgressMonitorAdapter.CreateMonitor(monitor))){
56
						display.asyncExec(new Runnable(){
57

    
58
							@Override
59
							public void run() {
60
								
61
								CdmDataSourceViewPart view = (CdmDataSourceViewPart) StoreUtil.getView(CdmDataSourceViewPart.ID, false);
62
								if(view != null){
63
									view.getViewer().update(new CdmMetaDataAwareDataSourceContainer[]{container}, null);
64
								}
65
								
66
							}
67
						});
68
						status = Status.OK_STATUS;
69
					}
70
				}catch(Exception e){
71
					status = new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, e.getMessage(), e);
72
					StoreUtil.errorDialog("Could not run updater", getClass(), status);
73
				}
74
				
75
				
76
				return status;
77
			}
78
			
79
		};
80
		
81
		job.setPriority(Job.BUILD);
82
		job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
83
		job.schedule();
84
		
85
		return false;
86
	}
87
}
(8-8/8)