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.expressions.PropertyTester;
|
14
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
15
|
|
16
|
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
|
17
|
|
18
|
/**
|
19
|
* <p>DataSourceMenuPropertyTester class.</p>
|
20
|
*
|
21
|
* @author n.hoffmann
|
22
|
* @created Sep 23, 2010
|
23
|
* @version 1.0
|
24
|
*/
|
25
|
public class DataSourceMenuPropertyTester extends PropertyTester {
|
26
|
|
27
|
private static final String COMPATIBLE = "isCompatible";
|
28
|
|
29
|
/*
|
30
|
* (non-Javadoc)
|
31
|
*
|
32
|
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object,
|
33
|
* java.lang.String, java.lang.Object[], java.lang.Object)
|
34
|
*/
|
35
|
/** {@inheritDoc} */
|
36
|
@Override
|
37
|
public boolean test(Object receiver, String property, Object[] args,
|
38
|
Object expectedValue) {
|
39
|
|
40
|
Object[] selectedElements = ((IStructuredSelection) receiver).toArray();
|
41
|
|
42
|
if (selectedElements.length == 0) {
|
43
|
// nothing selected so all tests should fail
|
44
|
return false;
|
45
|
}
|
46
|
|
47
|
if (COMPATIBLE.equals(property)) {
|
48
|
return isCompatible(selectedElements);
|
49
|
}
|
50
|
|
51
|
|
52
|
return false;
|
53
|
}
|
54
|
|
55
|
|
56
|
|
57
|
/**
|
58
|
* @param selectedElements
|
59
|
* @return
|
60
|
*/
|
61
|
private boolean isCompatible(Object[] selectedElements) {
|
62
|
for (Object object : selectedElements) {
|
63
|
|
64
|
if (object instanceof CdmMetaDataAwareDataSourceContainer) {
|
65
|
CdmMetaDataAwareDataSourceContainer container = (CdmMetaDataAwareDataSourceContainer) object;
|
66
|
return container.isDataSourceCompatible();
|
67
|
}
|
68
|
}
|
69
|
return false;
|
70
|
}
|
71
|
}
|