From 7e47ac962970065cb92b464283c922ad688271a5 Mon Sep 17 00:00:00 2001 From: Nassirou NAMBIEMA Date: Mon, 24 Feb 2020 17:02:28 +0100 Subject: [PATCH 1/8] Reposition Rename Button bar when importing files Signed-off-by: Nassirou NAMBIEMA --- .../java/com/powsybl/gse/afs/ext/base/ImportedCaseCreator.java | 2 +- gse-util/src/main/java/com/powsybl/gse/util/GseAlerts.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ImportedCaseCreator.java b/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ImportedCaseCreator.java index 587aa882..dfb358c6 100644 --- a/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ImportedCaseCreator.java +++ b/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ImportedCaseCreator.java @@ -196,7 +196,7 @@ private void replaceNode(ProjectFolder folder, Case aCase, Scene scene) { projectNode.rename(name); } }); - } else if (buttonType.getButtonData() == ButtonBar.ButtonData.OTHER) { + } else if (buttonType.getButtonData() == ButtonBar.ButtonData.NO) { folder.getChild(name).ifPresent(projectNode -> { Optional text = GseUtil.runOnPlatformAndWait(() -> RenamePane.showAndWaitDialog(scene.getWindow(), projectNode).orElse(null)); text.ifPresent(newName -> { diff --git a/gse-util/src/main/java/com/powsybl/gse/util/GseAlerts.java b/gse-util/src/main/java/com/powsybl/gse/util/GseAlerts.java index 4c409ab8..e86a86e0 100644 --- a/gse-util/src/main/java/com/powsybl/gse/util/GseAlerts.java +++ b/gse-util/src/main/java/com/powsybl/gse/util/GseAlerts.java @@ -82,7 +82,7 @@ public static Optional showReplaceAndQuitDialog(String folderName, S alert.setHeaderText(MessageFormat.format(RESOURCE_BUNDLE.getString("ReplaceFile"), documentName)); alert.setContentText(MessageFormat.format(RESOURCE_BUNDLE.getString("FileWithTheSameNameExists"), folderName)); ButtonType replace = new ButtonType(RESOURCE_BUNDLE.getString("Replace"), ButtonBar.ButtonData.YES); - ButtonType rename = new ButtonType(RESOURCE_BUNDLE.getString("Rename"), ButtonBar.ButtonData.OTHER); + ButtonType rename = new ButtonType(RESOURCE_BUNDLE.getString("Rename"), ButtonBar.ButtonData.NO); alert.getButtonTypes().setAll(replace, rename, ButtonType.CANCEL); alert.getDialogPane().setPrefWidth(600); alert.getDialogPane().setPrefHeight(170); From 24f3d1f69d11b3487577dff98fb6616296578792 Mon Sep 17 00:00:00 2001 From: Nassirou NAMBIEMA Date: Tue, 25 Feb 2020 15:06:06 +0100 Subject: [PATCH 2/8] Remove create Contigencies menu item if visible config property is set to false Signed-off-by: Nassirou NAMBIEMA --- .../ext/base/ContingencyStoreCreatorExtension.java | 13 +++++++++++++ .../main/java/com/powsybl/gse/app/ProjectPane.java | 2 +- .../gse/spi/ProjectFileCreatorExtension.java | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ContingencyStoreCreatorExtension.java b/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ContingencyStoreCreatorExtension.java index 4a0ca1ee..92f226e5 100644 --- a/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ContingencyStoreCreatorExtension.java +++ b/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ContingencyStoreCreatorExtension.java @@ -9,6 +9,8 @@ import com.google.auto.service.AutoService; import com.powsybl.afs.ProjectFolder; import com.powsybl.afs.contingency.ContingencyStore; +import com.powsybl.commons.config.ModuleConfig; +import com.powsybl.commons.config.PlatformConfig; import com.powsybl.gse.spi.GseContext; import com.powsybl.gse.spi.ProjectFileCreator; import com.powsybl.gse.spi.ProjectFileCreatorExtension; @@ -54,6 +56,17 @@ public KeyCodeCombination getMenuKeycode() { return new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN); } + @Override + public boolean isMenuVisible() { + ModuleConfig moduleConfig = PlatformConfig.defaultConfig().getOptionalModuleConfig("contingency-creator-extension-menu").orElse(null); + if (moduleConfig == null) { + return true; + } else if (moduleConfig.hasProperty("visible")) { + return moduleConfig.getBooleanProperty("visible"); + } + return true; + } + @Override public ProjectFileCreator newCreator(ProjectFolder folder, Scene scene, GseContext context) { return new ContingencyStoreCreator(folder); diff --git a/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java b/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java index 4449171d..24d5c15f 100644 --- a/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java +++ b/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java @@ -1154,7 +1154,7 @@ private ContextMenu createFolderContextMenu(TreeItem selectedTreeItem) { items.add(createCreateFolderItem(selectedTreeItem, folder).order(99)); for (Class type : project.getFileSystem().getData().getProjectFileClasses()) { for (ProjectFileCreatorExtension creatorExtension : findCreatorExtension(type)) { - if (creatorExtension != null) { + if (creatorExtension != null && creatorExtension.isMenuVisible()) { GseMenuItem menuItem = new GseMenuItem(creatorExtension.getMenuText()); menuItem.setOrder(creatorExtension.getMenuOrder()); menuItem.setGraphic(creatorExtension.getMenuGraphic()); diff --git a/gse-spi/src/main/java/com/powsybl/gse/spi/ProjectFileCreatorExtension.java b/gse-spi/src/main/java/com/powsybl/gse/spi/ProjectFileCreatorExtension.java index a536fb11..8d2087a3 100644 --- a/gse-spi/src/main/java/com/powsybl/gse/spi/ProjectFileCreatorExtension.java +++ b/gse-spi/src/main/java/com/powsybl/gse/spi/ProjectFileCreatorExtension.java @@ -35,5 +35,9 @@ default int getMenuOrder() { KeyCodeCombination getMenuKeycode(); + default boolean isMenuVisible() { + return true; + } + ProjectFileCreator newCreator(ProjectFolder folder, Scene scene, GseContext context); } From 2d5124ac83e27c9e8753e9a6732e47ffcbaf9162 Mon Sep 17 00:00:00 2001 From: Nassirou NAMBIEMA Date: Tue, 25 Feb 2020 15:35:03 +0100 Subject: [PATCH 3/8] Add changes Signed-off-by: Nassirou NAMBIEMA --- .../java/com/powsybl/gse/afs/ext/base/ImportedCaseCreator.java | 2 +- gse-util/src/main/java/com/powsybl/gse/util/GseAlerts.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ImportedCaseCreator.java b/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ImportedCaseCreator.java index dfb358c6..587aa882 100644 --- a/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ImportedCaseCreator.java +++ b/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ImportedCaseCreator.java @@ -196,7 +196,7 @@ private void replaceNode(ProjectFolder folder, Case aCase, Scene scene) { projectNode.rename(name); } }); - } else if (buttonType.getButtonData() == ButtonBar.ButtonData.NO) { + } else if (buttonType.getButtonData() == ButtonBar.ButtonData.OTHER) { folder.getChild(name).ifPresent(projectNode -> { Optional text = GseUtil.runOnPlatformAndWait(() -> RenamePane.showAndWaitDialog(scene.getWindow(), projectNode).orElse(null)); text.ifPresent(newName -> { diff --git a/gse-util/src/main/java/com/powsybl/gse/util/GseAlerts.java b/gse-util/src/main/java/com/powsybl/gse/util/GseAlerts.java index e86a86e0..4c409ab8 100644 --- a/gse-util/src/main/java/com/powsybl/gse/util/GseAlerts.java +++ b/gse-util/src/main/java/com/powsybl/gse/util/GseAlerts.java @@ -82,7 +82,7 @@ public static Optional showReplaceAndQuitDialog(String folderName, S alert.setHeaderText(MessageFormat.format(RESOURCE_BUNDLE.getString("ReplaceFile"), documentName)); alert.setContentText(MessageFormat.format(RESOURCE_BUNDLE.getString("FileWithTheSameNameExists"), folderName)); ButtonType replace = new ButtonType(RESOURCE_BUNDLE.getString("Replace"), ButtonBar.ButtonData.YES); - ButtonType rename = new ButtonType(RESOURCE_BUNDLE.getString("Rename"), ButtonBar.ButtonData.NO); + ButtonType rename = new ButtonType(RESOURCE_BUNDLE.getString("Rename"), ButtonBar.ButtonData.OTHER); alert.getButtonTypes().setAll(replace, rename, ButtonType.CANCEL); alert.getDialogPane().setPrefWidth(600); alert.getDialogPane().setPrefHeight(170); From 4e7a7fba49621fbc47783fdc1e59cfbe0d6c0695 Mon Sep 17 00:00:00 2001 From: Nassirou NAMBIEMA Date: Thu, 27 Feb 2020 11:45:54 +0100 Subject: [PATCH 4/8] Add changes Signed-off-by: Nassirou NAMBIEMA --- .../base/ContingencyStoreCreatorExtension.java | 12 ++---------- .../java/com/powsybl/gse/app/ProjectPane.java | 15 ++++++++++++++- .../gse/spi/ProjectFileCreatorExtension.java | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ContingencyStoreCreatorExtension.java b/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ContingencyStoreCreatorExtension.java index 92f226e5..fff7a166 100644 --- a/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ContingencyStoreCreatorExtension.java +++ b/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ContingencyStoreCreatorExtension.java @@ -9,8 +9,6 @@ import com.google.auto.service.AutoService; import com.powsybl.afs.ProjectFolder; import com.powsybl.afs.contingency.ContingencyStore; -import com.powsybl.commons.config.ModuleConfig; -import com.powsybl.commons.config.PlatformConfig; import com.powsybl.gse.spi.GseContext; import com.powsybl.gse.spi.ProjectFileCreator; import com.powsybl.gse.spi.ProjectFileCreatorExtension; @@ -57,14 +55,8 @@ public KeyCodeCombination getMenuKeycode() { } @Override - public boolean isMenuVisible() { - ModuleConfig moduleConfig = PlatformConfig.defaultConfig().getOptionalModuleConfig("contingency-creator-extension-menu").orElse(null); - if (moduleConfig == null) { - return true; - } else if (moduleConfig.hasProperty("visible")) { - return moduleConfig.getBooleanProperty("visible"); - } - return true; + public String getModuleConfigName() { + return "contingency-creator-extension-menu"; } @Override diff --git a/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java b/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java index 24d5c15f..70d3152e 100644 --- a/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java +++ b/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java @@ -13,6 +13,8 @@ import com.powsybl.afs.storage.AppStorage; import com.powsybl.afs.storage.NodeInfo; import com.powsybl.afs.storage.events.*; +import com.powsybl.commons.config.ModuleConfig; +import com.powsybl.commons.config.PlatformConfig; import com.powsybl.commons.util.ServiceLoaderCache; import com.powsybl.gse.copy_paste.afs.CopyManager; import com.powsybl.gse.copy_paste.afs.CopyService; @@ -1154,7 +1156,7 @@ private ContextMenu createFolderContextMenu(TreeItem selectedTreeItem) { items.add(createCreateFolderItem(selectedTreeItem, folder).order(99)); for (Class type : project.getFileSystem().getData().getProjectFileClasses()) { for (ProjectFileCreatorExtension creatorExtension : findCreatorExtension(type)) { - if (creatorExtension != null && creatorExtension.isMenuVisible()) { + if (creatorExtension != null && isCreatorExtensionAuthorized(creatorExtension)) { GseMenuItem menuItem = new GseMenuItem(creatorExtension.getMenuText()); menuItem.setOrder(creatorExtension.getMenuOrder()); menuItem.setGraphic(creatorExtension.getMenuGraphic()); @@ -1184,6 +1186,17 @@ private ContextMenu createFolderContextMenu(TreeItem selectedTreeItem) { return contextMenu; } + private static boolean isCreatorExtensionAuthorized(ProjectFileCreatorExtension creatorExtension) { + String moduleConfigName = creatorExtension.getModuleConfigName(); + if (moduleConfigName != null) { + ModuleConfig moduleConfig = PlatformConfig.defaultConfig().getOptionalModuleConfig(moduleConfigName).orElse(null); + if (moduleConfig != null && moduleConfig.hasProperty("visible")) { + return moduleConfig.getBooleanProperty("visible"); + } + } + return true; + } + public void dispose() { taskItems.dispose(); closeViews(); diff --git a/gse-spi/src/main/java/com/powsybl/gse/spi/ProjectFileCreatorExtension.java b/gse-spi/src/main/java/com/powsybl/gse/spi/ProjectFileCreatorExtension.java index 8d2087a3..b9f51ba5 100644 --- a/gse-spi/src/main/java/com/powsybl/gse/spi/ProjectFileCreatorExtension.java +++ b/gse-spi/src/main/java/com/powsybl/gse/spi/ProjectFileCreatorExtension.java @@ -35,8 +35,8 @@ default int getMenuOrder() { KeyCodeCombination getMenuKeycode(); - default boolean isMenuVisible() { - return true; + default String getModuleConfigName() { + return null; } ProjectFileCreator newCreator(ProjectFolder folder, Scene scene, GseContext context); From b0d629ab7aa5d629179852745ab7c0753752ef7c Mon Sep 17 00:00:00 2001 From: Nassirou NAMBIEMA Date: Thu, 27 Feb 2020 14:01:54 +0100 Subject: [PATCH 5/8] Refactor code Signed-off-by: Nassirou NAMBIEMA --- .../java/com/powsybl/gse/app/ProjectPane.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java b/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java index 70d3152e..4ada8ffe 100644 --- a/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java +++ b/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java @@ -89,6 +89,7 @@ public class ProjectPane extends Tab { private final Map lCache = new HashMap<>(); private final CopyManager localArchiveManager = CopyManager.getInstance(); private final AppStorageListener appStorageListener; + private List blackListExtensions = new ArrayList<>(); public ProjectPane(Scene scene, Project project, GseContext context) { this.project = Objects.requireNonNull(project); @@ -99,6 +100,12 @@ public ProjectPane(Scene scene, Project project, GseContext context) { copyService = initCopyService(); treeView = createProjectTreeview(); + ModuleConfig extensionsModuleConfig = PlatformConfig.defaultConfig().getOptionalModuleConfig("extensions").orElse(null); + if (extensionsModuleConfig != null && extensionsModuleConfig.hasProperty("disabled")) { + String disabled = extensionsModuleConfig.getStringProperty("disabled"); + blackListExtensions.addAll(Arrays.asList(disabled.split(","))); + } + appStorageListener = eventList -> eventList.getEvents().forEach(this::handleEvent); project.getFileSystem().getEventBus().addListener(appStorageListener); @@ -1186,15 +1193,8 @@ private ContextMenu createFolderContextMenu(TreeItem selectedTreeItem) { return contextMenu; } - private static boolean isCreatorExtensionAuthorized(ProjectFileCreatorExtension creatorExtension) { - String moduleConfigName = creatorExtension.getModuleConfigName(); - if (moduleConfigName != null) { - ModuleConfig moduleConfig = PlatformConfig.defaultConfig().getOptionalModuleConfig(moduleConfigName).orElse(null); - if (moduleConfig != null && moduleConfig.hasProperty("visible")) { - return moduleConfig.getBooleanProperty("visible"); - } - } - return true; + private boolean isCreatorExtensionAuthorized(ProjectFileCreatorExtension creatorExtension) { + return !blackListExtensions.contains(creatorExtension.getClass().getName()); } public void dispose() { From 842d385f249474943258f53259d66b658be1e196 Mon Sep 17 00:00:00 2001 From: Nassirou NAMBIEMA Date: Thu, 27 Feb 2020 14:15:29 +0100 Subject: [PATCH 6/8] delete useless code Signed-off-by: Nassirou NAMBIEMA --- .../gse/afs/ext/base/ContingencyStoreCreatorExtension.java | 5 ----- .../com/powsybl/gse/spi/ProjectFileCreatorExtension.java | 4 ---- 2 files changed, 9 deletions(-) diff --git a/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ContingencyStoreCreatorExtension.java b/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ContingencyStoreCreatorExtension.java index fff7a166..4a0ca1ee 100644 --- a/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ContingencyStoreCreatorExtension.java +++ b/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ContingencyStoreCreatorExtension.java @@ -54,11 +54,6 @@ public KeyCodeCombination getMenuKeycode() { return new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN); } - @Override - public String getModuleConfigName() { - return "contingency-creator-extension-menu"; - } - @Override public ProjectFileCreator newCreator(ProjectFolder folder, Scene scene, GseContext context) { return new ContingencyStoreCreator(folder); diff --git a/gse-spi/src/main/java/com/powsybl/gse/spi/ProjectFileCreatorExtension.java b/gse-spi/src/main/java/com/powsybl/gse/spi/ProjectFileCreatorExtension.java index b9f51ba5..a536fb11 100644 --- a/gse-spi/src/main/java/com/powsybl/gse/spi/ProjectFileCreatorExtension.java +++ b/gse-spi/src/main/java/com/powsybl/gse/spi/ProjectFileCreatorExtension.java @@ -35,9 +35,5 @@ default int getMenuOrder() { KeyCodeCombination getMenuKeycode(); - default String getModuleConfigName() { - return null; - } - ProjectFileCreator newCreator(ProjectFolder folder, Scene scene, GseContext context); } From e20ee18b14cca58d41e99a2e2d5635ed18f9b54a Mon Sep 17 00:00:00 2001 From: Nassirou NAMBIEMA Date: Thu, 27 Feb 2020 15:01:09 +0100 Subject: [PATCH 7/8] Use StringListPtoperty instead of StringProperty Signed-off-by: Nassirou NAMBIEMA --- gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java b/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java index 4ada8ffe..8b58421e 100644 --- a/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java +++ b/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java @@ -102,8 +102,8 @@ public ProjectPane(Scene scene, Project project, GseContext context) { ModuleConfig extensionsModuleConfig = PlatformConfig.defaultConfig().getOptionalModuleConfig("extensions").orElse(null); if (extensionsModuleConfig != null && extensionsModuleConfig.hasProperty("disabled")) { - String disabled = extensionsModuleConfig.getStringProperty("disabled"); - blackListExtensions.addAll(Arrays.asList(disabled.split(","))); + List disabledExtensions = extensionsModuleConfig.getStringListProperty("disabled"); + blackListExtensions.addAll(disabledExtensions); } appStorageListener = eventList -> eventList.getEvents().forEach(this::handleEvent); From 897b62bcf579d3c05c66e9827c5105a61c566948 Mon Sep 17 00:00:00 2001 From: Nassirou NAMBIEMA Date: Thu, 27 Feb 2020 15:30:55 +0100 Subject: [PATCH 8/8] Change method name Signed-off-by: Nassirou NAMBIEMA --- gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java b/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java index 8b58421e..b1939349 100644 --- a/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java +++ b/gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java @@ -1163,7 +1163,7 @@ private ContextMenu createFolderContextMenu(TreeItem selectedTreeItem) { items.add(createCreateFolderItem(selectedTreeItem, folder).order(99)); for (Class type : project.getFileSystem().getData().getProjectFileClasses()) { for (ProjectFileCreatorExtension creatorExtension : findCreatorExtension(type)) { - if (creatorExtension != null && isCreatorExtensionAuthorized(creatorExtension)) { + if (creatorExtension != null && isCreatorExtensionEnabled(creatorExtension)) { GseMenuItem menuItem = new GseMenuItem(creatorExtension.getMenuText()); menuItem.setOrder(creatorExtension.getMenuOrder()); menuItem.setGraphic(creatorExtension.getMenuGraphic()); @@ -1193,7 +1193,7 @@ private ContextMenu createFolderContextMenu(TreeItem selectedTreeItem) { return contextMenu; } - private boolean isCreatorExtensionAuthorized(ProjectFileCreatorExtension creatorExtension) { + private boolean isCreatorExtensionEnabled(ProjectFileCreatorExtension creatorExtension) { return !blackListExtensions.contains(creatorExtension.getClass().getName()); }