1 | package de.uka.ipd.sdq.pcm.dialogs.datatype; |
2 | |
3 | import java.util.Collection; |
4 | |
5 | import org.eclipse.core.runtime.Assert; |
6 | import org.eclipse.emf.common.util.EList; |
7 | import org.eclipse.emf.ecore.EObject; |
8 | import org.eclipse.emf.ecore.EReference; |
9 | import org.eclipse.emf.transaction.RecordingCommand; |
10 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
11 | import org.eclipse.emf.transaction.util.TransactionUtil; |
12 | import org.eclipse.jface.viewers.ISelectionChangedListener; |
13 | import org.eclipse.jface.viewers.IStructuredSelection; |
14 | import org.eclipse.jface.viewers.SelectionChangedEvent; |
15 | import org.eclipse.jface.viewers.TreeViewer; |
16 | import org.eclipse.swt.events.SelectionAdapter; |
17 | import org.eclipse.swt.events.SelectionEvent; |
18 | import org.eclipse.swt.widgets.Composite; |
19 | import org.eclipse.swt.widgets.Control; |
20 | import org.eclipse.swt.widgets.Shell; |
21 | |
22 | import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog; |
23 | import de.uka.ipd.sdq.pcm.repository.CollectionDataType; |
24 | import de.uka.ipd.sdq.pcm.repository.CompositeDataType; |
25 | import de.uka.ipd.sdq.pcm.repository.DataType; |
26 | import de.uka.ipd.sdq.pcm.repository.Repository; |
27 | |
28 | /** |
29 | * The class sets the actions (add, edit, delete), which |
30 | * PalladioSelectEObjectDialog were defined in. |
31 | * |
32 | * @author Roman Andrej |
33 | */ |
34 | public class CallDataTypeDialog extends PalladioSelectEObjectDialog { |
35 | |
36 | private DataType selectedDataType = null; |
37 | |
38 | /** |
39 | * The transactional editing domain which is used to get the commands and |
40 | * alter the model |
41 | */ |
42 | private TransactionalEditingDomain editingDomain = null; |
43 | |
44 | public CallDataTypeDialog(Shell parent, Collection<Object> filterList, |
45 | Collection<EReference> additionalChildReferences,Object input) { |
46 | super(parent, filterList, additionalChildReferences, input); |
47 | this.editingDomain = TransactionUtil.getEditingDomain(input); |
48 | } |
49 | |
50 | /* (non-Javadoc) |
51 | * @see de.uka.ipd.sdq.dialogs.selection.SelectEObjectDialog#createDialogArea(Composite parent) |
52 | */ |
53 | @Override |
54 | protected Control createDialogArea(Composite parent) { |
55 | Composite area = (Composite) super.createDialogArea(parent); |
56 | |
57 | /** |
58 | * Activire the ToolBar with items |
59 | * |
60 | * @See de.uka.ipd.sdq.dialogs.selection.SelectEObjectDialog#enableToolBar(Boolean |
61 | * addItemEnabled, boolean deleteItemEnabled, boolean |
62 | * editItemEnabled) |
63 | */ |
64 | enableToolBar(true, false, false); |
65 | |
66 | TreeViewer treeViewer = getTreeViewer(); |
67 | treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
68 | |
69 | public void selectionChanged(SelectionChangedEvent event) { |
70 | IStructuredSelection sel = (IStructuredSelection) event |
71 | .getSelection(); |
72 | EObject selection = (EObject) sel.getFirstElement(); |
73 | |
74 | enableToolBar(true, false, false); |
75 | if ((selection instanceof CollectionDataType) |
76 | || (selection instanceof CompositeDataType)) { |
77 | selectedDataType = (DataType) selection; |
78 | enableToolBar(true, true, true); |
79 | } |
80 | } |
81 | }); |
82 | |
83 | setAddSelectionListener(new SelectionAdapter() { |
84 | |
85 | /* (non-Javadoc) |
86 | * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
87 | */ |
88 | @Override |
89 | public void widgetSelected(SelectionEvent e) { |
90 | Shell shell = e.widget.getDisplay().getActiveShell(); |
91 | PalladioDataTypeDialog dialog = new PalladioDataTypeDialog( |
92 | shell,editingDomain); |
93 | dialog.open(); |
94 | } |
95 | |
96 | }); |
97 | |
98 | setDeleteSelectionListener(new SelectionAdapter() { |
99 | |
100 | /* (non-Javadoc) |
101 | * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
102 | */ |
103 | @Override |
104 | public void widgetSelected(SelectionEvent e) { |
105 | |
106 | RecordingCommand recCommand = new RecordingCommand( |
107 | editingDomain) { |
108 | @Override |
109 | protected void doExecute() { |
110 | Assert.isNotNull(selectedDataType); |
111 | |
112 | Repository repository = selectedDataType |
113 | .getRepository__DataType(); |
114 | |
115 | EList<DataType> datatypesRepository = repository |
116 | .getDataTypes__Repository(); |
117 | datatypesRepository.remove(selectedDataType); |
118 | |
119 | } |
120 | }; |
121 | |
122 | recCommand.setDescription("Delete the DataType"); |
123 | editingDomain.getCommandStack().execute(recCommand); |
124 | enableToolBar(true, false, false); |
125 | } |
126 | }); |
127 | |
128 | setEditeSelectionListener(new SelectionAdapter() { |
129 | |
130 | /* (non-Javadoc) |
131 | * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
132 | */ |
133 | @Override |
134 | public void widgetSelected(SelectionEvent e) { |
135 | |
136 | Assert.isNotNull(selectedDataType); |
137 | Shell shell = e.widget.getDisplay().getActiveShell(); |
138 | PalladioDataTypeDialog dialog = new PalladioDataTypeDialog( |
139 | shell, selectedDataType); |
140 | dialog.open(); |
141 | |
142 | } |
143 | |
144 | }); |
145 | return area; |
146 | } |
147 | } |