KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > javadoc > JavaDocVMInstallListener


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.javadoc;
12
13 import java.net.URL JavaDoc;
14
15 import org.eclipse.core.runtime.IPath;
16
17 import org.eclipse.jdt.launching.IVMInstall;
18 import org.eclipse.jdt.launching.IVMInstallChangedListener;
19 import org.eclipse.jdt.launching.IVMInstallType;
20 import org.eclipse.jdt.launching.JavaRuntime;
21 import org.eclipse.jdt.launching.LibraryLocation;
22 import org.eclipse.jdt.launching.PropertyChangeEvent;
23
24 import org.eclipse.jdt.ui.JavaUI;
25
26 /**
27   */

28 public class JavaDocVMInstallListener implements IVMInstallChangedListener {
29
30     /**
31      * Constructor for VMInstallListener.
32      */

33     public JavaDocVMInstallListener() {
34     }
35     
36     public void init() {
37         IVMInstallType[] types= JavaRuntime.getVMInstallTypes();
38         for (int i = 0; i < types.length; i++) {
39             IVMInstall[] installs= types[i].getVMInstalls();
40             for (int j = 0; j < installs.length; j++) {
41                 updateJavadocLocations(installs[j]);
42             }
43         }
44         
45         JavaRuntime.addVMInstallChangedListener(this);
46     }
47     
48     public void remove() {
49         JavaRuntime.removeVMInstallChangedListener(this);
50     }
51     
52     
53
54     /* (non-Javadoc)
55      * @see IVMInstallChangedListener#defaultVMInstallChanged(IVMInstall, IVMInstall)
56      */

57     public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
58     }
59
60     private void updateJavadocLocations(IVMInstall install) {
61         URL JavaDoc url= install.getJavadocLocation();
62         if (url != null) {
63             LibraryLocation[] locations= JavaRuntime.getLibraryLocations(install);
64             if (locations != null) {
65                 for (int i = 0; i < locations.length; i++) {
66                     IPath path= locations[i].getSystemLibraryPath();
67                     if (path != null) {
68                         JavaUI.setLibraryJavadocLocation(path, url);
69                     }
70                 }
71             }
72         }
73     }
74         
75
76     /* (non-Javadoc)
77      * @see IVMInstallChangedListener#vmChanged(PropertyChangeEvent)
78      */

79     public void vmChanged(PropertyChangeEvent event) {
80         String JavaDoc property= event.getProperty();
81         if (PROPERTY_INSTALL_LOCATION.equals(property)
82             || PROPERTY_JAVADOC_LOCATION.equals(property)
83             || PROPERTY_LIBRARY_LOCATIONS.equals(property)) {
84                     updateJavadocLocations((IVMInstall) event.getSource());
85         }
86     }
87
88     /* (non-Javadoc)
89      * @see IVMInstallChangedListener#vmAdded(IVMInstall)
90      */

91     public void vmAdded(IVMInstall vm) {
92         updateJavadocLocations(vm);
93     }
94
95     /* (non-Javadoc)
96      * @see IVMInstallChangedListener#vmRemoved(IVMInstall)
97      */

98     public void vmRemoved(IVMInstall vm) {
99     }
100
101 }
102
Popular Tags