Java Code Examples for javafx.scene.control.TableCell

The following are top voted examples for showing how to use javafx.scene.control.TableCell. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: marathonv5   File: JavaFXElementPropertyAccessor.java   View source code 8 votes vote down vote up
public Point2D getPoint(TableView<?> tableView, int columnIndex, int rowIndex) {
    Set<Node> tableRowCell = tableView.lookupAll(".table-row-cell");
    TableRow<?> row = null;
    for (Node tableRow : tableRowCell) {
        TableRow<?> r = (TableRow<?>) tableRow;
        if (r.getIndex() == rowIndex) {
            row = r;
            break;
        }
    }
    Set<Node> cells = row.lookupAll(".table-cell");
    for (Node node : cells) {
        TableCell<?, ?> cell = (TableCell<?, ?>) node;
        if (tableView.getColumns().indexOf(cell.getTableColumn()) == columnIndex) {
            Bounds bounds = cell.getBoundsInParent();
            Point2D localToParent = cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2);
            Point2D rowLocal = row.localToScene(localToParent, true);
            return rowLocal;
        }
    }
    return null;
}
 
Example 2
Project: marathonv5   File: JavaFXTableViewElementScrollTest.java   View source code 7 votes vote down vote up
public Point2D getPoint(TableView<?> tableView, int columnIndex, int rowIndex) {
    Set<Node> tableRowCell = tableView.lookupAll(".table-row-cell");
    TableRow<?> row = null;
    for (Node tableRow : tableRowCell) {
        TableRow<?> r = (TableRow<?>) tableRow;
        if (r.getIndex() == rowIndex) {
            row = r;
            break;
        }
    }
    Set<Node> cells = row.lookupAll(".table-cell");
    for (Node node : cells) {
        TableCell<?, ?> cell = (TableCell<?, ?>) node;
        if (tableView.getColumns().indexOf(cell.getTableColumn()) == columnIndex) {
            Bounds bounds = cell.getBoundsInParent();
            Point2D localToParent = cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2);
            Point2D rowLocal = row.localToScene(localToParent, true);
            return rowLocal;
        }
    }
    return null;
}
 
Example 3
Project: trex-stateless-gui   File: PacketTableView.java   View source code 7 votes vote down vote up
@Override
public TableCell call(TableColumn p) {
    return new TableCell<Object, String>() {
        private final ImageView imageview;

        {
            imageview = new ImageView();
            imageview.setFitHeight(16);
            imageview.setFitWidth(16);
            imageview.setCache(true);
        }

        @Override
        protected void updateItem(String item, boolean empty) {
            super.updateItem(item, empty);
            if (empty) {
                setText(null);
                setGraphic(null);
            } else {
                imageview.setImage(new Image(item));
                setGraphic(imageview);
            }
        }
    };
}
 
Example 4
Project: hygene   File: AnnotationController.java   View source code 6 votes vote down vote up
/**
 * Creates a wrapped table cell.
 *
 * @param column the table column in which the cell resides
 * @return a TableCell with the text wrapped inside
 */
private TableCell<Annotation, String> createWrappableTableCell(final TableColumn<Annotation, String> column) {
    return new TableCell<Annotation, String>() {
        @Override
        protected void updateItem(final String item, final boolean empty) {
            super.updateItem(item, empty);
            if (item == null || empty) {
                setGraphic(null);
                return;
            }

            final Text text = new Text(item);
            text.setWrappingWidth(column.getWidth() - TEXT_PADDING);
            setPrefHeight(text.getLayoutBounds().getHeight());

            setGraphic(text);
        }
    };
}
 
Example 5
Project: hygene   File: NodePropertiesController.java   View source code 6 votes vote down vote up
/**
 * Create a table cell that wraps the text inside.
 *
 * @param param the table column
 * @return a table cell that wraps the text inside
 */
TableCell<Annotation, String> wrappableTableCell(final TableColumn<Annotation, String> param) {
    return new TableCell<Annotation, String>() {
        @Override
        protected void updateItem(final String item, final boolean empty) {
            super.updateItem(item, empty);
            if (item == null || empty) {
                setGraphic(null);
                return;
            }
            final Text text = new Text(item);
            text.setWrappingWidth(param.getWidth());
            setPrefHeight(text.getLayoutBounds().getHeight());
            setGraphic(text);
        }
    };
}
 
Example 6
Project: marathonv5   File: JavaFXElementPropertyAccessor.java   View source code 6 votes vote down vote up
public TableCell<?, ?> getVisibleCellAt(TableView<?> tableView, int row, int column) {
    Set<Node> lookupAll = getTableCells(tableView);
    TableCell<?, ?> cell = null;
    for (Node node : lookupAll) {
        TableCell<?, ?> cell1 = (TableCell<?, ?>) node;
        TableRow<?> tableRow = cell1.getTableRow();
        TableColumn<?, ?> tableColumn = cell1.getTableColumn();
        if (tableRow.getIndex() == row && tableColumn == tableView.getColumns().get(column)) {
            cell = cell1;
            break;
        }
    }
    if (cell != null) {
        return cell;
    }
    return null;
}
 
Example 7
Project: marathonv5   File: JavaFXTableViewCellElement.java   View source code 6 votes vote down vote up
@Override public String _getValue() {
    TableCell<?, ?> cell = (TableCell<?, ?>) node;
    Node graphic = cell.getGraphic();
    JavaFXElement component = (JavaFXElement) JavaFXElementFactory.createElement(graphic, driver, window);
    if (graphic != null && component != null) {
        if (graphic instanceof CheckBox) {
            String cellText = cell.getText() == null ? "" : cell.getText();
            return cellText + ":" + component._getValue();
        }
        return component._getValue();
    }
    return super._getValue();
}
 
Example 8
Project: marathonv5   File: RFXComponentTest.java   View source code 6 votes vote down vote up
public Point2D getPoint(TableView<?> tableView, int columnIndex, int rowIndex) {
    Set<Node> tableRowCell = tableView.lookupAll(".table-row-cell");
    TableRow<?> row = null;
    for (Node tableRow : tableRowCell) {
        TableRow<?> r = (TableRow<?>) tableRow;
        if (r.getIndex() == rowIndex) {
            row = r;
            break;
        }
    }
    Set<Node> cells = row.lookupAll(".table-cell");
    for (Node node : cells) {
        TableCell<?, ?> cell = (TableCell<?, ?>) node;
        if (tableView.getColumns().indexOf(cell.getTableColumn()) == columnIndex) {
            Bounds bounds = cell.getBoundsInParent();
            Point2D localToParent = cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2);
            Point2D rowLocal = row.localToScene(localToParent, true);
            return rowLocal;
        }
    }
    return null;
}
 
Example 9
Project: Clipcon-Client   File: MainScene.java   View source code 6 votes vote down vote up
/** Add participant in group list */
public void addGroupParticipantList() {
	Platform.runLater(() -> {
		groupParticipantTable.setItems(groupParticipantList);

		// Nickname column setting
		groupPartiNicknameColumn.setCellValueFactory(cellData -> cellData.getValue().getNameProperty());
		groupPartiNicknameColumn.setCellFactory(new Callback<TableColumn<User, String>, TableCell<User, String>>() {
			@Override
			public TableCell<User, String> call(TableColumn<User, String> column) {
				TableCell<User, String> tc = new TableCell<User, String>() {
					@Override
					public void updateItem(String item, boolean empty) {
						if (item != null) {
							setText(item);
						}
					}
				};
				tc.setAlignment(Pos.CENTER);
				return tc;
			}
		});
	});
}
 
Example 10
Project: drd   File: CellUtils.java   View source code 6 votes vote down vote up
public static final <S> TableCell<S, Image> forImage() {
    final ImageView imageView = new ImageView();
    {
        imageView.setFitWidth(ItemSlot.SLOT_SIZE);
        imageView.setFitHeight(ItemSlot.SLOT_SIZE);
    }
    return new TableCell<S, Image>() {
        @Override
        protected void updateItem(Image item, boolean empty) {
            super.updateItem(item, empty);

            if (empty) {
                setText(null);
                setGraphic(null);
            } else {
                imageView.setImage(item);
                setGraphic(imageView);
            }
        }
    };
}
 
Example 11
Project: population   File: PrimaryController.java   View source code 6 votes vote down vote up
private <T> Callback<TableColumn<T, Number>, TableCell<T, Number>> integerCell(
        Predicate<Integer> validator, int defaultValue) {
    return TextFieldTableCell.forTableColumn(new StringConverter<Number>() {
        @Override
        public String toString(Number object) {
            if (object == null) {
                return null;
            }
            return object.toString();
        }

        @Override
        public Number fromString(String string) {
            try {
                int value = Integer.parseInt(string);
                if (validator.test(value)) {
                    return value;
                } else {
                    return defaultValue;
                }
            } catch (NumberFormatException e) {
                return defaultValue;
            }
        }
    });
}
 
Example 12
Project: photometric-data-retriever   File: StellarObjectTableController.java   View source code 6 votes vote down vote up
@FXML
private void initialize() {
    distanceColumn.setCellValueFactory(cell -> cell.getValue().distanceProperty());
    distanceColumn.setCellFactory(param -> new TableCell<StellarObjectModel, Number>() {
        @Override
        protected void updateItem(Number item, boolean empty) {
            if (item != null) {
                NumberFormat formatter = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
                setText(formatter.format(item));
            }
        }
    });
    nameColumn.setCellValueFactory(cell -> cell.getValue().nameProperty());
    raColumn.setCellValueFactory(cell -> cell.getValue().rightAscensionProperty());
    decColumn.setCellValueFactory(cell -> cell.getValue().declinationProperty());
}
 
Example 13
Project: jstackfx   File: ThreadListCellFactory.java   View source code 6 votes vote down vote up
protected TextFlow buildThreadListGraphic(final TableCell<ThreadElement, Set<ThreadElement>> cell, final Set<ThreadElement> threads) {
    final TextFlow threadsGraphic = new TextFlow();
    threadsGraphic.setPrefHeight(20);

    final Iterator<ThreadElement> threadIterator = threads.iterator();
    while (threadIterator.hasNext()) {
        final ThreadElement thread = threadIterator.next();

        threadsGraphic.getChildren().add(buildThreadLink(cell, thread));

        if (threadIterator.hasNext()) {
            threadsGraphic.getChildren().add(buildThreadSeparator());
        }
    }
    return threadsGraphic;
}
 
Example 14
Project: openjfx-8u-dev-tests   File: TableViewNewTest.java   View source code 6 votes vote down vote up
protected void checkTextContainment(final Wrap<? extends TableCell> cellWrap, final String textExpectToFind) {
    new Waiter(new Timeout("", 1000)).ensureState(new State() {
        public Object reached() {
            LookupCriteria<Node> lookupCriteria = new LookupCriteria<Node>() {
                public boolean check(Node cntrl) {
                    return Text.class.isAssignableFrom(cntrl.getClass())
                            || ((Text) cntrl).getText().equals(textExpectToFind);
                }
            };

            if (cellWrap.as(Parent.class, Node.class).lookup(Text.class, new ByText(textExpectToFind)).size() == 1) {
                return true;
            } else if (cellWrap.as(Parent.class, Node.class).lookup(lookupCriteria).size() == 1) {
                return true;
            } else {
                return null;
            }

        }
    });
}
 
Example 15
Project: openjfx-8u-dev-tests   File: TestBaseCommon.java   View source code 6 votes vote down vote up
protected static Range getVisibleRange(final Wrap<? extends Control> testedControl) {
    int[] visibleIndices;

    if (testedControl.getControl() instanceof TableView) {
        visibleIndices = org.jemmy.fx.control.TableUtils.shown(
                testedControl.getEnvironment(),
                testedControl,
                new org.jemmy.fx.control.TableUtils.TableViewIndexInfoProvider((TableViewWrap) testedControl), TableCell.class);
    } else {
        visibleIndices = org.jemmy.fx.control.TableUtils.shown(
                testedControl.getEnvironment(),
                testedControl,
                new org.jemmy.fx.control.TableUtils.TreeTableViewIndexInfoProvider((TreeTableViewWrap) testedControl), TreeTableCell.class);
    }

    return new Range(visibleIndices[1], visibleIndices[3]);
}
 
Example 16
Project: openjfx-8u-dev-tests   File: TableViewLookupTest.java   View source code 6 votes vote down vote up
@Test
public void cellLookup() {
    System.out.println("testLookup");

    final String D = "D";

    Wrap<? extends TableCell> tableCellWrap = tableDock.asParent().
            lookup(TableCell.class, control -> {
                String item = (String) control.getItem();
                return item != null && item.contains(D);
            }).wrap();
    assertTrue("tableViewCellsParent.lookup().wrap() returns "
            + "TableCellWrap",
            tableCellWrap instanceof TableCellWrap);

    assertTrue(tableCellWrap.getProperty(String.class, "getItem").contains(D));

    tableCellWrap.mouse().click();

    tableDock.wrap().waitState(() -> tableDock.getSelection().contains(new Point(0, 4)) ? true : null);
}
 
Example 17
Project: slogo   File: History.java   View source code 6 votes vote down vote up
/**
 * Generates the callback function to be called on button click.
 * @return
 */
private Callback<?, ?> generateCallback() {
	return new Callback<TableColumn<HistoricalItem, String>, TableCell<HistoricalItem, String>>() {
	@SuppressWarnings("rawtypes")
	@Override
                public TableCell call(TableColumn<HistoricalItem, String> parameter) {
                    final TableCell<HistoricalItem, String> cell = new TableCell<HistoricalItem, String>() {
                        final Button button = new Button(CALLBACK);
                        @Override
                        public void updateItem(String item, boolean empty) {
                        	super.updateItem(item, empty);
                            if(empty) {
                            	setGraphic(null);
                            } else  {
                            	HistoricalItem history = getTableView().getItems().get(getIndex());
                            	button.setId(CALLBACK + " " + history.getValue());
                            	button.setOnAction(event);
                            	setGraphic(button);
                            }
                        	setText(null);
                        }
                    }; return cell;
                }};
}
 
Example 18
Project: drbookings   File: StudioCellFactory.java   View source code 6 votes vote down vote up
@Override
public TableCell<DateBean, DateBean> call(final TableColumn<DateBean, DateBean> param) {
	return new TableCell<DateBean, DateBean>() {

		@Override
		protected void updateItem(final DateBean item, final boolean empty) {

			super.updateItem(item, empty);
			if (empty || item == null) {
				setText("");
				setStyle("");
				setGraphic(null);
			} else {
				setGraphic(buildCellContentFast(item.getRoom(id)));
				setStyle("-fx-padding: 0 0 0 0;");
			}
		}
	};
}
 
Example 19
Project: rpmjukebox   File: LoveButtonTableCellFactoryTest.java   View source code 6 votes vote down vote up
@Test
public void shouldSinglePrimaryClickOnCellTrackInPlaylist() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    tableCell.setItem("trackId");

    Track track = new Track("123", "Artist Name", "Artist Image", "456", "Album Name", "Album Image", 2000, "789",
        "Track Name", 1, "Location", true, Arrays.asList("Genre 1", "Genre 2"));
    track.setPlaylistId(999);
    TrackTableModel trackTableModel = new TrackTableModel(track);

    @SuppressWarnings("unchecked")
    TableRow<TrackTableModel> mockTableRow = (TableRow<TrackTableModel>)mock(TableRow.class);
    when(mockTableRow.getItem()).thenReturn(trackTableModel);

    ReflectionTestUtils.invokeMethod(tableCell, "setTableRow", mockTableRow);

    when(mockPlaylistManager.isTrackInPlaylist(anyInt(), anyString())).thenReturn(true);

    tableCell.onMouseClickedProperty().get()
        .handle(getMouseEvent(MouseEvent.MOUSE_CLICKED, MouseButton.PRIMARY, 1));

    verify(mockPlaylistManager, never()).addTrackToPlaylist(PLAYLIST_ID_FAVOURITES, track);
    verify(mockPlaylistManager, times(1)).removeTrackFromPlaylist(PLAYLIST_ID_FAVOURITES, track);
    verify(getMockEventManager(), times(1)).fireEvent(Event.PLAYLIST_CONTENT_UPDATED, track.getPlaylistId());
}
 
Example 20
Project: rpmjukebox   File: LoveButtonTableCellFactoryTest.java   View source code 6 votes vote down vote up
@Test
public void shouldSinglePrimaryClickOnCellTrackNotInPlaylist() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    tableCell.setItem("trackId");

    Track track = new Track("123", "Artist Name", "Artist Image", "456", "Album Name", "Album Image", 2000, "789",
        "Track Name", 1, "Location", true, Arrays.asList("Genre 1", "Genre 2"));
    track.setPlaylistId(999);
    TrackTableModel trackTableModel = new TrackTableModel(track);

    @SuppressWarnings("unchecked")
    TableRow<TrackTableModel> mockTableRow = (TableRow<TrackTableModel>)mock(TableRow.class);
    when(mockTableRow.getItem()).thenReturn(trackTableModel);

    ReflectionTestUtils.invokeMethod(tableCell, "setTableRow", mockTableRow);

    when(mockPlaylistManager.isTrackInPlaylist(anyInt(), anyString())).thenReturn(false);

    tableCell.onMouseClickedProperty().get()
        .handle(getMouseEvent(MouseEvent.MOUSE_CLICKED, MouseButton.PRIMARY, 1));

    verify(mockPlaylistManager, times(1)).addTrackToPlaylist(PLAYLIST_ID_FAVOURITES, track);
    verify(mockPlaylistManager, never()).removeTrackFromPlaylist(PLAYLIST_ID_FAVOURITES, track);
    verify(getMockEventManager(), times(1)).fireEvent(Event.PLAYLIST_CONTENT_UPDATED, track.getPlaylistId());
}
 
Example 21
Project: rpmjukebox   File: LoveButtonTableCellFactoryTest.java   View source code 6 votes vote down vote up
@Test
public void shouldSinglePrimaryClickOnCellNullItem() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    tableCell.setItem(null);

    Track track = new Track("123", "Artist Name", "Artist Image", "456", "Album Name", "Album Image", 2000, "789",
        "Track Name", 1, "Location", true, Arrays.asList("Genre 1", "Genre 2"));
    track.setPlaylistId(999);

    tableCell.onMouseClickedProperty().get()
        .handle(getMouseEvent(MouseEvent.MOUSE_CLICKED, MouseButton.PRIMARY, 1));

    verify(mockPlaylistManager, never()).addTrackToPlaylist(PLAYLIST_ID_FAVOURITES, track);
    verify(mockPlaylistManager, never()).removeTrackFromPlaylist(PLAYLIST_ID_FAVOURITES, track);
    verify(getMockEventManager(), never()).fireEvent(Event.PLAYLIST_CONTENT_UPDATED, track.getPlaylistId());
}
 
Example 22
Project: rpmjukebox   File: LoveButtonTableCellFactoryTest.java   View source code 6 votes vote down vote up
@Test
public void shouldDoublePrimaryClickOnCell() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    tableCell.setItem(null);

    Track track = new Track("123", "Artist Name", "Artist Image", "456", "Album Name", "Album Image", 2000, "789",
        "Track Name", 1, "Location", true, Arrays.asList("Genre 1", "Genre 2"));
    track.setPlaylistId(999);

    tableCell.onMouseClickedProperty().get()
        .handle(getMouseEvent(MouseEvent.MOUSE_CLICKED, MouseButton.PRIMARY, 2));

    verify(mockPlaylistManager, never()).addTrackToPlaylist(PLAYLIST_ID_FAVOURITES, track);
    verify(mockPlaylistManager, never()).removeTrackFromPlaylist(PLAYLIST_ID_FAVOURITES, track);
    verify(getMockEventManager(), never()).fireEvent(Event.PLAYLIST_CONTENT_UPDATED, track.getPlaylistId());
}
 
Example 23
Project: rpmjukebox   File: LoveButtonTableCellFactoryTest.java   View source code 6 votes vote down vote up
@Test
public void shouldSingleSecondaryClickOnCell() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    tableCell.setItem(null);

    Track track = new Track("123", "Artist Name", "Artist Image", "456", "Album Name", "Album Image", 2000, "789",
        "Track Name", 1, "Location", true, Arrays.asList("Genre 1", "Genre 2"));
    track.setPlaylistId(999);

    tableCell.onMouseClickedProperty().get()
        .handle(getMouseEvent(MouseEvent.MOUSE_CLICKED, MouseButton.SECONDARY, 1));

    verify(mockPlaylistManager, never()).addTrackToPlaylist(PLAYLIST_ID_FAVOURITES, track);
    verify(mockPlaylistManager, never()).removeTrackFromPlaylist(PLAYLIST_ID_FAVOURITES, track);
    verify(getMockEventManager(), never()).fireEvent(Event.PLAYLIST_CONTENT_UPDATED, track.getPlaylistId());
}
 
Example 24
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@Test
public void shouldOpenContextMenuOnSearchPlaylist() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    track.setPlaylistId(PLAYLIST_ID_SEARCH);
    updateTableCell(tableCell, track);

    tableCell.onContextMenuRequestedProperty().get().handle(getContextMenuEvent(tableCell));

    MenuItem createPlaylistFromAlbumItem = tableCell.getContextMenu().getItems().get(0);
    MenuItem deleteTrackFromPlaylistItem = tableCell.getContextMenu().getItems().get(1);

    assertThat("Create playlist from album item should not be disabled", createPlaylistFromAlbumItem.isDisable(),
        equalTo(false));
    assertThat("Delete track from playlist item should be disabled", deleteTrackFromPlaylistItem.isDisable(),
        equalTo(true));
}
 
Example 25
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@Test
public void shouldOpenContextMenuOnNonSearchPlaylist() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    updateTableCell(tableCell, track);

    tableCell.onContextMenuRequestedProperty().get().handle(getContextMenuEvent(tableCell));

    MenuItem createPlaylistFromAlbumItem = tableCell.getContextMenu().getItems().get(0);
    MenuItem deleteTrackFromPlaylistItem = tableCell.getContextMenu().getItems().get(1);

    assertThat("Create playlist from album item should be disabled", createPlaylistFromAlbumItem.isDisable(),
        equalTo(true));
    assertThat("Delete track from playlist item should not be disabled", deleteTrackFromPlaylistItem.isDisable(),
        equalTo(false));
}
 
Example 26
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@Test
public void shouldOpenContextMenuWhenItemIsNull() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    updateTableCell(tableCell, track);
    tableCell.setItem(null);

    tableCell.onContextMenuRequestedProperty().get().handle(getContextMenuEvent(tableCell));

    MenuItem createPlaylistFromAlbumItem = tableCell.getContextMenu().getItems().get(0);
    MenuItem deleteTrackFromPlaylistItem = tableCell.getContextMenu().getItems().get(1);

    assertThat("Create playlist from album item should be disabled", createPlaylistFromAlbumItem.isDisable(),
        equalTo(true));
    assertThat("Delete track from playlist item should be disabled", deleteTrackFromPlaylistItem.isDisable(),
        equalTo(true));
}
 
Example 27
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 28
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 29
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 30
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 31
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 32
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 33
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 34
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 35
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 36
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@Test
public void shouldNotTriggerDragEnteredWithSearchPlaylist() {
    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_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();
}
 
Example 37
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@Test
public void shouldTriggerDragExited() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    updateTableCell(tableCell, track);
    tableCell.getTableRow().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()));

    tableCell.onDragExitedProperty().get().handle(spyDragEvent);

    assertThat("Table row style should be empty", tableCell.getTableRow().getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
 
Example 38
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@Test
public void shouldTriggerDragDropped() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track target = getTrack();
    updateTableCell(tableCell, target);

    Track source = new Track("1231", "Artist Name 1", "Artist Image 1", "4561", "Album Name 1", "Album Image 1",
        2001, "7891", "Track Name 1", 2, "Location 1", true, Arrays.asList("Genre 1", "Genre 2"));
    source.setPlaylistId(2);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);
    when(mockDragboard.getContent(DND_TRACK_DATA_FORMAT)).thenReturn(source);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_DROPPED, mockDragboard, TransferMode.COPY, new Object()));

    tableCell.onDragDroppedProperty().get().handle(spyDragEvent);

    verify(mockPlaylistManager, times(1)).moveTracksInPlaylist(source.getPlaylistId(), source, target);
    verify(spyDragEvent, times(1)).setDropCompleted(true);
    verify(spyDragEvent, times(1)).consume();
}
 
Example 39
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@Test
public void shouldNotTriggerDragDroppedWithNoContent() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track target = getTrack();
    updateTableCell(tableCell, target);

    Track source = new Track("1231", "Artist Name 1", "Artist Image 1", "4561", "Album Name 1", "Album Image 1",
        2001, "7891", "Track Name 1", 2, "Location 1", true, Arrays.asList("Genre 1", "Genre 2"));
    source.setPlaylistId(2);

    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()));

    tableCell.onDragDroppedProperty().get().handle(spyDragEvent);

    verify(mockPlaylistManager, never()).moveTracksInPlaylist(source.getPlaylistId(), source, target);
    verify(spyDragEvent, never()).setDropCompleted(true);
    verify(spyDragEvent, times(1)).consume();
}
 
Example 40
Project: FxDock   File: FxTableColumn.java   View source code 6 votes vote down vote up
private TableCell<T,T> getCellFactory(TableColumn<T,T> f)
{
	return new TableCell<T,T>()
	{
		@Override
		protected void updateItem(T item, boolean empty)
		{
			super.updateItem(item, empty);
			
			if(empty)
			{
				item = null;
			}
			
			if(renderer == null)
			{
				setText(item == null ? null : item.toString());
			}
			else
			{
				Node n = (renderer == null ? null : renderer.apply(item));
				setGraphic(n);
			}
		}
	};
}