hotspot/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java
changeset 768 d0bebc7eefc2
child 1497 cd3234c89e59
equal deleted inserted replaced
767:64fb1fd7186d 768:d0bebc7eefc2
       
     1 /*
       
     2  * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  *
       
    23  */
       
    24 package com.sun.hotspot.igv.coordinator;
       
    25 
       
    26 import com.sun.hotspot.igv.coordinator.actions.RemoveCookie;
       
    27 import com.sun.hotspot.igv.data.Group;
       
    28 import com.sun.hotspot.igv.data.services.GroupOrganizer;
       
    29 import com.sun.hotspot.igv.data.InputGraph;
       
    30 import com.sun.hotspot.igv.data.Pair;
       
    31 import java.awt.Image;
       
    32 import java.util.ArrayList;
       
    33 import java.util.List;
       
    34 import org.openide.nodes.AbstractNode;
       
    35 import org.openide.nodes.Children;
       
    36 import org.openide.nodes.Node;
       
    37 import org.openide.util.Utilities;
       
    38 import org.openide.util.lookup.AbstractLookup;
       
    39 import org.openide.util.lookup.InstanceContent;
       
    40 
       
    41 /**
       
    42  *
       
    43  * @author Thomas Wuerthinger
       
    44  */
       
    45 public class FolderNode extends AbstractNode {
       
    46 
       
    47     private GroupOrganizer organizer;
       
    48     private InstanceContent content;
       
    49     private List<Pair<String, List<Group>>> structure;
       
    50     private List<String> subFolders;
       
    51     private FolderChildren children;
       
    52 
       
    53     private static class FolderChildren extends Children.Keys {
       
    54 
       
    55         private FolderNode parent;
       
    56 
       
    57         public void setParent(FolderNode parent) {
       
    58             this.parent = parent;
       
    59         }
       
    60 
       
    61         @Override
       
    62         protected Node[] createNodes(Object arg0) {
       
    63 
       
    64             Pair<String, List<Group>> p = (Pair<String, List<Group>>) arg0;
       
    65             if (p.getLeft().length() == 0) {
       
    66 
       
    67                 List<Node> curNodes = new ArrayList<Node>();
       
    68                 for (Group g : p.getRight()) {
       
    69                     for (InputGraph graph : g.getGraphs()) {
       
    70                         curNodes.add(new GraphNode(graph));
       
    71                     }
       
    72                 }
       
    73 
       
    74                 Node[] result = new Node[curNodes.size()];
       
    75                 for (int i = 0; i < curNodes.size(); i++) {
       
    76                     result[i] = curNodes.get(i);
       
    77                 }
       
    78                 return result;
       
    79 
       
    80             } else {
       
    81                 return new Node[]{new FolderNode(p.getLeft(), parent.organizer, parent.subFolders, p.getRight())};
       
    82             }
       
    83         }
       
    84 
       
    85         @Override
       
    86         public void addNotify() {
       
    87             this.setKeys(parent.structure);
       
    88 
       
    89         }
       
    90     }
       
    91 
       
    92     protected InstanceContent getContent() {
       
    93         return content;
       
    94     }
       
    95 
       
    96     @Override
       
    97     public Image getIcon(int i) {
       
    98         return Utilities.loadImage("com/sun/hotspot/igv/coordinator/images/folder.gif");
       
    99     }
       
   100 
       
   101     protected FolderNode(String name, GroupOrganizer organizer, List<String> subFolders, List<Group> groups) {
       
   102         this(name, organizer, subFolders, groups, new FolderChildren(), new InstanceContent());
       
   103     }
       
   104 
       
   105     private FolderNode(String name, GroupOrganizer organizer, List<String> oldSubFolders, final List<Group> groups, FolderChildren children, InstanceContent content) {
       
   106         super(children, new AbstractLookup(content));
       
   107         children.setParent(this);
       
   108         this.content = content;
       
   109         this.children = children;
       
   110         content.add(new RemoveCookie() {
       
   111 
       
   112             public void remove() {
       
   113                 for (Group g : groups) {
       
   114                     if (g.getDocument() != null) {
       
   115                         g.getDocument().removeGroup(g);
       
   116                     }
       
   117                 }
       
   118             }
       
   119         });
       
   120         init(name, organizer, oldSubFolders, groups);
       
   121     }
       
   122 
       
   123     public void init(String name, GroupOrganizer organizer, List<String> oldSubFolders, List<Group> groups) {
       
   124         this.setDisplayName(name);
       
   125         this.organizer = organizer;
       
   126         this.subFolders = new ArrayList<String>(oldSubFolders);
       
   127         if (name.length() > 0) {
       
   128             this.subFolders.add(name);
       
   129         }
       
   130         structure = organizer.organize(subFolders, groups);
       
   131         assert structure != null;
       
   132         children.addNotify();
       
   133     }
       
   134 
       
   135     @Override
       
   136     public Image getOpenedIcon(int i) {
       
   137         return getIcon(i);
       
   138     }
       
   139 }