Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4763a7b7ddd550590a826bbfdc8ec2c81c8aa795 (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
/*******************************************************************************
 * Copyright (c) 2000, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.ui.internal.dialogs;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.wizard.IWizardNode;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardSelectionPage;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.activities.ITriggerPoint;
import org.eclipse.ui.activities.WorkbenchActivityHelper;
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.model.AdaptableList;

/**
 * Page for selecting a wizard from a group of available wizards.
 */
public abstract class WorkbenchWizardSelectionPage extends WizardSelectionPage {

	// variables
	protected IWorkbench workbench;

	protected AdaptableList wizardElements;

	public TableViewer wizardSelectionViewer;

	protected IStructuredSelection currentResourceSelection;

	protected String triggerPointId;

	/**
	 * Create an instance of this class
	 */
	public WorkbenchWizardSelectionPage(String name, IWorkbench aWorkbench, IStructuredSelection currentSelection,
			AdaptableList elements, String triggerPointId) {
		super(name);
		this.wizardElements = elements;
		this.currentResourceSelection = currentSelection;
		this.workbench = aWorkbench;
		this.triggerPointId = triggerPointId;
		setTitle(WorkbenchMessages.Select);
	}

	/**
	 * Answer the wizard object corresponding to the passed id, or null if such an
	 * object could not be found
	 *
	 * @return WizardElement
	 * @param searchId the id to search on
	 */
	protected WorkbenchWizardElement findWizard(String searchId) {
		for (Object element : wizardElements.getChildren()) {
			WorkbenchWizardElement currentWizard = (WorkbenchWizardElement) element;
			if (currentWizard.getId().equals(searchId)) {
				return currentWizard;
			}
		}

		return null;
	}

	public IStructuredSelection getCurrentResourceSelection() {
		return currentResourceSelection;
	}

	public IWorkbench getWorkbench() {
		return this.workbench;
	}

	/**
	 * Specify the passed wizard node as being selected, meaning that if it's
	 * non-null then the wizard to be displayed when the user next presses the Next
	 * button should be determined by asking the passed node.
	 *
	 * @param node org.eclipse.jface.wizards.IWizardNode
	 */
	public void selectWizardNode(IWizardNode node) {
		setSelectedNode(node);
	}

	@Override
	public IWizardPage getNextPage() {
		ITriggerPoint triggerPoint = getWorkbench().getActivitySupport().getTriggerPointManager()
				.getTriggerPoint(triggerPointId);
		if (triggerPoint == null || WorkbenchActivityHelper.allowUseOf(triggerPoint, getSelectedNode())) {
			return super.getNextPage();
		}
		return null;
	}
}

Back to the top