Home | History | Annotate | Download | only in swing
      1  239  stephen /*
      2  239  stephen  * CDDL HEADER START
      3  239  stephen  *
      4  239  stephen  * The contents of this file are subject to the terms of the
      5  239  stephen  * Common Development and Distribution License (the "License").
      6  239  stephen  * You may not use this file except in compliance with the License.
      7  239  stephen  *
      8  239  stephen  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  239  stephen  * or http://www.opensolaris.org/os/licensing.
     10  239  stephen  * See the License for the specific language governing permissions
     11  239  stephen  * and limitations under the License.
     12  239  stephen  *
     13  239  stephen  * When distributing Covered Code, include this CDDL HEADER in each
     14  239  stephen  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  239  stephen  * If applicable, add the following below this CDDL HEADER, with the
     16  239  stephen  * fields enclosed by brackets "[]" replaced with your own identifying
     17  239  stephen  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  239  stephen  *
     19  239  stephen  * CDDL HEADER END
     20  239  stephen  */
     21  239  stephen 
     22  239  stephen /*
     23  239  stephen  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     24  239  stephen  * Use is subject to license terms.
     25  239  stephen  */
     26  239  stephen 
     27  239  stephen package org.opensolaris.os.vp.panels.example.time2.client.swing;
     28  239  stephen 
     29  239  stephen import java.io.IOException;
     30  239  stephen import javax.management.JMX;
     31  239  stephen import org.opensolaris.os.vp.panel.common.*;
     32  239  stephen import org.opensolaris.os.vp.panel.common.control.Control;
     33  250  stephen import org.opensolaris.os.vp.panel.common.model.ManagedObject;
     34  239  stephen import org.opensolaris.os.vp.panel.swing.model.AbstractSwingPanelDescriptor;
     35  239  stephen import org.opensolaris.os.vp.panels.example.time2.common.*;
     36  239  stephen import org.opensolaris.os.vp.util.misc.Finder;
     37  239  stephen 
     38  250  stephen public class TimePanelDescriptor
     39  250  stephen     extends AbstractSwingPanelDescriptor<ManagedObject>
     40  239  stephen     implements ConnectionListener {
     41  239  stephen 
     42  239  stephen     //
     43  239  stephen     // Instance data
     44  239  stephen     //
     45  239  stephen 
     46  239  stephen     private Control control;
     47  239  stephen     private TimeMXBean bean;
     48  239  stephen 
     49  239  stephen     //
     50  239  stephen     // Constructors
     51  239  stephen     //
     52  239  stephen 
     53  239  stephen     /**
     54  239  stephen      * Constructs a {@code TimePanelDescriptor}.
     55  239  stephen      *
     56  239  stephen      * @param	    id
     57  239  stephen      *		    a unique identifier for this Panel, taken from the panel
     58  239  stephen      *		    registration
     59  239  stephen      *
     60  239  stephen      * @param	    context
     61  239  stephen      *		    a handle to interact with the Visual Panels client
     62  239  stephen      */
     63  245    David     public TimePanelDescriptor(String id, ClientContext context) {
     64  239  stephen 
     65  245    David 	super(id, context);
     66  239  stephen 	control = new TimeControl(this);
     67  239  stephen 
     68  239  stephen 	setBean(context.getConnectionInfo());
     69  239  stephen 	context.addConnectionListener(this);
     70  239  stephen     }
     71  239  stephen 
     72  239  stephen     //
     73  239  stephen     // ConnectionListener methods
     74  239  stephen     //
     75  239  stephen 
     76  239  stephen     @Override
     77  239  stephen     public void connectionChanged(ConnectionEvent event) {
     78  239  stephen 	setBean(event.getConnectionInfo());
     79  239  stephen     }
     80  239  stephen 
     81  239  stephen     //
     82  239  stephen     // ManagedObject methods
     83  239  stephen     //
     84  239  stephen 
     85  239  stephen     @Override
     86  239  stephen     public String getName() {
     87  239  stephen 	return Finder.getString("panel.time.name");
     88  239  stephen     }
     89  239  stephen 
     90  239  stephen     //
     91  239  stephen     // PanelDescriptor methods
     92  239  stephen     //
     93  239  stephen 
     94  239  stephen     @Override
     95  239  stephen     public Control getControl() {
     96  239  stephen 	return control;
     97  239  stephen     }
     98  239  stephen 
     99  239  stephen     //
    100  239  stephen     // TimePanelDescriptor methods
    101  239  stephen     //
    102  239  stephen 
    103  239  stephen     public TimeMXBean getTimeBean() {
    104  239  stephen 	return bean;
    105  239  stephen     }
    106  239  stephen 
    107  239  stephen     //
    108  239  stephen     // Private methods
    109  239  stephen     //
    110  239  stephen 
    111  239  stephen     private void setBean(ConnectionInfo info) {
    112  239  stephen 	try {
    113  239  stephen 	    bean = JMX.newMXBeanProxy(
    114  239  stephen 		info.getConnector().getMBeanServerConnection(),
    115  239  stephen 		TimeUtil.OBJECT_NAME, TimeMXBean.class);
    116  239  stephen 	} catch (IOException e) {
    117  239  stephen 	    bean = null;
    118  239  stephen 	}
    119  239  stephen     }
    120  239  stephen }
    121