Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 148e5219c49c25d03456c9372b2ea6013e3cc17b (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
/*******************************************************************************
 * Copyright (c) 2012, 2014 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.editor;

import org.eclipse.core.runtime.Assert;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.tcf.te.launch.ui.tabs.AbstractFormsLaunchConfigurationTab;
import org.eclipse.tcf.te.ui.forms.CustomFormToolkit;
import org.eclipse.tcf.te.ui.views.editor.pages.AbstractCustomFormToolkitEditorPage;
import org.eclipse.ui.forms.AbstractFormPart;

/**
 * Abstract editor page implementation serving as container for a launch tab.
 */
public abstract class AbstractLaunchTabContainerEditorPage extends AbstractCustomFormToolkitEditorPage {
	// Reference to the launch configuration tab
	private final AbstractLaunchConfigurationTab launchTab;

	boolean isDirty = false;

	/**
	 * Constructor.
	 */
	public AbstractLaunchTabContainerEditorPage() {
		super();

		// Create the launch configuration tab instance
		launchTab = createLaunchConfigurationTab();
		Assert.isNotNull(launchTab);
	}

	/**
	 * Creates a new instance of the launch configuration tab to associate.
	 *
	 * @return The new launch configuration tab instance.
	 */
	protected abstract AbstractLaunchConfigurationTab createLaunchConfigurationTab();

	/**
	 * Returns the associated launch configuration tab.
	 *
	 * @return The launch configuration tab or <code>null</code>.
	 */
	protected final AbstractLaunchConfigurationTab getLaunchConfigurationTab() {
		return launchTab;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.views.editor.pages.AbstractCustomFormToolkitEditorPage#dispose()
	 */
	@Override
	public void dispose() {
		launchTab.dispose();
		super.dispose();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.views.editor.pages.AbstractCustomFormToolkitEditorPage#getContextHelpId()
	 */
	@Override
	protected String getContextHelpId() {
		return launchTab.getHelpContextId();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.views.editor.pages.AbstractCustomFormToolkitEditorPage#getFormTitle()
	 */
	@Override
	protected String getFormTitle() {
		return launchTab.getName();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.views.editor.pages.AbstractCustomFormToolkitEditorPage#getFormImage()
	 */
	@Override
	protected Image getFormImage() {
		return launchTab.getImage();
	}

	/**
	 * Set the dirty state for this editor page.
	 * @param dirty The dirty state.
	 */
	public void setDirty(boolean dirty) {
		isDirty = dirty;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.views.editor.pages.AbstractCustomFormToolkitEditorPage#doCreateFormContent(org.eclipse.swt.widgets.Composite, org.eclipse.tcf.te.ui.forms.CustomFormToolkit)
	 */
	@Override
	protected void doCreateFormContent(Composite parent, CustomFormToolkit toolkit) {
		Assert.isNotNull(parent);
		Assert.isNotNull(toolkit);

		// Create the launch tab content
		if (launchTab instanceof AbstractFormsLaunchConfigurationTab) {
			((AbstractFormsLaunchConfigurationTab)launchTab).createFormContent(getManagedForm());
		} else {
			launchTab.createControl(parent);
		}

		getManagedForm().addPart(new AbstractFormPart() {
			@Override
			public boolean isDirty() {
				return isDirty;
			}

			@Override
			public void commit(boolean onSave) {
				super.commit(onSave);

				if (onSave) {
					extractData();
				}
			}
		});

		// Fix the background color of the launch tab controls
		Color bg = parent.getBackground();
		Control[] children = parent.getChildren();
		if (bg != null && children != null && children.length > 0) {
			fixBackgrounds(children, bg);
		}
	}

	/**
	 * Set the data to the page.
	 * @param input The editor input.
	 * @return <code>true</code> if data was set.
	 */
	public abstract boolean setupData(Object input);

	/**
	 * Extract the data from the page.
	 * @return <code>true</code> if data was set.
	 */
	public abstract boolean extractData();

	@Override
	public void setActive(boolean active) {
		super.setActive(active);
		if (active) setupData(getEditorInput());
	}

	/**
	 * Set the background color of the given controls and their children
	 * to the given color.
	 *
	 * @param controls The list of controls. Must not be <code>null</code>.
	 * @param bg The background color. Must not be <code>null</code>.
	 */
	protected final void fixBackgrounds(Control[] controls, Color bg) {
		Assert.isNotNull(controls);
		Assert.isNotNull(bg);
		for (Control c : controls) {
			if (!(c instanceof Composite) && !(c instanceof Label) && !(c instanceof Button)) {
				continue;
			}
			if (c instanceof Button) {
				int style = ((Button)c).getStyle();
				if ((style & SWT.RADIO) == 0 && (style & SWT.CHECK) == 0) {
					continue;
				}
			}
			if (!bg.equals(c.getBackground())) {
				c.setBackground(bg);
			}
			if (c instanceof Composite) {
				Control[] children = ((Composite)c).getChildren();
				if (children != null && children.length > 0) {
					fixBackgrounds(children, bg);
				}
			}
		}
	}
}

Back to the top