KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.ant.internal.ui.AntUtil;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.debug.core.ILaunchConfiguration;
16 import org.eclipse.debug.ui.ILaunchConfigurationTab;
17 import org.eclipse.jdt.debug.ui.launchConfigurations.JavaClasspathTab;
18 import org.eclipse.jdt.internal.debug.ui.actions.AddExternalJarAction;
19 import org.eclipse.jdt.internal.debug.ui.actions.AddFolderAction;
20 import org.eclipse.jdt.internal.debug.ui.actions.AddJarAction;
21 import org.eclipse.jdt.internal.debug.ui.actions.MoveDownAction;
22 import org.eclipse.jdt.internal.debug.ui.actions.MoveUpAction;
23 import org.eclipse.jdt.internal.debug.ui.actions.RemoveAction;
24 import org.eclipse.jdt.internal.debug.ui.actions.RestoreDefaultEntriesAction;
25 import org.eclipse.jdt.internal.debug.ui.actions.RuntimeClasspathAction;
26 import org.eclipse.jdt.internal.debug.ui.classpath.ClasspathEntry;
27 import org.eclipse.jdt.internal.debug.ui.classpath.ClasspathModel;
28 import org.eclipse.jdt.internal.debug.ui.classpath.IClasspathEntry;
29 import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer;
30 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
31 import org.eclipse.swt.widgets.Button;
32 import org.eclipse.swt.widgets.Composite;
33
34 /**
35  * The Ant classpath tab
36  */

37 public class AntClasspathTab extends JavaClasspathTab {
38     
39     
40     /* (non-Javadoc)
41      * @see org.eclipse.jdt.debug.ui.launchConfigurations.JavaClasspathTab#isShowBootpath()
42      */

43     public boolean isShowBootpath() {
44         return false;
45     }
46     
47     /**
48      * Creates actions to manipulate the classpath.
49      *
50      * @param pathButtonComp composite buttons are contained in
51      * @since 3.0
52      */

53     protected void createPathButtons(Composite pathButtonComp) {
54         createButton(pathButtonComp, new MoveUpAction(fClasspathViewer));
55         createButton(pathButtonComp, new MoveDownAction(fClasspathViewer));
56         createButton(pathButtonComp, new RemoveAction(fClasspathViewer));
57         createButton(pathButtonComp, new AddJarAction(fClasspathViewer));
58         createButton(pathButtonComp, new AddExternalJarAction(fClasspathViewer, DIALOG_SETTINGS_PREFIX));
59         Button button = createButton(pathButtonComp, new AddFolderAction(fClasspathViewer));
60         button.setText(AntLaunchConfigurationMessages.AntClasspathTab_0);
61         createButton(pathButtonComp, new AddVariableStringAction(fClasspathViewer));
62         RuntimeClasspathAction action= new RestoreDefaultEntriesAction(fClasspathViewer, this);
63         createButton(pathButtonComp, action);
64         action.setEnabled(true);
65         
66         action= new EditAntHomeEntryAction(fClasspathViewer, this);
67         createButton(pathButtonComp, action);
68         action.setEnabled(true);
69     }
70     
71     /* (non-Javadoc)
72      * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#setDirty(boolean)
73      */

74     public void setDirty(boolean dirty) {
75         super.setDirty(dirty);
76     }
77     
78     
79     /* (non-Javadoc)
80      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
81      */

82     public void initializeFrom(ILaunchConfiguration configuration) {
83         try {
84             AntUtil.migrateToNewClasspathFormat(configuration);
85         } catch (CoreException e) {
86         }
87         super.initializeFrom(configuration);
88     }
89     /* (non-Javadoc)
90      * @see org.eclipse.jdt.internal.debug.ui.launcher.IEntriesChangedListener#entriesChanged(org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer)
91      */

92     public void entriesChanged(IClasspathViewer viewer) {
93         super.entriesChanged(viewer);
94         ILaunchConfigurationTab[] tabs = getLaunchConfigurationDialog().getTabs();
95         for (int i = 0; i < tabs.length; i++) {
96             ILaunchConfigurationTab tab = tabs[i];
97             if (tab instanceof AntTargetsTab) {
98                 ((AntTargetsTab)tab).setDirty(true);
99             }
100         }
101     }
102     
103     /* (non-Javadoc)
104      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
105      */

106     public boolean isValid(ILaunchConfiguration launchConfig) {
107         
108         boolean valid= super.isValid(launchConfig);
109         if (!valid) {
110             return false;
111         }
112         
113         return validateAntHome();
114     }
115     
116     private boolean validateAntHome() {
117         ClasspathModel model= getModel();
118         IClasspathEntry userEntry= model.getUserEntry();
119         IClasspathEntry[] entries= userEntry.getEntries();
120         for (int i = 0; i < entries.length; i++) {
121             ClasspathEntry entry = (ClasspathEntry) entries[i];
122             IRuntimeClasspathEntry runtimeEntry= entry.getDelegate();
123             if (runtimeEntry instanceof AntHomeClasspathEntry) {
124                 try {
125                     ((AntHomeClasspathEntry)runtimeEntry).resolveAntHome();
126                 } catch (CoreException ce) {
127                     setErrorMessage(ce.getStatus().getMessage());
128                     return false;
129                 }
130                 break;
131             }
132         }
133         return true;
134     }
135 }
136
Popular Tags