/**
* GRANITE DATA SERVICES
* Copyright (C) 2006-2015 GRANITE DATA SERVICES S.A.S.
*
* This file is part of the Granite Data Services Platform.
*
* ***
*
* Community License: GPL 3.0
*
* This file is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ***
*
* Available Commercial License: GraniteDS SLA 1.0
*
* This is the appropriate option if you are creating proprietary
* applications and you are not prepared to distribute and share the
* source code of your application under the GPL v3 license.
*
* Please visit http://www.granitedataservices.com/license for more
* details.
*/
package org.granite.client.javafx.tide;
import java.util.Map;
import javafx.application.Application;
import javafx.stage.Stage;
import javax.validation.TraversableResolver;
import javax.validation.ValidatorFactory;
import org.granite.client.tide.Context;
import org.granite.client.tide.data.spi.DataManager;
import org.granite.client.tide.server.ServerSession;
import org.granite.client.validation.NotifyingValidation;
import org.granite.logging.Logger;
/**
* @author William DRAI
*/
public class JavaFXApplication implements org.granite.client.tide.Application {
private static final Logger log = Logger.getLogger(JavaFXApplication.class);
private final Application application;
private final Stage stage;
public JavaFXApplication() {
this.application = null;
this.stage = null;
}
public JavaFXApplication(Application application, Stage stage) {
this.application = application;
this.stage = stage;
}
public void initContext(Context context, Map<String, Object> initialBeans) {
DataManager dataManager = new JavaFXDataManager();
context.setDataManager(dataManager);
if (application != null)
initialBeans.put(Application.class.getName(), application);
if (stage != null)
initialBeans.put(Stage.class.getName(), stage);
try {
new BeanValidationConfiguration().configure(context, initialBeans);
}
catch (Throwable e) {
// Assume Bean Validation not available
log.info("Bean validation not available, support not configured");
}
}
public void configure(Object instance) {
if (instance instanceof ServerSession)
((ServerSession)instance).setStatus(new JavaFXServerSessionStatus(stage));
}
@Override
public void execute(Object platformContext, Runnable runnable) {
javafx.application.Platform.runLater(runnable);
}
private static final class BeanValidationConfiguration {
public void configure(Context context, Map<String, Object> initialBeans) {
TraversableResolver traversableResolver = new JavaFXTraversableResolver(context.getDataManager());
ValidatorFactory validatorFactory = NotifyingValidation.byDefaultProvider().configure().traversableResolver(traversableResolver).buildValidatorFactory();
initialBeans.put(TraversableResolver.class.getName(), traversableResolver);
initialBeans.put(ValidatorFactory.class.getName(), validatorFactory);
}
}
}