summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/in/inf/se/projektthemenvergabe/view/KommentarHinzufuegenController.java
blob: a88a6af2f1a36c3f7dae4ee0ddd160cf3409118c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package de.fhswf.in.inf.se.projektthemenvergabe.view;

import java.io.IOException;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.TextArea;
import javafx.scene.layout.AnchorPane;

public class KommentarHinzufuegenController extends Dialog<String>
{
   @FXML
   private TextArea kommentarTextArea;

   /**
    * Create a {@link Dialog} with an empty {@link TextArea}.
    *
    */
   public KommentarHinzufuegenController()
   {
      this("");
   }

   /**
    * Create a {@link Dialog} with a {@link TextArea} and initialValue as
    * text.
    * 
    */
   public KommentarHinzufuegenController(String initialValue)
   {
      setTitle("Projektkommentar hinzufügen");
      setHeaderText("Geben Sie einen Kommentar zu dem Projekt ein.");

      FXMLLoader fxmlLoader = new FXMLLoader(
            getClass().getResource("KommentarHinzufuegen.fxml"));
      fxmlLoader.setController(this);

      try
      {
         getDialogPane().setContent((AnchorPane) fxmlLoader.load());
      }
      catch (IOException e)
      {
         // Ignoriert, da die FXML Datei immer da sein sollte :-P
         e.printStackTrace();
      }

      kommentarTextArea.setText(initialValue);

      // Setze die Button Typen für den Dialog
      getDialogPane().getButtonTypes().addAll(ButtonType.OK,
            ButtonType.CANCEL);

      // Setze Focus auf TextArea
      Platform.runLater(() -> kommentarTextArea.requestFocus());

      // Wenn OK gedrückt wurde, gib ein den Kommentar zurück
      setResultConverter(dialogButton -> {
         if (dialogButton == ButtonType.OK)
         {
            return kommentarTextArea.getText();
         }

         return null;
      });
   }
}