Revision: 3138
Author: jfuerth
Date: Wed Aug 12 14:58:23 2009
Log: Cleaned out a bunch of irrelevant/unused junk. No change in behaviour.
http://code.google.com/p/power-architect/source/detail?r=3138
Modified:
/trunk/src/ca/sqlpower/architect/swingui/table/ProfileTableModel.java
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/table/ProfileTableModel.java
Tue Feb 17 15:52:57 2009
+++ /trunk/src/ca/sqlpower/architect/swingui/table/ProfileTableModel.java
Wed Aug 12 14:58:23 2009
@@ -36,17 +36,17 @@
import ca.sqlpower.architect.profile.event.ProfileChangeEvent;
import ca.sqlpower.architect.profile.event.ProfileChangeListener;
import ca.sqlpower.architect.profile.output.ProfileColumn;
-import ca.sqlpower.sqlobject.SQLObjectException;
-import ca.sqlpower.sqlobject.SQLObjectRuntimeException;
import ca.sqlpower.sqlobject.SQLCatalog;
import ca.sqlpower.sqlobject.SQLColumn;
import ca.sqlpower.sqlobject.SQLDatabase;
-import ca.sqlpower.sqlobject.SQLObject;
+import ca.sqlpower.sqlobject.SQLObjectException;
+import ca.sqlpower.sqlobject.SQLObjectRuntimeException;
import ca.sqlpower.sqlobject.SQLObjectUtils;
import ca.sqlpower.sqlobject.SQLSchema;
import ca.sqlpower.sqlobject.SQLTable;
-
-public class ProfileTableModel extends AbstractTableModel {
+import ca.sqlpower.swingui.table.CleanupTableModel;
+
+public class ProfileTableModel extends AbstractTableModel implements
CleanupTableModel {
/**
* Requesting the value at this column index will give back the
@@ -58,9 +58,12 @@
*/
static final int CPR_PSEUDO_COLUMN_INDEX = -1;
- static Logger logger = Logger.getLogger(ProfileTableModel.class);
-
- private ProfileManager profileManager;
+ private static final Logger logger =
Logger.getLogger(ProfileTableModel.class);
+
+ /**
+ * The source of data for this table model.
+ */
+ private final ProfileManager profileManager;
/**
* A list of profile results to show in the ProfileResultsViewer
@@ -71,30 +74,39 @@
* Only tables in this list will have the results of their columns
shown.
*/
private List<TableProfileResult> tableResultsToScan = new
ArrayList<TableProfileResult>();
-
- private List<SQLObject> filters;
-
- public ProfileTableModel(ProfileManager profileManager) {
- filters = new ArrayList<SQLObject>();
- setProfileManager(profileManager);
- }
-
+
/**
- * removes all filters; this will show all the columns
- *
+ * Refreshes this table model (possibly firing a table model event)
whenever
+ * a change in the profile manager is detected.
*/
- public void removeAllFilters(){
- filters.clear();
- }
-
- public void removeFiltersByRegex(SQLObject sqo) {
- filters.remove(sqo);
- }
+ private final ProfileChangeListener profileChangeHandler = new
ProfileChangeListener() {
+ public void profilesRemoved(ProfileChangeEvent e) { refresh(); }
+ public void profilesAdded(ProfileChangeEvent e) { refresh(); }
+ public void profileListChanged(ProfileChangeEvent e) { refresh(); }
+ };
+
+ /**
+ * Creates a new table model attached to the given profile manager. Be
sure
+ * to call {...@link #cleanup()} when this table model is no longer needed
+ * (this will be done automatically if you are using a SQLPower
enhanced
+ * JTable; see {...@link CleanupTableModel} for details).
+ *
+ * @param profileManager The profile manager this table model is based
on.
+ */
+ public ProfileTableModel(ProfileManager profileManager) {
+ this.profileManager = profileManager;
+ profileManager.addProfileChangeListener(profileChangeHandler);
+ refresh();
+ }
+
/**
- * Adds a new object that passes the filter
+ * De-registers listeners that were installed when this table model
was created.
+ * To avoid memory leaks, it is important to call this cleanup method
when the
+ * table model is no longer needed.
*/
- public void addFilter(SQLObject sqo){
- filters.add(sqo);
+ public void cleanup() {
+ logger.debug("Cleaning up...");
+ profileManager.removeProfileChangeListener(profileChangeHandler);
}
@Override
@@ -210,54 +222,6 @@
Collections.sort(resultList);
fireTableDataChanged();
}
-
- /**
- * If one of the SQLObjects in filters matches with a sqlobject in the
- * profile results return true else return false
- *
- */
- private boolean shouldNotBeFilteredOut(ColumnProfileResult result) {
- for (SQLObject sqo : filters){
-
- ProfileColumn column;
- if (sqo instanceof SQLDatabase){
- column = ProfileColumn.DATABASE;
- } else if(sqo instanceof SQLCatalog) {
- column = ProfileColumn.CATALOG;
- } else if(sqo instanceof SQLSchema) {
- column = ProfileColumn.SCHEMA;
- } else if(sqo instanceof SQLTable) {
- column = ProfileColumn.TABLE;
- } else if(sqo instanceof SQLColumn) {
- column = ProfileColumn.COLUMN;
- } else {
- continue;
-
- }
- if (sqo.equals(getColumnValueFromProfile(column, result))) {
- return true;
- }
- }
- return false;
- }
-
- public void setProfileManager(ProfileManager profileManager) {
- this.profileManager = profileManager;
- profileManager.addProfileChangeListener(new
ProfileChangeListener(){
-
- public void profilesRemoved(ProfileChangeEvent e) {
- refresh();
- }
-
- public void profilesAdded(ProfileChangeEvent e) {
- refresh();
- }
-
- public void profileListChanged(ProfileChangeEvent event) {
- refresh();
- }});
- refresh();
- }
@Override
public Class<?> getColumnClass(int columnIndex) {