5.7.2.1 Designing Main Screen - Switch Configuration Screen

 

The main screen of the Configuration Management Application has a tree in the left side, tabbed pane in the right side and a panel with buttons at the bottom of the screen. The figure below shows the components in the main screen.

 

Design Time View

 

 

Steps Involved

 

Initial Settings

  1. Create a new screen under the "EMS_Configuration" project and rename it as "SwitchConfiguration".

  2. Change the build type of the Screen to "NMS Frame" using the menu command Build > Type > NMS Frame.

  3. Change the layout of the Screen to "Border Layout" by right-clicking the Draw Area to invoke the screen pop-up menu, select Layouts > Border Layout.

Dropping and Laying out the Components

  1. Drop the AdventNetTree bean and change its instance name by following the steps below

  1. Drop the JTabbedPane bean and change its instance name by following the steps below

  1. Drop the JPanel bean and change its instance name by following the steps below

Invoke the "Border Layout" dialog to arrange the components by right-clicking the Draw Area and select "Layout Properties" menu item.

 

Select each component in the "Component" combo box and ensure the parameters are as in the table given below, if not provide the values and click "OK" button to  close the dialog.

 

Component

Position

HGap

VGap

Button_panel

South

5

5

Switch_Tree

West

Details_TappedPane

Center

 

Designing Switch_Tree Bean

  1. Double-click the "Switch_Tree" bean to invoke the Property Form.

  2. Select the TreeValues  and Click "Click to edit Titles and class or File names"  button against it to invoke the "Tree Values" dialog.

  3. Add the "Configure Switches" node by following the steps below

Similarly, add following nodes under the root node (Configure Switches) of the tree with the respective icons as given in the table below.

 

Node Name

Icon Name

Switch Name

ems_tut_switch_tick.jpg

View Result

properties.png

 

  1. Click "Apply" button after adding the above nodes and Click "Close" to close the dialog.

  2. Close the Property Form using the "Close" button.

  3. Right-click the "Switch_Tree" bean, select Interaction Wizard > treeSelection > valueChanged  to get a rubber band line. Bring the rubber  band line into "Switch_Tree" bean itself to invoke the Interaction Wizard.

    1. Ensure that the "Create New Connection class" option is selected in the first screen of the Interaction Wizard. click "Next" button.

    2. Ensure the "General Component Interaction" is selected and Click "Next" button twice to go to the final screen of the Interaction Wizard.

    3. Insert the following code in the valueChanged method

String name=null;

TreePath tp=arg0.getNewLeadSelectionPath();

if(tp != null)

{

AdventNetTreeNode an=(AdventNetTreeNode)tp.getLastPathComponent();

name=an.getName();

if(name.equals("View Result"))

{

Details_TabbedPane.setEnabledAt(0,false);

if (userOperations.toString().indexOf("Ems") != -1)

{

if ( userOperations.contains("Ems Configure All") && (! userOperations.contains("Ems Configure None")))

{

Details_TabbedPane.setEnabledAt(1,false);

Details_TabbedPane.setEnabledAt(2,false);

}

}

if (userOperations.toString().indexOf("Ems") == -1)

{

Details_TabbedPane.setEnabledAt(1,false);

Details_TabbedPane.setEnabledAt(2,false);

}

if(Details_TabbedPane.indexOfTab("Results") == -1)

Details_TabbedPane.insertTab("Results",null,Results_Panel,null,Details_TabbedPane.getTabCount());

Details_TabbedPane.setSelectedIndex(Details_TabbedPane.getTabCount()-1);

configure.setEnabled(false);

refresh.setEnabled(false);

}

if(name.equals(getParameter("HOST")))

{

if((Details_TabbedPane.indexOfTab("Results")) != -1)

{

Details_TabbedPane.removeTabAt(Details_TabbedPane.indexOfTab("Results"));

}

Details_TabbedPane.setEnabledAt(0,true);

if (userOperations.toString().indexOf("Ems") != -1)

{

if ( userOperations.contains("Ems Configure All") && (! userOperations.contains("Ems Configure None")))

{

Details_TabbedPane.setEnabledAt(1,true);

Details_TabbedPane.setEnabledAt(2,true);

}

}

Details_TabbedPane.setSelectedIndex(0);

refresh.setEnabled(true);

if (userOperations.toString().indexOf("Ems") != -1)

{

if ( (userOperations.contains("Ems Configure Scalar") || userOperations.contains("Ems Configure All")) && ! userOperations.contains("Ems Configure None"))

{

configure.setEnabled(true);

}

}

if (userOperations.toString().indexOf("Ems") == -1)

{

Details_TabbedPane.setEnabledAt(1,true);

Details_TabbedPane.setEnabledAt(2,true);

configure.setEnabled(true);

}

}

}

 

  1. Switch to Source View tab and scroll to the setVisible method. Write the following code under the   //<End_setVisible_boolean> tag.

if(bl)

{

String icon2="../images/ems_tut_switch_small.png";

AdventNetTreeNode node=Switch_Tree.getNode(getParameter("HOST"),icon2);

Switch_Tree.setSelectionInterval(1,1);

Switch_Tree.addNode(node);

Switch_Tree.selectNode(node);

if (userOperations.toString().indexOf("Ems") != -1)

{

if(userOperations.contains("Ems Configure Scalar") && ( ! userOperations.contains("Ems Configure All") && ! (userOperations.contains("Ems Configure None"))

))

{

Details_TabbedPane.removeTabAt(Details_TabbedPane.indexOfTab("STP"));

Details_TabbedPane.removeTabAt(Details_TabbedPane.indexOfTab("PortParameters"));

}

if (userOperations.contains("Ems Configure None"))

{

configure.setEnabled(false);

}

}

}

  1. Add the following code under the package import declarations as given below :

import java.net.*;

import javax.swing.tree.TreePath;

import java.util.Vector;

import java.rmi.Naming;

import com.adventnet.beans.utilbeans.AdventNetTreeNode;

import com.adventnet.nms.util.NmsClientUtil;

import com.adventnet.nms.util.BrowserControl;

import com.adventnet.security.authorization.AuthorizationEngine;

  1. Add the following code under the package variable declarations as given below :

private Vector userOperations=new Vector();

  1. Add the following code in the init method before the closing braces ("}") of this method  as given below :

checkUserOperations();

setResizable(false);

  1. Add the following code in stop method before the closing braces ("}") of this method as given below :

PortDetails1.stop();

  1. Add the following code in start method after the opening braces ("{") of this method as given below :

PortDetails1.start();

 

Custom code that need to be added in the Configuration management screen to cater for Security administration

 

In the Configuration wizard, we have created the screens for configuring the Switches. In the SwitchConfiguration.java file of the EMS configuration project, the following code was accommodated in order to cater for Security administration.

 

When the switch configuration screen is invoked from the client, the checkUserOperations() method makes a RMI lookup to the AuthorizationEngineAPI for retrieving the operations for the logged-in user.  

 

private void checkUserOperations()

    {

       try{

            URL BE_Url = NmsClientUtil.applet.getCodeBase();

            String BEHostName = "localhost";

            BEHostName = BE_Url.getHost();

            if(BEHostName.trim().equalsIgnoreCase("localhost"))

                try

                {

                 BEHostName = InetAddress.getLocalHost().getHostName();

                }

                catch(UnknownHostException unknownhostexception1)

                {

                    System.err.println("unknown host : " + unknownhostexception1);

                }

           if(BE_Url != null && BEHostName != null)

            {

                String name = "//" + BEHostName + "/NmsAuthEngineAPI";

                AuthorizationEngine authEngine = (AuthorizationEngine) Naming.lookup(name);

                if(authEngine == null)

                {

            System.out.println("Could not get rmi handle to AuthAPI");

                }

                else

                {

                    String userName = NmsClientUtil.getUserName();

                    userOperations = authEngine.getOperationsForUser(userName);

                 }

            }

        }

        catch(AuthorizationException ex)

        {

            System.out.println("Exception while getting RMI handle to Authorization Engine " + ex.getMessage());

        }

        catch(Exception exp)

        {

            System.out.println("Exception while getting RMI handle to Authorization Engine " + exp.getMessage());

        }

    }

 

Whenever a component in the UI is added, disabled or enabled, a check is made if the user logged in has the required permission to perform the operation. Based on the user operation, the component is enabled or disabled.

 

if(userOperations.toString().indexOf("Ems") != -1)

        {

            if (userOperations.contains("Ems Configure None"))

            {

                configure.setEnabled(false);

            }

        }

 

  1. Switch back to Screen View tab.

Designing the Button_Panel Bean

  1. Ensure that the layout of Button_Panel is flow layout.

  2. Drop a JButton from the SwingBeans.list tab of BeansPalette and change its instance name as "configure" and provide "text" property value "Configure" in the Property Form. Similarly drop three more JButtons and change their properties in Property Form as given in the table below:

 

Instance Name

Text Property

refresh

Refresh

help

Help

close

Close

 

  1. Resize the bean components to the required size (refer the Design Time View screen shot).

 

Note: The actions for each of the above buttons are provided after the panel screens are designed and integrated.



Copyright © 2009 ZOHO Corp. All Rights Reserved.