Dynamic addition to JTree

HI all.Im a little frustrated.im emulating the structure of an xml file in a jtree.but what im trying to do is add a node to another node, when a button is clicked.the only problem im having is retrieving a particular node, whether it be a child or sub-child etc.
i have looked at the getIndexOfChild method of defaultTreeModel.but the problem is that when the user creates a child node (ive already created the root node) and wants to add it as a sub-child of another child node, it's here i have the prob.
i have
1 <-- root node
| 2 <-- child of 1
| | 3 <-- child of 2
| | |
1even though i created node 2 like so new DefaultMutableTreeNode("some name"); and i know the name i supplied to it in the constructor, how can i retrieve it again, so i can append another child onto this child.plz help (i dont want code)
thanks

So in the worst
case you could look at all the nodes in the tree, and
your problem is reduced to being able to recognize
the node when you see it.
That isn't a particularly good way, can i ask why this isnt a particularly good way?
here is what i ended up doing,
if(rowNumber == -1) {
                    //Create a new root node, for the very
                    //first entry.
                    rootNode = new DefaultMutableTreeNode(componentName);
                    dTreeModel = new DefaultTreeModel(rootNode);
                    dtm.addRow(new Object[] { componentName.trim(), new Boolean(false), new Boolean(false), new Boolean(false)});
                    rowNumber++;
                    v.add(rootNode);
                    drawTheHierarchy();
               else {
                    //we check to see if this variable is
                    //an attribute or a child of another component
                    //by scanning down through all the rows of table.
                    for(int     i = 0; i < rowCount; i++) {
                         //If user has checked one of the "Element OF"
                         //checkboxes:
                         String nameOfParent = getParentNames(i);
                         if(!nameOfParent.equals("null")) {
                              //get the index of the element with
                              //the name of 'component name' in the vector.
                              for(int j = 0; j < v.size(); j++) {
                                   //Get a string representation of the node
                                   //to allow comparison.
                                   String nodeStringRepresentation = v.get(j).toString();
                                   if(nameOfParent.equals(nodeStringRepresentation)) {
                                        //get the node from the vector
                                        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) v.get(j);
                                        //create a child node
                                        DefaultMutableTreeNode childNode =
                                                  new DefaultMutableTreeNode(componentName);
                                        //add a new node to this node.
                                        selectedNode.add(childNode);
                                        //and add to the vector.
                                        v.add(childNode);
                    }

Similar Messages

  • Dynamic addition of a column to a table

    Hi All,
    I need to add one column dynamically to the existing table and also I have to populate the data dynamically. Can you help me out in this? Thanks in advance.
    Message was edited by:
            Bharath Akuthota

    Either create it a design-time invisible and make it visible if needed (probably more simply than by code), or use some code like this:
    wdDoModifyView(...)
      if (<table structure changed>)
        IWDTable table = (IWDTable) view.getElement("TableID");
        IWDTableColumn col = (IWDTableColumn) view.createElement(IWDTableColumn.class, null);
        table.addColumn(col); // NW04
        table.addGroupedColumn(col); // NW 7.0
        IWDInputField editor = (IWDInputField) view.createElement(IWDInputField.class, null);
        col.setTableCellEditor(editor);
        editor.bindValue(<attribute inside table data source that should be edited>);
    Armin

  • Dynamic addition of  JMenuItem in JMenu

    I am trying to create a menu for my project. For that i have added the main menus and for each menu there will be menu item. But the problem is i will get the list of menu items for each menu , only at the runtime of my project. i.e. i wabt to add progrramatically add the menu items. Iam really confused with this. I will appriciate if any one help me on this.
    And also i want to know ..is that possible to get the mouse listener for menu.
    Thank in advance
    Regards,
    SAthish

    You can add and remove menu items from the jmenu dynamically, the only thing you will have to take care of is invoking validate() after each insertion/deletion (it's a bit buggy there). All you have to do is create the items on demand and add (remove) them via the add(JMenuItem) (remove(JMenuItem)) method.
    As for your second question, a JMenu is nothing but a JComponent, so you should be able to add a mouse listener like you would with any other component...

  • Dynamic update of JTree?

    Hi
    I have one JTree and one form. When I load data from database the JTree is not changed. When I click on the root the data apper, but when I make second query the Tree is not changed.
    How can I solve this two problems.
    Can someone help me.
    Thanks.

    Whichever TreeModel class you use to expose the data as a tree needs to fire events to let the tree know that the data changed. DefaultTreeModel does this for you, but if you implement your own TreeModel you'll need to fire events to the TreeModelListeners yourself.

  • Dynamic addition of values in Popup

    Hi ,
      I have a requirement to display a pop-up with check boxes and labels for the check box.
    Pop-up has to contain 'n' rows , each row having a check box (with a label).
    I dont know how to dynamically add rows in the pop-up ?
    (I just meant rows to give a more clear picture , not that the pop-up would contain tables)
    When i add dynamically check boxes to the pop-up, i have to add events too.. for their functionality.
    Could anyone please help me ?
    Thanks !
    Karthik.

    Hi Karthik,
    You ned to create the UI elements dynamically as per the requirement.
    First you need to count howmany rows are for display. With help  of the For loop, you can put the condition as howmany rows and in the for loop code, write the code for displaying the checkbox and label whatever you want to create. Follow the below link for dynamic UI creation
    http://help.sap.com/erp2005_ehp_03/helpdata/EN/4f/07cf3dd28b5610e10000000a114084/frameset.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6fdae690-0201-0010-a580-d104b459cb44
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/74cda090-0201-0010-6b91-f85b2489f765
    Dynamic Creation of Checkboxes!
    http://help.sap.com/saphelp_nw04/helpdata/en/24/4e70c63574ec4284d0f47324ab2d0e/frameset.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/74cda090-0201-0010-6b91-f85b2489f765
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6fdae690-0201-0010-a580-d104b459cb44
    Dynamic UI element creation
    Thanks
    Suresh
    Edited by: Suresh Mandalapu on Aug 24, 2008 8:33 AM

  • Dynamic resizing of JTree editor component

    I have a custom JTree cell editor which changes size depending on
    what the user is doing. But the JTree doesn't seem to recognize this
    size change and the need for laying out. Explicit resizing of the JTree
    does not seem to help, either, though clicking on the editor component
    causes it to behave correctly.
    Is there a way to instruct the JTree to pay attention to the changing
    size of the editor component?
    Thanks

    I have a custom JTree cell editor which changes size depending on
    what the user is doing. But the JTree doesn't seem to recognize this
    size change and the need for laying out. Explicit resizing of the JTree
    does not seem to help, either, though clicking on the editor component
    causes it to behave correctly.
    Is there a way to instruct the JTree to pay attention to the changing
    size of the editor component?
    Thanks

  • Dynamic addition of tabs to tabstrip

    hi gurus ,
    can ne1 plz tell me how can we hav dynamic tabs on the tabstrip control .
    one of the way is to have max no of tabs n making them visible n invisible .
    but wat the problem is dat the text on the tabs is also dynamic i don knw its value in advance .
    if any1 knws how to do dis then plzzz reply asap . its urgent
    pts wil b rewarded for sure ....

    1. Create program in SE38 type module pool and Activated
    2. Go to SE51 give the program name and screen number then Layout Editor in drags tabstrip with wizard.
    3. Automacaly code is generated.
    4. Subscreen(101) add the two Check Boxs (CH1,CH2).
    5. Changed the Tab1 properties on Program in Click check box <b>OUTPUT Field only</b>
    then tab text also you give Dynamic
    PROGRAM ZTAB1 .
    FUNCTION CODES FOR TABSTRIP 'TAB2'
    CONSTANTS: BEGIN OF C_TAB2,
                 TAB1 LIKE SY-UCOMM VALUE 'TAB2_FC1',
                 TAB2 LIKE SY-UCOMM VALUE 'TAB2_FC2',
                 TAB3 LIKE SY-UCOMM VALUE 'TAB2_FC3',
               END OF C_TAB2.
    DATA FOR TABSTRIP 'TAB2'
    CONTROLS:  TAB2 TYPE TABSTRIP.
    DATA:      BEGIN OF G_TAB2,
                 SUBSCREEN   LIKE SY-DYNNR,
                 PROG        LIKE SY-REPID VALUE 'ZTAB1',
                 PRESSED_TAB LIKE SY-UCOMM VALUE C_TAB2-TAB1,
               END OF G_TAB2.
    DATA:      OK_CODE LIKE SY-UCOMM.
    DATA:A(1),B(1).
    OUTPUT MODULE FOR TABSTRIP 'TAB2': SETS ACTIVE TAB
    MODULE TAB2_ACTIVE_TAB_SET OUTPUT.
      TAB2-ACTIVETAB = G_TAB2-PRESSED_TAB.
      CASE G_TAB2-PRESSED_TAB.
        WHEN C_TAB2-TAB1.
          G_TAB2-SUBSCREEN = '0101'.
        WHEN C_TAB2-TAB2.
          G_TAB2-SUBSCREEN = '0102'.
        WHEN C_TAB2-TAB3.
          G_TAB2-SUBSCREEN = '0103'.
        WHEN OTHERS.
         DO NOTHING
      ENDCASE.
    ENDMODULE.
    INPUT MODULE FOR TABSTRIP 'TAB2': GETS ACTIVE TAB
    MODULE TAB2_ACTIVE_TAB_GET INPUT.
      CASE OK_CODE.
        WHEN C_TAB2-TAB1.
          G_TAB2-PRESSED_TAB = C_TAB2-TAB1.
        WHEN C_TAB2-TAB2.
          G_TAB2-PRESSED_TAB = C_TAB2-TAB2.
        WHEN C_TAB2-TAB3.
          G_TAB2-PRESSED_TAB = C_TAB2-TAB3.
        WHEN OTHERS.
         DO NOTHING
      ENDCASE.
    ENDMODULE.
    <b>MAIN SCREEN 100</b>
    MODULE STATUS_0100 OUTPUT.
    LOOP AT SCREEN.
    IF SCREEN-NAME = 'TAB2_TAB2'.
       IF A = 1.
          SCREEN-ACTIVE = 1.
       ELSEIF A = 0.
          SCREEN-ACTIVE = 0.
       ENDIF.
    ENDIF.
    IF SCREEN-NAME = 'TAB2_TAB3'.
        IF B = 1.
          SCREEN-ACTIVE = 1.
        ELSEIF B = 0.
          SCREEN-ACTIVE = 0.
        ENDIF.
    ENDIF.
    MODIFY  SCREEN.
    ENDLOOP.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    <b>* SUBSCREEN 103</b>
    MODULE USER_COMMAND_0110 INPUT.
    CASE OK_CODE.
    WHEN 'CH1'.
        IF A = 0.
           A = 1.
        ELSEIF A = 1.
               A = 0.
        ENDIF.
    WHEN 'CH2'.
        IF B = 0.
           B = 1.
        ELSEIF B = 1.
               B = 0.
        ENDIF.
    WHEN 'EXIT'.
    LEAVE PROGRAM.
    ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0110  INPUT
    Message was edited by:
            Durga Vinta

  • Dynamic addition of fields in a TAB - urgent....

    Hello all,
    I have added a tab to the existing BSP application and the following fields will be available for user input as shown below .
    start date  end date
    Presently we are able to give 10 rows for input. But the user might want more than 10 rows fro input.
    so he wants a table control kind of thing where in he can scroll and enter as many values as he can.
    or provide a button, if he clicks on the button some more empty rows will be available for input.
    Is this feasible if so how??
    Any pointers are highly appreciated..

    Its possible. refer below thread, similar issue discussed & resolved.
    Re: Add new row in Tableview
    <i>*Reward each useful answer</i>
    Raja T

  • Dynamic addition of  MXML Component

    Is it possible to add an MXML component through an ActionScript.
    I have a situation where I display multiple checkboxes and on click of each I show a subform. I am planning to make that subform as MXML component and add/remove it based on the user's checking/unchecking the checkbox..Is this possible?
    Thanks
    Dharmesh

    Hi Ben ..
         Appreciate your quick response. This is my first Flex app. In a nut sheel here is a sample similar to what I am trying to achieve.
    Consider my Mxml component as follows
    <?xml version="1.0" encoding="utf-8"?>
    <!-- myComponents/TempComponent.mxml -->
    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
        <mx:Button label="Hey there from component"/>
    </mx:Canvas>
    Now here he my app mxml file
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
        xmlns:temp="mycomponents.*">
        <mx:Script>
            <![CDATA[
                import mx.controls.Alert;
                public function addRemove():void{
                    //How do i add that component to the Panel?
            ]]>
        </mx:Script>
         <mx:Checkbox id="cb" change="addRemove()" label="Check or Uncheck"/>
         <mx:Panel  id="testPanel" x="0" y="0" width="100%" height="200" layout="absolute" borderThickness="0" borderThicknessBottom="0"/>
    Can you guide me what should go in the listener to add the component to the panel?

  • Creation of table of table dynamically

    Hi everyone,
      i have created an alv grid with a dynamic number of columns. Now i need to edit specific rows in the alv table. In the BCALV_EDIT_02 you need to create in the data table a field CELLTAB (wich is also a table), how can i do this ?
    Xavier

    Hello Frederico
    The once again revised version of my sample report demonstrates how to store PBO and PAI data. Please note the following naming convention:
    - OUTTAB ==> itab for ALV list display with CELLTAB (i.e. a complex type)
    - ITAB      ==> flat itab without CELLTAB
    *& Report  ZUS_SDN_RTTI_CREATE_STRUCTUR_2
    *& NOTE: 1st revised version of ZUS_SDN_RTTI_CREATE_STRUCTUR_1
    REPORT  zus_sdn_rtti_create_structur_2.
    TYPE-POOLS: abap.
    DATA:
      celltab          TYPE lvc_t_styl.
    DATA:
      gd_tabnam        TYPE string,
      gd_tabfield      TYPE string,
      go_table         TYPE REF TO cl_salv_table,
      go_sdescr        TYPE REF TO cl_abap_structdescr,
      go_sdescr_new    TYPE REF TO cl_abap_structdescr,
      go_tdescr        TYPE REF TO cl_abap_tabledescr,
      go_typedescr     TYPE REF TO cl_abap_typedescr,
      gdo_data         TYPE REF TO data,
      gdo_handle       TYPE REF TO data,
      gs_component     TYPE abap_compdescr,
      gs_comp          TYPE abap_componentdescr,
      gt_components    TYPE abap_component_tab.
    *    name       TYPE string,
    *    type       TYPE REF TO cl_abap_datadescr,
    *    as_include TYPE abap_bool,
    *    suffix     TYPE string,
    FIELD-SYMBOLS:
      <gd_fld>            TYPE ANY,  " single field
      <gs_outtab>         TYPE ANY,  " structure with CELLTAB
      <gs_itab>           TYPE ANY,  " structure without CELLTAB
      <gt_itab_pbo>       TYPE STANDARD TABLE,  " without CELLTAB
      <gt_itab_pai>       TYPE STANDARD TABLE,  " without CELLTAB
      <gt_outtab_pbo>     TYPE STANDARD TABLE,  " with CELLTAB
      <gt_outtab_pai>     TYPE STANDARD TABLE.  " with CELLTAB
    PARAMETER:
      p_tabnam      TYPE tabname  DEFAULT 'KNB1'.
    PARAMETERS:
      p_skip        AS CHECKBOX  DEFAULT 'X'.  " skip simulation
    START-OF-SELECTION.
      " Describe structure
      go_sdescr ?= cl_abap_structdescr=>describe_by_name( p_tabnam ).
      gd_tabnam     = go_sdescr->get_relative_name( ).
    * Simulate dynamic addition of columns to ALV list
      DO 5 TIMES.
        READ TABLE go_sdescr->components INTO gs_component INDEX syst-index.
        "   Build fieldname
        CONCATENATE gd_tabnam gs_component-name INTO gd_tabfield
                                                SEPARATED BY '-'.
        CLEAR: gs_comp.
        gs_comp-type ?= cl_abap_datadescr=>describe_by_name( gd_tabfield ).
        gs_comp-name  = gs_component-name.
        APPEND gs_comp TO gt_components.
        go_sdescr_new  = cl_abap_structdescr=>create( gt_components ).
        go_tdescr      = cl_abap_tabledescr=>create( go_sdescr_new ).
        "   Create data refence followed by table creation
        CREATE DATA gdo_handle TYPE HANDLE go_tdescr.
        ASSIGN gdo_handle->* TO <gt_outtab_pbo>.
    *   Dynamic select
        SELECT        * FROM  (p_tabnam) UP TO 10 ROWS
          INTO CORRESPONDING FIELDS OF TABLE <gt_outtab_pbo>
               WHERE  bukrs  = '2000'.
        IF ( p_skip = abap_false ).
          TRY.
              CALL METHOD cl_salv_table=>factory
                IMPORTING
                  r_salv_table = go_table
                CHANGING
                  t_table      = <gt_outtab_pbo>.
              go_table->display( ).
            CATCH cx_salv_msg .
          ENDTRY.
        ENDIF.
      ENDDO.
      TRY.
          CALL METHOD cl_salv_table=>factory
            IMPORTING
              r_salv_table = go_table
            CHANGING
              t_table      = <gt_outtab_pbo>.
          go_table->display( ).
        CATCH cx_salv_msg .
      ENDTRY.
      " Display component list in order to prove that indeed the field names
      " are used (instead of the data element names)
      TRY.
          CALL METHOD cl_salv_table=>factory
            IMPORTING
              r_salv_table = go_table
            CHANGING
              t_table      = gt_components.
          go_table->display( ).
        CATCH cx_salv_msg .
      ENDTRY.
      " Create data reference for structure (without CELLTAB)!!!
      CREATE DATA gdo_handle TYPE HANDLE go_sdescr_new.
      REFRESH: gt_components.
      CLEAR: gs_comp.
      gs_comp-type ?=
            cl_abap_structdescr=>describe_by_data_ref( gdo_handle ).
      gs_comp-name       = 'DATA'.
      gs_comp-as_include = abap_true.
      APPEND gs_comp TO gt_components.
      " Add table type as field to structure ==> complex structure
      CLEAR: gs_comp.
      gs_comp-type ?= cl_abap_typedescr=>describe_by_data( celltab ).
      gs_comp-name  = 'CELLTAB'.
      APPEND gs_comp TO gt_components.
      go_sdescr  = cl_abap_structdescr=>create( gt_components ).
      go_tdescr  = cl_abap_tabledescr=>create( go_sdescr ).
      CREATE DATA gdo_handle TYPE HANDLE go_tdescr.
      ASSIGN gdo_handle->* TO <gt_outtab_pbo>.
    *   Dynamic select
      SELECT        * FROM  (p_tabnam) UP TO 10 ROWS
        INTO CORRESPONDING FIELDS OF TABLE <gt_outtab_pbo>
             WHERE  bukrs  = '2000'.
      PERFORM fill_celltab.
      " Create second itab (PAI data)
      CREATE DATA gdo_handle TYPE HANDLE go_tdescr.
      ASSIGN gdo_handle->* TO <gt_outtab_pai>.
      <gt_outtab_pai> = <gt_outtab_pbo>.  " PAI data = PBO data
      " Renumbering of customer makes it easier to spot the differences
      LOOP AT <gt_outtab_pai> ASSIGNING <gs_outtab>.
        ASSIGN COMPONENT 'KUNNR' OF STRUCTURE <gs_outtab> TO <gd_fld>.
        <gd_fld> = syst-tabix.  " new numbering of customers
      ENDLOOP.
      LOOP AT <gt_outtab_pbo> ASSIGNING <gs_outtab>.
        ASSIGN COMPONENT 'KUNNR' OF STRUCTURE <gs_outtab> TO <gd_fld>.
        <gd_fld> = syst-tabix.  " new numbering of customers
      ENDLOOP.
      DELETE <gt_outtab_pbo> INDEX 3.  " ==>  3rd row in PAI data is new
      DELETE <gt_outtab_pai> INDEX 7.  " ==>  7th row in PBO data is DELE
      " Shuffle data from outtab to corresponding itab (w/o CELLTAB)
      PERFORM shuffle_outtab_to_itab.
      " List output
      PERFORM write_list.
      EXIT.
      " Simplified version of table creation:
      CLEAR: gdo_data.
      UNASSIGN <gt_outtab_pbo>.
      CREATE DATA gdo_data TYPE STANDARD TABLE OF (p_tabnam).
      ASSIGN gdo_data->* TO <gt_outtab_pbo>.
    END-OF-SELECTION.
    *&      Form  FILL_CELLTAB
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM fill_celltab .
    * define local data
      DATA:
        ls_cell       TYPE lvc_s_styl,
        lt_celltab    TYPE lvc_t_styl.
      FIELD-SYMBOLS:
        <gs_struc>    TYPE ANY,
        <lt_celltab>  TYPE lvc_t_styl.
      " Create dummy entry for local CELLTAB
      ls_cell-fieldname = 'BUKRS'.
      ls_cell-style     = cl_gui_alv_grid=>mc_style_enabled.
      INSERT ls_cell INTO TABLE lt_celltab.
      LOOP AT <gt_outtab_pbo> ASSIGNING <gs_struc>.
        ASSIGN COMPONENT 'CELLTAB' OF STRUCTURE <gs_struc> TO <lt_celltab>.
        <lt_celltab> = lt_celltab.
        "   No MODIFY required because we are working with the field symbol
      ENDLOOP.
    ENDFORM.                    " FILL_CELLTAB
    *&      Form  SHUFFLE_OUTTAB_TO_ITAB
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM shuffle_outtab_to_itab .
      go_tdescr  = cl_abap_tabledescr=>create( go_sdescr_new ).
      CREATE DATA gdo_handle TYPE HANDLE go_tdescr.
      ASSIGN gdo_handle->* TO <gt_itab_pbo>.
      go_tdescr  = cl_abap_tabledescr=>create( go_sdescr_new ).
      CREATE DATA gdo_handle TYPE HANDLE go_tdescr.
      ASSIGN gdo_handle->* TO <gt_itab_pai>.
      LOOP AT <gt_outtab_pbo> ASSIGNING <gs_outtab>.
        ASSIGN COMPONENT 'DATA' OF STRUCTURE <gs_outtab> TO <gs_itab>.
        APPEND <gs_itab> TO <gt_itab_pbo>.
      ENDLOOP.
      LOOP AT <gt_outtab_pai> ASSIGNING <gs_outtab>.
        ASSIGN COMPONENT 'DATA' OF STRUCTURE <gs_outtab> TO <gs_itab>.
        APPEND <gs_itab> TO <gt_itab_pai>.
      ENDLOOP.
    ENDFORM.                    " SHUFFLE_OUTTAB_TO_ITAB
    *&      Form  WRITE_LIST
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM write_list .
      WRITE: / 'PBO data:'.
      LOOP AT <gt_itab_pbo> ASSIGNING <gs_itab>.
        WRITE: / 'Record No.=', syst-tabix, '==>'.
        DO.
          ASSIGN COMPONENT syst-index OF STRUCTURE <gs_itab> TO <gd_fld>.
          IF ( syst-subrc NE 0 ).
            EXIT.
          ENDIF.
          WRITE: <gd_fld>.
        ENDDO.
      ENDLOOP.
      SKIP 2.
      WRITE: / 'PAI data:'.
      LOOP AT <gt_itab_pai> ASSIGNING <gs_itab>.
        WRITE: / 'Record No.=', syst-tabix, '==>'.
        DO.
          ASSIGN COMPONENT syst-index OF STRUCTURE <gs_itab> TO <gd_fld>.
          IF ( syst-subrc NE 0 ).
            EXIT.
          ENDIF.
          WRITE: <gd_fld>.
        ENDDO.
      ENDLOOP.
    ENDFORM.                    " WRITE_LIST
    Finally, if you want to know the <i>differences </i>between PAI and PBO data, that is which records have been deleted, updated or inserted have a look at my code sample
    <a href="https://wiki.sdn.sap.com/wiki/display/Snippets/ComparingTwoInternalTables-AGeneric+Approach">Comparing Two Internal Tables - A Generic Approach</a>
    Regards
      Uwe

  • JTree  and Unique node values

    Hi,
    I am dynamically generating a JTree based on (non-unique) category descriptions found in a database. My trouble is that each node must also be identified by a (hidden) unique node id number.
    I have played around with myNode.setUserObject("uniqueNodeNumber");
    but that appears to change the title of the node itself.
    Any ideas or suggestions would be greatly appreciated.
    Thank you!

    class UserObject {
        private int id;
        private Object object;
        public UserObject (int id, Object object) {
            this.id = id;
            this.object = object;
        public int getID () {
            return id;
        public Object getObject () {
            return object;
        public String toString () {
            return object.toString ();
    }You can add this object to your tree.
    Kind regards,
      Levi

  • Dynamic Programming - RTTC - Appending lines

    I give up! Maybe someone else can help me with this Dynamic Programming problem.
    I am using RTTC to create an itab. Now I want to append lines and for some reason can't seem to crack the syntax I need.
    My latest attempt looks like this...
                FIELD-SYMBOLS: <table> TYPE ANY TABLE,
                               <row> TYPE ANY.
                lo_sdescr      = cl_abap_structdescr=>create( lt_components ).
                lo_tdescr      = cl_abap_tabledescr=>create( lo_sdescr ).
                CREATE DATA lr_alloc->alloc_table TYPE HANDLE lo_tdescr.
                CREATE DATA lr_struct TYPE HANDLE lo_rdescr.
                ASSIGN lr_alloc->alloc_table->* TO <table>.
                APPEND INITIAL LINE TO <table> ASSIGNING <row>.
    The syntax check I get on the APPEND statement is "You cannot use explicit or implicit index operations on tables with type "ANY TABLE".
    All the doco and examples I can find use a simple "SELECT * ... INTO CORRESPONDING FIELDS OF TABLE <table>" syntax which it not what I need to do.
    Any help it appreciated.
    Thanks
    Graham Robbo

    Hello Graham
    The solution is quite simple (at least to overcome your syntax error):
    FIELD-SYMBOLS:
      <gt_itab>     TYPE STANDARD TABLE,  " use STANDARD instead of ANY
      <gs_struc>    TYPE ANY.
    *& Report  Z_RTTI_CREATE_COMPLEX_ITAB
    *& NOTE: revised version of ZUS_SDN_RTTI_CREATE_STRUCTURES
    *& Thread: Dynamic Programming - RTTC - Appending lines
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="980407"></a>
    REPORT  z_rtti_create_complex_itab.
    TYPE-POOLS: abap.
    DATA:
      celltab          TYPE lvc_t_styl.  " becomes field of complex itab
    DATA:
      gd_tabnam        TYPE string,
      gd_tabfield      TYPE string,
      go_table         TYPE REF TO cl_salv_table,
      go_sdescr        TYPE REF TO cl_abap_structdescr,
      go_sdescr_new    TYPE REF TO cl_abap_structdescr,
      go_tdescr        TYPE REF TO cl_abap_tabledescr,
      gdo_data         TYPE REF TO data,
      gdo_handle       TYPE REF TO data,
      gs_component     TYPE abap_compdescr,
      gs_comp          TYPE abap_componentdescr,
      gt_components    TYPE abap_component_tab.
    FIELD-SYMBOLS:
      <gt_itab>     TYPE STANDARD TABLE,
      <gs_struc>    TYPE ANY.
    PARAMETER:
      p_tabnam      TYPE tabname  DEFAULT 'KNB1'.
    START-OF-SELECTION.
      " Describe structure
      go_sdescr ?= cl_abap_structdescr=>describe_by_name( p_tabnam ).
      gd_tabnam     = go_sdescr->get_relative_name( ).
      " Simulate dynamic addition of columns
      LOOP AT go_sdescr->components INTO gs_component.
        "   Build fieldname
        CONCATENATE gd_tabnam gs_component-name INTO gd_tabfield
                                                SEPARATED BY '-'.
        CLEAR: gs_comp.
        gs_comp-type ?= cl_abap_datadescr=>describe_by_name( gd_tabfield ).
        gs_comp-name  = gs_component-name.
        APPEND gs_comp TO gt_components.
      ENDLOOP.
      "   Create instances of dynamic structure and dynamic internal table
      go_sdescr_new  = cl_abap_structdescr=>create( gt_components ).
      go_tdescr      = cl_abap_tabledescr=>create( go_sdescr_new ).
      "   Create data refence followed by table creation
      CREATE DATA gdo_handle TYPE HANDLE go_sdescr_new.
      ASSIGN gdo_handle->* TO <gs_struc>.
      CREATE DATA gdo_handle TYPE HANDLE go_tdescr.  " !!!
      ASSIGN gdo_handle->* TO <gt_itab>.
      APPEND INITIAL LINE TO <gt_itab> ASSIGNING <gs_struc>.
      TRY.
          CALL METHOD cl_salv_table=>factory
            IMPORTING
              r_salv_table = go_table
            CHANGING
              t_table      = <gt_itab>.
          go_table->display( ).
        CATCH cx_salv_msg .
      ENDTRY.
    END-OF-SELECTION.
    Regards
      Uwe

  • JTree Behavior on Windows as opposed to other OSs

    I have been noticing something very strange. I have written my code and compiled the code on Mac OS X (10.3). After having compiled the code, I find that all runs well. I take the same code, in a jar file and run this on Linux, Unix, etc... within a 1.4.2_x and a 1.5.x environment, and everything works fine. The problem, is when executing my code on Windows, I get an IllegalStateException error, node doesn't allow children. Why is this? Is there a better way of doing this?
    Thanks,
    M2bright
    Scenario:
    I have a blank JTree. I am then adding nodes dynamically to the JTree based off of user input. If the JTree is blank, I add it to the root node. The actual code that is failing is as follows:
      //Previous code for setup and manipulation is before this
    // comp is a variable being passed in to the function.
    if(((DefaultMutableTreeNode)((JTree)comp).getModel().getRoot()).getChildCount() == 0)
    //This is the section where I make sure the root node allows children, works in every OS but windows.                 
    ((DefaultMutableTreeNode)((JTree)comp).getModel().getRoot()).setAllowsChildren(true);
                        DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode(((DBEntry)obj).getVolume()); // getVolume() returns a string
                        DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode(((DBEntry)obj).getBookShort()); //getBookShort() returns a string
                        DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode(obj); //obj is a personallized object yet, has a toString()
                        defaultmutabletreenode2.add(defaultmutabletreenode4);
                        defaultmutabletreenode.add(defaultmutabletreenode2);
                        ((DefaultMutableTreeNode)((JTree)obj2).getModel().getRoot()).add(defaultmutabletreenode);
                        ((JTree)obj2).scrollPathToVisible(new TreePath(defaultmutabletreenode4.getPath()));
      //End Snippet

    Select Tools / Options and remove the check for 'Open new windows in a new tab instead'

  • How to display dynamically generated SVG image

    Hello, I need some help on this issue...
    I need my page to display programmatically generated SVG image. but if i directly pass SVG string to the page like <h:outputText value="#{MyBean.SVGresult}"/> it will pop up a download dialog box. what should i do to properly include my svg into the page by using embed tag??

    The h:graphicImage does not appear to handle svg; maybe it should be extended. I'm still looking for the best way to do it. I don't know if I have the right solution but here is what I have done so far. This will throw up a x, y polyline graph.
    Put a panelGrid as place holder in the jsp
          <h:panelGrid  title="Report" style="color=black" border="0" id="dataReports" columns="1" binding="#{dataAnalysis.dataReport}">
          </h:panelGrid>Then take a 'template' svg and fill it in with the dynamic additions and changes in the backing bean. In a submit action
                    generateSVGGraph(twothetaArray, intensityArray);
                    UIColumn c=new UIColumn();
                    HtmlOutputText op=new HtmlOutputText();
                    op.getAttributes().put("style","color=black");
                    op.setTitle("header text");
                    op.setValue("header text");
                    c.setHeader(op);
                    //c.getFacets().put()
                    //c.getChildren().add("<embed src=\"../phase.svg\" align=\"left\" width=\"500\" height=\"500\" type=\"image/svg+xml\"/>");
                    //javax.faces.webapp.UIComponentBodyTag embed=new javax.faces.webapp.UIComponentBodyTag();
                    //javax.servlet.jsp.tagext.TagAdapter;
                    com.hypernex.jsf.ext.html.HtmlEmbedGraphic embedGraphic=new com.hypernex.jsf.ext.html.HtmlEmbedGraphic();
                    //embedGraphic.
                    embedGraphic.getAttributes().put("src","../session/phase"+phaseGraphCount+".svg");
                    embedGraphic.getAttributes().put("align","left");
                    embedGraphic.getAttributes().put("width","600");
                    embedGraphic.getAttributes().put("height","500");
                    embedGraphic.getAttributes().put("type","image/svg+xml");
                    c.getChildren().add(embedGraphic);
                     dataReport.getChildren().add(c);
                   c=new UIColumn();
                    op=new HtmlOutputText();
                    op.getAttributes().put("style","color=black");
                    op.setTitle("header text");
                    op.setValue("header text");
                    c.setHeader(op);
                    HtmlOutputText out=new HtmlOutputText();
                    out.getAttributes().put("style","color=black");
                    //out.setTitle("Figure 1.  Powder intensity as dependent on 2&theta;.");
                    out.setValue("Figure "+phaseGraphCount+".  Powder intensity as dependent on 2Theta.");
                    c.getChildren().add(out);
                    dataReport.getChildren().add(c);
    ...generateSVGGraph
        protected void generateSVGGraph(double[] x, double[] y)
            //FacesContext context = FacesContext.getCurrentInstance();
            //context.
            //Create an svg graph of the equation.
            org.apache.batik.dom.svg.SAXSVGDocumentFactory svgFactory=new org.apache.batik.dom.svg.SAXSVGDocumentFactory("org.apache.xerces.parsers.SAXParser");
               org.apache.batik.dom.svg.SVGDOMImplementation svgDOMImplementation=new org.apache.batik.dom.svg.SVGDOMImplementation();
            org.w3c.dom.DocumentType dt=null;//svgDOMImplementation.createDocumentType("svg","-//W3C//DTD SVG 1.1//EN",f.toURI().toString());
            //System.out.println(dt);
         org.w3c.dom.svg.SVGDocument svgOMDocument=null;
            try
                System.out.println("dir "+(new java.io.File(".")).toURI().toString());
                svgOMDocument=(org.w3c.dom.svg.SVGDocument)svgFactory.createDocument((new java.io.File("../webapps/jsf-wita/siteadmin/templates/graph-template.svg")).toURI().toString(), new java.io.FileInputStream(new java.io.File("../webapps/jsf-wita/siteadmin/templates/graph-template.svg")));//new org.apache.batik.dom.svg.SVGOMDocument(dt, (org.w3c.dom.DOMImplementation)svgDOMImplementation);
                org.w3c.dom.svg.SVGSVGElement root=svgOMDocument.getRootElement();
                        org.apache.batik.dom.svg.SVGOMGElement primary_g=new org.apache.batik.dom.svg.SVGOMGElement("", (org.apache.batik.dom.AbstractDocument)svgOMDocument);
                        primary_g.setAttribute("style","stroke:black; fill:none; stroke-width:1");
                        root.appendChild(primary_g);
                        //double[] x=new double[4*90];
                        //double[] y=new double[x.length];
                        //x[0]=(double)(1)/4.0;
                            //methodArgs[0]=new Double(Math.toRadians(x[0]));
                        //y[0]=((Double)method.invoke(mathmlObject, methodArgs)).doubleValue();
                        double xMin=x[0];
                        double yMin=y[0];
                        double xMax=x[x.length-1];
                        double yMax=xMax;
                        double xOfyMax=yMin;
                        StringBuffer points=new StringBuffer();
                        for(int index=0;index<x.length-1;index++)
                            //System.out.println(x[index]+" "+y[index]);
                            //x[index]=(double)(index+1)/4.0;
                            //methodArgs[0]=new Double(Math.toRadians(x[index]));
                            //y[index]=((Double)method.invoke(mathmlObject, methodArgs)).doubleValue();
                            double cx=x[index];
                            double cy=y[index];
                            //if(xMin>cx)xMin=cx;
                            if(yMin>cy)yMin=cy;
                            //if(xMax<cx)xMax=cx;
                            if(yMax<cy)
                             xOfyMax=cx;
                             yMax=cy;
                        org.w3c.dom.svg.SVGTextElement xLabel=(org.w3c.dom.svg.SVGTextElement)svgOMDocument.getElementById("xLabel");
                        xLabel.getFirstChild().setNodeValue("2?");//?");
                        org.w3c.dom.svg.SVGTextElement xMinimumLabel=(org.w3c.dom.svg.SVGTextElement)svgOMDocument.getElementById("xMinimumLabel");
                        xMinimumLabel.getFirstChild().setNodeValue(ddf.format(xMin,4).toString());
                        org.w3c.dom.svg.SVGTextElement xMaximumLabel=(org.w3c.dom.svg.SVGTextElement)svgOMDocument.getElementById("xMaximumLabel");
                        xMaximumLabel.getFirstChild().setNodeValue(ddf.format(xMax,4).toString());
                        org.w3c.dom.svg.SVGTextElement yMinimumLabel=(org.w3c.dom.svg.SVGTextElement)svgOMDocument.getElementById("yMinimumLabel");
                        yMinimumLabel.getFirstChild().setNodeValue(ddf.format(yMin,4).toString());
                        org.w3c.dom.svg.SVGTextElement yMaximumLabel=(org.w3c.dom.svg.SVGTextElement)svgOMDocument.getElementById("yMaximumLabel");
                        yMaximumLabel.getFirstChild().setNodeValue(ddf.format(yMax,4).toString());
                        for(int index=0;index<x.length-1;index++)
                            points.append((x[index]-xMin)*500/(xMax-xMin));
                            points.append(",");
                            points.append((y[index]-yMin)*500/(yMax-yMin));
                            points.append(" ");
                        //System.out.println(points);
                        org.apache.batik.dom.svg.SVGOMGElement g=new org.apache.batik.dom.svg.SVGOMGElement("", (org.apache.batik.dom.AbstractDocument)svgOMDocument);
                        g.setAttribute("id",(String)"data");
                        g.setAttribute("transform", "translate(100, 550)");
                        g.setAttribute("style","stroke:black; fill:none; stroke-width:1");
                        org.apache.batik.dom.svg.SVGOMPolylineElement polyLine=new org.apache.batik.dom.svg.SVGOMPolylineElement("", (org.apache.batik.dom.AbstractDocument)svgOMDocument);
                        polyLine.setAttribute("fill", "none");
                        polyLine.setAttribute("stroke", "blue");
                        polyLine.setAttribute("transform", "scale(1, -1)");
                        polyLine.setAttribute("stroke-width", "1");
                        polyLine.setAttribute("points", points.toString());
                        g.appendChild(polyLine);
                        primary_g.appendChild(g);
                       javax.xml.transform.TransformerFactory tFactory = javax.xml.transform.TransformerFactory.newInstance();
                       javax.xml.transform.Transformer intermediateTransformer=tFactory.newTransformer(new javax.xml.transform.stream.StreamSource("../webapps/jsf-wita/stylesheets/identity.xsl"));
                                    intermediateTransformer.setOutputProperty(OutputKeys.ENCODING, "iso-8859-1");
                                    intermediateTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
                         intermediateTransformer.transform(new javax.xml.transform.dom.DOMSource(svgOMDocument), new javax.xml.transform.stream.StreamResult(new java.io.FileOutputStream("../webapps/jsf-wita/session/phase"+phaseGraphCount+".svg")));
            catch(javax.xml.transform.TransformerConfigurationException tce)
                System.out.println("tce err: "+tce.getMessage());
            catch(javax.xml.transform.TransformerException te)
                System.out.println("te err: "+te.getMessage());
            catch(java.io.FileNotFoundException fnfe)
                System.out.println("fnfe:"+fnfe.getMessage());
            catch(java.io.IOException ioe)
                System.out.println("io:"+ioe.getMessage());
        HtmlEmbedGraphic.java
    * HtmlEmbedGraphic.java
    * Created on May 16, 2004, 8:12 AM
    package com.hypernex.jsf.ext.html;
    import javax.faces.component.UIComponent;
    import javax.faces.context.FacesContext;
    import javax.faces.context.ResponseWriter;
    * @author  hyperdev
    public class HtmlEmbedGraphic extends javax.faces.component.UIComponentBase
        /** Creates a new instance of HtmlEmbedGraphic */
        public HtmlEmbedGraphic()
            super();
        public String getFamily()
            return "javax.faces.Data";
        public boolean isRendered()
            return true;
    public void encodeBegin(FacesContext context,
      UIComponent component) throws java.io.IOException {
      if ((context == null) || (component == null)){
          System.out.println("encodeBegin NullPointerException "+context);
        throw new NullPointerException();
          System.out.println("encodeBegin "+context+" "+component);
      //MapComponent map=(MapComponent) component;
      ResponseWriter writer = context.getResponseWriter();
      writer.startElement("embed", this);
      writer.writeAttribute("src", getAttributes().get("src"),"id");
    public void encodeEnd(FacesContext context) throws java.io.IOException {
      if ((context == null)){
        throw new NullPointerException();
      //MapComponent map = (MapComponent) component;
      ResponseWriter writer = context.getResponseWriter();
      writer.startElement("embed", this);
      writer.writeAttribute("src", getAttributes().get("src"),"id");
      writer.writeAttribute("align", getAttributes().get("align"),"id");
      writer.writeAttribute("width", getAttributes().get("width"),"id");
      writer.writeAttribute("height", getAttributes().get("height"),"id");
      writer.writeAttribute("type", getAttributes().get("type"),"id");
      writer.endElement("embed");
    }graph-template.svg - More static parts of the graphic can be put in here.
    <?xml version="1.0" encoding="UTF-8"?>
    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentScriptType="text/ecmascript" width="100%" zoomAndPan="magnify" contentStyleType="text/css" viewBox="0 0 600% 600%" height="100%" preserveAspectRatio="xMidYMid meet" version="1.0">
    <g style="stroke:black; fill:none; stroke-width:1">
    <g id="visuals" style="stroke:black; fill:none; stroke-width:1" transform="translate(100, 550)">
    <rect id="box" transform="scale(1, -1)" x="1" y="1" width="500" height="500" fill="none" stroke="black" stroke-width="1.5"/>
    <g id="labels" transform="scale(1, 1)">
    <text id="xLabel" x="250" y="50" text-anchor="middle"
            font-family="Verdana" font-size="24" fill="blue" >x label</text>
    <text id="xMinimumLabel" x="0" y="20" text-anchor="middle"
            font-family="Verdana" font-size="18" fill="blue" >0.0</text>
    <text id="xMaximumLabel" x="500" y="20" text-anchor="middle"
            font-family="Verdana" font-size="18" fill="blue" >100.0</text>
    <text id="yMinimumLabel" x="-3" y="-3" text-anchor="end"
            font-family="Verdana" font-size="18" fill="blue" >0.0</text>
    <text id="yMaximumLabel" x="-3" y="-500" text-anchor="end"
            font-family="Verdana" font-size="18" fill="blue" >100.0</text>
    </g>
    </g>
    <g id="data" style="stroke:black; fill:none; stroke-width:1" transform="translate(10, 550)">
    </g>
    </g>
    </svg>

  • Dynamically changing tree node

    I'm having a problem when dynamically changing a JTree node. I can add a node to the tree no problem. If I then change the name of the node (via a property table in the app) and fire a node changed event, the change is not properly reflected in the tree, in that the new name is shown but the selection box remains the same size as the old (longer) name.
    If I manually click on the node with the mouse and then change the name everything works fine. Although this is only manifesting itself as a cosmetic problem I think this could be a timing problem that might show up under other circumstances. I have another tree in the app where this problem does not show up at all.
    Any ideas?
    Thanks

    1)fluctuating tree...what???
    2) Create a JPopUpMenu or a subclass. Add a mouselistener to the JTree.
    In this listener you handle rightMouseClick.
    When you detect such an mouse action open the popup with popup.show()
    If you need the selected component call JTree.getLastSelectedPathComponent().
    If you want to check if it is null use this: JTree.getSelectionModel().isSelectionEmpty(). So you can prevent nullpointers, cause selection can be empty
    You can write a method for your popup to give it the selected component.
    Then call the .show().
    Tweety

Maybe you are looking for

  • Solaris 10 gen the panic message and let the server auto reboot

    My Solaris 10 server would auto reboot at anytime. I think is ip:tcp_unfuse problem. But I don't know how to fix it. Anyone know how to fix this problem!!!!!!! Many Thanks! The following is error information # mdb 0 ::statusdebugging crash dump vmcor

  • After Restoring/Backup File System XI Java Instances are not up!

    Hello all, We are facing problem in restoring the SAP XI System, after taking backup of the system the java instances in SAP XI System are not starting again. ABAP connections are fine. Can anyone provide suggestions/solutions in order to restore the

  • LSMW Tcode in Production

    I have a request to add transaction LSMW on a Production role.  They said, it will help them maintain records in masses. Are there any issues/pitfalls assigning this transaction in Production system? Thanks. John

  • Can Yosemite Accesibility / Dictation open a  Folder?

    Can Yosemite Accesibility / Dictation open a specific Folder? The actions which can be assigned appear to be limited to: Open File... Open App... Run Workflow... Paste Text... Paste Data... Keyboard Shortcut... I'm looking for "Open Folder..."

  • How i can have all my opened tab when upgrade my firefox?

    now i'm still using very old Firefox 3.6.12, and i want to upgrede it. I always using "save and quit" to my all opened tab when quit and not using bookmarks. total about 300+ tab opened. i already try upgrade once and all my tab is lost. and because