List of usage examples for javax.swing ListSelectionModel setValueIsAdjusting
void setValueIsAdjusting(boolean valueIsAdjusting);
From source file:com.diversityarrays.kdxplore.trials.TrialOverviewPanel.java
private void selectTrial(Trial trial) { ListSelectionModel lsm = trialsTable.getSelectionModel(); lsm.setValueIsAdjusting(true); try {//from ww w. ja v a2 s . co m lsm.clearSelection(); int mrow = trialTableModel.indexOfTrial(trial); if (mrow >= 0) { int vrow = trialsTable.convertRowIndexToView(mrow); if (vrow >= 0) { lsm.addSelectionInterval(vrow, vrow); } } } finally { lsm.setValueIsAdjusting(false); } }
From source file:com.diversityarrays.kdxplore.trialmgr.trait.TraitExplorerPanel.java
@Override public void setSelectedTraits(List<Trait> traits) { List<Integer> traitIndices = traits.stream().map(traitTableModel::indexOf).filter(index -> index != null) // null if not found in model .map(modelIndex -> traitsTable.convertRowIndexToView(modelIndex)).filter(index -> index >= 0) // -1 if not visible .collect(Collectors.toList()); if (!traitIndices.isEmpty()) { Collections.sort(traitIndices); ListSelectionModel lsm = traitsTable.getSelectionModel(); lsm.setValueIsAdjusting(true); lsm.clearSelection();/*from w ww.j a v a2 s. com*/ try { for (Integer index : traitIndices) { lsm.addSelectionInterval(index, index); } } finally { lsm.setValueIsAdjusting(false); } } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java
protected void applySelectionIndexes(List<Integer> indexes) { Collections.sort(indexes);//from w ww .j ava 2 s . com ListSelectionModel model = impl.getSelectionModel(); model.setValueIsAdjusting(true); int lastOpened = indexes.get(0); int current = indexes.get(0); for (Integer index : indexes) { if (index > current + 1) { model.addSelectionInterval(lastOpened, current); lastOpened = index; } current = index; } model.addSelectionInterval(lastOpened, current); model.setValueIsAdjusting(false); }
From source file:com.diversityarrays.kdxplore.curate.TrialDataEditor.java
private void reapplySelection(List<PlotOrSpecimen> selectedPlotSpecimens, Set<TraitInstance> selectedTraitInstances) { boolean anySubPlot = false; List<Integer> selectedModelColumns = new ArrayList<>(); for (TraitInstance ti : selectedTraitInstances) { if (TraitLevel.PLOT != ti.trait.getTraitLevel()) { anySubPlot = true;/*ww w . j a v a 2s . c o m*/ } Integer columnIndex = curationTableModel.getColumnIndexForTraitInstance(ti); if (columnIndex != null) { selectedModelColumns.add(columnIndex); } } boolean nonTraitColumns = false; if (selectedModelColumns.isEmpty()) { nonTraitColumns = true; selectedModelColumns.addAll(curationTableModel.getNonTraitInstanceColumns()); } ListSelectionModel lsm = curationTable.getSelectionModel(); try { curationTable.clearSelection(); lsm.setValueIsAdjusting(true); // lsm.clearSelection(); above line already does this // For the curation table ... int countRowsFound = 0; if (anySubPlot) { // get all of the rows? Set<Integer> plotIds = selectedPlotSpecimens.stream().map(PlotOrSpecimen::getPlotId) .collect(Collectors.toSet()); for (Integer plotId : plotIds) { Integer[] modelRows = curationTableModel.getRowsForPlotId(plotId, TraitLevel.PLOT); for (Integer modelRow : modelRows) { int viewRow = curationTable.convertRowIndexToView(modelRow); if (viewRow >= 0) { lsm.addSelectionInterval(viewRow, viewRow); } } } } else { for (PlotOrSpecimen pos : selectedPlotSpecimens) { Optional<Integer> opt = curationTableModel.getRowForPlotOrSpecimen(pos); if (opt.isPresent()) { Integer modelRow = opt.get(); int viewRow = curationTable.convertRowIndexToView(modelRow); if (viewRow >= 0) { ++countRowsFound; lsm.addSelectionInterval(viewRow, viewRow); } } } } // Set<Integer> plotIds = selectedPlotSpecimens.stream().map(PlotOrSpecimen::getPlotId) // .collect(Collectors.toSet()); // for (Integer plotId : plotIds) { // Integer[] modelRows = curationTableModel.getRowsForPlotId(plotId); // for (Integer modelRow : modelRows) { // int viewRow = curationTable.convertRowIndexToView(modelRow); // if (viewRow >= 0) { // lsm.addSelectionInterval(viewRow, viewRow); // } // } // } StringBuilder msg = new StringBuilder(); if (!selectedModelColumns.isEmpty()) { List<Integer> sorted = new ArrayList<>(selectedModelColumns); Collections.sort(sorted); for (Integer mcol : sorted) { int vcol = curationTable.convertColumnIndexToView(mcol); if (vcol >= 0) { curationTable.addColumnSelectionInterval(vcol, vcol); } } if (!nonTraitColumns) { if (countRowsFound <= 0) { msg.append("\tSamples Table: selected ").append(selectedModelColumns.size()) .append(" Traits"); } else { msg.append("\tSamples Table: selected ").append(countRowsFound).append(" for ") .append(selectedModelColumns.size()).append(" Traits"); } // msg.append("\tSamples Table: selected ").append(selectedModelColumns.size()) // .append(" Traits"); // if (!plotIds.isEmpty()) { // msg.append(" in ").append(plotIds.size()).append(" Plots"); // } } else if (countRowsFound > 0) { msg.append("\tSamples Table: selected ").append(countRowsFound); } // else if (!plotIds.isEmpty()) { // msg.append("\tSamples Table: selected ").append(plotIds.size()) // .append(" Plots"); // } } // if (!plotIds.isEmpty()) { // if (msg.length() > 0) // msg.append('\n'); // msg.append("\tField View: selected ").append(plotIds.size()).append(" Plots"); // } if (msg.length() > 0) { messages.println(msg); } Set<Plot> plots = selectedPlotSpecimens.stream() .map(pos -> curationData.getPlotByPlotId(pos.getPlotId())).collect(Collectors.toSet()); fieldLayoutView.setSelectedPlots(new ArrayList<>(plots)); } finally { lsm.setValueIsAdjusting(false); curationTable.repaint(); } }
From source file:org.orbisgis.core.ui.plugins.views.geocatalog.Catalog.java
public void setActiveFiltersId(String[] filterIds) { ListSelectionModel selectionModel = lstFilters.getSelectionModel(); ListModel filterModel = lstFilters.getModel(); selectionModel.clearSelection();// w w w. j a v a 2 s.co m selectionModel.setValueIsAdjusting(true); for (String filterId : filterIds) { GeocatalogFilterDecorator filter = new GeocatalogFilterDecorator(filterId, null, null); int index = -1; for (int i = 0; i < filterModel.getSize(); i++) { if (filterModel.getElementAt(i).equals(filter)) { index = i; } } if (index != -1) { selectionModel.addSelectionInterval(index, index); } } selectionModel.setValueIsAdjusting(false); }
From source file:org.orbisgis.core.ui.plugins.views.geocatalog.Catalog.java
public void setActiveLabels(String[] labels) { ListSelectionModel selectionModel = lstTags.getSelectionModel(); selectionModel.clearSelection();//w w w.ja va2 s .co m for (String label : labels) { selectionModel.setValueIsAdjusting(true); int index = -1; for (int i = 0; i < tagListModel.getSize(); i++) { if (tagListModel.getElementAt(i).equals(label)) { index = i; } } if (index != -1) { selectionModel.addSelectionInterval(index, index); } } selectionModel.setValueIsAdjusting(false); }
From source file:org.springframework.richclient.form.binding.jide.CheckBoxListSelectableBinding.java
/** * Updates the selection model with the selected values from the value * model.//w ww .ja v a2 s .co m */ protected void updateSelectedItemsFromValueModel() { Object value = getValue(); Object[] selectedValues = EMPTY_VALUES; if (value != null) { selectedValues = (Object[]) convertValue(value, Object[].class); } // flag is used to avoid a round trip while we are selecting the values selectingValues = true; try { ListSelectionModel selectionModel = getList().getSelectionModel(); selectionModel.setValueIsAdjusting(true); try { int[] valueIndexes = determineValueIndexes(selectedValues); int selectionMode = getSelectionMode(); if (selectionMode == ListSelectionModel.SINGLE_SELECTION && valueIndexes.length > 1) { getList().setSelectedIndex(valueIndexes[0]); } else { getList().setSelectedIndices(valueIndexes); } // update value model if selectedValues contain elements which // where not found in the list model // elements if (valueIndexes.length != selectedValues.length && !isReadOnly() && isEnabled() || (selectionMode == ListSelectionModel.SINGLE_SELECTION && valueIndexes.length > 1)) { updateSelectedItemsFromSelectionModel(); } } finally { selectionModel.setValueIsAdjusting(false); } } finally { selectingValues = false; } }