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

Commit

Permalink
Merge branch 'master' into move_contingencyelements
Browse files Browse the repository at this point in the history
  • Loading branch information
miovd authored Oct 25, 2018
2 parents 99230b2 + b47fd95 commit 4682891
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.powsybl.gse.util.Glyph;
import com.powsybl.gse.util.IdAndName;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.ListChangeListener;
import javafx.scene.Node;
Expand Down Expand Up @@ -257,13 +258,15 @@ private void rename() {
dialog.setTitle(RESOURCE_BUNDLE.getString("RenameContingency"));
dialog.setHeaderText(RESOURCE_BUNDLE.getString("NewName"));
dialog.setContentText(RESOURCE_BUNDLE.getString("Name"));
TextField inputField = dialog.getEditor();
BooleanBinding isInvalid = Bindings.createBooleanBinding(() -> inputField.getText().equals(contingency.getId()) || inputField.getText().isEmpty(),
inputField.textProperty());
dialog.getDialogPane().lookupButton(ButtonType.OK).disableProperty().bind(isInvalid);
Optional<String> result = dialog.showAndWait();
result.ifPresent(newName -> {
if (!newName.isEmpty() && !newName.equals(contingency.getId())) {
contingency.setId(newName);
contingencyTree.refresh();
saved.set(false);
}
contingency.setId(newName);
contingencyTree.refresh();
saved.set(false);
});
}

Expand Down
25 changes: 10 additions & 15 deletions gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,12 @@ private TabPaneBehavior getBehavior() {
}
}

private static class MoveContext {
private Object source;
private TreeItem sourceTreeItem;
private TreeItem sourceparentTreeItem;
}

private int counter;

private boolean success;

private MoveContext moveContext;
private DragAndDropMove dragAndDropMove;

private final Project project;

Expand Down Expand Up @@ -293,7 +288,7 @@ private void setsForObjects(Object value, TreeCell<Object> treeCell, TreeItem<Ob
}

private void dragOverEvent(DragEvent event, Object item, TreeItem<Object> treeItem, TreeCell<Object> treeCell) {
if (item instanceof ProjectFolder && item != moveContext.source) {
if (item instanceof ProjectFolder && item != dragAndDropMove.getSource()) {
int count = 0;
treeItemChildrenSize(treeItem, count);
textFillColor(treeCell);
Expand All @@ -316,10 +311,10 @@ private int getCounter() {
}

private void dragDetectedEvent(Object value, TreeItem<Object> treeItem, MouseEvent event) {
moveContext = new MoveContext();
moveContext.source = value;
moveContext.sourceTreeItem = treeItem;
moveContext.sourceparentTreeItem = moveContext.sourceTreeItem.getParent();
dragAndDropMove = new DragAndDropMove();
dragAndDropMove.setSource(value);
dragAndDropMove.setSourceTreeItem(treeItem);

if (value instanceof ProjectNode && treeItem != treeView.getRoot()) {
Dragboard db = treeView.startDragAndDrop(TransferMode.ANY);
ClipboardContent cb = new ClipboardContent();
Expand All @@ -330,14 +325,14 @@ private void dragDetectedEvent(Object value, TreeItem<Object> treeItem, MouseEve
}

private void dragDroppedEvent(Object value, TreeItem<Object> treeItem, DragEvent event, ProjectNode projectNode) {
if (value instanceof ProjectFolder && value != moveContext.source) {
if (value instanceof ProjectFolder && value != dragAndDropMove.getSource()) {
ProjectFolder projectFolder = (ProjectFolder) projectNode;
int count = 0;
success = false;
treeItemChildrenSize(treeItem, count);
accepTransferDrag(projectFolder, success);
event.setDropCompleted(success);
refresh(moveContext.sourceparentTreeItem);
refresh(dragAndDropMove.getSourceTreeItem().getParent());
refresh(treeItem);
event.consume();
}
Expand All @@ -351,7 +346,7 @@ private void treeItemChildrenSize(TreeItem<Object> treeItem, int compte) {
for (ProjectNode node : treeItemFolder.getChildren()) {
if (node == null) {
break;
} else if (node.getName().equals(moveContext.source.toString())) {
} else if (node.getName().equals(dragAndDropMove.getSource().toString())) {
counter++;
}
}
Expand All @@ -364,7 +359,7 @@ private void accepTransferDrag(ProjectFolder projectFolder, boolean s) {
if (getCounter() >= 1) {
nameAlreadyExistsAlert();
} else if (getCounter() < 1) {
ProjectNode monfichier = (ProjectNode) moveContext.source;
ProjectNode monfichier = (ProjectNode) dragAndDropMove.getSource();
monfichier.moveTo(projectFolder);
success = true;
}
Expand Down
31 changes: 31 additions & 0 deletions gse-util/src/main/java/com/powsybl/gse/util/DragAndDropMove.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2017, 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.util;

import javafx.scene.control.TreeItem;

public class DragAndDropMove {
private Object source;
private TreeItem sourceTreeItem;


public Object getSource() {
return source;
}

public void setSource(Object source) {
this.source = source;
}

public TreeItem getSourceTreeItem() {
return sourceTreeItem;
}

public void setSourceTreeItem(TreeItem sourceTreeItem) {
this.sourceTreeItem = sourceTreeItem;
}
}
25 changes: 9 additions & 16 deletions gse-util/src/main/java/com/powsybl/gse/util/NodeChooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ public class NodeChooser<N, F extends N, D extends N, T extends N> extends GridP

private static final String ICON_SIZE = "1.1em";

private static class MoveContext {
private Object source;
private TreeItem sourceTreeItem;
private TreeItem sourceparentTreeItem;
}

private MoveContext moveContext;
private DragAndDropMove dragAndDropMove;
private int counter;
private boolean success;

Expand Down Expand Up @@ -459,7 +453,7 @@ private void textFillColor(TreeTableCell<N, N> treetableCell) {
}

private void dragOverEvent(DragEvent event, Object item, TreeTableRow<N> treeTableRow, TreeTableCell<N, N> treetableCell) {
if (item instanceof Folder && item != moveContext.source) {
if (item instanceof Folder && item != dragAndDropMove.getSource()) {
int count = 0;
treeItemChildrenSize(treeTableRow.getTreeItem(), count);
textFillColor(treetableCell);
Expand All @@ -473,10 +467,9 @@ public int getCounter() {
}

private void dragDetectedEvent(N value, TreeItem<N> treeItem, MouseEvent event) {
moveContext = new MoveContext();
moveContext.source = value;
moveContext.sourceTreeItem = treeItem;
moveContext.sourceparentTreeItem = moveContext.sourceTreeItem.getParent();
dragAndDropMove = new DragAndDropMove();
dragAndDropMove.setSource(value);
dragAndDropMove.setSourceTreeItem(treeItem);
if (value instanceof Project && treeItem != tree.getRoot()) {
Dragboard db = tree.startDragAndDrop(TransferMode.ANY);
ClipboardContent cb = new ClipboardContent();
Expand All @@ -487,14 +480,14 @@ private void dragDetectedEvent(N value, TreeItem<N> treeItem, MouseEvent event)
}

private void dragDroppedEvent(Object value, TreeItem<N> treeItem, DragEvent event, Node node) {
if (value instanceof Folder && value != moveContext.source) {
if (value instanceof Folder && value != dragAndDropMove.getSource()) {
Folder folder = (Folder) node;
int count = 0;
success = false;
treeItemChildrenSize(treeItem, count);
accepTransferDrag(folder, success);
event.setDropCompleted(success);
refreshTreeItem(moveContext.sourceparentTreeItem);
refreshTreeItem(dragAndDropMove.getSourceTreeItem().getParent());
refreshTreeItem(treeItem);
event.consume();
}
Expand All @@ -515,7 +508,7 @@ private void treeItemChildrenSize(TreeItem<N> treeItem, int compte) {
for (Node node : folder.getChildren()) {
if (node == null) {
break;
} else if (node.getName().equals(moveContext.source.toString())) {
} else if (node.getName().equals(dragAndDropMove.getSource().toString())) {
counter++;
}
}
Expand All @@ -528,7 +521,7 @@ private void accepTransferDrag(Folder folder, boolean s) {
if (getCounter() >= 1) {
nameAlreadyExistsAlert();
} else if (getCounter() < 1) {
Project monfichier = (Project) moveContext.source;
Project monfichier = (Project) dragAndDropMove.getSource();
monfichier.moveTo(folder);
success = true;
}
Expand Down

0 comments on commit 4682891

Please sign in to comment.