1 /*-
2  * Copyright (c) 2001, 2020 Oracle and/or its affiliates.  All rights reserved.
3  *
4  * See the file LICENSE for license information.
5  *
6  * $Id$
7  */
8 package db_gui.datapage;
9 
10 import com.sleepycat.db.DatabaseType;
11 
12 import java.io.ByteArrayInputStream;
13 import java.io.InputStream;
14 import java.net.URL;
15 import java.nio.charset.StandardCharsets;
16 import java.util.ResourceBundle;
17 
18 import javafx.fxml.FXML;
19 import javafx.scene.control.TextArea;
20 import db_gui.BDBInitializable;
21 
22 /**
23  * The root controller for the Data Access Page.  It implements the feedback
24  * box and constructs the Data Access page based on the database type and
25  * whether the Environment is transactional or not.
26  */
27 public class DataAccessController extends BDBInitializable {
28     @FXML
29     private TextArea FeedbackBox;
30     private final boolean transactional;
31     private final DatabaseType type;
32     private String FXMLResource = "";
33     final static private String FXMLheader =
34             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
35                     "\n" +
36                     "<?import java.lang.*?>\n" +
37                     "<?import java.util.*?>\n" +
38                     "<?import javafx.scene.*?>\n" +
39                     "<?import javafx.scene.control.*?>\n" +
40                     "<?import javafx.scene.layout.*?>\n" +
41                     "\n" +
42                     "\n" +
43                     "<AnchorPane id=\"AnchorPane\" prefHeight=\"600.0\" prefWidth=\"786.0\" xmlns:fx=\"http://javafx.com/fxml/1\" xmlns=\"http://javafx.com/javafx/8\">\n" +
44                     "    <children>";
45     final static private String FXMLfooter =
46             "<Separator layoutX=\"0.0\" layoutY=\"400.0\" prefHeight=\"5.0\" prefWidth=\"786.0\" />\n" +
47                     "      <Button fx:id=\"EnvironmentPageButton\" layoutX=\"19.0\" layoutY=\"565.0\" mnemonicParsing=\"false\" onAction=\"#handleEnvironmentPageButton\" text=\"Environment Page\" accessibleHelp=\"Closes the current environment and database and returns to the Environment page.\" accessibleText=\"Environment Page Button\" />\n" +
48                     "      <Button fx:id=\"DatabasePageButton\" layoutX=\"173.0\" layoutY=\"565.0\" mnemonicParsing=\"false\" onAction=\"#handleDatabasePageButton\" text=\"Database Page\" accessibleHelp=\"Closes the current database and returns to the Database page.\" accessibleText=\"Database Page Button\" />\n" +
49                     "       <Button fx:id=\"CloseButton\" layoutX=\"300.0\" layoutY=\"565.0\" mnemonicParsing=\"false\" onAction=\"#handleCloseButton\" text=\"Close\" accessibleHelp=\"Closes the environment and exits the application.\" accessibleText=\"Close button\"/>" +
50                     "      <TextArea fx:id=\"FeedbackBox\" layoutX=\"24.0\" layoutY=\"425.0\" prefHeight=\"120.0\" prefWidth=\"786.0\" accessibleHelp=\"Displays feedback, such as error messages and operation progress.\" accessibleText=\"Feedback text box\"/>\n" +
51                     "    </children>\n" +
52                     "</AnchorPane>";
53     final static private String FXMLBtreeHash =
54             "<Pane layoutX=\"0.0\" layoutY=\"50.0\" prefHeight=\"400.0\" prefWidth=\"786.0\">" +
55                     "<fx:include fx:id=\"BtreeHash\" source=\"/db_gui/datapage/FXMLBtreeHash.fxml\" />\n" +
56                     "</Pane>";
57     final static private String FXMLHeap =
58             "<Pane layoutX=\"0.0\" layoutY=\"50.0\" prefHeight=\"400.0\" prefWidth=\"786.0\">" +
59                     "<fx:include fx:id=\"Heap\" source=\"/db_gui/datapage/FXMLHeap.fxml\" />\n" +
60                     "</Pane>";
61     final static private String FXMLQueue =
62             "<Pane layoutX=\"0.0\" layoutY=\"50.0\" prefHeight=\"400.0\" prefWidth=\"786.0\">" +
63                     "<fx:include fx:id=\"Queue\" source=\"/db_gui/datapage/FXMLQueue.fxml\" />\n" +
64                     "</Pane>";
65     final static private String FXMLRecno =
66             "<Pane layoutX=\"0.0\" layoutY=\"50.0\" prefHeight=\"400.0\" prefWidth=\"786.0\">" +
67                     "<fx:include fx:id=\"Recno\" source=\"/db_gui/datapage/FXMLRecno.fxml\" />\n" +
68                     "</Pane>";
69     final static private String FXMLTransaction =
70             "<Pane layoutX=\"0.0\" layoutY=\"0.0\" prefHeight=\"50.0\" prefWidth=\"786.0\">" +
71                     "<fx:include fx:id=\"Transaction\" source=\"/db_gui/datapage/FXMLTransaction.fxml\" />\n" +
72                     "</Pane>";
73 
74     /**
75      * Default constructor.  It constructs the FXML used to display the Data
76      * Access page based on the database type and whether the Environment is
77      * transactional or not.
78      *
79      * @param txn - Whether the Environment is transactional or not.
80      * @param dbType - The database access method.
81      */
DataAccessController(boolean txn, DatabaseType dbType)82     public DataAccessController(boolean txn, DatabaseType dbType) {
83         transactional = txn;
84         type = dbType;
85         /* Contstruct the FXML document. */
86         FXMLResource = FXMLheader;
87         // Add transaction section if supported.
88         if (transactional)
89             FXMLResource += FXMLTransaction;
90         // Set the access type dependent data sections.
91         if (type == DatabaseType.BTREE || type == DatabaseType.HASH)
92             FXMLResource += FXMLBtreeHash;
93         else if (type == DatabaseType.HEAP)
94             FXMLResource += FXMLHeap;
95         else if (type == DatabaseType.QUEUE)
96             FXMLResource += FXMLQueue;
97         else if (type == DatabaseType.RECNO)
98             FXMLResource += FXMLRecno;
99         // Add the feedback box and environment and database buttons
100         FXMLResource += FXMLfooter;
101     }
102 
103     /**
104      * Clears the fields when the Clear button is pressed.
105      */
106     @Override
clearAllFields()107     public void clearAllFields() {
108         FeedbackBox.clear();
109     }
110 
111     /**
112      * Returns the constructed FXML page as an InputStream.
113      *
114      * @return
115      */
getFXMLInputStream()116     public InputStream getFXMLInputStream() {
117         return new ByteArrayInputStream(
118                 FXMLResource.getBytes(StandardCharsets.UTF_8));
119     }
120 
121     /**
122      * Initializes the controller class.
123      */
124     @Override
initialize(URL url, ResourceBundle rb)125     public void initialize(URL url, ResourceBundle rb) {
126         bdbState.setFeedbackBox(FeedbackBox);
127         bdbState.clearButtons();
128         bdbState.clearTabs();
129     }
130 
131 
132 }
133