summaryrefslogtreecommitdiff
path: root/java/src/IceGrid/TreeNode/Parent.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/IceGrid/TreeNode/Parent.java')
-rwxr-xr-xjava/src/IceGrid/TreeNode/Parent.java77
1 files changed, 75 insertions, 2 deletions
diff --git a/java/src/IceGrid/TreeNode/Parent.java b/java/src/IceGrid/TreeNode/Parent.java
index 6eaf05d1b33..c799078747d 100755
--- a/java/src/IceGrid/TreeNode/Parent.java
+++ b/java/src/IceGrid/TreeNode/Parent.java
@@ -8,6 +8,10 @@
// **********************************************************************
package IceGrid.TreeNode;
+import java.awt.event.ActionEvent;
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JPopupMenu;
import javax.swing.tree.TreePath;
import javax.swing.event.TreeModelEvent;
import IceGrid.Model;
@@ -19,6 +23,30 @@ import IceGrid.TreeModelI;
class Parent extends CommonBaseI
{
+ static class NewPopupMenu extends JPopupMenu
+ {
+ NewPopupMenu()
+ {
+ _new = new AbstractAction("New")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _parent.newChild();
+ }
+ };
+
+ add(_new);
+ }
+
+ void setParent(Parent parent)
+ {
+ _parent = parent;
+ }
+
+ protected Parent _parent;
+ private Action _new;
+ }
+
//
// Adapts parent to a ComboBoxModel
@@ -132,6 +160,24 @@ class Parent extends CommonBaseI
return null;
}
+ public JPopupMenu getPopupMenu()
+ {
+ if(canHaveNewChild())
+ {
+ if(_popup == null)
+ {
+ _popup = new NewPopupMenu();
+ }
+ _popup.setParent(this);
+ return _popup;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
void addChild(CommonBase child) throws DuplicateIdException
{
addChild(child, false);
@@ -180,8 +226,24 @@ class Parent extends CommonBaseI
void removeChild(CommonBase child)
{
- child.unregister();
- _children.remove(child);
+ if(_children.remove(child))
+ {
+ child.unregister();
+ }
+ }
+
+ void removeChild(CommonBase child, boolean fireEvent)
+ {
+ int index = _children.indexOf(child);
+ if(index > -1)
+ {
+ child.unregister();
+ _children.remove(child);
+ if(fireEvent)
+ {
+ fireNodeRemovedEvent(this, child, index);
+ }
+ }
}
void removeChild(String id, boolean fireEvent)
@@ -460,6 +522,15 @@ class Parent extends CommonBaseI
return new ComboBoxModel();
}
+ boolean canHaveNewChild()
+ {
+ return false;
+ }
+
+ void newChild()
+ {
+ assert canHaveNewChild();
+ }
Parent(String id, Model model, boolean root)
{
@@ -488,4 +559,6 @@ class Parent extends CommonBaseI
protected java.util.LinkedList _children = new java.util.LinkedList();
private ChildComparator _childComparator = new ChildComparator();
+
+ static private NewPopupMenu _popup;
}