1 | package de.uka.ipd.sdq.pipesandfilters.framework.recorder.sensorframework.launch; |
2 | |
3 | import org.eclipse.core.runtime.CoreException; |
4 | import org.eclipse.debug.core.ILaunchConfiguration; |
5 | import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
6 | import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; |
7 | import org.eclipse.jface.dialogs.Dialog; |
8 | import org.eclipse.swt.SWT; |
9 | import org.eclipse.swt.events.ModifyEvent; |
10 | import org.eclipse.swt.events.ModifyListener; |
11 | import org.eclipse.swt.events.SelectionAdapter; |
12 | import org.eclipse.swt.events.SelectionEvent; |
13 | import org.eclipse.swt.layout.GridData; |
14 | import org.eclipse.swt.layout.GridLayout; |
15 | import org.eclipse.swt.widgets.Button; |
16 | import org.eclipse.swt.widgets.Composite; |
17 | import org.eclipse.swt.widgets.Group; |
18 | import org.eclipse.swt.widgets.Label; |
19 | import org.eclipse.swt.widgets.Text; |
20 | |
21 | import de.uka.ipd.sdq.sensorframework.SensorFrameworkDataset; |
22 | import de.uka.ipd.sdq.sensorframework.dialogs.dataset.ConfigureDatasourceDialog; |
23 | import de.uka.ipd.sdq.sensorframework.dialogs.dataset.DatasourceListLabelProvider; |
24 | import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory; |
25 | |
26 | public class SensorFrameworkTab extends AbstractLaunchConfigurationTab { |
27 | |
28 | private Text dataField; |
29 | |
30 | protected int selectedDataSourceID; |
31 | |
32 | @Override |
33 | public void createControl(Composite parent) { |
34 | Composite container = new Composite(parent, SWT.NONE); |
35 | container.setLayout(new GridLayout()); |
36 | setControl(container); |
37 | |
38 | final ModifyListener modifyListener = new ModifyListener() { |
39 | |
40 | public void modifyText(ModifyEvent e) { |
41 | SensorFrameworkTab.this.setDirty(true); |
42 | SensorFrameworkTab.this.updateLaunchConfigurationDialog(); |
43 | } |
44 | }; |
45 | |
46 | final Group dataSetGroup = new Group(container, SWT.NONE); |
47 | dataSetGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, |
48 | false)); |
49 | final GridLayout gridLayout_2 = new GridLayout(); |
50 | gridLayout_2.numColumns = 3; |
51 | dataSetGroup.setLayout(gridLayout_2); |
52 | dataSetGroup.setText("Data Set"); |
53 | |
54 | final Label dataSourceLabel = new Label(dataSetGroup, SWT.NONE); |
55 | dataSourceLabel.setText("Data source:"); |
56 | |
57 | dataField = new Text(dataSetGroup, SWT.BORDER | SWT.READ_ONLY); |
58 | dataField |
59 | .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
60 | dataField.addModifyListener(modifyListener); |
61 | |
62 | final Button browseButton = new Button(dataSetGroup, SWT.NONE); |
63 | browseButton.setText("Browse..."); |
64 | browseButton.addSelectionListener(new SelectionAdapter() { |
65 | |
66 | /* |
67 | * (non-Javadoc) |
68 | * |
69 | * @see |
70 | * org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse |
71 | * .swt.events.SelectionEvent) |
72 | */ |
73 | @Override |
74 | public void widgetSelected(SelectionEvent e) { |
75 | ConfigureDatasourceDialog dialog = new ConfigureDatasourceDialog( |
76 | e.display.getActiveShell(), "Select Datasource...", |
77 | true); |
78 | if (dialog.open() == Dialog.OK) { |
79 | IDAOFactory dataSet = (IDAOFactory) dialog.getResult(); |
80 | selectedDataSourceID = (int) dataSet.getID(); |
81 | dataField.setText(dataSet.getName() + " [" |
82 | + dataSet.getID() + " ]"); |
83 | } |
84 | } |
85 | }); |
86 | |
87 | } |
88 | |
89 | @Override |
90 | public String getName() { |
91 | return "SensorFramework"; |
92 | } |
93 | |
94 | @Override |
95 | public void initializeFrom(ILaunchConfiguration configuration) { |
96 | try { |
97 | selectedDataSourceID = configuration.getAttribute( |
98 | SensorFrameworkConfig.DATASOURCE_ID, -1); |
99 | if (SensorFrameworkDataset.singleton().getDataSourceByID( |
100 | selectedDataSourceID) == null) |
101 | dataField.setText(""); |
102 | else { |
103 | IDAOFactory factory = SensorFrameworkDataset.singleton() |
104 | .getDataSourceByID(selectedDataSourceID); |
105 | dataField.setText(DatasourceListLabelProvider |
106 | .dataSetRepresentation(factory)); |
107 | } |
108 | } catch (CoreException e) { |
109 | selectedDataSourceID = -1; |
110 | dataField.setText(""); |
111 | } |
112 | } |
113 | |
114 | @Override |
115 | public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
116 | configuration.setAttribute(SensorFrameworkConfig.DATASOURCE_ID, |
117 | selectedDataSourceID); |
118 | |
119 | } |
120 | |
121 | @Override |
122 | public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { |
123 | configuration.setAttribute(SensorFrameworkConfig.DATASOURCE_ID, -1); |
124 | } |
125 | |
126 | @Override |
127 | public boolean isValid(ILaunchConfiguration launchConfig) { |
128 | if (SensorFrameworkDataset.singleton().getDataSourceByID( |
129 | selectedDataSourceID) == null) { |
130 | setErrorMessage("Data source is missing!"); |
131 | return false; |
132 | } |
133 | return true; |
134 | } |
135 | |
136 | @Override |
137 | public void activated(ILaunchConfigurationWorkingCopy workingCopy) {} |
138 | |
139 | @Override |
140 | public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {} |
141 | |
142 | } |