Search in sources :

Example 16 with ValidationException

use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.

the class MainDataNodeEditor method setNodeName.

public void setNodeName(String newName) {
    if (node == null) {
        return;
    }
    // validate...
    if (newName == null) {
        throw new ValidationException("Empty DataNode Name");
    }
    ProjectController parent = (ProjectController) getParent();
    DataNodeDefaults oldPref = parent.getDataNodePreferences();
    DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) getApplication().getProject().getRootNode();
    Collection<DataNodeDescriptor> matchingNode = dataChannelDescriptor.getNodeDescriptors();
    Iterator<DataNodeDescriptor> it = matchingNode.iterator();
    while (it.hasNext()) {
        DataNodeDescriptor node = it.next();
        if (node.getName().equals(newName)) {
            // there is an entity with the same name
            throw new ValidationException("There is another DataNode named '" + newName + "'. Use a different name.");
        }
    }
    // passed validation, set value...
    // TODO: fixme....there is a slight chance that domain is different than
    // the one
    // cached node belongs to
    ProjectUtil.setDataNodeName((DataChannelDescriptor) parent.getProject().getRootNode(), node, newName);
    oldPref.copyPreferences(newName);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataNodeDefaults(org.apache.cayenne.modeler.pref.DataNodeDefaults) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 17 with ValidationException

use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.

the class PKCustomSequenceGeneratorPanel method initView.

private void initView() {
    JLabel note = new JLabel("* Custom sequences are supported on Oracle and Postgres");
    note.setFont(note.getFont().deriveFont(Font.ITALIC).deriveFont(11f));
    customPKName = new TextAdapter(new JTextField()) {

        protected void updateModel(String text) throws ValidationException {
            setPKName(text);
        }
    };
    customPKSize = new TextAdapter(new JTextField()) {

        protected void updateModel(String text) throws ValidationException {
            setPKSize(text);
        }
    };
    // assemble
    DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("right:70dlu, 3dlu, 20dlu, 3dlu, fill:177dlu", ""));
    builder.setDefaultDialogBorder();
    builder.append("Sequence Name:", customPKName.getComponent(), 3);
    builder.append("Cached PK Size:", customPKSize.getComponent());
    builder.nextLine();
    builder.append("", note, 3);
    setLayout(new BorderLayout());
    add(builder.getPanel(), BorderLayout.CENTER);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) ValidationException(org.apache.cayenne.validation.ValidationException) BorderLayout(java.awt.BorderLayout) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) TextAdapter(org.apache.cayenne.modeler.util.TextAdapter) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField)

Example 18 with ValidationException

use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.

the class PKCustomSequenceGeneratorPanel method setPKSize.

protected void setPKSize(String text) {
    if (mediator.getCurrentDbEntity() == null || mediator.getCurrentDbEntity().getPrimaryKeyGenerator() == null) {
        return;
    }
    int cacheSize = 0;
    if (text != null && text.trim().length() > 0) {
        try {
            cacheSize = Integer.parseInt(text);
        } catch (NumberFormatException nfex) {
            throw new ValidationException("Invalid number");
        }
    }
    DbKeyGenerator generator = mediator.getCurrentDbEntity().getPrimaryKeyGenerator();
    if (!Util.nullSafeEquals(generator.getKeyCacheSize(), new Integer(cacheSize))) {
        generator.setKeyCacheSize(new Integer(cacheSize));
        mediator.fireDbEntityEvent(new EntityEvent(this, generator.getDbEntity()));
    }
}
Also used : ValidationException(org.apache.cayenne.validation.ValidationException) EntityEvent(org.apache.cayenne.map.event.EntityEvent) DbKeyGenerator(org.apache.cayenne.map.DbKeyGenerator)

Example 19 with ValidationException

use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.

the class BaseQueryMainTab method setQueryName.

/**
 * Initializes Query name from string.
 */
void setQueryName(String newName) {
    if (newName != null && newName.trim().length() == 0) {
        newName = null;
    }
    QueryDescriptor query = getQuery();
    if (query == null) {
        return;
    }
    if (Util.nullSafeEquals(newName, query.getName())) {
        return;
    }
    if (newName == null) {
        throw new ValidationException("SelectQuery name is required.");
    }
    DataMap map = mediator.getCurrentDataMap();
    QueryDescriptor matchingQuery = map.getQueryDescriptor(newName);
    if (matchingQuery == null) {
        // completely new name, set new name for entity
        QueryEvent e = new QueryEvent(this, query, query.getName());
        ProjectUtil.setQueryName(map, query, newName);
        mediator.fireQueryEvent(e);
    } else if (matchingQuery != query) {
        // 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) ValidationException(org.apache.cayenne.validation.ValidationException) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) DataMap(org.apache.cayenne.map.DataMap)

Example 20 with ValidationException

use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.

the class DataMapView method initView.

private void initView() {
    // create widgets
    name = new TextAdapter(new JTextField()) {

        protected void updateModel(String text) {
            setDataMapName(text);
        }
    };
    location = new JLabel();
    nodeSelector = Application.getWidgetFactory().createUndoableComboBox();
    nodeSelector.setRenderer(CellRenderers.listRendererWithIcons());
    updateDefaultCatalog = new JButton("Update...");
    defaultCatalog = new TextAdapter(new JTextField()) {

        protected void updateModel(String text) {
            setDefaultCatalog(text);
        }
    };
    updateDefaultSchema = new JButton("Update...");
    defaultSchema = new TextAdapter(new JTextField()) {

        protected void updateModel(String text) {
            setDefaultSchema(text);
        }
    };
    quoteSQLIdentifiers = new JCayenneCheckBox();
    comment = new TextAdapter(new JTextField()) {

        @Override
        protected void updateModel(String text) throws ValidationException {
            updateComment(text);
        }
    };
    updateDefaultPackage = new JButton("Update...");
    defaultPackage = new TextAdapter(new JTextField()) {

        protected void updateModel(String text) {
            setDefaultPackage(text);
        }
    };
    updateDefaultSuperclass = new JButton("Update...");
    defaultSuperclass = new TextAdapter(new JTextField()) {

        protected void updateModel(String text) {
            setDefaultSuperclass(text);
        }
    };
    updateDefaultLockType = new JButton("Update...");
    defaultLockType = new JCayenneCheckBox();
    clientSupport = new JCayenneCheckBox();
    updateDefaultClientPackage = new JButton("Update...");
    defaultClientPackage = new TextAdapter(new JTextField()) {

        protected void updateModel(String text) {
            setDefaultClientPackage(text);
        }
    };
    updateDefaultClientSuperclass = new JButton("Update...");
    defaultClientSuperclass = new TextAdapter(new JTextField()) {

        protected void updateModel(String text) {
            setDefaultClientSuperclass(text);
        }
    };
    // assemble
    FormLayout layout = new FormLayout("right:70dlu, 3dlu, fill:180dlu, 3dlu, fill:120", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();
    builder.appendSeparator("DataMap Configuration");
    builder.append("DataMap Name:", name.getComponent(), 2);
    builder.append("File:", location, 3);
    builder.append("DataNode:", nodeSelector, 2);
    builder.append("Quote SQL Identifiers:", quoteSQLIdentifiers, 3);
    builder.append("Comment:", comment.getComponent(), 2);
    builder.appendSeparator("Entity Defaults");
    builder.append("DB Catalog:", defaultCatalog.getComponent(), updateDefaultCatalog);
    builder.append("DB Schema:", defaultSchema.getComponent(), updateDefaultSchema);
    builder.append("Java Package:", defaultPackage.getComponent(), updateDefaultPackage);
    builder.append("Custom Superclass:", defaultSuperclass.getComponent(), updateDefaultSuperclass);
    builder.append("Optimistic Locking:", defaultLockType, updateDefaultLockType);
    builder.appendSeparator("Client Class Defaults");
    builder.append("Allow Client Entities:", clientSupport, new JPanel());
    defaultClientPackageLabel = builder.append("Client Java Package:", defaultClientPackage.getComponent(), updateDefaultClientPackage);
    defaultClientSuperclassLabel = builder.append("Custom Superclass:", defaultClientSuperclass.getComponent(), updateDefaultClientSuperclass);
    this.setLayout(new BorderLayout());
    add(builder.getPanel(), BorderLayout.CENTER);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JPanel(javax.swing.JPanel) ValidationException(org.apache.cayenne.validation.ValidationException) BorderLayout(java.awt.BorderLayout) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) TextAdapter(org.apache.cayenne.modeler.util.TextAdapter) JButton(javax.swing.JButton) JCayenneCheckBox(org.apache.cayenne.swing.components.JCayenneCheckBox) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField)

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