Editing a Tree Cell

Hi All,
I know that many questions crop up in this area; I will try to be brief.
My class extends JTextField and implements TreeCellEditor. I defined these methods:
1. addCellEditorListener
2. isCellEditable
3. getTreeCellEditorComponent
4. shouldSelectCell
5. getCellEditorValue
6. cancelCellEditing
7. stopCellEditing
8. removeCellEditorListener
Numbers 2,3,4 make sense to me. They seem to say "if the cell is editable, then get its editor component, and decide if the whole cell should be selected when placed into edit." These work as I expected.
But I also observe - and do not understand - this behavior:
1. click inside a cell to edit it
2. type something to change its content and hit the ENTER key
When I do this, nothing happens. That is, the text cursor remains positioned within the cell. I found this strange because before I defined my own cell editor, I am fairly certain that the default editor responded to the enter key by removing the cell from edit mode.
Stranger still is this: if, after editing a cell, I remove focus from it, e.g., I click on another cell, the first cell reverts to its former value. This is most frustrating. In this case, unlike the enter key case, I believe that getCellEditorValue is called. My understanding is that this method gets called when an edit is viewed as complete. Hence I return the current value of the cell. Some tracing shows that I am returning the proper value. Yet the cell reverts to its original, pre-edit value.
So I guess I have two questions:
1. what is "normative" in the "edit cycle", i.e., how is editing customarily terminated? Related to this is the disposition of the text cursor after edit. I prefer it not to remain in the edited field.
2. Why does losing focus after edit cause my edited field to revert to its pre-edit value?
As always, I am grateful for whatever light you can shed on these matters.
Cordially,
Paul

It is a good thing you are learning how to use the TreeCellEditor interface but if you are doing something more than just learning then I would advice you use the DefaultCellEditor class instead. also if you desire to implement your own TreeCellEditor then, take time to take a look at the source code for your DefaultCellEditor class you should see what you are doing wrong and what they did right. The source code is in "JDKdir/src.zip"
ICE

Similar Messages

  • Editing non-tree cells problem in JTreeTable

    Hello all,
    I've been playing around with the JTreeTable for quite a while and have a fairly good grip on it. However, I've run into a problem that involves the display of cell data in the non-tree cells.
    Assume I have a JTreeTable with one node below the root (and the root node is not displayed). Also assume I've edited some information in one of the other cells in a 5-celled JTreeTable. The JTreeTable behaves normally with regard to editing/setting the values of the table cells.
    Now, with the click of a separate button, I programmatically create a new node in the JTree. I update the JTree model with a call to nodeChanged() and nodeStructureChanged() (or I could call reload() - both seem to work).
    This successfully adds a node, but in the process clears the entire remainder of the table's cell values. If I call fireTableDataChanged(), then the display of the JTree gets all screwed up (basically what happens to the display if you add/remove nodes, but don't update the display in a JTree). Not only that, but the fireTableDataChanged() method still does not redisplay my cell information for the remainder of the table.
    I'm at a loss to figure out what's responsible for this. The tableCellRenderer seems to work just fine until I add node. Even then, the tableCellRenderer for the JTree still works until I call fireTableDataChanged().
    Any ideas?
    Thank you,
    Brion Swanson

    I use a JTreeTable and in looking at my code, I've
    noticed that I make use of treeTable.repaint() fairly
    frequently (as whenever I update my stuff).Did the treeTable.updateUI do funky things to your JTree? It does on mine if I do a programmatic node addition or removal (basically any change to the tree structure will cause treeTable.updateUI() to completely destroy the display of the tree). This is a separate issue, but I thought I'd ask anyway since you seem to have run into at least a few of the same problems I'm experiencing.
    I don't fully understand your problem<snip/>
    do you mean
    it drops all edits you have done?Yes, it drops all the edits except the one currently being "edited" (that is, the selected editable cell will not lose it's value).
    I had a problem about it dropping the edits I had
    done and I resolved them by adding key listeners
    and played with the TableCellEditor.Could you elaborate on what you did to the TableCellEditor and which object you had listening to the keys (the table? or the tree? or something else?).
    You help is greatly appreciated!
    Brion Swanson

  • Editing a single cell at node level in Alv tree

    Hi ,
    I  am a beginner in ALV tree.Can u please let me know if its possible to edit a single cell at the node level ?
    Thanks in advance.
    Archna

    Check the Standard Program may it helpful BCALV_TREE_ITEMLAYOUT.
    Kanagaraja L

  • Focus Lost on Tree Cell Edit

    I am trying to force changes made in a tree cell edit when focus to that tree node has been lost(like on an enter button press) but it always reverts to the old value. i have tried adding a CellEditorListener to force an enter key press on the editingCanceled action but this still reverts the value.
    Anyone have any ideas on how to fix this?
    Thanks.

    Hi,
    Try to use
        call method cl_gui_control=>set_focus exporting control = grid1.

  • Editable ALV Tree

    Hello All,
    I am trying to make an Editable ALV tree ..but cannot find the
    I have used fieldcat -edit = X but it only works for GRID ALV and not TREE ALV ...
    Please help me on this .....
    Edited by: Karan Chopra on Aug 2, 2010 1:11 PM

    Hi Karan
    CL_GUI_ALV_TREE is only a display tool.
    It has not a feature for editable data unfortunately.
    I was used a popup input screen on cell "double click" event to change the data in a cell
    in one of my projects.
    Maybe it can be a solution for u .

  • Editing in Tree....

    Hi group,
    In my tree I am setting in setCellRenderer method like
    mytree.setCellRenderer(new CellRend());
    In CellRend class:which extends DefaultTreeCellRenderer.
    in that getTreeCellRendererComponent()... I write like..
    public java.awt.Component getTreeCellRendererComponent(
         javax.swing.JTree tree,
         Object value,
         boolean sel,
         boolean expanded,
         boolean leaf,
         int w,
         boolean hasFocus) {
         setOpenIcon(new ImageIcon("open.gif"));
         setClosedIcon(new ImageIcon("closed.jpg"));
         java.awt.Component compo = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, w, hasFocus);
         javax.swing.tree.DefaultMutableTreeNode node = (javax.swing.tree.DefaultMutableTreeNode)value;
         if(node.toString().equalsIgnoreCase("House"))
              tree.setEditable(false);
         else
              tree.setEditable(true);
         return compo;
    in my tree I have "House" node out of 10 nodes.
    I don't want to edit that particular "House" node.
    But as per my code it is editing why?
    Is any possible solution not to edit that "House" node.?
    Shalinipriya.

    if you call tree.setEditable(true) (or false) this changes the editing option for the entire tree, not just the current node. And the tree cell renderer gets called for all the nodes... So here's what is happening in your code:
    Let us assume that node 7 is your "House" node...
    The tree starts to render the nodes... it calls getTreeCellRendererComponent() for nodes 1 to 6, and each time, the expression (node.toString().equalsIgnoreCase("House")) is false, so it does: tree.setEditable(true). OK - now it gets to node 7, and (node.toString().equalsIgnoreCase("House")) is now true, so it does tree.setEditable(false) - making the entire tree not editable. Finally, it renders nodes 8, 9 & 10, where (node.toString().equalsIgnoreCase("House")) is false again, so it does: tree.setEditable(true), so when it has finished rendering, the entire tree is editable.
    That's why it doesn't work. Now, I don't know if you can directlly make only one single node editable or not editable (unless someone else knows different??) One workaround would be to add a listener, and if the user tries to edit your House node, pop up a message telling them not to, or just silently change its value back to House after they have finished (That'll frustrate the hell out of 'em ;-)

  • How do I edit a table cell value in the same view?

    This is probably just a clarification more than a question, but when looking at the iPhone->Settings->Mail,Contacts,Calenders view. If you select a mail account, you are taken to the account edit view where you can edit your account information.
    In this particular example, there is a 4 row grouped table section, with headers like "Name", "Address", "Password" and "Description".
    I am trying to duplicate this method of data entry where I don't have the user select the cell and get navigated to a new screen, but rather just pop up the appropriate keyboard, and allow them to edit within the cells within the same view.
    Currently, the only implementation that seems to make sense is to add a UITextField to the cell, and when the user selects, it will allow them to duplicate this behavior. It seems like there's an easier way to do this, but just not finding it.
    it seems like SetEditing deals more with deleting, adding and reordering...not actually editing data within the cells.
    Anyways, if there are any tips/tutorials/etc to look at, much appreciated!

    i do that. but the new window doesnt open a folder in the same path location 

  • How to display multiple JComponents in a tree cell renderer

    I have an object in a tree cell renderer and want to display its members(three members) status in a JTree as checkboxes such that each node displays three checkboxex with member-names and a node name. i tried using a JPanel and adding three labels into this panel to be returned for the cell renderer but the GUI fails to paint the node componnents. However on clicking the node the component which isn't visible displays correctly. please Help me out

    Since you didn't provide any sample code, it's all about wild guesses on what your problem is. The following code shows the type of program you could have posted :import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.*;
    public class TestTree extends JPanel {
         private static class MyCell {
              String theCellName;
              boolean theFirstField;
              boolean theSecondField;
              boolean theThirdField;
              public MyCell(String aName, boolean firstField, boolean secondField, boolean thirdField) {
                   theCellName = aName;
                   theFirstField = firstField;
                   theSecondField = secondField;
                   theThirdField = thirdField;
         private static class MyTreeCellRenderer extends JPanel implements TreeCellRenderer {
              private JLabel theCellNameLabel;
              private JCheckBox theFirstCheckBox;
              private JCheckBox theSecondCheckBox;
              private JCheckBox theThirdCheckBox;
              private DefaultTreeCellRenderer theDelegate;
              public MyTreeCellRenderer() {
                   super(new GridLayout(4, 1));
                   theCellNameLabel = new JLabel();
                   add(theCellNameLabel);
                   theFirstCheckBox = new JCheckBox("firstField");
                   add(theFirstCheckBox);
                   theSecondCheckBox = new JCheckBox("secondField");
                   add(theSecondCheckBox);
                   theThirdCheckBox = new JCheckBox("thirdField");
                   add(theThirdCheckBox);
                   theDelegate = new DefaultTreeCellRenderer();
                   setOpaque(true);
              public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                                                                       boolean expanded, boolean leaf, int row, boolean hasFocus) {
                   if (!(value instanceof DefaultMutableTreeNode)) {
                        return theDelegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
                   Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
                   if (!(userObject instanceof MyCell)) {
                        return theDelegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
                   setBackground(tree.getBackground());
                   if (selected) {
                        setBorder(BorderFactory.createLineBorder(Color.BLUE, 2));
                   } else {
                        setBorder(BorderFactory.createLineBorder(getBackground(), 2));
                   MyCell cell = (MyCell)userObject;
                   theCellNameLabel.setText(cell.theCellName);
                   theFirstCheckBox.setSelected(cell.theFirstField);
                   theSecondCheckBox.setSelected(cell.theSecondField);
                   theThirdCheckBox.setSelected(cell.theThirdField);
                   return this;
              public Component add(Component comp) {
                   if (comp instanceof JComponent) {
                        ((JComponent)comp).setOpaque(false);
                   return super.add(comp);
         public TestTree() {
              super(new BorderLayout());
              JTree tree = new JTree(createModel());
              tree.setShowsRootHandles(true);
              tree.setCellRenderer(new MyTreeCellRenderer());
              add(new JScrollPane(tree), BorderLayout.CENTER);
         private static final TreeModel createModel() {
              DefaultMutableTreeNode root = new DefaultMutableTreeNode(new MyCell("root", true, true, true));
              DefaultMutableTreeNode child1 = new DefaultMutableTreeNode(new MyCell("child1", false, true, false));
              DefaultMutableTreeNode child2 = new DefaultMutableTreeNode(new MyCell("child2", false, false, true));
              root.add(child1);
              root.add(child2);
              return new DefaultTreeModel(root);
         public static void main(String[] args) {
              final JFrame frame = new JFrame("Test");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setContentPane(new TestTree());
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        frame.setSize(600, 400);
                        frame.show();
    }

  • Edit a JTable cell, click save button, value isn't stored in JTable

    I'm editing a JTable cell, just using default editor provided by JTable
    I click a save button elsewhere in my GUI
    The value typed into the cell so far isn't stored in the TableModel yet and so doesn't get saved.
    How can I make sure the value gets stored in the JTable in the above scenario when the JButton is pressed but before saving.
    Preferably I'd like the code with the JButton not to have to know about the JTable at all.
    Cheers,
    D

    I the forums 100s of times.Many thanks. If they had a decent search on this forum I might have found it as I did try.
    Come to think of it - Sun have completely fcukd up this forum.

  • Edit JTable Date Cell, press Enter, the Time Cell changes to GMT time!

    Has anyone seen this strange behavior? I try to edit a Date Cell in JTable (orig. value 10/02/2000) and change it to (10/03/2000), I press Enter. But, the value of my Time Cell in the next column, same row which I never edited (orig. value 00:05:00) changes to approximately my system time in GMT (16:28:48).
    This is an excerpt from my TableModel which get called from setValueAt():1734 javax.swing.JTable, JTable.java. In the code below, the debug statement prints out:
    row, col = 0,0
    Value in SubTableModel = 10-02-2000 16:28:48
    Value should be "10-02-2000" since I did not edit the time cell at all. And why is row and col both zero?
    public void setValueAt(Object value, int row, int col) {
    try {
    ((ITableCellAdapter)adapters.get(col)).setData(getRow(row),col);
    System.out.println("row, col = " + row + col);
    System.out.println("Value in SubTableModel = " + value.toString());
    ((ITableCellAdapter)adapters.get(col)).setValue(value);
    catch (PropertyVetoException badSet) {
    System.out.println("could not set value");
    fireTableCellUpdated(row,col);
    How can I force it to set the date cell's new value only and leave the time cell alone?
    I've also seen that sometimes my date entry gets lost, the old value still showing, what am I doing wrong? I've seen a bunch of bug parade listings about terminating edits within a JTable being buggy, is this related?
    Any help on this is most appreciated!

    Did you find the solution to yuor problem?
    Has anyone seen this strange behavior? I try to edit
    a Date Cell in JTable (orig. value 10/02/2000) and
    change it to (10/03/2000), I press Enter. But, the
    value of my Time Cell in the next column, same row
    which I never edited (orig. value 00:05:00) changes to
    approximately my system time in GMT (16:28:48).
    This is an excerpt from my TableModel which get called
    from setValueAt():1734 javax.swing.JTable,
    JTable.java. In the code below, the debug statement
    prints out:
    row, col = 0,0
    Value in SubTableModel = 10-02-2000 16:28:48
    Value should be "10-02-2000" since I did not edit the
    time cell at all. And why is row and col both zero?
    public void setValueAt(Object value, int row, int
    nt col) {
    try {
    ((ITableCellAdapter)adapters.get(col)).setData(getRow(
    ow),col);
    System.out.println("row, col = " + row +
    + row + col);
    System.out.println("Value in SubTableModel = "
    del = " + value.toString());
    ((ITableCellAdapter)adapters.get(col)).setValue(value)
    catch (PropertyVetoException badSet) {
    System.out.println("could not set value");
    fireTableCellUpdated(row,col);
    How can I force it to set the date cell's new value
    only and leave the time cell alone?
    I've also seen that sometimes my date entry gets lost,
    the old value still showing, what am I doing wrong?
    I've seen a bunch of bug parade listings about
    terminating edits within a JTable being buggy, is
    this related?
    Any help on this is most appreciated!

  • Add/Edit/Delete Tree Nodes using CL_GUI_ALV_TREE

    Hi All,
    I am looking for an example of program with CL_GUI_ALV_TREE that have a functionality of add a tree node, edit a tree node, and delete a tree node.
    I have already looked the BCALV_TREE* demo program but could not able to find a program to add/edit/delete node tree elements.
    Any info on this.
    Thanks
    aRs

    Hello aRs
    Here is a sample report showing how to delete nodes in an ALV tree. The report was copied from BCALV_TREE_01. Search for added code:
    *$ADDED: begin
    *$ADDED: end[/code]
    When you display the tree expand the first folder completely. When entering 'DELETE' into the command field directly the first flight date node will be deleted.
    REPORT ZUS_SDN_BCALV_TREE_01_DELNODE.
    based on: REPORT  bcalv_tree_01.
    Purpose:
    ~~~~~~~~
    This report shows the essential steps to build up a hierarchy
    using an ALV Tree Control (class CL_GUI_ALV_TREE).
    Note that it is not possible to build up this hierarchy
    using a simple ALV Tree Control (class CL_GUI_ALV_TREE_SIMPLE).
    To check program behavior
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    Start this report. The hierarchy tree consists of nodes for each
    month on top level (this level can not be build by a simple ALV Tree
    because there is no field for months in our output table SFLIGHT.
    Thus, you can not define this hierarchy by sorting).
    Nor initial calculations neither a special layout has been applied
    (the lines on the right do not show anything).
    Note also that this example does not build up and change the
    fieldcatalog of the output table. For this reason, all fields
    of the output table are shown in the columns although the fields
    CARRID and FLDATE are already placed in the tree on the left.
    (Of course, this is not a good style. See BCALV_TREE_02 on how to
    hide columns).
    Essential steps (Search for '§')
    ~~~~~~~~~~~~~~~
    1.Usual steps when using control technology.
       1a. Define reference variables.
       1b. Create ALV Tree Control and corresponding container.
    2.Create Hierarchy-header
    3.Create empty Tree Control
    4.Create hierarchy (nodes and leaves)
       4a. Select data
       4b. Sort output table according to your conceived hierarchy
       4c. Add data to tree
    5.Send data to frontend.
    6.Call dispatch to process toolbar functions
    *$ADDED: begin
    DATA:
      gd_del_nkey      TYPE lvc_nkey.
    *$ADDED: end
    §1a. Define reference variables
    DATA: g_alv_tree         TYPE REF TO cl_gui_alv_tree,
          g_custom_container TYPE REF TO cl_gui_custom_container.
    DATA: gt_sflight      TYPE sflight OCCURS 0,      "Output-Table
          ok_code LIKE sy-ucomm,
          save_ok LIKE sy-ucomm,           "OK-Code
          g_max TYPE i VALUE 255.
    END-OF-SELECTION.
      CALL SCREEN 100.
    *&      Module  PBO  OUTPUT
          process before output
    MODULE pbo OUTPUT.
      SET PF-STATUS 'MAIN100'.
      SET TITLEBAR 'MAINTITLE'.
      IF g_alv_tree IS INITIAL.
        PERFORM init_tree.
        CALL METHOD cl_gui_cfw=>flush
          EXCEPTIONS
            cntl_system_error = 1
            cntl_error        = 2.
        IF sy-subrc NE 0.
          CALL FUNCTION 'POPUP_TO_INFORM'
            EXPORTING
              titel = 'Automation Queue failure'(801)
              txt1  = 'Internal error:'(802)
              txt2  = 'A method in the automation queue'(803)
              txt3  = 'caused a failure.'(804).
        ENDIF.
      ENDIF.
    ENDMODULE.                             " PBO  OUTPUT
    *&      Module  PAI  INPUT
          process after input
    MODULE pai INPUT.
      save_ok = ok_code.
      CLEAR ok_code.
      CASE save_ok.
        WHEN 'EXIT' OR 'BACK' OR 'CANC'.
          PERFORM exit_program.
    *$ADDED: begin
        WHEN 'DELETE'.
          CALL METHOD g_alv_tree->delete_subtree
            EXPORTING
              i_node_key                = gd_del_nkey
             I_UPDATE_PARENTS_EXPANDER = SPACE
              i_update_parents_folder   = 'X'
            EXCEPTIONS
              node_key_not_in_model     = 1
              OTHERS                    = 2.
          IF sy-subrc <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                     WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          CALL METHOD g_alv_tree->frontend_update.
    *$ADDED: end
        WHEN OTHERS.
    §6. Call dispatch to process toolbar functions
          CALL METHOD cl_gui_cfw=>dispatch.
      ENDCASE.
      CALL METHOD cl_gui_cfw=>flush.
    ENDMODULE.                             " PAI  INPUT
    *&      Form  init_tree
          text
    -->  p1        text
    <--  p2        text
    FORM init_tree.
    §1b. Create ALV Tree Control and corresponding Container.
    create container for alv-tree
      DATA: l_tree_container_name(30) TYPE c.
      l_tree_container_name = 'CCONTAINER1'.
      CREATE OBJECT g_custom_container
         EXPORTING
               container_name = l_tree_container_name
         EXCEPTIONS
               cntl_error                  = 1
               cntl_system_error           = 2
               create_error                = 3
               lifetime_error              = 4
               lifetime_dynpro_dynpro_link = 5.
      IF sy-subrc <> 0.
        MESSAGE x208(00) WITH 'ERROR'(100).
      ENDIF.
    create tree control
      CREATE OBJECT g_alv_tree
        EXPORTING
            parent              = g_custom_container
            node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
            item_selection      = 'X'
            no_html_header      = 'X'
            no_toolbar          = ''
        EXCEPTIONS
            cntl_error                   = 1
            cntl_system_error            = 2
            create_error                 = 3
            lifetime_error               = 4
            illegal_node_selection_mode  = 5
            failed                       = 6
            illegal_column_name          = 7.
      IF sy-subrc <> 0.
        MESSAGE x208(00) WITH 'ERROR'.                          "#EC NOTEXT
      ENDIF.
    §2. Create Hierarchy-header
    The simple ALV Tree uses the text of the fields which were used
    for sorting to define this header. When you use
    the 'normal' ALV Tree the hierarchy is build up freely
    by the programmer this is not possible, so he has to define it
    himself.
      DATA l_hierarchy_header TYPE treev_hhdr.
      PERFORM build_hierarchy_header CHANGING l_hierarchy_header.
    §3. Create empty Tree Control
    IMPORTANT: Table 'gt_sflight' must be empty. Do not change this table
    (even after this method call). You can change data of your table
    by calling methods of CL_GUI_ALV_TREE.
    Furthermore, the output table 'gt_outtab' must be global and can
    only be used for one ALV Tree Control.
      CALL METHOD g_alv_tree->set_table_for_first_display
        EXPORTING
          i_structure_name    = 'SFLIGHT'
          is_hierarchy_header = l_hierarchy_header
        CHANGING
          it_outtab           = gt_sflight. "table must be empty !
    §4. Create hierarchy (nodes and leaves)
      PERFORM create_hierarchy.
    §5. Send data to frontend.
      CALL METHOD g_alv_tree->frontend_update.
    wait for automatic flush at end of pbo
    ENDFORM.                               " init_tree
    *&      Form  build_hierarchy_header
          build hierarchy-header-information
         -->P_L_HIERARCHY_HEADER  strucxture for hierarchy-header
    FORM build_hierarchy_header CHANGING
                                   p_hierarchy_header TYPE treev_hhdr.
      p_hierarchy_header-heading = 'Month/Carrier/Date'(300).
      p_hierarchy_header-tooltip = 'Flights in a month'(400).
      p_hierarchy_header-width = 30.
      p_hierarchy_header-width_pix = ' '.
    ENDFORM.                               " build_hierarchy_header
    *&      Form  exit_program
          free object and leave program
    FORM exit_program.
      CALL METHOD g_custom_container->free.
      LEAVE PROGRAM.
    ENDFORM.                               " exit_program
    *&      Form  create_hierarchy
          text
    -->  p1        text
    <--  p2        text
    FORM create_hierarchy.
      DATA: ls_sflight TYPE sflight,
            lt_sflight TYPE sflight OCCURS 0,
            l_yyyymm(6) TYPE c,            "year and month of sflight-fldate
            l_yyyymm_last(6) TYPE c,
            l_carrid LIKE sflight-carrid,
            l_carrid_last LIKE sflight-carrid.
      DATA: l_month_key TYPE lvc_nkey,
            l_carrid_key TYPE lvc_nkey,
            l_last_key TYPE lvc_nkey.
    §4a. Select data
      SELECT * FROM sflight INTO TABLE lt_sflight UP TO g_max ROWS.
    §4b. Sort output table according to your conceived hierarchy
    We sort in this order:
       year and month (top level nodes, yyyymm of DATS)
         carrier id (next level)
            day of month (leaves, dd of DATS)
      SORT lt_sflight BY fldate0(6) carrid fldate6(2).
    Note: The top level nodes do not correspond to a field of the
    output table. Instead we use data of the table to invent another
    hierarchy level above the levels that can be build by sorting.
    §4c. Add data to tree
      LOOP AT lt_sflight INTO ls_sflight.
    Prerequesite: The table is sorted.
    You add a node everytime the values of a sorted field changes.
    Finally, the complete line is added as a leaf below the last
    node.
        l_yyyymm = ls_sflight-fldate+0(6).
        l_carrid = ls_sflight-carrid.
    Top level nodes:
        IF l_yyyymm <> l_yyyymm_last.      "on change of l_yyyymm
          l_yyyymm_last = l_yyyymm.
    *Providing no key means that the node is added on top level:
          PERFORM add_month USING    l_yyyymm
                                 CHANGING l_month_key.
    The month changed, thus, there is no predecessor carrier
          CLEAR l_carrid_last.
        ENDIF.
    Carrier nodes:
    (always inserted as child of the last month
    which is identified by 'l_month_key')
        IF l_carrid <> l_carrid_last.      "on change of l_carrid
          l_carrid_last = l_carrid.
          PERFORM add_carrid_line USING    ls_sflight
                                           l_month_key
                                  CHANGING l_carrid_key.
        ENDIF.
    Leaf:
    (always inserted as child of the last carrier
    which is identified by 'l_carrid_key')
        PERFORM add_complete_line USING  ls_sflight
                                         l_carrid_key
                                CHANGING l_last_key.
      ENDLOOP.
    ENDFORM.                               " create_hierarchy
    *&      Form  add_month
    FORM add_month  USING     p_yyyymm TYPE c
                              p_relat_key TYPE lvc_nkey
                    CHANGING  p_node_key TYPE lvc_nkey.
      DATA: l_node_text TYPE lvc_value,
            ls_sflight TYPE sflight,
            l_month(15) TYPE c.            "output string for month
    get month name for node text
      PERFORM get_month USING p_yyyymm
                        CHANGING l_month.
      l_node_text = l_month.
    add node:
    ALV Tree firstly inserts this node as a leaf if you do not provide
    IS_NODE_LAYOUT with field ISFOLDER set. In form 'add_carrid_line'
    the leaf gets a child and thus ALV converts it to a folder
    automatically.
      CALL METHOD g_alv_tree->add_node
        EXPORTING
          i_relat_node_key = p_relat_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          i_node_text      = l_node_text
          is_outtab_line   = ls_sflight
        IMPORTING
          e_new_node_key   = p_node_key.
    ENDFORM.                               " add_month
    FORM add_carrid_line USING     ps_sflight TYPE sflight
                                   p_relat_key TYPE lvc_nkey
                         CHANGING  p_node_key TYPE lvc_nkey.
      DATA: l_node_text TYPE lvc_value,
            ls_sflight TYPE sflight.
    add node
    ALV Tree firstly inserts this node as a leaf if you do not provide
    IS_NODE_LAYOUT with field ISFOLDER set. In form 'add_carrid_line'
    the leaf gets a child and thus ALV converts it to a folder
    automatically.
      l_node_text =  ps_sflight-carrid.
      CALL METHOD g_alv_tree->add_node
        EXPORTING
          i_relat_node_key = p_relat_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          i_node_text      = l_node_text
          is_outtab_line   = ls_sflight
        IMPORTING
          e_new_node_key   = p_node_key.
    ENDFORM.                               " add_carrid_line
    *&      Form  add_complete_line
    FORM add_complete_line USING   ps_sflight TYPE sflight
                                   p_relat_key TYPE lvc_nkey
                         CHANGING  p_node_key TYPE lvc_nkey.
      DATA: l_node_text TYPE lvc_value.
      WRITE ps_sflight-fldate TO l_node_text MM/DD/YYYY.
    add leaf:
    ALV Tree firstly inserts this node as a leaf if you do not provide
    IS_NODE_LAYOUT with field ISFOLDER set.
    Since these nodes will never get children they stay leaves
    (as intended).
      CALL METHOD g_alv_tree->add_node
        EXPORTING
          i_relat_node_key = p_relat_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          is_outtab_line   = ps_sflight
          i_node_text      = l_node_text
        IMPORTING
          e_new_node_key   = p_node_key.
    *$ADDED: begin
      IF ( ps_sflight-fldate = '20040522' ).  " first flight date
        IF ( gd_del_nkey IS INITIAL ).  " collect only first date
          gd_del_nkey = p_node_key.
        ENDIF.
      ENDIF.
    *$ADDED: end
    ENDFORM.                               " add_complete_line
    *&      Form  GET_MONTH
          text
         -->P_P_YYYYMM  text
         <--P_L_MONTH  text
    FORM get_month USING    p_yyyymm
                   CHANGING p_month.
    Returns the name of month according to the digits in p_yyyymm
      DATA: l_monthdigits(2) TYPE c.
      l_monthdigits = p_yyyymm+4(2).
      CASE l_monthdigits.
        WHEN '01'.
          p_month = 'January'(701).
        WHEN '02'.
          p_month = 'February'(702).
        WHEN '03'.
          p_month = 'March'(703).
        WHEN '04'.
          p_month = 'April'(704).
        WHEN '05'.
          p_month = 'May'(705).
        WHEN '06'.
          p_month = 'June'(706).
        WHEN '07'.
          p_month = 'July'(707).
        WHEN '08'.
          p_month = 'August'(708).
        WHEN '09'.
          p_month = 'September'(709).
        WHEN '10'.
          p_month = 'October'(710).
        WHEN '11'.
          p_month = 'November'(711).
        WHEN '12'.
          p_month = 'December'(712).
      ENDCASE.
      CONCATENATE p_yyyymm+0(4) '->' p_month INTO p_month.
    ENDFORM.                               " GET_MONTH
    /code
    Regards
      Uwe

  • Tree cell disapearing

    Hi
    I'm using Java 1.5.0.11
    I'm trying to make my own tree cell renderer and editor : the goal is to add to the standard tree cell (icon + uneditable text) an icon to the left, to indicate a certain "state". The state can be change by clicking on it, showxing a JPopupMenu to select a new one.
    In my proto, it works well, except that when I change one row, it is redrawn completely blank. I need to click on it again to have it appear.
    Any idea on why?
    Best regards

    TreeSelector. java
    package treeselectproto;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.event.ActionEvent;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import javax.swing.AbstractAction;
    import javax.swing.AbstractCellEditor;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JPopupMenu;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.tree.TreeCellEditor;
    import javax.swing.tree.TreeCellRenderer;
    import javax.swing.tree.TreePath;
    public class TreeSelector {
         protected JTree itsTree;
         protected JScrollPane itsScrollPane;
         protected Map<Object, State> itsStates=new HashMap<Object, State>();
         protected CellRenderer itsRenderer;
         protected JPopupMenu itsPopupMenu = new JPopupMenu();
         public TreeSelector()
              itsTree=new JTree();
              itsRenderer=new CellRenderer();
              itsTree.setCellRenderer(itsRenderer);
              itsTree.setCellEditor(itsRenderer);
              itsTree.setEditable(true);
              buildScrollPane();
              List<State> theStates=State.getPopupStates();
              for(State s:theStates)
                   PopupAction a=new PopupAction(s);
                   JMenuItem mi=new JMenuItem(a);
                   itsPopupMenu.add(mi);
         private void buildScrollPane() {
              itsScrollPane= new JScrollPane(itsTree,
                        ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
         public JScrollPane getScrollPane() {
              return itsScrollPane;
         @SuppressWarnings("serial")
         private  class CellRenderer extends AbstractCellEditor implements TreeCellRenderer, TreeCellEditor
              private JPanel itsPanel;
              private JLabel itsLabel;
              private JButton itsStateBtn;
              private BorderLayout itsLayout;
              public  CellRenderer()
                   itsPanel=new JPanel();
                   itsPanel.setLayout(itsLayout=new BorderLayout());
                   itsPanel.setDoubleBuffered(false);
                   itsLayout.setVgap(1);
                   itsLayout.setHgap(1);
                   itsLabel=new JLabel();
                   itsLabel.setDoubleBuffered(false);
                   itsPanel.add(itsLabel,BorderLayout.CENTER);
                   itsStateBtn=new JButton(new AbstractAction(){
                        public void actionPerformed(ActionEvent aE) {
                             showPopup();
                   itsStateBtn.setBorderPainted(true);
                   itsStateBtn.setContentAreaFilled(false);
                   itsStateBtn.setDoubleBuffered(false);
                   itsPanel.add(itsStateBtn,BorderLayout.WEST);
              protected void showPopup() {
                   itsPopupMenu.show(itsStateBtn, 0, 0);
              public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
                   TreePath thePath=tree.getPathForRow(row);
                   itsPanel.setBackground(tree.getBackground());
                   if(thePath != null)
                        State theState=getStateForTreePath(thePath);
                        String ic=theState.getSign();
                        itsStateBtn.setText(ic);
                   itsLabel.setText(value.toString());
                   itsStateBtn.setPreferredSize(null);
                   itsLabel.setPreferredSize(null);
                   itsPanel.setBackground( selected? Color.lightGray:tree.getBackground());
                   itsLayout.invalidateLayout(itsPanel);
                   return itsPanel;
              private Object itsValue;
              public Component getTreeCellEditorComponent(JTree aTree, Object aValue, boolean aIsSelected, boolean aExpanded, boolean aLeaf, int aRow) {
                   // if edting, it has the focus
                   itsValue=aValue;
                   return getTreeCellRendererComponent(aTree,aValue,aIsSelected,aExpanded,aLeaf,aRow,true);
              public Object getCellEditorValue() {
                   return itsValue;
         public State getStateForTreePath(TreePath thePath) {
              State ret=itsStates.get(thePath.getLastPathComponent());
              if(ret==null)
                   ret=State.defaultState();
              return ret;
         @SuppressWarnings("serial")
         private class PopupAction extends AbstractAction
              protected State itsState;
              public PopupAction(State aState) {
                   super(aState.getLabel());
                   itsState = aState;
              public void actionPerformed(ActionEvent aE) {
                   TreePath thePath=itsTree.getEditingPath();
                   Object theObj=thePath.getLastPathComponent();
                   itsStates.put(theObj, itsState);
    }

  • Full ALV column getting editable not just cell!

    Need desparate help please...
    A very strange thing is happening. I have DATA_ITAB for ALV display. The ITAB has 2 extra fields one for STYLE one for COLOR as follows:-
    TYPES : cellstyles TYPE lvc_t_styl ,
    *for editing cells
    For cell coloring
    cellcolor TYPE lvc_t_scol.
    The correct cells are being coloured based on the logic. The issue is with the editable cells. The whole column is being made editable including the cell. I have checked in debugger all rows of the ITAB_DATA have correct fields in the cellstyles tab with fields sorted to reflect which fields should be edidable for each index. Still the whole column is being made editable.
    I am NOT using edit flag for the field catalogue so that is not a problem......I have included the cellstyles field in the layout of the grid....
    Can anyone help with this issue......thnx

    Thank you guys for your silence That prompted me to continue to look at my code and finally noticed I had marked the column editable in fieldcat
    Once i switched that of and then called the following it worked like a GEM:-
    CALL METHOD p_ob_grid->set_ready_for_input
          EXPORTING
            i_ready_for_input = 1.
    << Please do not offer points >>
    Edited by: Rob Burbank on Oct 8, 2010 2:11 PM

  • TextFormatter in list, table and tree cells

    Release 8u40 introduces the TextFormatter concept in the text input field area. It is currently a new property of the TextInputControl class.
    This is defintely a more elegant way to deal with validation than overriding "replaceText(...)".
    Shouldn't this property also be available in list, table and tree cells ?
    Are there plans to do this (before we make our own implementation) ?

    I've got exactly the same problem, +1.
    This shouldn't be to difficult to solve for 8u60 and definitely useful,
    giving access to the text input control in mutable cells could be a one-line workaround !
    Additionally, could a TextFormatter be made shareable between table/list rows
    by NOT using the value/valueConverter properties, but only the filter part in cases
    where the final desired output type is String ?

  • Tree Cell Editorer

    I have a problem with editing a cell in a tree
    I implemented the TreeCellEditorer
    public Component getTreeCellEditorComponent(JTree arg0, Object value, ...){
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
        Object userObject = node.getUserObject();
        if (userObject instanceof OverLay)
            return ((OverLay) userObject).getComponent();  // return a JPanel
        return new JLabel(userObject.toString());  // return the String
    public boolean isCellEditable(EventObject arg0) {
         return true;
    }I also set the tree editable property to true
    tree.setEditable(true);
    basiaclly, the line of code:
    return ((OverLay) userObject).getComponent();  // return a JPanelreturns a JPanel, and this panel contains 3 JCheckBox, and JLabels
    i cannot check or uncheck the JCheckBox. How can i fix this?

    my fault.
    I had the setEditable(false) on the JCheckBox.

Maybe you are looking for

  • Why is firefox crashing my pc out of the blue?

    I have a windows 8 Toshiba laptop. I've always used firefox for the past year since I got it, that's my choice of web-browsers but today something went wrong. I went open firefox and it crashed to the point where I couldn't even open the task manager

  • When on a website and I select an e-mail link it does not open.

    E-mail links for open web sites do not open>

  • 11S: can't use ax88179's Ethernet port

    As previously discussed in Microsoft's forums, ax88179 is a portable Ethernet card needed for laptops that only have WIFI...like Yoga 11S. When I download the latest driver Win 8.1 64-bit (both through setup.exe and the direct INF file) and install i

  • Modem DSL Light flashes

    Hello I posted a few days ago about my PPPOE connection dropping on my Apple router around once or twice per day. I have since noticed that when this happens, the DSL light on the white modem also goes out and flashes. In fact, it happened last night

  • Generating Envelopes in Report Builder

    I am wanting to know if there is a wizard or someway to generate a Mailing Envelope report for Number 10 envelopes. I end up creating a landscape report on 8 1/2 x 11 paper with a top margin of 2.5 inches and a left margin of 1.625 inches. I have to