Xtext New Project Wizard / New File Wizard Fragment: add possibilities
to generate toolbar buttons.

Signed-off-by: Tamas Miklossy <miklossy@itemis.de>
This commit is contained in:
Tamas Miklossy 2019-11-19 17:41:30 +01:00
parent 8f89743894
commit 87435d7a8b
6 changed files with 275 additions and 11 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2018 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2015, 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
@ -211,7 +211,7 @@ import org.eclipse.xtext.xtext.generator.xbase.XtypeGeneratorFragment2
/**
* Create a wizard able to create new projects with initial content based on template definitions.
* Supported options: 'generate', 'pluginProject'.
* Supported options: 'generate', 'generateToolbarButton', 'pluginProject'.
*/
def setProjectWizard(TemplateProjectWizardFragment fragment) {
this.projectWizard = fragment
@ -219,7 +219,7 @@ import org.eclipse.xtext.xtext.generator.xbase.XtypeGeneratorFragment2
/**
* Create a wizard able to create new files with initial content based on template definitions.
* Supported options: 'generate'.
* Supported options: 'generate', 'generateToolbarButton'.
*/
def setFileWizard(TemplateFileWizardFragment fragment) {
this.fileWizard = fragment

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2018, 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
@ -45,6 +45,7 @@ class TemplateFileWizardFragment extends AbstractXtextGeneratorFragment {
FileAccessFactory fileAccessFactory
@Accessors boolean generate = false;
@Accessors boolean generateToolbarButton = false;
override generate() {
if (!generate)
@ -94,6 +95,33 @@ class TemplateFileWizardFragment extends AbstractXtextGeneratorFragment {
</perspectiveExtension>
</extension>
'''
if (generateToolbarButton) {
projectConfig.eclipsePlugin.pluginXml.entries += '''
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="«grammar.eclipsePluginBasePackage».toolbar">
<!--
For some reason the tooltip is not shown when hovering over the toolbar button
See also https://www.eclipse.org/forums/index.php/t/1079111/
-->
<command
commandId="org.eclipse.ui.newWizard"
tooltip="Create a new «grammar.simpleName» file">
<parameter
name="newWizardId"
value="«fileWizardClassName»">
</parameter>
</command>
</toolbar>
</menuContribution>
</extension>
'''
}
}
generateProjectTemplateProvider
@ -179,4 +207,13 @@ class TemplateFileWizardFragment extends AbstractXtextGeneratorFragment {
generate = value
}
/**
* Generate a new file wizard toolbar button. Set to 'false' by default. Change to 'true' to add the new file wizard button to the toolbar.
*
* @since 2.20
*/
def setGenerateToolbarButton(boolean value) {
generateToolbarButton = value
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2018 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2017, 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
@ -47,6 +47,7 @@ class TemplateProjectWizardFragment extends AbstractXtextGeneratorFragment {
FileAccessFactory fileAccessFactory
@Accessors boolean generate = false;
@Accessors boolean generateToolbarButton = false;
@Accessors boolean pluginProject = true;
override generate() {
@ -109,6 +110,33 @@ class TemplateProjectWizardFragment extends AbstractXtextGeneratorFragment {
</perspectiveExtension>
</extension>
'''
if (generateToolbarButton) {
projectConfig.eclipsePlugin.pluginXml.entries += '''
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="«grammar.eclipsePluginBasePackage».toolbar">
<!--
For some reason the tooltip is not shown when hovering over the toolbar button
See also https://www.eclipse.org/forums/index.php/t/1079111/
-->
<command
commandId="org.eclipse.ui.newWizard"
tooltip="Create a new «grammar.simpleName» project">
<parameter
name="newWizardId"
value="«projectWizardClassName»">
</parameter>
</command>
</toolbar>
</menuContribution>
</extension>
'''
}
}
generateProjectTemplateProvider
@ -243,7 +271,7 @@ class TemplateProjectWizardFragment extends AbstractXtextGeneratorFragment {
protected def String getProjectWizardPackage() {
grammar.getEclipsePluginBasePackage + ".wizard."
}
/**
* Generate the wizard. Set to 'false' by default. Change to 'true' to generate the wizard.
*/
@ -251,6 +279,15 @@ class TemplateProjectWizardFragment extends AbstractXtextGeneratorFragment {
generate = value
}
/**
* Generate a new project wizard toolbar button. Set to 'false' by default. Change to 'true' to add the new project wizard button to the toolbar.
*
* @since 2.20
*/
def setGenerateToolbarButton(boolean value) {
generateToolbarButton = value
}
/**
* Generate the projects as eclipse plugins. Affects only the example content of the templates. Can be changed
* manually afterwards.

View file

@ -1,5 +1,5 @@
/**
* Copyright (c) 2015, 2018 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2015, 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
@ -253,7 +253,7 @@ public class StandardLanguage extends XtextGeneratorLanguage {
/**
* Create a wizard able to create new projects with initial content based on template definitions.
* Supported options: 'generate', 'pluginProject'.
* Supported options: 'generate', 'generateToolbarButton', 'pluginProject'.
*/
public TemplateProjectWizardFragment setProjectWizard(final TemplateProjectWizardFragment fragment) {
return this.projectWizard = fragment;
@ -261,7 +261,7 @@ public class StandardLanguage extends XtextGeneratorLanguage {
/**
* Create a wizard able to create new files with initial content based on template definitions.
* Supported options: 'generate'.
* Supported options: 'generate', 'generateToolbarButton'.
*/
public TemplateFileWizardFragment setFileWizard(final TemplateFileWizardFragment fragment) {
return this.fileWizard = fragment;

View file

@ -1,5 +1,5 @@
/**
* Copyright (c) 2018 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2018, 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
@ -63,6 +63,9 @@ public class TemplateFileWizardFragment extends AbstractXtextGeneratorFragment {
@Accessors
private boolean generate = false;
@Accessors
private boolean generateToolbarButton = false;
@Override
public void generate() {
if ((!this.generate)) {
@ -206,6 +209,84 @@ public class TemplateFileWizardFragment extends AbstractXtextGeneratorFragment {
_builder.append("</extension>");
_builder.newLine();
_entries.add(_builder.toString());
if (this.generateToolbarButton) {
List<CharSequence> _entries_1 = this.getProjectConfig().getEclipsePlugin().getPluginXml().getEntries();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("<extension");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("point=\"org.eclipse.ui.menus\">");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("<menuContribution");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("allPopups=\"false\"");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("locationURI=\"toolbar:org.eclipse.ui.main.toolbar\">");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("<toolbar");
_builder_1.newLine();
_builder_1.append("\t\t\t");
_builder_1.append("id=\"");
String _eclipsePluginBasePackage_3 = this._xtextGeneratorNaming.getEclipsePluginBasePackage(this.getGrammar());
_builder_1.append(_eclipsePluginBasePackage_3, "\t\t\t");
_builder_1.append(".toolbar\">");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t\t\t");
_builder_1.append("<!--");
_builder_1.newLine();
_builder_1.append("\t\t\t\t");
_builder_1.append("For some reason the tooltip is not shown when hovering over the toolbar button");
_builder_1.newLine();
_builder_1.append("\t\t\t\t");
_builder_1.append("See also https://www.eclipse.org/forums/index.php/t/1079111/");
_builder_1.newLine();
_builder_1.append("\t\t\t");
_builder_1.append("-->");
_builder_1.newLine();
_builder_1.append("\t\t\t");
_builder_1.append("<command");
_builder_1.newLine();
_builder_1.append("\t\t\t\t");
_builder_1.append("commandId=\"org.eclipse.ui.newWizard\"");
_builder_1.newLine();
_builder_1.append("\t\t\t\t");
_builder_1.append("tooltip=\"Create a new ");
String _simpleName_3 = GrammarUtil.getSimpleName(this.getGrammar());
_builder_1.append(_simpleName_3, "\t\t\t\t");
_builder_1.append(" file\">");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t\t\t\t");
_builder_1.append("<parameter");
_builder_1.newLine();
_builder_1.append("\t\t\t\t\t");
_builder_1.append("name=\"newWizardId\"");
_builder_1.newLine();
_builder_1.append("\t\t\t\t\t");
_builder_1.append("value=\"");
String _fileWizardClassName_3 = this.getFileWizardClassName();
_builder_1.append(_fileWizardClassName_3, "\t\t\t\t\t");
_builder_1.append("\">");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t\t\t\t");
_builder_1.append("</parameter>");
_builder_1.newLine();
_builder_1.append("\t\t\t");
_builder_1.append("</command>");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("</toolbar>");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("</menuContribution>");
_builder_1.newLine();
_builder_1.append("</extension>");
_builder_1.newLine();
_entries_1.add(_builder_1.toString());
}
}
this.generateProjectTemplateProvider();
this.generateDefaultIcons();
@ -371,8 +452,22 @@ public class TemplateFileWizardFragment extends AbstractXtextGeneratorFragment {
return this.generate = value;
}
/**
* Generate a new file wizard toolbar button. Set to 'false' by default. Change to 'true' to add the new file wizard button to the toolbar.
*
* @since 2.20
*/
public boolean setGenerateToolbarButton(final boolean value) {
return this.generateToolbarButton = value;
}
@Pure
public boolean isGenerate() {
return this.generate;
}
@Pure
public boolean isGenerateToolbarButton() {
return this.generateToolbarButton;
}
}

View file

@ -1,5 +1,5 @@
/**
* Copyright (c) 2017, 2018 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2017, 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
@ -64,6 +64,9 @@ public class TemplateProjectWizardFragment extends AbstractXtextGeneratorFragmen
@Accessors
private boolean generate = false;
@Accessors
private boolean generateToolbarButton = false;
@Accessors
private boolean pluginProject = true;
@ -221,6 +224,84 @@ public class TemplateProjectWizardFragment extends AbstractXtextGeneratorFragmen
_builder.append("</extension>");
_builder.newLine();
_entries.add(_builder.toString());
if (this.generateToolbarButton) {
List<CharSequence> _entries_1 = this.getProjectConfig().getEclipsePlugin().getPluginXml().getEntries();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("<extension");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("point=\"org.eclipse.ui.menus\">");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("<menuContribution");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("allPopups=\"false\"");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("locationURI=\"toolbar:org.eclipse.ui.main.toolbar\">");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("<toolbar");
_builder_1.newLine();
_builder_1.append("\t\t\t");
_builder_1.append("id=\"");
String _eclipsePluginBasePackage_3 = this._xtextGeneratorNaming.getEclipsePluginBasePackage(this.getGrammar());
_builder_1.append(_eclipsePluginBasePackage_3, "\t\t\t");
_builder_1.append(".toolbar\">");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t\t\t");
_builder_1.append("<!--");
_builder_1.newLine();
_builder_1.append("\t\t\t\t");
_builder_1.append("For some reason the tooltip is not shown when hovering over the toolbar button");
_builder_1.newLine();
_builder_1.append("\t\t\t\t");
_builder_1.append("See also https://www.eclipse.org/forums/index.php/t/1079111/");
_builder_1.newLine();
_builder_1.append("\t\t\t");
_builder_1.append("-->");
_builder_1.newLine();
_builder_1.append("\t\t\t");
_builder_1.append("<command");
_builder_1.newLine();
_builder_1.append("\t\t\t\t");
_builder_1.append("commandId=\"org.eclipse.ui.newWizard\"");
_builder_1.newLine();
_builder_1.append("\t\t\t\t");
_builder_1.append("tooltip=\"Create a new ");
String _simpleName_3 = GrammarUtil.getSimpleName(this.getGrammar());
_builder_1.append(_simpleName_3, "\t\t\t\t");
_builder_1.append(" project\">");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t\t\t\t");
_builder_1.append("<parameter");
_builder_1.newLine();
_builder_1.append("\t\t\t\t\t");
_builder_1.append("name=\"newWizardId\"");
_builder_1.newLine();
_builder_1.append("\t\t\t\t\t");
_builder_1.append("value=\"");
String _projectWizardClassName_3 = this.getProjectWizardClassName();
_builder_1.append(_projectWizardClassName_3, "\t\t\t\t\t");
_builder_1.append("\">");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t\t\t\t");
_builder_1.append("</parameter>");
_builder_1.newLine();
_builder_1.append("\t\t\t");
_builder_1.append("</command>");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("</toolbar>");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("</menuContribution>");
_builder_1.newLine();
_builder_1.append("</extension>");
_builder_1.newLine();
_entries_1.add(_builder_1.toString());
}
}
this.generateProjectTemplateProvider();
this.generateDefaultIcons();
@ -574,6 +655,15 @@ public class TemplateProjectWizardFragment extends AbstractXtextGeneratorFragmen
return this.generate = value;
}
/**
* Generate a new project wizard toolbar button. Set to 'false' by default. Change to 'true' to add the new project wizard button to the toolbar.
*
* @since 2.20
*/
public boolean setGenerateToolbarButton(final boolean value) {
return this.generateToolbarButton = value;
}
/**
* Generate the projects as eclipse plugins. Affects only the example content of the templates. Can be changed
* manually afterwards.
@ -587,6 +677,11 @@ public class TemplateProjectWizardFragment extends AbstractXtextGeneratorFragmen
return this.generate;
}
@Pure
public boolean isGenerateToolbarButton() {
return this.generateToolbarButton;
}
@Pure
public boolean isPluginProject() {
return this.pluginProject;