/*-
* Copyright (c) 2001, 2020 Oracle and/or its affiliates. All rights reserved.
*
* See the file LICENSE for license information.
*
* $Id$
*/
package db_gui.datapage;
import com.sleepycat.db.DatabaseType;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import db_gui.BDBInitializable;
/**
* The root controller for the Data Access Page. It implements the feedback
* box and constructs the Data Access page based on the database type and
* whether the Environment is transactional or not.
*/
public class DataAccessController extends BDBInitializable {
@FXML
private TextArea FeedbackBox;
private final boolean transactional;
private final DatabaseType type;
private String FXMLResource = "";
final static private String FXMLheader =
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
" ";
final static private String FXMLfooter =
"\n" +
" \n" +
" \n" +
" " +
" \n" +
" \n" +
"";
final static private String FXMLBtreeHash =
"" +
"\n" +
"";
final static private String FXMLHeap =
"" +
"\n" +
"";
final static private String FXMLQueue =
"" +
"\n" +
"";
final static private String FXMLRecno =
"" +
"\n" +
"";
final static private String FXMLTransaction =
"" +
"\n" +
"";
/**
* Default constructor. It constructs the FXML used to display the Data
* Access page based on the database type and whether the Environment is
* transactional or not.
*
* @param txn - Whether the Environment is transactional or not.
* @param dbType - The database access method.
*/
public DataAccessController(boolean txn, DatabaseType dbType) {
transactional = txn;
type = dbType;
/* Contstruct the FXML document. */
FXMLResource = FXMLheader;
// Add transaction section if supported.
if (transactional)
FXMLResource += FXMLTransaction;
// Set the access type dependent data sections.
if (type == DatabaseType.BTREE || type == DatabaseType.HASH)
FXMLResource += FXMLBtreeHash;
else if (type == DatabaseType.HEAP)
FXMLResource += FXMLHeap;
else if (type == DatabaseType.QUEUE)
FXMLResource += FXMLQueue;
else if (type == DatabaseType.RECNO)
FXMLResource += FXMLRecno;
// Add the feedback box and environment and database buttons
FXMLResource += FXMLfooter;
}
/**
* Clears the fields when the Clear button is pressed.
*/
@Override
public void clearAllFields() {
FeedbackBox.clear();
}
/**
* Returns the constructed FXML page as an InputStream.
*
* @return
*/
public InputStream getFXMLInputStream() {
return new ByteArrayInputStream(
FXMLResource.getBytes(StandardCharsets.UTF_8));
}
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
bdbState.setFeedbackBox(FeedbackBox);
bdbState.clearButtons();
bdbState.clearTabs();
}
}