KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > plugin > PluginReference


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.pde.internal.core.plugin;
12
13 import org.eclipse.core.runtime.PlatformObject;
14 import org.eclipse.pde.core.plugin.IPlugin;
15 import org.eclipse.pde.core.plugin.IPluginModel;
16 import org.eclipse.pde.core.plugin.IPluginModelBase;
17 import org.eclipse.pde.core.plugin.PluginRegistry;
18
19 public class PluginReference extends PlatformObject {
20     private String JavaDoc fId;
21
22     private transient IPlugin fPlugin;
23
24     public PluginReference() {
25     }
26
27     public PluginReference(String JavaDoc id) {
28         fId = id;
29     }
30
31     public PluginReference(IPlugin plugin) {
32         fId = plugin.getId();
33         fPlugin = plugin;
34     }
35
36     public String JavaDoc getId() {
37         return fId;
38     }
39
40     public IPlugin getPlugin() {
41         if (fPlugin == null && fId != null) {
42             IPluginModelBase model = PluginRegistry.findModel(fId);
43             fPlugin = model instanceof IPluginModel ? ((IPluginModel)model).getPlugin() : null;
44         }
45         return fPlugin;
46     }
47
48     public String JavaDoc toString() {
49         if (fPlugin != null) {
50             return fPlugin.getTranslatedName();
51         }
52         return fId != null ? fId : "?"; //$NON-NLS-1$
53
}
54
55     public boolean isResolved() {
56         return getPlugin() != null;
57     }
58     
59     /**
60      * @param plugin
61      */

62     public void reconnect(IPluginModelBase model) {
63         // Transient Field: Plugin
64
IPlugin plugin = null;
65         if (model instanceof IPluginModel) {
66             plugin = ((IPluginModel) model).getPlugin();
67         }
68         // It could also be an IFragmentModel
69
// Having IPlugin has an instance variable for both models does not
70
// make sense
71
// If we have a fragment model, leave the plugin as null
72
fPlugin = plugin;
73     }
74     
75 }
76
Popular Tags