Java Code Examples for javax.swing.RowFilter

The following examples show how to use javax.swing.RowFilter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: megamek   Source File: RATGeneratorEditor.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void filterFactionList() {
    RowFilter<FactionListTableModel, Integer> rf;
    rf = new RowFilter<FactionListTableModel, Integer>() {
        @Override
        public boolean include(Entry<? extends FactionListTableModel,
                ? extends Integer> entry) {
            FactionListTableModel model = entry.getModel();
            FactionRecord rec = model.getFactionRecord(entry.getIdentifier());
            if (!chkShowSubfactions.isSelected() &&
                    rec.getKey().contains(".")) {
                return false;
            }

            return chkShowMinorFactions.isSelected() ||
                    rec.getParentFactions() == null;
        }
    };
    masterFactionListSorter.setRowFilter(rf);
}
 
Example 2
Source Project: beautyeye   Source File: DefaultsDisplay.java    License: Apache License 2.0 6 votes vote down vote up
protected void initFilters(JTable table) {
    TableRowSorter sorter = new TableRowSorter(table.getModel());
    table.setRowSorter(sorter);
    
    if (visualsFilter == null) {
        visualsFilter = new RowFilter<UIDefaultsTableModel,Integer>() {
            public boolean include(Entry<? extends UIDefaultsTableModel, ? extends Integer> entry) {
                UIDefaultsTableModel model = entry.getModel();
                Object defaultsValue = model.getValueAt(entry.getIdentifier().intValue(),
                        UIDefaultsTableModel.VALUE_COLUMN);

                return defaultsValue instanceof Color ||
                        defaultsValue instanceof Font ||
                        defaultsValue instanceof Icon;
            }
        };
    }
    
    if (onlyVisualsCheckBox.isSelected()) {
        sorter.setRowFilter(visualsFilter);
    }
}
 
Example 3
Source Project: mzmine3   Source File: PeakListTableWindow.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void updateFilter() {

  List<RowFilter<Object, Object>> rowSorters = new ArrayList<RowFilter<Object, Object>>();

  TableRowSorter<PeakListTableModel> sorter =
      (TableRowSorter<PeakListTableModel>) table.getRowSorter();

  String textId = "(?i)" + filterTextId.getText();
  String textIdentity = "(?i)" + filterTextIdentity.getText();
  String textComment = "(?i)" + filterTextComment.getText();

  rowSorters.add(RowFilter.regexFilter(textId, 0));
  rowSorters.add(mzFilter);
  rowSorters.add(rtFilter);
  rowSorters.add(RowFilter.regexFilter(textIdentity, 3));
  rowSorters.add(RowFilter.regexFilter(textComment, 4));

  sorter.setRowFilter(RowFilter.andFilter(rowSorters));
  table.setRowSorter(sorter);

}
 
Example 4
Source Project: Qora   Source File: Gui.java    License: MIT License 6 votes vote down vote up
public static <T extends TableModel> JTable createSortableTable(T tableModel, int defaultSort, RowFilter<T, Object> rowFilter)
{
	//CREATE TABLE
	JTable table = new JTable(tableModel);
	
	//CREATE SORTER
	TableRowSorter<T> rowSorter = new TableRowSorter<T>(tableModel);
	//rowSorter.setSortsOnUpdates(true);
	rowSorter.setRowFilter(rowFilter);
	
	//DEFAULT SORT DESCENDING
	rowSorter.toggleSortOrder(defaultSort);	
	rowSorter.toggleSortOrder(defaultSort);	
	
	//ADD TO TABLE
	table.setRowSorter(rowSorter);
	
	//RETURN
	return table;
}
 
Example 5
Source Project: iBioSim   Source File: SBOLInputDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void updateFilter(String filterText) 
{
	filterText = "(?i)" + filterText;
	@SuppressWarnings({ "rawtypes", "unchecked" })
	TableRowSorter<TopLevelTableModel> sorter = (TableRowSorter) table.getRowSorter();
	if (filterText.length() == 0) {
		sorter.setRowFilter(null);
	} else {
		try {
			RowFilter<TopLevelTableModel, Object> rf = RowFilter.regexFilter(filterText, 0, 1);
			sorter.setRowFilter(rf);
		} catch (java.util.regex.PatternSyntaxException e) {
			sorter.setRowFilter(null);
		}
	}

	tableLabel.setText("Matching parts (" + sorter.getViewRowCount() + ")");
}
 
Example 6
Source Project: mzmine2   Source File: PeakListTableWindow.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void updateFilter() {

  List<RowFilter<Object, Object>> rowSorters = new ArrayList<RowFilter<Object, Object>>();


  TableRowSorter<PeakListTableModel> sorter =
      (TableRowSorter<PeakListTableModel>) table.getRowSorter();

  String textId = "(?i)" + filterTextId.getText();
  String textIdentity = "(?i)" + filterTextIdentity.getText();
  String textComment = "(?i)" + filterTextComment.getText();

  rowSorters.add(RowFilter.regexFilter(textId, 0));
  rowSorters.add(mzFilter);
  rowSorters.add(rtFilter);
  rowSorters.add(RowFilter.regexFilter(textIdentity, 3));
  rowSorters.add(RowFilter.regexFilter(textComment, 4));

  sorter.setRowFilter(RowFilter.andFilter(rowSorters));
  table.setRowSorter(sorter);

}
 
Example 7
Source Project: megamek   Source File: RATGeneratorEditor.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void filterMasterUnitList() {
    RowFilter<MasterUnitListTableModel, Integer> rf;
    rf = new RowFilter<MasterUnitListTableModel, Integer>() {
        @Override
        public boolean include(Entry<? extends MasterUnitListTableModel,
                ? extends Integer> entry) {
            MasterUnitListTableModel model = entry.getModel();
            ModelRecord rec = model.getUnitRecord(entry.getIdentifier());
            if (cbUnitType.getSelectedIndex() > 0 &&
                    !UnitType.getTypeName(rec.getUnitType()).equals(cbUnitType.getSelectedItem())) {
                return false;
            }
            if (cbMovementType.getSelectedIndex() > 0 &&
                    (rec.getMovementMode() != EntityMovementMode.getMode((String) cbMovementType.getSelectedItem()))) {
                return false;
            }
            if (txtSearch.getText().length() > 0) {
                return rec.getKey().toLowerCase().contains(txtSearch.getText().toLowerCase());
            }
            return true;
        }
    };
    masterUnitListSorter.setRowFilter(rf);
}
 
Example 8
Source Project: gameserver   Source File: MongoRowFilterAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
	public void actionPerformed(ActionEvent e) {
		SwingUtilities.invokeLater(new Runnable(){
			public void run() {
				DefaultRowSorter rowSorter = (DefaultRowSorter)parent.getTable().getRowSorter();
				String regex = parent.getFilterText();
				if ( regex == null || regex.length() == 0 ) {
//					JOptionPane.showMessageDialog(parent, "请输入需要过滤的正则表达式", 
//							"数据过滤", JOptionPane.INFORMATION_MESSAGE);
					rowSorter.setRowFilter(null);
				} else {
					rowSorter.setRowFilter(RowFilter.regexFilter(regex));
//					parent.getTable().setRowFilter(RowFilter.regexFilter(regex));
				}
			}
		});
	}
 
Example 9
Source Project: PacketProxy   Source File: FilterTextParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected boolean include(javax.swing.RowFilter.Entry<? extends Object, ? extends Object> value, int index) {
	if (!ValidPattern(this.searchWord)) { return false; }
	Object v = value.getValue(index);
	if (v instanceof Long) {
		return groupIds.contains(v);
	}
	return false;
}
 
Example 10
Source Project: netbeans   Source File: AllocTreeTableView.java    License: Apache License 2.0 5 votes vote down vote up
protected RowFilter getExcludesFilter() {
    return new RowFilter() { // Do not filter first level nodes
        public boolean include(RowFilter.Entry entry) {
            PresoObjAllocCCTNode node = (PresoObjAllocCCTNode)entry.getIdentifier();
            CCTNode parent = node.getParent();
            if (parent == null) return true;
            if (parent.getParent() == null) return !filterObjects;
            return !filterAllocations;
        }
    };
}
 
Example 11
Source Project: netbeans   Source File: LivenessTreeTableView.java    License: Apache License 2.0 5 votes vote down vote up
protected RowFilter getExcludesFilter() {
    return new RowFilter() { // Do not filter first level nodes
        public boolean include(RowFilter.Entry entry) {
            PresoObjAllocCCTNode node = (PresoObjAllocCCTNode)entry.getIdentifier();
            CCTNode parent = node.getParent();
            if (parent == null) return true;
            if (parent.getParent() == null) return !filterObjects;
            return !filterAllocations;
        }
    };
}
 
Example 12
Source Project: netbeans   Source File: JDBCTreeTableView.java    License: Apache License 2.0 5 votes vote down vote up
protected RowFilter getExcludesFilter() {
    return new RowFilter() { // Do not filter SQL commands
        public boolean include(RowFilter.Entry entry) {
            PresoObjAllocCCTNode node = (PresoObjAllocCCTNode)entry.getIdentifier();
            return isSQL(node);
        }
    };
}
 
Example 13
Source Project: netbeans   Source File: ProfilerRowSorter.java    License: Apache License 2.0 5 votes vote down vote up
private void refreshRowFilter() {
    if (filters == null || filters.isEmpty()) {
        setRowFilter(null);
    } else if (filters.size() == 1) {
        setRowFilter(filters.iterator().next());
    } else {
        setRowFilter(filterMode ? RowFilter.andFilter(filters) :
                                  RowFilter.orFilter(filters));
    }
}
 
Example 14
Source Project: netbeans   Source File: ProfilerTreeTable.java    License: Apache License 2.0 5 votes vote down vote up
private SortedFilteredTreeModel treeModelImpl(TreeNode root, Comparator comparator, RowFilter filter) {
    return new SortedFilteredTreeModel(root, tree == null ? null : tree.getCellRenderer(), comparator, filter) {
        protected void fireTreeStructureChanged(Object source, Object[] path,
                                int[] childIndices,
                                Object[] children) {
            UIState uiState = tree == null ? null : getUIState(tree);
            super.fireTreeStructureChanged(source, path, childIndices, children);
            if (uiState != null) restoreExpandedNodes(tree, uiState);
            fireTableDataChanged(); // Clears selection
            if (uiState != null) restoreSelectedNodes(tree, uiState);
        }
    };
}
 
Example 15
private void filter() {
    List<RowFilter<UnitTableModel,Integer>> filters = new ArrayList<>();
    for (int i = 0; i < allConstraints.size(); i++) {
        if (otherCriteriaChecks.get(i).isSelected()) {
            filters.add(new UnitTableRowFilter(allConstraints.get(i)));
        }            
    }
    if (otherCriteriaChecks.size() > allConstraints.size()
            && otherCriteriaChecks.get(otherCriteriaChecks.size() - 1).isSelected()) {
        filters.add(new UnitTableRowFilter(formationType.getGroupingCriteria()));
    }
    tableSorter.setRowFilter(RowFilter.andFilter(filters));
}
 
Example 16
Source Project: netbeans   Source File: ThreadsPanel.java    License: Apache License 2.0 5 votes vote down vote up
public boolean include(RowFilter.Entry entry) {
    ThreadData data = (ThreadData)entry.getValue(1);
    switch (filter) {
        case LIVE: return ThreadData.isAliveState(data.getLastState());
        case FINISHED: return !ThreadData.isAliveState(data.getLastState());
        case SELECTED: return selectedApplied.contains(entry.getIdentifier());
        default: return true;
    }
}
 
Example 17
Source Project: netbeans   Source File: MultiColPatternFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean include(RowFilter.Entry<? extends TableModel,? extends Integer> entry)  {
    for (int colIdx : cols) {
        Object val = entry.getValue(colIdx);
        if (testValue(val)) {
                return true;
            }
        }
    return false;
}
 
Example 18
private KeyListener customKeyListener() {
    final KeyAdapter adapter = new KeyAdapter() {

        @Override
        public void keyTyped(KeyEvent e) {

            String modifiedQuery = "(?i)" + searchField.getText();
            tableRowShorter.setRowFilter(RowFilter.regexFilter(modifiedQuery));

            super.keyTyped(e);
        }

    };
    return adapter;
}
 
Example 19
Source Project: domain_hunter   Source File: JtableFilter.java    License: MIT License 5 votes vote down vote up
public static void main(String[] args) {
  Object[][] data = { { "A", 5 }, { "B", 2 }, { "C", 4 }, { "D", 8 } };
  String columnNames[] = { "Item", "Value" };
  TableModel model = new DefaultTableModel(data, columnNames) {
    public Class<?> getColumnClass(int column) {
      return getValueAt(0, column).getClass();
    }
  };
  JTable table = new JTable(model);

  RowFilter<Object, Object> filter = new RowFilter<Object, Object>() {
    public boolean include(Entry entry) {
      Integer population = (Integer) entry.getValue(1);
      return population.intValue() > 3;
    }
  };

  TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
  sorter.setRowFilter(filter);
  table.setRowSorter(sorter);
  JScrollPane scrollPane = new JScrollPane(table);
  JFrame frame = new JFrame("Filtering Table");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(scrollPane);
  frame.setSize(300, 200);
  frame.setVisible(true);
}
 
Example 20
Source Project: programming   Source File: FTable.java    License: GNU General Public License v3.0 5 votes vote down vote up
public FTable(Object[][] rows, String columns[]){
		

	setModel(new ModdedTable(rows,columns));
	sorter = new TableRowSorter<>(getModel());
	setRowSorter(sorter);
	setBorder(new EtchedBorder(EtchedBorder.RAISED));
	setGridColor(Color.BLACK);
	setFillsViewportHeight(true);
	sortList = new ArrayList<RowFilter<Object,Object>>();
}
 
Example 21
Source Project: programming   Source File: TablePanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
public TablePanel(Object[][] rows, String columns[]){
	table = new FTable(rows,columns);
	table.getTableHeader().setReorderingAllowed(false);
	sortList = new ArrayList<RowFilter<Object,Object>>();
	sortDate = new ArrayList<RowFilter<Object,Object>>();
	formatIfDate = "dd/MM/yyyy";

}
 
Example 22
Source Project: programming   Source File: TablePanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
public TablePanel(JTable table){
	formatIfDate = "dd/MM/yyyy";

	this.table = table;
	table.getTableHeader().setReorderingAllowed(false);
	sortList = new ArrayList<RowFilter<Object,Object>>();
			sortDate = new ArrayList<RowFilter<Object,Object>>();

	initUI();
}
 
Example 23
Source Project: programming   Source File: TablePanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
public TablePanel(JTable table,String format){
	formatIfDate = format;

	this.table = table;
	table.getTableHeader().setReorderingAllowed(false);
	sortList = new ArrayList<RowFilter<Object,Object>>();
			sortDate = new ArrayList<RowFilter<Object,Object>>();

	initUI();
}
 
Example 24
Source Project: visualvm   Source File: FilterUtils.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static boolean filter(TreeTableView view, final GenericFilter textFilter, final RowFilter excludesFilter) {
    if (textFilter.isAll()) {
        view.setViewFilter(null);
        return false;
    }
    
    view.setViewFilter(new HeapViewerNodeFilter() {
        public boolean passes(HeapViewerNode node, Heap heap) {
            String typeName = HeapViewerNode.getValue(node, TruffleType.TYPE_NAME, heap);
            return typeName == null ? true : textFilter.passes(typeName);
        }
    });
    return true;
}
 
Example 25
Source Project: visualvm   Source File: AllocTreeTableView.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected RowFilter getExcludesFilter() {
    return new RowFilter() { // Do not filter first level nodes
        public boolean include(RowFilter.Entry entry) {
            PresoObjAllocCCTNode node = (PresoObjAllocCCTNode)entry.getIdentifier();
            CCTNode parent = node.getParent();
            if (parent == null) return true;
            if (parent.getParent() == null) return !filterObjects;
            return !filterAllocations;
        }
    };
}
 
Example 26
Source Project: visualvm   Source File: JDBCTreeTableView.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected RowFilter getExcludesFilter() {
    return new RowFilter() { // Do not filter SQL commands
        public boolean include(RowFilter.Entry entry) {
            PresoObjAllocCCTNode node = (PresoObjAllocCCTNode)entry.getIdentifier();
            return isSQL(node);
        }
    };
}
 
Example 27
Source Project: visualvm   Source File: ProfilerRowSorter.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void refreshRowFilter() {
    if (filters == null || filters.isEmpty()) {
        setRowFilter(null);
    } else if (filters.size() == 1) {
        setRowFilter(filters.iterator().next());
    } else {
        setRowFilter(filterMode ? RowFilter.andFilter(filters) :
                                  RowFilter.orFilter(filters));
    }
}
 
Example 28
Source Project: PacketProxy   Source File: FilterTextParser.java    License: Apache License 2.0 4 votes vote down vote up
public static RowFilter<Object, Object> parse(String str) throws ParseException, Exception {
	return new FilterTextParser(str).expr();
}
 
Example 29
Source Project: PacketProxy   Source File: FilterTextParser.java    License: Apache License 2.0 4 votes vote down vote up
private RowFilter<Object, Object> expr() throws Exception {
	return orExpr();
}
 
Example 30
Source Project: visualvm   Source File: ProfilerTreeTable.java    License: GNU General Public License v2.0 4 votes vote down vote up
RowFilter getFilter() {
    return filter;
}