尝试一下,看看第一次发表的Java文章是否另人满意!!:)
1 package org.eclipse.qt;
2
3 import java.io.*;
4 import java.util.ArrayList;
5 import org.eclipse.core.runtime.*;
6 import org.eclipse.jface.resource.ImageDescriptor;
7 import org.eclipse.ui.plugin.AbstractUIPlugin;
8 import org.osgi.framework.BundleContext;
9
10 public class QtPlugin extends AbstractUIPlugin {
11
12 public static String[] readStringsFrom(String file) {
13 try {
14 org.eclipse.core.runtime.IPath template = new Path(file);
15 java.io.InputStream stream = FileLocator.openStream(getDefault()
16 .getBundle(), template, false);
17 BufferedReader in = new BufferedReader(
18 new InputStreamReader(stream));
19 ArrayList lines = new ArrayList();
20 for (String s = in.readLine(); s != null; s = in.readLine())
21 lines.add(s);
22
23 return (String[]) lines.toArray(new String[lines.size()]);
24 } catch (IOException e) {
25 log(makeStatus(2, "Error searching qmake templates", e));
26 }
27 return new String[0];
28 }
29
30 public static void log(IStatus status) {
31 getDefault().getLog().log(status);
32 }
33
34 public QtPlugin() {
35 plugin = this;
36 }
37
38 public void start(BundleContext context) throws Exception {
39 super.start(context);
40 }
41
42 public void stop(BundleContext context) throws Exception {
43 super.stop(context);
44 plugin = null;
45 }
46
47 public static QtPlugin getDefault() {
48 return plugin;
49 }
50
51 public static ImageDescriptor getImageDescriptor(String path) {
52 return AbstractUIPlugin.imageDescriptorFromPlugin("qt", path);
53 }
54
55 public static IStatus makeStatus(int severity, String msg, Throwable exc) {
56 if (exc != null)
57 exc.printStackTrace();
58 return new Status(severity, "org.eclipse.qt", 0, msg, exc);
59 }
60
61 public static final String ID = "org.eclipse.qt";
62
63 private static QtPlugin plugin;
64 }
65