Search in sources :

Example 1 with JavaInputGeneratorWrapper

use of com.devonfw.cobigen.eclipse.generator.java.JavaInputGeneratorWrapper in project cobigen by devonfw.

the class GenerateWizard method generateContents.

// @Override
// public boolean performFinish() {
// buildPage2Job.cancel();
// return super.performFinish();
// }
// 
// @Override
// public boolean performCancel() {
// buildPage2Job.cancel();
// return super.performCancel();
// }
/**
 * Generates the contents to be generated and reports the progress to the user
 *
 * @param dialog {@link ProgressMonitorDialog} which should be used for reporting the progress
 */
@Override
protected void generateContents(ProgressMonitorDialog dialog) {
    if (this.cobigenWrapper instanceof JavaInputGeneratorWrapper) {
        for (String attr : this.page2.getUncheckedAttributes()) {
            ((JavaInputGeneratorWrapper) this.cobigenWrapper).removeFieldFromModel(attr);
        }
    }
    LOG.info("Start generation process job...");
    GenerateSelectionJob job = new GenerateSelectionJob(this.cobigenWrapper, this.page1.getTemplatesToBeGenerated());
    try {
        dialog.run(true, true, job);
    } catch (InvocationTargetException e) {
        LOG.error("An internal error occured while invoking the generation job.", e);
    } catch (InterruptedException e) {
        LOG.warn("The working thread doing the generation job has been interrupted.", e);
    }
}
Also used : JavaInputGeneratorWrapper(com.devonfw.cobigen.eclipse.generator.java.JavaInputGeneratorWrapper) InvocationTargetException(java.lang.reflect.InvocationTargetException) GenerateSelectionJob(com.devonfw.cobigen.eclipse.wizard.generate.control.GenerateSelectionJob)

Example 2 with JavaInputGeneratorWrapper

use of com.devonfw.cobigen.eclipse.generator.java.JavaInputGeneratorWrapper in project cobigen by devonfw.

the class GeneratorWrapperFactory method createGenerator.

/**
 * Creates a generator dependent on the input of the selection
 *
 * @param selection current {@link IStructuredSelection} treated as input for generation
 * @param monitor tracking progress
 * @return a specific {@link CobiGenWrapper} instance
 * @throws GeneratorCreationException if any exception occurred during converting the inputs or creating the generator
 * @throws GeneratorProjectNotExistentException if the generator configuration project does not exist
 * @throws InvalidInputException if the selection includes non supported input types or is composed in a non supported
 *         combination of inputs.
 */
public static CobiGenWrapper createGenerator(ISelection selection, IProgressMonitor monitor) throws GeneratorCreationException, GeneratorProjectNotExistentException, InvalidInputException {
    List<Object> extractedInputs = extractValidEclipseInputs(selection);
    if (extractedInputs.size() > 0) {
        monitor.subTask("Initialize CobiGen instance");
        CobiGen cobigen = initializeGenerator();
        monitor.subTask("Reading inputs...");
        monitor.worked(10);
        Object firstElement = extractedInputs.get(0);
        if (firstElement instanceof IJavaElement) {
            LOG.info("Create new CobiGen instance for java inputs...");
            return new JavaInputGeneratorWrapper(cobigen, ((IJavaElement) firstElement).getJavaProject().getProject(), JavaInputConverter.convertInput(extractedInputs, cobigen), monitor);
        } else if (firstElement instanceof IResource) {
            LOG.info("Create new CobiGen instance for file inputs...");
            return new FileInputGeneratorWrapper(cobigen, ((IResource) firstElement).getProject(), FileInputConverter.convertInput(cobigen, extractedInputs), monitor);
        }
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaInputGeneratorWrapper(com.devonfw.cobigen.eclipse.generator.java.JavaInputGeneratorWrapper) CobiGen(com.devonfw.cobigen.api.CobiGen) FileInputGeneratorWrapper(com.devonfw.cobigen.eclipse.generator.generic.FileInputGeneratorWrapper) IResource(org.eclipse.core.resources.IResource)

Aggregations

JavaInputGeneratorWrapper (com.devonfw.cobigen.eclipse.generator.java.JavaInputGeneratorWrapper)2 CobiGen (com.devonfw.cobigen.api.CobiGen)1 FileInputGeneratorWrapper (com.devonfw.cobigen.eclipse.generator.generic.FileInputGeneratorWrapper)1 GenerateSelectionJob (com.devonfw.cobigen.eclipse.wizard.generate.control.GenerateSelectionJob)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IResource (org.eclipse.core.resources.IResource)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1