Accessing currently selected entry in the table

User ad15b92aec

06-01-2009 02:12:10

Hello,





I want to be able to easily access the currently selected set of rows/columns in the active grid view table, and get the data in them without great hassle. I have been pouring over the javadocs for IJC and netbeans but I have not been able to figure out how to get a reference to the WBTable of interest. The WBTable does not seem to appear in any Lookups that I examine, and when I try to recurse through the list of active nodes and their children upon selecting the table in IJC, I am greeted by class com.im.ijc.core.api.views.AbstractViewTopComponent$FakeViewNode with no children. Is there a way to get a reference to the grid view WBTable, and if I get it, will the getValueAt() method return the same objects as I would get if I pulled them from the entity data provider??? If the answer is no, is there an easy way to go from cell in the WBTable to corresponding cell in the entity table?





I'd greatly appreciate help in this matter, I've spent a significant amount of time trying to figure this out and I'm frankly quite frustrated now.

ChemAxon 3b366b17e5

06-01-2009 08:02:49

Hi,


look at the example how to get selected data. Create new NetBeans action from template and replace its implementation. Feel free to ask any other question.





Petr





Code:
import com.im.commons.progress.BackgroundRunner;


import com.im.commons.progress.DFLockable;


import com.im.df.api.dml.DFResultSet.VertexState;


import com.im.df.api.support.SelectionDescription;


import com.im.df.util.UIBackgroundRunnerRW;


import com.im.ijc.core.api.util.IJCCoreUtils;


import java.util.ArrayList;


import java.util.List;


import java.util.Map;


import org.openide.nodes.Node;


import org.openide.util.actions.NodeAction;





public final class TestListRows extends NodeAction {





    protected void performAction(Node[] activatedNodes) {


        // get current vertex state (context) from selected nodes


        final VertexState vs = IJCCoreUtils.findVertexState(activatedNodes);


        final DFLockable lockable = vs.getResultSet().getLockable();


        if (vs != null) {


            BackgroundRunner runner = new UIBackgroundRunnerRW(lockable, NAME, false) {





                @Override


                public void phase1InRequestProcessor() {


                    // get all rows in current result set





                    SelectionDescription selection = vs.getSelection();


                    List ids = new ArrayList();


                    for (int i = selection.getMinSelectionIndex(); i <= selection.getMaxSelectionIndex(); i++) {


                        if (selection.isSelectedIndex(i)) {


                            ids.add(vs.getIdAt(i));


                        }


                    }


                    Map<Object, Map<String, Object>> data = vs.getData(ids, getEnvironment());


            }};


           runner.start();


        }


    }





    @Override


    protected boolean enable(Node[] node) {


            return IJCCoreUtils.findVertexState(node) != null;


    }


}

User ad15b92aec

06-01-2009 19:28:12

That worked perfectly, thank you very much Petr