1 | package de.uka.ipd.sdq.pcm.dialogs.parameters; |
2 | |
3 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
4 | import org.eclipse.jface.viewers.CellEditor; |
5 | import org.eclipse.jface.viewers.IBaseLabelProvider; |
6 | import org.eclipse.jface.viewers.ICellModifier; |
7 | import org.eclipse.jface.viewers.IContentProvider; |
8 | import org.eclipse.jface.viewers.ISelectionChangedListener; |
9 | import org.eclipse.jface.viewers.TableViewer; |
10 | import org.eclipse.jface.viewers.TextCellEditor; |
11 | import org.eclipse.swt.SWT; |
12 | import org.eclipse.swt.events.SelectionAdapter; |
13 | import org.eclipse.swt.events.SelectionEvent; |
14 | import org.eclipse.swt.events.SelectionListener; |
15 | import org.eclipse.swt.layout.FormAttachment; |
16 | import org.eclipse.swt.layout.FormData; |
17 | import org.eclipse.swt.layout.GridData; |
18 | import org.eclipse.swt.widgets.Composite; |
19 | import org.eclipse.swt.widgets.Label; |
20 | import org.eclipse.swt.widgets.Table; |
21 | import org.eclipse.swt.widgets.TableColumn; |
22 | import org.eclipse.swt.widgets.ToolBar; |
23 | import org.eclipse.swt.widgets.ToolItem; |
24 | |
25 | import de.uka.ipd.sdq.pcm.dialogs.DialogsImages; |
26 | |
27 | /** |
28 | * This class create a dialog area for Parameter-, DataTypeDialog. In order to |
29 | * make functionality possible from dialogue perfectly to, the following |
30 | * functions must be called: |
31 | * |
32 | * setViewerContentProvider(IContentProvider contentProvider), |
33 | * setViewerLabelProvider(IBaseLabelProvider labelProvider), |
34 | * setViewerCellModifier(ICellModifier cellModifier), |
35 | * setAddButtonActionListener(SelectionListener listener), |
36 | * setDeleteButtonActionListener(SelectionListener listener), |
37 | * setUpButtonActionListener(SelectionListener listener), |
38 | * setDownButtonActionListener(SelectionListener listener), |
39 | * setViewerInput(Object input){ |
40 | * |
41 | * @author Roman Andrej |
42 | */ |
43 | public class CreateEditorContents { |
44 | // local value |
45 | private TableViewer viewer; |
46 | private ToolItem addItem,deleteItem,downItem,upItem; |
47 | private Table table; |
48 | //private TransactionalEditingDomain editingDomain; |
49 | |
50 | public static final int ICON_COLUMN_INDEX = 0; |
51 | public static final int CONTEXT_COLUMN_INDEX = 1; |
52 | public static final int TYPE_COLUMN_INDEX = 2; |
53 | public static final int NAME_COLUMN_INDEX = 3; |
54 | |
55 | /** |
56 | * Columns of a table, which is used into ParameterEditDialog |
57 | */ |
58 | public final static String ATTRIBUTE_ICON_COLUMN = ""; |
59 | public final static String CONTEXT_COLUMN = "Context"; |
60 | public final static String TYPE_COLUMN = "Type"; |
61 | public final static String NAME_COLUMN = "Name"; |
62 | |
63 | // Set column names of Tabele |
64 | private static String[] columnNames = new String[] { ATTRIBUTE_ICON_COLUMN, |
65 | CONTEXT_COLUMN, NAME_COLUMN, TYPE_COLUMN }; |
66 | |
67 | /** |
68 | * Create the cell editors for Name, Type column |
69 | */ |
70 | private CellEditor[] editors = new CellEditor[columnNames.length]; |
71 | |
72 | private CreateEditorContents(Composite composite) { |
73 | init(composite); |
74 | } |
75 | |
76 | /** Factory Method */ |
77 | public static CreateEditorContents create(Composite composite){ |
78 | return new CreateEditorContents(composite); |
79 | } |
80 | |
81 | public void createNameColumnCellEditor(){ |
82 | editors[NAME_COLUMN_INDEX] = new TextCellEditor(table); |
83 | } |
84 | |
85 | public void createTypeColumnCellEditor(TransactionalEditingDomain editingDomain) { |
86 | editors[TYPE_COLUMN_INDEX] = new TypeDialogCellEditor(table, |
87 | editingDomain); |
88 | } |
89 | |
90 | public void setViewerContentProvider(IContentProvider contentProvider){ |
91 | viewer.setContentProvider(contentProvider); |
92 | } |
93 | |
94 | public void setViewerLabelProvider(IBaseLabelProvider labelProvider) { |
95 | viewer.setLabelProvider(labelProvider); |
96 | } |
97 | |
98 | public void setViewerCellModifier(ICellModifier cellModifier){ |
99 | viewer.setCellModifier(cellModifier); |
100 | } |
101 | |
102 | public void setAddButtonActionListener(SelectionListener listener){ |
103 | addItem.addSelectionListener(listener); |
104 | } |
105 | |
106 | public void setDeleteButtonActionListener(SelectionListener listener){ |
107 | deleteItem.addSelectionListener(listener); |
108 | } |
109 | |
110 | public void setUpButtonActionListener(SelectionListener listener){ |
111 | upItem.addSelectionListener(listener); |
112 | } |
113 | |
114 | public void setDownButtonActionListener(SelectionListener listener){ |
115 | downItem.addSelectionListener(listener); |
116 | } |
117 | |
118 | public void setViewerSelectionChangedListener(ISelectionChangedListener listener){ |
119 | viewer.addSelectionChangedListener(listener); |
120 | } |
121 | |
122 | public void setViewerInput(Object input){ |
123 | viewer.setInput(input); |
124 | } |
125 | |
126 | /** create dialog area */ |
127 | public void init(Composite composite) { |
128 | |
129 | FormData fdToolBar = new FormData(); |
130 | fdToolBar.top = new FormAttachment(0, 5); |
131 | fdToolBar.right = new FormAttachment(100, -7); |
132 | fdToolBar.left = new FormAttachment(100, -37); |
133 | fdToolBar.bottom = new FormAttachment(94, 0); |
134 | |
135 | final ToolBar toolBar = new ToolBar(composite, SWT.VERTICAL | SWT.NONE); |
136 | toolBar.setLayoutData(fdToolBar); |
137 | |
138 | addItem = new ToolItem(toolBar, SWT.PUSH); |
139 | addItem.setImage(DialogsImages.imageRegistry.get(DialogsImages.ADD)); |
140 | addItem.addSelectionListener(new SelectionAdapter(){ |
141 | |
142 | /* (non-Javadoc) |
143 | * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
144 | */ |
145 | @Override |
146 | public void widgetSelected(SelectionEvent e) { |
147 | viewer.refresh(); |
148 | } |
149 | }); |
150 | |
151 | deleteItem = new ToolItem(toolBar, SWT.PUSH); |
152 | deleteItem.setImage(DialogsImages.imageRegistry |
153 | .get(DialogsImages.DELETE)); |
154 | deleteItem.setEnabled(false); |
155 | |
156 | upItem = new ToolItem(toolBar, SWT.PUSH); |
157 | upItem.setImage(DialogsImages.imageRegistry |
158 | .get(DialogsImages.UP)); |
159 | upItem.setEnabled(false); |
160 | |
161 | downItem = new ToolItem(toolBar, SWT.PUSH); |
162 | downItem.setImage(DialogsImages.imageRegistry |
163 | .get(DialogsImages.DOWN)); |
164 | downItem.setEnabled(false); |
165 | |
166 | final FormData fdTableViewer = new FormData(); |
167 | fdTableViewer.right = new FormAttachment(toolBar, -5, SWT.LEFT); |
168 | fdTableViewer.top = new FormAttachment(0, 5); |
169 | fdTableViewer.left = new FormAttachment(0, 5); |
170 | fdTableViewer.bottom = new FormAttachment(94, 0); |
171 | |
172 | viewer = new TableViewer(composite, SWT.FULL_SELECTION |
173 | | SWT.BORDER); |
174 | table = viewer.getTable(); |
175 | table.setLayoutData(fdTableViewer); |
176 | table.setLinesVisible(true); |
177 | table.setHeaderVisible(true); |
178 | // set column editoren |
179 | viewer.setColumnProperties(columnNames); |
180 | // Assign the cell editors to the viewer |
181 | viewer.setCellEditors(editors); |
182 | |
183 | // Definere the table columns |
184 | final TableColumn zeroColumn = new TableColumn(table, SWT.NONE); |
185 | zeroColumn.setResizable(false); |
186 | zeroColumn.setWidth(30); |
187 | |
188 | final TableColumn contextColumn = new TableColumn(table, SWT.NONE); |
189 | contextColumn.setWidth(100); |
190 | contextColumn.setText(CONTEXT_COLUMN); |
191 | |
192 | final TableColumn typeColumn = new TableColumn(table, SWT.NONE); |
193 | typeColumn.setWidth(140); |
194 | typeColumn.setText(TYPE_COLUMN); |
195 | |
196 | final TableColumn nameColumn = new TableColumn(table, SWT.NONE); |
197 | nameColumn.setWidth(100); |
198 | nameColumn.setText(NAME_COLUMN); |
199 | |
200 | // Set EditorContent for Up/Down button validation |
201 | UpDownButtonsValidator.getSingelton().setContents(this); |
202 | } |
203 | |
204 | /** set upItem - ToolItem enabled or disabled */ |
205 | public void setUpItemsEnabled(boolean enabled) { |
206 | upItem.setEnabled(enabled); |
207 | } |
208 | |
209 | /** set downItem - ToolItem enabled or disabled */ |
210 | public void setDownItemsEnabled(boolean enabled) { |
211 | downItem.setEnabled(enabled); |
212 | } |
213 | |
214 | /** set deleteItem - ToolItem enabled or disabled */ |
215 | public void setDeleteItemsEnabled(boolean enabled) { |
216 | deleteItem.setEnabled(enabled); |
217 | } |
218 | |
219 | public void createSeparator(Composite composite) { |
220 | Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); |
221 | separator.setLayoutData(new GridData(492, SWT.DEFAULT)); |
222 | } |
223 | |
224 | public static String[] getColumnNames() { |
225 | return columnNames; |
226 | } |
227 | |
228 | public TableViewer getViewer() { |
229 | return viewer; |
230 | } |
231 | } |