blob: 6b00382fd67f2aa635c4ef6290e799641234f947 [file] [log] [blame]
/*
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
import javax.swing.JOptionPane;
import javax.swing.plaf.FileChooserUI;
/*
* NodeViewFrame.java
*
* Created on April 17, 2006, 8:35 PM
*/
/**
*
* @author Alex
*/
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import java.awt.Component;
import java.io.File;
import java.util.Enumeration;
import javax.management.AttributeList;
import javax.management.Attribute;
public class NodeViewFrame extends javax.swing.JFrame implements ListSelectionListener{
String _fileName;
String _current;
NameHelper _nameHelper;
/** Creates new form NodeViewFrame */
public NodeViewFrame() {
initComponents();
DefaultTreeModel model = (DefaultTreeModel)((JTree)jTree1).getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode)model.getRoot();
root.removeAllChildren();
root.setUserObject("GlassFish Configuration");
model.reload();
jTree1.setEnabled(false);
initTables();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
jTree1 = new javax.swing.JTree();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jScrollPane4 = new javax.swing.JScrollPane();
jAttrsTable = new javax.swing.JTable();
jScrollPane5 = new javax.swing.JScrollPane();
jPropsTable = new javax.swing.JTable();
jAddPropery = new javax.swing.JButton();
jDeletePropery = new javax.swing.JButton();
jDottedName = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("GlassFish Configuration Viewer");
setFocusable(false);
setLocationByPlatform(true);
jLabel2.setText("Config file:");
jTextField1.setHorizontalAlignment(javax.swing.JTextField.LEFT);
jTextField1.setText("c:\\gfroot\\glassfish\\appserv-tests\\devtests\\admin\\offlineconfig\\testfiles\\domain.xml ");
jTextField1.addInputMethodListener(new java.awt.event.InputMethodListener() {
public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
}
public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
jTextField1InputMethodTextChanged(evt);
}
});
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Open");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jTree1.setEditable(true);
jTree1.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
jTree1ValueChanged(evt);
}
});
jScrollPane2.setViewportView(jTree1);
jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18));
jLabel3.setText("Attributes:");
jLabel4.setFont(new java.awt.Font("Tahoma", 0, 18));
jLabel4.setText("Properties:");
jAttrsTable.setBackground(new java.awt.Color(255, 255, 153));
jAttrsTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane4.setViewportView(jAttrsTable);
jPropsTable.setBackground(new java.awt.Color(255, 255, 153));
jPropsTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane5.setViewportView(jPropsTable);
jAddPropery.setText("Add Property");
jAddPropery.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jAddProperyActionPerformed(evt);
}
});
jDeletePropery.setText("Delete Property");
jDeletePropery.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jDeleteProperyActionPerformed(evt);
}
});
jLabel1.setText("Dotted Name:");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
.add(6, 6, 6)
.add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton2)
.add(11, 11, 11))
.add(layout.createSequentialGroup()
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 243, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
.add(jScrollPane5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.add(jAddPropery, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 125, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 66, Short.MAX_VALUE)
.add(jDeletePropery, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 125, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jLabel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
.add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
.add(jDottedName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE))
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE, false)
.add(jLabel2)
.add(jButton2)
.add(jButton1)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(25, 25, 25)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(layout.createSequentialGroup()
.add(jLabel1)
.add(5, 5, 5)
.add(jDottedName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 10, Short.MAX_VALUE)
.add(jLabel3)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 222, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel4)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jAddPropery)
.add(jDeletePropery)))
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 460, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jDeleteProperyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jDeleteProperyActionPerformed
int iSelected = jPropsTable.getSelectedRow();
int nSelected = jPropsTable.getSelectedRowCount();
for(int i=iSelected; i<iSelected+nSelected; i++)
{
Object name = ((DefaultTableModel)jPropsTable.getModel()).getValueAt(i, 0);
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
jTree1.getLastSelectedPathComponent();
if(!(node.getUserObject() instanceof DottedNameInfo))
return;
try {
_nameHelper.setValue(node, (String)name, null, true);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Exception:\n"+e.getMessage(),"", JOptionPane.ERROR_MESSAGE);
setTablesForCurrentNode();
}
}
// fillArrayTable();
setTablesForCurrentNode();
jPropsTable.changeSelection(iSelected, iSelected, false, false);
}//GEN-LAST:event_jDeleteProperyActionPerformed
private void jAddProperyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAddProperyActionPerformed
//show add prop dialog here
NewPropDialog dialog = new NewPropDialog(this, true);
dialog.setVisible(true);
String[] pair = dialog.getNameAndValue();
if(pair[0]!=null)
((DefaultTableModel)jPropsTable.getModel()).addRow(pair);
}//GEN-LAST:event_jAddProperyActionPerformed
private void jTextField1InputMethodTextChanged(java.awt.event.InputMethodEvent evt)//GEN-FIRST:event_jTextField1InputMethodTextChanged
{//GEN-HEADEREND:event_jTextField1InputMethodTextChanged
jButton2.setEnabled((new File(jTextField1.getText())).exists());
}//GEN-LAST:event_jTextField1InputMethodTextChanged
private void setTablesForCurrentNode()
{
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
jTree1.getLastSelectedPathComponent();
if(!(node.getUserObject() instanceof DottedNameInfo))
{
jDottedName.setText("");
}
else
{
jDottedName.setText(((DottedNameInfo)node.getUserObject())._name);
}
Object[][] lines = null;
//ATTRS
try {
lines = _nameHelper.getAttributesForNodeInPrintForm(node, false);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Could not get attributes:\nException:\n"+e.getMessage(),"", JOptionPane.ERROR_MESSAGE);
}
fillTable(jAttrsTable, new String[]{"Attribute","Value"}, lines);
jAttrsTable.getModel().addTableModelListener(new MyTableListener(this, false));
//PROPERTIES
try {
lines = _nameHelper.getAttributesForNodeInPrintForm(node, true);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Could not get properties:\nException:\n"+e.getMessage(),"", JOptionPane.ERROR_MESSAGE);
}
fillTable(jPropsTable, new String[]{"Property","Value"}, lines);
jPropsTable.getModel().addTableModelListener(new MyTableListener(this, true));
jPropsTable.getSelectionModel().addListSelectionListener(this);
jDeletePropery.setEnabled(false);
}
private void jTree1ValueChanged(javax.swing.event.TreeSelectionEvent evt)//GEN-FIRST:event_jTree1ValueChanged
{//GEN-HEADEREND:event_jTree1ValueChanged
setTablesForCurrentNode();
}//GEN-LAST:event_jTree1ValueChanged
public void tableChanged(TableModelEvent event, boolean bProperty)
{
if(event.getType()==event.DELETE)
return;
int row = event.getFirstRow();
int column = 1;//event.getColumn();
TableModel model = (TableModel)event.getSource();
Object data = model.getValueAt(row, column);
Object name = model.getValueAt(row, 0);
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
jTree1.getLastSelectedPathComponent();
if(!(node.getUserObject() instanceof DottedNameInfo))
return;
if("".equals(data))
data = "()"; //special "empty property" value
try {
_nameHelper.setValue(node, (String)name, data, bProperty);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Exception:\n"+e.getMessage(),"", JOptionPane.ERROR_MESSAGE);
setTablesForCurrentNode();
}
}
private void initTables()
{
fillTable(jAttrsTable, new String[]{"Attribute","Value"}, null);
fillTable(jPropsTable, new String[]{"Property","Value"}, null);
jDeletePropery.setEnabled(false);
}
private void fillTable(JTable table, String[] header, Object[][] lines)
{
String[] longValues = {header[0], header[1]};
table.removeAll();
MyTableModel model = new MyTableModel(this);
model.addColumn(header[0]);
model.addColumn(header[1]);
if(lines!=null)
{
for (int i=0; i<lines.length; i++)
{
model.addRow(lines[i]);
if(lines[i][0].toString().length()>longValues[0].length())
longValues[0] = lines[i][0].toString();
if(lines[i][1]!=null && lines[i][1].toString().length()>longValues[1].length())
longValues[1] = lines[i][1].toString();
}
}
table.setModel(model);
Object obj0 = table.getDefaultEditor(table.getColumnClass(1));
for (int i = 0; i < 2; i++)
{
TableColumn column = table.getColumnModel().getColumn(i);
Component comp = table.getDefaultRenderer(model.getColumnClass(i)).
getTableCellRendererComponent(
table, longValues[i],
false, false, 0, i);
column.setPreferredWidth(comp.getPreferredSize().width);
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
JFileChooser chooser = new JFileChooser();
switch(chooser.showOpenDialog(this))
{
case JFileChooser.APPROVE_OPTION:
jTextField1.setText(chooser.getSelectedFile().getPath());
break;
}
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
openNewConfig(jTextField1.getText());
}//GEN-LAST:event_jButton2ActionPerformed
private void openNewConfig(String fileName)
{
_fileName = fileName;
jTextField1.setText(_fileName);
setCurrentDottedName("");
}
private void setCurrentDottedName(String current)
{
_current = current;
DefaultTreeModel model = (DefaultTreeModel)((JTree)jTree1).getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode)model.getRoot();
root.removeAllChildren();
root.setUserObject("GlassFish Configuration");
try {
_nameHelper = new NameHelper(_fileName);
_nameHelper.fillDottedNamesTree(root);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "File corrupted:\nException:\n"+e.getMessage(),"", JOptionPane.ERROR_MESSAGE);
}
model.reload();
jTree1.setEnabled(true);
}
class MyTableModel extends DefaultTableModel {
/*
* Don't need to implement this method unless your table's
* editable.
*/
JFrame parentFrame;
public MyTableModel(JFrame frame)
{
super();
parentFrame = frame;
}
public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
Object obj = this.getValueAt(row, col);
if (col < 1 || obj==null)
return false;
if((obj instanceof Object[] )) {
{
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
jTree1.getLastSelectedPathComponent();
if(!(node.getUserObject() instanceof DottedNameInfo))
return false;
//show dialog here
JSetArrayDialog dialog = new JSetArrayDialog(
parentFrame, true,
_nameHelper,
(DottedNameInfo)node.getUserObject(),
(String)this.getValueAt(row, col-1),
(Object[])obj);
dialog.setVisible(true);
return false;
}
} else {
return true;
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NodeViewFrame().setVisible(true);
}
});
}
public void valueChanged(ListSelectionEvent e) {
jDeletePropery.setEnabled(jPropsTable.getSelectedRowCount()>0);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JButton jAddPropery;
private javax.swing.JTable jAttrsTable;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jDeletePropery;
private javax.swing.JTextField jDottedName;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JTable jPropsTable;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JTextField jTextField1;
private javax.swing.JTree jTree1;
// End of variables declaration//GEN-END:variables
}