1 /* 2 * Copyright (c) 2008, 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * 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.*; 28 import com.sun.hotspot.igv.util.PropertiesSheet; 29 import java.awt.Image; 30 import java.util.List; 31 import org.openide.nodes.AbstractNode; 32 import org.openide.nodes.Children; 33 import org.openide.nodes.Node; 34 import org.openide.nodes.Sheet; 35 import org.openide.util.ImageUtilities; 36 import org.openide.util.lookup.AbstractLookup; 37 import org.openide.util.lookup.InstanceContent; 38 39 /** 40 * 41 * @author Thomas Wuerthinger 42 */ 43 public class FolderNode extends AbstractNode { 44 45 private InstanceContent content; 46 private FolderChildren children; 47 48 private static class FolderChildren extends Children.Keys<FolderElement> implements ChangedListener { 49 50 private final Folder folder; 51 52 public FolderChildren(Folder folder) { 53 this.folder = folder; 54 folder.getChangedEvent().addListener(this); 55 } 56 57 @Override 58 protected Node[] createNodes(FolderElement e) { 59 if (e instanceof InputGraph) { 60 return new Node[]{new GraphNode((InputGraph) e)}; 61 } else if (e instanceof Folder) { 62 return new Node[]{new FolderNode((Folder) e)}; 63 } else { 64 return null; 65 } 66 } 67 68 @Override 69 public void addNotify() { 70 this.setKeys(folder.getElements()); 71 } 72 73 @Override 74 public void changed(Object source) { 75 addNotify(); 76 } 77 } 78 79 @Override 80 protected Sheet createSheet() { 81 Sheet s = super.createSheet(); 82 if (children.folder instanceof Properties.Entity) { 83 Properties.Entity p = (Properties.Entity) children.folder; 84 PropertiesSheet.initializeSheet(p.getProperties(), s); 85 } 86 return s; 87 } 88 89 @Override 90 public Image getIcon(int i) { 91 return ImageUtilities.loadImage("com/sun/hotspot/igv/coordinator/images/folder.png"); 92 } 93 94 protected FolderNode(Folder folder) { 95 this(folder, new FolderChildren(folder), new InstanceContent()); 96 } 97 98 private FolderNode(final Folder folder, FolderChildren children, InstanceContent content) { 99 super(children, new AbstractLookup(content)); 100 this.content = content; 101 this.children = children; 102 if (folder instanceof FolderElement) { 103 final FolderElement folderElement = (FolderElement) folder; 104 this.setDisplayName(folderElement.getName()); 105 content.add(new RemoveCookie() { 106 @Override 107 public void remove() { 108 folderElement.getParent().removeElement(folderElement); 109 } 110 }); 111 } 112 } 113 114 public void init(String name, List<Group> groups) { 115 this.setDisplayName(name); 116 children.addNotify(); 117 118 for (Group g : groups) { 119 content.add(g); 120 } 121 } 122 123 @Override 124 public Image getOpenedIcon(int i) { 125 return getIcon(i); 126 } 127 }