PageRenderTime 106ms CodeModel.GetById 98ms app.highlight 6ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/JavaInsight/javainsight/JavaInsightPlugin.java

#
Java | 85 lines | 48 code | 9 blank | 28 comment | 15 complexity | bf867adee8dd731a323608226dd4b8c4 MD5 | raw file
 1/*
 2 * jEdit edit mode settings:
 3 * :mode=java:tabSize=4:indentSize=4:noTabs=true:maxLineLen=0:
 4 *
 5 * This program is free software; you can redistribute it and/or
 6 * modify it under the terms of the GNU General Public License
 7 * as published by the Free Software Foundation; either version 2
 8 * of the License, or any later version.
 9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20package javainsight;
21
22
23import org.gjt.sp.jedit.Buffer;
24import org.gjt.sp.jedit.EBMessage;
25import org.gjt.sp.jedit.EBPlugin;
26import org.gjt.sp.jedit.Mode;
27import org.gjt.sp.jedit.View;
28import org.gjt.sp.jedit.jEdit;
29import org.gjt.sp.jedit.io.VFS;
30import org.gjt.sp.jedit.io.VFSFile;
31import org.gjt.sp.jedit.io.VFSManager;
32import org.gjt.sp.jedit.msg.BufferUpdate;
33
34
35/**
36 * Main JavaInsight plugin class.
37 *
38 * @author Kevin A. Burton
39 * @version $Id: JavaInsightPlugin.java 9456 2007-04-18 20:09:54Z dmoebius $
40 */
41public class JavaInsightPlugin extends EBPlugin
42{
43    /**
44     * Handle message for decompile requests.
45     */
46    @Override
47    public void handleMessage(EBMessage message) {
48        if (message instanceof BufferUpdate) {
49            BufferUpdate bu = (BufferUpdate) message;
50            if (bu.getWhat() == BufferUpdate.LOADED) {
51                Buffer buffer = bu.getBuffer();
52                VFS    vfs    = buffer.getVFS();
53                Mode   mode   = null;
54                if (ClassVFS.PROTOCOL.equals(vfs.getName()) || JasminVFS.PROTOCOL.equals(vfs.getName())) {
55                    mode = jEdit.getMode("bcel");
56                } else if (JodeVFS.PROTOCOL.equals(vfs.getName())) {
57                    mode = jEdit.getMode("java");
58                }
59                if (mode != null) {
60                    buffer.setMode(mode);
61                }
62            }
63        }
64    }
65
66    public void handleBrowserAction(View view, VFSFile[] files, String protocol) {
67        if (files == null)  {
68            // TODO: error message
69            view.getToolkit().beep();
70            return;
71        }
72    
73        for (VFSFile entry : files) {
74            if (entry.getType() == VFSFile.FILE) {
75                VFS vfs = VFSManager.getVFSForPath(entry.getPath());
76                if(protocol.equals(vfs.getName()))
77                    jEdit.openFile(view, entry.getPath());
78                else
79                    jEdit.openFile(view, protocol + ':' + entry.getPath());
80            }
81        }
82    }
83
84}
85