Commit a3fbf344 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ project template provider improvements (include libraries, open main)

parent b62c915a
Loading
Loading
Loading
Loading
+42 −4
Original line number Diff line number Diff line
@@ -22,6 +22,13 @@ import org.etsi.mts.tdl.openapi2tdl.next.ConverterNext
import org.eclipse.ui.preferences.ScopedPreferenceStore
import org.eclipse.core.runtime.preferences.InstanceScope
import org.etsi.mts.tdl.ui.wizard.TemplateHelper.Libraries
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.core.resources.IFile
import org.eclipse.core.runtime.Path
import org.eclipse.core.runtime.IPath
import org.eclipse.ui.PlatformUI
import org.eclipse.ui.ide.IDE
import org.eclipse.swt.widgets.Display

/**
 * Create a list with all project templates to be shown in the template new project wizard.
@@ -126,6 +133,8 @@ final class TDLtxProject {
    val name = text("Main Package Name:", "Main", "The name of the main package")
	val path = text("Path:", "tdl", "The package path to place the files in", advancedGroup)
	//TODO: add other options
	val importStandard = check("Import Standard Library", true, "Import TDL standard library definitions.", advancedGroup)
	val importHTTP = check("Import HTTP Library", false, "Import TDL HTTP library definitions.", advancedGroup)

    @Inject
    PluginImageHelper pluginImageHelper
@@ -133,9 +142,13 @@ final class TDLtxProject {
	override protected updateVariables() {
		name.enabled = advanced.value
		path.enabled = advanced.value
		importStandard.enabled = advanced.value
		importHTTP.enabled = advanced.value
		if (!advanced.value) {
			name.value = "Main"
			path.value = "tdl"
			importStandard.value = true
			importHTTP.value = false
		}
	}

@@ -158,19 +171,44 @@ final class TDLtxProject {
			builderIds += #[XtextProjectHelper.BUILDER_ID]
			folders += "src"
			//TODO: remove hardcoded import
			var imports = ""
			if (importStandard.value) {
	            addFile('''src/«path»/Standard.tdltx''', TemplateHelper.getLibrary("Standard"))
	            imports += "Import all from Standard\n"
			}
			if (importHTTP.value) {
				addFile('''src/«path»/HTTP.tdltx''', TemplateHelper.getLibrary("HTTP"))
				imports += "Import all from HTTP\n"
				imports += "Import all from HTTP.MessageBased\n"
			}
			addFile('''src/«path»/«name».tdltx''', '''
				/*
				 * This is an example package
				 */
				Package «name» {
				    Import all from Standard
				    «imports»
				    //example type
				    Type float
				    //define elements here
				    //define additional elements here
				}
			''')
		])
		//TODO: make more robust and share among other templates
		open(projectInfo.projectName+"/src/"+path+"/"+name+".tdltx")		
	}
	
	private def open(String filePath) {
        val path = new Path(filePath)
		val ifile=ResourcesPlugin.getWorkspace().getRoot().getFile(path)
//        val page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		val page = PlatformUI.workbench.workbenchWindows.get(0).activePage
		Display.^default.asyncExec(new Runnable() {
			
			override run() {
				IDE.openEditor(page, ifile)
			}
			
        })
	}
	
    protected override List<Pair<String, Image>> getImages() {