1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.view.datasource.handler;
|
11
|
|
12
|
import org.eclipse.core.commands.AbstractHandler;
|
13
|
import org.eclipse.core.commands.ExecutionEvent;
|
14
|
import org.eclipse.jface.viewers.ISelection;
|
15
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
16
|
import org.eclipse.ui.handlers.HandlerUtil;
|
17
|
|
18
|
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
|
19
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
20
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
21
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
22
|
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
|
23
|
|
24
|
/**
|
25
|
* @author n.hoffmann
|
26
|
* @created 15.04.2009
|
27
|
* @version 1.0
|
28
|
*/
|
29
|
public class ChangeConnectionHandler extends AbstractHandler {
|
30
|
|
31
|
/** {@inheritDoc} */
|
32
|
@Override
|
33
|
public Object execute(ExecutionEvent event) {
|
34
|
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
35
|
|
36
|
if(selection != null && selection instanceof IStructuredSelection){
|
37
|
CdmMetaDataAwareDataSourceContainer container = (CdmMetaDataAwareDataSourceContainer) ((IStructuredSelection) selection).getFirstElement();
|
38
|
|
39
|
if(CdmStore.isConnecting()){
|
40
|
MessagingUtils.warningDialog(Messages.ChangeConnectionHandler_ALREADY_CONNECTING, this, Messages.ChangeConnectionHandler_CURRENTLY_CONNECTING_ALREADY);
|
41
|
return null;
|
42
|
}
|
43
|
|
44
|
try {
|
45
|
container.getCdmSource().checkConnection();
|
46
|
boolean confirmed = MessagingUtils.confirmDialog(Messages.ChangeConnectionHandler_CREATE_DATAMODEL, String.format(Messages.ChangeConnectionHandler_REALLY_CREATE_DATAMODEL, container.getCdmSource().getName()));
|
47
|
|
48
|
if(confirmed){
|
49
|
CdmDataSourceRepository.changeDataSource(container.getCdmSource());
|
50
|
}
|
51
|
} catch (Exception e) {
|
52
|
MessagingUtils.warningDialog(Messages.ChangeConnectionHandler_DATASOURCE_NOT_AVAILABLE, this, Messages.ChangeConnectionHandler_NOT_AVAILABLE_REASONS);
|
53
|
MessagingUtils.warn(getClass(), e);
|
54
|
return null;
|
55
|
}
|
56
|
}
|
57
|
|
58
|
return null;
|
59
|
}
|
60
|
}
|