Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 package org.apache.cayenne.modeler.util;
 
 
Common superclass of tables used in Cayenne. Contains some common configuration settings and utility methods.
 
 public class CayenneTable extends JTable {
 
     public CayenneTable() {
         super();
         this.setRowHeight(25);
         this.setRowMargin(3);
         
     }
 
     @Override
     protected void createDefaultEditors() {
         super.createDefaultEditors();
 
         JTextField textField = CayenneWidgetFactory.createTextField(0);
         final DefaultCellEditor textEditor = CayenneWidgetFactory.createCellEditor(textField);
         textEditor.setClickCountToStart(1);
 
         setDefaultEditor(Object.classtextEditor);
         setDefaultEditor(String.classtextEditor);
     }
 
     public CayenneTableModel getCayenneModel() {
         return (CayenneTableModelgetModel();
     }

    
Cancels editing of any cells that maybe currently edited. This method should be called before updating any selections.
 
     public void cancelEditing() {
         editingCanceled(new ChangeEvent(this));
     }
 
     public void select(Object row) {
         if (row == null) {
             return;
         }
 
         CayenneTableModel model = getCayenneModel();
         int ind = model.getObjectList().indexOf(row);
 
         if (ind >= 0) {
             getSelectionModel().setSelectionInterval(indind);
         }
     }
 
     public void select(int index) {
 
         CayenneTableModel model = getCayenneModel();
         if (index >= model.getObjectList().size()) {
             index = model.getObjectList().size() - 1;
         }
 
         if (index >= 0) {
             getSelectionModel().setSelectionInterval(indexindex);
         }
     }
    
    
Selects multiple rows at once. Fires not more than only one ListSelectionEvent
    public void select(int[] rows) {
    }
        int row = getSelectedRow();
        int column = getSelectedColumn();
        if (row < 0 || column < 0) {
            return null;
        }
        TableCellEditor editor = this.getCellEditor(rowcolumn);
        if (editor instanceof DefaultCellEditor) {
            Component comp = ((DefaultCellEditoreditor).getComponent();
            if (comp instanceof JTextComponent) {
                return (JTextComponentcomp;
            }
        }
        return null;
    }
    @Override
    public void tableChanged(TableModelEvent e) {
        cancelEditing();
        super.tableChanged(e);
    }
    
    
ListSelectionModel for Cayenne table. Has a method to set multiple rows selection at once.
        boolean fireForbidden = false;
        
        
Selects selection on multiple rows at once. Fires no more than one ListSelectionEvent
        public void setSelection(int[] rows) {
            
First check if we must do anything at all
            boolean selectionChanged = false;
            for (int row : rows) {
                if (!isRowSelected(row)) {
                    selectionChanged = true;
                    break;
                }
            }
            
            if (!selectionChanged) {
                for (int i = getMinSelectionIndex(); i < getMaxSelectionIndex(); i++) {
                    if (isSelectedIndex(i)) {
                        boolean inNewSelection = false;
                        for (int row : rows) {
                            if (row == i) {
                                inNewSelection = true;
                                break;
                            }
                        }
                        
                        if(!inNewSelection) {
                            selectionChanged = true;
                            break;
                        }
                    }
                }
            }
            
            if (!selectionChanged) {
                return;
            }
            
             = true;
            
            clearSelection();
            for (int row : rows) {
                if (row >= 0 && row < getRowCount()) {
                    addRowSelectionInterval(rowrow);
                }
            }
            
             = false;
            
            fireValueChanged(getValueIsAdjusting());
        }
        
        @Override
        protected void fireValueChanged(int firstIndexint lastIndexboolean isAdjusting) {
            if (!) {
                super.fireValueChanged(firstIndexlastIndexisAdjusting);
            }
        }
    }
New to GrepCode? Check out our FAQ X