Revision: 3810
Author: [email protected]
Date: Thu Jul 29 14:38:54 2010
Log: Changed BusinessDefinition and FormulaMetricCalculation constructor
parameters to not have @Nonnull annotations. The Architect EE metadata
screens require this change so that new rows with empty cells that are
added can be added to their table models.
Fixed the RemoveSelectedTableRowsAction to factor in having a RowSorter set
in the JTable, so that it selects the it removes the correct indices if the
table is sorted.
Also, added an abstract AddAndSelectTableRowsAction which adds a row to the
end of a table model and selects that row. This action is abstract because
different table models have different implementations for adding rows.
http://code.google.com/p/power-architect/source/detail?r=3810
Added:
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/AddAndSelectTableRowAction.java
Modified:
/trunk/src/main/java/ca/sqlpower/architect/enterprise/BusinessDefinition.java
/trunk/src/main/java/ca/sqlpower/architect/enterprise/FormulaMetricCalculation.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/RemoveSelectedTableRowsAction.java
=======================================
--- /dev/null
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/AddAndSelectTableRowAction.java
Thu Jul 29 14:38:54 2010
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of SQL Power Architect.
+ *
+ * SQL Power Architect is free software; you can redistribute it and/or
modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SQL Power Architect is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package ca.sqlpower.architect.swingui.action;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JTable;
+import javax.swing.RowSorter;
+import javax.swing.table.TableModel;
+
+/**
+ * This {...@link Action} adds a new row to a {...@link JTable}'s {...@link
TableModel}
+ * and selects the newly added row. This class is abstract because
different
+ * {...@link TableModel}s may have different implementations of adding rows.
+ */
+public abstract class AddAndSelectTableRowAction extends AbstractAction {
+
+ /**
+ * The {...@link JTable} to add and select the row on when this {...@link
Action}
+ * is performed.
+ */
+ private final JTable table;
+
+ /**
+ * Creates a new {...@link AddAndSelectTableRowAction}.
+ *
+ * @param table
+ * The JTable to add and select the row when this {...@link
Action}
+ * is performed.
+ */
+ public AddAndSelectTableRowAction(JTable table) {
+ this.table = table;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ table.getSelectionModel().clearSelection();
+ addRow();
+
+ RowSorter<? extends TableModel> rowSorter = table.getRowSorter();
+ int index = table.getRowCount() - 1;
+ if (rowSorter != null) {
+ index = rowSorter.convertRowIndexToView(index);
+ }
+
+ table.getSelectionModel().setSelectionInterval(index, index);
+ }
+
+ /**
+ * Adds a row in the {...@link TableModel}. This method must add the row
at the
+ * end of the {...@link TableModel}.
+ */
+ public abstract void addRow();
+
+}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/enterprise/BusinessDefinition.java
Fri Jul 16 07:18:35 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/enterprise/BusinessDefinition.java
Thu Jul 29 14:38:54 2010
@@ -22,8 +22,6 @@
import java.util.Collections;
import java.util.List;
-import javax.annotation.Nonnull;
-
import ca.sqlpower.architect.ArchitectProject;
import ca.sqlpower.object.AbstractSPObject;
import ca.sqlpower.object.SPObject;
@@ -68,8 +66,8 @@
*/
@Constructor
public BusinessDefinition(
- @ConstructorParameter(propertyName="term") @Nonnull String
term,
- @ConstructorParameter(propertyName="definition") @Nonnull
String definition) {
+ @ConstructorParameter(propertyName="term") String term,
+ @ConstructorParameter(propertyName="definition") String
definition) {
setTerm(term);
this.definition = definition;
}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/enterprise/FormulaMetricCalculation.java
Tue Jul 20 08:10:07 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/enterprise/FormulaMetricCalculation.java
Thu Jul 29 14:38:54 2010
@@ -22,8 +22,6 @@
import java.util.Collections;
import java.util.List;
-import javax.annotation.Nonnull;
-
import ca.sqlpower.object.AbstractSPObject;
import ca.sqlpower.object.SPObject;
import ca.sqlpower.object.annotation.Accessor;
@@ -66,9 +64,9 @@
*/
@Constructor
public FormulaMetricCalculation(
- @ConstructorParameter(propertyName="name") @Nonnull String
name,
- @ConstructorParameter(propertyName="formula") @Nonnull String
formula,
- @ConstructorParameter(propertyName="description") @Nonnull
String description) {
+ @ConstructorParameter(propertyName="name") String name,
+ @ConstructorParameter(propertyName="formula") String formula,
+ @ConstructorParameter(propertyName="description") String
description) {
setName(name);
this.formula = formula;
this.description = description;
@@ -125,7 +123,7 @@
* The {...@link String} formula. This value cannot be null.
*/
@Mutator
- public void setFormula(@Nonnull String formula) {
+ public void setFormula(String formula) {
String oldFormula = this.formula;
this.formula = formula;
firePropertyChange("formula", oldFormula, formula);
@@ -148,7 +146,7 @@
* The {...@link String} description of the formula.
*/
@Mutator
- public void setDescription(@Nonnull String description) {
+ public void setDescription(String description) {
String oldDescription = this.description;
this.description = description;
firePropertyChange("description", oldDescription, description);
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/RemoveSelectedTableRowsAction.java
Thu Jul 15 11:56:19 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/RemoveSelectedTableRowsAction.java
Thu Jul 29 14:38:54 2010
@@ -24,6 +24,7 @@
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JTable;
+import javax.swing.RowSorter;
import javax.swing.table.TableModel;
/**
@@ -50,9 +51,17 @@
public void actionPerformed(ActionEvent e) {
if (table.getSelectedRowCount() > 0) {
- for (int i = table.getSelectedRowCount()-1; i >= 0; i--) {
- int index = table.getSelectedRows()[i];
- removeRow(index);
+ RowSorter<? extends TableModel> rowSorter =
table.getRowSorter();
+ int[] selectedRows = table.getSelectedRows();
+
+ if (rowSorter == null) {
+ for (int i = selectedRows.length - 1; i >= 0; i--) {
+ removeRow(selectedRows[i]);
+ }
+ } else {
+ for (int i = selectedRows.length - 1; i >= 0; i--) {
+
removeRow(rowSorter.convertRowIndexToModel(selectedRows[i]));
+ }
}
}
}