001package conexp.fx.gui.assistent;
002
003import com.google.common.base.Function;
004import com.google.common.base.Predicate;
005import com.google.common.collect.Collections2;
006
007import conexp.fx.core.builder.Requests.Metatype;
008import conexp.fx.core.builder.Requests.Type;
009import conexp.fx.gui.ConExpFX;
010
011/*
012 * #%L
013 * Concept Explorer FX
014 * %%
015 * Copyright (C) 2010 - 2023 Francesco Kriegel
016 * %%
017 * This program is free software: you can redistribute it and/or modify
018 * it under the terms of the GNU General Public License as
019 * published by the Free Software Foundation, either version 3 of the
020 * License, or (at your option) any later version.
021 * 
022 * This program is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
025 * GNU General Public License for more details.
026 * 
027 * You should have received a copy of the GNU General Public
028 * License along with this program.  If not, see
029 * <http://www.gnu.org/licenses/gpl-3.0.html>.
030 * #L%
031 */
032
033import javafx.beans.binding.ObjectBinding;
034import javafx.scene.Node;
035import javafx.scene.control.Accordion;
036import javafx.scene.control.RadioButton;
037import javafx.scene.control.RadioButtonBuilder;
038import javafx.scene.control.TitledPaneBuilder;
039import javafx.scene.control.Toggle;
040import javafx.scene.control.ToggleGroup;
041import javafx.scene.layout.VBoxBuilder;
042import javafx.scene.text.FontBuilder;
043
044@SuppressWarnings("deprecation")
045public class ConstructAssistent extends Assistent<Type> {
046
047  private final Accordion accordion = new Accordion();
048
049  public ConstructAssistent() {
050    super(
051        ConExpFX.instance.primaryStage,
052        "Construction Wizard",
053        "Construct a new context",
054        "Choose a construction type",
055        null,
056        new Function<Type, String>() {
057
058          @Override
059          public String apply(Type constructionType) {
060            return constructionType.toString();
061          }
062        });
063    initialize();
064  }
065
066  @Override
067  protected final Node createInitialNode() {
068    final ToggleGroup radioGroup = new ToggleGroup();
069    for (Type constructionType : Type.values()) {
070      final RadioButton radioButton =
071          RadioButtonBuilder
072              .create()
073              .userData(constructionType)
074              .text(constructionType.title)
075              .font(FontBuilder.create().size(16).build())
076              .build();
077      radioGroup.getToggles().add(radioButton);
078    }
079    resultProperty.bind(new ObjectBinding<Type>() {
080
081      {
082        super.bind(radioGroup.selectedToggleProperty());
083      }
084
085      @Override
086      protected Type computeValue() {
087        if (radioGroup.selectedToggleProperty().get() == null)
088          return null;
089        return (Type) radioGroup.selectedToggleProperty().get().getUserData();
090      }
091    });
092    for (final Metatype constructionMetatype : Metatype.values())
093//      if (constructionMetatype != Metatype.OTHER)
094      accordion.getPanes().add(
095          TitledPaneBuilder
096              .create()
097              .text(constructionMetatype.title)
098              .font(FontBuilder.create().size(16).build())
099              .content(
100                  VBoxBuilder
101                      .create()
102                      .children(
103                          Collections2.filter(
104                              Collections2.transform(radioGroup.getToggles(), new Function<Toggle, RadioButton>() {
105
106                                @Override
107                                public RadioButton apply(Toggle toggle) {
108                                  return (RadioButton) toggle;
109                                }
110                              }),
111                              new Predicate<RadioButton>() {
112
113                                @Override
114                                public boolean apply(RadioButton radioButton) {
115                                  return ((Type) radioButton.getUserData()).type.equals(constructionMetatype);
116                                }
117                              }))
118                      .build())
119              .build());
120    accordion.setExpandedPane(accordion.getPanes().get(0));
121    return accordion;
122  }
123
124  @Override
125  protected final void createPages() {
126    for (Type type : Type.values())
127//      if (type.type != Metatype.OTHER)
128      availablePages.put(type.toString(), new TypePage(type));
129  }
130
131  @Override
132  protected void onNext() {}
133}