@Override public boolean validate(ListChangeEvent event) { boolean b = true; switch (event.getAction()) { case add: case append: case addAndSelect: Object e = event.getElement(); if (e == null || contains(e)) { b = false; } break; case addAll: case appendAll: Collection c = event.getCollection(); if (containsAny(c) || containsNull(c)) { b = false; } case set: e = event.getElement(); // new element in set method // Document old = (Document)event.getResult(); if (e == null || contains(e)) { b = false; } break; } return b; }
/** * Creates a new object of type <code>ListChangeEvent</code>. Sets the event properties values: * * <ul> * <li>action to {@link ListChangeEvent.Action#addSelect} * <li>element to the value of the parameter <code>e</code> * <li>result to the same value as <code>e</code> or null if element cannot be added. * </ul> * * @param e the element to be added * @param result <code>true</code> if the element added otherwise <code>false</code> * @return a new instance of {@link ListChangeEvent } */ protected ListChangeEvent createAddAndSelect(E e, boolean result) { ListChangeEvent event = new ListChangeEvent(this, ListChangeEvent.Action.addAndSelect); event.setElement(e); event.setResult(result); if (result) { event.setIndex(this.size() - 1); } else { event.setIndex(-1); } return event; }