/** * Mark the list item with the given ID. * * @param pItemId item ID */ @SuppressWarnings("unchecked") public void setMarked(final String pItemId) { if (LOG.isTraceEnabled()) { LOG.enter( "setMarked", //$NON-NLS-1$ new String[] {"pItemId"}, new Object[] {pItemId}); // $NON-NLS-1$ } boolean clear = pItemId == null || pItemId.equals( getIdFromWidget( ((CbGenericListItem<W>) iGuiList.getWidget(iMarkedIdx)).getDisplayWidget())); clearMarker(); if (pItemId != null && !clear) { int idx = 0; for (Iterator<Widget> iter = iGuiList.iterator(); iter.hasNext(); idx++) { CbGenericListItem<W> gli = (CbGenericListItem<W>) iter.next(); W w = gli.getDisplayWidget(); if (pItemId.equals(getIdFromWidget(w))) { setMarked(idx); break; } } } LOG.exit("setMarked"); // $NON-NLS-1$ }
/** * Add an item to the list. * * @param pNewWidget the new display widget */ @SuppressWarnings("unchecked") protected void addDisplayWidget(final W pNewWidget) { final String itemId = getIdFromWidget(pNewWidget); int beforeIdx = -1; for (Widget w : iGuiList) { CbGenericListItem<W> gli = (CbGenericListItem<W>) w; if (itemId.compareToIgnoreCase(getIdFromWidget(gli.getDisplayWidget())) < 0) { beforeIdx = gli.getRowIdx(); break; } } CbGenericListItem<W> newRow = new CbGenericListItem<W>(getSelectorCallback(), getMoreArrowCallback()); newRow.setDisplayWidget(pNewWidget); if (beforeIdx < 0) { newRow.setRowIdx(iGuiList.getWidgetCount()); iGuiList.add(newRow); } else { newRow.setRowIdx(beforeIdx); iGuiList.insert(newRow, beforeIdx); int i = 0; for (Widget w : iGuiList) { ((CbGenericListItem<W>) w).setRowIdx(i++); } } checkEmptyListHint(); }
/** * Gets the display widget with the given item ID from {@link #iGuiList}. * * @param pItemId the widget's item ID * @return the widget itself */ protected W getItem(final String pItemId) { W result = null; for (Iterator<Widget> iter = iGuiList.iterator(); iter.hasNext(); ) { @SuppressWarnings("unchecked") CbGenericListItem<W> gli = (CbGenericListItem<W>) iter.next(); W w = gli.getDisplayWidget(); if (pItemId.equals(getIdFromWidget(w))) { result = w; break; } } return result; }
/** * Removes the entry with the given item ID. * * @param pItemId the unique item ID */ protected void removeDisplayWidget(final String pItemId) { int i = 0; for (Iterator<Widget> iter = iGuiList.iterator(); iter.hasNext(); i++) { @SuppressWarnings("unchecked") CbGenericListItem<W> gli = (CbGenericListItem<W>) iter.next(); if (pItemId.equals(getIdFromWidget(gli.getDisplayWidget()))) { iter.remove(); i--; } else { gli.setRowIdx(i); } } checkEmptyListHint(); }