1 /*
   2  * $Id$
   3  *
   4  * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6  *
   7  * This code is free software; you can redistribute it and/or modify it
   8  * under the terms of the GNU General Public License version 2 only, as
   9  * published by the Free Software Foundation.  Oracle designates this
  10  * particular file as subject to the "Classpath" exception as provided
  11  * by Oracle in the LICENSE file that accompanied this code.
  12  *
  13  * This code is distributed in the hope that it will be useful, but WITHOUT
  14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16  * version 2 for more details (a copy is included in the LICENSE file that
  17  * accompanied this code).
  18  *
  19  * You should have received a copy of the GNU General Public License version
  20  * 2 along with this work; if not, write to the Free Software Foundation,
  21  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  22  *
  23  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  24  * or visit www.oracle.com if you need additional information or have any
  25  * questions.
  26  */
  27 package com.sun.javatest.exec;
  28 
  29 import java.awt.Dimension;
  30 import java.awt.GridBagConstraints;
  31 import java.awt.GridBagLayout;
  32 import java.awt.event.ComponentListener;
  33 import java.awt.event.ComponentEvent;
  34 
  35 import javax.swing.BorderFactory;
  36 import javax.swing.DefaultListModel;
  37 import javax.swing.JList;
  38 import javax.swing.JPanel;
  39 import javax.swing.JScrollPane;
  40 
  41 import com.sun.javatest.tool.UIFactory;
  42 import com.sun.javatest.tool.jthelp.ContextHelpManager;
  43 
  44 import com.sun.javatest.util.Debug;
  45 
  46 /**
  47  * This panel shows information when multiple nodes are selected in the tree.
  48  */
  49 class MultiSelectPanel
  50     extends JPanel
  51     //implements FilterSelectionHandler.Observer
  52 {
  53     MultiSelectPanel(UIFactory uif, TreePanelModel model, TestTreeModel ttm) {
  54         this.uif = uif;
  55         this.tpm = model;
  56         this.ttm = ttm;
  57 
  58         initGUI();
  59     }
  60 
  61     // XXX use TreePath[] as parameter?
  62     void setNodes(Object[] nodes) {
  63         this.nodes =nodes;
  64         updatePanel(nodes);
  65     }
  66 
  67     /**
  68      * This method should only be called to indicate that a change has occurred
  69      * which replaces the active TRT.  Changes to the parameters (filters,
  70      * initial URLs, etc... should propagate thru the FilterConfig system.
  71      *
  72      * @param p A validated set of parameters.
  73      * @see com.sun.javatest.exec.FilterConfig
  74     void setParameters(Parameters p) {
  75         this.params = p;
  76 
  77         TestResultTable newTrt = null;
  78         if (p.getWorkDirectory() != null) {
  79             newTrt = p.getWorkDirectory().getTestResultTable();
  80         }
  81     }
  82 
  83     void dispose() {
  84         // stop counter thread
  85         summPanel.dispose();
  86     }
  87      */
  88 
  89     protected void initGUI() {
  90         setName("multiselect");
  91         setLayout(new GridBagLayout());
  92         setMinimumSize(new Dimension(150, 100));
  93 
  94         listModel = new DefaultListModel<>();
  95         nodeList = uif.createList("ms.nlist", listModel);
  96         GridBagConstraints gbc = new GridBagConstraints();
  97         gbc.weightx= 1.0;
  98         gbc.gridy = 0;
  99         gbc.gridx = 0;
 100         gbc.anchor = GridBagConstraints.CENTER;
 101 
 102         // add inline help
 103         gbc.fill = GridBagConstraints.HORIZONTAL;
 104         add(uif.createMessageArea("ms.help"), gbc);
 105 
 106         gbc.weighty = 9.0;
 107         gbc.gridy = 1;
 108         gbc.fill = GridBagConstraints.BOTH;
 109         nodeList.setBorder(BorderFactory.createCompoundBorder(
 110             BorderFactory.createEmptyBorder(10, 5, 5, 5),
 111             uif.createTitledBorder("ms.nlist"))
 112         );
 113 
 114         nodeList.setCellRenderer(RenderingUtilities.createTRTNodeRenderer());
 115 
 116         add(new JScrollPane(nodeList), gbc);
 117 
 118         // --- anonymous class ---
 119         ComponentListener cl = new ComponentListener() {
 120             public void componentResized(ComponentEvent e) {
 121             }
 122 
 123             public void componentMoved(ComponentEvent e) {
 124             }
 125 
 126             public void componentShown(ComponentEvent e) {
 127                 if (needToUpdateGUIWhenShown) {
 128                     updateGUI();
 129                     needToUpdateGUIWhenShown = false;
 130                 }
 131             }
 132             public void componentHidden(ComponentEvent e) {
 133             }
 134         };
 135         addComponentListener(cl);
 136         ContextHelpManager.setHelpIDString(this, "browse.multiselectionTab.csh");
 137     }
 138 
 139     protected void updatePanel(Object[] nodes) {
 140         if (isVisible())
 141             updateGUI();
 142         else
 143             needToUpdateGUIWhenShown = true;
 144     }
 145 
 146     Object[] getNodes() {
 147         return nodes;
 148     }
 149 
 150     /**
 151      * Call when the target node or tree data have changed.  This is called
 152      * internally to force updates when filters have changed.
 153      */
 154     protected void updateGUI() {
 155         listModel.removeAllElements();
 156 
 157         if (nodes == null)
 158             return;
 159 
 160         for (int i = 0; i < nodes.length; i++)
 161             listModel.addElement(nodes[i]);
 162     }
 163 
 164     protected void finalize() throws Throwable {
 165         super.finalize();
 166     }
 167 
 168     private TestTreeModel ttm;
 169     private TreePanelModel tpm;
 170     private JList<?> nodeList;
 171     private DefaultListModel<Object> listModel;
 172     private Object[] nodes;
 173 
 174     private UIFactory uif;
 175 
 176     private volatile boolean needToUpdateGUIWhenShown;
 177 
 178     private static boolean debug = Debug.getBoolean(MultiSelectPanel.class);
 179 }