| /******************************************************************************* |
| * 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, |
| * Sebastien Gemme |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| *******************************************************************************/ |
| package org.eclipse.apogy.common.topology.ui.wizards; |
| |
| import org.eclipse.apogy.common.topology.AbstractViewPoint; |
| import org.eclipse.apogy.common.topology.ui.composites.AbstractViewPointComposite; |
| 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.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Composite; |
| |
| public class AbstractViewPointWizardPage extends WizardPage { |
| private final static String WIZARD_PAGE_ID = "org.eclipse.apogy.common.topology.ui.wizards.AbstractViewPointWizardPage"; |
| |
| private final AbstractViewPoint abstractViewPoint; |
| private Adapter adapter; |
| private AbstractViewPointComposite abstractViewPointComposite; |
| |
| public AbstractViewPointWizardPage(AbstractViewPoint abstractViewPoint) { |
| super(WIZARD_PAGE_ID); |
| this.abstractViewPoint = abstractViewPoint; |
| |
| setTitle("View Point"); |
| setDescription("Sets the View Point name and pose."); |
| |
| if (abstractViewPoint != null) |
| abstractViewPoint.eAdapters().add(getAdapter()); |
| |
| validate(); |
| } |
| |
| @Override |
| public void createControl(Composite parent) { |
| Composite top = new Composite(parent, SWT.None); |
| top.setLayout(new GridLayout(1, false)); |
| |
| this.abstractViewPointComposite = new AbstractViewPointComposite(top, SWT.NONE, this.abstractViewPoint); |
| this.abstractViewPointComposite.setAbstractViewPoint(this.abstractViewPoint); |
| this.abstractViewPointComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| |
| setControl(top); |
| |
| top.addDisposeListener(new DisposeListener() { |
| |
| @Override |
| public void widgetDisposed(DisposeEvent e) { |
| if (AbstractViewPointWizardPage.this.abstractViewPointComposite != null |
| && !AbstractViewPointWizardPage.this.abstractViewPointComposite.isDisposed()) |
| AbstractViewPointWizardPage.this.abstractViewPointComposite.dispose(); |
| if (AbstractViewPointWizardPage.this.abstractViewPoint != null) |
| AbstractViewPointWizardPage.this.abstractViewPoint.eAdapters().remove(getAdapter()); |
| |
| } |
| }); |
| } |
| |
| protected void validate() { |
| setErrorMessage(null); |
| |
| if (this.abstractViewPoint.getName() == null) { |
| setErrorMessage("Name is not set !"); |
| } |
| |
| setPageComplete(getErrorMessage() == null); |
| } |
| |
| private Adapter getAdapter() { |
| if (this.adapter == null) { |
| this.adapter = new AdapterImpl() { |
| @Override |
| public void notifyChanged(Notification msg) { |
| validate(); |
| } |
| }; |
| } |
| |
| return this.adapter; |
| } |
| } |