/** * When the dragging is detected, we place the content of the LabelCell * in the DragBoard. */ void setOnDragDetected() { setOnDragDetected(event -> { boolean isParentTask = getTreeItem().getParent().equals(root); boolean isEmpty = getTreeItem().getValue().getText().equals(""); if (!isEmpty && isParentTask) { Dragboard db = startDragAndDrop(TransferMode.MOVE); ClipboardContent content = new ClipboardContent(); content.put(controller.DATA_FORMAT, getTreeItem() .getValue()); db.setContent(content); } event.consume(); }); }
/** * Handle mouse drop events * * @param e */ private void mouseDragDropped(final DragEvent e) { final Dragboard db = e.getDragboard(); boolean success = false; if (db.hasFiles()) { success = true; boolean ctrlKeyPressed = popOver.isCtrlKeyPressed(); boolean altKeyPressed = popOver.isAltKeyPressed(); popOver.notifyDragEventListener(new DropzoneDragEvent(e, ctrlKeyPressed, altKeyPressed)); } e.setDropCompleted(success); e.consume(); }
@FXML private void initialize() throws IOException { root.getChildren().addListener((ListChangeListener<? super Node>) change -> { while (change.next()) { for (Node node : change.getAddedSubList()) { if (node instanceof WidgetGallery.WidgetGalleryItem) { WidgetGallery.WidgetGalleryItem galleryItem = (WidgetGallery.WidgetGalleryItem) node; galleryItem.setOnDragDetected(event -> { Dragboard dragboard = galleryItem.startDragAndDrop(TransferMode.COPY); // TODO type safety ClipboardContent clipboard = new ClipboardContent(); clipboard.put(DataFormats.widgetType, galleryItem.getWidget().getName()); dragboard.setContent(clipboard); event.consume(); }); } } } }); }
/** * Adds to the letter the possibility to be dragged on another element. * * @param letterElement The element to be dragged * @param letter The corresponding letter object */ public static void makeLetterDraggable(Node letterElement, LetterInterface letter) { // When an user starts to drag a letter letterElement.setOnDragDetected(event -> { Dragboard dragboard = letterElement.startDragAndDrop(TransferMode.ANY); dragboard.setDragView(letterElement.snapshot(null, null)); letterElement.setVisible(false); ClipboardContent clipboardContent = new ClipboardContent(); clipboardContent.put(LetterInterface.DATA_FORMAT, letter); dragboard.setContent(clipboardContent); event.consume(); }); // When the user has dropped the letter letterElement.setOnDragDone(event -> letterElement.setVisible(true)); }
public Pane decorate(Pane pane) { pane.setOnDragOver(evt -> { if (evt.getGestureSource() != pane && evt.getDragboard().hasString()) { evt.acceptTransferModes(TransferMode.ANY); } evt.consume(); }); pane.setOnDragDropped(evt -> { Dragboard db = evt.getDragboard(); boolean success = false; if (db.hasString()) { // Create a button and add to pane if (!locked) { addButton(db.getString(), pane, evt.getScreenX(), evt.getScreenY()); } success = true; } // Let the source know whether the string was dropped successfully evt.setDropCompleted(success); evt.consume(); }); return pane; }
@FXML private void handleDropped(DragEvent event) { // ドラッグボードを取得 Dragboard board = event.getDragboard(); if (board.hasFiles()) { board.getFiles().stream().forEach((f) -> { if (f.isDirectory()) { List<String> filePathList = new ArrayList<>(); getFileRecursion(filePathList, f.getAbsolutePath()).stream().filter(s -> isTextFile(s)).collect(Collectors.toList()).forEach(s -> fileList.getItems().add(new Label(s))); } else { if (isTextFile(f.getAbsolutePath())) fileList.getItems().add(new Label(f.getAbsolutePath())); } }); // ドロップ受け入れ event.setDropCompleted(true); } else { // ファイル以外なら // ドロップ受け入れ拒否 event.setDropCompleted(false); } }
private void targetSetOnDragDropped(ScreenMap target, DragEvent e) { Dragboard db = e.getDragboard(); boolean success = false; if (e.getDragboard().hasImage()) { String imageName = db.getString(); Point2D point = target.sceneToLocal(e.getSceneX(), e.getSceneY()); GamePoint gameCoords = new GamePoint(point.getX()/target.getScreenWidth(), point.getY()/target.getScreenHeight()); for (Pair<String, Image> p : myScreenObjects.keySet()) { String iName = p.getKey(); if (imageName.equals(iName)) { XStreamHandler xstream = new XStreamHandler(); File tempSpriteFile = new File("data/tempSprites/tempSprite.xml"); xstream.saveToFile(myScreenObjects.get(p), tempSpriteFile); SpriteMakerModel xmlSprite = (SpriteMakerModel) xstream.getAttributeFromFile(tempSpriteFile); xmlSprite.addComponent(new Position(gameCoords, 0)); //heading 0 because all sprites default to this myModel.addBackgroundTile(xmlSprite); break; } } success = true; } e.setDropCompleted(success); e.consume(); }
/** * Handle dropped files to editor. */ @FXThread private void dragDropped(@NotNull final DragEvent dragEvent) { final Dragboard dragboard = dragEvent.getDragboard(); final List<File> files = unsafeCast(dragboard.getContent(DataFormat.FILES)); if (files == null || files.size() != 1) { return; } final File file = files.get(0); if (!canAccept(file)) return; handleFile(file); }
/** * Handle drag over. */ @FXThread private void dragOver(@NotNull final DragEvent dragEvent) { final Dragboard dragboard = dragEvent.getDragboard(); final List<File> files = unsafeCast(dragboard.getContent(DataFormat.FILES)); if (files == null || files.size() != 1) { return; } final File file = files.get(0); if (!canAccept(file)) return; final Set<TransferMode> transferModes = dragboard.getTransferModes(); final boolean isCopy = transferModes.contains(TransferMode.COPY); dragEvent.acceptTransferModes(isCopy ? TransferMode.COPY : TransferMode.MOVE); dragEvent.consume(); }
/** * Handle dropped events. * * @param dragEvent the dropped event. */ @FXThread private void handleDragDroppedEvent(@NotNull final DragEvent dragEvent) { final Dragboard dragboard = dragEvent.getDragboard(); final List<File> files = unsafeCast(dragboard.getContent(DataFormat.FILES)); if (files == null || files.size() != 1) { return; } final File file = files.get(0); if (!file.getName().endsWith(FileExtensions.JME_MATERIAL)) { return; } addMaterial(file.toPath()); }
/** * Handle drag over events. * * @param dragEvent the drag over event. */ @FXThread private void handleDragOverEvent(@NotNull final DragEvent dragEvent) { final Dragboard dragboard = dragEvent.getDragboard(); final List<File> files = unsafeCast(dragboard.getContent(DataFormat.FILES)); if (files == null || files.size() != 1) { return; } final File file = files.get(0); if (!file.getName().endsWith(FileExtensions.JME_MATERIAL)) { return; } final Set<TransferMode> transferModes = dragboard.getTransferModes(); final boolean isCopy = transferModes.contains(TransferMode.COPY); dragEvent.acceptTransferModes(isCopy ? TransferMode.COPY : TransferMode.MOVE); dragEvent.consume(); }
private void initializeSetOnDragDetected() { // LoggerFacade.INSTANCE.debug(this.getClass(), "Initialize setOnDragDetected"); // NOI18N super.setOnDragDetected(event -> { if (super.getItem() == null) { return; } final Dragboard dragboard = startDragAndDrop(TransferMode.MOVE); final ClipboardContent content = new ClipboardContent(); content.putString(String.valueOf(super.getItem().getProjectId())); // dragboard.setDragView( // birdImages.get( // items.indexOf( // getItem() // ) // ) // ); dragboard.setContent(content); event.consume(); }); }
private void initializeSetOnDragDropped() { // LoggerFacade.INSTANCE.debug(this.getClass(), "Initialize setOnDragDropped"); // NOI18N super.setOnDragDropped(event -> { if (super.getItem() == null) { return; } final Dragboard dragboard = event.getDragboard(); boolean success = false; if (dragboard.hasString()) { final List<ProjectItemPresenter> items = this.updateOverview(dragboard); this.updateDatabase(items); success = true; } event.setDropCompleted(success); event.consume(); }); }
private List<ProjectItemPresenter> updateOverview(Dragboard dragboard) { final ObservableList<ProjectItemPresenter> items = super.getListView().getItems(); int draggedIndex = items.indexOf(dragboard.getString()); ProjectItemPresenter draggedItem = null; for (ProjectItemPresenter item : items) { if (item.getProjectId() == Long.parseLong(dragboard.getString())) { draggedItem = item; draggedIndex = items.indexOf(item); super.getItem().getParent().setOpacity(1.0); break; } } final int thisIndex = items.indexOf(getItem()); items.set(draggedIndex, getItem()); items.set(thisIndex, draggedItem); final List<ProjectItemPresenter> itemsCopy = new ArrayList<>(items); super.getListView().getItems().setAll(itemsCopy); return itemsCopy; }
/** * 트리 드래그 디텍트 이벤트 처리. <br/> * 트리내에 구성된 파일의 위치정보를 드래그 드롭 기능으로 <br/> * 전달해주는 역할을 수행한다.<br/> * <br/> * * @작성자 : KYJ * @작성일 : 2017. 11. 21. * @param ev */ public void treeProjectFileOnDragDetected(MouseEvent ev) { TreeItem<JavaProjectFileWrapper> selectedItem = treeProjectFile.getSelectionModel().getSelectedItem(); if (selectedItem == null || selectedItem.getValue() == null) { return; } File file = selectedItem.getValue().getFile(); if (file == null || !file.exists()) return; Dragboard board = treeProjectFile.startDragAndDrop(TransferMode.LINK); ClipboardContent content = new ClipboardContent(); content.putFiles(Arrays.asList(file)); board.setContent(content); ev.consume(); }
private void handleDragDropped(DragEvent event) { LOGGER.debug("drag dropped"); Dragboard dragboard = event.getDragboard(); boolean success = dragboard.hasString(); if (success) { try { int slideId = Integer.parseInt(dragboard.getString()); LOGGER.debug("dropped slide with id {} on divider", slideId); if (slideDroppedCallback != null) { slideDroppedCallback.accept(slideId); } } catch (NumberFormatException ex) { success = false; } } event.setDropCompleted(success); event.consume(); }
@Override public void start(Stage stage) throws Exception { this.stage = stage; this.stage.setTitle("CSVboard"); Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml")); Scene scene = new Scene(root); scene.getStylesheets().add("CSVboard/style_tableview.css"); // Dropping over surface scene.setOnDragDropped((DragEvent event) -> { Dragboard db = event.getDragboard(); boolean success = false; if (db.hasFiles()) { success = true; String filePath = null; for (File file:db.getFiles()) { filePath = file.getAbsolutePath(); } } event.setDropCompleted(success); event.consume(); }); // Give the controller access to the main app. stage.setScene(scene); stage.show(); }
@Override public void handle(final MouseEvent event) { final Pane pane = (Pane) event.getSource(); final ImageView view = (ImageView) pane.getChildren().get(0); final Dragboard db = view.startDragAndDrop(TransferMode.COPY); final ClipboardContent content = new ClipboardContent(); content.putString(view.getId()); final ComponentPane componentPane = loadComponent(pane.getChildren().get(0).getId().toLowerCase()); workspace.getChildren().add(componentPane); componentPane.applyCss(); final WritableImage w = componentPane.snapshot(null,null); workspace.getChildren().remove(componentPane); content.putImage(w); db.setContent(content); event.consume(); }
protected void handleRowDragDropped(TreeTableRow<T> r, DragEvent ev) { Dragboard db = ev.getDragboard(); if(isAcceptable(db, r)) { int ix = (Integer)db.getContent(JAVA_DATA_FORMAT); TreeItem item = tree.getTreeItem(ix); item.getParent().getChildren().remove(item); getTarget(r).getChildren().add(item); ev.setDropCompleted(true); tree.getSelectionModel().clearSelection(); tree.getSelectionModel().select(item); // FIX focus and selection differ after this ev.consume(); } }
@FXML void mouseDragOver(final DragEvent e) { final Dragboard db = e.getDragboard(); final boolean isAccepted = db.getFiles().get(0).getName().toLowerCase().endsWith(".log") || db.getFiles().get(0).getName().toLowerCase().endsWith(".txt"); if (db.hasFiles()) { if (isAccepted) { tabpane.setStyle("-fx-border-color: red;" + "-fx-border-width: 5;" + "-fx-background-color: #C6C6C6;" + "-fx-border-style: solid;");//TODO move to css e.acceptTransferModes(TransferMode.COPY); } } else { e.consume(); } }
private void onDragOver(final TreeTableRow<GPXLineItem> row, final DragEvent event) { Dragboard db = event.getDragboard(); if (db.getContent(SERIALIZED_MIME_TYPE) != null) { if (!row.isEmpty()) { event.acceptTransferModes(TransferMode.COPY_OR_MOVE); event.consume(); } } else { if (db.hasFiles()) { for (File file:db.getFiles()) { // accept only gpx files if (GPXEditorWorker.GPX_EXT.equals(FilenameUtils.getExtension(file.getName()).toLowerCase())) { event.acceptTransferModes(TransferMode.COPY_OR_MOVE); break; } } } else { event.consume(); } } }
private boolean acceptable(final Dragboard db, final TreeTableRow<GPXLineItem> row) { boolean result = false; if (db.hasContent(SERIALIZED_MIME_TYPE)) { final int index = (Integer) db.getContent(SERIALIZED_MIME_TYPE); //System.out.println("index: " + index + ", row index:" + row.getIndex()); if (!row.isEmpty() && (row.getIndex() != index)) { final TreeItem<GPXLineItem> target = row.getTreeItem(); final GPXLineItem.GPXLineItemType targetType = target.getValue().getType(); final TreeItem<GPXLineItem> item = myTreeTableView.getTreeItem(index); final GPXLineItem.GPXLineItemType itemType = item.getValue().getType(); // don't create loops and only insert on same level or drop on direct parent type result = !isParent(item, target) && (GPXLineItem.GPXLineItemType.isSameTypeAs(targetType, itemType) || GPXLineItem.GPXLineItemType.isParentTypeOf(targetType, itemType)); } } return result; }
@FXML public void songPathDragDropped(final DragEvent ev) { Dragboard db = ev.getDragboard(); if (db.hasFiles()) { for (File f : db.getFiles()) { if (f.isDirectory()) { boolean unique = true; for (String path : bmsroot.getItems()) { if (path.equals(f.getPath()) || f.getPath().startsWith(path + File.separatorChar)) { unique = false; break; } } if (unique) { bmsroot.getItems().add(f.getPath()); } } } } }
@Test public void shouldTriggerDragEntered() { ListCell<Playlist> listCell = cellFactory.call(getListView()); listCell.setItem(new Playlist(1, "Playlist", 10)); listCell.setStyle(null); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true); DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object())); listCell.onDragEnteredProperty().get().handle(spyDragEvent); assertThat("List cell style should not be empty", listCell.getStyle(), not(isEmptyString())); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldNotTriggerDragEnterdWithSameSource() { ListCell<Playlist> listCell = cellFactory.call(getListView()); listCell.setItem(new Playlist(1, "Playlist", 10)); listCell.setStyle(null); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true); DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, listCell)); listCell.onDragEnteredProperty().get().handle(spyDragEvent); assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString()); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldNotTriggerDragEnteredWithNoContent() { ListCell<Playlist> listCell = cellFactory.call(getListView()); listCell.setItem(new Playlist(1, "Playlist", 10)); listCell.setStyle(null); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(false); DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object())); listCell.onDragEnteredProperty().get().handle(spyDragEvent); assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString()); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldNotTriggerDragEnteredWithNoPlaylist() { ListCell<Playlist> listCell = cellFactory.call(getListView()); listCell.setItem(null); listCell.setStyle(null); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true); DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object())); listCell.onDragEnteredProperty().get().handle(spyDragEvent); assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString()); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldNotTriggerDragEnteredWithReservedPlaylist() { ListCell<Playlist> listCell = cellFactory.call(getListView()); listCell.setItem(new Playlist(PLAYLIST_ID_FAVOURITES, "Favourites", 10)); listCell.setStyle(null); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true); DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object())); listCell.onDragEnteredProperty().get().handle(spyDragEvent); assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString()); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldTriggerDragExited() { ListCell<Playlist> listCell = cellFactory.call(getListView()); listCell.setStyle("some-style"); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true); DragEvent spyDragEvent = spy( getDragEvent(DragEvent.DRAG_EXITED, mockDragboard, TransferMode.COPY, new Object())); listCell.onDragExitedProperty().get().handle(spyDragEvent); assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString()); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldTriggerDragDropped() { ListCell<Playlist> listCell = cellFactory.call(getListView()); listCell.setItem(new Playlist(1, "Playlist", 10)); Track mockTrack = mock(Track.class); when(mockTrack.clone()).thenReturn(mockTrack); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true); when(mockDragboard.getContent(DND_TRACK_DATA_FORMAT)).thenReturn(mockTrack); DragEvent spyDragEvent = spy( getDragEvent(DragEvent.DRAG_DROPPED, mockDragboard, TransferMode.COPY, new Object())); listCell.onDragDroppedProperty().get().handle(spyDragEvent); verify(mockPlaylistManager, times(1)).addTrackToPlaylist(1, mockTrack); verify(spyDragEvent, times(1)).setDropCompleted(true); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldNotTriggerDragDroppedWithNoContent() { ListCell<Playlist> listCell = cellFactory.call(getListView()); listCell.setItem(new Playlist(1, "Playlist", 10)); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(false); DragEvent spyDragEvent = spy( getDragEvent(DragEvent.DRAG_DROPPED, mockDragboard, TransferMode.COPY, new Object())); listCell.onDragDroppedProperty().get().handle(spyDragEvent); verify(mockPlaylistManager, never()).addTrackToPlaylist(anyInt(), any()); verify(spyDragEvent, never()).setDropCompleted(true); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldTriggerDragOver() { TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>()); Track track = getTrack(); updateTableCell(tableCell, track); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true); DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object())); tableCell.onDragOverProperty().get().handle(spyDragEvent); verify(spyDragEvent, times(1)).acceptTransferModes(TransferMode.MOVE); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldNotTriggerDragOverWithSameSource() { TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>()); Track track = getTrack(); updateTableCell(tableCell, track); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true); DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, tableCell)); tableCell.onDragOverProperty().get().handle(spyDragEvent); verify(spyDragEvent, never()).acceptTransferModes(TransferMode.MOVE); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldNotTriggerDragOverWithNoContent() { TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>()); Track track = getTrack(); updateTableCell(tableCell, track); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(false); DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object())); tableCell.onDragOverProperty().get().handle(spyDragEvent); verify(spyDragEvent, never()).acceptTransferModes(TransferMode.MOVE); verify(spyDragEvent, times(1)).consume(); }
@Test @SuppressWarnings("unchecked") public void shouldNotTriggerDragOverWithNoTrackTableModel() { TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>()); Track track = getTrack(); updateTableCell(tableCell, track); tableCell.getTableRow().setItem(null); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true); DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object())); tableCell.onDragOverProperty().get().handle(spyDragEvent); verify(spyDragEvent, never()).acceptTransferModes(TransferMode.MOVE); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldNotTriggerDragOverWithSearchPlaylist() { TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>()); Track track = getTrack(); track.setPlaylistId(PLAYLIST_ID_SEARCH); updateTableCell(tableCell, track); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true); DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object())); tableCell.onDragOverProperty().get().handle(spyDragEvent); verify(spyDragEvent, never()).acceptTransferModes(TransferMode.MOVE); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldTriggerDragEntered() { TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>()); Track track = getTrack(); updateTableCell(tableCell, track); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true); DragEvent spyDragEvent = spy( getDragEvent(DragEvent.DRAG_ENTERED, mockDragboard, TransferMode.COPY, new Object())); tableCell.onDragEnteredProperty().get().handle(spyDragEvent); assertThat("Table row style should not be empty", tableCell.getTableRow().getStyle(), not(isEmptyString())); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldNotTriggerDragEnteredWithSameSource() { TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>()); Track track = getTrack(); updateTableCell(tableCell, track); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true); DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_ENTERED, mockDragboard, TransferMode.COPY, tableCell)); tableCell.onDragEnteredProperty().get().handle(spyDragEvent); assertThat("Table row style should be empty", tableCell.getTableRow().getStyle(), isEmptyString()); verify(spyDragEvent, times(1)).consume(); }
@Test public void shouldNotTriggerDragEnteredWithNoContent() { TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>()); Track track = getTrack(); updateTableCell(tableCell, track); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(false); DragEvent spyDragEvent = spy( getDragEvent(DragEvent.DRAG_ENTERED, mockDragboard, TransferMode.COPY, new Object())); tableCell.onDragEnteredProperty().get().handle(spyDragEvent); assertThat("Table row style should be empty", tableCell.getTableRow().getStyle(), isEmptyString()); verify(spyDragEvent, times(1)).consume(); }
@Test @SuppressWarnings("unchecked") public void shouldNotTriggerDragEnteredWithNoTrackTableModel() { TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>()); Track track = getTrack(); updateTableCell(tableCell, track); tableCell.getTableRow().setItem(null); Dragboard mockDragboard = mock(Dragboard.class); when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true); DragEvent spyDragEvent = spy( getDragEvent(DragEvent.DRAG_ENTERED, mockDragboard, TransferMode.COPY, new Object())); tableCell.onDragEnteredProperty().get().handle(spyDragEvent); assertThat("Table row style should be empty", tableCell.getTableRow().getStyle(), isEmptyString()); verify(spyDragEvent, times(1)).consume(); }