Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Create virtual script pane #249

Open
wants to merge 12 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import com.google.auto.service.AutoService;
import com.powsybl.afs.ProjectFile;
import com.powsybl.afs.ext.base.StorableScript;
import com.powsybl.afs.ext.base.AbstractScript;
import com.powsybl.gse.spi.GseContext;
import com.powsybl.gse.spi.ProjectFileViewer;
import com.powsybl.gse.spi.ProjectFileViewerExtension;
Expand All @@ -33,7 +33,7 @@ public Class<ProjectFile> getProjectFileType() {

@Override
public Class<?> getAdditionalType() {
return StorableScript.class;
return AbstractScript.class;
}

@Override
Expand All @@ -53,7 +53,7 @@ public boolean isMenuEnabled(ProjectFile file) {

@Override
public ProjectFileViewer newViewer(ProjectFile file, Scene scene, GseContext context) {
return new ModificationScriptEditor((StorableScript) file, scene, context);
return new ModificationScriptEditor((AbstractScript) file, scene, context);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright (c) 2019, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.gse.afs.ext.base;

import com.powsybl.afs.Project;
import com.powsybl.afs.ext.base.AbstractScript;
import com.powsybl.afs.ext.base.GenericScript;
import com.powsybl.gse.spi.GseContext;
import com.powsybl.gse.util.ProjectNodeSelectionPane;
import javafx.beans.binding.BooleanBinding;
import javafx.scene.Scene;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;

import java.util.Objects;
import java.util.ResourceBundle;

/**
* @author Nassirou Nambiema <nassirou.nambiena at rte-france.com>
*/
public class VirtualScriptCreator extends GridPane {

protected static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle("lang.VirtualScriptCreator");

private final AbstractScript script;

private final ProjectNodeSelectionPane<AbstractScript> scriptSelectionPane;

public VirtualScriptCreator(AbstractScript script, Scene scene, GseContext context) {
this.script = Objects.requireNonNull(script);
Project project = script.getProject();
scriptSelectionPane = new ProjectNodeSelectionPane<>(project, RESOURCE_BUNDLE.getString("ConcatenateScript"), false, scene.getWindow(), context, (projectNode, treeModel) ->
!projectNode.getId().equals(script.getId()) && (script.getClass().isAssignableFrom(projectNode.getClass()) || GenericScript.class.isAssignableFrom(projectNode.getClass())));

setVgap(5);
setHgap(5);
setPrefWidth(500);
ColumnConstraints column0 = new ColumnConstraints();
ColumnConstraints column1 = new ColumnConstraints();
column1.setHgrow(Priority.ALWAYS);
getColumnConstraints().addAll(column0, column1);
add(scriptSelectionPane.getLabel(), 0, 0);
add(scriptSelectionPane.getTextField(), 1, 0);
add(scriptSelectionPane.getButton(), 2, 0);
}

public void create() {
AbstractScript abstractScript = scriptSelectionPane.nodeProperty().getValue();
if (abstractScript instanceof GenericScript) {
script.addGenericScript((GenericScript) abstractScript);
} else {
script.addScript(abstractScript);
}
}

public BooleanBinding okProperty() {
return scriptSelectionPane.nodeProperty().isNotNull();
}

public String getTitle() {
return RESOURCE_BUNDLE.getString("CreateVirtualScript");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CreateModificationScript=Create a modification script
Console=Console
EditScript=Edit script
IncludedScripts=Included scripts
ScriptName=Script name
TabSize=Tab size
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CreateModificationScript=Cr�er un script de modification/configuration
Console=Console
EditScript=Editer le script
IncludedScripts=Scripts inclus
ScriptName=Nom du script
TabSize=Taille Tabulation
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ConcatenateScript=Concatenate Script
CreateVirtualScript=Create virtual script
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ConcatenateScript=Ajout de Script
CreateVirtualScript=Cr�er un script virtuel
8 changes: 8 additions & 0 deletions gse-util/src/main/java/com/powsybl/gse/util/GseAlerts.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public final class GseAlerts {
private GseAlerts() {
}

public static Optional<ButtonType> showRemoveConfirmationAlert(String removeElementName) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
final String remove = RESOURCE_BUNDLE.getString("Remove");
alert.setTitle(remove);
alert.setHeaderText(remove + " \'" + removeElementName + "\' ?");
return alert.showAndWait();
}

public static void showDraggingError() {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(RESOURCE_BUNDLE.getString("DragError"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
package com.powsybl.gse.util;

import com.powsybl.afs.Project;
import com.powsybl.afs.ProjectFile;
import com.powsybl.afs.ProjectFolder;
import com.powsybl.afs.ProjectNode;
import com.powsybl.gse.spi.GseContext;
import javafx.stage.Window;

import java.util.function.BiPredicate;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
Expand All @@ -23,5 +27,9 @@ public ProjectNodeSelectionPane(Project project, String label, Window window, Gs
public ProjectNodeSelectionPane(Project project, String label, boolean mandatory, Window window, GseContext context, Class<T> filter, Class<?>... otherFilters) {
super(label, () -> NodeChooser.showAndWaitDialog(project, window, context, filter, otherFilters), mandatory, context);
}

public ProjectNodeSelectionPane(Project project, String label, boolean mandatory, Window window, GseContext context, BiPredicate<ProjectNode, NodeChooser.TreeModel<ProjectNode, ProjectFile, ProjectFolder>> filter) {
super(label, () -> NodeChooser.showAndWaitDialog(project, window, context, filter), mandatory, context);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public abstract class AbstractCodeEditor extends MasterDetailPane {

public abstract void setTabSize(int size);

public abstract void setEditable(boolean isEditable);

public abstract void setCode(String code);

public abstract String getCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javafx.beans.value.ObservableValue;
import javafx.geometry.Side;
import javafx.scene.input.*;
import javafx.scene.layout.Background;
import javafx.scene.layout.VBox;
import javafx.util.Pair;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -561,6 +562,12 @@ private void onDragDropped(DragEvent event) {
event.consume();
}

@Override
public void setEditable(boolean isEditable) {
pl-buiquang marked this conversation as resolved.
Show resolved Hide resolved
codeArea.setEditable(isEditable);
codeArea.setBackground(Background.EMPTY);
}

public void setCode(String code) {
codeArea.clear();
codeArea.replaceText(0, 0, code);
Expand Down
1 change: 1 addition & 0 deletions gse-util/src/main/resources/lang/GseAlerts.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ FileExists=The file name already exists
FileWillBeDeleted=File %s will be deleted
FilesWillBeDeleted=Files %s will be deleted
FileWithTheSameNameExists=A file with the same name already exists in \"{0}\". Replace it will overwrite its contents
Remove=Remove
Rename=Rename
Replace=Replace
ReplaceFile=Replace the file \"{0}\" ?
Expand Down
1 change: 1 addition & 0 deletions gse-util/src/main/resources/lang/GseAlerts_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ FileExists=Le nom du fichier existe d
FileWillBeDeleted=Le fichier %s sera supprim�
FilesWillBeDeleted=Les fichiers %s seront supprim�s
FileWithTheSameNameExists=Un fichier portant le m�me nom existe d�j� dans \"{0}\". Le remplacer �crasera son contenu
Remove=Supprimer
Rename=Renommer
Replace=Remplacer
ReplaceFile=Remplacer le fichier \"{0}\" ?
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<slf4j.version>1.7.22</slf4j.version>
<tiwulfx.version>2.0</tiwulfx.version>

<powsyblafs.version>3.1.0</powsyblafs.version>
<powsyblafs.version>3.2.0-SNAPSHOT</powsyblafs.version>
<powsyblcore.version>3.1.0</powsyblcore.version>

</properties>
Expand Down