All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jive3.DeviceLoggingPanel Maven / Gradle / Ivy

The newest version!
package jive3;

import jive.JiveUtils;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Vector;

public class DeviceLoggingPanel extends JPanel implements ActionListener, MouseListener {

  private JScrollPane textView;
  private JTable      theTable;
  private JButton     refreshButton;
  private JButton     applyButton;

  private JPopupMenu  tableMenu;
  private JMenuItem   resetMenuItem;

  private TaskLoggingNode[]  source = null;
  private DefaultTableModel   dm;
  private int selectedRow;

  DeviceLoggingPanel()  {

    setLayout(new BorderLayout());

    // Table model
    dm = new DefaultTableModel() {

      public Class getColumnClass(int columnIndex) {
        return String.class;
      }

      public boolean isCellEditable(int row, int column) {
          return (column==1) && (!JiveUtils.readOnly);
      }

      public void setValueAt(Object aValue, int row, int column) {
        if(!aValue.equals(getValueAt(row,column))) {
          super.setValueAt(aValue,row,column);
          int nb = source.length;
          int k = 0;

          // Confirmation dialog
          if (source.length > 1) {

            Vector propChange = new Vector();
            switch(row) {
              case 0:
                propChange.add("logging_level");
                break;
              case 1:
                propChange.add("cur_logging_level");
                break;
              case 2:
                propChange.add("logging_target");
                break;
              case 3:
                propChange.add("cur_logging_target");
                break;
              case 4:
                propChange.add("logging_rft");
                break;
            }
            propChange.add((String)aValue);

            if (!MultiChangeConfirmDlg.confirmChange(propChange, source.length)) {
              refreshValue();
              return;
            }

          }

          switch(row) {
            case 0:
              if(nb>1) ProgressFrame.displayProgress("Updating logging config");
              for(int i=0;i1) ProgressFrame.displayProgress("Updating logging config");
              for(int i=0;i1) ProgressFrame.displayProgress("Updating logging config");
              for(int i=0;i1) ProgressFrame.displayProgress("Updating logging config");
              for(int i=0;i1) ProgressFrame.displayProgress("Updating logging config");
              for(int i=0;i1 ) {
            String message = "You are going to reset logging level for " + source.length + " devices.\nDo you want to proceed ?";
            int result = JOptionPane.showConfirmDialog(this,message,"Confirmation",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
            if( result==JOptionPane.NO_OPTION )
              return;
          }
          if(nb>1) ProgressFrame.displayProgress("Reseting logging config");
          for(int i=0;i1 ) {
            String message = "You are going to reset logging target for " + source.length + " devices.\nDo you want to proceed ?";
            int result = JOptionPane.showConfirmDialog(this,message,"Confirmation",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
            if( result==JOptionPane.NO_OPTION )
              return;
          }
          if(nb>1) ProgressFrame.displayProgress("Reseting logging config");
          for(int i=0;i1 ) {
            String message = "You are going to reset logging rft for " + source.length + " devices.\nDo you want to proceed ?";
            int result = JOptionPane.showConfirmDialog(this,message,"Confirmation",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
            if( result==JOptionPane.NO_OPTION )
              return;
          }
          if(nb>1) ProgressFrame.displayProgress("Reseting logging config");
          for(int i=0;i=h && y<=h+theTable.getRowHeight(i));
      if(!found) {
        h+=theTable.getRowHeight(i);
        i++;
      }
    }

    if(found) {
      return i;
    } else {
      return -1;
    }

  }


  void setSource(TaskLoggingNode[] src) {
    this.source = src;
    // Check that all source belong to the same class

    refreshValue();
  }

  private void refreshValue() {

    if (source != null) {

      // Change event
      String colName[] = {"Property name", "Value"};
      Object[][] loggingInfo = new Object[5][2];
      loggingInfo[0][0] = "Logging level";
      loggingInfo[0][1] = source[0].getLoggingLevel();
      loggingInfo[1][0] = "Current logging level";
      loggingInfo[1][1] = source[0].getCurrentLoggingLevel();
      loggingInfo[2][0] = "Logging target";
      loggingInfo[2][1] = source[0].getLoggingTarget();
      loggingInfo[3][0] = "Current logging target";
      loggingInfo[3][1] = source[0].getCurrentLoggingTarget();
      loggingInfo[4][0] = "Logging RFT";
      loggingInfo[4][1] = source[0].getLoggingRft();
      dm.setDataVector(loggingInfo, colName);
      theTable.getColumnModel().getColumn(0).setPreferredWidth(200);

      String title = source[0].getTitle();
      if(source.length==1) {
        title += " [" + source[0].getName() + "]";
      } else {
        title += " [" + source.length + " devices selected]";
      }
      Border b = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),title);
      textView.setBorder(b);

    }

  }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy