blob: 4ca1b9037fb02b86e4ee938dd087a2fbbc48f179 (
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
|
package org.eclipse.papyrus.infra.gmfdiag.properties.databinding.custom;
import org.eclipse.emf.common.command.AbstractCommand;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.gmf.runtime.notation.NamedStyle;
import org.eclipse.gmf.runtime.notation.NotationFactory;
import org.eclipse.gmf.runtime.notation.View;
public abstract class AbstractCustomStyleListValueCommand extends AbstractCommand {
protected View view;
protected EClass styleClass;
protected String styleName;
protected boolean needsCreate;
protected EStructuralFeature styleFeature;
protected EditingDomain domain;
protected Command command;
protected NamedStyle style;
public AbstractCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass styleClass, EStructuralFeature styleFeature) {
this.view = view;
this.styleName = styleName;
this.styleClass = styleClass;
this.styleFeature = styleFeature;
this.domain = domain;
}
public void execute() {
//FIXME: Related to CompoundCommand vs StrictCompoundCommand.
//Sometimes, canExecute() is not called, and the command is not prepared
if(!isPrepared) {
prepare();
isPrepared = true;
}
if(needsCreate) {
view.getStyles().add(style);
}
command.execute();
}
public void redo() {
execute();
}
@Override
public boolean prepare() {
style = view.getNamedStyle(styleClass, styleName);
if(needsCreate = (style == null)) {
style = (NamedStyle)NotationFactory.eINSTANCE.create(styleClass);
style.setName(styleName);
}
command = createCommand();
// return true;
return command.canExecute();
}
protected abstract Command createCommand();
@Override
public void undo() {
EList currentList = (EList)(style.eGet(styleFeature));
command.undo();
if(needsCreate) {
view.getStyles().remove(style);
}
}
}
|