usr/src/java/vpanels/panels/sharemgr/org/opensolaris/os/vp/panels/sharemgr/client/swing/ProtocolControl.java
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
*/
package org.opensolaris.os.vp.panels.sharemgr.client.swing;
import java.awt.event.*;
import java.net.URL;
import java.util.*;
import javax.swing.JButton;
import org.opensolaris.os.vp.panel.common.control.*;
import org.opensolaris.os.vp.panel.swing.control.*;
import org.opensolaris.os.vp.panels.sharemgr.client.common.
SharemgrPanelDescriptor;
import org.opensolaris.os.vp.panels.sharemgr.common.*;
import org.opensolaris.os.vp.util.misc.property.MutableProperty;
public class ProtocolControl
extends SettingsControl<SharemgrPanelDescriptor, ProtocolPanel> {
//
// Instance data
//
private CommonTabbedControl<?> parent;
private ProtocolPropertySet pProps;
//
// Constructors
//
public ProtocolControl(CommonTabbedControl<?> parent,
ProtocolPropertySet pProps) {
super(pProps.getProtocol().getName(),
SharemgrUtil.getFriendlyProtocolName(
pProps.getProtocol().getName(), false),
parent.getPanelDescriptor());
this.parent = parent;
this.pProps = pProps;
}
//
// Control methods
//
@Override
public URL getHelpURL() {
String name = pProps.getProtocol().getName().toLowerCase();
return buildHelpURL("help/sharemgr-" + name + ".html", null);
}
@Override
public List<Navigable> getBrowsable() {
Protocol protocol = pProps.getProtocol();
String pName = protocol.getName();
// Return a Navigable for every enabled security mode
List<Navigable> navigables = new ArrayList<Navigable>();
for (SecurityModePropertySet sProps :
pProps.getSecurityModePropertySets()) {
if (sProps.getEnabledProperty().getValue()) {
String sName = sProps.getSecurityMode().getName();
String fName = SharemgrUtil.getFriendlySecurityModeName(
pName, sName, false);
Navigable navigable = new SimpleNavigable(sName, fName);
navigables.add(navigable);
}
}
return navigables;
}
@Override
public void start(Navigator navigator, Map<String, String> parameters)
throws NavigationAbortedException, InvalidParameterException {
setPropertyChangeSource(parent.getCommon());
super.start(navigator, parameters);
}
//
// DefaultControl methods
//
@Override
protected void ensureChildrenCreated() {
if (children.size() == 0) {
DefaultControl control = new DialogControl<SharemgrPanelDescriptor>(
getPanelDescriptor());
for (SecurityModePropertySet sProps :
pProps.getSecurityModePropertySets()) {
control.addChildren(new SecurityModeControl(this, sProps));
}
addChildren(control);
}
}
//
// SwingControl methods
//
@Override
protected ProtocolPanel createComponent() {
ProtocolPanel panel = createProtocolEditPanel();
for (Map.Entry<SecurityMode, JButton> entry :
panel.getSecurityButtons().entrySet()) {
final String sName = entry.getKey().getName();
entry.getValue().addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Navigable[] navigables = {
new SimpleNavigable(DialogControl.ID, null),
new SimpleNavigable(sName, null)
};
getNavigator().goToAsync(false,
ProtocolControl.this, navigables);
}
});
}
return panel;
}
@Override
protected void initComponent() {
getComponent().init(parent.getCommon());
}
//
// ProtocolControl methods
//
protected ProtocolPanel createProtocolEditPanel() {
return new ProtocolPanel(pProps);
}
public CommonTabbedControl<?> getParent() {
return parent;
}
public ProtocolPropertySet getProtocolPropertySet() {
return pProps;
}
}