Example usage for javax.swing ListSelectionModel clearSelection

List of usage examples for javax.swing ListSelectionModel clearSelection

Introduction

In this page you can find the example usage for javax.swing ListSelectionModel clearSelection.

Prototype

void clearSelection();

Source Link

Document

Change the selection to the empty set.

Usage

From source file:com.funambol.email.admin.user.ResultSearchUserPanel.java

/**
 * Resets the search result table (that is: no record has to be selected).
 *///from  w  w  w.  ja va  2 s  .  co  m
public void resetResultTableSelection() {

    ListSelectionModel lsm = table.getSelectionModel();
    lsm.clearSelection();
}

From source file:com.funambol.email.admin.user.ResultSearchUserPanel.java

/**
 * Set up graphic elements for this panel.
 *
 * @throws Exception if error occures during creation of the panel
 *//*  ww  w. j ava2s  .  c  o  m*/
private void init() throws Exception {

    // create objects to display
    this.setLayout(new BorderLayout());
    this.setBorder(BorderFactory.createEmptyBorder());

    // create a model for the user table and pass it to the JTable object
    model = new UserTableModel();
    table = new JTable(model);

    table.setShowGrid(true);
    table.setAutoscrolls(true);
    table.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
    JScrollPane scrollpane = new JScrollPane(table);
    table.setPreferredScrollableViewportSize(new Dimension(800, 200));
    table.setFont(GuiFactory.defaultTableFont);
    table.getTableHeader().setFont(GuiFactory.defaultTableHeaderFont);
    this.add(scrollpane, BorderLayout.CENTER);

    //
    // Select user.
    //
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    ListSelectionModel rowSM = table.getSelectionModel();

    rowSM.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {

            if (event.getValueIsAdjusting()) {
                return;
            }

            ListSelectionModel lsm = (ListSelectionModel) event.getSource();

            if (lsm.isSelectionEmpty()) {

                selectedUser = null;
            } else {

                int selectedRow = lsm.getMinSelectionIndex();
                selectedUser = users[selectedRow];
            }
        }
    });

    rowSM.clearSelection();

    table.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent event) {

            if (event.getClickCount() < 2) {
                return;
            }

            //
            // If the selected user is already associated to an account
            // then insertion process can't go on.
            //

            String userName = selectedUser.getUsername();
            String value[] = new String[] { userName };
            WhereClause wc = new WhereClause("username", value, WhereClause.OPT_EQ, true);
            MailServerAccount[] tmp = null;
            try {
                tmp = WSDao.getAccounts(wc);
            } catch (Exception e) {
            }

            if (tmp.length > 0) {

                StringBuilder sb = new StringBuilder("The user ");
                sb.append(userName).append(" is already associated to an account");
                Object[] options = { "OK" };
                JOptionPane.showOptionDialog(null, sb.toString(), "Warning", JOptionPane.OK_CANCEL_OPTION,
                        JOptionPane.WARNING_MESSAGE, null, options, options[0]);

            } else {
                //
                // Go to next step.
                //
                step.goToNextStep();
            }
        }
    });

}

From source file:com.diversityarrays.kdxplore.trials.TrialOverviewPanel.java

private void selectTrial(Trial trial) {
    ListSelectionModel lsm = trialsTable.getSelectionModel();
    lsm.setValueIsAdjusting(true);//  ww w .ja  va2s. c o  m
    try {
        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);/* w  w w  .  ja v  a2  s . co m*/
        lsm.clearSelection();
        try {
            for (Integer index : traitIndices) {
                lsm.addSelectionInterval(index, index);
            }
        } finally {
            lsm.setValueIsAdjusting(false);
        }
    }
}

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();
    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;/*from   w w w.  j  a  v  a  2  s  .  c o  m*/
            }
        }
        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();
    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;/*from  ww w .  j av a  2 s.  co  m*/
            }
        }
        if (index != -1) {
            selectionModel.addSelectionInterval(index, index);
        }
    }
    selectionModel.setValueIsAdjusting(false);
}

From source file:org.wings.SList.java

/**
 * Select some cells./*from  ww  w  .  jav  a 2  s.c o m*/
 *
 * @param indices The indices of the cells to select
 * @see ListSelectionModel#addSelectionInterval
 * @see #isSelectedIndex
 * @see #addListSelectionListener
 */
public void setSelectedIndices(int[] indices) {
    ListSelectionModel sm = getSelectionModel();
    int[] oldVal = this.getSelectedIndices();
    sm.clearSelection();
    for (int i = 0; i < indices.length; i++) {
        sm.addSelectionInterval(indices[i], indices[i]);
    }
    propertyChangeSupport.firePropertyChange("selectedIndices", oldVal, this.getSelectedIndices());
}