Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1714b964f1fe2f93088e8c12093ee77a5a9ff1db (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
/*******************************************************************************
 * Copyright (c) 2011 Wind River Systems, 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tm.te.ui.wizards.newWizard;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardNode;
import org.eclipse.swt.graphics.Point;
import org.eclipse.tm.te.ui.activator.UIPlugin;
import org.eclipse.tm.te.ui.nls.Messages;
import org.eclipse.tm.te.ui.wizards.interfaces.INewTargetWizard;
import org.eclipse.ui.IPluginContribution;
import org.eclipse.ui.IWorkbenchWizard;
import org.eclipse.ui.internal.util.Util;
import org.eclipse.ui.wizards.IWizardDescriptor;

/**
 * New wizard node implementation.
 */
@SuppressWarnings("restriction")
/* default */ class NewWizardNode implements IWizardNode, IPluginContribution {
	// The associated wizard descriptor
	private final IWizardDescriptor descriptor;
	// The parent wizard selection page
	private final NewWizardSelectionPage page;

	// The wizard instance, once created
	private IWizard wizard;

	/**
	 * Constructor.
	 *
	 * @param page The parent wizard selection page. Must not be <code>null</code>.
	 * @param descriptor The wizard descriptor. Must not be <code>null</code>.
	 */
	public NewWizardNode(NewWizardSelectionPage page, IWizardDescriptor descriptor) {
		Assert.isNotNull(page);
		Assert.isNotNull(descriptor);

		this.page = page;
		this.descriptor = descriptor;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.IWizardNode#dispose()
	 */
	@Override
	public void dispose() {
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.IWizardNode#getExtent()
	 */
	@Override
	public Point getExtent() {
        return new Point(-1, -1);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IPluginContribution#getLocalId()
	 */
	@Override
	public String getLocalId() {
    	IPluginContribution contribution = (IPluginContribution)Util.getAdapter(descriptor, IPluginContribution.class);
		if (contribution != null) {
			return contribution.getLocalId();
		}
		return descriptor.getId();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IPluginContribution#getPluginId()
	 */
	@Override
	public String getPluginId() {
       	IPluginContribution contribution = (IPluginContribution) Util.getAdapter(descriptor, IPluginContribution.class);
		if (contribution != null) {
			return contribution.getPluginId();
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.IWizardNode#isContentCreated()
	 */
	@Override
	public boolean isContentCreated() {
		return wizard != null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.IWizardNode#getWizard()
	 */
	@Override
	public IWizard getWizard() {
		if (wizard == null) {
			wizard = createWizard(descriptor);
		}
		return wizard;
	}

	/**
	 * Create the wizard associated with the specified wizard descriptor.
	 *
	 * @param descriptor The wizard descriptor. Must not be <code>null</code>.
	 * @return The wizard or <code>null</code> if the creation fails.
	 */
	private final IWorkbenchWizard createWizard(IWizardDescriptor descriptor) {
		Assert.isNotNull(descriptor);

		IWorkbenchWizard wizard = null;

		try {
			// Create the wizard instance
			wizard = descriptor.createWizard();

			// If the wizard is a INewTargetWizard, associate the wizard descriptor
			if (wizard instanceof INewTargetWizard) ((INewTargetWizard)wizard).setWizardDescriptor(descriptor);

			// Initialize the wizard
			IStructuredSelection wizardSelection = descriptor.adaptedSelection(page.getSelection());
			wizard.init(page.getWorkbench(), wizardSelection);
		} catch (CoreException e) {
			page.setErrorMessage(Messages.NewWizardSelectionPage_createWizardFailed);

			IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(),
										Messages.NewWizardSelectionPage_createWizardFailed, e);
			UIPlugin.getDefault().getLog().log(status);
		}

		return wizard;
	}
}

Back to the top