Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » How do I open a file from my table with a button click?
How do I open a file from my table with a button click? [message #997745] Tue, 08 January 2013 16:53 Go to next message
James Teater is currently offline James TeaterFriend
Messages: 17
Registered: July 2011
Junior Member
The Table Viewer is created and displayed in a Dialog Class. The columns and button creation is in a TableViewer class.
I have added a column in my JFace table that is populated with buttons. I have tried to insert a image of the table with no luck. So I will try my best to explain the table.
____________________________________________________________
|Date________|_____Item______|____Filename_____|_____button|
|01/09/13....|.....metal.....|...metal.pdf.....|....[adobe]|
|01/09/13....|.....metal01...|...metal01.pdf...|....[adobe]|
|01/09/13....|.....metal02...|...metal02.pdf...|....[adobe]|
____________________________________________________________

I want the corresponding file open when the user clicks the button in the same row.

Column / Button Code

case 6:
                   Map<Object, Button> buttons = new HashMap<Object, Button>();   
                   TableItem item = (TableItem) cell.getItem();
                   Button button;
                  
                   if(buttons.containsKey(cell.getElement())) {
                      button = buttons.get(cell.getElement());
                   }
                   else
                   {
                     button = new Button((Composite) cell.getViewerRow().getControl(),SWT.PUSH);
                     //button.setText("Adobe");
                     button.setImage(loadImage("/images/AdobeIcon.png"));
                     
                     buttons.put(cell.getElement(), button);
                   }
                   TableEditor editor = new TableEditor(item.getParent());
                   editor.grabHorizontal  = true;
                   editor.grabVertical = true;
                   editor.setEditor(button , item, cell.getColumnIndex());
                   button.addListener(SWT.Selection, new SelectionListener(item, button, cell.getElement()));
                   editor.layout();
                  }



Selection Listener Class Code

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

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

      //////////////////////////////////////////////////////////////////////////
      //                         handleEvent                                  //
      //////////////////////////////////////////////////////////////////////////
      @Override
      public void handleEvent(Event event) {
         AplotSaveDataModel.SaveData selected = (( AplotSaveDataModel.SaveData)element);
         int index = AplotSaveDataModel.getInstance().getIndexOf(selected);
         final File viewerFile = new File(AplotSaveDataModel.getInstance().getSelectedPDFFileName(index));
         try {
            Desktop.getDesktop().open(viewerFile);
         }
         catch (IOException e) {
           e.printStackTrace();
        }
      }



AplotSaveDataModel.SaveData selected = (( AplotSaveDataModel.SaveData)element);

This value does change when a differnt row is clicked

int index = AplotSaveDataModel.getInstance().getIndexOf(selected);

Allways Returns 0

This is the getIndexOf method in AplotSaveDataModel

public int getIndexOf(SaveData selected) {
       return data.indexOf(selected); //data is a arraylist
     }


I think that the above method may be the issue.

What is happening - It does not matter which button is clicked. The file in row 0 is always opened, because the index it always return 0

I am wondering if data.indexOf(selected) returns 0 is element is found and -1 if not.

I would be glad to change the code above, if there is a easier way to preform what is needed. I just want when the button is clicked the file opens that is in the same row has the button.

Thanks in advance for any help you can give me.
Re: How do I open a file from my table with a button click? [message #998115 is a reply to message #997745] Wed, 09 January 2013 11:59 Go to previous message
Timur Achmetow is currently offline Timur AchmetowFriend
Messages: 38
Registered: April 2012
Member
I would you suggest to work wie JFace TableViewer and EditingSupport.
Create for each row - if you needed - an editing support, which you allows to edit each row.

Examples see here: http://www.vogella.com/articles/EclipseJFaceTableAdvanced/article.html#jfaceeditor
Previous Topic:How to change enablement state of ControlContribution
Next Topic:How alignment done in this UI
Goto Forum:
  


Current Time: Tue Mar 19 05:48:49 GMT 2024

Powered by FUDForum. Page generated in 0.02254 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top