GroovyAwareConfigurableSwingWindowDisplayHandler.java
01 /*
02  * Copyright 2008-2016 the original author or authors.
03  *
04  * Licensed under the Apache License, Version 2.0 (the "License");
05  * you may not use this file except in compliance with the License.
06  * You may obtain a copy of the License at
07  *
08  *     http://www.apache.org/licenses/LICENSE-2.0
09  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.codehaus.griffon.runtime.swing;
17 
18 import griffon.core.GriffonApplication;
19 import griffon.swing.SwingWindowDisplayHandler;
20 import groovy.lang.Closure;
21 
22 import javax.annotation.Nonnull;
23 import javax.annotation.Nullable;
24 import javax.inject.Inject;
25 import javax.inject.Named;
26 import java.awt.Window;
27 
28 /**
29  @author Andres Almiray
30  @since 2.0.0
31  */
32 public class GroovyAwareConfigurableSwingWindowDisplayHandler extends ConfigurableSwingWindowDisplayHandler {
33     @Inject
34     public GroovyAwareConfigurableSwingWindowDisplayHandler(@Nonnull GriffonApplication application, @Nonnull @Named("defaultWindowDisplayHandler"SwingWindowDisplayHandler delegateWindowsDisplayHandler) {
35         super(application, delegateWindowsDisplayHandler);
36     }
37 
38     @Override
39     protected boolean canBeRun(@Nullable Object obj) {
40         return obj instanceof Closure || super.canBeRun(obj);
41     }
42 
43     @Override
44     protected void run(@Nonnull Object handler, @Nonnull String name, @Nonnull Window window) {
45         if (handler instanceof Closure) {
46             ((Closurehandler).call(name, window);
47             return;
48         }
49         super.run(handler, name, window);
50     }
51 }