KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > model > plugin > PluginModelBase


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

11 package org.eclipse.pde.internal.ui.model.plugin;
12
13 import java.net.*;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.jface.text.*;
17 import org.eclipse.pde.core.*;
18 import org.eclipse.pde.core.build.*;
19 import org.eclipse.pde.core.plugin.*;
20 import org.eclipse.pde.internal.core.*;
21 import org.eclipse.pde.internal.ui.model.*;
22 import org.xml.sax.helpers.*;
23
24 public abstract class PluginModelBase extends XMLEditingModel implements IPluginModelBase {
25
26     private PluginBaseNode fPluginBase;
27     private boolean fIsEnabled;
28     private PluginDocumentHandler fHandler;
29     private NodeOffsetHandler fNodeOffsetHandler;
30     private IPluginModelFactory fFactory;
31     
32     public PluginModelBase(IDocument document, boolean isReconciling) {
33         super(document, isReconciling);
34         fFactory = new PluginDocumentNodeFactory(this);
35     }
36     /* (non-Javadoc)
37      * @see org.eclipse.pde.core.plugin.IPluginModelBase#createPluginBase()
38      */

39     public IPluginBase createPluginBase(boolean isFragment) {
40         if (isFragment) {
41             fPluginBase = new FragmentNode();
42             fPluginBase.setXMLTagName("fragment"); //$NON-NLS-1$
43
} else {
44             fPluginBase = new PluginNode();
45             fPluginBase.setXMLTagName("plugin"); //$NON-NLS-1$
46
}
47         fPluginBase.setInTheModel(true);
48         fPluginBase.setModel(this);
49         return fPluginBase;
50     }
51     
52     public IPluginBase createPluginBase() {
53         return createPluginBase(isFragmentModel());
54     }
55
56     /* (non-Javadoc)
57      * @see org.eclipse.pde.core.plugin.IPluginModelBase#getBuildModel()
58      */

59     public IBuildModel getBuildModel() {
60         return null;
61     }
62
63     /* (non-Javadoc)
64      * @see org.eclipse.pde.core.plugin.IPluginModelBase#getPluginBase()
65      */

66     public IPluginBase getPluginBase() {
67         return getPluginBase(true);
68     }
69     
70     public IExtensions getExtensions() {
71         return getPluginBase();
72     }
73
74     /* (non-Javadoc)
75      * @see org.eclipse.pde.core.plugin.IPluginModelBase#getPluginBase(boolean)
76      */

77     public IPluginBase getPluginBase(boolean createIfMissing) {
78         if (!fLoaded && createIfMissing) {
79             createPluginBase();
80             try {
81                 load();
82             } catch (CoreException e) {
83             }
84         }
85         return fPluginBase;
86     }
87     
88     public IExtensions getExtensions(boolean createIfMissing) {
89         return getPluginBase(createIfMissing);
90     }
91
92     /* (non-Javadoc)
93      * @see org.eclipse.pde.core.plugin.IPluginModelBase#isEnabled()
94      */

95     public boolean isEnabled() {
96         return fIsEnabled;
97     }
98
99     /* (non-Javadoc)
100      * @see org.eclipse.pde.core.plugin.IPluginModelBase#setEnabled(boolean)
101      */

102     public void setEnabled(boolean enabled) {
103         fIsEnabled = enabled;
104     }
105     
106     /* (non-Javadoc)
107      * @see org.eclipse.pde.core.plugin.IPluginModelBase#getPluginFactory()
108      */

109     public IPluginModelFactory getPluginFactory() {
110         return fFactory;
111     }
112
113     /* (non-Javadoc)
114      * @see org.eclipse.pde.core.plugin.IPluginModelBase#getNLLookupLocation()
115      */

116     public URL getNLLookupLocation() {
117         String JavaDoc installLocation = getInstallLocation();
118         if (installLocation==null) return null;
119         if (installLocation.startsWith("file:") == false) //$NON-NLS-1$
120
installLocation = "file:" + installLocation; //$NON-NLS-1$
121
try {
122             URL url = new URL(installLocation + "/"); //$NON-NLS-1$
123
return url;
124         } catch (MalformedURLException e) {
125             return null;
126         }
127     }
128
129     /* (non-Javadoc)
130      * @see org.eclipse.pde.core.plugin.ISharedPluginModel#getFactory()
131      */

132     public IExtensionsModelFactory getFactory() {
133         return fFactory;
134     }
135
136     /* (non-Javadoc)
137      * @see org.eclipse.pde.internal.ui.model.AbstractEditingModel#createNLResourceHelper()
138      */

139     protected NLResourceHelper createNLResourceHelper() {
140         String JavaDoc name = isFragmentModel() ? "fragment" : "plugin"; //$NON-NLS-1$ //$NON-NLS-2$
141
URL lookupLocation = getNLLookupLocation();
142         if (lookupLocation==null) return null;
143         return new NLResourceHelper(name, new URL[] {lookupLocation});
144     }
145     
146     /* (non-Javadoc)
147      * @see org.eclipse.pde.internal.ui.model.XMLEditingModel#createDocumentHandler(org.eclipse.pde.core.IModel)
148      */

149     protected DefaultHandler createDocumentHandler(IModel model) {
150         if (fHandler == null)
151             fHandler = new PluginDocumentHandler(this);
152         return fHandler;
153     }
154     
155     /* (non-Javadoc)
156      * @see org.eclipse.pde.internal.ui.model.XMLEditingModel#createNodeOffsetHandler(org.eclipse.pde.core.IModel)
157      */

158     protected DefaultHandler createNodeOffsetHandler(IModel model) {
159         if (fNodeOffsetHandler == null)
160             fNodeOffsetHandler = new NodeOffsetHandler(this);
161         return fNodeOffsetHandler;
162     }
163 }
164
Popular Tags