KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > snippeteditor > SnippetEditorPropertyPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.internal.debug.ui.snippeteditor;
12
13
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.debug.core.ILaunchConfiguration;
17 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
18 import org.eclipse.debug.core.ILaunchManager;
19 import org.eclipse.debug.ui.ILaunchConfigurationDialog;
20 import org.eclipse.debug.ui.ILaunchConfigurationTab;
21 import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab;
22 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
23 import org.eclipse.jdt.internal.debug.ui.launcher.VMArgumentsBlock;
24 import org.eclipse.jdt.internal.debug.ui.launcher.WorkingDirectoryBlock;
25 import org.eclipse.jface.operation.IRunnableWithProgress;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Control;
30 import org.eclipse.ui.dialogs.PropertyPage;
31
32 /**
33  * Page to set working directory property on scrapbook page.
34  */

35 public class SnippetEditorPropertyPage extends PropertyPage {
36     
37     private WorkingDirectoryBlock fWorkingDirBlock = new WorkingDirectoryBlock();
38     
39     private JavaJRETab fJRETab = new JavaJRETab();
40     
41     private VMArgumentsBlock fVMArgumentsBlock = new VMArgumentsBlock();
42     
43     // launch config template for this scrapbook file
44
private ILaunchConfiguration fConfig;
45     private ILaunchConfigurationWorkingCopy fWorkingCopy;
46     
47     private Proxy fProxy;
48
49     class Proxy implements ILaunchConfigurationDialog {
50         /* (non-Javadoc)
51          * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#generateName(java.lang.String)
52          */

53         public String JavaDoc generateName(String JavaDoc name) {
54             return null;
55         }
56
57         /* (non-Javadoc)
58          * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#getMode()
59          */

60         public String JavaDoc getMode() {
61             return ILaunchManager.DEBUG_MODE;
62         }
63
64         /* (non-Javadoc)
65          * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#getTabs()
66          */

67         public ILaunchConfigurationTab[] getTabs() {
68             return new ILaunchConfigurationTab[] {fWorkingDirBlock};
69         }
70
71         /* (non-Javadoc)
72          * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#getActiveTab()
73          */

74         public ILaunchConfigurationTab getActiveTab() {
75             return fWorkingDirBlock;
76         }
77
78         /* (non-Javadoc)
79          * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#setName(java.lang.String)
80          */

81         public void setName(String JavaDoc name) {
82         }
83
84         /* (non-Javadoc)
85          * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#updateButtons()
86          */

87         public void updateButtons() {
88             
89         }
90
91         /* (non-Javadoc)
92          * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#updateMessage()
93          */

94         public void updateMessage() {
95             setValid(isValid());
96             setMessage(getMessage());
97             setErrorMessage(getErrorMessage());
98         }
99
100         /* (non-Javadoc)
101          * @see org.eclipse.jface.operation.IRunnableContext#run(boolean, boolean, org.eclipse.jface.operation.IRunnableWithProgress)
102          */

103         public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) {
104         }
105
106         /* (non-Javadoc)
107          * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#setActiveTab(org.eclipse.debug.ui.ILaunchConfigurationTab)
108          */

109         public void setActiveTab(ILaunchConfigurationTab tab) {
110         }
111
112         /* (non-Javadoc)
113          * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#setActiveTab(int)
114          */

115         public void setActiveTab(int index) {
116         }
117     }
118         
119     /* (non-Javadoc)
120      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
121      */

122     protected Control createContents(Composite parent) {
123         Composite comp = new Composite(parent, SWT.NONE);
124         GridLayout topLayout = new GridLayout();
125         topLayout.numColumns = 1;
126         comp.setLayout(topLayout);
127         comp.setFont(parent.getFont());
128         
129         // fake launch config dialog
130
fProxy = new Proxy();
131         
132         try {
133             fConfig = ScrapbookLauncher.getLaunchConfigurationTemplate(getFile());
134             if (fConfig != null) {
135                 fWorkingCopy = fConfig.getWorkingCopy();
136             }
137         } catch (CoreException e) {
138             // unable to retrieve launch config, create a new one
139
fConfig = null;
140             fWorkingCopy = null;
141             JDIDebugUIPlugin.statusDialog(SnippetMessages.getString("ScrapbookLauncher.Unable_to_retrieve_settings"), e.getStatus()); //$NON-NLS-1$
142
}
143
144         if (fConfig == null) {
145             try {
146                 fConfig = ScrapbookLauncher.createLaunchConfigurationTemplate(getFile());
147                 fWorkingCopy = fConfig.getWorkingCopy();
148             } catch (CoreException e) {
149                 JDIDebugUIPlugin.statusDialog(SnippetMessages.getString("ScrapbookLauncher.Unable_to_retrieve_settings"), e.getStatus()); //$NON-NLS-1$
150
}
151         }
152                 
153         fWorkingDirBlock.setLaunchConfigurationDialog(fProxy);
154         fWorkingDirBlock.createControl(comp);
155         fWorkingDirBlock.initializeFrom(fConfig);
156         
157         fVMArgumentsBlock.setLaunchConfigurationDialog(fProxy);
158         fVMArgumentsBlock.createControl(comp);
159         fVMArgumentsBlock.initializeFrom(fConfig);
160         
161         fJRETab.setLaunchConfigurationDialog(fProxy);
162         fJRETab.setVMSpecificArgumentsVisible(false);
163         fJRETab.createControl(comp);
164         fJRETab.initializeFrom(fConfig);
165         
166         return comp;
167     }
168
169     /**
170      * Returns the snippet page (file)
171      */

172     protected IFile getFile() {
173         return (IFile)getElement();
174     }
175     
176     /* (non-Javadoc)
177      * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
178      */

179     protected void performDefaults() {
180         super.performDefaults();
181         fWorkingDirBlock.setDefaults(fWorkingCopy);
182         fJRETab.setDefaults(fWorkingCopy);
183         fVMArgumentsBlock.setDefaults(fWorkingCopy);
184         fWorkingDirBlock.initializeFrom(fWorkingCopy);
185         fJRETab.initializeFrom(fWorkingCopy);
186         fVMArgumentsBlock.initializeFrom(fWorkingCopy);
187     }
188     
189     /* (non-Javadoc)
190      * @see org.eclipse.jface.preference.IPreferencePage#isValid()
191      */

192     public boolean isValid() {
193         return fWorkingDirBlock.isValid(fConfig);
194     }
195
196     /* (non-Javadoc)
197      * @see org.eclipse.jface.dialogs.IDialogPage#getErrorMessage()
198      */

199     public String JavaDoc getErrorMessage() {
200         String JavaDoc message = fWorkingDirBlock.getErrorMessage();
201         if (message == null) {
202             return fJRETab.getErrorMessage();
203         }
204         return message;
205     }
206
207     /* (non-Javadoc)
208      * @see org.eclipse.jface.dialogs.IMessageProvider#getMessage()
209      */

210     public String JavaDoc getMessage() {
211         String JavaDoc message = fWorkingDirBlock.getMessage();
212         if (message == null) {
213             return fJRETab.getMessage();
214         }
215         return message;
216     }
217
218     /* (non-Javadoc)
219      * @see org.eclipse.jface.preference.IPreferencePage#performOk()
220      */

221     public boolean performOk() {
222         fWorkingDirBlock.performApply(fWorkingCopy);
223         fJRETab.performApply(fWorkingCopy);
224         fVMArgumentsBlock.performApply(fWorkingCopy);
225         try {
226             if (!fWorkingCopy.contentsEqual(fConfig)) {
227                 fConfig = fWorkingCopy.doSave();
228                 fWorkingCopy = fConfig.getWorkingCopy();
229             }
230         } catch (CoreException e) {
231             JDIDebugUIPlugin.statusDialog(e.getStatus());
232         }
233         return super.performOk();
234     }
235 }
236
Popular Tags