blob: e19ff80f9e0aa3ec0191e3b3738b7d2033765bca [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.OperationCall;
import org.eclipse.apogy.core.invocator.ui.composites.OperationCallComposite;
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.TreeSelection;
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 OperationCallDetailsWizardPage extends WizardPage {
private final static String WIZARD_PAGE_ID = "org.eclipse.apogy.core.invocator.ui.wizards.OperationCallDetailsWizardPage";
private OperationCallComposite operationCallComposite;
private OperationCall operationCall;
private AdapterImpl adapter;
/**
* Constructor for the WizardPage.
*
* @param pageName
*/
public OperationCallDetailsWizardPage() {
super(WIZARD_PAGE_ID);
setTitle("Select the Operation");
setDescription("Select the operation to execute.");
}
public OperationCallDetailsWizardPage(OperationCall operationCall) {
this();
if (this.operationCall != null) {
this.operationCall.eAdapters().remove(getAdapter());
}
this.operationCall = operationCall;
this.operationCall.eAdapters().add(getAdapter());
}
private Adapter getAdapter() {
if (this.adapter == null) {
this.adapter = new AdapterImpl() {
@Override
public void notifyChanged(Notification msg) {
validate();
}
};
}
return this.adapter;
}
/**
* @see IDialogPage#createControl(Composite)
*/
@Override
public void createControl(Composite parent) {
this.operationCallComposite = new OperationCallComposite(parent, SWT.None, false) {
@Override
protected void newSelection(TreeSelection selection) {
validate();
}
};
this.operationCallComposite.setOperationCall(this.operationCall);
this.operationCallComposite.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
dispose();
}
});
setControl(this.operationCallComposite);
validate();
}
@Override
public void dispose() {
super.dispose();
if (this.operationCall != null) {
this.operationCall.eAdapters().remove(getAdapter());
}
}
/**
* This method is invoked to validate the content.
*/
protected void validate() {
String errorVariable = "";
String errorEOperation = "";
if (this.operationCall.getVariable() == null) {
errorVariable = " <variable>";
}
if (this.operationCall.getEOperation() == null) {
errorEOperation = " <operation>";
}
if (errorVariable != "" || errorEOperation != "") {
setErrorMessage(errorVariable + errorEOperation + " must be provided");
} else {
setErrorMessage(null);
}
setPageComplete(getErrorMessage() == null);
}
}