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

Commit

Permalink
move a contingency element in cse by drag and drop
Browse files Browse the repository at this point in the history
  • Loading branch information
ralambotianamio committed Oct 24, 2018
1 parent 918ad50 commit 99230b2
Showing 1 changed file with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
import com.powsybl.gse.spi.Savable;
import com.powsybl.gse.util.EquipmentInfo;
import com.powsybl.gse.util.Glyph;
import com.powsybl.gse.util.IdAndName;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.ListChangeListener;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.input.Dragboard;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.input.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.text.Text;

Expand Down Expand Up @@ -50,6 +48,9 @@ private final class ContingencyTreeCell extends TreeCell<Object> {

private ContingencyTreeCell() {
setOnDragDropped(event -> {
if (event.getGestureSource() == contingencyTree) {
remove();
}
Dragboard db = event.getDragboard();
boolean success = false;
if (db.hasContent(EquipmentInfo.DATA_FORMAT)) {
Expand Down Expand Up @@ -129,13 +130,29 @@ private ContingencyElement createElement(EquipmentInfo equipmentInfo) {

case "LINE":
case "TWO_WINDINGS_TRANSFORMER":
case "BRANCH":
return new BranchContingency(equipmentInfo.getIdAndName().getId());

default:
return null;
}
}

private EquipmentInfo createEquipmentInfo(ContingencyElement contingencyElement) {
ContingencyElementType type = contingencyElement.getType();
if (type.equals(ContingencyElementType.BUSBAR_SECTION)) {
return new EquipmentInfo(new IdAndName(contingencyElement.getId(), contingencyElement.getId()), "BUSBAR_SECTION");
} else if (type.equals(ContingencyElementType.GENERATOR)) {
return new EquipmentInfo(new IdAndName(contingencyElement.getId(), contingencyElement.getId()), "GENERATOR");
} else if (type.equals(ContingencyElementType.HVDC_LINE)) {
return new EquipmentInfo(new IdAndName(contingencyElement.getId(), contingencyElement.getId()), "HVDC_LINE");
} else if (type.equals(ContingencyElementType.BRANCH)) {
return new EquipmentInfo(new IdAndName(contingencyElement.getId(), contingencyElement.getId()), "BRANCH");
} else {
return null;
}
}

public ContingencyStoreEditor(ContingencyStore store) {
this.store = Objects.requireNonNull(store);

Expand All @@ -155,8 +172,7 @@ public ContingencyStoreEditor(ContingencyStore store) {
contingencyTree.setShowRoot(false);
contingencyTree.setOnDragOver(event -> {
Dragboard db = event.getDragboard();
if (event.getGestureSource() != contingencyTree &&
db.hasContent(EquipmentInfo.DATA_FORMAT)) {
if (db.hasContent(EquipmentInfo.DATA_FORMAT)) {
EquipmentInfo equipmentInfo = (EquipmentInfo) db.getContent(EquipmentInfo.DATA_FORMAT);
ContingencyElement element = createElement(equipmentInfo);
if (element != null) {
Expand All @@ -166,6 +182,17 @@ public ContingencyStoreEditor(ContingencyStore store) {
event.consume();
});

contingencyTree.setOnDragDetected(event -> {
TreeItem<Object> item = contingencyTree.getSelectionModel().getSelectedItem();
if (item.getValue() instanceof ContingencyElement) {
Dragboard db = contingencyTree.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
content.put(EquipmentInfo.DATA_FORMAT, createEquipmentInfo((ContingencyElement) item.getValue()));
db.setContent(content);
event.consume();
}
});

ContextMenu contingencyMenu = createContingencyMenu();
ContextMenu contingencyElementMenu = createContingencyElementMenu();

Expand Down

0 comments on commit 99230b2

Please sign in to comment.