2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.view
.datasource
.handler
;
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
;
18 import eu
.etaxonomy
.taxeditor
.Messages
;
19 import eu
.etaxonomy
.taxeditor
.datasource
.CdmDataSourceRepository
;
20 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
21 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
22 import eu
.etaxonomy
.taxeditor
.view
.datasource
.CdmMetaDataAwareDataSourceContainer
;
29 public class ChangeConnectionHandler
extends AbstractHandler
{
33 public Object
execute(ExecutionEvent event
) {
34 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
36 if(selection
!= null && selection
instanceof IStructuredSelection
){
37 CdmMetaDataAwareDataSourceContainer container
= (CdmMetaDataAwareDataSourceContainer
) ((IStructuredSelection
) selection
).getFirstElement();
39 if(CdmStore
.isConnecting()){
40 MessagingUtils
.warningDialog(Messages
.ChangeConnectionHandler_ALREADY_CONNECTING
, this, Messages
.ChangeConnectionHandler_CURRENTLY_CONNECTING_ALREADY
);
45 container
.getCdmSource().checkConnection();
46 boolean confirmed
= MessagingUtils
.confirmDialog(Messages
.ChangeConnectionHandler_CREATE_DATAMODEL
, String
.format(Messages
.ChangeConnectionHandler_REALLY_CREATE_DATAMODEL
, container
.getCdmSource().getName()));
49 CdmDataSourceRepository
.changeDataSource(container
.getCdmSource());
51 } catch (Exception e
) {
52 MessagingUtils
.warningDialog(Messages
.ChangeConnectionHandler_DATASOURCE_NOT_AVAILABLE
, this, Messages
.ChangeConnectionHandler_NOT_AVAILABLE_REASONS
);
53 MessagingUtils
.warn(getClass(), e
);