/* * � Copyright IBM Corp. 2015 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. See the License for the specific language governing * permissions and limitations under the License. */ package com.ibm.xsp.extlib.designer.bluemix.wizard; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.widgets.Composite; import com.ibm.commons.util.StringUtil; /** * @author Gary Marjoram * */ public abstract class AbstractBluemixWizardPage extends WizardPage { protected AbstractBluemixWizard _wiz; protected boolean _firstDisplay = true; protected boolean _hasChanged = false; protected boolean _alwaysShowError = false; protected AbstractBluemixWizardPage(String pageName) { super(pageName); } @Override public void createControl(Composite parent) { _wiz = (AbstractBluemixWizard) getWizard(); setTitle(getPageTitle()); setMessage(StringUtil.format(getPageMsg(), "\n"), IMessageProvider.INFORMATION); // $NON-NLS-1$ setImageDescriptor(_wiz._image); setPageComplete(false); } @Override public void setVisible(boolean visible) { if (visible) { if (_wiz.advancing && _firstDisplay) { initialisePageState(); } validatePage(); _firstDisplay = false; _hasChanged = false; } super.setVisible(visible); } protected void showError(String msg) { if (StringUtil.isEmpty(msg)) { setErrorMessage(null); setPageComplete(true); } else { setErrorMessage(_firstDisplay && (!_alwaysShowError) ? null : msg); setPageComplete(false); } } protected void showWarning(String msg) { if (StringUtil.isEmpty(msg)) { setMessage(StringUtil.format(getPageMsg(), "\n"), IMessageProvider.INFORMATION); // $NON-NLS-1$ } else { setMessage(msg, IMessageProvider.WARNING); } } protected void initialisePageState() { } protected void savePageState() { } protected void validatePage() { showError(null); } protected abstract String getPageTitle(); protected abstract String getPageMsg(); }