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