Skip to content

Commit

Permalink
Bug fixes and New features added
Browse files Browse the repository at this point in the history
 1) Experiment module:
         * Added import function to import design result
 2) Harvesting module:
        * do not allow to import stocks that already exist in database
        * fixed pedigree generation for PP mating type
        * when create entries for stock_composition table, bulk composition should be synced lastly.
    3) Inventory Module: Allow copy-paste the error message for failed imported stocks
  • Loading branch information
Felicity117 committed Jun 4, 2018
1 parent 6ca83b0 commit b7ea2fa
Show file tree
Hide file tree
Showing 18 changed files with 369 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public class AccreteGBConfiguration {

private String rPath;

private AccreteGBConfiguration() {
loadConfigs();
}

public static synchronized AccreteGBConfiguration getConfiguration() {
if (accreteGBConfiguration == null) {
accreteGBConfiguration = new AccreteGBConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public void setScrollBarRequired(boolean scrollBarRequired)
/**
* Alter the bounds of the popup just before it is made visible.
*/
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e)
{
JComboBox comboBox = (JComboBox)e.getSource();
Expand Down Expand Up @@ -336,8 +337,10 @@ protected boolean horizontalScrollBarWillBeVisible(BasicComboPopup popup, JScrol
return popupWidth > scrollPane.getPreferredSize().width;
}

@Override
public void popupMenuCanceled(PopupMenuEvent e) {}

@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e)
{
// In its normal state the scrollpane does not have a scrollbar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
import org.accretegb.modules.customswingcomponent.Utils;
import org.accretegb.modules.germplasm.stocksinfo.CreateStocksInfoPanel;
import org.accretegb.modules.germplasm.stocksinfo.StocksInfoPanel;
import org.accretegb.modules.hibernate.Classification;
import org.accretegb.modules.hibernate.ExperimentFactor;
import org.accretegb.modules.hibernate.ExperimentFactorValue;
import org.accretegb.modules.hibernate.HibernateSessionFactory;
import org.accretegb.modules.hibernate.MeasurementUnit;
import org.accretegb.modules.hibernate.Passport;
import org.accretegb.modules.hibernate.Stock;
import org.accretegb.modules.hibernate.dao.ExperimentDAO;
import org.accretegb.modules.hibernate.dao.ExperimentFactorDAO;
import org.accretegb.modules.hibernate.dao.ExperimentFactorValueDAO;
import org.accretegb.modules.hibernate.dao.MeasurementUnitDAO;
import org.accretegb.modules.hibernate.dao.StockDAO;
import org.accretegb.modules.tab.TabComponentPanel;
import org.accretegbR.experimental.AlphaDesign;
import org.accretegbR.experimental.CompleteRandomizedDesign;
Expand All @@ -32,6 +36,7 @@
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.JTextComponent;

Expand All @@ -51,6 +56,12 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -460,11 +471,193 @@ public void actionPerformed(ActionEvent e) {
}
});
randomizeButton.setName("Button");
designSelectionPanel.add(randomizeButton, "tag submit, sizegroup bttn, alignx right");
JPanel subPanel = new JPanel();
subPanel.add(randomizeButton, "pushx, align right");
setRandomizeButton(randomizeButton);
JButton importButton = new JButton("Import");
importButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
importDesignButtonActionPerformed();
}
});
subPanel.add(importButton,"pushx, align right");
designSelectionPanel.add(subPanel, "w 100%, spanx");
return designSelectionPanel;
}

/**
* import design
*/
public void importDesignButtonActionPerformed(){
int option = JOptionPane.showOptionDialog(null,
"Choose an option to proceed",
"",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
new String[]{"Import a file","Download a template","Cancel"},
"default");
String selectedExperiment = (String) experimentSelectionBox.getSelectedItem();
if(option ==JOptionPane.OK_OPTION )
{
//import a file
if (selectedExperiment.equalsIgnoreCase(ExperimentConstants.SPLIT_DESIGN)){
if(!isSplitDesignInputValid()){
return;
}
}
if(isStockNameEmpty()){
try {
final JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileNameExtensionFilter("Comma separated files(.csv)", "csv"));
int status = fc.showOpenDialog(this);
if (fc.getSelectedFile() == null)
{
return;
}
String filename = fc.getSelectedFile().toString();
if (status == JFileChooser.APPROVE_OPTION) {
if (!(filename.trim().endsWith(".csv"))) {
JLabel errorFields = new JLabel("<HTML><FONT COLOR = Blue>"
+ "File should have a .csv extension only"
+ ".</FONT></HTML>");
JOptionPane.showMessageDialog(null,errorFields);
} else {
DefaultTableModel model = (DefaultTableModel) getExperimentalOutputPanel().getTable().getModel();
Utils.removeAllRowsFromTable(model);
BufferedReader br = new BufferedReader(new FileReader(new File(filename)));
// skip first line
String first = br.readLine();
String line = br.readLine().trim();
HashMap<String, Stock> stockNames = new HashMap<String, Stock>();
if (!selectedExperiment.equalsIgnoreCase(ExperimentConstants.SPLIT_DESIGN)){
while (line != null) {
System.out.println(line);
line = line.trim();
String[] row = line.split(",");
if(row.length != 3 ){
line = br.readLine();
continue;
}
Object[] newRow = new Object[model.getColumnCount()];
newRow[0] = new Boolean(false);
newRow[1] = row[0]; //plot
newRow[2] = row[1]; //replication
newRow[3] = null; //Exp_id
newRow[4] = null; //Exp_factor_value_id
String stockName = row[2];
if(stockNames.containsKey(stockName)){
newRow[5] = stockNames.get(stockName).getStockId(); //stock_id
}else{
System.out.println("\nlooking for "+stockName);
List<Stock> stocks = StockDAO.getInstance().findStockByName(stockName);
if(stocks.size() == 0){
continue;
}
newRow[5] = stocks.get(0).getStockId(); //stock_id
stockNames.put(stockName, stocks.get(0));
}
newRow[6] = stockName; //stockName
Stock s = stockNames.get(stockName);
Passport p = s.getPassport();
if (p != null ){
newRow[7] = p.getAccession_name(); //Accession_name
newRow[8] = p.getPedigree(); //pedigree
newRow[11] = p.getClassification() == null ? "NULL" : p.getClassification().getClassificationCode(); //ClassificationCode
newRow[12] = p.getTaxonomy() == null ? "NULL" : p.getTaxonomy().getPopulation();// Population
}
newRow[9] = s.getStockGeneration() == null ? "NULL" : s.getStockGeneration().getGeneration(); //generation
newRow[10] = s.getStockGeneration() == null ? "NULL" : s.getStockGeneration().getCycle(); //cycle
model.addRow(newRow);
line = br.readLine();
}
}else{
while (line != null) {
System.out.println(line);
line = line.trim();
String[] row = line.split(",");
if(row.length != 6 ){
line = br.readLine();
continue;
}
Object[] newRow = new Object[model.getColumnCount()];
newRow[0] = new Boolean(false);
newRow[1] = row[0]; //plot
newRow[2] = row[1]; //splot
newRow[3] = row[2]; //replication
newRow[4] = row[3]; //tr1
newRow[5] = row[4]; //tr2
newRow[6] = null; //Exp_id
newRow[7] = null; //Exp_factor_value_id
String stockName = row[5];
if(stockNames.containsKey(stockName)){
newRow[8] = stockNames.get(stockName).getStockId(); //stock_id
}else{
System.out.println("\nlooking for "+stockName);
List<Stock> stocks = StockDAO.getInstance().findStockByName(stockName);
if(stocks.size() == 0){
continue;
}
newRow[8] = stocks.get(0).getStockId(); //stock_id
stockNames.put(stockName, stocks.get(0));
}
newRow[9] = stockName; //stockName
Stock s = stockNames.get(stockName);
Passport p = s.getPassport();
if (p != null ){
newRow[10] = p.getAccession_name(); //Accession_name
newRow[11] = p.getPedigree(); //pedigree
newRow[14] = p.getClassification() == null ? "NULL" : p.getClassification().getClassificationCode(); //ClassificationCode
newRow[15] = p.getTaxonomy() == null ? "NULL" : p.getTaxonomy().getPopulation();// Population
}
newRow[12] = s.getStockGeneration() == null ? "NULL" : s.getStockGeneration().getGeneration(); //generation
newRow[13] = s.getStockGeneration() == null ? "NULL" : s.getStockGeneration().getCycle(); //cycle
model.addRow(newRow);
line = br.readLine();
}
}
getExperimentalOutputPanel().getTable().setModel(model);
br.close();
setNumberOfItems();
}
}

}catch (Exception E) {
System.out.println(E.toString());
E.printStackTrace();
}
}

}else if(option == JOptionPane.NO_OPTION){
//download a template
JFileChooser fileChooser = new JFileChooser();
File file = new File(System.getProperty("java.io.tmpdir") + "/" + selectedExperiment.replace("\\s+", "_")+".csv");
fileChooser.setSelectedFile(file);
int approve = fileChooser.showSaveDialog(this);
if (approve != JFileChooser.APPROVE_OPTION) {
return;
}
file = fileChooser.getSelectedFile();
BufferedWriter writer;
try {
writer = new BufferedWriter(new FileWriter(file));
if (!selectedExperiment.equalsIgnoreCase(ExperimentConstants.SPLIT_DESIGN)){
writer.write("Plot,Replication,Stock Name");
}else{
writer.write("Plot,Splot,Replication,tr1,tr2,Stock Name");
}
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ;
}else{
return;
}

}

/**
* Generate ScrollPane for inputing treatment info
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ private void addListeners() {

final CheckBoxIndexColumnTable table = getBulkTablePanel().getTable();
Utils.removeAllRowsFromTable((DefaultTableModel)table.getModel());
table.getModel().addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
getBulkTablePanel().getNumberOfRows().setText(String.valueOf(getBulkTablePanel().getTable().getRowCount()));
}});
importStocks.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
showPopup();
Expand Down Expand Up @@ -329,27 +333,6 @@ public void actionPerformed(ActionEvent e) {
}
}
});
table.getModel().addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
bulkTablePanel.getNumberOfRows().setText(String.valueOf(bulkTablePanel.getTable().getRowCount()));
int quantityColumn = table.getIndexOf(ColumnConstants.QUANTITY);
if(e.getColumn() != quantityColumn)
return;
int unitIdColumn = table.getIndexOf(ColumnConstants.UNIT_ID);
int unitColumn = table.getIndexOf(ColumnConstants.UNIT);
MeasurementUnit count = unitsList.get(1);
for(MeasurementUnit unit : unitsList) {
if(unit.getUnitType().equals("count"))
count = unit;
}
for(int row : table.getSelectedRows()) {
if(table.getValueAt(row, unitColumn) == null && Utils.isInteger(String.valueOf(table.getValueAt(row, quantityColumn)))) {
table.setValueAt(count.getMeasurementUnitId(), row, unitIdColumn);
table.setValueAt(count.getUnitType(), row, unitColumn);
}// if not null
}//for
}
});

getBulkTablePanel().getTable().addMouseListener(new MouseAdapter() {
@Override
Expand Down Expand Up @@ -558,7 +541,6 @@ private JPanel getButtonsPanel() {
buttonsPanel.add(multiply);
buttonsPanel.add(mixButton);
buttonsPanel.add(unmixButton, "wrap");

return buttonsPanel;
}

Expand Down
Loading

0 comments on commit b7ea2fa

Please sign in to comment.