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);
}
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);
}
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()));
}
}
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.");
}
}
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);
}
Aggregations