*
* Modified by Zerbetto: javax.swing.JPopupMenu transformed into java.awt.PopupMenu
*
*/
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;
// modifications by Zerbetto
PopupMenu beanContextMenu = new PopupMenu();
//JPopupMenu beanContextMenu = new JPopupMenu();
// beanContextMenu.insert(new JLabel("Edit",
// SwingConstants.CENTER),
// menuItemCount);
MenuItem edit = new MenuItem("Edit:");
edit.setEnabled(false);
beanContextMenu.insert(edit, menuItemCount);
menuItemCount++;
if (m_mainKFPerspective.getSelectedBeans().size() > 0) {
MenuItem copyItem = new MenuItem("Copy");
copyItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
copyToClipboard();
m_mainKFPerspective.setSelectedBeans(new Vector());
}
});
beanContextMenu.add(copyItem);
menuItemCount++;
}
if (bc instanceof MetaBean) {
//JMenuItem ungroupItem = new JMenuItem("Ungroup");
MenuItem ungroupItem = new MenuItem("Ungroup");
ungroupItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// ungroup
bi.removeBean(m_beanLayout, m_mainKFPerspective.getCurrentTabIndex());
Vector group = ((MetaBean) bc).getBeansInSubFlow();
Vector associatedConnections = ((MetaBean) bc).getAssociatedConnections();
((MetaBean) bc).restoreBeans(xx, yy);
for (int i = 0; i < group.size(); i++) {
BeanInstance tbi = (BeanInstance) group.elementAt(i);
addComponent(tbi, false);
tbi.addBean(m_beanLayout, m_mainKFPerspective.getCurrentTabIndex());
}
for (int i = 0; i < associatedConnections.size(); i++) {
BeanConnection tbc = (BeanConnection) associatedConnections.elementAt(i);
tbc.setHidden(false);
}
m_beanLayout.repaint();
m_mainKFPerspective.setEditedStatus(true);
notifyIsDirty();
}
});
beanContextMenu.add(ungroupItem);
menuItemCount++;
// Add to user tab
//JMenuItem addToUserTabItem = new JMenuItem("Add to user tab");
MenuItem addToUserTabItem = new MenuItem("Add to user tab");
addToUserTabItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//addToUserToolBar((MetaBean) bi.getBean(), true);
//addToUserTreeNode((MetaBean) bi.getBean(), true);
addToUserTreeNode(bi, true);
notifyIsDirty();
}
});
beanContextMenu.add(addToUserTabItem);
menuItemCount++;
}
//JMenuItem deleteItem = new JMenuItem("Delete");
MenuItem deleteItem = new MenuItem("Delete");
deleteItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BeanConnection.removeConnections(bi, m_mainKFPerspective.getCurrentTabIndex());
bi.removeBean(m_beanLayout, m_mainKFPerspective.getCurrentTabIndex());
if (bc instanceof BeanCommon) {
String key = ((BeanCommon)bc).getCustomName()
+ "$" + bc.hashCode();
m_logPanel.statusMessage(key + "|remove");
}
// delete any that have been actively selected
if (m_mainKFPerspective.getSelectedBeans().size() > 0) {
deleteSelectedBeans();
}
revalidate();
m_mainKFPerspective.setEditedStatus(true);
notifyIsDirty();
m_selectAllB.setEnabled(BeanInstance.
getBeanInstances(m_mainKFPerspective.getCurrentTabIndex()).size() > 0);
}
});
if (bc instanceof BeanCommon) {
if (((BeanCommon)bc).isBusy()) {
deleteItem.setEnabled(false);
}
}
beanContextMenu.add(deleteItem);
menuItemCount++;
if (bc instanceof BeanCommon) {
MenuItem nameItem = new MenuItem("Set name");
nameItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String oldName = ((BeanCommon)bc).getCustomName();
String name = JOptionPane.showInputDialog(KnowledgeFlowApp.this,
"Enter a name for this component",
oldName);
if (name != null) {
((BeanCommon)bc).setCustomName(name);
m_mainKFPerspective.setEditedStatus(true);
}
}
});
if (bc instanceof BeanCommon) {
if (((BeanCommon)bc).isBusy()) {
nameItem.setEnabled(false);
}
}
beanContextMenu.add(nameItem);
menuItemCount++;
}
try {
//BeanInfo [] compInfo = null;
//JComponent [] associatedBeans = null;
Vector compInfo = new Vector(1);
Vector associatedBeans = null;
Vector outputBeans = null;
Vector compInfoOutputs = null;
if (bc instanceof MetaBean) {
compInfo = ((MetaBean) bc).getBeanInfoSubFlow();
associatedBeans = ((MetaBean) bc).getBeansInSubFlow();
outputBeans = ((MetaBean) bc).getBeansInOutputs();
compInfoOutputs = ((MetaBean) bc).getBeanInfoOutputs();
} else {
compInfo.add(Introspector.getBeanInfo(bc.getClass()));
compInfoOutputs = compInfo;
}
final Vector tempAssociatedBeans = associatedBeans;