Interacting with YouTube
To make testing this easy, and to make the search code usable elsewhere, it makes sense to create a separate class to handle taking a search term and returning a list of results.
The code listing for this is as follows.
* Return a list of video entries back to the calling method
public VideoFeed getResults(String author, String title) throws IOException, ServiceException
YouTubeService myService = new YouTubeService("mycompany-myapp-1");
YouTubeQuery query = new YouTubeQuery(new URL(VIDEO_FEED));
//set the author
if( (author != null) && author.length() > 0)
//set the actual query string
if((title != null) && title.length() > 0)
//choose most viewed as the ordering
//for the fun of it - include anything :-)
//get the video feed
VideoFeed feed = myService.query(query,VideoFeed.class);
Create a View For Searching
Rather than launching a plain old pop up dialog, we’ll do something slightly more advanced, to fit in with the Eclipse look & feel. This will also show how to use further extension points.
Using the org.eclipse.ui.views extension point, this time we’ll use the example template to get the necessary code generated faster.
As you fill out the example, use the TableViewer – we will be changing how the view looks, but selecting this gives a good headstart, and provides all the method stubs we will need.
On completion of this dialog, you will notice a number of new entries in the plugin editor, including use of the org.eclipse.ui.views and org.eclipse.ui.perspectiveExtension extension points.
If you run the application now, and choose Show View/Other – you will see a YouTube entry in the list, where you can choose to Search YouTube. If you click on this it will display the Search window at the bottom section of the screen. A number of default entries are provided in the table component.
Also, we will update our SearchHandler code so that when the action is executed for Search that it will also open the YouTube view. In the execute method, add the following code – you can get the id of the view by clicking on it in the plugin editor and copying the value of the id field. It is good practise to add the ID as a constant for each view for easy access in your code.
catch (WorkbenchException e)