WritableList casting issues [message #1007435] |
Tue, 05 February 2013 20:41 |
James Teater Messages: 17 Registered: July 2011 |
Junior Member |
|
|
I am using a writable list to store data the user selects. I am using a writable list so that when users add or remove data my table viewers update.
This is part of the class that creates the writable list.
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
I am using the class AplotDataset to format the list.
AplotDatasetData pp = new AplotDatasetData(tcRevision, selectedDataset);
Some of the 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()
Everything works as it should to this point.
In a different class I am trying to create a new ArrayList using data in my Writable List.
public void buildPlotArray() {
ArrayList<AplotDataModel.AplotDatasetData> tableData = new ArrayList<AplotDataModel.AplotDatasetData>(AplotDataModel.getInstance().getObservableList());//Getting Writable List
String yesECM = "yes";
String noECM = "no";
for(int i = 0; i < tableData.size(); i++){
TCComponentItemRevision rev = tableData.get(i).rev;
TCComponentDataset dataset = tableData.get(i).componentdataset;
String ecmCheck = tableData.get(i).getMarkupValue();
if(ecmCheck == "both"){
PlotData yfd = new PlotData(rev , dataset, yesECM);
plotData.add(yfd);
PlotData nfd = new PlotData(rev , dataset, noECM);
plotData.add(nfd);
}
else {
PlotData sfd = new PlotData(rev , dataset, ecmCheck);
plotData.add(sfd);
}
}
}
The code compiles, but I try to run specific operations. 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)
So what I know from the error. It is a casting issue with the Writable List.
The error is occurring in the equal method in AplotDatasetData
@Override
public boolean equals(Object o) {
AplotDatasetData p = (AplotDatasetData) o; //Right here
if (rev.equals(p.getRev()) && componentdataset.equals(p.getDataset())) {
return true;
}
else {
return false;
}
}// end equals()
I also know that the only place I am trying to cast the list is when I am trying to create the new ArrayList.
ArrayList<AplotDataModel.AplotDatasetData> tableData = new ArrayList<AplotDataModel.AplotDatasetData>(AplotDataModel.getInstance().getObservableList())
So at this point I don't know if I need to:
1. Work on the equals method, trying to get it to work with the writable list?
2. If I need to work on the place where I am trying to create a new ArrayList from the writable list?
3. If there is a better way to define the WritableList, when creating it?
I have to have the equals method, so the users can not put duplicate data in the list. I also have to have the writable list.
This issue is keeping me from be able to go live with my application.
Any help will be greatly appreciated!!
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03562 seconds