Search in sources :

Example 1 with LogLevelSelectorPanel

use of alma.acs.gui.loglevel.leveldlg.LogLevelSelectorPanel in project ACS by ACS-Community.

the class TreeMouseListener method showLoggingConfigTab.

/**
	 * Show the dialog to read and configure the log level
	 * 
	 * @param path The path of the selected node
	 *
	 */
private void showLoggingConfigTab(TreePath path) {
    if (path == null) {
        throw new IllegalArgumentException("Invalid null path");
    }
    DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    DefaultMutableTreeNode targetNode = selNode;
    boolean implementsLogging = implementsLoggingConfigurable(selNode);
    if (!implementsLogging) {
        // yatagai: ad hoc implementation
        targetNode = (DefaultMutableTreeNode) selNode.getParent();
        if (targetNode == null || !implementsLoggingConfigurable(targetNode))
            return;
    }
    // Get a reference to the LoggingConfigurable for the 
    // selected item
    LoggingConfigurableOperations logConf = null;
    if (model.isManagerNode(targetNode)) {
        try {
            logConf = getLogConfFromManager();
        } catch (Throwable t) {
            JOptionPane.showInternalMessageDialog(tree, "Error getting the LoggingConfigurable:\n" + t.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
    } else if (model.isServiceNode(targetNode)) {
        try {
            logConf = getLogConfFromService(targetNode.getUserObject().toString());
        } catch (Throwable t) {
            JOptionPane.showInternalMessageDialog(tree, "Error getting the LoggingConfigurable:\n" + t.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
    } else {
        ContainerInfo cInfo;
        try {
            cInfo = ((TreeContainerInfo) targetNode.getUserObject()).getClientInfo();
        } catch (Throwable t) {
            JOptionPane.showInternalMessageDialog(tree, "Error retrieving ContainerInfo from the node", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        try {
            logConf = getLogConfFromContainer(cInfo);
        } catch (Throwable t) {
            JOptionPane.showInternalMessageDialog(tree, "Error getting the LoggingConfigurable:\n" + t.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }
    if (logConf == null) {
        JOptionPane.showMessageDialog(tree, "LoggingConfigurable is null", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    try {
        tree.getTabPanel().showTab(targetNode.getUserObject().toString());
    } catch (LogPaneNotFoundException e) {
        // The tab with this name does not exist: create and add a new one
        LogLevelSelectorPanel pnl;
        try {
            pnl = new LogLevelSelectorPanel(logConf, targetNode.getUserObject().toString(), logger);
        //} catch (LogLvlSelNotSupportedException ex) {
        } catch (Exception t) {
            JOptionPane.showMessageDialog(tree, //"<HTML>"+targetNode.getUserObject().toString()+" does not support selection of log levels:<BR>"+ex.getMessage(),
            "<HTML>" + targetNode.getUserObject().toString() + " Error selecting log level panel:<BR>" + t.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        try {
            tree.getTabPanel().addLogSelectorTab(pnl);
        } catch (Throwable t) {
            JOptionPane.showMessageDialog(tree, "<HTML>Error creating the panel for " + targetNode.getUserObject().toString() + ":<BR>" + t.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }
    // yatagai : Although the mousePressed action for a LoggingConfigurable 
    // folder node, expanding or collapsing, which is set by the JTree UI is not desirable,
    // I could not find a good way to disable it. 
    //
    // Reaching here, a LoggingConfigTab is displayed.
    // If this is a folder node, the following code cancels expanding or collapsing
    // action.
    TreeNode node = (TreeNode) path.getLastPathComponent();
    if (node.isLeaf())
        return;
    else {
        if (tree.isExpanded(path))
            tree.collapsePath(path);
        else
            tree.expandPath(path);
    }
}
Also used : LoggingConfigurableOperations(alma.Logging.LoggingConfigurableOperations) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) LogPaneNotFoundException(alma.acs.gui.loglevel.LogPaneNotFoundException) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeContainerInfo(alma.acs.gui.loglevel.tree.node.TreeContainerInfo) ContainerInfo(si.ijs.maci.ContainerInfo) TreeContainerInfo(alma.acs.gui.loglevel.tree.node.TreeContainerInfo) LogLevelSelectorPanel(alma.acs.gui.loglevel.leveldlg.LogLevelSelectorPanel) LogPaneNotFoundException(alma.acs.gui.loglevel.LogPaneNotFoundException)

Example 2 with LogLevelSelectorPanel

use of alma.acs.gui.loglevel.leveldlg.LogLevelSelectorPanel in project ACS by ACS-Community.

the class LogLevelPanel method addLogSelectorTab.

/**
	 * Add a new selector tab.
	 * The name of the new tab is set to be the name of the tab
	 * 
	 *@param tab The panel to show in the new tab
	 *@throws InvalidLogPaneException If the name of the panel is empty or null
	 *@throws LogPaneAlreadyExistException If a tab with the given name already exist
	 */
public void addLogSelectorTab(LogLevelSelectorPanel logTab) throws InvalidLogPaneException, LogPaneAlreadyExistException {
    if (logTab == null) {
        throw new IllegalArgumentException("Invalid null component");
    }
    if (logTab.getName() == null || logTab.getName().isEmpty()) {
        throw new InvalidLogPaneException("Trying to add a panel with no name");
    }
    // Check if a tab with this name already exist
    String name = logTab.getName();
    for (int t = 0; t < getTabCount(); t++) {
        if (getComponentAt(t).getName().equals(name)) {
            throw new LogPaneAlreadyExistException("A log with the name " + name + " is already present");
        }
    }
    // Add the tab
    class TabInserter extends Thread {

        LogLevelSelectorPanel tabContent;

        LogLevelPanel thePane;

        public TabInserter(LogLevelSelectorPanel t, LogLevelPanel pane) {
            tabContent = t;
            thePane = pane;
        }

        public void run() {
            add(tabContent, new JLabel(tabContent.getName()));
            setTabComponentAt(indexOfComponent(tabContent), new ButtonTabComponent(thePane, tabContent));
        }
    }
    SwingUtilities.invokeLater(new TabInserter(logTab, this));
}
Also used : ButtonTabComponent(alma.acs.gui.loglevel.leveldlg.ButtonTabComponent) JLabel(javax.swing.JLabel) LogLevelSelectorPanel(alma.acs.gui.loglevel.leveldlg.LogLevelSelectorPanel)

Aggregations

LogLevelSelectorPanel (alma.acs.gui.loglevel.leveldlg.LogLevelSelectorPanel)2 LoggingConfigurableOperations (alma.Logging.LoggingConfigurableOperations)1 LogPaneNotFoundException (alma.acs.gui.loglevel.LogPaneNotFoundException)1 ButtonTabComponent (alma.acs.gui.loglevel.leveldlg.ButtonTabComponent)1 TreeContainerInfo (alma.acs.gui.loglevel.tree.node.TreeContainerInfo)1 JLabel (javax.swing.JLabel)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreeNode (javax.swing.tree.TreeNode)1 ContainerInfo (si.ijs.maci.ContainerInfo)1