server

Clone or download

Modified Files

package com.stream_pi.server.window.dashboard;
package com.stream_pi.server.window.dashboard;
import java.util.logging.Logger;
import java.util.logging.Logger;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionGridPane;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionGridPane;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPane;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPane;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.geometry.Orientation;
import javafx.geometry.Orientation;
import javafx.scene.control.SplitPane;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
public class DashboardBase extends SplitPane implements DashboardInterface {
public class DashboardBase extends SplitPane implements DashboardInterface {
private final SplitPane leftSplitPane;
private final SplitPane leftSplitPane;
private Logger logger;
private Logger logger;
public ClientProfile currentClientProfile;
public ClientProfile currentClientProfile;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
public DashboardBase(ExceptionAndAlertHandler exceptionAndAlertHandler, HostServices hostServices)
public DashboardBase(ExceptionAndAlertHandler exceptionAndAlertHandler, HostServices hostServices)
{
{
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
logger = Logger.getLogger(DashboardBase.class.getName());
logger = Logger.getLogger(DashboardBase.class.getName());
leftSplitPane = new SplitPane();
leftSplitPane = new SplitPane();
leftSplitPane.getStyleClass().add("dashboard_left_split_pane");
leftSplitPane.getStyleClass().add("dashboard_left_split_pane");
leftSplitPane.setOrientation(Orientation.VERTICAL);
leftSplitPane.setOrientation(Orientation.VERTICAL);
getStyleClass().add("dashboard_right_split_pane");
getStyleClass().add("dashboard_right_split_pane");
getItems().add(leftSplitPane);
getItems().add(leftSplitPane);
setPluginsPane(new PluginsPane(hostServices));
setPluginsPane(new PluginsPane(hostServices));
setClientDetailsPane(new ClientAndProfileSelectorPane(this));
setClientDetailsPane(new ClientAndProfileSelectorPane(this));
setActionGridPane(new ActionGridPane(exceptionAndAlertHandler));
setActionGridPane(new ActionGridPane(exceptionAndAlertHandler));
setActionDetailsPane(new ActionDetailsPane(exceptionAndAlertHandler, hostServices, getActionGridPane()));
setActionDetailsPane(new ActionDetailsPane(exceptionAndAlertHandler, hostServices, getActionGridPane()));
getActionGridPane().setActionDetailsPaneListener(getActionDetailsPane());
getActionGridPane().setActionDetailsPaneListener(getActionDetailsPane());
}
}
private PluginsPane pluginsPane;
private PluginsPane pluginsPane;
private void setPluginsPane(PluginsPane pluginsPane)
private void setPluginsPane(PluginsPane pluginsPane)
{
{
this.pluginsPane = pluginsPane;
this.pluginsPane = pluginsPane;
getItems().add(this.pluginsPane);
getItems().add(this.pluginsPane);
}
}
public PluginsPane getPluginsPane()
public PluginsPane getPluginsPane()
{
{
return pluginsPane;
return pluginsPane;
}
}
private ClientAndProfileSelectorPane clientAndProfileSelectorPane;
private ClientAndProfileSelectorPane clientAndProfileSelectorPane;
private void setClientDetailsPane(ClientAndProfileSelectorPane clientAndProfileSelectorPane)
private void setClientDetailsPane(ClientAndProfileSelectorPane clientAndProfileSelectorPane)
{
{
this.clientAndProfileSelectorPane = clientAndProfileSelectorPane;
this.clientAndProfileSelectorPane = clientAndProfileSelectorPane;
leftSplitPane.getItems().add(this.clientAndProfileSelectorPane);
leftSplitPane.getItems().add(this.clientAndProfileSelectorPane);
}
}
public ClientAndProfileSelectorPane getClientAndProfileSelectorPane()
public ClientAndProfileSelectorPane getClientAndProfileSelectorPane()
{
{
return clientAndProfileSelectorPane;
return clientAndProfileSelectorPane;
}
}
private ActionGridPane actionGridPane;
private ActionGridPane actionGridPane;
private void setActionGridPane(ActionGridPane actionGridPane)
private void setActionGridPane(ActionGridPane actionGridPane)
{
{
this.actionGridPane = actionGridPane;
this.actionGridPane = actionGridPane;
leftSplitPane.getItems().add(this.actionGridPane);
leftSplitPane.getItems().add(this.actionGridPane);
}
}
public ActionGridPane getActionGridPane()
public ActionGridPane getActionGridPane()
{
{
return actionGridPane;
return actionGridPane;
}
}
private ActionDetailsPane actionDetailsPane;
private ActionDetailsPane actionDetailsPane;
private void setActionDetailsPane(ActionDetailsPane actionDetailsPane)
private void setActionDetailsPane(ActionDetailsPane actionDetailsPane)
{
{
this.actionDetailsPane = actionDetailsPane;
this.actionDetailsPane = actionDetailsPane;
leftSplitPane.getItems().add(this.actionDetailsPane);
leftSplitPane.getItems().add(this.actionDetailsPane);
}
}
public ActionDetailsPane getActionDetailsPane()
public ActionDetailsPane getActionDetailsPane()
{
{
return actionDetailsPane;
return actionDetailsPane;
}
}
public void newSelectedClientConnection(ClientConnection clientConnection)
public void newSelectedClientConnection(ClientConnection clientConnection)
{
{
if(clientConnection == null)
if(clientConnection == null)
{
{
logger.info("Remove action grid");
logger.info("Remove action grid");
}
}
else
else
{
{
getActionDetailsPane().setClient(clientConnection.getClient());
getActionDetailsPane().setClientConnection(clientConnection);
getActionGridPane().setClient(clientConnection.getClient());
getActionGridPane().setClientConnection(clientConnection);
}
}
}
}
public void newSelectedClientProfile(ClientProfile clientProfile)
public void newSelectedClientProfile(ClientProfile clientProfile)
{
{
this.currentClientProfile = clientProfile;
this.currentClientProfile = clientProfile;
getActionDetailsPane().setClientProfile(clientProfile);
getActionDetailsPane().setClientProfile(clientProfile);
drawProfile(this.currentClientProfile);
drawProfile(this.currentClientProfile);
}
}
public void drawProfile(ClientProfile clientProfile)
public void drawProfile(ClientProfile clientProfile)
{
{
logger.info("Drawing ...");
logger.info("Drawing ...");
getActionGridPane().setClientProfile(clientProfile);
getActionGridPane().setClientProfile(clientProfile);
try {
try {
getActionGridPane().renderGrid();
getActionGridPane().renderGrid();
getActionGridPane().renderActions();
getActionGridPane().renderActions();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
}
}
}
}
package com.stream_pi.server.window.dashboard.actiondetailpane;
package com.stream_pi.server.window.dashboard.actiondetailpane;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.actionproperty.ClientProperties;
import com.stream_pi.action_api.actionproperty.ClientProperties;
import com.stream_pi.action_api.actionproperty.property.ControlType;
import com.stream_pi.action_api.actionproperty.property.ControlType;
import com.stream_pi.action_api.actionproperty.property.FileExtensionFilter;
import com.stream_pi.action_api.actionproperty.property.FileExtensionFilter;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.otheractions.CombineAction;
import com.stream_pi.action_api.otheractions.CombineAction;
import com.stream_pi.action_api.otheractions.FolderAction;
import com.stream_pi.action_api.otheractions.FolderAction;
import com.stream_pi.server.uipropertybox.UIPropertyBox;
import com.stream_pi.server.uipropertybox.UIPropertyBox;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.connection.ClientConnections;
import com.stream_pi.server.connection.ClientConnections;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionBox;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionBox;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.controller.ActionDataFormats;
import com.stream_pi.server.controller.ActionDataFormats;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionGridPaneListener;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionGridPaneListener;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxInputBoxWithFileChooser;
import com.stream_pi.util.uihelper.HBoxInputBoxWithFileChooser;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.uihelper.SpaceFiller;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.collections.FXCollections;
import javafx.collections.FXCollections;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.*;
import javafx.scene.input.Dragboard;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser;
import javafx.stage.Window;
import javafx.stage.Window;
import javafx.util.Callback;
import javafx.util.Callback;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.io.File;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashMap;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class ActionDetailsPane extends VBox implements ActionDetailsPaneListener
public class ActionDetailsPane extends VBox implements ActionDetailsPaneListener
{
{
private ScrollPane scrollPane;
private ScrollPane scrollPane;
private VBox vbox;
private VBox vbox;
private VBox clientPropertiesVBox;
private VBox clientPropertiesVBox;
private Button saveButton;
private Button saveButton;
private Button deleteButton;
private Button deleteButton;
private Button openFolderButton;
private Button openFolderButton;
private HBox buttonBar;
private HBox buttonBar;
private Label actionHeadingLabel;
private Label actionHeadingLabel;
private Logger logger;
private Logger logger;
private Button returnButtonForCombineActionChild;
private Button returnButtonForCombineActionChild;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private HostServices hostServices;
private HostServices hostServices;
private ActionGridPaneListener actionGridPaneListener;
private ActionGridPaneListener actionGridPaneListener;
public ActionDetailsPane(ExceptionAndAlertHandler exceptionAndAlertHandler, HostServices hostServices,
public ActionDetailsPane(ExceptionAndAlertHandler exceptionAndAlertHandler, HostServices hostServices,
ActionGridPaneListener actionGridPaneListener)
ActionGridPaneListener actionGridPaneListener)
{
{
this.hostServices = hostServices;
this.hostServices = hostServices;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.actionGridPaneListener = actionGridPaneListener;
this.actionGridPaneListener = actionGridPaneListener;
logger = Logger.getLogger(ActionDetailsPane.class.getName());
logger = Logger.getLogger(ActionDetailsPane.class.getName());
setSpacing(10.0);
setSpacing(10.0);
clientPropertiesVBox = new VBox();
clientPropertiesVBox = new VBox();
clientPropertiesVBox.setSpacing(10.0);
clientPropertiesVBox.setSpacing(10.0);
vbox = new VBox();
vbox = new VBox();
vbox.setPadding(new Insets(0, 25, 0, 5));
vbox.setPadding(new Insets(0, 25, 0, 5));
vbox.getStyleClass().add("action_details_pane_vbox");
vbox.getStyleClass().add("action_details_pane_vbox");
vbox.setSpacing(10.0);
vbox.setSpacing(10.0);
getStyleClass().add("action_details_pane");
getStyleClass().add("action_details_pane");
scrollPane = new ScrollPane();
scrollPane = new ScrollPane();
VBox.setMargin(scrollPane, new Insets(0, 0, 0, 10));
VBox.setMargin(scrollPane, new Insets(0, 0, 0, 10));
scrollPane.getStyleClass().add("action_details_pane_scroll_pane");
scrollPane.getStyleClass().add("action_details_pane_scroll_pane");
setMinHeight(210);
setMinHeight(210);
scrollPane.setContent(vbox);
scrollPane.setContent(vbox);
vbox.prefWidthProperty().bind(scrollPane.widthProperty());
vbox.prefWidthProperty().bind(scrollPane.widthProperty());
scrollPane.prefWidthProperty().bind(widthProperty());
scrollPane.prefWidthProperty().bind(widthProperty());
VBox.setVgrow(scrollPane, Priority.ALWAYS);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
openFolderButton = new Button("Open Folder");
openFolderButton = new Button("Open Folder");
FontIcon folderOpenIcon = new FontIcon("far-folder-open");
FontIcon folderOpenIcon = new FontIcon("far-folder-open");
openFolderButton.setGraphic(folderOpenIcon);
openFolderButton.setGraphic(folderOpenIcon);
openFolderButton.setOnAction(event -> onOpenFolderButtonClicked());
openFolderButton.setOnAction(event -> onOpenFolderButtonClicked());
saveButton = new Button("Apply Changes");
saveButton = new Button("Apply Changes");
FontIcon syncIcon = new FontIcon("fas-sync-alt");
FontIcon syncIcon = new FontIcon("fas-sync-alt");
saveButton.setGraphic(syncIcon);
saveButton.setGraphic(syncIcon);
saveButton.setOnAction(event -> onSaveButtonClicked());
saveButton.setOnAction(event -> onSaveButtonClicked());
deleteButton = new Button("Delete action");
deleteButton = new Button("Delete action");
deleteButton.getStyleClass().add("action_details_pane_delete_button");
deleteButton.getStyleClass().add("action_details_pane_delete_button");
FontIcon deleteIcon = new FontIcon("fas-trash");
FontIcon deleteIcon = new FontIcon("fas-trash");
deleteIcon.getStyleClass().add("action_details_pane_delete_button_icon");
deleteIcon.getStyleClass().add("action_details_pane_delete_button_icon");
deleteButton.setGraphic(deleteIcon);
deleteButton.setGraphic(deleteIcon);
deleteButton.setOnAction(event -> onDeleteButtonClicked());
deleteButton.setOnAction(event -> onDeleteButtonClicked());
returnButtonForCombineActionChild = new Button("Return");
returnButtonForCombineActionChild = new Button("Return");
returnButtonForCombineActionChild.setGraphic(new FontIcon("fas-caret-left"));
returnButtonForCombineActionChild.setGraphic(new FontIcon("fas-caret-left"));
returnButtonForCombineActionChild.managedProperty().bind(returnButtonForCombineActionChild.visibleProperty());
returnButtonForCombineActionChild.managedProperty().bind(returnButtonForCombineActionChild.visibleProperty());
returnButtonForCombineActionChild.setOnAction(event -> {
returnButtonForCombineActionChild.setOnAction(event -> {
try {
try {
logger.info("@@## : " + action.getParent());
logger.info("@@## : " + action.getParent());
onActionClicked(getClientProfile().getActionByID(action.getParent()), getActionBox());
onActionClicked(getClientProfile().getActionByID(action.getParent()), getActionBox());
} catch (MinorException e) {
} catch (MinorException e) {
e.printStackTrace();
e.printStackTrace();
}
}
});
});
buttonBar = new HBox(openFolderButton, returnButtonForCombineActionChild, saveButton, deleteButton);
buttonBar = new HBox(openFolderButton, returnButtonForCombineActionChild, saveButton, deleteButton);
buttonBar.getStyleClass().add("action_details_pane_button_bar");
buttonBar.getStyleClass().add("action_details_pane_button_bar");
buttonBar.setPadding(new Insets(10, 10, 10, 0));
buttonBar.setPadding(new Insets(10, 10, 10, 0));
buttonBar.setAlignment(Pos.CENTER_RIGHT);
buttonBar.setAlignment(Pos.CENTER_RIGHT);
buttonBar.setVisible(false);
buttonBar.setVisible(false);
buttonBar.setSpacing(10.0);
buttonBar.setSpacing(10.0);
actionHeadingLabel = new Label();
actionHeadingLabel = new Label();
actionHeadingLabel.getStyleClass().add("action_details_pane_heading_label");
actionHeadingLabel.getStyleClass().add("action_details_pane_heading_label");
HBox headingHBox = new HBox(actionHeadingLabel);
HBox headingHBox = new HBox(actionHeadingLabel);
headingHBox.getStyleClass().add("action_details_pane_heading_box");
headingHBox.getStyleClass().add("action_details_pane_heading_box");
headingHBox.setPadding(new Insets(5, 10, 0, 10));
headingHBox.setPadding(new Insets(5, 10, 0, 10));
getChildren().addAll(headingHBox, scrollPane, buttonBar);
getChildren().addAll(headingHBox, scrollPane, buttonBar);
displayTextAlignmentComboBox = new ComboBox<>(FXCollections.observableArrayList(DisplayTextAlignment.TOP,
displayTextAlignmentComboBox = new ComboBox<>(FXCollections.observableArrayList(DisplayTextAlignment.TOP,
DisplayTextAlignment.CENTER, DisplayTextAlignment.BOTTOM));
DisplayTextAlignment.CENTER, DisplayTextAlignment.BOTTOM));
displayTextAlignmentComboBox.managedProperty().bind(displayTextAlignmentComboBox.visibleProperty());
displayTextAlignmentComboBox.managedProperty().bind(displayTextAlignmentComboBox.visibleProperty());
Callback<ListView<DisplayTextAlignment>, ListCell<DisplayTextAlignment>> displayTextAlignmentComboBoxFactory = new Callback<>() {
Callback<ListView<DisplayTextAlignment>, ListCell<DisplayTextAlignment>> displayTextAlignmentComboBoxFactory = new Callback<>() {
@Override
@Override
public ListCell<DisplayTextAlignment> call(ListView<DisplayTextAlignment> displayTextAlignment) {
public ListCell<DisplayTextAlignment> call(ListView<DisplayTextAlignment> displayTextAlignment) {
return new ListCell<>() {
return new ListCell<>() {
@Override
@Override
protected void updateItem(DisplayTextAlignment displayTextAlignment, boolean b) {
protected void updateItem(DisplayTextAlignment displayTextAlignment, boolean b) {
super.updateItem(displayTextAlignment, b);
super.updateItem(displayTextAlignment, b);
if (displayTextAlignment != null) {
if (displayTextAlignment != null) {
setText(displayTextAlignment.getUIName());
setText(displayTextAlignment.getUIName());
}
}
}
}
};
};
}
}
};
};
displayTextAlignmentComboBox.setCellFactory(displayTextAlignmentComboBoxFactory);
displayTextAlignmentComboBox.setCellFactory(displayTextAlignmentComboBoxFactory);
displayTextAlignmentComboBox.setButtonCell(displayTextAlignmentComboBoxFactory.call(null));
displayTextAlignmentComboBox.setButtonCell(displayTextAlignmentComboBoxFactory.call(null));
actionClientProperties = new ArrayList<>();
actionClientProperties = new ArrayList<>();
displayNameTextField = new TextField();
displayNameTextField = new TextField();
displayNameTextField.managedProperty().bind(displayNameTextField.visibleProperty());
displayNameTextField.managedProperty().bind(displayNameTextField.visibleProperty());
defaultIconFileTextField = new TextField();
defaultIconFileTextField = new TextField();
defaultIconFileTextField.textProperty().addListener((observableValue, s, t1) -> {
defaultIconFileTextField.textProperty().addListener((observableValue, s, t1) -> {
try {
try {
if (!s.equals(t1) && t1.length() > 0) {
if (!s.equals(t1) && t1.length() > 0) {
byte[] iconFileByteArray = Files.readAllBytes(new File(t1).toPath());
byte[] iconFileByteArray = Files.readAllBytes(new File(t1).toPath());
hideDefaultIconCheckBox.setDisable(false);
hideDefaultIconCheckBox.setDisable(false);
hideDefaultIconCheckBox.setSelected(false);
hideDefaultIconCheckBox.setSelected(false);
clearIconButton.setDisable(false);
clearIconButton.setDisable(false);
action.addIcon("default", iconFileByteArray);
action.addIcon("default", iconFileByteArray);
setSendIcon(true);
setSendIcon(true);
}
}
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
}
}
});
});
toggleOffIconFileTextField = new TextField();
toggleOffIconFileTextField = new TextField();
toggleOffIconFileTextField.textProperty().addListener((observableValue, s, t1) -> {
toggleOffIconFileTextField.textProperty().addListener((observableValue, s, t1) -> {
try {
try {
if (!s.equals(t1) && t1.length() > 0) {
if (!s.equals(t1) && t1.length() > 0) {
byte[] iconFileByteArray = Files.readAllBytes(new File(t1).toPath());
byte[] iconFileByteArray = Files.readAllBytes(new File(t1).toPath());
hideToggleOffIconCheckBox.setDisable(false);
hideToggleOffIconCheckBox.setDisable(false);
hideToggleOffIconCheckBox.setSelected(false);
hideToggleOffIconCheckBox.setSelected(false);
clearIconButton.setDisable(false);
clearIconButton.setDisable(false);
action.addIcon("toggle_off", iconFileByteArray);
action.addIcon("toggle_off", iconFileByteArray);
setSendIcon(true);
setSendIcon(true);
}
}
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
}
}
});
});
toggleOnIconFileTextField = new TextField();
toggleOnIconFileTextField = new TextField();
toggleOnIconFileTextField.textProperty().addListener((observableValue, s, t1) -> {
toggleOnIconFileTextField.textProperty().addListener((observableValue, s, t1) -> {
try {
try {
if (!s.equals(t1) && t1.length() > 0) {
if (!s.equals(t1) && t1.length() > 0) {
byte[] iconFileByteArray = Files.readAllBytes(new File(t1).toPath());
byte[] iconFileByteArray = Files.readAllBytes(new File(t1).toPath());
hideToggleOnIconCheckBox.setDisable(false);
hideToggleOnIconCheckBox.setDisable(false);
hideToggleOnIconCheckBox.setSelected(false);
hideToggleOnIconCheckBox.setSelected(false);
clearIconButton.setDisable(false);
clearIconButton.setDisable(false);
action.addIcon("toggle_on", iconFileByteArray);
action.addIcon("toggle_on", iconFileByteArray);
setSendIcon(true);
setSendIcon(true);
}
}
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
}
}
});
});
clearIconButton = new Button("Clear Icon");
clearIconButton = new Button("Clear Icon");
clearIconButton.managedProperty().bind(clearIconButton.visibleProperty());
clearIconButton.managedProperty().bind(clearIconButton.visibleProperty());
clearIconButton.setOnAction(event -> {
clearIconButton.setOnAction(event -> {
hideDefaultIconCheckBox.setDisable(true);
hideDefaultIconCheckBox.setDisable(true);
hideDefaultIconCheckBox.setSelected(false);
hideDefaultIconCheckBox.setSelected(false);
hideToggleOffIconCheckBox.setDisable(true);
hideToggleOffIconCheckBox.setDisable(true);
hideToggleOffIconCheckBox.setSelected(false);
hideToggleOffIconCheckBox.setSelected(false);
hideToggleOnIconCheckBox.setDisable(true);
hideToggleOnIconCheckBox.setDisable(true);
hideToggleOnIconCheckBox.setSelected(false);
hideToggleOnIconCheckBox.setSelected(false);
clearIconButton.setDisable(true);
clearIconButton.setDisable(true);
setSendIcon(false);
setSendIcon(false);
defaultIconFileTextField.clear();
defaultIconFileTextField.clear();
toggleOffIconFileTextField.clear();
toggleOffIconFileTextField.clear();
toggleOnIconFileTextField.clear();
toggleOnIconFileTextField.clear();
});
});
hideDisplayTextCheckBox = new CheckBox("Hide");
hideDisplayTextCheckBox = new CheckBox("Hide");
hideDisplayTextCheckBox.managedProperty().bind(hideDisplayTextCheckBox.visibleProperty());
hideDisplayTextCheckBox.managedProperty().bind(hideDisplayTextCheckBox.visibleProperty());
hideDefaultIconCheckBox = new CheckBox("Hide");
hideDefaultIconCheckBox = new CheckBox("Hide");
hideToggleOnIconCheckBox = new CheckBox("Hide");
hideToggleOnIconCheckBox = new CheckBox("Hide");
hideToggleOffIconCheckBox = new CheckBox("Hide");
hideToggleOffIconCheckBox = new CheckBox("Hide");
actionBackgroundColourPicker = new ColorPicker();
actionBackgroundColourPicker = new ColorPicker();
actionBackgroundColourPicker.managedProperty().bind(actionBackgroundColourPicker.visibleProperty());
actionBackgroundColourPicker.managedProperty().bind(actionBackgroundColourPicker.visibleProperty());
displayTextColourPicker = new ColorPicker();
displayTextColourPicker = new ColorPicker();
displayTextColourPicker.managedProperty().bind(displayTextColourPicker.visibleProperty());
displayTextColourPicker.managedProperty().bind(displayTextColourPicker.visibleProperty());
actionBackgroundColourTransparentCheckBox = new CheckBox("Default");
actionBackgroundColourTransparentCheckBox = new CheckBox("Default");
actionBackgroundColourPicker.disableProperty()
actionBackgroundColourPicker.disableProperty()
.bind(actionBackgroundColourTransparentCheckBox.selectedProperty());
.bind(actionBackgroundColourTransparentCheckBox.selectedProperty());
HBox.setMargin(actionBackgroundColourTransparentCheckBox, new Insets(0, 0, 0, 10));
HBox.setMargin(actionBackgroundColourTransparentCheckBox, new Insets(0, 0, 0, 10));
displayTextColourDefaultCheckBox = new CheckBox("Default");
displayTextColourDefaultCheckBox = new CheckBox("Default");
displayTextColourPicker.disableProperty()
displayTextColourPicker.disableProperty()
.bind(displayTextColourDefaultCheckBox.selectedProperty());
.bind(displayTextColourDefaultCheckBox.selectedProperty());
HBox.setMargin(displayTextColourDefaultCheckBox, new Insets(0, 0, 0, 10));
HBox.setMargin(displayTextColourDefaultCheckBox, new Insets(0, 0, 0, 10));
HBox displayTextColourHBox = new HBox(new Label("Display Text Colour"), SpaceFiller.horizontal(), displayTextColourPicker,
HBox displayTextColourHBox = new HBox(new Label("Display Text Colour"), SpaceFiller.horizontal(), displayTextColourPicker,
displayTextColourDefaultCheckBox);
displayTextColourDefaultCheckBox);
displayTextColourHBox.setAlignment(Pos.CENTER);
displayTextColourHBox.setAlignment(Pos.CENTER);
displayTextColourHBox.setSpacing(5.0);
displayTextColourHBox.setSpacing(5.0);
HBox bgColourHBox = new HBox(new Label("Background Colour"), SpaceFiller.horizontal(), actionBackgroundColourPicker,
HBox bgColourHBox = new HBox(new Label("Background Colour"), SpaceFiller.horizontal(), actionBackgroundColourPicker,
actionBackgroundColourTransparentCheckBox);
actionBackgroundColourTransparentCheckBox);
bgColourHBox.setAlignment(Pos.CENTER);
bgColourHBox.setAlignment(Pos.CENTER);
bgColourHBox.setSpacing(5.0);
bgColourHBox.setSpacing(5.0);
HBox clearIconHBox = new HBox(clearIconButton);
HBox clearIconHBox = new HBox(clearIconButton);
clearIconHBox.setAlignment(Pos.CENTER_RIGHT);
clearIconHBox.setAlignment(Pos.CENTER_RIGHT);
displayTextFieldHBox = new HBoxInputBox("Display Name", displayNameTextField, hideDisplayTextCheckBox);
displayTextFieldHBox = new HBoxInputBox("Display Name", displayNameTextField, hideDisplayTextCheckBox);
HBox alignmentHBox = new HBox(new Label("Alignment"), SpaceFiller.horizontal(),
HBox alignmentHBox = new HBox(new Label("Alignment"), SpaceFiller.horizontal(),
displayTextAlignmentComboBox);
displayTextAlignmentComboBox);
normalToggleActionCommonPropsVBox = new VBox(
normalToggleActionCommonPropsVBox = new VBox(
displayTextColourHBox,
displayTextColourHBox,
alignmentHBox,
alignmentHBox,
bgColourHBox,
bgColourHBox,
clearIconHBox
clearIconHBox
);
);
normalToggleActionCommonPropsVBox.managedProperty().bind(normalToggleActionCommonPropsVBox.visibleProperty());
normalToggleActionCommonPropsVBox.managedProperty().bind(normalToggleActionCommonPropsVBox.visibleProperty());
normalToggleActionCommonPropsVBox.setSpacing(10.0);
normalToggleActionCommonPropsVBox.setSpacing(10.0);
normalActionsPropsVBox = new VBox(
normalActionsPropsVBox = new VBox(
new HBoxInputBoxWithFileChooser("Icon", defaultIconFileTextField, hideDefaultIconCheckBox,
new HBoxInputBoxWithFileChooser("Icon", defaultIconFileTextField, hideDefaultIconCheckBox,
new FileChooser.ExtensionFilter("Images", "*.jpeg", "*.jpg", "*.png", "*.gif"))
new FileChooser.ExtensionFilter("Images", "*.jpeg", "*.jpg", "*.png", "*.gif"))
);
);
normalActionsPropsVBox.managedProperty().bind(normalActionsPropsVBox.visibleProperty());
normalActionsPropsVBox.managedProperty().bind(normalActionsPropsVBox.visibleProperty());
normalActionsPropsVBox.setSpacing(10.0);
normalActionsPropsVBox.setSpacing(10.0);
toggleActionsPropsVBox = new VBox(
toggleActionsPropsVBox = new VBox(
new HBoxInputBoxWithFileChooser("Toggle Off Icon", toggleOffIconFileTextField, hideToggleOffIconCheckBox,
new HBoxInputBoxWithFileChooser("Toggle Off Icon", toggleOffIconFileTextField, hideToggleOffIconCheckBox,
new FileChooser.ExtensionFilter("Images", "*.jpeg", "*.jpg", "*.png", "*.gif")),
new FileChooser.ExtensionFilter("Images", "*.jpeg", "*.jpg", "*.png", "*.gif")),
new HBoxInputBoxWithFileChooser("Toggle On Icon", toggleOnIconFileTextField, hideToggleOnIconCheckBox,
new HBoxInputBoxWithFileChooser("Toggle On Icon", toggleOnIconFileTextField, hideToggleOnIconCheckBox,
new FileChooser.ExtensionFilter("Images", "*.jpeg", "*.jpg", "*.png", "*.gif"))
new FileChooser.ExtensionFilter("Images", "*.jpeg", "*.jpg", "*.png", "*.gif"))
);
);
toggleActionsPropsVBox.managedProperty().bind(toggleActionsPropsVBox.visibleProperty());
toggleActionsPropsVBox.managedProperty().bind(toggleActionsPropsVBox.visibleProperty());
toggleActionsPropsVBox.setSpacing(10.0);
toggleActionsPropsVBox.setSpacing(10.0);
vbox.getChildren().addAll(displayTextFieldHBox,normalToggleActionCommonPropsVBox, normalActionsPropsVBox, toggleActionsPropsVBox, clientPropertiesVBox);
vbox.getChildren().addAll(displayTextFieldHBox,normalToggleActionCommonPropsVBox, normalActionsPropsVBox, toggleActionsPropsVBox, clientPropertiesVBox);
vbox.setVisible(false);
vbox.setVisible(false);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
setOnDragOver(dragEvent -> {
setOnDragOver(dragEvent -> {
if (dragEvent.getDragboard().hasContent(ActionDataFormats.ACTION_TYPE) && action != null) {
if (dragEvent.getDragboard().hasContent(ActionDataFormats.ACTION_TYPE) && action != null) {
if (action.getActionType() == ActionType.COMBINE) {
if (action.getActionType() == ActionType.COMBINE) {
dragEvent.acceptTransferModes(TransferMode.ANY);
dragEvent.acceptTransferModes(TransferMode.ANY);
dragEvent.consume();
dragEvent.consume();
}
}
}
}
});
});
setOnDragDropped(dragEvent -> {
setOnDragDropped(dragEvent -> {
try {
try {
Dragboard db = dragEvent.getDragboard();
Dragboard db = dragEvent.getDragboard();
ActionType actionType = (ActionType) db.getContent(ActionDataFormats.ACTION_TYPE);
ActionType actionType = (ActionType) db.getContent(ActionDataFormats.ACTION_TYPE);
if(actionType == ActionType.NORMAL || actionType == ActionType.TOGGLE)
if(actionType == ActionType.NORMAL || actionType == ActionType.TOGGLE)
{
{
ExternalPlugin newAction = actionGridPaneListener.createNewActionFromExternalPlugin(
ExternalPlugin newAction = actionGridPaneListener.createNewActionFromExternalPlugin(
(String) db.getContent(ActionDataFormats.MODULE_NAME)
(String) db.getContent(ActionDataFormats.MODULE_NAME)
);
);
boolean isNew = (boolean) db.getContent(ActionDataFormats.IS_NEW);
boolean isNew = (boolean) db.getContent(ActionDataFormats.IS_NEW);
if(isNew)
if(isNew)
{
{
newAction.setDisplayText("Untitled Action");
newAction.setDisplayText("Untitled Action");
newAction.setShowDisplayText(true);
newAction.setShowDisplayText(true);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
if(actionType == ActionType.TOGGLE)
if(actionType == ActionType.TOGGLE)
newAction.setCurrentIconState("false__false");
newAction.setCurrentIconState("false__false");
}
}
else
else
{
{
newAction.setClientProperties((ClientProperties) db.getContent(ActionDataFormats.CLIENT_PROPERTIES));
newAction.setClientProperties((ClientProperties) db.getContent(ActionDataFormats.CLIENT_PROPERTIES));
newAction.setIcons((HashMap<String, byte[]>) db.getContent(ActionDataFormats.ICONS));
newAction.setIcons((HashMap<String, byte[]>) db.getContent(ActionDataFormats.ICONS));
newAction.setCurrentIconState((String) db.getContent(ActionDataFormats.CURRENT_ICON_STATE));
newAction.setCurrentIconState((String) db.getContent(ActionDataFormats.CURRENT_ICON_STATE));
newAction.setBgColourHex((String) db.getContent(ActionDataFormats.BACKGROUND_COLOUR));
newAction.setBgColourHex((String) db.getContent(ActionDataFormats.BACKGROUND_COLOUR));
newAction.setDisplayTextFontColourHex((String) db.getContent(ActionDataFormats.DISPLAY_TEXT_FONT_COLOUR));
newAction.setDisplayTextFontColourHex((String) db.getContent(ActionDataFormats.DISPLAY_TEXT_FONT_COLOUR));
newAction.setDisplayText((String) db.getContent(ActionDataFormats.DISPLAY_TEXT));
newAction.setDisplayText((String) db.getContent(ActionDataFormats.DISPLAY_TEXT));
newAction.setDisplayTextAlignment((DisplayTextAlignment) db.getContent(ActionDataFormats.DISPLAY_TEXT_ALIGNMENT));
newAction.setDisplayTextAlignment((DisplayTextAlignment) db.getContent(ActionDataFormats.DISPLAY_TEXT_ALIGNMENT));
newAction.setShowDisplayText((boolean) db.getContent(ActionDataFormats.DISPLAY_TEXT_SHOW));
newAction.setShowDisplayText((boolean) db.getContent(ActionDataFormats.DISPLAY_TEXT_SHOW));
}
}
newAction.setLocation(new Location(-1, -1));
newAction.setLocation(new Location(-1, -1));
newAction.setParent(this.action.getID());
newAction.setParent(this.action.getID());
try
try
{
{
newAction.onActionCreate();
newAction.onActionCreate();
}
}
catch (Exception e)
catch (Exception e)
{
{
exceptionAndAlertHandler.handleMinorException(new MinorException("Error","onCreate() failed for "+action.getModuleName()+"\n\n"+e.getMessage()));
exceptionAndAlertHandler.handleMinorException(new MinorException("Error","onCreate() failed for "+action.getModuleName()+"\n\n"+e.getMessage()));
}
}
combineActionPropertiesPane.getCombineAction().addChild(newAction.getID());
combineActionPropertiesPane.getCombineAction().addChild(newAction.getID());
addActionToCurrentClientProfile(newAction);
addActionToCurrentClientProfile(newAction);
ClientConnection connection = ClientConnections.getInstance()
ClientConnection connection = ClientConnections.getInstance()
.getClientConnectionBySocketAddress(getClient().getRemoteSocketAddress());
.getClientConnectionBySocketAddress(getClient().getRemoteSocketAddress());
connection.saveActionDetails(getClientProfile().getID(), newAction);
connection.saveActionDetails(getClientProfile().getID(), newAction);
combineActionPropertiesPane.renderProps();
combineActionPropertiesPane.renderProps();
saveAction(true, false);
saveAction(true, false);
}
}
} catch (MinorException e) {
} catch (MinorException e) {
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
e.printStackTrace();
e.printStackTrace();
} catch (SevereException e) {
} catch (SevereException e) {
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
e.printStackTrace();
e.printStackTrace();
} catch (CloneNotSupportedException e) {
} catch (CloneNotSupportedException e) {
e.printStackTrace();
e.printStackTrace();
} catch (Exception e)
} catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
});
});
}
}
private VBox normalActionsPropsVBox;
private VBox normalActionsPropsVBox;
private VBox normalToggleActionCommonPropsVBox;
private VBox normalToggleActionCommonPropsVBox;
private VBox toggleActionsPropsVBox;
private VBox toggleActionsPropsVBox;
private HBox displayTextFieldHBox;
private HBox displayTextFieldHBox;
private Client client;
private ClientConnection clientConnection;
private ClientProfile clientProfile;
private ClientProfile clientProfile;
public void setClient(Client client) {
public void setClientConnection(ClientConnection clientConnection) {
this.client = client;
this.clientConnection = clientConnection;
}
}
public Client getClient() {
public ClientConnection getClientConnection() {
return client;
return clientConnection;
}
public Client getClient()
{
return getClientConnection().getClient();
}
}
public void setClientProfile(ClientProfile clientProfile) {
public void setClientProfile(ClientProfile clientProfile) {
this.clientProfile = clientProfile;
this.clientProfile = clientProfile;
}
}
public ClientProfile getClientProfile() {
public ClientProfile getClientProfile() {
return clientProfile;
return clientProfile;
}
}
public void setActionHeadingLabelText(String text) {
public void setActionHeadingLabelText(String text) {
actionHeadingLabel.setText(text);
actionHeadingLabel.setText(text);
}
}
private Action action;
private Action action;
public Action getAction() {
public Action getAction() {
return action;
return action;
}
}
private ActionBox actionBox;
private ActionBox actionBox;
public ActionBox getActionBox() {
public ActionBox getActionBox() {
return actionBox;
return actionBox;
}
}
@Override
@Override
public void onActionClicked(Action action, ActionBox actionBox) throws MinorException
public void onActionClicked(Action action, ActionBox actionBox) throws MinorException
{
{
clear();
clear();
this.action = action;
this.action = action;
this.actionBox = actionBox;
this.actionBox = actionBox;
renderActionProperties();
renderActionProperties();
}
}
public void refresh() throws MinorException
public void refresh() throws MinorException
{
{
clear(false);
clear(false);
renderActionProperties();
renderActionProperties();
}
}
private TextField displayNameTextField;
private TextField displayNameTextField;
private CheckBox hideDisplayTextCheckBox;
private CheckBox hideDisplayTextCheckBox;
private CheckBox hideDefaultIconCheckBox;
private CheckBox hideDefaultIconCheckBox;
private TextField defaultIconFileTextField;
private TextField defaultIconFileTextField;
private CheckBox hideToggleOnIconCheckBox;
private CheckBox hideToggleOnIconCheckBox;
private TextField toggleOnIconFileTextField;
private TextField toggleOnIconFileTextField;
private CheckBox hideToggleOffIconCheckBox;
private CheckBox hideToggleOffIconCheckBox;
private TextField toggleOffIconFileTextField;
private TextField toggleOffIconFileTextField;
private Button clearIconButton;
private Button clearIconButton;
private ColorPicker actionBackgroundColourPicker;
private ColorPicker actionBackgroundColourPicker;
private ColorPicker displayTextColourPicker;
private ColorPicker displayTextColourPicker;
private CheckBox actionBackgroundColourTransparentCheckBox;
private CheckBox actionBackgroundColourTransparentCheckBox;
private CheckBox displayTextColourDefaultCheckBox;
private CheckBox displayTextColourDefaultCheckBox;
private ComboBox<DisplayTextAlignment> displayTextAlignmentComboBox;
private ComboBox<DisplayTextAlignment> displayTextAlignmentComboBox;
public void clear(boolean actionNull)
public void clear(boolean actionNull)
{
{
sendIcon = false;
sendIcon = false;
actionClientProperties.clear();
actionClientProperties.clear();
displayNameTextField.clear();
displayNameTextField.clear();
defaultIconFileTextField.clear();
defaultIconFileTextField.clear();
toggleOffIconFileTextField.clear();
toggleOffIconFileTextField.clear();
toggleOnIconFileTextField.clear();
toggleOnIconFileTextField.clear();
clientPropertiesVBox.getChildren().clear();
clientPropertiesVBox.getChildren().clear();
vbox.setVisible(false);
vbox.setVisible(false);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
buttonBar.setVisible(false);
buttonBar.setVisible(false);
setActionHeadingLabelText("");
setActionHeadingLabelText("");
actionBackgroundColourPicker.setValue(Color.WHITE);
actionBackgroundColourPicker.setValue(Color.WHITE);
displayTextColourPicker.setValue(Color.WHITE);
displayTextColourPicker.setValue(Color.WHITE);
if(actionNull)
if(actionNull)
{
{
action = null;
action = null;
actionBox = null;
actionBox = null;
}
}
}
}
@Override
@Override
public void clear()
public void clear()
{
{
clear(true);
clear(true);
}
}
boolean isCombineChild = false;
boolean isCombineChild = false;
public boolean isCombineChild() {
public boolean isCombineChild() {
return isCombineChild;
return isCombineChild;
}
}
public void renderActionProperties() throws MinorException
public void renderActionProperties() throws MinorException
{
{
//Combine Child action
//Combine Child action
isCombineChild = action.getLocation().getCol() == -1;
isCombineChild = action.getLocation().getCol() == -1;
System.out.println(isCombineChild);
System.out.println(isCombineChild);
System.out.println("DISPLAY : "+action.getDisplayText());
System.out.println("DISPLAY : "+action.getDisplayText());
displayNameTextField.setText(action.getDisplayText());
displayNameTextField.setText(action.getDisplayText());
if(isCombineChild)
if(isCombineChild)
{
{
setReturnButtonForCombineActionChildVisible(true);
setReturnButtonForCombineActionChildVisible(true);
normalActionsPropsVBox.setVisible(false);
normalActionsPropsVBox.setVisible(false);
normalToggleActionCommonPropsVBox.setVisible(false);
normalToggleActionCommonPropsVBox.setVisible(false);
hideDisplayTextCheckBox.setSelected(false);
hideDisplayTextCheckBox.setSelected(false);
hideDisplayTextCheckBox.setVisible(false);
hideDisplayTextCheckBox.setVisible(false);
}
}
else
else
{
{
normalToggleActionCommonPropsVBox.setVisible(true);
normalToggleActionCommonPropsVBox.setVisible(true);
if(getAction().getActionType() == ActionType.NORMAL)
if(getAction().getActionType() == ActionType.NORMAL)
{
{
normalActionsPropsVBox.setVisible(true);
normalActionsPropsVBox.setVisible(true);
toggleActionsPropsVBox.setVisible(false);
toggleActionsPropsVBox.setVisible(false);
boolean doesDefaultExist = action.getIcons().containsKey("default");
boolean doesDefaultExist = action.getIcons().containsKey("default");
boolean isDefaultHidden = !action.getCurrentIconState().equals("default");
boolean isDefaultHidden = !action.getCurrentIconState().equals("default");
if(!doesDefaultExist)
if(!doesDefaultExist)
isDefaultHidden = false;
isDefaultHidden = false;
hideDefaultIconCheckBox.setDisable(!doesDefaultExist);
hideDefaultIconCheckBox.setDisable(!doesDefaultExist);
hideDefaultIconCheckBox.setSelected(isDefaultHidden);
hideDefaultIconCheckBox.setSelected(isDefaultHidden);
}
}
else
else
{
{
normalActionsPropsVBox.setVisible(false);
normalActionsPropsVBox.setVisible(false);
toggleActionsPropsVBox.setVisible(true);
toggleActionsPropsVBox.setVisible(true);
boolean doesToggleOnExist = action.getIcons().containsKey("toggle_on");
boolean doesToggleOnExist = action.getIcons().containsKey("toggle_on");
boolean isToggleOnHidden = action.getCurrentIconState().contains("toggle_on");
boolean isToggleOnHidden = action.getCurrentIconState().contains("toggle_on");
if(!doesToggleOnExist)
if(!doesToggleOnExist)
isToggleOnHidden = false;
isToggleOnHidden = false;
hideToggleOnIconCheckBox.setDisable(!doesToggleOnExist);
hideToggleOnIconCheckBox.setDisable(!doesToggleOnExist);
hideToggleOnIconCheckBox.setSelected(isToggleOnHidden);
hideToggleOnIconCheckBox.setSelected(isToggleOnHidden);
boolean doesToggleOffExist = action.getIcons().containsKey("toggle_off");
boolean doesToggleOffExist = action.getIcons().containsKey("toggle_off");
boolean isToggleOffHidden = action.getCurrentIconState().contains("toggle_off");
boolean isToggleOffHidden = action.getCurrentIconState().contains("toggle_off");
if(!doesToggleOffExist)
if(!doesToggleOffExist)
isToggleOffHidden = false;
isToggleOffHidden = false;
hideToggleOffIconCheckBox.setDisable(!doesToggleOffExist);
hideToggleOffIconCheckBox.setDisable(!doesToggleOffExist);
hideToggleOffIconCheckBox.setSelected(isToggleOffHidden);
hideToggleOffIconCheckBox.setSelected(isToggleOffHidden);
}
}
setReturnButtonForCombineActionChildVisible(false);
setReturnButtonForCombineActionChildVisible(false);
hideDisplayTextCheckBox.setVisible(true);
hideDisplayTextCheckBox.setVisible(true);
setFolderButtonVisible(action.getActionType().equals(ActionType.FOLDER));
setFolderButtonVisible(action.getActionType().equals(ActionType.FOLDER));
displayTextAlignmentComboBox.getSelectionModel().select(action.getDisplayTextAlignment());
displayTextAlignmentComboBox.getSelectionModel().select(action.getDisplayTextAlignment());
if(!action.getBgColourHex().isEmpty())
if(!action.getBgColourHex().isEmpty())
actionBackgroundColourPicker.setValue(Color.valueOf(action.getBgColourHex()));
actionBackgroundColourPicker.setValue(Color.valueOf(action.getBgColourHex()));
else
else
actionBackgroundColourTransparentCheckBox.setSelected(true);
actionBackgroundColourTransparentCheckBox.setSelected(true);
if(!action.getDisplayTextFontColourHex().isEmpty())
if(!action.getDisplayTextFontColourHex().isEmpty())
displayTextColourPicker.setValue(Color.valueOf(action.getDisplayTextFontColourHex()));
displayTextColourPicker.setValue(Color.valueOf(action.getDisplayTextFontColourHex()));
else
else
displayTextColourDefaultCheckBox.setSelected(true);
displayTextColourDefaultCheckBox.setSelected(true);
hideDisplayTextCheckBox.setSelected(!action.isShowDisplayText());
hideDisplayTextCheckBox.setSelected(!action.isShowDisplayText());
clearIconButton.setDisable(!action.isHasIcon());
clearIconButton.setDisable(!action.isHasIcon());
}
}
buttonBar.setVisible(true);
buttonBar.setVisible(true);
vbox.setVisible(true);
vbox.setVisible(true);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
if(action.getActionType() == ActionType.NORMAL || action.getActionType() == ActionType.TOGGLE)
if(action.getActionType() == ActionType.NORMAL || action.getActionType() == ActionType.TOGGLE)
{
{
if(action.isInvalid())
if(action.isInvalid())
setActionHeadingLabelText("Invalid action ("+action.getModuleName()+")");
setActionHeadingLabelText("Invalid action ("+action.getModuleName()+")");
else
else
setActionHeadingLabelText(action.getName());
setActionHeadingLabelText(action.getName());
}
}
else if(action.getActionType() == ActionType.COMBINE)
else if(action.getActionType() == ActionType.COMBINE)
setActionHeadingLabelText("Combine action");
setActionHeadingLabelText("Combine action");
else if(action.getActionType() == ActionType.FOLDER)
else if(action.getActionType() == ActionType.FOLDER)
setActionHeadingLabelText("Folder action");
setActionHeadingLabelText("Folder action");
if(!action.isInvalid())
if(!action.isInvalid())
{
{
if(action.getActionType() == ActionType.NORMAL || action.getActionType() == ActionType.TOGGLE)
if(action.getActionType() == ActionType.NORMAL || action.getActionType() == ActionType.TOGGLE)
renderClientProperties();
renderClientProperties();
else if(action.getActionType() == ActionType.COMBINE)
else if(action.getActionType() == ActionType.COMBINE)
renderCombineActionProperties();
renderCombineActionProperties();
}
}
}
}
private CombineActionPropertiesPane combineActionPropertiesPane;
private CombineActionPropertiesPane combineActionPropertiesPane;
public CombineActionPropertiesPane getCombineActionPropertiesPane() {
public CombineActionPropertiesPane getCombineActionPropertiesPane() {
return combineActionPropertiesPane;
return combineActionPropertiesPane;
}
}
public void setReturnButtonForCombineActionChildVisible(boolean visible)
public void setReturnButtonForCombineActionChildVisible(boolean visible)
{
{
returnButtonForCombineActionChild.setVisible(visible);
returnButtonForCombineActionChild.setVisible(visible);
}
}
public void renderCombineActionProperties()
public void renderCombineActionProperties()
{
{
try
try
{
{
combineActionPropertiesPane = new CombineActionPropertiesPane(getActionAsCombineAction(action),
combineActionPropertiesPane = new CombineActionPropertiesPane(getActionAsCombineAction(action),
getClientProfile(),
getClientProfile(),
this
this
);
);
clientPropertiesVBox.getChildren().add(combineActionPropertiesPane);
clientPropertiesVBox.getChildren().add(combineActionPropertiesPane);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
}
}
public void setAction(Action action) {
public void setAction(Action action) {
this.action = action;
this.action = action;
}
}
public FolderAction getActionAsFolderAction(Action action)
public FolderAction getActionAsFolderAction(Action action)
{
{
FolderAction folderAction = new FolderAction();
FolderAction folderAction = new FolderAction();
folderAction.setDisplayText(action.getDisplayText());
folderAction.setDisplayText(action.getDisplayText());
folderAction.setName(action.getName());
folderAction.setName(action.getName());
folderAction.setID(action.getID());
folderAction.setID(action.getID());
folderAction.setLocation(action.getLocation());
folderAction.setLocation(action.getLocation());
folderAction.setBgColourHex(action.getBgColourHex());
folderAction.setBgColourHex(action.getBgColourHex());
folderAction.setParent(action.getParent());
folderAction.setParent(action.getParent());
folderAction.getClientProperties().set(action.getClientProperties());
folderAction.getClientProperties().set(action.getClientProperties());
folderAction.setDisplayTextAlignment(action.getDisplayTextAlignment());
folderAction.setDisplayTextAlignment(action.getDisplayTextAlignment());
folderAction.setIcons(action.getIcons());
folderAction.setIcons(action.getIcons());
folderAction.setCurrentIconState(action.getCurrentIconState());
folderAction.setCurrentIconState(action.getCurrentIconState());
folderAction.setDisplayTextFontColourHex(action.getDisplayTextFontColourHex());
folderAction.setDisplayTextFontColourHex(action.getDisplayTextFontColourHex());
return folderAction;
return folderAction;
}
}
public CombineAction getActionAsCombineAction(Action action)
public CombineAction getActionAsCombineAction(Action action)
{
{
CombineAction combineAction = new CombineAction();
CombineAction combineAction = new CombineAction();
combineAction.setDisplayText(action.getDisplayText());
combineAction.setDisplayText(action.getDisplayText());
combineAction.setName(action.getName());
combineAction.setName(action.getName());
combineAction.setID(action.getID());
combineAction.setID(action.getID());
combineAction.setLocation(action.getLocation());
combineAction.setLocation(action.getLocation());
combineAction.setBgColourHex(action.getBgColourHex());
combineAction.setBgColourHex(action.getBgColourHex());
combineAction.setParent(action.getParent());
combineAction.setParent(action.getParent());
combineAction.getClientProperties().set(action.getClientProperties());
combineAction.getClientProperties().set(action.getClientProperties());
combineAction.setDisplayTextAlignment(action.getDisplayTextAlignment());
combineAction.setDisplayTextAlignment(action.getDisplayTextAlignment());
combineAction.setIcons(action.getIcons());
combineAction.setIcons(action.getIcons());
combineAction.setCurrentIconState(action.getCurrentIconState());
combineAction.setCurrentIconState(action.getCurrentIconState());
combineAction.setDisplayTextFontColourHex(action.getDisplayTextFontColourHex());
combineAction.setDisplayTextFontColourHex(action.getDisplayTextFontColourHex());
return combineAction;
return combineAction;
}
}
@Override
@Override
public void onOpenFolderButtonClicked()
public void onOpenFolderButtonClicked()
{
{
FolderAction folderAction = getActionAsFolderAction(action);
FolderAction folderAction = getActionAsFolderAction(action);
actionBox.getActionGridPaneListener().renderFolder(folderAction);
actionBox.getActionGridPaneListener().renderFolder(folderAction);
clear();
clear();
}
}
@Override
@Override
public Window getCurrentWindow() {
public Window getCurrentWindow() {
return getScene().getWindow();
return getScene().getWindow();
}
}
private ArrayList<UIPropertyBox> actionClientProperties;
private ArrayList<UIPropertyBox> actionClientProperties;
private TextField delayBeforeRunningTextField;
private TextField delayBeforeRunningTextField;
public void renderClientProperties() throws MinorException
public void renderClientProperties() throws MinorException
{
{
delayBeforeRunningTextField = new TextField();
delayBeforeRunningTextField = new TextField();
delayBeforeRunningTextField.setText(getAction().getDelayBeforeExecuting()+"");
delayBeforeRunningTextField.setText(getAction().getDelayBeforeExecuting()+"");
clientPropertiesVBox.getChildren().add(
clientPropertiesVBox.getChildren().add(
new HBoxInputBox("Delay before running (milli-seconds)", delayBeforeRunningTextField, 100)
new HBoxInputBox("Delay before running (milli-seconds)", delayBeforeRunningTextField, 100)
);
);
for(int i =0;i< action.getClientProperties().getSize(); i++)
for(int i =0;i< action.getClientProperties().getSize(); i++)
{
{
Property eachProperty = action.getClientProperties().get().get(i);
Property eachProperty = action.getClientProperties().get().get(i);
if(!eachProperty.isVisible())
if(!eachProperty.isVisible())
continue;
continue;
Label label = new Label(eachProperty.getDisplayName());
Label label = new Label(eachProperty.getDisplayName());
HBox hBox = new HBox(label);
HBox hBox = new HBox(label);
hBox.setSpacing(5.0);
hBox.setSpacing(5.0);
hBox.setAlignment(Pos.CENTER_LEFT);
hBox.setAlignment(Pos.CENTER_LEFT);
Node controlNode = null;
Node controlNode = null;
if(eachProperty.getHelpLink() != null)
if(eachProperty.getHelpLink() != null)
{
{
Button helpButton = new Button();
Button helpButton = new Button();
FontIcon questionIcon = new FontIcon("fas-question");
FontIcon questionIcon = new FontIcon("fas-question");
helpButton.setGraphic(questionIcon);
helpButton.setGraphic(questionIcon);
helpButton.setOnAction(event -> {
helpButton.setOnAction(event -> {
hostServices.showDocument(eachProperty.getHelpLink());
hostServices.showDocument(eachProperty.getHelpLink());
});
});
hBox.getChildren().add(helpButton);
hBox.getChildren().add(helpButton);
hBox.getChildren().add(controlNode);
hBox.getChildren().add(controlNode);
}
}
hBox.getChildren().add(SpaceFiller.horizontal());
hBox.getChildren().add(SpaceFiller.horizontal());
if(eachProperty.getControlType() == ControlType.COMBO_BOX)
if(eachProperty.getControlType() == ControlType.COMBO_BOX)
{
{
ComboBox<String> comboBox = new ComboBox<>();
ComboBox<String> comboBox = new ComboBox<>();
comboBox.getItems().addAll(eachProperty.getListValue());
comboBox.getItems().addAll(eachProperty.getListValue());
comboBox.getSelectionModel().select(eachProperty.getSelectedIndex());
comboBox.getSelectionModel().select(eachProperty.getSelectedIndex());
controlNode = comboBox;
controlNode = comboBox;
hBox.getChildren().add(controlNode);
hBox.getChildren().add(controlNode);
}
}
else if(eachProperty.getControlType() == ControlType.FILE_PATH)
else if(eachProperty.getControlType() == ControlType.FILE_PATH)
{
{
TextField textField = new TextField(eachProperty.getRawValue());
TextField textField = new TextField(eachProperty.getRawValue());
FileExtensionFilter[] fileExtensionFilters = eachProperty.getExtensionFilters();
FileExtensionFilter[] fileExtensionFilters = eachProperty.getExtensionFilters();
FileChooser.ExtensionFilter[] extensionFilters = new FileChooser.ExtensionFilter[fileExtensionFilters.length];
FileChooser.ExtensionFilter[] extensionFilters = new FileChooser.ExtensionFilter[fileExtensionFilters.length];
for(int x = 0;x<fileExtensionFilters.length;x++)
for(int x = 0;x<fileExtensionFilters.length;x++)
{
{
extensionFilters[x] = new FileChooser.ExtensionFilter(
extensionFilters[x] = new FileChooser.ExtensionFilter(
fileExtensionFilters[x].getDescription(),
fileExtensionFilters[x].getDescription(),
fileExtensionFilters[x].getExtensions()
fileExtensionFilters[x].getExtensions()
);
);
}
}
hBox = new HBoxInputBoxWithFileChooser(eachProperty.getDisplayName(), textField, null,
hBox = new HBoxInputBoxWithFileChooser(eachProperty.getDisplayName(), textField, null,
extensionFilters);
extensionFilters);
controlNode = textField;
controlNode = textField;
}
}
else if(eachProperty.getControlType() == ControlType.TEXT_FIELD)
else if(eachProperty.getControlType() == ControlType.TEXT_FIELD)
{
{
controlNode= new TextField(eachProperty.getRawValue());
controlNode= new TextField(eachProperty.getRawValue());
hBox.getChildren().add(controlNode);
hBox.getChildren().add(controlNode);
}
}
else if(eachProperty.getControlType() == ControlType.TEXT_FIELD_MASKED)
else if(eachProperty.getControlType() == ControlType.TEXT_FIELD_MASKED)
{
{
PasswordField textField = new PasswordField();
PasswordField textField = new PasswordField();
textField.setText(eachProperty.getRawValue());
textField.setText(eachProperty.getRawValue());
controlNode= textField;
controlNode= textField;
hBox.getChildren().add(controlNode);
hBox.getChildren().add(controlNode);
}
}
else if(eachProperty.getControlType() == ControlType.TOGGLE)
else if(eachProperty.getControlType() == ControlType.TOGGLE)
{
{
ToggleButton toggleButton = new ToggleButton();
ToggleButton toggleButton = new ToggleButton();
toggleButton.setSelected(eachProperty.getBoolValue());
toggleButton.setSelected(eachProperty.getBoolValue());
if(eachProperty.getBoolValue())
if(eachProperty.getBoolValue())
toggleButton.setText("ON");
toggleButton.setText("ON");
else
else
toggleButton.setText("OFF");
toggleButton.setText("OFF");
toggleButton.selectedProperty().addListener((observableValue, aBoolean, t1) -> {
toggleButton.selectedProperty().addListener((observableValue, aBoolean, t1) -> {
if(t1)
if(t1)
toggleButton.setText("ON");
toggleButton.setText("ON");
else
else
toggleButton.setText("OFF");
toggleButton.setText("OFF");
});
});
controlNode = toggleButton;
controlNode = toggleButton;
hBox.getChildren().add(controlNode);
hBox.getChildren().add(controlNode);
}
}
else if(eachProperty.getControlType() == ControlType.SLIDER_DOUBLE)
else if(eachProperty.getControlType() == ControlType.SLIDER_DOUBLE)
{
{
Slider slider = new Slider();
Slider slider = new Slider();
slider.setValue(eachProperty.getDoubleValue());
slider.setValue(eachProperty.getDoubleValue());
slider.setMax(eachProperty.getMaxDoubleValue());
slider.setMax(eachProperty.getMaxDoubleValue());
slider.setMin(eachProperty.getMinDoubleValue());
slider.setMin(eachProperty.getMinDoubleValue());
controlNode = slider;
controlNode = slider;
hBox.getChildren().add(controlNode);
hBox.getChildren().add(controlNode);
}
}
else if(eachProperty.getControlType() == ControlType.SLIDER_INTEGER)
else if(eachProperty.getControlType() == ControlType.SLIDER_INTEGER)
{
{
Slider slider = new Slider();
Slider slider = new Slider();
slider.setValue(eachProperty.getIntValue());
slider.setValue(eachProperty.getIntValue());
slider.setMax(eachProperty.getMaxIntValue());
slider.setMax(eachProperty.getMaxIntValue());
slider.setMin(eachProperty.getMinIntValue());
slider.setMin(eachProperty.getMinIntValue());
slider.setBlockIncrement(1.0);
slider.setBlockIncrement(1.0);
slider.setSnapToTicks(true);
slider.setSnapToTicks(true);
controlNode = slider;
controlNode = slider;
hBox.getChildren().add(controlNode);
hBox.getChildren().add(controlNode);
}
}
UIPropertyBox clientProperty = new UIPropertyBox(i, eachProperty.getDisplayName(), controlNode,
UIPropertyBox clientProperty = new UIPropertyBox(i, eachProperty.getDisplayName(), controlNode,
eachProperty.getControlType(), eachProperty.getType(), eachProperty.isCanBeBlank());
eachProperty.getControlType(), eachProperty.getType(), eachProperty.isCanBeBlank());
actionClientProperties.add(clientProperty);
actionClientProperties.add(clientProperty);
clientPropertiesVBox.getChildren().add(hBox);
clientPropertiesVBox.getChildren().add(hBox);
}
}
}
}
public void onSaveButtonClicked()
public void onSaveButtonClicked()
{
{
try {
try {
// saveButton.setDisable(true);
// saveButton.setDisable(true);
// deleteButton.setDisable(true);
// deleteButton.setDisable(true);
validateForm();
validateForm();
saveAction(true, true);
saveAction(true, true);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
}
}
private boolean sendIcon = false;
private boolean sendIcon = false;
@Override
@Override
public void setSendIcon(boolean sendIcon)
public void setSendIcon(boolean sendIcon)
{
{
this.sendIcon = sendIcon;
this.sendIcon = sendIcon;
}
}
public void addActionToCurrentClientProfile(Action newAction) throws CloneNotSupportedException {
public void addActionToCurrentClientProfile(Action newAction) throws CloneNotSupportedException {
getClientProfile().addAction(newAction);
getClientProfile().addAction(newAction);
}
}
@Override
@Override
public void saveAction(Action action, boolean runAsync, boolean runOnActionSavedFromServer)
public void saveAction(Action action, boolean runAsync, boolean runOnActionSavedFromServer)
{
{
new OnSaveActionTask(
new OnSaveActionTask(
ClientConnections.getInstance().getClientConnectionBySocketAddress(
ClientConnections.getInstance().getClientConnectionBySocketAddress(
getClient().getRemoteSocketAddress()
getClient().getRemoteSocketAddress()
),
),
action,
action,
delayBeforeRunningTextField.getText(),
delayBeforeRunningTextField.getText(),
displayNameTextField.getText(),
displayNameTextField.getText(),
isCombineChild(),
isCombineChild(),
!hideDisplayTextCheckBox.isSelected(),
!hideDisplayTextCheckBox.isSelected(),
displayTextColourDefaultCheckBox.isSelected(),
displayTextColourDefaultCheckBox.isSelected(),
"#" + displayTextColourPicker.getValue().toString().substring(2),
"#" + displayTextColourPicker.getValue().toString().substring(2),
clearIconButton.isDisable(),
clearIconButton.isDisable(),
hideDefaultIconCheckBox.isSelected(),
hideDefaultIconCheckBox.isSelected(),
hideToggleOffIconCheckBox.isSelected(),
hideToggleOffIconCheckBox.isSelected(),
hideToggleOnIconCheckBox.isSelected(),
hideToggleOnIconCheckBox.isSelected(),
displayTextAlignmentComboBox.getSelectionModel().getSelectedItem(),
displayTextAlignmentComboBox.getSelectionModel().getSelectedItem(),
actionBackgroundColourTransparentCheckBox.isSelected(),
actionBackgroundColourTransparentCheckBox.isSelected(),
"#" + actionBackgroundColourPicker.getValue().toString().substring(2),
"#" + actionBackgroundColourPicker.getValue().toString().substring(2),
getCombineActionPropertiesPane(),
getCombineActionPropertiesPane(),
clientProfile, sendIcon, actionBox, actionClientProperties, exceptionAndAlertHandler,
clientProfile, sendIcon, actionBox, actionClientProperties, exceptionAndAlertHandler,
saveButton, deleteButton, runOnActionSavedFromServer, runAsync
saveButton, deleteButton, runOnActionSavedFromServer, runAsync
);
);
}
}
@Override
@Override
public void saveAction(boolean runAsync, boolean runOnActionSavedFromServer)
public void saveAction(boolean runAsync, boolean runOnActionSavedFromServer)
{
{
saveAction(action, runAsync, runOnActionSavedFromServer);
saveAction(action, runAsync, runOnActionSavedFromServer);
}
}
public void setFolderButtonVisible(boolean visible)
public void setFolderButtonVisible(boolean visible)
{
{
openFolderButton.setVisible(visible);
openFolderButton.setVisible(visible);
}
}
public void validateForm() throws MinorException
public void validateForm() throws MinorException
{
{
String displayNameStr = displayNameTextField.getText();
String displayNameStr = displayNameTextField.getText();
StringBuilder finalErrors = new StringBuilder();
StringBuilder finalErrors = new StringBuilder();
if(displayNameStr.isBlank())
if(displayNameStr.isBlank())
{
{
finalErrors.append(" * Display Name cannot be blank\n");
finalErrors.append(" * Display Name cannot be blank\n");
}
}
if(!isCombineChild())
if(!isCombineChild())
{
{
if(action.getActionType() == ActionType.NORMAL)
if(action.getActionType() == ActionType.NORMAL)
{
{
if(action.isHasIcon())
if(action.isHasIcon())
{
{
if(hideDisplayTextCheckBox.isSelected() && hideDefaultIconCheckBox.isSelected())
if(hideDisplayTextCheckBox.isSelected() && hideDefaultIconCheckBox.isSelected())
{
{
finalErrors.append(" * Both Icon and display text check box cannot be hidden.\n");
finalErrors.append(" * Both Icon and display text check box cannot be hidden.\n");
}
}
}
}
else
else
{
{
if(hideDisplayTextCheckBox.isSelected())
if(hideDisplayTextCheckBox.isSelected())
finalErrors.append(" * Display Text cannot be hidden, since there is also no icon.\n");
finalErrors.append(" * Display Text cannot be hidden, since there is also no icon.\n");
}
}
}
}
}
}
if(action.getActionType() == ActionType.NORMAL)
if(action.getActionType() == ActionType.NORMAL)
{
{
try
try
{
{
int n = Integer.parseInt(delayBeforeRunningTextField.getText());
int n = Integer.parseInt(delayBeforeRunningTextField.getText());
if (n<0)
if (n<0)
{
{
finalErrors.append(" * Sleep should be greater than 0.\n");
finalErrors.append(" * Sleep should be greater than 0.\n");
}
}
}
}
catch (Exception e)
catch (Exception e)
{
{
finalErrors.append(" * Sleep should be a number.\n");
finalErrors.append(" * Sleep should be a number.\n");
}
}
}
}
for (UIPropertyBox clientProperty : actionClientProperties) {
for (UIPropertyBox clientProperty : actionClientProperties) {
Node controlNode = clientProperty.getControlNode();
Node controlNode = clientProperty.getControlNode();
if (clientProperty.getControlType() == ControlType.TEXT_FIELD ||
if (clientProperty.getControlType() == ControlType.TEXT_FIELD ||
clientProperty.getControlType() == ControlType.FILE_PATH)
clientProperty.getControlType() == ControlType.FILE_PATH)
{
{
String value = ((TextField) controlNode).getText();
String value = ((TextField) controlNode).getText();
if(clientProperty.getType() == Type.INTEGER)
if(clientProperty.getType() == Type.INTEGER)
{
{
try
try
{
{
Integer.parseInt(value);
Integer.parseInt(value);
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
finalErrors.append(" -> ").append(clientProperty.getDisplayName()).append(" must be integer.\n");
finalErrors.append(" -> ").append(clientProperty.getDisplayName()).append(" must be integer.\n");
}
}
}
}
else
else
{
{
if(value.isBlank() && !clientProperty.isCanBeBlank())
if(value.isBlank() && !clientProperty.isCanBeBlank())
finalErrors.append(" -> ").append(clientProperty.getDisplayName()).append(" cannot be blank.\n");
finalErrors.append(" -> ").append(clientProperty.getDisplayName()).append(" cannot be blank.\n");
}
}
}
}
}
}
if(!finalErrors.toString().isEmpty())
if(!finalErrors.toString().isEmpty())
{
{
throw new MinorException("You made mistakes",
throw new MinorException("You made mistakes",
finalErrors.toString());
finalErrors.toString());
}
}
}
}
public void onDeleteButtonClicked()
public void onDeleteButtonClicked()
{
{
new OnDeleteActionTask(
new OnDeleteActionTask(
ClientConnections.getInstance().getClientConnectionBySocketAddress(
ClientConnections.getInstance().getClientConnectionBySocketAddress(
getClient().getRemoteSocketAddress()
getClient().getRemoteSocketAddress()
),
),
action,
action,
isCombineChild(),
isCombineChild(),
getCombineActionPropertiesPane(),
getCombineActionPropertiesPane(),
clientProfile, actionBox, this, exceptionAndAlertHandler,
clientProfile, actionBox, this, exceptionAndAlertHandler,
!isCombineChild
!isCombineChild
);
);
}
}
}
}
package com.stream_pi.server.window.dashboard.actiondetailpane;
package com.stream_pi.server.window.dashboard.actiondetailpane;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.logging.Logger;
import java.util.logging.Logger;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.actionproperty.ClientProperties;
import com.stream_pi.action_api.actionproperty.ClientProperties;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.uipropertybox.UIPropertyBox;
import com.stream_pi.server.uipropertybox.UIPropertyBox;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionBox;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionBox;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.scene.control.Button;
import javafx.scene.control.Button;
public class OnSaveActionTask extends Task<Void>
public class OnSaveActionTask extends Task<Void>
{
{
private Logger logger;
private Logger logger;
public OnSaveActionTask(ClientConnection connection, Action action, String delayBeforeRunningString, String displayNameText, boolean isCombineChild,
public OnSaveActionTask(ClientConnection connection, Action action, String delayBeforeRunningString, String displayNameText, boolean isCombineChild,
boolean isShowDisplayText, boolean isDefaultDisplayTextColour, String displayTextFontColour, boolean isClearIcon,
boolean isShowDisplayText, boolean isDefaultDisplayTextColour, String displayTextFontColour, boolean isClearIcon,
boolean isHideDefaultIcon, boolean isHideToggleOffIcon, boolean isHideToggleOnIcon, DisplayTextAlignment displayTextAlignment, boolean isTransparentBackground, String backgroundColour,
boolean isHideDefaultIcon, boolean isHideToggleOffIcon, boolean isHideToggleOnIcon, DisplayTextAlignment displayTextAlignment, boolean isTransparentBackground, String backgroundColour,
CombineActionPropertiesPane combineActionPropertiesPane, ClientProfile clientProfile, boolean sendIcon, ActionBox actionBox,
CombineActionPropertiesPane combineActionPropertiesPane, ClientProfile clientProfile, boolean sendIcon, ActionBox actionBox,
ArrayList<UIPropertyBox> actionClientProperties, ExceptionAndAlertHandler exceptionAndAlertHandler, Button saveButton, Button deleteButton,
ArrayList<UIPropertyBox> actionClientProperties, ExceptionAndAlertHandler exceptionAndAlertHandler, Button saveButton, Button deleteButton,
boolean runOnActionSavedFromServer, boolean runAsync)
boolean runOnActionSavedFromServer, boolean runAsync)
{
{
this.saveButton = saveButton;
this.saveButton = saveButton;
this.deleteButton = deleteButton;
this.deleteButton = deleteButton;
this.delayBeforeRunningString = delayBeforeRunningString;
this.delayBeforeRunningString = delayBeforeRunningString;
this.connection = connection;
this.connection = connection;
this.action = action;
this.action = action;
this.displayNameText = displayNameText;
this.displayNameText = displayNameText;
this.isCombineChild = isCombineChild;
this.isCombineChild = isCombineChild;
this.isShowDisplayText = isShowDisplayText;
this.isShowDisplayText = isShowDisplayText;
this.isDefaultDisplayTextColour = isDefaultDisplayTextColour;
this.isDefaultDisplayTextColour = isDefaultDisplayTextColour;
this.displayTextFontColour = displayTextFontColour;
this.displayTextFontColour = displayTextFontColour;
this.isClearIcon = isClearIcon;
this.isClearIcon = isClearIcon;
this.isHideDefaultIcon = isHideDefaultIcon;
this.isHideDefaultIcon = isHideDefaultIcon;
this.isHideToggleOffIcon = isHideToggleOffIcon;
this.isHideToggleOffIcon = isHideToggleOffIcon;
this.isHideToggleOnIcon = isHideToggleOnIcon;
this.isHideToggleOnIcon = isHideToggleOnIcon;
this.displayTextAlignment = displayTextAlignment;
this.displayTextAlignment = displayTextAlignment;
this.isTransparentBackground = isTransparentBackground;
this.isTransparentBackground = isTransparentBackground;
this.combineActionPropertiesPane = combineActionPropertiesPane;
this.combineActionPropertiesPane = combineActionPropertiesPane;
this.clientProfile = clientProfile;
this.clientProfile = clientProfile;
this.sendIcon = sendIcon;
this.sendIcon = sendIcon;
this.actionBox = actionBox;
this.actionBox = actionBox;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.backgroundColour = backgroundColour;
this.backgroundColour = backgroundColour;
this.actionClientProperties = actionClientProperties;
this.actionClientProperties = actionClientProperties;
this.runOnActionSavedFromServer = runOnActionSavedFromServer;
this.runOnActionSavedFromServer = runOnActionSavedFromServer;
logger = Logger.getLogger(getClass().getName());
logger = Logger.getLogger(getClass().getName());
if(runAsync)
if(runAsync)
new Thread(this).start();
new Thread(this).start();
else
else
runTask();
runTask();
}
}
private boolean runOnActionSavedFromServer;
private boolean runOnActionSavedFromServer;
private Button saveButton;
private Button saveButton;
private Button deleteButton;
private Button deleteButton;
private String delayBeforeRunningString;
private String delayBeforeRunningString;
private boolean isShowDisplayText;
private boolean isShowDisplayText;
private boolean isCombineChild;
private boolean isCombineChild;
private String displayNameText;
private String displayNameText;
private boolean isDefaultDisplayTextColour;
private boolean isDefaultDisplayTextColour;
private ArrayList<UIPropertyBox> actionClientProperties;
private ArrayList<UIPropertyBox> actionClientProperties;
private String displayTextFontColour;
private String displayTextFontColour;
private boolean isClearIcon;
private boolean isClearIcon;
private boolean isHideDefaultIcon;
private boolean isHideDefaultIcon;
private boolean isHideToggleOffIcon;
private boolean isHideToggleOffIcon;
private boolean isHideToggleOnIcon;
private boolean isHideToggleOnIcon;
private DisplayTextAlignment displayTextAlignment;
private DisplayTextAlignment displayTextAlignment;
private boolean isTransparentBackground;
private boolean isTransparentBackground;
private String backgroundColour;
private String backgroundColour;
private CombineActionPropertiesPane combineActionPropertiesPane;
private CombineActionPropertiesPane combineActionPropertiesPane;
private ClientProfile clientProfile;
private ClientProfile clientProfile;
private boolean sendIcon;
private boolean sendIcon;
private ActionBox actionBox;
private ActionBox actionBox;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private Action action;
private Action action;
private ClientConnection connection;
private ClientConnection connection;
private void setSaveDeleteButtonState(boolean state)
private void setSaveDeleteButtonState(boolean state)
{
{
Platform.runLater(()->{
Platform.runLater(()->{
saveButton.setDisable(state);
saveButton.setDisable(state);
deleteButton.setDisable(state);
deleteButton.setDisable(state);
});
});
}
}
private void runTask()
private void runTask()
{
{
action.setDisplayText(displayNameText);
action.setDisplayText(displayNameText);
if(!isCombineChild)
if(!isCombineChild)
{
{
setSaveDeleteButtonState(true);
setSaveDeleteButtonState(true);
action.setShowDisplayText(isShowDisplayText);
action.setShowDisplayText(isShowDisplayText);
if(isDefaultDisplayTextColour)
if(isDefaultDisplayTextColour)
action.setDisplayTextFontColourHex("");
action.setDisplayTextFontColourHex("");
else
else
{
{
action.setDisplayTextFontColourHex(displayTextFontColour);
action.setDisplayTextFontColourHex(displayTextFontColour);
//String fontColour = "#" + displayTextColourPicker.getValue().toString().substring(2);
//String fontColour = "#" + displayTextColourPicker.getValue().toString().substring(2);
//action.setDisplayTextFontColourHex(fontColour);
//action.setDisplayTextFontColourHex(fontColour);
}
}
if(isClearIcon)
if(isClearIcon)
{
{
action.setIcons(null);
action.setIcons(null);
action.setCurrentIconState("");
action.setCurrentIconState("");
}
}
if(action.getActionType() == ActionType.NORMAL)
if(action.getActionType() == ActionType.NORMAL)
{
{
if(isHideDefaultIcon)
if(isHideDefaultIcon)
{
{
if(action.getIcon("default") != null)
if(action.getIcon("default") != null)
action.setCurrentIconState("default");
action.setCurrentIconState("default");
}
}
else
else
{
{
action.setCurrentIconState("");
action.setCurrentIconState("");
}
}
}
}
else if (action.getActionType() == ActionType.TOGGLE)
else if (action.getActionType() == ActionType.TOGGLE)
{
{
action.setCurrentIconState(isHideToggleOffIcon+"__"+isHideToggleOnIcon);
action.setCurrentIconState(isHideToggleOffIcon+"__"+isHideToggleOnIcon);
}
}
action.setDisplayTextAlignment(displayTextAlignment);
action.setDisplayTextAlignment(displayTextAlignment);
if(isTransparentBackground)
if(isTransparentBackground)
action.setBgColourHex("");
action.setBgColourHex("");
else
else
{
{
action.setBgColourHex(backgroundColour);
action.setBgColourHex(backgroundColour);
}
}
}
}
System.out.println("parent : "+action.getParent());
System.out.println("parent : "+action.getParent());
if(action.getActionType() == ActionType.COMBINE)
if(action.getActionType() == ActionType.COMBINE)
{
{
List<String> finalChildren = combineActionPropertiesPane.getFinalChildren();
List<String> finalChildren = combineActionPropertiesPane.getFinalChildren();
System.out.println("2334 "+finalChildren.size());
System.out.println("2334 "+finalChildren.size());
ClientProperties clientProperties = new ClientProperties();
ClientProperties clientProperties = new ClientProperties();
for(int i = 0;i<finalChildren.size();i++)
for(int i = 0;i<finalChildren.size();i++)
{
{
Property property = new Property(i+"", Type.STRING);
Property property = new Property(i+"", Type.STRING);
property.setRawValue(finalChildren.get(i));
property.setRawValue(finalChildren.get(i));
clientProperties.addProperty(property);
clientProperties.addProperty(property);
}
}
action.getClientProperties().set(clientProperties);
action.getClientProperties().set(clientProperties);
}
}
else
else
{
{
action.setDelayBeforeExecuting(Integer.parseInt(delayBeforeRunningString));
action.setDelayBeforeExecuting(Integer.parseInt(delayBeforeRunningString));
//properties
//properties
for (UIPropertyBox clientProperty : actionClientProperties) {
for (UIPropertyBox clientProperty : actionClientProperties) {
action.getClientProperties().get().get(clientProperty.getIndex()).setRawValue(clientProperty.getRawValue());
action.getClientProperties().get().get(clientProperty.getIndex()).setRawValue(clientProperty.getRawValue());
}
}
}
}
try
try
{
{
logger.info("Saving action ... "+action.isHasIcon()+"+"+sendIcon);
logger.info("Saving action ... "+action.isHasIcon()+"+"+sendIcon);
if(runOnActionSavedFromServer)
{
for(Property property : action.getClientProperties().get())
{
System.out.println("SSSSSDDD : "+property.getName());
System.out.println("@@@@DDD : "+property.getRawValue());
}
try
{
if(action instanceof ExternalPlugin)
((ExternalPlugin) action).onActionSavedFromServer();
}
catch (Exception e)
{
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(new MinorException("Error","onActionSavedFromServer() failed for "+action.getModuleName()+"\n\n"+e.getMessage()));
}
}
connection.saveActionDetails(clientProfile.getID(), action);
connection.saveActionDetails(clientProfile.getID(), action);
if(sendIcon)
if(sendIcon)
{
{
sendAllIcons(clientProfile, action);
sendAllIcons(clientProfile, action);
}
}
if(!isCombineChild)
if(!isCombineChild)
{
{
Platform.runLater(()->{
Platform.runLater(()->{
actionBox.clear();
actionBox.clear();
actionBox.setAction(action);
actionBox.setAction(action);
//actionBox.baseInit();
//actionBox.baseInit();
actionBox.init();
actionBox.init();
});
});
setSaveDeleteButtonState(false);
setSaveDeleteButtonState(false);
}
}
//clientProfile.removeActionByID(action.getID());
//clientProfile.removeActionByID(action.getID());
//clientProfile.addAction(action);
//clientProfile.addAction(action);
if(runOnActionSavedFromServer)
{
for(Property property : action.getClientProperties().get())
{
System.out.println("SSSSSDDD : "+property.getName());
System.out.println("@@@@DDD : "+property.getRawValue());
}
try
{
if(action instanceof ExternalPlugin)
((ExternalPlugin) action).onActionSavedFromServer();
}
catch (Exception e)
{
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(new MinorException("Error","onActionSavedFromServer() failed for "+action.getModuleName()+"\n\n"+e.getMessage()));
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
}
}
private void sendAllIcons(ClientProfile clientProfile, Action action) throws SevereException
private void sendAllIcons(ClientProfile clientProfile, Action action) throws SevereException
{
{
for(String state : action.getIcons().keySet())
for(String state : action.getIcons().keySet())
{
{
connection.sendIcon(clientProfile.getID(), action.getID(), state, action.getIcon(state));
connection.sendIcon(clientProfile.getID(), action.getID(), state, action.getIcon(state));
}
}
}
}
@Override
@Override
protected Void call() throws Exception
protected Void call() throws Exception
{
{
runTask();
runTask();
return null;
return null;
}
}
}
}
package com.stream_pi.server.window.dashboard.actiongridpane;
package com.stream_pi.server.window.dashboard.actiongridpane;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.actionproperty.ClientProperties;
import com.stream_pi.action_api.actionproperty.ClientProperties;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.server.controller.ActionDataFormats;
import com.stream_pi.server.controller.ActionDataFormats;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPaneListener;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPaneListener;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.CacheHint;
import javafx.scene.CacheHint;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.image.Image;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseButton;
import javafx.scene.input.TransferMode;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.Background;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.TextAlignment;
import javafx.scene.text.TextAlignment;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.io.ObjectInputStream;
import java.nio.ByteBuffer;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.HashMap;
public class ActionBox extends StackPane{
public class ActionBox extends StackPane{
private Label displayTextLabel;
private Label displayTextLabel;
private int row;
private int row;
private int col;
private int col;
public void setRow(int row) {
public void setRow(int row) {
this.row = row;
this.row = row;
}
}
public void setCol(int col) {
public void setCol(int col) {
this.col = col;
this.col = col;
}
}
public int getRow() {
public int getRow() {
return row;
return row;
}
}
public int getCol() {
public int getCol() {
return col;
return col;
}
}
private ActionDetailsPaneListener actionDetailsPaneListener;
private ActionDetailsPaneListener actionDetailsPaneListener;
public void clear()
public void clear()
{
{
setStyle(null);
setStyle(null);
setAction(null);
setAction(null);
getStyleClass().clear();
getStyleClass().clear();
setBackground(Background.EMPTY);
setBackground(Background.EMPTY);
removeFontIcon();
removeFontIcon();
getChildren().clear();
getChildren().clear();
baseInit();
baseInit();
}
}
public void baseInit()
public void baseInit()
{
{
displayTextLabel = new Label();
displayTextLabel = new Label();
displayTextLabel.setWrapText(true);
displayTextLabel.setWrapText(true);
displayTextLabel.setTextAlignment(TextAlignment.CENTER);
displayTextLabel.setTextAlignment(TextAlignment.CENTER);
displayTextLabel.getStyleClass().add("action_box_display_text_label");
displayTextLabel.getStyleClass().add("action_box_display_text_label");
displayTextLabel.prefHeightProperty().bind(heightProperty());
displayTextLabel.prefHeightProperty().bind(heightProperty());
displayTextLabel.prefWidthProperty().bind(widthProperty());
displayTextLabel.prefWidthProperty().bind(widthProperty());
getChildren().addAll(displayTextLabel);
getChildren().addAll(displayTextLabel);
setMinSize(size, size);
setMinSize(size, size);
setMaxSize(size, size);
setMaxSize(size, size);
getStyleClass().add("action_box");
getStyleClass().add("action_box");
setIcon(null);
setIcon(null);
getStyleClass().add("action_box_valid");
getStyleClass().add("action_box_valid");
setOnDragOver(dragEvent ->
setOnDragOver(dragEvent ->
{
{
if(dragEvent.getDragboard().hasContent(ActionDataFormats.ACTION_TYPE))
if(dragEvent.getDragboard().hasContent(ActionDataFormats.ACTION_TYPE))
{
{
dragEvent.acceptTransferModes(TransferMode.ANY);
dragEvent.acceptTransferModes(TransferMode.ANY);
dragEvent.consume();
dragEvent.consume();
}
}
});
});
setOnDragDropped(dragEvent ->
setOnDragDropped(dragEvent ->
{
{
try
try
{
{
if(action == null)
if(action == null)
{
{
Dragboard db = dragEvent.getDragboard();
Dragboard db = dragEvent.getDragboard();
ActionType actionType = (ActionType) db.getContent(ActionDataFormats.ACTION_TYPE);
ActionType actionType = (ActionType) db.getContent(ActionDataFormats.ACTION_TYPE);
if(actionType == ActionType.NORMAL || actionType == ActionType.TOGGLE)
if(actionType == ActionType.NORMAL || actionType == ActionType.TOGGLE)
{
{
String moduleName = (String) dragEvent.getDragboard().getContent(ActionDataFormats.MODULE_NAME);
String moduleName = (String) dragEvent.getDragboard().getContent(ActionDataFormats.MODULE_NAME);
ExternalPlugin newAction = actionGridPaneListener.createNewActionFromExternalPlugin(moduleName);
ExternalPlugin newAction = actionGridPaneListener.createNewActionFromExternalPlugin(moduleName);
boolean isNew = (boolean) db.getContent(ActionDataFormats.IS_NEW);
boolean isNew = (boolean) db.getContent(ActionDataFormats.IS_NEW);
if(isNew)
if(isNew)
{
{
newAction.setDisplayText("Untitled Action");
newAction.setDisplayText("Untitled Action");
newAction.setShowDisplayText(true);
newAction.setShowDisplayText(true);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
if(actionType == ActionType.TOGGLE)
if(actionType == ActionType.TOGGLE)
newAction.setCurrentIconState("false__false");
newAction.setCurrentIconState("false__false");
}
}
else
else
{
{
newAction.setClientProperties((ClientProperties) db.getContent(ActionDataFormats.CLIENT_PROPERTIES));
newAction.setClientProperties((ClientProperties) db.getContent(ActionDataFormats.CLIENT_PROPERTIES));
newAction.setIcons((HashMap<String, byte[]>) db.getContent(ActionDataFormats.ICONS));
newAction.setIcons((HashMap<String, byte[]>) db.getContent(ActionDataFormats.ICONS));
newAction.setCurrentIconState((String) db.getContent(ActionDataFormats.CURRENT_ICON_STATE));
newAction.setCurrentIconState((String) db.getContent(ActionDataFormats.CURRENT_ICON_STATE));
newAction.setBgColourHex((String) db.getContent(ActionDataFormats.BACKGROUND_COLOUR));
newAction.setBgColourHex((String) db.getContent(ActionDataFormats.BACKGROUND_COLOUR));
newAction.setDisplayTextFontColourHex((String) db.getContent(ActionDataFormats.DISPLAY_TEXT_FONT_COLOUR));
newAction.setDisplayTextFontColourHex((String) db.getContent(ActionDataFormats.DISPLAY_TEXT_FONT_COLOUR));
newAction.setDisplayText((String) db.getContent(ActionDataFormats.DISPLAY_TEXT));
newAction.setDisplayText((String) db.getContent(ActionDataFormats.DISPLAY_TEXT));
newAction.setDisplayTextAlignment((DisplayTextAlignment) db.getContent(ActionDataFormats.DISPLAY_TEXT_ALIGNMENT));
newAction.setDisplayTextAlignment((DisplayTextAlignment) db.getContent(ActionDataFormats.DISPLAY_TEXT_ALIGNMENT));
newAction.setShowDisplayText((boolean) db.getContent(ActionDataFormats.DISPLAY_TEXT_SHOW));
newAction.setShowDisplayText((boolean) db.getContent(ActionDataFormats.DISPLAY_TEXT_SHOW));
}
}
newAction.setLocation(new Location(getRow(),
newAction.setLocation(new Location(getRow(),
getCol()));
getCol()));
newAction.setProfileID(actionGridPaneListener.getCurrentProfile().getID());
newAction.setProfileID(actionGridPaneListener.getCurrentProfile().getID());
newAction.setParent(actionGridPaneListener.getCurrentParent());
newAction.setParent(actionGridPaneListener.getCurrentParent());
newAction.setSocketAddressForClient(actionGridPaneListener.getClientConnection().getRemoteSocketAddress());
try
try
{
{
newAction.onActionCreate();
newAction.onActionCreate();
}
}
catch (Exception e)
catch (Exception e)
{
{
exceptionAndAlertHandler.handleMinorException(new MinorException("Error","onCreate() failed for "+action.getModuleName()+"\n\n"+e.getMessage()));
exceptionAndAlertHandler.handleMinorException(new MinorException("Error","onCreate() failed for "+action.getModuleName()+"\n\n"+e.getMessage()));
}
}
actionGridPaneListener.addActionToCurrentClientProfile(newAction);
actionGridPaneListener.addActionToCurrentClientProfile(newAction);
setAction(newAction);
setAction(newAction);
actionDetailsPaneListener.onActionClicked(newAction, this);
actionDetailsPaneListener.onActionClicked(newAction, this);
if(newAction.isHasIcon())
if(newAction.isHasIcon())
actionDetailsPaneListener.setSendIcon(true);
actionDetailsPaneListener.setSendIcon(true);
actionDetailsPaneListener.saveAction(true, false);
actionDetailsPaneListener.saveAction(true, false);
}
}
else
else
{
{
Action newAction = actionGridPaneListener.createNewOtherAction(actionType);
Action newAction = actionGridPaneListener.createNewOtherAction(actionType);
newAction.setLocation(new Location(getRow(),
newAction.setLocation(new Location(getRow(),
getCol()));
getCol()));
newAction.setParent(actionGridPaneListener.getCurrentParent());
newAction.setParent(actionGridPaneListener.getCurrentParent());
newAction.setProfileID(actionGridPaneListener.getCurrentProfile().getID());
newAction.setProfileID(actionGridPaneListener.getCurrentProfile().getID());
newAction.setSocketAddressForClient(actionGridPaneListener.getClientConnection().getRemoteSocketAddress());
actionGridPaneListener.addActionToCurrentClientProfile(newAction);
actionGridPaneListener.addActionToCurrentClientProfile(newAction);
setAction(newAction);
setAction(newAction);
init();
init();
actionDetailsPaneListener.onActionClicked(newAction, this);
actionDetailsPaneListener.onActionClicked(newAction, this);
if(newAction.isHasIcon())
if(newAction.isHasIcon())
actionDetailsPaneListener.setSendIcon(true);
actionDetailsPaneListener.setSendIcon(true);
actionDetailsPaneListener.saveAction(true, false);
actionDetailsPaneListener.saveAction(true, false);
}
}
}
}
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
e.printStackTrace();
e.printStackTrace();
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
});
});
setOnDragDetected(mouseEvent -> {
setOnDragDetected(mouseEvent -> {
if(action!=null)
if(action!=null)
{
{
if(action.getActionType() == ActionType.NORMAL)
if(action.getActionType() == ActionType.NORMAL)
{
{
Dragboard db = startDragAndDrop(TransferMode.ANY);
Dragboard db = startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
ClipboardContent content = new ClipboardContent();
content.put(ActionDataFormats.CLIENT_PROPERTIES, getAction().getClientProperties());
content.put(ActionDataFormats.CLIENT_PROPERTIES, getAction().getClientProperties());
content.put(ActionDataFormats.ICONS, getAction().getIcons());
content.put(ActionDataFormats.ICONS, getAction().getIcons());
content.put(ActionDataFormats.CURRENT_ICON_STATE, getAction().getCurrentIconState());
content.put(ActionDataFormats.CURRENT_ICON_STATE, getAction().getCurrentIconState());
content.put(ActionDataFormats.BACKGROUND_COLOUR, getAction().getBgColourHex());
content.put(ActionDataFormats.BACKGROUND_COLOUR, getAction().getBgColourHex());
content.put(ActionDataFormats.DISPLAY_TEXT_FONT_COLOUR, getAction().getDisplayTextFontColourHex());
content.put(ActionDataFormats.DISPLAY_TEXT_FONT_COLOUR, getAction().getDisplayTextFontColourHex());
content.put(ActionDataFormats.DISPLAY_TEXT, getAction().getDisplayText());
content.put(ActionDataFormats.DISPLAY_TEXT, getAction().getDisplayText());
content.put(ActionDataFormats.DISPLAY_TEXT_ALIGNMENT, getAction().getDisplayTextAlignment());
content.put(ActionDataFormats.DISPLAY_TEXT_ALIGNMENT, getAction().getDisplayTextAlignment());
content.put(ActionDataFormats.DISPLAY_TEXT_SHOW, getAction().isShowDisplayText());
content.put(ActionDataFormats.DISPLAY_TEXT_SHOW, getAction().isShowDisplayText());
content.put(ActionDataFormats.IS_NEW, false);
content.put(ActionDataFormats.IS_NEW, false);
content.put(ActionDataFormats.ACTION_TYPE, getAction().getActionType());
content.put(ActionDataFormats.ACTION_TYPE, getAction().getActionType());
content.put(ActionDataFormats.MODULE_NAME, getAction().getModuleName());
content.put(ActionDataFormats.MODULE_NAME, getAction().getModuleName());
db.setContent(content);
db.setContent(content);
mouseEvent.consume();
mouseEvent.consume();
}
}
}
}
});
});
setOnMouseClicked(mouseEvent -> {
setOnMouseClicked(mouseEvent -> {
if(action != null)
if(action != null)
{
{
if(mouseEvent.getButton().equals(MouseButton.PRIMARY))
if(mouseEvent.getButton().equals(MouseButton.PRIMARY))
{
{
if(mouseEvent.getClickCount() == 2 && action.getActionType() == ActionType.FOLDER)
if(mouseEvent.getClickCount() == 2 && action.getActionType() == ActionType.FOLDER)
{
{
getActionDetailsPaneListener().onOpenFolderButtonClicked();
getActionDetailsPaneListener().onOpenFolderButtonClicked();
}
}
else
else
{
{
try
try
{
{
actionDetailsPaneListener.onActionClicked(action, this);
actionDetailsPaneListener.onActionClicked(action, this);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
e.printStackTrace();
e.printStackTrace();
}
}
}
}
}
}
else if(mouseEvent.getButton().equals(MouseButton.SECONDARY))
else if(mouseEvent.getButton().equals(MouseButton.SECONDARY))
{
{
if(action.getActionType() == ActionType.TOGGLE)
if(action.getActionType() == ActionType.TOGGLE)
{
{
toggleStateContextMenu.show(this, mouseEvent.getScreenX(),
toggleStateContextMenu.show(this, mouseEvent.getScreenX(),
mouseEvent.getScreenY());
mouseEvent.getScreenY());
}
}
}
}
}
}
});
});
toggleStateContextMenu = new ContextMenu();
toggleStateContextMenu = new ContextMenu();
MenuItem showToggleOffMenuItem = new MenuItem("Show Toggle OFF");
MenuItem showToggleOffMenuItem = new MenuItem("Show Toggle OFF");
showToggleOffMenuItem.setOnAction(event-> fakeToggle(false));
showToggleOffMenuItem.setOnAction(event-> fakeToggle(false));
MenuItem showToggleOnMenuItem = new MenuItem("Show Toggle ON");
MenuItem showToggleOnMenuItem = new MenuItem("Show Toggle ON");
showToggleOnMenuItem.setOnAction(event-> fakeToggle(true));
showToggleOnMenuItem.setOnAction(event-> fakeToggle(true));
toggleStateContextMenu.getItems().addAll(showToggleOffMenuItem, showToggleOnMenuItem);
toggleStateContextMenu.getItems().addAll(showToggleOffMenuItem, showToggleOnMenuItem);
setCache(true);
setCache(true);
setCacheHint(CacheHint.QUALITY);
setCacheHint(CacheHint.QUALITY);
}
}
ContextMenu toggleStateContextMenu;
ContextMenu toggleStateContextMenu;
public void setInvalid(boolean invalid)
public void setInvalid(boolean invalid)
{
{
if(invalid)
if(invalid)
{
{
getStyleClass().remove("action_box_valid");
getStyleClass().remove("action_box_valid");
getStyleClass().add("action_box_invalid");
getStyleClass().add("action_box_invalid");
}
}
else
else
{
{
getStyleClass().remove("action_box_invalid");
getStyleClass().remove("action_box_invalid");
getStyleClass().add("action_box_valid");
getStyleClass().add("action_box_valid");
}
}
}
}
public ActionDetailsPaneListener getActionDetailsPaneListener() {
public ActionDetailsPaneListener getActionDetailsPaneListener() {
return actionDetailsPaneListener;
return actionDetailsPaneListener;
}
}
public ActionGridPaneListener getActionGridPaneListener() {
public ActionGridPaneListener getActionGridPaneListener() {
return actionGridPaneListener;
return actionGridPaneListener;
}
}
private int size;
private int size;
private ActionGridPaneListener actionGridPaneListener;
private ActionGridPaneListener actionGridPaneListener;
public ActionBox(int size, ActionDetailsPaneListener actionDetailsPaneListener, ActionGridPaneListener actionGridPaneListener,
public ActionBox(int size, ActionDetailsPaneListener actionDetailsPaneListener, ActionGridPaneListener actionGridPaneListener,
int col, int row)
int col, int row)
{
{
this.actionGridPaneListener = actionGridPaneListener;
this.actionGridPaneListener = actionGridPaneListener;
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.size = size;
this.size = size;
this.col = col;
this.col = col;
this.row = row;
this.row = row;
baseInit();
baseInit();
}
}
public static Action deserialize(ByteBuffer buffer) {
public static Action deserialize(ByteBuffer buffer) {
try {
try {
ByteArrayInputStream is = new ByteArrayInputStream(buffer.array());
ByteArrayInputStream is = new ByteArrayInputStream(buffer.array());
ObjectInputStream ois = new ObjectInputStream(is);
ObjectInputStream ois = new ObjectInputStream(is);
Action obj = (Action) ois.readObject();
Action obj = (Action) ois.readObject();
return obj;
return obj;
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
throw new RuntimeException(e);
throw new RuntimeException(e);
}
}
}
}
public void setIcon(byte[] iconByteArray)
public void setIcon(byte[] iconByteArray)
{
{
removeFontIcon();
removeFontIcon();
if(iconByteArray == null)
if(iconByteArray == null)
{
{
getStyleClass().remove("action_box_icon_present");
getStyleClass().remove("action_box_icon_present");
getStyleClass().add("action_box_icon_not_present");
getStyleClass().add("action_box_icon_not_present");
setBackground(null);
setBackground(null);
}
}
else
else
{
{
getStyleClass().add("action_box_icon_present");
getStyleClass().add("action_box_icon_present");
getStyleClass().remove("action_box_icon_not_present");
getStyleClass().remove("action_box_icon_not_present");
setBackground(
setBackground(
new Background(
new Background(
new BackgroundImage(new Image(
new BackgroundImage(new Image(
new ByteArrayInputStream(iconByteArray), size, size, false, true
new ByteArrayInputStream(iconByteArray), size, size, false, true
), BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER,
), BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER,
new BackgroundSize(100, 100, true, true, true, false))
new BackgroundSize(100, 100, true, true, true, false))
)
)
);
);
}
}
}
}
public void setDefaultToggleIcon(boolean isToggleOn)
public void setDefaultToggleIcon(boolean isToggleOn)
{
{
String styleClass;
String styleClass;
if(isToggleOn)
if(isToggleOn)
{
{
styleClass = "action_box_toggle_on";
styleClass = "action_box_toggle_on";
}
}
else
else
{
{
styleClass = "action_box_toggle_off";
styleClass = "action_box_toggle_off";
}
}
setBackground(null);
setBackground(null);
removeFontIcon();
removeFontIcon();
fontIcon = new FontIcon();
fontIcon = new FontIcon();
fontIcon.getStyleClass().add(styleClass);
fontIcon.getStyleClass().add(styleClass);
fontIcon.setIconSize((int) (size * 0.8));
fontIcon.setIconSize((int) (size * 0.8));
getChildren().add(fontIcon);
getChildren().add(fontIcon);
fontIcon.toBack();
fontIcon.toBack();
}
}
public void removeFontIcon()
public void removeFontIcon()
{
{
if(fontIcon!=null)
if(fontIcon!=null)
{
{
getChildren().remove(fontIcon);
getChildren().remove(fontIcon);
fontIcon = null;
fontIcon = null;
}
}
}
}
FontIcon fontIcon = null;
FontIcon fontIcon = null;
private Action action = null;
private Action action = null;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
public ActionBox(int size, Action action, ActionDetailsPaneListener actionDetailsPaneListener, ExceptionAndAlertHandler exceptionAndAlertHandler, ActionGridPaneListener actionGridPaneListener,
public ActionBox(int size, Action action, ActionDetailsPaneListener actionDetailsPaneListener, ExceptionAndAlertHandler exceptionAndAlertHandler, ActionGridPaneListener actionGridPaneListener,
int col, int row)
int col, int row)
{
{
this.actionGridPaneListener = actionGridPaneListener;
this.actionGridPaneListener = actionGridPaneListener;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.action = action;
this.action = action;
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.size = size;
this.size = size;
this.col = col;
this.col = col;
this.row = row;
this.row = row;
baseInit();
baseInit();
init();
init();
}
}
public Action getAction() {
public Action getAction() {
return action;
return action;
}
}
public void setAction(Action action)
public void setAction(Action action)
{
{
this.action = action;
this.action = action;
}
}
public void init()
public void init()
{
{
if(action.isShowDisplayText())
if(action.isShowDisplayText())
setDisplayTextLabel(action.getDisplayText());
setDisplayTextLabel(action.getDisplayText());
else
else
setDisplayTextLabel("");
setDisplayTextLabel("");
setDisplayTextAlignment(action.getDisplayTextAlignment());
setDisplayTextAlignment(action.getDisplayTextAlignment());
setBackgroundColour(action.getBgColourHex());
setBackgroundColour(action.getBgColourHex());
setDisplayTextFontColour(action.getDisplayTextFontColourHex());
setDisplayTextFontColour(action.getDisplayTextFontColourHex());
setInvalid(action.isInvalid());
setInvalid(action.isInvalid());
Platform.runLater(()->{
Platform.runLater(()->{
try {
try {
if(action.getActionType() == ActionType.TOGGLE)
if(action.getActionType() == ActionType.TOGGLE)
{
{
fakeToggle(false);
fakeToggle(false);
}
}
else
else
{
{
if(action.isHasIcon())
if(action.isHasIcon())
{
{
if(!action.getCurrentIconState().isBlank())
if(!action.getCurrentIconState().isBlank())
{
{
setIcon(action.getCurrentIcon());
setIcon(action.getCurrentIcon());
}
}
}
}
else
else
{
{
setIcon(null);
setIcon(null);
}
}
}
}
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
});
});
}
}
private void fakeToggle(boolean isON)
private void fakeToggle(boolean isON)
{
{
System.out.println("CURRENT ICONS : "+action.getCurrentIconState());
System.out.println("CURRENT ICONS : "+action.getCurrentIconState());
String[] toggleStatesHiddenStatus = action.getCurrentIconState().split("__");
String[] toggleStatesHiddenStatus = action.getCurrentIconState().split("__");
boolean isToggleOffHidden = toggleStatesHiddenStatus[0].equals("true");
boolean isToggleOffHidden = toggleStatesHiddenStatus[0].equals("true");
boolean isToggleOnHidden = toggleStatesHiddenStatus[1].equals("true");
boolean isToggleOnHidden = toggleStatesHiddenStatus[1].equals("true");
if(isON) // ON
if(isON) // ON
{
{
if(action.isHasIcon())
if(action.isHasIcon())
{
{
boolean isToggleOnPresent = action.getIcons().containsKey("toggle_on");
boolean isToggleOnPresent = action.getIcons().containsKey("toggle_on");
if(isToggleOnPresent)
if(isToggleOnPresent)
{
{
if(isToggleOnHidden)
if(isToggleOnHidden)
{
{
setDefaultToggleIcon(true);
setDefaultToggleIcon(true);
}
}
else
else
{
{
setIcon(action.getIcons().get("toggle_on"));
setIcon(action.getIcons().get("toggle_on"));
}
}
}
}
else
else
{
{
setDefaultToggleIcon(true);
setDefaultToggleIcon(true);
}
}
}
}
else
else
{
{
setDefaultToggleIcon(true);
setDefaultToggleIcon(true);
}
}
}
}
else // OFF
else // OFF
{
{
if(action.isHasIcon())
if(action.isHasIcon())
{
{
boolean isToggleOffPresent = action.getIcons().containsKey("toggle_off");
boolean isToggleOffPresent = action.getIcons().containsKey("toggle_off");
if(isToggleOffPresent)
if(isToggleOffPresent)
{
{
if(isToggleOffHidden)
if(isToggleOffHidden)
{
{
setDefaultToggleIcon(false);
setDefaultToggleIcon(false);
}
}
else
else
{
{
setIcon(action.getIcons().get("toggle_off"));
setIcon(action.getIcons().get("toggle_off"));
}
}
}
}
else
else
{
{
setDefaultToggleIcon(false);
setDefaultToggleIcon(false);
}
}
}
}
else
else
{
{
setDefaultToggleIcon(false);
setDefaultToggleIcon(false);
}
}
}
}
}
}
public void setDisplayTextLabel(String text)
public void setDisplayTextLabel(String text)
{
{
displayTextLabel.setText(text);
displayTextLabel.setText(text);
}
}
public void setDisplayTextAlignment(DisplayTextAlignment displayTextAlignment)
public void setDisplayTextAlignment(DisplayTextAlignment displayTextAlignment)
{
{
if(displayTextAlignment == DisplayTextAlignment.CENTER)
if(displayTextAlignment == DisplayTextAlignment.CENTER)
displayTextLabel.setAlignment(Pos.CENTER);
displayTextLabel.setAlignment(Pos.CENTER);
else if (displayTextAlignment == DisplayTextAlignment.BOTTOM)
else if (displayTextAlignment == DisplayTextAlignment.BOTTOM)
displayTextLabel.setAlignment(Pos.BOTTOM_CENTER);
displayTextLabel.setAlignment(Pos.BOTTOM_CENTER);
else if (displayTextAlignment == DisplayTextAlignment.TOP)
else if (displayTextAlignment == DisplayTextAlignment.TOP)
displayTextLabel.setAlignment(Pos.TOP_CENTER);
displayTextLabel.setAlignment(Pos.TOP_CENTER);
}
}
public void setDisplayTextFontColour(String colour)
public void setDisplayTextFontColour(String colour)
{
{
System.out.println("COLOr : "+colour);
System.out.println("COLOr : "+colour);
if(!colour.isEmpty())
if(!colour.isEmpty())
displayTextLabel.setStyle("-fx-text-fill : "+colour+";");
displayTextLabel.setStyle("-fx-text-fill : "+colour+";");
}
}
public void setBackgroundColour(String colour)
public void setBackgroundColour(String colour)
{
{
System.out.println("COLOr : "+colour);
System.out.println("COLOr : "+colour);
if(!colour.isEmpty())
if(!colour.isEmpty())
setStyle("-fx-background-color : "+colour);
setStyle("-fx-background-color : "+colour);
}
}
}
}
package com.stream_pi.server.window.dashboard.actiongridpane;
package com.stream_pi.server.window.dashboard.actiongridpane;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.otheractions.CombineAction;
import com.stream_pi.action_api.otheractions.CombineAction;
import com.stream_pi.action_api.otheractions.FolderAction;
import com.stream_pi.action_api.otheractions.FolderAction;
import com.stream_pi.server.action.ExternalPlugins;
import com.stream_pi.server.action.ExternalPlugins;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPaneListener;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPaneListener;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.CacheHint;
import javafx.scene.CacheHint;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.*;
import javafx.scene.layout.*;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class ActionGridPane extends ScrollPane implements ActionGridPaneListener {
public class ActionGridPane extends ScrollPane implements ActionGridPaneListener {
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ActionDetailsPaneListener actionDetailsPaneListener;
private ActionDetailsPaneListener actionDetailsPaneListener;
public ActionGridPane(ExceptionAndAlertHandler exceptionAndAlertHandler)
public ActionGridPane(ExceptionAndAlertHandler exceptionAndAlertHandler)
{
{
logger = Logger.getLogger(ActionGridPane.class.getName());
logger = Logger.getLogger(ActionGridPane.class.getName());
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
getStyleClass().add("action_grid_pane_parent");
getStyleClass().add("action_grid_pane_parent");
actionsGridPane = new GridPane();
actionsGridPane = new GridPane();
actionsGridPane.setPadding(new Insets(5.0));
actionsGridPane.setPadding(new Insets(5.0));
actionsGridPane.getStyleClass().add("action_grid_pane");
actionsGridPane.getStyleClass().add("action_grid_pane");
actionsGridPane.setPrefSize(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE);
actionsGridPane.setPrefSize(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE);
setContent(actionsGridPane);
setContent(actionsGridPane);
setCache(true);
setCache(true);
setCacheHint(CacheHint.SPEED);
setCacheHint(CacheHint.SPEED);
}
}
public void setActionDetailsPaneListener(ActionDetailsPaneListener actionDetailsPaneListener) {
public void setActionDetailsPaneListener(ActionDetailsPaneListener actionDetailsPaneListener) {
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.actionDetailsPaneListener = actionDetailsPaneListener;
}
}
private String currentParent = null;
private String currentParent = null;
@Override
@Override
public ExternalPlugin createNewActionFromExternalPlugin(String moduleName) throws Exception
public ExternalPlugin createNewActionFromExternalPlugin(String moduleName) throws Exception
{
{
ExternalPlugin newAction = ExternalPlugins.getInstance().getPluginByModuleName(moduleName).clone();
ExternalPlugin newAction = ExternalPlugins.getInstance().getPluginByModuleName(moduleName).clone();
if(newAction.getActionType() == ActionType.TOGGLE)
if(newAction.getActionType() == ActionType.TOGGLE)
{
{
newAction.setCurrentIconState("false__false");
newAction.setCurrentIconState("false__false");
}
}
newAction.setIDRandom();
newAction.setIDRandom();
newAction.setShowDisplayText(true);
newAction.setShowDisplayText(true);
newAction.setDisplayText("Untitled Action");
newAction.setDisplayText("Untitled Action");
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
newAction.setBgColourHex("");
newAction.setBgColourHex("");
newAction.setDisplayTextFontColourHex("");
newAction.setDisplayTextFontColourHex("");
return newAction;
return newAction;
}
}
@Override
@Override
public Action createNewOtherAction(ActionType actionType) throws Exception
public Action createNewOtherAction(ActionType actionType) throws Exception
{
{
Action newAction;
Action newAction;
String displayText;
String displayText;
if(actionType == ActionType.FOLDER)
if(actionType == ActionType.FOLDER)
{
{
displayText = "Untitled Folder";
displayText = "Untitled Folder";
newAction = new FolderAction();
newAction = new FolderAction();
}
}
else if(actionType == ActionType.COMBINE)
else if(actionType == ActionType.COMBINE)
{
{
displayText = "Untitled Combine";
displayText = "Untitled Combine";
newAction = new CombineAction();
newAction = new CombineAction();
}
}
else
else
throw new IllegalArgumentException("External Plugins are not supported here!");
throw new IllegalArgumentException("External Plugins are not supported here!");
newAction.setIDRandom();
newAction.setIDRandom();
newAction.setShowDisplayText(true);
newAction.setShowDisplayText(true);
newAction.setDisplayText(displayText);
newAction.setDisplayText(displayText);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
newAction.setBgColourHex("");
newAction.setBgColourHex("");
newAction.setDisplayTextFontColourHex("");
newAction.setDisplayTextFontColourHex("");
return newAction;
return newAction;
}
}
@Override
@Override
public void setCurrentParent(String currentParent) {
public void setCurrentParent(String currentParent) {
this.currentParent = currentParent;
this.currentParent = currentParent;
}
}
@Override
public ClientConnection getClientConnection() {
return clientConnection;
}
public ClientProfile getClientProfile() {
public ClientProfile getClientProfile() {
return clientProfile;
return clientProfile;
}
}
private Client client;
private ClientConnection clientConnection;
public void setClient(Client client) {
this.client = client;
public void setClientConnection(ClientConnection clientConnection)
{
this.clientConnection = clientConnection;
}
}
public Client getClient() {
public Client getClient() {
return client;
return getClientConnection().getClient();
}
}
private int rows, cols;
private int rows, cols;
private GridPane actionsGridPane;
private GridPane actionsGridPane;
private ClientProfile clientProfile;
private ClientProfile clientProfile;
public void setClientProfile(ClientProfile clientProfile)
public void setClientProfile(ClientProfile clientProfile)
{
{
this.clientProfile = clientProfile;
this.clientProfile = clientProfile;
setCurrentParent("root");
setCurrentParent("root");
setRows(clientProfile.getRows());
setRows(clientProfile.getRows());
setCols(clientProfile.getCols());
setCols(clientProfile.getCols());
}
}
@Override
@Override
public String getCurrentParent() {
public String getCurrentParent() {
return currentParent;
return currentParent;
}
}
@Override
@Override
public ClientProfile getCurrentProfile() {
public ClientProfile getCurrentProfile() {
return clientProfile;
return clientProfile;
}
}
public StackPane getFolderBackButton() throws SevereException
public StackPane getFolderBackButton() throws SevereException
{
{
StackPane stackPane = new StackPane();
StackPane stackPane = new StackPane();
stackPane.getStyleClass().add("action_box");
stackPane.getStyleClass().add("action_box");
stackPane.getStyleClass().add("action_box_valid");
stackPane.getStyleClass().add("action_box_valid");
stackPane.setPrefSize(
stackPane.setPrefSize(
Config.getInstance().getActionGridActionSize(),
Config.getInstance().getActionGridActionSize(),
Config.getInstance().getActionGridActionSize()
Config.getInstance().getActionGridActionSize()
);
);
FontIcon fontIcon = new FontIcon("fas-chevron-left");
FontIcon fontIcon = new FontIcon("fas-chevron-left");
fontIcon.getStyleClass().add("folder_action_back_button_icon");
fontIcon.getStyleClass().add("folder_action_back_button_icon");
fontIcon.setIconSize((int) (Config.getInstance().getActionGridActionSize() * 0.8));
fontIcon.setIconSize((int) (Config.getInstance().getActionGridActionSize() * 0.8));
stackPane.setAlignment(Pos.CENTER);
stackPane.setAlignment(Pos.CENTER);
stackPane.getChildren().add(fontIcon);
stackPane.getChildren().add(fontIcon);
stackPane.setOnMouseClicked(e->returnToPreviousParent());
stackPane.setOnMouseClicked(e->returnToPreviousParent());
return stackPane;
return stackPane;
}
}
private ActionBox[][] actionBoxes;
private ActionBox[][] actionBoxes;
private boolean isFreshRender = true;
private boolean isFreshRender = true;
private Node folderBackButton = null;
private Node folderBackButton = null;
public void renderGrid() throws SevereException
public void renderGrid() throws SevereException
{
{
actionsGridPane.setHgap(Config.getInstance().getActionGridActionGap());
actionsGridPane.setHgap(Config.getInstance().getActionGridActionGap());
actionsGridPane.setVgap(Config.getInstance().getActionGridActionGap());
actionsGridPane.setVgap(Config.getInstance().getActionGridActionGap());
if(isFreshRender)
if(isFreshRender)
{
{
clear();
clear();
actionBoxes = new ActionBox[cols][rows];
actionBoxes = new ActionBox[cols][rows];
}
}
boolean isFolder = false;
boolean isFolder = false;
if(getCurrentParent().equals("root"))
if(getCurrentParent().equals("root"))
{
{
if(folderBackButton != null)
if(folderBackButton != null)
{
{
actionsGridPane.getChildren().remove(folderBackButton);
actionsGridPane.getChildren().remove(folderBackButton);
folderBackButton = null;
folderBackButton = null;
actionBoxes[0][0] = addBlankActionBox(0,0);
actionBoxes[0][0] = addBlankActionBox(0,0);
}
}
}
}
else
else
{
{
isFolder = true;
isFolder = true;
if(folderBackButton != null)
if(folderBackButton != null)
{
{
actionsGridPane.getChildren().remove(folderBackButton);
actionsGridPane.getChildren().remove(folderBackButton);
folderBackButton = null;
folderBackButton = null;
}
}
else
else
{
{
actionsGridPane.getChildren().remove(actionBoxes[0][0]);
actionsGridPane.getChildren().remove(actionBoxes[0][0]);
}
}
folderBackButton = getFolderBackButton();
folderBackButton = getFolderBackButton();
actionsGridPane.add(folderBackButton, 0,0);
actionsGridPane.add(folderBackButton, 0,0);
}
}
for(int row = 0; row<rows; row++)
for(int row = 0; row<rows; row++)
{
{
for(int col = 0; col<cols; col++)
for(int col = 0; col<cols; col++)
{
{
if(row == 0 && col == 0 && isFolder)
if(row == 0 && col == 0 && isFolder)
continue;
continue;
if(isFreshRender)
if(isFreshRender)
{
{
actionBoxes[col][row] = addBlankActionBox(col, row);
actionBoxes[col][row] = addBlankActionBox(col, row);
}
}
else
else
{
{
if(actionBoxes[col][row].getAction() != null)
if(actionBoxes[col][row].getAction() != null)
{
{
actionBoxes[col][row].clear();
actionBoxes[col][row].clear();
}
}
}
}
}
}
}
}
isFreshRender = false;
isFreshRender = false;
}
}
public void setFreshRender(boolean freshRender)
public void setFreshRender(boolean freshRender)
{
{
isFreshRender = freshRender;
isFreshRender = freshRender;
}
}
public ActionBox addBlankActionBox(int col, int row) throws SevereException {
public ActionBox addBlankActionBox(int col, int row) throws SevereException {
ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), actionDetailsPaneListener, this,
ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), actionDetailsPaneListener, this,
col, row);
col, row);
actionsGridPane.add(actionBox, row, col);
actionsGridPane.add(actionBox, row, col);
return actionBox;
return actionBox;
}
}
public void renderActions()
public void renderActions()
{
{
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
for(String action1x : getClientProfile().getActionsKeySet())
for(String action1x : getClientProfile().getActionsKeySet())
{
{
Action eachAction = getClientProfile().getActionByID(action1x);
Action eachAction = getClientProfile().getActionByID(action1x);
logger.info("action ID : "+eachAction.getID()+
logger.info("action ID : "+eachAction.getID()+
"\nInvalid : "+eachAction.isInvalid());
"\nInvalid : "+eachAction.isInvalid());
try {
try {
renderAction(eachAction);
renderAction(eachAction);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
errors.append("*").append(e.getShortMessage()).append("\n");
errors.append("*").append(e.getShortMessage()).append("\n");
}
}
}
}
if(!errors.toString().isEmpty())
if(!errors.toString().isEmpty())
{
{
exceptionAndAlertHandler.handleMinorException(new MinorException("Error while rendering following actions", errors.toString()));
exceptionAndAlertHandler.handleMinorException(new MinorException("Error while rendering following actions", errors.toString()));
}
}
}
}
public void clear()
public void clear()
{
{
actionsGridPane.getChildren().clear();
actionsGridPane.getChildren().clear();
}
}
private Logger logger;
private Logger logger;
public void renderAction(Action action) throws SevereException, MinorException
public void renderAction(Action action) throws SevereException, MinorException
{
{
if(!action.getParent().equals(currentParent))
if(!action.getParent().equals(currentParent))
{
{
logger.info("Skipping action "+action.getID()+", not current parent!");
logger.info("Skipping action "+action.getID()+", not current parent!");
return;
return;
}
}
if(action.getLocation().getRow()==-1)
if(action.getLocation().getRow()==-1)
{
{
logger.info("action has -1 rowIndex. Probably Combine action. Skipping ...");
logger.info("action has -1 rowIndex. Probably Combine action. Skipping ...");
return;
return;
}
}
if(action.getLocation().getRow() >= rows || action.getLocation().getCol() >= cols)
if(action.getLocation().getRow() >= rows || action.getLocation().getCol() >= cols)
{
{
throw new MinorException("action "+action.getDisplayText()+" ("+action.getID()+") falls outside bounds.\n" +
throw new MinorException("action "+action.getDisplayText()+" ("+action.getID()+") falls outside bounds.\n" +
" Consider increasing rows/cols from client settings and relocating/deleting it.");
" Consider increasing rows/cols from client settings and relocating/deleting it.");
}
}
Location location = action.getLocation();
Location location = action.getLocation();
ActionBox actionBox = actionBoxes[location.getCol()][location.getRow()];
ActionBox actionBox = actionBoxes[location.getCol()][location.getRow()];
actionBox.clear();
actionBox.clear();
actionBox.setAction(action);
actionBox.setAction(action);
actionBox.init();
actionBox.init();
/*ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), action, actionDetailsPaneListener, exceptionAndAlertHandler, this);
/*ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), action, actionDetailsPaneListener, exceptionAndAlertHandler, this);
Location location = action.getLocation();
Location location = action.getLocation();
actionBox.setStreamPiParent(currentParent);
actionBox.setStreamPiParent(currentParent);
actionBox.setRow(location.getRow());
actionBox.setRow(location.getRow());
actionBox.setCol(location.getCol());
actionBox.setCol(location.getCol());
for(Node node : actionsGridPane.getChildren())
for(Node node : actionsGridPane.getChildren())
{
{
if(GridPane.getColumnIndex(node) == location.getRow() &&
if(GridPane.getColumnIndex(node) == location.getRow() &&
GridPane.getRowIndex(node) == location.getCol())
GridPane.getRowIndex(node) == location.getCol())
{
{
actionsGridPane.getChildren().remove(node);
actionsGridPane.getChildren().remove(node);
break;
break;
}
}
}
}
System.out.println(location.getCol()+","+location.getRow());
System.out.println(location.getCol()+","+location.getRow());
actionsGridPane.add(actionBox, location.getRow(), location.getCol());*/
actionsGridPane.add(actionBox, location.getRow(), location.getCol());*/
}
}
public void setRows(int rows)
public void setRows(int rows)
{
{
this.rows = rows;
this.rows = rows;
}
}
public void setCols(int cols)
public void setCols(int cols)
{
{
this.cols = cols;
this.cols = cols;
}
}
public int getRows()
public int getRows()
{
{
return rows;
return rows;
}
}
public int getCols()
public int getCols()
{
{
return cols;
return cols;
}
}
@Override
@Override
public void addActionToCurrentClientProfile(Action newAction) {
public void addActionToCurrentClientProfile(Action newAction) {
try {
try {
getClientProfile().addAction(newAction);
getClientProfile().addAction(newAction);
} catch (CloneNotSupportedException e) {
} catch (CloneNotSupportedException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
private String previousParent;
private String previousParent;
public void setPreviousParent(String previousParent) {
public void setPreviousParent(String previousParent) {
this.previousParent = previousParent;
this.previousParent = previousParent;
}
}
public String getPreviousParent() {
public String getPreviousParent() {
return previousParent;
return previousParent;
}
}
@Override
@Override
public void renderFolder(FolderAction action) {
public void renderFolder(FolderAction action) {
setCurrentParent(action.getID());
setCurrentParent(action.getID());
setPreviousParent(action.getParent());
setPreviousParent(action.getParent());
try {
try {
renderGrid();
renderGrid();
renderActions();
renderActions();
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
public void returnToPreviousParent()
public void returnToPreviousParent()
{
{
setCurrentParent(getPreviousParent());
setCurrentParent(getPreviousParent());
if(!getPreviousParent().equals("root"))
if(!getPreviousParent().equals("root"))
{
{
System.out.println("parent : "+getPreviousParent());
System.out.println("parent : "+getPreviousParent());
setPreviousParent(getClientProfile().getActionByID(
setPreviousParent(getClientProfile().getActionByID(
getPreviousParent()
getPreviousParent()
).getParent());
).getParent());
}
}
try {
try {
renderGrid();
renderGrid();
renderActions();
renderActions();
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
}
}
package com.stream_pi.server.window.dashboard.actiongridpane;
package com.stream_pi.server.window.dashboard.actiongridpane;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.otheractions.FolderAction;
import com.stream_pi.action_api.otheractions.FolderAction;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.connection.ClientConnection;
public interface ActionGridPaneListener
public interface ActionGridPaneListener
{
{
void addActionToCurrentClientProfile(Action newAction);
void addActionToCurrentClientProfile(Action newAction);
void renderFolder(FolderAction action);
void renderFolder(FolderAction action);
String getCurrentParent();
String getCurrentParent();
ClientProfile getCurrentProfile();
ClientProfile getCurrentProfile();
void setCurrentParent(String currentParent);
void setCurrentParent(String currentParent);
ClientConnection getClientConnection();
ExternalPlugin createNewActionFromExternalPlugin(String module) throws Exception;
ExternalPlugin createNewActionFromExternalPlugin(String module) throws Exception;
Action createNewOtherAction(ActionType actionType) throws Exception;
Action createNewOtherAction(ActionType actionType) throws Exception;
}
}