KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > debug > ui > JavaSourceLookupDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jdt.debug.ui;
12
13
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.debug.core.ILaunchConfiguration;
16 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
17 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
18 import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages;
19 import org.eclipse.jdt.internal.debug.ui.launcher.SourceLookupBlock;
20 import org.eclipse.jface.dialogs.Dialog;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.graphics.Font;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Button;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Control;
28 import org.eclipse.swt.widgets.Display;
29 import org.eclipse.swt.widgets.Label;
30 import org.eclipse.swt.widgets.Shell;
31
32 /**
33  * A dialog to manipulate the source lookup path for a launch
34  * configuration.
35  * <p>
36  * This class may be instantiated; it is not intended to be subclassed.
37  * </p>
38  * @since 2.0.2
39  * @see org.eclipse.jface.dialogs.Dialog
40  * @deprecated In 3.0, the debug platform provides source lookup facilities that
41  * should be used in place of the Java source lookup support provided in 2.0.
42  * The new facilities provide a source lookup director that coordinates source
43  * lookup among a set of participants, searching a set of source containers.
44  * See the following packages: <code>org.eclipse.debug.core.sourcelookup</code>
45  * and <code>org.eclipse.debug.core.sourcelookup.containers</code>. This class
46  * has been replaced by a dialog in the debug platform -
47  * <code>org.eclipse.debug.ui.sourcelookup.SourceLookupDialog</code>.
48  */

49 public class JavaSourceLookupDialog extends Dialog {
50         
51     private SourceLookupBlock fSourceLookupBlock;
52     private ILaunchConfiguration fConfiguration;
53     private String JavaDoc fMessage;
54     private boolean fNotAskAgain;
55     private Button fAskAgainCheckBox;
56     
57     /**
58      * Constructs a dialog to manipulate the source lookup path of the given
59      * launch configuration. The source lookup path is retrieved from the given
60      * launch configuration, based on the attributes
61      * <code>IJavaLaunchConfigurationConstants.ATTR_DEFAULT_SOURCE_PATH</code> and
62      * <code>IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH</code>. If the user
63      * changes the source lookup path and presses "OK", the launch configuration
64      * is updated with the new source lookup path.
65      *
66      * @param shell the shell to open the dialog on
67      * @param message the message to display in the dialog
68      * @param configuration the launch configuration from which the source lookup
69      * path is retrieved and (possibly) updated
70      */

71     public JavaSourceLookupDialog(Shell shell, String JavaDoc message, ILaunchConfiguration configuration) {
72         super(shell);
73         fSourceLookupBlock= new SourceLookupBlock();
74         fMessage = message;
75         fNotAskAgain= false;
76         fAskAgainCheckBox= null;
77         fConfiguration = configuration;
78     }
79     
80     /**
81      * Returns whether the "do not ask again" check box is selected in the dialog.
82      *
83      * @return whether the "do not ask again" check box is selected in the dialog
84      */

85     public boolean isNotAskAgain() {
86         return fNotAskAgain;
87     }
88             
89     /* (non-Javadoc)
90      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
91      */

92     protected Control createDialogArea(Composite parent) {
93         Font font = parent.getFont();
94         initializeDialogUnits(parent);
95         getShell().setText(LauncherMessages.JavaUISourceLocator_selectprojects_title);
96         
97         Composite composite= (Composite) super.createDialogArea(parent);
98         composite.setLayout(new GridLayout());
99         composite.setFont(font);
100         
101         int pixelWidth= convertWidthInCharsToPixels(70);
102         Label message= new Label(composite, SWT.LEFT + SWT.WRAP);
103         message.setText(fMessage);
104         GridData data= new GridData();
105         data.widthHint= pixelWidth;
106         message.setLayoutData(data);
107         message.setFont(font);
108         
109         fSourceLookupBlock.createControl(composite);
110         Control inner = fSourceLookupBlock.getControl();
111         fSourceLookupBlock.initializeFrom(fConfiguration);
112         GridData gd = new GridData(GridData.FILL_BOTH);
113         int height = Display.getCurrent().getBounds().height;
114         gd.heightHint = (int)(0.4f * height);
115         inner.setLayoutData(gd);
116         fAskAgainCheckBox= new Button(composite, SWT.CHECK + SWT.WRAP);
117         data= new GridData();
118         data.widthHint= pixelWidth;
119         fAskAgainCheckBox.setLayoutData(data);
120         fAskAgainCheckBox.setFont(font);
121         fAskAgainCheckBox.setText(LauncherMessages.JavaUISourceLocator_askagain_message);
122         
123         return composite;
124     }
125
126     /* (non-Javadoc)
127      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
128      */

129     protected void okPressed() {
130         try {
131             if (fAskAgainCheckBox != null) {
132                 fNotAskAgain= fAskAgainCheckBox.getSelection();
133             }
134             ILaunchConfigurationWorkingCopy wc = fConfiguration.getWorkingCopy();
135             fSourceLookupBlock.performApply(wc);
136             if (!fConfiguration.contentsEqual(wc)) {
137                 fConfiguration = wc.doSave();
138             }
139         } catch (CoreException e) {
140             JDIDebugUIPlugin.log(e);
141         }
142         super.okPressed();
143     }
144 }
145
Popular Tags