Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 80c9308c378b9cbdc792663dd4611e61073a503c (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
/*******************************************************************************
 * Copyright (c) 2012 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.tcf.te.launch.ui.tabs;

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

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.tcf.te.launch.core.lm.LaunchManager;
import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate;
import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
import org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection;
import org.eclipse.tcf.te.launch.ui.selection.LaunchSelectionManager;

/**
 * Abstract launch configuration tab group default implementation.
 * <p>
 * The implementation provided assures to forward launch configuration attributes defaults
 * initialization to the corresponding launch manager delegates before the single launch
 * configuration tabs might want to override these defaults based on their data.
 */
public abstract class AbstractLaunchConfigurationTabGroup extends org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup {
	private ILaunchConfigurationDialog dialog;
	private String mode;

	/**
	 * Constructor.
	 */
	public AbstractLaunchConfigurationTabGroup() {
		super();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTabGroup#createTabs(org.eclipse.debug.ui.ILaunchConfigurationDialog, java.lang.String)
	 */
	@Override
	public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
		this.dialog = dialog;
		this.mode = mode;

		// The list of tabs to be set to the launch tab group
		List<ILaunchConfigurationTab> tabs = new ArrayList<ILaunchConfigurationTab>();

		// Create the default launch tabs
		createContextSelectorTab(dialog, tabs, mode);

		// Create and add any additional launch tabs
		createAdditionalTabs(dialog, tabs, mode);

		// Apply the tabs
		setTabs(tabs.toArray(new ILaunchConfigurationTab[tabs.size()]));
	}

	/**
	 * Create the context selector tab.
	 *
	 * @param dialog The launch configuration dialog this tab group is contained in.
	 * @param tabs The list of launch configuration tabs. Must not be <code>null</code>.
	 * @param mode The mode the launch configuration dialog was opened in.
	 */
	public void createContextSelectorTab(ILaunchConfigurationDialog dialog, List<ILaunchConfigurationTab> tabs, String mode) {
		Assert.isNotNull(tabs);
	}

	/**
	 * Hook for subclasses to overwrite to add additional launch configuration tabs to the given
	 * tab list.
	 * <p>
	 * Called from {@link #createTabs(ILaunchConfigurationDialog, String)} before setting the tabs list
	 * to the launch configuration tab group.
	 *
	 * @param dialog The launch configuration dialog this tab group is contained in.
	 * @param tabs The list of launch configuration tabs. Must not be <code>null</code>.
	 * @param mode The mode the launch configuration dialog was opened in.
	 */
	public void createAdditionalTabs(ILaunchConfigurationDialog dialog, List<ILaunchConfigurationTab> tabs, String mode) {
		Assert.isNotNull(tabs);
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup#dispose()
	 */
	@Override
	public void dispose() {
		dialog = null;
		mode = null;

		super.dispose();
	}

	/**
	 * Returns the associated launch configuration dialog. The dialog is only valid between the
	 * calls of <code>createTabs(...)</code> and <code>dispose()</code>.
	 *
	 * @return The associated launch configuration dialog or <code>null</code>.
	 */
	protected final ILaunchConfigurationDialog getLaunchConfigurationDialog() {
		return dialog;
	}

	/**
	 * Returns the launch mode the launch configuration dialog has been opened in. The launch mode
	 * is only valid between the calls of <code>createTabs(...)</code> and <code>dispose()</code>.
	 *
	 * @return The launch mode the launch configuration dialog has been opened in or <code>null</code>.
	 */
	protected final String getLaunchMode() {
		return mode;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
	 */
	@Override
	public final void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
		if (configuration != null && getLaunchMode() != null) {
			// extract the launch configuration type from the launch configuration and
			// pass the launch configuration to the corresponding launch manager
			// delegate (based on the extracted launch configuration type) for
			// initializing the defaults within the launch configuration.
			try {
				ILaunchConfigurationType launchConfigType = configuration.getType();
				String launchConfigTypeId = launchConfigType.getIdentifier();
				String launchMode = getLaunchConfigurationDialog().getMode();
				ILaunchSelection launchSelection = LaunchSelectionManager.getInstance().getLaunchSelection(launchConfigType, launchMode, null);
				ILaunchManagerDelegate delegate = LaunchManager.getInstance().getLaunchManagerDelegate(launchConfigType, launchMode);
				if (delegate != null && launchSelection != null) {
					// create an empty launch configuration specification to initialize all
					// attributes with their default defaults.
					ILaunchSpecification launchSpec = delegate.getLaunchSpecification(launchConfigTypeId, launchSelection);
					// initialize the new launch configuration.
					// ignore validation result of launch spec - init as much attributes as possible
					if (launchSpec != null) {
						delegate.initLaunchConfigAttributes(configuration, launchSpec);
					}
				}
			}
			catch (CoreException e) {
				// Ignore: If we run into the CoreException, we cannot get the launch configuration
				// type. So, what are we supposed to do then?
			}
		}
		// And finally, call the setDefaults methods from the single tabs.
		super.setDefaults(configuration);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
	 */
	@Override
	public final void initializeFrom(ILaunchConfiguration configuration) {
		if (!(configuration instanceof ILaunchConfigurationWorkingCopy)) {
			try {
				configuration = configuration.getWorkingCopy();
			}
			catch (CoreException e) {
			}
		}
		super.initializeFrom(configuration);
	}
}

Back to the top