KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > helloworld > listeners > HelloWorldRemoveTreeNode_li


1 /*******************************************************************************
2  * Copyright (c) 2004, Dirk von der Weiden.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * Dirk von der Weiden - initial API and implementation
10  *
11  * Created on 21.02.2005
12  *
13  * date: 21.02.2005
14  * project: WiSer-HelloWorld
15  *
16  * *******************************************************************************/

17
18 package helloworld.listeners;
19
20 import Jmc.baseGui.*;
21 import Jmc.commonGui.*;
22 import Jmc.commonGui.loader.*;
23 import Jmc.baseTools.*;
24
25 import javax.swing.tree.*;
26
27 /**
28  * @author Dirk
29  *
30  * date: 21.02.2005
31  *
32  * <p>
33  * Purpose: This listener inserts a new item into the tree model of the treeView. It shows the
34  * connection between model and view
35  * </p>
36  */

37 public class HelloWorldRemoveTreeNode_li implements base_guiListener
38 {
39   /**
40      * <p>
41      * This method is called whenever the button is pressed.
42      * </p><p>
43      *
44      * </p><p>
45      * @param xParam the widget which generates the event
46      * </p>
47      */

48   public void pcmf_execListener(base_guiObj xParam) throws Exception JavaDoc
49   {
50     // get all relevant widgets from the registry
51
base_treeViewLoader l_load = (base_treeViewLoader)base_registredObject.pcmf_getObjByName("treeLoader");
52     base_treeView_if l_tree = (base_treeView_if)base_registredObject.pcmf_getObjByName("atree2");
53        
54     // get selection
55
Object JavaDoc l_rawSelected = l_tree.pcmf_getValue();
56     
57     // node selected?
58
if (l_rawSelected instanceof base_treeNode)
59     {
60       // cast to tree node
61
base_treeNode l_selected = (base_treeNode)l_rawSelected;
62       
63       // get corresponding model value
64
DefaultMutableTreeNode l_node = (DefaultMutableTreeNode)l_load.pcmf_toModelValue(l_selected);
65       if (l_node == null)
66         return;
67       
68       // change model - remove node
69
((DefaultTreeModel)l_load.pcmf_getModel()).removeNodeFromParent(l_node);
70     }
71
72     return;
73   }
74 }
Popular Tags