1 11 package org.eclipse.ant.internal.ui.launchConfigurations; 12 13 import org.eclipse.ant.internal.ui.AntUIPlugin; 14 import org.eclipse.ant.internal.ui.AntUtil; 15 import org.eclipse.ant.internal.ui.IAntUIConstants; 16 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds; 17 import org.eclipse.core.resources.IFile; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.resources.ResourcesPlugin; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.variables.IStringVariableManager; 22 import org.eclipse.core.variables.VariablesPlugin; 23 import org.eclipse.debug.core.ILaunchConfiguration; 24 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 25 import org.eclipse.debug.ui.ILaunchConfigurationTab; 26 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 27 import org.eclipse.jface.dialogs.Dialog; 28 import org.eclipse.jface.viewers.IStructuredSelection; 29 import org.eclipse.swt.SWT; 30 import org.eclipse.swt.events.SelectionAdapter; 31 import org.eclipse.swt.events.SelectionEvent; 32 import org.eclipse.swt.layout.GridData; 33 import org.eclipse.swt.layout.GridLayout; 34 import org.eclipse.swt.widgets.Button; 35 import org.eclipse.swt.widgets.Composite; 36 import org.eclipse.ui.PlatformUI; 37 import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsMainTab; 38 import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants; 39 import org.eclipse.ui.externaltools.internal.ui.FileSelectionDialog; 40 41 public class AntMainTab extends ExternalToolsMainTab { 42 43 private String fCurrentLocation= null; 44 private Button fSetInputHandlerButton; 45 private IFile fNewFile; 46 47 50 public void initializeFrom(ILaunchConfiguration configuration) { 51 super.initializeFrom(configuration); 52 try { 53 fCurrentLocation= configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String )null); 54 } catch (CoreException e) { 55 } 56 updateCheckButtons(configuration); 57 } 58 59 62 public void performApply(ILaunchConfigurationWorkingCopy configuration) { 63 super.performApply(configuration); 64 try { 65 String newLocation= configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String )null); 67 if (newLocation != null) { 68 if (!newLocation.equals(fCurrentLocation)) { 69 updateTargetsTab(); 70 fCurrentLocation= newLocation; 71 updateProjectName(configuration); 72 } 73 } else if (fCurrentLocation != null){ 74 updateTargetsTab(); 75 fCurrentLocation= newLocation; 76 updateProjectName(configuration); 77 } 78 } catch (CoreException e) { 79 } 80 81 setMappedResources(configuration); 82 setAttribute(IAntUIConstants.SET_INPUTHANDLER, configuration, fSetInputHandlerButton.getSelection(), true); 83 } 84 85 private void setMappedResources(ILaunchConfigurationWorkingCopy configuration) { 86 IFile file= getIFile(configuration); 87 configuration.setMappedResources(new IResource[] {file}); 88 } 89 90 private void updateProjectName(ILaunchConfigurationWorkingCopy configuration) { 91 IFile file = getIFile(configuration); 92 String projectName= ""; if (file != null) { 94 projectName= file.getProject().getName(); 95 } 96 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName); 97 } 98 99 private IFile getIFile(ILaunchConfigurationWorkingCopy configuration) { 100 IFile file= null; 101 if (fNewFile != null) { 102 file= fNewFile; 103 fNewFile= null; 104 } else { 105 IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); 106 try { 107 String location= configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String )null); 108 if (location != null) { 109 String expandedLocation= manager.performStringSubstitution(location); 110 if (expandedLocation != null) { 111 file= AntUtil.getFileForLocation(expandedLocation, null); 112 } 113 } 114 } catch (CoreException e) { 115 } 116 } 117 return file; 118 } 119 120 123 public void createControl(Composite parent) { 124 Composite mainComposite = new Composite(parent, SWT.NONE); 125 setControl(mainComposite); 126 PlatformUI.getWorkbench().getHelpSystem().setHelp(mainComposite, IAntUIHelpContextIds.ANT_MAIN_TAB); 127 GridLayout layout = new GridLayout(); 128 layout.numColumns = 1; 129 GridData gridData = new GridData(GridData.FILL_HORIZONTAL); 130 mainComposite.setLayout(layout); 131 mainComposite.setLayoutData(gridData); 132 mainComposite.setFont(parent.getFont()); 133 createLocationComponent(mainComposite); 134 createWorkDirectoryComponent(mainComposite); 135 createArgumentComponent(mainComposite); 136 createVerticalSpacer(mainComposite, 2); 137 createSetInputHandlerComponent(mainComposite); 138 Dialog.applyDialogFont(parent); 139 } 140 141 147 private void createSetInputHandlerComponent(Composite parent) { 148 fSetInputHandlerButton = createCheckButton(parent, AntLaunchConfigurationMessages.AntMainTab_0); 149 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); 150 data.horizontalSpan = 2; 151 fSetInputHandlerButton.setLayoutData(data); 152 fSetInputHandlerButton.addSelectionListener(new SelectionAdapter() { 153 public void widgetSelected(SelectionEvent e) { 154 updateLaunchConfigurationDialog(); 155 } 156 }); 157 } 158 159 private void updateCheckButtons(ILaunchConfiguration configuration) { 160 boolean setInputHandler= true; 161 try { 162 setInputHandler= configuration.getAttribute(IAntUIConstants.SET_INPUTHANDLER, true); 163 } catch (CoreException ce) { 164 AntUIPlugin.log(AntLaunchConfigurationMessages.AntMainTab_1, ce); 165 } 166 fSetInputHandlerButton.setSelection(setInputHandler); 167 } 168 169 172 protected void handleWorkspaceLocationButtonSelected() { 173 FileSelectionDialog dialog; 174 dialog = new FileSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), AntLaunchConfigurationMessages.AntMainTab__Select_a_build_file__1); 175 dialog.open(); 176 IStructuredSelection result = dialog.getResult(); 177 if (result == null) { 178 return; 179 } 180 Object file= result.getFirstElement(); 181 if (file instanceof IFile) { 182 fNewFile= (IFile)file; 183 locationField.setText(VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression("workspace_loc", fNewFile.getFullPath().toString())); } 185 } 186 187 190 protected String getWorkingDirectoryLabel() { 191 return AntLaunchConfigurationMessages.AntMainTab_3; 192 } 193 194 private void updateTargetsTab() { 195 ILaunchConfigurationTab[] tabs= getLaunchConfigurationDialog().getTabs(); 198 for (int i = 0; i < tabs.length; i++) { 199 ILaunchConfigurationTab tab = tabs[i]; 200 if (tab instanceof AntTargetsTab) { 201 ((AntTargetsTab)tab).setDirty(true); 202 break; 203 } 204 } 205 } 206 207 210 protected String getLocationLabel() { 211 return AntLaunchConfigurationMessages.AntMainTab_6; 212 } 213 } 214 | Popular Tags |