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

Commit

Permalink
create script with include
Browse files Browse the repository at this point in the history
Signed-off-by: Nassirou NAMBIEMA <[email protected]>
  • Loading branch information
Nassirou NAMBIEMA committed Dec 13, 2019
1 parent a2a5790 commit 0748458
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
package com.powsybl.gse.afs.ext.base;

import com.powsybl.afs.ProjectFile;
import com.powsybl.afs.ProjectFolder;
import com.powsybl.afs.ext.base.*;
import com.powsybl.afs.ext.base.AbstractScript;
import com.powsybl.afs.ext.base.ScriptListener;
import com.powsybl.afs.ext.base.ScriptType;
import com.powsybl.afs.ext.base.StorableScript;
import com.powsybl.commons.util.ServiceLoaderCache;
import com.powsybl.gse.spi.AutoCompletionWordsProvider;
import com.powsybl.gse.spi.GseContext;
Expand Down Expand Up @@ -174,21 +176,7 @@ private void createVirtualScript(AbstractScript script, Scene scene, GseContext
VirtualScriptCreator virtualScriptCreator = new VirtualScriptCreator(script, scene, context);
Callback<ButtonType, Boolean> resultConverter = buttonType -> buttonType == ButtonType.OK ? Boolean.TRUE : Boolean.FALSE;
Dialog<Boolean> dialog = new GseDialog<>(virtualScriptCreator.getTitle(), virtualScriptCreator, scene.getWindow(), virtualScriptCreator.okProperty().not(), resultConverter);
dialog.showAndWait().filter(result -> result).ifPresent(result -> {
virtualScriptCreator.create();
updateScript(true);

// System.out.println(scriptWithIncludes);
//System.out.println(script.readScript(true));
//codeEditor.setCode(scriptWithIncludes);


// System.out.println(script.readScript(true));
/* Optional<ProjectFolder> projectFolder = script.getParent();
projectFolder.ifPresent(folder -> {
});*/
});
dialog.showAndWait().filter(result -> result).ifPresent(result -> virtualScriptCreator.create());
}

private void setUpEditor(AbstractCodeEditor editor, List<String> completions) {
Expand Down Expand Up @@ -291,11 +279,11 @@ public Node getContent() {
return this;
}

private void updateScript(boolean withInclude) {
private void updateScript() {
scriptUpdateService = GseUtil.createService(new Task<String>() {
@Override
protected String call() {
return storableScript.readScript(withInclude);
return storableScript.readScript();
}
}, context.getExecutor());
progressIndicator.visibleProperty().bind(scriptUpdateService.runningProperty());
Expand All @@ -316,12 +304,12 @@ public SimpleBooleanProperty savedProperty() {

@Override
public void scriptUpdated() {
updateScript(false);
updateScript();
}

@Override
public void view() {
updateScript(false);
updateScript();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public VirtualScriptCreator(AbstractScript script, Scene scene, GseContext conte
this.script = Objects.requireNonNull(script);
Project project = script.getProject();
nameTextField = NameTextField.create(script);
scriptSelectionPane = new ProjectNodeSelectionPane<>(project, RESOURCE_BUNDLE.getString("ConcatenateScript"), scene.getWindow(), context, ModificationScript.class);
scriptSelectionPane = new ProjectNodeSelectionPane<>(project, RESOURCE_BUNDLE.getString("ConcatenateScript"), false, scene.getWindow(), context, (projectNode, treeModel) ->
!projectNode.getId().equals(script.getId()) && ModificationScript.class.isAssignableFrom(projectNode.getClass()));

setVgap(5);
setHgap(5);
Expand All @@ -67,14 +68,14 @@ public void create() {
ModificationScript modificationScript = scriptSelectionPane.nodeProperty().getValue();
script.addScript(modificationScript);

String scriptWithIncludesName = nameTextField.getText();
final String scriptWithInclude = script.readScript(true);
String scriptWithIncludeName = nameTextField.getText();
Optional<ProjectFolder> projectFolder = script.getParent();
projectFolder.ifPresent(folder -> folder.fileBuilder(ModificationScriptBuilder.class)
.withName(scriptWithIncludesName)
.withName(scriptWithIncludeName)
.withType(ScriptType.GROOVY)
.withContent(script.readScript(true))
.withContent(scriptWithInclude)
.build());
//return script.readScript(true);
}

public BooleanBinding okProperty() {
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);
}
}

0 comments on commit 0748458

Please sign in to comment.