components/visual-panels/smf/src/java/vpanels/app/smf/com/oracle/solaris/vp/panels/smf/client/swing/InstanceTabbedControl.java
changeset 3553 f1d133b09a8c
parent 3552 077ebe3d0d24
child 3554 ef58713bafc4
equal deleted inserted replaced
3552:077ebe3d0d24 3553:f1d133b09a8c
     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 (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.panels.smf.client.swing;
       
    27 
       
    28 import java.util.Map;
       
    29 import com.oracle.solaris.scf.common.FMRI;
       
    30 import com.oracle.solaris.vp.panel.common.control.*;
       
    31 import com.oracle.solaris.vp.panel.common.smf.*;
       
    32 import com.oracle.solaris.vp.panel.swing.control.TabbedControl;
       
    33 import com.oracle.solaris.vp.panel.swing.smf.*;
       
    34 
       
    35 public class InstanceTabbedControl extends TabbedControl<SmfPanelDescriptor>
       
    36     implements HasSmfManagedObject<InstanceManagedObject>, HasServiceTracker {
       
    37 
       
    38     //
       
    39     // Static data
       
    40     //
       
    41 
       
    42     public static final String ID = "instance";
       
    43     public static final String PARAM_INSTANCE = "instance";
       
    44 
       
    45     //
       
    46     // Instance data
       
    47     //
       
    48 
       
    49     private MainControl parent;
       
    50     private InstanceManagedObject instance;
       
    51 
       
    52     //
       
    53     // Constructors
       
    54     //
       
    55 
       
    56     public InstanceTabbedControl(SmfPanelDescriptor descriptor,
       
    57 	MainControl parent) {
       
    58 
       
    59 	super(ID, null, descriptor);
       
    60 	this.parent = parent;
       
    61     }
       
    62 
       
    63     //
       
    64     // HasServiceTracker methods
       
    65     //
       
    66 
       
    67     @Override
       
    68     public ServiceTracker getServiceTracker() {
       
    69 	return getSmfManagedObject().getServiceTracker();
       
    70     }
       
    71 
       
    72     //
       
    73     // HasSmfManagedObject methods
       
    74     //
       
    75 
       
    76     @Override
       
    77     public InstanceManagedObject getSmfManagedObject() {
       
    78 	return instance;
       
    79     }
       
    80 
       
    81     //
       
    82     // Control methods
       
    83     //
       
    84 
       
    85     @Override
       
    86     public boolean isBrowsable() {
       
    87 	// This Control requires init parameters
       
    88 	return false;
       
    89     }
       
    90 
       
    91     @Override
       
    92     public void start(Navigator navigator, Map<String, String> parameters)
       
    93 	throws NavigationAbortedException, InvalidParameterException,
       
    94 	NavigationFailedException {
       
    95 
       
    96 	String param = getParameter(parameters, PARAM_INSTANCE);
       
    97 	FMRI fmri = parent.getSmfManagedObject().getSMFFmri().toInstanceFMRI(
       
    98 	    param);
       
    99 
       
   100 	SmfManagedObject smo = getPanelDescriptor().getRepo().getSMO(
       
   101 	    fmri.toString());
       
   102 	if (smo == null || !(smo instanceof InstanceManagedObject)) {
       
   103 	    throw new InvalidParameterException(getId(), PARAM_INSTANCE,
       
   104 		param);
       
   105 	}
       
   106 
       
   107 	setInstance((InstanceManagedObject)smo);
       
   108 
       
   109 	super.start(navigator, parameters);
       
   110     }
       
   111 
       
   112     @Override
       
   113     public void stop(boolean isCancel) throws NavigationAbortedException {
       
   114 	super.stop(isCancel);
       
   115 
       
   116 	// Remove reference so it can be garbage collected if deleted
       
   117 	setInstance(null);
       
   118     }
       
   119 
       
   120     //
       
   121     // DefaultControl methods
       
   122     //
       
   123 
       
   124     @Override
       
   125     protected void ensureChildrenCreated() {
       
   126 	if (children.size() == 0) {
       
   127 	    SmfPanelDescriptor descriptor = getPanelDescriptor();
       
   128 
       
   129 	    addChildren(new GeneralControl(descriptor, this));
       
   130 	    addChildren(new SmfPropertiesControl<SmfPanelDescriptor>(
       
   131 		descriptor, this));
       
   132 	    addChildren(new SmfDependenciesControl<SmfPanelDescriptor,
       
   133 		InstanceManagedObject>(
       
   134 		descriptor, this, descriptor.getRepo()));
       
   135 	    addChildren(new SmfLogControl<SmfPanelDescriptor>(
       
   136 		descriptor, this));
       
   137 	}
       
   138     }
       
   139 
       
   140     //
       
   141     // TabbedControl methods
       
   142     //
       
   143 
       
   144     @Override
       
   145     protected boolean isInsettable(Control child) {
       
   146 	if (child instanceof SmfDependenciesControl ||
       
   147 	    child instanceof SmfPropertiesControl ||
       
   148 	    child instanceof SmfLogControl) {
       
   149 	    return false;
       
   150 	}
       
   151 	return true;
       
   152     }
       
   153 
       
   154     //
       
   155     // Private methods
       
   156     //
       
   157 
       
   158     private void setInstance(InstanceManagedObject instance) {
       
   159 	this.instance = instance;
       
   160 	setName(instance == null ? null : instance.getSMFFmri().getInstance());
       
   161     }
       
   162 }