Project

General

Profile

Download (5.14 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 *
3
 */
4
package eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler;
5

    
6
import org.eclipse.core.expressions.PropertyTester;
7
import org.eclipse.jface.viewers.IStructuredSelection;
8

    
9
import eu.etaxonomy.cdm.model.description.DescriptionBase;
10
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
11
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
12
import eu.etaxonomy.cdm.model.media.Media;
13
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
14
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
15
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
16
import eu.etaxonomy.taxeditor.model.AbstractUtility;
17
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
18

    
19
/**
20
 * Property tester used by the description tree menu.
21
 *
22
 * @author p.ciardelli
23
 * @author n.hoffmann
24
 * @version $Id: $
25
 */
26
public class DescriptionsMenuPropertyTesterE4 extends PropertyTester {
27

    
28
	private static final String MEDIA = "isMedia"; //$NON-NLS-1$
29
	private static final String FEATURE_NODE_CONTAINER = "isFeatureNodeContainer"; //$NON-NLS-1$
30
	private static final String DESCRIPTION = "isDescription"; //$NON-NLS-1$
31
	private static final String INDIVIDUALS_ASSOCIATION = "isIndividualsAssociation"; //$NON-NLS-1$
32
	private static final String DESCRIPTION_ELEMENT = "isDescriptionElement"; //$NON-NLS-1$
33
	private static final String DELETABLE = "isDeletable"; //$NON-NLS-1$
34
	private static final String IMAGE_GALLERY = "isImageGallery"; //$NON-NLS-1$
35
	private static final String TAXON_EDITOR = "isTaxonEditor"; //$NON-NLS-1$
36
	private static final String BULK_EDITOR = "isBulkEditor"; //$NON-NLS-1$
37
	private static final String DERIVATE_EDITOR = "isDerivateEditor"; //$NON-NLS-1$
38

    
39
	/* (non-Javadoc)
40
	 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
41
	 */
42
	/** {@inheritDoc} */
43
	@Override
44
    public boolean test(Object receiver, String property, Object[] args,
45
			Object expectedValue) {
46

    
47
	    if(TAXON_EDITOR.equals(property)){
48
	        return isTaxonEditor();
49
	    }
50
	    else if(BULK_EDITOR.equals(property)){
51
	        return isBulkEditor();
52
	    }
53
	    else if(DERIVATE_EDITOR.equals(property)){
54
	        return isDerivateEditor();
55
	    }
56

    
57
	    Object[] selectedElements = ((IStructuredSelection) receiver).toArray();
58

    
59
	    if(selectedElements.length == 0){
60
			// nothing selected so all tests should fail
61
			return false;
62
		}
63

    
64
		if(MEDIA.equals(property)){
65
			return isMedia(selectedElements);
66
		}
67
		else if(FEATURE_NODE_CONTAINER.equals(property)){
68
			return isFeatureNodeContainer(selectedElements);
69
		}
70
		else if(DESCRIPTION.equals(property)){
71
			return isDescription(selectedElements);
72
		}
73
		else if(INDIVIDUALS_ASSOCIATION.equals(property)){
74
		    return isIndividualsAssociation(selectedElements);
75
		}
76
		else if(DESCRIPTION_ELEMENT.equals(property)){
77
			return isDescriptionElement(selectedElements);
78
		}
79
		else if(DELETABLE.equals(property)){
80
			return isDeletable(selectedElements);
81
		}
82
		else if(IMAGE_GALLERY.equals(property)){
83
			return isImageGallery(selectedElements);
84
		}
85
		else{
86
			return false;
87
		}
88
	}
89

    
90
	private boolean isImageGallery(Object[] selectedElements) {
91
		for (Object object : selectedElements){
92
			if(!(object instanceof DescriptionBase) || !((DescriptionBase<?>) object).isImageGallery()){
93
				return false;
94
			}
95
		}
96
		return true;
97
	}
98

    
99
	private boolean isFeatureNodeContainer(Object[] selectedElements) {
100
		for (Object object : selectedElements){
101
			if(!(object instanceof FeatureNodeContainer)){
102
				return false;
103
			}
104
		}
105
		return true;
106
	}
107

    
108
	private boolean isDeletable(Object[] selectedElements) {
109
		boolean result = false;
110

    
111
		for (Object object : selectedElements) {
112

    
113
			if((object instanceof DescriptionBase)
114
				|| (object instanceof DescriptionElementBase)
115
				|| (object instanceof Media)
116
				|| (object instanceof FeatureNodeContainer)){
117
				result = true;
118
			}else{
119
				return false;
120
			}
121

    
122
		}
123
		return result;
124
	}
125

    
126
	private boolean isDescriptionElement(Object[] selectedElements) {
127
		for (Object object : selectedElements){
128
			if(!(object instanceof DescriptionElementBase)){
129
				return false;
130
			}
131
		}
132
		return true;
133
	}
134

    
135
	private boolean isDescription(Object[] selectedElements) {
136
		for (Object object : selectedElements){
137
			if(!(object instanceof DescriptionBase)){
138
				return false;
139
			}
140
		}
141
		return true;
142
	}
143

    
144
	private boolean isIndividualsAssociation(Object[] selectedElements) {
145
	    for (Object object : selectedElements){
146
	        if(!(object instanceof IndividualsAssociation)){
147
	            return false;
148
	        }
149
	    }
150
	    return true;
151
	}
152

    
153
	private boolean isMedia(Object[] selectedElements) {
154
		for (Object object : selectedElements){
155
			if(!(object instanceof Media)){
156
				return false;
157
			}
158
		}
159
		return true;
160
	}
161

    
162
	private boolean isTaxonEditor() {
163
	    if(AbstractUtility.getActiveEditor() instanceof TaxonNameEditorE4){
164
	        return true;
165
	    }
166
	    return false;
167
	}
168

    
169
	private boolean isBulkEditor() {
170
	    if(AbstractUtility.getActiveEditor() instanceof BulkEditorE4){
171
	        return true;
172
	    }
173
	    return false;
174
	}
175

    
176
	private boolean isDerivateEditor() {
177
	    if(AbstractUtility.getActiveEditor() instanceof DerivateView){
178
	        return true;
179
	    }
180
	    return false;
181
	}
182
}
(4-4/8)