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.expressions.PropertyTester;
|
13
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName;
|
16
|
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
|
17
|
|
18
|
/**
|
19
|
* @author n.hoffmann
|
20
|
* @created Sep 23, 2010
|
21
|
* @version 1.0
|
22
|
*/
|
23
|
public class DataSourceMenuPropertyTester extends PropertyTester {
|
24
|
|
25
|
private static final String COMPATIBLE = "isCompatible";
|
26
|
private static final String TEST = "test";
|
27
|
private static final String HAS_DATA_MODEL = "hasDataModel";
|
28
|
|
29
|
/** {@inheritDoc} */
|
30
|
@Override
|
31
|
public boolean test(Object receiver, String property, Object[] args,
|
32
|
Object expectedValue) {
|
33
|
|
34
|
Object[] selectedElements = ((IStructuredSelection) receiver).toArray();
|
35
|
if (selectedElements.length == 0 && property.equals(TEST)) {
|
36
|
// nothing selected so all tests should fail
|
37
|
return true;
|
38
|
}
|
39
|
if (selectedElements.length == 0 && COMPATIBLE.equals(property)) {
|
40
|
// nothing selected so all tests should fail
|
41
|
return true;
|
42
|
}
|
43
|
|
44
|
if (COMPATIBLE.equals(property)) {
|
45
|
return isCompatible(selectedElements);
|
46
|
}
|
47
|
if (HAS_DATA_MODEL.equals(property)) {
|
48
|
return hasDataModel(selectedElements);
|
49
|
}
|
50
|
return false;
|
51
|
}
|
52
|
|
53
|
private boolean hasDataModel(Object[] selectedElements) {
|
54
|
|
55
|
if (selectedElements.length == 0 ) {
|
56
|
// nothing selected so all tests should fail
|
57
|
return false;
|
58
|
}
|
59
|
for (Object object : selectedElements) {
|
60
|
|
61
|
if (object instanceof CdmMetaDataAwareDataSourceContainer) {
|
62
|
CdmMetaDataAwareDataSourceContainer container = (CdmMetaDataAwareDataSourceContainer) object;
|
63
|
String schemaVersion = container.getMetaData(CdmMetaDataPropertyName.DB_SCHEMA_VERSION);
|
64
|
return !schemaVersion.equals(CdmMetaDataAwareDataSourceContainer.DEFAULT_ENTRY);
|
65
|
}
|
66
|
}
|
67
|
return false;
|
68
|
|
69
|
}
|
70
|
|
71
|
|
72
|
private boolean isCompatible(Object[] selectedElements) {
|
73
|
|
74
|
if (selectedElements.length == 0 ) {
|
75
|
// nothing selected so all tests should fail
|
76
|
return false;
|
77
|
}
|
78
|
for (Object object : selectedElements) {
|
79
|
|
80
|
if (object instanceof CdmMetaDataAwareDataSourceContainer) {
|
81
|
CdmMetaDataAwareDataSourceContainer container = (CdmMetaDataAwareDataSourceContainer) object;
|
82
|
return container.isDataSourceCompatible();
|
83
|
}
|
84
|
}
|
85
|
return false;
|
86
|
|
87
|
}
|
88
|
}
|