KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ant.internal.ui.launchConfigurations;
12
13 import com.ibm.icu.text.MessageFormat;
14
15 import org.eclipse.ant.internal.ui.AntUIPlugin;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.debug.core.ILaunchConfiguration;
18 import org.eclipse.jdt.internal.debug.ui.launcher.WorkingDirectoryBlock;
19 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
20 import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
21
22
23 public class AntWorkingDirectoryBlock extends WorkingDirectoryBlock {
24     
25     private String JavaDoc fDefaultWorkingDirPath;
26
27     /**
28      * Returns the default working directory path
29      * @return the default working directory path
30      */

31     public String JavaDoc getDefaultWorkingDirPath() {
32         return fDefaultWorkingDirPath;
33     }
34
35     /* (non-Javadoc)
36      * @see org.eclipse.jdt.internal.debug.ui.launcher.WorkingDirectoryBlock#setDefaultWorkingDir()
37      */

38     protected void setDefaultWorkingDir() {
39         if (fDefaultWorkingDirPath == null) {
40             super.setDefaultWorkingDir();
41             return;
42         }
43         setDefaultWorkingDirectoryText(fDefaultWorkingDirPath);
44     }
45     
46     /* (non-Javadoc)
47      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
48      */

49     public void initializeFrom(ILaunchConfiguration configuration) {
50         setLaunchConfiguration(configuration);
51         try {
52             try {
53                 fDefaultWorkingDirPath= ExternalToolsUtil.getLocation(configuration).removeLastSegments(1).toOSString();
54             }
55             catch(CoreException ce){}
56             String JavaDoc wd = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String JavaDoc)null);
57             setDefaultWorkingDir();
58             if (wd != null || !isSameAsDefault(wd)) {
59                 setOtherWorkingDirectoryText(wd);
60             }
61         } catch (CoreException e) {
62             setErrorMessage(MessageFormat.format(AntLaunchConfigurationMessages.AntWorkingDirectoryBlock_0, new String JavaDoc[] {e.getStatus().getMessage()}));
63             AntUIPlugin.log(e);
64         }
65     }
66     
67     private boolean isSameAsDefault(String JavaDoc workingDir) {
68         return workingDir == null || (workingDir.equals(fDefaultWorkingDirPath) || workingDir.equals(System.getProperty("user.dir"))); //$NON-NLS-1$
69
}
70     
71     /* (non-Javadoc)
72      * @see org.eclipse.jdt.internal.debug.ui.launcher.WorkingDirectoryBlock#setEnabled(boolean)
73      */

74     protected void setEnabled(boolean enabled) {
75         super.setEnabled(enabled);
76     }
77 }
78
Popular Tags