/* * 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. */ /* * * */ package org.netbeans.modules.j2ee.deployment.impl.ui.actions; import org.openide.nodes.*; import org.openide.util.actions.*; import org.openide.*; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.netbeans.modules.j2ee.deployment.impl.*; import org.netbeans.modules.j2ee.deployment.impl.ui.FindServerPanel; import org.netbeans.modules.j2ee.deployment.impl.ui.ServerRegistryNode; import java.io.IOException; import java.text.MessageFormat; import javax.swing.SwingUtilities; import org.openide.awt.StatusDisplayer; import org.openide.windows.TopComponent; import org.openide.explorer.ExplorerManager; import org.openide.explorer.ExplorerPanel; import org.openide.filesystems.*; import org.openide.util.Lookup; import java.beans.PropertyVetoException; import org.openide.loaders.*; /** * @author George FinKlang * @author Jeri Lockhart */ public class FindDeploymentManagerAction extends CallableSystemAction { public HelpCtx getHelpCtx() { return HelpCtx.DEFAULT_HELP; } public String getName() { return NbBundle.getMessage(FindDeploymentManagerAction.class, "LBL_Add_Server_Instance"); } public void performAction() { SwingUtilities.invokeLater (new Runnable () { public void run () { StatusDisplayer.getDefault().setStatusText(""); //NOI18N FindServerPanel panel = new FindServerPanel (); if (panel.showDialog (null, null)) { String url = panel.getUrl(); String username = panel.getUsername(); String pw = panel.getPassword(); try { ServerRegistry.getInstance().addInstance(url, username, pw); } catch (IOException e) { e.printStackTrace(); return; } // Select the newly created instance node and write status message ServerInstance instance = ServerRegistry.getInstance().getServerInstance(url); if (instance != null) { ServerRegistryNode svrRegNode = null; try { FileSystem defaultFileSystem = Repository.getDefault().getDefaultFileSystem(); FileObject fo = defaultFileSystem.findResource("UI/Runtime"); //NOI18N DataFolder df = (DataFolder) DataObject.find(fo); Lookup l = new FolderLookup(df).getLookup(); svrRegNode = (ServerRegistryNode) l.lookup(ServerRegistryNode.class); } catch (DataObjectNotFoundException e) { e.printStackTrace(); } Node instanceNode = findInstanceNode(svrRegNode, ServerRegistry.getInstance().getServerInstance(url)); TopComponent tc = TopComponent.getRegistry().getActivated(); ExplorerPanel expPanel = null; if (tc instanceof ExplorerPanel) { expPanel = (ExplorerPanel) tc; } ExplorerManager expMgr = expPanel.getExplorerManager(); try { expMgr.setSelectedNodes(new Node[] {instanceNode}); }catch (PropertyVetoException e) { e.printStackTrace(); } System.out.println("instanceNode " + instanceNode ); StatusDisplayer.getDefault().setStatusText( MessageFormat.format(NbBundle.getMessage(FindDeploymentManagerAction.class, "MSG_Server_Instance_Added"), new Object[] {instance.getDisplayName()})); } } } }); } private Node findInstanceNode (Node root, ServerInstance instance) { Children ch = root.getChildren (); Node [] n = ch.getNodes (); if ((n == null) || (n.length < 1)) { return null; } for (int i = 0; i < n.length; i++) { Node node = null; ServerInstance siInst = (ServerInstance) n [i].getCookie (ServerInstance.class); if (siInst != null) { if (siInst.getUrl().equals(instance.getUrl())) { node = n [i]; } } else { node = findInstanceNode (n [i], instance); } if (node != null) { return node; } } return null; } }