Search in sources :

Example 1 with IModelProvider

use of org.eclipse.scanning.api.IModelProvider in project gda-core by openGDA.

the class MultiStepEditorDialog method createDialogArea.

@Override
public Control createDialogArea(Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(comp);
    Button loadButton = new Button(comp, SWT.PUSH);
    loadButton.setImage(Activator.getImage("icons/folder-import.png"));
    loadButton.setToolTipText("Load multi-step model");
    Button saveButton = new Button(comp, SWT.PUSH);
    saveButton.setImage(Activator.getImage("icons/folder-export.png"));
    saveButton.setToolTipText("Save multi-step model");
    if (model == null) {
        model = new AxialMultiStepModel();
        model.setName(scannableName);
    }
    final IModelProvider<AxialMultiStepModel> modelProvider = new IModelProvider<AxialMultiStepModel>() {

        @Override
        public AxialMultiStepModel getModel() throws Exception {
            return model;
        }

        @Override
        public void updateModel(AxialMultiStepModel model) throws Exception {
        // updateModel is not needed for this implementation
        // Overriding because super throws IllegalArgumentException
        }
    };
    ed = new TypeEditor<>(modelProvider, comp, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(ed);
    try {
        ed.setModel(model);
    } catch (Exception e) {
        logger.error("Could not set model:", e);
    }
    ((MultiStepComposite) ed.getUI()).updateUnits(scannableName);
    // Disabling scannable name combo since dialog is tied to single scannable
    ((MultiStepComposite) ed.getUI()).setNameComboEnabled(false);
    // Load default values
    ((MultiStepComposite) ed.getUI()).getStepModels().setBeanConfigurator(getBeanConfigurator());
    // save & load logic
    ModelPersistAction<AxialMultiStepModel> load = new ModelPersistAction<>(ed, PersistType.LOAD);
    loadButton.addListener(SWT.Selection, event -> load.run());
    ModelPersistAction<AxialMultiStepModel> save = new ModelPersistAction<>(ed, PersistType.SAVE);
    saveButton.addListener(SWT.Selection, event -> save.run());
    return ed;
}
Also used : ModelPersistAction(org.eclipse.scanning.device.ui.model.ModelPersistAction) MultiStepComposite(org.eclipse.scanning.device.ui.composites.MultiStepComposite) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) MultiStepComposite(org.eclipse.scanning.device.ui.composites.MultiStepComposite) IModelProvider(org.eclipse.scanning.api.IModelProvider) AxialMultiStepModel(org.eclipse.scanning.api.points.models.AxialMultiStepModel)

Aggregations

IModelProvider (org.eclipse.scanning.api.IModelProvider)1 AxialMultiStepModel (org.eclipse.scanning.api.points.models.AxialMultiStepModel)1 MultiStepComposite (org.eclipse.scanning.device.ui.composites.MultiStepComposite)1 ModelPersistAction (org.eclipse.scanning.device.ui.model.ModelPersistAction)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1