use of com.twinsoft.convertigo.beans.references.ProjectSchemaReference in project convertigo by convertigo.
the class ProjectTreeObject method treeObjectRemoved.
@Override
public void treeObjectRemoved(TreeObjectEvent treeObjectEvent) {
super.treeObjectRemoved(treeObjectEvent);
TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
if (!(treeObject.equals(this)) && (treeObject.getParents().contains(this))) {
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
String dboName = databaseObject.getName();
// Case of a connector deletion
if (databaseObject instanceof Connector) {
// connector in this project
if (treeObject.getProjectTreeObject().equals(this)) {
String path = Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME;
IFolder parentFolder = getProjectTreeObject().getFolder(path);
IFolder folder = parentFolder.getFolder(dboName);
if (folder.exists()) {
IPath folderPath = folder.getLocation().makeAbsolute();
try {
// delete folder
folder.delete(true, null);
// refresh folder
parentFolder.refreshLocal(IResource.DEPTH_ONE, null);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not delete folder \"" + folderPath + "\"!");
}
}
}
} else // Case of a transaction deletion
if (databaseObject instanceof Transaction) {
// transaction in this project
if (treeObject.getProjectTreeObject().equals(this)) {
String path = Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME;
ConnectorTreeObject cto = ((TransactionTreeObject) treeObject).getConnectorTreeObject();
IFolder parentFolder = getProjectTreeObject().getFolder(path).getFolder(cto.getName());
IFile file = parentFolder.getFile(dboName + ".xsd");
if (file.exists()) {
IPath filePath = file.getLocation().makeAbsolute();
try {
// delete file
file.delete(true, null);
// refresh folder
parentFolder.refreshLocal(IResource.DEPTH_ONE, null);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not delete file \"" + filePath + "\"!");
}
}
}
} else if (databaseObject instanceof ProjectSchemaReference) {
checkMissingProjects(false);
}
// Clear schema cache
if (this.equals(treeObject.getProjectTreeObject())) {
Engine.theApp.schemaManager.clearCache(getName());
}
}
}
}
use of com.twinsoft.convertigo.beans.references.ProjectSchemaReference in project convertigo by convertigo.
the class ReferenceTreeObject method handlesBeanNameChanged.
protected void handlesBeanNameChanged(TreeObjectEvent treeObjectEvent) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
int update = treeObjectEvent.update;
// Updates project name references
if (update != TreeObjectEvent.UPDATE_NONE) {
boolean isLocalProject = false;
boolean isSameValue = false;
boolean shouldUpdate = false;
if (getObject() instanceof ProjectSchemaReference) {
ProjectSchemaReference reference = (ProjectSchemaReference) getObject();
// Case of project rename
if (databaseObject instanceof Project) {
isLocalProject = reference.getProject().equals(databaseObject);
isSameValue = reference.getParser().getProjectName().equals(oldValue);
shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
if (isSameValue && shouldUpdate) {
reference.setProjectName((String) newValue);
hasBeenModified(true);
viewer.refresh();
// refresh editors (e.g labels in combobox)
getDescriptors();
}
}
}
}
}
use of com.twinsoft.convertigo.beans.references.ProjectSchemaReference in project convertigo by convertigo.
the class XmlSchemaBuilder method preBuildSchema.
private void preBuildSchema() throws EngineException {
try {
schema.setElementFormDefault(new XmlSchemaForm(project.getSchemaElementForm().name()));
schema.setAttributeFormDefault(new XmlSchemaForm(project.getSchemaElementForm().name()));
ConvertigoError.addXmlSchemaObjects(schema);
EngineStatistics.addXmlSchemaObjects(schema);
// static and read-only generation : references, transactions, sequences declaration
new WalkHelper() {
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
if (databaseObject instanceof ISchemaGenerator) {
// generate itself and add to the caller list
if (databaseObject instanceof ISchemaImportGenerator) {
// Import case
if (databaseObject instanceof ProjectSchemaReference) {
// done further in buildSchema
} else {
XmlSchemaImport schemaImport = ((ISchemaImportGenerator) databaseObject).getXmlSchemaObject(collection, schema);
if (schemaImport != null) {
SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaImport);
XmlSchemaUtils.add(schema, schemaImport);
}
}
} else if (databaseObject instanceof ISchemaIncludeGenerator) {
// Include case
if (databaseObject instanceof Transaction) {
XmlSchemaInclude schemaInclude = ((ISchemaIncludeGenerator) databaseObject).getXmlSchemaObject(collection, schema);
addSchemaIncludeObjects(databaseObject, schemaInclude.getSchema());
} else {
XmlSchemaInclude schemaInclude = ((ISchemaIncludeGenerator) databaseObject).getXmlSchemaObject(collection, schema);
SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaInclude);
XmlSchemaUtils.add(schema, schemaInclude);
}
} else if (databaseObject instanceof Sequence) {
// Sequence case
XmlSchemaElement element = ((Sequence) databaseObject).getXmlSchemaObject(collection, schema);
SchemaMeta.setXmlSchemaObject(schema, databaseObject, element);
XmlSchemaUtils.add(schema, element);
}
} else {
// doesn't generate schema, just deep walk
super.walk(databaseObject);
}
}
@Override
protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
// just walk references, transactions, sequences declaration
return Step.class.isAssignableFrom(dboClass) || Transaction.class.isAssignableFrom(dboClass) || Sequence.class.isAssignableFrom(dboClass) || Reference.class.isAssignableFrom(dboClass) || Connector.class.isAssignableFrom(dboClass);
}
protected void addSchemaIncludeObjects(DatabaseObject databaseObject, XmlSchema xmlSchema) {
if (xmlSchema != null) {
XmlSchemaObjectCollection c = xmlSchema.getItems();
Iterator<XmlSchemaObject> it = GenericUtils.cast(c.getIterator());
while (it.hasNext()) {
XmlSchemaObject xmlSchemaObject = it.next();
SchemaMeta.getReferencedDatabaseObjects(xmlSchemaObject).add(databaseObject);
if (xmlSchemaObject instanceof XmlSchemaImport) {
// ignore
} else if (xmlSchemaObject instanceof XmlSchemaInclude) {
XmlSchemaInclude schemaInclude = (XmlSchemaInclude) xmlSchemaObject;
addSchemaIncludeObjects(databaseObject, schemaInclude.getSchema());
} else if (xmlSchemaObject instanceof XmlSchemaAttribute) {
XmlSchemaAttribute attribute = (XmlSchemaAttribute) xmlSchemaObject;
if (schema.getAttributes().getItem(attribute.getQName()) == null) {
schema.getAttributes().add(attribute.getQName(), attribute);
schema.getItems().add(attribute);
}
} else if (xmlSchemaObject instanceof XmlSchemaAttributeGroup) {
XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup) xmlSchemaObject;
if (schema.getAttributeGroups().getItem(attributeGroup.getName()) == null) {
schema.getAttributeGroups().add(attributeGroup.getName(), attributeGroup);
schema.getItems().add(attributeGroup);
}
} else if (xmlSchemaObject instanceof XmlSchemaGroup) {
XmlSchemaGroup group = (XmlSchemaGroup) xmlSchemaObject;
if (schema.getGroups().getItem(group.getName()) == null) {
schema.getGroups().add(group.getName(), group);
schema.getItems().add(group);
}
} else if (xmlSchemaObject instanceof XmlSchemaElement) {
XmlSchemaElement element = (XmlSchemaElement) xmlSchemaObject;
if (collection.getElementByQName(element.getQName()) == null && schema.getElementByName(element.getQName()) == null) {
schema.getElements().add(element.getQName(), element);
schema.getItems().add(element);
}
} else if (xmlSchemaObject instanceof XmlSchemaType) {
XmlSchemaType schemaType = (XmlSchemaType) xmlSchemaObject;
if (collection.getTypeByQName(schemaType.getQName()) == null && schema.getTypeByName(schemaType.getQName()) == null) {
schema.addType(schemaType);
schema.getItems().add(schemaType);
}
} else {
schema.getItems().add(xmlSchemaObject);
}
}
}
}
}.init(project);
} catch (Exception e) {
throw new EngineException("preBuildSchema failed", e);
}
}
use of com.twinsoft.convertigo.beans.references.ProjectSchemaReference in project convertigo by convertigo.
the class ProjectSchemaWizardPage method initialize.
private void initialize() {
if (parentObject instanceof Project) {
Project project = (Project) parentObject;
List<String> projectList = new ArrayList<String>();
projectList.add(project.getName());
List<Reference> references = project.getReferenceList();
for (Reference reference : references) {
if (reference instanceof ProjectSchemaReference) {
projectList.add(((ProjectSchemaReference) reference).getParser().getProjectName());
}
}
for (String name : Engine.theApp.databaseObjectsManager.getAllProjectNamesList()) {
if (!projectList.contains(name)) {
TreeItem branch = new TreeItem(tree, SWT.NONE);
branch.setText(name);
}
}
tree.setVisible(true);
} else
tree.setVisible(false);
}
use of com.twinsoft.convertigo.beans.references.ProjectSchemaReference in project convertigo by convertigo.
the class ReferencedProjectManager method getReferenceFromProject.
public ProjectSchemaReference getReferenceFromProject(Project project, String projectName) throws EngineException {
ProjectSchemaReference prjRef = null;
for (Reference ref : project.getReferenceList()) {
if (ref instanceof ProjectSchemaReference) {
prjRef = (ProjectSchemaReference) ref;
if (projectName.equals(prjRef.getParser().getProjectName())) {
break;
} else {
prjRef = null;
}
}
}
if (prjRef == null) {
prjRef = new ProjectSchemaReference();
if (projectName.startsWith("mobilebuilder_tpl_")) {
prjRef.setProjectName(projectName + "=https://github.com/convertigo/c8oprj-mobilebuilder-tpl/archive/" + projectName + ".zip");
} else {
prjRef.setProjectName(projectName);
}
project.add(prjRef);
project.changed();
project.hasChanged = true;
}
return prjRef;
}
Aggregations