corefx - added connect dialog to allow connections after initial attempt
This commit is contained in:
parent
24157e7be5
commit
1b728770f1
8 changed files with 110 additions and 40 deletions
|
@ -52,8 +52,8 @@ public class Controller implements Initializable {
|
|||
private Stage window;
|
||||
|
||||
// core client utilities
|
||||
private CoreWebSocket coreWebSocket;
|
||||
private ICoreClient coreClient;
|
||||
private CoreWebSocket coreWebSocket;
|
||||
|
||||
// ui elements
|
||||
private NetworkGraph networkGraph = new NetworkGraph(this);
|
||||
|
@ -77,28 +77,22 @@ public class Controller implements Initializable {
|
|||
private BackgroundDialog backgroundDialog = new BackgroundDialog(this);
|
||||
private LocationDialog locationDialog = new LocationDialog(this);
|
||||
private GeoDialog geoDialog = new GeoDialog(this);
|
||||
private ConnectDialog connectDialog = new ConnectDialog(this);
|
||||
|
||||
public Controller() {
|
||||
// load configuration
|
||||
Properties properties = ConfigUtils.load();
|
||||
String coreUrl = properties.getProperty("core-rest");
|
||||
logger.info("core rest: {}", coreUrl);
|
||||
}
|
||||
|
||||
// start web socket thread
|
||||
try {
|
||||
coreWebSocket = new CoreWebSocket(this, coreUrl);
|
||||
coreWebSocket.start();
|
||||
} catch (URISyntaxException ex) {
|
||||
logger.error("error starting web socket", ex);
|
||||
}
|
||||
public void connectToCore(String coreUrl) {
|
||||
coreWebSocket.stop();
|
||||
|
||||
coreClient = new CoreRestClient(this, coreUrl);
|
||||
ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
executorService.submit(() -> {
|
||||
try {
|
||||
coreClient.initialJoin();
|
||||
} catch (IOException ex) {
|
||||
Toast.error(String.format("Initial join failure: %s", ex.getMessage()), ex);
|
||||
coreWebSocket.start(coreUrl);
|
||||
coreClient.initialJoin(coreUrl);
|
||||
} catch (IOException | URISyntaxException ex) {
|
||||
Toast.error(String.format("Connection failure: %s", ex.getMessage()), ex);
|
||||
Platform.runLater(() -> connectDialog.showDialog());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -144,6 +138,13 @@ public class Controller implements Initializable {
|
|||
nodeTypesDialog.setOwner(window);
|
||||
backgroundDialog.setOwner(window);
|
||||
locationDialog.setOwner(window);
|
||||
connectDialog.setOwner(window);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onCoreMenuConnect(ActionEvent event) {
|
||||
logger.info("showing connect!");
|
||||
connectDialog.showDialog();
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
@ -261,6 +262,14 @@ public class Controller implements Initializable {
|
|||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
coreClient = new CoreRestClient(this);
|
||||
coreWebSocket = new CoreWebSocket(this);
|
||||
Properties properties = ConfigUtils.load();
|
||||
String coreUrl = properties.getProperty("core-rest");
|
||||
logger.info("core rest: {}", coreUrl);
|
||||
connectDialog.setCoreUrl(coreUrl);
|
||||
connectToCore(coreUrl);
|
||||
|
||||
logger.info("controller initialize");
|
||||
swingNode.setContent(networkGraph.getGraphViewer());
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ public interface ICoreClient {
|
|||
|
||||
GetSession getSession(Integer sessionId) throws IOException;
|
||||
|
||||
void initialJoin() throws IOException;
|
||||
void initialJoin(String url) throws IOException;
|
||||
|
||||
boolean start() throws IOException;
|
||||
|
||||
|
|
|
@ -22,13 +22,12 @@ public class CoreRestClient implements ICoreClient {
|
|||
private static final Logger logger = LogManager.getLogger();
|
||||
private final Controller controller;
|
||||
private final NetworkGraph networkGraph;
|
||||
private final String baseUrl;
|
||||
private String baseUrl;
|
||||
private Integer sessionId;
|
||||
private SessionState sessionState;
|
||||
|
||||
public CoreRestClient(Controller controller, String baseUrl) {
|
||||
public CoreRestClient(Controller controller) {
|
||||
this.controller = controller;
|
||||
this.baseUrl = baseUrl;
|
||||
this.networkGraph = controller.getNetworkGraph();
|
||||
}
|
||||
|
||||
|
@ -91,7 +90,8 @@ public class CoreRestClient implements ICoreClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void initialJoin() throws IOException {
|
||||
public void initialJoin(String url) throws IOException {
|
||||
this.baseUrl = url;
|
||||
GetServices services = getServices();
|
||||
logger.info("core services: {}", services);
|
||||
controller.getNodeServicesDialog().setServices(services);
|
||||
|
|
|
@ -46,6 +46,7 @@ public final class Toast {
|
|||
}
|
||||
JFXSnackbar.SnackbarEvent snackbarEvent = new JFXSnackbar.SnackbarEvent(message,
|
||||
"toast-error", "X", TIMEOUT, true, event -> snackbar.close());
|
||||
snackbar.close();
|
||||
snackbar.enqueue(snackbarEvent);
|
||||
}
|
||||
}
|
||||
|
|
37
corefx/src/main/java/com/core/ui/dialogs/ConnectDialog.java
Normal file
37
corefx/src/main/java/com/core/ui/dialogs/ConnectDialog.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
package com.core.ui.dialogs;
|
||||
|
||||
import com.core.Controller;
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXTextField;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.StageStyle;
|
||||
import lombok.Data;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Data
|
||||
public class ConnectDialog extends StageDialog {
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
private String coreUrl;
|
||||
private JFXButton saveButton;
|
||||
@FXML JFXTextField urlTextField;
|
||||
|
||||
public ConnectDialog(Controller controller) {
|
||||
super(controller, "/fxml/connect_dialog.fxml");
|
||||
saveButton = createButton("Connect");
|
||||
saveButton.setOnAction(event -> {
|
||||
coreUrl = urlTextField.getText();
|
||||
controller.connectToCore(coreUrl);
|
||||
close();
|
||||
});
|
||||
addCancelButton();
|
||||
setTitle("CORE Connection");
|
||||
getStage().sizeToScene();
|
||||
}
|
||||
|
||||
public void showDialog() {
|
||||
urlTextField.setText(coreUrl);
|
||||
show();
|
||||
}
|
||||
}
|
|
@ -14,24 +14,33 @@ import java.net.URISyntaxException;
|
|||
public class CoreWebSocket {
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
private final Controller controller;
|
||||
private final String url;
|
||||
private final Socket socket;
|
||||
private Thread socketThread;
|
||||
private Socket socket;
|
||||
|
||||
public CoreWebSocket(Controller controller, String url) throws URISyntaxException {
|
||||
public CoreWebSocket(Controller controller) {
|
||||
this.controller = controller;
|
||||
this.url = url;
|
||||
socket = IO.socket(this.url);
|
||||
socket.on(Socket.EVENT_CONNECT, args -> {
|
||||
logger.info("connected to web socket");
|
||||
});
|
||||
}
|
||||
|
||||
public void start(String url) throws URISyntaxException {
|
||||
socket = IO.socket(url);
|
||||
socket.on(Socket.EVENT_CONNECT, args -> logger.info("connected to web socket"));
|
||||
socket.on("node", this::handleNodes);
|
||||
socket.on("event", this::handleEvents);
|
||||
socket.on("config", this::handleConfigs);
|
||||
socket.on("link", this::handleLinks);
|
||||
socket.on(Socket.EVENT_DISCONNECT, args -> {
|
||||
logger.info("disconnected from web socket");
|
||||
});
|
||||
socket.on(Socket.EVENT_DISCONNECT, args -> logger.info("disconnected from web socket"));
|
||||
|
||||
logger.info("attempting to connect to web socket!");
|
||||
socketThread = new Thread(socket::connect);
|
||||
socketThread.setDaemon(true);
|
||||
socketThread.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (socketThread != null) {
|
||||
socket.close();
|
||||
socketThread.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleNodes(Object... args) {
|
||||
|
@ -87,11 +96,4 @@ public class CoreWebSocket {
|
|||
logger.info("handling broadcast config: {}", arg);
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
logger.info("attempting to connect to web socket!");
|
||||
socketThread = new Thread(socket::connect);
|
||||
socketThread.setDaemon(true);
|
||||
socketThread.start();
|
||||
}
|
||||
}
|
||||
|
|
16
corefx/src/main/resources/fxml/connect_dialog.fxml
Normal file
16
corefx/src/main/resources/fxml/connect_dialog.fxml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import com.jfoenix.controls.JFXTextField?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<VBox prefWidth="800.0" spacing="10.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<padding>
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||
</padding>
|
||||
<children>
|
||||
<Label maxWidth="1.7976931348623157E308" text="URL" />
|
||||
<JFXTextField fx:id="urlTextField" />
|
||||
</children>
|
||||
</VBox>
|
|
@ -17,10 +17,15 @@
|
|||
<children>
|
||||
<MenuBar>
|
||||
<menus>
|
||||
<Menu mnemonicParsing="false" text="Main">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" onAction="#onCoreMenuConnect" text="Connection" />
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="File">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" onAction="#onOpenXmlAction" text="Open XML" />
|
||||
<MenuItem fx:id="saveXmlMenuItem" disable="true" mnemonicParsing="false" onAction="#onSaveXmlAction" text="Save XML" />
|
||||
<MenuItem mnemonicParsing="false" onAction="#onOpenXmlAction" text="Open XML" />
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="Session">
|
||||
|
|
Loading…
Reference in a new issue