aboutsummaryrefslogtreecommitdiffstats
path: root/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/FiniteStateWizardPage.java
blob: 4a26d1336442b33cb6524bba5b043ff29abe1e6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package org.openembedded.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 <code>true</code> 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 <code>validatePage()</code> 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();
        }
    }
}