001package conexp.fx.gui.assistent;
002
003import com.google.common.base.Function;
004
005/*
006 * #%L
007 * Concept Explorer FX
008 * %%
009 * Copyright (C) 2010 - 2023 Francesco Kriegel
010 * %%
011 * This program is free software: you can redistribute it and/or modify
012 * it under the terms of the GNU General Public License as
013 * published by the Free Software Foundation, either version 3 of the
014 * License, or (at your option) any later version.
015 * 
016 * This program is distributed in the hope that it will be useful,
017 * but WITHOUT ANY WARRANTY; without even the implied warranty of
018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
019 * GNU General Public License for more details.
020 * 
021 * You should have received a copy of the GNU General Public
022 * License along with this program.  If not, see
023 * <http://www.gnu.org/licenses/gpl-3.0.html>.
024 * #L%
025 */
026
027
028import javafx.beans.binding.StringBinding;
029import javafx.beans.property.ObjectProperty;
030import javafx.beans.property.SimpleObjectProperty;
031import javafx.beans.property.SimpleStringProperty;
032import javafx.beans.property.StringProperty;
033import javafx.scene.Node;
034
035public abstract class AssistentPage<T>
036{
037  public final StringProperty       titleProperty;
038  public final StringProperty       textProperty;
039  public final ObjectProperty<Node> contentProperty;
040  public final ObjectProperty<T>    resultProperty = new SimpleObjectProperty<T>();
041  public final StringBinding        nextPageIdBinding;
042
043  public AssistentPage(
044      final String title,
045      final String text,
046      final Node content,
047      final Function<T, String> nextPageIdFunction)
048  {
049    super();
050    this.titleProperty = new SimpleStringProperty(title);
051    this.textProperty = new SimpleStringProperty(text);
052    this.contentProperty = new SimpleObjectProperty<Node>(content);
053    this.nextPageIdBinding = new StringBinding()
054    {
055      {
056        super.bind(resultProperty);
057      }
058
059      @Override
060      protected String computeValue()
061      {
062        if (nextPageIdFunction == null || resultProperty.isNull().get())
063          return null;
064        return nextPageIdFunction.apply(resultProperty.get());
065      }
066    };
067  }
068
069  protected abstract void onNext();
070}