3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.view
.datasource
.handler
;
13 import org
.eclipse
.core
.expressions
.PropertyTester
;
14 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
16 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
.MetaDataPropertyName
;
17 import eu
.etaxonomy
.taxeditor
.view
.datasource
.CdmMetaDataAwareDataSourceContainer
;
21 * @created Sep 23, 2010
24 public class DataSourceMenuPropertyTester
extends PropertyTester
{
26 private static final String COMPATIBLE
= "isCompatible";
27 private static final String TEST
= "test";
28 private static final String HAS_DATA_MODEL
= "hasDataModel";
32 public boolean test(Object receiver
, String property
, Object
[] args
,
33 Object expectedValue
) {
35 Object
[] selectedElements
= ((IStructuredSelection
) receiver
).toArray();
36 if (selectedElements
.length
== 0 && property
.equals(TEST
)) {
37 // nothing selected so all tests should fail
40 if (selectedElements
.length
== 0 && COMPATIBLE
.equals(property
)) {
41 // nothing selected so all tests should fail
45 if (COMPATIBLE
.equals(property
)) {
46 return isCompatible(selectedElements
);
48 if (HAS_DATA_MODEL
.equals(property
)) {
49 return hasDataModel(selectedElements
);
54 private boolean hasDataModel(Object
[] selectedElements
) {
56 if (selectedElements
.length
== 0 ) {
57 // nothing selected so all tests should fail
60 for (Object object
: selectedElements
) {
62 if (object
instanceof CdmMetaDataAwareDataSourceContainer
) {
63 CdmMetaDataAwareDataSourceContainer container
= (CdmMetaDataAwareDataSourceContainer
) object
;
64 String schemaVersion
= container
.getMetaData(MetaDataPropertyName
.DB_SCHEMA_VERSION
);
65 return !schemaVersion
.equals(CdmMetaDataAwareDataSourceContainer
.DEFAULT_ENTRY
);
73 private boolean isCompatible(Object
[] selectedElements
) {
75 if (selectedElements
.length
== 0 ) {
76 // nothing selected so all tests should fail
79 for (Object object
: selectedElements
) {
81 if (object
instanceof CdmMetaDataAwareDataSourceContainer
) {
82 CdmMetaDataAwareDataSourceContainer container
= (CdmMetaDataAwareDataSourceContainer
) object
;
83 return container
.isDataSourceCompatible();