| 1 | package de.uka.ipd.sdq.sensorframework.visualisation.views; |
| 2 | |
| 3 | import org.eclipse.jface.dialogs.MessageDialog; |
| 4 | import org.eclipse.jface.viewers.IStructuredSelection; |
| 5 | import org.eclipse.swt.dnd.DND; |
| 6 | import org.eclipse.swt.dnd.DropTargetAdapter; |
| 7 | import org.eclipse.swt.dnd.DropTargetEvent; |
| 8 | import org.eclipse.ui.IEditorInput; |
| 9 | import org.eclipse.ui.views.navigator.LocalSelectionTransfer; |
| 10 | |
| 11 | import de.uka.ipd.sdq.sensorframework.entities.Experiment; |
| 12 | import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun; |
| 13 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
| 14 | import de.uka.ipd.sdq.sensorframework.entities.SensorAndMeasurements; |
| 15 | import de.uka.ipd.sdq.sensorframework.visualisation.editor.ConfigEditorInput; |
| 16 | import de.uka.ipd.sdq.sensorframework.visualisation.editor.ConfigEntry; |
| 17 | import de.uka.ipd.sdq.sensorframework.visualisation.editor.SensorValidationToView; |
| 18 | |
| 19 | /** @author admin */ |
| 20 | public class ViewDropTargetListener extends DropTargetAdapter { |
| 21 | |
| 22 | private ConfigEditorInput configEditorInput; |
| 23 | |
| 24 | public ViewDropTargetListener(IEditorInput editorInput) { |
| 25 | this.configEditorInput = (ConfigEditorInput)editorInput; |
| 26 | } |
| 27 | |
| 28 | /* (non-Javadoc) |
| 29 | * @see org.eclipse.swt.dnd.DropTargetListener#dragEnter(org.eclipse.swt.dnd.DropTargetEvent) |
| 30 | */ |
| 31 | @Override |
| 32 | public void dragEnter(DropTargetEvent event) { |
| 33 | if (event.detail == DND.DROP_DEFAULT) |
| 34 | { |
| 35 | if ((event.operations & DND.DROP_COPY) != 0) |
| 36 | event.detail = DND.DROP_COPY; |
| 37 | else |
| 38 | event.detail = DND.DROP_NONE; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /* |
| 43 | * (non-Javadoc) |
| 44 | * |
| 45 | * @see org.eclipse.swt.dnd.DropTargetListener#dragLeave(org.eclipse.swt.dnd.DropTargetEvent) |
| 46 | */ |
| 47 | @Override |
| 48 | public void dragLeave(DropTargetEvent event) { |
| 49 | // TODO Auto-generated method stub |
| 50 | } |
| 51 | |
| 52 | /* (non-Javadoc) |
| 53 | * @see org.eclipse.swt.dnd.DropTargetListener#dragOperationChanged(org.eclipse.swt.dnd.DropTargetEvent) |
| 54 | */ |
| 55 | @Override |
| 56 | public void dragOperationChanged(DropTargetEvent event) { |
| 57 | if (event.detail == DND.DROP_DEFAULT) |
| 58 | { |
| 59 | if ((event.operations & DND.DROP_COPY) != 0) |
| 60 | event.detail = DND.DROP_COPY; |
| 61 | else |
| 62 | event.detail = DND.DROP_NONE; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /* (non-Javadoc) |
| 67 | * @see org.eclipse.swt.dnd.DropTargetListener#drop(org.eclipse.swt.dnd.DropTargetEvent) |
| 68 | */ |
| 69 | @Override |
| 70 | public void drop(DropTargetEvent event) { |
| 71 | IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer |
| 72 | .getTransfer().getSelection(); |
| 73 | Object object = selection.getFirstElement(); |
| 74 | if (object instanceof TreeObject) { |
| 75 | TreeObject treeObject = (TreeObject) object; |
| 76 | Object innerObject = treeObject.getObject(); |
| 77 | /** Drop a sensor */ |
| 78 | if (innerObject instanceof Sensor) { |
| 79 | Sensor sensor = (Sensor) innerObject; |
| 80 | ExperimentRun run = treeObject.getRun(); |
| 81 | Experiment experiment = treeObject.getExperiment(); |
| 82 | SensorAndMeasurements sam = run.getMeasurementsOfSensor(sensor); |
| 83 | if (sam.getMeasurements().size() > 0){ |
| 84 | /** |
| 85 | * sensor validation - if view do support the representation of |
| 86 | * the selected sensor |
| 87 | */ |
| 88 | if (SensorValidationToView.canViewSensor(sam)) { |
| 89 | configEditorInput.editConfigEntry(treeObject.getDatasource(), run, experiment, sensor, null); |
| 90 | } else { |
| 91 | SensorValidationToView.showMessage(event.display |
| 92 | .getActiveShell()); |
| 93 | } |
| 94 | } else { |
| 95 | MessageDialog.openWarning(event.display.getActiveShell(), |
| 96 | "Empty Sensor", |
| 97 | "The dropped sensor does not contain measurements in the selected Experiment Run." + |
| 98 | " Refused to add sensor to view."); |
| 99 | } |
| 100 | } |
| 101 | /** Drop a experiment run */ |
| 102 | if (innerObject instanceof ExperimentRun) { |
| 103 | ExperimentRun run = (ExperimentRun) innerObject; |
| 104 | if (configEditorInput.getConfigEntryToRun(run) == null) { |
| 105 | ConfigEntry configEntry = new ConfigEntry(treeObject.getDatasource(), |
| 106 | run, treeObject |
| 107 | .getExperiment(), null); |
| 108 | configEditorInput.addConfigEntry(configEntry); |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | |
| 115 | /* (non-Javadoc) |
| 116 | * @see org.eclipse.swt.dnd.DropTargetListener#dropAccept(org.eclipse.swt.dnd.DropTargetEvent) |
| 117 | */ |
| 118 | @Override |
| 119 | public void dropAccept(DropTargetEvent event) { |
| 120 | // TODO Auto-generated method stub |
| 121 | } |
| 122 | } |