public void testStartEditing() { assertFalse(ui.isEditing(tree)); ui.startEditing(new TreePath(root), null); assertFalse(ui.isEditing(tree)); tree.setEditable(true); assertFalse(ui.isEditing(tree)); ui.startEditing(new TreePath(root), null); assertTrue(ui.isEditing(tree)); ui.cancelEditing(tree); assertFalse(ui.isEditing(tree)); tree.setCellEditor(new DefaultTreeCellEditor(tree, (DefaultTreeCellRenderer) tree .getCellRenderer()) { @Override public boolean shouldSelectCell(final EventObject event) { return false; } }); ui.startEditing(new TreePath(root), null); assertTrue(ui.isEditing(tree)); }
/** * {@inheritDoc} */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
/** * focus issues with popup in editors: tweak with * custom cellEditorListener. * */ @Test public void testEditorListenerRemovedOnEditorStopped() { JXTree tree = createEditingTree(); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); // core doesn't remove the listener ... dooh cellEditor.stopCellEditing(); // but we do ... assertEquals(1, cellEditor.getCellEditorListeners().length); }
/** * focus issues with popup in editors: tweak with * custom cellEditorListener. * */ @Test public void testEditorListenerRemovedOnEditorCancel() { JXTree tree = createEditingTree(); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); // core doesn't remove the listener ... dooh cellEditor.cancelCellEditing(); // but we do ... assertEquals(1, cellEditor.getCellEditorListeners().length); }
/** * focus issues with popup in editors: tweak with * custom cellEditorListener. * */ @Test public void testEditorListenerRemovedOnTreeCancel() { JXTree tree = createEditingTree(); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); // core doesn't remove the listener ... dooh tree.cancelEditing(); // but we do ... assertEquals(1, cellEditor.getCellEditorListeners().length); }
/** * focus issues with popup in editors: tweak with * custom cellEditorListener. * */ @Test public void testEditorListenerRemovedOnTreeStop() { JXTree tree = createEditingTree(); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); // core doesn't remove the listener ... dooh tree.stopEditing(); // but we do ... assertEquals(1, cellEditor.getCellEditorListeners().length); }
/** * focus issues with popup in editors: tweak with * custom cellEditorListener. * */ @Test public void testEditorListenerOnXTree() { JTree core = new JTree(); int coreCount = getListenerCountAfterStartEditing(core); JXTree tree = createEditingTree(); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); assertEquals("need one more listener than core", coreCount + 1, cellEditor.getCellEditorListeners().length); }
/** * characterization: listeners in core tree. * */ @Test public void testEditorListenerOnCoreTree() { JTree tree = new JTree(); int listenerCount = getListenerCountAfterStartEditing(tree); assertEquals(1, listenerCount); tree.stopEditing(); // doesn't remove the listener ... dooh assertEquals(1, ((DefaultTreeCellEditor) tree.getCellEditor()).getCellEditorListeners().length); }
/** * Starts editing on row 2 and returns the cell editor listener count after. * * @param tree * @return */ private int getListenerCountAfterStartEditing(JTree tree) { tree.setEditable(true); // sanity assertTrue(tree.getRowCount() > 2); TreePath path = tree.getPathForRow(2); tree.startEditingAtPath(path); DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor(); int listenerCount = cellEditor.getCellEditorListeners().length; return listenerCount; }
/** * visually check if invokesStopCellEditing jumps in on focusLost. * */ public void interactiveToggleEditProperties() { final JXTree table = new JXTree(); table.setEditable(true); DefaultTreeCellEditor editor = new DefaultTreeCellEditor(null, null) { @Override public boolean stopCellEditing() { String value = String.valueOf(getCellEditorValue()); if (value.startsWith("s")) { return false; } return super.stopCellEditing(); } }; table.setCellEditor(editor); JXFrame frame = wrapWithScrollingInFrame(table, new JButton("something to focus"), "JXTree: toggle invokesStopEditing "); Action toggleTerminate = new AbstractAction("toggleInvokesStop") { public void actionPerformed(ActionEvent e) { table.setInvokesStopCellEditing(!table.getInvokesStopCellEditing()); } }; addAction(frame, toggleTerminate); frame.setVisible(true); }
/** * visualize datepicker editing of the hierarchical column, both * in a tree and a xTree switching CO. * * standard editor */ public void interactiveTreeEditingRToLDatePicker() { TreeModel model = createTreeModelWithDates(); JTree tree = new JTree(model); tree.setEditable(true); tree.setCellEditor(new DefaultTreeCellEditor(tree, null, new DatePickerCellEditor())); JXTree xTree = new JXTree(model); xTree.setEditable(true); xTree.setCellEditor(new DefaultTreeCellEditor(tree, null, new DatePickerCellEditor())); final JXFrame frame = wrapWithScrollingInFrame(tree, xTree, "standard Editing (DatePicker): compare tree and xtree"); addComponentOrientationToggle(frame); show(frame); }
/** * Constructor */ public ProjectTree() { ProjectTreeRenderer renderer = new ProjectTreeRenderer(); setCellRenderer(renderer); DefaultTreeCellEditor editor = new DefaultTreeCellEditor(this, renderer, new ProjectTreeEditor(this)); setCellEditor(editor); setEditable(true); setInvokesStopCellEditing(true); setRootVisible(true); setShowsRootHandles(false); setToggleClickCount(-1); // Activate drag&drop ProjectTreeDnDHandler dndHandler = new ProjectTreeDnDHandler(); setTransferHandler(dndHandler); setDropMode(DropMode.INSERT); setDragEnabled(true); // Attach a handler for handling popup menus and double clicks ProjectTreeMouseHandler popupHandler = new ProjectTreeMouseHandler(this); addMouseListener(popupHandler); }
/** * @inheritDoc */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if (renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
/** * @inheritDoc */ @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; }
protected TreeCellEditor createDefaultCellEditor() { DefaultTreeCellRenderer renderer = currentCellRenderer instanceof DefaultTreeCellRenderer ? (DefaultTreeCellRenderer)currentCellRenderer : null; return new DefaultTreeCellEditor(tree, renderer); }
public void testSetCellEditor() { PropertyChangeController listener = new PropertyChangeController(); DefaultTreeCellEditor editor1 = new DefaultTreeCellEditor(tree, (DefaultTreeCellRenderer) tree.getCellRenderer()); DefaultTreeCellEditor editor2 = new DefaultTreeCellEditor(tree, (DefaultTreeCellRenderer) tree.getCellRenderer()); tree.addPropertyChangeListener(listener); TreeCellEditor oldEditor = tree.getCellEditor(); tree.setCellEditor(editor1); listener.checkPropertyFired(tree, "cellEditor", oldEditor, editor1); assertEquals("cellEditor", editor1, tree.getCellEditor()); tree.setEditable(true); listener.reset(); tree.setCellEditor(editor2); listener.checkPropertyFired(tree, "cellEditor", editor1, editor2); assertEquals("cellEditor", editor2, tree.getCellEditor()); assertTrue(tree.isEditable()); listener.reset(); tree.setCellEditor(editor2); assertFalse("event's not been fired ", listener.isChanged()); listener.reset(); tree.setCellEditor(null); listener.checkPropertyFired(tree, "cellEditor", editor2, null); // it's being controlled by UI via listener assertNotNull("cellEditor", tree.getCellEditor()); assertNotSame("cellEditor", oldEditor, tree.getCellEditor()); assertNotSame("cellEditor", editor2, tree.getCellEditor()); assertTrue(tree.isEditable()); listener.reset(); }
public void testSetGetCellEditor() { assertNull(ui.getCellEditor()); DefaultTreeCellEditor editor = new DefaultTreeCellEditor(tree, new DefaultTreeCellRenderer()); tree.setCellEditor(editor); assertEquals(editor, ui.getCellEditor()); ui.setCellEditor(new DefaultTreeCellEditor(tree, new DefaultTreeCellRenderer())); assertEquals(editor, ui.getCellEditor()); }
public void testUpdateCellEditor() { DefaultTreeCellEditor e1 = new DefaultTreeCellEditor(tree, new DefaultTreeCellRenderer()); tree.setCellEditor(e1); assertSame(e1, tree.getCellEditor()); assertNull(ui.cellEditor); assertSame(e1, ui.getCellEditor()); tree.setEditable(true); assertSame(e1, ui.cellEditor); assertSame(e1, ui.getCellEditor()); DefaultTreeCellEditor e2 = new DefaultTreeCellEditor(tree, new DefaultTreeCellRenderer()); ui.cellEditor = e2; assertSame(e1, ui.getCellEditor()); assertSame(e2, ui.cellEditor); ui.updateCellEditor(); assertSame(e1, ui.cellEditor); assertSame(e1, tree.getCellEditor()); ui.cellEditor = null; assertFalse(ui.createdCellEditor); ui.createdCellEditor = true; assertTrue(ui.createdCellEditor); ui.updateCellEditor(); assertFalse(ui.createdCellEditor); assertSame(e1, ui.cellEditor); assertSame(e1, tree.getCellEditor()); tree.setCellRenderer(new DefaultTreeCellRenderer()); assertFalse(ui.createdCellEditor); assertSame(e1, ui.cellEditor); assertSame(e1, tree.getCellEditor()); ui.createdCellEditor = true; tree.setCellRenderer(new DefaultTreeCellRenderer()); assertTrue(ui.createdCellEditor); assertNotSame(e1, ui.cellEditor); assertNotSame(e1, tree.getCellEditor()); }