1 | package de.uka.ipd.sdq.pcmbench.tabs.parameters; |
2 | |
3 | import java.util.Observable; |
4 | |
5 | import org.eclipse.core.runtime.Assert; |
6 | import org.eclipse.emf.ecore.EObject; |
7 | import org.eclipse.emf.transaction.RecordingCommand; |
8 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
9 | import org.eclipse.emf.transaction.util.TransactionUtil; |
10 | import org.eclipse.jface.viewers.ISelectionChangedListener; |
11 | import org.eclipse.jface.viewers.IStructuredSelection; |
12 | import org.eclipse.jface.viewers.SelectionChangedEvent; |
13 | import org.eclipse.swt.events.SelectionEvent; |
14 | import org.eclipse.swt.events.SelectionListener; |
15 | |
16 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext; |
17 | import de.uka.ipd.sdq.pcm.parameter.VariableUsage; |
18 | |
19 | public class DeleteComponentParameterAction extends Observable implements |
20 | SelectionListener, ISelectionChangedListener { |
21 | |
22 | private EObject selectedElement = null; |
23 | |
24 | /* (non-Javadoc) |
25 | * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) |
26 | */ |
27 | public void selectionChanged(SelectionChangedEvent event) { |
28 | IStructuredSelection sel = (IStructuredSelection) event.getSelection(); |
29 | Object selection = (Object) sel.getFirstElement(); |
30 | this.selectedElement = (EObject) selection; |
31 | } |
32 | |
33 | /* (non-Javadoc) |
34 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
35 | */ |
36 | public void widgetSelected(SelectionEvent e) { |
37 | final VariableUsageWrapper wrapper = (VariableUsageWrapper) selectedElement; |
38 | final VariableUsage variableUsage = wrapper.getVariableUsage(); |
39 | final AssemblyContext context = (AssemblyContext) variableUsage |
40 | .eContainer(); |
41 | |
42 | Assert.isNotNull(context); |
43 | |
44 | TransactionalEditingDomain editingDomain = TransactionUtil |
45 | .getEditingDomain(context); |
46 | |
47 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
48 | @Override |
49 | protected void doExecute() { |
50 | context.getConfigParameterUsages__AssemblyContext().remove( |
51 | variableUsage); |
52 | } |
53 | }; |
54 | |
55 | recCommand.setDescription("Delete ..."); |
56 | editingDomain.getCommandStack().execute(recCommand); |
57 | |
58 | // set TabelItem not edited |
59 | wrapper.setEdited(false); |
60 | // update observer |
61 | notifyObservers(wrapper); |
62 | |
63 | } |
64 | |
65 | /* (non-Javadoc) |
66 | * @see java.util.Observable#notifyObservers(java.lang.Object) |
67 | */ |
68 | @Override |
69 | public void notifyObservers(Object arg) { |
70 | setChanged(); |
71 | super.notifyObservers(arg); |
72 | } |
73 | |
74 | /* (non-Javadoc) |
75 | * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) |
76 | */ |
77 | public void widgetDefaultSelected(SelectionEvent e) { |
78 | // The implementation is not necessary. |
79 | } |
80 | } |