menuItems = menuItemService.getMenuItemsByParent(0l);
150 | for (com.skynet.javafx.model.MenuItem item : menuItems) {
151 | Button button = new Button();
152 | button.setTooltip(new Tooltip(item.getValue()));
153 | if (!item.getImage().isEmpty()) {
154 | button.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/images/" + item.getImage()))));
155 | }
156 | button.setOnAction((event) -> { onToolBarButtonAction(item); });
157 | toolbar.getItems().add(button);
158 | }
159 | return toolbar;
160 | }
161 |
162 | private void onToolBarButtonAction(com.skynet.javafx.model.MenuItem item) {
163 | int tabIndex = findTabIndex(item.getValue());
164 | if (tabIndex == -1) {
165 | tabPane.getTabs().contains((Object) item.getValue());
166 | showItemContent(item);
167 | } else {
168 | tabPane.getSelectionModel().select(tabIndex);
169 | }
170 | }
171 |
172 | private int findTabIndex(String title) {
173 | for (int i = 0; i < tabPane.getTabs().size(); i++) {
174 | Tab tab = tabPane.getTabs().get(i);
175 | if (tab.getText().equals(title + ADDITIONAL_TAB_TITLE)) {
176 | return i;
177 | }
178 | }
179 | return -1;
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/src/main/java/com/skynet/javafx/jfxsupport/AbstractFxmlView.java:
--------------------------------------------------------------------------------
1 | package com.skynet.javafx.jfxsupport;
2 |
3 | import static java.util.ResourceBundle.getBundle;
4 |
5 | import java.io.IOException;
6 | import java.net.URL;
7 | import java.util.List;
8 | import java.util.MissingResourceException;
9 | import java.util.ResourceBundle;
10 | import java.util.concurrent.CompletableFuture;
11 | import java.util.function.Consumer;
12 |
13 | import org.slf4j.Logger;
14 | import org.slf4j.LoggerFactory;
15 | import org.springframework.beans.BeansException;
16 | import org.springframework.context.ApplicationContext;
17 | import org.springframework.context.ApplicationContextAware;
18 | import org.springframework.util.StringUtils;
19 |
20 | import javafx.application.Platform;
21 | import javafx.beans.property.ObjectProperty;
22 | import javafx.beans.property.SimpleObjectProperty;
23 | import javafx.beans.value.ObservableValue;
24 | import javafx.collections.ObservableList;
25 | import javafx.fxml.FXMLLoader;
26 | import javafx.scene.Node;
27 | import javafx.scene.Parent;
28 | import javafx.scene.layout.AnchorPane;
29 | import javafx.util.Callback;
30 |
31 | /**
32 | * Base class for fxml-based view classes.
33 | *
34 | * It is derived from Adam Bien's
35 | * afterburner.fx project.
36 | *
37 | * {@link AbstractFxmlView} is a stripped down version of FXMLView that provides DI for Java FX Controllers via Spring.
40 | *
41 | *
42 | * Supports annotation driven creation of FXML based view beans with {@link FXMLView}
43 | *
44 | *
45 | * @author Thomas Darimont
46 | * @author Felix Roske
47 | * @author Andreas Jay
48 | *
49 | */
50 | public abstract class AbstractFxmlView implements ApplicationContextAware {
51 |
52 | private static final Logger LOGGER = LoggerFactory.getLogger(AbstractFxmlView.class);
53 |
54 | private final ObjectProperty