Search in sources :

Example 1 with ConfigWrapper

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();
}
Also used : Action(org.eclipse.jface.action.Action) Composite(org.eclipse.swt.widgets.Composite) ConfigWrapper(uk.ac.diamond.daq.mapping.api.ConfigWrapper) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) MenuManager(org.eclipse.jface.action.MenuManager) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Menu(org.eclipse.swt.widgets.Menu) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 2 with ConfigWrapper

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;
}
Also used : Path(java.nio.file.Path) IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) ConfigWrapper(uk.ac.diamond.daq.mapping.api.ConfigWrapper) OperationModelWizardDialog(org.dawnsci.processing.ui.model.OperationModelWizardDialog) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) BufferedWriter(java.io.BufferedWriter) IOperationSetupWizardPage(org.dawnsci.processing.ui.api.IOperationSetupWizardPage) IOperationModelWizard(org.dawnsci.processing.ui.api.IOperationModelWizard) IOperationUIService(org.dawnsci.processing.ui.api.IOperationUIService)

Example 3 with ConfigWrapper

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);
}
Also used : MappingExperimentBean(uk.ac.diamond.daq.mapping.impl.MappingExperimentBean) ConfigWrapper(uk.ac.diamond.daq.mapping.api.ConfigWrapper) ScriptFiles(uk.ac.diamond.daq.mapping.impl.ScriptFiles) HashMap(java.util.HashMap) DetectorModelWrapper(uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper) MandelbrotModel(org.eclipse.scanning.example.detector.MandelbrotModel) SimpleSampleMetadata(uk.ac.diamond.daq.mapping.impl.SimpleSampleMetadata) IScanDefinition(uk.ac.diamond.daq.mapping.api.IScanDefinition) Test(org.junit.Test)

Example 4 with ConfigWrapper

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);
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ConfigWrapper(uk.ac.diamond.daq.mapping.api.ConfigWrapper) ProcessingRequest(org.eclipse.scanning.api.event.scan.ProcessingRequest) Test(org.junit.Test)

Example 5 with ConfigWrapper

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);
        }
    }
}
Also used : ConfigWrapper(uk.ac.diamond.daq.mapping.api.ConfigWrapper) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Collectors.toCollection(java.util.stream.Collectors.toCollection) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ConfigWrapper (uk.ac.diamond.daq.mapping.api.ConfigWrapper)7 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Test (org.junit.Test)2 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 Path (java.nio.file.Path)1 Iterator (java.util.Iterator)1 Collectors.toCollection (java.util.stream.Collectors.toCollection)1 IOperationModelWizard (org.dawnsci.processing.ui.api.IOperationModelWizard)1 IOperationSetupWizardPage (org.dawnsci.processing.ui.api.IOperationSetupWizardPage)1 IOperationUIService (org.dawnsci.processing.ui.api.IOperationUIService)1 OperationModelWizardDialog (org.dawnsci.processing.ui.model.OperationModelWizardDialog)1 IMarshallerService (org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService)1 Action (org.eclipse.jface.action.Action)1 MenuManager (org.eclipse.jface.action.MenuManager)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1