01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Chris Aniszczyk <zx@us.ibm.com> - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.runtime.spy.sections;
11:
12: import org.eclipse.core.commands.ExecutionEvent;
13: import org.eclipse.jface.preference.IPreferencePage;
14: import org.eclipse.jface.preference.PreferenceDialog;
15: import org.eclipse.osgi.util.NLS;
16: import org.eclipse.pde.internal.runtime.PDERuntimeMessages;
17: import org.eclipse.pde.internal.runtime.PDERuntimePlugin;
18: import org.eclipse.pde.internal.runtime.spy.SpyFormToolkit;
19: import org.eclipse.swt.widgets.Shell;
20: import org.eclipse.ui.forms.widgets.ExpandableComposite;
21: import org.eclipse.ui.forms.widgets.FormText;
22: import org.eclipse.ui.forms.widgets.ScrolledForm;
23: import org.eclipse.ui.forms.widgets.Section;
24: import org.eclipse.ui.forms.widgets.TableWrapData;
25: import org.eclipse.ui.handlers.HandlerUtil;
26: import org.osgi.framework.Bundle;
27: import org.osgi.service.packageadmin.PackageAdmin;
28:
29: public class ActivePreferenceDialogSection implements ISpySection {
30:
31: public void build(ScrolledForm form, SpyFormToolkit toolkit,
32: ExecutionEvent event) {
33: final Shell shell = HandlerUtil.getActiveShell(event);
34: Object object = shell.getData();
35: if (object == null)
36: return;
37: Class clazz = object.getClass();
38:
39: if (object instanceof PreferenceDialog) {
40: PreferenceDialog dialog = (PreferenceDialog) object;
41: IPreferencePage page = (IPreferencePage) dialog
42: .getSelectedPage();
43: clazz = page.getClass();
44:
45: Section section = toolkit.createSection(form.getBody(),
46: ExpandableComposite.TITLE_BAR);
47: section
48: .setText(NLS
49: .bind(
50: PDERuntimeMessages.ActivePreferenceDialogSection_title,
51: page.getTitle()));
52:
53: // the active page
54: FormText text = toolkit.createFormText(section, true);
55: section.setClient(text);
56: TableWrapData td = new TableWrapData();
57: td.align = TableWrapData.FILL;
58: td.grabHorizontal = true;
59: section.setLayoutData(td);
60:
61: StringBuffer buffer = new StringBuffer();
62: buffer.append("<form>"); //$NON-NLS-1$
63:
64: buffer
65: .append(toolkit
66: .createClassSection(
67: text,
68: PDERuntimeMessages.ActivePreferenceDialogSection_desc,
69: new Class[] { clazz }));
70:
71: PackageAdmin admin = PDERuntimePlugin.getDefault()
72: .getPackageAdmin();
73: Bundle bundle = admin.getBundle(clazz);
74: toolkit.generatePluginDetailsText(bundle, null,
75: "preference", buffer, text); //$NON-NLS-1$
76:
77: buffer.append("</form>"); //$NON-NLS-1$
78: text.setText(buffer.toString(), true, false);
79: }
80: }
81:
82: }
|