Mercurial > hg > truffle
comparison visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterNode.java @ 4512:015fb895586b
Moved visualizer to new directory.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 07 Feb 2012 22:41:09 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4511:6cb549627941 | 4512:015fb895586b |
---|---|
1 /* | |
2 * Copyright (c) 2008, 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.filterwindow; | |
25 | |
26 import com.sun.hotspot.igv.data.ChangedListener; | |
27 import com.sun.hotspot.igv.filter.Filter; | |
28 import com.sun.hotspot.igv.filter.FilterChain; | |
29 import com.sun.hotspot.igv.filterwindow.actions.MoveFilterDownAction; | |
30 import com.sun.hotspot.igv.filterwindow.actions.MoveFilterUpAction; | |
31 import com.sun.hotspot.igv.filterwindow.actions.RemoveFilterAction; | |
32 import com.sun.hotspot.igv.util.PropertiesSheet; | |
33 import javax.swing.Action; | |
34 import org.openide.actions.OpenAction; | |
35 import org.openide.nodes.Children; | |
36 import org.openide.nodes.Sheet; | |
37 import org.openide.util.Lookup; | |
38 import org.openide.util.LookupEvent; | |
39 import org.openide.util.LookupListener; | |
40 import org.openide.util.Utilities; | |
41 import org.openide.util.lookup.AbstractLookup; | |
42 import org.openide.util.lookup.InstanceContent; | |
43 | |
44 /** | |
45 * | |
46 * @author Thomas Wuerthinger | |
47 */ | |
48 public class FilterNode extends CheckNode implements LookupListener, ChangedListener<FilterTopComponent> { | |
49 | |
50 private Filter filter; | |
51 private Lookup.Result<FilterChain> result; | |
52 | |
53 public FilterNode(Filter filter) { | |
54 this(filter, new InstanceContent()); | |
55 } | |
56 | |
57 private FilterNode(Filter filter, InstanceContent content) { | |
58 super(Children.LEAF, new AbstractLookup(content)); | |
59 content.add(filter); | |
60 | |
61 content.add(filter.getEditor()); | |
62 this.filter = filter; | |
63 filter.getChangedEvent().addListener(new ChangedListener<Filter>() { | |
64 | |
65 @Override | |
66 public void changed(Filter source) { | |
67 update(); | |
68 } | |
69 }); | |
70 | |
71 update(); | |
72 | |
73 Lookup.Template<FilterChain> tpl = new Lookup.Template<>(FilterChain.class); | |
74 result = Utilities.actionsGlobalContext().lookup(tpl); | |
75 result.addLookupListener(this); | |
76 | |
77 FilterTopComponent.findInstance().getFilterSettingsChangedEvent().addListener(this); | |
78 resultChanged(null); | |
79 | |
80 setShortDescription("Double-click to open filter"); | |
81 } | |
82 | |
83 private void update() { | |
84 this.setDisplayName(filter.getName()); | |
85 } | |
86 | |
87 public Filter getFilter() { | |
88 return filter; | |
89 } | |
90 | |
91 @Override | |
92 protected Sheet createSheet() { | |
93 Sheet s = super.createSheet(); | |
94 PropertiesSheet.initializeSheet(getFilter().getProperties(), s); | |
95 return s; | |
96 } | |
97 | |
98 @Override | |
99 public Action[] getActions(boolean b) { | |
100 return new Action[]{(Action) OpenAction.findObject(OpenAction.class, true), (Action) MoveFilterUpAction.findObject(MoveFilterUpAction.class, true), (Action) MoveFilterDownAction.findObject(MoveFilterDownAction.class, true), (Action) RemoveFilterAction.findObject(RemoveFilterAction.class, true)}; | |
101 } | |
102 | |
103 @Override | |
104 public Action getPreferredAction() { | |
105 return OpenAction.get(OpenAction.class).createContextAwareInstance(Utilities.actionsGlobalContext()); | |
106 } | |
107 | |
108 @Override | |
109 public void resultChanged(LookupEvent lookupEvent) { | |
110 changed(FilterTopComponent.findInstance()); | |
111 } | |
112 | |
113 @Override | |
114 public void changed(FilterTopComponent source) { | |
115 setSelected(source.getFilterChain().containsFilter(filter)); | |
116 } | |
117 } |