1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package com
.sun
.star
.xml
.security
.uno
;
30 import org
.w3c
.dom
.Document
;
31 import javax
.swing
.event
.TreeModelListener
;
32 import javax
.swing
.event
.TreeModelEvent
;
33 import javax
.swing
.tree
.TreePath
;
34 import java
.util
.Enumeration
;
35 import java
.util
.Vector
;
38 * This adapter converts the current Document (a DOM) into
41 class DomToTreeModelAdapter
42 implements javax
.swing
.tree
.TreeModel
44 private Document m_document
;
45 private Vector m_listenerList
= new Vector();
47 public DomToTreeModelAdapter(Document document
)
49 m_document
= document
;
53 * Basic TreeModel operations
55 public Object
getRoot()
57 return new AdapterNode(m_document
);
60 public boolean isLeaf(Object aNode
)
65 * Determines whether the icon shows up to the left.
66 * Return true for any node with no children.
68 AdapterNode node
= (AdapterNode
) aNode
;
70 if (node
.childCount() > 0)
78 public int getChildCount(Object parent
)
80 AdapterNode node
= (AdapterNode
) parent
;
81 return node
.childCount();
84 public Object
getChild(Object parent
, int index
)
86 AdapterNode node
= (AdapterNode
) parent
;
87 return node
.child(index
);
90 public int getIndexOfChild(Object parent
, Object child
)
92 AdapterNode node
= (AdapterNode
) parent
;
93 return node
.index((AdapterNode
) child
);
96 public void valueForPathChanged(TreePath path
, Object newValue
)
99 * Null. We won't be making changes in the GUI
100 * If we did, we would ensure the new value was really new,
101 * adjust the model, and then fire a TreeNodesChanged event.
105 public void addTreeModelListener(TreeModelListener listener
)
107 if ( listener
!= null
108 && ! m_listenerList
.contains( listener
) )
110 m_listenerList
.addElement( listener
);
114 public void removeTreeModelListener(TreeModelListener listener
)
116 if ( listener
!= null )
118 m_listenerList
.removeElement( listener
);
122 public void fireTreeNodesChanged( TreeModelEvent e
)
124 Enumeration listeners
= m_listenerList
.elements();
125 while ( listeners
.hasMoreElements() )
127 TreeModelListener listener
=
128 (TreeModelListener
) listeners
.nextElement();
129 listener
.treeNodesChanged( e
);
133 public void fireTreeNodesInserted( TreeModelEvent e
)
135 Enumeration listeners
= m_listenerList
.elements();
136 while ( listeners
.hasMoreElements() )
138 TreeModelListener listener
=
139 (TreeModelListener
) listeners
.nextElement();
140 listener
.treeNodesInserted( e
);
144 public void fireTreeNodesRemoved( TreeModelEvent e
)
146 Enumeration listeners
= m_listenerList
.elements();
147 while ( listeners
.hasMoreElements() )
149 TreeModelListener listener
=
150 (TreeModelListener
) listeners
.nextElement();
151 listener
.treeNodesRemoved( e
);
155 public void fireTreeStructureChanged( TreeModelEvent e
)
157 Enumeration listeners
= m_listenerList
.elements();
158 while ( listeners
.hasMoreElements() )
160 TreeModelListener listener
=
161 (TreeModelListener
) listeners
.nextElement();
162 listener
.treeStructureChanged( e
);