1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 package com.sun.star.xml.security.uno; 29 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; 36 37 /* 38 * This adapter converts the current Document (a DOM) into 39 * a JTree model. 40 */ 41 class DomToTreeModelAdapter 42 implements javax.swing.tree.TreeModel 43 { 44 private Document m_document; 45 private Vector m_listenerList = new Vector(); 46 47 public DomToTreeModelAdapter(Document document) 48 { 49 m_document = document; 50 } 51 52 /* 53 * Basic TreeModel operations 54 */ 55 public Object getRoot() 56 { 57 return new AdapterNode(m_document); 58 } 59 60 public boolean isLeaf(Object aNode) 61 { 62 boolean rc = true; 63 64 /* 65 * Determines whether the icon shows up to the left. 66 * Return true for any node with no children. 67 */ 68 AdapterNode node = (AdapterNode) aNode; 69 70 if (node.childCount() > 0) 71 { 72 rc = false; 73 } 74 75 return rc; 76 } 77 78 public int getChildCount(Object parent) 79 { 80 AdapterNode node = (AdapterNode) parent; 81 return node.childCount(); 82 } 83 84 public Object getChild(Object parent, int index) 85 { 86 AdapterNode node = (AdapterNode) parent; 87 return node.child(index); 88 } 89 90 public int getIndexOfChild(Object parent, Object child) 91 { 92 AdapterNode node = (AdapterNode) parent; 93 return node.index((AdapterNode) child); 94 } 95 96 public void valueForPathChanged(TreePath path, Object newValue) 97 { 98 /* 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. 102 */ 103 } 104 105 public void addTreeModelListener(TreeModelListener listener) 106 { 107 if ( listener != null 108 && ! m_listenerList.contains( listener ) ) 109 { 110 m_listenerList.addElement( listener ); 111 } 112 } 113 114 public void removeTreeModelListener(TreeModelListener listener) 115 { 116 if ( listener != null ) 117 { 118 m_listenerList.removeElement( listener ); 119 } 120 } 121 122 public void fireTreeNodesChanged( TreeModelEvent e ) 123 { 124 Enumeration listeners = m_listenerList.elements(); 125 while ( listeners.hasMoreElements() ) 126 { 127 TreeModelListener listener = 128 (TreeModelListener) listeners.nextElement(); 129 listener.treeNodesChanged( e ); 130 } 131 } 132 133 public void fireTreeNodesInserted( TreeModelEvent e ) 134 { 135 Enumeration listeners = m_listenerList.elements(); 136 while ( listeners.hasMoreElements() ) 137 { 138 TreeModelListener listener = 139 (TreeModelListener) listeners.nextElement(); 140 listener.treeNodesInserted( e ); 141 } 142 } 143 144 public void fireTreeNodesRemoved( TreeModelEvent e ) 145 { 146 Enumeration listeners = m_listenerList.elements(); 147 while ( listeners.hasMoreElements() ) 148 { 149 TreeModelListener listener = 150 (TreeModelListener) listeners.nextElement(); 151 listener.treeNodesRemoved( e ); 152 } 153 } 154 155 public void fireTreeStructureChanged( TreeModelEvent e ) 156 { 157 Enumeration listeners = m_listenerList.elements(); 158 while ( listeners.hasMoreElements() ) 159 { 160 TreeModelListener listener = 161 (TreeModelListener) listeners.nextElement(); 162 listener.treeStructureChanged( e ); 163 } 164 } 165 } 166 167