Question

I need to allow my users to edit a filename value in the my table. So in my tableviewer I added the code to create and display the edit button(s) in my last column. I have this working.

When they click on the edit button, I want a dialog box to open with the filename in a textbox with a save and cancel button.

So I created FileNameDialog class.

My question is: Where do I create the dialog?

  • Do I create a method in the base dialog and call the method from the tableviewer


class SelectionListener implements Listener {
    TableItem item;
    Button editButton;
    Object element;

    public SelectionListener(TableItem item, Button deleteButton, Object element) {
        this.item = item;
        this.editButton = deleteButton;
        this.element = element;
    }

    public void handleEvent(Event event) {
        AplotPDFDataModel.FileNameData selected = (( AplotPDFDataModel.FileNameData)element);
        int index = AplotPDFDataModel.getInstance().getIndexOf(selected);
        pdfDialog.showEditFileNameDialog();  <<++++++++HERE

        Table table = getTable();
        table.getColumn(5).pack();
        table.getColumn(5).setWidth(100);
    }
} // End SelectionListener Class
  • Do I just create a method in the tableviewer and create the dialog there?


public void showEditFileNameDialog() {
    editFileNameDialog = new EditFileNameDialog(getShell());
    editFileNameDialog.create();
    editFileNameDialog.getShell().setSize(300, 200);
    editFileNameDialog.open();  
}

What is the best procedure for opening a dialog from a button click in a tableviewer?

Était-ce utile?

La solution

Normally you would just create and show the Dialog in the handleEvent method of the Listener.

To get a Shell that you can hand to the Dialog either of the following will do:

new EditFileNameDialog(getTable().getShell());

or

new EditFileNameDialog(new Shell());
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top