1 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 39 public IPluginBase createPluginBase(boolean isFragment) { 40 if (isFragment) { 41 fPluginBase = new FragmentNode(); 42 fPluginBase.setXMLTagName("fragment"); } else { 44 fPluginBase = new PluginNode(); 45 fPluginBase.setXMLTagName("plugin"); } 47 fPluginBase.setInTheModel(true); 48 fPluginBase.setModel(this); 49 return fPluginBase; 50 } 51 52 public IPluginBase createPluginBase() { 53 return createPluginBase(isFragmentModel()); 54 } 55 56 59 public IBuildModel getBuildModel() { 60 return null; 61 } 62 63 66 public IPluginBase getPluginBase() { 67 return getPluginBase(true); 68 } 69 70 public IExtensions getExtensions() { 71 return getPluginBase(); 72 } 73 74 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 95 public boolean isEnabled() { 96 return fIsEnabled; 97 } 98 99 102 public void setEnabled(boolean enabled) { 103 fIsEnabled = enabled; 104 } 105 106 109 public IPluginModelFactory getPluginFactory() { 110 return fFactory; 111 } 112 113 116 public URL getNLLookupLocation() { 117 String installLocation = getInstallLocation(); 118 if (installLocation==null) return null; 119 if (installLocation.startsWith("file:") == false) installLocation = "file:" + installLocation; try { 122 URL url = new URL(installLocation + "/"); return url; 124 } catch (MalformedURLException e) { 125 return null; 126 } 127 } 128 129 132 public IExtensionsModelFactory getFactory() { 133 return fFactory; 134 } 135 136 139 protected NLResourceHelper createNLResourceHelper() { 140 String name = isFragmentModel() ? "fragment" : "plugin"; URL lookupLocation = getNLLookupLocation(); 142 if (lookupLocation==null) return null; 143 return new NLResourceHelper(name, new URL[] {lookupLocation}); 144 } 145 146 149 protected DefaultHandler createDocumentHandler(IModel model) { 150 if (fHandler == null) 151 fHandler = new PluginDocumentHandler(this); 152 return fHandler; 153 } 154 155 158 protected DefaultHandler createNodeOffsetHandler(IModel model) { 159 if (fNodeOffsetHandler == null) 160 fNodeOffsetHandler = new NodeOffsetHandler(this); 161 return fNodeOffsetHandler; 162 } 163 } 164 | Popular Tags |