1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package org.openoffice.idesupport.ui; 29 30 import java.io.File; 31 import java.util.Vector; 32 import java.util.ArrayList; 33 34 import java.lang.reflect.Method; 35 import java.lang.reflect.Modifier; 36 37 import javax.swing.JPanel; 38 import javax.swing.JScrollPane; 39 import javax.swing.JList; 40 import javax.swing.JTable; 41 import javax.swing.table.AbstractTableModel; 42 import javax.swing.JLabel; 43 import java.awt.BorderLayout; 44 import java.net.URL; 45 import java.net.URLClassLoader; 46 import java.net.MalformedURLException; 47 48 import com.sun.star.script.framework.container.ScriptEntry; 49 import org.openoffice.idesupport.MethodFinder; 50 import org.openoffice.idesupport.ExtensionFinder; 51 import org.openoffice.idesupport.JavaFinder; 52 53 public class MethodPanel extends JPanel { 54 55 private File basedir; 56 private Vector classpath; 57 private final static String FIRST_PARAM = 58 "drafts.com.sun.star.script.framework.runtime.XScriptContext"; 59 60 // private JTable table; 61 // private MethodTableModel model; 62 private JList list; 63 private ScriptEntry[] values; 64 65 public MethodPanel(File basedir, Vector classpath, String language) { 66 this.basedir = basedir; 67 this.classpath = classpath; 68 69 initValues(language); 70 initUI(); 71 } 72 73 public void reload(File basedir, Vector classpath, String language) { 74 this.basedir = basedir; 75 this.classpath = classpath; 76 77 initValues(language); 78 list.setListData(values); 79 } 80 81 public ScriptEntry[] getSelectedEntries() { 82 Object[] selections = list.getSelectedValues(); 83 ScriptEntry[] entries = new ScriptEntry[selections.length]; 84 85 for (int i = 0; i < selections.length; i++) { 86 entries[i] = (ScriptEntry)selections[i]; 87 } 88 89 return entries; 90 } 91 92 private void initUI() { 93 JLabel label = new JLabel("Available Methods:"); 94 // table = new JTable(model); 95 list = new JList(values); 96 97 JScrollPane pane = new JScrollPane(list); 98 label.setLabelFor(pane); 99 100 BorderLayout layout = new BorderLayout(); 101 setLayout(layout); 102 layout.setVgap(5); 103 104 add(label, BorderLayout.NORTH); 105 add(pane, BorderLayout.CENTER); 106 } 107 108 private void initValues(String language) { 109 MethodFinder finder; 110 111 if (language == null) 112 finder = JavaFinder.getInstance(classpath); 113 else if (language.toLowerCase().equals("beanshell")) 114 finder = new ExtensionFinder(language, new String[] {".bsh"}); 115 else 116 finder = JavaFinder.getInstance(classpath); 117 118 values = finder.findMethods(basedir); 119 } 120 121 /* 122 private class MethodTableModel extends AbstractTableModel { 123 final String[] columnNames = {"Method", 124 "Language"}; 125 126 private Vector methods; 127 private int nextRow; 128 129 public MethodTableModel() { 130 methods = new Vector(11); 131 } 132 133 public int getColumnCount() { 134 return columnNames.length; 135 } 136 137 public int getRowCount() { 138 return methods.size(); 139 } 140 141 public String getColumnName(int col) { 142 return columnNames[col]; 143 } 144 145 public void add(ScriptEntry entry) { 146 methods.addElement(entry); 147 fireTableRowsInserted(nextRow, nextRow); 148 nextRow++; 149 } 150 151 public void remove(int row) { 152 methods.removeElementAt(row); 153 fireTableRowsDeleted(row, row); 154 nextRow--; 155 } 156 157 public void removeAll() { 158 methods.removeAllElements(); 159 fireTableRowsDeleted(0, nextRow); 160 nextRow = 0; 161 } 162 163 public Object getValueAt(int row) { 164 return methods.elementAt(row); 165 } 166 167 public Object getValueAt(int row, int col) { 168 String result = ""; 169 ScriptEntry entry; 170 171 entry = (ScriptEntry)methods.elementAt(row); 172 173 if (col == 0) 174 result = entry.getLanguageName(); 175 else if (col == 1) 176 result = entry.getLanguage(); 177 178 return result; 179 } 180 181 public boolean isCellEditable(int row, int col) { 182 return false; 183 } 184 } 185 */ 186 } 187