use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class DefaultDbImportAction method saveLoaded.
/**
* Save imported data.
* This can create DataMap and/or Project files.
*/
protected void saveLoaded(DataMap dataMap, DbImportConfiguration config) throws MalformedURLException {
ConfigurationTree<ConfigurationNode> projectRoot;
if (config.getCayenneProject() == null) {
// Old version of cdbimport, no Cayenne project, need to save only DataMap
projectRoot = new ConfigurationTree<>(dataMap);
} else {
// Cayenne project is present
DataChannelDescriptor dataChannelDescriptor;
if (config.getCayenneProject().exists()) {
// Cayenne project file exists, need to read it and push DataMap inside
URLResource configurationResource = new URLResource(config.getCayenneProject().toURI().toURL());
ConfigurationTree<DataChannelDescriptor> configurationTree = dataChannelDescriptorLoader.load(configurationResource);
if (!configurationTree.getLoadFailures().isEmpty()) {
throw new CayenneRuntimeException("Unable to load cayenne project %s, %s", config.getCayenneProject(), configurationTree.getLoadFailures().iterator().next().getDescription());
}
dataChannelDescriptor = configurationTree.getRootNode();
// remove old copy of DataMap if it's there
DataMap oldDataMap = dataChannelDescriptor.getDataMap(dataMap.getName());
if (oldDataMap != null) {
dataChannelDescriptor.getDataMaps().remove(oldDataMap);
}
} else {
// No project file yet, can simply create empty project with resulting DataMap
dataChannelDescriptor = new DataChannelDescriptor();
dataChannelDescriptor.setName(getProjectNameFromFileName(config.getCayenneProject().getName()));
dataChannelDescriptor.setConfigurationSource(new URLResource(config.getCayenneProject().toURI().toURL()));
logger.info("Project file does not exist. New project will be saved into '" + config.getCayenneProject().getAbsolutePath());
}
dataChannelDescriptor.getDataMaps().add(dataMap);
projectRoot = new ConfigurationTree<>(dataChannelDescriptor);
}
Project project = new Project(projectRoot);
projectSaver.save(project);
logger.info("");
logger.info("All changes saved.");
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class ObjAttributeTableModel method setObjAttributeType.
private void setObjAttributeType(ObjAttributeWrapper attribute, Object value) {
String oldType = attribute.getType();
String newType = value != null ? value.toString() : null;
attribute.setType(newType);
if (oldType == null || newType == null) {
return;
}
String[] registeredTypes = ModelerUtil.getRegisteredTypeNames();
Collection<String> registeredTypesList = Arrays.asList(registeredTypes);
if (registeredTypesList.contains(oldType) == registeredTypesList.contains(newType)) {
return;
}
ObjEntity entity = attribute.getEntity();
ObjAttribute attributeNew;
if (registeredTypesList.contains(newType) || !mediator.getEmbeddableNamesInCurrentDataDomain().contains(newType)) {
attributeNew = new ObjAttribute();
attributeNew.setDbAttributePath(attribute.getDbAttributePath());
} else {
attributeNew = new EmbeddedAttribute();
attributeNew.setDbAttributePath(null);
}
attributeNew.setName(attribute.getName());
attributeNew.setEntity(entity);
attributeNew.setParent(attribute.getParent());
attributeNew.setType(attribute.getType());
attributeNew.setUsedForLocking(attribute.isUsedForLocking());
entity.updateAttribute(attributeNew);
mediator.fireObjEntityEvent(new EntityEvent(this, entity, MapEvent.CHANGE));
mediator.fireObjEntityDisplayEvent(new EntityDisplayEvent(this, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
mediator.fireObjAttributeEvent(new AttributeEvent(this, attributeNew, entity, MapEvent.CHANGE));
mediator.fireObjAttributeDisplayEvent(new AttributeDisplayEvent(this, attributeNew, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class ObjEntityTab method initController.
private void initController() {
// initialize events processing and tracking of UI updates...
mediator.addObjEntityDisplayListener(this);
dbEntityCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Change DbEntity for current ObjEntity
ObjEntity entity = mediator.getCurrentObjEntity();
DbEntity dbEntity = (DbEntity) dbEntityCombo.getSelectedItem();
if (dbEntity != entity.getDbEntity()) {
entity.setDbEntity(dbEntity);
mediator.fireObjEntityEvent(new EntityEvent(this, entity));
}
}
});
superEntityCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Change super-entity
ObjEntity superEntity = (ObjEntity) superEntityCombo.getSelectedItem();
String name = (superEntity == null || superEntity == NO_INHERITANCE) ? null : superEntity.getName();
ObjEntity entity = mediator.getCurrentObjEntity();
if (!Util.nullSafeEquals(name, entity.getSuperEntityName())) {
List<ObjAttribute> duplicateAttributes = null;
if (name != null) {
duplicateAttributes = getDuplicatedAttributes(superEntity);
}
if (duplicateAttributes != null && duplicateAttributes.size() > 0) {
DuplicatedAttributesDialog.showDialog(Application.getFrame(), duplicateAttributes, superEntity, entity);
if (DuplicatedAttributesDialog.getResult().equals(DuplicatedAttributesDialog.CANCEL_RESULT)) {
superEntityCombo.setSelectedItem(entity.getSuperEntity());
superClassName.setText(entity.getSuperClassName());
return;
}
}
entity.setSuperEntityName(name);
// drop not valid dbAttributePath
if (name == null) {
for (ObjAttribute objAttribute : entity.getAttributes()) {
if (objAttribute.getDbAttribute() == null) {
objAttribute.setDbAttributePath(null);
}
}
}
if (name == null) {
dbEntityCombo.setEnabled(true);
} else {
dbEntityCombo.setEnabled(false);
dbEntityCombo.getModel().setSelectedItem(null);
}
// if a super-entity selected, disable table selection
// and also update parent DbEntity selection...
toggleEnabled(name == null, !serverOnly.isSelected());
dbEntityCombo.getModel().setSelectedItem(entity.getDbEntity());
superClassName.setText(entity.getSuperClassName());
// fire both EntityEvent and EntityDisplayEvent;
// the later is to update attribute and relationship display
DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
DataMap map = mediator.getCurrentDataMap();
mediator.fireObjEntityEvent(new EntityEvent(this, entity));
mediator.fireObjEntityDisplayEvent(new EntityDisplayEvent(this, entity, map, domain));
}
}
});
tableLabel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Jump to DbEntity of the current ObjEntity
DbEntity entity = mediator.getCurrentObjEntity().getDbEntity();
if (entity != null) {
DataChannelDescriptor dom = (DataChannelDescriptor) mediator.getProject().getRootNode();
mediator.fireDbEntityDisplayEvent(new EntityDisplayEvent(this, entity, entity.getDataMap(), dom));
}
}
});
readOnly.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
ObjEntity entity = mediator.getCurrentObjEntity();
if (entity != null) {
entity.setReadOnly(readOnly.isSelected());
mediator.fireObjEntityEvent(new EntityEvent(this, entity));
}
}
});
optimisticLocking.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
ObjEntity entity = mediator.getCurrentObjEntity();
if (entity != null) {
entity.setDeclaredLockType(optimisticLocking.isSelected() ? ObjEntity.LOCK_TYPE_OPTIMISTIC : ObjEntity.LOCK_TYPE_NONE);
mediator.fireObjEntityEvent(new EntityEvent(this, entity));
}
}
});
serverOnly.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
ObjEntity entity = mediator.getCurrentObjEntity();
if (entity != null) {
entity.setServerOnly(serverOnly.isSelected());
toggleEnabled(dbEntityCombo.isEnabled(), !serverOnly.isSelected());
mediator.fireObjEntityEvent(new EntityEvent(this, entity));
}
}
});
isAbstract.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
ObjEntity entity = mediator.getCurrentObjEntity();
if (entity != null) {
entity.setAbstract(isAbstract.isSelected());
mediator.fireObjEntityEvent(new EntityEvent(this, entity));
}
}
});
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class QueryType method fireQueryEvent.
/**
* Fires events when a query was added
*/
public static void fireQueryEvent(Object src, ProjectController mediator, DataMap dataMap, QueryDescriptor query) {
mediator.fireQueryEvent(new QueryEvent(src, query, MapEvent.ADD, dataMap));
mediator.fireQueryDisplayEvent(new QueryDisplayEvent(src, query, dataMap, (DataChannelDescriptor) mediator.getProject().getRootNode()));
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class ProcedureParameterErrorMsg method displayField.
public void displayField(ProjectController mediator, JFrame frame) {
Object object = super.validationFailure.getSource();
DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
ProcedureParameter procedureParameter = (ProcedureParameter) object;
Procedure procedure = procedureParameter.getProcedure();
DataMap map = procedure.getDataMap();
// Race condition between the two events...?
// first display the stored procedure
// for whatever reason, other validators do not require this step
// (E.g. DbAttributeErrorMsg)
ProcedureDisplayEvent procedureEvent = new ProcedureDisplayEvent(frame, procedure, map, domain);
procedureEvent.setTabReset(true);
mediator.fireProcedureDisplayEvent(procedureEvent);
// now show the failed parameter
ProcedureParameterDisplayEvent event = new ProcedureParameterDisplayEvent(frame, procedureParameter, procedure, map, domain);
event.setTabReset(true);
mediator.fireProcedureParameterDisplayEvent(event);
}
Aggregations