2. Define view
(1) View overview
l View is a visual container in the Eclipse table, allowing users to display or navigate specific types of resources.
l View is responsible for displaying data from the domain model, and the similar type of object should be packet into the same view.
l This method minimizes the user to complete the need to switch between a particular task
l The number of views contained in the application depends largely on the size and complexity of the application.
l The Google application example in this tutorial has two views, one for querying and displaying query results, another web page for displaying query results
(2) Define org.eclipse.ui.Views extension
}
Point = "org.eclipse.ui.views"> Name = "Google" ID = "com.xqtu.igoogle.views" /> Class = "com.xqtu.igoogle.views.searchview" category = "com.xqtu.google.view" Name = "Search" ID = "com.xqtu.igoogle.views.searchview" /> Class = "com.xqtu.google.views.browserview" category = "com.xqtu.google.view" Name = "browser" ID = "com.xqtu.google.views.browserview" /> extension> l Define org.eclipse.ui.Views extension in Plugin.xml l l l SearchView view allows the user to search for Google and display search results in the list; the Browserview view contains a SWT browser control, displays a specific URL web page according to the user in the search results table. (3) Implement SearchView view Package com.xqtu.igoogle.view; Import org.eclipse.jface.dialogs.MessageDialog; Import org.eclipse.jface.viewers.doubleClickevent; Import org.eclipse.jface.viewers.idoubleClickListener; Import org.eclipse.jface.viewers.istructupstence; Import org.eclipse.jface.viewers.tableviewer; Import org.eclipse.swt.swt; Import org.eclipse.swt.events.selectionEvent; Import org.eclipse.swt.events.selectionListener; import org.eclipse.swt.layout.Griddata; Import org.eclipse.swt.Layout.GridLayout; Import org.eclipse.swt.widgets.button; Import org.eclipse.swt.widgets.composite; Import org.eclipse.swt.widgets.label; Import org.eclipse.swt.widgets.table; Import org.eclipse.swt.widgets.tableColumn; Import org.eclipse.swt.widgets.text; Import org.eclipse.ui.internal.dialogs.viewContentProvider; Import org.eclipse.ui.part.viewpart; Import com.google.soap.search.googlesearch; Import com.google.soap.search.googlesearchfault; Import com.google.soap.search.googlesearchResult; Import com.google.soap.search.googlesearchResulTelement; Import com.xqtu.google.wizards.LicenseKeywizard; Public Class searchView Extends ViewPart IMPLEments iDoucastLickListener { Public static final string id = "com.xqtu.igoogle.views.searchview"; Private TableViewer TableViewer; Private text searchText; Private GooglesearchResulTelement Model; Public void createpartControl (Composite Parent) { GridLayout GridLayout = New GridLayout (); GridLayout.NumColumns = 3; GridLayout.Marginheight = 5; GridLayout.marginwidth = 5; Parent.setLayout (GridLayout); Label SearchLabel = New Label (PARENT, SWT.NONE); SearchLabel.Settext ("Search:"); SearchText = New Text (Parent, Swt.Border); SearchText.setLayOutdata (New GridData (GridData.grab_horizontal GridData.horizontal_align_fill); Button searchButton = new button (parent, swt.push); SearchButton.Settext ("Search"); SearchButton.addSerectionListener () {NEW SelectionListener Public void widgetselected (SelectionEvent E) { Googlesearch Search = New GoogleSearch (); Search.setKey (licenseKeywizard.getlicenseKey ()); search.setQueryString (SearchText.getText ()); Try { GooglesearchResult Result = search.dosearch (); TableViewer.setInput (model); TableViewer.Add (Result.getResulTelements ()); } catch (Googlesearch Fault EX) { MessageDialog.OpenWarning (E.Display.GetActiveShell (), "Google Error", EX.GETMESSAGE ()); } } Public void widgetdefaultselected (SelectionEvent E) { } }); Griddata griddata = new griddata (); GridData.VerticalIgnment = griddata.fill; Griddata.horizontalspan = 3; Griddata.grabexcesshorizontalspace = true; Griddata.grabexcessverticalspace = true; Griddata.horizontalalignment = griddata.fill; TableViewer = New TableViewer (PARENT, SWT.FULL_SELECTION | SWT.BORDER); TableViewer.SetLabelProvider (New SearchViewLabelProvider ()); TableViewer.SetContentProvider (New ViewContentProvider ()); TableViewer.setInput (model); TableViewer.getControl (). setLayOutdata (Griddata); TableViewer.adddoubleClickListener (this); Table Table = TableViewer.getTable (); Table.setHeadervisible (TRUE); Table.SetLinesVisible (TRUE); TableColumn Titlecolumn = New TableColumn (Table, SWT.NONE); Titlecolumn.Settext ("Title"); Titlecolumn.SetWidth (250); TableColumn Urlcolumn = New TableColumn (Table, Swt.none); Urlcolumn.Settext ("URL"); Urlcolumn.Setwidth (200); } Public void setfocus () { SearchText.Setfocus (); } Public void DoubleClick (doubleclickevent event) { IF (! TableViewer.getSelection (). ISEMPTY ()) { IstructureDSelection SS = (istructureDSelection) TableViewer .getSelection (); Googlesearch Element Element = (GooglesearchResulTelement) SS .Getfirstlement (); BrowserView.browser.SetURL (Element.geturl ());} } } l SearchView extension ViewPart, ViewPart is an abstract base class for all works. l This must implement CreatePartControl and SetFocus abstraction methods, the former is responsible for creating user interface controls, the latter is used to set the default focus l SearchView uses GridLayout layout view, the main control is the title of SWT style, text domain (search content), buttons, buttons (search results) l View 3 unit column layout, Search title, text domain, Search button on one line, forms exclusive 3 columns l Search button Increases the SelectionListener listener, perform Google Search when the user selects (ie, click) buttons. l SelectionListener listener needs to implement widgetSelected and WidgetDefaultSelected methods, and Google search features are placed in widgetSelected methods. l Google Search: Create a GoogleSearch object; set the license key, this tutorial collects the license key value by the wizard (later introduction); set the query content (obtained by text domain); execute the dosearch method for search, search results return to GooglesearchResult object; Search results are loaded into the table; if you find out, display warning information l Table control uses JFACE TableViewer view to package l First, use GridData to set the layout of the table control: 3 mesh units, horizontal and vertical stretching and total unit l Set the TableViewer view: Have a full range of all-elective and border style; use the SearchViewLabelProvider object (later introduction) to set the column value of each row of the table; use the previous GridData object to set the layout of the table control; add a listener that doubles the event, in the user Display the page of the specified URL in the Browserview view when you double-click l Adding a double-clicking on the event is implemented by the SearchView view to implement the method of the iDoubleClickListener interface, add a DoubleClick method to implement specific features. l Set the topic of the table and the width of the column of the list l SetFOCUS method is relatively simple, set the text domain to get the default focus