| 1 | package de.uka.ipd.sdq.sensorframework.visualisation.views; |
| 2 | |
| 3 | import org.eclipse.core.runtime.IConfigurationElement; |
| 4 | import org.eclipse.jface.dialogs.MessageDialog; |
| 5 | import org.eclipse.jface.viewers.DoubleClickEvent; |
| 6 | import org.eclipse.jface.viewers.IDoubleClickListener; |
| 7 | import org.eclipse.jface.viewers.IStructuredSelection; |
| 8 | import org.eclipse.ui.PlatformUI; |
| 9 | |
| 10 | import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun; |
| 11 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
| 12 | import de.uka.ipd.sdq.sensorframework.entities.SensorAndMeasurements; |
| 13 | import de.uka.ipd.sdq.sensorframework.visualisation.dialogs.ViewAndAdapterFactory; |
| 14 | import de.uka.ipd.sdq.sensorframework.visualisation.editor.ConfigEditorInput; |
| 15 | import de.uka.ipd.sdq.sensorframework.visualisation.editor.ConfigEntry; |
| 16 | import de.uka.ipd.sdq.sensorframework.visualisation.editor.SensorValidationToView; |
| 17 | import de.uka.ipd.sdq.sensorframework.visualisation.menu.DoubleClickAction; |
| 18 | |
| 19 | /** @author roman */ |
| 20 | public class DoubleClickListener implements IDoubleClickListener { |
| 21 | |
| 22 | private DoubleClickAction doubleClickAction; |
| 23 | |
| 24 | /* (non-Javadoc) |
| 25 | * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent) |
| 26 | */ |
| 27 | public void doubleClick(DoubleClickEvent event) { |
| 28 | if (event.getSelection() instanceof IStructuredSelection) { |
| 29 | IStructuredSelection selection = (IStructuredSelection) event |
| 30 | .getSelection(); |
| 31 | Object object = selection.getFirstElement(); |
| 32 | |
| 33 | if (object instanceof TreeObject) { |
| 34 | |
| 35 | TreeObject treeObject = (TreeObject) object; |
| 36 | Object innerObject = treeObject.getObject(); |
| 37 | ExperimentRun run = treeObject.getRun(); |
| 38 | |
| 39 | /** Sensor */ |
| 40 | if (innerObject instanceof Sensor && run != null) { |
| 41 | Sensor sensor = (Sensor) innerObject; |
| 42 | SensorAndMeasurements sam = run.getMeasurementsOfSensor(sensor); |
| 43 | |
| 44 | if (sam.getMeasurements().size() != 0) { |
| 45 | /** return all view, which can represent the sensor */ |
| 46 | Object[] viewers = SensorValidationToView.findViews(sam); |
| 47 | |
| 48 | ViewAndAdapterFactory selecedView = SensorValidationToView.getSelectedAction(event.getViewer().getControl() |
| 49 | .getShell(), viewers); |
| 50 | if (selecedView != null) { |
| 51 | ConfigEditorInput editorInput = new ConfigEditorInput(selecedView.getFactory().getAdapterFactoryID()); |
| 52 | ConfigEntry configEntry = new ConfigEntry(treeObject |
| 53 | .getDatasource(), treeObject.getRun(), treeObject |
| 54 | .getExperiment(), sensor); |
| 55 | editorInput.addConfigEntry(configEntry); |
| 56 | IConfigurationElement action = selecedView.getView(); |
| 57 | hookDoubleClickAction(editorInput, action.getAttribute("editorID")); |
| 58 | } |
| 59 | } else { |
| 60 | MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
| 61 | "Empty Sensor", |
| 62 | "The selected sensor does not contain measurements in the selected Experiment Run." + |
| 63 | " Refused to open view."); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | private void hookDoubleClickAction(ConfigEditorInput editorInput, |
| 71 | String editorID) { |
| 72 | doubleClickAction = new DoubleClickAction(editorInput, editorID); |
| 73 | doubleClickAction.run(); |
| 74 | } |
| 75 | } |