KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > ui > launcher > MainTab


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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 package org.eclipse.pde.ui.launcher;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.debug.core.ILaunchConfiguration;
15 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
16 import org.eclipse.jface.dialogs.Dialog;
17 import org.eclipse.pde.internal.ui.IHelpContextIds;
18 import org.eclipse.pde.internal.ui.PDEPlugin;
19 import org.eclipse.pde.internal.ui.PDEPluginImages;
20 import org.eclipse.pde.internal.ui.PDEUIMessages;
21 import org.eclipse.pde.internal.ui.launcher.JREBlock;
22 import org.eclipse.pde.internal.ui.launcher.ProgramBlock;
23 import org.eclipse.pde.internal.ui.launcher.WorkspaceDataBlock;
24 import org.eclipse.pde.ui.launcher.AbstractLauncherTab;
25 import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.custom.ScrolledComposite;
28 import org.eclipse.swt.graphics.Image;
29 import org.eclipse.swt.graphics.Point;
30 import org.eclipse.swt.graphics.Rectangle;
31 import org.eclipse.swt.layout.GridData;
32 import org.eclipse.swt.layout.GridLayout;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Control;
35 import org.eclipse.swt.widgets.Event;
36 import org.eclipse.swt.widgets.Listener;
37 import org.eclipse.ui.PlatformUI;
38
39
40 /**
41  * A launch configuration tab that displays and edits the main launching arguments
42  * of an Eclipse application.
43  * <p>
44  * This class may be instantiated. This class is not intended to be subclassed by clients.
45  * </p>
46  * @since 3.2
47  */

48 public class MainTab extends AbstractLauncherTab implements IPDELauncherConstants {
49     
50     protected WorkspaceDataBlock fDataBlock;
51     protected ProgramBlock fProgramBlock;
52     protected JREBlock fJreBlock;
53     
54     private Image fImage;
55
56     public MainTab() {
57         createWorkspaceDataBlock();
58         createProgramBlock();
59         fJreBlock = new JREBlock(this);
60         fImage = PDEPluginImages.DESC_MAIN_TAB.createImage();
61     }
62
63     /*
64      * (non-Javadoc)
65      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#dispose()
66      */

67     public void dispose() {
68         fImage.dispose();
69         super.dispose();
70     }
71
72     /*
73      * (non-Javadoc)
74      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
75      */

76     public void createControl(Composite parent) {
77         final ScrolledComposite scrollContainer = new ScrolledComposite(parent, SWT.V_SCROLL);
78         scrollContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
79         
80         Composite composite = new Composite(scrollContainer, SWT.NONE);
81         scrollContainer.setContent(composite);
82         composite.setLayout(new GridLayout());
83         composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
84         
85         fDataBlock.createControl(composite);
86         fProgramBlock.createControl(composite);
87         fJreBlock.createControl(composite);
88         
89         // Add listener for each control to recalculate scroll bar when it is entered.
90
// This results in scrollbar scrolling when user tabs to a control that is not in the field of view.
91
Listener listener = new Listener() {
92             public void handleEvent(Event e) {
93                 Control child = (Control)e.widget;
94                 Rectangle bounds = child.getBounds();
95                 Rectangle area = scrollContainer.getClientArea();
96                 Point origin = scrollContainer.getOrigin();
97                 if (origin.x > bounds.x) origin.x = Math.max(0, bounds.x);
98                 if (origin.y > bounds.y) origin.y = Math.max(0, bounds.y);
99                 if (origin.x + area.width < bounds.x + bounds.width) origin.x = Math.max(0, bounds.x + bounds.width - area.width);
100                 if (origin.y + area.height < bounds.y + bounds.height) origin.y = Math.max(0, bounds.y + bounds.height - area.height);
101                 scrollContainer.setOrigin(origin);
102             }
103         };
104         Control[] controls = composite.getChildren();
105         for (int i = 0; i < controls.length; i++)
106             controls[i].addListener(SWT.Activate, listener);
107                 
108         composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
109         scrollContainer.setExpandHorizontal(true);
110         setControl(scrollContainer);
111         Dialog.applyDialogFont(composite);
112         PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.LAUNCHER_BASIC);
113     }
114     
115     /*
116      * (non-Javadoc)
117      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
118      */

119     public void initializeFrom(ILaunchConfiguration config) {
120         try {
121             fDataBlock.initializeFrom(config);
122             fProgramBlock.initializeFrom(config);
123             fJreBlock.initializeFrom(config);
124         } catch (CoreException e) {
125             PDEPlugin.logException(e);
126         } finally {
127         }
128     }
129     
130     /*
131      * (non-Javadoc)
132      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
133      */

134     public void setDefaults(ILaunchConfigurationWorkingCopy config) {
135         fDataBlock.setDefaults(config, false);
136         fProgramBlock.setDefaults(config);
137         fJreBlock.setDefaults(config);
138     }
139     
140     /*
141      * (non-Javadoc)
142      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
143      */

144     public void performApply(ILaunchConfigurationWorkingCopy config) {
145         fDataBlock.performApply(config);
146         fProgramBlock.performApply(config);
147         fJreBlock.performApply(config);
148     }
149     
150     /*
151      * (non-Javadoc)
152      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
153      */

154     public String JavaDoc getName() {
155         return PDEUIMessages.MainTab_name;
156     }
157     
158     /*
159      * (non-Javadoc)
160      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
161      */

162     public Image getImage() {
163         return fImage;
164     }
165     
166     /**
167      * Creates the Workspace Data group on the tab
168      */

169     protected void createWorkspaceDataBlock() {
170         fDataBlock = new WorkspaceDataBlock(this);
171     }
172     
173     /**
174      * Creates the Program To Run group on the tab
175      *
176      */

177     protected void createProgramBlock() {
178         fProgramBlock = new ProgramBlock(this);
179     }
180
181     /*
182      * (non-Javadoc)
183      * @see org.eclipse.pde.ui.launcher.AbstractLauncherTab#validateTab()
184      */

185     public void validateTab() {
186         setErrorMessage(fDataBlock.validate());
187     }
188     
189 }
190
Popular Tags