Author: kevin1219
Date: Tue Aug 26 07:54:30 2008
New Revision: 2607
Modified:
trunk/src/ca/sqlpower/architect/olap/OLAPUtil.java
trunk/src/ca/sqlpower/architect/swingui/olap/CubeEditPanel.java
trunk/src/ca/sqlpower/architect/swingui/olap/DimensionEditPanel.java
trunk/src/ca/sqlpower/architect/swingui/olap/OLAPObjectNameValidator.java
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateCubeAction.java
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateDimensionAction.java
Log:
Modified the method for checking unique names to take in the parent object,
the class, and name. OLAPObjectNameValidator now handles OLAPObjects that
allow null names more appropriately. Create actions for Cube and Dimension
now sets the initial name to a unique name.
Modified: trunk/src/ca/sqlpower/architect/olap/OLAPUtil.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/olap/OLAPUtil.java (original)
+++ trunk/src/ca/sqlpower/architect/olap/OLAPUtil.java Tue Aug 26 07:54:30
2008
@@ -314,33 +314,32 @@
}
/**
- * Checks if the given name would be unique for the given OLAPObject.
+ * Checks if the name is unique for an OLAPObject.
*
- * @param oo
- * The OLAPObject to check, OLAPSession ancestor must not be
- * null.
+ * @param parent
+ * The object that will be the parent.
+ * @param type
+ * The type of the object.
* @param name
- * The name to check for.
- * @return True if the given object is the only object in its schema
with
- * the given name, false otherwise.
+ * The name to check for, can be null.
+ * @return False if any child of the given type from the parent has the
+ * given name, true otherwise.
*/
- public static boolean isNameUnique(OLAPObject oo, String name) {
- OLAPSession olapSession = getSession(oo);
+ public static boolean isNameUnique(OLAPObject parent, Class<? extends
OLAPObject> type, String name) {
+ OLAPSession olapSession = getSession(parent);
if (olapSession == null) {
- throw new IllegalArgumentException("Can't find OLAPSession
ancestor: " + oo);
+ throw new IllegalArgumentException("Can't find OLAPSession
ancestor: " + parent);
}
OLAPObject foundObj;
- if (oo instanceof Cube) {
+ if (type == Cube.class) {
foundObj = olapSession.findCube(name);
- } else if (oo instanceof Dimension && oo.getParent() instanceof
Schema) {
+ } else if (type == Dimension.class && parent instanceof Schema) {
foundObj = olapSession.findPublicDimension(name);
- } else if (oo instanceof CubeDimension && oo.getParent()
instanceof Cube) {
- foundObj =
olapSession.findCubeDimension(oo.getParent().getName(), oo.getName());
} else {
return true;
}
- return foundObj == null || foundObj == oo;
+ return foundObj == null;
}
}
Modified: trunk/src/ca/sqlpower/architect/swingui/olap/CubeEditPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/olap/CubeEditPanel.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/olap/CubeEditPanel.java Tue Aug
26 07:54:30 2008
@@ -91,7 +91,7 @@
panel = builder.getPanel();
handler = new FormValidationHandler(status);
- Validator validator = new OLAPObjectNameValidator(cube, true);
+ Validator validator = new
OLAPObjectNameValidator(cube.getParent(), cube, false);
handler.addValidateObject(nameField, validator);
}
Modified:
trunk/src/ca/sqlpower/architect/swingui/olap/DimensionEditPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/olap/DimensionEditPanel.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/olap/DimensionEditPanel.java
Tue Aug 26 07:54:30 2008
@@ -73,7 +73,7 @@
panel = builder.getPanel();
handler = new FormValidationHandler(status);
- Validator validator = new OLAPObjectNameValidator(dimension, true);
+ Validator validator = new
OLAPObjectNameValidator(dimension.getParent(), dimension, false);
handler.addValidateObject(nameField, validator);
}
public boolean applyChanges() {
Modified:
trunk/src/ca/sqlpower/architect/swingui/olap/OLAPObjectNameValidator.java
==============================================================================
---
trunk/src/ca/sqlpower/architect/swingui/olap/OLAPObjectNameValidator.java
(original)
+++
trunk/src/ca/sqlpower/architect/swingui/olap/OLAPObjectNameValidator.java
Tue Aug 26 07:54:30 2008
@@ -26,34 +26,44 @@
import ca.sqlpower.validation.Validator;
/**
- * A simple validator for OLAPObjects that checks for empty and unique
names.
+ * A simple validator for OLAPObjects that checks for invalid names.
*
*/
public class OLAPObjectNameValidator implements Validator {
- private final OLAPObject oo;
+ private final OLAPObject parent;
+ private final OLAPObject obj;
/**
- * Indicates whether to check if the name is empty or null; true to
check,
- * false for otherwise.
+ * Indicates whether name can be null. If true, empty string will also
be
+ * treated as null.
*/
- private final boolean checkEmptyName;
+ private final boolean allowNull;
- public OLAPObjectNameValidator(OLAPObject oo, boolean checkEmptyName) {
- this.oo = oo;
- this.checkEmptyName = checkEmptyName;
+ public OLAPObjectNameValidator(OLAPObject parent, OLAPObject obj,
boolean allowNull) {
+ this.parent = parent;
+ this.obj = obj;
+ this.allowNull = allowNull;
}
public ValidateResult validate(Object contents) {
String value = (String) contents;
- if (checkEmptyName && (value == null || value.trim().length() ==
0)) {
- return ValidateResult.createValidateResult(Status.FAIL,
- "A name is required.");
- } else if (OLAPUtil.isNameUnique(oo, value)) {
- return ValidateResult.createValidateResult(Status.OK, "");
+
+ if (value == null || value.length() == 0) {
+ if (allowNull) {
+ if (OLAPUtil.nameFor(obj) != null
&& !OLAPUtil.isNameUnique(parent, obj.getClass(), null)) {
+ return
ValidateResult.createValidateResult(Status.FAIL, "Name already exists.");
+ }
+ } else {
+ return ValidateResult.createValidateResult(Status.FAIL, "A
name is required.");
+ }
} else {
- return ValidateResult.createValidateResult(Status.FAIL, "Name
already exists.");
+ if (!(value.equals(OLAPUtil.nameFor(obj)))
&& !OLAPUtil.isNameUnique(parent, obj.getClass(), value)) {
+ return
ValidateResult.createValidateResult(Status.FAIL, "Name already exists.");
+ }
}
+
+ return ValidateResult.createValidateResult(Status.OK, "");
}
}
Modified:
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateCubeAction.java
==============================================================================
---
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateCubeAction.java
(original)
+++
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateCubeAction.java
Tue Aug 26 07:54:30 2008
@@ -25,6 +25,7 @@
import javax.swing.KeyStroke;
import ca.sqlpower.architect.ArchitectException;
+import ca.sqlpower.architect.olap.OLAPUtil;
import ca.sqlpower.architect.olap.MondrianModel.Cube;
import ca.sqlpower.architect.olap.MondrianModel.Schema;
import ca.sqlpower.architect.swingui.AbstractPlacer;
@@ -48,7 +49,13 @@
public void actionPerformed(ActionEvent e) {
Cube cube = new Cube();
- cube.setName("New Cube");
+
+ int count = 1;
+ while (!OLAPUtil.isNameUnique(schema, Cube.class, "New Cube " +
count)) {
+ count++;
+ }
+ cube.setName("New Cube " + count);
+
CubePane cp = new CubePane(cube, playpen.getContentPane());
CubePlacer cubePlacer = new CubePlacer(cp);
cubePlacer.dirtyup();
Modified:
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateDimensionAction.java
==============================================================================
---
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateDimensionAction.java
(original)
+++
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateDimensionAction.java
Tue Aug 26 07:54:30 2008
@@ -25,6 +25,7 @@
import javax.swing.KeyStroke;
import ca.sqlpower.architect.ArchitectException;
+import ca.sqlpower.architect.olap.OLAPUtil;
import ca.sqlpower.architect.olap.MondrianModel.Dimension;
import ca.sqlpower.architect.olap.MondrianModel.Schema;
import ca.sqlpower.architect.swingui.AbstractPlacer;
@@ -48,7 +49,13 @@
public void actionPerformed(ActionEvent e) {
Dimension dim = new Dimension();
- dim.setName("New Dimension");
+
+ int count = 1;
+ while (!OLAPUtil.isNameUnique(schema, Dimension.class, "New
Dimension " + count)) {
+ count++;
+ }
+ dim.setName("New Cube " + count);
+
if (playpen.getSelectedContainers().size() >= 1) {
// TODO add a DimensionUsage to the selected cube(s)
}