質問

I am trying to make an editable table by using swt, while I have trouble to save dates which are modified in the database by using toplink:

  if (referenceViewId.equalsIgnoreCase(TISTableViewPart.ID)) {
        //TODO YUCHEN : Register and save objects in db
        System.out.println("test");

        final IViewPart viewPart = workbenchPage.findView(TISTableViewPart.ID);
        final TISTableViewPart vdv = (TISTableViewPart) viewPart;

        WorkingUnitMasterDataImpl sessionUow = new WorkingUnitMasterDataImpl();


        Object test = vdv.getLocalComposite().getTableViewer().getElementAt(1);
        sessionUow.registerObject(test);

        try {
            sessionUow.commitAndResume();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

 }

By using

Object test = vdv.getLocalComposite().getTableViewer().getElementAt(1);

I can only get the object of the first colomne of the table, then I use

sessionUow.registerObject(test);

to save the change. Does someone have idea to get the whole table as an object in order to register and commitResume? Thanks in advance.

役に立ちましたか?

解決

If you are using a TableViewer properly set up with a ContentProvider, it is assumed that the ContentProvider holds the all the elements the table contains.

Try to access these elements through the getElements() method in case you content provider implements IStructuredContentProvider.

Object[] elements = tableViever.getContentProvider().getElements();

In case you want to register to object changes, you can do that in the method setInput() ofthe ContentProvider. Indeed the javadoc for the IContentProvider interface suggests this method as the place for registering to changes.

If you need to access the input at a certain moment, the TableViewer object gives you access to your table input through the getInput() method:

Object tableInput = tableViewer.getInput();

Good luck!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top