1 25 26 package org.jrobin.inspector; 27 28 import org.jrobin.core.RrdDb; 29 import org.jrobin.core.RrdException; 30 31 import javax.swing.tree.DefaultTreeModel ; 32 import javax.swing.tree.DefaultMutableTreeNode ; 33 import java.io.IOException ; 34 import java.io.File ; 35 36 class MainTreeModel extends DefaultTreeModel { 37 private static final DefaultMutableTreeNode INVALID_NODE = 38 new DefaultMutableTreeNode ("No valid RRD file specified"); 39 40 private File file; 41 42 MainTreeModel() { 43 super(INVALID_NODE); 44 } 45 46 boolean setFile(File newFile) { 47 try { 48 file = newFile; 49 RrdDb rrd = new RrdDb(file.getAbsolutePath()); 50 DefaultMutableTreeNode root = new DefaultMutableTreeNode (new RrdNode(rrd)); 51 int dsCount = rrd.getRrdDef().getDsCount(); 52 int arcCount = rrd.getRrdDef().getArcCount(); 53 for (int dsIndex = 0; dsIndex < dsCount; dsIndex++) { 54 DefaultMutableTreeNode dsNode = 55 new DefaultMutableTreeNode (new RrdNode(rrd, dsIndex)); 56 for (int arcIndex = 0; arcIndex < arcCount; arcIndex++) { 57 DefaultMutableTreeNode arcNode = 58 new DefaultMutableTreeNode (new RrdNode(rrd, dsIndex, arcIndex)); 59 dsNode.add(arcNode); 60 } 61 root.add(dsNode); 62 } 63 rrd.close(); 64 setRoot(root); 65 return true; 66 } catch (IOException e) { 67 setRoot(INVALID_NODE); 68 } catch (RrdException e) { 69 setRoot(INVALID_NODE); 70 } 71 return false; 72 } 73 } 74 | Popular Tags |