mdkInventory1/bean/TableViewDefinition.java
package mdkInventory1.bean;
import java.util.Vector;
import mdkInventory1.Constants;
/**
* A bean used as databag to transport data from a servlet to the JSP. The bean contains a string
* that can be used as title/headline for the JSP, the header and footer information and a vector
* that contains the headline and data for the JSP to display in tabular form.
* The int values tableRows and tableColumns should be set to the actual dimension of the array.
* The JSP uses the two values to iterate.
*/
public class TableViewDefinition implements Constants {
private int maxPage;
// Header and footer panel
private Vector headerPanel;
private Vector footerPanel;
// Command line
private Vector commandLine;
// variables that define the size of the array
private int selected_index;
private String centerPageTitle;
private String formName;
private int currentPage;
// get and set methods for the gui
// Header. Header is a vector that contains two text strings which are displayed on the left and
// and right handside. The Header is displayed on the top of the aplication.
// Footer. Similar to header. The footer is displayed on the bottom of the application.
//
public Vector getFooterPanel() {
return footerPanel;
}
public String getFooterPanelEntryLeft() {
return footerPanel.elementAt(0).toString();
}
public String getFooterPanelEntryRight() {
return footerPanel.elementAt(1).toString();
}
public void setFooterPanelEntryLeft(String entry) {
if (footerPanel == null)
initFooterPanel();
footerPanel.setElementAt(entry, 0);
}
public void setFooterPanelEntryRight(String entry) {
if (footerPanel == null)
initFooterPanel();
footerPanel.setElementAt(entry, 1);
}
public void initFooterPanel() {
if (footerPanel == null) {
footerPanel = new Vector();
footerPanel.addElement(" ");
footerPanel.addElement(" ");
}
}
public void initHeaderPanel() {
if (headerPanel == null) {
headerPanel = new Vector();
headerPanel.addElement(" ");
headerPanel.addElement(" ");
}
}
public Vector getHeaderPanel() {
return headerPanel;
}
public String getHeaderPanelEntryLeft() {
return headerPanel.elementAt(0).toString();
}
public String getHeaderPanelEntryRight() {
return headerPanel.elementAt(1).toString();
}
public void setHeaderPanelEntryLeft(String entry) {
if (headerPanel == null)
initHeaderPanel();
headerPanel.setElementAt(entry, 0);
}
public void setHeaderPanelEntryRight(String entry) {
if (headerPanel == null)
initHeaderPanel();
headerPanel.setElementAt(entry, 1);
}
public void setFooterPanel(Vector vector) {
footerPanel = vector;
}
public void setHeaderPanel(Vector vector) {
headerPanel = vector;
}
public String getCenterPageTitle() {
return centerPageTitle;
}
public void setCenterPageTitle(String title) {
centerPageTitle = title;
}
public String getCommandLine(String separator) {
// Iterator dataIterator = commandLine.iterator();
String commandLineString = "";
for (int j = 0; j < commandLine.size(); j++) {
String dataEntry = (String) commandLine.elementAt(j);
if (commandLineString.length() > 1)
commandLineString = commandLineString.concat(separator);
commandLineString = commandLineString.concat(dataEntry);
}
return commandLineString;
}
public void setCommandLine(Vector commands) {
commandLine = commands;
}
public void addCommand(String command) {
commandLine.addElement(command);
}
/*
* Returns the HTML code for the navigation buttons in the JSP
* If a icon is disabled, it displays only the icon - no event will be fired
* If the icon is enabled it displays the icon and generated a href statement for the event
*/
public boolean isTopPrevPagesAvailable() {
boolean ret = false;
if (BasicDataHandler.current_index >= MAX_TABLE_ROWS) {
ret = true;
}
return ret;
}
public boolean isNextLastPageAvailable() {
boolean ret = false;
if (BasicDataHandler.rows_in_dataset > (BasicDataHandler.tablerows + BasicDataHandler.current_index))
ret = true;
return ret;
}
public String getTopIcon() {
String event = "";
String icon = ICON_FIRSTPAGE_DISABLED;
if (isTopPrevPagesAvailable()) {
icon = ICON_FIRSTPAGE_ENABLED;
event = " href=\"?event=" + EVENT_FIRSTPAGE + "\"";
}
String ret = "<a" + event + "><img src=\"" + icon + "\" alt=\"First page\" ></a>";
return ret;
}
public String getBottomIcon() {
String event = "";
String icon = ICON_LASTPAGE_DISABLED;
if (isNextLastPageAvailable()) {
icon = ICON_LASTPAGE_ENABLED;
event = " href=\"?event=" + EVENT_LASTPAGE + "\"";
}
String ret = "<a" + event + "><img src=\"" + icon + "\" alt=\"Last page\" ></a>";
return ret;
}
public String getPageupIcon() {
String event = "";
String icon = ICON_PAGEUP_DISABLED;
if (isTopPrevPagesAvailable()) {
icon = ICON_PAGEUP_ENABLED;
event = " href=\"?event=" + EVENT_PAGEUP + "\"";
}
String ret = "<a" + event + "><img src=\"" + icon + "\" alt=\"Page up\" ></a>";
return ret;
}
public String getPagedownIcon() {
String event = "";
String icon = ICON_PAGEDOWN_DISABLED;
if (isNextLastPageAvailable()) {
icon = ICON_PAGEDOWN_ENABLED;
event = " href=\"?event=" + EVENT_PAGEDOWN + "\"";
}
String ret = "<a" + event + "><img src=\"" + icon + "\" alt=\"Page down\" ></a>";
return ret;
}
public String getGotoIcon() {
/* the goto icon is created as submit button so that the form is submitted and we have access to the input fields
* The "input" tag with type = image in menu.jsp returns the eventname with .x and .y appended to it. So the event
* handler checks only the beginning of the eventname.
* Alternative is the button tag. The button tag send the event name without .x and .y
* Example:
String ret = "<button type=\"submit\" value=\"gotoButton\" class=\"image\" name=\"" + EVENT_GOTOPAGE + "\"><img src=\"" + ICON_GOTO_PAGE + "\" alt=\"go to page\" ></button>";
* Disadvantage of the button tag is that it is not available on all browsers.
*/
String ret = "<input type=\"image\" value=\"\" class=\"image\" name=\"_event_" + EVENT_GOTOPAGE + "\" title=\"Go to selected page\" src=\"" + ICON_GOTO_PAGE + "\" alt=\"go to page\" >";
return ret;
}
/**
* @return the maximum pages for the data set - the page size is define in Constants.java
* variable: MAX_TABLE_ROWS
*/
public int getMaxPage() {
maxPage = 1;
if (BasicDataHandler.rows_in_dataset != 0) {
maxPage = ((BasicDataHandler.rows_in_dataset - 1) + MAX_TABLE_ROWS) / MAX_TABLE_ROWS;
}
return maxPage;
}
public void setMaxPage(int i) {
maxPage = i;
}
/**
* @return the form name of the HTML page generated in the JSP
*/
public String getFormName() {
return MI_FORM_NAME;
}
public String getEventID() {
return MI_EVENT_ID;
}
public String getEventType() {
return MI_EVENT_TYPE;
}
public String getEventObject() {
return MI_EVENT_OBJECT;
}
/**
* @return the currently selected index
*/
public int getSelected_index() {
return selected_index;
}
/**
* @param i sets the currently selected index
*/
public void setSelected_index(int i) {
selected_index = i;
}
public int getCurrentPage() {
currentPage = (BasicDataHandler.current_index / MAX_TABLE_ROWS) + 1;
return currentPage;
}
public void setCurrentPage(int i) {
currentPage = i;
}
}