01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core.plugin;
11:
12: import org.eclipse.core.runtime.PlatformObject;
13: import org.eclipse.pde.core.plugin.IPlugin;
14: import org.eclipse.pde.core.plugin.IPluginModel;
15: import org.eclipse.pde.core.plugin.IPluginModelBase;
16: import org.eclipse.pde.core.plugin.PluginRegistry;
17:
18: public class PluginReference extends PlatformObject {
19: private String fId;
20:
21: private transient IPlugin fPlugin;
22:
23: public PluginReference() {
24: }
25:
26: public PluginReference(String id) {
27: fId = id;
28: }
29:
30: public PluginReference(IPlugin plugin) {
31: fId = plugin.getId();
32: fPlugin = plugin;
33: }
34:
35: public String getId() {
36: return fId;
37: }
38:
39: public IPlugin getPlugin() {
40: if (fPlugin == null && fId != null) {
41: IPluginModelBase model = PluginRegistry.findModel(fId);
42: fPlugin = model instanceof IPluginModel ? ((IPluginModel) model)
43: .getPlugin()
44: : null;
45: }
46: return fPlugin;
47: }
48:
49: public String toString() {
50: if (fPlugin != null) {
51: return fPlugin.getTranslatedName();
52: }
53: return fId != null ? fId : "?"; //$NON-NLS-1$
54: }
55:
56: public boolean isResolved() {
57: return getPlugin() != null;
58: }
59:
60: /**
61: * @param plugin
62: */
63: public void reconnect(IPluginModelBase model) {
64: // Transient Field: Plugin
65: IPlugin plugin = null;
66: if (model instanceof IPluginModel) {
67: plugin = ((IPluginModel) model).getPlugin();
68: }
69: // It could also be an IFragmentModel
70: // Having IPlugin has an instance variable for both models does not
71: // make sense
72: // If we have a fragment model, leave the plugin as null
73: fPlugin = plugin;
74: }
75:
76: }
|