|
29 | 29 | import org.eclipse.swt.SWT; |
30 | 30 | import org.eclipse.swt.custom.TableEditor; |
31 | 31 | import org.eclipse.swt.events.ControlAdapter; |
32 | | -import org.eclipse.swt.events.ControlEvent; |
33 | | -import org.eclipse.swt.events.ModifyEvent; |
34 | | -import org.eclipse.swt.events.ModifyListener; |
| 32 | +import org.eclipse.swt.events.ControlEvent; |
35 | 33 | import org.eclipse.swt.events.SelectionAdapter; |
36 | 34 | import org.eclipse.swt.events.SelectionEvent; |
37 | 35 | import org.eclipse.swt.graphics.Point; |
|
41 | 39 | import org.eclipse.swt.widgets.Button; |
42 | 40 | import org.eclipse.swt.widgets.Composite; |
43 | 41 | import org.eclipse.swt.widgets.Control; |
44 | | -import org.eclipse.swt.widgets.Display; |
45 | | -import org.eclipse.swt.widgets.Event; |
| 42 | +import org.eclipse.swt.widgets.Display; |
46 | 43 | import org.eclipse.swt.widgets.FileDialog; |
47 | | -import org.eclipse.swt.widgets.List; |
48 | | -import org.eclipse.swt.widgets.Listener; |
| 44 | +import org.eclipse.swt.widgets.List; |
49 | 45 | import org.eclipse.swt.widgets.Table; |
50 | 46 | import org.eclipse.swt.widgets.TableColumn; |
51 | 47 | import org.eclipse.swt.widgets.TableItem; |
@@ -154,49 +150,41 @@ private void addComponentTable(Composite comp) { |
154 | 150 | tableEditor.grabHorizontal = true; |
155 | 151 | tableEditor.minimumWidth = 50; |
156 | 152 |
|
157 | | - tableCmsComponents.addListener(SWT.MouseDown, new Listener() { |
| 153 | + tableCmsComponents.addListener(SWT.MouseDown, event -> { |
158 | 154 |
|
159 | | - @Override |
160 | | - public void handleEvent(Event event) { |
161 | | - |
162 | | - Point pt = new Point(event.x, event.y); |
163 | | - // Clean up any previous editor control |
164 | | - Control oldEditor = tableEditor.getEditor(); |
165 | | - if(oldEditor != null) { |
166 | | - oldEditor.dispose(); |
167 | | - } |
168 | | - TableItem item = tableCmsComponents.getItem(pt); |
169 | | - if(item != null) { |
170 | | - /* Iterate over all columns and check if event is contained */ |
171 | | - for(int col = 0; col < tableCmsComponents.getColumnCount(); col++) { |
172 | | - Rectangle rect = item.getBounds(col); |
173 | | - int rowIndex; |
174 | | - if(rect.contains(pt) && (null != cmsLibSpectra) && (0 <= (rowIndex = tableCmsComponents.indexOf(item)))) { |
175 | | - ICalibratedVendorLibraryMassSpectrum libSpectrum = (ICalibratedVendorLibraryMassSpectrum)cmsLibSpectra.getList().get(rowIndex); |
176 | | - if(COLUMN_1 == col) { |
177 | | - libSpectrum.setSelected(!libSpectrum.isSelected()); |
178 | | - item.setText(makeTableStrings(libSpectrum, libSpectrum.isSelected())); |
179 | | - } else if(COLUMN_0 == col) { |
180 | | - // The control that will be the editor must be a child of the Table |
181 | | - Text newEditor = new Text(tableCmsComponents, SWT.NONE); |
182 | | - newEditor.setText(item.getText(COLUMN_0)); |
183 | | - newEditor.addModifyListener(new ModifyListener() { |
184 | | - |
185 | | - @Override |
186 | | - public void modifyText(ModifyEvent e) { |
187 | | - |
188 | | - Text text = (Text)tableEditor.getEditor(); |
189 | | - if(isValidDoubleString(text.getText())) { |
190 | | - tableEditor.getItem().setText(COLUMN_0, text.getText()); |
191 | | - libSpectrum.setScaleFactor(Double.parseDouble(text.getText())); |
192 | | - item.setText(makeTableStrings(libSpectrum, libSpectrum.isSelected())); |
193 | | - } |
194 | | - } |
195 | | - }); |
196 | | - newEditor.selectAll(); |
197 | | - newEditor.setFocus(); |
198 | | - tableEditor.setEditor(newEditor, item, COLUMN_0); |
199 | | - } |
| 155 | + Point pt = new Point(event.x, event.y); |
| 156 | + // Clean up any previous editor control |
| 157 | + Control oldEditor = tableEditor.getEditor(); |
| 158 | + if(oldEditor != null) { |
| 159 | + oldEditor.dispose(); |
| 160 | + } |
| 161 | + TableItem item = tableCmsComponents.getItem(pt); |
| 162 | + if(item != null) { |
| 163 | + /* Iterate over all columns and check if event is contained */ |
| 164 | + for(int col = 0; col < tableCmsComponents.getColumnCount(); col++) { |
| 165 | + Rectangle rect = item.getBounds(col); |
| 166 | + int rowIndex; |
| 167 | + if(rect.contains(pt) && (null != cmsLibSpectra) && (0 <= (rowIndex = tableCmsComponents.indexOf(item)))) { |
| 168 | + ICalibratedVendorLibraryMassSpectrum libSpectrum = (ICalibratedVendorLibraryMassSpectrum)cmsLibSpectra.getList().get(rowIndex); |
| 169 | + if(COLUMN_1 == col) { |
| 170 | + libSpectrum.setSelected(!libSpectrum.isSelected()); |
| 171 | + item.setText(makeTableStrings(libSpectrum, libSpectrum.isSelected())); |
| 172 | + } else if(COLUMN_0 == col) { |
| 173 | + // The control that will be the editor must be a child of the Table |
| 174 | + Text newEditor = new Text(tableCmsComponents, SWT.NONE); |
| 175 | + newEditor.setText(item.getText(COLUMN_0)); |
| 176 | + newEditor.addModifyListener(e -> { |
| 177 | + |
| 178 | + Text text = (Text)tableEditor.getEditor(); |
| 179 | + if(isValidDoubleString(text.getText())) { |
| 180 | + tableEditor.getItem().setText(COLUMN_0, text.getText()); |
| 181 | + libSpectrum.setScaleFactor(Double.parseDouble(text.getText())); |
| 182 | + item.setText(makeTableStrings(libSpectrum, libSpectrum.isSelected())); |
| 183 | + } |
| 184 | + }); |
| 185 | + newEditor.selectAll(); |
| 186 | + newEditor.setFocus(); |
| 187 | + tableEditor.setEditor(newEditor, item, COLUMN_0); |
200 | 188 | } |
201 | 189 | } |
202 | 190 | } |
|
0 commit comments