usr/src/java/vpanels/panels/firewall/org/opensolaris/os/vp/panels/firewall/client/swing/GlobalControl.java
author Stephen Talley <stephen.talley@sun.com>
Tue, 22 Sep 2009 16:46:54 -0400
changeset 360 8943c58ad2f5
parent 349 cb1b71664c9a
child 361 d3611020acea
permissions -rw-r--r--
11508 Control, DefaultControl refactoring

/*
 * 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 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

package org.opensolaris.os.vp.panels.firewall.client.swing;

import java.util.Map;
import java.util.logging.*;
import java.net.UnknownHostException;
import org.opensolaris.os.vp.panel.common.ClientContext;
import org.opensolaris.os.vp.panel.swing.control.SwingSettingsControl;
import org.opensolaris.os.vp.panel.common.control.*;
import org.opensolaris.os.vp.panel.common.action.*;
import org.opensolaris.os.vp.panel.common.smf.*;
import org.opensolaris.os.vp.panel.swing.control.TabbedControl;
import org.opensolaris.os.vp.util.misc.*;
import org.opensolaris.os.scf.common.*;

public class GlobalControl extends TabbedControl<FirewallPanelDescriptor> {
    //
    // Static data
    //

    public static final String ID = "global";
    public static final String NAME = Finder.getString("global.name");

    //
    // Instance data
    //

    FirewallDefaultTab defaultTab;
    FirewallOverrideTab overrideTab;
    FirewallOpenPortsTab openPortsTab;

    ChangeableAggregator changeableAggregator = new ChangeableAggregator();

    //
    // Constructors
    //

    public GlobalControl(FirewallPanelDescriptor descriptor) {
	super(ID, NAME, descriptor);
    }

    //
    // Control methods
    //

    @Override
    public void childStarted(Control child) {
	super.childStarted(child);

	ChangeableAggregator childAgg =
	    ((SwingSettingsControl<?, ?>)child).getComponent().
	    getChangeableAggregator();

	if (changeableAggregator.getChangeables().contains(childAgg))
	    return;

	changeableAggregator.addChangeables(childAgg);
    }

    @Override
    protected boolean isSaveNeeded() {
	return (changeableAggregator.isChanged());
    }

    @Override
    public void reset() throws ActionAbortedException, ActionFailedException {
	getPanelDescriptor().resetPolicies();
	changeableAggregator.reset();
    }

    @Override
    public void save() throws ActionAbortedException, ActionFailedException,
	ActionUnauthorizedException {

	Logger logger = getClientContext().getLog();
	setPropertyChangeIgnore(true);
	try {
	    getPanelDescriptor().saveToRepo();
	} catch (ScfException e) {
	    ScfUtil.throwActionException(e);
	} catch (UnknownHostException e) {
	    logger.log(Level.SEVERE, e.getMessage());
	    throw new ActionFailedException(e);
	} finally {
	    setPropertyChangeIgnore(false);
	}
	changeableAggregator.save();
    }

    @Override
    public void start(Navigator navigator, Map<String, String> parameters)
	throws NavigationAbortedException, InvalidParameterException {
	setPropertyChangeSource(getPanelDescriptor());
	super.start(navigator, parameters);
    }

    //
    // DefaultControl methods
    //

    @Override
    protected void ensureChildrenCreated() {
	if (children.size() == 0) {

	    defaultTab = new FirewallDefaultTab(getPanelDescriptor());
	    overrideTab = new FirewallOverrideTab(getPanelDescriptor());
	    openPortsTab = new FirewallOpenPortsTab(getPanelDescriptor());

	    addChildren(defaultTab);
	    addChildren(openPortsTab);
	    addChildren(overrideTab);
	}
    }

    //
    // GlobalControl methods
    //

    public ChangeableAggregator getChangeableAggregator() {
	return changeableAggregator;
    }
}