use of org.apache.cayenne.modeler.ProjectController in project cayenne by apache.
the class RemoveRelationshipAction method performAction.
@Override
public void performAction(ActionEvent e, boolean allowAsking) {
ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
ProjectController mediator = getProjectController();
ObjRelationship[] rels = getProjectController().getCurrentObjRelationships();
if (rels != null && rels.length > 0) {
if ((rels.length == 1 && dialog.shouldDelete("ObjRelationship", rels[0].getName())) || (rels.length > 1 && dialog.shouldDelete("selected ObjRelationships"))) {
ObjEntity entity = mediator.getCurrentObjEntity();
removeObjRelationships(entity, rels);
Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, rels));
}
} else {
DbRelationship[] dbRels = getProjectController().getCurrentDbRelationships();
if (dbRels != null && dbRels.length > 0) {
if ((dbRels.length == 1 && dialog.shouldDelete("DbRelationship", dbRels[0].getName())) || (dbRels.length > 1 && dialog.shouldDelete("selected DbRelationships"))) {
DbEntity entity = mediator.getCurrentDbEntity();
removeDbRelationships(entity, dbRels);
Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, dbRels));
}
}
}
}
use of org.apache.cayenne.modeler.ProjectController in project cayenne by apache.
the class AdapterEditor method setAdapterName.
public void setAdapterName(String name) {
if (node == null) {
return;
}
// ModelerDbAdapter adapter = new ModelerDbAdapter(name, node.getDataSource());
// adapter.validate();
node.setAdapterType(name);
DataNodeEvent e = new DataNodeEvent(AdapterEditor.this, node);
((ProjectController) getParent()).fireDataNodeEvent(e);
}
use of org.apache.cayenne.modeler.ProjectController in project cayenne by apache.
the class JDBCDataSourceEditor method syncDataSourceAction.
/**
* This action is called whenever the password location is changed
* in the GUI pulldown. It changes labels and editability of the
* password fields depending on the option that was selected.
*/
public void syncDataSourceAction() {
CayenneModelerController mainController = getApplication().getFrameController();
if (getNode() == null || getNode().getDataSourceDescriptor() == null) {
return;
}
DataSourceInfo projectDSI = getNode().getDataSourceDescriptor();
ProjectController parent = (ProjectController) getParent();
String key = parent.getDataNodePreferences().getLocalDataSource();
if (key == null) {
mainController.updateStatus("No Local DataSource selected for node...");
return;
}
DBConnectionInfo dataSource = (DBConnectionInfo) getApplication().getCayenneProjectPreferences().getDetailObject(DBConnectionInfo.class).getObject(key);
if (dataSource != null) {
if (dataSource.copyTo(projectDSI)) {
refreshView();
super.nodeChangeProcessor.modelUpdated(null, null, null);
mainController.updateStatus(null);
} else {
mainController.updateStatus("DataNode is up to date...");
}
} else {
mainController.updateStatus("Invalid Local DataSource selected for node...");
}
}
use of org.apache.cayenne.modeler.ProjectController 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.modeler.ProjectController in project cayenne by apache.
the class LockingUpdateController method updateAction.
public void updateAction() {
int defaultLockType = dataMap.getDefaultLockType();
boolean on = defaultLockType == ObjEntity.LOCK_TYPE_OPTIMISTIC;
boolean updateEntities = view.getEntities().isSelected();
boolean updateAttributes = view.getAttributes().isSelected();
boolean updateRelationships = view.getRelationships().isSelected();
ProjectController parent = (ProjectController) getParent();
for (ObjEntity entity : dataMap.getObjEntities()) {
if (updateEntities && defaultLockType != entity.getDeclaredLockType()) {
entity.setDeclaredLockType(defaultLockType);
parent.fireObjEntityEvent(new EntityEvent(this, entity));
}
if (updateAttributes) {
for (ObjAttribute a : entity.getAttributes()) {
if (a.isUsedForLocking() != on) {
a.setUsedForLocking(on);
parent.fireObjAttributeEvent(new AttributeEvent(this, a, entity));
}
}
}
if (updateRelationships) {
for (ObjRelationship r : entity.getRelationships()) {
if (r.isUsedForLocking() != on) {
r.setUsedForLocking(on);
parent.fireObjRelationshipEvent(new RelationshipEvent(this, r, entity));
}
}
}
}
if (view != null) {
view.dispose();
}
}
Aggregations