1 /*
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.sun.javafx.scene.control.infrastructure;
26
27 import static org.junit.Assert.assertNotNull;
28
29 import com.sun.javafx.scene.control.skin.*;
30 import javafx.geometry.Orientation;
31 import javafx.scene.Group;
32 import javafx.scene.Node;
33 import javafx.scene.Scene;
34 import javafx.scene.control.*;
35 import javafx.stage.Stage;
36 import javafx.util.Callback;
37 import java.util.List;
38
39 import static org.junit.Assert.*;
40
41 public class VirtualFlowTestUtils {
42
43 public static void assertListContainsItemsInOrder(final List items, final Object... expected) {
44 assertEquals(expected.length, items.size());
45 for (int i = 0; i < expected.length; i++) {
46 Object item = items.get(i);
47 assertEquals(expected[i], item);
48 }
49 }
50
51 public static void clickOnRow(final Control control, int row, KeyModifier... modifiers) {
52 clickOnRow(control, row, 1, false, modifiers);
53 }
54
55 public static void clickOnRow(final Control control, int row, int clickCount, KeyModifier... modifiers) {
295 }
296
297 public static void assertGraphicIsNotVisible(final Control control, int row, int column) {
298 Cell cell = getCell(control, row, column);
299 Node graphic = cell.getGraphic();
300 if (graphic == null) {
301 return;
302 }
303
304 assertNotNull(graphic);
305 assertTrue(!graphic.isVisible() || graphic.getOpacity() == 0.0);
306 }
307
308 public static void assertCellCount(final Control control, final int expected) {
309 assertEquals(getVirtualFlow(control).getCellCount(), expected);
310 }
311
312 public static void assertTableHeaderColumnExists(final Control control, final TableColumnBase column, boolean expected) {
313 TableHeaderRow headerRow = getTableHeaderRow(control);
314
315 NestedTableColumnHeader rootHeader = headerRow.getRootHeader();
316 boolean match = false;
317 for (TableColumnHeader header : rootHeader.getColumnHeaders()) {
318 match = column.equals(header.getTableColumn());
319 if (match) break;
320 }
321
322 if (expected) {
323 assertTrue(match);
324 } else {
325 assertFalse(match);
326 }
327 }
328
329 public static boolean BLOCK_STAGE_LOADER_DISPOSE = false;
330
331 public static VirtualFlow<?> getVirtualFlow(Control control) {
332 StageLoader sl = null;
333 boolean stageLoaderCreated = false;
334 if (control.getScene() == null) {
335 sl = new StageLoader(control);
336 stageLoaderCreated = true;
337 }
338
339 VirtualFlow<?> flow;
340 if (control instanceof ComboBox) {
341 final ComboBox cb = (ComboBox) control;
342 final ComboBoxListViewSkin skin = (ComboBoxListViewSkin) cb.getSkin();
343 control = skin.getListView();
344 }
345
346 flow = (VirtualFlow<?>)control.lookup("#virtual-flow");
347
348 if (stageLoaderCreated && sl != null && ! BLOCK_STAGE_LOADER_DISPOSE) {
349 sl.dispose();
350 }
351
352 return flow;
353 }
354
355 public static VirtualScrollBar getVirtualFlowVerticalScrollbar(final Control control) {
356 return getVirtualFlowScrollbar(control, Orientation.VERTICAL);
357 }
358
359 public static VirtualScrollBar getVirtualFlowHorizontalScrollbar(final Control control) {
360 return getVirtualFlowScrollbar(control, Orientation.HORIZONTAL);
361 }
362
363 // this method must be called with the control having been shown in a
364 // stage (e.g. via StageLoader). Be sure to dispose too!
365 public static TableHeaderRow getTableHeaderRow(final Control control) {
366 if (control.getSkin() == null) {
367 throw new IllegalStateException("getTableHeaderRow requires the control to be visible in a stage");
368 }
369
370 TableViewSkinBase<?,?,?,?,?,?> skin = (TableViewSkinBase) control.getSkin();
371 TableHeaderRow headerRow = null;
372 for (Node n : skin.getChildren()) {
373 if (n instanceof TableHeaderRow) {
374 headerRow = (TableHeaderRow) n;
375 break;
376 }
377 }
378
379 return headerRow;
380 }
381
382 private static VirtualScrollBar getVirtualFlowScrollbar(final Control control, Orientation orientation) {
383 VirtualFlow<?> flow = getVirtualFlow(control);
384 VirtualScrollBar scrollBar = null;
385 for (Node child : flow.getChildrenUnmodifiable()) {
386 if (child instanceof VirtualScrollBar) {
387 if (((VirtualScrollBar)child).getOrientation() == orientation) {
388 scrollBar = (VirtualScrollBar) child;
389 }
390 }
391 }
392
393 return scrollBar;
394 }
395
396 public static TableColumnHeader getTableColumnHeader(Control table, TableColumnBase<?,?> column) {
397 TableHeaderRow headerRow = VirtualFlowTestUtils.getTableHeaderRow(table);
398 return findColumnHeader(headerRow.getRootHeader(), column);
399 }
400
401 private static TableColumnHeader findColumnHeader(NestedTableColumnHeader nestedHeader, TableColumnBase<?,?> column) {
402 for (TableColumnHeader header : nestedHeader.getColumnHeaders()) {
403 if (header instanceof NestedTableColumnHeader) {
404 TableColumnHeader result = findColumnHeader((NestedTableColumnHeader)header, column);
405 if (result != null) {
406 return result;
407 }
408 } else {
409 if (column.equals(header.getTableColumn())) {
410 return header;
411 }
412 }
413 }
414 return null;
415 }
416 }
|
1 /*
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.sun.javafx.scene.control.infrastructure;
26
27 import static org.junit.Assert.assertNotNull;
28
29 import javafx.geometry.Orientation;
30 import javafx.scene.Node;
31 import javafx.scene.control.*;
32 import javafx.scene.control.skin.ComboBoxListViewSkin;
33 import com.sun.javafx.scene.control.LabeledText;
34 import javafx.scene.control.skin.NestedTableColumnHeader;
35 import javafx.scene.control.skin.TableColumnHeader;
36 import javafx.scene.control.skin.TableHeaderRow;
37 import javafx.scene.control.skin.TableViewSkinBase;
38 import javafx.scene.control.skin.VirtualFlow;
39 import com.sun.javafx.scene.control.VirtualScrollBar;
40 import javafx.util.Callback;
41 import java.util.List;
42
43 import static org.junit.Assert.*;
44
45 public class VirtualFlowTestUtils {
46
47 public static void assertListContainsItemsInOrder(final List items, final Object... expected) {
48 assertEquals(expected.length, items.size());
49 for (int i = 0; i < expected.length; i++) {
50 Object item = items.get(i);
51 assertEquals(expected[i], item);
52 }
53 }
54
55 public static void clickOnRow(final Control control, int row, KeyModifier... modifiers) {
56 clickOnRow(control, row, 1, false, modifiers);
57 }
58
59 public static void clickOnRow(final Control control, int row, int clickCount, KeyModifier... modifiers) {
299 }
300
301 public static void assertGraphicIsNotVisible(final Control control, int row, int column) {
302 Cell cell = getCell(control, row, column);
303 Node graphic = cell.getGraphic();
304 if (graphic == null) {
305 return;
306 }
307
308 assertNotNull(graphic);
309 assertTrue(!graphic.isVisible() || graphic.getOpacity() == 0.0);
310 }
311
312 public static void assertCellCount(final Control control, final int expected) {
313 assertEquals(getVirtualFlow(control).getCellCount(), expected);
314 }
315
316 public static void assertTableHeaderColumnExists(final Control control, final TableColumnBase column, boolean expected) {
317 TableHeaderRow headerRow = getTableHeaderRow(control);
318
319 NestedTableColumnHeader rootHeader = getNestedTableColumnHeader(headerRow);
320 boolean match = false;
321 for (TableColumnHeader header : rootHeader.getColumnHeaders()) {
322 match = column.equals(header.getTableColumn());
323 if (match) break;
324 }
325
326 if (expected) {
327 assertTrue(match);
328 } else {
329 assertFalse(match);
330 }
331 }
332
333 public static boolean BLOCK_STAGE_LOADER_DISPOSE = false;
334
335 public static VirtualFlow<?> getVirtualFlow(Control control) {
336 StageLoader sl = null;
337 boolean stageLoaderCreated = false;
338 if (control.getScene() == null) {
339 sl = new StageLoader(control);
340 stageLoaderCreated = true;
341 }
342
343 VirtualFlow<?> flow;
344 if (control instanceof ComboBox) {
345 final ComboBox cb = (ComboBox) control;
346 final ComboBoxListViewSkin skin = (ComboBoxListViewSkin) cb.getSkin();
347 control = (ListView) skin.getPopupContent();
348 }
349
350 flow = (VirtualFlow<?>)control.lookup("#virtual-flow");
351
352 if (stageLoaderCreated && sl != null && ! BLOCK_STAGE_LOADER_DISPOSE) {
353 sl.dispose();
354 }
355
356 return flow;
357 }
358
359 public static VirtualScrollBar getVirtualFlowVerticalScrollbar(final Control control) {
360 return getVirtualFlowScrollbar(control, Orientation.VERTICAL);
361 }
362
363 public static VirtualScrollBar getVirtualFlowHorizontalScrollbar(final Control control) {
364 return getVirtualFlowScrollbar(control, Orientation.HORIZONTAL);
365 }
366
367 // this method must be called with the control having been shown in a
368 // stage (e.g. via StageLoader). Be sure to dispose too!
369 public static TableHeaderRow getTableHeaderRow(final Control control) {
370 if (control.getSkin() == null) {
371 throw new IllegalStateException("getTableHeaderRow requires the control to be visible in a stage");
372 }
373
374 TableViewSkinBase<?,?,?,?,?> skin = (TableViewSkinBase) control.getSkin();
375 TableHeaderRow headerRow = null;
376 for (Node n : skin.getChildren()) {
377 if (n instanceof TableHeaderRow) {
378 headerRow = (TableHeaderRow) n;
379 break;
380 }
381 }
382
383 return headerRow;
384 }
385
386 private static VirtualScrollBar getVirtualFlowScrollbar(final Control control, Orientation orientation) {
387 VirtualFlow<?> flow = getVirtualFlow(control);
388 VirtualScrollBar scrollBar = null;
389 for (Node child : flow.getChildrenUnmodifiable()) {
390 if (child instanceof VirtualScrollBar) {
391 if (((VirtualScrollBar)child).getOrientation() == orientation) {
392 scrollBar = (VirtualScrollBar) child;
393 }
394 }
395 }
396
397 return scrollBar;
398 }
399
400 public static TableColumnHeader getTableColumnHeader(Control table, TableColumnBase<?,?> column) {
401 TableHeaderRow headerRow = VirtualFlowTestUtils.getTableHeaderRow(table);
402 return findColumnHeader(getNestedTableColumnHeader(headerRow), column);
403 }
404
405 private static TableColumnHeader findColumnHeader(NestedTableColumnHeader nestedHeader, TableColumnBase<?,?> column) {
406 for (TableColumnHeader header : nestedHeader.getColumnHeaders()) {
407 if (header instanceof NestedTableColumnHeader) {
408 TableColumnHeader result = findColumnHeader((NestedTableColumnHeader)header, column);
409 if (result != null) {
410 return result;
411 }
412 } else {
413 if (column.equals(header.getTableColumn())) {
414 return header;
415 }
416 }
417 }
418 return null;
419 }
420
421 public static NestedTableColumnHeader getNestedTableColumnHeader(TableHeaderRow headerRow) {
422 NestedTableColumnHeader rootHeader = null;
423
424 for (Node n : headerRow.getChildren()) {
425 if (n instanceof NestedTableColumnHeader) {
426 rootHeader = (NestedTableColumnHeader) n;
427 }
428 }
429 return rootHeader;
430 }
431 }
|