/*
* SelectPanel.java
* The package panels contains the different class executing the different windows of each function of the FlightSystem Reservation.
*/
package reservation.system.panels;
import reservation.system.functions.Functions;
import reservation.system.Profile;
import reservation.system.Flight;
import reservation.system.Person;
import reservation.system.Pos;
import reservation.CustomDialog;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;
import java.awt.event.*;
import java.util.Vector;
import java.awt.Dimension;
import java.util.StringTokenizer;
/**
* This class hold Select structure. This object allows to see the persons who have got a same bookingNumber or the persons present in a same flight.
* It use a GUI that contains a form with the several field to fill.
* @author Texier Mathieu and Frederic Bidon
*/
public class SelectPanel extends Panels {
/** Creates new form SelectPanel */
public SelectPanel() {
personNameLabel
= new JLabel();
add(flightSelect);
add(bookingSelect);
add(personNameInput);
add(colInput);
flightLabel.setText("Flight");
add(flightLabel);
personNameLabel.setText("Person");
add(personNameLabel);
bookingLabel.setText("Booking");
add(bookingLabel);
colLabel.setText("Seat col");
add(colLabel);
rowLabel.setText("row");
add(rowLabel);
add(rowInput);
searchButton.setText("Search");
searchAction(evt);
}
});
add(searchButton);
bookingTable.setRowSelectionAllowed(false);
jScrollPane.setViewportView(bookingTable);
add(jScrollPane);
}
/**
* Create the button of validation to search in the database the persons who have the same bookingNumber or who are registered in the same flight.
*/
Vector groupePersonVector
= null;
try {
Profile profile = new Profile();
if (personName != null)
if (!personName.equals(""))
profile.setPersonName(personName);
String flightName
= (String) flightSelect.
getSelectedItem();
if (flightName != null)
if (!flightName.equals(""))
profile.setFlight(fs.selectFlight(flightName));
if (bookingNumber != null) {
profile.setBookingNumber(bookingNumber.intValue());
}
String colString
= colInput.
getText();
String rowString
= rowInput.
getText();
if ((colString != null) && (rowString != null)) {
if (colString.equals("") ^ rowString.equals("")) {
throw new Exception("Both col and row have to be either null or non null");
}
if (!colString.equals("") && !rowString.equals(""))
if (Functions.checkInteger(colString, 1, Flight.ROWS_MAX)
&& Functions.checkInteger(rowString, 1, Flight.ROW_LENGTH_MAX)) {
short col
= (short) Integer.
parseInt(colString
);
short row
= (short) Integer.
parseInt(rowString
);
Pos pos = new Pos(row,col);
profile.setPos(pos);
}
else {
colInput.setText("");
rowInput.setText("");
throw new Exception("Col or Row have incorect value");
}
}
groupePersonVector = fs.search(profile);
CustomDialog.alert(e);
}
if (groupePersonVector != null) {
int groupePersonSize = groupePersonVector.size();
String title
[] = {"Name",
"Booking number",
"flight name",
"seat"};
for (int i=0; i< groupePersonSize; i++) {
try {
Person person = (Person) groupePersonVector.get(i);
listData[i][0] = person.getPersonName();
listData
[i
][1] = new Integer(person.
getBookingNumber()).
toString();
listData[i][2] = person.getFlight().getFlightName();
listData[i][3] = person.getPos().toString();
} catch (Exception e
) {CustomDialog.
alert(e
);}
}
}
}
/**
* Causes this container to lay out its components.
*/
public void doLayout() {
flightSelect.setBounds(20, 40, 90, 20);
bookingSelect.setBounds(210, 40, 80, 20);
personNameInput.setBounds(130, 40, 60, 20);
colInput.setBounds(310, 40, 40, 20);
flightLabel.setBounds(20, 10, 40, 20);
personNameLabel.setBounds(130, 10, 40, 20);
bookingLabel.setBounds(210, 10, 40, 20);
colLabel.setBounds(310, 10, 40, 20);
rowLabel.setBounds(360, 10, 40, 20);
rowInput.setBounds(360, 40, 40, 20);
searchButton.setBounds(420, 40, 70, 20);
jScrollPane.setBounds(20, 90, 500, 120);
bookingTable.setBounds(20, 90, 500, 120);
}
/**
* Set the size of the panel
* @return an instance of Dimension that represents the minimum size of this container.
*/
}
/**
* Set the size of the panel
* @return an instance of Dimension that represents the preferred size of this container.
*/
}
/**
* Initialize the number of the field and fill them with default values.
* Dispaly the label of the Window.
*/
public void init() {
bookingSelect.addItem(null);
flightSelect.addItem(null);
try {
String [] flightList
= fs.
getFlightList();
if (flightList != null) {
for (int i=0;i< flightList.length;i++) {
flightSelect.addItem(flightList[i]);
}
}
Integer [] bookingtList
= fs.
getBookingList();
if (bookingtList != null) {
for (int i=0;i< bookingtList.length;i++) {
bookingSelect.addItem(bookingtList[i]);
}
}
CustomDialog.alert(e);
}
searchAction(null);
}
/**
* Proceed the execution of the action
* @return the result of the request.
* @param unUsed not used
* @throws Exception if the command is not executed.
*/
return "";
}
private JLabel personNameLabel
;
}