blob: 967ef38d94b3ad4baaa97f080f67279fb65395b3 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pierre Allard - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*******************************************************************************/
package org.eclipse.apogy.core.environment.earth.atmosphere.ui.preferences;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.apogy.core.environment.earth.atmosphere.ui.Activator;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
public class ApogyEarthAtmosphereUIPreferencesPage extends PreferencePage implements IWorkbenchPreferencePage {
private StringFieldEditor wmsUrlEditor;
private StringFieldEditor wmsLayersEditor;
private BooleanFieldEditor earthSurfaceWorksiteAxisVisibleEditor;
private StringFieldEditor earthSurfaceWorksiteAxisLengthEditor;
private BooleanFieldEditor earthSurfaceWorksiteAzimuthVisibleEditor;
private BooleanFieldEditor earthSurfaceWorksiteAzimuthLinesVisibleEditor;
private BooleanFieldEditor earthSurfaceWorksiteElevationLinesVisibleEditor;
private BooleanFieldEditor earthSurfaceWorksitePlaneVisibleEditor;
private StringFieldEditor earthSurfaceWorksitePlaneGridSizeEditor;
private StringFieldEditor earthSurfaceWorksitePlaneSizeEditor;
private final List<FieldEditor> editors = new ArrayList<FieldEditor>();
/**
* Create the preference page.
*/
public ApogyEarthAtmosphereUIPreferencesPage() {
}
/**
* Create contents of the preference page.
*
* @param parent
*/
@Override
public Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
container.setLayout(new GridLayout(1, true));
Group grpStarField = new Group(container, SWT.NONE);
grpStarField.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
grpStarField.setLayout(new GridLayout(1, true));
grpStarField.setText("Web Map Server (WMS) Settings");
this.wmsUrlEditor = createStringFieldEditor(grpStarField,
ApogyEarthAtmosphereUIPreferencesConstants.DEFAULT_WMS_URL_ID, "WMS URL : ");
this.editors.add(this.wmsUrlEditor);
this.wmsLayersEditor = createStringFieldEditor(grpStarField,
ApogyEarthAtmosphereUIPreferencesConstants.DEFAULT_WMS_LAYERS_ID, "Layers (comma separated) : ");
this.editors.add(this.wmsLayersEditor);
Group grpAxis = new Group(container, SWT.NONE);
grpAxis.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
grpAxis.setLayout(new GridLayout(1, true));
grpAxis.setText("Axis");
this.earthSurfaceWorksiteAxisVisibleEditor = createBooleanFieldEditor(grpAxis,
ApogyEarthAtmosphereUIPreferencesConstants.DEFAULT_ATMOSPHERE_WORKSITE_AXIS_VISIBLE_ID, "Axis Visible");
this.editors.add(this.earthSurfaceWorksiteAxisVisibleEditor);
this.earthSurfaceWorksiteAxisLengthEditor = createStringFieldEditor(grpAxis,
ApogyEarthAtmosphereUIPreferencesConstants.DEFAULT_ATMOSPHERE_WORKSITE_AXIS_LENGTH_ID,
"Axis Length (m)");
this.editors.add(this.earthSurfaceWorksiteAxisLengthEditor);
Group grpAzimuth = new Group(container, SWT.NONE);
grpAzimuth.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
grpAzimuth.setLayout(new GridLayout(1, true));
grpAzimuth.setText("Azimuth Displays");
this.earthSurfaceWorksiteAzimuthVisibleEditor = createBooleanFieldEditor(grpAzimuth,
ApogyEarthAtmosphereUIPreferencesConstants.DEFAULT_ATMOSPHERE_WORKSITE_AZIMUTH_VISIBLE_ID,
"Azimuth Visible");
this.editors.add(this.earthSurfaceWorksiteAzimuthVisibleEditor);
this.earthSurfaceWorksiteAzimuthLinesVisibleEditor = createBooleanFieldEditor(grpAzimuth,
ApogyEarthAtmosphereUIPreferencesConstants.DEFAULT_ATMOSPHERE_WORKSITE_AZIMUTH_LINES_VISIBLE_ID,
"Azimuth Lines Visible");
this.editors.add(this.earthSurfaceWorksiteAzimuthLinesVisibleEditor);
Group grpElevation = new Group(container, SWT.NONE);
grpElevation.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
grpElevation.setLayout(new GridLayout(1, true));
grpElevation.setText("Elevation Displays");
this.earthSurfaceWorksiteElevationLinesVisibleEditor = createBooleanFieldEditor(grpElevation,
ApogyEarthAtmosphereUIPreferencesConstants.DEFAULT_ATMOSPHERE_WORKSITE_ELEVATION_LINES_VISIBLE_ID,
"Elevation Lines Visible");
this.editors.add(this.earthSurfaceWorksiteElevationLinesVisibleEditor);
Group grpPlane = new Group(container, SWT.NONE);
grpPlane.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
grpPlane.setLayout(new GridLayout(1, true));
grpPlane.setText("Plane");
this.earthSurfaceWorksitePlaneVisibleEditor = createBooleanFieldEditor(grpPlane,
ApogyEarthAtmosphereUIPreferencesConstants.DEFAULT_ATMOSPHERE_WORKSITE_PLANE_VISIBLE_ID,
"Plane Visible");
this.editors.add(this.earthSurfaceWorksitePlaneVisibleEditor);
this.earthSurfaceWorksitePlaneSizeEditor = createStringFieldEditor(grpPlane,
ApogyEarthAtmosphereUIPreferencesConstants.DEFAULT_ATMOSPHERE_WORKSITE_PLANE_SIZE_ID, "Plane Size");
this.editors.add(this.earthSurfaceWorksitePlaneSizeEditor);
this.earthSurfaceWorksitePlaneGridSizeEditor = createStringFieldEditor(grpPlane,
ApogyEarthAtmosphereUIPreferencesConstants.DEFAULT_ATMOSPHERE_WORKSITE_PLANE_GRID_SIZE_ID, "Grid Size");
this.editors.add(this.earthSurfaceWorksitePlaneGridSizeEditor);
return container;
}
/**
* Initialize the preference page.
*/
@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
}
@Override
public boolean performOk() {
storePreferences();
return super.performOk();
}
@Override
protected void performApply() {
storePreferences();
super.performApply();
}
@Override
protected void performDefaults() {
for (FieldEditor editor : this.editors) {
editor.loadDefault();
}
super.performDefaults();
}
@Override
public void dispose() {
this.editors.clear();
super.dispose();
}
private void storePreferences() {
for (FieldEditor editor : this.editors) {
editor.store();
}
}
private StringFieldEditor createStringFieldEditor(final Composite container, final String preferenceID,
final String preferenceLabel) {
Composite editorContainer = new Composite(container, SWT.NULL);
editorContainer.setLayout(new GridLayout(1, true));
editorContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
StringFieldEditor editor = new StringFieldEditor(preferenceID, preferenceLabel, 100, editorContainer);
// Set the editor up to use this page
editor.setPreferenceStore(getPreferenceStore());
editor.load();
return editor;
}
private BooleanFieldEditor createBooleanFieldEditor(final Composite container, final String preferenceID,
final String preferenceLabel) {
BooleanFieldEditor editor = new BooleanFieldEditor(preferenceID, preferenceLabel, container);
// Set the editor up to use this page
editor.setPreferenceStore(getPreferenceStore());
editor.load();
return editor;
}
}