Partial selection of child does not keep parent node selected

Hi All,
Please help! I have a checkbox JTree which is working fine in all regard as I want except one condition i.e. if all child(leaf) of a parent are not selected parent gets deselected i.e. if we uncheck any child(leaf) node parent will get unselected even if there are some child are selected. I am posing code for the model. let me know if I need to post other codes also
tree.setModel(new DefaultTreeModel(rootNode1) {
    public void valueForPathChanged(TreePath path, Object newValue) {
        Object currNode = path.getLastPathComponent();
        super.valueForPathChanged(path, newValue);
        if ((currNode != null) && (currNode instanceof DefaultMutableTreeNode)) {
            DefaultMutableTreeNode editedNode = (DefaultMutableTreeNode) currNode;
            CheckBoxNode newCBN = (CheckBoxNode) newValue;
            //CheckBoxNode newCBN1 = (CheckBoxNode) newValue;
            if (!editedNode.isLeaf()) {
                int i=0;
                //for (int i = 0; i < editedNode.getChildCount(); i++) {
                  while(i < editedNode.getChildCount()){
                     System.out.println("child count root"+editedNode.getChildCount());
                     System.out.println("child count root i"+i);
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getChildAt(i);
                    CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
                    cbn.setSelected(newCBN.isSelected());
                    if(!editedNode.getChildAt(i).isLeaf())
                    for(int j=0;j<editedNode.getChildAt(i).getChildCount();j++)
                     System.out.println("child count roottt"+editedNode.getChildCount());
                     System.out.println("child count root j"+j);
                     DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) editedNode.getChildAt(i).getChildAt(j);
                     CheckBoxNode cbn1 = (CheckBoxNode) node1.getUserObject();
                     //cbn1.setSelected(true);
                     cbn1.setSelected(newCBN.isSelected());
                    i++;
            else{
                boolean isAllChiledSelected = true;
               for (int i = 0; i < editedNode.getParent().getChildCount(); i++) {
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getParent().getChildAt(i);
                    CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
                    if(!cbn.isSelected()){
                        isAllChiledSelected = false;
                if(isAllChiledSelected){
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode)editedNode.getParent();
                      CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
                    cbn.setSelected(isAllChiledSelected);
            if (!newCBN.isSelected()) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getParent();
                if (node.getUserObject() instanceof CheckBoxNode)
                    ((CheckBoxNode) node.getUserObject()).setSelected(false);
          /*if (!newCBN.isSelected()) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getParent();
                if (node.getUserObject() instanceof CheckBoxNode)
                    ((CheckBoxNode) node.getUserObject()).setSelected(false);
});

Hi Thomas,
Sorry for late reply due to weekend.
I had already tried your suggestion but it is not working. Do not know why? here is the code.
else {
  int countselection=0;
int t=editedNode.getParent().getChildCount();
               for (int i = 0; i < editedNode.getParent().getChildCount(); i++) {
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getParent().getChildAt(i);
                    CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
                    if(cbn.isSelected()){
                        countselection= countselection+1;
                if(icountselection==0 ){
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode)editedNode.getParent();
                      CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
                    cbn.setSelected(false );}
else if(countselection==1 && countselection<=t)
DefaultMutableTreeNode node = (DefaultMutableTreeNode)editedNode.getParent();
                      CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
                    cbn.setSelected(true );
}}

Similar Messages

  • Finding accounts where child does not match Parent acct category

    Hi,
    I have an interesting problem. There is Parent Account Group with child accounts under it. The child accounts must
    have been assigned the SAME category as the Parent account. If they are not, then they must show-up on the mismatch report.
    So, if there is a Parent Acct 1 with childacct a AND childacct b and if childacct a has category of Base and childacct b has category of offshore, while Parent Acct 1 has category of Base, then because BOTH A AND B do NOT have the same category as assigned to its parent, it should show up on report.
    I can get all children but how do this: check if any ONE acct category is NOT the same as the Parent???
    DO I have to use If AcctCATPARENT <>ANY(CHILDcate). then select Acct ID from table ....will this work??
    This is urgent, any help is appreciated!!
    Regards,
    hena

    Hello
    if you have a problem please remember to post some create table statements along with inserts to provide sample data to work with. Also, remember to show what the output is you're expecting and what you've tried so far. And finally remember that this is a volunteer forum so there aren't any urgent requests.
    anyway, isn't it just a matter of joining between parent and child?....
    WITH parent_acc AS
    (    SELECT 1 ID, 'cat a' cat FROM dual UNION ALL
         SELECT 2 ID, 'cat b' cat FROM dual UNION ALL
         SELECT 3 ID, 'cat c' cat FROM dual UNION ALL
         SELECT 4 ID, 'cat d' cat FROM dual
    child_acc AS
    (   SELECT 1 ID, 1 parent_id, 'cat a' cat FROM dual UNION ALL
        SELECT 2 ID, 1 parent_id, 'cat a' cat FROM dual UNION ALL
        SELECT 3 ID, 2 parent_id, 'cat b' cat FROM dual UNION ALL
        SELECT 4 ID, 2 parent_id, 'cat b' cat FROM dual UNION ALL
        SELECT 5 ID, 3 parent_id, 'cat a' cat FROM dual UNION ALL
        SELECT 6 ID, 3 parent_id, 'cat c' cat FROM dual UNION ALL
        SELECT 7 ID, 4 parent_id, 'cat a' cat FROM dual UNION ALL
        SELECT 8 ID, 4 parent_id, 'cat d' cat FROM dual        
    SELECT
          p.ID parent_id,
          p.cat parent_cat,
          c.ID child_id,
          c.cat child_cat
    FROM
        parent_acc p
    JOIN
        child_acc c
    ON
        (   c.parent_id = p.ID
    WHERE
         c.cat != p.cat                 
    /David

  • Java bytecode operation 'invokevirtual' does not keep consistency

    I have following codes.
    public class Parent {
    @Override
    public int hashCode() {
    return 0;
    public class Child extends Parent {
    public void test() {
    this.toString();
    this.hashCode();
    As you see in the above codes, Child inherits toString() from Object and hashCode() from Parent. Bytecode operation of Child#test is as following.
    ALOAD 0: this
    INVOKEVIRTUAL Object.toString() : String
    ALOAD 0: this
    INVOKEVIRTUAL Child.hashCode() : int
    RETURN
    I think if invokevirtual calls Object.toString(), it should call Parent.hashCode() for consistency. or, Child.hashCode() called, then Child.toString() should be called.
    However, invokevirtual does not keep its consistency if and only if target method is inherited by Object.
    Only that case, invokevirtual calls method in the Object. For other cases, invokevirtual calls method in current class.
    I want to know why this happens.

    I think if invokevirtual calls Object.toString(), it should call Parent.hashCode() for consistencyExcept that it doesn't exist.
    You can't seriously be suggesting that this doesn't work correctly.

  • My safari does not keep my history despite all the settings and adjustment i made to the safari preferences so as to be able to keep my browsing history. the browsing history is wiped out whenever i close safari.

    i use macbook pro mid 2012, OS X mavericks. my safari does not keep my history desp[ite all the adjustments made to the settings at safari preferences. my browsing history are cleared whenever i exit safari. i dont know why. i want to try and re - in stall it . the safari is version 7.0.1. but i dont know how.

    If you're having trouble making changes to files that are inside your home folder (represented by a house icon in the sidebar of a Finder window), or if you can't get changes to the settings of an application to stick, then please see below.
    Back up all data.
    This procedure will unlock all your user files (not system files) and reset their ownership and access-control lists to the default. If you've set special values for those attributes on any of your files, they will be reverted. In that case, either stop here, or be prepared to recreate the settings if necessary. Do so only after verifying that those settings didn't cause the problem. If none of this is meaningful to you, you don't need to worry about it.
    I've tested these instructions only with the Safari web browser. If you use another browser, they may not work as described.
    Step 1
    If you have more than one user account, and the one in question is not an administrator account, then temporarily promote it to administrator status in the Users & Groups preference pane. To do that, unlock the preference pane using the credentials of an administrator, check the box marked Allow user to administer this computer, then reboot. You can demote the problem account back to standard status when this step has been completed.
    Triple-click anywhere in the following line on this page to select it:
    { sudo chflags -R nouchg,nouappnd ~ $TMPDIR..; sudo chown -R $UID:staff ~ $_; sudo chmod -R u+rwX ~ $_; chmod -R -N ~ $_; } 2>&-
    Copy the selected text to the Clipboard by pressing the key combination command-C.
    Launch the built-in Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window (command-V). I've tested these instructions only with the Safari web browser. If you use another browser, you may have to press the return key after pasting.
    You'll be prompted for your login password. Nothing will be displayed when you type it. You may get a one-time warning to be careful. If you don’t have a login password, you’ll need to set one before you can run the command. If you see a message that your username "is not in the sudoers file," then you're not logged in as an administrator.
    The command may take a few minutes to run, or perhaps longer if you have literally millions of files in your home folder. Wait for a new line ending in a dollar sign ($) to appear, then quit Terminal.
    Step 2 (optional)
    Take this step only if you have trouble with Step 1 or if it doesn't solve the problem.
    Boot into Recovery. When the OS X Utilities screen appears, select
    Utilities ▹ Terminal
    from the menu bar. A Terminal window will open.
    In the Terminal window, type this:
    res
    Press the tab key. The partial command you typed will automatically be completed to this:
    resetpassword
    Press return. A Reset Password dialog will open. You’re not going to reset a password.
    In the dialog, select the startup volume ("Macintosh HD," unless you gave it a different name) if it's not already selected.
    Select your username from the menu labeled Select the user account if it's not already selected.
    Under Reset Home Directory Permissions and ACLs, click the Reset button.
    Select
     ▹ Restart
    from the menu bar.

  • RH7- Insert action does not display window to select the file.

    I have a nightmare situation with RH7 with no clue to resolve. What are my options to fix this
    I am having trouble with robohelp, selecting insert action does not display the pop up window. This prevents functions such as inserting images & files, importing files and creating hyperlinks to documents created in word, frame maker.
    when I perform this action, the pop up window appears virtually but is not visible to make the selection and RH freezes.
    I have to end the process or press esc to find some work around - so far none available
    Please help.

    Welcome to the community.
    Have you recently gone from a dual monitor setup to a single monitor?  When this happens, RH can sometimes keep tossing dialog boxes over where it thinks the second monitor is.  I typically use a program called ForceWindowVisible (get it here) to push wandering dialogs back into view.  Give that a try and see if it works.  Hope this helps,
    Ben
    GryphonMountain.net

  • HT204022 How can I delete my photos from my I phone? It does not let me by selecting and trash it. I did back them up but now I need to free my storage on my phone.

    I keep Trying to Delete my photos, which I backed them up on my computer, on my Iphone, but my iphone does not let me to delete them. It shows select, but it does not show trash. I have no more storage on my phone and I have to delete my photos.
    If you may know how, Please let me know.
    Thanks
    Matt Berenji

    Photos synced to your phone from your computer can only be removed by syncing them off again.  To do this, do the following:
    Connect your phone to your computer using your usb cable
    Open iTunes on your computer
    Click on the name of your phone in iTunes
    Go to the Photos tab of your iTunes sync settings
    Uncheck the folders that contain the photos you no longer want on your phone.  To remove them all, uncheck "Sync Photos"
    Click Apply at the bottom to sync your phone.
    If you only want to remove some of the photos from an album, but not all, remove these photos from the folder by the same name on your computer, then sync your phone.

  • Facebook does not keep logged in

    Facebook does not keep me logged in, although
    I tic keep logged in box.

    Make sure that you not run Firefox in (permanent) [[Private Browsing]] mode.
    * You enter Private Browsing mode if you select: Tools > Options > Privacy > History: Firefox will: "Never Remember History"
    * To see all History and Cookie settings, choose: Tools > Options > Privacy, choose the setting <b>Firefox will: Use custom settings for history</b>
    * Uncheck: [ ] "Permanent Private Browsing mode"
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    * https://support.mozilla.com/kb/Safe+Mode
    * [[Troubleshooting extensions and themes]]

  • When clicking on a lookup, firefor does not allow me to select from the list

    When I use firefox, the website I am on has lookup fields located on it, firefox does not allow me to select my preferred option from the list. also when I slect another lookup from a list it displays the message 'invalid lookup value located in field ......'
    This does not happen in IE

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • Visual Studio 2012 SharePoint Project Error : The partial project item type does not have a value for this property

    Hi,
    I am getting this error from visual studio 2012 whenever i try to create the following project types:
    - Workflow Custom activity
    - Web parts
    The error is as mentioned below
    "The partial project item type does not have a value for this property"
    Due to this the when I add above type of items in my project, they show a red cross icon against them.
    Please let me know If have you any solution?

    Hi
    I had same issue. Below is the solution
    Installing
    "Visual Studio 2012 Update 3" usually solves this problem. (You can download it through microsoft's official site at
    "http://www.microsoft.com/en-in/download/details.aspx?id=39305")
    Hansraj Rathva

  • How do I keep format when copying a table to keynote? paste and match style does not keep format

    how do I keep format when copying a table to keynote? paste and match style does not keep format

    It used to work until recent updates and it is very frustrating.....I hope someone out there knows how to deal with this.

  • Why do my songs and audio books keep getting erased when I add a new book?  Now some books will not play and the iPod does not keep track of where I was when I pause a book, leave for music and then go back!

    About a month ago I added some new audio books to my iPod Classic and then after disconnecting, I discovered EVERYTHING had been erased. 
    I had to restore through my iTunes but then I could not load my music back on.
    I uninstalled / reinstalled iTunes and completely reformated the iPod drive.
    I successfully got my music and books back on but then added a new book two days ago only to discover everything got erased AGAIN!!!
    Of course, my 1 Year Warranty was up about a week before the first incident.....
    I formatted the iPod again, uninstalled / reinstalled iTunes (it was freezing during sync) and downloaded all my music and books again.
    Now I have several books that will not play (they play on iTunes and they played on the iPod before all these events) and the iPod does not keep track of where I was in a book when I have to stop and go to something else.
    Does anyone know what is going on with this thing???  I have a 5th Gen Video and in all the years I've had it, I've NEVER had problems like this! 
    Does anyone have any ideas on what I can do to get my iPod Classic up and running properly again?
    Thanks.

    When iTunes/iPod sync process failed due to timeout, the iPod, has only the initilaised  filesytem structure at the start of the Sync.
    The timeout failure could be due to
    Bad hardisk - do the iPod disk diagnostic, refer to this excellent post by tt2
    Slow USB port or resource - Dont use any USB hub, disconnect all other USB devices while syncing
    Timeout due to Antivirus or other plugins - disconnect from Internet and stop the Antivirus or monitoribng software if you are syncing.
    Preferably stop doing other things while syncing this ancient device, which the latest iTunes designer, think will soon be extinct.
    Have a nice day!

  • The selected Flex SDK does not support building mobile projects

    I am unable to create a new Actionscript Mobile project.  The new project dialogue gives the error: "The selected Flex SDK does not support building mobile projects."  I tried seting the default Flec SDK both to the SDK included with Flash Builder 4.7, and also to a version of the 4.6.0 SDK (build 23201) with AIR 3.3 SDK overlayed on it, which already existed on my computer.  Both resulted in the same error.  Any ideas?

    Hi ,
    Actionscript Mobile projects use AIR SDK by default in Flash Builder 4.7 . Flex SDK won't be used for Actionscript projects.
    Could you please try creating an Actionscript project in fresh workspace and let me know if the issue still exists.
    Also attach screenshot and error log if any.
    Thanks,
    Sanjay

  • HT4009 My 6 year old was playing on a app we have used for ages, then i received numerous emails sating about $600 of in app purchases had been made. i don't understand how this happened as my child does not know my apple i.d password.

    My 6 year old was playing on an app we have used for ages then last night i recieved numerous emails stating about $600 of in app purchases had been made! i dont know how this happened as my child does not know my apple i.d. password!

    You can try contacting iTunes support and see if they give you a refund or credit for some/all of it : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchaes, Billing & Redemption.
    To stop it happening again you can turn off in-app purchases on your iPad via Settings > General > Restrictions > In-App Purchases, and also in Restrictions change Require Password to 'Immediately' - the default is 15 minutes during which it doesn't need to be re-entered.

  • SharePoint 2010 list view - How to filter on a multiline text box field - the view filter does not allow me to select it.

    Hi there,
    Does someone know in SharePoint 2010 list view - How to filter on a multiline text box field - the view filter does not allow me to select it.
    Thanks,

    Hi,
    Per my knowledge,
    it is by design that the data type multiple lines of text can only use “contains” and “begins with” operators.
    You can also filter the list view using SharePoint Designer,
    Open your list AllItem.aspx page in SPD ->click “Filter” > in “Field Name” select your multipe line of text field, in “Comparison” will displayed four choices.
    Best Regards,
    Lisa Chen
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • X does not apply to your selection because it is not inherited...

    Hi
    I'm trying to design a website using HTML and CSS. I have done the basic layout of the website using Div tags. However, the middle column of the website is showing up differently in Dreamweaver compared to on a browser.
    I have researched the problem and found that it is caused by an error occuring on the middle column and the wrapper tag not applying to it: "x does not apply to your selection because it is not inherited. It is applied to an enclosing tag".
    The code for my web page is here:
    http://pastebin.com/DfXLL7Zb
    This is my CSS styles code:
    http://pastebin.com/81u476zE
    Any help would be appreciated.
    Cheers

    This tells me you have unbalanced opening and closing <div> tags somewhere in your document.
    Use the validation tools to check your code.
    Code Validation Tools
    CSS - http://jigsaw.w3.org/css-validator/
    HTML - http://validator.w3.org/
    In the web forums, you can mark this discussion as answered.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists 
    http://alt-web.com/
    http://twitter.com/altweb

Maybe you are looking for