View Javadoc
1   /*
2    * Copyright 2013-2023 Medical Information Systems Research Group (https://medical.zcu.cz),
3    * Department of Computer Science and Engineering, University of West Bohemia.
4    * Address: Univerzitni 8, 306 14 Plzen, Czech Republic.
5    *
6    * This file is part of Sparkle project.
7    *
8    * Sparkle is free software: you can redistribute it and/or modify
9    * it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation, either version 3 of the License.
11   *
12   * Sparkle is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with Sparkle. If not, see <http://www.gnu.org/licenses/>.
19   */
20  package cz.zcu.mre.sparkle.gui.evaluation;
21  
22  import cz.zcu.mre.sparkle.Messages;
23  import cz.zcu.mre.sparkle.data.DataAgent;
24  import cz.zcu.mre.sparkle.data.PrefixesStorage;
25  import cz.zcu.mre.sparkle.gui.query.QueryTab;
26  import cz.zcu.mre.sparkle.gui.tools.ReferenceKeeper;
27  import javafx.beans.property.ReadOnlyBooleanProperty;
28  import javafx.scene.control.ProgressIndicator;
29  import javafx.scene.control.Tab;
30  
31  /**
32   * Základ pro kontrolery komponenty představující záložku obsahující nějakou z
33   * instancí {@link EvaluationPane}. V záložce s kontrolerem typu
34   * {@link EvaluationTab} probíhá vyhodnocování konkrétního dotazu pocházejícího
35   * ze záložky typu {@link QueryTab}.
36   *
37   * @param <T> tab type.
38   *
39   * @author Jan Smucr
40   * @author Klara Hlavacova
41   * @author Petr Vcelak (vcelak@kiv.zcu.cz)
42   */
43  public abstract class EvaluationTab<T>
44          extends Tab
45          implements EvaluatorTab {
46  
47      public static final String EVALUATION_TAB_ID = "evaluationTab";//$NON-NLS-1$
48  
49      /**
50       * Komponenta indikující probíhající vyhodnocování zobrazená na místě ikony
51       * záložky.
52       */
53      private final ProgressIndicator progressIndicator;
54      /**
55       * Záložka s dotazem, pod kterou tato záložka spadá.
56       */
57      private final QueryTab<T> parent;
58      /**
59       * Obsah této záložky.
60       */
61      private final EvaluationPane<T> pane;
62      private final ReferenceKeeper keeper = new ReferenceKeeper();
63      // private DataAgent dataAgent;
64      private final PrefixesStorage prefixesStorage;
65  
66      protected EvaluationTab(final QueryTab<T> parent) {
67          this.parent = parent;
68  
69          this.prefixesStorage = parent.getQueryFormPane().getQueryPrefixesStorage();
70  
71          progressIndicator = new ProgressIndicator(-1);
72          progressIndicator.setPrefSize(14, 14);
73  
74          setText(Messages.getString("EVALUATION_TAB_SUFFIX"));
75          //setClosable(true);
76          pane = getEvaluationPane();
77  
78          setOnCloseRequest((e) -> pane.cancelEvaluation());
79          setContent(pane);
80  
81          // Automatické skrývání a zobrazování progressIndicator
82          pane.evaluatingProperty().addListener(keeper.toWeak((observable, oldValue, newValue) -> {
83              if (newValue) {
84                  showProgressIndicator();
85              } else {
86                  hideProgressIndicator();
87              }
88          }));
89  
90      }
91  
92      private void showProgressIndicator() {
93          setGraphic(progressIndicator);
94      }
95  
96      private void hideProgressIndicator() {
97          setGraphic(null);
98      }
99  
100     public final QueryTab<T> getQueryTab() {
101         return parent;
102     }
103 
104     @Override
105     public final void evaluate(DataAgent dataAgent) {
106         pane.evaluate(dataAgent);
107     }
108 
109     /**
110      * Spustí vyhodnocování předaného dotazu.
111      *
112      * @param queryString Znění dotazu.
113      * @param dataAgent Data agent.
114      */
115     public final void evaluate(final String queryString, DataAgent dataAgent) {
116         pane.evaluate(queryString, dataAgent);
117     }
118 
119     @Override
120     public void stopEvaluating() {
121         pane.cancelEvaluation();
122     }
123 
124     @Override
125     public ReadOnlyBooleanProperty evaluatingProperty() {
126         return pane.evaluatingProperty();
127     }
128 
129     /**
130      * Učiní záložku aktivní.
131      */
132     public final void select() {
133         getTabPane().getSelectionModel().select(this);
134     }
135 
136     public final PrefixesStorage getPrefixesStorage() {
137         return prefixesStorage;
138     }
139 
140     /**
141      * @return Obsah záložky {@link EvaluationTab}.
142      */
143     protected abstract EvaluationPane<T> getEvaluationPane();
144 
145 }