You can now search sharedtrips by stops
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
package controllers;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import model.SharedTrip;
|
||||
import model.Stop;
|
||||
import model.TripStop;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
@@ -22,13 +27,41 @@ public class SharedTripsController extends Controller{
|
||||
private TableColumn<SharedTrip, String> directionColumn;
|
||||
@FXML
|
||||
private TableColumn<SharedTrip, String> daysColumn;
|
||||
@FXML
|
||||
private ComboBox<Stop> stopsFilter;
|
||||
@FXML
|
||||
private ObservableList<SharedTrip> sharedTrips;
|
||||
|
||||
public void search(){
|
||||
sharedTrips.removeAll();
|
||||
sharedTrips.remove(0, sharedTrips.size());
|
||||
for(SharedTrip sharedTrip: parent.getSession().getDataManager().getSharedTrips()){
|
||||
//stops are equal
|
||||
boolean added = false;
|
||||
for (TripStop stop: sharedTrip.route){
|
||||
if (stop.equals(stopsFilter.getValue())){
|
||||
sharedTrips.add(sharedTrip);
|
||||
added = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (added){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runLater(){
|
||||
sharedTripsTable.setItems(parent.getSession().getDataManager().getSharedTrips());
|
||||
sharedTrips = FXCollections.observableArrayList(parent.getSession().getDataManager().getSharedTrips());
|
||||
sharedTripsTable.setItems(sharedTrips);
|
||||
tripNameColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().name));
|
||||
directionColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().direction));
|
||||
daysColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getDays()));
|
||||
stopsFilter.setItems(parent.getSession().getDataManager().getStops());
|
||||
stopsFilter.valueProperty().addListener( e ->{
|
||||
search();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,6 +46,10 @@ public class TripStop{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Stop stop){
|
||||
return name.getValue().equals(stop.getAddress());
|
||||
}
|
||||
|
||||
public void serialise(){
|
||||
serialiseTime = time.getValue();
|
||||
serialiseName = name.getValue();
|
||||
|
||||
@@ -11,27 +11,36 @@
|
||||
<GridPane layoutX="213.0" layoutY="99.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="20.0" minHeight="20.0" prefHeight="20.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="5.0" minHeight="5.0" prefHeight="5.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label text="Shared Trips" GridPane.columnSpan="3" GridPane.halignment="CENTER">
|
||||
<Label text="Shared Trips" GridPane.columnSpan="6" GridPane.halignment="CENTER">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<TableView fx:id="sharedTripsTable" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="3" GridPane.rowIndex="2">
|
||||
<TableView fx:id="sharedTripsTable" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="6" GridPane.rowIndex="4">
|
||||
<columns>
|
||||
<TableColumn fx:id="tripNameColumn" prefWidth="75.0" text="Trip Name" />
|
||||
<TableColumn fx:id="directionColumn" prefWidth="75.0" text="Direction" />
|
||||
<TableColumn fx:id="daysColumn" prefWidth="75.0" text="Days" />
|
||||
</columns>
|
||||
</TableView>
|
||||
<Label text="Search" GridPane.columnSpan="6" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
|
||||
<Separator prefWidth="200.0" GridPane.columnSpan="6" GridPane.rowIndex="2" />
|
||||
<Label text="Stops:" GridPane.rowIndex="3" />
|
||||
<ComboBox fx:id="stopsFilter" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
|
||||
Reference in New Issue
Block a user