blob: 2d26942bbfae5ea74037a79f6058a33236f95420 (
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*****************************************************************************
* Copyright (c) 2014 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:
*
*****************************************************************************/
package org.eclipse.papyrus.uml.alf.properties.xtext.sheet;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.jface.viewers.IFilter;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.uml.alf.transaction.observation.listener.filter.FUMLScopeUtil;
import org.eclipse.uml2.uml.Element;
import org.eclipse.papyrus.uml.alf.preferences.AlfIntegrationPreferencesUtil;
/**
* This class constrains the availability of the embedded ALF editor.
*
* The ALF editor must only be available when:
* 1. The selection is a Class (not composite)
* 2. The selection is an Association
* 3. The selection is a Signal
* 4. The selection is a Datatype
* 5. The selection is an Enumeration
* 6. The selection is a Package
* 7. The selection is an Activity
*/
public class AlfEditorPropertySectionFilter implements IFilter {
/**
* @see org.eclipse.jface.viewers.IFilter#select(java.lang.Object)
*
* @param toTest
*
* @return accepted
*/
public boolean select(Object toTest) {
Element element = this.resolveSemanticElement(toTest);
boolean accepted = false;
if(element!=null &&
AlfIntegrationPreferencesUtil.isAlfSupportEnabled()){
accepted = this.isValidInput(element);
}
return accepted;
}
/**
* Check the given input and returns true if it is a valid input for the embedded ALF editor
* false otherwise
*
* @param element
* an input element for ALF embedded editor
*
* @return true if element is accepted as an input false otherwise
*/
private boolean isValidInput(Element element){
/*1. First constraint: the element must be modifiable (i.e. not read only)*/
if(!this.isModifiable(element)){
return false;
}
/*2. It should be in the scope supported by the ALF editor*/
if(FUMLScopeUtil.isClass(element)){
return true;
}else if(FUMLScopeUtil.isPackage(element)){
return true;
}else if(FUMLScopeUtil.isSignal(element)){
return true;
}else if(FUMLScopeUtil.isEnumeration(element)){
return true;
}else if(FUMLScopeUtil.isDataType(element)){
return true;
}else if(FUMLScopeUtil.isAssociation(element)){
return true;
}else if(FUMLScopeUtil.isActivity(element)){
return true;
}else if(FUMLScopeUtil.isOperationWithImplementation(element)){
return true;
}
return false;
}
private boolean isModifiable(Element element){
Resource resource = element.eResource();
if(resource != null ){
return !EMFHelper.isReadOnly(element);
}
return false;
}
/**
* From a selection this methods tries to extract the underlying model element
*
* @param selectedElement
* an object selected in the view (e.g., a class in a diagram)
*
* @return semanticElement
* the model element that is under the graphical element (may be null)
*/
private Element resolveSemanticElement(Object selectedElement){
Element semanticElement = null;
if (selectedElement instanceof IAdaptable) {
semanticElement = (Element) ((IAdaptable) selectedElement).getAdapter(EObject.class);
}
else if (selectedElement instanceof GraphicalEditPart) {
GraphicalEditPart part = (GraphicalEditPart) selectedElement;
semanticElement = (Element)part.resolveSemanticElement();
}
return semanticElement;
}
}
|