Revision: 3741
Author: [email protected]
Date: Thu Jul 15 11:56:19 2010
Log: Added a BusinessDefinition object, which is an allowed child type of
ArchitectSwingProject and ArchitectProject.
Also, made the RemoveSelectedTableRowsAction an abstract class because
removal of table rows is dependent on the type of TableModel that is
implemented.
http://code.google.com/p/power-architect/source/detail?r=3741
Added:
/trunk/src/main/java/ca/sqlpower/architect/enterprise/BusinessDefinition.java
Modified:
/trunk/src/main/java/ca/sqlpower/architect/ArchitectProject.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingProject.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/RemoveSelectedTableRowsAction.java
=======================================
--- /dev/null
+++
/trunk/src/main/java/ca/sqlpower/architect/enterprise/BusinessDefinition.java
Thu Jul 15 11:56:19 2010
@@ -0,0 +1,187 @@
+/*
+ * 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.enterprise;
+
+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;
+import ca.sqlpower.object.annotation.Accessor;
+import ca.sqlpower.object.annotation.Constructor;
+import ca.sqlpower.object.annotation.ConstructorParameter;
+import ca.sqlpower.object.annotation.Mutator;
+import ca.sqlpower.object.annotation.NonProperty;
+
+/**
+ * This business definition object associates a business term to its
definition.
+ * Essentially, this is a dictionary entry for business words used within
an
+ * organization.
+ */
+public class BusinessDefinition extends AbstractSPObject {
+
+ public static final List<Class<? extends SPObject>> allowedChildTypes =
+ Collections.emptyList();
+
+ /**
+ * {...@link #getTerm()}
+ */
+ private String term;
+
+ /**
+ * {...@link #getDefinition()}
+ */
+ private String definition;
+
+ /**
+ * Creates a new {...@link BusinessDefinition}.
+ *
+ * @param term
+ * The business term.
+ * @param definition
+ * The definition for the business term.
+ */
+ @Constructor
+ public BusinessDefinition(
+ @ConstructorParameter(propertyName="term") @Nonnull String
term,
+ @ConstructorParameter(propertyName="definition") @Nonnull
String definition) {
+ setTerm(term);
+ this.definition = definition;
+ }
+
+ /**
+ * Copy constructor for {...@link BusinessDefinition}.
+ *
+ * @param busDef
+ * The {...@link BusinessDefinition} to copy.
+ */
+ public BusinessDefinition(BusinessDefinition busDef) {
+ this(busDef.getTerm(), busDef.getDefinition());
+ }
+
+ @NonProperty
+ public List<? extends SPObject> getChildren() {
+ return Collections.emptyList();
+ }
+
+ public boolean allowsChildren() {
+ return false;
+ }
+
+ public int childPositionOffset(Class<? extends SPObject> childType) {
+ return 0;
+ }
+
+ public void removeDependency(SPObject dependency) {
+ // No operation.
+ }
+
+ @NonProperty
+ public List<? extends SPObject> getDependencies() {
+ return Collections.emptyList();
+ }
+
+ @NonProperty
+ public List<Class<? extends SPObject>> getAllowedChildTypes() {
+ return allowedChildTypes;
+ }
+
+ @Override
+ protected boolean removeChildImpl(SPObject child) {
+ return false;
+ }
+
+ /**
+ * Gets the business term.
+ *
+ * @return The {...@link String} business term.
+ */
+ @Accessor(isInteresting=true)
+ public String getTerm() {
+ return term;
+ }
+
+ /**
+ * Sets the business term. Also sets the name to be the same as the
term.
+ *
+ * @param term
+ * The {...@link String} business term.
+ */
+ @Mutator
+ public void setTerm(String term) {
+ setName(term);
+ }
+
+ /**
+ * Gets the business definition for this term.
+ * @return The {...@link String} business definition for this term.
+ */
+ @Accessor(isInteresting=true)
+ public String getDefinition() {
+ return definition;
+ }
+
+ /**
+ * Sets the business definition for this term.
+ *
+ * @param definition
+ * The {...@link String} business definition for this term.
+ */
+ @Mutator
+ public void setDefinition(String definition) {
+ String oldDefinition = this.definition;
+ this.definition = definition;
+ firePropertyChange("definition", oldDefinition, definition);
+ }
+
+ /**
+ * Overridden so that the name and term properties are the same.
+ */
+ @Override @Mutator
+ public void setName(String name) {
+ begin("Setting name and term of business definition.");
+ super.setName(name);
+
+ String oldTerm = this.term;
+ this.term = name;
+ firePropertyChange("term", oldTerm, name);
+ commit();
+ }
+
+ @Override @Accessor
+ public ArchitectProject getParent() {
+ return (ArchitectProject) super.getParent();
+ }
+
+ @Override @Mutator
+ public void setParent(SPObject parent) {
+ if (parent != null &&
+ !ArchitectProject.class.isAssignableFrom(parent.getClass()))
{
+ throw new IllegalArgumentException("The parent of a " +
+ BusinessDefinition.class.getSimpleName() + " must be
an " +
+ ArchitectProject.class.getSimpleName() + ".");
+ }
+ super.setParent(parent);
+ }
+
+}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ArchitectProject.java Thu
Jul 15 08:20:30 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/ArchitectProject.java Thu
Jul 15 11:56:19 2010
@@ -24,6 +24,7 @@
import java.util.Collections;
import java.util.List;
+import ca.sqlpower.architect.enterprise.BusinessDefinition;
import ca.sqlpower.architect.enterprise.DomainCategory;
import ca.sqlpower.architect.profile.ProfileManager;
import ca.sqlpower.enterprise.client.Group;
@@ -70,7 +71,7 @@
public static final List<Class<? extends SPObject>> allowedChildTypes
= Collections
.unmodifiableList(new ArrayList<Class<? extends
SPObject>>(Arrays.asList(UserDefinedSQLType.class,
DomainCategory.class, SPObjectSnapshot.class,
SQLObjectRoot.class, ProfileManager.class,
- ProjectSettings.class, User.class, Group.class)));
+ ProjectSettings.class, User.class, Group.class,
BusinessDefinition.class)));
/**
* There is a 1:1 ratio between the session and the project.
@@ -86,6 +87,8 @@
private final List<SPObjectSnapshot> sqlTypeSnapshots = new
ArrayList<SPObjectSnapshot>();
private final List<DomainCategory> domainCategories = new
ArrayList<DomainCategory>();
+ private final List<BusinessDefinition> businessDefinitions = new
ArrayList<BusinessDefinition>();
+
/**
* The current integrity watcher on the project.
*/
@@ -265,6 +268,12 @@
fireChildRemoved(SPObjectSnapshot.class, child, index);
child.setParent(null);
return true;
+ } else if (child instanceof BusinessDefinition) {
+ int index = businessDefinitions.indexOf((BusinessDefinition)
child);
+ businessDefinitions.remove((BusinessDefinition) child);
+ fireChildRemoved(BusinessDefinition.class, child, index);
+ child.setParent(null);
+ return true;
}
return false;
}
@@ -324,6 +333,7 @@
allChildren.add(projectSettings);
allChildren.addAll(users);
allChildren.addAll(groups);
+ allChildren.addAll(businessDefinitions);
return allChildren;
}
@@ -353,11 +363,19 @@
addDomainCategory((DomainCategory) child, index);
} else if (child instanceof SPObjectSnapshot) {
addSPObjectSnapshot((SPObjectSnapshot) child, index);
+ } else if (child instanceof BusinessDefinition) {
+ addBusinessDefinition((BusinessDefinition) child, index);
} else {
throw new IllegalArgumentException("Cannot add child of type "
+
child.getClass() + " to the project once it has been
created.");
}
}
+
+ public void addBusinessDefinition(BusinessDefinition
businessDefinition, int index) {
+ businessDefinitions.add(index, businessDefinition);
+ businessDefinition.setParent(this);
+ fireChildAdded(BusinessDefinition.class, businessDefinition,
index);
+ }
public void addSQLType(UserDefinedSQLType sqlType, int index) {
@@ -372,6 +390,7 @@
fireChildAdded(SPObjectSnapshot.class, child, index);
}
+ @NonProperty
protected List<UserDefinedSQLType> getSqlTypes() {
return Collections.unmodifiableList(sqlTypes);
}
@@ -385,6 +404,11 @@
public List<DomainCategory> getDomainCategories() {
return Collections.unmodifiableList(domainCategories);
}
+
+ @NonProperty
+ public List<BusinessDefinition> getBusinessDefinitions() {
+ return Collections.unmodifiableList(businessDefinitions);
+ }
public void addUser(User user, int index) {
users.add(index, user);
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingProject.java
Thu Jul 15 08:20:30 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingProject.java
Thu Jul 15 11:56:19 2010
@@ -30,6 +30,7 @@
import ca.sqlpower.architect.ArchitectProject;
import ca.sqlpower.architect.ProjectSettings;
import ca.sqlpower.architect.ddl.critic.CriticManager;
+import ca.sqlpower.architect.enterprise.BusinessDefinition;
import ca.sqlpower.architect.enterprise.DomainCategory;
import ca.sqlpower.architect.etl.kettle.KettleSettings;
import ca.sqlpower.architect.olap.OLAPRootObject;
@@ -78,7 +79,8 @@
.unmodifiableList(new ArrayList<Class<? extends
SPObject>>(Arrays.asList(UserDefinedSQLType.class,
DomainCategory.class, SPObjectSnapshot.class,
SQLObjectRoot.class,
OLAPRootObject.class, PlayPenContentPane.class,
ProfileManager.class, ProjectSettings.class,
- CriticManager.class, KettleSettings.class, User.class,
Group.class)));
+ CriticManager.class, KettleSettings.class, User.class,
Group.class,
+ BusinessDefinition.class)));
/**
* A hash map mapping all the descendants of this project.
@@ -271,6 +273,7 @@
//TODO make specific getters for these types.
allChildren.addAll(getUsers());
allChildren.addAll(getGroups());
+ allChildren.addAll(getBusinessDefinitions());
return allChildren;
}
@@ -313,6 +316,8 @@
addDomainCategory((DomainCategory) child, index);
} else if (child instanceof SPObjectSnapshot) {
addSPObjectSnapshot((SPObjectSnapshot) child, index);
+ } else if (child instanceof BusinessDefinition) {
+ addBusinessDefinition((BusinessDefinition) child, index);
} else {
throw new IllegalArgumentException("Cannot add child of type "
+
child.getClass() + " to the project once it has been
created.");
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/RemoveSelectedTableRowsAction.java
Wed Jul 7 11:16:36 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/RemoveSelectedTableRowsAction.java
Thu Jul 15 11:56:19 2010
@@ -24,13 +24,14 @@
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JTable;
-import javax.swing.table.DefaultTableModel;
+import javax.swing.table.TableModel;
/**
- * This {...@link Action} removes selected rows from a {...@link JTable}. The
- * assumption made here is that the table uses a {...@link DefaultTableModel}.
+ * This {...@link Action} removes selected rows from a {...@link JTable}. This
class
+ * is abstract because different {...@link TableModel}s may have different
+ * implementations of removing rows.
*/
-public class RemoveSelectedTableRowsAction extends AbstractAction {
+public abstract class RemoveSelectedTableRowsAction extends AbstractAction
{
/**
* The {...@link JTable} to remove the selected rows from.
@@ -49,13 +50,19 @@
public void actionPerformed(ActionEvent e) {
if (table.getSelectedRowCount() > 0) {
- DefaultTableModel model = (DefaultTableModel) table.getModel();
-
for (int i = table.getSelectedRowCount()-1; i >= 0; i--) {
int index = table.getSelectedRows()[i];
- model.removeRow(index);
+ removeRow(index);
}
}
}
+
+ /**
+ * Removes a row in a {...@link TableModel}.
+ *
+ * @param row
+ * The index of the row to remove.
+ */
+ public abstract void removeRow(int row);
}