| 
01 /*02  * Copyright 2008-2015 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.javafx;
 17
 18 import griffon.core.GriffonApplication;
 19 import griffon.exceptions.InstanceNotFoundException;
 20 import griffon.javafx.JavaFXWindowDisplayHandler;
 21 import javafx.stage.Window;
 22 import org.codehaus.griffon.runtime.core.view.ConfigurableWindowDisplayHandler;
 23 import org.slf4j.Logger;
 24 import org.slf4j.LoggerFactory;
 25
 26 import javax.annotation.Nonnull;
 27 import javax.inject.Inject;
 28 import javax.inject.Named;
 29
 30 import static griffon.util.AnnotationUtils.named;
 31
 32 /**
 33  * @author Andres Almiray
 34  * @since 2.0.0
 35  */
 36 public class ConfigurableJavaFXWindowDisplayHandler extends ConfigurableWindowDisplayHandler<Window> implements JavaFXWindowDisplayHandler {
 37     private static final Logger LOG = LoggerFactory.getLogger(ConfigurableJavaFXWindowDisplayHandler.class);
 38
 39     @Inject
 40     public ConfigurableJavaFXWindowDisplayHandler(@Nonnull GriffonApplication application, @Nonnull @Named("defaultWindowDisplayHandler") JavaFXWindowDisplayHandler delegateWindowsDisplayHandler) {
 41         super(application, delegateWindowsDisplayHandler);
 42     }
 43
 44     @Nonnull
 45     protected JavaFXWindowDisplayHandler fetchDefaultWindowDisplayHandler() {
 46         Object handler = windowManagerBlock().get("defaultHandler");
 47         return (JavaFXWindowDisplayHandler) (handler instanceof JavaFXWindowDisplayHandler ? handler : getDelegateWindowsDisplayHandler());
 48     }
 49
 50     @Override
 51     protected boolean handleShowByInjectedHandler(@Nonnull String name, @Nonnull Window window) {
 52         try {
 53             JavaFXWindowDisplayHandler handler = getApplication().getInjector()
 54                 .getInstance(JavaFXWindowDisplayHandler.class, named(name));
 55             LOG.trace("Showing {} with injected handler", name);
 56             handler.show(name, window);
 57             return true;
 58         } catch (InstanceNotFoundException infe) {
 59             return super.handleShowByInjectedHandler(name, window);
 60         }
 61     }
 62
 63     @Override
 64     protected boolean handleHideByInjectedHandler(@Nonnull String name, @Nonnull Window window) {
 65         try {
 66             JavaFXWindowDisplayHandler handler = getApplication().getInjector()
 67                 .getInstance(JavaFXWindowDisplayHandler.class, named(name));
 68             LOG.trace("Hiding {} with injected handler", name);
 69             handler.hide(name, window);
 70             return true;
 71         } catch (InstanceNotFoundException infe) {
 72             return super.handleHideByInjectedHandler(name, window);
 73         }
 74     }
 75 }
 |