Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 201758 | Differences between
and this patch

Collapse All | Expand All

(-)launching/org/eclipse/jdt/internal/launching/LaunchingMessages.java (+6 lines)
Lines 40-45 Link Here
40
40
41
	public static String EEVMType_1;
41
	public static String EEVMType_1;
42
42
43
	public static String EEVMType_2;
44
45
	public static String EEVMType_3;
46
43
	public static String JavaLocalApplicationLaunchConfigurationDelegate_Verifying_launch_attributes____1;
47
	public static String JavaLocalApplicationLaunchConfigurationDelegate_Verifying_launch_attributes____1;
44
	public static String JavaLocalApplicationLaunchConfigurationDelegate_Creating_source_locator____2;
48
	public static String JavaLocalApplicationLaunchConfigurationDelegate_Creating_source_locator____2;
45
	public static String JavaLocalApplicationLaunchConfigurationDelegate_0;
49
	public static String JavaLocalApplicationLaunchConfigurationDelegate_0;
Lines 53-58 Link Here
53
	public static String JavaRemoteApplicationLaunchConfigurationDelegate_Verifying_launch_attributes____1;
57
	public static String JavaRemoteApplicationLaunchConfigurationDelegate_Verifying_launch_attributes____1;
54
	public static String JavaRemoteApplicationLaunchConfigurationDelegate_Creating_source_locator____2;
58
	public static String JavaRemoteApplicationLaunchConfigurationDelegate_Creating_source_locator____2;
55
59
60
	public static String JavaRuntime_24;
61
56
	public static String JavaRuntime_25;
62
	public static String JavaRuntime_25;
57
63
58
	public static String JavaRuntime_badFormat;
64
	public static String JavaRuntime_badFormat;
(-)launching/org/eclipse/jdt/internal/launching/StandardVMRunner.java (-2 / +8 lines)
Lines 171-181 Link Here
171
		
171
		
172
		// If no java command was specified, use default executable
172
		// If no java command was specified, use default executable
173
		if (command == null) {
173
		if (command == null) {
174
			File exe = StandardVMType.findJavaExecutable(fVMInstance.getInstallLocation());
174
			File exe = null;
175
			if (fVMInstance instanceof StandardVM) {
176
				exe = ((StandardVM)fVMInstance).getJavaExecutable();
177
			} else {
178
				exe = StandardVMType.findJavaExecutable(fVMInstance.getInstallLocation());
179
			}
175
			if (exe == null) {
180
			if (exe == null) {
176
				abort(MessageFormat.format(LaunchingMessages.StandardVMRunner_Unable_to_locate_executable_for__0__1, new String[]{fVMInstance.getName()}), null, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR); 
181
				abort(MessageFormat.format(LaunchingMessages.StandardVMRunner_Unable_to_locate_executable_for__0__1, new String[]{fVMInstance.getName()}), null, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR); 
182
			} else {
183
				return exe.getAbsolutePath();
177
			}
184
			}
178
			return exe.getAbsolutePath();
179
		}
185
		}
180
				
186
				
181
		// Build the path to the java executable.  First try 'bin', and if that
187
		// Build the path to the java executable.  First try 'bin', and if that
(-)launching/org/eclipse/jdt/internal/launching/StandardVM.java (-4 / +16 lines)
Lines 41-50 Link Here
41
        StandardVMType installType = (StandardVMType) getVMInstallType();
41
        StandardVMType installType = (StandardVMType) getVMInstallType();
42
        File installLocation = getInstallLocation();
42
        File installLocation = getInstallLocation();
43
        if (installLocation != null) {
43
        if (installLocation != null) {
44
        	if (EEVMType.isEEInstall(installLocation)) {
44
            File executable = getJavaExecutable();
45
        		return EEVMType.getJavaVersion(installLocation);
46
        	}
47
            File executable = StandardVMType.findJavaExecutable(installLocation);
48
            if (executable != null) {
45
            if (executable != null) {
49
                String vmVersion = installType.getVMVersion(installLocation, executable);
46
                String vmVersion = installType.getVMVersion(installLocation, executable);
50
                // strip off extra info
47
                // strip off extra info
Lines 64-67 Link Here
64
        }
61
        }
65
        return null;
62
        return null;
66
    }
63
    }
64
    
65
    /**
66
     * Returns the java executable for this VM or <code>null</code> if cannot be found
67
     * 
68
     * @return executable for this VM or <code>null</code> if none
69
     */
70
    File getJavaExecutable() {
71
    	File installLocation = getInstallLocation();
72
        if (installLocation != null) {
73
            return StandardVMType.findJavaExecutable(installLocation);
74
        }
75
        return null;
76
    }
77
    
78
    
67
}
79
}
(-)launching/org/eclipse/jdt/internal/launching/EEVMType.java (-45 / +114 lines)
Lines 28-33 Link Here
28
import org.eclipse.core.runtime.IStatus;
28
import org.eclipse.core.runtime.IStatus;
29
import org.eclipse.core.runtime.Path;
29
import org.eclipse.core.runtime.Path;
30
import org.eclipse.core.runtime.Status;
30
import org.eclipse.core.runtime.Status;
31
import org.eclipse.jdt.launching.AbstractVMInstall;
32
import org.eclipse.jdt.launching.AbstractVMInstallType;
33
import org.eclipse.jdt.launching.IVMInstall;
31
import org.eclipse.jdt.launching.LibraryLocation;
34
import org.eclipse.jdt.launching.LibraryLocation;
32
35
33
import com.ibm.icu.text.MessageFormat;
36
import com.ibm.icu.text.MessageFormat;
Lines 38-44 Link Here
38
 * 
41
 * 
39
 * @since 3.4
42
 * @since 3.4
40
 */
43
 */
41
public class EEVMType {
44
public class EEVMType extends AbstractVMInstallType {
45
	
46
	/**
47
	 * VM Type id
48
	 */
49
	public static final String ID_EE_VM_TYPE = "org.eclipse.jdt.launching.EEVMType"; //$NON-NLS-1$
42
	
50
	
43
	/**
51
	/**
44
	 * Map of {EE File -> {Map of {PropertyName -> PropertyValue}}
52
	 * Map of {EE File -> {Map of {PropertyName -> PropertyValue}}
Lines 58-112 Link Here
58
	public static final String PROP_CLASS_LIB_LEVEL = "-Dee.class.library.level";  //$NON-NLS-1$
66
	public static final String PROP_CLASS_LIB_LEVEL = "-Dee.class.library.level";  //$NON-NLS-1$
59
	public static final String PROP_EXECUTABLE = "-Dee.executable";  //$NON-NLS-1$
67
	public static final String PROP_EXECUTABLE = "-Dee.executable";  //$NON-NLS-1$
60
	public static final String PROP_EXECUTABLE_CONSOLE = "-Dee.executable.console";  //$NON-NLS-1$
68
	public static final String PROP_EXECUTABLE_CONSOLE = "-Dee.executable.console";  //$NON-NLS-1$
69
	public static final String PROP_JAVA_HOME = "-Djava.home";  //$NON-NLS-1$
61
	
70
	
62
	private static final String[] REQUIRED_PROPERTIES = new String[]{PROP_EXECUTABLE, PROP_BOOT_CLASS_PATH, PROP_LANGUAGE_LEVEL};
71
	private static final String[] REQUIRED_PROPERTIES = new String[]{PROP_EXECUTABLE, PROP_BOOT_CLASS_PATH, PROP_LANGUAGE_LEVEL, PROP_JAVA_HOME};
63
	
72
64
	/**
73
	/**
65
	 * Returns whether the given install location corresponds to an .ee file.
74
	 * Returns the library locations defined in the given definition file.
66
	 * 
75
	 * 
67
	 * @param installLocation
76
	 * @param eeFile definition file
68
	 * @return whether the given install location corresponds to an .ee file.
77
	 * @return library locations defined in the file or an empty collection if none
69
	 */
78
	 */
70
	public static boolean isEEInstall(File installLocation) {
79
	public static LibraryLocation[] getLibraryLocations(File eeFile) {
71
		if (installLocation.isFile()) {
72
			String name = installLocation.getName();
73
			if (name.endsWith(".ee")) { //$NON-NLS-1$
74
				return true;
75
			}
76
		}
77
		return false;
78
	}
79
80
	/* (non-Javadoc)
81
	 * @see org.eclipse.jdt.launching.IVMInstallType#getDefaultLibraryLocations(java.io.File)
82
	 */
83
	public static LibraryLocation[] getDefaultLibraryLocations(File installLocation) {
84
		
80
		
85
		Map properties = getProperties(installLocation);
81
		Map properties = getProperties(eeFile);
86
		if (properties == null) {
82
		if (properties == null) {
87
			return new LibraryLocation[]{};
83
			return new LibraryLocation[]{};
88
		}
84
		}
89
		
85
		
90
		List allLibs = new ArrayList(); 
86
		List allLibs = new ArrayList(); 
91
		
87
		
92
		String dirs = getProperty(PROP_ENDORSED_DIRS, installLocation);
88
		String dirs = getProperty(PROP_ENDORSED_DIRS, eeFile);
93
		if (dirs != null) {
89
		if (dirs != null) {
94
			// Add all endorsed libraries - they are first, as they replace
90
			// Add all endorsed libraries - they are first, as they replace
95
			allLibs.addAll(StandardVMType.gatherAllLibraries(resolvePaths(dirs, installLocation)));
91
			allLibs.addAll(StandardVMType.gatherAllLibraries(resolvePaths(dirs, eeFile)));
96
		}
92
		}
97
		
93
		
98
		// next is the bootpath libraries
94
		// next is the bootpath libraries
99
		dirs = getProperty(PROP_BOOT_CLASS_PATH, installLocation);
95
		dirs = getProperty(PROP_BOOT_CLASS_PATH, eeFile);
100
		if (dirs != null) {
96
		if (dirs != null) {
101
			String[] bootpath = resolvePaths(dirs, installLocation);
97
			String[] bootpath = resolvePaths(dirs, eeFile);
102
			List boot = new ArrayList(bootpath.length);
98
			List boot = new ArrayList(bootpath.length);
103
			URL url = getDefaultJavadocLocation(installLocation);
99
			URL url = getJavadocLocation(eeFile);
104
			for (int i = 0; i < bootpath.length; i++) {
100
			for (int i = 0; i < bootpath.length; i++) {
105
				IPath path = new Path(bootpath[i]);
101
				IPath path = new Path(bootpath[i]);
106
				File lib = path.toFile(); 
102
				File lib = path.toFile(); 
107
				if (lib.exists() && lib.isFile()) {
103
				if (lib.exists() && lib.isFile()) {
108
					LibraryLocation libraryLocation = new LibraryLocation(path,
104
					LibraryLocation libraryLocation = new LibraryLocation(path,
109
									getDefaultSourceLocation(installLocation),
105
									getDefaultSourceLocation(eeFile),
110
									Path.EMPTY,
106
									Path.EMPTY,
111
									url);
107
									url);
112
					boot.add(libraryLocation);
108
					boot.add(libraryLocation);
Lines 116-124 Link Here
116
		}
112
		}
117
				
113
				
118
		// Add all extension libraries
114
		// Add all extension libraries
119
		dirs = getProperty(PROP_EXTENSION_DIRS, installLocation);
115
		dirs = getProperty(PROP_EXTENSION_DIRS, eeFile);
120
		if (dirs != null) {
116
		if (dirs != null) {
121
			allLibs.addAll(StandardVMType.gatherAllLibraries(resolvePaths(dirs, installLocation)));
117
			allLibs.addAll(StandardVMType.gatherAllLibraries(resolvePaths(dirs, eeFile)));
122
		}
118
		}
123
		
119
		
124
		
120
		
Lines 135-158 Link Here
135
		return (LibraryLocation[])allLibs.toArray(new LibraryLocation[allLibs.size()]);
131
		return (LibraryLocation[])allLibs.toArray(new LibraryLocation[allLibs.size()]);
136
	}
132
	}
137
	
133
	
138
	/* (non-Javadoc)
134
139
	 * @see org.eclipse.jdt.launching.AbstractVMInstallType#getDefaultJavadocLocation(java.io.File)
135
	/**
136
	 * Returns the javadoc location specified in the definition file or <code>null</code>
137
	 * if none.
138
	 * 
139
	 * @param eeFile definition file
140
	 * @return javadoc location specified in the definition file or <code>null</code> if none
140
	 */
141
	 */
141
	public static URL getDefaultJavadocLocation(File installLocation) {
142
	public static URL getJavadocLocation(File eeFile) {
142
		String version = getProperty(PROP_LANGUAGE_LEVEL, installLocation);
143
		String version = getProperty(PROP_LANGUAGE_LEVEL, eeFile);
143
		if (version != null) {
144
		if (version != null) {
144
			return StandardVMType.getDefaultJavadocLocation(version);
145
			return StandardVMType.getDefaultJavadocLocation(version);
145
		}
146
		}
146
		return null;
147
		return null;
147
	}
148
	}
148
	
149
	
149
	/* (non-Javadoc)
150
	/**
150
	 * @see org.eclipse.jdt.launching.AbstractVMInstallType#getDefaultVMArguments(java.io.File)
151
	 * Returns the definition file associated with the given VM or <code>null</code>
152
	 * if none.
153
	 * 
154
	 * @param vm VM install
155
	 * @return definition file or <code>null</code> if none. The file may/may not exist.
156
	 */
157
	public static File getDefinitionFile(IVMInstall vm) {
158
		if (vm instanceof AbstractVMInstall) {
159
			AbstractVMInstall avm = (AbstractVMInstall) vm;
160
			String path = avm.getAttribute(EEVMInstall.ATTR_DEFINITION_FILE);
161
			if (path != null) {
162
				return new File(path);
163
			}
164
		}
165
		return null;
166
	}
167
	
168
	/**
169
	 * Returns VM arguments defined in the given definition file or <code>null</code> if none.
170
	 * 
171
	 * @param eeFile definition file
172
	 * @return VM arguments or <code>null</code> if none
151
	 */
173
	 */
152
	public static String getDefaultVMArguments(File installLocation) {
174
	public static String getVMArguments(File eeFile) {
153
		Map properties = getProperties(installLocation);
175
		Map properties = getProperties(eeFile);
154
		if (properties != null) {
176
		if (properties != null) {
155
			List args = (List) fgArguments.get(installLocation);
177
			List args = (List) fgArguments.get(eeFile);
156
			StringBuffer buf = new StringBuffer();
178
			StringBuffer buf = new StringBuffer();
157
			Iterator iterator = args.iterator();
179
			Iterator iterator = args.iterator();
158
			while (iterator.hasNext()) {
180
			while (iterator.hasNext()) {
Lines 185-204 Link Here
185
		return Path.EMPTY;
207
		return Path.EMPTY;
186
	}
208
	}
187
209
188
	/* (non-Javadoc)
210
	/**
189
	 * @see org.eclipse.jdt.launching.IVMInstallType#validateInstallLocation(java.io.File)
211
	 * Returns a status indicating if the given definition file is valid.
212
	 * 
213
	 * @param eeFile definition file
214
	 * @return status indicating if the given definition file is valid
190
	 */
215
	 */
191
	public static IStatus validateInstallLocation(File installLocation) {
216
	public static IStatus validateDefinitionFile(File eeFile) {
192
		Map properties = getProperties(installLocation);
217
		Map properties = getProperties(eeFile);
193
		if (properties == null) {
218
		if (properties == null) {
194
			return new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), MessageFormat.format(LaunchingMessages.EEVMType_0, new String[]{installLocation.getName()} ));
219
			return new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), MessageFormat.format(LaunchingMessages.EEVMType_0, new String[]{eeFile.getName()} ));
195
		}
220
		}
196
		// validate required properties
221
		// validate required properties
197
		for (int i = 0; i < REQUIRED_PROPERTIES.length; i++) {
222
		for (int i = 0; i < REQUIRED_PROPERTIES.length; i++) {
198
			String key = REQUIRED_PROPERTIES[i];
223
			String key = REQUIRED_PROPERTIES[i];
199
			String property = (String) properties.get(key);
224
			String property = (String) properties.get(key);
200
			if (property == null) {
225
			if (property == null) {
201
				return new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), MessageFormat.format(LaunchingMessages.EEVMType_1, new String[]{installLocation.getName(), key} ));
226
				return new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), MessageFormat.format(LaunchingMessages.EEVMType_1, new String[]{eeFile.getName(), key} ));
202
			}
227
			}
203
		}
228
		}
204
		return Status.OK_STATUS;
229
		return Status.OK_STATUS;
Lines 209-215 Link Here
209
	 * is considered first.
234
	 * is considered first.
210
	 * 
235
	 * 
211
	 * @param installLocation ee file
236
	 * @param installLocation ee file
212
	 * @return standard executable
237
	 * @return standard executable or <code>null</code> if none
213
	 */
238
	 */
214
	public static File getExecutable(File installLocation) { 
239
	public static File getExecutable(File installLocation) { 
215
		String property = getProperty(PROP_EXECUTABLE, installLocation);
240
		String property = getProperty(PROP_EXECUTABLE, installLocation);
Lines 320-323 Link Here
320
		}
345
		}
321
		return null;
346
		return null;
322
	}
347
	}
348
349
	/* (non-Javadoc)
350
	 * @see org.eclipse.jdt.launching.AbstractVMInstallType#doCreateVMInstall(java.lang.String)
351
	 */
352
	protected IVMInstall doCreateVMInstall(String id) {
353
		return new EEVMInstall(this, id);
354
	}
355
356
	/* (non-Javadoc)
357
	 * @see org.eclipse.jdt.launching.IVMInstallType#detectInstallLocation()
358
	 */
359
	public File detectInstallLocation() {
360
		return null;
361
	}
362
363
	/* (non-Javadoc)
364
	 * @see org.eclipse.jdt.launching.IVMInstallType#getDefaultLibraryLocations(java.io.File)
365
	 */
366
	public LibraryLocation[] getDefaultLibraryLocations(File installLocationOrDefinitionFile) {
367
		return new LibraryLocation[0];
368
	}
369
370
	/* (non-Javadoc)
371
	 * @see org.eclipse.jdt.launching.IVMInstallType#getName()
372
	 */
373
	public String getName() {
374
		return LaunchingMessages.EEVMType_2;
375
	}
376
377
	/* (non-Javadoc)
378
	 * @see org.eclipse.jdt.launching.IVMInstallType#validateInstallLocation(java.io.File)
379
	 */
380
	public IStatus validateInstallLocation(File installLocationOrDefinitionFile) {
381
		return new Status(IStatus.INFO, LaunchingPlugin.getUniqueIdentifier(), LaunchingMessages.EEVMType_3);
382
	}
383
	
384
	/**
385
	 * Clears any cached properties for the given file.
386
	 * 
387
	 * @param eeFile
388
	 */
389
	public synchronized static void clearProperties(File eeFile) {
390
		fgProperites.remove(eeFile);
391
	}
323
}
392
}
(-)launching/org/eclipse/jdt/internal/launching/LaunchingMessages.properties (+3 lines)
Lines 49-54 Link Here
49
JavaRuntime_Could_not_resolve_classpath_container___0__1=Could not resolve classpath container: {0}
49
JavaRuntime_Could_not_resolve_classpath_container___0__1=Could not resolve classpath container: {0}
50
JavaRuntime_Classpath_references_non_existant_project___0__3=The project: {0} which is referenced by the classpath, does not exist.
50
JavaRuntime_Classpath_references_non_existant_project___0__3=The project: {0} which is referenced by the classpath, does not exist.
51
JavaRuntime_Classpath_references_non_existant_archive___0__4=The archive: {0} which is referenced by the classpath, does not exist.
51
JavaRuntime_Classpath_references_non_existant_archive___0__4=The archive: {0} which is referenced by the classpath, does not exist.
52
JavaRuntime_24=Failed to create installed JRE
52
JavaRuntime_26=Referenced classpath provider does not exist: {0}
53
JavaRuntime_26=Referenced classpath provider does not exist: {0}
53
JavaRuntime_27=Referenced source lookup provider does not exist: {0}
54
JavaRuntime_27=Referenced source lookup provider does not exist: {0}
54
JavaRuntime_28=Launch configuration {0} references closed project {1}
55
JavaRuntime_28=Launch configuration {0} references closed project {1}
Lines 177-182 Link Here
177
PackageFragmentRootSourceContainerTypeDelegate_8=Missing required <packageFragmentRoot> attribute
178
PackageFragmentRootSourceContainerTypeDelegate_8=Missing required <packageFragmentRoot> attribute
178
EEVMType_0={0} is not a valid .ee property file
179
EEVMType_0={0} is not a valid .ee property file
179
EEVMType_1={0} missing required property ''{1}''
180
EEVMType_1={0} missing required property ''{1}''
181
EEVMType_2=Execution Environment Description
182
EEVMType_3=Unable to validate install location.
180
VMDefinitionsContainer_0=Installed JRE ''{0}'' removed due to missing VM type extension.
183
VMDefinitionsContainer_0=Installed JRE ''{0}'' removed due to missing VM type extension.
181
VMDefinitionsContainer_2=Installed JRE of type ''{0}'' removed due to missing VM type extension.
184
VMDefinitionsContainer_2=Installed JRE of type ''{0}'' removed due to missing VM type extension.
182
VMDefinitionsContainer_3=Installed JRE of type ''{0}'' removed due to missing install path and name.
185
VMDefinitionsContainer_3=Installed JRE of type ''{0}'' removed due to missing install path and name.
(-)launching/org/eclipse/jdt/internal/launching/StandardVMType.java (-31 / +7 lines)
Lines 79-87 Link Here
79
	 * <code>null</code>.
79
	 * <code>null</code>.
80
	 */
80
	 */
81
	public static File findJavaExecutable(File vmInstallLocation) {
81
	public static File findJavaExecutable(File vmInstallLocation) {
82
		if (EEVMType.isEEInstall(vmInstallLocation)) {
83
			return EEVMType.getExecutable(vmInstallLocation);
84
		}
85
		// Try each candidate in order.  The first one found wins.  Thus, the order
82
		// Try each candidate in order.  The first one found wins.  Thus, the order
86
		// of fgCandidateJavaLocations and fgCandidateJavaFiles is significant.
83
		// of fgCandidateJavaLocations and fgCandidateJavaFiles is significant.
87
		for (int i = 0; i < fgCandidateJavaFiles.length; i++) {
84
		for (int i = 0; i < fgCandidateJavaFiles.length; i++) {
Lines 282-291 Link Here
282
	 * @see org.eclipse.jdt.launching.IVMInstallType#getDefaultLibraryLocations(File)
279
	 * @see org.eclipse.jdt.launching.IVMInstallType#getDefaultLibraryLocations(File)
283
	 */
280
	 */
284
	public LibraryLocation[] getDefaultLibraryLocations(File installLocation) {
281
	public LibraryLocation[] getDefaultLibraryLocations(File installLocation) {
285
		if (EEVMType.isEEInstall(installLocation)) {
286
			return EEVMType.getDefaultLibraryLocations(installLocation);
287
		}
288
289
		// Determine the java executable that corresponds to the specified install location
282
		// Determine the java executable that corresponds to the specified install location
290
		// and use this to generate library information.  If no java executable was found, 
283
		// and use this to generate library information.  If no java executable was found, 
291
		// the 'standard' libraries will be returned.
284
		// the 'standard' libraries will be returned.
Lines 446-454 Link Here
446
	 * @see org.eclipse.jdt.launching.IVMInstallType#validateInstallLocation(java.io.File)
439
	 * @see org.eclipse.jdt.launching.IVMInstallType#validateInstallLocation(java.io.File)
447
	 */
440
	 */
448
	public IStatus validateInstallLocation(File javaHome) {
441
	public IStatus validateInstallLocation(File javaHome) {
449
		if (EEVMType.isEEInstall(javaHome)) {
450
			return EEVMType.validateInstallLocation(javaHome);
451
		}
452
		IStatus status = null;
442
		IStatus status = null;
453
		if (Platform.getOS().equals(Constants.OS_MACOSX)) {
443
		if (Platform.getOS().equals(Constants.OS_MACOSX)) {
454
			status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), 0, LaunchingMessages.StandardVMType_Standard_VM_not_supported_on_MacOS__1, null); 
444
			status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), 0, LaunchingMessages.StandardVMType_Standard_VM_not_supported_on_MacOS__1, null); 
Lines 602-630 Link Here
602
	 * @see org.eclipse.jdt.launching.AbstractVMInstallType#getDefaultJavadocLocation(java.io.File)
592
	 * @see org.eclipse.jdt.launching.AbstractVMInstallType#getDefaultJavadocLocation(java.io.File)
603
	 */
593
	 */
604
	public URL getDefaultJavadocLocation(File installLocation) {
594
	public URL getDefaultJavadocLocation(File installLocation) {
605
		if (EEVMType.isEEInstall(installLocation)) {
595
		File javaExecutable = findJavaExecutable(installLocation);
606
			return EEVMType.getDefaultJavadocLocation(installLocation);
596
		if (javaExecutable != null) {
607
		} else {
597
			LibraryInfo libInfo = getLibraryInfo(installLocation, javaExecutable);
608
			File javaExecutable = findJavaExecutable(installLocation);
598
			if (libInfo != null) {
609
			if (javaExecutable != null) {
599
				String version = libInfo.getVersion();
610
				LibraryInfo libInfo = getLibraryInfo(installLocation, javaExecutable);
600
				return getDefaultJavadocLocation(version);
611
				if (libInfo != null) {
612
					String version = libInfo.getVersion();
613
					return getDefaultJavadocLocation(version);
614
				}
615
			}
601
			}
616
			return null;
617
		}
602
		}
618
	}
603
		return null;
619
620
	/* (non-Javadoc)
621
	 * @see org.eclipse.jdt.launching.AbstractVMInstallType#getDefaultVMArguments(java.io.File)
622
	 */
623
	public String getDefaultVMArguments(File installLocation) {
624
		if (EEVMType.isEEInstall(installLocation)) {
625
			return EEVMType.getDefaultVMArguments(installLocation);
626
		}
627
		return super.getDefaultVMArguments(installLocation);
628
	}
604
	}
629
605
630
	/**
606
	/**
(-)launching/org/eclipse/jdt/internal/launching/VMDefinitionsContainer.java (-3 / +33 lines)
Lines 23-28 Link Here
23
import java.util.List;
23
import java.util.List;
24
import java.util.Map;
24
import java.util.Map;
25
import java.util.Set;
25
import java.util.Set;
26
import java.util.Map.Entry;
26
27
27
import javax.xml.parsers.DocumentBuilder;
28
import javax.xml.parsers.DocumentBuilder;
28
import javax.xml.parsers.DocumentBuilderFactory;
29
import javax.xml.parsers.DocumentBuilderFactory;
Lines 35-40 Link Here
35
import org.eclipse.core.runtime.Path;
36
import org.eclipse.core.runtime.Path;
36
import org.eclipse.core.runtime.Status;
37
import org.eclipse.core.runtime.Status;
37
import org.eclipse.debug.core.DebugPlugin;
38
import org.eclipse.debug.core.DebugPlugin;
39
import org.eclipse.jdt.launching.AbstractVMInstall;
38
import org.eclipse.jdt.launching.IVMInstall;
40
import org.eclipse.jdt.launching.IVMInstall;
39
import org.eclipse.jdt.launching.IVMInstall2;
41
import org.eclipse.jdt.launching.IVMInstall2;
40
import org.eclipse.jdt.launching.IVMInstallType;
42
import org.eclipse.jdt.launching.IVMInstallType;
Lines 130-136 Link Here
130
			}
132
			}
131
			vmList.add(vm);
133
			vmList.add(vm);
132
			File installLocation = vm.getInstallLocation();
134
			File installLocation = vm.getInstallLocation();
133
			if (installLocation == null || !vmInstallType.validateInstallLocation(installLocation).isOK()) {
135
			if (installLocation == null || vmInstallType.validateInstallLocation(installLocation).getSeverity() == IStatus.ERROR) {
134
				fInvalidVMList.add(vm);
136
				fInvalidVMList.add(vm);
135
			}
137
			}
136
			fVMList.add(vm);
138
			fVMList.add(vm);
Lines 344-349 Link Here
344
			}
346
			}
345
		}
347
		}
346
		
348
		
349
		// vm attributes
350
		if (vm instanceof AbstractVMInstall) {
351
			Map attributes = ((AbstractVMInstall)vm).getAttributes();
352
			if (!attributes.isEmpty()) {
353
				Element attrElement = doc.createElement("attributeMap"); //$NON-NLS-1$
354
				Iterator iterator = attributes.entrySet().iterator();
355
				while (iterator.hasNext()) {
356
					Entry entry = (Entry) iterator.next();
357
					Element entryElement = doc.createElement("entry"); //$NON-NLS-1$
358
					entryElement.setAttribute("key", (String)entry.getKey()); //$NON-NLS-1$
359
					entryElement.setAttribute("value", (String)entry.getValue()); //$NON-NLS-1$
360
					attrElement.appendChild(entryElement);
361
				}
362
				element.appendChild(attrElement);
363
			}
364
		}
365
		
347
		return element;
366
		return element;
348
	}
367
	}
349
	
368
	
Lines 534-543 Link Here
534
					if (subElementName.equals("libraryLocation")) { //$NON-NLS-1$
553
					if (subElementName.equals("libraryLocation")) { //$NON-NLS-1$
535
						LibraryLocation loc = getLibraryLocation(subElement);
554
						LibraryLocation loc = getLibraryLocation(subElement);
536
						vmStandin.setLibraryLocations(new LibraryLocation[]{loc});
555
						vmStandin.setLibraryLocations(new LibraryLocation[]{loc});
537
						break;
538
					} else if (subElementName.equals("libraryLocations")) { //$NON-NLS-1$
556
					} else if (subElementName.equals("libraryLocations")) { //$NON-NLS-1$
539
						setLibraryLocations(vmStandin, subElement);
557
						setLibraryLocations(vmStandin, subElement);
540
						break;
558
					} else if (subElementName.equals("attributeMap")) { //$NON-NLS-1$
559
						NodeList entries = subElement.getElementsByTagName("entry"); //$NON-NLS-1$
560
						for (int j = 0; j < entries.getLength(); j++) {
561
							Node entryNode = entries.item(j);
562
							if (entryNode instanceof Element) {
563
								Element entryElement = (Element) entryNode;
564
								String key = entryElement.getAttribute("key"); //$NON-NLS-1$
565
								String value = entryElement.getAttribute("value"); //$NON-NLS-1$
566
								if (key != null && value != null) {
567
									vmStandin.setAttribute(key, value);
568
								}
569
							}
570
						}
541
					}
571
					}
542
				}
572
				}
543
			}
573
			}
(-)launching/org/eclipse/jdt/launching/AbstractVMInstall.java (+57 lines)
Lines 55-60 Link Here
55
	private LibraryLocation[] fSystemLibraryDescriptions;
55
	private LibraryLocation[] fSystemLibraryDescriptions;
56
	private URL fJavadocLocation;
56
	private URL fJavadocLocation;
57
	private String fVMArgs;
57
	private String fVMArgs;
58
	/**
59
	 * Map VM specific attributes that are persisted restored with a VM install.
60
	 * @since 3.4
61
	 */
62
	private Map fAttributeMap = new HashMap();
63
	
58
	// system properties are cached in user preferences prefixed with this key, followed
64
	// system properties are cached in user preferences prefixed with this key, followed
59
	// by vm type, vm id, and system property name
65
	// by vm type, vm id, and system property name
60
	private static final String PREF_VM_INSTALL_SYSTEM_PROPERTY = "PREF_VM_INSTALL_SYSTEM_PROPERTY"; //$NON-NLS-1$
66
	private static final String PREF_VM_INSTALL_SYSTEM_PROPERTY = "PREF_VM_INSTALL_SYSTEM_PROPERTY"; //$NON-NLS-1$
Lines 484-488 Link Here
484
		throw new CoreException(new Status(IStatus.ERROR, LaunchingPlugin
490
		throw new CoreException(new Status(IStatus.ERROR, LaunchingPlugin
485
				.getUniqueIdentifier(), code, message, exception));
491
				.getUniqueIdentifier(), code, message, exception));
486
	}	
492
	}	
493
	
494
	/**
495
	 * Sets a VM specific attribute. Attributes are persisted and restored with VM installs.
496
	 * Specifying a value of <code>null</code> as a value removes the attribute. Change
497
	 * notification is provided to {@link IVMInstallChangedListener} for VM attributes.
498
	 * 
499
	 * @param key attribute key, cannot be <code>null</code>
500
	 * @param value attribute value or <code>null</code> to remove the attribute
501
	 * @since 3.4
502
	 */
503
	public void setAttribute(String key, String value) {
504
		String prevValue = (String) fAttributeMap.remove(key);
505
		boolean notify = false;
506
		if (value == null) {
507
			if (prevValue != null && fNotify) {
508
				notify = true;
509
			}
510
		} else {
511
			fAttributeMap.put(key, value);
512
			if (fNotify && (prevValue == null || !prevValue.equals(value))) {
513
				notify = true;
514
			}
515
		}
516
		if (notify) {
517
			PropertyChangeEvent event = new PropertyChangeEvent(this, key, prevValue, value);
518
			JavaRuntime.fireVMChanged(event);
519
		}
520
	}
487
    
521
    
522
	/**
523
	 * Returns a VM specific attribute associated with the given key or <code>null</code> 
524
	 * if none.
525
	 * 
526
	 * @param key attribute key, cannot be <code>null</code>
527
	 * @return attribute value, or <code>null</code> if none
528
	 * @since 3.4
529
	 */
530
	public String getAttribute(String key) {
531
		return (String) fAttributeMap.get(key);
532
	}
533
	
534
	/**
535
	 * Returns a map of VM specific attributes stored with this VM install. Keys
536
	 * and values are strings. Modifying the map does not modify the attributes
537
	 * associated with this VM install.
538
	 * 
539
	 * @return map of VM attributes
540
	 * @since 3.4
541
	 */
542
	public Map getAttributes() {
543
		return new HashMap(fAttributeMap);
544
	}
488
}
545
}
(-)launching/org/eclipse/jdt/launching/IVMInstall.java (-15 / +4 lines)
Lines 68-95 Link Here
68
	void setName(String name);
68
	void setName(String name);
69
	/**
69
	/**
70
	 * Returns the root directory of the install location of this VM.
70
	 * Returns the root directory of the install location of this VM.
71
	 * <p>
71
	 * 
72
	 * Since 3.4, this may also be a file describing a VM install.
73
	 * For example, the standard VM installs support execution
74
	 * environment description files, as described by
75
	 * <code>http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions</code>.
76
	 * </p>
77
	 * @return the root directory of this VM installation. May
72
	 * @return the root directory of this VM installation. May
78
	 * 			return <code>null</code>.
73
	 * 			return <code>null</code>.
79
	 */
74
	 */
80
	File getInstallLocation();
75
	File getInstallLocation();
81
	/**
76
	/**
82
	 * Sets the root directory of the install location of this VM.
77
	 * Sets the root directory of the install location of this VM.
83
	 * <p>
78
	 * 
84
	 * Since 3.4, this may also be a file describing a VM install.
79
	 * @param installLocation the root directory of this VM installation
85
	 * For example, the standard VM installs support execution
86
	 * environment description files, as described by
87
	 * <code>http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions</code>.
88
	 * </p>
89
	 * @param installLocationOrDefinitionFile the root directory or definition file for
90
	 * 	this VM installation
91
	 */
80
	 */
92
	void setInstallLocation(File installLocationOrDefinitionFile);
81
	void setInstallLocation(File installLocation);
93
		
82
		
94
	/**
83
	/**
95
	 * Returns the VM type of this VM.
84
	 * Returns the VM type of this VM.
(-)launching/org/eclipse/jdt/launching/IVMInstallType.java (-18 / +7 lines)
Lines 88-107 Link Here
88
	/**
88
	/**
89
	 * Validates the given location of a VM installation.
89
	 * Validates the given location of a VM installation.
90
	 * <p>
90
	 * <p>
91
	 * Since 3.4, the given installLocation may be a file (rather than a home
92
	 * directory). For example, the standard VM install type accepts execution
93
	 * environment description files, as described by
94
	 * <code>http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions</code>.
95
	 * </p> 
96
	 * <p>
97
	 * For example, an implementation might check whether the VM executable 
91
	 * For example, an implementation might check whether the VM executable 
98
	 * is present.
92
	 * is present.
99
	 * </p>
93
	 * </p>
100
	 * @param installLocationOrDefinitionFile the root directory of a potential installation for
94
	 * 
101
	 *   this type of VM or since 3.4, a file describing an installation
95
	 * @param installLocation the root directory of a potential installation for
96
	 *   this type of VM
102
	 * @return a status object describing whether the install location is valid
97
	 * @return a status object describing whether the install location is valid
103
	 */
98
	 */
104
	IStatus validateInstallLocation(File installLocationOrDefinitionFile);
99
	IStatus validateInstallLocation(File installLocation);
105
	
100
	
106
	/**
101
	/**
107
	 * Tries to detect an installed VM that matches this VM install type.
102
	 * Tries to detect an installed VM that matches this VM install type.
Lines 120-138 Link Here
120
	 * at the given <code>installLocation</code>.
115
	 * at the given <code>installLocation</code>.
121
	 * The returned <code>LibraryLocation</code>s may not exist if the
116
	 * The returned <code>LibraryLocation</code>s may not exist if the
122
	 * <code>installLocation</code> is not a valid install location.
117
	 * <code>installLocation</code> is not a valid install location.
123
	 * <p>
118
	 * 
124
	 * Since 3.4, the given installLocation may be a file (rather than a home
119
	 * @param installLocation home location
125
	 * directory). For example, the standard VM install type accepts execution
126
	 * environment description files, as described by
127
	 * <code>http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions</code>.
128
	 * </p> 
129
	 * @param installLocationOrDefinitionFile home directory or since 3.4, a file
130
	 * 	describing an installation
131
	 * @see LibraryLocation
120
	 * @see LibraryLocation
132
	 * @see IVMInstallType#validateInstallLocation(File)
121
	 * @see IVMInstallType#validateInstallLocation(File)
133
	 * 
122
	 * 
134
	 * @return default library locations based on the given <code>installLocation</code>.
123
	 * @return default library locations based on the given <code>installLocation</code>.
135
	 * @since 2.0
124
	 * @since 2.0
136
	 */
125
	 */
137
	LibraryLocation[] getDefaultLibraryLocations(File installLocationOrDefinitionFile);	
126
	LibraryLocation[] getDefaultLibraryLocations(File installLocation);	
138
}
127
}
(-)launching/org/eclipse/jdt/launching/JavaRuntime.java (-61 / +112 lines)
Lines 59-64 Link Here
59
import org.eclipse.jdt.internal.launching.CompositeId;
59
import org.eclipse.jdt.internal.launching.CompositeId;
60
import org.eclipse.jdt.internal.launching.DefaultEntryResolver;
60
import org.eclipse.jdt.internal.launching.DefaultEntryResolver;
61
import org.eclipse.jdt.internal.launching.DefaultProjectClasspathEntry;
61
import org.eclipse.jdt.internal.launching.DefaultProjectClasspathEntry;
62
import org.eclipse.jdt.internal.launching.EEVMInstall;
63
import org.eclipse.jdt.internal.launching.EEVMType;
62
import org.eclipse.jdt.internal.launching.JREContainerInitializer;
64
import org.eclipse.jdt.internal.launching.JREContainerInitializer;
63
import org.eclipse.jdt.internal.launching.JavaSourceLookupUtil;
65
import org.eclipse.jdt.internal.launching.JavaSourceLookupUtil;
64
import org.eclipse.jdt.internal.launching.LaunchingMessages;
66
import org.eclipse.jdt.internal.launching.LaunchingMessages;
Lines 1465-1472 Link Here
1465
						}		
1467
						}		
1466
						String javadoc = element.getAttribute("javadocURL"); //$NON-NLS-1$
1468
						String javadoc = element.getAttribute("javadocURL"); //$NON-NLS-1$
1467
						String vmArgs = element.getAttribute("vmArgs"); //$NON-NLS-1$
1469
						String vmArgs = element.getAttribute("vmArgs"); //$NON-NLS-1$
1468
						VMStandin standin = new VMStandin(installType, id);
1470
						VMStandin standin = null;
1469
						standin.setName(name);
1470
						home = substitute(home);
1471
						home = substitute(home);
1471
						File homeDir = new File(home);
1472
						File homeDir = new File(home);
1472
                        if (homeDir.exists()) {
1473
                        if (homeDir.exists()) {
Lines 1477-1543 Link Here
1477
                            } catch (IOException e) {
1478
                            } catch (IOException e) {
1478
                            }
1479
                            }
1479
                        }
1480
                        }
1480
                        IStatus status = installType.validateInstallLocation(homeDir);
1481
						if (EEVMType.ID_EE_VM_TYPE.equals(installType.getId())) {
1481
                        if (!status.isOK()) {
1482
							standin = createVMFromDefinitionFile(homeDir, name, id);
1482
                        	abort(MessageFormat.format("Illegal install location {0} for vmInstall {1} contributed by {2}: {3}", //$NON-NLS-1$
1483
						} else {
1483
                        			new String[]{home, id, element.getContributor().getName(), status.getMessage()}), null);
1484
							standin = new VMStandin(installType, id);
1484
                        }
1485
							standin.setName(name);
1485
                        standin.setInstallLocation(homeDir);
1486
	                        IStatus status = installType.validateInstallLocation(homeDir);
1486
						if (javadoc != null) {
1487
	                        if (!status.isOK()) {
1487
							try {
1488
	                        	abort(MessageFormat.format("Illegal install location {0} for vmInstall {1} contributed by {2}: {3}", //$NON-NLS-1$
1488
								standin.setJavadocLocation(new URL(javadoc));
1489
	                        			new String[]{home, id, element.getContributor().getName(), status.getMessage()}), null);
1489
							} catch (MalformedURLException e) {
1490
	                        }
1490
								abort(MessageFormat.format("Illegal javadocURL attribute for vmInstall {0} contributed by {1}", //$NON-NLS-1$
1491
	                        standin.setInstallLocation(homeDir);
1491
										new String[]{id, element.getContributor().getName()}), e);
1492
							if (javadoc != null) {
1493
								try {
1494
									standin.setJavadocLocation(new URL(javadoc));
1495
								} catch (MalformedURLException e) {
1496
									abort(MessageFormat.format("Illegal javadocURL attribute for vmInstall {0} contributed by {1}", //$NON-NLS-1$
1497
											new String[]{id, element.getContributor().getName()}), e);
1498
								}
1492
							}
1499
							}
1493
						}
1500
							// allow default arguments to be specified by vm install type if no explicit arguments
1494
						// allow default arguments to be specified by vm install type if no explicit arguments
1501
							if (vmArgs == null) {
1495
						if (vmArgs == null) {
1502
								if (installType instanceof AbstractVMInstallType) {
1496
							if (installType instanceof AbstractVMInstallType) {
1503
									AbstractVMInstallType type = (AbstractVMInstallType) installType;
1497
								AbstractVMInstallType type = (AbstractVMInstallType) installType;
1504
									vmArgs = type.getDefaultVMArguments(homeDir);
1498
								vmArgs = type.getDefaultVMArguments(homeDir);
1505
								}
1499
							}
1506
							}
1507
							if (vmArgs != null) {
1508
								standin.setVMArgs(vmArgs);
1509
							}
1510
	                        IConfigurationElement[] libraries = element.getChildren("library"); //$NON-NLS-1$
1511
	                        LibraryLocation[] locations = null;
1512
	                        if (libraries.length > 0) {
1513
	                            locations = new LibraryLocation[libraries.length];
1514
	                            for (int j = 0; j < libraries.length; j++) {
1515
	                                IConfigurationElement library = libraries[j];
1516
	                                String libPathStr = library.getAttribute("path"); //$NON-NLS-1$
1517
	                                if (libPathStr == null) {
1518
	                                    abort(MessageFormat.format("library for vmInstall {0} contributed by {1} missing required attribute libPath", //$NON-NLS-1$
1519
	                                            new String[]{id, element.getContributor().getName()}), null);
1520
	                                }
1521
	                                String sourcePathStr = library.getAttribute("sourcePath"); //$NON-NLS-1$
1522
	                                String packageRootStr = library.getAttribute("packageRootPath"); //$NON-NLS-1$
1523
	                                String javadocOverride = library.getAttribute("javadocURL"); //$NON-NLS-1$
1524
	                                URL url = null;
1525
	                                if (javadocOverride != null) {
1526
	                                    try {
1527
	                                        url = new URL(javadocOverride);
1528
	                                    } catch (MalformedURLException e) {
1529
	                                        abort(MessageFormat.format("Illegal javadocURL attribute specified for library {0} for vmInstall {1} contributed by {2}" //$NON-NLS-1$
1530
	                                                ,new String[]{libPathStr, id, element.getContributor().getName()}), e);
1531
	                                    }
1532
	                                }
1533
	                                IPath homePath = new Path(home);
1534
	                                IPath libPath = homePath.append(substitute(libPathStr));
1535
	                                IPath sourcePath = Path.EMPTY;
1536
	                                if (sourcePathStr != null) {
1537
	                                    sourcePath = homePath.append(substitute(sourcePathStr));
1538
	                                }
1539
	                                IPath packageRootPath = Path.EMPTY;
1540
	                                if (packageRootStr != null) {
1541
	                                    packageRootPath = new Path(substitute(packageRootStr));
1542
	                                }
1543
	                                locations[j] = new LibraryLocation(libPath, sourcePath, packageRootPath, url);
1544
	                            }
1545
	                        }
1546
	                        standin.setLibraryLocations(locations);
1500
						}
1547
						}
1501
						if (vmArgs != null) {
1502
							standin.setVMArgs(vmArgs);
1503
						}
1504
                        IConfigurationElement[] libraries = element.getChildren("library"); //$NON-NLS-1$
1505
                        LibraryLocation[] locations = null;
1506
                        if (libraries.length > 0) {
1507
                            locations = new LibraryLocation[libraries.length];
1508
                            for (int j = 0; j < libraries.length; j++) {
1509
                                IConfigurationElement library = libraries[j];
1510
                                String libPathStr = library.getAttribute("path"); //$NON-NLS-1$
1511
                                if (libPathStr == null) {
1512
                                    abort(MessageFormat.format("library for vmInstall {0} contributed by {1} missing required attribute libPath", //$NON-NLS-1$
1513
                                            new String[]{id, element.getContributor().getName()}), null);
1514
                                }
1515
                                String sourcePathStr = library.getAttribute("sourcePath"); //$NON-NLS-1$
1516
                                String packageRootStr = library.getAttribute("packageRootPath"); //$NON-NLS-1$
1517
                                String javadocOverride = library.getAttribute("javadocURL"); //$NON-NLS-1$
1518
                                URL url = null;
1519
                                if (javadocOverride != null) {
1520
                                    try {
1521
                                        url = new URL(javadocOverride);
1522
                                    } catch (MalformedURLException e) {
1523
                                        abort(MessageFormat.format("Illegal javadocURL attribute specified for library {0} for vmInstall {1} contributed by {2}" //$NON-NLS-1$
1524
                                                ,new String[]{libPathStr, id, element.getContributor().getName()}), e);
1525
                                    }
1526
                                }
1527
                                IPath homePath = new Path(home);
1528
                                IPath libPath = homePath.append(substitute(libPathStr));
1529
                                IPath sourcePath = Path.EMPTY;
1530
                                if (sourcePathStr != null) {
1531
                                    sourcePath = homePath.append(substitute(sourcePathStr));
1532
                                }
1533
                                IPath packageRootPath = Path.EMPTY;
1534
                                if (packageRootStr != null) {
1535
                                    packageRootPath = new Path(substitute(packageRootStr));
1536
                                }
1537
                                locations[j] = new LibraryLocation(libPath, sourcePath, packageRootPath, url);
1538
                            }
1539
                        }
1540
                        standin.setLibraryLocations(locations);
1541
                        // in case the contributed JRE attributes changed, remove it first, then add
1548
                        // in case the contributed JRE attributes changed, remove it first, then add
1542
                        vmDefs.removeVM(standin);
1549
                        vmDefs.removeVM(standin);
1543
                        vmDefs.addVM(standin);
1550
                        vmDefs.addVM(standin);
Lines 1592-1598 Link Here
1592
		LibraryLocation[] locations= vm.getLibraryLocations();
1599
		LibraryLocation[] locations= vm.getLibraryLocations();
1593
		if (locations == null) {
1600
		if (locations == null) {
1594
            URL defJavaDocLocation = vm.getJavadocLocation(); 
1601
            URL defJavaDocLocation = vm.getJavadocLocation(); 
1595
			LibraryLocation[] dflts= vm.getVMInstallType().getDefaultLibraryLocations(vm.getInstallLocation());
1602
			File installLocation = vm.getInstallLocation();
1603
			if (installLocation == null) {
1604
				return new LibraryLocation[0];
1605
			}
1606
			LibraryLocation[] dflts= vm.getVMInstallType().getDefaultLibraryLocations(installLocation);
1596
			libraryPaths = new IPath[dflts.length];
1607
			libraryPaths = new IPath[dflts.length];
1597
			sourcePaths = new IPath[dflts.length];
1608
			sourcePaths = new IPath[dflts.length];
1598
			sourceRootPaths = new IPath[dflts.length];
1609
			sourceRootPaths = new IPath[dflts.length];
Lines 2654-2658 Link Here
2654
            }
2665
            }
2655
        }		
2666
        }		
2656
	}
2667
	}
2668
	
2669
	/**
2670
	 * Creates a new VM based on the attributes specified in the given execution 
2671
	 * environment description file. The format of the file is defined by
2672
	 * <code>http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions</code>.
2673
	 * 
2674
	 * @param eeFile VM definition file
2675
	 * @param name name for the VM
2676
	 * @param id id to assign to the new VM
2677
	 * @return VM standin 
2678
	 * @exception CoreException if unable to create a VM from the given definition file
2679
	 * @since 3.4
2680
	 */
2681
	public static VMStandin createVMFromDefinitionFile(File eeFile, String name, String id) throws CoreException {
2682
		IStatus status = EEVMType.validateDefinitionFile(eeFile);
2683
		if (status.isOK()) {
2684
			VMStandin standin = new VMStandin(getVMInstallType(EEVMType.ID_EE_VM_TYPE), id);
2685
			standin.setName(name);
2686
			String home = EEVMType.getProperty(EEVMType.PROP_JAVA_HOME, eeFile);
2687
			standin.setInstallLocation(new File(home));
2688
			standin.setLibraryLocations(EEVMType.getLibraryLocations(eeFile));
2689
			standin.setVMArgs(EEVMType.getVMArguments(eeFile));
2690
			standin.setJavadocLocation(EEVMType.getJavadocLocation(eeFile));
2691
			standin.setAttribute(EEVMInstall.ATTR_EXECUTION_ENVIRONMENT_ID, EEVMType.getProperty(EEVMType.PROP_CLASS_LIB_LEVEL, eeFile));
2692
			File exe = EEVMType.getExecutable(eeFile);
2693
			if (exe != null) {
2694
				try {
2695
					standin.setAttribute(EEVMInstall.ATTR_JAVA_EXE, exe.getCanonicalPath());
2696
				} catch (IOException e) {
2697
					throw new CoreException(new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(),
2698
							LaunchingMessages.JavaRuntime_24, e));
2699
				}
2700
			}
2701
			standin.setAttribute(EEVMInstall.ATTR_JAVA_VERSION, EEVMType.getJavaVersion(eeFile));
2702
			standin.setAttribute(EEVMInstall.ATTR_DEFINITION_FILE, eeFile.getPath());
2703
			return standin;
2704
		} else {
2705
			throw new CoreException(status);
2706
		}
2707
	}
2657
2708
2658
}
2709
}
(-)launching/org/eclipse/jdt/launching/AbstractVMInstallType.java (-11 / +5 lines)
Lines 157-185 Link Here
157
	 * implementation returns <code>null</code>, subclasses must override as
157
	 * implementation returns <code>null</code>, subclasses must override as
158
	 * appropriate.
158
	 * appropriate.
159
	 * <p>
159
	 * <p>
160
	 * Since 3.4, the argument may also be a file describing a VM install.
161
	 * For example, the standard VM installs support execution
162
	 * environment description files, as described by
163
	 * <code>http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions</code>.
164
	 * </p>
165
	 * <p>
166
	 * Note, this method would ideally be added to <code>IVMInstallType</code>,
160
	 * Note, this method would ideally be added to <code>IVMInstallType</code>,
167
	 * but it would have been a breaking API change between 2.0 and 2.1. Thus,
161
	 * but it would have been a breaking API change between 2.0 and 2.1. Thus,
168
	 * it has been added to the abstract base class that VM install types should
162
	 * it has been added to the abstract base class that VM install types should
169
	 * subclass.
163
	 * subclass.
170
	 * </p>
164
	 * </p>
171
	 * 
165
	 * 
172
	 * @param installLocationOrDefinitionFile home location or since 3.4, a definition file
166
	 * @param installLocationOrDefinitionFile home location
173
	 * @return default javadoc location or <code>null</code>
167
	 * @return default javadoc location or <code>null</code>
174
	 * @since 2.1
168
	 * @since 2.1
175
	 */
169
	 */
176
	public URL getDefaultJavadocLocation(File installLocationOrDefinitionFile) {
170
	public URL getDefaultJavadocLocation(File installLocation) {
177
		return null;		
171
		return null;		
178
	}
172
	}
179
	
173
	
180
	/**
174
	/**
181
	 * Returns a string of default VM arguments for a VM installed at the
175
	 * Returns a string of default VM arguments for a VM installed at the
182
	 * given home location or definition file, or <code>null</code> if none.
176
	 * given home location, or <code>null</code> if none.
183
	 * The default implementation returns <code>null</code>, subclasses must override
177
	 * The default implementation returns <code>null</code>, subclasses must override
184
	 * as appropriate.
178
	 * as appropriate.
185
	 * <p>
179
	 * <p>
Lines 188-198 Link Here
188
	 * it has been added to the abstract base class that VM install types should
182
	 * it has been added to the abstract base class that VM install types should
189
	 * subclass.
183
	 * subclass.
190
	 * </p>
184
	 * </p>
191
	 * @param installLocationOrDefinitionFile home location or definition file
185
	 * @param installLocation home location
192
	 * @return default VM arguments or <code>null</code> if none
186
	 * @return default VM arguments or <code>null</code> if none
193
	 * @since 3.4
187
	 * @since 3.4
194
	 */
188
	 */
195
	public String getDefaultVMArguments(File installLocationOrDefinitionFile) {
189
	public String getDefaultVMArguments(File installLocation) {
196
		return null;
190
		return null;
197
	}
191
	}
198
}
192
}
(-)launching/org/eclipse/jdt/launching/VMStandin.java (-1 / +20 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.launching;
11
package org.eclipse.jdt.launching;
12
12
13
import java.util.Iterator;
14
import java.util.Map;
15
import java.util.Map.Entry;
16
13
17
14
18
15
/**
19
/**
Lines 93-98 Link Here
93
			setVMArguments(realVM.getVMArguments());
97
			setVMArguments(realVM.getVMArguments());
94
			fJavaVersion = null;
98
			fJavaVersion = null;
95
		}
99
		}
100
		if (realVM instanceof AbstractVMInstall) {
101
			AbstractVMInstall vm2 = (AbstractVMInstall) realVM;
102
			Map attributes = vm2.getAttributes();
103
			Iterator iterator = attributes.entrySet().iterator();
104
			while (iterator.hasNext()) {
105
				Entry entry = (Entry) iterator.next();
106
				setAttribute((String)entry.getKey(), (String)entry.getValue());
107
			}
108
		}
96
	}
109
	}
97
	
110
	
98
	/**
111
	/**
Lines 126-132 Link Here
126
		}
139
		}
127
		
140
		
128
		if (realVM instanceof AbstractVMInstall) {
141
		if (realVM instanceof AbstractVMInstall) {
129
			 ((AbstractVMInstall)realVM).setNotify(true);
142
			AbstractVMInstall avm = (AbstractVMInstall) realVM;
143
			Iterator iterator = getAttributes().entrySet().iterator();
144
			while (iterator.hasNext()) {
145
				Entry entry = (Entry) iterator.next();
146
				avm.setAttribute((String)entry.getKey(), (String)entry.getValue());
147
			}
148
			avm.setNotify(true);
130
		}		
149
		}		
131
		if (!notify) {
150
		if (!notify) {
132
			JavaRuntime.fireVMAdded(realVM);
151
			JavaRuntime.fireVMAdded(realVM);
(-)launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironmentAnalyzer.java (-2 / +3 lines)
Lines 18-23 Link Here
18
18
19
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.jdt.internal.launching.EEVMInstall;
21
import org.eclipse.jdt.internal.launching.EEVMType;
22
import org.eclipse.jdt.internal.launching.EEVMType;
22
import org.eclipse.jdt.launching.IVMInstall;
23
import org.eclipse.jdt.launching.IVMInstall;
23
import org.eclipse.jdt.launching.IVMInstall2;
24
import org.eclipse.jdt.launching.IVMInstall2;
Lines 72-79 Link Here
72
			return new CompatibleEnvironment[0];
73
			return new CompatibleEnvironment[0];
73
		IVMInstall2 vm2 = (IVMInstall2) vm;
74
		IVMInstall2 vm2 = (IVMInstall2) vm;
74
		List types = null;
75
		List types = null;
75
		if (EEVMType.isEEInstall(vm.getInstallLocation())) {
76
		if (EEVMType.ID_EE_VM_TYPE.equals(vm.getVMInstallType().getId())) {
76
			String eeId = EEVMType.getProperty(EEVMType.PROP_CLASS_LIB_LEVEL, vm.getInstallLocation());
77
			String eeId = ((EEVMInstall)vm).getAttribute(EEVMInstall.ATTR_EXECUTION_ENVIRONMENT_ID);
77
			if (eeId != null) {
78
			if (eeId != null) {
78
				types = getTypes(eeId);
79
				types = getTypes(eeId);
79
			}
80
			}
(-)plugin.xml (+4 lines)
Lines 23-28 Link Here
23
            class="org.eclipse.jdt.internal.launching.Standard11xVMType"
23
            class="org.eclipse.jdt.internal.launching.Standard11xVMType"
24
            id="org.eclipse.jdt.launching.Standard11xVMType">
24
            id="org.eclipse.jdt.launching.Standard11xVMType">
25
      </vmInstallType>
25
      </vmInstallType>
26
      <vmInstallType
27
            class="org.eclipse.jdt.internal.launching.EEVMType"
28
            id="org.eclipse.jdt.launching.EEVMType">
29
      </vmInstallType>
26
   </extension>
30
   </extension>
27
   <extension
31
   <extension
28
         point="org.eclipse.debug.core.launchConfigurationTypes">
32
         point="org.eclipse.debug.core.launchConfigurationTypes">
(-)schema/vmInstallTypes.exsd (-1 / +3 lines)
Lines 65-70 Link Here
65
      </complexType>
65
      </complexType>
66
   </element>
66
   </element>
67
67
68
68
   <annotation>
69
   <annotation>
69
      <appInfo>
70
      <appInfo>
70
         <meta.section type="examples"/>
71
         <meta.section type="examples"/>
Lines 85-97 Link Here
85
      </documentation>
86
      </documentation>
86
   </annotation>
87
   </annotation>
87
88
89
88
   <annotation>
90
   <annotation>
89
      <appInfo>
91
      <appInfo>
90
         <meta.section type="implementation"/>
92
         <meta.section type="implementation"/>
91
      </appInfo>
93
      </appInfo>
92
      <documentation>
94
      <documentation>
93
         Abstract implementations of IVMInstall and IVMInstallType are provided.  The Java Development Tools Launching Support plug-in defines a VM
95
         Abstract implementations of IVMInstall and IVMInstallType are provided.  The Java Development Tools Launching Support plug-in defines a VM
94
install type for the standard 1.1.* and 1.2/1.3/1.4 level &lt;b&gt;JRE&lt;/b&gt;.
96
install type for the standard 1.1.* level JRE, and an install type for JREs conforming to standard command line options (1.2, 1.3, 1.4, 5.0, 6.0, and 7.0 level JREs). As well an install type is provided for JREs defined by an &lt;a href=&quot; http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions&quot;&gt;execution environment description&lt;/a&gt; file.
95
      </documentation>
97
      </documentation>
96
   </annotation>
98
   </annotation>
97
99
(-)schema/vmInstalls.exsd (-1 / +15 lines)
Lines 71-77 Link Here
71
         <attribute name="home" type="string" use="required">
71
         <attribute name="home" type="string" use="required">
72
            <annotation>
72
            <annotation>
73
               <documentation>
73
               <documentation>
74
                  Path to the home installation directory for this VM install. Paths must be absolute and may use string substitution variables such as ${eclipse_home}. Since 3.4, this attribute may reference a VM definition file in addition to a home directory. The standard VM type included with the SDK supports &lt;a href=&quot; http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions&quot;&gt;execution environment descriptions&lt;/a&gt;.
74
                  Path to the home installation directory for this VM install. Paths must be absolute and may use string substitution variables such as ${eclipse_home}. Since 3.4, this attribute may reference a VM definition file in addition to a home directory. The Execution Environment VM type included with the SDK supports &lt;a href=&quot; http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions&quot;&gt;execution environment descriptions&lt;/a&gt;. When an execution environment description file is specified, any library elements are ignored. In this case, libraries are defined by the execution environment description file.
75
               </documentation>
75
               </documentation>
76
            </annotation>
76
            </annotation>
77
         </attribute>
77
         </attribute>
Lines 151-156 Link Here
151
&lt;/extension&gt; 
151
&lt;/extension&gt; 
152
&lt;/pre&gt;
152
&lt;/pre&gt;
153
&lt;/p&gt;
153
&lt;/p&gt;
154
&lt;p&gt;
155
The following example will create a JRE definition based on the contents of the specified execution environment description file. When an execution environment description file is provided as the home location the &quot;Execution Environment Description&quot; VM type must be specified for the &lt;code&gt;vmInstallType&lt;/code&gt; attribute.
156
&lt;/p&gt;
157
&lt;p&gt;
158
&lt;pre&gt;
159
&lt;extension point=&quot;org.eclipse.jdt.launching.vmInstalls&quot;&gt;
160
 &lt;vmInstall
161
  home=&quot;${eclipse_home}/jre-def.ee&quot;
162
  id=&quot;com.example.ee.id&quot;
163
  name=&quot;Default JRE&quot;
164
  vmInstallType=&quot;org.eclipse.jdt.launching.EEVMType&quot;/&gt;
165
&lt;/extension&gt; 
166
&lt;/pre&gt;
167
&lt;/p&gt;
154
      </documentation>
168
      </documentation>
155
   </annotation>
169
   </annotation>
156
170
(-)launching/org/eclipse/jdt/internal/launching/EEVMInstall.java (+74 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.jdt.internal.launching;
12
13
import java.io.File;
14
15
import org.eclipse.jdt.launching.IVMInstallType;
16
17
/**
18
 * A VM install created from an execution environment description file.
19
 * 
20
 * @since 3.4
21
 */
22
public class EEVMInstall extends StandardVM {
23
	
24
	/**
25
	 * Attribute key for Java version property
26
	 */
27
	public static final String ATTR_JAVA_VERSION = "ATTR_JAVA_VERSION"; //$NON-NLS-1$
28
	
29
	/**
30
	 * Attribute key for supported execution environment by this runtime
31
	 */
32
	public static final String ATTR_EXECUTION_ENVIRONMENT_ID = "ATTR_EXECUTION_ENVIRONMENT_ID"; //$NON-NLS-1$
33
	
34
	/**
35
	 * Attribute key for Java executable used by this VM
36
	 */
37
	public static final String ATTR_JAVA_EXE = "ATTR_JAVA_EXE"; //$NON-NLS-1$
38
39
	/**
40
	 * Path to file used to define the JRE
41
	 */
42
	public static final String ATTR_DEFINITION_FILE = "ATTR_DEFINITION_FILE"; //$NON-NLS-1$
43
	
44
	/**
45
	 * Constructs a VM install.
46
	 * 
47
	 * @param type vm type
48
	 * @param id unique id
49
	 */
50
	EEVMInstall(IVMInstallType type, String id) {
51
		super(type, id);
52
	}
53
54
	/* (non-Javadoc)
55
	 * @see org.eclipse.jdt.internal.launching.StandardVM#getJavaVersion()
56
	 */
57
	public String getJavaVersion() {
58
    	return getAttribute(ATTR_JAVA_VERSION);
59
	}
60
61
	/* (non-Javadoc)
62
	 * @see org.eclipse.jdt.internal.launching.StandardVM#getJavaExecutable()
63
	 */
64
	File getJavaExecutable() {
65
		String exe = getAttribute(ATTR_JAVA_EXE);
66
		if (exe != null) {
67
			return new File(exe);
68
		}
69
		return null;
70
	}
71
	
72
	
73
74
}
(-)buildnotes_jdt-debug.html (-19 / +15 lines)
Lines 42-62 Link Here
42
42
43
<h3>Support for Execution Environment Descriptions</h3>
43
<h3>Support for Execution Environment Descriptions</h3>
44
<p>An installed JRE can be defined by an <a href="http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions">execution 
44
<p>An installed JRE can be defined by an <a href="http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions">execution 
45
  environment description file</a>. The API for <code>IVMInstallType</code> and 
45
  environment description file</a>. A new 'Execution Environment Description' 
46
  <code>IVMInstall</code> have been augmented to allow for a file to be specified 
46
  VM install type shipped with the Eclipse SDK supports standard &quot;.ee&quot; 
47
  for an install location in addition to a home directory. The 'Standard VM Install 
47
  files.</p>
48
  Type' shipped with the Eclipse SDK supports standard &quot;.ee&quot; files.</p>
48
<p>API has been added to <code>JavaRuntime</code> to create a VM from an execution 
49
<p>This change effects the following methods in <code>IVMInstallType</code>, which 
49
  environment description file. A name and unique identifier must be provided 
50
  now accept the location of a description file as well as a home directory.</p>
50
  to create a new JRE.</p>
51
<ul>
51
<ul>
52
  <li><code>public IStatus validateInstallLocation(File installLocation)</code></li>
52
  <li><code>public VMStandin createVMFromDefinitionFile(File eeFile, String name, 
53
  <li><code>public LibraryLocation[] getDefaultLibraryLocations(File installLocation)</code></li>
53
    String id)</code></li>
54
</ul>
55
<p>This change effects the following methods in <code>IVMInstall</code>, which 
56
  can now accept/return a file as well as home directory.</p>
57
<ul>
58
  <li><code>public File getInstallLocation()</code></li>
59
  <li><code>public void setInstallLocation(File installLocation)</code></li>
60
</ul>
54
</ul>
61
<p>A new method has been added to <code>AbstractVMInstallType</code> to allow 
55
<p>A new method has been added to <code>AbstractVMInstallType</code> to allow 
62
  default arguments to be provided for newly created VM installs. Ideally, this 
56
  default arguments to be provided for newly created VM installs. Ideally, this 
Lines 68-78 Link Here
68
<ul>
62
<ul>
69
  <li><code>public String getDefaultVMArguments(File installLocation)</code></li>
63
  <li><code>public String getDefaultVMArguments(File installLocation)</code></li>
70
</ul>
64
</ul>
71
<p>As well, the specification of the following method in <code>AbstractVMInstallType</code> 
65
<h3>Support for custom wizard pages used to edit VM installs</h3>
72
  has been changed to allow a file to be supplied as an argument.</p>
66
<p>An new extension point (<code>org.eclipse.jdt.debug.ui.vmInstallPages</code>) 
73
<ul>
67
  allows a wizard page to be contributed for editing the properties of an <code>IVMInstall</code>. 
74
  <li><code>public URL getDefaultJavadocLocation(File installLocation)</code></li>
68
  The page is used when adding or editing an installed JRE via user preference. 
75
</ul>
69
  A standard page is provided based on the <code>IVMInstallType</code> and <code>IVMInstall</code> 
70
  interfaces. JDT contributes a page for editing a JRE based on an execution environment 
71
  description file.</p>
76
<h3>Support for setting a range of values in array objects</h3>
72
<h3>Support for setting a range of values in array objects</h3>
77
<p>API has been added to <code>IJavaArray</code> to support setting ranges of 
73
<p>API has been added to <code>IJavaArray</code> to support setting ranges of 
78
  values in the arrays. It is more efficient to set a range of values at once 
74
  values in the arrays. It is more efficient to set a range of values at once 
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryContentProvider.java (-1 / +3 lines)
Lines 142-148 Link Here
142
		for (int i = 0; i < libs.length; i++) {
142
		for (int i = 0; i < libs.length; i++) {
143
			fLibraries[i] = new LibraryStandin(libs[i]);
143
			fLibraries[i] = new LibraryStandin(libs[i]);
144
		}
144
		}
145
		fViewer.refresh();
145
		if (fViewer != null) {
146
			fViewer.refresh();
147
		}
146
	}
148
	}
147
149
148
	/**
150
	/**
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/JREMessages.properties (-5 / +21 lines)
Lines 15-20 Link Here
15
AbstractJavaCommandTab_4=&Alternate
15
AbstractJavaCommandTab_4=&Alternate
16
AbstractJavaCommandTab_Java_executable_must_be_specified_5=Java executable must be specified
16
AbstractJavaCommandTab_Java_executable_must_be_specified_5=Java executable must be specified
17
17
18
AddVMInstallWizard_0=Add JRE
18
BuildJREDescriptor_0=Workspace &default JRE ({0})
19
BuildJREDescriptor_0=Workspace &default JRE ({0})
19
20
20
InstalledJREsBlock_0=Name
21
InstalledJREsBlock_0=Name
Lines 46-51 Link Here
46
JREsComboBlock_0=No JREs defined in workspace
47
JREsComboBlock_0=No JREs defined in workspace
47
JREsComboBlock_4=E&xecution Environment:
48
JREsComboBlock_4=E&xecution Environment:
48
JREsComboBlock_5=No execution environments defined in workspace
49
JREsComboBlock_5=No execution environments defined in workspace
50
StandardVMPage_0=Add Standard VM
51
StandardVMPage_1=JRE Definition
52
StandardVMPage_2=Specify attributes for a JRE
49
JREContainerWizardPage_JRE_System_Library_1=JRE System Library
53
JREContainerWizardPage_JRE_System_Library_1=JRE System Library
50
JREContainerWizardPage_4=Select JRE for the project build path.
54
JREContainerWizardPage_4=Select JRE for the project build path.
51
JREContainerWizardPage_3=System library
55
JREContainerWizardPage_3=System library
Lines 58-74 Link Here
58
JREsPreferencePage_14=Conflicting compliance settings can be changed on the <a>Compiler</a> page.
62
JREsPreferencePage_14=Conflicting compliance settings can be changed on the <a>Compiler</a> page.
59
63
60
addVMDialog_duplicateName=The JRE name is already in use.
64
addVMDialog_duplicateName=The JRE name is already in use.
61
addVMDialog_enterLocation=Enter the location of the JRE.
65
addVMDialog_enterLocation=Enter the home directory of the JRE.
62
addVMDialog_enterName=Enter a name for the JRE.
66
addVMDialog_enterName=Enter a name for the JRE.
63
addVMDialog_jreHome=&JRE location:
67
EditVMInstallWizard_0=Edit JRE
68
addVMDialog_jreHome=&JRE home:
64
addVMDialog_jreName=JRE &name:
69
addVMDialog_jreName=JRE &name:
65
addVMDialog_jreType=JRE &type:
70
addVMDialog_jreType=JRE &type:
66
addVMDialog_locationNotExists=The location does not exist.
71
addVMDialog_locationNotExists=The home directory does not exist.
67
addVMDialog_pickJRERootDialog_message=Select the root directory of the JRE installation:
72
addVMDialog_pickJRERootDialog_message=Select the root directory of the JRE installation:
68
AddVMDialog_JRE_system_libraries__1=JRE system libraries:
73
AddVMDialog_JRE_system_libraries__1=JRE system libraries:
69
AddVMDialog_JRE_name_must_be_a_valid_file_name___0__1=JRE name must be a valid file name: {0}
74
AddVMDialog_JRE_name_must_be_a_valid_file_name___0__1=JRE name must be a valid file name: {0}
70
AddVMDialog_21=Definition &File...
75
AddVMDialog_21=Definition &File...
71
AddVMDialog_22=H&ome Directory...
76
AddVMDialog_22=Direct&ory...
72
AddVMDialog_23=Default &VM Arguments:
77
AddVMDialog_23=Default &VM Arguments:
73
78
74
JREsUpdater_0=Save VM Definitions
79
JREsUpdater_0=Save VM Definitions
Lines 76-82 Link Here
76
VMLibraryBlock_1=(none)
81
VMLibraryBlock_1=(none)
77
VMLibraryBlock_10=Jar Selection
82
VMLibraryBlock_10=Jar Selection
78
VMDetailsDialog_0=JRE Details
83
VMDetailsDialog_0=JRE Details
79
VMLibraryBlock_2=Javadoc location:
84
VMLibraryBlock_2=JRE System Libraries
80
VMLibraryBlock_11=Source &Attachment...
85
VMLibraryBlock_11=Source &Attachment...
81
VMLibraryBlock_16=Select to add an external JAR to the list
86
VMLibraryBlock_16=Select to add an external JAR to the list
82
VMLibraryBlock_17=Select to add a JavaDoc location to the selected library
87
VMLibraryBlock_17=Select to add a JavaDoc location to the selected library
Lines 101-103 Link Here
101
MacVMSearch_0=Searching for installed JREs
106
MacVMSearch_0=Searching for installed JREs
102
MacVMSearch_1=JVM {0} (MacOS X Default)
107
MacVMSearch_1=JVM {0} (MacOS X Default)
103
MacVMSearch_2=JVM {0}
108
MacVMSearch_2=JVM {0}
109
EEVMPage_0=Add EE VM
110
EEVMPage_1=&Definition File:
111
EEVMPage_2=F&ile...
112
EEVMPage_4=Enter definition file
113
EEVMPage_5=Definition file does not exist
114
EEVMPage_6=JRE Definition
115
EEVMPage_7=Specify attributes for a JRE
116
VMTypePage_0=Select JRE Type
117
VMTypePage_1=Select the type of JRE to add to the workspace.
118
VMTypePage_2=JRE Type
119
VMTypePage_3=Installed JRE &Types:
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/JREMessages.java (+33 lines)
Lines 25-30 Link Here
25
25
26
	public static String AddVMDialog_22;
26
	public static String AddVMDialog_22;
27
27
28
	public static String AddVMInstallWizard_0;
29
28
	public static String BuildJREDescriptor_0;
30
	public static String BuildJREDescriptor_0;
29
31
30
	public static String InstalledJREsBlock_0;
32
	public static String InstalledJREsBlock_0;
Lines 70-75 Link Here
70
	public static String addVMDialog_duplicateName;
72
	public static String addVMDialog_duplicateName;
71
	public static String addVMDialog_enterLocation;
73
	public static String addVMDialog_enterLocation;
72
	public static String addVMDialog_enterName;
74
	public static String addVMDialog_enterName;
75
76
	public static String EditVMInstallWizard_0;
73
	public static String addVMDialog_jreHome;
77
	public static String addVMDialog_jreHome;
74
	public static String addVMDialog_jreName;
78
	public static String addVMDialog_jreName;
75
	public static String addVMDialog_jreType;
79
	public static String addVMDialog_jreType;
Lines 100-107 Link Here
100
	public static String VMLibraryBlock_18;
104
	public static String VMLibraryBlock_18;
101
105
102
	public static String JREsUpdater_0;
106
	public static String JREsUpdater_0;
107
108
	public static String EEVMPage_0;
109
110
	public static String EEVMPage_1;
111
112
	public static String EEVMPage_2;
113
114
	public static String EEVMPage_4;
115
116
	public static String EEVMPage_5;
117
118
	public static String EEVMPage_6;
119
120
	public static String EEVMPage_7;
121
122
	public static String VMTypePage_0;
123
124
	public static String VMTypePage_1;
125
126
	public static String VMTypePage_2;
127
128
	public static String VMTypePage_3;
103
	public static String VMLibraryBlock_0;
129
	public static String VMLibraryBlock_0;
104
	public static String VMLibraryBlock_1;
130
	public static String VMLibraryBlock_1;
131
105
	public static String VMLibraryBlock_2;
132
	public static String VMLibraryBlock_2;
106
	public static String VMLibraryBlock_3;
133
	public static String VMLibraryBlock_3;
107
	public static String VMLibraryBlock_4;
134
	public static String VMLibraryBlock_4;
Lines 123-128 Link Here
123
150
124
	public static String JREsComboBlock_5;
151
	public static String JREsComboBlock_5;
125
152
153
	public static String StandardVMPage_0;
154
155
	public static String StandardVMPage_1;
156
157
	public static String StandardVMPage_2;
158
126
	public static String JREProfilesPreferencePage_0;
159
	public static String JREProfilesPreferencePage_0;
127
160
128
	public static String JREProfilesPreferencePage_1;
161
	public static String JREProfilesPreferencePage_1;
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/InstalledJREsBlock.java (-20 / +42 lines)
Lines 56-61 Link Here
56
import org.eclipse.jface.viewers.Viewer;
56
import org.eclipse.jface.viewers.Viewer;
57
import org.eclipse.jface.viewers.ViewerComparator;
57
import org.eclipse.jface.viewers.ViewerComparator;
58
import org.eclipse.jface.window.Window;
58
import org.eclipse.jface.window.Window;
59
import org.eclipse.jface.wizard.WizardDialog;
59
import org.eclipse.swt.SWT;
60
import org.eclipse.swt.SWT;
60
import org.eclipse.swt.events.KeyAdapter;
61
import org.eclipse.swt.events.KeyAdapter;
61
import org.eclipse.swt.events.KeyEvent;
62
import org.eclipse.swt.events.KeyEvent;
Lines 129-134 Link Here
129
	// happen very quickly
130
	// happen very quickly
130
	private static String fgLastUsedID;	
131
	private static String fgLastUsedID;	
131
	
132
	
133
	/**
134
	 * VM install type id for OSX VMs
135
	 */
136
	public static final String MACOSX_VM_TYPE_ID = "org.eclipse.jdt.internal.launching.macosx.MacOSXType"; //$NON-NLS-1$
137
	
132
	/** 
138
	/** 
133
	 * Content provider to show a list of JREs
139
	 * Content provider to show a list of JREs
134
	 */ 
140
	 */ 
Lines 357-373 Link Here
357
        ArrayList newEntries = new ArrayList();
363
        ArrayList newEntries = new ArrayList();
358
        while (it.hasNext()) {
364
        while (it.hasNext()) {
359
            IVMInstall selectedVM = (IVMInstall) it.next();
365
            IVMInstall selectedVM = (IVMInstall) it.next();
360
361
            // duplicate & add vm
366
            // duplicate & add vm
362
            VMStandin standin = new VMStandin(selectedVM, createUniqueId(selectedVM.getVMInstallType()));
367
            VMStandin standin = new VMStandin(selectedVM, createUniqueId(selectedVM.getVMInstallType()));
363
            standin.setName(generateName(selectedVM.getName()));
368
            standin.setName(generateName(selectedVM.getName()));
364
            AddVMDialog dialog = new AddVMDialog(this, getShell(), JavaRuntime.getVMInstallTypes(), standin);
369
			EditVMInstallWizard wizard = new EditVMInstallWizard(standin, (IVMInstall[]) fVMs.toArray(new IVMInstall[fVMs.size()]));
365
            dialog.setTitle(JREMessages.InstalledJREsBlock_18);
370
			WizardDialog dialog = new WizardDialog(getShell(), wizard);
366
            if (dialog.open() != Window.OK) {
371
			if (dialog.open() == Window.OK) {
367
                return;
372
				VMStandin result = wizard.getResult();
368
            }
373
				if (result != null) {
369
            newEntries.add(standin);
374
					// add the new VM
370
            fVMs.add(standin);
375
					fVMs.add(result);
376
					fVMList.refresh();
377
					fVMList.setSelection(new StructuredSelection(result));
378
				}
379
			}
371
        }
380
        }
372
        fVMList.refresh();
381
        fVMList.refresh();
373
        fVMList.setSelection(new StructuredSelection(newEntries.toArray()));
382
        fVMList.setSelection(new StructuredSelection(newEntries.toArray()));
Lines 543-557 Link Here
543
	}
552
	}
544
	
553
	
545
	/**
554
	/**
546
	 * Bring up a dialog that lets the user create a new VM definition.
555
	 * Bring up a wizard that lets the user create a new VM definition.
547
	 */
556
	 */
548
	private void addVM() {
557
	private void addVM() {
549
		AddVMDialog dialog= new AddVMDialog(this, getShell(), JavaRuntime.getVMInstallTypes(), null);
558
		AddVMInstallWizard wizard = new AddVMInstallWizard((IVMInstall[]) fVMs.toArray(new IVMInstall[fVMs.size()]));
550
		dialog.setTitle(JREMessages.InstalledJREsBlock_7); 
559
		WizardDialog dialog = new WizardDialog(getShell(), wizard);
551
		if (dialog.open() != Window.OK) {
560
		if (dialog.open() == Window.OK) {
552
			return;
561
			VMStandin result = wizard.getResult();
562
			if (result != null) {
563
				fVMs.add(result);
564
				fVMList.refresh();
565
				fVMList.setSelection(new StructuredSelection(result));
566
			}
553
		}
567
		}
554
		fVMList.refresh();
555
	}
568
	}
556
	
569
	
557
	/**
570
	/**
Lines 580-586 Link Here
580
	 */
593
	 */
581
	private void editVM() {
594
	private void editVM() {
582
		IStructuredSelection selection= (IStructuredSelection)fVMList.getSelection();
595
		IStructuredSelection selection= (IStructuredSelection)fVMList.getSelection();
583
		IVMInstall vm= (IVMInstall)selection.getFirstElement();
596
		VMStandin vm= (VMStandin)selection.getFirstElement();
584
		if (vm == null) {
597
		if (vm == null) {
585
			return;
598
			return;
586
		}
599
		}
Lines 588-600 Link Here
588
			VMDetailsDialog dialog= new VMDetailsDialog(getShell(), vm);
601
			VMDetailsDialog dialog= new VMDetailsDialog(getShell(), vm);
589
			dialog.open();
602
			dialog.open();
590
		} else {
603
		} else {
591
			AddVMDialog dialog= new AddVMDialog(this, getShell(), JavaRuntime.getVMInstallTypes(), vm);
604
			EditVMInstallWizard wizard = new EditVMInstallWizard(vm, (IVMInstall[]) fVMs.toArray(new IVMInstall[fVMs.size()]));
592
			dialog.setTitle(JREMessages.InstalledJREsBlock_8); 
605
			WizardDialog dialog = new WizardDialog(getShell(), wizard);
593
			if (dialog.open() != Window.OK) {
606
			if (dialog.open() == Window.OK) {
594
				return;
607
				VMStandin result = wizard.getResult();
608
				if (result != null) {
609
					// replace with the edited VM
610
					int index = fVMs.indexOf(vm);
611
					fVMs.remove(index);
612
					fVMs.add(index, result);
613
					fVMList.refresh();
614
					fVMList.setSelection(new StructuredSelection(result));
615
				}
595
			}
616
			}
596
			fVMList.refresh(vm);
597
		}
617
		}
618
		
619
		
598
	}
620
	}
599
	
621
	
600
	/**
622
	/**
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/MacVMSearch.java (-1 / +1 lines)
Lines 91-97 Link Here
91
		IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
91
		IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
92
		for (int i = 0; i < types.length; i++) {
92
		for (int i = 0; i < types.length; i++) {
93
			IVMInstallType installType = types[i];
93
			IVMInstallType installType = types[i];
94
			if (installType.getId().equals(AddVMDialog.MACOSX_VM_TYPE_ID)) {
94
			if (installType.getId().equals(InstalledJREsBlock.MACOSX_VM_TYPE_ID)) {
95
				return installType;
95
				return installType;
96
			}
96
			}
97
		}
97
		}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java (-659 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 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.jdt.internal.debug.ui.jres;
12
13
14
import java.io.File;
15
import java.io.IOException;
16
import java.net.URL;
17
import java.util.Arrays;
18
import java.util.Comparator;
19
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.ResourcesPlugin;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.Path;
25
import org.eclipse.core.runtime.Platform;
26
import org.eclipse.debug.core.DebugPlugin;
27
import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds;
28
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
29
import org.eclipse.jdt.internal.debug.ui.SWTFactory;
30
import org.eclipse.jdt.internal.debug.ui.StatusInfo;
31
import org.eclipse.jdt.internal.launching.StandardVMType;
32
import org.eclipse.jdt.launching.AbstractVMInstallType;
33
import org.eclipse.jdt.launching.IVMInstall;
34
import org.eclipse.jdt.launching.IVMInstall2;
35
import org.eclipse.jdt.launching.IVMInstallType;
36
import org.eclipse.jdt.launching.VMStandin;
37
import org.eclipse.jface.dialogs.IDialogConstants;
38
import org.eclipse.jface.dialogs.IDialogSettings;
39
import org.eclipse.jface.dialogs.StatusDialog;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.custom.BusyIndicator;
42
import org.eclipse.swt.events.ModifyEvent;
43
import org.eclipse.swt.events.ModifyListener;
44
import org.eclipse.swt.events.SelectionEvent;
45
import org.eclipse.swt.events.SelectionListener;
46
import org.eclipse.swt.graphics.Point;
47
import org.eclipse.swt.layout.GridData;
48
import org.eclipse.swt.layout.GridLayout;
49
import org.eclipse.swt.widgets.Button;
50
import org.eclipse.swt.widgets.Combo;
51
import org.eclipse.swt.widgets.Composite;
52
import org.eclipse.swt.widgets.Control;
53
import org.eclipse.swt.widgets.DirectoryDialog;
54
import org.eclipse.swt.widgets.FileDialog;
55
import org.eclipse.swt.widgets.Shell;
56
import org.eclipse.swt.widgets.Text;
57
import org.eclipse.ui.PlatformUI;
58
59
import com.ibm.icu.text.MessageFormat;
60
61
/**
62
 * Provides the Add VM dialog
63
 */
64
public class AddVMDialog extends StatusDialog {
65
	
66
	/**
67
	 * VM install type id for OSX VMs
68
	 */
69
	public static final String MACOSX_VM_TYPE_ID = "org.eclipse.jdt.internal.launching.macosx.MacOSXType"; //$NON-NLS-1$
70
	
71
	private IAddVMDialogRequestor fRequestor;
72
	private IVMInstall fEditedVM;
73
	private IVMInstallType[] fVMTypes;
74
	private IVMInstallType fSelectedVMType;
75
	private Combo fVMCombo;
76
	private Text fVMName;
77
	private Text fVMArgs;
78
	private Text fJRERoot;
79
	private Button fFileButton;
80
	private VMLibraryBlock fLibraryBlock;
81
// the VM install's javadoc location
82
	private URL fJavadocLocation = null;
83
	private boolean fAutoDetectAttributes = false;
84
	private IStatus[] fStatus;
85
	private int fPrevIndex = -1;
86
		
87
	/**
88
	 * Constructor
89
	 * @param requestor dialog validation requester
90
	 * @param shell the parent shell 
91
	 * @param vmInstallTypes the types of VM installs
92
	 * @param editedVM the editedVM
93
	 */
94
	public AddVMDialog(IAddVMDialogRequestor requestor, Shell shell, IVMInstallType[] vmInstallTypes, IVMInstall editedVM) {
95
		super(shell);
96
		setShellStyle(getShellStyle() | SWT.RESIZE);
97
		fRequestor = requestor;
98
		fStatus = new IStatus[5];
99
		for (int i= 0; i < fStatus.length; i++) {
100
			fStatus[i] = new StatusInfo();
101
		}
102
		fVMTypes = vmInstallTypes;
103
		sortVMTypes();
104
		int typeIndex = 0;
105
		if (Platform.OS_MACOSX.equals(Platform.getOS())) {
106
			// select OSX VM type by default
107
			for (int i = 0; i < fVMTypes.length; i++) {
108
				IVMInstallType type = fVMTypes[i];
109
				if (type.getId().equals(MACOSX_VM_TYPE_ID)) {
110
					typeIndex = i;
111
					break;
112
				}
113
			}
114
		}
115
		fSelectedVMType = editedVM != null ? editedVM.getVMInstallType() : vmInstallTypes[typeIndex];
116
		fEditedVM = editedVM;
117
	//only detect the javadoc location if not already set
118
		fAutoDetectAttributes = fEditedVM == null || fEditedVM.getJavadocLocation() == null;
119
	}
120
121
	/**
122
	 * This method is used to sort the array of VM install types, placing 
123
	 * the 'Standard VM' type first, if it exists
124
	 * 
125
	 * @since 3.3.0
126
	 */
127
	private void sortVMTypes() {
128
		Comparator compare = new Comparator() {
129
			public int compare(Object o1, Object o2) {
130
				if(o1 instanceof IVMInstallType && o2 instanceof IVMInstallType) {
131
					return ((IVMInstallType) o1).getName().compareTo(((IVMInstallType) o2).getName());
132
				}
133
				return 0;
134
			}
135
		};
136
		//first find the 'Standard VM' and set it at position 0
137
		for(int i = 0; i < fVMTypes.length; i++) {
138
			if(fVMTypes[i].getId().equals("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType")) { //$NON-NLS-1$
139
				if(i > 0) {
140
					IVMInstallType tmp = fVMTypes[0];
141
					fVMTypes[0] = fVMTypes[i];
142
					fVMTypes[i] = tmp;
143
					break;
144
				}
145
				else {
146
					break;
147
				}
148
			}
149
		}
150
		if(fVMTypes[0].getId().equals("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType")) { //$NON-NLS-1$
151
			Arrays.sort(fVMTypes, 1, fVMTypes.length, compare);
152
		}
153
		else {
154
			Arrays.sort(fVMTypes, compare);
155
		}
156
	}
157
	
158
	/* (non-Javadoc)
159
	 * @see org.eclipse.jface.dialogs.StatusDialog#configureShell(org.eclipse.swt.widgets.Shell)
160
	 */
161
	protected void configureShell(Shell newShell) {
162
		super.configureShell(newShell);
163
		PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaDebugHelpContextIds.EDIT_JRE_DIALOG);
164
	}		
165
	
166
	/**
167
	 * Returns the VM name from the text control
168
	 * @return
169
	 */
170
	protected String getVMName() {
171
		return fVMName.getText();
172
	}
173
		
174
	/**
175
	 * Returns the installation location as a file from the JRE root text control
176
	 * @return the installation location as a file
177
	 */
178
	protected File getInstallLocation() {
179
		return new File(fJRERoot.getText());
180
	}
181
		
182
	/* (non-Javadoc)
183
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
184
	 */
185
	protected Control createDialogArea(Composite ancestor) {
186
		Composite parent = (Composite)super.createDialogArea(ancestor);
187
		((GridLayout)parent.getLayout()).numColumns = 3;
188
	//VM type
189
		SWTFactory.createLabel(parent, JREMessages.addVMDialog_jreType, 1);
190
		fVMCombo = SWTFactory.createCombo(parent, SWT.READ_ONLY, 2, getVMTypeNames());
191
	// VM location
192
		SWTFactory.createLabel(parent, JREMessages.addVMDialog_jreHome, 1);
193
		fJRERoot = SWTFactory.createSingleText(parent, 2);
194
		Composite buttons = SWTFactory.createComposite(parent, parent.getFont(), 2, 4, GridData.HORIZONTAL_ALIGN_END, 0, 0);
195
		Button folders = SWTFactory.createPushButton(buttons, JREMessages.AddVMDialog_22, null);
196
		GridData data = (GridData) folders.getLayoutData();
197
		data.horizontalAlignment = GridData.END;
198
		fFileButton = SWTFactory.createPushButton(buttons, JREMessages.AddVMDialog_21, null);
199
		data = (GridData) fFileButton.getLayoutData();
200
		data.horizontalAlignment = GridData.END;
201
	//VM name
202
		SWTFactory.createLabel(parent, JREMessages.addVMDialog_jreName, 1);
203
		fVMName = SWTFactory.createSingleText(parent, 2);
204
	//VM arguments
205
		SWTFactory.createLabel(parent, JREMessages.AddVMDialog_23, 1);
206
		fVMArgs = SWTFactory.createSingleText(parent, 2);
207
	//VM libraries block 
208
		SWTFactory.createLabel(parent, JREMessages.AddVMDialog_JRE_system_libraries__1, 3);
209
		fLibraryBlock = new VMLibraryBlock(this);
210
		Control block = fLibraryBlock.createControl(parent);
211
		GridData gd = new GridData(GridData.FILL_BOTH);
212
		gd.horizontalSpan = 3;
213
		block.setLayoutData(gd);
214
	
215
	//initialize the fields
216
		initializeFields();
217
		
218
	//add the listeners now to prevent them from monkeying with initialized settings
219
		fVMCombo.addSelectionListener(new SelectionListener() {
220
			public void widgetDefaultSelected(SelectionEvent e) {}
221
			public void widgetSelected(SelectionEvent e) {
222
				updateVMType();
223
			}
224
		});
225
		fVMName.addModifyListener(new ModifyListener() {
226
			public void modifyText(ModifyEvent e) {
227
				validateVMName();
228
				updateStatusLine();	
229
			}
230
		});
231
		fJRERoot.addModifyListener(new ModifyListener() {
232
			public void modifyText(ModifyEvent e) {
233
				validateJRELocation();
234
				updateStatusLine();
235
			}
236
		});
237
		folders.addSelectionListener(new SelectionListener() {
238
			public void widgetDefaultSelected(SelectionEvent e) {}
239
			public void widgetSelected(SelectionEvent e) {
240
				DirectoryDialog dialog = new DirectoryDialog(getShell());
241
				File file = new File(fJRERoot.getText());
242
				String text = fJRERoot.getText();
243
				if (file.isFile()) {
244
					text = file.getParentFile().getAbsolutePath();
245
				}
246
				dialog.setFilterPath(text);
247
				dialog.setMessage(JREMessages.addVMDialog_pickJRERootDialog_message); 
248
				String newPath = dialog.open();
249
				if (newPath != null) {
250
					fJRERoot.setText(newPath);
251
				}
252
			}
253
		});
254
		fFileButton.addSelectionListener(new SelectionListener() {
255
			public void widgetDefaultSelected(SelectionEvent e) {}
256
			public void widgetSelected(SelectionEvent e) {
257
				FileDialog dialog = new FileDialog(getShell());
258
				dialog.setFilterExtensions(new String[]{"*.ee"}); //$NON-NLS-1$
259
				dialog.setFilterPath(fJRERoot.getText());
260
				String newPath = dialog.open();
261
				if (newPath != null) {
262
					fJRERoot.setText(newPath);
263
				}
264
			}
265
		});		
266
		applyDialogFont(parent);
267
		return parent;
268
	}
269
	
270
	/**
271
	 * Updates the JRE location status and initializes the library block
272
	 */
273
	private void updateVMType() {
274
		int selIndex = fVMCombo.getSelectionIndex();
275
		if (selIndex == fPrevIndex) {
276
			return;
277
		}
278
		fPrevIndex = selIndex;
279
		if (selIndex >= 0 && selIndex < fVMTypes.length) {
280
			fSelectedVMType= fVMTypes[selIndex];
281
		}
282
		validateJRELocation();
283
		fLibraryBlock.initializeFrom(fEditedVM, fSelectedVMType);
284
		updateFileButton();
285
		updateStatusLine();
286
	}	
287
	
288
	/**
289
	 * Updates enabled state of the "Definition File..." button.
290
	 */
291
	private void updateFileButton() {
292
		fFileButton.setEnabled(fSelectedVMType.getId().equals(StandardVMType.ID_STANDARD_VM_TYPE));
293
	}
294
	
295
	/* (non-Javadoc)
296
	 * @see org.eclipse.jface.dialogs.StatusDialog#create()
297
	 */
298
	public void create() {
299
		super.create();
300
		if (fJRERoot.getText().length() == 0) {
301
			fJRERoot.setFocus();
302
		} else {
303
			fVMName.setFocus();
304
		}
305
		selectVMType();  
306
	}
307
	
308
	/**
309
	 * Returns the VM type names
310
	 * @return an array of strings with the names of the applicable VMs
311
	 */
312
	private String[] getVMTypeNames() {
313
		String[] names =  new String[fVMTypes.length];
314
		for (int i = 0; i < fVMTypes.length; i++) {
315
			names[i]= fVMTypes[i].getName();
316
		}
317
		return names;
318
	}
319
	
320
	/**
321
	 * Selects the corresponding VM for fSelectedVMType
322
	 */
323
	private void selectVMType() {
324
		for (int i= 0; i < fVMTypes.length; i++) {
325
			if (fSelectedVMType == fVMTypes[i]) {
326
				if(i < fVMCombo.getItemCount()) {
327
					fVMCombo.select(i);
328
					return;
329
				}
330
			}
331
		}
332
	}
333
	
334
	/**
335
	 * Initialize the dialogs fields
336
	 */
337
	private void initializeFields() {
338
		if (fEditedVM == null) {
339
			fVMName.setText(""); //$NON-NLS-1$
340
			fJRERoot.setText(""); //$NON-NLS-1$
341
			fLibraryBlock.initializeFrom(null, fSelectedVMType);
342
			fVMArgs.setText(""); //$NON-NLS-1$	
343
		} else {
344
			fVMCombo.setEnabled(false);
345
			fVMName.setText(fEditedVM.getName());
346
			fJRERoot.setText(fEditedVM.getInstallLocation().getAbsolutePath());
347
			fLibraryBlock.initializeFrom(fEditedVM, fSelectedVMType);
348
			if (fEditedVM instanceof IVMInstall2) {
349
				IVMInstall2 vm2 = (IVMInstall2) fEditedVM;
350
				String vmArgs = vm2.getVMArgs();
351
				if (vmArgs != null) {
352
					fVMArgs.setText(vmArgs);
353
				}
354
			} else {
355
				String[] vmArgs = fEditedVM.getVMArguments();
356
				if (vmArgs != null) {
357
					StringBuffer buffer = new StringBuffer();
358
					int length= vmArgs.length;
359
					if (length > 0) {
360
						buffer.append(vmArgs[0]);
361
						for (int i = 1; i < length; i++) {
362
							buffer.append(' ').append(vmArgs[i]);
363
						}
364
					}
365
					fVMArgs.setText(buffer.toString());
366
				}				
367
			}
368
		}
369
		updateFileButton();
370
		validateVMName();
371
		updateStatusLine();
372
	}
373
	
374
	/**
375
	 * Validates the JRE location
376
	 * @return the status after validating the JRE location
377
	 */
378
	private IStatus validateJRELocation() {
379
		String locationName = fJRERoot.getText();
380
		IStatus s = null;
381
		File file = null;
382
		if (locationName.length() == 0) {
383
			s = new StatusInfo(IStatus.INFO, JREMessages.addVMDialog_enterLocation); 
384
		} 
385
		else {
386
			file = new File(locationName);
387
			if (!file.exists()) {
388
				s = new StatusInfo(IStatus.ERROR, JREMessages.addVMDialog_locationNotExists); 
389
			} 
390
			else {
391
				final IStatus[] temp = new IStatus[1];
392
				final File tempFile = file; 
393
				Runnable r = new Runnable() {
394
					public void run() {
395
						temp[0] = fSelectedVMType.validateInstallLocation(tempFile);
396
					}
397
				};
398
				BusyIndicator.showWhile(getShell().getDisplay(), r);
399
				s = temp[0];
400
			}
401
		}
402
		if (s.isOK()) {
403
			fLibraryBlock.setHomeDirectory(file);
404
			String name = fVMName.getText();
405
			if (name == null || name.trim().length() == 0) {
406
				// auto-generate VM name
407
				if (file.isFile()) {
408
					String fileName = file.getName();
409
					int index = fileName.lastIndexOf(".ee"); //$NON-NLS-1$
410
					if (index > 0) {
411
						fileName = fileName.substring(0, index);
412
					}
413
					fVMName.setText(fileName);
414
				} else {
415
					try {
416
						String genName = null;
417
						IPath path = new Path(file.getCanonicalPath());
418
						int segs = path.segmentCount();
419
						if (segs == 1) {
420
							genName = path.segment(0);
421
						} 
422
						else if (segs >= 2) {
423
							String last = path.lastSegment();
424
							if ("jre".equalsIgnoreCase(last)) { //$NON-NLS-1$
425
								genName = path.segment(segs - 2);
426
							} 
427
							else {
428
								genName = last;
429
							}
430
						}
431
						if (genName != null) {
432
							fVMName.setText(genName);
433
						}
434
					} catch (IOException e) {}
435
				}
436
			}
437
		} else {
438
			fLibraryBlock.setHomeDirectory(null);
439
		}
440
		fLibraryBlock.restoreDefaultLibraries();
441
		detectJavadocLocation();
442
		fStatus[1] = s;
443
		return s;
444
	}
445
	
446
	/**
447
	 * Auto-detects the default javadoc location
448
	 */
449
	private void detectJavadocLocation() {
450
		if (fAutoDetectAttributes) {
451
			if (fSelectedVMType instanceof AbstractVMInstallType) {
452
				AbstractVMInstallType type = (AbstractVMInstallType)fSelectedVMType;
453
				fJavadocLocation = type.getDefaultJavadocLocation(getInstallLocation());
454
				String args = type.getDefaultVMArguments(getInstallLocation());
455
				if (args != null) {
456
					fVMArgs.setText(args);
457
				}
458
			}
459
		} else {
460
			fJavadocLocation = fEditedVM.getJavadocLocation();
461
		}
462
	}
463
464
	/**
465
	 * Validates the entered name of the VM
466
	 * @return the status of the name validation
467
	 */
468
	private IStatus validateVMName() {
469
		StatusInfo status= new StatusInfo();
470
		String name= fVMName.getText();
471
		if (name == null || name.trim().length() == 0) {
472
			status.setInfo(JREMessages.addVMDialog_enterName); 
473
		} else {
474
			if (fRequestor.isDuplicateName(name) && (fEditedVM == null || !name.equals(fEditedVM.getName()))) {
475
				status.setError(JREMessages.addVMDialog_duplicateName); 
476
			} else {
477
				IStatus s = ResourcesPlugin.getWorkspace().validateName(name, IResource.FILE);
478
				if (!s.isOK()) {
479
					status.setError(MessageFormat.format(JREMessages.AddVMDialog_JRE_name_must_be_a_valid_file_name___0__1, new String[]{s.getMessage()})); 
480
				}
481
			}
482
		}
483
		fStatus[0] = status;
484
		return status;
485
	}
486
	
487
	/**
488
	 * Updates the status line to show/hide messages to the user 
489
	 */
490
	protected void updateStatusLine() {
491
		IStatus max= null;
492
		for (int i = 0; i < fStatus.length; i++) {
493
			IStatus curr = fStatus[i];
494
			if (curr.matches(IStatus.ERROR)) {
495
				updateStatus(curr);
496
				return;
497
			}
498
			if (max == null || curr.getSeverity() > max.getSeverity()) {
499
				max = curr;
500
			}
501
		}
502
		updateStatus(max);
503
	}
504
	
505
	/**
506
	 * Returns the URL for the javadoc location
507
	 * @return the URL for the javadoc location
508
	 */
509
	protected URL getURL() {
510
		return fJavadocLocation;
511
	}
512
	
513
	/* (non-Javadoc)
514
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
515
	 */
516
	protected void okPressed() {
517
		if (fEditedVM == null) {
518
			IVMInstall vm = new VMStandin(fSelectedVMType, createUniqueId(fSelectedVMType));
519
			setFieldValuesToVM(vm);
520
			fRequestor.vmAdded(vm);
521
		} else {
522
			setFieldValuesToVM(fEditedVM);
523
		}
524
		super.okPressed();
525
	}
526
	
527
	/**
528
	 * Creates a unique name for the VMInstallType
529
	 * @param vmType the vm install type
530
	 * @return a unique name
531
	 */
532
	private String createUniqueId(IVMInstallType vmType) {
533
		String id = null;
534
		do {
535
			id = String.valueOf(System.currentTimeMillis());
536
		} while (vmType.findVMInstall(id) != null);
537
		return id;
538
	}
539
	
540
	/**
541
	 * initialize fields to the specified VM
542
	 * @param vm the VM to initialize from
543
	 */
544
	protected void setFieldValuesToVM(IVMInstall vm) {
545
		File dir = new File(fJRERoot.getText());
546
		try {
547
			vm.setInstallLocation(dir.getCanonicalFile());
548
		} 
549
		catch (IOException e) {
550
			vm.setInstallLocation(dir.getAbsoluteFile());
551
		}
552
		vm.setName(fVMName.getText());
553
		vm.setJavadocLocation(getURL());
554
		
555
		String argString = fVMArgs.getText().trim();
556
		if (vm instanceof IVMInstall2) {
557
			IVMInstall2 vm2 = (IVMInstall2) vm;
558
			if (argString != null && argString.length() > 0) {
559
				vm2.setVMArgs(argString);			
560
			} 
561
			else {
562
				vm2.setVMArgs(null);
563
			}
564
		} 
565
		else {
566
			if (argString != null && argString.length() > 0) {
567
				vm.setVMArguments(DebugPlugin.parseArguments(argString));			
568
			} 
569
			else {
570
				vm.setVMArguments(null);
571
			}			
572
		}
573
		fLibraryBlock.performApply(vm);
574
	}
575
	
576
	/**
577
	 * returns an absolute file or an empty file if the path is either null or zero length
578
	 * @param path the path to the file
579
	 * @return a new file
580
	 */
581
	protected File getAbsoluteFileOrEmpty(String path) {
582
		if (path == null || path.length() == 0) {
583
			return new File(""); //$NON-NLS-1$
584
		}
585
		return new File(path).getAbsoluteFile();
586
	}
587
	
588
	/**
589
	 * @return the status of the system library 
590
	 */
591
	protected IStatus getSystemLibraryStatus() {
592
		return fStatus[3];
593
	}
594
	
595
	/**
596
	 * Allows the VM page to set the status of the current system library
597
	 * @param status the specified status
598
	 */
599
	protected void setSystemLibraryStatus(IStatus status) {
600
		fStatus[3] = status;
601
	}
602
	
603
	/**
604
	 * Updates the status of the OK button to reflect the given status.
605
	 * Subclasses may override this method to update additional buttons.
606
	 * @param status the status.
607
	 */
608
	protected void updateButtonsEnableState(IStatus status) {
609
		Button ok = getButton(IDialogConstants.OK_ID);
610
		if (ok != null && !ok.isDisposed())
611
			ok.setEnabled(status.getSeverity() == IStatus.OK);
612
	}	
613
	
614
	/**
615
	 * Returns the name of the section that this dialog stores its settings in
616
	 * 
617
	 * @return String
618
	 */
619
	protected String getDialogSettingsSectionName() {
620
		return "ADD_VM_DIALOG_SECTION"; //$NON-NLS-1$
621
	}
622
	
623
	 /* (non-Javadoc)
624
     * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
625
     */
626
    protected IDialogSettings getDialogBoundsSettings() {
627
    	 IDialogSettings settings = JDIDebugUIPlugin.getDefault().getDialogSettings();
628
         IDialogSettings section = settings.getSection(getDialogSettingsSectionName());
629
         if (section == null) {
630
             section = settings.addNewSection(getDialogSettingsSectionName());
631
         } 
632
         return section;
633
    }
634
    
635
	/* (non-Javadoc)
636
	 * @see org.eclipse.jface.dialogs.Dialog#getInitialSize()
637
	 */
638
	protected Point getInitialSize() {
639
		IDialogSettings settings = getDialogBoundsSettings();
640
		if(settings != null) {
641
			try {
642
				int width = settings.getInt("DIALOG_WIDTH"); //$NON-NLS-1$
643
				int height = settings.getInt("DIALOG_HEIGHT"); //$NON-NLS-1$
644
				if(width > 0 & height > 0) {
645
					return new Point(width, height);
646
				}
647
			}
648
			catch (NumberFormatException nfe) {
649
				return new Point(500, 570);
650
			}
651
		}
652
		return new Point(500, 570);
653
	}
654
655
	protected void setButtonLayoutData(Button button) {
656
		super.setButtonLayoutData(button);
657
	}
658
    
659
}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/VMLibraryBlock.java (-90 / +98 lines)
Lines 21-34 Link Here
21
import org.eclipse.core.runtime.Status;
21
import org.eclipse.core.runtime.Status;
22
import org.eclipse.jdt.core.IClasspathEntry;
22
import org.eclipse.jdt.core.IClasspathEntry;
23
import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
23
import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
24
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
24
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
25
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
25
import org.eclipse.jdt.internal.debug.ui.SWTFactory;
26
import org.eclipse.jdt.internal.debug.ui.SWTFactory;
26
import org.eclipse.jdt.internal.debug.ui.jres.LibraryContentProvider.SubElement;
27
import org.eclipse.jdt.internal.debug.ui.jres.LibraryContentProvider.SubElement;
28
import org.eclipse.jdt.internal.launching.EEVMType;
27
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
29
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
28
import org.eclipse.jdt.launching.IVMInstall;
30
import org.eclipse.jdt.launching.IVMInstall;
29
import org.eclipse.jdt.launching.IVMInstallType;
30
import org.eclipse.jdt.launching.JavaRuntime;
31
import org.eclipse.jdt.launching.JavaRuntime;
31
import org.eclipse.jdt.launching.LibraryLocation;
32
import org.eclipse.jdt.launching.LibraryLocation;
33
import org.eclipse.jdt.launching.VMStandin;
32
import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess;
34
import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess;
33
import org.eclipse.jface.dialogs.IDialogSettings;
35
import org.eclipse.jface.dialogs.IDialogSettings;
34
import org.eclipse.jface.viewers.DoubleClickEvent;
36
import org.eclipse.jface.viewers.DoubleClickEvent;
Lines 44-57 Link Here
44
import org.eclipse.swt.layout.GridData;
46
import org.eclipse.swt.layout.GridData;
45
import org.eclipse.swt.widgets.Button;
47
import org.eclipse.swt.widgets.Button;
46
import org.eclipse.swt.widgets.Composite;
48
import org.eclipse.swt.widgets.Composite;
47
import org.eclipse.swt.widgets.Control;
48
import org.eclipse.swt.widgets.FileDialog;
49
import org.eclipse.swt.widgets.FileDialog;
49
 
50
 
50
/**
51
/**
51
 * Control used to edit the libraries associated with a VM install
52
 * Control used to edit the libraries associated with a VM install
52
 */
53
 */
53
public class VMLibraryBlock implements SelectionListener, ISelectionChangedListener {
54
public class VMLibraryBlock extends AbstractVMInstallPage implements SelectionListener, ISelectionChangedListener {
54
	
55
55
	/**
56
	/**
56
	 * Attribute name for the last path used to open a file/directory chooser
57
	 * Attribute name for the last path used to open a file/directory chooser
57
	 * dialog.
58
	 * dialog.
Lines 64-76 Link Here
64
	protected static final String DIALOG_SETTINGS_PREFIX = "VMLibraryBlock"; //$NON-NLS-1$
65
	protected static final String DIALOG_SETTINGS_PREFIX = "VMLibraryBlock"; //$NON-NLS-1$
65
	
66
	
66
	protected boolean fInCallback = false;
67
	protected boolean fInCallback = false;
67
	protected IVMInstall fVmInstall;
68
	protected VMStandin fVmInstall;
68
	protected IVMInstallType fVmInstallType;
69
	protected File fHome;
70
	
69
	
71
	//widgets
70
	//widgets
72
	protected LibraryContentProvider fLibraryContentProvider;
71
	protected LibraryContentProvider fLibraryContentProvider;
73
	protected AddVMDialog fDialog = null;
74
	protected TreeViewer fLibraryViewer;
72
	protected TreeViewer fLibraryViewer;
75
	private Button fUpButton;
73
	private Button fUpButton;
76
	private Button fDownButton;
74
	private Button fDownButton;
Lines 80-98 Link Here
80
	private Button fSourceButton;
78
	private Button fSourceButton;
81
	protected Button fDefaultButton;
79
	protected Button fDefaultButton;
82
	
80
	
81
	private IStatus[] fLibStatus;
82
	
83
	/**
83
	/**
84
	 * Constructor for VMLibraryBlock.
84
	 * Constructs a new wizard page with the given name.
85
	 * 
86
	 * @param pageName page name
85
	 */
87
	 */
86
	public VMLibraryBlock(AddVMDialog dialog) {
88
	VMLibraryBlock() {
87
		fDialog = dialog;
89
		super(JREMessages.VMLibraryBlock_2);
88
	}
90
		fLibStatus = new IStatus[]{Status.OK_STATUS};
91
	}	
89
92
90
	/**
93
	/* (non-Javadoc)
91
	 * Creates and returns the source lookup control.
94
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
92
	 * 
93
	 * @param parent the parent widget of this control
94
	 */
95
	 */
95
	public Control createControl(Composite parent) {
96
	public void createControl(Composite parent) {
96
		Font font = parent.getFont();
97
		Font font = parent.getFont();
97
		
98
		
98
		Composite comp = SWTFactory.createComposite(parent, font, 2, 1, GridData.FILL_BOTH, 0, 0);
99
		Composite comp = SWTFactory.createComposite(parent, font, 2, 1, GridData.FILL_BOTH, 0, 0);
Lines 132-193 Link Here
132
		fDefaultButton = SWTFactory.createPushButton(pathButtonComp, JREMessages.VMLibraryBlock_9, JREMessages.VMLibraryBlock_15, null);
133
		fDefaultButton = SWTFactory.createPushButton(pathButtonComp, JREMessages.VMLibraryBlock_9, JREMessages.VMLibraryBlock_15, null);
133
		fDefaultButton.addSelectionListener(this);
134
		fDefaultButton.addSelectionListener(this);
134
		
135
		
135
		return comp;
136
		setControl(comp);
136
	}
137
	}
137
138
138
	/**
139
	/**
139
	 * The "default" button has been toggled
140
	 * The "default" button has been toggled
140
	 */
141
	 */
141
	public void restoreDefaultLibraries() {
142
	private void restoreDefaultLibraries() {
142
		LibraryLocation[] libs = null;
143
		LibraryLocation[] libs = null;
143
		File installLocation = getHomeDirectory();
144
		File installLocation = null;
144
		if (installLocation == null) {
145
		if (fVmInstall != null) {
145
			libs = new LibraryLocation[0];
146
			if (EEVMType.ID_EE_VM_TYPE.equals(fVmInstall.getVMInstallType().getId())) {
146
		} else {
147
				File definitionFile = EEVMType.getDefinitionFile(fVmInstall);
147
			libs = getVMInstallType().getDefaultLibraryLocations(installLocation);
148
				if (definitionFile != null) {
149
					libs = EEVMType.getLibraryLocations(definitionFile);
150
				} else {
151
					libs = new LibraryLocation[0];
152
				}
153
			} else {
154
				installLocation = fVmInstall.getInstallLocation();
155
				if (installLocation == null) {
156
					libs = new LibraryLocation[0];
157
				} else {
158
					libs = fVmInstall.getVMInstallType().getDefaultLibraryLocations(installLocation);
159
				}
160
			}
148
		}
161
		}
149
		fLibraryContentProvider.setLibraries(libs);
162
		fLibraryContentProvider.setLibraries(libs);
150
		update();
163
		update();
151
	}
164
	}
152
	
165
	
153
	/**
166
	/**
154
	 * Initializes this control based on the settings in the given
155
	 * vm install and type.
156
	 * 
157
	 * @param vm vm or <code>null</code> if none
158
	 * @param type type of vm install
159
	 */
160
	public void initializeFrom(IVMInstall vm, IVMInstallType type) {
161
		fVmInstall = vm;
162
		fVmInstallType = type;
163
		if (vm != null) {
164
			setHomeDirectory(vm.getInstallLocation());
165
			fLibraryContentProvider.setLibraries(JavaRuntime.getLibraryLocations(getVMInstall()));
166
		}
167
		update();
168
	}
169
	
170
	/**
171
	 * Sets the home directory of the VM Install the user has chosen
172
	 */
173
	public void setHomeDirectory(File file) {
174
		fHome = file;
175
	}
176
	
177
	/**
178
	 * Returns the home directory
179
	 */
180
	protected File getHomeDirectory() {
181
		return fHome;
182
	}
183
	
184
	/**
185
	 * Updates buttons and status based on current libraries
167
	 * Updates buttons and status based on current libraries
186
	 */
168
	 */
187
	public void update() {
169
	private void update() {
188
		updateButtons();
170
		updateButtons();
189
		IStatus status = Status.OK_STATUS;
171
		IStatus status = Status.OK_STATUS;
190
		if (fLibraryContentProvider.getLibraries().length == 0) { // && !isDefaultSystemLibrary()) {
172
		if (fLibraryContentProvider.getLibraries().length == 0) {
191
			status = new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), IJavaDebugUIConstants.INTERNAL_ERROR, "Libraries cannot be empty.", null); //$NON-NLS-1$
173
			status = new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), IJavaDebugUIConstants.INTERNAL_ERROR, "Libraries cannot be empty.", null); //$NON-NLS-1$
192
		}
174
		}
193
		LibraryStandin[] standins = fLibraryContentProvider.getStandins();
175
		LibraryStandin[] standins = fLibraryContentProvider.getStandins();
Lines 198-218 Link Here
198
				break;
180
				break;
199
			}
181
			}
200
		}
182
		}
201
		fDialog.setSystemLibraryStatus(status);
183
		fLibStatus[0] = status;
202
		fDialog.updateStatusLine();
184
		if (status.isOK()) {
203
	}
185
			setErrorMessage(null);
204
	
186
			setPageComplete(true);
205
	/**
206
	 * Saves settings in the given working copy
207
	 */
208
	public void performApply(IVMInstall vm) {
209
		if (isDefaultLocations(vm)) {
210
			vm.setLibraryLocations(null);
211
		} else {
187
		} else {
212
			LibraryLocation[] libs = fLibraryContentProvider.getLibraries();
188
			setErrorMessage(status.getMessage());
213
			vm.setLibraryLocations(libs);
189
			setPageComplete(false);
214
		}		
190
		}
215
	}	
191
		// must force since this page is a 'sub-page' and may not be considered the current page
192
		if (getContainer().getCurrentPage() != this) {
193
			getContainer().updateMessage();
194
			getContainer().updateButtons();
195
		}
196
	}
216
	
197
	
217
	/**
198
	/**
218
	 * Determines if the current libraries displayed to the user are the default location
199
	 * Determines if the current libraries displayed to the user are the default location
Lines 228-234 Link Here
228
		}
209
		}
229
		File installLocation = vm.getInstallLocation();
210
		File installLocation = vm.getInstallLocation();
230
		if (installLocation != null) {
211
		if (installLocation != null) {
231
			LibraryLocation[] def = getVMInstallType().getDefaultLibraryLocations(installLocation);
212
			LibraryLocation[] def = vm.getVMInstallType().getDefaultLibraryLocations(installLocation);
232
			if (def.length == libraryLocations.length) {
213
			if (def.length == libraryLocations.length) {
233
				for (int i = 0; i < def.length; i++) {
214
				for (int i = 0; i < def.length; i++) {
234
					if (!def[i].equals(libraryLocations[i])) {
215
					if (!def[i].equals(libraryLocations[i])) {
Lines 240-263 Link Here
240
		}
221
		}
241
		return false;
222
		return false;
242
	}
223
	}
243
	
244
	/**
245
	 * Returns the vm install associated with this library block.
246
	 * 
247
	 * @return vm install
248
	 */
249
	protected IVMInstall getVMInstall() {
250
		return fVmInstall;
251
	}	
252
	
253
	/**
254
	 * Returns the vm install type associated with this library block.
255
	 * 
256
	 * @return vm install
257
	 */
258
	protected IVMInstallType getVMInstallType() {
259
		return fVmInstallType;
260
	}
261
224
262
	/* (non-Javadoc)
225
	/* (non-Javadoc)
263
	 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
226
	 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
Lines 409-412 Link Here
409
		fJavadocButton.setEnabled(!selection.isEmpty() && (allJavadoc || allRoots));
372
		fJavadocButton.setEnabled(!selection.isEmpty() && (allJavadoc || allRoots));
410
		fSourceButton.setEnabled(!selection.isEmpty() && (allSource || allRoots));
373
		fSourceButton.setEnabled(!selection.isEmpty() && (allSource || allRoots));
411
	}
374
	}
375
376
	/* (non-Javadoc)
377
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#finish()
378
	 */
379
	public boolean finish() {
380
		if (fVmInstall != null) {
381
			if (isDefaultLocations(fVmInstall)) {
382
				fVmInstall.setLibraryLocations(null);
383
			} else {
384
				LibraryLocation[] libs = fLibraryContentProvider.getLibraries();
385
				fVmInstall.setLibraryLocations(libs);
386
			}
387
		}
388
		return true;
389
	}
390
391
	/* (non-Javadoc)
392
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#getSelection()
393
	 */
394
	public VMStandin getSelection() {
395
		return fVmInstall;
396
	}
397
398
	/* (non-Javadoc)
399
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#setSelection(org.eclipse.jdt.launching.VMStandin)
400
	 */
401
	public void setSelection(VMStandin vm) {
402
		super.setSelection(vm);
403
		LibraryLocation[] libraryLocations = null;
404
		if (vm == null) {
405
			libraryLocations = new LibraryLocation[0];
406
		} else {
407
			libraryLocations = JavaRuntime.getLibraryLocations(vm);
408
		}
409
		fVmInstall = vm;
410
		fLibraryContentProvider.setLibraries(libraryLocations);
411
	}
412
	
413
	/* (non-Javadoc)
414
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#getVMStatus()
415
	 */
416
	protected IStatus[] getVMStatus() {
417
		return fLibStatus;
418
	}	
419
		
412
}
420
}
(-)ui/org/eclipse/jdt/debug/ui/IJavaDebugUIConstants.java (+8 lines)
Lines 32-37 Link Here
32
	public static final String EXTENSION_POINT_VM_INSTALL_TYPE_PAGE = "vmInstallTypePage"; //$NON-NLS-1$
32
	public static final String EXTENSION_POINT_VM_INSTALL_TYPE_PAGE = "vmInstallTypePage"; //$NON-NLS-1$
33
33
34
	/**
34
	/**
35
	 * Extension point identifier for contributions of a wizard page that for a VMInstallType
36
	 * (value <code>"vmInstallPages"</code>).
37
	 * 
38
	 * @since 3.4
39
	 */
40
	public static final String EXTENSION_POINT_VM_INSTALL_PAGES = "vmInstallPages"; //$NON-NLS-1$
41
	
42
	/**
35
	 * Display view identifier (value <code>"org.eclipse.jdt.debug.ui.DisplayView"</code>).
43
	 * Display view identifier (value <code>"org.eclipse.jdt.debug.ui.DisplayView"</code>).
36
	 */
44
	 */
37
	public static final String ID_DISPLAY_VIEW= PLUGIN_ID + ".DisplayView"; //$NON-NLS-1$
45
	public static final String ID_DISPLAY_VIEW= PLUGIN_ID + ".DisplayView"; //$NON-NLS-1$
(-)plugin.xml (+8 lines)
Lines 5-10 Link Here
5
    
5
    
6
<!-- Extensions Points -->
6
<!-- Extensions Points -->
7
   <extension-point id="vmInstallTypePage" name="%vmInstallTypePage" schema="schema/vmInstallTypePage.exsd"/>
7
   <extension-point id="vmInstallTypePage" name="%vmInstallTypePage" schema="schema/vmInstallTypePage.exsd"/>
8
   <extension-point id="vmInstallPages" name="VM Install Page" schema="schema/vmInstallPages.exsd"/>
8
9
9
<!-- Extensions -->
10
<!-- Extensions -->
10
   <extension
11
   <extension
Lines 3369-3372 Link Here
3369
          targetId="org.eclipse.jdt.ui.javaCode">
3370
          targetId="org.eclipse.jdt.ui.javaCode">
3370
    </hyperlinkDetector>
3371
    </hyperlinkDetector>
3371
 </extension>
3372
 </extension>
3373
 <extension
3374
       point="org.eclipse.jdt.debug.ui.vmInstallPages">
3375
    <vmInstallPage
3376
          class="org.eclipse.jdt.internal.debug.ui.jres.EEVMPage"
3377
          vmInstallType="org.eclipse.jdt.launching.EEVMType">
3378
    </vmInstallPage>
3379
 </extension>
3372
</plugin>
3380
</plugin>
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/VMTypePage.java (+164 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.jdt.internal.debug.ui.jres;
12
13
import java.util.HashSet;
14
import java.util.Iterator;
15
import java.util.Set;
16
17
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
18
import org.eclipse.jdt.internal.debug.ui.JavaDebugImages;
19
import org.eclipse.jdt.internal.debug.ui.SWTFactory;
20
import org.eclipse.jdt.internal.launching.StandardVMType;
21
import org.eclipse.jdt.launching.IVMInstallType;
22
import org.eclipse.jdt.launching.JavaRuntime;
23
import org.eclipse.jdt.launching.VMStandin;
24
import org.eclipse.jface.viewers.ArrayContentProvider;
25
import org.eclipse.jface.viewers.CheckStateChangedEvent;
26
import org.eclipse.jface.viewers.CheckboxTableViewer;
27
import org.eclipse.jface.viewers.ICheckStateListener;
28
import org.eclipse.jface.viewers.LabelProvider;
29
import org.eclipse.jface.viewers.ViewerComparator;
30
import org.eclipse.jface.wizard.IWizardPage;
31
import org.eclipse.jface.wizard.WizardPage;
32
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.graphics.Image;
34
import org.eclipse.swt.layout.GridData;
35
import org.eclipse.swt.layout.GridLayout;
36
import org.eclipse.swt.widgets.Composite;
37
38
/**
39
 * Wizard page used to select a VM type.
40
 * 
41
 * @since 3.4
42
 */
43
public class VMTypePage extends WizardPage {
44
	
45
	private CheckboxTableViewer fTypesViewer;
46
	
47
	private AbstractVMInstallPage fNextPage;
48
	
49
	/**
50
	 * Keep track of pages created, so we can dispose of them.
51
	 */
52
	private Set fPages = new HashSet();
53
	
54
	/**
55
	 * Label provider for VM types
56
	 */
57
	private class TypeLabelProvider extends LabelProvider {
58
59
		/* (non-Javadoc)
60
		 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
61
		 */
62
		public String getText(Object element) {
63
			if (element instanceof IVMInstallType) {
64
				IVMInstallType type = (IVMInstallType) element;
65
				return type.getName();
66
			}
67
			return super.getText(element);
68
		}
69
		
70
	}
71
	
72
	/**
73
	 * Constructs a VM type selection page
74
	 */
75
	public VMTypePage() {
76
		super(JREMessages.VMTypePage_0);
77
		setDescription(JREMessages.VMTypePage_1);
78
		setTitle(JREMessages.VMTypePage_2);
79
	}
80
	
81
	
82
	/* (non-Javadoc)
83
	 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
84
	 */
85
	public void dispose() {
86
		super.dispose();
87
		Iterator iterator = fPages.iterator();
88
		while (iterator.hasNext()) {
89
			AbstractVMInstallPage page = (AbstractVMInstallPage)iterator.next();
90
			page.dispose();
91
		}
92
	}
93
94
95
	/* (non-Javadoc)
96
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
97
	 */
98
	public void createControl(Composite parent) {
99
		Composite composite = new Composite(parent, SWT.NONE);
100
		GridLayout layout = new GridLayout();
101
		layout.numColumns = 1;
102
		composite.setLayout(layout);
103
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
104
		
105
		SWTFactory.createLabel(composite, JREMessages.VMTypePage_3, 1);
106
		
107
		fTypesViewer = CheckboxTableViewer.newCheckList(composite, SWT.SINGLE | SWT.BORDER);
108
		GridData data = new GridData(GridData.FILL_BOTH);
109
        data.heightHint = 250;
110
        data.widthHint = 300;
111
        fTypesViewer.getTable().setLayoutData(data);
112
        fTypesViewer.setContentProvider(new ArrayContentProvider());
113
        fTypesViewer.setLabelProvider(new TypeLabelProvider());
114
		fTypesViewer.setComparator(new ViewerComparator());
115
		fTypesViewer.addCheckStateListener(new ICheckStateListener() {
116
			public void checkStateChanged(CheckStateChangedEvent event) {
117
				if (event.getChecked()) {
118
					// only check one element
119
					fTypesViewer.setCheckedElements(new Object[]{event.getElement()});
120
					setPageComplete(true);
121
					updateNextPage();
122
				} else {
123
					setPageComplete(false);
124
				}
125
			}
126
		});
127
		fTypesViewer.setInput(JavaRuntime.getVMInstallTypes());
128
		setControl(composite);
129
		
130
		fTypesViewer.setChecked(JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE), true);
131
		updateNextPage();
132
	}
133
	
134
	/* (non-Javadoc)
135
	 * @see org.eclipse.jface.dialogs.IDialogPage#getImage()
136
	 */
137
	public Image getImage() {
138
		return JavaDebugImages.get(JavaDebugImages.IMG_WIZBAN_LIBRARY);
139
	}	
140
	
141
	/* (non-Javadoc)
142
	 * @see org.eclipse.jface.wizard.WizardPage#getNextPage()
143
	 */
144
	public IWizardPage getNextPage() {
145
		return fNextPage;
146
	}
147
	
148
	private void updateNextPage() {
149
		if (isPageComplete()) {
150
			Object[] checkedElements = fTypesViewer.getCheckedElements();
151
			if (checkedElements.length == 1) {
152
				IVMInstallType installType = (IVMInstallType)checkedElements[0];
153
				AbstractVMInstallPage page = ((VMInstallWizard)getWizard()).getPage(installType);
154
				page.setWizard(getWizard());
155
				VMStandin standin = new VMStandin(installType, StandardVMPage.createUniqueId(installType));
156
				standin.setName(""); //$NON-NLS-1$
157
				page.setSelection(standin);
158
				fNextPage = page;
159
				fPages.add(page);
160
			}
161
		}		
162
	}
163
164
}
(-)schema/vmInstallPages.exsd (+131 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.jdt.debug.ui">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.jdt.debug.ui" id="vmInstallPages" name="VM Install Pages"/>
7
      </appInfo>
8
      <documentation>
9
         This extension point allows a wizard page to be contributed for VM installs that require custom editing controls.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <complexType>
15
         <sequence minOccurs="1" maxOccurs="unbounded">
16
            <element ref="vmInstallPage"/>
17
         </sequence>
18
         <attribute name="point" type="string" use="required">
19
            <annotation>
20
               <documentation>
21
                  
22
               </documentation>
23
            </annotation>
24
         </attribute>
25
         <attribute name="id" type="string">
26
            <annotation>
27
               <documentation>
28
                  
29
               </documentation>
30
            </annotation>
31
         </attribute>
32
         <attribute name="name" type="string">
33
            <annotation>
34
               <documentation>
35
                  
36
               </documentation>
37
               <appInfo>
38
                  <meta.attribute translatable="true"/>
39
               </appInfo>
40
            </annotation>
41
         </attribute>
42
      </complexType>
43
   </element>
44
45
   <element name="vmInstallPage">
46
      <annotation>
47
         <documentation>
48
            Contributes a wizard page for a specific VM install type.
49
         </documentation>
50
      </annotation>
51
      <complexType>
52
         <attribute name="vmInstallType" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  Specifies the VM install type this wizard page is to be used for. Unique identifier corresponding to an &lt;code&gt;IVMInstallType&lt;/code&gt;&apos;s id.
56
               </documentation>
57
            </annotation>
58
         </attribute>
59
         <attribute name="class" type="string" use="required">
60
            <annotation>
61
               <documentation>
62
                  Wizard page implementation. Must be a subclass of &lt;code&gt;org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage&lt;/code&gt;.
63
               </documentation>
64
               <appInfo>
65
                  <meta.attribute kind="java" basedOn="org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage:"/>
66
               </appInfo>
67
            </annotation>
68
         </attribute>
69
      </complexType>
70
   </element>
71
72
   <annotation>
73
      <appInfo>
74
         <meta.section type="since"/>
75
      </appInfo>
76
      <documentation>
77
         3.4
78
      </documentation>
79
   </annotation>
80
81
   <annotation>
82
      <appInfo>
83
         <meta.section type="examples"/>
84
      </appInfo>
85
      <documentation>
86
         Following is an example definition of a VM install page.
87
&lt;p&gt;
88
&lt;pre&gt;
89
&lt;extension point=&quot;org.eclipse.jdt.debug.ui.vmInstallPages&quot;&gt;
90
  &lt;vmInstallPage 
91
     vmInstallType=&quot;org.eclipse.jdt.launching.EEVMType&quot;
92
     class=&quot;org.eclipse.jdt.internal.debug.ui.jres.EEVMPage&quot;&gt;
93
  &lt;/vmInstallPage&gt;
94
&lt;/extension&gt;
95
&lt;/pre&gt;
96
&lt;/p&gt;
97
      </documentation>
98
   </annotation>
99
100
   <annotation>
101
      <appInfo>
102
         <meta.section type="apiInfo"/>
103
      </appInfo>
104
      <documentation>
105
         A wizard page must be a subclass of &lt;code&gt;org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage&lt;/code&gt;.
106
      </documentation>
107
   </annotation>
108
109
   <annotation>
110
      <appInfo>
111
         <meta.section type="implementation"/>
112
      </appInfo>
113
      <documentation>
114
         JDT provides a default implementation of a wizard page for VMs that do not contribute one.
115
      </documentation>
116
   </annotation>
117
118
   <annotation>
119
      <appInfo>
120
         <meta.section type="copyright"/>
121
      </appInfo>
122
      <documentation>
123
         Copyright (c) 2007 IBM Corporation and others.&lt;br&gt;
124
All rights reserved. This program and the accompanying materials are made 
125
available under the terms of the Eclipse Public License v1.0 which 
126
accompanies this distribution, and is available at 
127
&lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
128
      </documentation>
129
   </annotation>
130
131
</schema>
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/EEVMPage.java (+383 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.jdt.internal.debug.ui.jres;
12
13
import java.io.File;
14
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Status;
18
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
19
import org.eclipse.jdt.internal.debug.ui.JavaDebugImages;
20
import org.eclipse.jdt.internal.debug.ui.SWTFactory;
21
import org.eclipse.jdt.internal.debug.ui.StatusInfo;
22
import org.eclipse.jdt.internal.launching.EEVMInstall;
23
import org.eclipse.jdt.internal.launching.EEVMType;
24
import org.eclipse.jdt.launching.IVMInstallType;
25
import org.eclipse.jdt.launching.JavaRuntime;
26
import org.eclipse.jdt.launching.VMStandin;
27
import org.eclipse.jface.dialogs.Dialog;
28
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.custom.BusyIndicator;
30
import org.eclipse.swt.events.ModifyEvent;
31
import org.eclipse.swt.events.ModifyListener;
32
import org.eclipse.swt.events.SelectionEvent;
33
import org.eclipse.swt.events.SelectionListener;
34
import org.eclipse.swt.graphics.Image;
35
import org.eclipse.swt.layout.GridData;
36
import org.eclipse.swt.layout.GridLayout;
37
import org.eclipse.swt.widgets.Button;
38
import org.eclipse.swt.widgets.Composite;
39
import org.eclipse.swt.widgets.Control;
40
import org.eclipse.swt.widgets.FileDialog;
41
import org.eclipse.swt.widgets.Label;
42
import org.eclipse.swt.widgets.Text;
43
44
/**
45
 * Page used to edit an 'EE' VM.
46
 * 
47
 * @since 3.4
48
 */
49
public class EEVMPage extends AbstractVMInstallPage {
50
	
51
	// VM being edited or created
52
	private VMStandin fVM;
53
	private Text fVMName;
54
	private Text fVMArgs;
55
	private Text fEEFile;
56
	private VMLibraryBlock fLibraryBlock;
57
	private IStatus[] fFieldStatus = new IStatus[1];
58
	private boolean fIgnoreCallbacks = false;
59
	
60
	/**
61
	 * 
62
	 */
63
	public EEVMPage() {
64
		super(JREMessages.EEVMPage_0);
65
		for (int i = 0; i < fFieldStatus.length; i++) {
66
			fFieldStatus[i] = Status.OK_STATUS;
67
		}
68
	}
69
	
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.jface.dialogs.IDialogPage#getImage()
72
	 */
73
	public Image getImage() {
74
		return JavaDebugImages.get(JavaDebugImages.IMG_WIZBAN_LIBRARY);
75
	}	
76
77
	/* (non-Javadoc)
78
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
79
	 */
80
	public void createControl(Composite p) {
81
		// create a composite with standard margins and spacing
82
		Composite composite = new Composite(p, SWT.NONE);
83
		GridLayout layout = new GridLayout();
84
		layout.numColumns = 3;
85
		composite.setLayout(layout);
86
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
87
		
88
	// VM location
89
		SWTFactory.createLabel(composite, JREMessages.EEVMPage_1, 1);
90
		fEEFile = SWTFactory.createSingleText(composite, 1);
91
		Button folders = SWTFactory.createPushButton(composite, JREMessages.EEVMPage_2, null);
92
		GridData data = (GridData) folders.getLayoutData();
93
		data.horizontalAlignment = GridData.END;
94
	//VM name
95
		SWTFactory.createLabel(composite, JREMessages.addVMDialog_jreName, 1);
96
		fVMName = SWTFactory.createSingleText(composite, 2);
97
	//VM arguments
98
		Label label = SWTFactory.createLabel(composite, JREMessages.AddVMDialog_23, 1);
99
		GridData gd = (GridData) label.getLayoutData();
100
		gd.verticalAlignment = SWT.BEGINNING;
101
		fVMArgs = SWTFactory.createText(composite, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP, 2, ""); //$NON-NLS-1$
102
		gd = (GridData) fVMArgs.getLayoutData();
103
		gd.widthHint = 200;
104
		gd.heightHint = 50;
105
	//VM libraries block 
106
		SWTFactory.createLabel(composite, JREMessages.AddVMDialog_JRE_system_libraries__1, 3);
107
		fLibraryBlock = new VMLibraryBlock();
108
		fLibraryBlock.setWizard(getWizard());
109
		fLibraryBlock.createControl(composite);
110
		Control libControl = fLibraryBlock.getControl();
111
		gd = new GridData(GridData.FILL_BOTH);
112
		gd.horizontalSpan = 3;
113
		libControl.setLayoutData(gd);
114
		
115
		initializeFields();
116
	//add the listeners now to prevent them from monkeying with initialized settings
117
		fVMName.addModifyListener(new ModifyListener() {
118
			public void modifyText(ModifyEvent e) {
119
				if (!fIgnoreCallbacks) {
120
					validateVMName();
121
				}
122
			}
123
		});
124
		fEEFile.addModifyListener(new ModifyListener() {
125
			public void modifyText(ModifyEvent e) {
126
				if (!fIgnoreCallbacks) {
127
					if (validateDefinitionFile().isOK()) {
128
						reloadDefinitionFile();
129
					}
130
				}
131
			}
132
		});
133
		folders.addSelectionListener(new SelectionListener() {
134
			public void widgetDefaultSelected(SelectionEvent e) {}
135
			public void widgetSelected(SelectionEvent e) {
136
				FileDialog dialog = new FileDialog(getShell());
137
				dialog.setFilterExtensions(new String[]{"*.ee"}); //$NON-NLS-1$
138
				File file = getDefinitionFile();
139
				String text = fEEFile.getText();
140
				if (file != null && file.isFile()) {
141
					text = file.getParentFile().getAbsolutePath();
142
				}
143
				dialog.setFileName(text); 
144
				String newPath = dialog.open();
145
				if (newPath != null) {
146
					fEEFile.setText(newPath);
147
				}
148
			}
149
		});
150
		Dialog.applyDialogFont(composite);
151
		setControl(composite);
152
	}	
153
	
154
	/**
155
	 * Validates the JRE location
156
	 * @return the status after validating the JRE location
157
	 */
158
	private IStatus validateDefinitionFile() {
159
		String locationName = fEEFile.getText();
160
		IStatus s = null;
161
		File file = null;
162
		if (locationName.length() == 0) {
163
			s = new StatusInfo(IStatus.INFO, JREMessages.EEVMPage_4); 
164
		}  else {
165
			file = new File(locationName);
166
			if (!file.exists()) {
167
				s = new StatusInfo(IStatus.ERROR, JREMessages.EEVMPage_5); 
168
			} else {
169
				EEVMType.clearProperties(file);
170
				final IStatus[] temp = new IStatus[1];
171
				final VMStandin[] vm = new VMStandin[1];
172
				final File tempFile = file; 
173
				Runnable r = new Runnable() {
174
					public void run() {
175
						try {
176
							vm[0] = JavaRuntime.createVMFromDefinitionFile(tempFile, fVM.getName(), fVM.getId());
177
							temp[0] = Status.OK_STATUS;
178
						} catch (CoreException e) {
179
							temp[0] = e.getStatus();
180
						}
181
					}
182
				};
183
				BusyIndicator.showWhile(getShell().getDisplay(), r);
184
				s = temp[0];
185
			}
186
		}
187
		setDefinitionFileStatus(s);
188
		updatePageStatus();
189
		return s;
190
	}
191
	
192
	/**
193
	 * Initializes the JRE attributes from the definition file
194
	 */
195
	private void reloadDefinitionFile() {
196
		IStatus s = Status.OK_STATUS;
197
		File file = getDefinitionFile();
198
		if (file != null && file.exists()) {
199
			final IStatus[] temp = new IStatus[1];
200
			final VMStandin[] vm = new VMStandin[1];
201
			final File tempFile = file; 
202
			Runnable r = new Runnable() {
203
				public void run() {
204
					try {
205
						vm[0] = JavaRuntime.createVMFromDefinitionFile(tempFile, fVM.getName(), fVM.getId());
206
						temp[0] = Status.OK_STATUS;
207
					} catch (CoreException e) {
208
						temp[0] = e.getStatus();
209
					}
210
				}
211
			};
212
			BusyIndicator.showWhile(getShell().getDisplay(), r);
213
			s = temp[0];
214
			if (s.isOK()) {
215
				fVM = vm[0];
216
			}
217
		}
218
		if (s.isOK() && file != null) {
219
			String name = fVMName.getText();
220
			if (name == null || name.trim().length() == 0) {
221
				// auto-generate VM name
222
				String fileName = file.getName();
223
				int index = fileName.lastIndexOf("."); //$NON-NLS-1$
224
				if (index > 0) {
225
					fileName = fileName.substring(0, index);
226
				}
227
				fVM.setName(fileName);
228
			}
229
			initializeFields();
230
		}
231
		setDefinitionFileStatus(s);
232
	}	
233
234
	/**
235
	 * Validates the entered name of the VM
236
	 * @return the status of the name validation
237
	 */
238
	private void validateVMName() {
239
		nameChanged(fVMName.getText());
240
	}
241
	
242
	/* (non-Javadoc)
243
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#finish()
244
	 */
245
	public boolean finish() {
246
		setFieldValuesToVM(fVM);
247
		fLibraryBlock.finish();
248
		return true;
249
	}
250
251
	/* (non-Javadoc)
252
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#getSelection()
253
	 */
254
	public VMStandin getSelection() {
255
		return fVM;
256
	}
257
	
258
	/* (non-Javadoc)
259
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#setSelection(org.eclipse.jdt.launching.VMStandin)
260
	 */
261
	public void setSelection(VMStandin vm) {
262
		super.setSelection(vm);
263
		fVM = vm;
264
		setTitle(JREMessages.EEVMPage_6);
265
		setDescription(JREMessages.EEVMPage_7);
266
	}
267
	
268
	/**
269
	 * initialize fields to the specified VM
270
	 * @param vm the VM to initialize from
271
	 */
272
	protected void setFieldValuesToVM(VMStandin vm) {
273
		File eeFile = getDefinitionFile();
274
		File home = null;
275
		if (eeFile != null) {
276
			vm.setAttribute(EEVMInstall.ATTR_DEFINITION_FILE, eeFile.getPath());
277
			String homePath = EEVMType.getProperty(EEVMType.PROP_JAVA_HOME, eeFile);
278
			if (homePath != null) {
279
				home = new File(homePath);
280
			}
281
		}
282
		vm.setInstallLocation(home);
283
		vm.setName(fVMName.getText());
284
		
285
		String argString = fVMArgs.getText().trim();
286
		if (argString != null && argString.length() > 0) {
287
			vm.setVMArgs(argString);			
288
		} else {
289
			vm.setVMArgs(null);
290
		}
291
	}
292
	
293
	/**
294
	 * Returns the definition file from the text control or <code>null</code>
295
	 * if none.
296
	 * 
297
	 * @return definition file or <code>null</code>
298
	 */
299
	private File getDefinitionFile() {
300
		String path = fEEFile.getText().trim();
301
		if (path.length() > 0) {
302
			return new File(path);
303
		} else {
304
			return null;
305
		}
306
	}
307
	
308
	/**
309
	 * Creates a unique name for the VMInstallType
310
	 * @param vmType the vm install type
311
	 * @return a unique name
312
	 */
313
	protected static String createUniqueId(IVMInstallType vmType) {
314
		String id = null;
315
		do {
316
			id = String.valueOf(System.currentTimeMillis());
317
		} while (vmType.findVMInstall(id) != null);
318
		return id;
319
	}	
320
	
321
	/**
322
	 * Initialize the dialogs fields
323
	 */
324
	private void initializeFields() {
325
		try {
326
			fIgnoreCallbacks = true;
327
			fLibraryBlock.setSelection(fVM);
328
			fVMName.setText(fVM.getName());
329
			String eePath = fVM.getAttribute(EEVMInstall.ATTR_DEFINITION_FILE);
330
			if (eePath != null) {
331
				fEEFile.setText(eePath);
332
			}
333
			String vmArgs = fVM.getVMArgs();
334
			if (vmArgs != null) {
335
				fVMArgs.setText(vmArgs);
336
			}
337
			validateVMName();
338
			validateDefinitionFile();
339
		} finally {
340
			fIgnoreCallbacks = false;
341
		}
342
	}	
343
	
344
	/**
345
	 * Sets the status of the definition file.
346
	 * 
347
	 * @param status definition file status
348
	 */
349
	private void setDefinitionFileStatus(IStatus status) {
350
		fFieldStatus[0] = status;
351
	}
352
353
	/* (non-Javadoc)
354
	 * @see org.eclipse.jface.dialogs.DialogPage#getErrorMessage()
355
	 */
356
	public String getErrorMessage() {
357
		String message = super.getErrorMessage();
358
		if (message == null) {
359
			return fLibraryBlock.getErrorMessage();
360
		}
361
		return message;
362
	}
363
364
	/* (non-Javadoc)
365
	 * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
366
	 */
367
	public boolean isPageComplete() {
368
		boolean complete = super.isPageComplete();
369
		if (complete) {
370
			return fLibraryBlock.isPageComplete();
371
		}
372
		return complete;
373
	}
374
375
	/* (non-Javadoc)
376
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#getVMStatus()
377
	 */
378
	protected IStatus[] getVMStatus() {
379
		return fFieldStatus;
380
	}
381
	
382
	
383
}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/StandardVMPage.java (+381 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.jdt.internal.debug.ui.jres;
12
13
import java.io.File;
14
import java.io.IOException;
15
import java.net.URL;
16
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Path;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
22
import org.eclipse.jdt.internal.debug.ui.JavaDebugImages;
23
import org.eclipse.jdt.internal.debug.ui.SWTFactory;
24
import org.eclipse.jdt.internal.debug.ui.StatusInfo;
25
import org.eclipse.jdt.launching.AbstractVMInstallType;
26
import org.eclipse.jdt.launching.IVMInstallType;
27
import org.eclipse.jdt.launching.VMStandin;
28
import org.eclipse.jface.dialogs.Dialog;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.custom.BusyIndicator;
31
import org.eclipse.swt.events.ModifyEvent;
32
import org.eclipse.swt.events.ModifyListener;
33
import org.eclipse.swt.events.SelectionEvent;
34
import org.eclipse.swt.events.SelectionListener;
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.swt.widgets.Control;
41
import org.eclipse.swt.widgets.DirectoryDialog;
42
import org.eclipse.swt.widgets.Text;
43
44
/**
45
 * Page used to edit a standard VM.
46
 * 
47
 * @since 3.4
48
 */
49
public class StandardVMPage extends AbstractVMInstallPage {
50
	
51
	// VM being edited or created
52
	private VMStandin fVM;
53
	private Text fVMName;
54
	private Text fVMArgs;
55
	private Text fJRERoot;
56
	private VMLibraryBlock fLibraryBlock;
57
// the VM install's javadoc location
58
	private URL fJavadocLocation = null;
59
	private boolean fAutoDetectAttributes = false;
60
	private IStatus[] fFieldStatus = new IStatus[1];
61
	
62
	/**
63
	 * 
64
	 */
65
	public StandardVMPage() {
66
		super(JREMessages.StandardVMPage_0);
67
		for (int i = 0; i < fFieldStatus.length; i++) {
68
			fFieldStatus[i] = Status.OK_STATUS;
69
		}
70
	}
71
	
72
	/* (non-Javadoc)
73
	 * @see org.eclipse.jface.dialogs.IDialogPage#getImage()
74
	 */
75
	public Image getImage() {
76
		return JavaDebugImages.get(JavaDebugImages.IMG_WIZBAN_LIBRARY);
77
	}	
78
79
	/* (non-Javadoc)
80
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
81
	 */
82
	public void createControl(Composite p) {
83
		// create a composite with standard margins and spacing
84
		Composite composite = new Composite(p, SWT.NONE);
85
		GridLayout layout = new GridLayout();
86
		layout.numColumns = 3;
87
		composite.setLayout(layout);
88
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
89
		
90
	// VM location
91
		SWTFactory.createLabel(composite, JREMessages.addVMDialog_jreHome, 1);
92
		fJRERoot = SWTFactory.createSingleText(composite, 1);
93
		Button folders = SWTFactory.createPushButton(composite, JREMessages.AddVMDialog_22, null);
94
		GridData data = (GridData) folders.getLayoutData();
95
		data.horizontalAlignment = GridData.END;
96
	//VM name
97
		SWTFactory.createLabel(composite, JREMessages.addVMDialog_jreName, 1);
98
		fVMName = SWTFactory.createSingleText(composite, 2);
99
	//VM arguments
100
		SWTFactory.createLabel(composite, JREMessages.AddVMDialog_23, 1);
101
		fVMArgs = SWTFactory.createSingleText(composite, 2);
102
	//VM libraries block 
103
		SWTFactory.createLabel(composite, JREMessages.AddVMDialog_JRE_system_libraries__1, 3);
104
		fLibraryBlock = new VMLibraryBlock();
105
		fLibraryBlock.setWizard(getWizard());
106
		fLibraryBlock.createControl(composite);
107
		Control libControl = fLibraryBlock.getControl();
108
		GridData gd = new GridData(GridData.FILL_BOTH);
109
		gd.horizontalSpan = 3;
110
		libControl.setLayoutData(gd);
111
		
112
	
113
	//add the listeners now to prevent them from monkeying with initialized settings
114
		fVMName.addModifyListener(new ModifyListener() {
115
			public void modifyText(ModifyEvent e) {
116
				validateVMName();
117
			}
118
		});
119
		fJRERoot.addModifyListener(new ModifyListener() {
120
			public void modifyText(ModifyEvent e) {
121
				validateJRELocation();
122
			}
123
		});
124
		folders.addSelectionListener(new SelectionListener() {
125
			public void widgetDefaultSelected(SelectionEvent e) {}
126
			public void widgetSelected(SelectionEvent e) {
127
				DirectoryDialog dialog = new DirectoryDialog(getShell());
128
				File file = new File(fJRERoot.getText());
129
				String text = fJRERoot.getText();
130
				if (file.isFile()) {
131
					text = file.getParentFile().getAbsolutePath();
132
				}
133
				dialog.setFilterPath(text);
134
				dialog.setMessage(JREMessages.addVMDialog_pickJRERootDialog_message); 
135
				String newPath = dialog.open();
136
				if (newPath != null) {
137
					fJRERoot.setText(newPath);
138
				}
139
			}
140
		});
141
		Dialog.applyDialogFont(composite);
142
		setControl(composite);
143
		initializeFields();
144
	}	
145
	
146
	/**
147
	 * Validates the JRE location
148
	 * @return the status after validating the JRE location
149
	 */
150
	private void validateJRELocation() {
151
		String locationName = fJRERoot.getText();
152
		IStatus s = null;
153
		File file = null;
154
		if (locationName.length() == 0) {
155
			s = new StatusInfo(IStatus.INFO, JREMessages.addVMDialog_enterLocation); 
156
		} 
157
		else {
158
			file = new File(locationName);
159
			if (!file.exists()) {
160
				s = new StatusInfo(IStatus.ERROR, JREMessages.addVMDialog_locationNotExists); 
161
			} 
162
			else {
163
				final IStatus[] temp = new IStatus[1];
164
				final File tempFile = file; 
165
				Runnable r = new Runnable() {
166
					public void run() {
167
						temp[0] = fVM.getVMInstallType().validateInstallLocation(tempFile);
168
					}
169
				};
170
				BusyIndicator.showWhile(getShell().getDisplay(), r);
171
				s = temp[0];
172
			}
173
		}
174
		if (file != null) {
175
			fVM.setInstallLocation(file);
176
		}
177
		if (s.isOK() && file != null) {
178
			String name = fVMName.getText();
179
			if (name == null || name.trim().length() == 0) {
180
				// auto-generate VM name
181
				if (file.isFile()) {
182
					String fileName = file.getName();
183
					int index = fileName.lastIndexOf(".ee"); //$NON-NLS-1$
184
					if (index > 0) {
185
						fileName = fileName.substring(0, index);
186
					}
187
					fVMName.setText(fileName);
188
				} else {
189
					try {
190
						String genName = null;
191
						IPath path = new Path(file.getCanonicalPath());
192
						int segs = path.segmentCount();
193
						if (segs == 1) {
194
							genName = path.segment(0);
195
						} 
196
						else if (segs >= 2) {
197
							String last = path.lastSegment();
198
							if ("jre".equalsIgnoreCase(last)) { //$NON-NLS-1$
199
								genName = path.segment(segs - 2);
200
							} 
201
							else {
202
								genName = last;
203
							}
204
						}
205
						if (genName != null) {
206
							fVMName.setText(genName);
207
						}
208
					} catch (IOException e) {}
209
				}
210
			}
211
		}
212
		detectJavadocLocation();
213
		setJRELocationStatus(s);
214
		fLibraryBlock.setSelection(fVM);
215
		updatePageStatus();
216
	}
217
	
218
	/**
219
	 * Auto-detects the default javadoc location
220
	 */
221
	private void detectJavadocLocation() {
222
		if (fAutoDetectAttributes) {
223
			IVMInstallType type = fVM.getVMInstallType();
224
			if (type instanceof AbstractVMInstallType) {
225
				AbstractVMInstallType atype = (AbstractVMInstallType)type;
226
				fJavadocLocation = atype.getDefaultJavadocLocation(getInstallLocation());
227
				String args = atype.getDefaultVMArguments(getInstallLocation());
228
				if (args != null) {
229
					fVMArgs.setText(args);
230
				}
231
			}
232
		} else {
233
			fJavadocLocation = fVM.getJavadocLocation();
234
		}
235
	}
236
	
237
	/**
238
	 * Returns the installation location as a file from the JRE root text control
239
	 * @return the installation location as a file
240
	 */
241
	protected File getInstallLocation() {
242
		return new File(fJRERoot.getText());
243
	}	
244
245
	/**
246
	 * Validates the entered name of the VM
247
	 * @return the status of the name validation
248
	 */
249
	private void validateVMName() {
250
		nameChanged(fVMName.getText());
251
	}
252
	
253
	/* (non-Javadoc)
254
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#finish()
255
	 */
256
	public boolean finish() {
257
		setFieldValuesToVM(fVM);
258
		fLibraryBlock.finish();
259
		return true;
260
	}
261
262
	/* (non-Javadoc)
263
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#getSelection()
264
	 */
265
	public VMStandin getSelection() {
266
		return fVM;
267
	}
268
	
269
	/* (non-Javadoc)
270
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#setSelection(org.eclipse.jdt.launching.VMStandin)
271
	 */
272
	public void setSelection(VMStandin vm) {
273
		super.setSelection(vm);
274
		fVM = vm;
275
		fAutoDetectAttributes = vm.getJavadocLocation() == null;
276
		setTitle(JREMessages.StandardVMPage_1);
277
		setDescription(JREMessages.StandardVMPage_2);
278
	}
279
	
280
	/**
281
	 * initialize fields to the specified VM
282
	 * @param vm the VM to initialize from
283
	 */
284
	protected void setFieldValuesToVM(VMStandin vm) {
285
		File dir = new File(fJRERoot.getText());
286
		try {
287
			vm.setInstallLocation(dir.getCanonicalFile());
288
		} 
289
		catch (IOException e) {
290
			vm.setInstallLocation(dir.getAbsoluteFile());
291
		}
292
		vm.setName(fVMName.getText());
293
		vm.setJavadocLocation(getURL());
294
		
295
		String argString = fVMArgs.getText().trim();
296
		if (argString != null && argString.length() > 0) {
297
			vm.setVMArgs(argString);			
298
		} 
299
		else {
300
			vm.setVMArgs(null);
301
		} 
302
	}
303
	
304
	/**
305
	 * Returns the URL for the javadoc location
306
	 * @return the URL for the javadoc location
307
	 */
308
	protected URL getURL() {
309
		return fJavadocLocation;
310
	}
311
	
312
	/**
313
	 * Creates a unique name for the VMInstallType
314
	 * @param vmType the vm install type
315
	 * @return a unique name
316
	 */
317
	protected static String createUniqueId(IVMInstallType vmType) {
318
		String id = null;
319
		do {
320
			id = String.valueOf(System.currentTimeMillis());
321
		} while (vmType.findVMInstall(id) != null);
322
		return id;
323
	}	
324
	
325
	/**
326
	 * Initialize the dialogs fields
327
	 */
328
	private void initializeFields() {
329
		fLibraryBlock.setSelection(fVM);
330
		fVMName.setText(fVM.getName());
331
		File installLocation = fVM.getInstallLocation();
332
		if (installLocation != null) {
333
			fJRERoot.setText(installLocation.getAbsolutePath());
334
		}
335
		String vmArgs = fVM.getVMArgs();
336
		if (vmArgs != null) {
337
			fVMArgs.setText(vmArgs);
338
		}
339
		validateVMName();
340
		validateJRELocation();
341
	}	
342
	
343
	/**
344
	 * Sets the status of the JRE location field.
345
	 * 
346
	 * @param status JRE location status
347
	 */
348
	private void setJRELocationStatus(IStatus status) {
349
		fFieldStatus[0] = status;
350
	}
351
352
	/* (non-Javadoc)
353
	 * @see org.eclipse.jface.dialogs.DialogPage#getErrorMessage()
354
	 */
355
	public String getErrorMessage() {
356
		String message = super.getErrorMessage();
357
		if (message == null) {
358
			return fLibraryBlock.getErrorMessage();
359
		}
360
		return message;
361
	}
362
363
	/* (non-Javadoc)
364
	 * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
365
	 */
366
	public boolean isPageComplete() {
367
		boolean complete = super.isPageComplete();
368
		if (complete) {
369
			return fLibraryBlock.isPageComplete();
370
		}
371
		return complete;
372
	}
373
374
	/* (non-Javadoc)
375
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#getVMStatus()
376
	 */
377
	protected IStatus[] getVMStatus() {
378
		return fFieldStatus;
379
	}
380
	
381
}
(-)ui/org/eclipse/jdt/debug/ui/launchConfigurations/AbstractVMInstallPage.java (+248 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.jdt.debug.ui.launchConfigurations;
12
13
import org.eclipse.core.resources.IResource;
14
import org.eclipse.core.resources.ResourcesPlugin;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.Status;
17
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
18
import org.eclipse.jdt.internal.debug.ui.jres.JREMessages;
19
import org.eclipse.jdt.launching.VMStandin;
20
import org.eclipse.jface.dialogs.IMessageProvider;
21
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.jface.wizard.IWizardPage;
23
import org.eclipse.jface.wizard.WizardPage;
24
25
import com.ibm.icu.text.MessageFormat;
26
27
/**
28
 * A wizard page used to edit the attributes of an installed JRE. A page is 
29
 * provided by JDT to edit standard JREs, but clients may contribute a custom
30
 * page for a VM install type if required.
31
 * <p>
32
 * A VM install page is contributed via the <code>vmInstallPages</code> extension
33
 * point. Following is an example definition of a VM install page.
34
 * <pre>
35
 * &lt;extension point="org.eclipse.jdt.debug.ui.vmInstallPages"&gt;
36
 *   &lt;vmInstallPage 
37
 *      vmInstallType="org.eclipse.jdt.launching.EEVMType"
38
 *      class="org.eclipse.jdt.internal.debug.ui.jres.EEVMPage"&gt;
39
 *   &lt;/vmInstallPage&gt;
40
 * &lt;/extension&gt;
41
 * </pre>
42
 * The attributes are specified as follows:
43
 * <ul>
44
 * <li><code>vmInstallType</code> Specifies the VM install type this wizard page is to be used for.
45
 * 	Unique identifier corresponding to an <code>IVMInstallType</code>'s id.</li>
46
 * <li><code>class</code> Wizard page implementation. Must be a subclass of
47
 *  <code>org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage</code>.</li>
48
 * </ul>
49
 * </p>
50
 * <p>
51
 * Clients contributing a custom VM install page via the <code>vmInstallPages</code> 
52
 * extension point must subclass this class.
53
 * </p>
54
 * @since 3.4
55
 */
56
public abstract class AbstractVMInstallPage extends WizardPage {
57
	
58
	/**
59
	 * Name of the original VM being edited, or <code>null</code> if none.
60
	 */
61
	private String fOriginalName = null;
62
	
63
	/**
64
	 * Status of VM name (to notify of name already in use)
65
	 */
66
	private IStatus fNameStatus = Status.OK_STATUS;
67
	
68
	private String[] fExistingNames;
69
		
70
	/**
71
	 * Constructs a new page with the given page name.
72
	 * 
73
	 * @param pageName the name of the page
74
	 */
75
	protected AbstractVMInstallPage(String pageName) {
76
		super(pageName);
77
	}
78
79
	/**
80
     * Creates a new wizard page with the given name, title, and image.
81
     *
82
     * @param pageName the name of the page
83
     * @param title the title for this wizard page,
84
     *   or <code>null</code> if none
85
     * @param titleImage the image descriptor for the title of this wizard page,
86
     *   or <code>null</code> if none
87
     */
88
	protected AbstractVMInstallPage(String pageName, String title, ImageDescriptor titleImage) {
89
		super(pageName, title, titleImage);
90
	}
91
92
	/**
93
	 * Called when the VM install page wizard is closed by selecting 
94
	 * the finish button. Implementers typically override this method to 
95
	 * store the page result (new/changed vm install returned in 
96
	 * getSelection) into its model.
97
	 * 
98
	 * @return if the operation was successful. Only when returned
99
	 * <code>true</code>, the wizard will close.
100
	 */
101
	public abstract boolean finish();
102
	
103
	/**
104
	 * Returns the edited or created VM install. This method
105
	 * may return <code>null</code> if no VM install exists.
106
	 * 
107
	 * @return the edited or created VM install.
108
	 */
109
	public abstract VMStandin getSelection();
110
111
	/**
112
	 * Sets the VM install to be edited. 
113
	 * 
114
	 * @param vm the VM install to edit
115
	 */
116
	public void setSelection(VMStandin vm) {
117
		fOriginalName = vm.getName();
118
	}
119
	
120
	/**
121
	 * Updates the name status based on the new name. This method should be called
122
	 * by the page each time the VM name changes.
123
	 * 
124
	 * @param newName new name of VM
125
	 */
126
	protected void nameChanged(String newName) {
127
		fNameStatus = Status.OK_STATUS;
128
		if (newName == null || newName.trim().length() == 0) {
129
			int sev = IStatus.ERROR;
130
			if (fOriginalName == null || fOriginalName.length() == 0) {
131
				sev = IStatus.INFO;
132
			}
133
			fNameStatus = new Status(sev, JDIDebugUIPlugin.getUniqueIdentifier(), JREMessages.addVMDialog_enterName);
134
		} else {
135
			if (isDuplicateName(newName)) {
136
				fNameStatus = new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), JREMessages.addVMDialog_duplicateName); 
137
			} else {
138
				IStatus s = ResourcesPlugin.getWorkspace().validateName(newName, IResource.FILE);
139
				if (!s.isOK()) {
140
					fNameStatus = new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), MessageFormat.format(JREMessages.AddVMDialog_JRE_name_must_be_a_valid_file_name___0__1, new String[]{s.getMessage()})); 
141
				}
142
			}
143
		}
144
		updatePageStatus();
145
	}
146
	
147
	/**
148
	 * Returns whether the name is already in use by an existing VM
149
	 * 
150
	 * @param name new name
151
	 * @return whether the name is already in use
152
	 */
153
	private boolean isDuplicateName(String name) {
154
		if (fExistingNames != null) {
155
			for (int i = 0; i < fExistingNames.length; i++) {
156
				if (name.equals(fExistingNames[i])) {
157
					return true;
158
				}
159
			}
160
		}
161
		return false;
162
	}	
163
	
164
	/**
165
	 * Sets the names of existing VMs, not including the VM being edited. This method
166
	 * is called by the wizard and clients should not call this method.
167
	 * 
168
	 * @param names existing VM names or an empty array
169
	 */
170
	public void setExistingNames(String[] names) {
171
		fExistingNames = names;
172
	}
173
	
174
	/* (non-Javadoc)
175
	 * @see org.eclipse.jface.wizard.WizardPage#getNextPage()
176
	 */
177
	public IWizardPage getNextPage() {
178
		return null;
179
	}
180
	
181
	/**
182
	 * Sets this page's message based on the status severity.
183
	 * 
184
	 * @param status status with message and severity
185
	 */
186
	protected void setStatusMessage(IStatus status) {
187
		if (status.isOK()) {
188
			setMessage(status.getMessage());
189
		} else {
190
			switch (status.getSeverity()) {
191
			case IStatus.ERROR:
192
				setMessage(status.getMessage(), IMessageProvider.ERROR);
193
				break;
194
			case IStatus.INFO:
195
				setMessage(status.getMessage(), IMessageProvider.INFORMATION);
196
				break;
197
			case IStatus.WARNING:
198
				setMessage(status.getMessage(), IMessageProvider.WARNING);
199
				break;
200
			default:
201
				break;
202
			}
203
		}
204
	}	
205
	
206
	/**
207
	 * Returns the current status of the name being used for the VM.
208
	 * 
209
	 * @return status of current VM name
210
	 */
211
	protected IStatus getNameStatus() {
212
		return fNameStatus;
213
	}
214
	
215
	/**
216
	 * Updates the status message on the page, based on the status of the VM and other
217
	 * status provided by the page.
218
	 */
219
	protected void updatePageStatus() {
220
		IStatus max = Status.OK_STATUS;
221
		IStatus[] vmStatus = getVMStatus();
222
		for (int i = 0; i < vmStatus.length; i++) {
223
			IStatus status = vmStatus[i];
224
			if (status.getSeverity() > max.getSeverity()) {
225
				max = status;
226
			}
227
		}
228
		if (fNameStatus.getSeverity() > max.getSeverity()) {
229
			max = fNameStatus;
230
		}
231
		if (max.isOK()) {
232
			setMessage(null, IMessageProvider.NONE);
233
			setPageComplete(true);
234
		} else {
235
			setStatusMessage(max);
236
			setPageComplete(false);
237
		}
238
	}	
239
	
240
	/**
241
	 * Returns a collection of status messages pertaining to the current edit
242
	 * status of the VM on this page. An empty collection or a collection of
243
	 * OK status objects indicates all is well.
244
	 * 
245
	 * @return collection of status objects for this page
246
	 */
247
	protected abstract IStatus[] getVMStatus();
248
}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/EditVMInstallWizard.java (+62 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.jdt.internal.debug.ui.jres;
12
13
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
14
import org.eclipse.jdt.launching.IVMInstall;
15
import org.eclipse.jdt.launching.VMStandin;
16
17
/**
18
 * @since 3.4
19
 */
20
public class EditVMInstallWizard extends VMInstallWizard {
21
	
22
	private AbstractVMInstallPage fEditPage;
23
	
24
	/**
25
	 * Constructs a wizard to edit the given vm.
26
	 * 
27
	 * @param vm vm to edit
28
	 * @param allVMs all VMs being edited
29
	 */
30
	public EditVMInstallWizard(VMStandin vm, IVMInstall[] allVMs) {
31
		super(vm, allVMs);
32
		setWindowTitle(JREMessages.EditVMInstallWizard_0);
33
	}
34
35
	/* (non-Javadoc)
36
	 * @see org.eclipse.jface.wizard.Wizard#addPages()
37
	 */
38
	public void addPages() {
39
		fEditPage = getPage(getVMInstall().getVMInstallType());
40
		fEditPage.setSelection(new VMStandin(getVMInstall()));
41
		addPage(fEditPage);
42
	}
43
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
46
	 */
47
	public boolean performFinish() {
48
		if (fEditPage.finish()) {
49
			return super.performFinish();
50
		}
51
		return false;
52
	}
53
54
	/* (non-Javadoc)
55
	 * @see org.eclipse.jdt.internal.debug.ui.jres.VMInstallWizard#getResult()
56
	 */
57
	protected VMStandin getResult() {
58
		return fEditPage.getSelection();
59
	}
60
61
	
62
}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMInstallWizard.java (+77 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.jdt.internal.debug.ui.jres;
12
13
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
14
import org.eclipse.jdt.launching.IVMInstall;
15
import org.eclipse.jdt.launching.VMStandin;
16
import org.eclipse.jface.wizard.IWizardPage;
17
18
/**
19
 * @since 3.4
20
 */
21
public class AddVMInstallWizard extends VMInstallWizard {
22
	
23
	private IWizardPage fTypePage = null;
24
	
25
	private VMStandin fResult = null;
26
27
	/**
28
	 * Constructs a wizard to add a new VM install.
29
	 * 
30
	 * @param currentInstalls currently existing VMs, used for name validation
31
	 */
32
	public AddVMInstallWizard(IVMInstall[] currentInstalls) {
33
		super(null, currentInstalls);
34
		setForcePreviousAndNextButtons(true);
35
		setWindowTitle(JREMessages.AddVMInstallWizard_0);
36
	}
37
38
	/* (non-Javadoc)
39
	 * @see org.eclipse.jface.wizard.Wizard#addPages()
40
	 */
41
	public void addPages() {
42
		fTypePage = new VMTypePage();
43
		addPage(fTypePage);
44
	}
45
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.jdt.internal.debug.ui.jres.VMInstallWizard#getResult()
48
	 */
49
	protected VMStandin getResult() {
50
		return fResult;
51
	}
52
53
	/* (non-Javadoc)
54
	 * @see org.eclipse.jdt.internal.debug.ui.jres.VMInstallWizard#canFinish()
55
	 */
56
	public boolean canFinish() {
57
		IWizardPage currentPage = getContainer().getCurrentPage();
58
		return currentPage != fTypePage && super.canFinish() && currentPage.isPageComplete();
59
	}
60
61
	/* (non-Javadoc)
62
	 * @see org.eclipse.jdt.internal.debug.ui.jres.VMInstallWizard#performFinish()
63
	 */
64
	public boolean performFinish() {
65
		IWizardPage currentPage = getContainer().getCurrentPage();
66
		if (currentPage instanceof AbstractVMInstallPage) {
67
			AbstractVMInstallPage page = (AbstractVMInstallPage) currentPage;
68
			boolean finish = page.finish();
69
			fResult = page.getSelection();
70
			return finish;
71
		}
72
		return false;
73
	}
74
75
	
76
	
77
}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/VMInstallWizard.java (+104 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.jdt.internal.debug.ui.jres;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IConfigurationElement;
18
import org.eclipse.core.runtime.IExtensionPoint;
19
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
21
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
22
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
23
import org.eclipse.jdt.launching.IVMInstall;
24
import org.eclipse.jdt.launching.IVMInstallType;
25
import org.eclipse.jdt.launching.VMStandin;
26
import org.eclipse.jface.wizard.Wizard;
27
28
/**
29
 * 
30
 */
31
public abstract class VMInstallWizard extends Wizard {
32
	
33
	private VMStandin fEditVM;
34
	private String[] fExistingNames;
35
	
36
	/**
37
	 * Constructs a new wizard to add/edit a vm install.
38
	 * 
39
	 * @param editVM the VM being edited, or <code>null</code> if none
40
	 * @param currentInstalls current VM installs used to validate name changes
41
	 */
42
	public VMInstallWizard(VMStandin editVM, IVMInstall[] currentInstalls) {
43
		fEditVM = editVM;
44
		List names = new ArrayList(currentInstalls.length);
45
		for (int i = 0; i < currentInstalls.length; i++) {
46
			IVMInstall install = currentInstalls[i];
47
			if (!install.equals(editVM)) {
48
				names.add(install.getName());
49
			}
50
		}
51
		fExistingNames = (String[]) names.toArray(new String[names.size()]);
52
	}
53
	
54
	/**
55
	 * Returns the VM to edit, or <code>null</code> if creating a VM
56
	 * 
57
	 * @return vm to edit or <code>null</code>
58
	 */
59
	protected VMStandin getVMInstall() {
60
		return fEditVM;
61
	}
62
	
63
	/**
64
	 * Returns the resulting VM after edit or creation or <code>null</code> if none.
65
	 * 
66
	 * @return resulting VM
67
	 */
68
	protected abstract VMStandin getResult();
69
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
72
	 */
73
	public boolean performFinish() {
74
		return getResult() != null;
75
	}
76
	
77
	/**
78
	 * Returns a page to use for editing a VM install type
79
	 * 
80
	 * @param type
81
	 * @return
82
	 */
83
	public AbstractVMInstallPage getPage(IVMInstallType type) {
84
		IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(JDIDebugUIPlugin.getUniqueIdentifier(), IJavaDebugUIConstants.EXTENSION_POINT_VM_INSTALL_PAGES);
85
		IConfigurationElement[] infos= extensionPoint.getConfigurationElements();
86
		for (int i = 0; i < infos.length; i++) {
87
			IConfigurationElement element = infos[i];
88
			String id = element.getAttribute("vmInstallType"); //$NON-NLS-1$
89
			if (type.getId().equals(id)) {
90
				try {
91
					AbstractVMInstallPage page = (AbstractVMInstallPage) element.createExecutableExtension("class"); //$NON-NLS-1$
92
					page.setExistingNames(fExistingNames);
93
					return page;
94
				} catch (CoreException e) {
95
					JDIDebugUIPlugin.log(e);
96
				}
97
			}
98
		}
99
		StandardVMPage standardVMPage = new StandardVMPage();
100
		standardVMPage.setExistingNames(fExistingNames);
101
		return standardVMPage;
102
	}
103
104
}

Return to bug 201758