Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Eclipse RCP Meets Spring: A Perfect Thick-Client Match : Page 4

Eclipse Rich Client Platform (RCP) is fast becoming the framework of choice for building thick client applications. Get a step-by-step guide to leveraging Eclipse RCP with Spring.


advertisement

Creating a New WatchListView

Now you are ready to begin creating your own view classes. You first create a WatchListView, which will make a request of the application server's StockDataService:
  1. In plugin.xml, go to the extensions tab.
  2. Select org.eclipse.ui.views in the All Extensions tree and then click Add.
  3. You will have a new dialog window. Scroll down in the Extension Points tree and select org.eclipse.ui.views. Under Available templates for org.eclipse.ui.views, choose SampleView and then click Next (see Figure 13).

    Click to enlarge

    Figure 13. New Extension Dialog
  4. Complete the following information in the Main View Settings window:

    Java Package Name = eclipseTradeClient.views.watchlist View Class Name = WatchListView View Name = Watch List View View Category ID = EclipseTradeClient View Category Name = WatchList Category



    Leave Table Viewer selected and keep Add the view to the resource perspective checked (see Figure 14). Click Next.

    Click to enlarge

    Figure 14. Main View Settings for Watch List View
  5. Under View Features, leave the defaults and click Finish.
  6. You will now see the new View and Category in the All Extensions tab of plugin.xml.
  7. You are now ready to code your Watch List View. The watch list will be a table, so first implement an ITableLabelProvider for the table. Create a new class called WatchListTableLabelProvider under package eclipseTradeClient.views.watchlist. Think of an ITableLabelProvider as JFace's equivalent to a TableCellRenderer in Swing. The following is the code for WatchListTableLabelProvider:

    package eclipseTradeClient.views.watchlist; import java.text.NumberFormat; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; import stephenlum.services.stock.dto.StockDTO; public class WatchListTableLabelProvider extends LabelProvider implements ITableLabelProvider { private static NumberFormat numberFormat = NumberFormat.getInstance(); public Image getColumnImage(Object element, int columnIndex) { return null; } public String getColumnText(Object element, int columnIndex) { if (element != null) { switch (columnIndex) { case 0: return ((StockDTO) element).getTickerSymbol(); case 1: return ((StockDTO) element).getLastTrade().toString(); case 2: return numberFormat.format(((StockDTO) element).getVolume()); case 3: return ((StockDTO) element).getDaysRange(); case 4: return numberFormat.format(((StockDTO) element).getAvgVol()); case 5: return ((StockDTO) element).getDaysRange(); case 6: return ((StockDTO) element).getFiftyTwoWeekRange(); case 7: return ((StockDTO) element).getMarketCap(); } } return ""; } }

  8. Finally, you add your WatchListView to the Perspective class. Open class Perspective in the Package Explorer and make the following changes so that the WatchListView will appear at the bottom of the page:

    package eclipseTradeClient; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; import org.eclipse.ui.IFolderLayout; import eclipseTradeClient.views.WatchListView; public class Perspective implements IPerspectiveFactory { public void createInitialLayout(IPageLayout layout) { String editorArea = layout.getEditorArea(); layout.setEditorAreaVisible(false); layout.setFixed(false); layout.addStandaloneView(ExplorerView.ID, false, IPageLayout.LEFT, 0.25f, editorArea); IFolderLayout topLeft = layout.createFolder("TOP", IPageLayout.TOP, 0.50f, editorArea); layout.addView(WatchListView.ID, IPageLayout.BOTTOM, 0.25f, editorArea); } }

  9. Now make your additions to class WatchListView. I've kept much of the code generated by the template wizard intact so that you can freely add your own code to it. Essentially, you are adding a table that will display all the information contained within an instance of class StockDTO. As such, the columns are based on the members of StockDTO as well. I've renamed the two generated actions, such that action1 now fetches the list of stocks from the stocktradeserver and displays them in the table, and action2 removes all elements from the table (see Listing 1. eclipseTradeClient.views.watchlist).



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap