Search in sources :

Example 1 with Sampler

use of eu.esdihumboldt.hale.ui.service.instance.sample.Sampler in project hale by halestudio.

the class InstanceViewPreferencePage method createContents.

@Override
protected Control createContents(Composite parent) {
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    Composite page = new Composite(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(1).applyTo(page);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(page);
    // current sampler settings
    samplerSettings.clear();
    for (Entry<String, Sampler> entry : InstanceViewPreferences.SAMPLERS.entrySet()) {
        Value settings = ps.getConfigurationService().getProperty(InstanceViewPreferences.KEY_SETTINGS_PREFIX + entry.getKey());
        if (settings.isEmpty()) {
            settings = entry.getValue().getDefaultSettings();
        }
        samplerSettings.put(entry.getKey(), settings);
    }
    // sampler group
    samplerGroup = new Group(page, SWT.NONE);
    samplerGroup.setText("Instance sampling");
    GridDataFactory.fillDefaults().grab(true, false).applyTo(samplerGroup);
    GridLayoutFactory.swtDefaults().applyTo(samplerGroup);
    // enabled button
    enabled = new Button(samplerGroup, SWT.CHECK);
    enabled.setText("Use a sub-set of the imported source data as specified below:");
    enabled.setSelection(ps.getConfigurationService().getBoolean(InstanceViewPreferences.KEY_ENABLED, InstanceViewPreferences.ENABLED_DEFAULT));
    enabled.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            changed = true;
        }
    });
    // sampler selector
    samplers = new ComboViewer(samplerGroup);
    samplers.setContentProvider(ArrayContentProvider.getInstance());
    samplers.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof Sampler) {
                return ((Sampler) element).getDisplayName(Value.NULL);
            }
            return super.getText(element);
        }
    });
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false);
    samplers.setInput(InstanceViewPreferences.SAMPLERS.values());
    samplers.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection.isEmpty()) {
                updateEditor(null);
            } else {
                if (selection instanceof IStructuredSelection) {
                    updateEditor((Sampler) ((IStructuredSelection) selection).getFirstElement());
                }
            }
            changed = true;
        }
    });
    // restore the selected sampler
    String samplerId = ps.getConfigurationService().get(InstanceViewPreferences.KEY_SAMPLER, InstanceViewPreferences.SAMPLER_FIRST);
    Sampler selectedSampler = InstanceViewPreferences.SAMPLERS.get(samplerId);
    if (selectedSampler != null) {
        samplers.setSelection(new StructuredSelection(selectedSampler));
        changed = false;
    }
    // occurring values group
    Group ovGroup = new Group(page, SWT.NONE);
    ovGroup.setText("Occurring values");
    GridDataFactory.fillDefaults().grab(true, false).applyTo(ovGroup);
    GridLayoutFactory.swtDefaults().applyTo(ovGroup);
    // occurring values button
    occurringValuesComplete = new Button(ovGroup, SWT.CHECK);
    occurringValuesComplete.setText("Always use complete source data to determine occurring values (ignore sampling)");
    occurringValuesComplete.setSelection(ps.getConfigurationService().getBoolean(InstanceViewPreferences.KEY_OCCURRING_VALUES_USE_EXTERNAL, InstanceViewPreferences.OCCURRING_VALUES_EXTERNAL_DEFAULT));
    occurringValuesComplete.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ov_changed = true;
        }
    });
    return page;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Sampler(eu.esdihumboldt.hale.ui.service.instance.sample.Sampler) Value(eu.esdihumboldt.hale.common.core.io.Value) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 2 with Sampler

use of eu.esdihumboldt.hale.ui.service.instance.sample.Sampler in project hale by halestudio.

the class InstanceViewPreferencePage method performOk.

@Override
public boolean performOk() {
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    if (changed) {
        if (!MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Reload source data", "Applying the new settings will result in the source data being reloaded.")) {
            return false;
        }
        // save the enabled state
        ps.getConfigurationService().setBoolean(InstanceViewPreferences.KEY_ENABLED, enabled.getSelection());
        // store the current editor value in the map
        if (currentEditor != null) {
            // store value for current sampler
            Value setting = currentEditor.getValue();
            samplerSettings.put(InstanceViewPreferences.SAMPLERS.inverse().get(currentSampler), setting);
        }
        // store the map in the configuration
        for (Entry<String, Value> entry : samplerSettings.entrySet()) {
            ps.getConfigurationService().setProperty(InstanceViewPreferences.KEY_SETTINGS_PREFIX + entry.getKey(), entry.getValue());
        }
        // store the selected sampler
        Sampler selectedSampler = null;
        if (!samplers.getSelection().isEmpty()) {
            selectedSampler = (Sampler) ((IStructuredSelection) samplers.getSelection()).getFirstElement();
        }
        if (selectedSampler != null) {
            ps.getConfigurationService().set(InstanceViewPreferences.KEY_SAMPLER, InstanceViewPreferences.SAMPLERS.inverse().get(selectedSampler));
        }
        // reload the data
        ps.reloadSourceData();
        changed = false;
    }
    if (ov_changed) {
        ps.getConfigurationService().setBoolean(InstanceViewPreferences.KEY_OCCURRING_VALUES_USE_EXTERNAL, occurringValuesComplete.getSelection());
        ov_changed = false;
    }
    return true;
}
Also used : Sampler(eu.esdihumboldt.hale.ui.service.instance.sample.Sampler) Value(eu.esdihumboldt.hale.common.core.io.Value) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with Sampler

use of eu.esdihumboldt.hale.ui.service.instance.sample.Sampler in project hale by halestudio.

the class InstanceViewPreferencePage method performDefaults.

@Override
protected void performDefaults() {
    super.performDefaults();
    // update the enabled button with the default
    enabled.setSelection(InstanceViewPreferences.ENABLED_DEFAULT);
    // update the settings map with default values
    for (Entry<String, Sampler> entry : InstanceViewPreferences.SAMPLERS.entrySet()) {
        samplerSettings.put(entry.getKey(), entry.getValue().getDefaultSettings());
    }
    // update the current editor
    if (currentEditor != null) {
        // set the editor value
        currentEditor.setValue(samplerSettings.get(InstanceViewPreferences.SAMPLERS.inverse().get(currentSampler)));
    }
    // select the default sampler
    Sampler selectedSampler = InstanceViewPreferences.SAMPLERS.get(InstanceViewPreferences.SAMPLER_FIRST);
    if (selectedSampler != null) {
        samplers.setSelection(new StructuredSelection(selectedSampler));
    } else {
        samplers.setSelection(StructuredSelection.EMPTY);
    }
    changed = true;
    // update the occurring values button with the default
    occurringValuesComplete.setSelection(InstanceViewPreferences.OCCURRING_VALUES_EXTERNAL_DEFAULT);
    ov_changed = true;
}
Also used : Sampler(eu.esdihumboldt.hale.ui.service.instance.sample.Sampler) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

Sampler (eu.esdihumboldt.hale.ui.service.instance.sample.Sampler)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 Value (eu.esdihumboldt.hale.common.core.io.Value)2 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1