1
1
/*
2
- * Copyright (c) 2009-2010 jMonkeyEngine
2
+ * Copyright (c) 2009-2016 jMonkeyEngine
3
3
* All rights reserved.
4
4
*
5
5
* Redistribution and use in source and binary forms, with or without
45
45
import java .util .List ;
46
46
import java .util .concurrent .Callable ;
47
47
import java .util .concurrent .ExecutionException ;
48
+ import java .util .logging .Level ;
49
+ import java .util .logging .Logger ;
48
50
import javax .swing .Action ;
49
51
import org .openide .nodes .AbstractNode ;
50
52
import org .openide .nodes .Children ;
63
65
public class FilterPostProcessorNode extends AbstractNode {
64
66
65
67
private FilterDataObject dataObject ;
66
- private static Image smallImage = IconList .eyeOpen .getImage ();
68
+ private final static Image smallImage = IconList .eyeOpen .getImage ();
67
69
private FilterPostProcessor fpp ;
70
+ private static final Logger logger = Logger .getLogger (FilterPostProcessorNode .class .getName ());
68
71
69
72
public FilterPostProcessorNode (FilterDataObject dataObject ) {
70
73
super (new FilterChildren (dataObject ), Lookups .singleton (new FilterIndexSupport ()));
@@ -74,7 +77,6 @@ public FilterPostProcessorNode(FilterDataObject dataObject) {
74
77
setName (dataObject .getName ());
75
78
getLookup ().lookup (FilterIndexSupport .class ).setFilterPostProcessorNode (this );
76
79
((FilterChildren ) getChildren ()).setFilterPostProcessorNode (this );
77
-
78
80
}
79
81
80
82
@ Override
@@ -89,7 +91,9 @@ public Image getOpenedIcon(int type) {
89
91
90
92
public FilterPostProcessor getFilterPostProcessor () {
91
93
if (fpp == null ) {
92
- this .fpp = dataObject .loadAsset ();
94
+ fpp = dataObject .loadAsset ();
95
+ if (fpp == null )
96
+ logger .log (Level .SEVERE , "Cannot load Filter. Maybe it's not in the Asset Path?" );
93
97
}
94
98
return fpp ;
95
99
}
@@ -130,7 +134,9 @@ public void addFilter(final Filter filter) {
130
134
SceneApplication .getApplication ().enqueue (new Callable <Object >() {
131
135
132
136
public Object call () throws Exception {
133
- getFilterPostProcessor ().addFilter (filter );
137
+ FilterPostProcessor fp = getFilterPostProcessor ();
138
+ if (fp != null )
139
+ fp .addFilter (filter );
134
140
return null ;
135
141
}
136
142
});
@@ -142,7 +148,10 @@ public void removeFilter(final Filter filter) {
142
148
SceneApplication .getApplication ().enqueue (new Callable <Object >() {
143
149
144
150
public Object call () throws Exception {
145
- getFilterPostProcessor ().removeFilter (filter );
151
+ FilterPostProcessor fp = getFilterPostProcessor ();
152
+ if (fp != null )
153
+ fp .removeFilter (filter );
154
+
146
155
return null ;
147
156
}
148
157
});
@@ -163,8 +172,8 @@ public void run() {
163
172
public Action [] getActions (boolean context ) {
164
173
// return super.getActions(context);
165
174
return new Action []{
166
- new NewFilterPopup (this )
167
- };
175
+ new NewFilterPopup (this )
176
+ };
168
177
}
169
178
170
179
public static class FilterChildren extends Children .Keys <Object > {
@@ -184,7 +193,9 @@ public void setFilterPostProcessorNode(FilterPostProcessorNode node) {
184
193
@ Override
185
194
protected void addNotify () {
186
195
super .addNotify ();
187
- setKeys (createKeys ());
196
+ List <Object > keys = createKeys ();
197
+ if (keys != null )
198
+ setKeys (keys );
188
199
}
189
200
190
201
protected void doRefresh () {
@@ -201,7 +212,11 @@ protected List<Object> createKeys() {
201
212
202
213
public List <Object > call () throws Exception {
203
214
List <Object > keys = new LinkedList <Object >();
204
- for (Iterator it = node .getFilterPostProcessor ().getFilterIterator (); it .hasNext ();) {
215
+ FilterPostProcessor fp = node .getFilterPostProcessor ();
216
+ if (fp == null ) /* e.g. Filter not in Asset Path */
217
+ return null ;
218
+
219
+ for (Iterator it = fp .getFilterIterator (); it .hasNext ();) {
205
220
Filter filter = (Filter ) it .next ();
206
221
keys .add (filter );
207
222
}
@@ -219,10 +234,15 @@ public List<Object> call() throws Exception {
219
234
@ Override
220
235
protected Node [] createNodes (Object t ) {
221
236
Filter filter = (Filter ) t ;
222
- //get JmeFilter, the only FilterNode spi
223
- FilterNode di = Lookup .getDefault ().lookup (FilterNode .class );
224
- Node [] ret = di .createNodes (filter , dataObject , readOnly );
225
- return ret ;
237
+ for (FilterNode di : Lookup .getDefault ().lookupAll (FilterNode .class )) {
238
+ if (di .getExplorerObjectClass ().getName ().equals (filter .getClass ().getName ())) {
239
+ Node [] ret = di .createNodes (filter , dataObject , readOnly );
240
+ if (ret != null ) {
241
+ return ret ;
242
+ }
243
+ }
244
+ }
245
+ return new Node []{};
226
246
}
227
247
}
228
248
}
0 commit comments