Vector closestConnections =
BeanConnection.getClosestConnections(new Point(x, y),
10, m_mainKFPerspective.getCurrentTabIndex());
PopupMenu rightClickMenu = new PopupMenu();
int menuItemCount = 0;
if (m_mainKFPerspective.getSelectedBeans().size() > 0 ||
closestConnections.size() > 0 ||
(m_pasteBuffer != null && m_pasteBuffer.length() > 0)) {
if (m_mainKFPerspective.getSelectedBeans().size() > 0) {
MenuItem snapItem = new MenuItem("Snap selected to grid");
snapItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
snapSelectedToGrid();
}
});
rightClickMenu.add(snapItem);
menuItemCount++;
MenuItem copyItem = new MenuItem("Copy selected");
copyItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
copyToClipboard();
m_mainKFPerspective.setSelectedBeans(new Vector());
}
});
rightClickMenu.add(copyItem);
menuItemCount++;
MenuItem cutItem = new MenuItem("Cut selected");
cutItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// only delete if our copy was successful!
if (copyToClipboard()) {
deleteSelectedBeans();
}
}
});
rightClickMenu.add(cutItem);
menuItemCount++;
MenuItem deleteSelected = new MenuItem("Delete selected");
deleteSelected.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
deleteSelectedBeans();
}
});
rightClickMenu.add(deleteSelected);
menuItemCount++;
// Able to group selected subflow?
boolean groupable = true;
final Vector selected = m_mainKFPerspective.getSelectedBeans();
// check if sub flow is valid
final Vector inputs = BeanConnection.inputs(selected,
m_mainKFPerspective.getCurrentTabIndex());
final Vector outputs = BeanConnection.outputs(selected,
m_mainKFPerspective.getCurrentTabIndex());
// screen the inputs and outputs
if (inputs.size() == 0 || outputs.size() == 0) {
groupable = false;
}
// dissallow MetaBeans in the selected set (for the
// time being).
if (groupable) {
for (int i = 0; i < selected.size(); i++) {
BeanInstance temp = (BeanInstance)selected.elementAt(i);
if (temp.getBean() instanceof MetaBean) {
groupable = false;
break;
}
}
}
if (groupable) {
// show connector dots for input beans
for (int i = 0; i < inputs.size(); i++) {
BeanInstance temp = (BeanInstance)inputs.elementAt(i);
if (temp.getBean() instanceof Visible) {
((Visible)temp.getBean()).getVisual().
setDisplayConnectors(true, java.awt.Color.red);
}
}
// show connector dots for output beans
for (int i = 0; i < outputs.size(); i++) {
BeanInstance temp = (BeanInstance)outputs.elementAt(i);
if (temp.getBean() instanceof Visible) {
((Visible)temp.getBean()).getVisual().
setDisplayConnectors(true, java.awt.Color.green);
}
}
MenuItem groupItem = new MenuItem("Group selected");
groupItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
groupSubFlow(selected, inputs, outputs);
}
});
rightClickMenu.add(groupItem);
menuItemCount++;
}
}
if (m_pasteBuffer != null && m_pasteBuffer.length() > 0) {
rightClickMenu.addSeparator();
menuItemCount++;
MenuItem pasteItem = new MenuItem("Paste");
pasteItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// deserialize, integerate and
// position at x, y
pasteFromClipboard(x, y, m_pasteBuffer, true);
}
});
rightClickMenu.add(pasteItem);
menuItemCount++;
}
if (closestConnections.size() > 0) {
rightClickMenu.addSeparator();
menuItemCount++;
MenuItem deleteConnection = new MenuItem("Delete Connection:");
deleteConnection.setEnabled(false);
rightClickMenu.insert(deleteConnection, menuItemCount);
menuItemCount++;
for (int i = 0; i < closestConnections.size(); i++) {
final BeanConnection bc = (BeanConnection) closestConnections.elementAt(i);
String connName = bc.getSourceEventSetDescriptor().getName();
//JMenuItem deleteItem = new JMenuItem(connName);
String targetName = "";
if (bc.getTarget().getBean() instanceof BeanCommon) {
targetName = ((BeanCommon)bc.getTarget().getBean()).getCustomName();
} else {
targetName = bc.getTarget().getBean().getClass().getName();
targetName = targetName.substring(targetName.lastIndexOf('.')+1, targetName.length());
}
MenuItem deleteItem = new MenuItem(connName + "-->" + targetName);
deleteItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addUndoPoint();
bc.remove(m_mainKFPerspective.getCurrentTabIndex());
m_beanLayout.revalidate();
m_beanLayout.repaint();
m_mainKFPerspective.setEditedStatus(true);
if (m_mainKFPerspective.getSelectedBeans().size() > 0) {
m_mainKFPerspective.setSelectedBeans(new Vector());
}
notifyIsDirty();
}
});
rightClickMenu.add(deleteItem);
menuItemCount++;
}
}
}
if (menuItemCount > 0) {
rightClickMenu.addSeparator();
menuItemCount++;
}
MenuItem noteItem = new MenuItem("New note");
noteItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Note n = new Note();
m_toolBarBean = n;
KnowledgeFlowApp.this.setCursor(Cursor.
getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
m_mode = ADDING;
}
});
rightClickMenu.add(noteItem);
menuItemCount++;
m_beanLayout.add(rightClickMenu);
rightClickMenu.show(m_beanLayout, x, y);
}