001: /*******************************************************************************
002: * Copyright (c) 2005, 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: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.ui.launcher;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.debug.core.ILaunchConfiguration;
014: import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
015: import org.eclipse.jface.dialogs.Dialog;
016: import org.eclipse.pde.internal.ui.IHelpContextIds;
017: import org.eclipse.pde.internal.ui.PDEPlugin;
018: import org.eclipse.pde.internal.ui.PDEPluginImages;
019: import org.eclipse.pde.internal.ui.PDEUIMessages;
020: import org.eclipse.pde.internal.ui.launcher.JREBlock;
021: import org.eclipse.pde.internal.ui.launcher.ProgramBlock;
022: import org.eclipse.pde.internal.ui.launcher.WorkspaceDataBlock;
023: import org.eclipse.pde.ui.launcher.AbstractLauncherTab;
024: import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
025: import org.eclipse.swt.SWT;
026: import org.eclipse.swt.custom.ScrolledComposite;
027: import org.eclipse.swt.graphics.Image;
028: import org.eclipse.swt.graphics.Point;
029: import org.eclipse.swt.graphics.Rectangle;
030: import org.eclipse.swt.layout.GridData;
031: import org.eclipse.swt.layout.GridLayout;
032: import org.eclipse.swt.widgets.Composite;
033: import org.eclipse.swt.widgets.Control;
034: import org.eclipse.swt.widgets.Event;
035: import org.eclipse.swt.widgets.Listener;
036: import org.eclipse.ui.PlatformUI;
037:
038: /**
039: * A launch configuration tab that displays and edits the main launching arguments
040: * of an Eclipse application.
041: * <p>
042: * This class may be instantiated. This class is not intended to be subclassed by clients.
043: * </p>
044: * @since 3.2
045: */
046: public class MainTab extends AbstractLauncherTab implements
047: IPDELauncherConstants {
048:
049: protected WorkspaceDataBlock fDataBlock;
050: protected ProgramBlock fProgramBlock;
051: protected JREBlock fJreBlock;
052:
053: private Image fImage;
054:
055: public MainTab() {
056: createWorkspaceDataBlock();
057: createProgramBlock();
058: fJreBlock = new JREBlock(this );
059: fImage = PDEPluginImages.DESC_MAIN_TAB.createImage();
060: }
061:
062: /*
063: * (non-Javadoc)
064: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#dispose()
065: */
066: public void dispose() {
067: fImage.dispose();
068: super .dispose();
069: }
070:
071: /*
072: * (non-Javadoc)
073: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
074: */
075: public void createControl(Composite parent) {
076: final ScrolledComposite scrollContainer = new ScrolledComposite(
077: parent, SWT.V_SCROLL);
078: scrollContainer.setLayoutData(new GridData(
079: GridData.FILL_HORIZONTAL));
080:
081: Composite composite = new Composite(scrollContainer, SWT.NONE);
082: scrollContainer.setContent(composite);
083: composite.setLayout(new GridLayout());
084: composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
085:
086: fDataBlock.createControl(composite);
087: fProgramBlock.createControl(composite);
088: fJreBlock.createControl(composite);
089:
090: // Add listener for each control to recalculate scroll bar when it is entered.
091: // This results in scrollbar scrolling when user tabs to a control that is not in the field of view.
092: Listener listener = new Listener() {
093: public void handleEvent(Event e) {
094: Control child = (Control) e.widget;
095: Rectangle bounds = child.getBounds();
096: Rectangle area = scrollContainer.getClientArea();
097: Point origin = scrollContainer.getOrigin();
098: if (origin.x > bounds.x)
099: origin.x = Math.max(0, bounds.x);
100: if (origin.y > bounds.y)
101: origin.y = Math.max(0, bounds.y);
102: if (origin.x + area.width < bounds.x + bounds.width)
103: origin.x = Math.max(0, bounds.x + bounds.width
104: - area.width);
105: if (origin.y + area.height < bounds.y + bounds.height)
106: origin.y = Math.max(0, bounds.y + bounds.height
107: - area.height);
108: scrollContainer.setOrigin(origin);
109: }
110: };
111: Control[] controls = composite.getChildren();
112: for (int i = 0; i < controls.length; i++)
113: controls[i].addListener(SWT.Activate, listener);
114:
115: composite.setSize(composite.computeSize(SWT.DEFAULT,
116: SWT.DEFAULT));
117: scrollContainer.setExpandHorizontal(true);
118: setControl(scrollContainer);
119: Dialog.applyDialogFont(composite);
120: PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
121: IHelpContextIds.LAUNCHER_BASIC);
122: }
123:
124: /*
125: * (non-Javadoc)
126: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
127: */
128: public void initializeFrom(ILaunchConfiguration config) {
129: try {
130: fDataBlock.initializeFrom(config);
131: fProgramBlock.initializeFrom(config);
132: fJreBlock.initializeFrom(config);
133: } catch (CoreException e) {
134: PDEPlugin.logException(e);
135: } finally {
136: }
137: }
138:
139: /*
140: * (non-Javadoc)
141: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
142: */
143: public void setDefaults(ILaunchConfigurationWorkingCopy config) {
144: fDataBlock.setDefaults(config, false);
145: fProgramBlock.setDefaults(config);
146: fJreBlock.setDefaults(config);
147: }
148:
149: /*
150: * (non-Javadoc)
151: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
152: */
153: public void performApply(ILaunchConfigurationWorkingCopy config) {
154: fDataBlock.performApply(config);
155: fProgramBlock.performApply(config);
156: fJreBlock.performApply(config);
157: }
158:
159: /*
160: * (non-Javadoc)
161: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
162: */
163: public String getName() {
164: return PDEUIMessages.MainTab_name;
165: }
166:
167: /*
168: * (non-Javadoc)
169: * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
170: */
171: public Image getImage() {
172: return fImage;
173: }
174:
175: /**
176: * Creates the Workspace Data group on the tab
177: */
178: protected void createWorkspaceDataBlock() {
179: fDataBlock = new WorkspaceDataBlock(this );
180: }
181:
182: /**
183: * Creates the Program To Run group on the tab
184: *
185: */
186: protected void createProgramBlock() {
187: fProgramBlock = new ProgramBlock(this );
188: }
189:
190: /*
191: * (non-Javadoc)
192: * @see org.eclipse.pde.ui.launcher.AbstractLauncherTab#validateTab()
193: */
194: public void validateTab() {
195: String error = fDataBlock.validate();
196: if (error == null)
197: error = fJreBlock.validate();
198: setErrorMessage(error);
199: }
200:
201: }
|