Skip to content

Commit

Permalink
Prompt to save projects when there was change
Browse files Browse the repository at this point in the history
Only ask the user to save the projects when changes to the projects were detected.
  • Loading branch information
Felicity117 committed Sep 25, 2019
1 parent 270a4f7 commit 7ac15eb
Show file tree
Hide file tree
Showing 28 changed files with 255 additions and 117 deletions.
34 changes: 13 additions & 21 deletions AccreteGB-src/src/main/java/org/accretegb/modules/MainLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.accretegb.modules.projectexplorer.ProjectExplorerTabbedPane;
import org.accretegb.modules.projectexplorer.ProjectTreeNode;
import org.accretegb.modules.tab.TabManager;
import org.accretegb.modules.util.ChangeMonitor;
import org.accretegb.modules.projectexplorer.ProjectExplorerPanel;
import org.accretegb.modules.projectmanager.ProjectManager;

Expand All @@ -37,6 +38,7 @@
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map.Entry;

/**
* @author nkumar
Expand All @@ -49,7 +51,7 @@ public class MainLayout {
private static String TITLE = "AccreteGB - The Breeder's ToolBox";
private static String EXIT_MESSAGE = "Exit MaizeAtlas Application";
private static String CONFIRM_MESSAGE = "Are you sure you want to exit ?";
private static String SAVE_PROJECTS_MESSAGE = "You may have modified the following projects :\n";
private static String SAVE_PROJECTS_MESSAGE = "Changes to the following projects have been detected:\n";
private static String SAVE_BEFORE_EXIT = "Save all before exit, click yes\nExit without saving, click no";


Expand Down Expand Up @@ -95,28 +97,20 @@ public void initialize() throws IOException {
getFrame().addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
JFrame frame = (JFrame) e.getSource();
ArrayList<String> modifiedProjects = new ArrayList();
JTree projectTrees = AccreteGBBeanFactory.getContext().getBean("projectExplorerTabbedPane", ProjectExplorerTabbedPane.class)
.getExplorerPanel().getProjectsTree();
DefaultMutableTreeNode projectsRoot = (DefaultMutableTreeNode) projectTrees.getModel().getRoot();
for(int index = 0;index < projectsRoot.getChildCount(); ++index){
ProjectTreeNode projectNode = (ProjectTreeNode) projectsRoot.getChildAt(index);
if(projectNode.isModified()){
modifiedProjects.add(projectNode.getNodeName());
}
}
for (Entry<Integer, Boolean> entry : ChangeMonitor.changedProject.entrySet()) {
if(entry.getValue()) {
modifiedProjects.add(ChangeMonitor.projectIdName.get(entry.getKey()));
}
}

if(modifiedProjects.size() > 0){
int result = JOptionPane.showConfirmDialog(frame, SAVE_PROJECTS_MESSAGE + modifiedProjects + "\n" + SAVE_BEFORE_EXIT, EXIT_MESSAGE,
int result = JOptionPane.showConfirmDialog(null, SAVE_PROJECTS_MESSAGE + modifiedProjects + "\n" + SAVE_BEFORE_EXIT, EXIT_MESSAGE,
JOptionPane.YES_NO_CANCEL_OPTION);
if (result == JOptionPane.YES_OPTION) {
for(int index = 0;index < projectsRoot.getChildCount(); ++index){
ProjectTreeNode projectNode = (ProjectTreeNode) projectsRoot.getChildAt(index);
if(projectNode.isModified()){
projectNode.setModified(false);
String projectName = projectNode.getNodeName();
int projectId = PMProjectDAO.getInstance().findProjectId(projectName);
for(Entry<Integer, Boolean> entry : ChangeMonitor.changedProject.entrySet()){
if(entry.getValue()) {
int projectId = entry.getKey();
ProjectManager.saveOrDeleteProject(projectId,"save");
System.exit(0);
}
Expand All @@ -126,14 +120,12 @@ public void windowClosing(WindowEvent e) {
}

}else{
int result = JOptionPane.showConfirmDialog(frame, CONFIRM_MESSAGE, EXIT_MESSAGE,
int result = JOptionPane.showConfirmDialog(null, CONFIRM_MESSAGE, EXIT_MESSAGE,
JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) {
System.exit(0);
}
}


}

private JTabbedPane getProjectsTree() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.accretegb.modules.hibernate.dao.MeasurementUnitDAO;
import org.accretegb.modules.hibernate.dao.StockDAO;
import org.accretegb.modules.tab.TabComponentPanel;
import org.accretegb.modules.util.ChangeMonitor;
import org.accretegbR.experimental.AlphaDesign;
import org.accretegbR.experimental.CompleteRandomizedDesign;
import org.accretegbR.experimental.ExperimentDesign;
Expand Down Expand Up @@ -105,6 +106,8 @@ public class ExperimentSelectionPanel extends TabComponentPanel {
public JProgressBar progress = new JProgressBar();
private JLabel reminderMsg;
private String currentComm = "";
private int projectID = -1;

public void initialize() {
setDesignSelectionComboBoxActionListener();
setSyncButtonListener();
Expand Down Expand Up @@ -467,7 +470,8 @@ public JPanel getDesignSelectionPanel() {
JButton randomizeButton = new JButton("Randomize");
randomizeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
submitDesignSelectionButton();
submitDesignSelectionButton();
ChangeMonitor.markAsChanged(projectID);
}
});
randomizeButton.setName("Button");
Expand Down Expand Up @@ -1592,4 +1596,10 @@ public String getCurrentComm() {
public void setCurrentComm(String currentComm) {
this.currentComm = currentComm;
}
public int getProjectID() {
return projectID;
}
public void setProjectID(int projectID) {
this.projectID = projectID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.accretegb.modules.hibernate.dao.MeasurementUnitDAO;
import org.accretegb.modules.hibernate.dao.StockDAO;
import org.accretegb.modules.tab.TabComponentPanel;
import org.accretegb.modules.util.ChangeMonitor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.support.GenericXmlApplicationContext;
Expand All @@ -72,8 +73,16 @@ public class Bulk extends JPanel {
private List<MeasurementUnit> unitsList;
private FieldGenerated fieldGenerated;
private StickerGenerator stickerGenerator;
private int projectID = -1;
public boolean modified;

public int getProjectID() {
return projectID;
}

public void setProjectID(int projectID) {
this.projectID = projectID;
}
public TableToolBoxPanel getBulkTablePanel() {
return bulkTablePanel;
}
Expand Down Expand Up @@ -117,11 +126,16 @@ private void addListeners() {
Utils.removeAllRowsFromTable((DefaultTableModel)table.getModel());
table.getModel().addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
getBulkTablePanel().getNumberOfRows().setText(String.valueOf(getBulkTablePanel().getTable().getRowCount()));
if (e.getType() == TableModelEvent.DELETE || e.getType() == TableModelEvent.INSERT) {
getBulkTablePanel().getNumberOfRows().setText(String.valueOf(getBulkTablePanel().getTable().getRowCount()));
ChangeMonitor.markAsChanged(projectID);
}

}});
importStocks.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
showPopup();
ChangeMonitor.markAsChanged(projectID);
}
});
mixButton.addActionListener(new ActionListener() {
Expand Down Expand Up @@ -201,7 +215,7 @@ public void actionPerformed(ActionEvent e) {
}else{
nextLink++;
}

ChangeMonitor.markAsChanged(projectID);

}
});
Expand All @@ -221,7 +235,7 @@ public void actionPerformed(ActionEvent e) {
table.setValueAt(null, i, table.getIndexOf(ColumnConstants.FINAL_STOCK_NAME));
}
}

ChangeMonitor.markAsChanged(projectID);
}

});
Expand All @@ -234,7 +248,7 @@ public void actionPerformed(ActionEvent e) {
table.setValueAt(quantity, row, table.getIndexOf(ColumnConstants.QUANTITY));
}
}

ChangeMonitor.markAsChanged(projectID);
}
});
setUnit.addActionListener(new ActionListener() {
Expand All @@ -253,7 +267,7 @@ public void actionPerformed(ActionEvent e) {
table.setValueAt(unit, row, table.getIndexOf(ColumnConstants.UNIT));
table.setValueAt(unitId, row, table.getIndexOf(ColumnConstants.UNIT_ID));
}

ChangeMonitor.markAsChanged(projectID);
}
});
mixUnit.addActionListener(new ActionListener() {
Expand All @@ -278,7 +292,7 @@ public void actionPerformed(ActionEvent e) {
}
else break;
}//while

ChangeMonitor.markAsChanged(projectID);
}//if last element
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.accretegb.modules.hibernate.dao.ObservationUnitDAO;
import org.accretegb.modules.hibernate.dao.StockDAO;
import org.accretegb.modules.tab.TabComponentPanel;
import org.accretegb.modules.util.ChangeMonitor;
import org.accretegb.modules.constants.ColumnConstants;

public class FieldGenerated extends TabComponentPanel {
Expand All @@ -64,15 +65,17 @@ public class FieldGenerated extends TabComponentPanel {
private JButton multiFemaleButton;
private JButton clearMatingtypeButton;
private JButton setUnsetSelectionButton;
int rowNum;
public int nextLink;
private JProgressBar progressBar;
private JComboBox matingMethod;
private JButton setMatingMethod;
private JButton unsetMatingMethod;
private List<PlantingRow> stockList;
public HashMap<String, Integer> mateMethodtoID = new HashMap<String, Integer>();
private HashSet<Integer> tagsCreatedinHarvest = new HashSet<Integer>();
private int projectID = -1;
public HashMap<String, Integer> mateMethodtoID = new HashMap<String, Integer>();
public int rowNum;
public int nextLink;

public boolean modified = false;

public TableToolBoxPanel getCrossingTablePanel() {
Expand All @@ -82,6 +85,14 @@ public TableToolBoxPanel getCrossingTablePanel() {
public void setCrossingTablePanel(TableToolBoxPanel crossingTablePanel) {
this.crossingTablePanel = crossingTablePanel;
}

public int getProjectID() {
return projectID;
}

public void setProjectID(int projectID) {
this.projectID = projectID;
}

public void initialize() {
setLayout(new MigLayout("insets 10, gap 10"));
Expand Down Expand Up @@ -132,6 +143,7 @@ public void actionPerformed(ActionEvent e) {
if(matingMethod.getSelectedIndex() == matingMethod.getItemCount()-1) {
matingMethod.setSelectedIndex(0);
new MateMethodPanel(FieldGenerated.this);
ChangeMonitor.markAsChanged(projectID);
}
}
});
Expand Down Expand Up @@ -160,6 +172,7 @@ public void actionPerformed(ActionEvent e) {
table.setValueAt(selectedMethod, i, table.getIndexOf(ColumnConstants.MATE_METHOD));
}
}
ChangeMonitor.markAsChanged(projectID);
}
});
unsetMatingMethod.addActionListener(new ActionListener() {
Expand All @@ -178,6 +191,7 @@ public void actionPerformed(ActionEvent e) {
table.setValueAt(null, i, table.getIndexOf(ColumnConstants.MATE_METHOD));
}
}
ChangeMonitor.markAsChanged(projectID);
}
});
}
Expand Down Expand Up @@ -363,6 +377,7 @@ public void actionPerformed(ActionEvent e) {
setButtonsUsability();
table.getRowSorter().toggleSortOrder(table.getIndexOf(ColumnConstants.MATE_LINK));
table.getRowSorter().toggleSortOrder(table.getIndexOf(ColumnConstants.MATE_LINK));
ChangeMonitor.markAsChanged(projectID);
}
});
}
Expand All @@ -380,11 +395,13 @@ private void generateButtons() {
selfButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SFOrSB("SF");
ChangeMonitor.markAsChanged(projectID);
}
});
sbButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SFOrSB("SB");
ChangeMonitor.markAsChanged(projectID);
}
});
addMatingButtonListener(crButton, "CR");
Expand Down Expand Up @@ -502,6 +519,7 @@ public void actionPerformed(ActionEvent e) {
table.getRowSorter().toggleSortOrder(table.getIndexOf(ColumnConstants.MATE_LINK));

}
ChangeMonitor.markAsChanged(projectID);
}

});
Expand All @@ -528,6 +546,7 @@ public void actionPerformed(ActionEvent e) {

table.clearSelection();
setButtonsUsability();
ChangeMonitor.markAsChanged(projectID);
}
});

Expand All @@ -552,6 +571,7 @@ public void actionPerformed(ActionEvent e) {

table.clearSelection();
setButtonsUsability();
ChangeMonitor.markAsChanged(projectID);
}
});

Expand Down Expand Up @@ -703,7 +723,11 @@ private void addListeners() {
Utils.removeAllRowsFromTable((DefaultTableModel)table.getModel());
table.getModel().addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
getCrossingTablePanel().getNumberOfRows().setText(String.valueOf(getCrossingTablePanel().getTable().getRowCount()));
if (e.getType() == TableModelEvent.DELETE || e.getType() == TableModelEvent.INSERT) {
getCrossingTablePanel().getNumberOfRows().setText(String.valueOf(getCrossingTablePanel().getTable().getRowCount()));
ChangeMonitor.markAsChanged(projectID);
}

}});
getCrossingTablePanel().getDeleteButton().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Expand Down Expand Up @@ -842,6 +866,7 @@ public void actionPerformed(ActionEvent e) {
progressBar.setVisible(true);
new HarvestingImportWorker(FieldGenerated.this, fc).execute();
updateTableStatus();
ChangeMonitor.markAsChanged(projectID);
}
});

Expand Down
Loading

0 comments on commit 7ac15eb

Please sign in to comment.