Project

General

Profile

Download (2.4 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.AbstractHandler;
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.jface.viewers.ISelection;
16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.ui.handlers.HandlerUtil;
18

    
19
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21
import eu.etaxonomy.taxeditor.store.StoreUtil;
22
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
23

    
24
/**
25
 * <p>ChangeConnectionHandler class.</p>
26
 *
27
 * @author n.hoffmann
28
 * @created 15.04.2009
29
 * @version 1.0
30
 */
31
public class ChangeConnectionHandler extends AbstractHandler {
32

    
33
	/* (non-Javadoc)
34
	 * @see eu.etaxonomy.taxeditor.store.datasource.handler.AbstractDataSourceHandler#specificExecute(org.eclipse.core.commands.ExecutionEvent)
35
	 */
36
	/** {@inheritDoc} */
37
	public Object execute(ExecutionEvent event) {
38
		ISelection selection = HandlerUtil.getCurrentSelection(event);
39
		
40
		if(selection != null && selection instanceof IStructuredSelection){
41
			CdmMetaDataAwareDataSourceContainer container = (CdmMetaDataAwareDataSourceContainer) ((IStructuredSelection) selection).getFirstElement();
42
			
43
			if(CdmStore.isConnecting()){
44
				StoreUtil.warningDialog("Already connecting", this, "You are currently connecting to a different datasource already.");
45
				return null;
46
			}
47
			
48
			try {
49
				container.getDataSource().testConnection();
50
				boolean confirmed = StoreUtil.confirmDialog("Confirm Datasource Connection", "Do you really want to connect to this datasource?\n\n"
51
						+ container.getDataSource().getName());
52
				
53
				if(confirmed){
54
					CdmDataSourceRepository.changeDataSource(container.getDataSource());
55
				}
56
			} catch (Exception e) {
57
				StoreUtil.warningDialog("Chosen datasource is not available", this, "This could mean that either the database server is " +
58
						"not running or the machine is not reachable.\n\n" +
59
						"Please also make sure that you are connected to the network when trying to connect to a remote datasource.");
60
				StoreUtil.warn(getClass(), e);
61
				return null;
62
			} 
63
		}
64
		
65
		return null;
66
	}
67
}
(2-2/8)