1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package com.sun.star.xml.security.uno; 25 26 import org.w3c.dom.Document; 27 import javax.swing.event.TreeModelListener; 28 import javax.swing.event.TreeModelEvent; 29 import javax.swing.tree.TreePath; 30 import java.util.Enumeration; 31 import java.util.Vector; 32 33 /* 34 * This adapter converts the current Document (a DOM) into 35 * a JTree model. 36 */ 37 class DomToTreeModelAdapter 38 implements javax.swing.tree.TreeModel 39 { 40 private Document m_document; 41 private Vector m_listenerList = new Vector(); 42 DomToTreeModelAdapter(Document document)43 public DomToTreeModelAdapter(Document document) 44 { 45 m_document = document; 46 } 47 48 /* 49 * Basic TreeModel operations 50 */ getRoot()51 public Object getRoot() 52 { 53 return new AdapterNode(m_document); 54 } 55 isLeaf(Object aNode)56 public boolean isLeaf(Object aNode) 57 { 58 boolean rc = true; 59 60 /* 61 * Determines whether the icon shows up to the left. 62 * Return true for any node with no children. 63 */ 64 AdapterNode node = (AdapterNode) aNode; 65 66 if (node.childCount() > 0) 67 { 68 rc = false; 69 } 70 71 return rc; 72 } 73 getChildCount(Object parent)74 public int getChildCount(Object parent) 75 { 76 AdapterNode node = (AdapterNode) parent; 77 return node.childCount(); 78 } 79 getChild(Object parent, int index)80 public Object getChild(Object parent, int index) 81 { 82 AdapterNode node = (AdapterNode) parent; 83 return node.child(index); 84 } 85 getIndexOfChild(Object parent, Object child)86 public int getIndexOfChild(Object parent, Object child) 87 { 88 AdapterNode node = (AdapterNode) parent; 89 return node.index((AdapterNode) child); 90 } 91 valueForPathChanged(TreePath path, Object newValue)92 public void valueForPathChanged(TreePath path, Object newValue) 93 { 94 /* 95 * Null. We won't be making changes in the GUI 96 * If we did, we would ensure the new value was really new, 97 * adjust the model, and then fire a TreeNodesChanged event. 98 */ 99 } 100 addTreeModelListener(TreeModelListener listener)101 public void addTreeModelListener(TreeModelListener listener) 102 { 103 if ( listener != null 104 && ! m_listenerList.contains( listener ) ) 105 { 106 m_listenerList.addElement( listener ); 107 } 108 } 109 removeTreeModelListener(TreeModelListener listener)110 public void removeTreeModelListener(TreeModelListener listener) 111 { 112 if ( listener != null ) 113 { 114 m_listenerList.removeElement( listener ); 115 } 116 } 117 fireTreeNodesChanged( TreeModelEvent e )118 public void fireTreeNodesChanged( TreeModelEvent e ) 119 { 120 Enumeration listeners = m_listenerList.elements(); 121 while ( listeners.hasMoreElements() ) 122 { 123 TreeModelListener listener = 124 (TreeModelListener) listeners.nextElement(); 125 listener.treeNodesChanged( e ); 126 } 127 } 128 fireTreeNodesInserted( TreeModelEvent e )129 public void fireTreeNodesInserted( TreeModelEvent e ) 130 { 131 Enumeration listeners = m_listenerList.elements(); 132 while ( listeners.hasMoreElements() ) 133 { 134 TreeModelListener listener = 135 (TreeModelListener) listeners.nextElement(); 136 listener.treeNodesInserted( e ); 137 } 138 } 139 fireTreeNodesRemoved( TreeModelEvent e )140 public void fireTreeNodesRemoved( TreeModelEvent e ) 141 { 142 Enumeration listeners = m_listenerList.elements(); 143 while ( listeners.hasMoreElements() ) 144 { 145 TreeModelListener listener = 146 (TreeModelListener) listeners.nextElement(); 147 listener.treeNodesRemoved( e ); 148 } 149 } 150 fireTreeStructureChanged( TreeModelEvent e )151 public void fireTreeStructureChanged( TreeModelEvent e ) 152 { 153 Enumeration listeners = m_listenerList.elements(); 154 while ( listeners.hasMoreElements() ) 155 { 156 TreeModelListener listener = 157 (TreeModelListener) listeners.nextElement(); 158 listener.treeStructureChanged( e ); 159 } 160 } 161 } 162 163