Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5d3ff735f0383e937b9ae049c0314d427608c97d (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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*******************************************************************************
 * Copyright (c) 2000, 2010 QNX Software Systems 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:
 *     QNX Software Systems - Initial API and implementation
 *     Intel corporation    - customization for New Project model.
 *******************************************************************************/
package org.eclipse.cdt.managedbuilder.ui.wizards;


import java.util.ArrayList;
import java.util.List;

import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.cdt.ui.newui.AbstractPage;
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.cdt.ui.newui.PageLayout;
import org.eclipse.cdt.ui.wizards.CDTMainWizardPage;
import org.eclipse.cdt.ui.wizards.CWizardHandler;
import org.eclipse.cdt.ui.wizards.EntryDescriptor;
import org.eclipse.cdt.ui.wizards.IWizardItemsListListener;
import org.eclipse.cdt.ui.wizards.conversion.ConvertProjectWizardPage;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;

/**
 * @noextend This class is not intended to be subclassed by clients.
 * @noinstantiate This class is not intended to be instantiated by clients.
 */
public class ConvertToMakeWizardPage extends ConvertProjectWizardPage {

    private static final String WZ_TITLE = "WizardMakeProjectConversion.title"; //$NON-NLS-1$
    private static final String WZ_DESC = "WizardMakeProjectConversion.description"; //$NON-NLS-1$

    /**
	 * @since 5.1
	 */
    protected CWizardHandler h_selected = null;

    // widgets
    private Button specifyProjectTypeButton;
    private Tree tree;
    private Composite right;
    private Button show_sup;
    private Label right_label;
    private Label left_label;

	/**
	 * Constructor for ConvertToStdMakeProjectWizardPage.
	 * @param pageName
	 */
	public ConvertToMakeWizardPage(String pageName) {
		super(pageName);
	}

	@Override
	public void createControl(Composite parent) {
		super.createControl(parent);
		IStructuredSelection sel = ((BasicNewResourceWizard) getWizard())
				.getSelection();
		if (sel != null) {
			tableViewer.setCheckedElements(sel.toArray());
			setPageComplete(validatePage());
		}
	}

	@Override
	protected void addToMainPage(Composite container) {
		super.addToMainPage(container);

		Group optionsGroup = new Group(container, SWT.NONE);
		optionsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
		optionsGroup.setLayout(new GridLayout(1, true));
		optionsGroup.setText(MakeUIPlugin.getResourceString("WizardMakeProjectConversion.projectOptions.title")); //$NON-NLS-1$
		Composite c = new Composite(optionsGroup, SWT.NONE);
		c.setLayoutData(new GridData(GridData.FILL_BOTH));
		c.setLayout(new GridLayout(2, true));

		specifyProjectTypeButton = new Button(c, SWT.CHECK);
		specifyProjectTypeButton.setText(MakeUIPlugin.getResourceString("WizardMakeProjectConversion.projectOptions.projectType")); //$NON-NLS-1$
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 2;
		specifyProjectTypeButton.setLayoutData(gd);
		specifyProjectTypeButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				enableProjectTypeControls(specifyProjectTypeButton
						.getSelection());
			}
		});

		left_label = new Label(c, SWT.NONE);
		left_label.setText(MakeUIPlugin.getResourceString("WizardMakeProjectConversion.projectOptions.projectTypeTable")); //$NON-NLS-1$
		left_label.setFont(container.getFont());
		left_label.setLayoutData(new GridData(GridData.BEGINNING));

		right_label = new Label(c, SWT.NONE);
		right_label.setFont(container.getFont());
		right_label.setLayoutData(new GridData(GridData.BEGINNING));

		tree = new Tree(c, SWT.SINGLE | SWT.BORDER);
		tree.setLayoutData(new GridData(GridData.FILL_BOTH));
		tree.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				TreeItem[] tis = tree.getSelection();
				if (tis == null || tis.length == 0)
					return;
				switchTo((CWizardHandler) tis[0].getData(),
						(EntryDescriptor) tis[0]
								.getData(CDTMainWizardPage.DESC));
			}
		});
		right = new Composite(c, SWT.NONE);
		right.setLayoutData(new GridData(GridData.FILL_BOTH));
		right.setLayout(new PageLayout());

		show_sup = new Button(c, SWT.CHECK);
		show_sup.setSelection(true);
		show_sup.setText(MakeUIPlugin.getResourceString("WizardMakeProjectConversion.projectOptions.showSuppressed")); //$NON-NLS-1$
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 2;
		show_sup.setLayoutData(gd);
		final IWizardItemsListListener filter = new IWizardItemsListListener() {

			// Show only category
			@Override
			public List<EntryDescriptor> filterItems(
					List<? extends EntryDescriptor> items) {
				List<EntryDescriptor> results = new ArrayList<EntryDescriptor>();

				for (EntryDescriptor entry : items) {
					if (entry.isCategory()) {
						results.add(entry);
					}
				}

				return results;
			}

			@Override
			public boolean isCurrent() {
				return true;
			}

			@Override
			public void toolChainListChanged(int count) {
				// Do nothing
			}
		};

		show_sup.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if (h_selected != null)
					h_selected.setSupportedOnly(show_sup.getSelection());
				switchTo(CDTMainWizardPage.updateData(tree, right, show_sup,
						filter, null), CDTMainWizardPage.getDescriptor(tree));
			}
		});

		CDTPrefUtil.readPreferredTCs();
		switchTo(CDTMainWizardPage.updateData(tree, right, show_sup, filter,
				null), CDTMainWizardPage.getDescriptor(tree));

		specifyProjectTypeButton.setSelection(true);
		enableProjectTypeControls(true);
	}

	private void enableProjectTypeControls(boolean enabled) {
		left_label.setEnabled(enabled);
		right_label.setEnabled(enabled);
		tree.setEnabled(enabled);
		right.setEnabled(enabled);
		enabledCompositeChildren(right, enabled);
		show_sup.setEnabled(enabled);
	}

	private void enabledCompositeChildren(Composite composite, boolean enabled) {
		Control[] children = composite.getChildren();
		for (int i = 0; i < children.length; i++) {
			children[i].setEnabled(enabled);
			if (children[i] instanceof Composite) {
				enabledCompositeChildren((Composite) children[i], enabled);
			}
		}
	}

	private void switchTo(CWizardHandler h, EntryDescriptor ed) {
		if (h == null)
			h = ed.getHandler();
		try {
			if (h != null && ed != null)
				h.initialize(ed);
		} catch (CoreException e) {
			h = null;
		}
		if (h_selected != null)
			h_selected.handleUnSelection();
		h_selected = h;
		if (h == null)
			return;
		right_label.setText(h_selected.getHeader());
		h_selected.handleSelection();
		h_selected.setSupportedOnly(show_sup.getSelection());
	}

	/**
     * Method getWzTitleResource returns the correct Title Label for this class
     * overriding the default in the superclass.
     */
    @Override
	protected String getWzTitleResource(){
        return MakeUIPlugin.getResourceString(WZ_TITLE);
    }

    /**
     * Method getWzDescriptionResource returns the correct description
     * Label for this class overriding the default in the superclass.
     */
    @Override
	protected String getWzDescriptionResource(){
        return MakeUIPlugin.getResourceString(WZ_DESC);
    }

    /**
     * Method isCandidate returns true for:
     * - non-CDT projects
     * - old style Make CDT projects
     * So new model projects and
     * old style managed projects
     * are refused.
     */
    @Override
	public boolean isCandidate(IProject project) {
    	boolean a = !AbstractPage.isCDTPrj(project);
    	boolean b = ManagedBuilderCorePlugin.getDefault().isOldStyleMakeProject(project);
		return a || b;
    }

    @Override
	public void convertProject(IProject project, String bsId, IProgressMonitor monitor) throws CoreException{
		monitor.beginTask(MakeUIPlugin.getResourceString("WizardMakeProjectConversion.monitor.convertingToMakeProject"), 3); //$NON-NLS-1$
		try {
			if (ManagedBuilderCorePlugin.getDefault().isOldStyleMakeProject(project)) {
				ManagedBuilderCorePlugin.getDefault().convertOldStdMakeToNewStyle(project, monitor);
			} else {
				super.convertProject(project, bsId, new SubProgressMonitor(monitor, 1));
				if (isSetProjectType()) {
					h_selected.convertProject(project, monitor);
				}
			}
		} finally {
			monitor.done();
		}
    }

	@Override
	public void convertProject(IProject project, IProgressMonitor monitor, String projectID) throws CoreException {
		monitor.beginTask(MakeUIPlugin.getResourceString("WizardMakeProjectConversion.monitor.convertingToMakeProject"), 3); //$NON-NLS-1$
		try {
			if (ManagedBuilderCorePlugin.getDefault().isOldStyleMakeProject(project)) {
				ManagedBuilderCorePlugin.getDefault().convertOldStdMakeToNewStyle(project, monitor);
			} else {
				super.convertProject(project, new SubProgressMonitor(monitor, 1), projectID);
				if (isSetProjectType()) {
					h_selected.convertProject(project, monitor);
				}
			}
		} finally {
			monitor.done();
		}
	}

	/**
	 * @since 5.1
	 */
	public boolean isSetProjectType() {
		return specifyProjectTypeButton != null && specifyProjectTypeButton.getSelection();
    }
}

Back to the top