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.e4.handler;
|
11
|
|
12
|
import javax.inject.Named;
|
13
|
|
14
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
15
|
import org.eclipse.e4.core.di.annotations.Execute;
|
16
|
import org.eclipse.e4.core.di.annotations.Optional;
|
17
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
18
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
19
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
20
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName;
|
23
|
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
|
24
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
25
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
|
28
|
import eu.etaxonomy.taxeditor.view.datasource.e4.CdmDataSourceViewPartE4;
|
29
|
|
30
|
/**
|
31
|
*
|
32
|
* @author pplitzner
|
33
|
* @date 22.08.2017
|
34
|
*
|
35
|
*/
|
36
|
public class ChangeConnectionHandlerE4 {
|
37
|
|
38
|
@Execute
|
39
|
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection) {
|
40
|
|
41
|
if(CdmStore.isConnecting()){
|
42
|
MessagingUtils.warningDialog(Messages.ChangeConnectionHandler_ALREADY_CONNECTING, this, Messages.ChangeConnectionHandler_CURRENTLY_CONNECTING_ALREADY);
|
43
|
return ;
|
44
|
}
|
45
|
|
46
|
try {
|
47
|
CdmMetaDataAwareDataSourceContainer container = (CdmMetaDataAwareDataSourceContainer) selection.getFirstElement();
|
48
|
container.getCdmSource().checkConnection();
|
49
|
boolean confirmed = MessagingUtils.confirmDialog(Messages.ChangeConnectionHandler_CREATE_DATAMODEL, String.format(Messages.ChangeConnectionHandler_REALLY_CREATE_DATAMODEL, container.getCdmSource().getName()));
|
50
|
|
51
|
if(confirmed){
|
52
|
CdmDataSourceRepository.changeDataSource(container.getCdmSource());
|
53
|
}
|
54
|
} catch (Exception e) {
|
55
|
MessagingUtils.warningDialog(Messages.ChangeConnectionHandler_DATASOURCE_NOT_AVAILABLE, this, Messages.ChangeConnectionHandler_NOT_AVAILABLE_REASONS);
|
56
|
MessagingUtils.warn(getClass(), e);
|
57
|
return ;
|
58
|
}
|
59
|
|
60
|
return ;
|
61
|
}
|
62
|
|
63
|
@CanExecute
|
64
|
public boolean canExecute(
|
65
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
66
|
@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
|
67
|
MHandledMenuItem menuItem) {
|
68
|
boolean canExecute = false;
|
69
|
canExecute = thisPart.getObject() instanceof CdmDataSourceViewPartE4
|
70
|
&& selection!=null
|
71
|
&& selection.size()==1
|
72
|
&& selection.getFirstElement() instanceof CdmMetaDataAwareDataSourceContainer
|
73
|
&& ((CdmMetaDataAwareDataSourceContainer) selection.getFirstElement()).getMetaData(CdmMetaDataPropertyName.DB_SCHEMA_VERSION).equals(CdmMetaDataAwareDataSourceContainer.DEFAULT_ENTRY);
|
74
|
menuItem.setVisible(canExecute);
|
75
|
return canExecute;
|
76
|
}
|
77
|
}
|