Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: edb4066ae702fde98bf4b7dfb1ff3e35c540c5ce (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package org.eclipse.cdt.managedbuilder.ui.wizards;

/**********************************************************************
 * Copyright (c) 2002,2003 Rational Software Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: 
 * IBM Rational Software - Initial API and implementation
***********************************************************************/

import java.util.ArrayList;
import java.util.Arrays;
import java.util.ListIterator;

import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.ITarget;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIPlugin;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;

public class CProjectPlatformPage extends WizardPage {
	/*
	 * Bookeeping variables
	 */
//	private CProjectWizard wizard;
	private ArrayList selectedConfigurations;
	protected ITarget selectedTarget;
	protected String[] targetNames;
	protected ArrayList targets;

	/*
	 * Dialog variables and string constants
	 */
	protected Combo platformSelection;
	protected CheckboxTableViewer tableViewer;
	private static final String PREFIX = "PlatformBlock"; //$NON-NLS-1$
	private static final String LABEL = PREFIX + ".label"; //$NON-NLS-1$
	private static final String TIP = PREFIX + ".tip"; //$NON-NLS-1$
	private static final String PLATFORM_TIP = TIP + ".platform"; //$NON-NLS-1$
	private static final String PLATFORM_LABEL = LABEL + ".platform"; //$NON-NLS-1$
	private static final String CONFIG_LABEL = LABEL + ".configs"; //$NON-NLS-1$

	/**
	 * Constructor.
	 * @param wizard
	 * @param pageName
	 */
	public CProjectPlatformPage(/*CProjectWizard wizard,*/ String pageName) {
		super(pageName);
		setPageComplete(false);
//		this.wizard = wizard;
		populateTargets();
		selectedTarget = null;
		selectedConfigurations = new ArrayList(0);
	}

	/**
	 * @see org.eclipse.jface.wizard.IWizardPage#canFlipToNextPage()
	 */
	public boolean canFlipToNextPage() {
		return validatePage();
	}

	/**
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
	public void createControl(Composite parent) {
		// Create the composite control for the tab
		Composite composite = ControlFactory.createComposite(parent, 6);

		// Create the platform selection label and combo widgets
		Label platformLabel = ControlFactory.createLabel(composite, ManagedBuilderUIPlugin.getResourceString(PLATFORM_LABEL));
		platformLabel.setLayoutData(new GridData());

		platformSelection =	ControlFactory.createSelectCombo(composite, targetNames, null);
		platformSelection.setToolTipText(ManagedBuilderUIPlugin.getResourceString(PLATFORM_TIP));
		platformSelection.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event e) {
				handleTargetSelection();
			}
		});
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 5;
		platformSelection.setLayoutData(gd);

		// Create a check box table of valid configurations
		Label configLabel = ControlFactory.createLabel(composite, ManagedBuilderUIPlugin.getResourceString(CONFIG_LABEL));
		configLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		Table table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.MULTI
								| SWT.SINGLE | SWT.H_SCROLL	| SWT.V_SCROLL);
		gd = new GridData(GridData.FILL_BOTH);
		gd.horizontalSpan = 6;
		table.setLayoutData(gd);
		table.setHeaderVisible(true);
		table.setLinesVisible(false);

		// Add a table layout to the table
		TableLayout tableLayout = new TableLayout();
		table.setHeaderVisible(false);
		table.setLayout(tableLayout);

		// Add the viewer
		tableViewer = new CheckboxTableViewer(table);
		tableViewer.setLabelProvider(new ConfigurationLabelProvider());
		tableViewer.setContentProvider(new ConfigurationContentProvider());
		tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
			public void selectionChanged(SelectionChangedEvent e) {
				// will default to false until a selection is made
				handleConfigurationSelectionChange();
			}
		});
		
		// Select the first target in the list
		handleTargetSelection();
		
		// Do the nasty
		setErrorMessage(null);
		setMessage(null);
		setControl(composite);
	}

	public IConfiguration[] getSelectedConfigurations() {
		return (IConfiguration[]) selectedConfigurations.toArray(new IConfiguration[selectedConfigurations.size()]);
	}

	/**
	 * Returns the name of the selected platform.
	 * 
	 * @return String containing platform name or <code>null</code> if an invalid selection
	 * has been made.
	 */
	public ITarget getSelectedTarget() {
		return selectedTarget;
	}

	private void handleConfigurationSelectionChange() {
		// Get the selections from the table viewer
		selectedConfigurations.clear();
		selectedConfigurations.addAll(Arrays.asList(tableViewer.getCheckedElements()));
	}

	/**
	 * Returns whether this page's controls currently all contain valid 
	 * values.
	 *
	 * @return <code>true</code> if all controls are valid, and
	 *   <code>false</code> if at least one is invalid
	 */
	protected void handleTargetSelection() {
		/*
		 * The index in the combo is the offset into the target list
		 */
		int index;
		if (platformSelection != null
			&& (index = platformSelection.getSelectionIndex()) != -1) {
			selectedTarget = (ITarget) targets.get(index);
		}
		populateConfigurations();
		setPageComplete(validatePage());
	}

	/**
	 * Populate the table viewer with the known configurations. 
	 * By default, all the configurations are selected.
	 */
	private void populateConfigurations() {
		// Make the root of the content provider the new target
		tableViewer.setInput(selectedTarget);
		tableViewer.setAllChecked(true);
		handleConfigurationSelectionChange();
	}

	private void populateTargetNames() {
		targetNames = new String[targets.size()];
		ListIterator iter = targets.listIterator();
		int index = 0;
		while (iter.hasNext()) {
			targetNames[index++] = ((ITarget) iter.next()).getName();
		}
	}

	private void populateTargets() {
		// Get a list of platforms defined by plugins
		ITarget[] allTargets = ManagedBuildManager.getDefinedTargets(null);
		targets = new ArrayList();
		// Add all of the concrete targets to the target list
		for (int index = 0; index < allTargets.length; ++index) {
			ITarget target = allTargets[index];
			if (!target.isAbstract() && !target.isTestTarget()) {
				targets.add(target);
			}
		}
		targets.trimToSize();
		populateTargetNames();
	}

	/**
	 * @return
	 */
	private boolean validatePage() {
		// TODO Auto-generated method stub
		return true;
	}
}

Back to the top