Skip to main content
summaryrefslogtreecommitdiffstats
blob: e917466ba0f8b3aea367c266a7d26d66711fc9f0 (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
139
140
141
142
143
144
145
146
147
/*******************************************************************************
 * Copyright (c) 2004, 2005 Sybase, Inc. 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: Sybase,
 * Inc. - initial API and implementation
 ******************************************************************************/
package org.eclipse.jst.jsf.facesconfig.ui.wizard;

import org.eclipse.jface.viewers.ColumnPixelData;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.jst.jsf.common.ui.internal.guiutils.SWTUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

/**
 * Common wizard page used to summarize information entered in previous pages.
 * 
 * @author plevin
 * @version 1.0
 */
public class SummaryPage extends WizardPage
{
	private static final String WIZARD_SUMMARY_PAGE = "WizardSummaryPage"; //$NON-NLS-1$

	/** The source of the summary items */
	private ISummaryDataSource source;

	/** The table control that displays the summary items */
	private Table table;

	/**
	 * This Constructor creates the summary page
	 */
	public SummaryPage()
	{
		super( WIZARD_SUMMARY_PAGE );
		setTitle( WizardMessages.WizardSummaryPage_Title_WizardSummary );
		setDescription( WizardMessages.WizardSummaryPage_Summary_SummaryDesc );
	}

	/**
	 * This Constructor initializes the data source.
	 * 
	 * @param source -
	 *            Summary data source
	 */
	public SummaryPage( ISummaryDataSource source )
	{
		this();
		this.source = source;
	}

	/**
	 * Determines if the wizard can enable the Next button
	 * 
	 * @return boolean - the state of the Next button
	 */
	public boolean canFlipToNextPage()
	{
		return false;
	}

	/**
	 * Creates the page controls
	 * 
	 * @param parent -
	 *            the wizard composite
	 */
	public void createControl( Composite parent )
	{

		Composite composite = SWTUtils.createComposite( parent, 1 );

		table = new Table( composite, SWT.BORDER );
		table.setLayoutData( new GridData( GridData.FILL_BOTH ) );
		table.setHeaderVisible( true );
		table.setLinesVisible( true );

		TableLayout layout = new TableLayout();
		table.setLayout( layout );

		layout.addColumnData( new ColumnPixelData( 163 ) );
		layout.addColumnData( new ColumnPixelData( 350 ) );

		TableColumn keyCol = new TableColumn( table, SWT.NONE );
		keyCol.setText( WizardMessages.WizardSummaryPage_Label_Field );

		TableColumn valueCol = new TableColumn( table, SWT.NONE );
		valueCol
				.setText( WizardMessages.WizardSummaryPage_Label_Value );

		setControl( composite );
		setPageComplete( true );
	}

	/**
	 * Populates the table with summary information.
	 */
	public void loadSummaryData()
	{
		if ( source == null )
		{
			return;
		}
		Object[] data = source.getSummaryData().toArray();
		table.removeAll();
		for ( int i = 0; i < data.length; i++ )
		{
			TableItem item = new TableItem( table, SWT.NONE );
			item.setText( (String[]) data[i] );
		}
		return;
	}

	/**
	 * Sets summary page data source.
	 * 
	 * @param s -
	 *            Data source.
	 */
	public void setSummaryDataSource( ISummaryDataSource s )
	{
		source = s;
	}

	/**
	 * Populates the table with summary items when the page becomes visible.
	 * 
	 * @param visible -
	 *            the visible state of the page
	 */
	public void setVisible( boolean visible )
	{
		super.setVisible( visible );

		if ( visible == true )
		{
			loadSummaryData();
		}
	}
}

Back to the top