io.sitoolkit.wt.gui.pres.editor.TestScriptEditorController Maven / Gradle / Ivy
package io.sitoolkit.wt.gui.pres.editor;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import org.controlsfx.control.spreadsheet.GridChange;
import org.controlsfx.control.spreadsheet.SpreadsheetView;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.input.Clipboard;
import javafx.scene.input.DataFormat;
import javafx.stage.WindowEvent;
public class TestScriptEditorController {
static final DataFormat DATAFORMAT_SPREADSHEET;
static {
DataFormat fmt;
if ((fmt = DataFormat.lookupMimeType("SpreadsheetView")) == null) {
fmt = new DataFormat("SpreadsheetView");
}
DATAFORMAT_SPREADSHEET = fmt;
}
static TestScriptEditor editor = new TestScriptEditor();
final SpreadsheetView spreadSheet;
final List myItems = new ArrayList();
public TestScriptEditorController(SpreadsheetView spreadSheet) {
this.spreadSheet = spreadSheet;
spreadSheet.getContextMenu().getItems().addAll(createMenuItems());
EventHandler defaultHandler = spreadSheet.getContextMenu().getOnShowing();
spreadSheet.getContextMenu().setOnShowing(e -> {
onContextMenuShowing(e);
defaultHandler.handle(e);
});
}
public void newTestCase(ActionEvent e) {
editor.insertTestCase(spreadSheet);
}
public void newTestStep(ActionEvent e) {
editor.insertTestStep(spreadSheet);
}
public void newTestCaseTail(ActionEvent e) {
editor.appendTestCase(spreadSheet);
}
public void newTestStepTail(ActionEvent e) {
editor.appendTestStep(spreadSheet);
}
public void pasteCase(ActionEvent e) {
Clipboard cb = Clipboard.getSystemClipboard();
if (cb.hasContent(DATAFORMAT_SPREADSHEET)) {
@SuppressWarnings("unchecked")
List changeList = (List) cb.getContent(DATAFORMAT_SPREADSHEET);
int count = editor.getCaseCount(spreadSheet, changeList);
if (count > 0) {
if (editor.insertTestCases(spreadSheet, count)) {
spreadSheet.pasteClipboard();
}
}
}
}
public void pasteStep(ActionEvent e) {
Clipboard cb = Clipboard.getSystemClipboard();
if (cb.hasContent(DATAFORMAT_SPREADSHEET)) {
@SuppressWarnings("unchecked")
List changeList = (List) cb.getContent(DATAFORMAT_SPREADSHEET);
int count = editor.getStepCount(spreadSheet, changeList);
if (count > 0) {
if (editor.insertTestSteps(spreadSheet, count)) {
spreadSheet.pasteClipboard();
}
}
}
}
public void pasteCaseTail(ActionEvent e) {
Clipboard cb = Clipboard.getSystemClipboard();
if (cb.hasContent(DATAFORMAT_SPREADSHEET)) {
@SuppressWarnings("unchecked")
List changeList = (List) cb.getContent(DATAFORMAT_SPREADSHEET);
int count = editor.getCaseCount(spreadSheet, changeList);
if (count > 0) {
editor.appendTestCases(spreadSheet, count);
spreadSheet.pasteClipboard();
}
}
}
public void pasteStepTail(ActionEvent e) {
Clipboard cb = Clipboard.getSystemClipboard();
if (cb.hasContent(DATAFORMAT_SPREADSHEET)) {
@SuppressWarnings("unchecked")
List changeList = (List) cb.getContent(DATAFORMAT_SPREADSHEET);
int count = editor.getStepCount(spreadSheet, changeList);
if (count > 0) {
editor.appendTestSteps(spreadSheet, count);
spreadSheet.pasteClipboard();
}
}
}
public void deleteCase(ActionEvent e) {
editor.deleteTestCase(spreadSheet);
}
public void deleteStep(ActionEvent e) {
editor.deleteTestStep(spreadSheet);
}
public void onContextMenuShowing(WindowEvent e) {
myItems.stream().forEach(item -> item.refreshDisable(spreadSheet));
}
private ObservableList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy