Skip to content

Commit

Permalink
Prototype Project Manager take 1. (#5)
Browse files Browse the repository at this point in the history
* revises look and feel

* adds basic support arch

* refactors

* refactors

* adds prefix tree (trie) for use with parsing spot names

* fixes css location

* prototypes new feature for project per Bodorkos

* refactors apearance

* refines look and feel

* begins applying serializability to project

* basic project save and open using serialization

* tweaks to menu

* prototypes project manager phase one

* prototypes project manager phase one
  • Loading branch information
bowring authored May 19, 2017
1 parent 30617d5 commit 9959a5e
Show file tree
Hide file tree
Showing 23 changed files with 1,624 additions and 131 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ nbproject/
test_*
*.ser
*.zip
*.squid

# Resources
!squidApp/src/main/resources/org/cirdles/squid/gui/version.txt
Expand Down
2 changes: 1 addition & 1 deletion common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'java'
apply plugin: 'maven'

String mavenGroupId = 'org.cirdles'
String mavenVersion = '0.0.1'
String mavenVersion = '0.0.2'


sourceCompatibility = '1.8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.function.Predicate;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
Expand All @@ -32,14 +34,25 @@
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.BorderStrokeStyle;
import javafx.scene.layout.BorderWidths;
import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Color;
import javax.xml.bind.JAXBException;
import org.cirdles.calamari.prawn.PrawnFile.Run;
import org.cirdles.squid.dialogs.SquidMessageDialog;
import org.cirdles.squid.gui.RunsViewModel.ShrimpFractionListCell;
import org.cirdles.squid.gui.RunsViewModel.SpotNameMatcher;
import static org.cirdles.squid.gui.SquidUI.primaryStageWindow;
import static org.cirdles.squid.gui.SquidUIController.squidProject;
import org.cirdles.squid.utilities.SquidPrefixTree;
import org.xml.sax.SAXException;

/**
Expand All @@ -51,11 +64,11 @@
*/
public class ProjectManagerController implements Initializable {


private ObservableList<Run> shrimpRuns;
private ObservableList<Run> shrimpRunsRefMat;
private static final String SPOT_LIST_CSS_STYLE_SPECS = "-fx-font-size: 12px; -fx-font-weight: bold; -fx-font-family: 'Courier New';";
private static ObservableList<Run> shrimpRuns;
private static ObservableList<Run> shrimpRunsRefMat;
private final RunsViewModel runsModel = new RunsViewModel();

@FXML
private TextField orignalPrawnFileName;
@FXML
Expand All @@ -69,18 +82,29 @@ public class ProjectManagerController implements Initializable {
@FXML
private Label headerLabel;
@FXML
private TextField filterSpotName;
@FXML
private Label spotsShownLabel;
@FXML
private Label headerLabelRefMat;
private static final String spotListStyleSpecs = "-fx-font-size: 12px; -fx-font-weight: bold; -fx-font-family: 'Courier New';";
@FXML
private Button saveSpotNameButton;
@FXML
private Button savePrawnFileButton;
@FXML
private Button setFilteredSpotsAsRefMatButton;
@FXML
private TreeView<String> prawnAuditTree;
@FXML
private TabPane prawnFileTabPane;
@FXML
private Label summaryStatsLabel;
@FXML
private Label totalAnalysisTimeLabel;
@FXML
private TextField projectNameText;
@FXML
private TextField analystNameText;
@FXML
private TextField filterSpotNameText;

/**
* Initializes the controller class.
Expand All @@ -95,46 +119,117 @@ public void initialize(URL url, ResourceBundle rb) {
savePrawnFileButton.setDisable(true);
saveSpotNameButton.setDisable(true);
setFilteredSpotsAsRefMatButton.setDisable(true);

prawnFileTabPane.setBorder(new Border(new BorderStroke(Color.GRAY, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(1))));

// detect if project opened from menu by deserialization
if (squidProject.prawnFileExists()) {
setUpPrawnFile();
}
}

@FXML
private void selectPrawnFileAction(ActionEvent event) {
private void setUpPrawnFile() {
projectNameText.setText(squidProject.getProjectName());
analystNameText.setText(squidProject.getAnalystName());

try {
if (squidProject.selectPrawnFile(primaryStageWindow)) {
orignalPrawnFileName.setText(squidProject.getPrawnXMLFileName());

orignalPrawnFileName.setText(squidProject.getPrawnXMLFileName());
softwareVersionLabel.setText(
"Software Version: "
+ squidProject.getPrawnFileShrimpSoftwareVersionName());

shrimpRuns = squidProject.getListOfPrawnFileRuns();
shrimpRunsRefMat = squidProject.getShrimpRunsRefMat();
shrimpRefMatList.setItems(shrimpRunsRefMat);

softwareVersionLabel.setText(
"Software Version: "
+ squidProject.getPrawnFileShrimpSoftwareVersionName());
setUpShrimpFractionList();

shrimpRuns = squidProject.getListOfPrawnFileRuns();
shrimpRunsRefMat = FXCollections.observableArrayList();
savePrawnFileButton.setDisable(false);
saveSpotNameButton.setDisable(false);
setFilteredSpotsAsRefMatButton.setDisable(false);

setUpShrimpFractionList();
setUpPrawnFileAuditTreeView();
}

private void setUpPrawnFileAuditTreeView() {
prawnAuditTree.setStyle(SPOT_LIST_CSS_STYLE_SPECS);

TreeItem<String> rootItem = new TreeItem<>("Spots", null);
rootItem.setExpanded(true);
prawnAuditTree.setRoot(rootItem);

SquidPrefixTree spotPrefixTree = squidProject.generatePrefixTreeFromSpotNames();

String summaryStatsString = buildSummaryDataString(spotPrefixTree);
rootItem.setValue("Spots by prefix:" + summaryStatsString);

// format into rows for summary tab
summaryStatsLabel.setText("Session summary:\n\t" + summaryStatsString.replaceAll(";", "\n\t"));

totalAnalysisTimeLabel.setText("Total session time in hours = " + (int) squidProject.getSessionDurationHours());

populatePrefixTreeView(rootItem, spotPrefixTree);
}

private void populatePrefixTreeView(TreeItem<String> parentItem, SquidPrefixTree squidPrefixTree) {

List<SquidPrefixTree> children = squidPrefixTree.getChildren();

for (int i = 0; i < children.size(); i++) {
if (!children.get(i).isleaf()) {
TreeItem<String> item
= new TreeItem<>(children.get(i).getStringValue()
+ buildSummaryDataString(children.get(i))
);

parentItem.getChildren().add(item);

if (children.get(i).hasChildren()) {
populatePrefixTreeView(item, children.get(i));
}

savePrawnFileButton.setDisable(false);
saveSpotNameButton.setDisable(false);
setFilteredSpotsAsRefMatButton.setDisable(false);
} else {
parentItem.setValue(children.get(i).getParent().getStringValue()
+ " Dups=" + String.format("%1$ 2d", children.get(i).getParent().getCountOfDups())
+ " Species=" + String.format("%1$ 2d", children.get(i).getCountOfSpecies())
+ " Scans=" + String.format("%1$ 2d", children.get(i).getCountOfScans())
+ ((String) (children.size() > 1 ? " ** see duplicates below **" : ""))
);
}
}
}

} catch (IOException | JAXBException | SAXException iOException) {
private String buildSummaryDataString(SquidPrefixTree tree) {
// build species and scans count string
String speciesCounts = "";
for (Integer count : tree.getMapOfSpeciesFrequencies().keySet()) {
speciesCounts += "[" + String.format("%1$ 2d", count) + " in " + String.format("%1$ 3d", tree.getMapOfSpeciesFrequencies().get(count)) + "]";
}

String scansCounts = "";
for (Integer count : tree.getMapOfScansFrequencies().keySet()) {
scansCounts += "[" + String.format("%1$ 2d", count) + " in " + String.format("%1$ 3d", tree.getMapOfScansFrequencies().get(count)) + "]";
}

String summary = " Analyses=" + String.format("%1$ 3d", tree.getCountOfLeaves())
+ "; Dups=" + String.format("%1$ 3d", tree.getCountOfDups())
+ "; Species:" + speciesCounts
+ "; Scans:" + scansCounts;

return summary;
}

private void setUpShrimpFractionListHeaders() {

headerLabel.setStyle(spotListStyleSpecs);
headerLabel.setStyle(SPOT_LIST_CSS_STYLE_SPECS);
headerLabel.setText(
String.format("%1$-" + 20 + "s", "Spot Name")
+ String.format("%1$-" + 12 + "s", "Date")
+ String.format("%1$-" + 12 + "s", "Time")
+ String.format("%1$-" + 6 + "s", "Peaks")
+ String.format("%1$-" + 6 + "s", "Scans"));

headerLabelRefMat.setStyle(spotListStyleSpecs);
headerLabelRefMat.setStyle(SPOT_LIST_CSS_STYLE_SPECS);
headerLabelRefMat.setText(
String.format("%1$-" + 20 + "s", "Ref Mat Name")
+ String.format("%1$-" + 12 + "s", "Date")
Expand All @@ -145,7 +240,7 @@ private void setUpShrimpFractionListHeaders() {

private void setUpShrimpFractionList() {

shrimpFractionList.setStyle(spotListStyleSpecs);
shrimpFractionList.setStyle(SPOT_LIST_CSS_STYLE_SPECS);

shrimpFractionList.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Run>() {
@Override
Expand All @@ -169,19 +264,21 @@ public void changed(ObservableValue<? extends Run> observable, Run oldValue, Run

shrimpFractionList.itemsProperty().bind(runsModel.viewableShrimpRunsProperty());

shrimpFractionList.setContextMenu(createContextMenu());
shrimpFractionList.setContextMenu(createAllSpotsViewContextMenu());

// display of selected reference materials
shrimpRefMatList.setStyle(spotListStyleSpecs);
shrimpRefMatList.setStyle(SPOT_LIST_CSS_STYLE_SPECS);

shrimpRefMatList.setCellFactory(
(lv)
-> new ShrimpFractionListCell()
);

shrimpRefMatList.setContextMenu(createRefMatSpotsViewContextMenu());

}

private ContextMenu createContextMenu() {
private ContextMenu createAllSpotsViewContextMenu() {
ContextMenu contextMenu = new ContextMenu();
MenuItem menuItem = new MenuItem("Remove this spot.");
menuItem.setOnAction((evt) -> {
Expand All @@ -194,17 +291,40 @@ private ContextMenu createContextMenu() {
}
});
contextMenu.getItems().add(menuItem);

menuItem = new MenuItem("Split Prawn file starting with this run.");
menuItem.setOnAction((evt) -> {
Run selectedRun = shrimpFractionList.getSelectionModel().getSelectedItem();
if (selectedRun != null) {
SquidMessageDialog.showInfoDialog("Coming soon!");
}
});
contextMenu.getItems().add(menuItem);

return contextMenu;
}

private ContextMenu createRefMatSpotsViewContextMenu() {
ContextMenu contextMenu = new ContextMenu();
MenuItem menuItem = new MenuItem("Clear list.");
menuItem.setOnAction((evt) -> {
shrimpRunsRefMat.clear();
shrimpRefMatList.setItems(shrimpRunsRefMat);
});
contextMenu.getItems().add(menuItem);
return contextMenu;
}

@FXML
private void filterSpotNameKeyReleased(KeyEvent event) {
String filterString = filterSpotName.getText().toUpperCase(Locale.US).trim();
filterRuns();
}

private void filterRuns() {
String filterString = filterSpotNameText.getText().toUpperCase(Locale.US).trim();
Predicate<Run> filter = new SpotNameMatcher(filterString);
runsModel.filterProperty().set(filter);
spotsShownLabel.setText(runsModel.showFilteredOverAllCount());

squidProject.setFilterForRefMatSpotNames(filterString);
}

@FXML
Expand All @@ -213,13 +333,15 @@ private void saveSpotNameAction(ActionEvent event) {
((Run) saveSpotNameButton.getUserData()).getPar().get(0).setValue(selectedSpotNameText.getText().trim().toUpperCase(Locale.US));
shrimpFractionList.refresh();
shrimpRefMatList.refresh();
setUpPrawnFileAuditTreeView();
}
}

@FXML
private void setFilteredSpotsToRefMatAction(ActionEvent event) {
shrimpRunsRefMat = runsModel.getViewableShrimpRuns();
shrimpRefMatList.setItems(shrimpRunsRefMat);
squidProject.setFilterForRefMatSpotNames(filterSpotNameText.getText().toUpperCase(Locale.US).trim());
}

@FXML
Expand All @@ -229,7 +351,20 @@ private void savePrawnFileAction(ActionEvent event) {
orignalPrawnFileName.setText(SquidUIController.squidProject.getPrawnXMLFileName());
shrimpFractionList.refresh();
shrimpRefMatList.refresh();
setUpPrawnFileAuditTreeView();
} catch (IOException | JAXBException | SAXException iOException) {
}
}

/**
* Saves underlying List to squidProject so it can be serialized
*/
public static void saveProjectData() {
List<Run> plainListRefMat = new ArrayList<>(shrimpRunsRefMat.size());
for (Run r : shrimpRunsRefMat) {
plainListRefMat.add(r);
}
squidProject.setShrimpRunsRefMat(plainListRefMat);
}

}
Loading

0 comments on commit 9959a5e

Please sign in to comment.