use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.
the class ObjEntityTab method setQualifier.
void setQualifier(String text) {
if (text != null && text.trim().length() == 0) {
text = null;
}
ObjEntity entity = mediator.getCurrentObjEntity();
if (entity != null) {
ExpressionConvertor convertor = new ExpressionConvertor();
try {
String oldQualifier = convertor.valueAsString(entity.getDeclaredQualifier());
if (!Util.nullSafeEquals(oldQualifier, text)) {
Expression exp = (Expression) convertor.stringAsValue(text);
entity.setDeclaredQualifier(exp);
mediator.fireObjEntityEvent(new EntityEvent(this, entity));
}
} catch (IllegalArgumentException ex) {
// unparsable qualifier
throw new ValidationException(ex.getMessage());
}
}
}
use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.
the class ObjEntityTab method initView.
private void initView() {
this.setLayout(new BorderLayout());
JToolBar toolBar = new JToolBar();
toolBar.setBorder(BorderFactory.createEmptyBorder());
toolBar.setFloatable(false);
ActionManager actionManager = Application.getInstance().getActionManager();
toolBar.add(actionManager.getAction(CreateAttributeAction.class).buildButton(1));
toolBar.add(actionManager.getAction(CreateRelationshipAction.class).buildButton(3));
toolBar.addSeparator();
toolBar.add(actionManager.getAction(ObjEntitySyncAction.class).buildButton(1));
toolBar.add(actionManager.getAction(ObjEntityCounterpartAction.class).buildButton(3));
toolBar.addSeparator();
toolBar.add(actionManager.getAction(ShowGraphEntityAction.class).buildButton());
add(toolBar, BorderLayout.NORTH);
// create widgets
name = new TextAdapter(new JTextField()) {
@Override
protected void updateModel(String text) {
setEntityName(text);
}
};
superClassName = new TextAdapter(new JTextField()) {
@Override
protected void updateModel(String text) {
setSuperClassName(text);
}
};
className = new TextAdapter(new JTextField()) {
@Override
protected void updateModel(String text) {
setClassName(text);
}
};
qualifier = new TextAdapter(new JTextField()) {
@Override
protected void updateModel(String text) {
setQualifier(text);
}
};
dbEntityCombo = Application.getWidgetFactory().createComboBox();
superEntityCombo = Application.getWidgetFactory().createComboBox();
AutoCompletion.enable(dbEntityCombo);
AutoCompletion.enable(superEntityCombo);
readOnly = new JCayenneCheckBox();
optimisticLocking = new JCayenneCheckBox();
// borderless clickable button used as a label
tableLabel = new JButton("Table/View:");
tableLabel.setBorderPainted(false);
tableLabel.setHorizontalAlignment(SwingConstants.LEFT);
tableLabel.setFocusPainted(false);
tableLabel.setMargin(new Insets(0, 0, 0, 0));
tableLabel.setBorder(null);
isAbstract = new JCayenneCheckBox();
serverOnly = new JCayenneCheckBox();
comment = new TextAdapter(new JTextField()) {
@Override
protected void updateModel(String text) throws ValidationException {
setComment(text);
}
};
clientClassName = new TextAdapter(new JTextField()) {
@Override
protected void updateModel(String text) {
setClientClassName(text);
}
};
clientSuperClassName = new TextAdapter(new JTextField()) {
@Override
protected void updateModel(String text) {
setClientSuperClassName(text);
}
};
// assemble
FormLayout layout = new FormLayout("right:pref, 3dlu, fill:200dlu", "");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
builder.setDefaultDialogBorder();
builder.appendSeparator("ObjEntity Configuration");
builder.append("ObjEntity Name:", name.getComponent());
builder.append("Inheritance:", superEntityCombo);
builder.append(tableLabel, dbEntityCombo);
isAbstractLabel = builder.append("Abstract class:", isAbstract);
builder.append("Comment:", comment.getComponent());
builder.appendSeparator();
builder.append("Java Class:", className.getComponent());
superclassLabel = builder.append("Superclass:", superClassName.getComponent());
builder.append("Qualifier:", qualifier.getComponent());
builder.append("Read-Only:", readOnly);
builder.append("Optimistic Locking:", optimisticLocking);
clientSeparator = builder.appendSeparator("Java Client");
serverOnlyLabel = builder.append("Not for Client Use:", serverOnly);
clientClassNameLabel = builder.append("Client Java Class:", clientClassName.getComponent());
clientSuperClassNameLabel = builder.append("Client Superclass:", clientSuperClassName.getComponent());
add(builder.getPanel(), BorderLayout.CENTER);
}
use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.
the class ProcedureQueryView method setQueryName.
/**
* Initializes Query name from string.
*/
void setQueryName(String newName) {
if (newName != null && newName.trim().length() == 0) {
newName = null;
}
QueryDescriptor query = mediator.getCurrentQuery();
if (query == null) {
return;
}
if (Util.nullSafeEquals(newName, query.getName())) {
return;
}
if (newName == null) {
throw new ValidationException("Query name is required.");
}
DataMap map = mediator.getCurrentDataMap();
if (map.getQueryDescriptor(newName) == null) {
// completely new name, set new name for entity
QueryEvent e = new QueryEvent(this, query, query.getName(), map);
ProjectUtil.setQueryName(map, query, newName);
mediator.fireQueryEvent(e);
} else {
// there is a query with the same name
throw new ValidationException("There is another query named '" + newName + "'. Use a different name.");
}
}
use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.
the class SelectQueryMainTab method createQualifier.
/**
* Method to create and check an expression
* @param text String to be converted as Expression
* @return Expression if a new expression was created, null otherwise.
* @throws ValidationException if <code>text</code> can't be converted
*/
Expression createQualifier(String text) throws ValidationException {
SelectQueryDescriptor query = getQuery();
if (query == null) {
return null;
}
ExpressionConvertor convertor = new ExpressionConvertor();
try {
String oldQualifier = convertor.valueAsString(query.getQualifier());
if (!Util.nullSafeEquals(oldQualifier, text)) {
Expression exp = (Expression) convertor.stringAsValue(text);
/*
* Advanced checking. See CAY-888 #1
*/
if (query.getRoot() instanceof Entity) {
checkExpression((Entity) query.getRoot(), exp);
}
return exp;
}
return null;
} catch (IllegalArgumentException ex) {
// unparsable qualifier
throw new ValidationException(ex.getMessage());
}
}
use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.
the class SelectQueryMainTab method initView.
private void initView() {
// create widgets
name = new TextAdapter(new JTextField()) {
@Override
protected void updateModel(String text) {
setQueryName(text);
}
};
qualifier = new ValidatorTextAdapter(new JTextField()) {
@Override
protected void updateModel(String text) {
setQueryQualifier(text);
}
@Override
protected void validate(String text) throws ValidationException {
createQualifier(text);
}
};
comment = new TextAdapter(new JTextField()) {
@Override
protected void updateModel(String text) {
setQueryComment(text);
}
};
distinct = new JCayenneCheckBox();
properties = new ObjectQueryPropertiesPanel(mediator);
// assemble
CellConstraints cc = new CellConstraints();
FormLayout layout = new FormLayout("right:max(80dlu;pref), 3dlu, fill:200dlu", "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p");
PanelBuilder builder = new PanelBuilder(layout);
builder.setDefaultDialogBorder();
builder.addSeparator("SelectQuery Settings", cc.xywh(1, 1, 3, 1));
builder.addLabel("Query Name:", cc.xy(1, 3));
builder.add(name.getComponent(), cc.xy(3, 3));
builder.addLabel("Query Root:", cc.xy(1, 5));
builder.add(queryRoot, cc.xy(3, 5));
builder.addLabel("Qualifier:", cc.xy(1, 7));
builder.add(qualifier.getComponent(), cc.xy(3, 7));
builder.addLabel("Distinct:", cc.xy(1, 9));
builder.add(distinct, cc.xy(3, 9));
builder.addLabel("Comment:", cc.xy(1, 11));
builder.add(comment.getComponent(), cc.xy(3, 11));
this.setLayout(new BorderLayout());
this.add(builder.getPanel(), BorderLayout.NORTH);
this.add(properties, BorderLayout.CENTER);
}
Aggregations