/** * Instantiates a new movie selection model. Usage in MoviePanel * * @param sortedList * the sorted list * @param source * the source * @param matcher * the matcher */ public MovieSelectionModel(SortedList<Movie> sortedList, EventList<Movie> source, MovieMatcherEditor matcher) { this.sortedList = sortedList; this.selectionModel = new DefaultEventSelectionModel<>(source); this.selectionModel.addListSelectionListener(this); this.matcherEditor = matcher; this.selectedMovies = selectionModel.getSelected(); propertyChangeListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getSource() == selectedMovie) { firePropertyChange(evt); } } }; }
/** * Change the selection to be the set union of the current selection and the indices between index0 and index1 inclusive */ @Override public void addSelectionInterval(int index0, int index1) { delegateSelectionModel.addSelectionInterval(index0, index1); }
/** * Set the EventSelectionModel as editable or not. This means that the user cannot * manipulate the selection by clicking. The selection can still be changed as * the source list changes. * * <p>Note that this will also disable the selection from being modified * <strong>programatically</strong>. Therefore you must use setEnabled(true) to * modify the selection in code. */ public void setEnabled(boolean enabled) { delegateSelectionModel.setEnabled(enabled); }
/** * Gets an {@link EventList} that contains only selected * values and modifies the source list on mutation. * * Adding and removing items from this list performs the same operation on * the source list. */ public EventList<E> getSelected() { return delegateSelectionModel.getSelected(); }
/** * Set the selection mode. */ public void setSelectionMode(int selectionMode) { delegateSelectionModel.setSelectionMode(selectionMode); }
/** * Creates a new selection model that also presents a list of the selection. * * The {@link AdvancedListSelectionModel} listens to this {@link EventList} in order * to adjust selection when the {@link EventList} is modified. For example, * when an element is added to the {@link EventList}, this may offset the * selection of the following elements. * * <p>The returned selection model is <strong>not thread-safe</strong>. Unless otherwise * noted, all methods are only safe to be called from the event dispatch thread. * To do this programmatically, use {@link SwingUtilities#invokeAndWait(Runnable)} and * wrap the source list (or some part of the source list's pipeline) using * GlazedListsSwing#swingThreadProxyList(EventList).</p> * * @param source the {@link EventList} whose selection will be managed. This should * be the same {@link EventList} passed to the constructor of your * {@link AdvancedTableModel} or {@link EventListModel}. */ public static <E> AdvancedListSelectionModel<E> eventSelectionModel(EventList<E> source) { return new DefaultEventSelectionModel<E>(source); }
public final void afterUpdateData() { if (eventSelectionModel != null && eventTableModel != null && selected != null) { eventSelectionModel.setValueIsAdjusting(true); for (int i = 0; i < eventTableModel.getRowCount(); i++) { Object object = eventTableModel.getElementAt(i); if (selected.contains(object)) { eventSelectionModel.addSelectionInterval(i, i); } } eventSelectionModel.setValueIsAdjusting(false); selected = null; } if (selectedColumns != null) { for (int index : selectedColumns) { jTable.getColumnModel().getSelectionModel().addSelectionInterval(index, index); } } if (jTable != null) { jTable.unlock(); } if (jTable instanceof JSeparatorTable) { JSeparatorTable jSeparatorTable = (JSeparatorTable) jTable; jSeparatorTable.loadExpandedState(); } }
/** * Add a listener to the list that's notified each time a change to * the selection occurs. * * Note that the change events fired by this class may include rows * that have been removed from the table. For this reason it is * advised not to <code>for()</code> through the changed range without * also verifying that each row is still in the table. */ public void addListSelectionListener(ListSelectionListener listener) { delegateSelectionModel.addListSelectionListener(listener); }
/** * This property is true if upcoming changes to the value of the model should be considered a single event. */ @Override public void setValueIsAdjusting(boolean valueIsAdjusting) { delegateSelectionModel.setValueIsAdjusting(valueIsAdjusting); }
/** * Add a matcher which decides when source elements are valid for selection. * * @param validSelectionMatcher returns <tt>true</tt> if a source element * can be selected; <tt>false</tt> otherwise */ public void addValidSelectionMatcher(Matcher<E> validSelectionMatcher) { delegateSelectionModel.addValidSelectionMatcher(validSelectionMatcher); }
/** * Change the selection to the empty set. */ public void clearSelection() { delegateSelectionModel.clearSelection(); }
/** * Releases the resources consumed by this {@link EventSelectionModel} so that it * may eventually be garbage collected. * * <p>An {@link EventSelectionModel} will be garbage collected without a call to * {@link #dispose()}, but not before its source {@link EventList} is garbage * collected. By calling {@link #dispose()}, you allow the {@link EventSelectionModel} * to be garbage collected before its source {@link EventList}. This is * necessary for situations where an {@link EventSelectionModel} is short-lived but * its source {@link EventList} is long-lived. * * <p><strong><font color="#FF0000">Warning:</font></strong> It is an error * to call any method on a {@link EventSelectionModel} after it has been disposed. */ public void dispose() { delegateSelectionModel.dispose(); swingThreadSource.dispose(); }
/** * Gets an {@link EventList} that contains only selected * values and modifies the source list on mutation. * * Adding and removing items from this list performs the same operation on * the source list. */ public EventList<E> getSelected() { return delegateSelectionModel.getSelected(); }
/** * Set the selection mode. */ @Override public void setSelectionMode(int selectionMode) { delegateSelectionModel.setSelectionMode(selectionMode); }
/** * Creates a new selection model that also presents a list of the selection. * * The {@link AdvancedListSelectionModel} listens to this {@link EventList} in order * to adjust selection when the {@link EventList} is modified. For example, * when an element is added to the {@link EventList}, this may offset the * selection of the following elements. * * <p>The returned selection model is <strong>not thread-safe</strong>. Unless otherwise * noted, all methods are only safe to be called from the event dispatch thread. * To do this programmatically, use {@link SwingUtilities#invokeAndWait(Runnable)} and * wrap the source list (or some part of the source list's pipeline) using * {@link GlazedListsSwing#swingThreadProxyList(EventList)}.</p> * * @param source the {@link EventList} whose selection will be managed. This should * be the same {@link EventList} passed to the constructor of your * {@link AdvancedTableModel} or {@link EventListModel}. */ public static <E> AdvancedListSelectionModel<E> eventSelectionModel(EventList<E> source) { return new DefaultEventSelectionModel<E>(source); }
/** * Add a listener to the list that's notified each time a change to * the selection occurs. * * Note that the change events fired by this class may include rows * that have been removed from the table. For this reason it is * advised not to <code>for()</code> through the changed range without * also verifying that each row is still in the table. */ @Override public void addListSelectionListener(ListSelectionListener listener) { delegateSelectionModel.addListSelectionListener(listener); }
/** * This property is true if upcoming changes to the value of the model should be considered a single event. */ public void setValueIsAdjusting(boolean valueIsAdjusting) { delegateSelectionModel.setValueIsAdjusting(valueIsAdjusting); }
/** * Add a matcher which decides when source elements are valid for selection. * * @param validSelectionMatcher returns <tt>true</tt> if a source element * can be selected; <tt>false</tt> otherwise */ public void addValidSelectionMatcher(Matcher<E> validSelectionMatcher) { delegateSelectionModel.addValidSelectionMatcher(validSelectionMatcher); }
/** * Change the selection to the empty set. */ public void clearSelection() { delegateSelectionModel.clearSelection(); }
/** * Releases the resources consumed by this {@link EventSelectionModel} so that it * may eventually be garbage collected. * * <p>An {@link EventSelectionModel} will be garbage collected without a call to * {@link #dispose()}, but not before its source {@link EventList} is garbage * collected. By calling {@link #dispose()}, you allow the {@link EventSelectionModel} * to be garbage collected before its source {@link EventList}. This is * necessary for situations where an {@link EventSelectionModel} is short-lived but * its source {@link EventList} is long-lived. * * <p><strong><font color="#FF0000">Warning:</font></strong> It is an error * to call any method on a {@link EventSelectionModel} after it has been disposed. */ public void dispose() { delegateSelectionModel.dispose(); swingThreadSource.dispose(); }