View Javadoc
1   /*
2    * *************************************************************************************************************************************************************
3    *
4    * SteelBlue: DCI User Interfaces
5    * http://tidalwave.it/projects/steelblue
6    *
7    * Copyright (C) 2015 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8    *
9    * *************************************************************************************************************************************************************
10   *
11   * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12   * You may obtain a copy of the License at
13   *
14   *     http://www.apache.org/licenses/LICENSE-2.0
15   *
16   * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17   * CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and limitations under the License.
18   *
19   * *************************************************************************************************************************************************************
20   *
21   * git clone https://bitbucket.org/tidalwave/steelblue-src
22   * git clone https://github.com/tidalwave-it/steelblue-src
23   *
24   * *************************************************************************************************************************************************************
25   */
26  package it.tidalwave.ui.example.presentation.impl.javafx;
27  
28  import jakarta.annotation.Nonnull;
29  import java.nio.file.Path;
30  import javafx.fxml.FXML;
31  import javafx.scene.control.Button;
32  import javafx.scene.control.ComboBox;
33  import javafx.scene.control.ListView;
34  import javafx.scene.control.TableView;
35  import javafx.scene.control.TextArea;
36  import javafx.scene.control.TextField;
37  import javafx.scene.control.TreeTableView;
38  import javafx.scene.control.TreeView;
39  import it.tidalwave.util.ui.UserNotificationWithFeedback;
40  import it.tidalwave.ui.core.BoundProperty;
41  import it.tidalwave.ui.core.role.PresentationModel;
42  import it.tidalwave.ui.javafx.JavaFXBinder;
43  import it.tidalwave.ui.example.presentation.MainPanelPresentation;
44  import lombok.RequiredArgsConstructor;
45  import lombok.extern.slf4j.Slf4j;
46  
47  /***************************************************************************************************************************************************************
48   *
49   * The JavaFX controller just works as a dumb object with SteelBlue: it must implement in the most simple way each
50   * method in the presentation interface, by applying simple manipulation to the UI. No logic here, neither presentaton
51   * nor business.
52   *
53   * @author  Fabrizio Giudici
54   *
55   **************************************************************************************************************************************************************/
56  @RequiredArgsConstructor @Slf4j
57  public class JavaFXMainPanelPresentationDelegate implements MainPanelPresentation
58    {
59      // START SNIPPET: fields
60      // This facility provides all the methods to bind JavaFX controls to DCI roles.
61      @Nonnull
62      private final JavaFXBinder binder;
63  
64      @FXML
65      private Button btButton;
66  
67      @FXML
68      private Button btDialogOk;
69  
70      @FXML
71      private Button btDialogOkCancel;
72  
73      @FXML
74      private Button btPickFile;
75  
76      @FXML
77      private Button btPickDirectory;
78  
79      @FXML
80      private TextField tfTextField;
81  
82      @FXML
83      private ListView<PresentationModel> lvListView;
84  
85      @FXML
86      private ComboBox<PresentationModel> cbComboBox;
87  
88      @FXML
89      private TableView<PresentationModel> tvTableView;
90  
91      @FXML
92      private TreeView<PresentationModel> tvTreeView;
93  
94      @FXML
95      private TreeTableView<PresentationModel> ttvTreeTableView;
96  
97      @FXML
98      private TextArea taLog;
99      // END SNIPPET: fields
100 
101     /***********************************************************************************************************************************************************
102      * {@inheritDoc}
103      **********************************************************************************************************************************************************/
104     // START SNIPPET: bind
105     @Override
106     public void bind (@Nonnull final Bindings bindings)
107       {
108         binder.bind(btButton, bindings.actionButton);
109         binder.bind(btDialogOk, bindings.actionDialogOk);
110         binder.bind(btDialogOkCancel, bindings.actionDialogCancelOk);
111         binder.bind(btPickFile, bindings.actionPickFile);
112         binder.bind(btPickDirectory, bindings.actionPickDirectory);
113         binder.bindBidirectionally(tfTextField, bindings.textProperty, bindings.booleanProperty);
114       }
115     // END SNIPPET: bind
116 
117     /***********************************************************************************************************************************************************
118      * {@inheritDoc}
119      **********************************************************************************************************************************************************/
120     // START SNIPPET: populate
121     @Override
122     public void populate (@Nonnull final PresentationModel pmSimpleEntities,
123                           @Nonnull final PresentationModel pmDciEntities,
124                           @Nonnull final PresentationModel pmFileEntities)
125       {
126         binder.bind(lvListView, pmSimpleEntities, () -> log.info("Finished setup of lvListView"));
127         binder.bind(cbComboBox, pmSimpleEntities, () -> log.info("Finished setup of cbComboBox"));
128         binder.bind(tvTableView, pmDciEntities, () -> log.info("Finished setup of tvTableView"));
129         binder.bind(tvTreeView, pmFileEntities, () -> log.info("Finished setup of tvTreeView"));
130         binder.bind(ttvTreeTableView, pmFileEntities, () -> log.info("Finished setup of ttvTreeTableView"));
131       }
132     // END SNIPPET: populate
133 
134     /***********************************************************************************************************************************************************
135      * {@inheritDoc}
136      **********************************************************************************************************************************************************/
137     // START SNIPPET: notify1
138     @Override
139     public void notify (@Nonnull final UserNotificationWithFeedback notification)
140       {
141         binder.showInModalDialog(notification);
142       }
143     // END SNIPPET: notify1
144 
145     /***********************************************************************************************************************************************************
146      * {@inheritDoc}
147      **********************************************************************************************************************************************************/
148     // START SNIPPET: notify2
149     @Override
150     public void notify (@Nonnull final String message)
151       {
152         taLog.appendText(message + "\n");
153       }
154     // END SNIPPET: notify2
155 
156     /***********************************************************************************************************************************************************
157      * {@inheritDoc}
158      **********************************************************************************************************************************************************/
159     // START SNIPPET: pickFile
160     @Override
161     public void pickFile (@Nonnull final BoundProperty<Path> selectedFile,
162                           @Nonnull final UserNotificationWithFeedback notification)
163       {
164         binder.openFileChooserFor(notification, selectedFile);
165       }
166     // END SNIPPET: pickFile
167 
168     /***********************************************************************************************************************************************************
169      * {@inheritDoc}
170      **********************************************************************************************************************************************************/
171     // START SNIPPET: pickDirectory
172     @Override
173     public void pickDirectory (@Nonnull final BoundProperty<Path> selectedFolder,
174                                @Nonnull final UserNotificationWithFeedback notification)
175       {
176         binder.openDirectoryChooserFor(notification, selectedFolder);
177       }
178     // END SNIPPET: pickDirectory
179   }