2

My eclipse plugin takes in input from file which it reads from xml file

Problem Statement :

It is able to read xml for the first time but when i am trying to read the file for the second time the results are not refreshing in the table view .

View part :

private void createViewer(Composite parent) {

        viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);

        System.out.println("i am being called in best practice ");
        table = viewer.getTable();
        table.setHeaderVisible(true);
        table.setLinesVisible(true);
        viewer.setContentProvider(new ArrayContentProvider());
        BestPracticeModelProvider bestpracticeprovider = new BestPracticeModelProvider();
        viewer.setInput(bestpracticeprovider.getbestpractices());
        System.out.println("model is being set here in best practice ");
        getSite().setSelectionProvider(viewer);
        createColumns(parent, viewer);      

    }

    @Override
    public void setFocus() {
        // TODO Auto-generated method stub
         viewer.getControl().setFocus();
    }

    public TableViewer getViewer() {
        return viewer;
    }

    private TableViewerColumn createTableViewerColumn(String title, int bound,
            final int colNumber) {
        final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
                SWT.NONE);
        final TableColumn column = viewerColumn.getColumn();
        column.setText(title);
        column.setWidth(bound);
        column.setResizable(true);
        column.setMoveable(true);
        return viewerColumn;
    }

    private void createColumns(Composite parent, TableViewer viewer) {
        String[] titles = new String[] { IViewConstants.CATEGORY,
                IViewConstants.VIOLATION, IViewConstants.DETAILS,
                IViewConstants.CODE_FRAGMENT, IViewConstants.LOCATION,
                IViewConstants.PATTERN_ID };
        int[] bounds = { 100, 100, 100, 100, 100, 100 };

        TableViewerColumn col = createTableViewerColumn(titles[0], bounds[0], 0);

        col.setLabelProvider(new ColumnLabelProvider() {
            @Override
            public String getText(Object element) {
                BestPracticeView p = (BestPracticeView) element;
                return p.getType();
            }
        });

        col = createTableViewerColumn(titles[1], bounds[1], 1);
        col.setLabelProvider(new ColumnLabelProvider() {
            @Override
            public String getText(Object element) {
                BestPracticeView p = (BestPracticeView) element;
                return p.getDetails();
            }
        });

        // Now the Type
        col = createTableViewerColumn(titles[2], bounds[2], 2);
        col.setLabelProvider(new ColumnLabelProvider() {
            @Override
            public String getText(Object element) {
                BestPracticeView p = (BestPracticeView) element;
                return p.getLocation();
            }
        });

Model part :

public class BestPracticeView {

    private String type;
    private String details;
    private String location;
    private String patternid;
    private String locationfile;
    private String category;
    private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);


    public BestPracticeView() {
      }


     public void addPropertyChangeListener(String propertyName,PropertyChangeListener listener) {
         propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
    }

     public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.removePropertyChangeListener(listener);
    }


    public BestPracticeView(String type, String details, String location,
            String patternid, String locationfile, String category) {
        this.type = type;
        this.details = details;
        this.location = location;

        this.patternid = patternid;
        this.locationfile = locationfile;
        this.category = category;

    }

    public String getCategory() {

        return category;
    }

    public void setCategory(String category) {
        propertyChangeSupport.firePropertyChange("category", this.category,
                this.category = category);

    }

    public String getType() {

        return type;
    }

    public void setType(String type) {

//code snippet

4

0 回答 0