Skip to content
Snippets Groups Projects
Commit 97c02d9b authored by Robert Goldmann's avatar Robert Goldmann
Browse files

prepared gui for #15

parent 761b764b
Branches
Tags
No related merge requests found
...@@ -860,6 +860,34 @@ public class Controller ...@@ -860,6 +860,34 @@ public class Controller
settings.setSavePath(DEFAULT_SAVE_PATH); settings.setSavePath(DEFAULT_SAVE_PATH);
} }
} }
@FXML
public void createReport()
{
try
{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/de/deadlocker8/smarttime/fxml/ReportGUI.fxml"));
Parent root = (Parent)fxmlLoader.load();
Stage newStage = new Stage();
newStage.setScene(new Scene(root, 500, 500));
newStage.setMinWidth(300);
newStage.setMinHeight(300);
newStage.setTitle("PDF-Report erstellen");
newStage.getIcons().add(icon);
newStage.initOwner(stage);
ReportController reportController = (ReportController)fxmlLoader.getController();
reportController.init(this, newStage, settings, icon);
newStage.setResizable(true);
newStage.initModality(Modality.APPLICATION_MODAL);
newStage.showAndWait();
}
catch(IOException d)
{
Logger.error(d);
}
}
public void about() public void about()
{ {
......
package de.deadlocker8.smarttime.controller;
import java.util.ArrayList;
import java.util.Collections;
import de.deadlocker8.smarttime.core.SQL;
import de.deadlocker8.smarttime.core.Settings;
import de.deadlocker8.smarttime.core.Utils;
import javafx.fxml.FXML;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ListView;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import logger.Logger;
import tools.AlertGenerator;
public class ReportController
{
@FXML private ComboBox<String> comboBoxProject;
@FXML private ListView<CheckBox> listViewTasks;
@FXML private RadioButton radioButtonList;
@FXML private RadioButton radioButtonGroupByTasks;
@FXML private RadioButton radioButtonGroupByDate;
private Controller controller;
private Stage stage;
private Image icon;
private Settings settings;
private SQL sql;
private final String ALL_PROJECTS = "Alle";
public void init(Controller controller, Stage stage, Settings settings, Image icon)
{
this.controller = controller;
this.stage = stage;
this.settings = settings;
this.icon = icon;
sql = new SQL(settings.getSavePath() + "/" + Utils.DATABASE_NAME);
prefill();
}
private void prefill()
{
ToggleGroup toggleGroup = new ToggleGroup();
radioButtonList.setToggleGroup(toggleGroup);
radioButtonGroupByTasks.setToggleGroup(toggleGroup);
radioButtonGroupByDate.setToggleGroup(toggleGroup);
radioButtonList.setSelected(true);
try
{
ArrayList<String> projectNames = sql.getProjectNames();
Collections.sort(projectNames);
comboBoxProject.getItems().add(ALL_PROJECTS);
comboBoxProject.getItems().addAll(projectNames);
}
catch(Exception e)
{
Logger.error(e);
}
comboBoxProject.valueProperty().addListener((observable, oldValue, newValue)->{
if(newValue.equals(ALL_PROJECTS))
{
radioButtonGroupByTasks.setDisable(true);
listViewTasks.getItems().clear();
return;
}
try
{
ArrayList<String> tasks = sql.getTaskNamesByProject(newValue);
Collections.sort(tasks);
listViewTasks.getItems().clear();
for(String currentTask : tasks)
{
CheckBox currentCheckBox = new CheckBox(currentTask);
currentCheckBox.setSelected(true);
currentCheckBox.selectedProperty().addListener((obs, oldVal, newVal)->{
checkTasks();
});
listViewTasks.getItems().add(currentCheckBox);
}
radioButtonGroupByTasks.setDisable(false);
}
catch(Exception e)
{
Logger.error(e);
}
checkTasks();
});
comboBoxProject.setValue(ALL_PROJECTS);
}
private int getNumberOfActivatedTasks()
{
int numberOfActivatedTasks = 0;
for(CheckBox currentCheckBox : listViewTasks.getItems())
{
if(currentCheckBox.isSelected())
{
numberOfActivatedTasks++;
}
}
return numberOfActivatedTasks;
}
private void checkTasks()
{
if(getNumberOfActivatedTasks() > 1)
{
radioButtonGroupByTasks.setDisable(false);
}
else
{
radioButtonGroupByTasks.setDisable(true);
}
}
@FXML
public void generateReport()
{
String project = comboBoxProject.getValue();
if(project == null || project.equals(""))
{
AlertGenerator.showAlert(AlertType.WARNING, "Warnung", "", "Bitte wähle ein Projekt aus", icon, stage, null, false);
return;
}
if(!project.equals(ALL_PROJECTS) && getNumberOfActivatedTasks() == 0)
{
AlertGenerator.showAlert(AlertType.WARNING, "Warnung", "", "Bitte wähle mindestens einen Task aus aus", icon, stage, null, false);
return;
}
//TODO file chooser
//TODO generate report
}
@FXML
public void cancel()
{
stage.close();
}
}
\ No newline at end of file
...@@ -41,6 +41,11 @@ ...@@ -41,6 +41,11 @@
<MenuItem mnemonicParsing="false" onAction="#exportAsJSON" text="als JSON" /> <MenuItem mnemonicParsing="false" onAction="#exportAsJSON" text="als JSON" />
</items> </items>
</Menu> </Menu>
<Menu mnemonicParsing="false" text="Report">
<items>
<MenuItem mnemonicParsing="false" onAction="#createReport" text="PDF Report erstellen" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="?"> <Menu mnemonicParsing="false" text="?">
<items> <items>
<MenuItem mnemonicParsing="false" onAction="#about" text="Über" /> <MenuItem mnemonicParsing="false" onAction="#about" text="Über" />
......
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.deadlocker8.smarttime.controller.ReportController">
<children>
<VBox prefHeight="200.0" prefWidth="100.0" spacing="14.0" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0">
<children>
<HBox spacing="14.0">
<children>
<Label alignment="CENTER_RIGHT" minWidth="100.0" prefWidth="100.0" text="Projekt:">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<ComboBox fx:id="comboBoxProject" maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="14.0" VBox.vgrow="ALWAYS">
<children>
<Label alignment="CENTER_RIGHT" minWidth="100.0" prefWidth="100.0" text="Task:">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<ListView fx:id="listViewTasks" prefWidth="358.0" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="14.0">
<children>
<Label alignment="CENTER_RIGHT" minWidth="100.0" prefWidth="100.0" text="Darstellung:">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<VBox spacing="5.0">
<children>
<RadioButton fx:id="radioButtonList" mnemonicParsing="false" text="Liste" />
<RadioButton fx:id="radioButtonGroupByTasks" mnemonicParsing="false" text="gruppiert nach Tasks" />
<RadioButton fx:id="radioButtonGroupByDate" mnemonicParsing="false" text="gruppiert nach Datum" />
</children>
</VBox>
</children>
</HBox>
<HBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="200.0" spacing="25.0">
<children>
<Button mnemonicParsing="false" onAction="#generateReport" text="Erzeugen">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#cancel" text="Abbrechen">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Button>
</children>
<VBox.margin>
<Insets top="10.0" />
</VBox.margin>
</HBox>
</children>
</VBox>
</children>
</AnchorPane>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment