Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0790c1503a8c35778fc9ef53b8d8f4a57ce99ec4 (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
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylyn.internal.commons.repositories.ui.wizards;

import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.internal.activities.ws.WorkbenchTriggerPoints;
import org.eclipse.ui.internal.dialogs.WorkbenchWizardSelectionPage;
import org.eclipse.ui.wizards.IWizardCategory;
import org.eclipse.ui.wizards.IWizardDescriptor;

/**
 * New wizard selection tab that allows the user to either select a registered 'New' wizard to be launched, or to select
 * a solution or projects to be retrieved from an available server. This page contains two visual tabs that allow the
 * user to perform these tasks. Temporarily has two inner pages. The new format page is used if the system is currently
 * aware of activity categories.
 */
class NewRepositoryWizardSelectionPage extends WorkbenchWizardSelectionPage {

	private final IWizardCategory wizardCategories;

	// widgets
	private NewRepositoryWizardNewPage newResourcePage;

	private final IWizardDescriptor[] primaryWizards;

	private final boolean projectsOnly;

	private boolean canFinishEarly = false, hasPages = true;

	/**
	 * Create an instance of this class.
	 * 
	 * @param workbench
	 *            the workbench
	 * @param selection
	 *            the current selection
	 * @param root
	 *            the wizard root element
	 * @param primary
	 *            the primary wizard elements
	 * @param projectsOnly
	 *            if only projects should be shown
	 */
	public NewRepositoryWizardSelectionPage(IWorkbench workbench, IStructuredSelection selection, IWizardCategory root,
			IWizardDescriptor[] primary, boolean projectsOnly) {
		super("newWizardSelectionPage", workbench, selection, null, WorkbenchTriggerPoints.NEW_WIZARDS);//$NON-NLS-1$

		setTitle(WorkbenchMessages.NewWizardSelectionPage_description);
		wizardCategories = root;
		primaryWizards = primary;
		this.projectsOnly = projectsOnly;
	}

	/**
	 * Makes the next page visible.
	 */
	public void advanceToNextPageOrFinish() {
		if (canFlipToNextPage()) {
			getContainer().showPage(getNextPage());
		} else if (canFinishEarly()) {
			if (getWizard().performFinish()) {
				((WizardDialog) getContainer()).close();
			}
		}
	}

	/**
	 * (non-Javadoc) Method declared on IDialogPage.
	 */
	public void createControl(Composite parent) {
		IDialogSettings settings = getDialogSettings();
		newResourcePage = new NewRepositoryWizardNewPage(this, wizardCategories, primaryWizards, projectsOnly);
		newResourcePage.setDialogSettings(settings);

		Control control = newResourcePage.createControl(parent);
		getWorkbench().getHelpSystem().setHelp(control, IWorkbenchHelpContextIds.NEW_WIZARD_SELECTION_WIZARD_PAGE);
		setControl(control);
	}

	/**
	 * Since Finish was pressed, write widget values to the dialog store so that they will persist into the next
	 * invocation of this wizard page
	 */
	protected void saveWidgetValues() {
		newResourcePage.saveWidgetValues();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.IWizardPage#canFlipToNextPage()
	 */
	@Override
	public boolean canFlipToNextPage() {
		// if the current page advertises that it does have pages then ask it via the super call
		if (hasPages) {
			return super.canFlipToNextPage();
		}
		return false;
	}

	/**
	 * Sets whether the selected wizard advertises that it does provide pages.
	 * 
	 * @param newValue
	 *            whether the selected wizard has pages
	 * @since 3.1
	 */
	public void setHasPages(boolean newValue) {
		hasPages = newValue;
	}

	/**
	 * Sets whether the selected wizard advertises that it can finish early.
	 * 
	 * @param newValue
	 *            whether the selected wizard can finish early
	 * @since 3.1
	 */
	public void setCanFinishEarly(boolean newValue) {
		canFinishEarly = newValue;
	}

	/**
	 * Answers whether the currently selected page, if any, advertises that it may finish early.
	 * 
	 * @return whether the page can finish early
	 * @since 3.1
	 */
	public boolean canFinishEarly() {
		return canFinishEarly;
	}
}

Back to the top