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.viewers.ISelection;
14: import org.eclipse.jface.viewers.IStructuredSelection;
15: import org.eclipse.pde.internal.runtime.PDERuntimeMessages;
16: import org.eclipse.pde.internal.runtime.spy.SpyFormToolkit;
17: import org.eclipse.ui.IWorkbenchWindow;
18: import org.eclipse.ui.forms.widgets.ExpandableComposite;
19: import org.eclipse.ui.forms.widgets.FormText;
20: import org.eclipse.ui.forms.widgets.ScrolledForm;
21: import org.eclipse.ui.forms.widgets.Section;
22: import org.eclipse.ui.forms.widgets.TableWrapData;
23: import org.eclipse.ui.handlers.HandlerUtil;
24:
25: public class ActiveSelectionSection implements ISpySection {
26:
27: public void build(ScrolledForm form, SpyFormToolkit toolkit,
28: ExecutionEvent event) {
29: IWorkbenchWindow window = HandlerUtil
30: .getActiveWorkbenchWindow(event);
31: if (window == null) // if we don't have an active workbench, we don't have a valid selection to analyze
32: return;
33:
34: // analyze the selection
35: ISelection selection = HandlerUtil.getCurrentSelection(event);
36: if (selection instanceof IStructuredSelection) {
37: IStructuredSelection ss = (IStructuredSelection) selection;
38: Object object = ss.getFirstElement();
39: if (object != null) { // check for a valid class
40: Class clazz = object.getClass();
41:
42: Section section = toolkit.createSection(form.getBody(),
43: ExpandableComposite.TITLE_BAR);
44: section.setExpanded(true);
45: section
46: .setText(PDERuntimeMessages.SpyDialog_activeSelection_title);
47: FormText text = toolkit.createFormText(section, true);
48: section.setClient(text);
49:
50: TableWrapData td = new TableWrapData();
51: td.align = TableWrapData.FILL;
52: td.grabHorizontal = true;
53: section.setLayoutData(td);
54:
55: // time to analyze the selection
56: StringBuffer buffer = new StringBuffer();
57: buffer.append("<form>"); //$NON-NLS-1$
58: buffer
59: .append(toolkit
60: .createClassSection(
61: text,
62: PDERuntimeMessages.SpyDialog_activeSelection_desc,
63: new Class[] { clazz }));
64:
65: Class[] interfaces = clazz.getInterfaces();
66: buffer
67: .append(toolkit
68: .createInterfaceSection(
69: text,
70: PDERuntimeMessages.SpyDialog_activeSelectionInterfaces_desc,
71: interfaces));
72:
73: buffer.append("</form>"); //$NON-NLS-1$
74: text.setText(buffer.toString(), true, false);
75: }
76: }
77: }
78:
79: }
|