KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > launchConfigurations > AntPropertiesTab


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.ant.internal.ui.launchConfigurations;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.List JavaDoc;
15 import java.util.Map JavaDoc;
16 import org.eclipse.ant.core.AntCorePlugin;
17 import org.eclipse.ant.core.AntCorePreferences;
18 import org.eclipse.ant.core.Property;
19 import org.eclipse.ant.internal.ui.AntUIImages;
20 import org.eclipse.ant.internal.ui.AntUIPlugin;
21 import org.eclipse.ant.internal.ui.AntUtil;
22 import org.eclipse.ant.internal.ui.IAntUIConstants;
23 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
24 import org.eclipse.ant.internal.ui.preferences.AntPropertiesBlock;
25 import org.eclipse.ant.internal.ui.preferences.IAntBlockContainer;
26 import org.eclipse.core.runtime.CoreException;
27 import org.eclipse.debug.core.ILaunchConfiguration;
28 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
29 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
30 import org.eclipse.debug.ui.ILaunchConfigurationTab;
31 import org.eclipse.jface.dialogs.Dialog;
32 import org.eclipse.swt.SWT;
33 import org.eclipse.swt.events.SelectionAdapter;
34 import org.eclipse.swt.events.SelectionEvent;
35 import org.eclipse.swt.graphics.Image;
36 import org.eclipse.swt.layout.GridData;
37 import org.eclipse.swt.layout.GridLayout;
38 import org.eclipse.swt.widgets.Button;
39 import org.eclipse.swt.widgets.Composite;
40 import org.eclipse.ui.PlatformUI;
41
42 /**
43  * Tab for setting Ant user properties per launch configuration. All properties
44  * specified here will be set as user properties on the project for the
45  * specified Ant build
46  */

47 public class AntPropertiesTab extends AbstractLaunchConfigurationTab implements IAntBlockContainer {
48     
49     private Button fUseDefaultButton;
50     private AntPropertiesBlock fAntPropertiesBlock= new AntPropertiesBlock(this);
51     private boolean fSeparateJRE= true;
52     
53     public void createControl(Composite parent) {
54         Composite top = new Composite(parent, SWT.NONE);
55         top.setFont(parent.getFont());
56         setControl(top);
57         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IAntUIHelpContextIds.ANT_PROPERTIES_TAB);
58
59         top.setLayout(new GridLayout());
60         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
61         top.setLayoutData(gridData);
62         
63         createChangeProperties(top);
64         
65         Composite propertiesBlockComposite= new Composite(top, SWT.NONE);
66         GridLayout layout = new GridLayout();
67         layout.numColumns= 2;
68         propertiesBlockComposite.setLayout(layout);
69         propertiesBlockComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
70         
71         fAntPropertiesBlock.createControl(propertiesBlockComposite, AntLaunchConfigurationMessages.AntPropertiesTab__Properties__6, AntLaunchConfigurationMessages.AntPropertiesTab_Property_f_iles__7);
72         
73         Dialog.applyDialogFont(top);
74     }
75     
76     private void createChangeProperties(Composite top) {
77         fUseDefaultButton= createCheckButton(top, AntLaunchConfigurationMessages.AntPropertiesTab_6);
78         fUseDefaultButton.addSelectionListener(new SelectionAdapter() {
79             public void widgetSelected(SelectionEvent e) {
80                 toggleUseDefaultProperties();
81                 updateLaunchConfigurationDialog();
82             }
83         });
84     }
85         
86     private void toggleUseDefaultProperties() {
87         boolean enable= !fUseDefaultButton.getSelection();
88         fAntPropertiesBlock.setEnabled(enable);
89         if (!enable) {
90             initializeAsGlobal(fSeparateJRE);
91         }
92     }
93     
94     /**
95      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
96      */

97     public Image getImage() {
98         return AntUIImages.getImage(IAntUIConstants.IMG_PROPERTY);
99     }
100
101     /**
102      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
103      */

104     public String JavaDoc getName() {
105         return AntLaunchConfigurationMessages.AntPropertiesTab_P_roperties_8;
106     }
107
108     /**
109      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
110      */

111     public void initializeFrom(ILaunchConfiguration configuration) {
112         fSeparateJRE= AntUtil.isSeparateJREAntBuild(configuration);
113         setErrorMessage(null);
114         setMessage(null);
115         Map JavaDoc properties= null;
116         try {
117             properties= configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, (Map JavaDoc)null);
118         } catch (CoreException ce) {
119             AntUIPlugin.log(AntLaunchConfigurationMessages.AntPropertiesTab_Error_reading_configuration_9, ce);
120         }
121         
122         String JavaDoc propertyFiles= null;
123         try {
124             propertyFiles= configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTY_FILES, (String JavaDoc)null);
125         } catch (CoreException ce) {
126             AntUIPlugin.log(AntLaunchConfigurationMessages.AntPropertiesTab_Error_reading_configuration_9, ce);
127         }
128         
129         if (properties == null && propertyFiles == null) {
130             initializeAsGlobal(fSeparateJRE);
131         } else {
132             fUseDefaultButton.setSelection(false);
133             fAntPropertiesBlock.populatePropertyViewer(properties);
134         
135             String JavaDoc[] files= AntUtil.parseString(propertyFiles, ","); //$NON-NLS-1$
136
fAntPropertiesBlock.setPropertyFilesInput(files);
137         }
138         
139         toggleUseDefaultProperties();
140     }
141
142     private void initializeAsGlobal(boolean separateVM) {
143         AntCorePreferences prefs = AntCorePlugin.getPlugin().getPreferences();
144         List JavaDoc prefProperties;
145         if (separateVM) {
146             prefProperties= prefs.getRemoteAntProperties();
147         } else {
148             prefProperties= prefs.getProperties();
149         }
150         fAntPropertiesBlock.setPropertiesInput((Property[]) prefProperties.toArray(new Property[prefProperties.size()]));
151         fAntPropertiesBlock.setPropertyFilesInput(AntCorePlugin.getPlugin().getPreferences().getCustomPropertyFiles(false));
152         fAntPropertiesBlock.setTablesEnabled(false);
153         fUseDefaultButton.setSelection(true);
154     }
155     
156     /**
157      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
158      */

159     public void performApply(ILaunchConfigurationWorkingCopy configuration) {
160         if (fUseDefaultButton.getSelection()) {
161             configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, (Map JavaDoc)null);
162             configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTY_FILES, (String JavaDoc)null);
163             return;
164         }
165                 
166         Object JavaDoc[] items= fAntPropertiesBlock.getProperties();
167         Map JavaDoc properties= null;
168         if (items.length > 0) {
169             properties= new HashMap JavaDoc(items.length);
170             for (int i = 0; i < items.length; i++) {
171                 Property property = (Property)items[i];
172                 properties.put(property.getName(), property.getValue(false));
173             }
174         }
175         
176         configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, properties);
177         
178         items= fAntPropertiesBlock.getPropertyFiles();
179         String JavaDoc files= null;
180         if (items.length > 0) {
181             StringBuffer JavaDoc buff= new StringBuffer JavaDoc();
182             for (int i = 0; i < items.length; i++) {
183                 String JavaDoc path = (String JavaDoc)items[i];
184                 buff.append(path);
185                 buff.append(',');
186             }
187             files= buff.toString();
188         }
189         
190         configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTY_FILES, files);
191     }
192
193     /**
194      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
195      */

196     public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
197     }
198     
199     /* (non-Javadoc)
200      * @see org.eclipse.ant.internal.ui.preferences.IAntBlockContainer#createPushButton(org.eclipse.swt.widgets.Composite, java.lang.String)
201      */

202     public void setMessage(String JavaDoc message) {
203         super.setMessage(message);
204     }
205
206     /* (non-Javadoc)
207      * @see org.eclipse.ant.internal.ui.preferences.IAntBlockContainer#createPushButton(org.eclipse.swt.widgets.Composite, java.lang.String)
208      */

209     public void setErrorMessage(String JavaDoc message) {
210         super.setErrorMessage(message);
211     }
212
213     /* (non-Javadoc)
214      * @see org.eclipse.ant.internal.ui.preferences.IAntBlockContainer#createPushButton(org.eclipse.swt.widgets.Composite, java.lang.String)
215      */

216     public Button createPushButton(Composite parent, String JavaDoc buttonText) {
217         return super.createPushButton(parent, buttonText, null);
218     }
219
220     /* (non-Javadoc)
221      * @see org.eclipse.ant.internal.ui.preferences.IAntBlockContainer#createPushButton(org.eclipse.swt.widgets.Composite, java.lang.String)
222      */

223     public void update() {
224         updateTargetsTab();
225         updateLaunchConfigurationDialog();
226     }
227     
228     private void updateTargetsTab() {
229         //the properties have changed...set the targets tab to
230
//need to be recomputed
231
ILaunchConfigurationTab[] tabs= getLaunchConfigurationDialog().getTabs();
232         for (int i = 0; i < tabs.length; i++) {
233             ILaunchConfigurationTab tab = tabs[i];
234             if (tab instanceof AntTargetsTab) {
235                 ((AntTargetsTab)tab).setDirty(true);
236                 break;
237             }
238         }
239     }
240
241     /* (non-Javadoc)
242      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
243      */

244     public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
245         if (fSeparateJRE != AntUtil.isSeparateJREAntBuild(workingCopy)) {
246             //update the properties if changed whether build is in separate JRE
247
initializeFrom(workingCopy);
248         }
249     }
250
251     /* (non-Javadoc)
252      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
253      */

254     public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
255     }
256 }
257
Popular Tags