From: Debayan Sutradhar Date: Mon, 22 Mar 2021 00:15:08 +0530 Subject: Implemented saveClientIcon, saveClientAction etc for External Plugins --- Implemented saveClientIcon, saveClientAction etc for External Plugins --- --- 'a/src/main/java/com/stream_pi/server/connection/ClientConnection.java' +++ b/src/main/java/com/stream_pi/server/connection/ClientConnection.java @@ -29,6 +29,7 @@ import javafx.concurrent.Task; import java.io.*; import java.net.Socket; +import java.net.SocketAddress; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; @@ -82,7 +83,7 @@ public class ClientConnection extends Th { if(socket !=null) { - logger.info("Stopping connection "+socket.getRemoteSocketAddress()); + logger.info("Stopping connection "+getRemoteSocketAddress()); disconnect(); } } @@ -93,6 +94,11 @@ public class ClientConnection extends Th } } + public SocketAddress getRemoteSocketAddress() + { + return socket.getRemoteSocketAddress(); + } + public synchronized void exitAndRemove() { exit(); @@ -793,7 +799,7 @@ public class ClientConnection extends Th if(action.getActionType() == ActionType.NORMAL || action.getActionType() == ActionType.TOGGLE) { - if(!action.isInvalid()) + if(action.isInvalid()) { throw new MinorException( "The action isn't installed on the server." @@ -801,7 +807,6 @@ public class ClientConnection extends Th } else { - if(action instanceof ToggleAction) { new Thread(new Task() { --- 'a/src/main/java/com/stream_pi/server/controller/Controller.java' +++ b/src/main/java/com/stream_pi/server/controller/Controller.java @@ -561,7 +561,7 @@ public class Controller extends Base imp @Override public void clearTemp() { Platform.runLater(() -> { - getDashboardPane().getClientDetailsPane().refresh(); + getDashboardPane().getClientAndProfileSelectorPane().refresh(); getDashboardPane().getActionGridPane().clear(); getDashboardPane().getActionGridPane().setFreshRender(true); getDashboardPane().getActionDetailsPane().clear(); @@ -594,7 +594,30 @@ public class Controller extends Base imp ClientProfile clientProfile = clientConnection.getClient().getProfileByID(profileID); - clientConnection.saveActionDetails(profileID, clientProfile.getActionByID(actionID)); + Action action = clientProfile.getActionByID(actionID); + clientConnection.saveActionDetails(profileID, action); + + Platform.runLater(()->{ + try { + if(getDashboardPane().getActionGridPane().getCurrentParent().equals(action.getParent()) && + getDashboardPane().getClientAndProfileSelectorPane().getCurrentSelectedClientProfile().getID().equals(profileID) && + getDashboardPane().getClientAndProfileSelectorPane().getCurrentSelectedClientConnection().getRemoteSocketAddress().equals(socketAddress)) + { + getDashboardPane().getActionGridPane().renderAction(action); + } + + if(getDashboardPane().getActionDetailsPane().getAction().getID().equals(actionID)) + { + getDashboardPane().getActionDetailsPane().setAction(action); + getDashboardPane().getActionDetailsPane().refresh(); + } + + } + catch (Exception e) + { + e.printStackTrace(); + } + }); } catch (SevereException e) { --- 'a/src/main/java/com/stream_pi/server/window/dashboard/ClientAndProfileSelectorPane.java' +++ b/src/main/java/com/stream_pi/server/window/dashboard/ClientAndProfileSelectorPane.java @@ -39,6 +39,20 @@ public class ClientAndProfileSelectorPan private ComboBox clientProfilesComboBox; + private ClientProfile currentSelectedClientProfile = null; + + public ClientProfile getCurrentSelectedClientProfile() + { + return currentSelectedClientProfile; + } + + private ClientConnection currentSelectedClientConnection = null; + + public ClientConnection getCurrentSelectedClientConnection() + { + return currentSelectedClientConnection; + } + public void initUI() { noClientsConnectedLabel = new Label("No Clients Connected"); @@ -52,6 +66,7 @@ public class ClientAndProfileSelectorPan clientsComboBox.valueProperty().addListener((observableValue, oldVal, newVal) -> { if(oldVal!=newVal && newVal!=null) { + currentSelectedClientConnection = newVal; dashboard.newSelectedClientConnection(newVal); clientProfilesComboBox.setItems(FXCollections.observableArrayList(newVal.getClient().getAllClientProfiles())); clientProfilesComboBox.setVisible(true); @@ -94,6 +109,7 @@ public class ClientAndProfileSelectorPan clientProfilesComboBox.valueProperty().addListener((observableValue, oldVal, newVal) -> { if(oldVal!=newVal && newVal!=null) { + currentSelectedClientProfile = newVal; dashboard.newSelectedClientProfile(newVal); } }); --- 'a/src/main/java/com/stream_pi/server/window/dashboard/DashboardBase.java' +++ b/src/main/java/com/stream_pi/server/window/dashboard/DashboardBase.java @@ -69,7 +69,8 @@ public class DashboardBase extends Split this.clientAndProfileSelectorPane = clientAndProfileSelectorPane; leftSplitPane.getItems().add(this.clientAndProfileSelectorPane); } - public ClientAndProfileSelectorPane getClientDetailsPane() + + public ClientAndProfileSelectorPane getClientAndProfileSelectorPane() { return clientAndProfileSelectorPane; } --- 'a/src/main/java/com/stream_pi/server/window/dashboard/actiondetailpane/ActionDetailsPane.java' +++ b/src/main/java/com/stream_pi/server/window/dashboard/actiondetailpane/ActionDetailsPane.java @@ -189,7 +189,7 @@ public class ActionDetailsPane extends V hideDefaultIconCheckBox.setSelected(false); clearIconButton.setDisable(false); - action.setDefaultIcon(iconFileByteArray); + action.addIcon("default", iconFileByteArray); setSendIcon(true); } } catch (Exception e) { @@ -208,7 +208,7 @@ public class ActionDetailsPane extends V hideToggleOffIconCheckBox.setSelected(false); clearIconButton.setDisable(false); - action.setToggleOffIcon(iconFileByteArray); + action.addIcon("toggle_off", iconFileByteArray); setSendIcon(true); } } catch (Exception e) { @@ -228,7 +228,7 @@ public class ActionDetailsPane extends V hideToggleOnIconCheckBox.setSelected(false); clearIconButton.setDisable(false); - action.setToggleOnIcon(iconFileByteArray); + action.addIcon("toggle_on", iconFileByteArray); setSendIcon(true); } } catch (Exception e) { @@ -428,16 +428,22 @@ public class ActionDetailsPane extends V } @Override - public void onActionClicked(Action action, ActionBox actionBox) throws MinorException { + public void onActionClicked(Action action, ActionBox actionBox) throws MinorException + { this.action = action; this.actionBox = actionBox; - logger.info("action Display text : "+action.getDisplayText()); clear(); renderActionProperties(); } + public void refresh() throws MinorException + { + clear(); + renderActionProperties(); + } + private TextField displayNameTextField; private CheckBox hideDisplayTextCheckBox; @@ -477,6 +483,9 @@ public class ActionDetailsPane extends V actionBackgroundColourPicker.setValue(Color.WHITE); displayTextColourPicker.setValue(Color.WHITE); + + action = null; + actionBox = null; } boolean isCombineChild = false; @@ -491,6 +500,8 @@ public class ActionDetailsPane extends V //Combine Child action isCombineChild = action.getLocation().getCol() == -1; + System.out.println("DISPLAY : "+action.getDisplayText()); + displayNameTextField.setText(action.getDisplayText()); if(isCombineChild) --- 'a/src/main/java/com/stream_pi/server/window/dashboard/actiongridpane/ActionGridPane.java' +++ b/src/main/java/com/stream_pi/server/window/dashboard/actiongridpane/ActionGridPane.java @@ -47,7 +47,7 @@ public class ActionGridPane extends Scro this.actionDetailsPaneListener = actionDetailsPaneListener; } - private String currentParent; + private String currentParent = null; @Override public void setCurrentParent(String currentParent) {