Revision 33

tmp/org.txm.rcp.about.fragment/.classpath (revision 33)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="src" path="src"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
0 8

  
tmp/org.txm.rcp.about.fragment/META-INF/MANIFEST.MF (revision 33)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: org.txm.rcp.about.fragment
4
Bundle-SymbolicName: org.txm.rcp.about.fragment
5
Bundle-Version: 1.0.0.qualifier
6
Fragment-Host: org.eclipse.ui.workbench;bundle-version="3.105.0"
7
Eclipse-PatchFragment: true
8
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
9
Bundle-ClassPath: library.jar,
10
 .
0 11

  
tmp/org.txm.rcp.about.fragment/.project (revision 33)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.rcp.about.fragment</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

  
tmp/org.txm.rcp.about.fragment/src/org/eclipse/ui/internal/about/InstallationDialog.java (revision 33)
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11

  
12
package org.eclipse.ui.internal.about;
13

  
14
import java.util.ArrayList;
15
import java.util.HashMap;
16
import java.util.List;
17
import java.util.Map;
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IConfigurationElement;
21
import org.eclipse.core.runtime.IExtensionPoint;
22
import org.eclipse.core.runtime.IProduct;
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.jface.dialogs.Dialog;
25
import org.eclipse.jface.dialogs.IDialogConstants;
26
import org.eclipse.jface.dialogs.IDialogSettings;
27
import org.eclipse.jface.dialogs.TrayDialog;
28
import org.eclipse.osgi.util.NLS;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.events.DisposeEvent;
31
import org.eclipse.swt.events.DisposeListener;
32
import org.eclipse.swt.events.SelectionAdapter;
33
import org.eclipse.swt.events.SelectionEvent;
34
import org.eclipse.swt.graphics.FontMetrics;
35
import org.eclipse.swt.graphics.GC;
36
import org.eclipse.swt.graphics.Point;
37
import org.eclipse.swt.layout.GridData;
38
import org.eclipse.swt.layout.GridLayout;
39
import org.eclipse.swt.widgets.Button;
40
import org.eclipse.swt.widgets.Composite;
41
import org.eclipse.swt.widgets.Control;
42
import org.eclipse.swt.widgets.Label;
43
import org.eclipse.swt.widgets.Shell;
44
import org.eclipse.swt.widgets.TabFolder;
45
import org.eclipse.swt.widgets.TabItem;
46
import org.eclipse.ui.about.IInstallationPageContainer;
47
import org.eclipse.ui.about.InstallationPage;
48
import org.eclipse.ui.internal.ConfigurationInfo;
49
import org.eclipse.ui.internal.WorkbenchMessages;
50
import org.eclipse.ui.internal.WorkbenchPlugin;
51
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
52
import org.eclipse.ui.services.IServiceLocator;
53

  
54
/**
55
 * @since 3.5
56
 * 
57
 */
58
public class InstallationDialog extends TrayDialog implements
59
IInstallationPageContainer {
60
	class ButtonManager {
61

  
62
		private Composite composite;
63
		HashMap buttonMap = new HashMap(); // page id->Collection of page
64

  
65
		// buttons
66

  
67
		public ButtonManager(Composite composite) {
68
			this.composite = composite;
69
		}
70

  
71
		public Composite getParent() {
72
			return composite;
73
		}
74

  
75
		public void update(String currentPageId) {
76
			if (composite == null || composite.isDisposed())
77
				return;
78
			GC metricsGC = new GC(composite);
79
			FontMetrics metrics = metricsGC.getFontMetrics();
80
			metricsGC.dispose();
81
			List buttons = (List) buttonMap.get(currentPageId);
82
			Control[] children = composite.getChildren();
83

  
84
			int visibleChildren = 0;
85
			Button closeButton = getButton(IDialogConstants.CLOSE_ID);
86

  
87
			for (int i = 0; i < children.length; i++) {
88
				Control control = children[i];
89
				if (closeButton == control)
90
					closeButton.dispose();
91
				else {
92
					control.setVisible(false);
93
					setButtonLayoutData(metrics, control, false);
94
				}
95
			}
96
			if (buttons != null) {
97
				for (int i = 0; i < buttons.size(); i++) {
98
					Button button = (Button) buttons.get(i);
99
					button.setVisible(true);
100
					setButtonLayoutData(metrics, button, true);
101
					GridData data = (GridData) button.getLayoutData();
102
					data.exclude = false;
103
					visibleChildren++;
104
				}
105
			}
106

  
107
			GridLayout compositeLayout = (GridLayout) composite.getLayout();
108
			compositeLayout.numColumns = visibleChildren;
109
			composite.layout(true);
110
		}
111

  
112
		protected void setButtonLayoutData(FontMetrics metrics, Control button,
113
				boolean visible) {
114
			GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
115
			int widthHint = Dialog.convertHorizontalDLUsToPixels(metrics,
116
					IDialogConstants.BUTTON_WIDTH);
117
			Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
118
			data.widthHint = Math.max(widthHint, minSize.x);
119
			data.exclude = !visible;
120
			button.setLayoutData(data);
121
		}
122

  
123
		public void addPageButton(String id, Button button) {
124
			List list = (List) buttonMap.get(id);
125
			if (list == null) {
126
				list = new ArrayList(1);
127
				buttonMap.put(id, list);
128
			}
129
			list.add(button);
130
		}
131

  
132
		public void clear() {
133
			buttonMap = new HashMap();
134
		}
135
	}
136

  
137
	protected static final String ID = "ID"; //$NON-NLS-1$
138
	private static final String DIALOG_SETTINGS_SECTION = "InstallationDialogSettings"; //$NON-NLS-1$
139
	private final static int TAB_WIDTH_IN_DLUS = 440;
140
	private final static int TAB_HEIGHT_IN_DLUS = 320;
141

  
142
	private static String lastSelectedTabId = null;
143
	private TabFolder folder;
144
	IServiceLocator serviceLocator;
145
	private ButtonManager buttonManager;
146
	private Map pageToId = new HashMap();
147
	private Dialog modalParent;
148

  
149
	/**
150
	 * @param parentShell
151
	 * @param locator
152
	 */
153
	public InstallationDialog(Shell parentShell, IServiceLocator locator) {
154
		super(parentShell);
155
		serviceLocator = locator;
156

  
157
	}
158

  
159
	/*
160
	 * (non-Javadoc)
161
	 * 
162
	 * @see
163
	 * org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets
164
	 * .Shell)
165
	 */
166
	protected void configureShell(Shell newShell) {
167
		super.configureShell(newShell);
168
		String productName = ""; //$NON-NLS-1$
169
		IProduct product = Platform.getProduct();
170
		if (product != null && product.getName() != null)
171
			productName = product.getName();
172
		newShell.setText(NLS.bind(
173
				WorkbenchMessages.InstallationDialog_ShellTitle, productName));
174
	}
175

  
176
	/*
177
	 * (non-Javadoc)
178
	 * 
179
	 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
180
	 */
181
	protected boolean isResizable() {
182
		return true;
183
	}
184

  
185
	/*
186
	 * (non-Javadoc)
187
	 * 
188
	 * @see
189
	 * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
190
	 * .Composite)
191
	 */
192
	protected Control createDialogArea(Composite parent) {
193
		Composite composite = (Composite) super.createDialogArea(parent);
194

  
195
		folder = new TabFolder(composite, SWT.NONE);
196
		configureFolder();
197
		createFolderItems(folder);
198

  
199
		GridData folderData = new GridData(SWT.FILL, SWT.FILL, true, true);
200
		folderData.widthHint = convertHorizontalDLUsToPixels(TAB_WIDTH_IN_DLUS);
201
		folderData.heightHint = convertVerticalDLUsToPixels(TAB_HEIGHT_IN_DLUS);
202
		folder.setLayoutData(folderData);
203
		folder.addSelectionListener(createFolderSelectionListener());
204
		folder.addDisposeListener(new DisposeListener() {
205
			public void widgetDisposed(DisposeEvent e) {
206
				releaseContributions();
207
			}
208
		});
209
		return composite;
210
	}
211

  
212
	protected void createFolderItems(TabFolder folder) {
213
		IConfigurationElement[] elements = ConfigurationInfo
214
				.getSortedExtensions(loadElements());
215

  
216
		// Patch !!
217
		if (elements.length > 1) {
218
			IConfigurationElement tmp = elements[0];
219
			elements[0] = elements[1];
220
			elements[1] = tmp;
221
		}
222

  
223
		for (int i = 0; i < elements.length; i++) {
224
			IConfigurationElement element = elements[i];
225
			TabItem item = new TabItem(folder, SWT.NONE);
226
			item.setText(element
227
					.getAttribute(IWorkbenchRegistryConstants.ATT_NAME));
228
			item.setData(element);
229
			item.setData(ID, element
230
					.getAttribute(IWorkbenchRegistryConstants.ATT_ID));
231

  
232
			Composite control = new Composite(folder, SWT.NONE);
233
			control.setLayout(new GridLayout());
234
			item.setControl(control);
235
		}
236

  
237

  
238

  
239
	}
240

  
241
	protected Control createContents(Composite parent) {
242
		Control control = super.createContents(parent);
243
		boolean selected = false;
244
		if (folder.getItemCount() > 0) {
245
			if (lastSelectedTabId != null) {
246
				TabItem[] items = folder.getItems();
247
				for (int i = 0; i < items.length; i++)
248
					if (items[i].getData(ID).equals(lastSelectedTabId)) {
249
						folder.setSelection(i);
250
						tabSelected(items[i]);
251
						selected = true;
252
						break;
253
					}
254
			}
255
			if (!selected)
256
				tabSelected(folder.getItem(0));
257
		}
258
		// need to reapply the dialog font now that we've created new
259
		// tab items
260
		Dialog.applyDialogFont(folder);
261
		return control;
262
	}
263

  
264
	private SelectionAdapter createFolderSelectionListener() {
265
		return new SelectionAdapter() {
266

  
267
			public void widgetSelected(SelectionEvent e) {
268
				tabSelected((TabItem) e.item);
269
			}
270
		};
271
	}
272

  
273
	/*
274
	 * Must be called after contributions and button manager are created.
275
	 */
276
	private void tabSelected(TabItem item) {
277
		if (item.getData() instanceof IConfigurationElement) {
278
			final IConfigurationElement element = (IConfigurationElement) item
279
					.getData();
280

  
281
			Composite pageComposite = (Composite) item.getControl();
282
			try {
283
				final InstallationPage page = (InstallationPage) element
284
						.createExecutableExtension(IWorkbenchRegistryConstants.ATT_CLASS);
285
				page.createControl(pageComposite);
286
				// new controls created since the dialog font was applied, so
287
				// apply again.
288
				Dialog.applyDialogFont(pageComposite);
289
				page.setPageContainer(this);
290
				// Must be done before creating the buttons because the control
291
				// button creation methods
292
				// use this map.
293
				pageToId.put(page, element
294
						.getAttribute(IWorkbenchRegistryConstants.ATT_ID));
295
				createButtons(page);
296
				item.setData(page);
297
				item.addDisposeListener(new DisposeListener() {
298

  
299
					public void widgetDisposed(DisposeEvent e) {
300
						page.dispose();
301
					}
302
				});
303
				pageComposite.layout(true, true);
304

  
305
			} catch (CoreException e1) {
306
				Label label = new Label(pageComposite, SWT.NONE);
307
				label.setText(e1.getMessage());
308
				item.setData(null);
309
			}
310

  
311
		}
312
		String id = (String) item.getData(ID);
313
		rememberSelectedTab(id);
314
		buttonManager.update(id);
315
		Button button = createButton(buttonManager.getParent(),
316
				IDialogConstants.CLOSE_ID, IDialogConstants.CLOSE_LABEL, true);
317
		GridData gd = (GridData) button.getLayoutData();
318
		gd.horizontalAlignment = SWT.BEGINNING;
319
		gd.horizontalIndent = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH) / 2;
320
		// Layout the button bar's parent and all of its children.  We must
321
		// cascade through all children because the buttons have changed and
322
		// because tray dialog inserts an extra composite in the button bar
323
		// hierarchy.
324
		getButtonBar().getParent().layout(true, true);
325

  
326
	}
327

  
328
	protected void createButtons(InstallationPage page) {
329
		page.createPageButtons(buttonManager.getParent());
330
		Dialog.applyDialogFont(buttonManager.getParent());
331
	}
332

  
333
	private void rememberSelectedTab(String pageId) {
334
		lastSelectedTabId = pageId;
335
	}
336

  
337
	/*
338
	 * (non-Javadoc)
339
	 * 
340
	 * @see
341
	 * org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse
342
	 * .swt.widgets.Composite)
343
	 */
344
	protected void createButtonsForButtonBar(Composite parent) {
345
		// The button manager will handle the correct sizing of the buttons.
346
		// We do not want columns equal width because we are going to add some
347
		// padding in the final column (close button).
348
		GridLayout layout = (GridLayout) parent.getLayout();
349
		layout.makeColumnsEqualWidth = false;
350
		buttonManager = new ButtonManager(parent);
351
	}
352

  
353
	private void configureFolder() {
354
	}
355

  
356
	private IConfigurationElement[] loadElements() {
357
		IExtensionPoint point = Platform.getExtensionRegistry()
358
				.getExtensionPoint("org.eclipse.ui", "installationPages"); //$NON-NLS-1$ //$NON-NLS-2$
359
		return point.getConfigurationElements();
360
	}
361

  
362
	protected IDialogSettings getDialogBoundsSettings() {
363
		IDialogSettings settings = WorkbenchPlugin.getDefault()
364
				.getDialogSettings();
365
		IDialogSettings section = settings.getSection(DIALOG_SETTINGS_SECTION);
366
		if (section == null) {
367
			section = settings.addNewSection(DIALOG_SETTINGS_SECTION);
368
		}
369
		return section;
370
	}
371

  
372
	protected void releaseContributions() {
373
		buttonManager.clear();
374
	}
375

  
376
	public void closeModalContainers() {
377
		close();
378
		if (modalParent != null)
379
			modalParent.close();
380
	}
381

  
382
	protected void buttonPressed(int buttonId) {
383
		if (IDialogConstants.CLOSE_ID == buttonId) {
384
			okPressed();
385
		}
386
	}
387

  
388
	public void registerPageButton(InstallationPage page, Button button) {
389
		buttonManager.addPageButton(pageToId(page), button);
390
	}
391

  
392
	protected String pageToId(InstallationPage page) {
393
		String pageId = (String) pageToId.get(page);
394
		Assert.isLegal(pageId != null);
395
		return pageId;
396
	}
397

  
398
	/**
399
	 * Set the modal parent dialog that was used to launch this dialog. This
400
	 * should be used by any launching dialog so that the {
401
	 * {@link #closeModalContainers()} method can be properly implemented.
402
	 * 
403
	 * @param parent
404
	 *            the modal parent dialog that launched this dialog, or
405
	 *            <code>null</code> if there was no parent.
406
	 * 
407
	 *            This is an internal method and should not be used outside of
408
	 *            platform UI.
409
	 */
410
	public void setModalParent(Dialog parent) {
411
		this.modalParent = parent;
412
	}
413
}
0 414

  
tmp/org.txm.rcp.about.fragment/build.properties (revision 33)
1
bin.includes = META-INF/,\
2
               library.jar
3
source.library.jar = src/
4
jars.compile.order = library.jar
0 5

  
tmp/org.txm.rcp.about.fragment/.settings/org.eclipse.jdt.core.prefs (revision 33)
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4
org.eclipse.jdt.core.compiler.compliance=1.6
5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7
org.eclipse.jdt.core.compiler.source=1.6
0 8

  

Also available in: Unified diff