minor tweaks to how i handle progress updates, and database searchs
This commit is contained in:
@@ -9,7 +9,9 @@ package com.TwentyCodes.java.OrderProcessor.DB;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.LineNumberReader;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -69,6 +71,22 @@ public class OrderDB {
|
|||||||
conn.close();
|
conn.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* counts the number of lines in a file
|
||||||
|
* @param file to be read
|
||||||
|
* @return number of lines in a file
|
||||||
|
* @throws IOException
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public int countLines(File file) throws IOException {
|
||||||
|
LineNumberReader reader = new LineNumberReader(new FileReader(file));
|
||||||
|
int cnt = 0;
|
||||||
|
while ((reader.readLine()) != null) ;
|
||||||
|
cnt = reader.getLineNumber();
|
||||||
|
reader.close();
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* added the order to the database
|
* added the order to the database
|
||||||
* @param order
|
* @param order
|
||||||
@@ -100,6 +118,7 @@ public class OrderDB {
|
|||||||
public ArrayList<Order> getAllOrders() throws SQLException, IOException, ClassNotFoundException {
|
public ArrayList<Order> getAllOrders() throws SQLException, IOException, ClassNotFoundException {
|
||||||
|
|
||||||
int row = 1;
|
int row = 1;
|
||||||
|
int count = getCount();
|
||||||
Connection conn = getConnection();
|
Connection conn = getConnection();
|
||||||
Statement stat = conn.createStatement();
|
Statement stat = conn.createStatement();
|
||||||
ResultSet rs = stat.executeQuery("select * from Orders;");
|
ResultSet rs = stat.executeQuery("select * from Orders;");
|
||||||
@@ -109,7 +128,7 @@ public class OrderDB {
|
|||||||
ObjectInputStream ins;
|
ObjectInputStream ins;
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
if(mListener != null && ! isLoadingFile)
|
if(mListener != null && ! isLoadingFile)
|
||||||
mListener.onProgressUpdate(row++);
|
mListener.onProgressUpdate(row++, count);
|
||||||
bais = new ByteArrayInputStream(rs.getBytes("item"));
|
bais = new ByteArrayInputStream(rs.getBytes("item"));
|
||||||
ins = new ObjectInputStream(bais);
|
ins = new ObjectInputStream(bais);
|
||||||
list.add((Order) ins.readObject());
|
list.add((Order) ins.readObject());
|
||||||
@@ -160,6 +179,7 @@ public class OrderDB {
|
|||||||
public void load(File file) throws SQLException, IOException, ClassNotFoundException{
|
public void load(File file) throws SQLException, IOException, ClassNotFoundException{
|
||||||
Scanner scan = new Scanner(file);
|
Scanner scan = new Scanner(file);
|
||||||
int line = 1;
|
int line = 1;
|
||||||
|
int lineCount = countLines(file);
|
||||||
isLoadingFile = true;
|
isLoadingFile = true;
|
||||||
|
|
||||||
Connection conn = getConnection();
|
Connection conn = getConnection();
|
||||||
@@ -169,7 +189,7 @@ public class OrderDB {
|
|||||||
while(scan.hasNextLine()){
|
while(scan.hasNextLine()){
|
||||||
|
|
||||||
if(mListener != null)
|
if(mListener != null)
|
||||||
mListener.onProgressUpdate(line++);
|
mListener.onProgressUpdate(line++, lineCount);
|
||||||
|
|
||||||
if(Main.DEBUG)
|
if(Main.DEBUG)
|
||||||
System.out.println("\non line: "+ line);
|
System.out.println("\non line: "+ line);
|
||||||
@@ -213,30 +233,55 @@ public class OrderDB {
|
|||||||
* returns a list of orders that pertain any information being searched for.
|
* returns a list of orders that pertain any information being searched for.
|
||||||
* possible seraches include: item name, google order number, customer name
|
* possible seraches include: item name, google order number, customer name
|
||||||
* @param text
|
* @param text
|
||||||
* @return a list containing all possible orders
|
* @param isExclusive true if the search is excluding the string
|
||||||
|
* @return an array list containing all orders meeting search criteria
|
||||||
|
* @throws SQLException
|
||||||
|
* @throws IOException
|
||||||
|
* @throws ClassNotFoundException
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
* @throws ClassNotFoundException
|
|
||||||
* @throws IOException
|
|
||||||
* @throws SQLException
|
|
||||||
*/
|
*/
|
||||||
public ArrayList<Order> search(String text) throws SQLException, IOException, ClassNotFoundException {
|
public ArrayList<Order> search(String text, boolean isExclusive) throws SQLException, IOException, ClassNotFoundException {
|
||||||
ArrayList<Order> array = getAllOrders();
|
|
||||||
long orderNumber = -1;
|
long orderNumber = -1;
|
||||||
try {
|
try {
|
||||||
orderNumber = Long.parseLong(text);
|
orderNumber = Long.parseLong(text);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TO NOTHING
|
// TO NOTHING
|
||||||
}
|
}
|
||||||
ArrayList<Order> list = new ArrayList<Order>();
|
int row = 1;
|
||||||
for(int i = 0; i < array.size(); i++){
|
int count = getCount();
|
||||||
if(array.get(i).getItemName().equalsIgnoreCase(text)
|
|
||||||
|| (orderNumber > 0) && (array.get(i).getGoogleOrderNumber() == orderNumber)
|
Connection conn = getConnection();
|
||||||
|| array.get(i).getCustomerName().toLowerCase(Locale.ENGLISH).contains(text.toLowerCase(Locale.ENGLISH)))
|
Statement stat = conn.createStatement();
|
||||||
list.add(array.get(i));
|
ResultSet rs = stat.executeQuery("select * from Orders;");
|
||||||
|
ArrayList<Order> list = new ArrayList<Order>();
|
||||||
|
|
||||||
|
ByteArrayInputStream bais;
|
||||||
|
ObjectInputStream ins;
|
||||||
|
while (rs.next()) {
|
||||||
|
if(mListener != null && ! isLoadingFile)
|
||||||
|
mListener.onProgressUpdate(row++, count);
|
||||||
|
bais = new ByteArrayInputStream(rs.getBytes("item"));
|
||||||
|
ins = new ObjectInputStream(bais);
|
||||||
|
Order order = (Order) ins.readObject();
|
||||||
|
|
||||||
|
if (isExclusive){
|
||||||
|
if ( ! order.getItemName().equalsIgnoreCase(text)
|
||||||
|
|| (orderNumber > 0)
|
||||||
|
&& (order.getGoogleOrderNumber() == orderNumber)
|
||||||
|
|| order.getCustomerName().toLowerCase(Locale.ENGLISH).contains(text.toLowerCase(Locale.ENGLISH)))
|
||||||
|
list.add(order);
|
||||||
|
} else if ( order.getItemName().equalsIgnoreCase(text)
|
||||||
|
|| (orderNumber > 0)
|
||||||
|
&& (order.getGoogleOrderNumber() == orderNumber)
|
||||||
|
|| order.getCustomerName().toLowerCase(Locale.ENGLISH).contains(text.toLowerCase(Locale.ENGLISH)))
|
||||||
|
list.add(order);
|
||||||
|
|
||||||
|
ins.close();
|
||||||
|
bais.close();
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
conn.close();
|
||||||
|
|
||||||
if(mListener != null)
|
|
||||||
mListener.onProgressUpdate(i);
|
|
||||||
}
|
|
||||||
Collections.sort(list);
|
Collections.sort(list);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -246,14 +291,15 @@ public class OrderDB {
|
|||||||
* @param search string to search for
|
* @param search string to search for
|
||||||
* @param start date
|
* @param start date
|
||||||
* @param end date
|
* @param end date
|
||||||
|
* @param isExclusive true if the search is excluding the string
|
||||||
* @return list of orders that meet requirements
|
* @return list of orders that meet requirements
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws ClassNotFoundException
|
* @throws ClassNotFoundException
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public ArrayList<Order> search(String search, Date start, Date end) throws SQLException, IOException, ClassNotFoundException {
|
public ArrayList<Order> search(String search, Date start, Date end, boolean isExclusive) throws SQLException, IOException, ClassNotFoundException {
|
||||||
ArrayList<Order> prelist = search(search);
|
ArrayList<Order> prelist = search(search, isExclusive);
|
||||||
ArrayList<Order> list = new ArrayList<Order>();
|
ArrayList<Order> list = new ArrayList<Order>();
|
||||||
|
|
||||||
for(Order item : prelist){
|
for(Order item : prelist){
|
||||||
|
|||||||
@@ -34,37 +34,17 @@ public class Date implements Comparable<Date>, Serializable{
|
|||||||
String[] date = parts[0].split("-");
|
String[] date = parts[0].split("-");
|
||||||
String[] time = parts[1].split(":");
|
String[] time = parts[1].split(":");
|
||||||
try {
|
try {
|
||||||
this.mYear = Integer.parseInt(removeFirstChar(date[0]));
|
this.mYear = Integer.parseInt(date[0]);
|
||||||
this.mDay = Byte.parseByte(date[2]);
|
this.mDay = Byte.parseByte(date[2]);
|
||||||
this.mMonth = Byte.parseByte(date[1]);
|
this.mMonth = Byte.parseByte(date[1]);
|
||||||
this.mHour = Byte.parseByte(time[0]);
|
this.mHour = Byte.parseByte(time[0]);
|
||||||
this.mMinute = Byte.parseByte(time[1]);
|
this.mMinute = Byte.parseByte(time[1]);
|
||||||
this.mSecond = Byte.parseByte(removeLastChar(time[2]));
|
this.mSecond = Byte.parseByte(time[2]);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new InvalidDateFormatException(newDate);
|
throw new InvalidDateFormatException(newDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* removes the first string from a string
|
|
||||||
* @param s
|
|
||||||
* @return
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
private String removeFirstChar(String s) {
|
|
||||||
return s.substring(1,s.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* removes the last char from a string
|
|
||||||
* @param s
|
|
||||||
* @return
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
private String removeLastChar(String s) {
|
|
||||||
return s.substring(0,s.length()-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a human readable string that reprensts this object
|
* returns a human readable string that reprensts this object
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class Order implements Comparable<Order>, Serializable{
|
|||||||
lineParts = order.split(",");
|
lineParts = order.split(",");
|
||||||
|
|
||||||
this.mGoogleOrderNumber = Long.parseLong(removeLastChar(lineParts[0].split(" ")[1]));
|
this.mGoogleOrderNumber = Long.parseLong(removeLastChar(lineParts[0].split(" ")[1]));
|
||||||
this.mOrderCreationDate = new Date(lineParts[2]);
|
this.mOrderCreationDate = new Date(lineParts[2].substring(1, (lineParts[2].length() -1) ));
|
||||||
this.mOrderAmount = Float.parseFloat(lineParts[4]);
|
this.mOrderAmount = Float.parseFloat(lineParts[4]);
|
||||||
this.mAmountCharged = Float.parseFloat(lineParts[5]);
|
this.mAmountCharged = Float.parseFloat(lineParts[5]);
|
||||||
this.mFinancialStatus = Status.parseStatus(lineParts[6]);
|
this.mFinancialStatus = Status.parseStatus(lineParts[6]);
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ public interface ProgressListener {
|
|||||||
* @param progress
|
* @param progress
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void onProgressUpdate(int progress);
|
public void onProgressUpdate(int progress, int max);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -88,9 +88,9 @@ public class DatePicker extends JFrame implements ActionListener {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
try {
|
try {
|
||||||
mListener.onDatePicked(mResultCode, new Date("\""+
|
mListener.onDatePicked(mResultCode, new Date(
|
||||||
mCalendar.getYearChooser().getYear()+"-"+ (mCalendar.getMonthChooser().getMonth()+1) +"-"+ mCalendar.getDayChooser().getDay() +
|
mCalendar.getYearChooser().getYear()+"-"+ (mCalendar.getMonthChooser().getMonth()+1) +"-"+ mCalendar.getDayChooser().getDay() +
|
||||||
" "+ Integer.parseInt(mHours.getText())+":"+ Integer.parseInt(mMinutes.getText())+":"+ Integer.parseInt(mSeconds.getText())+"\""));
|
" "+ Integer.parseInt(mHours.getText())+":"+ Integer.parseInt(mMinutes.getText())+":"+ Integer.parseInt(mSeconds.getText())));
|
||||||
this.dispose();
|
this.dispose();
|
||||||
} catch (NumberFormatException e1) {
|
} catch (NumberFormatException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
|
|||||||
@@ -9,11 +9,8 @@ package com.TwentyCodes.java.OrderProcessor.UI;
|
|||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.LineNumberReader;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
@@ -82,18 +79,16 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
|||||||
setVisible(true);
|
setVisible(true);
|
||||||
pack();
|
pack();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db = new OrderDB();
|
db = new OrderDB();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fc = new JFileChooser();
|
fc = new JFileChooser();
|
||||||
fc.setFileFilter(new FileFilter());
|
fc.setFileFilter(new FileFilter());
|
||||||
|
|
||||||
// db.setOnProgressListerner(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,64 +110,37 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
|||||||
* Prepares the progress bar, and loads the file using an executer to prevent UI hangups
|
* Prepares the progress bar, and loads the file using an executer to prevent UI hangups
|
||||||
*/
|
*/
|
||||||
if(e.getSource() == mLoadFileButton){
|
if(e.getSource() == mLoadFileButton){
|
||||||
try {
|
if(fc.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION){
|
||||||
if(fc.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION){
|
mLoadFileButton.setEnabled(false);
|
||||||
mLoadFileButton.setEnabled(false);
|
db.setOnProgressListerner(this);
|
||||||
db.setOnProgressListerner(this);
|
mProgressBar.setIndeterminate(true);
|
||||||
mProgressBar.setIndeterminate(true);
|
mCurrentFile = fc.getSelectedFile().toString();
|
||||||
mCurrentFile = fc.getSelectedFile().toString();
|
mProgressBar.setString(mCurrentFile);
|
||||||
mProgressBar.setString(mCurrentFile);
|
|
||||||
mProgressBar.setMaximum(countLines(fc.getSelectedFile())+1);
|
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
|
||||||
|
public void run() {
|
||||||
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
|
try {
|
||||||
public void run() {
|
db.load(fc.getSelectedFile());
|
||||||
try {
|
} catch (FileNotFoundException e) {
|
||||||
db.load(fc.getSelectedFile());
|
e.printStackTrace();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (SQLException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
} catch (ClassNotFoundException e) {
|
||||||
} catch (IOException e) {
|
e.printStackTrace();
|
||||||
// TODO Auto-generated catch block
|
}
|
||||||
e.printStackTrace();
|
}
|
||||||
} catch (ClassNotFoundException e) {
|
});
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
} else {
|
} else {
|
||||||
mProgressBar.setIndeterminate(false);
|
mProgressBar.setIndeterminate(false);
|
||||||
}
|
|
||||||
|
|
||||||
} catch (FileNotFoundException e1) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (IOException e2) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e2.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* counts the number of lines in a file
|
|
||||||
* @param file to be read
|
|
||||||
* @return number of lines in a file
|
|
||||||
* @throws IOException
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public int countLines(File file) throws IOException {
|
|
||||||
LineNumberReader reader = new LineNumberReader(new FileReader(file));
|
|
||||||
int cnt = 0;
|
|
||||||
while ((reader.readLine()) != null) ;
|
|
||||||
cnt = reader.getLineNumber();
|
|
||||||
reader.close();
|
|
||||||
return cnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,8 +150,9 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onProgressUpdate(int progress) {
|
public void onProgressUpdate(int progress, int max) {
|
||||||
progress++;
|
progress++;
|
||||||
|
mProgressBar.setMaximum(max);
|
||||||
mProgressBar.setValue(progress);
|
mProgressBar.setValue(progress);
|
||||||
mProgressBar.setString(" "+mCurrentFile + " ~ Parsing Order: "+ progress +" of "+mProgressBar.getMaximum()+" ");
|
mProgressBar.setString(" "+mCurrentFile + " ~ Parsing Order: "+ progress +" of "+mProgressBar.getMaximum()+" ");
|
||||||
if(mProgressBar.isIndeterminate()) {
|
if(mProgressBar.isIndeterminate()) {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class OrderPane extends JScrollPane {
|
|||||||
int total = 0;
|
int total = 0;
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
if(mListener != null)
|
if(mListener != null)
|
||||||
mListener.onProgressUpdate(i);
|
mListener.onProgressUpdate(i, list.size());
|
||||||
switch (list.get(i).getFinancialStatus()) {
|
switch (list.get(i).getFinancialStatus()) {
|
||||||
case CANCELLED:
|
case CANCELLED:
|
||||||
updateTextPane(list.get(i).toString(), TextStyle.RED);
|
updateTextPane(list.get(i).toString(), TextStyle.RED);
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ package com.TwentyCodes.java.OrderProcessor.UI;
|
|||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ItemEvent;
|
||||||
|
import java.awt.event.ItemListener;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -17,6 +19,7 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
@@ -34,7 +37,7 @@ import com.TwentyCodes.java.OrderProcessor.ProgressListener;
|
|||||||
* This class will be the dialog that will ask the user for a specific make to show
|
* This class will be the dialog that will ask the user for a specific make to show
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class SearchDialog extends JFrame implements ActionListener, ProgressListener, MouseListener, DatePickerListener {
|
public class SearchDialog extends JFrame implements ActionListener, ProgressListener, MouseListener, DatePickerListener, ItemListener {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1750326106927701404L;
|
private static final long serialVersionUID = 1750326106927701404L;
|
||||||
private static final int END_DATE_RESULT = 1;
|
private static final int END_DATE_RESULT = 1;
|
||||||
@@ -47,6 +50,8 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
private OrderPane mOrderPanel;
|
private OrderPane mOrderPanel;
|
||||||
private JTextField mStartDateField;
|
private JTextField mStartDateField;
|
||||||
private JTextField mEndDateField;
|
private JTextField mEndDateField;
|
||||||
|
private boolean isExclusive = false;
|
||||||
|
private JCheckBox mExclusiveCheckBox;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new ShowAllMakeDialog
|
* Creates a new ShowAllMakeDialog
|
||||||
@@ -70,6 +75,11 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
mTextField.addActionListener(this);
|
mTextField.addActionListener(this);
|
||||||
panel.add(mTextField);
|
panel.add(mTextField);
|
||||||
|
|
||||||
|
//exclusive check box
|
||||||
|
mExclusiveCheckBox = new JCheckBox("Exclusive Search");
|
||||||
|
mExclusiveCheckBox.addItemListener(this);
|
||||||
|
panel.add(mExclusiveCheckBox);
|
||||||
|
|
||||||
//start date
|
//start date
|
||||||
panel.add(new JLabel("Start Date:"));
|
panel.add(new JLabel("Start Date:"));
|
||||||
mStartDateField = new JTextField();
|
mStartDateField = new JTextField();
|
||||||
@@ -111,7 +121,7 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if(! mStartDateField.getText().isEmpty() && !mEndDateField.getText().isEmpty())
|
if(! mStartDateField.getText().isEmpty() && !mEndDateField.getText().isEmpty())
|
||||||
try {
|
try {
|
||||||
preformSearch(mTextField.getText(), new Date("\""+mStartDateField.getText()+"\""), new Date("\""+mEndDateField.getText()+"\""));
|
preformSearch(mTextField.getText(), new Date(mStartDateField.getText()), new Date(mEndDateField.getText()));
|
||||||
} catch (InvalidDateFormatException e1) {
|
} catch (InvalidDateFormatException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -124,19 +134,14 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
public void run() {
|
public void run() {
|
||||||
mProgressBar.setString("Searching for: "+search);
|
mProgressBar.setString("Searching for: "+search);
|
||||||
mProgressBar.setStringPainted(true);
|
mProgressBar.setStringPainted(true);
|
||||||
try {
|
|
||||||
mProgressBar.setMaximum(MainWindow.db.getCount());
|
|
||||||
} catch (SQLException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
MainWindow.db.setOnProgressListerner(SearchDialog.this);
|
MainWindow.db.setOnProgressListerner(SearchDialog.this);
|
||||||
|
|
||||||
ArrayList<Order> list = null;
|
ArrayList<Order> list = null;
|
||||||
try {
|
try {
|
||||||
if((start != null) && (end != null)){
|
if((start != null) && (end != null)){
|
||||||
list = MainWindow.db.search(search, start, end);
|
list = MainWindow.db.search(search, start, end, isExclusive);
|
||||||
} else{
|
} else{
|
||||||
list = MainWindow.db.search(search);
|
list = MainWindow.db.search(search, isExclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -171,10 +176,12 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onProgressUpdate(int progress) {
|
public void onProgressUpdate(int progress, int max) {
|
||||||
if(Main.DEBUG)
|
if(Main.DEBUG)
|
||||||
System.out.println("search progress = "+ progress);
|
System.out.println("search progress = "+ progress);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
progress++;
|
progress++;
|
||||||
if(mProgressBar.isIndeterminate()) {
|
if(mProgressBar.isIndeterminate()) {
|
||||||
mProgressBar.setIndeterminate(false);
|
mProgressBar.setIndeterminate(false);
|
||||||
@@ -187,8 +194,10 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
mProgressBar.setValue(progress);
|
mProgressBar.setValue(progress);
|
||||||
|
mProgressBar.setMaximum(max);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -231,7 +240,6 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDatePicked(int resultCode, Date date) {
|
public void onDatePicked(int resultCode, Date date) {
|
||||||
switch(resultCode){
|
switch(resultCode){
|
||||||
@@ -244,5 +252,16 @@ public class SearchDialog extends JFrame implements ActionListener, ProgressList
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void itemStateChanged(ItemEvent e) {
|
||||||
|
if(e.getSource() == mExclusiveCheckBox)
|
||||||
|
if(e.getStateChange() == java.awt.event.ItemEvent.SELECTED)
|
||||||
|
isExclusive = true;
|
||||||
|
if(e.getStateChange() == java.awt.event.ItemEvent.DESELECTED)
|
||||||
|
isExclusive = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,11 +45,6 @@ public class ShowAllDialog extends JFrame implements ActionListener, ProgressLis
|
|||||||
getContentPane().add(mProgressBar, BorderLayout.SOUTH);
|
getContentPane().add(mProgressBar, BorderLayout.SOUTH);
|
||||||
this.getContentPane().add(mOutput, BorderLayout.CENTER);
|
this.getContentPane().add(mOutput, BorderLayout.CENTER);
|
||||||
this.getContentPane().add(ok, BorderLayout.NORTH);
|
this.getContentPane().add(ok, BorderLayout.NORTH);
|
||||||
try {
|
|
||||||
mProgressBar.setMaximum(MainWindow.db.getCount());
|
|
||||||
} catch (SQLException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
mProgressBar.setString("Loading from Database");
|
mProgressBar.setString("Loading from Database");
|
||||||
mProgressBar.setStringPainted(true);
|
mProgressBar.setStringPainted(true);
|
||||||
MainWindow.db.setOnProgressListerner(this);
|
MainWindow.db.setOnProgressListerner(this);
|
||||||
@@ -108,7 +103,8 @@ public class ShowAllDialog extends JFrame implements ActionListener, ProgressLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgressUpdate(int progress) {
|
public void onProgressUpdate(int progress, int max) {
|
||||||
|
mProgressBar.setMaximum(max);
|
||||||
mProgressBar.setValue(progress);
|
mProgressBar.setValue(progress);
|
||||||
if(progress >= mProgressBar.getMaximum()){
|
if(progress >= mProgressBar.getMaximum()){
|
||||||
this.pack();
|
this.pack();
|
||||||
|
|||||||
Reference in New Issue
Block a user