blob: 291e3e1f91c889976ebc77ca7e1af56772a97e6c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*****************************************************************************
* Copyright (c) 2011 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.table.modelexplorer.providers;
import java.util.Iterator;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
/**
* This class provides test called by the plugin.xml in order to know if handlers should be active or not.
*
* Sometimes these test can be done directly in the plugin.xml in the activeWhen (with instanceof, adapt, ...),
* but in this case, Eclipse doesn't refresh correctly the status of the command in the menu Edit or in other menu.
*
*
* FIXME : i think this class is not yet used
*/
public class TablePropertyTester extends PropertyTester {
/** property to test if the selected elements is a table */
public static final String IS_TABLE = "isTable"; //$NON-NLS-1$
/**
*
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
*
* @param receiver
* @param property
* @param args
* @param expectedValue
* @return
*/
public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
if (IS_TABLE.equals(property) && receiver instanceof IStructuredSelection) {
boolean answer = isTable((IStructuredSelection) receiver);
return new Boolean(answer).equals(expectedValue);
}
return false;
}
/**
* Tests the selection in order to know if it contains only {@link TableInstance}
*
* @param selection
* @return
* <code>true</code> if the selection is composed by {@link TableInstance}
*/
private boolean isTable(final IStructuredSelection selection) {
if (!selection.isEmpty()) {
Iterator<?> iter = selection.iterator();
while (iter.hasNext()) {
/**
* Set to use the IAdaptable mechanism
* Used for example for facet elements
*/
final Object next = iter.next();
EObject table = EMFHelper.getEObject(next);
if (!(table instanceof PapyrusTableInstance)) {
return false;
}
}
return true;
}
return false;
}
}
|