in taverna-xpath-activity-ui/src/main/java/org/apache/taverna/activities/xpath/ui/config/xmltree/XPathActivityXMLTree.java [86:155]
private XPathActivityXMLTree(XPathActivityXMLTreeNode root, Document documentUsedToPopulateTree,
boolean bIncludeElementValues, boolean bIncludeElementNamespaces, XPathActivityConfigurationPanel parentConfigPanel)
{
super(root);
this.instanceOfSelf = this;
this.allSelectionListeners = new TreeSelectionListener[0];
this.parentConfigPanel = parentConfigPanel;
this.documentUsedToPopulateTree = documentUsedToPopulateTree;
this.currentXPathExpression = null;
this.currentXPathNamespaces = new HashMap<String,String>();
this.prepopulateNamespaceMap();
// custom renderer of the nodes in the XML tree
this.treeRenderer = new XPathActivityXMLTreeRenderer(bIncludeElementValues, bIncludeElementNamespaces);
this.setCellRenderer(treeRenderer);
// add listener to handle various selections of nodes in the tree
this.xmlTreeSelectionHandler = new XPathActivityXMLTreeSelectionHandler(parentConfigPanel, this);
this.addTreeSelectionListener(xmlTreeSelectionHandler);
// --- CONTEXTUAL MENU FOR EXPANDING / COLLAPSING THE TREE ---
// create popup menu for expanding / collapsing all nodes in the tree
JMenuItem miExpandAll = new JMenuItem("Expand all", XPathActivityIcon.getIconById(XPathActivityIcon.XML_TREE_EXPAND_ALL_ICON));
miExpandAll.setToolTipText("Expand all nodes in the filtering tree");
miExpandAll.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < getRowCount(); i++) {
instanceOfSelf.expandRow(i);
}
}
});
JMenuItem miCollapseAll = new JMenuItem("Collapse all", XPathActivityIcon.getIconById(XPathActivityIcon.XML_TREE_COLLAPSE_ALL_ICON));
miCollapseAll.setToolTipText("Collapse all expanded nodes in the filtering tree");
miCollapseAll.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int i = getRowCount() - 1; i >= 0; i--) {
instanceOfSelf.collapseRow(i);
}
}
});
// populate the popup menu with created menu items
contextualMenu = new JPopupMenu();
contextualMenu.add(miExpandAll);
contextualMenu.add(miCollapseAll);
// mouse events may cause the contextual menu to be shown - adding a listener
this.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
contextualMenu.show(instanceOfSelf, e.getX(), e.getY());
}
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
// another way a popup menu may be called on different systems
contextualMenu.show(instanceOfSelf, e.getX(), e.getY());
}
}
});
}