From 36730cdc1cf4fac1e47836af3901573e92414e20 Mon Sep 17 00:00:00 2001 From: Mara Date: Fri, 10 May 2024 13:06:48 +0800 Subject: [PATCH] a6.8.1 --- .../ExpressionCalculator.java | 16 +- .../controller/BaseController_Attributes.java | 2 - .../controller/BaseController_Interface.java | 198 ++++++++---------- .../BaseData2DSourceRowsController.java | 12 +- .../controller/BaseData2DTableController.java | 1 - .../controller/BaseTableViewController.java | 16 ++ .../ControlData2DRowExpression.java | 2 +- .../controller/ControlData2DRowFilter.java | 6 +- .../controller/ControlSynchronizeOptions.java | 16 +- .../Data2DRowExpressionController.java | 12 +- .../controller/Data2DSetValuesController.java | 17 +- .../controller/MathFunctionController.java | 31 +-- .../MathFunctionDataController.java | 21 +- .../mybox/controller/MathFunctionEditor.java | 40 ++-- .../RemotePathHandleFilesController.java | 17 +- .../java/mara/mybox/data2d/Data2D_Edit.java | 5 +- .../java/mara/mybox/data2d/Data2D_Filter.java | 2 +- .../mara/mybox/data2d/Data2D_Operations.java | 2 +- .../java/mara/mybox/data2d/DataFilter.java | 4 +- .../java/mara/mybox/data2d/DataMatrix.java | 2 +- .../main/java/mara/mybox/data2d/TmpTable.java | 2 +- .../mybox/data2d/modify/Data2DSetValue.java | 14 +- .../mybox/data2d/operate/Data2DOperate.java | 7 +- .../data2d/operate/Data2DRowExpression.java | 15 +- .../resources/bundles/Messages_en.properties | 3 +- .../bundles/Messages_zh_CN.properties | 3 +- .../data/examples/JavaScript_Examples_en.txt | 24 ++- .../data/examples/JavaScript_Examples_zh.txt | 26 ++- .../data/examples/RowFilter_Examples_zh.txt | 132 +++++++++--- .../MyBox/src/main/resources/doc/en/README.md | 5 +- .../MyBox/src/main/resources/doc/zh/README.md | 5 +- .../fxml/ControlData2DRowExpression.fxml | 4 +- .../fxml/ControlData2DRowFilter.fxml | 25 +-- .../resources/fxml/ControlData2DSetValue.fxml | 1 - .../resources/fxml/MathFunctionXYChart.fxml | 12 +- .../main/resources/fxml/RowFilterEditor.fxml | 2 +- 36 files changed, 421 insertions(+), 281 deletions(-) rename alpha/MyBox/src/main/java/mara/mybox/{fxml => calculation}/ExpressionCalculator.java (94%) diff --git a/alpha/MyBox/src/main/java/mara/mybox/fxml/ExpressionCalculator.java b/alpha/MyBox/src/main/java/mara/mybox/calculation/ExpressionCalculator.java similarity index 94% rename from alpha/MyBox/src/main/java/mara/mybox/fxml/ExpressionCalculator.java rename to alpha/MyBox/src/main/java/mara/mybox/calculation/ExpressionCalculator.java index 22eed2590..571c0760e 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/fxml/ExpressionCalculator.java +++ b/alpha/MyBox/src/main/java/mara/mybox/calculation/ExpressionCalculator.java @@ -1,4 +1,4 @@ -package mara.mybox.fxml; +package mara.mybox.calculation; import java.util.ArrayList; import java.util.HashMap; @@ -76,9 +76,14 @@ private boolean executeScript() { } } - public String calculate(String script) { + public String calculate(String script, Map variables) { reset(); this.expression = script; + if (variables != null) { + for (String v : variables.keySet()) { + variableValues.put(v, variables.get(v)); + } + } if (executeScript()) { return result; } else { @@ -86,8 +91,8 @@ public String calculate(String script) { } } - public boolean condition(String script) { - calculate(script); + public boolean condition(String script, Map variables) { + calculate(script, variables); return "true".equals(result); } @@ -210,7 +215,8 @@ public boolean validateExpression(Data2D data2D, String script, boolean allPages } List row = new ArrayList<>(); for (int i = 0; i < data2D.columnsNumber(); i++) { - row.add("0"); + Data2DColumn column = data2D.columns.get(i); + row.add(column.makeDefaultValue()); } String filledScript = replaceDummyStatistic(data2D, script); if (allPages) { diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/BaseController_Attributes.java b/alpha/MyBox/src/main/java/mara/mybox/controller/BaseController_Attributes.java index 0cc305175..4b6097dd1 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/BaseController_Attributes.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/BaseController_Attributes.java @@ -123,8 +123,6 @@ public static enum SaveAsType { protected ComboBox dpiSelector; @FXML protected TabPane tabPane; - @FXML - protected CheckBox errorContinueCheck; public void setFileType() { setFileType(FileType.All); diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/BaseController_Interface.java b/alpha/MyBox/src/main/java/mara/mybox/controller/BaseController_Interface.java index 44e782014..9cca6606b 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/BaseController_Interface.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/BaseController_Interface.java @@ -46,7 +46,7 @@ * @License Apache License Version 2.0 */ public abstract class BaseController_Interface extends BaseController_Files { - + protected final int minSize = 200; protected ChangeListener leftDividerListener, rightDividerListener; @@ -61,7 +61,7 @@ public void initBaseControls() { if (thisPane != null) { thisPane.setStyle("-fx-font-size: " + AppVariables.sceneFontSize + "px;"); } - + if (mainMenuController != null) { mainMenuController.SourceFileType = getSourceFileType(); mainMenuController.sourceExtensionFilter = sourceExtensionFilter; @@ -72,7 +72,7 @@ public void initBaseControls() { mainMenuController.AddFileType = AddFileType; mainMenuController.AddPathType = AddPathType; } - + if (sourceFileInput != null) { sourceFileInput.textProperty().addListener( (ObservableValue observable, String oldValue, String newValue) -> { @@ -80,7 +80,7 @@ public void initBaseControls() { }); // sourceFileInput.setText(UserConfig.getString(interfaceName + "SourceFile", null)); } - + if (sourcePathInput != null) { sourcePathInput.textProperty().addListener(new ChangeListener() { @Override @@ -91,7 +91,7 @@ public void changed( }); sourcePathInput.setText(UserConfig.getString(interfaceName + "SourcePath", AppPaths.getGeneratedPath())); } - + if (targetPrefixInput != null) { targetPrefixInput.textProperty().addListener(new ChangeListener() { @Override @@ -103,7 +103,7 @@ public void changed(ObservableValue observable, String oldValu }); targetPrefixInput.setText(UserConfig.getString(interfaceName + "TargetPrefix", "mm")); } - + if (targetFileController != null) { targetFileController.notify.addListener(new ChangeListener() { @Override @@ -113,7 +113,7 @@ public void changed(ObservableValue observable, Boolean oldVa }); targetFileController.baseName(interfaceName).savedName(interfaceName + "TargetFile").type(TargetFileType).initFile(); } - + if (targetPathController != null) { targetPathController.notify.addListener(new ChangeListener() { @Override @@ -123,7 +123,7 @@ public void changed(ObservableValue observable, Boolean oldVa }); targetPathController.baseName(interfaceName).savedName(interfaceName + "TargetPath").type(TargetPathType).initFile(); } - + if (operationBarController != null) { operationBarController.parentController = myController; if (operationBarController.openTargetButton != null) { @@ -138,7 +138,7 @@ public void changed(ObservableValue observable, Boolean oldVa } } } - + saveAsType = BaseController.SaveAsType.Open; if (saveAsGroup != null && saveOpenRadio != null) { String v = UserConfig.getString(interfaceName + "SaveAsType", BaseController.SaveAsType.Open.name()); @@ -189,7 +189,7 @@ public void changed(ObservableValue ov, Toggle oldValue, Toggle newValue) { } }); } - + dpi = UserConfig.getInt(interfaceName + "DPI", 96); if (dpiSelector != null) { List dpiValues = new ArrayList(); @@ -211,27 +211,13 @@ public void changed(ObservableValue ov, Toggle oldValue, Toggle newValue) { checkDPI(); }); } - + if (openSourceButton != null) { openSourceButton.setDisable(true); } - - if (errorContinueCheck != null) { - errorContinueCheck.setSelected(false); - errorContinueCheck.selectedProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue ov, Boolean oldValue, Boolean newValue) { - if (errorContinueCheck.isSelected()) { - errorContinueCheck.setStyle(NodeStyleTools.darkRedTextStyle()); - } else { - errorContinueCheck.setStyle(null); - } - } - }); - } - + initMainArea(); - + if (onTopCheck != null) { onTopCheck.selectedProperty().addListener(new ChangeListener() { @Override @@ -252,7 +238,7 @@ public void changed(ObservableValue v, Boolean ov, Boolean nv } }); } - + if (tipsView != null) { tipsView.setPickOnBounds(true); tipsView.setOnMouseClicked(new EventHandler() { @@ -262,7 +248,7 @@ public void handle(MouseEvent event) { } }); } - + if (rightTipsView != null) { rightTipsView.setPickOnBounds(true); rightTipsView.setOnMouseClicked(new EventHandler() { @@ -272,19 +258,19 @@ public void handle(MouseEvent event) { } }); } - + initLeftPaneControl(); initRightPaneControl(); - + initNodes(thisPane); initSplitPanes(); setControlsStyle(); - + } catch (Exception e) { MyBoxLog.error(e); } } - + public void initMainArea() { if (toolbar == null || toolbarCheck == null || mainAreaBox == null) { return; @@ -299,7 +285,7 @@ public void changed(ObservableValue ov, Boolean oldValue, Boolean newValue) { }); checkToolbar(); } - + public void checkToolbar() { if (toolbar == null || toolbarCheck == null || mainAreaBox == null) { return; @@ -315,7 +301,7 @@ public void checkToolbar() { } refreshStyle(mainAreaBox); } - + public void initLeftPaneControl() { if (splitPane != null && leftPane != null && leftPaneControl != null) { leftPaneControl.setOnMouseClicked(new EventHandler() { @@ -329,7 +315,7 @@ public void handle(MouseEvent event) { leftPane.setVvalue(0); } } - + public void initRightPaneControl() { if (splitPane != null && rightPane != null && rightPaneControl != null) { rightPaneControl.setOnMouseClicked(new EventHandler() { @@ -343,7 +329,7 @@ public void handle(MouseEvent event) { rightPane.setVvalue(0); } } - + private void initNodes(Node node) { if (node == null) { return; @@ -379,11 +365,11 @@ private void initNodes(Node node) { } } } - + public void makeEditContextMenu(Node node) { makeEditContextMenu(node, node); } - + public void makeEditContextMenu(Node node, Node textInput) { try { textInput.setOnContextMenuRequested(new EventHandler() { @@ -396,7 +382,7 @@ public void handle(ContextMenuEvent event) { MyBoxLog.error(e); } } - + public void checkDPI() { try { int v = Integer.parseInt(dpiSelector.getValue()); @@ -411,9 +397,9 @@ public void checkDPI() { dpiSelector.getEditor().setStyle(UserConfig.badStyle()); } } - + public void initControls() { - + } /* @@ -425,18 +411,18 @@ public void afterSceneLoaded() { try { getMyScene(); getMyStage(); - + myStage.setMinWidth(minSize); myStage.setMinHeight(20); - + refreshStyle(); - + if (this instanceof LoadingController) { return; } - + setStageStatus(); - + Rectangle2D screen = NodeTools.getScreen(); if (myStage.getHeight() > screen.getHeight()) { myStage.setHeight(screen.getHeight()); @@ -450,9 +436,9 @@ public void afterSceneLoaded() { if (myStage.getY() < 0) { myStage.setY(0); } - + toFront(); - + if (leftPane != null || rightPane != null) { new Timer().schedule(new TimerTask() { @Override @@ -462,7 +448,7 @@ public void run() { leftPane.setHvalue(0); leftPane.setVvalue(0); } - + if (rightPane != null) { rightPane.setHvalue(0); rightPane.setVvalue(0); @@ -472,32 +458,32 @@ public void run() { } }, 1000); } - + if (onTopCheck != null) { isSettingValues = true; onTopCheck.setSelected(myStage.isAlwaysOnTop()); isSettingValues = false; } - + } catch (Exception e) { MyBoxLog.error(e); } } - + public String interfaceKeysPrefix() { return "Interface_" + interfaceName; } - + public void setStageStatus() { try { if (AppVariables.recordWindowsSizeLocation) { String prefix = interfaceKeysPrefix(); if (UserConfig.getBoolean(prefix + "FullScreen", false)) { myStage.setFullScreen(true); - + } else if (UserConfig.getBoolean(prefix + "Maximized", false)) { NodeTools.setMaximized(myStage, true); - + } else { int mw = UserConfig.getInt(prefix + "StageWidth", -1); int mh = UserConfig.getInt(prefix + "StageHeight", -1); @@ -512,7 +498,7 @@ public void setStageStatus() { myStage.setY(my); } } - + myStage.fullScreenProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue ov, Boolean old_val, Boolean new_val) { @@ -525,7 +511,7 @@ public void changed(ObservableValue ov, Boolean old_val, Bool UserConfig.setBoolean(prefix + "Maximized", myStage.isMaximized()); } }); - + } else { myStage.sizeToScene(); myStage.centerOnScreen(); @@ -534,7 +520,7 @@ public void changed(ObservableValue ov, Boolean old_val, Bool MyBoxLog.error(e); } } - + public void setMinWidth(int minWidth) { try { if (getMyStage() == null) { @@ -548,7 +534,7 @@ public void setMinWidth(int minWidth) { MyBoxLog.error(e); } } - + public void setInterfaceStyle(Scene scene, String style) { try { if (scene != null && style != null) { @@ -559,7 +545,7 @@ public void setInterfaceStyle(Scene scene, String style) { // MyBoxLog.error(e); } } - + public void setInterfaceStyle(String style) { try { if (thisPane != null && style != null) { @@ -573,7 +559,7 @@ public void setInterfaceStyle(String style) { // MyBoxLog.error(e); } } - + public void refreshStyle() { if (getMyScene() != null) { refreshStyle(myScene.getRoot()); @@ -581,7 +567,7 @@ public void refreshStyle() { refreshStyle(thisPane); } } - + public void refreshStyle(Parent node) { try { NodeStyleTools.refreshStyle(node); @@ -590,7 +576,7 @@ public void refreshStyle(Parent node) { MyBoxLog.error(e); } } - + public void toFront() { try { new Timer().schedule(new TimerTask() { @@ -608,7 +594,7 @@ public void run() { MyBoxLog.error(e); } } - + public void setAlwaysTop(boolean onTop, boolean info) { try { myStage = getMyStage(); @@ -628,7 +614,7 @@ public void setAlwaysTop(boolean onTop, boolean info) { MyBoxLog.error(e); } } - + public void iconified() { try { getMyStage().setIconified(true); @@ -636,7 +622,7 @@ public void iconified() { MyBoxLog.error(e); } } - + public void requestMouse() { try { if (getMyStage() == null || this instanceof MyBoxLogViewerController) { @@ -661,16 +647,16 @@ public void setControlsStyle() { if (tipsLabel != null) { NodeStyleTools.setTooltip(tipsLabel, new Tooltip(message(TipsLabelKey))); } - + if (tipsView != null) { NodeStyleTools.setTooltip(tipsView, new Tooltip(message(TipsLabelKey))); } - + if (rightTipsView != null) { NodeStyleTools.setTooltip(rightTipsView, new Tooltip(message(TipsLabelKey))); } } - + if (copyButton == null) { if (copyToSystemClipboardButton != null) { NodeStyleTools.setTooltip(copyToSystemClipboardButton, new Tooltip(message("CopyToSystemClipboard") + "\nCTRL+c / ALT+c")); @@ -678,7 +664,7 @@ public void setControlsStyle() { NodeStyleTools.setTooltip(copyToMyBoxClipboardButton, new Tooltip(message("CopyToMyBoxClipboard") + "\nCTRL+c / ALT+c")); } } - + if (pasteButton == null) { if (pasteContentInSystemClipboardButton != null) { NodeStyleTools.setTooltip(pasteContentInSystemClipboardButton, new Tooltip(message("PasteContentInSystemClipboard") + "\nCTRL+v / ALT+v")); @@ -686,13 +672,13 @@ public void setControlsStyle() { NodeStyleTools.setTooltip(loadContentInSystemClipboardButton, new Tooltip(message("LoadContentInSystemClipboard") + "\nCTRL+v / ALT+v")); } } - + } catch (Exception e) { MyBoxLog.debug(e); } - + } - + public BaseController reload() { try { if (!checkBeforeNextAction()) { @@ -724,7 +710,7 @@ public BaseController reload() { return myController; } } - + public boolean setSceneFontSize(int size) { if (thisPane == null) { return false; @@ -736,7 +722,7 @@ public boolean setSceneFontSize(int size) { } return true; } - + public boolean setIconSize(int size) { if (thisPane == null) { return false; @@ -748,7 +734,7 @@ public boolean setIconSize(int size) { refreshInterface(); return true; } - + public BaseController refreshInterfaceAndFile() { refreshInterface(); if (checkBeforeNextAction()) { @@ -756,7 +742,7 @@ public BaseController refreshInterfaceAndFile() { } return myController; } - + public BaseController refreshInterface() { try { if (thisPane != null) { @@ -772,7 +758,7 @@ public BaseController refreshInterface() { return null; } } - + public BaseController loadScene(String newFxml) { try { if (!leavingScene()) { @@ -784,23 +770,23 @@ public BaseController loadScene(String newFxml) { return null; } } - + public BaseController openStage(String newFxml) { return WindowTools.openStage(getStage(), newFxml); } - + public BaseController childStage(String newFxml) { return WindowTools.childStage(myController, newFxml); } - + public BaseController branchStage(String newFxml) { return WindowTools.branchStage(myController, newFxml); } - + public BaseController popStage(String newFxml) { return WindowTools.popStage(myController, newFxml); } - + public void updateStageTitle(File file) { try { if (getMyStage() == null) { @@ -834,7 +820,7 @@ public boolean leavingScene() { return false; } } - + public static boolean checkBeforeNextAction(Node node) { if (node == null) { return true; @@ -875,7 +861,7 @@ public static boolean checkBeforeNextAction(Node node) { } return true; } - + public void leaveScene() { try { cleanNode(thisPane); @@ -884,7 +870,7 @@ public void leaveScene() { MyBoxLog.error(e); } } - + public static void cleanNode(Node node) { if (node == null) { return; @@ -913,7 +899,7 @@ public static void cleanNode(Node node) { } node.setUserData(null); } - + public void cleanPane() { try { if (timer != null) { @@ -942,9 +928,9 @@ public void cleanPane() { } catch (Exception e) { MyBoxLog.debug(e); } - + } - + public void cleanWindow() { try { if (myScene != null) { @@ -961,14 +947,14 @@ public void cleanWindow() { UserConfig.setInt(prefix + "StageHeight", (int) myStage.getHeight()); myStage = null; } - + myWindow = null; System.gc(); } catch (Exception e) { MyBoxLog.debug(e); } } - + public boolean close() { if (leavingScene()) { WindowTools.closeWindow(getMyWindow()); @@ -977,7 +963,7 @@ public boolean close() { return false; } } - + public boolean closeStage() { return close(); } @@ -1001,9 +987,9 @@ public void initSplitPanes() { UserConfig.setBoolean(interfaceName + "DisplayRightPane", rightPaneCheck.isSelected()); checkRightPane(); }); - + } - + if (leftPaneCheck != null) { leftPaneCheck.setSelected(UserConfig.getBoolean(interfaceName + "DisplayLeftPane", true)); checkLeftPane(); @@ -1026,7 +1012,7 @@ public void changed(ObservableValue o, Boolean ov, Boolean nv MyBoxLog.error(e); } } - + public void checkLeftPane() { try { if (isSettingValues || splitPane == null || leftPane == null @@ -1048,7 +1034,7 @@ public void checkLeftPane() { MyBoxLog.error(e); } } - + public void checkRightPane() { try { if (isSettingValues || splitPane == null || rightPane == null @@ -1070,7 +1056,7 @@ public void checkRightPane() { MyBoxLog.error(e); } } - + public boolean checkRightPaneHide() { try { if (isSettingValues || splitPane == null || rightPane == null @@ -1090,7 +1076,7 @@ public boolean checkRightPaneHide() { return false; } } - + public void setSplitDividerPositions() { try { if (isSettingValues || splitPane == null) { @@ -1139,7 +1125,7 @@ public void setSplitDividerPositions() { MyBoxLog.error(e); } } - + @FXML public void controlLeftPane() { if (isSettingValues || splitPane == null || leftPane == null @@ -1152,7 +1138,7 @@ public void controlLeftPane() { showLeftPane(); } } - + public void hideLeftPane() { if (isSettingValues || splitPane == null || leftPane == null || (leftPaneControl != null && !leftPaneControl.isVisible()) @@ -1170,7 +1156,7 @@ public void hideLeftPane() { StyleTools.setIconName(leftPaneControl, "iconDoubleRight.png"); } } - + public void showLeftPane() { if (isSettingValues || splitPane == null || leftPane == null || (leftPaneControl != null && !leftPaneControl.isVisible()) @@ -1189,7 +1175,7 @@ public void showLeftPane() { leftPane.setHvalue(0); leftPane.setVvalue(0); } - + @FXML public void controlRightPane() { if (isSettingValues || splitPane == null || rightPane == null @@ -1202,7 +1188,7 @@ public void controlRightPane() { showRightPane(); } } - + public void hideRightPane() { if (isSettingValues || splitPane == null || rightPane == null || (rightPaneControl != null && !rightPaneControl.isVisible()) @@ -1220,7 +1206,7 @@ public void hideRightPane() { StyleTools.setIconName(rightPaneControl, "iconDoubleLeft.png"); } } - + public void showRightPane() { try { if (isSettingValues || splitPane == null || rightPane == null @@ -1243,5 +1229,5 @@ public void showRightPane() { MyBoxLog.error(e); } } - + } diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/BaseData2DSourceRowsController.java b/alpha/MyBox/src/main/java/mara/mybox/controller/BaseData2DSourceRowsController.java index 25b863662..9a898ab2c 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/BaseData2DSourceRowsController.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/BaseData2DSourceRowsController.java @@ -66,26 +66,26 @@ public void initParameters() { String rowsSelectionType = UserConfig.getString(baseName + "RowsSelectionType", "Selected"); if ("AllPages".equals(rowsSelectionType)) { allPagesRadio.setSelected(true); - tableView.setDisable(true); + setSelectable(false); } else if ("CurrentPage".equals(rowsSelectionType)) { currentPageRadio.setSelected(true); - tableView.setDisable(true); + setSelectable(false); } else { selectedRadio.setSelected(true); - tableView.setDisable(false); + setSelectable(true); } rowsGroup.selectedToggleProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue ov, Toggle oldValue, Toggle newValue) { if (allPagesRadio.isSelected()) { UserConfig.setString(baseName + "RowsSelectionType", "AllPages"); - tableView.setDisable(true); + setSelectable(false); } else if (selectedRadio.isSelected()) { UserConfig.setString(baseName + "RowsSelectionType", "Selected"); - tableView.setDisable(false); + setSelectable(true); } else { UserConfig.setString(baseName + "RowsSelectionType", "CurrentPage"); - tableView.setDisable(true); + setSelectable(false); } } }); diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/BaseData2DTableController.java b/alpha/MyBox/src/main/java/mara/mybox/controller/BaseData2DTableController.java index 89510aeb3..7745a54f6 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/BaseData2DTableController.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/BaseData2DTableController.java @@ -542,7 +542,6 @@ protected void showPaginationPane(boolean show) { } } - /* interface */ diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/BaseTableViewController.java b/alpha/MyBox/src/main/java/mara/mybox/controller/BaseTableViewController.java index bfc8a1621..5e929a604 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/BaseTableViewController.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/BaseTableViewController.java @@ -197,6 +197,22 @@ protected void hovering(boolean isHovering) { } } + protected void setSelectable(boolean selectable) { + tableView.getSelectionModel().clearSelection(); + if (rowsSelectionColumn == null) { + return; + } + if (selectable) { + if (!tableView.getColumns().contains(rowsSelectionColumn)) { + tableView.getColumns().add(0, rowsSelectionColumn); + } + } else { + if (tableView.getColumns().contains(rowsSelectionColumn)) { + tableView.getColumns().remove(rowsSelectionColumn); + } + } + } + /* status */ diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/ControlData2DRowExpression.java b/alpha/MyBox/src/main/java/mara/mybox/controller/ControlData2DRowExpression.java index 87a26c57e..47312b3cd 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/ControlData2DRowExpression.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/ControlData2DRowExpression.java @@ -12,7 +12,7 @@ import mara.mybox.db.data.Data2DColumn; import mara.mybox.db.table.TableStringValues; import mara.mybox.dev.MyBoxLog; -import mara.mybox.fxml.ExpressionCalculator; +import mara.mybox.calculation.ExpressionCalculator; import mara.mybox.fxml.HelpTools; import mara.mybox.fxml.PopTools; import static mara.mybox.value.Languages.message; diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/ControlData2DRowFilter.java b/alpha/MyBox/src/main/java/mara/mybox/controller/ControlData2DRowFilter.java index 297e50251..1292438f1 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/ControlData2DRowFilter.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/ControlData2DRowFilter.java @@ -26,7 +26,7 @@ public class ControlData2DRowFilter extends ControlData2DRowExpression { protected DataFilter filter; @FXML - protected RadioButton trueRadio, othersRadio; + protected RadioButton trueRadio, falseRadio; @FXML protected TextField maxInput; @@ -124,7 +124,7 @@ public void load(String script, boolean isTrue, long max) { if (isTrue) { trueRadio.setSelected(true); } else { - othersRadio.setSelected(true); + falseRadio.setSelected(true); } } if (maxInput != null) { @@ -146,7 +146,7 @@ public void load(Data2D data2D, DataFilter filter) { } public DataFilter pickValues() { - filter.setReversed(othersRadio.isSelected()) + filter.setReversed(falseRadio.isSelected()) .setMaxPassed(maxFilteredNumber).setPassedNumber(0) .setSourceScript(scriptInput.getText()); if (data2D != null) { diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/ControlSynchronizeOptions.java b/alpha/MyBox/src/main/java/mara/mybox/controller/ControlSynchronizeOptions.java index a19b6cb93..91ced0124 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/ControlSynchronizeOptions.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/ControlSynchronizeOptions.java @@ -45,7 +45,7 @@ public class ControlSynchronizeOptions extends BaseController { protected CheckBox copySubdirCheck, copyEmptyCheck, copyNewCheck, copyHiddenCheck, copyReadonlyCheck, copyExistedCheck, copyModifiedCheck, deleteNonExistedCheck, notCopyCheck, copyAttrCheck, copyMtimeCheck, permissionCheck, - deleteSourceCheck; + deleteSourceCheck, errorContinueCheck; @FXML protected DatePicker modifyAfterInput; @@ -193,6 +193,20 @@ public void changed(ObservableValue v, Boolean ov, Boolean nv }); deleteSourceCheck.setSelected(UserConfig.getBoolean(baseName + "DeleteSource", false)); + if (errorContinueCheck != null) { + errorContinueCheck.setSelected(false); + errorContinueCheck.selectedProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue ov, Boolean oldValue, Boolean newValue) { + if (errorContinueCheck.isSelected()) { + errorContinueCheck.setStyle(NodeStyleTools.darkRedTextStyle()); + } else { + errorContinueCheck.setStyle(null); + } + } + }); + } + } catch (Exception e) { MyBoxLog.debug(e); } diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/Data2DRowExpressionController.java b/alpha/MyBox/src/main/java/mara/mybox/controller/Data2DRowExpressionController.java index cc6986c17..792e61fb4 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/Data2DRowExpressionController.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/Data2DRowExpressionController.java @@ -174,12 +174,8 @@ public boolean handleRows() { sourceController.tableData.get(rowIndex), rowIndex)) { checkedRow.add(data2D.expressionResult()); } else { - if (errorContinueCheck.isSelected()) { - checkedRow.add(null); - } else { - error = data2D.getError(); - return false; - } + error = data2D.getError(); + return false; } outputData.set(i, checkedRow); } @@ -199,8 +195,8 @@ public boolean handleRows() { @Override public boolean handleAllData(FxTask currentTask, Data2DWriter writer) { return data2D.rowExpression(currentTask, writer, expression, - nameInput.getText().trim(), errorContinueCheck.isSelected(), - checkedColsIndices, rowNumberCheck.isSelected(), colNameCheck.isSelected()); + nameInput.getText().trim(), checkedColsIndices, + rowNumberCheck.isSelected(), colNameCheck.isSelected()); } @FXML diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/Data2DSetValuesController.java b/alpha/MyBox/src/main/java/mara/mybox/controller/Data2DSetValuesController.java index 00efdf800..e4d56c4c3 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/Data2DSetValuesController.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/Data2DSetValuesController.java @@ -169,8 +169,7 @@ protected boolean handle() { addBackup(this, data2D.getFile()); } data2D.startTask(this, filterController.filter); - count = data2D.setValue(this, checkedColsIndices, valueController.setValue, - valueController.errorContinueCheck.isSelected()); + count = data2D.setValue(this, checkedColsIndices, valueController.setValue); data2D.stopFilter(); taskSuccessed = count >= 0; return taskSuccessed; @@ -378,18 +377,8 @@ public boolean expression() { for (int row : sourceController.filteredRowsIndices) { List values = sourceController.tableData.get(row); if (!data2D.calculateTableRowExpression(script, values, row)) { - error = data2D.expressionError(); - if (valueController.errorContinueCheck.isSelected()) { - if (error != null) { - MyBoxLog.console(row + "" + error); - } - continue; - } else { - if (error != null) { - setError(error); - } - return false; - } + setError(data2D.expressionError()); + return false; } String v = data2D.expressionResult(); for (int col : checkedColsIndices) { diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/MathFunctionController.java b/alpha/MyBox/src/main/java/mara/mybox/controller/MathFunctionController.java index 1e34d755f..e9b6ff8ed 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/MathFunctionController.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/MathFunctionController.java @@ -1,7 +1,9 @@ package mara.mybox.controller; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javafx.event.Event; import javafx.fxml.FXML; import javafx.geometry.Pos; @@ -149,14 +151,14 @@ public void calculateAction() { popError(message("InvalidParameter") + ": " + message("DecimalScale")); return; } + Map variableValues = pickVariables(); expression = script(); domain = domain(); - if (!editorController.inDomain(fillInputs(domain))) { + if (!editorController.inDomain(domain, variableValues)) { popError(message("NotInDomain")); return; } - String finalScript = fillInputs(expression); - String ret = editorController.eval(finalScript); + String ret = editorController.calculate(expression, variableValues); if (ret == null) { popError(message("Failed")); return; @@ -164,8 +166,15 @@ public void calculateAction() { double d = DoubleTools.scale(ret, ColumnDefinition.InvalidAs.Empty, calculateScale); ret = DoubleTools.invalidDouble(d) ? ret : (d + ""); outputs += DateTools.nowString() + "
" - + HtmlWriteTools.stringToHtml(finalScript) - + "
"; + + message("Expression") + ":
\n" + + HtmlWriteTools.stringToHtml(expression) + "
\n"; + if (variableValues != null && !variableValues.isEmpty()) { + outputs += "
" + message("Variables") + ":
\n"; + for (String n : variableValues.keySet()) { + outputs += n + "=" + variableValues.get(n) + "
"; + } + } + outputs += ""; outputs += "
" + HtmlWriteTools.stringToHtml(editorController.functionName() + "=" + ret) + "


"; @@ -180,22 +189,18 @@ public void calculateAction() { } } - public String fillInputs(String script) { + public Map pickVariables() { try { - List variables = editorController.variableNames(); - if (script == null || script.isBlank() || variables == null) { - return script; - } - String vars = ""; + Map vs = new HashMap<>(); List nodes = inputsBox.getChildren(); for (int i = 0; i < nodes.size(); i++) { FlowPane fp = (FlowPane) nodes.get(i); Label label = (Label) fp.getChildren().get(0); TextField input = (TextField) fp.getChildren().get(1); double d = DoubleTools.toDouble(input.getText(), ColumnDefinition.InvalidAs.Empty); - vars += "var " + label.getText() + "=" + d + ";\n"; + vs.put(label.getText(), d); } - return vars + script; + return vs; } catch (Exception e) { MyBoxLog.error(e); return null; diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/MathFunctionDataController.java b/alpha/MyBox/src/main/java/mara/mybox/controller/MathFunctionDataController.java index 94d60d75a..5e7b960e9 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/MathFunctionDataController.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/MathFunctionDataController.java @@ -4,7 +4,9 @@ import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.control.ComboBox; @@ -197,11 +199,11 @@ public void makeRow(List values) { public void calculateRow(List values) { try { - if (!editorController.inDomain(fillValues(domain, values))) { + Map variableValues = fillValues(values); + if (!editorController.inDomain(domain, variableValues)) { return; } - String finalScript = fillValues(expression, values); - String fx = editorController.eval(finalScript); + String fx = editorController.calculate(expression, variableValues); if (fx == null) { return; } @@ -219,17 +221,16 @@ public void calculateRow(List values) { } } - public String fillValues(String script, List values) { + public Map fillValues(List values) { try { - if (script == null || script.isBlank() - || variables == null || variables.size() > values.size()) { - return script; + if (variables == null || variables.size() > values.size()) { + return null; } - String vars = ""; + Map vs = new HashMap<>(); for (int i = 0; i < variables.size(); i++) { - vars += "var " + variables.get(i) + "=" + values.get(i) + ";\n"; + vs.put(variables.get(i), values.get(i)); } - return vars + script; + return vs; } catch (Exception e) { MyBoxLog.error(e); return null; diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/MathFunctionEditor.java b/alpha/MyBox/src/main/java/mara/mybox/controller/MathFunctionEditor.java index aaa90a56c..767fbaad5 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/MathFunctionEditor.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/MathFunctionEditor.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; import javafx.beans.value.ChangeListener; @@ -12,10 +13,11 @@ import javafx.scene.control.ComboBox; import javafx.scene.control.TextField; import javafx.scene.input.MouseEvent; +import javax.script.Bindings; +import mara.mybox.calculation.ExpressionCalculator; import mara.mybox.db.data.InfoNode; import static mara.mybox.db.data.InfoNode.ValueSeparater; import mara.mybox.dev.MyBoxLog; -import mara.mybox.fxml.ExpressionCalculator; import mara.mybox.fxml.PopTools; import mara.mybox.tools.StringTools; import static mara.mybox.value.Languages.message; @@ -135,6 +137,14 @@ public List variableNames() { } } + public Bindings bindings() { + if (calculator == null) { + return null; + } else { + return calculator.variableValues; + } + } + public String script() { return valueInput.getText(); } @@ -157,28 +167,27 @@ public String titleName() { return name == null || name.isBlank() ? message("MathFunction") : name; } - public String eval(String script) { - return calculator.calculate(script); + public String calculate(String script, Map variables) { + return calculator.calculate(script, variables); } - public boolean inDomain(String domain) { + public boolean inDomain(String domain, Map variables) { if (domain == null || domain.isBlank()) { return true; } - return calculator.condition(domain); + return calculator.condition(domain, variables); } - public String fillDummy(String script) { + public Map dummyBindings() { try { + Map vs = new HashMap<>(); List variables = variableNames(); - if (script == null || script.isBlank() || variables == null) { - return script; - } - String vars = ""; - for (int i = 0; i < variables.size(); i++) { - vars += "var " + variables.get(i) + "=" + 1 + ";\n"; + if (variables != null) { + for (int i = 0; i < variables.size(); i++) { + vs.put(variables.get(i), 1); + } } - return vars + script; + return vs; } catch (Exception e) { MyBoxLog.error(e); return null; @@ -191,8 +200,9 @@ public boolean checkScripts() { popError(message("InvalidParameters") + ": " + message("Expression")); return false; } + Map variableValues = dummyBindings(); script = script.trim(); - String ret = eval(fillDummy(script)); + String ret = calculate(script, variableValues); if (ret == null) { if (calculator.getError() != null) { popError(calculator.getError()); @@ -205,7 +215,7 @@ public boolean checkScripts() { if (edomain == null) { return true; } - ret = eval(fillDummy(edomain)); + ret = calculate(edomain, variableValues); if (ret == null) { if (calculator.getError() != null) { popError(calculator.getError()); diff --git a/alpha/MyBox/src/main/java/mara/mybox/controller/RemotePathHandleFilesController.java b/alpha/MyBox/src/main/java/mara/mybox/controller/RemotePathHandleFilesController.java index 8b9e33315..347838c57 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/controller/RemotePathHandleFilesController.java +++ b/alpha/MyBox/src/main/java/mara/mybox/controller/RemotePathHandleFilesController.java @@ -16,6 +16,7 @@ import mara.mybox.fxml.FxTask; import mara.mybox.fxml.SoundTools; import mara.mybox.fxml.WindowTools; +import mara.mybox.fxml.style.NodeStyleTools; import mara.mybox.value.Fxmls; import static mara.mybox.value.Languages.message; import mara.mybox.value.UserConfig; @@ -38,7 +39,7 @@ public abstract class RemotePathHandleFilesController extends BaseTaskController @FXML protected Label hostLabel; @FXML - protected CheckBox wrapCheck; + protected CheckBox wrapCheck, errorContinueCheck; public void setParameters(RemotePathManageController manageController) { try { @@ -66,6 +67,20 @@ public void changed(ObservableValue v, Boolean ov, Boolean nv }); namesArea.setWrapText(wrapCheck.isSelected()); + if (errorContinueCheck != null) { + errorContinueCheck.setSelected(false); + errorContinueCheck.selectedProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue ov, Boolean oldValue, Boolean newValue) { + if (errorContinueCheck.isSelected()) { + errorContinueCheck.setStyle(NodeStyleTools.darkRedTextStyle()); + } else { + errorContinueCheck.setStyle(null); + } + } + }); + } + } catch (Exception e) { MyBoxLog.error(e); popError(e.toString()); diff --git a/alpha/MyBox/src/main/java/mara/mybox/data2d/Data2D_Edit.java b/alpha/MyBox/src/main/java/mara/mybox/data2d/Data2D_Edit.java index 7f01fcebf..8d962f75f 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/data2d/Data2D_Edit.java +++ b/alpha/MyBox/src/main/java/mara/mybox/data2d/Data2D_Edit.java @@ -303,7 +303,7 @@ public long saveAttributes(FxTask task, Data2D attributes) { } } - public long setValue(FxTask task, List cols, SetValue setValue, boolean errorContinue) { + public long setValue(FxTask task, List cols, SetValue setValue) { try { if (!isValidData() || cols == null || cols.isEmpty()) { return -1; @@ -314,8 +314,7 @@ public long setValue(FxTask task, List cols, SetValue setValue, boolean if (operate == null) { return -2; } - operate.setCols(cols).setErrorContinue(errorContinue) - .setTask(task).start(); + operate.setCols(cols).setTask(task).start(); if (operate.isFailed()) { return -3; } diff --git a/alpha/MyBox/src/main/java/mara/mybox/data2d/Data2D_Filter.java b/alpha/MyBox/src/main/java/mara/mybox/data2d/Data2D_Filter.java index c73b6c683..929868814 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/data2d/Data2D_Filter.java +++ b/alpha/MyBox/src/main/java/mara/mybox/data2d/Data2D_Filter.java @@ -11,7 +11,7 @@ import mara.mybox.db.data.Data2DColumn; import mara.mybox.db.data.Data2DStyle; import mara.mybox.dev.MyBoxLog; -import mara.mybox.fxml.ExpressionCalculator; +import mara.mybox.calculation.ExpressionCalculator; import mara.mybox.fxml.FxTask; import mara.mybox.tools.DoubleTools; import static mara.mybox.value.Languages.message; diff --git a/alpha/MyBox/src/main/java/mara/mybox/data2d/Data2D_Operations.java b/alpha/MyBox/src/main/java/mara/mybox/data2d/Data2D_Operations.java index f8469d93a..a22c0817a 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/data2d/Data2D_Operations.java +++ b/alpha/MyBox/src/main/java/mara/mybox/data2d/Data2D_Operations.java @@ -391,7 +391,7 @@ public List splitByList(List cols, boolean includeRowNumbe } public boolean rowExpression(FxTask task, Data2DWriter writer, - String script, String name, boolean errorContinue, + String script, String name, List cols, boolean includeRowNumber, boolean includeColName) { try { if (writer == null || cols == null || cols.isEmpty()) { diff --git a/alpha/MyBox/src/main/java/mara/mybox/data2d/DataFilter.java b/alpha/MyBox/src/main/java/mara/mybox/data2d/DataFilter.java index c1811be08..2a7f87627 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/data2d/DataFilter.java +++ b/alpha/MyBox/src/main/java/mara/mybox/data2d/DataFilter.java @@ -1,8 +1,8 @@ package mara.mybox.data2d; import java.util.List; +import mara.mybox.calculation.ExpressionCalculator; import mara.mybox.dev.MyBoxLog; -import mara.mybox.fxml.ExpressionCalculator; import mara.mybox.fxml.FxTask; import mara.mybox.value.AppValues; import static mara.mybox.value.Languages.message; @@ -75,7 +75,7 @@ public boolean readResult(boolean calculateSuccess) { passed = false; if (calculateSuccess) { if (reversed) { - passed = !"true".equals(calculator.getResult()); + passed = "false".equals(calculator.getResult()); } else { passed = "true".equals(calculator.getResult()); } diff --git a/alpha/MyBox/src/main/java/mara/mybox/data2d/DataMatrix.java b/alpha/MyBox/src/main/java/mara/mybox/data2d/DataMatrix.java index b4eb579a0..546260ff3 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/data2d/DataMatrix.java +++ b/alpha/MyBox/src/main/java/mara/mybox/data2d/DataMatrix.java @@ -173,7 +173,7 @@ public List> toTableData(double[][] data) { } @Override - public long setValue(FxTask task, List cols, SetValue value, boolean errorContinue) { + public long setValue(FxTask task, List cols, SetValue value) { return -1; } diff --git a/alpha/MyBox/src/main/java/mara/mybox/data2d/TmpTable.java b/alpha/MyBox/src/main/java/mara/mybox/data2d/TmpTable.java index f1130155d..6d3b377a7 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/data2d/TmpTable.java +++ b/alpha/MyBox/src/main/java/mara/mybox/data2d/TmpTable.java @@ -24,7 +24,7 @@ import mara.mybox.db.data.Data2DRow; import static mara.mybox.db.table.BaseTable.StringMaxLength; import mara.mybox.dev.MyBoxLog; -import mara.mybox.fxml.ExpressionCalculator; +import mara.mybox.calculation.ExpressionCalculator; import mara.mybox.fxml.FxTask; import mara.mybox.tools.DateTools; import mara.mybox.tools.FileTmpTools; diff --git a/alpha/MyBox/src/main/java/mara/mybox/data2d/modify/Data2DSetValue.java b/alpha/MyBox/src/main/java/mara/mybox/data2d/modify/Data2DSetValue.java index f65c5ae38..af5fd6129 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/data2d/modify/Data2DSetValue.java +++ b/alpha/MyBox/src/main/java/mara/mybox/data2d/modify/Data2DSetValue.java @@ -56,20 +56,14 @@ public void handleRow(List row, long index) { passFilter = sourceData.filterDataRow(sourceRow, sourceRowIndex); reachMax = sourceData.filterReachMaxPassed(); boolean handle = passFilter && !reachMax; - String expResult = null, currentValue, error; + String expResult = null, currentValue; if (handle) { if (setValue.isExpression() && dataValue != null) { if (sourceData.calculateDataRowExpression(dataValue, sourceRow, sourceRowIndex)) { expResult = sourceData.expressionResult(); } else { - error = sourceData.expressionError(); - if (errorContinue) { - showError(error); - handle = false; - } else { - failStop(error); - return; - } + failStop(sourceData.expressionError()); + return; } } } @@ -112,13 +106,13 @@ public void handleRow(List row, long index) { } else { v = dataValue; } + handledCount++; } else { v = currentValue; } targetRow.add(v); } writeRow(); - handledCount++; } catch (Exception e) { MyBoxLog.console(e); } diff --git a/alpha/MyBox/src/main/java/mara/mybox/data2d/operate/Data2DOperate.java b/alpha/MyBox/src/main/java/mara/mybox/data2d/operate/Data2DOperate.java index 7611339f4..bcf9391f3 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/data2d/operate/Data2DOperate.java +++ b/alpha/MyBox/src/main/java/mara/mybox/data2d/operate/Data2DOperate.java @@ -36,7 +36,7 @@ public abstract class Data2DOperate { protected List cols, otherCols; protected int colsLen, scale = -1; protected boolean includeRowNumber, writeHeader, passFilter, reachMax; - protected boolean stopped, needCheckTask, errorContinue, failed, closeConn; + protected boolean stopped, needCheckTask, failed, closeConn; protected long sourceRowIndex; // 1-based protected long handledCount; protected InvalidAs invalidAs; @@ -387,11 +387,6 @@ public Data2DOperate setWriters(List writers) { return this; } - public Data2DOperate setErrorContinue(boolean errorContinue) { - this.errorContinue = errorContinue; - return this; - } - public Data2DOperate setController(BaseController controller) { this.controller = controller; return this; diff --git a/alpha/MyBox/src/main/java/mara/mybox/data2d/operate/Data2DRowExpression.java b/alpha/MyBox/src/main/java/mara/mybox/data2d/operate/Data2DRowExpression.java index 869299f72..0e9ce615e 100644 --- a/alpha/MyBox/src/main/java/mara/mybox/data2d/operate/Data2DRowExpression.java +++ b/alpha/MyBox/src/main/java/mara/mybox/data2d/operate/Data2DRowExpression.java @@ -48,15 +48,11 @@ public boolean handleRow() { } if (sourceData.calculateDataRowExpression(script, sourceRow, sourceRowIndex)) { targetRow.add(sourceData.expressionResult()); + return true; } else { - if (errorContinue) { - targetRow.add(null); - } else { - stop(); - return false; - } + stop(); + return false; } - return true; } catch (Exception e) { showError(e.toString()); return false; @@ -76,9 +72,4 @@ public Data2DRowExpression setName(String name) { return this; } - public Data2DRowExpression setErrorContinue(boolean errorContinue) { - this.errorContinue = errorContinue; - return this; - } - } diff --git a/alpha/MyBox/src/main/resources/bundles/Messages_en.properties b/alpha/MyBox/src/main/resources/bundles/Messages_en.properties index 1a7e58647..cfeb12343 100644 --- a/alpha/MyBox/src/main/resources/bundles/Messages_en.properties +++ b/alpha/MyBox/src/main/resources/bundles/Messages_en.properties @@ -4382,7 +4382,7 @@ RowFilter=Row filter JEXLCode=JEXL Codes TableRowNumber=TableRowNumber DataRowNumber=DataRowNumber -TakeSourceDataWhenExpressionEmptyOr=Take source data when the expression is blank or +TakeSourceDataWhenExpressionEmptyOr=Take source data row when the expression is blank or CopyFilterQueryConvert=Copy/Filter/Query/Convert RowExpression=Row expression SelectToPaste=Select to paste @@ -5235,3 +5235,4 @@ Robustness=Robustness Usability=Usability Compatibility=Compatibility Security=Security +DataFilterComments=When expression value is not empty, true, nor false, the row is not taken. diff --git a/alpha/MyBox/src/main/resources/bundles/Messages_zh_CN.properties b/alpha/MyBox/src/main/resources/bundles/Messages_zh_CN.properties index eb25dc9f6..5981d1ca9 100644 --- a/alpha/MyBox/src/main/resources/bundles/Messages_zh_CN.properties +++ b/alpha/MyBox/src/main/resources/bundles/Messages_zh_CN.properties @@ -4382,7 +4382,7 @@ RowFilter=\u884c\u8fc7\u6ee4 JEXLCode=JEXL\u4ee3\u7801 TableRowNumber=\u8868\u884c\u53f7 DataRowNumber=\u6570\u636e\u884c\u53f7 -TakeSourceDataWhenExpressionEmptyOr=\u91c7\u7eb3\u6e90\u6570\u636e\u7684\u6761\u4ef6\u4e3a\u8868\u8fbe\u5f0f\u4e3a\u7a7a\u6216\u503c\u7b49\u4e8e +TakeSourceDataWhenExpressionEmptyOr=\u91c7\u7eb3\u6e90\u6570\u636e\u884c\u7684\u6761\u4ef6\u4e3a\uff1a\u8868\u8fbe\u5f0f\u4e3a\u7a7a\u3001\u6216\u503c\u7b49\u4e8e CopyFilterQueryConvert=\u590d\u5236/\u8fc7\u6ee4/\u67e5\u8be2/\u8f6c\u6362 RowExpression=\u884c\u8868\u8fbe\u5f0f SelectToPaste=\u9009\u62e9\u4ee5\u7c98\u8d34 @@ -5234,3 +5234,4 @@ Robustness=\u5065\u58ee\u6027 Usability=\u53ef\u7528\u6027 Compatibility=\u517c\u5bb9\u6027 Security=\u5b89\u5168 +DataFilterComments=\u5f53\u8868\u8fbe\u5f0f\u7684\u503c\u4e0d\u4e3a\uff1a\u7a7a\u3001true\u3001\u6216false\uff0c\u5219\u4e0d\u53d6\u6b64\u884c\u3002 diff --git a/alpha/MyBox/src/main/resources/data/examples/JavaScript_Examples_en.txt b/alpha/MyBox/src/main/resources/data/examples/JavaScript_Examples_en.txt index 3ed99ef64..640f8e80d 100644 --- a/alpha/MyBox/src/main/resources/data/examples/JavaScript_Examples_en.txt +++ b/alpha/MyBox/src/main/resources/data/examples/JavaScript_Examples_en.txt @@ -291,8 +291,9 @@ arrayA.includes('C'); ##MyBox# JavaScript > Examples > Expressions > Boolean operations -is number -Math.abs(2a) >= 0 +is not number +var v1='hello' +isNaN(v1 - 1) ##MyBox# JavaScript > Examples > Expressions > Boolean operations @@ -331,6 +332,25 @@ new Date('2022-11-30 10:35:32'.replace(/-/g,'/')).toLocaleString() + "\n" + new Date('2022/11/30') + "\n" + new Date('2022-11-30'.replace(/-/g,'/')) +##MyBox# +JavaScript > Examples > Expressions > Date operations +format date +function formatDate(date) { + var y = date.getFullYear(); + var m = date.getMonth() + 1; + m = m < 10 ? ('0' + m) : m; + var d = date.getDate(); + d = d < 10 ? ('0' + d) : d; + var h =date.getHours(); + h = h < 10 ? ('0' + h) : h; + var M =date.getMinutes(); + M = M < 10 ? ('0' + M) : M; + var s =date.getSeconds(); + s = s < 10 ? ('0' + s) : s; + return y + '-' + m + '-' + d + ' ' + h + ':' + M + ':' + s; +} +formatDate(new Date()); + ##MyBox# JavaScript > Examples > Expressions > Date operations components of date diff --git a/alpha/MyBox/src/main/resources/data/examples/JavaScript_Examples_zh.txt b/alpha/MyBox/src/main/resources/data/examples/JavaScript_Examples_zh.txt index bfd038e74..40703a65a 100644 --- a/alpha/MyBox/src/main/resources/data/examples/JavaScript_Examples_zh.txt +++ b/alpha/MyBox/src/main/resources/data/examples/JavaScript_Examples_zh.txt @@ -169,7 +169,7 @@ JavaScript > 示例 > 表达式 ##MyBox# JavaScript > 示例 > 表达式 > 字符串处理 比较 -'Hello' == 'hello' || 'a' < 'A' || 'a' != 'A' +'Hello' === 'hello' || 'a' < 'A' || 'a' != 'A' ##MyBox# JavaScript > 示例 > 表达式 > 字符串处理 @@ -291,8 +291,9 @@ var 数组a = ['A', 'B', 'C', 'D']; ##MyBox# JavaScript > 示例 > 表达式 > 布尔运算 -是否为数值 -Math.abs(2a) >= 0 +不是数字 +var 值1='你好' +isNaN(值1 - 1) ##MyBox# JavaScript > 示例 > 表达式 > 布尔运算 @@ -331,6 +332,25 @@ new Date('2022-11-30 10:35:32'.replace(/-/g,'/')).toLocaleString() + "\n" + new Date('2022/11/30') + "\n" + new Date('2022-11-30'.replace(/-/g,'/')) +##MyBox# +JavaScript > 示例 > 表达式 > 时间运算 +格式化时间 +function formatDate(date) { + var y = date.getFullYear(); + var m = date.getMonth() + 1; + m = m < 10 ? ('0' + m) : m; + var d = date.getDate(); + d = d < 10 ? ('0' + d) : d; + var h =date.getHours(); + h = h < 10 ? ('0' + h) : h; + var M =date.getMinutes(); + M = M < 10 ? ('0' + M) : M; + var s =date.getSeconds(); + s = s < 10 ? ('0' + s) : s; + return y + '-' + m + '-' + d + ' ' + h + ':' + M + ':' + s; +} +formatDate(new Date()); + ##MyBox# JavaScript > 示例 > 表达式 > 时间运算 时间的分量 diff --git a/alpha/MyBox/src/main/resources/data/examples/RowFilter_Examples_zh.txt b/alpha/MyBox/src/main/resources/data/examples/RowFilter_Examples_zh.txt index d1f8a7e43..a1f830804 100644 --- a/alpha/MyBox/src/main/resources/data/examples/RowFilter_Examples_zh.txt +++ b/alpha/MyBox/src/main/resources/data/examples/RowFilter_Examples_zh.txt @@ -6,82 +6,156 @@ MyBoxTreeRoot;;; 行过滤 示例 -##MyBox# -行过滤 > 示例 -数值为空(null或empty) -'#{列1}' == '' - -##MyBox# -行过滤 > 示例 -数值不为空 -'#{列1}'.length > 0 - -##MyBox# -行过滤 > 示例 -最前面10行 -_:;MyBoxNodeValue;:_ -true_:;MyBoxNodeValue;:_ -10 - ##MyBox# 行过滤 > 示例 数字 ##MyBox# 行过滤 > 示例 > 数字 -数值是数字 -Math.abs(#{列1}) >= 0 +列值不是数字 +isNaN(#{字符串列} - 1) ##MyBox# 行过滤 > 示例 > 数字 比较数字 -#{列1} != 0 || #{列1} < #{列2} +#{数字列1} != 0 || #{数字列1} < #{数字列2} ##MyBox# 行过滤 > 示例 > 数字 比较统计值 -#{列1} < #{列1-均值} +#{数字列} < #{数字列-均值} ##MyBox# 行过滤 > 示例 时间 +##MyBox# +行过滤 > 示例 > 时间 +列值的时间值 +new Date(#{时间列}.replace(/-/g,'/')) + ##MyBox# 行过滤 > 示例 > 时间 时间点 -'#{时间}' == '2016-05-19 11:34:28' +new Date(#{时间列}.replace(/-/g,'/')) == '2016-05-19 11:34:28' ##MyBox# 行过滤 > 示例 > 时间 匹配时间 -'#{时间}'.startsWith('2016-05-19 09') +#{时间列}.startsWith('2016-05-19 09') ##MyBox# 行过滤 > 示例 > 时间 比较时间 -new Date('#{时间}'.replace(/-/g,'/')).getTime() > new Date('2016/05/19 09:23:12').getTime() +new Date(#{时间列}.replace(/-/g,'/')).getTime() > new Date('2016/05/19 09:23:12').getTime() + +##MyBox# +行过滤 > 示例 > 时间 +格式化时间 +function formatDate(date) { + var y = date.getFullYear(); + var m = date.getMonth() + 1; + m = m < 10 ? ('0' + m) : m; + var d = date.getDate(); + d = d < 10 ? ('0' + d) : d; + var h =date.getHours(); + h = h < 10 ? ('0' + h) : h; + var M =date.getMinutes(); + M = M < 10 ? ('0' + M) : M; + var s =date.getSeconds(); + s = s < 10 ? ('0' + s) : s; + return y + '-' + m + '-' + d + ' ' + h + ':' + M + ':' + s; +} +formatDate(#{时间列}.replace(/-/g,'/')); ##MyBox# 行过滤 > 示例 字符串 +##MyBox# +行过滤 > 示例 > 字符串 +列值为empty +#{字符串列} == '' + +##MyBox# +行过滤 > 示例 > 字符串 +列值不为null +#{字符串列} != null + ##MyBox# 行过滤 > 示例 > 字符串 字串长度 -'#{列1}'.length > 3 +if ( #{字符串列} != null ) + #{字符串列}.length +else + -1 ##MyBox# 行过滤 > 示例 > 字符串 -匹配字串 -'#{列1}'.search(/Hello/ig) >= 0 +包含子串 +if ( #{字符串列} != null ) + #{字符串列}.search(/昔去雪如花/ig) >= 0 +else + false ##MyBox# 行过滤 > 示例 > 字符串 子串位置 -'#{列1}'.indexOf('Hello') == 3 +if ( #{字符串列} != null ) + #{字符串列}.indexOf('今来花似雪') +else + -1 + +##MyBox# +行过滤 > 示例 > 字符串 +比较 +#{字符串列} === '只恐夜深花睡去' + +##MyBox# +行过滤 > 示例 > 字符串 +替换首个 +if ( #{字符串列} != null ) + #{字符串列}.replace("敲门", "推门"); +else + null + +##MyBox# +行过滤 > 示例 > 字符串 +替换所有 +if ( #{字符串列} != null ) + #{字符串列}.replace(/怨年华/g, "鸟惊心"); +else + null + +##MyBox# +行过滤 > 示例 > 字符串 +开始于 +if ( #{字符串列} != null ) + #{字符串列}.startsWith('君不见') +else + undefined + +##MyBox# +行过滤 > 示例 > 字符串 +结尾于 +if ( #{字符串列} != null ) + #{字符串列}.endsWith('需尽欢') +else + undefined ##MyBox# 行过滤 > 示例 > 字符串 特定值 var array = [ 'A', 'B', 'C', 'D' ]; -array.includes('#{列1}') +array.includes(#{字符串列}) + +##MyBox# +行过滤 > 示例 +限制行数 + +##MyBox# +行过滤 > 示例 > 限制行数 +最前面10行 +_:;MyBoxNodeValue;:_ +true_:;MyBoxNodeValue;:_ +10 diff --git a/alpha/MyBox/src/main/resources/doc/en/README.md b/alpha/MyBox/src/main/resources/doc/en/README.md index 5fef07cec..e59f676a4 100644 --- a/alpha/MyBox/src/main/resources/doc/en/README.md +++ b/alpha/MyBox/src/main/resources/doc/en/README.md @@ -12,15 +12,16 @@ This is compute application to provide simple and easy functions. It's free and * Improve: - Redesign and implement "Data manufacture". The base framework is: reader + operate + writers. - Options: Verify types when edit data; Verify types when save data. - - Implement row expresion with bindings. + - Implement row expresion with bindings. Placeholders are handled as variable names instead of variable values. - Simplify interface of "Data manufacture". - Transparent can be set when customized colors. - "rtbufsize" and rotation can be set for ffmpeg. - Notes: Node can be any html which can include head. * Solved problems: - Fail to switch language when default locale is not Chinese. - - Errors popped when edit data row. - Row expression is messed when value is string of multiple lines. + - In data manufacture, "Set Values" should not clear data rows when expression is invalid. + - Errors popped when edit data row. - Icon is displayed as blank. - "Era" is converted wrongly when import data in database table. - Options of "Target file" in some interfaces do not work. diff --git a/alpha/MyBox/src/main/resources/doc/zh/README.md b/alpha/MyBox/src/main/resources/doc/zh/README.md index a994eba81..e9e3dcc46 100644 --- a/alpha/MyBox/src/main/resources/doc/zh/README.md +++ b/alpha/MyBox/src/main/resources/doc/zh/README.md @@ -13,15 +13,16 @@ * 改进: - 重新设计和实现"处理数据",基础框架为:读+处理+写。 - 可选:编辑数据时检验类型、保存数据时检验类型。 - - 行表达式的实现:以bindings代入参数值。 + - 行表达式的实现:以bindings代入变量值,占位符被处理为变量名而不是变量值。 - 简化"处理数据"的界面。 - 定制颜色时可以设置透明度。 - ffmpeg可以设置"rtbufsize"和旋转。 - 笔记:节点是任何html,可以包含head。 * 解决问题: - 缺省locale非中文时无法切换语言。 - - 编辑数据行时弹出错误。 - 当数据值为多行字串时行表达式会解析混乱。 + - 数据处理中当表达式非法时“赋值”不应当清除数据行。 + - 编辑数据行时弹出错误。 - 对数据库表导入数据时,类型“纪元”转换错误。 - icon图片显示为空白。 - 一些界面中“目标文件”的选项未生效。 diff --git a/alpha/MyBox/src/main/resources/fxml/ControlData2DRowExpression.fxml b/alpha/MyBox/src/main/resources/fxml/ControlData2DRowExpression.fxml index b06c1f3ad..37a95fe07 100644 --- a/alpha/MyBox/src/main/resources/fxml/ControlData2DRowExpression.fxml +++ b/alpha/MyBox/src/main/resources/fxml/ControlData2DRowExpression.fxml @@ -23,7 +23,7 @@ License: Apache License Version 2.0 - + @@ -133,7 +133,7 @@ License: Apache License Version 2.0 -