Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 40baa6121892759e632f7aef54d0c692e6a19bd8 (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2007 Symbian Software Limited and others.
 * 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:
 * Bala Torati (Symbian) - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.ui.templateengine;

import java.util.Iterator;
import java.util.Map;

import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardNode;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;

import org.eclipse.cdt.ui.templateengine.pages.UIWizardPage;


/**
 * Wizard Node 
 */
class WizardNode implements IWizardNode {
	private IWizard wizard;
	private Template template;
	private TemplateListSelectionPage parentPage;

	/**
	 * Constructor.
	 * @param parentPage
	 * @param template
	 */
	public WizardNode(TemplateListSelectionPage parentPage, Template template) {
		this.parentPage = parentPage;
		this.template = template;
	}
	
	public void dispose() {
		if (wizard != null) {
			wizard.dispose();
			wizard = null;
		}
	}
	
	/**
	 * Returns the Template
	 */
	public Template getTemplate() {
		return template;
	}

	public Point getExtent() {
		return new Point(-1, -1);
	}
	
	/**
	 * Returns the Wizard.
	 */
	public IWizard getWizard() {
		if (wizard != null) {
			return wizard;
		}
		wizard = new Wizard() {
			{
				setWindowTitle(template.getLabel());
			}
			
			private boolean finishPressed;
			
			public void addPages() {
				IWizardPage[] wpages = null;
				try {
					wpages = parentPage.getPagesAfterTemplateSelection();
				} catch (Exception e) {
				}
				for(int i=0; i<wpages.length; i++) {
					addPage(wpages[i]);
				}
				
				Map/*<String, UIWizardPage>*/ pages = template.getUIPages();
				for(Iterator i = template.getPagesOrderVector().iterator(); i.hasNext(); ){
					String id = (String) i.next();
					addPage((UIWizardPage) pages.get(id));
				}

				wpages = parentPage.getPagesAfterTemplatePages();
				for(int i=0; i<wpages.length; i++) {
					addPage(wpages[i]);
				}
			}
			
			public boolean performFinish() {
				Map/*<String, String>*/ valueStore = template.getValueStore();
				finishPressed = true;
				getContainer().updateButtons();
				IWizardPage[] wpages = getPages();
				for(int i=0; i<wpages.length; i++) {
					IWizardPage page = wpages[i];
					if (page instanceof UIWizardPage)
						valueStore.putAll(((UIWizardPage) page).getPageData());
				}
				template.getValueStore().putAll(parentPage.getDataInPreviousPages());
				return true;
			}
			
			public boolean canFinish(){
				return !finishPressed && super.canFinish();
			}

			public void createPageControls(Composite pageContainer) {
				super.createPageControls(pageContainer);
				parentPage.adjustTemplateValues(template);
				IWizardPage[] wpages = getPages();
				for(int i=0; i<wpages.length; i++) {
					IWizardPage page = wpages[i];
					if (page instanceof UIWizardPage)
					((UIWizardPage) page).getComposite().getUIElement().setValues(template.getValueStore());
				}
			}

			public Image getDefaultPageImage() {
				return parentPage.getImage();
			}
		};
		return wizard;
	}

	public boolean isContentCreated() {
		return wizard != null;
	}
}

Back to the top