1 - /* 1 - * ALMA - Atacama Large Millimiter Array 1 - * (c) European Southern Observatory, 2002 1 - * Copyright by ESO (in the framework of the ALMA collaboration) 1 - * and Cosylab 2002, All rights reserved 1 - * 1 - * This library is free software; you can redistribute it and/or 1 - * modify it under the terms of the GNU Lesser General Public 1 - * License as published by the Free Software Foundation; either 1 - * version 2.1 of the License, or (at your option) any later version. 1 - * 1 - * This library is distributed in the hope that it will be useful, 1 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 1 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1 - * Lesser General Public License for more details. 1 - * 1 - * You should have received a copy of the GNU Lesser General Public 1 - * License along with this library; if not, write to the Free Software 1 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 1 - * MA 02111-1307 USA 1 - */ 1 - package com.cosylab.logging; 1 - 1 - import java.awt.Component; 1 - import java.awt.Dimension; 1 - import javax.swing.event.MenuEvent; 1 - import java.awt.event.ComponentEvent; 1 - import java.awt.event.ComponentListener; 1 - import java.util.AbstractList; 1 - import java.util.List; 1 - import java.util.Vector; 1 - import java.util.Date; 1 - import java.util.Iterator; 1 - import java.util.regex.PatternSyntaxException; 1 - import java.io.File; 1 - import java.io.IOException; 1 - import java.io.FileOutputStream; 1 - import java.io.FileInputStream; 1 - import java.io.DataOutputStream; 1 - 1 - import javax.swing.JFrame; 1 - import javax.swing.JLabel; 1 - import javax.swing.JMenu; 1 - import javax.swing.JMenuBar; 1 - import javax.swing.JMenuItem; 1 - import javax.swing.JPanel; 1 - import javax.swing.JScrollPane; 1 - import javax.swing.JSeparator; 1 - import javax.swing.JSplitPane; 1 - import javax.swing.JTable; 1 - import javax.swing.JOptionPane; 1 - import javax.swing.JToggleButton; 1 - import javax.swing.JFileChooser; 1 - import javax.swing.UIManager; 1 - import javax.swing.table.AbstractTableModel; 1 - import javax.swing.table.TableModel; 1 - import javax.swing.filechooser.FileFilter; 1 - 1 - import com.cosylab.logging.engine.LogEntry; 1 - import com.cosylab.logging.engine.Filter; 1 - import com.cosylab.logging.engine.InvalidFilterConstraintException; 1 - 1 - import org.w3c.dom.NamedNodeMap; 1 - import org.w3c.dom.Node; 1 - import org.w3c.dom.NodeList; 1 - 1 - import org.jdom.Document; 1 - import org.jdom.Element; 1 - import org.jdom.input.DOMBuilder; 1 - import org.jdom.adapters.JAXPDOMAdapter; 1 - import org.jdom.JDOMException; 1 - 1 - import alma.acs.gui.widgets.ExtendedTextArea; 1 - 1 - /** 1 - * This type was generated by a SmartGuide. 1 - * 1 - * Defines a JFrame Application LoggingClient for displaying event logs 1 - * received through the CORBA protocol for the purpose of monitoring and 1 - * reviewing of the logs. It contains of a JScrollPane ivjLogTable for the 1 - * logs and a LogEntryTable ivjScrollPaneTable for displaying the status 1 - * as well as a JPanel ivjJFrameContentPane. Multiple listeners handle 1 - * user's input. 1 - * Based on the current code and our understanding of it one could describe 1 - * the information flow as follows. User's input triggers events which are 1 - * caught by the listeners attached to each one of the available GUI object 1 - * representations defined in the LoggingClient class. 1 - * Independent of that there are messages available at the logging system 1 - * generated by the other services running in the framework. These messages are 1 - * parsed by the ACSStructuredPushConsumer class using the SAX parser and are 1 - * then passed on using the LogTableDataModel's appendLog method for outputing 1 - * the logs to the log table. 1 - * In particular, we are interested in the saving and loading of files to be 1 - * implemented by the LoggingClient. While saveFile and loadFromFile are defined 1 - * in LogTabledataModel, the LogImportTask file makes use of the 1 - * the LogTabledataModel's appendLog method as well. The use of the DocumentBuilderFactory 1 - * in the LogImportTask defines a way for transforming a DOM tree into XML. 1 - * 1 - * An important issue is the format of the Log Entry Message produced by the Logging 1 - * Service. Certain characters ('<', '>', '&', ''', '"') need to be escaped 1 - * because they delineate markup data from character data and cause the following exception 1 - * in ACSLogParser class: 1 - * org.xml.sax.SAXParseException: The content beginning with '<' 1 - * is not legal markup. 1 - * One solution is replacing the character with the appropriate html substitute <. 1 - * Another solution is keeping it in a CDATA section: <[!CDATA[the log entry message]]>. 1 - */ 1 - public class LoggingClient extends JFrame { 1 - private JMenuItem ivjNewMenuItem = null; // Connect 1 - private JMenuItem ivjLoadMenuItem = null; // Load 1 - private JMenuItem ivjSaveFileMenuItem = null; // Save File As 1 - private JMenuItem ivjClearAllMenuItem = null; // Clear All 1 - private JMenuItem ivjExitMenuItem = null; // Exit 1 - 1 - private JMenuItem ivjFiltersMenuItem = null; // Filters... 1 - 1 - /** 1 - * The menu item to lad filters 1 - */ 1 - private JMenuItem loadFiltersMenuItem = null; /** The menu item to save the filters */ private JMenuItem saveFiltersMenuItem = null; 1 - 1 - /** 1 - * The menu item to save the filters with a new name */ 1 - private JMenuItem saveAsFiltersMenuItem = null; 1 - 1 - /** 1 - * The menu item to edit the filters 1 - */ 1 - private JMenuItem editFiltersMenuItem = null; 1 - 1 - /** 1 - * The name of the last save/load filter file 1 - * (to implement the save as option) 1 - */ 1 - private String filterFileName = null; 1 - 1 - private JMenuItem ivjFieldsMenuItem = null; // Fields... 1 - private JMenu ivjGroupMenu = null; // Group By 1 - private JMenu ivjSortMenu = null; // Sort By 1 - 1 - private JSeparator ivjJSeparator1 = null; 1 - private JSeparator ivjJSeparator2 = null; 1 - 1 - private JMenu ivjFileMenu = null; // File 1 - private JMenu ivjViewMenu = null; // View 1 - 1 - private JLabel ivjFilterStatus = null; // Not filtered 1 - private JLabel ivjInfoStatus = null; // Additional info 1 - 1 - private JToggleButton ivjJToggleButton1 = null; // Suspend 1 - 1 - private JMenuBar ivjLoggingClientJMenuBar = null; 1 - 1 - private JPanel ivjJPanel1 = null; 1 - private JPanel ivjJPanel2 = null; 1 - private JPanel ivjJPanel3 = null; 1 - private JPanel ivjJPanel4 = null; 1 - 1 - private JScrollPane ivjJScrollPane1 = null; 1 - private JScrollPane ivjJScrollPane2 = null; 1 - 1 - private JSplitPane ivjJSplitPane1 = null; 1 - private JSplitPane ivjJSplitPane2 = null; 1 - 1 - private JScrollPane ivjLogTable = null; 1 - private LogEntryTable ivjScrollPaneTable = null; 1 - 1 - private ExtendedTextArea ivjStatusArea = null; 1 - 1 - private JPanel ivjJFrameContentPane = null; 1 - 1 - IvjEventHandler ivjEventHandler = new IvjEventHandler(); 1 - 1 - private boolean ivjConnPtoSort = false; 1 - private boolean ivjConnPtoGroup = false; 1 - private boolean ivjConnPtoLCMod = false; 1 - 1 - private com.cosylab.logging.client.DomTree ivjDomTree = null; 1 - 1 - private LCEngine ivjLCEngine = null; 1 - private LogTableDataModel ivjLCModel1 = null; 1 - private LCRemoteResponseCallbackBean ivjLCRemoteResponseCallback = null; 1 - 1 - class IvjEventHandler implements java.awt.event.ActionListener, java.awt.event.ItemListener,java.awt.event.WindowListener,java.beans.PropertyChangeListener, 1 - javax.swing.event.MenuListener 1 - {public void actionPerformed(java.awt.event.ActionEvent e) 1 - {if (e.getSource() == LoggingClient.this.getNewMenuItem()) connNew(e); 1 - 1 - if (e.getSource() == LoggingClient.this.getLoadMenuItem()) 1 - connLoad(e); 1 - if (e.getSource() == LoggingClient.this.getLoadMenuItem()) 1 - connLoad2(e); 1 - if (e.getSource() == LoggingClient.this.getSaveFileMenuItem()) 1 - connSaveFile(e); 1 - 1 - if (e.getSource() == LoggingClient.this.getSaveFileMenuItem()) 1 - connSaveFile2(e); 1 - 1 - if (e.getSource() == LoggingClient.this.getClearAllMenuItem()) 1 - connClearAll(e); 1 - 1 - if (e.getSource() == LoggingClient.this.getClearAllMenuItem()) 1 - connClearAll2(e); 1 - 1 - if (e.getSource() == LoggingClient.this.getExitMenuItem()) 1 - connExit(e); if (e.getSource() == LoggingClient.this.getFieldsMenuItem()) 1 - connFields(e); 1 - 1 - if (e.getSource() == LoggingClient.this.editFiltersMenuItem) 1 - connFilters(e); 1 - 1 - if (e.getSource() == LoggingClient.this.loadFiltersMenuItem) 1 - loadFilters(); 1 - 1 - if (e.getSource() == LoggingClient.this.saveFiltersMenuItem) { 1 - if (filterFileName!=null) 1 - if (filterFileName.length()>0) 1 - saveFilters(filterFileName); 1 - } 1 - 1 - if (e.getSource() == LoggingClient.this.saveAsFiltersMenuItem) {saveAsFilters(); 1 - }}; 1 - 1 - public void itemStateChanged(java.awt.event.ItemEvent e) 1 - { 1 - 1 - if (e.getSource() == LoggingClient.this.getJToggleButton1()) 1 - connSuspend(); 1 - }; 1 - 1 - public void propertyChange(java.beans.PropertyChangeEvent evt) { if (evt.getSource() == LoggingClient.this.getScrollPaneTable() 1 - && (evt.getPropertyName().equals("SortMenu"))) 1 - connPtoP4SetTarget(); if (evt.getSource() == LoggingClient.this.getScrollPaneTable() 1 - && (evt.getPropertyName().equals("GroupMenu"))) 1 - connPtoP5SetTarget(); 1 - if (evt.getSource() == LoggingClient.this.getScrollPaneTable() 1 - && (evt.getPropertyName().equals("filterString"))) 1 - connFilter(evt); 1 - 1 - if (evt.getSource() == LoggingClient.this.getScrollPaneTable() 1 - && (evt.getPropertyName().equals("extraInfo"))) 1 - connDomInfo(evt); 1 - 1 - if (evt.getSource() == LoggingClient.this.getScrollPaneTable() 1 - && (evt.getPropertyName().equals("LCModel"))) 1 - connLCMod(); 1 - }; 1 - public void windowActivated(java.awt.event.WindowEvent e) 1 - { }; 1 - 1 - public void windowClosed(java.awt.event.WindowEvent e) 1 - { 1 - } 1 - ; 1 - 1 - public void windowClosing(java.awt.event.WindowEvent e) 1 - { 1 - 1 - if (e.getSource() == LoggingClient.this) 1 - connLCEngDisconnect(e); 1 - }; 1 - 1 - public void windowDeactivated(java.awt.event.WindowEvent e) 1 - { 1 - }; 1 - 1 - public void windowDeiconified(java.awt.event.WindowEvent e) 1 - { 1 - }; 1 - 1 - public void windowIconified(java.awt.event.WindowEvent e) 1 - { 1 - }; 1 - 1 - public void windowOpened(java.awt.event.WindowEvent e) 1 - { 1 - }; 1 - 1 - 1 - public void menuCanceled(MenuEvent menuE) { 1 - }; 1 - 1 - public void menuSelected(MenuEvent menuE) { 1 - // Check if Save and Save As menu items are selectable 1 - saveAsFiltersMenuItem.setEnabled(true); 1 - if (ivjLCModel1.getFilters().length==0) { 1 - saveFiltersMenuItem.setEnabled(false); saveAsFiltersMenuItem.setEnabled(false);} else if(filterFileName==null) { 1 - saveFiltersMenuItem.setEnabled(false); 1 - } else if (filterFileName.length()==0) { saveFiltersMenuItem.setEnabled(false); } else { saveFiltersMenuItem.setEnabled(true); 1 - } 1 - } public void menuDeselected(MenuEvent menuE) { 1 - } 1 - }; 1 - 1 - /** 1 - * The filter to load save filters as xml files 1 - * The filter checks for the extension .xml in the name 1 - * 1 - * @author acaproni 1 - */ 1 - private class xmlFileFilter extends FileFilter { 1 - public boolean accept(File f) { 1 - // Check if the name has the extension .xml at the end and is readable 1 - boolean pass = f.isFile() && f.getName().toUpperCase().endsWith(".XML") && f.canRead(); 1 - // Check if the file is a directory 1 - pass = pass || f.isDirectory(); 1 - // Check if f is a hidden file 1 - pass = pass && !f.isHidden(); 1 - return pass; 1 - } 1 - 1 - public String getDescription() { 1 - return "xml file"; 1 - } 1 - }/** * LoggingClient constructor comment. 1 - */ 1 - public LoggingClient() 1 - { 1 - 1 - 1 - 1 - 1 - super(); 1 - initialize(); 1 - } 1 - 1 - /** 1 - * LoggingClient constructor comment. 1 - * @param title java.lang.String 1 - */ 1 - public LoggingClient(String title) 1 - { 1 - super(title); 1 - } 1 - /** 1 - * Connects to the remote system 1 - * as soon as the item "New" is clicked. 1 - * @param arg1 java.awt.event.ActionEvent 1 - */ 1 - 1 - private void connNew(java.awt.event.ActionEvent arg1) 1 - { 1 - try 1 - { 1 - 1 - getLCEngine().connect(); 1 - 1 - } 1 - catch (java.lang.Throwable ivjExc) 1 - { 1 - 1 - handleException(ivjExc); 1 - } 1 - } 1 - /** 1 - * Returns the SaveFileMenuItem property value. 1 - * @return javax.swing.JMenuItem 1 - */ 1 - private javax.swing.JMenuItem getSaveFileMenuItem() 1 - { 1 - if (ivjSaveFileMenuItem == null) 1 - { 1 - try 1 - { 1 - ivjSaveFileMenuItem = new javax.swing.JMenuItem(); 1 - ivjSaveFileMenuItem.setName("SaveFileMenuItem"); 1 - ivjSaveFileMenuItem.setText("Save File As"); 1 - }catch (java.lang.Throwable ivjExc) 1 - { 1 - handleException(ivjExc);} 1 - } 1 - return ivjSaveFileMenuItem; 1 - } 1 - 1 - /** 1 - * Returns the LoadMenuItem property value. 1 - * @return javax.swing.JMenuItem 1 - */ 1 - 1 - private javax.swing.JMenuItem getLoadMenuItem() 1 - { 1 - if (ivjLoadMenuItem == null) 1 - { 1 - try 1 - { 1 - ivjLoadMenuItem = new javax.swing.JMenuItem(); 1 - ivjLoadMenuItem.setName("ivjLoadMenuItem"); 1 - ivjLoadMenuItem.setText("Load"); 1 - } 1 - catch (java.lang.Throwable ivjExc) 1 - { 1 - handleException(ivjExc); 1 - } 1 - } 1 - return ivjLoadMenuItem; 1 - } 1 - 1 - private void saveFilters(String fileName) { // Check if the name terminate with xml 1 - if (!fileName.toUpperCase().endsWith(".XML")) {fileName=fileName+".xml";} File f = new File(fileName); try {saveFilters(f);} catch (IOException e) {System.err.println("Error opening "+fileName);}} 1 - 1 - } 1 -