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
120
121
122
123
124
125
126
127
|
/*****************************************************************************
* 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:
* Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.uml.properties.databinding;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList;
import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.UMLPackage;
/**
* Observable list for property {@link org.eclipse.uml2.uml.Element#getOwnedElements <em>Owned Element</em>}.
*
* @author Gabriel Pascual
*/
public class OwnedCommentsObservableList extends PapyrusObservableList {
/**
* Constructor.
*
* @param domain
* the domain
* @param source
* the source
*/
public OwnedCommentsObservableList(EditingDomain domain, EObject source) {
super(getOwnedComments(source), domain, source, UMLPackage.eINSTANCE.getElement_OwnedComment());
}
/**
* Gets the owned comments.
*
* @param source
* the source
* @return the owned comments
*/
private static List<Comment> getOwnedComments(EObject source) {
List<Comment> result = new LinkedList<Comment>();
if(source instanceof Element) {
EList<Comment> allOwnedComments = ((Element)source).getOwnedComments();
// Filter owned comments list
for(Comment comment : allOwnedComments) {
if(!comment.getAnnotatedElements().contains(source)) {
result.add(comment);
}
}
}
return result;
}
/**
* <p>
* Redefine method to add filtered list.
* </p>
*
* @see org.eclipse.papyrus.infra.ui.emf.databinding.EMFObservableList#refreshCacheList()
*
*/
@Override
protected void refreshCacheList() {
if(isDisposed()) {
//This observable can be disposed, but the commands might still be
//in the command stack. Undo() or Redo() will call this method, which
//should be ignored. The command should probably not call refresh directly ;
//we should have listeners on the concrete list... but it is not necessarily
//observable
return;
}
wrappedList.clear();
wrappedList.addAll(getOwnedComments(source));
fireListChange(null);
}
/**
* @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList#getAddCommand(java.lang.Object)
*
* @param value
* @return
*/
@Override
public Command getAddCommand(Object value) {
assert value instanceof Comment : "Added value is not a Comment";
SetRequest setRequest = new SetRequest((TransactionalEditingDomain)editingDomain, source, feature, value);
return getCommandFromRequests(getProvider(), Collections.singletonList(setRequest));
}
/**
* @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList#getRemoveCommand(java.lang.Object)
*
* @param value
* @return
*/
@Override
public Command getRemoveCommand(Object value) {
assert value instanceof Comment : "Deleted value is not a Comment";
DestroyElementRequest destroyRequest = new DestroyElementRequest((TransactionalEditingDomain)editingDomain, (EObject)value, false);
return getCommandFromRequests(getProvider(), Collections.singletonList(destroyRequest));
}
}
|