1 | package com.framsticks.framclipse; |
---|
2 | |
---|
3 | import java.io.IOException; |
---|
4 | import java.net.URL; |
---|
5 | import java.util.HashMap; |
---|
6 | import java.util.Map; |
---|
7 | |
---|
8 | import org.eclipse.jface.resource.ImageDescriptor; |
---|
9 | import org.eclipse.jface.text.rules.RuleBasedScanner; |
---|
10 | import org.eclipse.ui.plugin.AbstractUIPlugin; |
---|
11 | import org.jdom.Document; |
---|
12 | import org.jdom.JDOMException; |
---|
13 | import org.jdom.input.SAXBuilder; |
---|
14 | import org.osgi.framework.BundleContext; |
---|
15 | |
---|
16 | import com.framsticks.framclipse.editors.configuration.FramscriptPartitionScanner; |
---|
17 | import com.framsticks.framclipse.syntaxColoring.ColorManager; |
---|
18 | import com.framsticks.framclipse.syntaxColoring.FramscriptCodeScanner; |
---|
19 | |
---|
20 | |
---|
21 | /** |
---|
22 | * The activator class controls the plug-in life cycle |
---|
23 | */ |
---|
24 | public class Framclipse extends AbstractUIPlugin { |
---|
25 | |
---|
26 | private static final String FRAMSCRIPT_SYNTAX = "framscript.xml"; |
---|
27 | private static final String FRAMSCRIPT_CONTEXT = "framscontext.xml"; |
---|
28 | |
---|
29 | public final static String FRAMSCRIPT_PARTITIONING = "__framscript_partitioning"; |
---|
30 | |
---|
31 | // The plug-in ID |
---|
32 | public static final String PLUGIN_ID = "Framclipse"; |
---|
33 | |
---|
34 | // The shared instance |
---|
35 | private static Framclipse plugin; |
---|
36 | |
---|
37 | private ColorManager colorManager; |
---|
38 | |
---|
39 | private RuleBasedScanner codeScanner; |
---|
40 | |
---|
41 | private Map<String, FramscriptPartitionScanner> partitionScanners; |
---|
42 | |
---|
43 | private Document framscriptSyntax; |
---|
44 | private Document framscriptContext; |
---|
45 | |
---|
46 | /** |
---|
47 | * The constructor |
---|
48 | */ |
---|
49 | public Framclipse() { |
---|
50 | plugin = this; |
---|
51 | partitionScanners = new HashMap<String, FramscriptPartitionScanner>(); |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * Returns the singleton color manager. |
---|
56 | * |
---|
57 | * @return the singleton color manager. |
---|
58 | */ |
---|
59 | public ColorManager getColorManager() { |
---|
60 | if (colorManager == null) { |
---|
61 | colorManager = new ColorManager(); |
---|
62 | } |
---|
63 | return colorManager; |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * Returns the singleton Framscript scanner. |
---|
68 | * |
---|
69 | * @return the singleton Framscript scanner |
---|
70 | */ |
---|
71 | public RuleBasedScanner getFramscriptCodeScanner() { |
---|
72 | if (codeScanner == null) { |
---|
73 | codeScanner = new FramscriptCodeScanner(); |
---|
74 | } |
---|
75 | return codeScanner; |
---|
76 | } |
---|
77 | |
---|
78 | /** |
---|
79 | * Return a scanner for creating framscript partitions. |
---|
80 | * |
---|
81 | * @return a scanner for creating framscript partitions |
---|
82 | */ |
---|
83 | public FramscriptPartitionScanner getFramscriptPartitionScanner(String codeFileName) { |
---|
84 | FramscriptPartitionScanner partitionScanner = partitionScanners.get(codeFileName); |
---|
85 | if (partitionScanner == null) { |
---|
86 | partitionScanner = new FramscriptPartitionScanner(codeFileName); |
---|
87 | partitionScanners.put(codeFileName, partitionScanner); |
---|
88 | } |
---|
89 | return partitionScanner; |
---|
90 | } |
---|
91 | |
---|
92 | /* |
---|
93 | * (non-Javadoc) |
---|
94 | * |
---|
95 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) |
---|
96 | */ |
---|
97 | @Override |
---|
98 | public void start(BundleContext context) throws Exception { |
---|
99 | super.start(context); |
---|
100 | } |
---|
101 | |
---|
102 | /* |
---|
103 | * (non-Javadoc) |
---|
104 | * |
---|
105 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
---|
106 | */ |
---|
107 | @Override |
---|
108 | public void stop(BundleContext context) throws Exception { |
---|
109 | plugin = null; |
---|
110 | super.stop(context); |
---|
111 | } |
---|
112 | |
---|
113 | /** |
---|
114 | * Returns the shared instance |
---|
115 | * |
---|
116 | * @return the shared instance |
---|
117 | */ |
---|
118 | public static Framclipse getDefault() { |
---|
119 | return plugin; |
---|
120 | } |
---|
121 | |
---|
122 | /** |
---|
123 | * Returns an image descriptor for the image file at the given plug-in |
---|
124 | * relative path |
---|
125 | * |
---|
126 | * @param path |
---|
127 | * the path |
---|
128 | * @return the image descriptor |
---|
129 | */ |
---|
130 | public static ImageDescriptor getImageDescriptor(String path) { |
---|
131 | return imageDescriptorFromPlugin(PLUGIN_ID, path); |
---|
132 | } |
---|
133 | |
---|
134 | public Document getFramscriptSyntax() { |
---|
135 | if (framscriptSyntax == null) { |
---|
136 | framscriptSyntax = readDocument(FRAMSCRIPT_SYNTAX); |
---|
137 | } |
---|
138 | |
---|
139 | return framscriptSyntax; |
---|
140 | } |
---|
141 | |
---|
142 | public Document getFramscriptContext() { |
---|
143 | if (framscriptContext == null) { |
---|
144 | framscriptContext = readDocument(FRAMSCRIPT_CONTEXT); |
---|
145 | } |
---|
146 | |
---|
147 | return framscriptContext; |
---|
148 | } |
---|
149 | |
---|
150 | private Document readDocument(String fileName) { |
---|
151 | Document document = null; |
---|
152 | try { |
---|
153 | SAXBuilder builder = new SAXBuilder(); |
---|
154 | ClassLoader classLoader = getDefault().getClass().getClassLoader(); |
---|
155 | URL syntaxURL = classLoader.getResource(fileName); |
---|
156 | document = builder.build(syntaxURL); |
---|
157 | } catch (JDOMException e) { |
---|
158 | e.printStackTrace(); |
---|
159 | } catch (IOException e) { |
---|
160 | e.printStackTrace(); |
---|
161 | } |
---|
162 | return document; |
---|
163 | } |
---|
164 | } |
---|