1*cd519653SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*cd519653SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*cd519653SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*cd519653SAndrew Rist * distributed with this work for additional information 6*cd519653SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*cd519653SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*cd519653SAndrew Rist * "License"); you may not use this file except in compliance 9*cd519653SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*cd519653SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*cd519653SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*cd519653SAndrew Rist * software distributed under the License is distributed on an 15*cd519653SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*cd519653SAndrew Rist * KIND, either express or implied. See the License for the 17*cd519653SAndrew Rist * specific language governing permissions and limitations 18*cd519653SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*cd519653SAndrew Rist *************************************************************/ 21*cd519653SAndrew Rist 22*cd519653SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package org.openoffice.idesupport.ui; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.File; 27cdf0e10cSrcweir import java.util.Vector; 28cdf0e10cSrcweir import java.util.ArrayList; 29cdf0e10cSrcweir 30cdf0e10cSrcweir import java.lang.reflect.Method; 31cdf0e10cSrcweir import java.lang.reflect.Modifier; 32cdf0e10cSrcweir 33cdf0e10cSrcweir import javax.swing.JPanel; 34cdf0e10cSrcweir import javax.swing.JScrollPane; 35cdf0e10cSrcweir import javax.swing.JList; 36cdf0e10cSrcweir import javax.swing.JTable; 37cdf0e10cSrcweir import javax.swing.table.AbstractTableModel; 38cdf0e10cSrcweir import javax.swing.JLabel; 39cdf0e10cSrcweir import java.awt.BorderLayout; 40cdf0e10cSrcweir import java.net.URL; 41cdf0e10cSrcweir import java.net.URLClassLoader; 42cdf0e10cSrcweir import java.net.MalformedURLException; 43cdf0e10cSrcweir 44cdf0e10cSrcweir import com.sun.star.script.framework.container.ScriptEntry; 45cdf0e10cSrcweir import org.openoffice.idesupport.MethodFinder; 46cdf0e10cSrcweir import org.openoffice.idesupport.ExtensionFinder; 47cdf0e10cSrcweir import org.openoffice.idesupport.JavaFinder; 48cdf0e10cSrcweir 49cdf0e10cSrcweir public class MethodPanel extends JPanel { 50cdf0e10cSrcweir 51cdf0e10cSrcweir private File basedir; 52cdf0e10cSrcweir private Vector classpath; 53cdf0e10cSrcweir private final static String FIRST_PARAM = 54cdf0e10cSrcweir "drafts.com.sun.star.script.framework.runtime.XScriptContext"; 55cdf0e10cSrcweir 56cdf0e10cSrcweir // private JTable table; 57cdf0e10cSrcweir // private MethodTableModel model; 58cdf0e10cSrcweir private JList list; 59cdf0e10cSrcweir private ScriptEntry[] values; 60cdf0e10cSrcweir MethodPanel(File basedir, Vector classpath, String language)61cdf0e10cSrcweir public MethodPanel(File basedir, Vector classpath, String language) { 62cdf0e10cSrcweir this.basedir = basedir; 63cdf0e10cSrcweir this.classpath = classpath; 64cdf0e10cSrcweir 65cdf0e10cSrcweir initValues(language); 66cdf0e10cSrcweir initUI(); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir reload(File basedir, Vector classpath, String language)69cdf0e10cSrcweir public void reload(File basedir, Vector classpath, String language) { 70cdf0e10cSrcweir this.basedir = basedir; 71cdf0e10cSrcweir this.classpath = classpath; 72cdf0e10cSrcweir 73cdf0e10cSrcweir initValues(language); 74cdf0e10cSrcweir list.setListData(values); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir getSelectedEntries()77cdf0e10cSrcweir public ScriptEntry[] getSelectedEntries() { 78cdf0e10cSrcweir Object[] selections = list.getSelectedValues(); 79cdf0e10cSrcweir ScriptEntry[] entries = new ScriptEntry[selections.length]; 80cdf0e10cSrcweir 81cdf0e10cSrcweir for (int i = 0; i < selections.length; i++) { 82cdf0e10cSrcweir entries[i] = (ScriptEntry)selections[i]; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir return entries; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir initUI()88cdf0e10cSrcweir private void initUI() { 89cdf0e10cSrcweir JLabel label = new JLabel("Available Methods:"); 90cdf0e10cSrcweir // table = new JTable(model); 91cdf0e10cSrcweir list = new JList(values); 92cdf0e10cSrcweir 93cdf0e10cSrcweir JScrollPane pane = new JScrollPane(list); 94cdf0e10cSrcweir label.setLabelFor(pane); 95cdf0e10cSrcweir 96cdf0e10cSrcweir BorderLayout layout = new BorderLayout(); 97cdf0e10cSrcweir setLayout(layout); 98cdf0e10cSrcweir layout.setVgap(5); 99cdf0e10cSrcweir 100cdf0e10cSrcweir add(label, BorderLayout.NORTH); 101cdf0e10cSrcweir add(pane, BorderLayout.CENTER); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir initValues(String language)104cdf0e10cSrcweir private void initValues(String language) { 105cdf0e10cSrcweir MethodFinder finder; 106cdf0e10cSrcweir 107cdf0e10cSrcweir if (language == null) 108cdf0e10cSrcweir finder = JavaFinder.getInstance(classpath); 109cdf0e10cSrcweir else if (language.toLowerCase().equals("beanshell")) 110cdf0e10cSrcweir finder = new ExtensionFinder(language, new String[] {".bsh"}); 111cdf0e10cSrcweir else 112cdf0e10cSrcweir finder = JavaFinder.getInstance(classpath); 113cdf0e10cSrcweir 114cdf0e10cSrcweir values = finder.findMethods(basedir); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir /* 118cdf0e10cSrcweir private class MethodTableModel extends AbstractTableModel { 119cdf0e10cSrcweir final String[] columnNames = {"Method", 120cdf0e10cSrcweir "Language"}; 121cdf0e10cSrcweir 122cdf0e10cSrcweir private Vector methods; 123cdf0e10cSrcweir private int nextRow; 124cdf0e10cSrcweir 125cdf0e10cSrcweir public MethodTableModel() { 126cdf0e10cSrcweir methods = new Vector(11); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir public int getColumnCount() { 130cdf0e10cSrcweir return columnNames.length; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir public int getRowCount() { 134cdf0e10cSrcweir return methods.size(); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir public String getColumnName(int col) { 138cdf0e10cSrcweir return columnNames[col]; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir public void add(ScriptEntry entry) { 142cdf0e10cSrcweir methods.addElement(entry); 143cdf0e10cSrcweir fireTableRowsInserted(nextRow, nextRow); 144cdf0e10cSrcweir nextRow++; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir public void remove(int row) { 148cdf0e10cSrcweir methods.removeElementAt(row); 149cdf0e10cSrcweir fireTableRowsDeleted(row, row); 150cdf0e10cSrcweir nextRow--; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir public void removeAll() { 154cdf0e10cSrcweir methods.removeAllElements(); 155cdf0e10cSrcweir fireTableRowsDeleted(0, nextRow); 156cdf0e10cSrcweir nextRow = 0; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir public Object getValueAt(int row) { 160cdf0e10cSrcweir return methods.elementAt(row); 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir public Object getValueAt(int row, int col) { 164cdf0e10cSrcweir String result = ""; 165cdf0e10cSrcweir ScriptEntry entry; 166cdf0e10cSrcweir 167cdf0e10cSrcweir entry = (ScriptEntry)methods.elementAt(row); 168cdf0e10cSrcweir 169cdf0e10cSrcweir if (col == 0) 170cdf0e10cSrcweir result = entry.getLanguageName(); 171cdf0e10cSrcweir else if (col == 1) 172cdf0e10cSrcweir result = entry.getLanguage(); 173cdf0e10cSrcweir 174cdf0e10cSrcweir return result; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir public boolean isCellEditable(int row, int col) { 178cdf0e10cSrcweir return false; 179cdf0e10cSrcweir } 180cdf0e10cSrcweir } 181cdf0e10cSrcweir */ 182cdf0e10cSrcweir } 183