Skip to content
This repository has been archived by the owner on Mar 27, 2018. It is now read-only.

Commit

Permalink
Merge pull request #570 from DiamondLightSource/DAQ-463_ValidationRes…
Browse files Browse the repository at this point in the history
…ults

Created a Validation Results view
  • Loading branch information
gerring authored Feb 27, 2017
2 parents 14d3430 + 3dc47a5 commit 5264180
Show file tree
Hide file tree
Showing 19 changed files with 439 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,20 @@ default void validate(T model) throws ValidationException, InstantiationExceptio
default void setService(IValidatorService vservice) {

}

/**
* Same as Validation method above but returns any results sent back by validation.
*
* @param model
* @return
* @throws ValidationException
*/
default Object validateWithReturn(T model) throws ValidationException {
try {
validate(model);
} catch (InstantiationException | IllegalAccessException e) {
throw new ValidationException(e);
}
return null; // They should implement a validation which throws an exception
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ private static void processRunnables(DeviceRequest request, IRunnableDeviceServi
tdevice.terminate(action.to());
} else if (action==DeviceAction.VALIDATE) {
device.validate(request.getDeviceModel());
} else if (action==DeviceAction.VALIDATEWITHRETURN) {
request.setDeviceValue(device.validateWithReturn(request.getDeviceModel()));
} else if (action==DeviceAction.CONFIGURE) {
device.configure(request.getDeviceModel());
} else if (action==DeviceAction.RUN) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ public enum DeviceAction {
/**
* Disable device, stopping all activity.
*/
DISABLE;
DISABLE,

/**
* Validate, with an expectation that the result will be returned
*/
VALIDATEWITHRETURN;

public static DeviceAction as(TerminationPreference pref) {
switch(pref) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.scanning.api.device.IAttributableDevice;
import org.eclipse.scanning.api.device.IRunnableEventDevice;
import org.eclipse.scanning.api.points.IPointGenerator;
import org.eclipse.scanning.api.scan.ScanningException;


/**
Expand Down Expand Up @@ -67,17 +68,12 @@ public interface IMalcolmDevice<T> extends IRunnableEventDevice<T>, IMalcolmEven
*/
public boolean isLocked() throws MalcolmDeviceException ;

/**
* Gets the value of an attribute on the device
*/
public <A> A getAttributeValue(String attribute) throws MalcolmDeviceException;

/**
* Returns the axes that this malcolm device can move.
* @return
* @throws MalcolmDeviceException
* @throws ScanningException
*/
public Set<String> getAxesToMove() throws MalcolmDeviceException;
public Set<String> getAxesToMove() throws ScanningException;

/**
* Set the point generator for the malcolm device.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class MalcolmMessage {
private String message;
private Object arguments;
private Object value;
private Object rawValue;

public Type getType() {
return type;
Expand Down Expand Up @@ -69,6 +70,7 @@ public int hashCode() {
result = prime * result + ((param == null) ? 0 : param.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
result = prime * result + ((rawValue == null) ? 0 : rawValue.hashCode());
return result;
}

Expand Down Expand Up @@ -115,6 +117,11 @@ public boolean equals(Object obj) {
return false;
} else if (!value.equals(other.value))
return false;
if (rawValue == null) {
if (other.rawValue != null)
return false;
} else if (!rawValue.equals(other.rawValue))
return false;
return true;
}
public Object getArguments() {
Expand Down Expand Up @@ -162,4 +169,10 @@ public String getEndpoint() {
public void setEndpoint(String endPoint) {
this.endpoint = endPoint;
}
public Object getRawValue() {
return rawValue;
}
public void setRawValue(Object rawValue) {
this.rawValue = rawValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public MalcolmMessage convertCallPVStructureToMalcolmMessage(PVStructure structu
result.setType(Type.RETURN);
result.setEndpoint(message.getEndpoint());
result.setId(message.getId());
result.setRawValue(structure.toString());

if (structure.getStructure().getID().startsWith(ERROR_TYPE)) {
result.setType(Type.ERROR);
Expand All @@ -182,6 +183,7 @@ public MalcolmMessage convertSubscribeUpdatePVStructureToMalcolmMessage(PVStruct
result.setType(Type.UPDATE);
result.setEndpoint(message.getEndpoint());
result.setId(message.getId());
result.setRawValue(structure.toString());

Object returnedObject = getEndpointObjectFromPVStructure(structure, message.getEndpoint());

Expand All @@ -196,6 +198,7 @@ public MalcolmMessage convertGetPVStructureToMalcolmMessage(PVStructure structur
result.setType(Type.RETURN);
result.setEndpoint(message.getEndpoint());
result.setId(message.getId());
result.setRawValue(structure.toString());

if (structure.getStructure().getID().startsWith(ERROR_TYPE)) {
result.setType(Type.ERROR);
Expand Down
3 changes: 2 additions & 1 deletion org.eclipse.scanning.device.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.107.0",
org.eclipse.dawnsci.analysis.dataset;bundle-version="1.0.0",
org.eclipse.richbeans.widgets.file;bundle-version="1.0.0",
org.eclipse.scanning.api;bundle-version="1.0.0",
org.eclipse.richbeans.annot;bundle-version="1.0.0"
org.eclipse.richbeans.annot;bundle-version="1.0.0",
org.eclipse.scanning.event.ui;bundle-version="1.0.0"
Import-Package: org.osgi.framework;version="1.8.0",
org.osgi.service.event;version="1.3.1",
org.slf4j;version="1.7.2"
Expand Down
Binary file added org.eclipse.scanning.device.ui/icons/report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions org.eclipse.scanning.device.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
id="org.eclipse.scanning.device.ui.scan.executeView"
name="Run">
</view>
<view
category="org.eclipse.scanning.device.ui"
class="org.eclipse.scanning.device.ui.points.ValidateResultsView"
icon="icons/report.png"
id="org.eclipse.scanning.device.ui.scan.validateResultsView"
name="Validation Results">
</view>
<view
category="org.eclipse.scanning.device.ui"
class="org.eclipse.scanning.device.ui.device.ControlView"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.scanning.api.ValidationException;
import org.eclipse.scanning.api.device.IActivatable;
import org.eclipse.scanning.api.device.IRunnableDevice;
import org.eclipse.scanning.api.device.IRunnableDeviceService;
Expand All @@ -43,7 +44,11 @@
import org.eclipse.scanning.device.ui.DevicePreferenceConstants;
import org.eclipse.scanning.device.ui.EventConnectionView;
import org.eclipse.scanning.device.ui.ServiceHolder;
import org.eclipse.scanning.device.ui.points.ValidateResults;
import org.eclipse.scanning.device.ui.points.ValidateResultsView;
import org.eclipse.scanning.device.ui.util.PageUtil;
import org.eclipse.scanning.device.ui.util.ViewUtil;
import org.eclipse.scanning.event.ui.view.DelegatingSelectionProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
Expand All @@ -53,6 +58,9 @@
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.osgi.framework.Bundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -73,7 +81,8 @@ public class DetectorView extends EventConnectionView {
private TableViewer viewer;
private Image ticked, unticked, defaultIcon;
private Map<String,Image> iconMap;

private DelegatingSelectionProvider selectionProvider;

// Services
private IRunnableDeviceService dservice;

Expand Down Expand Up @@ -122,7 +131,8 @@ public void createPartControl(Composite parent) {
}
viewer.setInput(new Object());

getSite().setSelectionProvider(viewer);
selectionProvider = new DelegatingSelectionProvider(viewer);
getSite().setSelectionProvider(selectionProvider);

createActions();
initializeToolBar();
Expand Down Expand Up @@ -332,14 +342,44 @@ protected void configure() {
try {
IRunnableDevice<Object> device = dservice.getRunnableDevice(info.getName());
Object model = info.getModel();

// Pass null to 'clear' the validation results view
selectionProvider.fireSelection(new StructuredSelection(new ValidateResults(info.getName(), null)));

Object validateReturn = device.validateWithReturn(model);

ValidateResults validateResults = new ValidateResults(info.getName(), validateReturn);

showValidationResultsView(validateResults);

selectionProvider.fireSelection(new StructuredSelection(validateResults));

device.configure(model);

} catch (ScanningException ne) {
} catch (ScanningException|ValidationException ne) {
ErrorDialog.openError(getViewSite().getShell(), "Configure Failed", "The configure of '"+info.getName()+"' failed",
new Status(IStatus.ERROR, "org.eclipse.scanning.device.ui", ne.getMessage(), ne));
logger.error("Cannot configure '"+info.getName()+"'", ne);
}
}

private void showValidationResultsView(ValidateResults validateResults) {
PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
try {
if (PageUtil.getPage().findView(ValidateResultsView.ID) == null) {
IViewPart viewPart = PageUtil.getPage().showView(ValidateResultsView.ID);
if (viewPart instanceof ValidateResultsView) {
ValidateResultsView validateResultsView = (ValidateResultsView)viewPart;
validateResultsView.update(validateResults);
}
} else {
PageUtil.getPage().showView(ValidateResultsView.ID);
}
} catch (PartInitException e) {
logger.warn("Unable to show validate results view " + e);
}
});
}

private DeviceInformation<?> getSelection() {
if (viewer.getSelection() == null || viewer.getSelection().isEmpty()) return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.eclipse.scanning.device.ui.points;

/**
* Class to contain validation results for display in the UI
*
* @author Matt Taylor
*
*/
public class ValidateResults {
private String deviceName;
private Object results;

public ValidateResults(String deviceName, Object results) {
this.deviceName = deviceName;
this.results = results;
}

public String getDeviceName() {
return deviceName;
}

public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}

public Object getResults() {
return results;
}

public void setResults(Object results) {
this.results = results;
}

}
Loading

0 comments on commit 5264180

Please sign in to comment.