alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

/*
 * SetDefaultServerAction.java
 *
 * Date: 3/6/01
 *
 */
package org.netbeans.modules.j2ee.deployment.impl.ui.actions;

import javax.swing.*;
import java.text.MessageFormat;

import org.openide.nodes.*;
import org.openide.util.*;
import org.openide.util.actions.*;
import org.openide.awt.StatusDisplayer;

import org.netbeans.modules.j2ee.deployment.impl.*;
import org.netbeans.modules.j2ee.deployment.impl.ui.*;

/**
 * Set Default Server action which is used on the various
 * server nodes (Web Servers, App Servers).
 *
 * @author Joe Warzecha
 */

public class SetDefaultServerAction extends CallableSystemAction {

    /**
     * Return the human presentable name of the action. This
     * should be presented as an item in a menu.
     *
     * @return the name of the action
     */
    public String getName () {
	return NbBundle.getMessage (SetDefaultServerAction.class, 
				    "LBL_SetDefaultServer");		//NOI18N
    }

    /** 
     * Help context where to find more about the action.
     * 
     * @return the help context for this action
     */
    public HelpCtx getHelpCtx () {
        return null;
    }

    protected boolean enable (Node [] nodes) {
	if ((nodes != null) && (nodes.length == 1)) {
	    return true;
	}

	return false;
    }

    public void performAction () {
	SwingUtilities.invokeLater (new Runnable () {
	    public void run () {
                StatusDisplayer.getDefault().setStatusText(""); //NOI18N
		ServerTargetSelector selector = 
			new ServerTargetSelector ();
		selector.setText 
			(NbBundle.getMessage (SetDefaultServerAction.class,
			 getMsgKey ()));
                selector.setTextMnemonic(NbBundle.getMessage(SetDefaultServerAction.class, getMsgKeyMnemonic()));
                selector.setTextA11yDesc(NbBundle.getMessage(SetDefaultServerAction.class, getMsgKeyA11yDesc()));
		if (selector.showDialog 
			(NbBundle.getMessage (SetDefaultServerAction.class,
					      getDialogTitleKey ()), getHelpId())) {
                    ServerTarget[] targets = selector.getServerTargets();
                    ServerInstance instance = selector.getServerInstance();
                    ServerString defaultTarget = null;
                    if (targets != null && targets.length > 0) {
                        StringBuffer targetsSB = new StringBuffer();
                        String[] targetNames = new String [targets.length];
                        instance = targets[0].getInstance();
                        for (int i = 0; i < targets.length; i++) {
                            targetNames[i] = targets[i].getName();
                        }
                        defaultTarget = new ServerString(instance.getServer().getShortName(), instance.getUrl(), targetNames);
                    } else if (instance != null) {
        		defaultTarget = new ServerString(selector.getServerInstance ());
                    }
                    if (defaultTarget != null) {
                        ServerRegistry.getInstance().setDefaultInstance(defaultTarget);
                        StatusDisplayer.getDefault().setStatusText(
                            NbBundle.getMessage(SetDefaultServerAction.class, "MSG_Default_Targets_Set", defaultTarget));
                    }
                }
	    }
	});
    }

    protected boolean showWebServers () {
        return false;
    }

    protected boolean showAppServers () {
	return true;
    }

    protected String getDialogTitleKey () {
	return "LBL_SetDefaultDlgTitle";				//NOI18N
    }

    protected String getMsgKey () {
	return "LBL_SetDefaultDlgMsg";				//NOI18N
    }

    protected String getMsgKeyMnemonic()
    {
        return "LBL_SetDefaultDlgMsg_Mnemonic";			//NOI18N
    }
    
    protected String getMsgKeyA11yDesc()
    {
        return "ACS_SetDefaultDlgMsgA11yDesc";			//NOI18N
    }
    
    protected String getHelpId()
    {
        return null;
    }

    protected void setDefault (ServerString instance) {
        if (instance != null) {
	    ServerRegistry.getInstance ().
					setDefaultInstance (instance);
	}
    }

    protected ServerString getDefault () {
	return ServerRegistry.getInstance ().getDefaultInstance ();
    }

    protected boolean asynchronous() { return false; }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.