Search in sources :

Example 11 with ProjectSchemaReference

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());
            }
        }
    }
}
Also used : CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) IFile(org.eclipse.core.resources.IFile) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) IPath(org.eclipse.core.runtime.IPath) Transaction(com.twinsoft.convertigo.beans.core.Transaction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) EngineException(com.twinsoft.convertigo.engine.EngineException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) IFolder(org.eclipse.core.resources.IFolder)

Example 12 with ProjectSchemaReference

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();
                }
            }
        }
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 13 with ProjectSchemaReference

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);
    }
}
Also used : ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Step(com.twinsoft.convertigo.beans.core.Step) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) XMLCopyStep(com.twinsoft.convertigo.beans.steps.XMLCopyStep) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) Iterator(java.util.Iterator) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection) ISchemaIncludeGenerator(com.twinsoft.convertigo.beans.core.ISchemaIncludeGenerator) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Reference(com.twinsoft.convertigo.beans.core.Reference) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) XmlSchemaAttributeGroup(org.apache.ws.commons.schema.XmlSchemaAttributeGroup) XmlSchemaForm(org.apache.ws.commons.schema.XmlSchemaForm) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) Sequence(com.twinsoft.convertigo.beans.core.Sequence) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) XmlSchemaGroup(org.apache.ws.commons.schema.XmlSchemaGroup) Transaction(com.twinsoft.convertigo.beans.core.Transaction) XmlSchema(org.apache.ws.commons.schema.XmlSchema) ISchemaImportGenerator(com.twinsoft.convertigo.beans.core.ISchemaImportGenerator) XmlSchemaInclude(org.apache.ws.commons.schema.XmlSchemaInclude) ISchemaGenerator(com.twinsoft.convertigo.beans.core.ISchemaGenerator)

Example 14 with ProjectSchemaReference

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);
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) TreeItem(org.eclipse.swt.widgets.TreeItem) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) Reference(com.twinsoft.convertigo.beans.core.Reference) ArrayList(java.util.ArrayList)

Example 15 with ProjectSchemaReference

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;
}
Also used : ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) Reference(com.twinsoft.convertigo.beans.core.Reference) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference)

Aggregations

ProjectSchemaReference (com.twinsoft.convertigo.beans.references.ProjectSchemaReference)16 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)9 Reference (com.twinsoft.convertigo.beans.core.Reference)9 Project (com.twinsoft.convertigo.beans.core.Project)8 RequestableStep (com.twinsoft.convertigo.beans.core.RequestableStep)4 Sequence (com.twinsoft.convertigo.beans.core.Sequence)4 Transaction (com.twinsoft.convertigo.beans.core.Transaction)4 ArrayList (java.util.ArrayList)4 Step (com.twinsoft.convertigo.beans.core.Step)3 SequenceStep (com.twinsoft.convertigo.beans.steps.SequenceStep)3 TransactionStep (com.twinsoft.convertigo.beans.steps.TransactionStep)3 EngineException (com.twinsoft.convertigo.engine.EngineException)3 CouchDbConnector (com.twinsoft.convertigo.beans.connectors.CouchDbConnector)2 Connector (com.twinsoft.convertigo.beans.core.Connector)2 ISchemaGenerator (com.twinsoft.convertigo.beans.core.ISchemaGenerator)2 ISchemaImportGenerator (com.twinsoft.convertigo.beans.core.ISchemaImportGenerator)2 XMLCopyStep (com.twinsoft.convertigo.beans.steps.XMLCopyStep)2 ConvertigoException (com.twinsoft.convertigo.engine.ConvertigoException)2 ProjectUrlParser (com.twinsoft.convertigo.engine.util.ProjectUrlParser)2 Iterator (java.util.Iterator)2