Vector associatedBeansWithCustomizers = new Vector();
  private void doPopup(Point pt, final BeanInstance bi,		       int x, int y) {    final JComponent bc = (JComponent)bi.getBean();    final int xx = x;    final int yy = y;    int menuItemCount = 0;    JPopupMenu beanContextMenu = new JPopupMenu();    beanContextMenu.insert(new JLabel("Edit", 				      SwingConstants.CENTER), 			   menuItemCount);    menuItemCount++;    if (bc instanceof MetaBean) {      JMenuItem ungroupItem = new JMenuItem("Ungroup");      ungroupItem.addActionListener(new ActionListener() {          public void actionPerformed(ActionEvent e) {            // ungroup            bi.removeBean(m_beanLayout);            Vector group = ((MetaBean)bc).getBeansInSubFlow();            Vector associatedConnections =               ((MetaBean)bc).getAssociatedConnections();            ((MetaBean)bc).restoreBeans();            for (int i = 0; i < group.size(); i++) {              BeanInstance tbi = (BeanInstance)group.elementAt(i);              addComponent(tbi, false);              tbi.addBean(m_beanLayout);            }            for (int i = 0; i < associatedConnections.size(); i++) {              BeanConnection tbc =                 (BeanConnection)associatedConnections.elementAt(i);              tbc.setHidden(false);            }            m_beanLayout.repaint();          }        });      beanContextMenu.add(ungroupItem);      menuItemCount++;      // Add to user tab      JMenuItem addToUserTabItem = new JMenuItem("Add to user tab");      addToUserTabItem.addActionListener(new ActionListener() {          public void actionPerformed(ActionEvent e) {            addToUserToolBar((MetaBean)bi.getBean(), true);          }        });      beanContextMenu.add(addToUserTabItem);      menuItemCount++;    }    JMenuItem deleteItem = new JMenuItem("Delete");    deleteItem.addActionListener(new ActionListener() {	public void actionPerformed(ActionEvent e) {	  BeanConnection.removeConnections(bi);	  bi.removeBean(m_beanLayout);	  revalidate();	}      });    beanContextMenu.add(deleteItem);    menuItemCount++;    // first determine if there is a customizer for this bean    try {      //BeanInfo [] compInfo = null;      //JComponent [] associatedBeans = null;      Vector compInfo = new Vector(1);      Vector associatedBeans = null;      Vector associatedBeansWithCustomizers = new Vector();      Vector outputBeans = null;      Vector compInfoOutputs = null;      if (bc instanceof MetaBean) {        compInfo = ((MetaBean)bc).getBeanInfoSubFlow();                associatedBeans = ((MetaBean)bc).getBeansInSubFlow();        // make a list of only those sub flow beans that have customizers        for (int i = 0; i < associatedBeans.size(); i++) {          Object bn = ((BeanInstance)associatedBeans.elementAt(i)).getBean();          BeanInfo tbi = Introspector.getBeanInfo(bn.getClass());          if (tbi.getBeanDescriptor().getCustomizerClass() != null) {            associatedBeansWithCustomizers.add(associatedBeans.elementAt(i));          }        }        outputBeans = ((MetaBean)bc).getBeansInOutputs();        compInfoOutputs = ((MetaBean)bc).getBeanInfoOutputs();      } else {        compInfo.add(Introspector.getBeanInfo(bc.getClass()));        compInfoOutputs = compInfo;      }      final Vector tempAssociatedBeans = associatedBeans;      if (compInfo == null) {	System.err.println("Error");      } else {	//	System.err.println("Got bean info");        for (int zz = 0; zz < compInfo.size(); zz++) {          final int tt = zz;          final Class custClass =             ((BeanInfo)compInfo.elementAt(zz)).getBeanDescriptor().            getCustomizerClass();          if (custClass != null) {            //	  System.err.println("Got customizer class");            //	  popupCustomizer(custClass, bc);            JMenuItem custItem = null;            if (!(bc instanceof MetaBean)) {              custItem = new JMenuItem("Configure...");            } else {              String custName = custClass.getName();              BeanInstance tbi =                 (BeanInstance)associatedBeansWithCustomizers.elementAt(zz);              if (tbi.getBean() instanceof WekaWrapper) {                custName = ((WekaWrapper)tbi.getBean()).                  getWrappedAlgorithm().getClass().getName();              } else {                custName = custName.substring(0, custName.indexOf("Customizer"));              }              custName = custName.                substring(custName.lastIndexOf('.')+1 , custName.length());              custItem = new JMenuItem("Configure: "+ custName);            }            custItem.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e) {                  if (bc instanceof MetaBean) {                    popupCustomizer(custClass,                                     (JComponent)((BeanInstance)tempAssociatedBeans.                                                 elementAt(tt)).getBean());                  } else {                    popupCustomizer(custClass, bc);                  }                }              });            beanContextMenu.add(custItem);            menuItemCount++;                   } else {            System.err.println("No customizer class");          }        }        Vector esdV = new Vector();        for (int i = 0; i < compInfoOutputs.size(); i++) {          EventSetDescriptor [] temp =             ((BeanInfo)compInfoOutputs.elementAt(i)).getEventSetDescriptors();          if (temp != null && temp.length > 0) {            esdV.add(temp);          }        }        //        EventSetDescriptor [] esds = compInfo.getEventSetDescriptors();        //        if (esds != null && esds.length > 0) {        if (esdV.size() > 0) {          beanContextMenu.insert(new JLabel("Connections",                                             SwingConstants.CENTER),                                  menuItemCount);          menuItemCount++;	}        final Vector finalOutputs = outputBeans;        for (int j = 0; j < esdV.size(); j++) {          final int fj = j;          String sourceBeanName="";          if (bc instanceof MetaBean) {            Object sourceBean = ((BeanInstance)outputBeans.elementAt(j)).getBean();            if (sourceBean instanceof WekaWrapper) {              sourceBeanName = ((WekaWrapper)sourceBean).                getWrappedAlgorithm().getClass().getName();            } else {              sourceBeanName = sourceBean.getClass().getName();            }            sourceBeanName = sourceBeanName.              substring(sourceBeanName.lastIndexOf('.')+1, sourceBeanName.length());            sourceBeanName += ": ";          }          EventSetDescriptor [] esds =             (EventSetDescriptor [])esdV.elementAt(j);          for (int i = 0; i < esds.length; i++) {            //	  System.err.println(esds[i].getName());            // add each event name to the menu            JMenuItem evntItem = new JMenuItem(sourceBeanName                                               +esds[i].getName());            final EventSetDescriptor esd = esds[i];            // Check EventConstraints (if any) here            boolean ok = true;            if (bc instanceof EventConstraints) {              ok = ((EventConstraints) bc).eventGeneratable(esd.getName());            }            if (ok) {              evntItem.addActionListener(new ActionListener() {                  public void actionPerformed(ActionEvent e) {                    connectComponents(esd, (bc instanceof MetaBean)                                      ? ((BeanInstance)finalOutputs.elementAt(fj))                                      : bi,                                       xx, yy);                  }                });            } else {              evntItem.setEnabled(false);            }            beanContextMenu.add(evntItem);            menuItemCount++;          }        }      }    } catch (IntrospectionException ie) {      ie.printStackTrace();    }    //    System.err.println("Just before look for other options");    // now look for other options for this bean    if (bc instanceof UserRequestAcceptor) {      Enumeration req = ((UserRequestAcceptor)bc).enumerateRequests();      if (req.hasMoreElements()) {	beanContextMenu.insert(new JLabel("Actions", 					  SwingConstants.CENTER), 			       menuItemCount);	menuItemCount++;      }      while (req.hasMoreElements()) {	String tempS = (String)req.nextElement();	boolean disabled = false;	// check to see if this item is currently disabled	if (tempS.charAt(0) == '$') {	  tempS = tempS.substring(1, tempS.length());	  disabled = true;	}	final String tempS2 = tempS;	JMenuItem custItem = new JMenuItem(tempS2);	custItem.addActionListener(new ActionListener() {	    public void actionPerformed(ActionEvent e) {	      ((UserRequestAcceptor)bc).performRequest(tempS2);	      	    }	  });	if (disabled) {	  custItem.setEnabled(false);	}	beanContextMenu.add(custItem);	menuItemCount++;      }    }    //    System.err.println("Just before showing menu");    // popup the menu    if (menuItemCount > 0) {      beanContextMenu.show(m_beanLayout, x, y);    }  }