Example usage for javafx.collections FXCollections observableArrayList

List of usage examples for javafx.collections FXCollections observableArrayList

Introduction

In this page you can find the example usage for javafx.collections FXCollections observableArrayList.

Prototype

@SuppressWarnings("unchecked")
public static <E> ObservableList<E> observableArrayList() 

Source Link

Document

Creates a new empty observable list that is backed by an arraylist.

Usage

From source file:caillou.company.clonemanager.gui.customComponent.settings.SettingsController.java

@Override
public void initialize(URL location, ResourceBundle resources) {
    languageComboBoxId.setCellFactory(new Callback<ListView<Language>, ListCell<Language>>() {
        @Override/* w  ww  . jav a  2 s  . c  o m*/
        public ListCell<Language> call(ListView<Language> language) {
            return new LanguageListCell();
        }
    });

    languageComboBoxId.setButtonCell(new LanguageListCell());

    Language frenchLanguage = new Language(Locale.FRENCH);
    Language englishLanguage = new Language(Locale.ENGLISH);
    ObservableList<Language> languages = FXCollections.observableArrayList();
    languages.add(englishLanguage);
    languages.add(frenchLanguage);
    languageComboBoxId.setItems(languages);

    Locale currentLocale = SpringFxmlLoader.getLocale();
    if (currentLocale.equals(Locale.FRENCH)) {
        languageComboBoxId.setValue(frenchLanguage);
    } else {
        languageComboBoxId.setValue(englishLanguage);
    }

    languageComboBoxId.valueProperty().addListener(new ChangeListener<Language>() {

        @Override
        public void changed(ObservableValue<? extends Language> observable, Language oldValue,
                Language newValue) {
            SpringFxmlLoader.changeLocale(newValue.getLocale());
        }
    });
}

From source file:gmailclientfx.controllers.SpamController.java

public void fetchSpam() {
    ObservableList<MyMessage> data = FXCollections.observableArrayList();
    stupacId.setCellValueFactory(new PropertyValueFactory<MyMessage, Integer>("TblId"));
    stupacNaslov.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Subject"));
    stupacFrom.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Sender"));
    stupacDatum.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("DateReceived"));

    spamTable.setItems(data);/* ww  w.j a  v a  2 s.c  om*/
    spamTable.setOnMousePressed(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            if (event.isPrimaryButtonDown() && event.getClickCount() == 2) {
                MyMessage selectedMsg = spamTable.getSelectionModel().getSelectedItem();
                PregledEmailaHelper.setMsg(selectedMsg);
                try {
                    Parent root;
                    FXMLLoader loader = new FXMLLoader();
                    loader.setLocation(
                            getClass().getClassLoader().getResource("gmailclientfx/views/pregledEmaila.fxml"));
                    root = loader.load();
                    Stage stage = new Stage();
                    stage.setScene(new Scene(root));
                    PregledEmailaController pgec = loader.getController();
                    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
                        @Override
                        public void handle(WindowEvent event) {
                            pgec.bodyWebViewEngine.load(null);
                            System.out.println("Closing form!");
                        }

                    });
                    stage.setTitle(PregledEmailaHelper.getMsg().getSubject() + " - "
                            + PregledEmailaHelper.getMsg().getSender());
                    stage.show();
                } catch (IOException ex) {
                    Logger.getLogger(InboxController.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    });
    try {
        IMAPStore store = OAuth2Authenticator.connectToImap("imap.gmail.com", 993, GmailClient.getEmail(),
                GmailClient.getAccesToken(), true);
        Folder spam = null;
        Folder[] folders = store.getDefaultFolder().list("*");
        for (Folder f : folders) {
            IMAPFolder imapFolder = (IMAPFolder) f;
            for (String att : imapFolder.getAttributes()) {
                if ("\\Junk".equals(att)) {
                    spam = f;
                }
            }
        }
        spam.open(Folder.READ_WRITE);

        MimeMessage[] seenMessages = (MimeMessage[]) spam
                .search(new FlagTerm(new Flags(Flags.Flag.SEEN), true));
        for (int i = 0; i < seenMessages.length; i++) {
            MyMessage msg = GmailClient.fetchMessage(seenMessages[i], i + 1, "SPAM");
            data.add(msg);
        }
        MimeMessage[] unseenMessages = (MimeMessage[]) spam
                .search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
        for (int i = 0; i < unseenMessages.length; i++) {
            MyMessage msg = GmailClient.fetchMessage(unseenMessages[i], i + 1, "SPAM");
            data.add(msg);
        }
        spam.close(false);
        store.close();
    } catch (Exception ex) {
        Logger.getLogger(SpamController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:account.management.controller.CreateAccountController.java

@Override
public void initialize(URL url, ResourceBundle rb) {

    try {//from   ww  w. j  av  a  2 s  .  c o  m
        String res = Unirest.get(MetaData.baseUrl + "get/nextAccountId").asString().getBody();
        this.id.setText("LN" + String.format("%03d", Integer.parseInt(res)));
    } catch (UnirestException ex) {
        Logger.getLogger(CreateAccountController.class.getName()).log(Level.SEVERE, null, ex);
    }

    location = FXCollections.observableArrayList();

    new AutoCompleteComboBoxListener<>(select_location);
    select_location.setOnHiding((e) -> {
        Location a = select_location.getSelectionModel().getSelectedItem();
        select_location.setEditable(false);
        select_location.getSelectionModel().select(a);
    });
    select_location.setOnShowing((e) -> {
        select_location.setEditable(true);
    });

    // account type
    new Thread(() -> {
        this.select_account_type.getItems().add(new AccountType("0", "None"));
        try {
            HttpResponse<JsonNode> response = Unirest.get(MetaData.baseUrl + "get/account_type").asJson();
            JSONArray account_type = response.getBody().getArray();
            for (int i = 0; i < account_type.length(); i++) {
                JSONObject obj = account_type.getJSONObject(i);
                select_account_type.getItems()
                        .add(new AccountType(obj.get("id").toString(), obj.getString("name")));
            }
        } catch (UnirestException ex) {

        } finally {
            Platform.runLater(() -> {
                new AutoCompleteComboBoxListener<>(this.select_account_type);
                this.select_account_type.setOnHiding((e) -> {
                    AccountType a = this.select_account_type.getSelectionModel().getSelectedItem();
                    this.select_account_type.setEditable(false);
                    this.select_account_type.getSelectionModel().select(a);
                });
                this.select_account_type.setOnShowing((e) -> {
                    this.select_account_type.setEditable(true);
                });
                this.select_account_type.getSelectionModel().select(0);
            });
        }
    }).start();

    /*
    *   add location to combo box
    */
    new Thread(() -> {
        try {
            HttpResponse<JsonNode> response = Unirest.get(MetaData.baseUrl + "get/locations").asJson();
            JSONArray locationArray = response.getBody().getArray();
            for (int i = 0; i < locationArray.length(); i++) {
                JSONObject obj = locationArray.getJSONObject(i);
                int id = Integer.parseInt(obj.get("id").toString());
                String name = obj.get("name").toString();
                String details = obj.get("details").toString();
                location.add(new Location(id, name, details));
            }
            select_location.getItems().addAll(location);
        } catch (UnirestException ex) {

        } finally {
            Platform.runLater(() -> {
                this.select_location.getSelectionModel().select(0);
            });
        }
    }).start();

    new Thread(() -> {
        try {
            account = FXCollections.observableArrayList();
            /*
            *   add dr/cr options in select_dr_cr combobox
            */
            select_dr_cr.setItems(FXCollections.observableArrayList("Dr", "Cr"));
            HttpResponse<JsonNode> response = Unirest.get(MetaData.baseUrl + "get/accounts").asJson();

            JSONArray array = response.getBody().getArray();
            for (int i = 6; i < array.length(); i++) {

                JSONObject obj = array.getJSONObject(i);
                int id = Integer.parseInt(obj.get("id").toString());
                String name = obj.get("name").toString();
                int parent = Integer.parseInt(obj.get("parent").toString());
                String desc = obj.get("description").toString();

                account.add(new Account(id, name, parent, desc, 0f));
            }

            select_parent.getItems().addAll(account);
        } catch (UnirestException ex) {
            Logger.getLogger(CreateAccountController.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            Platform.runLater(() -> {
                new AutoCompleteComboBoxListener<>(this.select_parent);
                this.select_parent.setOnHiding((e) -> {
                    Account a = this.select_parent.getSelectionModel().getSelectedItem();
                    this.select_parent.setEditable(false);
                    this.select_parent.getSelectionModel().select(a);
                });
                this.select_parent.setOnShowing((e) -> {
                    this.select_parent.setEditable(true);
                });
            });
        }
    }).start();

    this.input_opening_balance.setText("0");
    this.select_dr_cr.getSelectionModel().select("Dr");

}

From source file:gmailclientfx.controllers.PoslaneController.java

public void fetchPoslane() {
    ObservableList<MyMessage> data = FXCollections.observableArrayList();
    stupacId.setCellValueFactory(new PropertyValueFactory<MyMessage, Integer>("TblId"));
    stupacNaslov.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Subject"));
    stupacTo.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Sender"));
    stupacDatum.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("DateReceived"));

    poslaneTable.setItems(data);/* w ww .ja  va  2 s .  c o m*/
    poslaneTable.setOnMousePressed(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            if (event.isPrimaryButtonDown() && event.getClickCount() == 2) {
                MyMessage selectedMsg = poslaneTable.getSelectionModel().getSelectedItem();
                PregledEmailaHelper.setMsg(selectedMsg);
                try {
                    Parent root;
                    FXMLLoader loader = new FXMLLoader();
                    loader.setLocation(
                            getClass().getClassLoader().getResource("gmailclientfx/views/pregledEmaila.fxml"));
                    root = loader.load();
                    Stage stage = new Stage();
                    stage.setScene(new Scene(root));
                    stage.setTitle(PregledEmailaHelper.getMsg().getSubject() + " - "
                            + PregledEmailaHelper.getMsg().getSender());
                    stage.show();
                    PregledEmailaController pgec = loader.getController();
                    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
                        @Override
                        public void handle(WindowEvent event) {
                            pgec.bodyWebViewEngine.load(null);
                            System.out.println("Closing form!");
                        }

                    });
                } catch (IOException ex) {
                    Logger.getLogger(InboxController.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    });
    try {
        IMAPStore store = OAuth2Authenticator.connectToImap("imap.gmail.com", 993, GmailClient.getEmail(),
                GmailClient.getAccesToken(), true);

        Folder poslane = null;
        Folder[] folders = store.getDefaultFolder().list("*");
        for (Folder f : folders) {
            IMAPFolder imapFolder = (IMAPFolder) f;
            for (String att : imapFolder.getAttributes()) {
                if ("\\Sent".equals(att)) {
                    poslane = f;
                }
            }
        }
        poslane.open(Folder.READ_WRITE);

        MimeMessage[] seenMessages = (MimeMessage[]) poslane
                .search(new FlagTerm(new Flags(Flags.Flag.SEEN), true));
        for (int i = 0; i < seenMessages.length; i++) {
            MyMessage msg = GmailClient.fetchMessage(seenMessages[i], i + 1, "SENT");
            data.add(msg);
        }

        MimeMessage[] unseenMessages = (MimeMessage[]) poslane
                .search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
        for (int i = 0; i < unseenMessages.length; i++) {
            MyMessage msg = GmailClient.fetchMessage(unseenMessages[i], i + 1, "SENT");
            data.add(msg);
        }
        poslane.close(false);
        store.close();
    } catch (Exception ex) {
        Logger.getLogger(PoslaneController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:account.management.controller.EditAccountController.java

/**
 * Initializes the controller class.// w w  w .j av a2 s . c  o  m
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    new AutoCompleteComboBoxListener<>(parent);
    parent.setOnHiding((e) -> {
        Account a = parent.getSelectionModel().getSelectedItem();
        parent.setEditable(false);
        parent.getSelectionModel().select(a);
    });
    parent.setOnShowing((e) -> {
        parent.setEditable(true);
    });

    new AutoCompleteComboBoxListener<>(account_type);
    account_type.setOnHiding((e) -> {
        AccountType a = account_type.getSelectionModel().getSelectedItem();
        account_type.setEditable(false);
        account_type.getSelectionModel().select(a);
    });
    account_type.setOnShowing((e) -> {
        account_type.setEditable(true);
    });

    accountList = FXCollections.observableArrayList();
    accounTypetList = FXCollections.observableArrayList();
    new Thread(() -> {

        try {
            HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/accounts").asJson();
            JSONArray array = res.getBody().getArray();
            for (int i = 0; i < array.length(); i++) {
                JSONObject obj = array.getJSONObject(i);

                String id = obj.get("id").toString();
                String name = obj.getString("name");
                String parent = obj.get("parent").toString();
                String desc = obj.getString("description");
                String account_type = obj.get("account_type").toString();
                accountList.add(new Account(id, name, parent, desc, account_type));
            }
        } catch (UnirestException ex) {

        } finally {
            this.account.getItems().addAll(accountList);
            this.parent.getItems().addAll(accountList);
            Platform.runLater(() -> {
                new AutoCompleteComboBoxListener<>(this.account);
                this.account.setOnHiding((e) -> {
                    Account a = this.account.getSelectionModel().getSelectedItem();
                    this.account.setEditable(false);
                    this.account.getSelectionModel().select(a);
                });
                this.account.setOnShowing((e) -> {
                    this.account.setEditable(true);
                });
            });

        }

    }).start();

    new Thread(() -> {
        try {
            HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/account/type").asJson();
            JSONArray array = res.getBody().getArray();
            accounTypetList.add(new AccountType("0", "None"));
            for (int i = 0; i < array.length(); i++) {
                JSONObject obj = array.getJSONObject(i);
                String id = obj.getString("id");
                String name = obj.getString("name");
                accounTypetList.add(new AccountType(id, name));
            }

        } catch (UnirestException ex) {
            Logger.getLogger(EditAccountController.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            this.account_type.getItems().addAll(accounTypetList);
        }
    }).start();

}

From source file:gmailclientfx.controllers.ObrisaneController.java

public void fetchObrisane() {
    ObservableList<MyMessage> data = FXCollections.observableArrayList();
    stupacId.setCellValueFactory(new PropertyValueFactory<MyMessage, Integer>("TblId"));
    stupacNaslov.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Subject"));
    stupacFrom.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Sender"));
    stupacDatum.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("DateReceived"));

    obrisaneTable.setItems(data);/* ww w.j av a2s.  c o m*/
    obrisaneTable.setOnMousePressed(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            if (event.isPrimaryButtonDown() && event.getClickCount() == 2) {
                MyMessage selectedMsg = obrisaneTable.getSelectionModel().getSelectedItem();
                PregledEmailaHelper.setMsg(selectedMsg);
                try {
                    Parent root;
                    FXMLLoader loader = new FXMLLoader();
                    loader.setLocation(
                            getClass().getClassLoader().getResource("gmailclientfx/views/pregledEmaila.fxml"));
                    root = loader.load();
                    Stage stage = new Stage();
                    stage.setScene(new Scene(root));
                    stage.show();
                    PregledEmailaController pgec = loader.getController();
                    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
                        @Override
                        public void handle(WindowEvent event) {
                            pgec.bodyWebViewEngine.load(null);
                            System.out.println("Closing form!");
                        }

                    });
                    stage.setTitle(PregledEmailaHelper.getMsg().getSubject() + " - "
                            + PregledEmailaHelper.getMsg().getSender());
                } catch (IOException ex) {
                    Logger.getLogger(InboxController.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    });
    try {
        IMAPStore store = OAuth2Authenticator.connectToImap("imap.gmail.com", 993, GmailClient.getEmail(),
                GmailClient.getAccesToken(), true);

        Folder obrisane = null;
        Folder[] folders = store.getDefaultFolder().list("*");
        for (Folder f : folders) {
            IMAPFolder imapFolder = (IMAPFolder) f;
            for (String att : imapFolder.getAttributes()) {
                if ("\\Trash".equals(att)) {
                    obrisane = f;
                }
            }
        }
        obrisane.open(Folder.READ_WRITE);

        MimeMessage[] seenMessages = (MimeMessage[]) obrisane
                .search(new FlagTerm(new Flags(Flags.Flag.SEEN), true));
        for (int i = 0; i < seenMessages.length; i++) {
            MyMessage msg = GmailClient.fetchMessage(seenMessages[i], i + 1, "DELETED");
            data.add(msg);
        }

        MimeMessage[] unseenMessages = (MimeMessage[]) obrisane
                .search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
        for (int i = 0; i < unseenMessages.length; i++) {
            MyMessage msg = GmailClient.fetchMessage(unseenMessages[i], i + 1, "DELETED");
            data.add(msg);
        }
        obrisane.close(false);
        store.close();
    } catch (Exception ex) {
        Logger.getLogger(ObrisaneController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Person.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("");
    Group root = new Group();
    Scene scene = new Scene(root, 500, 250, Color.WHITE);
    // create a grid pane
    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(10);/*from   w  w w  .ja v  a2 s .  com*/
    gridpane.setVgap(10);

    ObservableList<Person> leaders = FXCollections.observableArrayList();
    leaders.add(new Person("A", "B", "C"));
    leaders.add(new Person("D", "E", "F"));
    final ListView<Person> leaderListView = new ListView<Person>(leaders);
    leaderListView.setPrefWidth(150);
    leaderListView.setPrefHeight(150);

    // 
    leaderListView.setCellFactory(new Callback<ListView<Person>, ListCell<Person>>() {

        public ListCell<Person> call(ListView<Person> param) {
            final Label leadLbl = new Label();
            final Tooltip tooltip = new Tooltip();
            final ListCell<Person> cell = new ListCell<Person>() {
                @Override
                public void updateItem(Person item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null) {
                        leadLbl.setText(item.getAliasName());
                        setText(item.getFirstName() + " " + item.getLastName());
                        tooltip.setText(item.getAliasName());
                        setTooltip(tooltip);
                    }
                }
            }; // ListCell
            return cell;
        }
    }); // setCellFactory

    gridpane.add(leaderListView, 0, 1);

    leaderListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Person>() {
        public void changed(ObservableValue<? extends Person> observable, Person oldValue, Person newValue) {
            System.out.println("selection changed");
        }
    });

    root.getChildren().add(gridpane);

    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:ninja.eivind.hotsreplayuploader.services.UploaderService.java

public UploaderService() throws IOException {
    logger.info("Instantiating " + getClass().getSimpleName());
    uploadQueue = new LinkedBlockingQueue<>();
    files = FXCollections.observableArrayList();
    setExecutor(Executors.newCachedThreadPool());
    logger.info("Instantiated " + getClass().getSimpleName());
}

From source file:gndata.app.ui.metadata.manage.AddRDFInstanceCtrl.java

public AddRDFInstanceCtrl(ProjectState projState, MetadataNavState navigationState, Resource extRes) {

    projectState = projState;//from w w  w .j  a  v a 2  s  . co m
    navState = navigationState;
    oh = projectState.getMetadata().ontmanager;

    preSelNewClass = extRes;

    currInsets = new SimpleObjectProperty<>(new Insets(5));
    labelText = new SimpleStringProperty();

    newClassesList = FXCollections.observableArrayList();
    newClasses = new SimpleObjectProperty<>();
    selectedNewClass = new SimpleObjectProperty<>();

    newPredicatesList = FXCollections.observableArrayList();
    newPredicates = new SimpleObjectProperty<>();

    additionalPredicatesList = FXCollections.observableArrayList();
    additionalPredicates = new SimpleObjectProperty<>();
    selectedPredicate = new SimpleObjectProperty<>();
    addPredValue = new SimpleStringProperty();
    addPredType = new SimpleObjectProperty<>();
    addPredPromptText = new SimpleStringProperty();

    // Update the contents of the DataProperty table, if a new class has been selected
    selectedNewClass.addListener((observable, oldValue, newValue) -> {

        if (selectedNewClass.get().getValue() != null) {

            newPredicatesList.clear();

            oh.listDatatypeProperties(selectedNewClass.get().getValue()).stream().forEach(c -> {
                //TODO take care of the case of multiple datatypes
                Set<RDFDatatype> dts = oh.getRange(c.asDatatypeProperty());
                RDFDatatype dt = dts.iterator().next();
                newPredicatesList.add(new DataPropertyTableItem(c.asProperty(), dt));
            });
        }
    });

    // Listen on the selected new predicate and set the corresponding RDF DataType accordingly
    selectedPredicate.addListener((observable, oldValue, newValue) -> {
        addPredPromptText.set("");
        if (observable != null && newValue != null) {
            //TODO take care of the case of multiple datatypes
            Set<RDFDatatype> dts = oh.getRange(observable.getValue());
            RDFDatatype dt = dts.iterator().next();

            addPredType.set(dt);
            addPredPromptText
                    .set("Enter " + (dt == null ? "String" : dt.getJavaClass().getSimpleName()) + " value");
        }
    });

    // Handle list of additional DataType properties
    newPredicatesList.addListener((ListChangeListener<DataPropertyTableItem>) change -> {
        // Reset list of additional DataType properties
        additionalPredicatesList.clear();

        // Get all available datatype properties for selected class
        oh.listDatatypeProperties(selectedNewClass.get().getValue()).stream()
                .forEach(c -> additionalPredicatesList.add(c.asDatatypeProperty()));

        // TODO implement check for DataType Properties which can be added
        // TODO multiple times
        // Remove all datatype properties which already exist in the table
        newPredicatesList.stream().forEach(c -> {
            if (additionalPredicatesList.contains(c.getProperty())) {
                additionalPredicatesList.remove(c.getProperty());
            }
        });
    });
}

From source file:gmailclientfx.controllers.NedovrseneController.java

public void fetchNedovrsene() {
    ObservableList<MyMessage> data = FXCollections.observableArrayList();
    stupacId.setCellValueFactory(new PropertyValueFactory<MyMessage, Integer>("TblId"));
    stupacNaslov.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Subject"));
    stupacTo.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Sender"));
    stupacDatum.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("DateReceived"));

    nedovrseneTable.setItems(data);/*from   w  w w  . j  a va 2 s . c o m*/
    nedovrseneTable.setOnMousePressed(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            if (event.isPrimaryButtonDown() && event.getClickCount() == 2) {
                MyMessage selectedMsg = nedovrseneTable.getSelectionModel().getSelectedItem();
                PregledEmailaHelper.setMsg(selectedMsg);
                try {
                    Parent root;
                    FXMLLoader loader = new FXMLLoader();
                    loader.setLocation(
                            getClass().getClassLoader().getResource("gmailclientfx/views/pregledEmaila.fxml"));
                    root = loader.load();
                    Stage stage = new Stage();
                    stage.setScene(new Scene(root));
                    stage.setTitle(PregledEmailaHelper.getMsg().getSubject() + " - "
                            + PregledEmailaHelper.getMsg().getSender());
                    stage.show();
                    PregledEmailaController pgec = loader.getController();
                    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
                        @Override
                        public void handle(WindowEvent event) {
                            pgec.bodyWebViewEngine.load(null);
                            System.out.println("Closing form!");
                        }

                    });
                } catch (IOException ex) {
                    Logger.getLogger(InboxController.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    });

    try {
        IMAPStore store = OAuth2Authenticator.connectToImap("imap.gmail.com", 993, GmailClient.getEmail(),
                GmailClient.getAccesToken(), true);

        Folder nedovrsene = null;
        Folder[] folders = store.getDefaultFolder().list("*");
        for (Folder f : folders) {
            IMAPFolder imapFolder = (IMAPFolder) f;
            for (String att : imapFolder.getAttributes()) {
                if ("\\Drafts".equals(att)) {
                    nedovrsene = f;
                }
            }
        }
        nedovrsene.open(Folder.READ_WRITE);

        MimeMessage[] seenMessages = (MimeMessage[]) nedovrsene
                .search(new FlagTerm(new Flags(Flags.Flag.SEEN), true));
        for (int i = 0; i < seenMessages.length; i++) {
            MyMessage msg = GmailClient.fetchMessage(seenMessages[i], i + 1, "DRAFT");
            data.add(msg);
        }

        MimeMessage[] unseenMessages = (MimeMessage[]) nedovrsene
                .search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
        for (int i = 0; i < unseenMessages.length; i++) {
            MyMessage msg = GmailClient.fetchMessage(unseenMessages[i], i + 1, "DRAFT");
            data.add(msg);
        }
        nedovrsene.close(false);
        store.close();
    } catch (Exception ex) {
        Logger.getLogger(NedovrseneController.class.getName()).log(Level.SEVERE, null, ex);
    }
}