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.*; 33 import org.opensolaris.os.vp.panel.common.model.*; 34 import org.opensolaris.os.vp.panel.swing.control.PanelFrameControl; 35 import org.opensolaris.os.vp.panel.swing.model.AbstractSwingPanelDescriptor; 36 import org.opensolaris.os.vp.panels.example.time2.common.*; 37 import org.opensolaris.os.vp.util.misc.Finder; 38 39 public class TimePanelDescriptor 40 extends AbstractSwingPanelDescriptor<ManagedObject> 41 implements ConnectionListener { 42 43 // 44 // Instance data 45 // 46 47 private DefaultControl control; 48 private TimeMXBean bean; 49 50 // 51 // Constructors 52 // 53 54 /** 55 * Constructs a {@code TimePanelDescriptor}. 56 * 57 * @param id 58 * a unique identifier for this Panel, taken from the panel 59 * registration 60 * 61 * @param context 62 * a handle to interact with the Visual Panels client 63 */ 64 public TimePanelDescriptor(String id, ClientContext context) { 65 66 super(id, context); 67 68 control = new PanelFrameControl<TimePanelDescriptor>(this); 69 control.addChildren(new TimeControl(this)); 70 71 setBean(context.getConnectionInfo()); 72 context.addConnectionListener(this); 73 } 74 75 // 76 // ConnectionListener methods 77 // 78 79 @Override 80 public void connectionChanged(ConnectionEvent event) { 81 setBean(event.getConnectionInfo()); 82 } 83 84 // 85 // ManagedObject methods 86 // 87 88 @Override 89 public String getName() { 90 return Finder.getString("panel.time.name"); 91 } 92 93 // 94 // PanelDescriptor methods 95 // 96 97 @Override 98 public Control getControl() { 99 return control; 100 } 101 102 // 103 // TimePanelDescriptor methods 104 // 105 106 public TimeMXBean getTimeBean() { 107 return bean; 108 } 109 110 // 111 // Private methods 112 // 113 114 private void setBean(ConnectionInfo info) { 115 try { 116 bean = JMX.newMXBeanProxy( 117 info.getConnector().getMBeanServerConnection(), 118 TimeUtil.OBJECT_NAME, TimeMXBean.class); 119 } catch (IOException e) { 120 bean = null; 121 } 122 } 123 } 124