Search in sources :

Example 1 with JavaSource

use of com.centurylink.mdw.plugin.designer.model.JavaSource in project mdw-designer by CenturyLinkCloud.

the class CodeGenWizard method generateCode.

/**
 * @return true if registration should continue
 */
protected boolean generateCode(String jetFile, IProgressMonitor monitor) throws CoreException {
    String targetFolder;
    if (getCodeGenType() == CodeGenType.staticJavaCode) {
        targetFolder = getCodeElement().getPackageFragmentRoot().getPath().toString();
        String targetFile = getCodeElement().getClassName() + ".java";
        IPackageFragment packageFragment = getCodeElement().getPackageFragment();
        JetAccess jet = getJet(jetFile, targetFolder, targetFile, packageFragment);
        Generator generator = new Generator(getShell());
        generator.createFileAndOpen(getShell(), jet, monitor);
    } else if (getCodeGenType() == CodeGenType.dynamicJavaCode) {
        String pkgPath = getCodeElement().getPackage().getName().replace('.', '/');
        if (getCodeElement().getProject().isFilePersist())
            targetFolder = getCodeElement().getProject().getAssetFolder().getFullPath() + "/" + pkgPath;
        else
            targetFolder = getCodeElement().getProject().getTempFolder().getFullPath() + "/" + pkgPath;
        String targetFile = getCodeElement().getClassName() + ".java";
        getCodeElement().getProject().setJava();
        JavaSource javaAsset = createJavaAssetAndOpen(getCodeElement().getPackage(), jetFile, targetFolder, targetFile, monitor);
        return javaAsset != null;
    }
    return true;
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) JavaSource(com.centurylink.mdw.plugin.designer.model.JavaSource)

Example 2 with JavaSource

use of com.centurylink.mdw.plugin.designer.model.JavaSource in project mdw-designer by CenturyLinkCloud.

the class CodeGenWizard method createJavaAssetAndOpen.

protected JavaSource createJavaAssetAndOpen(WorkflowPackage workflowPackage, String jetFile, String targetFolder, String targetFile, IProgressMonitor monitor) throws CoreException {
    JetAccess jet = getJet(jetFile, targetFolder, targetFile);
    Generator generator = new Generator(getShell());
    IFile contentFile = generator.createFile(jet, monitor);
    WorkflowProject workflowProject = workflowPackage.getProject();
    JavaSource javaAsset = new JavaSource();
    javaAsset.setLanguage(RuleSetVO.JAVA);
    javaAsset.setName(contentFile.getName());
    javaAsset.setProject(workflowProject);
    javaAsset.setPackage(workflowPackage);
    String content = new String(PluginUtil.readFile(contentFile));
    javaAsset.setContent(content);
    contentFile.refreshLocal(IResource.DEPTH_ZERO, monitor);
    contentFile.delete(true, monitor);
    DesignerProxy designerProxy = javaAsset.getProject().getDesignerProxy();
    try {
        designerProxy.createNewWorkflowAsset(javaAsset, true);
    } catch (Exception ex) {
        PluginMessages.uiError(getShell(), ex, "New " + javaAsset.getTitle(), javaAsset.getProject());
        return null;
    }
    if (designerProxy.getRunnerStatus().equals(RunnerStatus.SUCCESS)) {
        javaAsset.openFile(new NullProgressMonitor());
        javaAsset.addElementChangeListener(javaAsset.getProject());
        javaAsset.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, javaAsset);
        WorkflowAssetFactory.registerAsset(javaAsset);
        return javaAsset;
    } else {
        return null;
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) JavaSource(com.centurylink.mdw.plugin.designer.model.JavaSource) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with JavaSource

use of com.centurylink.mdw.plugin.designer.model.JavaSource in project mdw-designer by CenturyLinkCloud.

the class ProjectConfigurator method loadJavaLibraries.

public void loadJavaLibraries(IProgressMonitor monitor) {
    // locally save all the Java libraries
    for (WorkflowAsset asset : project.getTopLevelWorkflowAssets()) {
        if (asset instanceof JavaSource) {
            if (!asset.isLoaded())
                asset.load();
            try {
                IFolder folder = asset.getTempFolder();
                if (!folder.exists())
                    PluginUtil.createFoldersAsNeeded(project.getSourceProject(), folder, monitor);
                IFile tempFile = asset.getTempFile(folder);
                if (tempFile.exists())
                    new TempFileRemover(folder, tempFile).remove(monitor);
                tempFile.create(new ByteArrayInputStream(asset.getFileContent()), true, monitor);
                PluginMessages.log("Created Java lib file: " + tempFile.getFullPath().toString());
            } catch (CoreException ex) {
                PluginMessages.uiError(ex, "Load Java Libraries", project);
            }
        }
    }
}
Also used : TempFileRemover(com.centurylink.mdw.plugin.workspace.TempFileRemover) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) JavaSource(com.centurylink.mdw.plugin.designer.model.JavaSource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

JavaSource (com.centurylink.mdw.plugin.designer.model.JavaSource)3 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 DesignerProxy (com.centurylink.mdw.plugin.designer.DesignerProxy)1 WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)1 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)1 TempFileRemover (com.centurylink.mdw.plugin.workspace.TempFileRemover)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IFolder (org.eclipse.core.resources.IFolder)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1