Search in sources :

Example 11 with ValidationException

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());
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ValidationException(org.apache.cayenne.validation.ValidationException) Expression(org.apache.cayenne.exp.Expression) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ExpressionConvertor(org.apache.cayenne.modeler.util.ExpressionConvertor)

Example 12 with ValidationException

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);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) Insets(java.awt.Insets) ValidationException(org.apache.cayenne.validation.ValidationException) TextAdapter(org.apache.cayenne.modeler.util.TextAdapter) JButton(javax.swing.JButton) JToolBar(javax.swing.JToolBar) JTextField(javax.swing.JTextField) ActionManager(org.apache.cayenne.modeler.action.ActionManager) BorderLayout(java.awt.BorderLayout) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) JCayenneCheckBox(org.apache.cayenne.swing.components.JCayenneCheckBox)

Example 13 with ValidationException

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.");
    }
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ProcedureQueryDescriptor(org.apache.cayenne.map.ProcedureQueryDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) DataMap(org.apache.cayenne.map.DataMap)

Example 14 with ValidationException

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());
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) ValidationException(org.apache.cayenne.validation.ValidationException) Expression(org.apache.cayenne.exp.Expression) SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor) ExpressionConvertor(org.apache.cayenne.modeler.util.ExpressionConvertor)

Example 15 with ValidationException

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);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) ValidatorTextAdapter(org.apache.cayenne.modeler.util.ValidatorTextAdapter) ValidationException(org.apache.cayenne.validation.ValidationException) BorderLayout(java.awt.BorderLayout) ValidatorTextAdapter(org.apache.cayenne.modeler.util.ValidatorTextAdapter) TextAdapter(org.apache.cayenne.modeler.util.TextAdapter) JCayenneCheckBox(org.apache.cayenne.swing.components.JCayenneCheckBox) JTextField(javax.swing.JTextField) CellConstraints(com.jgoodies.forms.layout.CellConstraints)

Aggregations

ValidationException (org.apache.cayenne.validation.ValidationException)20 FormLayout (com.jgoodies.forms.layout.FormLayout)5 BorderLayout (java.awt.BorderLayout)5 JTextField (javax.swing.JTextField)5 TextAdapter (org.apache.cayenne.modeler.util.TextAdapter)5 DefaultFormBuilder (com.jgoodies.forms.builder.DefaultFormBuilder)4 DataMap (org.apache.cayenne.map.DataMap)4 JLabel (javax.swing.JLabel)3 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)3 QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)3 Expression (org.apache.cayenne.exp.Expression)3 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)3 EntityEvent (org.apache.cayenne.map.event.EntityEvent)3 ExpressionConvertor (org.apache.cayenne.modeler.util.ExpressionConvertor)3 JCayenneCheckBox (org.apache.cayenne.swing.components.JCayenneCheckBox)3 Test (org.junit.Test)3 JButton (javax.swing.JButton)2 JPanel (javax.swing.JPanel)2 JToolBar (javax.swing.JToolBar)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2