a8a01defa134a51bb393d5a2c41ca98c221f17ff
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / datasource / handler / DataSourceMenuPropertyTester.java
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 private static final String TEST = "test";
29
30 /*
31 * (non-Javadoc)
32 *
33 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object,
34 * java.lang.String, java.lang.Object[], java.lang.Object)
35 */
36 /** {@inheritDoc} */
37 @Override
38 public boolean test(Object receiver, String property, Object[] args,
39 Object expectedValue) {
40
41 Object[] selectedElements = ((IStructuredSelection) receiver).toArray();
42
43 if (selectedElements.length == 0 && property.equals(TEST)) {
44 // nothing selected so all tests should fail
45 return true;
46 }
47 if (selectedElements.length == 0 && COMPATIBLE.equals(property)) {
48 // nothing selected so all tests should fail
49 return true;
50 }
51
52 if (COMPATIBLE.equals(property)) {
53 return isCompatible(selectedElements);
54 }
55
56
57
58
59 return false;
60 }
61
62
63
64 /**
65 * @param selectedElements
66 * @return
67 */
68 private boolean isCompatible(Object[] selectedElements) {
69
70 if (selectedElements.length == 0 ) {
71 // nothing selected so all tests should fail
72 return false;
73 }
74 for (Object object : selectedElements) {
75
76 if (object instanceof CdmMetaDataAwareDataSourceContainer) {
77 CdmMetaDataAwareDataSourceContainer container = (CdmMetaDataAwareDataSourceContainer) object;
78 return container.isDataSourceCompatible();
79 }
80 }
81 return false;
82
83 }
84 }