usr/src/java/vpanels/panels/usermgr/org/opensolaris/os/vp/panels/usermgr/client/swing/UserMgrBasicControl.java
author Stephen Talley <stephen.talley@oracle.com>
Thu, 22 Jul 2010 10:10:18 -0400
changeset 547 e1d8b4ddb166
parent 536 2051d6c000cc
child 591 7c5752b99fd6
permissions -rw-r--r--
16625 SwingSettingsControl does not follow naming conventions

/*
 * 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.usermgr.client.swing;

import java.net.URL;
import org.opensolaris.os.vp.panel.common.action.ActionAbortedException;
import org.opensolaris.os.vp.panel.common.action.ActionFailedException;
import org.opensolaris.os.vp.panel.common.action.ActionUnauthorizedException;
import org.opensolaris.os.vp.panel.swing.control.SettingsControl;
import org.opensolaris.os.vp.util.misc.Finder;

public class UserMgrBasicControl
    extends SettingsControl<UserMgrPanelDescriptor, UserMgrBasicPanel> {

    //
    // Static data
    //
    public static final String ID = "basic";
    public static final String NAME = Finder.getString("usermgr.basic.name");

    //
    // Instance data
    //

    private UserMgrControl parent;

    //
    // Constructor
    //
    public UserMgrBasicControl(UserMgrControl parent) {
        super(ID, NAME, parent.getPanelDescriptor());
	this.parent = parent;
    }

    //
    // Control methods
    //

    @Override
    public URL getHelpURL() {
	return buildHelpURL("help/usermgr-overview.html", null);
    }

    @Override
    protected boolean isChanged() {
	// Save unconditionally for now
	return true;
    }

    @Override
    protected UnsavedChangesAction getUnsavedChangesAction() {
	// Always save changes on the client
	return UnsavedChangesAction.SAVE;
    }

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

	UserMgrBasicPanel panel = getComponent();
	UserManagedObject umo = parent.getUserManagedObject();

	setPropertyChangeIgnore(true);
	try {
	    // Set the values from the panel
	    if (panel.getUserDescProperty().isChanged()) {
		String userdesc = panel.getUserDescProperty().getValue();
		UserMgrUtils.validateUserDesc(userdesc);
		umo.getUserDescProperty().setValue(userdesc);
	    }

	    if (panel.getIsAdminProperty().isChanged()) {
		boolean admin = panel.getIsAdminProperty().getValue();
		umo.getIsAdminProperty().setValue(admin);
	    }

	    if (panel.getPassProperty().isChanged() ||
		panel.getPassConfirmProperty().isChanged()) {
		char[] pass1 = panel.getPassProperty().getValue();
		char[] pass2 = panel.getPassConfirmProperty().getValue();
		UserMgrUtils.validatePassword(umo.isNewUser(), pass1, pass2);
		umo.getPassProperty().setValue(pass1);
	    }
	} finally {
	    setPropertyChangeIgnore(false);
	}
    }

    //
    // SwingControl Methods
    //

    @Override
    protected UserMgrBasicPanel createComponent() {
        UserMgrBasicPanel panel = new UserMgrBasicPanel();
        return panel;
    }

    @Override
    protected void initComponent() {
	UserMgrBasicPanel panel = getComponent();
	UserManagedObject umo = parent.getUserManagedObject();

	// Initialize the panel
	panel.init(umo);
    }
}