use of uk.ac.diamond.daq.mapping.api.ConfigWrapper in project gda-core by openGDA.
the class ProcessingSection method createProcessingTable.
private void createProcessingTable(Composite parent) {
processingChainsComposite = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, true).applyTo(processingChainsComposite);
GridLayoutFactory.fillDefaults().applyTo(processingChainsComposite);
viewer = new TableViewer(processingChainsComposite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getTable());
viewer.getTable().setHeaderVisible(true);
ColumnViewerToolTipSupport.enableFor(viewer);
viewer.setContentProvider(new ArrayContentProvider());
TableViewerColumn check = new TableViewerColumn(viewer, SWT.CENTER, 0);
check.setEditingSupport(new CheckBoxEditSupport(viewer));
check.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return "";
}
@Override
public Image getImage(Object element) {
return ((ConfigWrapper) element).isActive() ? ticked : unticked;
}
});
check.getColumn().setWidth(28);
TableViewerColumn app = new TableViewerColumn(viewer, SWT.LEFT);
app.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((ConfigWrapper) element).getAppName();
}
});
app.getColumn().setText("App");
app.getColumn().setWidth(100);
TableViewerColumn name = new TableViewerColumn(viewer, SWT.LEFT);
name.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((ConfigWrapper) element).getName();
}
@Override
public String getToolTipText(Object element) {
return ((ConfigWrapper) element).getPathToConfig();
}
});
name.getColumn().setText("Name");
name.getColumn().setWidth(200);
MenuManager menuMgr = new MenuManager();
menuMgr.add(new Action("Remove") {
@Override
public void run() {
ISelection s = viewer.getSelection();
if (s instanceof StructuredSelection) {
List<ConfigWrapper> w = new ArrayList<>();
@SuppressWarnings("rawtypes") Iterator iterator = ((StructuredSelection) s).iterator();
while (iterator.hasNext()) {
Object next = iterator.next();
if (next instanceof ConfigWrapper) {
w.add((ConfigWrapper) next);
}
}
if (!w.isEmpty()) {
getMappingBean().getProcessingConfigs().removeAll(w);
}
getMappingView().updateControls();
}
}
});
Menu menu = menuMgr.createContextMenu(viewer.getControl());
viewer.getTable().setMenu(menu);
List<ConfigWrapper> configs = getMappingBean().getProcessingConfigs();
viewer.setInput(configs.toArray());
setTableSize();
}
use of uk.ac.diamond.daq.mapping.api.ConfigWrapper in project gda-core by openGDA.
the class ProcessingSection method configureProcessingModel.
private ConfigWrapper configureProcessingModel() {
final List<IOperationSetupWizardPage> startPages = new ArrayList<>(2);
final AcquireDataWizardPage acquirePage = new AcquireDataWizardPage(getEclipseContext());
DawnConfigBean processingConfig = new DawnConfigBean();
ConfigWrapper w = new ConfigWrapper();
final ProcessingSelectionWizardPage selectionPage = new ProcessingSelectionWizardPage(getEclipseContext(), processingConfig, w, getMappingBean().getDetectorParameters());
startPages.add(selectionPage);
final Supplier<ProcessingSelectionWizardPage.ProcessingMode> selectedMode;
selectedMode = selectionPage::selectedMode;
startPages.add(acquirePage);
try {
IOperationModelWizard wizard = getEclipseContext().get(IOperationUIService.class).getWizard(null, startPages, (String) null, null);
OperationModelWizardDialog dialog = new OperationModelWizardDialog(getShell(), wizard);
dialog.setTitle("Setup Processing");
if (dialog.open() == Window.OK) {
if (ProcessingSelectionWizardPage.ProcessingMode.NEW_DAWN.equals(selectedMode.get())) {
try {
final Path processingFilePath = Paths.get(processingConfig.getProcessingFile());
Files.createDirectories(processingFilePath.getParent());
wizard.saveOutputFile(processingFilePath.toString());
} catch (Exception e) {
logger.error("Could not save template file!", e);
}
}
if (!ProcessingSelectionWizardPage.ProcessingMode.OTHER.equals(selectedMode.get())) {
IMarshallerService ms = getEclipseContext().get(IMarshallerService.class);
String json = ms.marshal(processingConfig, false);
try (BufferedWriter wr = new BufferedWriter(new FileWriter(w.getPathToConfig()))) {
wr.write(json);
} catch (Exception e) {
// TODO: dialog!
}
}
return w;
}
} catch (Exception e) {
logger.error("Could not open operation wizard", e);
}
return null;
}
use of uk.ac.diamond.daq.mapping.api.ConfigWrapper in project gda-core by openGDA.
the class MappingUISerializationTest method testSerializeMappingExperimentBean.
@Test
public void testSerializeMappingExperimentBean() throws Exception {
ScriptFiles scriptFiles = new ScriptFiles();
scriptFiles.setBeforeScanScript("/path/to/before.py");
scriptFiles.setAfterScanScript("/path/to/after.py");
Map<String, Object> beamlineConfiguration = new HashMap<>();
beamlineConfiguration.put("D7A", "Gap");
beamlineConfiguration.put("D7B", "gap");
beamlineConfiguration.put("kb_vfm_x", "7.0");
MandelbrotModel model = createMandelbrotModel();
DetectorModelWrapper mandelbrotWrapper = new DetectorModelWrapper("Mandelbrot Detector", model, true);
SimpleSampleMetadata sampleMetadata = new SimpleSampleMetadata();
sampleMetadata.setSampleName("SampleName");
sampleMetadata.setDescription("Description of sample");
IScanDefinition scanDefinition = createScanDefinition();
MappingExperimentBean mappingBean = new MappingExperimentBean();
mappingBean.setScriptFiles(scriptFiles);
mappingBean.setBeamlineConfiguration(beamlineConfiguration);
mappingBean.setDetectorParameters(Arrays.asList(mandelbrotWrapper));
mappingBean.setSampleMetadata(sampleMetadata);
mappingBean.setScanDefinition(scanDefinition);
ConfigWrapper w = new ConfigWrapper();
w.setAppName("dawn");
w.setPathToConfig("/path/to/config.json");
mappingBean.addProcessingRequest(w);
String json = service.marshal(mappingBean);
MappingExperimentBean newMappingBean = service.unmarshal(json, MappingExperimentBean.class);
assertEquals(mappingBean, newMappingBean);
}
use of uk.ac.diamond.daq.mapping.api.ConfigWrapper in project gda-core by openGDA.
the class ScanRequestConverterTest method testProcessingRequestIncludedCorrectly.
@Test
public void testProcessingRequestIncludedCorrectly() throws Exception {
ConfigWrapper wrapper = new ConfigWrapper();
String appName = "test";
String pathToConfig = "/path/to/config";
wrapper.setAppName(appName);
wrapper.setPathToConfig(pathToConfig);
wrapper.setActive(true);
mappingBean.addProcessingRequest(wrapper);
// Act - convert mapping bean to scan request
final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
// Assert
ProcessingRequest processingRequest = scanRequest.getProcessingRequest();
testProcessingRequest(appName, pathToConfig, processingRequest);
// Act again - merge scan request into new mapping bean
scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
// Assert again - check the new mapping bean is the same as the old one
ProcessingRequest r = new ProcessingRequest();
r.setRequest(newMappingBean.getProcessingRequest());
testProcessingRequest(appName, pathToConfig, r);
}
use of uk.ac.diamond.daq.mapping.api.ConfigWrapper in project gda-core by openGDA.
the class ScanRequestConverter method mergeProcessingRequest.
private void mergeProcessingRequest(ScanRequest scanRequest, IMappingExperimentBean mappingBean) {
List<ConfigWrapper> pc = mappingBean.getProcessingConfigs();
// disable all current
for (ConfigWrapper w : pc) {
w.setActive(false);
}
Map<String, Collection<Object>> pr = scanRequest.getProcessingRequest().getRequest();
List<ConfigWrapper> newWrappers = new ArrayList<>();
for (String k : pr.keySet()) {
Object object = pr.get(k);
if (object instanceof List<?>) {
for (Object o : (List<?>) object) {
if (!found(pc, k, o.toString())) {
ConfigWrapper w = new ConfigWrapper();
w.setAppName(k);
w.setPathToConfig(o.toString());
w.setActive(true);
newWrappers.add(w);
}
}
}
}
if (!newWrappers.isEmpty()) {
for (ConfigWrapper w : newWrappers) {
mappingBean.addProcessingRequest(w);
}
}
}
Aggregations