001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Chris Aniszczyk <zx@us.ibm.com> - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.runtime.spy.dialogs;
011:
012: import org.eclipse.core.commands.ExecutionEvent;
013: import org.eclipse.jface.dialogs.PopupDialog;
014: import org.eclipse.pde.internal.runtime.PDERuntimeMessages;
015: import org.eclipse.pde.internal.runtime.PDERuntimePluginImages;
016: import org.eclipse.pde.internal.runtime.spy.SpyFormToolkit;
017: import org.eclipse.pde.internal.runtime.spy.sections.ActivePartSection;
018: import org.eclipse.pde.internal.runtime.spy.sections.ActivePreferenceDialogSection;
019: import org.eclipse.pde.internal.runtime.spy.sections.ActiveSelectionSection;
020: import org.eclipse.pde.internal.runtime.spy.sections.ActiveShellSection;
021: import org.eclipse.pde.internal.runtime.spy.sections.ActiveWizardSection;
022: import org.eclipse.pde.internal.runtime.spy.sections.ISpySection;
023: import org.eclipse.swt.SWT;
024: import org.eclipse.swt.graphics.Image;
025: import org.eclipse.swt.graphics.Point;
026: import org.eclipse.swt.graphics.Rectangle;
027: import org.eclipse.swt.widgets.Composite;
028: import org.eclipse.swt.widgets.Control;
029: import org.eclipse.swt.widgets.Shell;
030: import org.eclipse.ui.forms.widgets.ScrolledForm;
031: import org.eclipse.ui.forms.widgets.TableWrapLayout;
032:
033: public class SpyDialog extends PopupDialog {
034:
035: private ExecutionEvent event;
036: private Point fAnchor;
037: private Composite composite;
038: private SpyFormToolkit toolkit;
039:
040: public SpyDialog(Shell parent, ExecutionEvent event, Point point) {
041: super (parent, SWT.NONE, true, false, false, false, null, null);
042: this .event = event;
043: this .fAnchor = point;
044: this .toolkit = new SpyFormToolkit(this );
045: }
046:
047: protected Control createContents(Composite parent) {
048: getShell().setBackground(
049: getShell().getDisplay().getSystemColor(
050: SWT.COLOR_DARK_GRAY));
051: initializeBounds();
052: return createDialogArea(parent);
053: }
054:
055: protected Control createDialogArea(Composite parent) {
056: this .composite = (Composite) super .createDialogArea(parent);
057:
058: ScrolledForm form = toolkit.createScrolledForm(composite);
059: toolkit.decorateFormHeading(form.getForm());
060:
061: // set title and image
062: form.setText(PDERuntimeMessages.SpyDialog_title);
063: Image image = PDERuntimePluginImages
064: .get(PDERuntimePluginImages.IMG_SPY_OBJ);
065: form.setImage(image);
066:
067: TableWrapLayout layout = new TableWrapLayout();
068: layout.leftMargin = 10;
069: layout.rightMargin = 10;
070: layout.topMargin = 10;
071: layout.verticalSpacing = 10;
072: form.getBody().setLayout(layout);
073:
074: // TODO, make this so we use an extension point.
075: ISpySection section = new ActiveShellSection();
076: section.build(form, toolkit, event);
077:
078: section = new ActivePartSection();
079: section.build(form, toolkit, event);
080:
081: section = new ActiveSelectionSection();
082: section.build(form, toolkit, event);
083:
084: section = new ActiveWizardSection();
085: section.build(form, toolkit, event);
086:
087: section = new ActivePreferenceDialogSection();
088: section.build(form, toolkit, event);
089:
090: // section = new ActiveHelpSection();
091: // section.build(form, toolkit, event);
092:
093: parent.pack();
094: return composite;
095: }
096:
097: protected Point getInitialLocation(Point initialSize) {
098: if (fAnchor == null) {
099: return super .getInitialLocation(initialSize);
100: }
101: Point point = fAnchor;
102: Rectangle monitor = getShell().getMonitor().getClientArea();
103: if (monitor.width < point.x + initialSize.x) {
104: point.x = Math.max(0, point.x - initialSize.x);
105: }
106: if (monitor.height < point.y + initialSize.y) {
107: point.y = Math.max(0, point.y - initialSize.y);
108: }
109: return point;
110: }
111:
112: public boolean close() {
113: toolkit.dispose();
114: return super .close();
115: }
116:
117: protected Control getFocusControl() {
118: return this.composite;
119: }
120:
121: }
|