/** Synchronize the root context from the manager of this Explorer. */ final void synchronizeRootContext() { // #151850 cancel editing before changing root node Mutex.EVENT.readAccess(new Runnable() { @Override public void run() { TreeCellEditor cellEditor = tree.getCellEditor(); if (cellEditor instanceof TreeViewCellEditor) { ((TreeViewCellEditor) cellEditor).abortTimer(); } tree.cancelEditing(); final Node rc = manager.getRootContext(); LOG.log(Level.FINE, "synchronizeRootContext {0}", rc); treeModel.setNode(rc, visHolder); } }); }
/** * Uninstall all registered listeners */ protected void uninstallListeners() { tree.removePropertyChangeListener(propertyChangeListener); tree.removeFocusListener(focusListener); tree.removeTreeSelectionListener(treeSelectionListener); tree.removeMouseListener(mouseListener); tree.removeKeyListener(keyListener); tree.removePropertyChangeListener(selectionModelPropertyChangeListener); tree.removeComponentListener(componentListener); tree.removeTreeExpansionListener(treeExpansionListener); TreeCellEditor tce = tree.getCellEditor(); if (tce != null) tce.removeCellEditorListener(cellEditorListener); if (treeModel != null) treeModel.removeTreeModelListener(treeModelListener); }
public void propertyChange(final PropertyChangeEvent e) { String changedProperty = e.getPropertyName(); if (JTree.CELL_RENDERER_PROPERTY.equals(changedProperty)) { setCellRenderer((TreeCellRenderer)e.getNewValue()); } else if (JTree.CELL_EDITOR_PROPERTY.equals(changedProperty)) { setCellEditor((TreeCellEditor)e.getNewValue()); } else if (JTree.TREE_MODEL_PROPERTY.equals(changedProperty)) { setModel((TreeModel)e.getNewValue()); } else if (JTree.ROOT_VISIBLE_PROPERTY.equals(changedProperty)) { setRootVisible(((Boolean)e.getNewValue()).booleanValue()); } else if (JTree.SHOWS_ROOT_HANDLES_PROPERTY.equals(changedProperty)) { setShowsRootHandles(((Boolean)e.getNewValue()).booleanValue()); } else if (JTree.ROW_HEIGHT_PROPERTY.equals(changedProperty)) { setRowHeight(((Integer)e.getNewValue()).intValue()); } else if (JTree.EDITABLE_PROPERTY.equals(changedProperty)) { setEditable(((Boolean)e.getNewValue()).booleanValue()); } else if (JTree.LARGE_MODEL_PROPERTY.equals(changedProperty)) { setLargeModel(((Boolean)e.getNewValue()).booleanValue()); } else if (JTree.SELECTION_MODEL_PROPERTY.equals(changedProperty)) { setSelectionModel((TreeSelectionModel)e.getNewValue()); } else if (JTree.LEAD_SELECTION_PATH_PROPERTY.equals(changedProperty)) { TreePath leadPath = (TreePath)e.getNewValue(); lastSelectedRow = leadPath != null ? tree.getRowForPath(leadPath) : -1; } }
/** * This is invoked if a TreeCellEditor is not supplied in the constructor. * It returns a TextField editor. */ @Override protected TreeCellEditor createTreeCellEditor() { JTextField tf = new JTextField() { @Override public void addNotify() { stopped = cancelled = false; super.addNotify(); requestFocus(); } }; //#137454 - text not visible in in-place editor String laf = UIManager.getLookAndFeel().getID(); if( "GTK".equals( laf ) ) { //NOI18N tf.setBorder( BorderFactory.createEmptyBorder() ); } else if( "Nimbus".equals( laf ) ) { //NOI18N tf.setBorder( BorderFactory.createLineBorder( new JTree().getBackground() ) ); } tf.registerKeyboardAction( //TODO update to use inputMap/actionMap this, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true), JComponent.WHEN_FOCUSED); tf.addFocusListener(this); Ed ed = new Ed(tf); ed.setClickCountToStart(1); ed.getComponent().getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(TreeViewCellEditor.class, "ACSD_TreeViewCellEditor") ); // NOI18N ed.getComponent().getAccessibleContext().setAccessibleName( NbBundle.getMessage(TreeViewCellEditor.class, "ACSN_TreeViewCellEditor") ); // NOI18N return ed; }
/** * {@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; }
@Override protected TreeCellEditor createTreeCellEditor() { JTextField tf = new JTextField() { @Override public String getName() { return "Tree.cellEditor"; } }; DefaultCellEditor editor = new DefaultCellEditor(tf); // One click to edit. editor.setClickCountToStart(1); return editor; }
@Override protected TreeCellEditor createTreeCellEditor() { @SuppressWarnings("serial") // anonymous class JTextField tf = new JTextField() { @Override public String getName() { return "Tree.cellEditor"; } }; DefaultCellEditor editor = new DefaultCellEditor(tf); // One click to edit. editor.setClickCountToStart(1); return editor; }
/** * Maps {@code JTree.getCellEditor()} through queue */ public TreeCellEditor getCellEditor() { return (runMapping(new MapAction<TreeCellEditor>("getCellEditor") { @Override public TreeCellEditor map() { return ((JTree) getSource()).getCellEditor(); } })); }
/** * Maps {@code JTree.setCellEditor(TreeCellEditor)} through queue */ public void setCellEditor(final TreeCellEditor treeCellEditor) { runMapping(new MapVoidAction("setCellEditor") { @Override public void map() { ((JTree) getSource()).setCellEditor(treeCellEditor); } }); }
public void setCellEditor(TreeCellEditor editor) { if (cellEditor == editor) return; TreeCellEditor oldValue = cellEditor; cellEditor = editor; firePropertyChange(CELL_EDITOR_PROPERTY, oldValue, editor); }
/** * Updates the cellEditor based on editability of the JTree that we're * contained in. If the tree is editable but doesn't have a cellEditor, a * basic one will be used. */ protected void updateCellEditor() { completeEditing(); TreeCellEditor newEd = null; if (tree != null && tree.isEditable()) { newEd = tree.getCellEditor(); if (newEd == null) { newEd = createDefaultCellEditor(); if (newEd != null) { tree.setCellEditor(newEd); createdCellEditor = true; } } } // Update listeners. if (newEd != cellEditor) { if (cellEditor != null && cellEditorListener != null) cellEditor.removeCellEditorListener(cellEditorListener); cellEditor = newEd; if (cellEditorListener == null) cellEditorListener = createCellEditorListener(); if (cellEditor != null && cellEditorListener != null) cellEditor.addCellEditorListener(cellEditorListener); createdCellEditor = false; } }
@Override public Component getTreeCellEditorComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row) { final ErrorTreeElement element = getElement(value); if (element instanceof EditableMessageElement) { EditableMessageElement editableMessageElement = (EditableMessageElement)element; final CustomizeColoredTreeCellRenderer leftSelfRenderer = editableMessageElement.getLeftSelfRenderer(); final TreeCellEditor rightSelfEditor = editableMessageElement.getRightSelfEditor(); myColoredTreeCellRenderer.setCurrentCallback(leftSelfRenderer); myRightCellRenderer.setCurrentCallback(rightSelfEditor); return myWrapperEditor.getTreeCellEditorComponent(tree, value, selected, expanded, leaf, row); } return myTree.getCellRenderer().getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, true); }
@NotNull private Pair<JEditorPane, String> getCellEditorAndText() { // There is no specific UI component for a hyperlink in the "Messages" window. Instead we have a JEditorPane with HTML. This method // finds the anchor tags, and matches the text of each of them against the given text. If a matching hyperlink is found, we fire a // HyperlinkEvent, simulating a click on the actual hyperlink. assertThat(myTarget).isInstanceOf(EditableNotificationMessageElement.class); final JEditorPane editorComponent = execute(new GuiQuery<JEditorPane>() { @Override protected JEditorPane executeInEDT() throws Throwable { EditableNotificationMessageElement message = (EditableNotificationMessageElement)myTarget; TreeCellEditor cellEditor = message.getRightSelfEditor(); return field("editorComponent").ofType(JEditorPane.class).in(cellEditor).get(); } }); assertNotNull(editorComponent); String text = execute(new GuiQuery<String>() { @Override protected String executeInEDT() throws Throwable { return editorComponent.getText(); } }); assertNotNull(text); return Pair.create(editorComponent, text); }
/** * @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; }