1 | package de.uka.ipd.sdq.pcmbench.tabs.operations; |
2 | |
3 | |
4 | import org.eclipse.emf.ecore.EObject; |
5 | import org.eclipse.jface.dialogs.Dialog; |
6 | import org.eclipse.jface.viewers.CellEditor; |
7 | import org.eclipse.jface.viewers.DialogCellEditor; |
8 | import org.eclipse.jface.viewers.TextCellEditor; |
9 | import org.eclipse.swt.SWT; |
10 | import org.eclipse.swt.events.SelectionListener; |
11 | import org.eclipse.swt.widgets.Composite; |
12 | import org.eclipse.swt.widgets.Control; |
13 | import org.eclipse.swt.widgets.Table; |
14 | import org.eclipse.swt.widgets.TableColumn; |
15 | |
16 | import de.uka.ipd.sdq.pcm.dialogs.parameters.ParametersDialog; |
17 | import de.uka.ipd.sdq.pcm.repository.Signature; |
18 | import de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection; |
19 | import de.uka.ipd.sdq.pcmbench.tabs.generic.ObservableCellModifier; |
20 | |
21 | /**Editor section for infrastructure signatures. |
22 | * Allows to display and edit the list of signatures for a given infrastructure interface. |
23 | * @author groenda |
24 | * |
25 | */ |
26 | public class InfrastructureSignaturesEditorSection extends EditorSection{ |
27 | |
28 | /** Index of the icon column in the table. */ |
29 | public static final int ICON_COLUMN_INDEX = 0; |
30 | /** Index of the signature column in the table. */ |
31 | public static final int SIGNATURENAME_COLUMN_INDEX = 1; |
32 | /** Index of the parameter column in the table. */ |
33 | public static final int PARAMETER_COLUMN_INDEX = 2; |
34 | /** Index of the exception column in the table. */ |
35 | public static final int EXCEPTIONS_COLUMN_INDEX = 3; |
36 | |
37 | /** |
38 | * Columns of a table, which is used into operations table |
39 | */ |
40 | public final static String OPERATIONS_ICON_COLUMN = ""; |
41 | public final static String OWNEDPARAMETER_COLUMN = "Owned Parameter(s)"; |
42 | public final static String SERVICENAME_COLUMN = "Signature Name"; |
43 | public final static String EXEPTIONTYPE_COLUM = "Exception Type"; |
44 | |
45 | /** Column to name mapping. */ |
46 | public static String[] columnNames = new String[] { OPERATIONS_ICON_COLUMN, |
47 | SERVICENAME_COLUMN, OWNEDPARAMETER_COLUMN, EXEPTIONTYPE_COLUM }; |
48 | |
49 | /** Define the Add-Button listener. Listener must by later initialized. */ |
50 | private InfrastructureSignatureAddActionListener addButtonListener; |
51 | |
52 | /** Constructor */ |
53 | public InfrastructureSignaturesEditorSection(Composite composite) { |
54 | super(composite); |
55 | } |
56 | |
57 | /* (non-Javadoc) |
58 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#createViewerCellEditors(org.eclipse.swt.widgets.Table) |
59 | */ |
60 | @Override |
61 | protected CellEditor[] createViewerCellEditors(Table table) { |
62 | CellEditor[] editors = new CellEditor[columnNames.length]; |
63 | |
64 | editors[SIGNATURENAME_COLUMN_INDEX] = new TextCellEditor(table); |
65 | |
66 | // create 'DeleteCellValueListener' and as SelectionListener to the 'TableVewer' |
67 | InfrastructureSignatureDeleteCellValueListener cellValueListener = new InfrastructureSignatureDeleteCellValueListener(viewer); |
68 | viewer.addSelectionChangedListener(cellValueListener); |
69 | |
70 | editors[PARAMETER_COLUMN_INDEX] = new DialogCellEditor(table) { |
71 | @Override |
72 | protected Object openDialogBox(Control cellEditorWindow) { |
73 | ParametersDialog dialog = new ParametersDialog(cellEditorWindow |
74 | .getShell(), getSelectedSignature()); |
75 | if (dialog.open() == Dialog.OK) |
76 | viewer.refresh(); |
77 | return null; |
78 | } |
79 | }; |
80 | |
81 | return editors; |
82 | } |
83 | |
84 | /* (non-Javadoc) |
85 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#createViewerCellModifier() |
86 | */ |
87 | @Override |
88 | protected ObservableCellModifier createViewerCellModifier() { |
89 | return new InfrastructureSignaturesCellModifier(); |
90 | } |
91 | |
92 | /* (non-Javadoc) |
93 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#createTableColumns(org.eclipse.swt.widgets.Table) |
94 | */ |
95 | @Override |
96 | protected void createTableColumns(Table table) { |
97 | // 1st column |
98 | TableColumn column = new TableColumn(table, SWT.CENTER, 0); |
99 | column.setText(""); |
100 | column.setWidth(25); |
101 | |
102 | for (int i = 1; i < columnNames.length; i++) { |
103 | // n-te column with task Description |
104 | column = new TableColumn(table, SWT.LEFT, i); |
105 | column.setText((String) columnNames[i]); |
106 | column.setWidth(140); |
107 | } |
108 | } |
109 | |
110 | /* (non-Javadoc) |
111 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#createAddButtonActionListener() |
112 | */ |
113 | @Override |
114 | protected SelectionListener createAddButtonActionListener() { |
115 | // the value must by initialized! (don't return new AddActionListener()) |
116 | this.addButtonListener = new InfrastructureSignatureAddActionListener(); |
117 | |
118 | return addButtonListener; |
119 | } |
120 | |
121 | /* (non-Javadoc) |
122 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#createDeleteButtonListener() |
123 | */ |
124 | @Override |
125 | protected SelectionListener createDeleteButtonListener() { |
126 | return new InfrastructureSignatureDeleteActionListener(); |
127 | } |
128 | |
129 | /* (non-Javadoc) |
130 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#getViewerColumnProperties() |
131 | */ |
132 | @Override |
133 | protected String[] getTableColumnNames() { |
134 | return columnNames; |
135 | } |
136 | |
137 | /* (non-Javadoc) |
138 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#canAddButonCreated() |
139 | */ |
140 | @Override |
141 | protected boolean canAddButonCreated() { |
142 | return true; |
143 | } |
144 | |
145 | /* (non-Javadoc) |
146 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#canDeleteButonCreated() |
147 | */ |
148 | @Override |
149 | protected boolean canDeleteButonCreated() { |
150 | return true; |
151 | } |
152 | |
153 | /* (non-Javadoc) |
154 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#inputValidation(org.eclipse.emf.ecore.EObject) |
155 | */ |
156 | @Override |
157 | protected boolean inputValidation(EObject object) { |
158 | return true; |
159 | } |
160 | |
161 | public Signature getSelectedSignature() { |
162 | return (Signature) getSelectedObject(); |
163 | } |
164 | |
165 | /** |
166 | * @return the addButtonListener |
167 | */ |
168 | public InfrastructureSignatureAddActionListener getAddButtonListener() { |
169 | return addButtonListener; |
170 | } |
171 | } |