blob: e742727aee7289d043875c0c4e5ce62b73176a3c [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
* Regent L'Archeveque
* SPDX-License-Identifier: EPL-1.0
*******************************************************************************/
package org.eclipse.apogy.addons.sensors.fov.ui.wizards;
import org.eclipse.apogy.addons.sensors.fov.DistanceRange;
import org.eclipse.apogy.addons.sensors.fov.ui.composites.DistanceRangeComposite;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
public class DistanceRangeWizardPage extends WizardPage {
private final static String WIZARD_PAGE_ID = "org.eclipse.apogy.addons.sensors.fov.ui.wizards.DistanceRangeWizardPage";
private final DistanceRange distanceRange;
private DistanceRangeComposite distanceRangeComposite;
private Adapter adapter;
public DistanceRangeWizardPage(DistanceRange distanceRange) {
super(WIZARD_PAGE_ID);
this.distanceRange = distanceRange;
setTitle("Distance Range");
setDescription("Sets the distance range minium and maximum distances.");
}
@Override
public void createControl(Composite parent) {
Composite top = new Composite(parent, SWT.None);
top.setLayout(new GridLayout(1, false));
this.distanceRangeComposite = new DistanceRangeComposite(top, SWT.NONE);
this.distanceRangeComposite.setDistanceRange(this.distanceRange);
setControl(top);
if (this.distanceRange != null)
this.distanceRange.eAdapters().add(getAdapter());
top.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent arg0) {
if (DistanceRangeWizardPage.this.distanceRange != null)
DistanceRangeWizardPage.this.distanceRange.eAdapters().remove(getAdapter());
}
});
validate();
}
protected void validate() {
setErrorMessage(null);
if (this.distanceRange.getMinimumDistance() < 0) {
setErrorMessage("The specified minimum range should equal or greater than zero !");
}
if (this.distanceRange.getMaximumDistance() < 0) {
setErrorMessage("The specified maximum range should equal or greater than zero !");
}
if (this.distanceRange.getMaximumDistance() <= this.distanceRange.getMinimumDistance()) {
setErrorMessage("The specified maximum range should equal or greater than the minimum range !");
}
setPageComplete(getErrorMessage() == null);
}
protected Adapter getAdapter() {
if (this.adapter == null) {
this.adapter = new AdapterImpl() {
@Override
public void notifyChanged(Notification msg) {
if (msg.getNotifier() instanceof DistanceRange) {
validate();
}
}
};
}
return this.adapter;
}
}