1 11 package org.eclipse.ant.internal.ui.launchConfigurations; 12 13 import java.util.HashMap ; 14 import java.util.List ; 15 import java.util.Map ; 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 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 97 public Image getImage() { 98 return AntUIImages.getImage(IAntUIConstants.IMG_PROPERTY); 99 } 100 101 104 public String getName() { 105 return AntLaunchConfigurationMessages.AntPropertiesTab_P_roperties_8; 106 } 107 108 111 public void initializeFrom(ILaunchConfiguration configuration) { 112 fSeparateJRE= AntUtil.isSeparateJREAntBuild(configuration); 113 setErrorMessage(null); 114 setMessage(null); 115 Map properties= null; 116 try { 117 properties= configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, (Map )null); 118 } catch (CoreException ce) { 119 AntUIPlugin.log(AntLaunchConfigurationMessages.AntPropertiesTab_Error_reading_configuration_9, ce); 120 } 121 122 String propertyFiles= null; 123 try { 124 propertyFiles= configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTY_FILES, (String )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 [] files= AntUtil.parseString(propertyFiles, ","); fAntPropertiesBlock.setPropertyFilesInput(files); 137 } 138 139 toggleUseDefaultProperties(); 140 } 141 142 private void initializeAsGlobal(boolean separateVM) { 143 AntCorePreferences prefs = AntCorePlugin.getPlugin().getPreferences(); 144 List 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 159 public void performApply(ILaunchConfigurationWorkingCopy configuration) { 160 if (fUseDefaultButton.getSelection()) { 161 configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, (Map )null); 162 configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTY_FILES, (String )null); 163 return; 164 } 165 166 Object [] items= fAntPropertiesBlock.getProperties(); 167 Map properties= null; 168 if (items.length > 0) { 169 properties= new HashMap (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 files= null; 180 if (items.length > 0) { 181 StringBuffer buff= new StringBuffer (); 182 for (int i = 0; i < items.length; i++) { 183 String path = (String )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 196 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { 197 } 198 199 202 public void setMessage(String message) { 203 super.setMessage(message); 204 } 205 206 209 public void setErrorMessage(String message) { 210 super.setErrorMessage(message); 211 } 212 213 216 public Button createPushButton(Composite parent, String buttonText) { 217 return super.createPushButton(parent, buttonText, null); 218 } 219 220 223 public void update() { 224 updateTargetsTab(); 225 updateLaunchConfigurationDialog(); 226 } 227 228 private void updateTargetsTab() { 229 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 244 public void activated(ILaunchConfigurationWorkingCopy workingCopy) { 245 if (fSeparateJRE != AntUtil.isSeparateJREAntBuild(workingCopy)) { 246 initializeFrom(workingCopy); 248 } 249 } 250 251 254 public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) { 255 } 256 } 257 | Popular Tags |