Created
March 26, 2015 08:49
-
-
Save nunenuh/e3dd92f1626cccfe7728 to your computer and use it in GitHub Desktop.
sample table model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package epcust.domain.subdomain; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Vector; | |
import javax.swing.table.AbstractTableModel; | |
import orm.entity.Subdomain; | |
/** | |
* | |
* @author gen5x4 | |
*/ | |
public class SubdomainTableModel extends AbstractTableModel{ | |
private static final long serialVersionUID = -1; | |
private Vector<Subdomain> row; | |
private Vector<String> column; | |
/** | |
* | |
*/ | |
public SubdomainTableModel() { | |
super(); | |
column = new Vector<String>(); | |
column.add("Subdomain"); | |
column.add("Document Root Path"); | |
column.add("Log Path"); | |
row = new Vector<Subdomain>(); | |
} | |
public void add(List<Subdomain> get) { | |
for (Subdomain t : get) { | |
row.add(t); | |
} | |
fireTableDataChanged(); | |
} | |
/** | |
* | |
* @param index | |
* @param element | |
* @return | |
*/ | |
public synchronized Subdomain set(int index, Subdomain element) { | |
Subdomain t = row.set(index, element); | |
fireTableRowsUpdated(index, index); | |
return t; | |
} | |
/** | |
* | |
*/ | |
public synchronized void removeAllElements() { | |
row.removeAllElements(); | |
fireTableDataChanged(); | |
} | |
/** | |
* | |
* @param index | |
* @return | |
*/ | |
public synchronized Subdomain remove(int index) { | |
Subdomain t = row.remove(index); | |
fireTableRowsDeleted(index, index); | |
return t; | |
} | |
/** | |
* | |
* @param index | |
* @return | |
*/ | |
public synchronized Subdomain get(int index) { | |
return row.get(index); | |
} | |
/** | |
* | |
* @param e | |
* @return | |
*/ | |
public synchronized boolean add(Subdomain e) { | |
int index = row.size(); | |
boolean b = row.add(e); | |
fireTableRowsInserted(index, index); | |
return b; | |
} | |
@Override | |
public String getColumnName(int column) { | |
return this.column.get(column); | |
} | |
@Override | |
public int getRowCount() { | |
return row.size(); | |
} | |
@Override | |
public int getColumnCount() { | |
return column.size(); | |
} | |
@Override | |
public Object getValueAt(int rowIndex, int columnIndex) { | |
if (columnIndex == 0) { | |
return row.get(rowIndex).getSubdomain(); | |
} else if (columnIndex == 1) { | |
return row.get(rowIndex).getDocRootPath(); | |
} else if (columnIndex == 2) { | |
return row.get(rowIndex).getErrorLogPath(); | |
} | |
return null; | |
} | |
/** | |
* | |
* @param keywords | |
* @return | |
*/ | |
public ArrayList<Subdomain> search(String keywords){ | |
int tCol = getColumnCount(); | |
int tRow = getRowCount(); | |
int count = 0; | |
boolean founded = false; | |
Integer[] foundRow = new Integer[tRow]; | |
ArrayList<Subdomain> list = new ArrayList<Subdomain>(); | |
for (int crow=0; crow<tRow; crow++){ | |
for (int ccol=0; ccol<tCol; ccol++){ | |
String next = String.valueOf(getValueAt(crow, ccol)); | |
if (next.contains(keywords)){ | |
foundRow[count]=crow; | |
count++; | |
list.add(row.get(crow)); | |
founded=true; | |
} | |
if (founded==true){ | |
break; | |
} | |
} | |
founded=false; | |
} | |
return list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment