From c7da892cb23d50d4d85746c9a0b6b14bf570989d Mon Sep 17 00:00:00 2001 From: Adrian Dudau Date: Thu, 26 Jun 2014 13:23:09 +0200 Subject: initial commit for Enea Linux 4.0 Migrated from the internal git server on the daisy-enea branch Signed-off-by: Adrian Dudau --- .../yocto/bc/ui/wizards/FiniteStateWizardPage.java | 149 +++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java') diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java new file mode 100644 index 0000000..a83a389 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java @@ -0,0 +1,149 @@ +package org.yocto.bc.ui.wizards; +import java.util.Map; + +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; + +public abstract class FiniteStateWizardPage extends WizardPage { + protected Map model = null; + protected FiniteStateWizard wizard = null; + private static boolean previousState = false; + /** + * @param pageName + */ + protected FiniteStateWizardPage(String name, Map model) { + super(name); + this.model = model; + this.setPageComplete(false); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + public abstract void createControl(Composite parent); + + protected void setModelWizard() { + if (wizard == null) { + wizard = (FiniteStateWizard)FiniteStateWizardPage.this.getWizard(); + } + } + + /** + * Add page validation logic here. Returning true means that + * the page is complete and the user can go to the next page. + * + * @return + */ + protected abstract boolean validatePage(); + + /** + * This method should be implemented by ModelWizardPage classes. This method + * is called after the validatePage() returns successfully. + * Update the model with the contents of the controls on the page. + */ + protected abstract void updateModel(); + + /** + * Helper method to see if a field has some sort of text in it. + * @param value + * @return + */ + protected boolean hasContents(String value) { + if (value == null || value.length() == 0) { + return false; + } + + return true; + } + + /** + * This method is called right before a page is displayed. + * This occurs on user action (Next/Back buttons). + */ + public abstract void pageDisplay(); + + /** + * This method is called on the concrete WizardPage after the user has + * gone to the page after. + */ + public abstract void pageCleanup(); + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean) + */ + public void setVisible(boolean arg0) { + + if (!arg0 && previousState) { + pageCleanup(); + } else if (arg0 && !previousState) { + pageDisplay(); + } else if (arg0 && previousState) { + pageDisplay(); + } + + previousState = arg0; + + super.setVisible(arg0); + } + + public class ValidationListener implements SelectionListener, ModifyListener, Listener, ISelectionChangedListener { + + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) + */ + public void widgetSelected(SelectionEvent e) { + validate(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) + */ + public void widgetDefaultSelected(SelectionEvent e) { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent) + */ + public void modifyText(ModifyEvent e) { + validate(); + } + + public void validate() { + if (validatePage()) { + updateModel(); + setPageComplete(true); + return; + } + + setPageComplete(false); + } + + /* (non-Javadoc) + * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) + */ + public void handleEvent(Event event) { + + validate(); + } + + public void selectionChanged(SelectionChangedEvent event) { + validate(); + } + } +} -- cgit v1.2.3-54-g00ecf