New feature: show custom panel (if its class is enabled as plugin)
Working on Kollimators.java custom panel
This commit is contained in:
@@ -295,9 +295,9 @@ public class TestingList extends Panel {
|
||||
*/
|
||||
private void initialise(){
|
||||
initComponents();
|
||||
addCustomPanel();
|
||||
initLogger();
|
||||
buildTable();
|
||||
closeCustomPanel();
|
||||
try {
|
||||
loadTests();
|
||||
//if not administrator, then show only enabled tests
|
||||
@@ -313,32 +313,69 @@ public class TestingList extends Panel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add custom panel if specified
|
||||
* close the custom panel if present
|
||||
*/
|
||||
private void closeCustomPanel(){
|
||||
jPanelCustomFrame.removeAll();
|
||||
jPanelCustom.setVisible(false);
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* load plugins available excluding the plugins used directly by TestingList
|
||||
* @return list of plugins assumed to be custom panels
|
||||
*/
|
||||
private void addCustomPanel(){
|
||||
private List<String> getCustomPanels(){
|
||||
Path pluginsPath = Paths.get(".", "home", "config", "plugins.properties");
|
||||
List<String> stringBuffer =new ArrayList<String>() ;
|
||||
try {
|
||||
File file = new File(pluginsPath.toString());
|
||||
FileReader fileReader = new FileReader(file);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
String line;
|
||||
String line, fileName;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
stringBuffer.append(line);
|
||||
stringBuffer.append("\n");
|
||||
if(line.contains("=enabled")){
|
||||
fileName = line.replace(".java=enabled", "");
|
||||
fileName = (Paths.get(fileName)).getFileName().toString();
|
||||
if( !(fileName.contains("TestingListDetails") ||
|
||||
fileName.contains("TestingList") ||
|
||||
fileName.contains("NewTest"))){
|
||||
stringBuffer.add(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
fileReader.close();
|
||||
System.out.println("Contents of file:");
|
||||
System.out.println(stringBuffer.toString());
|
||||
//System.out.println("Contents of file:");
|
||||
//System.out.println(stringBuffer.toString());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return stringBuffer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add custom panel if specified.
|
||||
* Custom panels are java classes. To add a new custom panel MyNewPanel:
|
||||
* - create a panel and save it as MyNewPanel.java
|
||||
* - add MyNewPanel.java file in the pshell plugins folder
|
||||
* - on pshell, open Plugins and enable MyNewPanel.java
|
||||
* - restart pshell
|
||||
* To show the new panel, open the enu Advanced/Load Custom Panel
|
||||
*
|
||||
*/
|
||||
private void loadCustomPanel(String sPanelClassName){
|
||||
try {
|
||||
closeCustomPanel();
|
||||
//create a class to visualise the details panel
|
||||
Class panelClass = getController().getClassByName("Kollimators");
|
||||
Class panelClass = getController().getClassByName(sPanelClassName);
|
||||
JPanel detailsPanel = (JPanel) panelClass.getConstructor(new Class[]{String.class}).newInstance(new Object[]{""});
|
||||
this.jPanelCustom.add(detailsPanel);
|
||||
this.jPanelCustomFrame.add(detailsPanel);
|
||||
repaint();
|
||||
revalidate();
|
||||
jPanelCustom.setVisible(true);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
@@ -413,6 +450,7 @@ public class TestingList extends Panel {
|
||||
jMenuAdvanced = new javax.swing.JMenu();
|
||||
jMenuItemNewTest = new javax.swing.JMenuItem();
|
||||
jMenuItemNewDevice = new javax.swing.JMenuItem();
|
||||
jMenuLoadCustomPanel = new javax.swing.JMenu();
|
||||
jSeparator2 = new javax.swing.JPopupMenu.Separator();
|
||||
jMenuItemEditScript = new javax.swing.JMenuItem();
|
||||
jMenuItemOpenLog = new javax.swing.JMenuItem();
|
||||
@@ -430,8 +468,6 @@ public class TestingList extends Panel {
|
||||
jSeparator4 = new javax.swing.JPopupMenu.Separator();
|
||||
jCheckBoxMenuShowSelectedTests1 = new javax.swing.JCheckBoxMenuItem();
|
||||
jMenuItemReload1 = new javax.swing.JMenuItem();
|
||||
jScrollPane2 = new javax.swing.JScrollPane();
|
||||
jTable1 = new javax.swing.JTable();
|
||||
jPanel1 = new javax.swing.JPanel();
|
||||
jPanelTopCommands = new javax.swing.JPanel();
|
||||
jPanelButtons = new javax.swing.JPanel();
|
||||
@@ -443,7 +479,11 @@ public class TestingList extends Panel {
|
||||
jCheckBoxEnableDisable = new javax.swing.JCheckBox();
|
||||
jButtonMoveDown = new javax.swing.JButton();
|
||||
jButtonMoveUp = new javax.swing.JButton();
|
||||
jScrollPane2 = new javax.swing.JScrollPane();
|
||||
jTable1 = new javax.swing.JTable();
|
||||
jPanelCustom = new javax.swing.JPanel();
|
||||
jPanelCustomFrame = new javax.swing.JPanel();
|
||||
jButtonX = new javax.swing.JButton();
|
||||
|
||||
jCheckBoxMenuShowSelectedTests.setSelected(true);
|
||||
jCheckBoxMenuShowSelectedTests.setText("Show enabled tests only");
|
||||
@@ -480,6 +520,18 @@ public class TestingList extends Panel {
|
||||
}
|
||||
});
|
||||
jMenuAdvanced.add(jMenuItemNewDevice);
|
||||
|
||||
jMenuLoadCustomPanel.setText("Load Custom Panel");
|
||||
jMenuLoadCustomPanel.addMenuListener(new javax.swing.event.MenuListener() {
|
||||
public void menuCanceled(javax.swing.event.MenuEvent evt) {
|
||||
}
|
||||
public void menuDeselected(javax.swing.event.MenuEvent evt) {
|
||||
}
|
||||
public void menuSelected(javax.swing.event.MenuEvent evt) {
|
||||
jMenuLoadCustomPanelMenuSelected(evt);
|
||||
}
|
||||
});
|
||||
jMenuAdvanced.add(jMenuLoadCustomPanel);
|
||||
jMenuAdvanced.add(jSeparator2);
|
||||
|
||||
jMenuItemEditScript.setText("Edit selected test");
|
||||
@@ -574,48 +626,6 @@ public class TestingList extends Panel {
|
||||
|
||||
setLayout(new java.awt.BorderLayout());
|
||||
|
||||
jTable1.setAutoCreateRowSorter(true);
|
||||
jTable1.setFont(new java.awt.Font("Tahoma", 0, 15)); // NOI18N
|
||||
jTable1.setModel(new javax.swing.table.DefaultTableModel(
|
||||
new Object [][] {
|
||||
|
||||
},
|
||||
new String [] {
|
||||
"Enable", "Start", "Time", "Device Name", "Device Description", "Test Suite", "Test Name", "Test Peth", "Test Parameters", "Test Description", "Test Help", "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, 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, false, false, false, false, false, false, false, false, false, false, false, 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.setRowHeight(22);
|
||||
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
||||
jTable1MouseClicked(evt);
|
||||
}
|
||||
});
|
||||
jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
|
||||
public void keyReleased(java.awt.event.KeyEvent evt) {
|
||||
jTable1KeyReleased(evt);
|
||||
}
|
||||
});
|
||||
jScrollPane2.setViewportView(jTable1);
|
||||
|
||||
add(jScrollPane2, java.awt.BorderLayout.CENTER);
|
||||
|
||||
jPanel1.setMinimumSize(new java.awt.Dimension(100, 200));
|
||||
jPanel1.setPreferredSize(new java.awt.Dimension(110, 110));
|
||||
jPanel1.setLayout(new java.awt.BorderLayout());
|
||||
@@ -717,7 +727,80 @@ public class TestingList extends Panel {
|
||||
jPanel1.add(jPanelTopCommands, java.awt.BorderLayout.CENTER);
|
||||
|
||||
add(jPanel1, java.awt.BorderLayout.NORTH);
|
||||
add(jPanelCustom, java.awt.BorderLayout.PAGE_END);
|
||||
|
||||
jTable1.setAutoCreateRowSorter(true);
|
||||
jTable1.setFont(new java.awt.Font("Tahoma", 0, 15)); // NOI18N
|
||||
jTable1.setModel(new javax.swing.table.DefaultTableModel(
|
||||
new Object [][] {
|
||||
|
||||
},
|
||||
new String [] {
|
||||
"Enable", "Start", "Time", "Device Name", "Device Description", "Test Suite", "Test Name", "Test Peth", "Test Parameters", "Test Description", "Test Help", "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, 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, false, false, false, false, false, false, false, false, false, false, false, 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.setRowHeight(22);
|
||||
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
||||
jTable1MouseClicked(evt);
|
||||
}
|
||||
});
|
||||
jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
|
||||
public void keyReleased(java.awt.event.KeyEvent evt) {
|
||||
jTable1KeyReleased(evt);
|
||||
}
|
||||
});
|
||||
jScrollPane2.setViewportView(jTable1);
|
||||
|
||||
add(jScrollPane2, java.awt.BorderLayout.CENTER);
|
||||
|
||||
jPanelCustom.setPreferredSize(new java.awt.Dimension(400, 100));
|
||||
|
||||
jButtonX.setFont(new java.awt.Font("Tahoma", 0, 8)); // NOI18N
|
||||
jButtonX.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/x-8px.png"))); // NOI18N
|
||||
jButtonX.setToolTipText("Close this custom panel");
|
||||
jButtonX.setPreferredSize(new java.awt.Dimension(8, 8));
|
||||
jButtonX.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButtonXActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout jPanelCustomLayout = new javax.swing.GroupLayout(jPanelCustom);
|
||||
jPanelCustom.setLayout(jPanelCustomLayout);
|
||||
jPanelCustomLayout.setHorizontalGroup(
|
||||
jPanelCustomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jPanelCustomFrame, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelCustomLayout.createSequentialGroup()
|
||||
.addGap(0, 382, Short.MAX_VALUE)
|
||||
.addComponent(jButtonX, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
);
|
||||
jPanelCustomLayout.setVerticalGroup(
|
||||
jPanelCustomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanelCustomLayout.createSequentialGroup()
|
||||
.addComponent(jButtonX, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE)
|
||||
.addGap(0, 0, 0)
|
||||
.addComponent(jPanelCustomFrame, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(253, 253, 253))
|
||||
);
|
||||
|
||||
add(jPanelCustom, java.awt.BorderLayout.SOUTH);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void jButtonRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRunActionPerformed
|
||||
@@ -985,6 +1068,27 @@ public class TestingList extends Panel {
|
||||
jButtonRunActionPerformed( evt);
|
||||
}//GEN-LAST:event_jMenuItemRunSingleTestActionPerformed
|
||||
|
||||
private void jMenuLoadCustomPanelMenuSelected(javax.swing.event.MenuEvent evt) {//GEN-FIRST:event_jMenuLoadCustomPanelMenuSelected
|
||||
// TODO add your handling code here:
|
||||
List<String> menuList = getCustomPanels();
|
||||
jMenuLoadCustomPanel.removeAll();
|
||||
for(int u = 0; u < menuList.size(); u++){
|
||||
|
||||
JMenuItem menuItem = new JMenuItem(menuList.get(u));
|
||||
menuItem.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
loadCustomPanel(((JMenuItem)evt.getSource()).getText());
|
||||
}
|
||||
});
|
||||
jMenuLoadCustomPanel.add(menuItem);
|
||||
}
|
||||
}//GEN-LAST:event_jMenuLoadCustomPanelMenuSelected
|
||||
|
||||
private void jButtonXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonXActionPerformed
|
||||
// TODO add your handling code here:
|
||||
closeCustomPanel();
|
||||
}//GEN-LAST:event_jButtonXActionPerformed
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="Witget Variables declaration">
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton jButtonMoveDown;
|
||||
@@ -993,6 +1097,7 @@ public class TestingList extends Panel {
|
||||
private javax.swing.JButton jButtonOptions;
|
||||
private javax.swing.JButton jButtonRun;
|
||||
private javax.swing.JButton jButtonSave;
|
||||
private javax.swing.JButton jButtonX;
|
||||
private javax.swing.JCheckBox jCheckBoxEnableDisable;
|
||||
private javax.swing.JCheckBoxMenuItem jCheckBoxMenuShowSelectedTests;
|
||||
private javax.swing.JCheckBoxMenuItem jCheckBoxMenuShowSelectedTests1;
|
||||
@@ -1009,10 +1114,12 @@ public class TestingList extends Panel {
|
||||
private javax.swing.JMenuItem jMenuItemSelectNone;
|
||||
private javax.swing.JMenuItem jMenuItemSelectSelection;
|
||||
private javax.swing.JMenuItem jMenuItemShowDetails;
|
||||
private javax.swing.JMenu jMenuLoadCustomPanel;
|
||||
private javax.swing.JMenu jMenuSelect;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JPanel jPanelButtons;
|
||||
private javax.swing.JPanel jPanelCustom;
|
||||
private javax.swing.JPanel jPanelCustomFrame;
|
||||
private javax.swing.JPanel jPanelSelection;
|
||||
private javax.swing.JPanel jPanelTopCommands;
|
||||
private javax.swing.JPopupMenu jPopupMenuConfigs;
|
||||
|
||||
Reference in New Issue
Block a user