I am using a writablelist to store dataset data the user adds to the application.
public class AplotDataModel {
IObservableList observableList = new WritableList();
private static AplotDataModel instance = null;
//////////////////////////////////////////////////////////////////////////
// Constructor //
//////////////////////////////////////////////////////////////////////////
private AplotDataModel() {
}// end Constructor
//////////////////////////////////////////////////////////////////////////
// SingletonSelectTable getInstance() //
//////////////////////////////////////////////////////////////////////////
public static AplotDataModel getInstance() {
if (instance == null) {
instance = new AplotDataModel();
}
return instance;
}
//////////////////////////////////////////////////////////////////////////
// add() //
//////////////////////////////////////////////////////////////////////////
public void add(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset) {
AplotDatasetData pp = new AplotDatasetData(tcRevision, selectedDataset);
if (!observableList.contains(pp)) {
observableList.add(pp);
}
}
//////////////////////////////////////////////////////////////////////////
// clearTableArray() //
//////////////////////////////////////////////////////////////////////////
public void clearTableArray() {
observableList.clear();
}
}// End Class
In the ADD method, I am using a class to format the data to add to the writable list
AplotDatasetData pp = etc.....
Class
public class AplotDatasetData {
TCComponentItemRevision rev;
TCComponentDataset componentdataset;
String markUp = "no";
//////////////////////////////////////////////////////////////////////////
// Constructor //
//////////////////////////////////////////////////////////////////////////
public AplotDatasetData(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset) {
rev = tcRevision;
componentdataset = selectedDataset;
}// end Constructor
//////////////////////
// getDataset() //
//////////////////////
public TCComponent getDataset() {
return componentdataset;
}
//////////////////
// getRev() //
//////////////////
public TCComponent getRev() {
return rev;
}
//////////////////
// equals() //
//////////////////
@Override
public boolean equals(Object o) {
AplotDatasetData p = (AplotDatasetData) o;
if (rev.equals(p.getRev()) && componentdataset.equals(p.getDataset())) {
return true;
}
else {
return false;
}
}// end equals()
My code compiles – But I run a operation involving the writable list.
I get the following error.
ERROR: 11:31:00,591 – TcLogger$IC_LogListener.logging:?
org.eclipse.core.runtime – org.eclipse.ui – 0 – Unhandled event loop exception
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.ClassCastExc
eption: org.eclipse.core.databinding.observable.list.WritableList cannot be cast
to com.lexmark.aplot.datamodels.AplotDataModel$AplotDatasetData)
etc …..Caused by: java.lang.ClassCastException: org.eclipse.core.databinding.observable
.list.WritableList cannot be cast to com.lexmark.aplot.datamodels.AplotDataModel
$AplotDatasetData
at com.lexmark.aplot.datamodels.AplotDataModel$AplotDatasetData.equals(A
plotDataModel.java:167)
I know the issue is in the Equals method, but I am not sure how to change it, so it will work with the writable list.
EDIT
I traced the issue to this
ArrayList<AplotDataModel.AplotDatasetData> tableData = new ArrayList<AplotDataModel.AplotDatasetData>(AplotDataModel.getInstance().getObservableList());
I am trying to create a new arraylist using the data from a writablelist
The problem was in the Equals Method. I had to make the method more robust.