Firebase image delete - firebase

I'm building a gallery app with firebase.
My problem is that when I delete the image, it deletes the document from firebase, but it does not delete it from the screen and the other images are copied on the screen, I could not handle it, I will show you the example below.
THİS GALLERY ADAPTER
#Override
public void onBindViewHolder(#NonNull GalleryHolder holder, int position) {
Picasso.get().load(galleryAdapterArrayList.get(position).downloadUrl).into(holder.imageView);
}
public class GalleryHolder extends RecyclerView.ViewHolder{
public Gallery gallery;
public CheckBox checkBox;
ImageView imageView;
public FirebaseFirestore firebaseFirestore;
public FirebaseUser firebaseUser;
public FirebaseAuth firebaseAuth;
public String Docıd;
public DocumentSnapshot snapshot;
public CollectionReference collectionReference;
public GalleryHolder(#NonNull View itemview) {
super(itemview);
imageView=itemview.findViewById(R.id.gallerLayoutimageview);
firebaseFirestore=FirebaseFirestore.getInstance();
firebaseAuth=FirebaseAuth.getInstance();
firebaseUser=FirebaseAuth.getInstance().getCurrentUser();
itemview.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
PopupMenu popupMenu=new PopupMenu(v.getContext(),v);
popupMenu.setGravity(Gravity.END);
popupMenu.getMenu().add(R.string.sil).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem menuItem) {
DocumentReference documentReference=firebaseFirestore.collection("Gallery").document(firebaseUser.getUid()).collection("myGallery").document(galleryAdapterArrayList.get(getPosition()).docId);
documentReference.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
System.out.println("dsadad");
notifyDataSetChanged();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(v.getContext(),R.string.notSilinmedi,Toast.LENGTH_SHORT);
}
});
return false;
}
});
popupMenu.show();
return false;
}
});
}
}
}
THİS GALLERY ACTIVITY
public void getData() {
firebaseFirestore.collection("Gallery").document(firebaseUser.getUid()).collection("myGallery").orderBy("date", Query.Direction.DESCENDING).addSnapshotListener(new EventListener<QuerySnapshot>() {
#Override
public void onEvent(#Nullable QuerySnapshot value, #Nullable FirebaseFirestoreException error) {
if (error != null) {
Toast.makeText(getApplicationContext(), error.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
if (value != null) {
for (DocumentSnapshot snapshot : value.getDocuments()) {
Map<String, Object> data = snapshot.getData();
String downloadUrl = (String) data.get("downloadUrl");
String docId = (String) data.get("docId");
checkBox=findViewById(R.id.checkimages);
GalleryModel galleryModel=new GalleryModel(docId,downloadUrl,checkBox);
galleryModelArrayList.add(galleryModel);
}
galleryAdapter.notifyDataSetChanged();
}
}
});
}
before deleting images
after deleting images
Reset activity

Related

how to write a query firebase

I'm trying to filter specific user posts like this:
filter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(
ProfileActivity.this, R.style.BottomSheetDialogTheme
);
View bottomSheetView = LayoutInflater.from(getApplicationContext())
.inflate(R.layout.layout_bottom_sheet,
(LinearLayout)findViewById(R.id.bottomSheetContainer)
);
final RadioButton b = bottomSheetView.findViewById(R.id.breakfast);
final RadioButton dinner = bottomSheetView.findViewById(R.id.dinner);
if(dinner.isChecked()){
Query reference = FirebaseDatabase.getInstance().getReference("posts").orderByChild("Meal");
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
if (snapshot.getValue().equals(dinner.getText().toString()))
{
Toast.makeText(ProfileActivity.this, dinner.getText() + "is clicked", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
I want to check whether the checked radioButton value is equal to Meal from database, the current code doesn't show the toast message which means the condition is not met even though it is supposed to. How can I write a proper query for this case?
Query reference = FirebaseDatabase.getInstance().getReference("Posts").orderByChild("Meal");
This will return list of matched data snapshot.
get each snapshot like
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
for (DataSnapshot ds : snapshot.getChildren()) {
if (ds.getValue().equals(dinner.getText().toString())) {
Toast.makeText(ProfileActivity.this, dinner.getText() + "is clicked", Toast.LENGTH_SHORT).show();
}
}
}
});

How do I change the value of child in firebase using a checkbox click

This is the code am using to fetch data from my firebase realtime database.
private void fetch() {
Query query = FirebaseDatabase.getInstance()
.getReference()
.child("products");
FirebaseRecyclerOptions<Product> options =
new FirebaseRecyclerOptions.Builder<Product>()
.setQuery(query, new SnapshotParser<Product>() {
#NonNull
#Override
public Product parseSnapshot(#NonNull DataSnapshot snapshot) {
return new Product(snapshot.child("id").getValue().toString(),
snapshot.child("name").getValue().toString(),
snapshot.child("price").getValue().toString(),
snapshot.child("sku").getValue().toString(),
snapshot.child("category").getValue().toString(),
snapshot.child("subCategory").getValue().toString(),
snapshot.child("availability").getValue().toString());
}
})
.build();
adapter = new FirebaseRecyclerAdapter<Product, ProductsViewHolder>(options) {
#Override
public ProductsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_product, parent, false);
return new ProductsViewHolder(view);
}
#Override
protected void onBindViewHolder(ProductsViewHolder holder, final int position, final Product model) {
holder.setName(model.getName());
holder.setPrice(model.getPrice());
holder.setSubCategory(model.getSubCategory());
holder.setViewAvailability(model.getAvailability());
//holder.setSku(model.getSku());
holder.root.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Toast.makeText(ProductsActivity.this, model.getId(), Toast.LENGTH_SHORT).show();
}
});
}
};
recyclerView.setAdapter(adapter);
}
This is the product viewHolder
public class ProductsViewHolder extends RecyclerView.ViewHolder{
public CardView root;
public TextView viewSubCategory;
public TextView viewName;
public TextView viewPrice;
//public TextView viewSku;
public CheckBox viewAvailability;
Context context;
public ProductsViewHolder(View itemView) {
super(itemView);
root = itemView.findViewById(R.id.list_product_root);
viewSubCategory = itemView.findViewById(R.id.viewSubCategory);
viewName = itemView.findViewById(R.id.viewName);
viewPrice = itemView.findViewById(R.id.viewPrice);
viewAvailability = itemView.findViewById(R.id.viewAvailability);
//viewAvailability.setOnCheckedChangeListener(this);
}
public void setName(String string) {
viewName.setText(string);
}
public void setViewAvailability(String string) {
if (string.equals("0")){
viewAvailability.setChecked(false);
}else {
viewAvailability.setChecked(true);
}
}
public void setPrice(String string) {
viewPrice.setText(String.format("%,d", Integer.parseInt(string)));
}
/* public void setSku(String string) {
viewSku.setText(string);
}*/
public void setSubCategory(String string) {
viewSubCategory.setText(string);
}
}
veiwAvailaibility is a checkbox, that when checked it should change the value of availability (which is a child of a product) in firebase from 0 to 1 (checked and unchecked respectively). I am failing to get the clicking checking functionality done in the ViewHolder or in my fetch class. Any assistance is appreciated.
private void fetch() {
Query query = FirebaseDatabase.getInstance()
.getReference()
.child("products");
FirebaseRecyclerOptions<Product> options =
new FirebaseRecyclerOptions.Builder<Product>()
.setQuery(query, new SnapshotParser<Product>() {
#NonNull
#Override
public Product parseSnapshot(#NonNull DataSnapshot snapshot) {
return new Product(snapshot.child("id").getValue().toString(),
snapshot.child("name").getValue().toString(),
snapshot.child("price").getValue().toString(),
snapshot.child("sku").getValue().toString(),
snapshot.child("category").getValue().toString(),
snapshot.child("subCategory").getValue().toString(),
snapshot.child("availability").getValue().toString());
}
})
.build();
adapter = new FirebaseRecyclerAdapter<Product, ProductsViewHolder>(options) {
#Override
public ProductsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_product, parent, false);
return new ProductsViewHolder(view);
}
#Override
protected void onBindViewHolder(ProductsViewHolder holder, final int position, final Product model) {
holder.setName(model.getName());
holder.setPrice(model.getPrice());
holder.setSubCategory(model.getSubCategory());
holder.setViewAvailability(model.getAvailability());
holder.viewAvailability.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if(isChecked){
//suggestion.setSelected(true);
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("products").child(model.getId());
Map<String, Object> updates = new HashMap<String,Object>();
updates.put("availability", "1");
ref.updateChildren(updates);
}else {
//suggestion.setSelected(false);
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("products").child(model.getId());
Map<String, Object> updates = new HashMap<String,Object>();
updates.put("availability", "0");
ref.updateChildren(updates);
}
}
});
//holder.setSku(model.getSku());
holder.root.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
}
});
}
};
recyclerView.setAdapter(adapter);
}

Using database on recyclerview

The first activity save some data at the firebase database and i need to show on the second activity using a recyclerview. I'm trying many times and i follow a tutorial, but always the recyclerview isn't displaying anything.
The Firebase was working correctly saving the data, but i can't put at recyclerview.
The activities are:
MenuActivity (recyclerview)
private RecyclerView recyclerView;
private Informações informações;
FirebaseDatabase database;
DatabaseReference myRef;
List<Informações> list;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
database = FirebaseDatabase.getInstance();
myRef = database.getReference("Informações");
myRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
list = new ArrayList<Informações>();
for (DataSnapshot dataSnapshot1 :dataSnapshot.getChildren()){
Informações value = dataSnapshot1.getValue(Informações.class);
Informações informações = new Informações();
String empresa = value.getEmpresa();
String setor = value.getSetor();
String data = value.getData();
informações.setEmpresa(empresa);
informações.setSetor(setor);
informações.setData(data);
list.add(informações);
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
RecyclerAdapter recyclerAdapter = new RecyclerAdapter(list, MenuActivity.this);
RecyclerView.LayoutManager recyce = new GridLayoutManager(MenuActivity.this,2);
recyclerView.setLayoutManager(recyce);
recyclerView.setAdapter(recyclerAdapter);
The RecyclerAdapter
List<Informações> list;
Context context;
public RecyclerAdapter(List<Informações> list, Context context){
this.list = list;
this.context = context;
}
#Override
public MyViewHolder onCreateViewHolder( ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.adapter_lista,parent,false);
MyViewHolder myViewHolder = new MyViewHolder(view);
return myViewHolder;
}
#Override
public void onBindViewHolder( MyViewHolder holder, int position) {
Informações mylist = list.get( position );
holder.empresa.setText(mylist.getEmpresa());
holder.setor.setText(mylist.getSetor());
holder.data.setText(mylist.getData());
}
#Override
public int getItemCount() {
int arr = 0;
try {
if (list.size() == 0)
{ arr = 0;
} else { arr = list.size(); }
} catch (Exception e) {}
return arr;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView empresa, setor, data;
public MyViewHolder(View itemView) {
super(itemView);
empresa = (TextView) itemView.findViewById(R.id.textEmpresa);
setor = (TextView) itemView.findViewById(R.id.textSetor);
data = (TextView) itemView.findViewById(R.id.textData);
}
}
}
And the Firebase
public class Informações {
private String equipe;
private String empresa;
private String setor;
private String responsavel;
private String visita;
private String ferramenta;
private String data;
public Informações() {
}
public void salvar(){
DatabaseReference firebase = ConfiguracaoFirebase.getFirebaseDatabase();
firebase.child("Informações")
.child( this.empresa )
.setValue( this );
}
public String getVisita() { return visita; }
public void setVisita(String visita) { this.visita = visita; }
public String getFerramenta() { return ferramenta; }
public void setFerramenta(String ferramenta) { this.ferramenta = ferramenta; }
public String getData() { return data; }
public void setData(String data) { this.data = data; }
public String getEquipe() { return equipe; }
public void setEquipe(String equipe) { this.equipe = equipe; }
public String getEmpresa() { return empresa; }
public void setEmpresa(String empresa) { this.empresa = empresa; }
public String getSetor() { return setor; }
public void setSetor(String setor) { this.setor = setor; }
public String getResponsavel() { return responsavel; }
public void setResponsavel(String responsavel) { this.responsavel = responsavel; }
}

Correcting a null object reference while adding a recyclerview into a fragment

Trying to implement a recycleview inside of a fragment using a custom adapter and receiving the following error.
java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference. AtStoreAdapter.getItemCount(StoreAdapter.java:xx)
I have looked around SO, but have not seen anything that is leading to a solution. Any help would be appreciated.
Android app - Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
and a few others
StoreAdapter
public class StoreAdapter extends RecyclerView.Adapter<StoreAdapter.StoreHolder>{
private LayoutInflater mInflator;
private List<Store> mStore= Collections.emptyList();
private Context mContext;
public StoreAdapter(Context mContext, List<Store> mStore){
mInflator = LayoutInflater.from(mContext);
this.mStore = mStore;
this.mContext = mContext;
}
// Simple nested class that holds the various view components for the adapter
// and as specified in *layout.xml .
public class StoreHolder extends RecyclerView.ViewHolder{
TextView mStoreTitle, mStoreDetails, mStoreCategory;
public StoreHolder (View itemView){
super(itemView);
mStoreTitle = (TextView) itemView.findViewById(R.id.title);
mStoreDetails = (TextView) itemView.findViewById(R.id.details);
mStoreCategory = (TextView) itemView.findViewById(R.id.category);
}
}
// Called when the RecyclerView needs a new RecyclerView.ViewHolder (*Holder)
// to represent an item. We inflate the XML layout and return our view (*Holder)
#Override
public StoreHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = mInflator.inflate(R.layout.todo_list_row, parent,false);
return new StoreHolder(view);
}
// Called by RecyclerView to display the data at the specified position.
// This method needs to update the contents of the view to reflect the item at the
// given position e.g. we are updating the view here with the data
#Override
public void onBindViewHolder(StoreAdapter.StoreHolder holder, int position) {
holder.mStoreTitle.setText(mStore.get(position).getStoreTitle());
holder.mStoreDetails.setText(mStore.get(position).getStoreDetails());
holder.mStoreCategory.setText(mStore.get(position).getStoreCategory());
}
public void setData(List<Store> store){
this.mStore = store;
}
public void delete(int position){
mStore.remove(position);
notifyItemRemoved(position);
}
#Override
public int getItemCount() {
return mStore.size();
}
}
StoreSectionLoader
public class StoreSectionLoader extends AsyncTaskLoader<List<Store>> {
private static final String LOG_TAG = StoreSectionLoader.class.getSimpleName();
private List<Store> mStore;
private ContentResolver mContentResolver;
private Cursor mCursor;
public StoreSectionLoader(Context context, Uri uri, ContentResolver contentResolver){
super(context);
mContentResolver = contentResolver;
}
#Override
public List<Store> loadInBackground() {
String[] projection = {BaseColumns._ID,
RetailFinderContract.RetailFinderColumns.STORE_COMPLETE,
RetailFinderContract.RetailFinderColumns.STORE_CREATED,
RetailFinderContract.RetailFinderColumns.STORE_TITLE,
RetailFinderContract.RetailFinderColumns.STORE_DETAILS,
RetailFinderContract.RetailFinderColumns.STORE_CATEGRORY};
List<Store> entry = new ArrayList<>();
Uri uri = RetailFinderContract.URI_LOCATION_TABLE;
mCursor = mContentResolver.query(uri, projection, null, null, null);
if(mCursor != null){
if(mCursor.moveToFirst()){
do {
int _id = mCursor.getInt(mCursor.getColumnIndex(BaseColumns._ID));
String store_title = mCursor.getString(
mCursor.getColumnIndex(RetailFinderContract.RetailFinderColumns.STORE_TITLE));
String store_details = mCursor.getString(
mCursor.getColumnIndex(RetailFinderContract.RetailFinderColumns.STORE_DETAILS));
String store_category = mCursor.getString(
mCursor.getColumnIndex(RetailFinderContract.RetailFinderColumns.STORE_CATEGRORY));
Store store = new Store(_id,store_title,store_details,store_category);
entry.add(store);
} while (mCursor.moveToNext());
}
}
return entry;
}
#Override
public void deliverResult(List<Store> store) {
if(isReset()){
if (mStore != null){
mCursor.close();
}
}
List<Store> oldStoreList = mStore;
if(mStore == null || mStore.size() == 0 ){
Log.d(LOG_TAG, "+++++++++++++++ No Data returned");
}
mStore = store;
if(isStarted()){
super.deliverResult(store);
}
if(oldStoreList != null && oldStoreList != store){
mCursor.close();
}
}
#Override
protected void onStartLoading() {
if(mStore != null){
deliverResult(mStore);
}
if(takeContentChanged() || mStore == null){
forceLoad();
}
}
#Override
protected void onStopLoading() {
cancelLoad();
}
#Override
protected void onReset() {
onStopLoading();
if(mCursor != null){
mCursor.close();
}
mStore = null;
}
#Override
public void onCanceled(List<Store> store) {
super.onCanceled(store);
if(mCursor != null){
mCursor.close();
}
}
#Override
public void forceLoad() {
super.forceLoad();
}
}
StoreFragment
public class StoreFragment extends Fragment implements
LoaderManager.LoaderCallbacks<List<Store>> {
private static final String LOG_TAG = StoreListFragment.class.getSimpleName();
private StoreAdapter mAdapter;
private static final int LOADER_ID = 1;
private ContentResolver mContentReslover;
private List<Store> mStore;
private Context mContext;
protected RecyclerView mRecyclerView;
private static final String TAG = "RecyclerViewFragment";
private static final String KEY_LAYOUT_MANAGER = "layoutManager";
private enum LayoutManagerType {
GRID_LAYOUT_MANAGER,
LINEAR_LAYOUT_MANAGER
}
protected LayoutManagerType mCurrentLayoutManagerType;
protected RecyclerView.LayoutManager mLayoutManager;
// end added
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
mContentReslover = getActivity().getContentResolver();
getLoaderManager().initLoader(LOADER_ID, null, this);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.store_list_row, container, false);
rootView.setTag(TAG);
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.t_recycler);
mLayoutManager = new LinearLayoutManager(getActivity());
mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;
if (savedInstanceState != null) {
// Restore saved layout manager type.
mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState
.getSerializable(KEY_LAYOUT_MANAGER);
}
setRecyclerViewLayoutManager(mCurrentLayoutManagerType);
mAdapter = StoreAdapter(getContext(), mStore); //issue
mRecyclerView.setAdapter(mAdapter);
return rootView;
}
public void setRecyclerViewLayoutManager(LayoutManagerType layoutManagerType) {
int scrollPosition = 0;
// If a layout manager has already been set, get current scroll position.
if (mRecyclerView.getLayoutManager() != null) {
scrollPosition = ((LinearLayoutManager) mRecyclerView.getLayoutManager())
.findFirstCompletelyVisibleItemPosition();
}
switch (layoutManagerType) {
case LINEAR_LAYOUT_MANAGER:
mLayoutManager = new LinearLayoutManager(getActivity());
mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;
break;
default:
mLayoutManager = new LinearLayoutManager(getActivity());
mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;
}
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.scrollToPosition(scrollPosition);
}
#Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save currently selected layout manager.
savedInstanceState.putSerializable(KEY_LAYOUT_MANAGER, mCurrentLayoutManagerType);
super.onSaveInstanceState(savedInstanceState);
}
#Override
public Loader<List<Store>> onCreateLoader(int id, Bundle args) {
mContentReslover = getActivity().getContentResolver();
return new StoreSectionLoader(getActivity(), RetailFinderContract.URI_STORES_TABLE, mContentReslover);
}
#Override
public void onLoadFinished(Loader<List<Store>> loader, List<Store> store) {
mAdapter.setData(store);
mStore = store;
}
#Override
public void onLoaderReset(Loader<List<Store>> loader) {
mAdapter.setData(null);
}
}

Disable ContextMenu with dependency to TreeTableView selection

I have a TreeTableView which allows multiselection. I got a ContextMenu for editing or deleting that selected items.
Delete and edit should only be enabled if there is at least one selection.
final BooleanBinding isTableSelectionEmpty = Bindings.isEmpty(this.table.getSelectionModel().getSelectedItems());
this.menuItemDelete.disableProperty().bind(isTableSelectionEmpty);
That is working as expected.
But now I have dependencies on different values of the selected rows. Like for example that the row is system-mandatory and should not be deleted.
I tried the following but it is not working
final BooleanBinding invalidSelection = Bindings.and(Bindings.isEmpty(tableSelection),
Bindings.isNotEmpty(tableSelection.filtered(item -> {
this.logger.trace("filtering :" + item);
return item.getValue().getSystemProperty().get();
})));
this.menuItemDelete.disableProperty().bind(invalidSelection);
Not even the debug-trace is printed and the value of the binding is always false (thus enabling the menu item). Now I am a bit lost. Where is my mistake?
FilteredList relies on a correct ListIterator, but currently there is a bug in the ListIterator the selectedItems list in MultipleSelectionModelBase. This prevents the filtering to properly work. To fix this you could create a ObservableList implementation delegating everything but the ListIterator creation to a source ObservableList. Most IDEs have a functionality to generate this kind of methods automatically, reducing the amount of work to a minimum (e.g.in NetBeans: Generate -> Delegate Method).
public class ObservableListIteratorFix<T> implements ObservableList<T> {
private final ObservableList<T> list;
public ObservableListIteratorFix(ObservableList<T> list) {
this.list = list;
}
#Override
public void addListener(ListChangeListener<? super T> listener) {
list.addListener(listener);
}
#Override
public void removeListener(ListChangeListener<? super T> listener) {
list.removeListener(listener);
}
#Override
public boolean addAll(T... elements) {
return list.addAll(elements);
}
...
private class CustomListIterator implements ListIterator<T> {
private final ListIterator<T> iterator;
private int index;
public CustomListIterator(int index) {
this.iterator = list.listIterator(index);
this.index = index;
}
#Override
public boolean hasNext() {
return iterator.hasNext();
}
#Override
public T next() {
T t = iterator.next();
index++;
return t;
}
#Override
public boolean hasPrevious() {
return iterator.hasPrevious();
}
#Override
public T previous() {
T t = iterator.previous();
index--;
return t;
}
#Override
public int nextIndex() {
return index;
}
#Override
public int previousIndex() {
return index-1;
}
#Override
public void remove() {
iterator.remove();
}
#Override
public void set(T e) {
iterator.set(e);
}
#Override
public void add(T e) {
iterator.add(e);
}
#Override
public void forEachRemaining(Consumer<? super T> action) {
iterator.forEachRemaining(action);
}
}
#Override
public ListIterator<T> listIterator() {
return listIterator(0);
}
#Override
public ListIterator<T> listIterator(int index) {
return new CustomListIterator(index);
}
#Override
public FilteredList<T> filtered(Predicate<T> predicate) {
return new FilteredList<>(this, predicate);
}
...
This allows you to use the class as wrapper the selectedItems which should fix the filtering...
new ObservableListIteratorFix<>(tableSelection).filtered(...)

Resources