Question

One of the rows in my table is a ComboBox. They have the choice between 'Yes', 'No', 'Both' If they choose Both have to make some modifications to the data array that is building the table and refresh the table. It was suggested in a previous post to build my logic in the else statement for Both.

protected void setValue(Object element, Object value) 
{
   if((element instanceof AplotDatasetData) && (value instanceof Integer)) {
        Integer choice = (Integer)value;
        String option = ((AplotDatasetData)element).getMarkupValue();;
        if(choice == 0) {
            option = "No";
        }    
        else if(choice == 1) {
            option = "Yes";
        }    
        else {
            option = "Both";
            abd.getIndexOfSelectedBoth(); <<<<<<<<<
        }    
       ((AplotDatasetData)element).setMarkupValue(option);
        getViewer().update(element, null);
    }
}

The code above is in class OptionEditingSupport.

The table is in class AplotBaseDailog.

So in the OptionEditingSupport class, I imported the AplotBaseDailog class and assigned it.

AplotBaseDialog abd;

Then I wrote a method in the AplotBaseDailog class to get the row index of the column they just changed to Both. I need the index value to get the data from the array.

 public void getIndexOfSelectedBoth() {
     int row = viewer.getTable().getSelectionIndex();
     AplotDataModel.getInstance().rebuildDataArray(row);
     updateTableViewer();
  }

Then I am passing in the index of the row to a method in my dataModel class. It is in the dataModel class that has the data array.

I am guessing I am reinventing the wheel here. There has to be a better way to do this process. Right now with all my code in place, I am getting a Null Pointer Error at the line that calls AplotBaseDialog

else {
        option = "Both";
        abd.getIndexOfSelectedBoth(); <<<<----
      }  

Can you get the index in the OptionEditingSupport class?

Était-ce utile?

La solution

So you want to find the index of the AplotDatasetData for which "both" was selected.

Your ModelProvider (APlotDataModel) contains a List with your data, right?

Each List implements the method indexOf(Object). So you can get the index of your current object by using this method.

AplotDatasetData selected = ...
int index = AplotDataModel.getInstance().getIndexOf(selected);

and within your model:

public int getIndexOf(APlotDatasetData object)
{
    return LIST_HOLDING_YOUR_DATA.indexOf(object);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top