/** * * @return */ @Override public IVItem[] getItems() { IVItem[] _items = items; if (_items == null) { IVItem[] _rawItems = rawItems(NullOut.cNull, backcall); rawItems = _rawItems; releaseItems(); _items = items = filterItems(NullOut.cNull, _rawItems); } if ((_items == null || _items.length == 0) && !(filter.toString().equals(""))) { Viewer titleViewer = new Viewer(new ViewString(" filter= ")); titleViewer.setBorder(new SolidBorder(ViewColor.cThemeAccent)); Viewer filterViewer = new Viewer(new ViewString(filter)); filterViewer.setBorder(new SolidBorder(ViewColor.cThemeAccent)); titleViewer.place(filterViewer, UV.cEW); Viewer v = new Viewer(titleViewer); VItem item = new VItem(v); item.setBorder(new ViewBorder()); item.paint(); return new IVItem[]{item}; } return _items; }
/** * * @param e */ @Override public void keyPressed(KeyPressed e) { if (e.isControlDown()) { int code = e.getKeyCode(); switch (code) { case IKeyEventConstants.cA: selectAllItems(); break; } return; } if (filter.modify(e)) { filterModified(null); } }
/** * * @param _ * @param _rawItems * @return */ protected IVItem[] filterItems(IOut _, IVItem[] _rawItems) { if (_rawItems == null) { return new IVItem[0]; } if (comparator != null) { Arrays.sort(_rawItems, comparator); } int count = 0; int len = _rawItems.length; IVItem[] filteredItems = new IVItem[len]; Pattern pattern = null; String regx = ""; if (filter != null) { regx = filter.toString(); } if (regx.length() > 0) { try { pattern = Pattern.compile(regx); } catch (Exception x) { if (_ != null) { _.out(x); } } } for (int i = 0; i < len; i++) { if (_ != null) { _.out(i, len); } IVItem next = _rawItems[i]; IVItem filtered = filter(next, pattern); if (filtered == null) { continue; } filteredItems[count++] = filtered; } if (count < len) { filteredItems = (IVItem[]) UArray.trim(filteredItems, new IVItem[count]); } else if (count == 0) { filteredItems = new IVItem[0]; } return filteredItems; }
@Override public String toString() { return (filter == null) ? "" : filter.toString(); }
/** * * @return */ @Override public String getFilter() { return filter.toString(); }
/** * * @param _filter */ @Override public void setFilter(String _filter) { filter.setText((_filter == null) ? "" : _filter); filterModified(null);//?? }