Files
ncs/plugins/TestingList.java
boccioli_m e54ae23d66 Closedown
2015-06-16 15:46:13 +02:00

692 lines
29 KiB
Java

/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
import ch.psi.pshell.core.Controller;
import ch.psi.utils.swing.MonitoredPanel;
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.swing.SwingUtils;
import ch.psi.wsaf.ApplicationStateException;
import ch.psi.wsaf.Task;
import ch.psi.wsaf.TaskRunningException;
import java.awt.Desktop;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.FileHandler;
import java.util.logging.SimpleFormatter;
import javafx.scene.control.SelectionMode;
import javax.script.ScriptException;
import javax.swing.JFileChooser;
import javax.swing.SwingUtilities;
import org.apache.commons.io.FilenameUtils;
public class TestingList extends Panel {
NetbeansPluginPanel testingList;
Task task = new Task() {
@Override
protected Object execute() throws Exception {
return true;
}
};
@Override
protected JPanel create() {
try {
testingList = new NetbeansPluginPanel();
} catch (IOException ex) {
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex);
}
return testingList;
}
//listen to script end of execution and get return value
@Override
protected void onExecutedFile(String fileName) {
int iCurrentTestPos = 0;
try {
Object ret = eval("ret");
boolean status = (boolean) eval("status");
Object deviceName = eval("DEVICE");
String sStatus = (status == true) ? TestStatus.SUCCESS.toString() : TestStatus.FAILURE.toString();
if (ret != "" ) {
File fTest = new File(fileName);
String sTestName = fTest.getName();
//SwingUtils.showMessage(getComponent(), "", ret.toString() + " - " + ret.getClass().getName());
iCurrentTestPos = testingList.showResult(deviceName.toString(), sTestName, ret.toString(), sStatus);
//start next test
if(iCurrentTestPos>=0 && testingList.isTestRunAllowed())
{
testingList.executeTest(iCurrentTestPos+1);
}
}
else{ // ret empty means that either the test script does not have variable ret, or that the script could not be started at all
ret = "Could not start test script";
sStatus = TestStatus.FAILURE.toString();
String[] dsDeviceName = testingList.getTestInProgress();
//SwingUtils.showException(getComponent(), ex );
if(dsDeviceName[0] != ""){
iCurrentTestPos = testingList.showResult(dsDeviceName[0], fileName, ret.toString(), sStatus);
//start next test
if(iCurrentTestPos>=0 && testingList.isTestRunAllowed())
{
testingList.executeTest(iCurrentTestPos+1);
}
}
}
} catch (Exception ex) {
String ret = "Could not start test script";
String sStatus = TestStatus.FAILURE.toString();
String[] dsDeviceName = testingList.getTestInProgress();
//SwingUtils.showException(getComponent(), ex );
SwingUtils.showMessage(getComponent(), "onExecutedFile()", ex.toString() + " " + dsDeviceName[0]);
if(dsDeviceName[0] != ""){
iCurrentTestPos = testingList.showResult(dsDeviceName[0], fileName, ret, sStatus);
//start next test
if(iCurrentTestPos>=0 && testingList.isTestRunAllowed() )
{
testingList.executeTest(iCurrentTestPos+1);
}
}
}
}
//table column indexes
public enum COL {
CHECK (0),
TIME (1),
DEVICENAME (2),
DEVICEDESCR (3),
TESTSUITE (4),
TESTNAME (5),
RESULT (6),
STATUS (7),
ICON (8);
private int value;
private COL(int value) {
this.value = value;
}
public int index(){
return (int) value;
}
};
//enumeration of possible test statuses: text and related icon
public enum TestStatus {
SUCCESS (0),
FAILURE (1),
PENDING (2),
DISABLED (3),
RUNNING (4);
private int value;
private TestStatus(int value) {
this.value = value;
}
public int index(){
return (int) value;
}
public String IconFilename(){
String iconFileName = "";
switch (this){
case SUCCESS:
iconFileName = "/icons/button_ok-16px.png";
break;
case FAILURE:
iconFileName = "/icons/button_close-16px.png";
break;
case PENDING:
iconFileName = "/icons/button_stop-16px.png";
break;
case DISABLED:
iconFileName = "";
break;
case RUNNING:
iconFileName = "/icons/button_play-16px.png";
break;
}
return iconFileName;
}
@Override
public final String toString() {
String status = "";
switch (this) {
case SUCCESS:
status = "Success";
break;
case FAILURE:
status = "Failure";
break;
case PENDING:
status = "Pending";
break;
case DISABLED:
status = "Disabled";
break;
case RUNNING:
status = "Running";
break;
}
return status;
}
public ImageIcon Icon(){
String iconFileName = this.IconFilename();
ImageIcon icon = null;
if (iconFileName != "")
icon = new ImageIcon(getClass().getResource(this.IconFilename()));
return icon;
}
};
public class NetbeansPluginPanel extends MonitoredPanel {
Logger logger = Logger.getLogger("TestsLog");
//these paths are converted to unix or win path according to host OS
private final String TESTS_DEVICES_DEFAULT_DIR = new java.io.File(".").getCanonicalPath()
+ FilenameUtils.separatorsToSystem("/home/script/tests/devices/");
private final String TESTS_TESTS_DEFAULT_DIR = new java.io.File(".").getCanonicalPath()
+ FilenameUtils.separatorsToSystem("/home/script/tests/tests/");
private final String TESTS_LOG_DEFAULT_DIR = new java.io.File(".").getCanonicalPath()
+ FilenameUtils.separatorsToSystem("/home/script/tests/log/TestsLog" + getnow() + ".txt");
//table1 columns indexes
private void initLogger() {
try {
FileHandler fh;
// This block configure the logger with handler and formatter
fh = new FileHandler(TESTS_LOG_DEFAULT_DIR);
logger.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
logger.log(Level.INFO, "New testing session");
} catch (SecurityException e) {
SwingUtils.showMessage(this, "initLogger()", e.toString());
} catch (IOException e) {
SwingUtils.showMessage(this, "initLogger()", e.toString());
}
}
public NetbeansPluginPanel() throws IOException {
initComponents();
initLogger();
buildTable();
loadTests();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane2 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jPanel1 = new javax.swing.JPanel();
jButtonRun = new javax.swing.JButton();
jCheckBox1 = new javax.swing.JCheckBox();
jButtonOpenLog = new javax.swing.JButton();
setLayout(new java.awt.BorderLayout());
jTable1.setFont(new java.awt.Font("Tahoma", 0, 15)); // NOI18N
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Select", "Time", "Device Name", "Device Description", "Test Suite", "Test Name", "Last Test Result", "Status", ""
}
) {
Class[] types = new Class [] {
java.lang.Boolean.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, javax.swing.Icon.class
};
boolean[] canEdit = new boolean [] {
true, true, true, true, true, true, true, true, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jTable1.getTableHeader().setReorderingAllowed(false);
jTable1.setDragEnabled(true);
jTable1.setDropMode(javax.swing.DropMode.INSERT);
jTable1.setRowHeight(22);
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTable1MouseClicked(evt);
}
});
jTable1.addInputMethodListener(new java.awt.event.InputMethodListener() {
public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
jTable1CaretPositionChanged(evt);
}
public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
jTable1InputMethodTextChanged(evt);
}
});
jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
jTable1KeyReleased(evt);
}
public void keyTyped(java.awt.event.KeyEvent evt) {
jTable1KeyTyped(evt);
}
});
jScrollPane2.setViewportView(jTable1);
add(jScrollPane2, java.awt.BorderLayout.CENTER);
jPanel1.setMinimumSize(new java.awt.Dimension(100, 100));
jPanel1.setPreferredSize(new java.awt.Dimension(110, 110));
jPanel1.setLayout(new java.awt.BorderLayout());
jButtonRun.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/button_play-64px.png"))); // NOI18N
jButtonRun.setToolTipText("Run selected tests");
jButtonRun.setMaximumSize(new java.awt.Dimension(33, 39));
jButtonRun.setMinimumSize(new java.awt.Dimension(90, 90));
jButtonRun.setPreferredSize(new java.awt.Dimension(33, 39));
jButtonRun.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonRunActionPerformed(evt);
}
});
jPanel1.add(jButtonRun, java.awt.BorderLayout.CENTER);
jCheckBox1.setToolTipText("Select/Deselect All Tests");
jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox1ActionPerformed(evt);
}
});
jPanel1.add(jCheckBox1, java.awt.BorderLayout.WEST);
jButtonOpenLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/log-icon-64px.png"))); // NOI18N
jButtonOpenLog.setToolTipText("Open current sessions Log");
jButtonOpenLog.setMaximumSize(new java.awt.Dimension(80, 39));
jButtonOpenLog.setMinimumSize(new java.awt.Dimension(90, 90));
jButtonOpenLog.setPreferredSize(new java.awt.Dimension(90, 39));
jButtonOpenLog.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonOpenLogActionPerformed(evt);
}
});
jPanel1.add(jButtonOpenLog, java.awt.BorderLayout.EAST);
add(jPanel1, java.awt.BorderLayout.NORTH);
}// </editor-fold>//GEN-END:initComponents
private void jButtonRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRunActionPerformed
if(this.jButtonRun.getToolTipText().equals("Run selected tests")){
setButtonToStart();
executeTest(0);
}
else{
setButtonToStop();
}
}//GEN-LAST:event_jButtonRunActionPerformed
private void setButtonToStop(){
abort();
this.jButtonRun.setToolTipText("Run selected tests");
jButtonRun.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/button_play-64px.png")));
this.jTable1.setEnabled(true);
}
private void setButtonToStart(){
this.jButtonRun.setToolTipText("Stop tests");
jButtonRun.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/button_stop-64px.png")));
this.jTable1.clearSelection();
this.jTable1.setEnabled(false);
}
private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
boolean bSelected = jCheckBox1.isSelected();
int iSelRows = jTable1.getSelectedRowCount();
if(iSelRows>0){// if some rows are selected, check/uncheck selected rows
for (int row = 0; row <= jTable1.getRowCount()-1; row++) {
for(int selRow=0 ; selRow <= jTable1.getSelectedRowCount()-1 ; selRow++){
if(row == jTable1.getSelectedRows()[selRow])
jTable1.setValueAt(bSelected, row, 0);
}
}
}
else{//if none of the rows are selected, check/uncheck all
for (int row = 0; row <= jTable1.getRowCount()-1; row++) {
jTable1.setValueAt(bSelected, row, 0);
}
}
updateStatus();
}//GEN-LAST:event_jCheckBox1ActionPerformed
private void jTable1InputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jTable1InputMethodTextChanged
}//GEN-LAST:event_jTable1InputMethodTextChanged
private void jTable1CaretPositionChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jTable1CaretPositionChanged
}//GEN-LAST:event_jTable1CaretPositionChanged
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
int colIndex = jTable1.getSelectedColumn();
if (colIndex == COL.CHECK.ordinal()) updateStatus();
}//GEN-LAST:event_jTable1MouseClicked
private void jTable1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyTyped
}//GEN-LAST:event_jTable1KeyTyped
//oopen the log file using one of th default OS text reades
private void jButtonOpenLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOpenLogActionPerformed
String cmd;
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
cmd = "notepad.exe " + TESTS_LOG_DEFAULT_DIR;
} else {
cmd = "nedit " + TESTS_LOG_DEFAULT_DIR;
}
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException ex) {
SwingUtils.showMessage(this, "jButtonOpenLogActionPerformed()", "jButtonOpenLogActionPerformed() "+ ex.toString() + " \nPlease open the file manually. \nFile dir: "+TESTS_LOG_DEFAULT_DIR);
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_jButtonOpenLogActionPerformed
private void jTable1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyReleased
int colIndex = jTable1.getSelectedColumn();
if (colIndex == COL.CHECK.ordinal()) updateStatus();
}//GEN-LAST:event_jTable1KeyReleased
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButtonOpenLog;
private javax.swing.JButton jButtonRun;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable1;
// End of variables declaration//GEN-END:variables
//return status of run button. True = tests launching sequence is running
public boolean isTestRunAllowed(){
return this.jButtonRun.getToolTipText().equals("Stop tests");
}
//show test result in table
public int showResult(String deviceName, String testName, String res, String status) {
int rowD = -1;
//search for device name in table
for (int row = 0; row <= jTable1.getRowCount() - 1; row++) {
if (deviceName.equals(jTable1.getValueAt(row, COL.DEVICENAME.ordinal())) &&
testName.equals(jTable1.getValueAt(row, COL.TESTNAME.ordinal()))) {
rowD = row;
break;
}
}
ImageIcon icon = new ImageIcon();
switch (status) {
case "Success":
icon = TestStatus.SUCCESS.Icon();
logger.log(Level.INFO, "Device: " + deviceName + "; Test: " + testName + " Result: " + res + " (" + status + ")");
break;
case "Failure":
icon = TestStatus.FAILURE.Icon();
logger.log(Level.SEVERE, "Device: " + deviceName + "; Test: " + testName + " Result: " + res + " (" + status + ")");
break;
case "Running":
icon = TestStatus.RUNNING.Icon();
logger.log(Level.INFO, "Running Test: " + testName + ".");
break;
}
if (rowD >= 0) {
jTable1.setValueAt(icon, rowD, COL.ICON.ordinal());
jTable1.setValueAt(getNow(), rowD, COL.TIME.ordinal());
jTable1.setValueAt(res, rowD, COL.RESULT.ordinal());
jTable1.setValueAt(status, rowD, COL.STATUS.ordinal());
}
return rowD;
}
//find the test currently in progress
public String[] getTestInProgress() {
String[] dsTestProperties = {"",""};
//search for device name in table
try{
for (int row = 0; row <= jTable1.getRowCount() - 1; row++) {
if (jTable1.getValueAt(row, COL.STATUS.ordinal()).toString().equals(TestStatus.RUNNING.toString())) {
dsTestProperties[0] = jTable1.getValueAt(row, COL.DEVICENAME.ordinal()).toString();
dsTestProperties[1] = jTable1.getValueAt(row, COL.TESTNAME.ordinal()).toString();
break;
}
}
}
catch (Exception ex) {
this.setButtonToStop();
SwingUtils.showMessage(this, "getTestInProgress()", ex.toString());
}
finally{
return dsTestProperties;
}
}
//returns the status of the specified test name for specified device name
public String getResult(String deviceName, String testName){
String sStatus = "";
int rowD = -1, colT = -1;
//search for device name in table
for (int row = 0; row <= jTable1.getRowCount() - 1; row++) {
if (deviceName.equals(jTable1.getValueAt(row, COL.DEVICENAME.ordinal()))) {
rowD = row;
break;
}
}
if (rowD >= 0) {
//search for test name in table
if (testName.equals(jTable1.getValueAt(rowD, COL.TESTNAME.ordinal()))) {
colT = COL.TESTNAME.ordinal();
}
}
if (colT >= 0 && rowD >= 0) {
sStatus = jTable1.getValueAt(rowD, COL.STATUS.ordinal()).toString();
}
return sStatus;
}
//visualise test status (columns status and icon)
public void updateStatus() {
String sStatus;
boolean bSelected;
ImageIcon icon = null;
for (int row = 0; row <= jTable1.getRowCount() - 1; row++) {
bSelected = (boolean) jTable1.getValueAt(row, COL.CHECK.ordinal());
if (bSelected) {
sStatus = TestStatus.PENDING.toString();
icon = TestStatus.PENDING.Icon();
} else {
sStatus = TestStatus.DISABLED.toString();
icon = TestStatus.DISABLED.Icon();
}
jTable1.setValueAt(bSelected, row, COL.CHECK.ordinal());
jTable1.setValueAt(icon, row, COL.ICON.ordinal());
jTable1.setValueAt(sStatus, row, COL.STATUS.ordinal());
}
}
//execute the selected tests in the list, starting from the position
public void executeTest(int position){
boolean bSelected = false;
String sDeviceName;
String sTestName;
String sTestCaseName;
String sTestPath;
HashMap args = new HashMap();
//scan through the table starting from 'position' and execute the first selected test found
int row = position;
if (row >=0 && row <= jTable1.getRowCount()-1 ) {
for(row = position ; row <= jTable1.getRowCount()-1 ; row++){
bSelected = (boolean) jTable1.getValueAt(row, COL.CHECK.ordinal());
if(bSelected) break;
}
if (bSelected) {
//build the .py test file path
sDeviceName = jTable1.getValueAt(row, COL.DEVICENAME.ordinal()).toString();
sTestName = jTable1.getValueAt(row, COL.TESTNAME.ordinal()).toString();
sTestCaseName = jTable1.getValueAt(row, COL.TESTSUITE.ordinal()).toString();
sTestPath = FilenameUtils.separatorsToSystem(TESTS_TESTS_DEFAULT_DIR + sTestCaseName + "/" + sTestName + "/" + sTestName + ".py");
File f = new File(sTestPath);
if(!f.exists() || f.isDirectory()){
logger.log(Level.SEVERE, "Test file not found: " + sTestPath);
showResult(sDeviceName, sTestName, "Test file not found: " + sTestPath, TestStatus.FAILURE.toString());
return;
}
showResult(sDeviceName, sTestName, "Test running", TestStatus.RUNNING.toString());
//launch the test
try{
args.put("DEVICE", sDeviceName);
args.put("ret", "");
args.put("status", false);
runAsync(sTestPath, args);
} catch (Exception ex) {
SwingUtils.showMessage(this, "executeTest()", ex.toString());
logger.log(Level.SEVERE, ex.toString());
showResult(sDeviceName, sTestName, ex.toString(), TestStatus.FAILURE.toString());
setButtonToStop();
}
}
}
if(!bSelected){ //No test to play. Stop
setButtonToStop();
logger.log(Level.INFO, "End of tests.");
}
}
//table management
public void buildTable() {
String sDate = getNow();
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
jTable1.setModel(model);
jTable1.getColumnModel().getColumn(COL.ICON.ordinal()).setMaxWidth(27);
jTable1.getColumnModel().getColumn(COL.CHECK.ordinal()).setMaxWidth(27);
jTable1.getColumnModel().getColumn(COL.DEVICENAME.ordinal()).setPreferredWidth(30);
jTable1.getColumnModel().getColumn(COL.STATUS.ordinal()).setPreferredWidth(30);
jTable1.setAutoCreateRowSorter(true);
updateStatus();
}
//append test info to table
public void addToTable(String deviceName, String deviceDescription, String testSuite, String testName) {
String sDate = "";
if (testName.equals("") || deviceName.equals("")) {
return;
}
ImageIcon icon = null;// new ImageIcon(getClass().getResource("/icons/button_pause-16px.png"));
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
model.addRow(new Object[]{false, sDate, deviceName, deviceDescription, testSuite, testName, "", "Pending", icon});
jTable1.setModel(model);
updateStatus();
}
//formatted time
public String getNow() {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
return dateFormat.format(date);
}
//time without format
public String getnow() {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
Date date = new Date();
return dateFormat.format(date);
}
//scan tests directory, scan devices directory, search for their test cases and scan for tests.
public void loadTests() throws FileNotFoundException, IOException {
Properties propDevice = new Properties();
Properties propTest = new Properties();
String fileName = TESTS_DEVICES_DEFAULT_DIR;
File folder = new File(fileName);
File testsFolder = null;
String sTestName;
int iCounter = 0;
//search devices and their tests
//Scan the list of devices
File[] listOfFiles = folder.listFiles();
for (File listOfFile : listOfFiles) {
if (listOfFile.isFile()) {
} else if (listOfFile.isDirectory()) {
File configFile = new File(listOfFile.getPath() + FilenameUtils.separatorsToSystem("/.config"));
if (configFile.exists() && !configFile.isDirectory()) {
InputStream is = new FileInputStream(configFile);
propDevice.load(is);
//config of device was loaded. now load the config of each test belonging to the device
sTestName = TESTS_TESTS_DEFAULT_DIR + propDevice.getProperty("tests");
testsFolder = new File(sTestName);
if (testsFolder.exists() && testsFolder.isDirectory()) {
File[] listOfTests = testsFolder.listFiles();
for (File listOfTest : listOfTests) {
if (listOfTest.isDirectory()) {
configFile = new File(listOfTest.getPath() + FilenameUtils.separatorsToSystem("/.config"));
if (configFile.exists() && !configFile.isDirectory()) {
InputStream ist = new FileInputStream(configFile);
propTest.load(ist);
addToTable(propDevice.getProperty("name"),
propDevice.getProperty("description"),
propDevice.getProperty("tests"),
propTest.getProperty("name"));
iCounter++;
}
}
}
}
}
}
}
logger.log(Level.INFO, iCounter + " tests loaded.");
}
public void selectFile() {
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(NetbeansPluginPanel.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
//This is where a real application would open the file.
System.out.println("Opening: " + file.getName() + ".");
} else {
System.out.println("Open command cancelled by user.");
}
}
}
}