| 1 | package de.uka.ipd.sdq.sensorframework.visualisation.dialogs; |
| 2 | |
| 3 | import org.eclipse.jface.dialogs.IDialogConstants; |
| 4 | import org.eclipse.jface.dialogs.TitleAreaDialog; |
| 5 | import org.eclipse.jface.viewers.CellEditor; |
| 6 | import org.eclipse.jface.viewers.CheckboxCellEditor; |
| 7 | import org.eclipse.jface.viewers.ISelectionChangedListener; |
| 8 | import org.eclipse.jface.viewers.SelectionChangedEvent; |
| 9 | import org.eclipse.jface.viewers.TableViewer; |
| 10 | import org.eclipse.jface.viewers.Viewer; |
| 11 | import org.eclipse.jface.viewers.ViewerComparator; |
| 12 | import org.eclipse.swt.SWT; |
| 13 | import org.eclipse.swt.graphics.Point; |
| 14 | import org.eclipse.swt.layout.GridData; |
| 15 | import org.eclipse.swt.layout.GridLayout; |
| 16 | import org.eclipse.swt.widgets.Composite; |
| 17 | import org.eclipse.swt.widgets.Control; |
| 18 | import org.eclipse.swt.widgets.Shell; |
| 19 | import org.eclipse.swt.widgets.Table; |
| 20 | import org.eclipse.swt.widgets.TableColumn; |
| 21 | |
| 22 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
| 23 | import de.uka.ipd.sdq.sensorframework.visualisation.editor.ConfigEntry; |
| 24 | |
| 25 | /** |
| 26 | * TODO |
| 27 | * @author admin |
| 28 | * |
| 29 | */ |
| 30 | public class SensorsDialog extends TitleAreaDialog { |
| 31 | |
| 32 | private ConfigEntry entry; |
| 33 | |
| 34 | public static final int CHECK_COLUMN_INDEX = 0; |
| 35 | public static final int SENSOR_ID_INDEX = 1; |
| 36 | public static final int SENSOR_NAME_COLUMN_INDEX = 2; |
| 37 | |
| 38 | /** |
| 39 | * Columns of a table, which is used into ParameterEditDialog |
| 40 | */ |
| 41 | public final static String CHECK_COLUMN = ""; |
| 42 | public final static String SENSOR_ID_COLUMN = "Id"; |
| 43 | public final static String SENSOR_NAME_COLUMN = "Sensorname"; |
| 44 | |
| 45 | // Set column names of Tabele |
| 46 | public static String[] columnNames = new String[] { CHECK_COLUMN, |
| 47 | SENSOR_ID_COLUMN, SENSOR_NAME_COLUMN }; |
| 48 | |
| 49 | private Table table; |
| 50 | |
| 51 | public SensorsDialog(Shell parentShell, ConfigEntry entry) { |
| 52 | super(parentShell); |
| 53 | this.entry = entry; |
| 54 | } |
| 55 | |
| 56 | /* (non-Javadoc) |
| 57 | * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite) |
| 58 | */ |
| 59 | @Override |
| 60 | protected Control createDialogArea(Composite parent) { |
| 61 | Composite area = (Composite) super.createDialogArea(parent); |
| 62 | Composite container = new Composite(area, SWT.NONE); |
| 63 | container.setLayout(new GridLayout()); |
| 64 | container.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 65 | |
| 66 | final TableViewer tableViewer = new TableViewer(container, SWT.BORDER); |
| 67 | //| SWT.CHECK); |
| 68 | table = tableViewer.getTable(); |
| 69 | table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 70 | table.setLinesVisible(true); |
| 71 | table.setHeaderVisible(true); |
| 72 | |
| 73 | final TableColumn checkColumn = new TableColumn(table, SWT.LEFT); |
| 74 | checkColumn.setWidth(24); |
| 75 | checkColumn.setText(CHECK_COLUMN); |
| 76 | |
| 77 | final TableColumn experimentColumn = new TableColumn(table, SWT.LEFT); |
| 78 | experimentColumn.setWidth(40); |
| 79 | experimentColumn.setText(SENSOR_ID_COLUMN); |
| 80 | |
| 81 | final TableColumn sensorColumn = new TableColumn(table, SWT.LEFT); |
| 82 | sensorColumn.setWidth(260); |
| 83 | sensorColumn.setText(SENSOR_NAME_COLUMN); |
| 84 | |
| 85 | CellEditor[] editors = new CellEditor[columnNames.length]; |
| 86 | |
| 87 | // Column 1 : Completed (Checkbox) |
| 88 | editors[0] = new CheckboxCellEditor(table); |
| 89 | |
| 90 | tableViewer.addSelectionChangedListener(new ISelectionChangedListener(){ |
| 91 | |
| 92 | public void selectionChanged(SelectionChangedEvent event) { |
| 93 | tableViewer.refresh(); |
| 94 | } |
| 95 | }); |
| 96 | // Assign the cell editors to the viewer |
| 97 | tableViewer.setColumnProperties(columnNames); |
| 98 | tableViewer.setCellEditors(editors); |
| 99 | tableViewer.setCellModifier(new SensorsDialogCellModifier(entry)); |
| 100 | tableViewer.setContentProvider(new SensorsDialogContentProvider()); |
| 101 | tableViewer.setLabelProvider(new SensorsDialogLabelProvider(entry)); |
| 102 | tableViewer.setComparator(new ViewerComparator() { |
| 103 | |
| 104 | @Override |
| 105 | public int compare(Viewer viewer, Object e1, Object e2) { |
| 106 | if (e1 instanceof Sensor && e2 instanceof Sensor ) { |
| 107 | return ((Sensor ) e1).getSensorName().compareToIgnoreCase( |
| 108 | ((Sensor ) e2).getSensorName()); |
| 109 | } |
| 110 | throw new IllegalArgumentException("Not comparable: " + e1 + " " + e2); |
| 111 | } |
| 112 | |
| 113 | }); |
| 114 | |
| 115 | tableViewer.setInput(entry); |
| 116 | |
| 117 | // |
| 118 | return area; |
| 119 | } |
| 120 | |
| 121 | /* (non-Javadoc) |
| 122 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) |
| 123 | */ |
| 124 | @Override |
| 125 | protected void createButtonsForButtonBar(Composite parent) { |
| 126 | createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, |
| 127 | true); |
| 128 | createButton(parent, IDialogConstants.CANCEL_ID, |
| 129 | IDialogConstants.CANCEL_LABEL, false); |
| 130 | } |
| 131 | |
| 132 | /* (non-Javadoc) |
| 133 | * @see org.eclipse.jface.dialogs.TitleAreaDialog#getInitialSize() |
| 134 | */ |
| 135 | @Override |
| 136 | protected Point getInitialSize() { |
| 137 | return new Point(400, 350); |
| 138 | } |
| 139 | |
| 140 | /* (non-Javadoc) |
| 141 | * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) |
| 142 | */ |
| 143 | @Override |
| 144 | protected void configureShell(Shell newShell) { |
| 145 | super.configureShell(newShell); |
| 146 | newShell.setText("Select sensors"); |
| 147 | } |
| 148 | } |