Example usage for javax.swing DefaultListModel remove

List of usage examples for javax.swing DefaultListModel remove

Introduction

In this page you can find the example usage for javax.swing DefaultListModel remove.

Prototype

public E remove(int index) 

Source Link

Document

Removes the element at the specified position in this list.

Usage

From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.ApplicationProperties.java

private void deleteFavourite() {
    final DefaultListModel model = (DefaultListModel) lstFavourites.getModel();
    model.remove(lstFavourites.getSelectedIndex());
    checkButtons();/*from  www  .  ja  v a2  s .  c om*/
}

From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.ApplicationProperties.java

private void deleteFileToIgnore() {
    final DefaultListModel model = (DefaultListModel) lstFilesToIgnore.getModel();
    model.remove(lstFilesToIgnore.getSelectedIndex());
    checkButtons();/*from  ww  w  .j  a  va 2 s .c  om*/
}

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java

public void deleteSipStatus() {
    if (theSipList == null) {
        return;//from   www  . j  a v a 2  s  . c  o  m
    }
    DefaultListModel model = (DefaultListModel) theSipList.getModel();
    int selectedIndex = theSipList.getSelectedIndex();
    SIPStatus status = (SIPStatus) model.get(selectedIndex);
    sipStatusCollection.deleteStatus(status);
    model.remove(selectedIndex);
    int newSize = model.size();
    if (newSize > 0) {
        if (selectedIndex >= (newSize - 1)) {
            selectedIndex = newSize - 1;
        }
        theSipList.setSelectedIndex(selectedIndex);
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java

public void deleteUser() {
    if (theUserList == null) {
        return;/*from   w  ww .  j  a  v  a 2  s  .  c  o m*/
    }
    DefaultListModel model = (DefaultListModel) theUserList.getModel();
    int selectedIndex = theUserList.getSelectedIndex();
    IndigoUser user = (IndigoUser) model.get(selectedIndex);
    userData.deleteUser(user);
    model.remove(selectedIndex);
    int newSize = model.size();
    if (newSize > 0) {
        if (selectedIndex >= (newSize - 1)) {
            selectedIndex = newSize - 1;
        }
        theUserList.setSelectedIndex(selectedIndex);
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java

public void deleteLookupItem() {
    MetaDataListValues value = (MetaDataListValues) theDataLookupList.getSelectedValue();
    if (configuratorFrame.confirm("Delete list item " + value.getDisplay() + "?")) {
        setDirty(true);/*from  www .ja  va  2s.c  om*/
        DefaultListModel model = (DefaultListModel) theDataLookupList.getModel();
        model.remove(theDataLookupList.getSelectedIndex());
        updateDataLookupValues();
    }
}

From source file:org.executequery.gui.editor.ManageShortcutsPanel.java

public void deleteShortcut() {

    int index = selectedIndex();

    if (index != -1) {

        try {/*www .j ava 2 s .  c om*/

            list.removeListSelectionListener(this);

            DefaultListModel model = modelFromList();
            model.remove(index);

            lastSelectedIndex = -1;

            int size = model.getSize();
            if (size > 0) {

                if (index > size - 1) {

                    list.setSelectedIndex(size - 1);

                } else {

                    list.setSelectedIndex(index);
                }

                shortcutSelected();

            } else {

                textPane.setText("");
            }

        } finally {

            list.addListSelectionListener(this);
        }

    }

}

From source file:org.n52.ifgicopter.spf.output.GpxOutputPlugin.java

/**
 * /*from   w  w w .  j  ava2 s .  co  m*/
 */
protected void updateGUI() {
    if (this.gpx == null)
        return;

    final String t = this.gpx.xmlText(GPX_OPTIONS);
    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            GpxOutputPlugin.this.textPane.setText(t);

            GpxOutputPlugin.this.outputFileLabel
                    .setText("<html><b>Output file: </b>" + getGpxFilePath() + "</html>");

            DefaultListModel model = (DefaultListModel) GpxOutputPlugin.this.valuesToSaveList.getModel();
            // update list
            if (model.getSize() < GpxOutputPlugin.this.availableDataKeys.size()) {
                if (model.contains(NO_DATA_LIST_ELEMENT))
                    model.remove(model.indexOf(NO_DATA_LIST_ELEMENT));

                for (String s : GpxOutputPlugin.this.availableDataKeys) {
                    if (!model.contains(s)) {
                        model.addElement(s);
                    }
                }
            }
        }
    });
}

From source file:org.nuclos.client.wizard.steps.NuclosEntitySQLLayoutStep.java

private void buttonDownAttributeAction() {
    int iSelected = listAttributeOrder.getSelectedIndex();
    if (iSelected < 0 || iSelected >= listAttributeOrder.getModel().getSize() - 1)
        return;/*w ww  .j  a v  a  2  s  .c o  m*/

    DefaultListModel model = (DefaultListModel) listAttributeOrder.getModel();
    Object obj = model.remove(iSelected);
    model.add(iSelected + 1, obj);
    listAttributeOrder.getSelectionModel().setSelectionInterval(iSelected + 1, iSelected + 1);
}

From source file:org.nuclos.client.wizard.steps.NuclosEntitySQLLayoutStep.java

private void buttonUpAttributeAction() {
    int iSelected = listAttributeOrder.getSelectedIndex();
    if (iSelected < 1 || iSelected > listAttributeOrder.getModel().getSize())
        return;/*  w w w .  j  a v  a  2  s.  c o m*/

    DefaultListModel model = (DefaultListModel) listAttributeOrder.getModel();
    Object obj = model.remove(iSelected);
    model.add(iSelected - 1, obj);

    listAttributeOrder.getSelectionModel().setSelectionInterval(iSelected - 1, iSelected - 1);
}

From source file:org.rimudb.editor.DescriptorEditor.java

/**
 * Build the panel/*www  .  j  a va2 s.c o  m*/
 */
private JPanel createColumnTablePanel() {
    JPanel columnPanel = new JPanel();
    columnPanel.setLayout(new BoxLayout(columnPanel, BoxLayout.Y_AXIS));

    // Create the property table panel
    propertyModel = new PropertyTableModel();

    // Add a listener to set the changed state
    propertyModel.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            markChanged();

            if (e instanceof PropertyTableModelEvent) {
                PropertyTableModelEvent ptme = (PropertyTableModelEvent) e;

                // If the columnName column was changed then check it isn't
                // a PK
                if (ptme.getColumn() == 1) {

                    String beforeColumnName = (String) ptme.getBeforeValue();
                    String afterColumnName = (String) ptme.getAfterValue();

                    // Is the field entry in the list of primary keys?
                    for (int i = 0; i < pkListModel.getSize(); i++) {
                        String pkColumnName = (String) pkListModel.get(i);
                        // If it's found then remove it
                        if (beforeColumnName.equals(pkColumnName)) {
                            pkListModel.set(i, afterColumnName);
                            break;
                        }
                    }

                }

            }
        }
    });

    table = new ATable(getPropertyModel());
    table.setName("ColumnTable");
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            int selectedRowCount = table.getSelectedRowCount();
            removeColumnBtn.setEnabled(selectedRowCount > 0);
            moveUpBtn.setEnabled(selectedRowCount > 0);
            moveDownBtn.setEnabled(selectedRowCount > 0);
        }
    });
    table.setTransferHandler(new TransferHandler() {

        public int getSourceActions(JComponent c) {
            return COPY;
        }

        protected Transferable createTransferable(JComponent c) {
            ATable columnTable = (ATable) c;
            int row = columnTable.getSelectedRow();
            String columnName = getPropertyModel().getRow(row).getColumnName();
            return new StringSelection(columnName);
        }
    });
    table.setDragEnabled(true);

    JScrollPane sp = new JScrollPane(table);
    sp.setMaximumSize(new Dimension(Short.MAX_VALUE, 325));
    sp.setPreferredSize(new Dimension(Short.MAX_VALUE, 325));
    sp.setMinimumSize(new Dimension(Short.MAX_VALUE, 325));

    JComboBox typeCB = new JComboBox(DatabaseTypes.getAllTypes());
    typeCB.setEditable(false);

    javax.swing.table.TableColumn typeColumn = table.getColumnModel().getColumn(2);
    typeColumn.setCellEditor(new DefaultCellEditor(typeCB));

    // Create the popup menu and set it on the table
    propertyPopup = new TablePopupMenu(this, table);
    table.addMouseListener(propertyPopup);
    sp.addMouseListener(propertyPopup);
    sp.setAlignmentX(LEFT_ALIGNMENT);

    columnPanel.add(sp);

    columnPanel.add(Box.createVerticalStrut(10));

    JLabel pkLabel = new JLabel("Primary Key Columns", SwingConstants.LEFT);
    pkLabel.setAlignmentX(LEFT_ALIGNMENT);
    columnPanel.add(pkLabel);

    pkListModel = new DefaultListModel();
    pkListModel.addListDataListener(new ListDataListener() {
        public void intervalRemoved(ListDataEvent e) {
            markChanged();
        }

        public void intervalAdded(ListDataEvent e) {
            markChanged();
        }

        public void contentsChanged(ListDataEvent e) {
            markChanged();
        }
    });

    pkList = new JList(pkListModel);
    pkList.setName("pkList");
    pkList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    pkList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            int selectedRowCount = pkList.getSelectedIndex();
            removePkBtn.setEnabled(selectedRowCount > -1);
        }
    });
    pkList.setTransferHandler(new TransferHandler() {

        public boolean canImport(TransferHandler.TransferSupport info) {
            // we only import Strings
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            if (dl.getIndex() == -1) {
                return false;
            }
            return true;
        }

        public boolean importData(TransferHandler.TransferSupport info) {
            if (!info.isDrop()) {
                return false;
            }

            // Check for String flavor
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                displayDropLocation("List doesn't accept a drop of this type.");
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            DefaultListModel listModel = (DefaultListModel) pkList.getModel();
            int index = dl.getIndex();

            // Get the string that is being dropped.
            Transferable t = info.getTransferable();
            String data;
            try {
                data = (String) t.getTransferData(DataFlavor.stringFlavor);
            } catch (Exception e) {
                return false;
            }

            // If this is a copy action then check we don't already have that String
            if (info.getDropAction() == COPY && listModel.indexOf(data) > -1) {
                displayDropLocation("The column " + data + " is already a primary key");
                return false;
            }

            // Perform the actual import. 
            if (dl.isInsert()) {
                int oldIndex = listModel.indexOf(data);
                if (oldIndex < index) {
                    listModel.add(index, data);
                    listModel.remove(oldIndex);
                } else {
                    listModel.remove(oldIndex);
                    listModel.add(index, data);
                }
            } else {
                // Don't handle replacements
            }
            return true;
        }

        public int getSourceActions(JComponent c) {
            return MOVE;
        }

        protected Transferable createTransferable(JComponent c) {
            JList list = (JList) c;
            Object[] values = list.getSelectedValues();

            StringBuffer buff = new StringBuffer();

            for (int i = 0; i < values.length; i++) {
                Object val = values[i];
                buff.append(val == null ? "" : val.toString());
                if (i != values.length - 1) {
                    buff.append("\n");
                }
            }
            return new StringSelection(buff.toString());
        }
    });
    pkList.setDropMode(DropMode.INSERT);
    pkList.setDragEnabled(true);

    JScrollPane pkScrollPanel = new JScrollPane(pkList);
    pkScrollPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, 100));
    pkScrollPanel.setAlignmentX(LEFT_ALIGNMENT);

    columnPanel.add(pkScrollPanel);

    return columnPanel;
}