This repository has been archived by the owner on Apr 21, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#1259] Statemachine example: add New Project Wizard/New File Wizard.
- Extend the org.eclipse.xtext.ui.wizard.template.AbstractProjectTemplate class by the List<Pair<String, Image>> getImages API method to be able toto register images that can be used in the template descriptions. - Add new project wizard / new file wizard to the Xtext Statemachine Example to demonstrate the usage of the API. Signed-off-by: Tamas Miklossy <miklossy@itemis.de>
- Loading branch information
Showing
22 changed files
with
665 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
...xt.xtext.ui.examples/projects/fowlerdsl/org.eclipse.xtext.example.fowlerdsl.ui/.classpath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...xt.ui.examples/projects/fowlerdsl/org.eclipse.xtext.example.fowlerdsl.ui/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| source.. = src/,\ | ||
| src-gen/ | ||
| src-gen/,\ | ||
| xtend-gen/ | ||
| bin.includes = META-INF/,\ | ||
| .,\ | ||
| plugin.xml,\ | ||
| icons/,\ | ||
| templates/ |
Binary file added
BIN
+30.6 KB
...dsl/org.eclipse.xtext.example.fowlerdsl.ui/icons/mrsgrantssecretcompartment.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.73 KB
...owlerdsl/org.eclipse.xtext.example.fowlerdsl.ui/icons/new_Statemachine_proj.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+493 Bytes
...cts/fowlerdsl/org.eclipse.xtext.example.fowlerdsl.ui/icons/project_template.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...text.example.fowlerdsl.ui/src/org/eclipse/xtext/example/fowlerdsl/ui/wizard/Messages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package org.eclipse.xtext.example.fowlerdsl.ui.wizard; | ||
|
|
||
| import org.eclipse.osgi.util.NLS; | ||
|
|
||
| public class Messages extends NLS { | ||
| private static final String BUNDLE_NAME = "org.eclipse.xtext.example.fowlerdsl.ui.wizard.messages"; //$NON-NLS-1$ | ||
|
|
||
| public static String StatemachineProject_Label; | ||
| public static String StatemachineProject_Description; | ||
| public static String MrsGrantsSecretCompartments_Label; | ||
| public static String MrsGrantsSecretCompartments_Description; | ||
| public static String MrsGrantsSecretCompartmentsFile_Label; | ||
| public static String MrsGrantsSecretCompartmentsFile_Description; | ||
| public static String MrsGrantsSecretCompartmentsProject_Label; | ||
| public static String MrsGrantsSecretCompartmentsProject_Description; | ||
| public static String EmptyFile_Label; | ||
| public static String EmptyFile_Description; | ||
|
|
||
| static { | ||
| // initialize resource bundle | ||
| NLS.initializeMessages(BUNDLE_NAME, Messages.class); | ||
| } | ||
|
|
||
| private Messages() { | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
.../src/org/eclipse/xtext/example/fowlerdsl/ui/wizard/StatemachineFileTemplateProvider.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2019 itemis AG (http://www.itemis.eu) and others. | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License v1.0 | ||
| * which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-v10.html | ||
| *******************************************************************************/ | ||
| package org.eclipse.xtext.example.fowlerdsl.ui.wizard | ||
|
|
||
| import org.eclipse.xtext.ui.wizard.template.FileTemplate | ||
| import org.eclipse.xtext.ui.wizard.template.IFileGenerator | ||
| import org.eclipse.xtext.ui.wizard.template.IFileTemplateProvider | ||
|
|
||
| /** | ||
| * Create a list with all file templates to be shown in the template new file wizard. | ||
| * | ||
| * Each template is able to generate one or more files. | ||
| * | ||
| * @author miklossy - Initial contribution and API | ||
| */ | ||
| class StatemachineFileTemplateProvider implements IFileTemplateProvider { | ||
| override getFileTemplates() { | ||
| #[new EmptyFile, new MrsGrantsSecretCompartmentsFile] | ||
| } | ||
| } | ||
|
|
||
| @FileTemplate(label="Empty Statemachine", icon="file_template.png", description="Empty Statemachine") | ||
| final class EmptyFile { | ||
|
|
||
| override generateFiles(IFileGenerator generator) { | ||
| generator.generate('''«folder»/«name».statemachine''', '''''') | ||
| } | ||
| } | ||
|
|
||
| @FileTemplate(label="Mrs Grant's Secret Compartments", icon="file_template.png", description="Mrs Grant's Secret Compartments") | ||
| final class MrsGrantsSecretCompartmentsFile { | ||
|
|
||
| override generateFiles(IFileGenerator generator) { | ||
| generator.generate('''«folder»/«name».statemachine''', TemplateContent.MrsGrantsSecretCompartments) | ||
| } | ||
| } |
80 changes: 80 additions & 0 deletions
80
...c/org/eclipse/xtext/example/fowlerdsl/ui/wizard/StatemachineProjectTemplateProvider.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2019 itemis AG (http://www.itemis.eu) and others. | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License v1.0 | ||
| * which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-v10.html | ||
| *******************************************************************************/ | ||
| package org.eclipse.xtext.example.fowlerdsl.ui.wizard | ||
|
|
||
| import java.util.List | ||
| import org.eclipse.core.runtime.Status | ||
| import org.eclipse.jdt.core.JavaCore | ||
| import org.eclipse.swt.graphics.Image | ||
| import org.eclipse.xtext.example.fowlerdsl.ui.internal.FowlerdslActivator | ||
| import org.eclipse.xtext.ui.PluginImageHelper | ||
| import org.eclipse.xtext.ui.XtextProjectHelper | ||
| import org.eclipse.xtext.ui.util.PluginProjectFactory | ||
| import org.eclipse.xtext.ui.wizard.template.IProjectGenerator | ||
| import org.eclipse.xtext.ui.wizard.template.IProjectTemplateProvider | ||
| import org.eclipse.xtext.ui.wizard.template.ProjectTemplate | ||
|
|
||
| import static org.eclipse.core.runtime.IStatus.* | ||
|
|
||
| /** | ||
| * Create a list with all project templates to be shown in the template new project wizard. | ||
| * | ||
| * Each template is able to generate one or more projects. Each project can be configured such that any number of files are included. | ||
| * | ||
| * @author miklossy - Initial contribution and API | ||
| */ | ||
| class StatemachineProjectTemplateProvider implements IProjectTemplateProvider { | ||
|
|
||
| override getProjectTemplates() { | ||
| #[new MrsGrantsSecretCompartmentsProject] | ||
| } | ||
| } | ||
|
|
||
| @ProjectTemplate(label="Mrs Grant's Secret Compartments", icon="project_template.png", description="<p><b>Mrs Grant's Secret Compartments</b></p> | ||
| <p>A Fowler Statemachine representing Mrs Grant's Secret Compartments.</p><p><img href=\"mrsgrantssecretcompartment.png\"/></p>") | ||
| final class MrsGrantsSecretCompartmentsProject { | ||
|
|
||
| val advanced = check("Advanced:", false) | ||
| val advancedGroup = group("Properties") | ||
| val path = text("Package:", "mydsl", "The package path to place the files in", advancedGroup) | ||
|
|
||
| override protected updateVariables() { | ||
| path.enabled = advanced.value | ||
| if (!advanced.value) { | ||
| path.value = "statemachine" | ||
| } | ||
| } | ||
|
|
||
| override protected validate() { | ||
| if (path.value.matches('[a-z][a-z0-9_]*(/[a-z][a-z0-9_]*)*')) | ||
| null | ||
| else | ||
| new Status(ERROR, "Wizard", "'" + path + "' is not a valid package name") | ||
| } | ||
|
|
||
| override generateProjects(IProjectGenerator generator) { | ||
| generator.generate(new PluginProjectFactory => [ | ||
| projectName = projectInfo.projectName | ||
| location = projectInfo.locationPath | ||
| projectNatures += #[JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature", XtextProjectHelper.NATURE_ID] | ||
| builderIds += #[JavaCore.BUILDER_ID, XtextProjectHelper.BUILDER_ID] | ||
| folders += "src" | ||
| folders += "src-gen" | ||
| addFile('''src/«path»/MrsGrantsSecretCompartments.statemachine''', TemplateContent.MrsGrantsSecretCompartments) | ||
| ]) | ||
| } | ||
|
|
||
| protected override List<Pair<String, Image>> getImages() { | ||
| #["mrsgrantssecretcompartment.png".image] | ||
| } | ||
|
|
||
| private def image(String id) { | ||
| id -> new PluginImageHelper().getImage('''platform:/plugin/«FowlerdslActivator.PLUGIN_ID»/«id»''') | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.