Search in sources :

Example 36 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project adempiere by adempiere.

the class VCreateFromRMAUI method loadTableOIS.

/**
	 *  Load Order/Invoice/Shipment data into Table
	 *  @param data data
	 */
protected void loadTableOIS(Vector<?> data) {
    //  Remove previous listeners
    v_CreateFromPanel.getMiniTable().removeMiniTableSelectionListener(v_CreateFromPanel);
    //  Set Model
    DefaultTableModel model = new DefaultTableModel(data, getOISColumnNames());
    v_CreateFromPanel.getMiniTable().setModel(model);
    // 
    configureMiniTable(v_CreateFromPanel.getMiniTable());
    v_CreateFromPanel.getMiniTable().addMiniTableSelectionListener(v_CreateFromPanel);
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel)

Example 37 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project adempiere by adempiere.

the class VCreateFromShipmentUI method findProductRow.

/**
	 * Finds the row where a given product is. If the product is not found
	 * in the table -1 is returned.
	 * @param M_Product_ID
	 * @return  Row of the product or -1 if non existing.
	 * 
	 */
private int findProductRow(int M_Product_ID) {
    DefaultTableModel model = (DefaultTableModel) v_CreateFromPanel.getMiniTable().getModel();
    KeyNamePair kp;
    for (int i = 0; i < model.getRowCount(); i++) {
        kp = (KeyNamePair) model.getValueAt(i, 4);
        if (kp.getKey() == M_Product_ID) {
            return (i);
        }
    }
    return (-1);
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) KeyNamePair(org.compiere.util.KeyNamePair)

Example 38 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project adempiere by adempiere.

the class VBrowserTable method setRowCount.

//  setColumnClass
/**
     * Clear Table Content
     *
     * @param no number of rows
     */
public void setRowCount(int no) {
    if (getModel() instanceof DefaultTableModel) {
        DefaultTableModel model = (DefaultTableModel) getModel();
        model.setRowCount(no);
    //	log.config( "MiniTable.setRowCount", "rows=" + getRowCount() + ", cols=" + getColumnCount());
    } else
        throw new IllegalArgumentException("Model must be instance of DefaultTableModel");
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel)

Example 39 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project adempiere by adempiere.

the class VBrowserTable method addColumn.

//  prepareTable
/**
     * Add Table Column.
     * after adding a column, you need to set the column classes again
     * (DefaultTableModel fires TableStructureChanged, which calls
     * JTable.tableChanged .. createDefaultColumnsFromModel
     *
     * @param header header
     */
public void addColumn(String header) {
    if (getModel() instanceof DefaultTableModel) {
        DefaultTableModel model = (DefaultTableModel) getModel();
        model.addColumn(Util.cleanAmp(header));
    } else
        throw new IllegalArgumentException("Model must be instance of DefaultTableModel");
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel)

Example 40 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project adempiere by adempiere.

the class CTable method sort.

/**
	 *  Sort Table
	 *  @param modelColumnIndex model column sort index
	 */
@SuppressWarnings("unchecked")
protected void sort(final int modelColumnIndex) {
    int rows = getRowCount();
    if (rows == 0)
        return;
    sorting = true;
    //  other column
    if (modelColumnIndex != p_lastSortIndex)
        p_asc = true;
    else
        p_asc = !p_asc;
    p_lastSortIndex = modelColumnIndex;
    //
    log.config("#" + modelColumnIndex + " - rows=" + rows + ", asc=" + p_asc);
    //  Selection
    Object selected = null;
    int selRow = getSelectedRow();
    //	used to identify current row
    int selCol = p_keyColumnIndex == -1 ? 0 : p_keyColumnIndex;
    if (getSelectedRow() >= 0)
        selected = getValueAt(selRow, selCol);
    //  Prepare sorting
    DefaultTableModel model = (DefaultTableModel) getModel();
    final MSort sort = new MSort(0, null);
    sort.setSortAsc(p_asc);
    /* teo_sarca: commented: [ 1585369 ] CTable sorting is TOO LAZY *
		//  while something to sort
		sorting:
		while (true)
		{
			//  Create sortList
			ArrayList<MSort> sortList = new ArrayList<MSort>(rows);
			//	fill with data entity
			for (int i = 0; i < rows; i++)
			{
				Object value = model.getValueAt(i, modelColumnIndex);
				sortList.add(new MSort(i, value));
			}
			//	sort list it
			Collections.sort(sortList, sort);
			//  move out of sequence row
			for (int i = 0; i < rows; i++)
			{
				int index = ((MSort)sortList.get(i)).index;
				if (i != index)
				{
		//			log.config( "move " + i + " to " + index);
					model.moveRow(i,i, index);
					continue sorting;
				}
			}
			//  we are done
		//	log.config("done");
			break;
		}   //  while something to sort
		*/
    // teo_sarca: [ 1585369 ] CTable sorting is TOO LAZY
    Collections.sort(model.getDataVector(), new Comparator<Object>() {

        public int compare(Object o1, Object o2) {
            Object item1 = ((Vector) o1).get(modelColumnIndex);
            Object item2 = ((Vector) o2).get(modelColumnIndex);
            return sort.compare(item1, item2);
        }
    });
    //  selection
    clearSelection();
    if (selected != null) {
        for (int r = 0; r < rows; r++) {
            if (selected.equals(getValueAt(r, selCol))) {
                setRowSelectionInterval(r, r);
                // teo_sarca: bug fix [ 1585369 ] 
                scrollRectToVisible(getCellRect(r, modelColumnIndex, true));
                break;
            }
        }
    }
    //  selected != null
    sorting = false;
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) MSort(org.compiere.util.MSort)

Aggregations

DefaultTableModel (javax.swing.table.DefaultTableModel)139 JTable (javax.swing.JTable)18 Dimension (java.awt.Dimension)14 Vector (java.util.Vector)14 JScrollPane (javax.swing.JScrollPane)14 TableColumn (javax.swing.table.TableColumn)12 JBTable (com.intellij.ui.table.JBTable)10 Point (java.awt.Point)10 ActionEvent (java.awt.event.ActionEvent)9 JPanel (javax.swing.JPanel)9 ListSelectionEvent (javax.swing.event.ListSelectionEvent)9 ListSelectionListener (javax.swing.event.ListSelectionListener)9 JButton (javax.swing.JButton)8 ActionListener (java.awt.event.ActionListener)7 WebAppDetails (com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails)6 Color (java.awt.Color)6 ArrayList (java.util.ArrayList)6 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5