private void saveState() { // merge all tracks into one tour final boolean isMergeIntoOneTour = _chkOneTour.getSelection(); _importState.put(RawDataView.STATE_IS_MERGE_TRACKS, isMergeIntoOneTour); _rawDataMgr.setMergeTracks(isMergeIntoOneTour); // convert waypoints final boolean isConvertWayPoints = _chkConvertWayPoints.getSelection(); _importState.put(RawDataView.STATE_IS_CONVERT_WAYPOINTS, isConvertWayPoints); _rawDataMgr.setState_ConvertWayPoints(isConvertWayPoints); // relative/absolute distance _prefStore.setValue( IPreferences.GPX_IS_RELATIVE_DISTANCE_VALUE, _rdoDistanceRelative.getSelection()); }
public class PrefPageImportGPX extends PreferencePage implements IWorkbenchPreferencePage { public static final String ID = "net.tourbook.device.PrefPageGPX"; // $NON-NLS-1$ private IPreferenceStore _prefStore = Activator.getDefault().getPreferenceStore(); private final IDialogSettings _importState = TourbookPlugin.getState(RawDataView.ID); private RawDataManager _rawDataMgr = RawDataManager.getInstance(); private PixelConverter _pc; /* * UI controls */ private Button _chkConvertWayPoints; private Button _chkOneTour; private Button _rdoDistanceRelative; private Button _rdoDistanceAbsolute; @Override protected Control createContents(final Composite parent) { initUI(parent); final Composite ui = createUI(parent); restoreState(); return ui; } private Composite createUI(final Composite parent) { final Composite container = new Composite(parent, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).applyTo(container); GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container); { createUI_10_Options(container); createUI_20_Distance(container); } return container; } private void createUI_10_Options(final Composite parent) { final Composite container = new Composite(parent, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).applyTo(container); GridLayoutFactory.fillDefaults().numColumns(2).applyTo(container); { // checkbox: convert waypoints { _chkConvertWayPoints = new Button(container, SWT.CHECK); GridDataFactory.fillDefaults().span(2, 1).applyTo(_chkConvertWayPoints); _chkConvertWayPoints.setText(Messages.PrefPage_GPX_Checkbox_ConvertWayPoints); _chkConvertWayPoints.setToolTipText( Messages.PrefPage_GPX_Checkbox_ConvertWayPoints_Tooltip); } // checkbox: merge all tracks into one tour { _chkOneTour = new Button(container, SWT.CHECK); GridDataFactory.fillDefaults().span(2, 1).applyTo(_chkOneTour); _chkOneTour.setText(Messages.PrefPage_GPX_Checkbox_OneTour); } } } private void createUI_20_Distance(final Composite parent) { final Group group = new Group(parent, SWT.NONE); GridDataFactory.fillDefaults() // .grab(true, false) .indent(0, _pc.convertVerticalDLUsToPixels(4)) .applyTo(group); GridLayoutFactory.swtDefaults().numColumns(2).applyTo(group); group.setText(Messages.PrefPage_GPX_Group_DistanceValues); { // label { final Label label = new Label(group, SWT.NONE); GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING).applyTo(label); label.setText(Messages.PrefPage_GPX_Label_DistanceValues); } // radio { final Composite container = new Composite(group, SWT.NONE); GridDataFactory.fillDefaults() // .indent(_pc.convertWidthInCharsToPixels(3), 0) .applyTo(container); GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container); { _rdoDistanceAbsolute = new Button(container, SWT.RADIO); _rdoDistanceAbsolute.setText(Messages.PrefPage_GPX_Radio_DistanceAbsolute); _rdoDistanceAbsolute.setToolTipText(Messages.PrefPage_GPX_Radio_DistanceAbsolute_Tooltip); _rdoDistanceRelative = new Button(container, SWT.RADIO); _rdoDistanceRelative.setText(Messages.PrefPage_GPX_Radio_DistanceRelative); _rdoDistanceRelative.setToolTipText(Messages.PrefPage_GPX_Radio_DistanceRelative_Tooltip); } } } } @Override public void init(final IWorkbench workbench) {} private void initUI(final Composite parent) { _pc = new PixelConverter(parent); } @Override protected void performDefaults() { // merge all tracks into one tour _chkOneTour.setSelection(RawDataView.STATE_IS_MERGE_TRACKS_DEFAULT); // convert waypoints _chkConvertWayPoints.setSelection(RawDataView.STATE_IS_CONVERT_WAYPOINTS_DEFAULT); // relative/absolute distance final boolean isRelativeDistance = _prefStore.getDefaultBoolean(IPreferences.GPX_IS_RELATIVE_DISTANCE_VALUE); _rdoDistanceAbsolute.setSelection(isRelativeDistance == false); _rdoDistanceRelative.setSelection(isRelativeDistance); super.performDefaults(); } @Override public boolean performOk() { final boolean isOK = super.performOk(); if (isOK) { saveState(); } return isOK; } private void restoreState() { // merge all tracks into one tour final boolean isMergeIntoOneTour = Util.getStateBoolean( _importState, RawDataView.STATE_IS_MERGE_TRACKS, RawDataView.STATE_IS_MERGE_TRACKS_DEFAULT); _chkOneTour.setSelection(isMergeIntoOneTour); // convert waypoints final boolean isConvertWayPoints = Util.getStateBoolean( _importState, RawDataView.STATE_IS_CONVERT_WAYPOINTS, RawDataView.STATE_IS_CONVERT_WAYPOINTS_DEFAULT); _chkConvertWayPoints.setSelection(isConvertWayPoints); // relative/absolute distance final boolean isRelativeDistance = _prefStore.getBoolean(IPreferences.GPX_IS_RELATIVE_DISTANCE_VALUE); _rdoDistanceAbsolute.setSelection(isRelativeDistance == false); _rdoDistanceRelative.setSelection(isRelativeDistance); } private void saveState() { // merge all tracks into one tour final boolean isMergeIntoOneTour = _chkOneTour.getSelection(); _importState.put(RawDataView.STATE_IS_MERGE_TRACKS, isMergeIntoOneTour); _rawDataMgr.setMergeTracks(isMergeIntoOneTour); // convert waypoints final boolean isConvertWayPoints = _chkConvertWayPoints.getSelection(); _importState.put(RawDataView.STATE_IS_CONVERT_WAYPOINTS, isConvertWayPoints); _rawDataMgr.setState_ConvertWayPoints(isConvertWayPoints); // relative/absolute distance _prefStore.setValue( IPreferences.GPX_IS_RELATIVE_DISTANCE_VALUE, _rdoDistanceRelative.getSelection()); } }