blob: d07c6226b605f9b76677e8dad3666ceea833665d (
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
|
/*****************************************************************************
* Copyright (c) 2009-2010 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.diagram.component.custom.actions;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.diagram.common.actions.AbstractShowHideAction;
import org.eclipse.papyrus.diagram.common.actions.ShowHideContentsAction;
import org.eclipse.papyrus.diagram.common.editpolicies.ShowHideRelatedContentsEditPolicy;
import org.eclipse.papyrus.diagram.common.providers.EditorLabelProvider;
import org.eclipse.papyrus.diagram.component.custom.messages.Messages;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Type;
public class ShowHideRelatedContentsAction extends ShowHideContentsAction {
/**
*
* Constructor.
*
*/
public ShowHideRelatedContentsAction() {
super(Messages.ShowHideRelatedContentsAction_Title, Messages.ShowHideRelatedContentsAction_Message, ShowHideRelatedContentsEditPolicy.SHOW_HIDE_RELATED_CONTENTS_POLICY);
}
/**
*
* @see org.eclipse.papyrus.diagram.common.actions.AbstractShowHideAction#initAction()
*
*/
@Override
protected void initAction() {
super.initAction();
setEditorLabelProvider(new EditorLabelProvider());
this.representations = new ArrayList<AbstractShowHideAction.EditPartRepresentation>();
for(EditPart current : this.selectedElements) {
//the selected elements which aren't Classifier are ignored
EObject element = ((View)current.getModel()).getElement();
if(element instanceof Property) {
Type type = ((Property)element).getType();
if(type instanceof Classifier) {
this.representations.add(new CustomEditPartRepresentation(current, (Classifier)type));
}
}
}
this.setEditorLabelProvider(new CustomEditorLabelProvider());
this.setContentProvider(new CustomContentProvider());
}
protected class CustomContentProvider extends ShowHideContentsAction.ContentProvider {
/**
*
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
*
* @param element
* @return
*/
@Override
public Object getParent(Object element) {
if(!(element instanceof EditPartRepresentation)) {
EditPartRepresentation rep = findEditPartRepresentation(element);
if(rep != null) {
//element can be owned by the class (rep), or by a superclass (ClassifierRepresentation)
List<ClassifierRepresentation> classes = ((CustomEditPartRepresentation)rep).getSuperClasses();
for(ClassifierRepresentation classifierRepresentation : classes) {
if(classifierRepresentation.getRepresentedClassifier().getOwnedMembers().contains(element)) {
return classifierRepresentation;
}
}
}
return rep;
}
return null;
}
}
}
|