KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > ui > sourcelookup > SourceLookupDialog


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.debug.ui.sourcelookup;
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.debug.core.sourcelookup.ISourceLookupDirector;
17 import org.eclipse.debug.internal.ui.DebugPluginImages;
18 import org.eclipse.debug.internal.ui.DebugUIPlugin;
19 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
20 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
21 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupPanel;
22 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIMessages;
23 import org.eclipse.jface.dialogs.Dialog;
24 import org.eclipse.jface.dialogs.IDialogConstants;
25 import org.eclipse.jface.dialogs.IDialogSettings;
26 import org.eclipse.jface.dialogs.TitleAreaDialog;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Shell;
33 import org.eclipse.ui.PlatformUI;
34
35 /**
36  * A dialog for editing the source lookup path of a
37  * source lookup director.
38  * <p>
39  * This class may be instantiated; it is not intended to be
40  * subclassed.
41  * </p>
42  * @since 3.0
43  */

44 public class SourceLookupDialog extends TitleAreaDialog {
45     
46     private SourceLookupPanel fPanel;
47     private ISourceLookupDirector fDirector;
48     
49     /**
50      * Constructs a dialog to edit the source lookup path managed by the
51      * given source lookup director. Persists the resulting source lookup
52      * path on the launch configuration associated with the given source
53      * lookup director.
54      *
55      * @param shell shell to parent the dialog
56      * @param director source lookup director managing the source lookup
57      * path to be edited
58      */

59     public SourceLookupDialog(Shell shell, ISourceLookupDirector director) {
60         super(shell);
61         setShellStyle(getShellStyle() | SWT.RESIZE);
62         fDirector = director;
63     }
64     
65     /* (non-Javadoc)
66      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
67      */

68     protected Control createDialogArea(Composite parent) {
69         // create a composite with standard margins and spacing
70
setTitle(SourceLookupUIMessages.manageSourceDialog_description);
71         setTitleImage(DebugPluginImages.getImage(IInternalDebugUIConstants.IMG_EDIT_SRC_LOC_WIZ));
72         Composite composite = new Composite(parent, SWT.NONE);
73         
74         GridLayout layout = new GridLayout();
75         layout.marginHeight =
76             convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
77         layout.marginWidth =
78             convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
79         layout.verticalSpacing =
80             convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
81         layout.horizontalSpacing =
82             convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
83         composite.setLayout(layout);
84         GridData data = new GridData(GridData.FILL_BOTH);
85         composite.setLayoutData(data);
86         composite.setFont(parent.getFont());
87         fPanel = new SourceLookupPanel();
88         fPanel.createControl(composite);
89         fPanel.initializeFrom(fDirector);
90         Dialog.applyDialogFont(composite);
91         ILaunchConfiguration config = fDirector.getLaunchConfiguration();
92         if(config != null && config.isReadOnly()) {
93             setErrorMessage(SourceLookupUIMessages.SourceLookupDialog_0+config.getName()+SourceLookupUIMessages.SourceLookupDialog_1);
94         }
95         PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IDebugHelpContextIds.EDIT_SOURCELOOKUP_DIALOG);
96         
97         return composite;
98     }
99     
100     /* (non-Javadoc)
101      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
102      */

103     protected void okPressed() {
104         ILaunchConfiguration config = fDirector.getLaunchConfiguration();
105         ILaunchConfigurationWorkingCopy copy = null;
106         if(config != null) {
107             try {
108                 copy = config.getWorkingCopy();
109                 fPanel.performApply(copy);
110                 copy.doSave();
111             }
112             catch (CoreException e) {DebugUIPlugin.log(e);}
113         }
114         super.okPressed();
115     }
116     
117     /* (non-Javadoc)
118      * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
119      */

120     protected void configureShell(Shell shell) {
121         super.configureShell(shell);
122         shell.setText(SourceLookupUIMessages.manageSourceDialog_title);
123     }
124     
125     /* (non-Javadoc)
126      * @see org.eclipse.jface.window.Window#close()
127      */

128     public boolean close() {
129         fPanel.dispose();
130         return super.close();
131     }
132     
133     /* (non-Javadoc)
134      * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
135      * @since 3.2
136      */

137     protected IDialogSettings getDialogBoundsSettings() {
138          IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings();
139          IDialogSettings section = settings.getSection(getClass().getName());
140          if (section == null) {
141              section = settings.addNewSection(getClass().getName());
142          }
143          return section;
144     }
145 }
146
Popular Tags