Friday, April 19, 2013

Creating SWT table


                    SWT TableViewer

Below I will try to explain you as to how to create a SWT table .
1.Set the layout on the composite over which you wanna create the Table specifying width and height etc .

2. Create a table
         TableViewer tableViewer = new TableViewer(parentComposite,SWT.BORDER );

3.Set the content provider
          tableViewer.setContentProvider(new TableContentProvider())
here TableContentProvider is implemeting IStructuredContentProvider
its method : public Object[] getElements(Object inputElement)
 Returns the elements in the input, which must be either an array or a Collection
So what ever you set as Input in the table we must convert it into array of objects here .

4. Set the LabelProvider  :tableViewer.setLabelProvider(new tableLabelprovider())
         tableLabelprovider    implements ITableLabelProvider
Here we can override two methods
  public String getColumnText(Object element, int columnIndex) : Returns the label text for the given column of the given element.
 Get the model which you setting in the table as input from element and using switch case we can return the value for each column according to the column Index
this is to set the label for each field in your table

5.Add columns according to your requirement

6. If you want any kind of cellEditor eg:TextCellEditor ,CheckboxCellEditor,Dialog cellEditor ,then you have  to add CellEditors for each column . If you want your column to be editable then we can use TextCellEditor .
7. set a cellModifier to your table viewer .
here in the method canModify we have to return true if for a particular column you want it to be editable .
in the method getValue() return value from your model according to the column (property name )
in the method modify() get the value from the table that has been modified and set it to your model and save the model accordingly .
Remember to refresh your table viewer .




Monday, April 8, 2013

Creating quick fix extension for Eclipse Below i am listing the steps needed for creating quick fix extensions in eclipse . I am assuming that the problem has already been registered with eclipse 1.Create a marker type with extension point org.eclipse.core.resources.markers 2.Extend the org.eclipse.ui.ide.markerResolution extension point and create a markerresolutiongenerator . 3.add the marker type while creating the validation error in the code . 4.Create a class resolution generator implements IMarkerResolutionGenerator and register it to plugin while extending the extension point markerResolution . 5.In the function getResolutions(IMarker marker) return a new object which implements IMarkerResolution2 . 6.In the run function do the necessary work . 7.Use other methods such as getDescription() etc to make ur quick fix more informative