blob: b14042a6fce281bb82e3b96a28aba3c36ce82735 [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,
* Regent L'Archeveque,
* Olivier L. Larouche - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.core.invocator.ui.wizards;
import org.eclipse.apogy.core.invocator.ApogyCoreInvocatorPackage;
import org.eclipse.apogy.core.invocator.VariableFeatureReference;
import org.eclipse.apogy.core.invocator.VariablesList;
import org.eclipse.apogy.core.invocator.ui.composites.VariableFeatureReferenceComposite;
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.dialogs.IDialogPage;
import org.eclipse.jface.viewers.ISelection;
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.widgets.Composite;
public class VariableFeatureReferenceWizardPage extends WizardPage {
private final static String WIZARD_PAGE_ID = "org.eclipse.apogy.core.invocator.ui.wizards.VariableFeatureReferenceWizardPage";
private VariableFeatureReferenceComposite variableFeatureReferenceComposite;
protected VariableFeatureReference variableFeatureReference;
private VariablesList variablesList;
protected AdapterImpl adapter;
/**
* Constructor for the WizardPage.
*
* @param pageName
*/
public VariableFeatureReferenceWizardPage() {
super(WIZARD_PAGE_ID);
setTitle("Variable / Type / Feature Selection");
setDescription("Select the Variable/Type/Feature.");
}
public VariableFeatureReferenceWizardPage(VariablesList variablesList,
VariableFeatureReference variableFeatureReference) {
this();
if (this.variableFeatureReference != null) {
this.variableFeatureReference.eAdapters().remove(getAdapter());
}
this.variableFeatureReference = variableFeatureReference;
this.variablesList = variablesList;
variableFeatureReference.eAdapters().add(getAdapter());
}
protected Adapter getAdapter() {
if (this.adapter == null) {
this.adapter = new AdapterImpl() {
@Override
public void notifyChanged(Notification msg) {
if (msg.getFeatureID(
VariableFeatureReference.class) == ApogyCoreInvocatorPackage.VARIABLE_FEATURE_REFERENCE__VARIABLE
|| msg.getFeatureID(
VariableFeatureReference.class) == ApogyCoreInvocatorPackage.VARIABLE_FEATURE_REFERENCE__FEATURE_ROOT
|| msg.getFeatureID(
VariableFeatureReference.class) == ApogyCoreInvocatorPackage.VARIABLE_FEATURE_REFERENCE__TYPE_MEMBER_REFERENCE_LIST_ELEMENT) {
validate();
}
}
};
}
return this.adapter;
}
/**
* @see IDialogPage#createControl(Composite)
*/
@Override
public void createControl(Composite parent) {
this.variableFeatureReferenceComposite = new VariableFeatureReferenceComposite(parent, SWT.None) {
@Override
protected void newSelection(ISelection selection) {
resetOperationCall();
}
};
this.variableFeatureReferenceComposite.set(this.variablesList, this.variableFeatureReference);
this.variableFeatureReferenceComposite.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (VariableFeatureReferenceWizardPage.this.variableFeatureReference != null) {
VariableFeatureReferenceWizardPage.this.variableFeatureReference.eAdapters().remove(getAdapter());
}
}
});
setControl(this.variableFeatureReferenceComposite);
validate();
}
protected void resetOperationCall() {
}
/**
* This method is invoked to validate the content.
*/
protected void validate() {
String errorStr = null;
if (this.variableFeatureReference.getVariable() == null) {
errorStr = "Select the variable.";
}
setErrorMessage(errorStr);
setPageComplete(errorStr == null);
}
}