| /** |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * 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 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| * |
| * This copyright notice shows up in the generated Java code |
| */ |
| package org.eclipse.osbp.xtext.chart.jvmmodel; |
| |
| import com.vaadin.annotations.JavaScript; |
| import com.vaadin.shared.ui.JavaScriptComponentState; |
| import com.vaadin.ui.AbstractJavaScriptComponent; |
| import java.util.ArrayList; |
| import java.util.List; |
| import javax.inject.Inject; |
| import org.eclipse.emf.common.util.EList; |
| import org.eclipse.osbp.utils.constants.GeneratorConstants; |
| import org.eclipse.osbp.xtext.chart.Chart; |
| import org.eclipse.osbp.xtext.chart.ChartOption; |
| import org.eclipse.osbp.xtext.chart.ChartTree; |
| import org.eclipse.osbp.xtext.chart.jvmmodel.D3JsJavaUtil; |
| import org.eclipse.xtend2.lib.StringConcatenation; |
| import org.eclipse.xtext.common.types.JvmAnnotationReference; |
| import org.eclipse.xtext.common.types.JvmAnnotationValue; |
| import org.eclipse.xtext.common.types.JvmConstructor; |
| import org.eclipse.xtext.common.types.JvmDeclaredType; |
| import org.eclipse.xtext.common.types.JvmField; |
| import org.eclipse.xtext.common.types.JvmFormalParameter; |
| import org.eclipse.xtext.common.types.JvmGenericType; |
| import org.eclipse.xtext.common.types.JvmMember; |
| import org.eclipse.xtext.common.types.JvmOperation; |
| import org.eclipse.xtext.common.types.JvmStringAnnotationValue; |
| import org.eclipse.xtext.common.types.JvmTypeReference; |
| import org.eclipse.xtext.common.types.JvmVisibility; |
| import org.eclipse.xtext.common.types.TypesFactory; |
| import org.eclipse.xtext.xbase.compiler.output.ITreeAppendable; |
| import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor; |
| import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder; |
| import org.eclipse.xtext.xbase.lib.CollectionLiterals; |
| import org.eclipse.xtext.xbase.lib.Extension; |
| import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; |
| |
| @SuppressWarnings("all") |
| public class ChartDSLD3JavaComponentsCreator { |
| @Inject |
| @Extension |
| private JvmTypesBuilder _jvmTypesBuilder; |
| |
| @Inject |
| @Extension |
| private D3JsJavaUtil _d3JsJavaUtil; |
| |
| @Inject |
| private TypesFactory typesFactory; |
| |
| public void createJsJavaComponent(final Chart chart, final IJvmDeclaredTypeAcceptor acceptor) { |
| final String stateClassName = this._d3JsJavaUtil.createStateFilename(chart); |
| String _createfullyQualifiedChartFilename = this._d3JsJavaUtil.createfullyQualifiedChartFilename(chart); |
| JvmGenericType chart_cls = this._jvmTypesBuilder.toClass(chart, _createfullyQualifiedChartFilename); |
| this._jvmTypesBuilder.setDocumentation(chart_cls, GeneratorConstants.GENERATED_CLASSES_DOCUMENTATION); |
| String _createfullyQualifiedStateFilename = this._d3JsJavaUtil.createfullyQualifiedStateFilename(chart); |
| JvmGenericType state_cls = this._jvmTypesBuilder.toClass(chart, _createfullyQualifiedStateFilename); |
| this._jvmTypesBuilder.setDocumentation(state_cls, GeneratorConstants.GENERATED_CLASSES_DOCUMENTATION); |
| ChartOption _charttype = chart.getCharttype(); |
| if ((_charttype instanceof ChartTree)) { |
| ChartOption _charttype_1 = chart.getCharttype(); |
| final ChartTree chartTree = ((ChartTree) _charttype_1); |
| IJvmDeclaredTypeAcceptor.IPostIndexingInitializing<JvmGenericType> _accept = acceptor.<JvmGenericType>accept(chart_cls); |
| final Procedure1<JvmGenericType> _function = new Procedure1<JvmGenericType>() { |
| public void apply(final JvmGenericType it) { |
| EList<JvmTypeReference> _superTypes = it.getSuperTypes(); |
| JvmTypeReference _newTypeRef = ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.newTypeRef(chart, AbstractJavaScriptComponent.class); |
| ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.<JvmTypeReference>operator_add(_superTypes, _newTypeRef); |
| JvmAnnotationReference jsAnnotationRef = ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.toAnnotation(chartTree, JavaScript.class); |
| String _createChartJsFilename = ChartDSLD3JavaComponentsCreator.this._d3JsJavaUtil.createChartJsFilename(chart); |
| ArrayList<String> jsAnnotationList = CollectionLiterals.<String>newArrayList("d3.min.js", _createChartJsFilename); |
| ChartDSLD3JavaComponentsCreator.this.addStringValuesToAnnotation(jsAnnotationRef, jsAnnotationList); |
| EList<JvmAnnotationReference> _annotations = it.getAnnotations(); |
| ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.<JvmAnnotationReference>operator_add(_annotations, jsAnnotationRef); |
| boolean _isMap = chartTree.isMap(); |
| if (_isMap) { |
| ChartDSLD3JavaComponentsCreator.this.toTreeMapConstructor(it, chart); |
| } else { |
| boolean _isCollapsible = chartTree.isCollapsible(); |
| if (_isCollapsible) { |
| ChartDSLD3JavaComponentsCreator.this.toChartConstructor(it, chart); |
| } |
| } |
| ChartDSLD3JavaComponentsCreator.this.toChartOperations(it, chart, stateClassName); |
| } |
| }; |
| _accept.initializeLater(_function); |
| IJvmDeclaredTypeAcceptor.IPostIndexingInitializing<JvmGenericType> _accept_1 = acceptor.<JvmGenericType>accept(state_cls); |
| final Procedure1<JvmGenericType> _function_1 = new Procedure1<JvmGenericType>() { |
| public void apply(final JvmGenericType it) { |
| EList<JvmTypeReference> _superTypes = it.getSuperTypes(); |
| JvmTypeReference _newTypeRef = ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.newTypeRef(chart, JavaScriptComponentState.class); |
| ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.<JvmTypeReference>operator_add(_superTypes, _newTypeRef); |
| boolean _isMap = chartTree.isMap(); |
| if (_isMap) { |
| ChartDSLD3JavaComponentsCreator.this.toTreeMapStateFields(it, chart); |
| } else { |
| boolean _isCollapsible = chartTree.isCollapsible(); |
| if (_isCollapsible) { |
| ChartDSLD3JavaComponentsCreator.this.toChartStateFields(it, chart); |
| } |
| } |
| } |
| }; |
| _accept_1.initializeLater(_function_1); |
| } |
| } |
| |
| public void toChartOperations(final JvmDeclaredType type, final Chart chart, final String stateClassName) { |
| EList<JvmMember> _members = type.getMembers(); |
| JvmTypeReference _newTypeRef = this._jvmTypesBuilder.newTypeRef(chart, stateClassName); |
| final Procedure1<JvmOperation> _function = new Procedure1<JvmOperation>() { |
| public void apply(final JvmOperation it) { |
| final Procedure1<ITreeAppendable> _function = new Procedure1<ITreeAppendable>() { |
| public void apply(final ITreeAppendable it) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("return ("); |
| _builder.append(stateClassName, ""); |
| _builder.append(") super.getState();"); |
| it.append(_builder); |
| } |
| }; |
| ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.setBody(it, _function); |
| } |
| }; |
| JvmOperation _method = this._jvmTypesBuilder.toMethod(chart, "getState", _newTypeRef, _function); |
| this._jvmTypesBuilder.<JvmOperation>operator_add(_members, _method); |
| } |
| |
| public CharSequence getD3StateVars() { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("getState().jsonData = _jsonData;"); |
| _builder.newLine(); |
| _builder.append("getState().htmlTagId=_htmlTagId;"); |
| return _builder; |
| } |
| |
| public JvmConstructor getChartConstructor(final JvmDeclaredType type, final Chart chart) { |
| final Procedure1<JvmConstructor> _function = new Procedure1<JvmConstructor>() { |
| public void apply(final JvmConstructor it) { |
| EList<JvmFormalParameter> _parameters = it.getParameters(); |
| JvmTypeReference _newTypeRef = ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.newTypeRef(chart, String.class); |
| JvmFormalParameter _parameter = ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.toParameter(chart, "_htmlTagId", _newTypeRef); |
| ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters, _parameter); |
| EList<JvmFormalParameter> _parameters_1 = it.getParameters(); |
| JvmTypeReference _newTypeRef_1 = ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.newTypeRef(chart, String.class); |
| JvmFormalParameter _parameter_1 = ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.toParameter(chart, "_jsonData", _newTypeRef_1); |
| ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters_1, _parameter_1); |
| final Procedure1<ITreeAppendable> _function = new Procedure1<ITreeAppendable>() { |
| public void apply(final ITreeAppendable it) { |
| CharSequence _d3StateVars = ChartDSLD3JavaComponentsCreator.this.getD3StateVars(); |
| it.append(_d3StateVars); |
| } |
| }; |
| ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.setBody(it, _function); |
| } |
| }; |
| return this._jvmTypesBuilder.toConstructor(chart, _function); |
| } |
| |
| public void toTreeMapConstructor(final JvmDeclaredType type, final Chart chart) { |
| JvmConstructor constructor = this.getChartConstructor(type, chart); |
| EList<JvmFormalParameter> _parameters = constructor.getParameters(); |
| JvmTypeReference _newTypeRef = this._jvmTypesBuilder.newTypeRef(chart, String.class); |
| JvmTypeReference _newTypeRef_1 = this._jvmTypesBuilder.newTypeRef(chart, List.class, _newTypeRef); |
| JvmFormalParameter _parameter = this._jvmTypesBuilder.toParameter(chart, "dataColumns", _newTypeRef_1); |
| this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters, _parameter); |
| final Procedure1<ITreeAppendable> _function = new Procedure1<ITreeAppendable>() { |
| public void apply(final ITreeAppendable it) { |
| StringConcatenation _builder = new StringConcatenation(); |
| CharSequence _d3StateVars = ChartDSLD3JavaComponentsCreator.this.getD3StateVars(); |
| _builder.append(_d3StateVars, ""); |
| _builder.newLineIfNotEmpty(); |
| _builder.append("getState().dataColumnList = dataColumns;"); |
| it.append(_builder); |
| } |
| }; |
| this._jvmTypesBuilder.setBody(constructor, _function); |
| EList<JvmMember> _members = type.getMembers(); |
| this._jvmTypesBuilder.<JvmConstructor>operator_add(_members, constructor); |
| } |
| |
| public void toChartConstructor(final JvmDeclaredType type, final Chart chart) { |
| JvmConstructor constructor = this.getChartConstructor(type, chart); |
| EList<JvmMember> _members = type.getMembers(); |
| this._jvmTypesBuilder.<JvmConstructor>operator_add(_members, constructor); |
| } |
| |
| public void addStringValuesToAnnotation(final JvmAnnotationReference annotationRef, final ArrayList<String> annotationStringList) { |
| JvmStringAnnotationValue value = this.typesFactory.createJvmStringAnnotationValue(); |
| for (final String annotationString : annotationStringList) { |
| EList<String> _values = value.getValues(); |
| this._jvmTypesBuilder.<String>operator_add(_values, annotationString); |
| } |
| EList<JvmAnnotationValue> _explicitValues = annotationRef.getExplicitValues(); |
| this._jvmTypesBuilder.<JvmStringAnnotationValue>operator_add(_explicitValues, value); |
| } |
| |
| public void toTreeMapStateFields(final JvmDeclaredType type, final Chart chart) { |
| this.toChartStateFields(type, chart); |
| EList<JvmMember> _members = type.getMembers(); |
| JvmTypeReference _newTypeRef = this._jvmTypesBuilder.newTypeRef(chart, String.class); |
| JvmTypeReference _newTypeRef_1 = this._jvmTypesBuilder.newTypeRef(chart, List.class, _newTypeRef); |
| final Procedure1<JvmField> _function = new Procedure1<JvmField>() { |
| public void apply(final JvmField it) { |
| it.setVisibility(JvmVisibility.PUBLIC); |
| final Procedure1<ITreeAppendable> _function = new Procedure1<ITreeAppendable>() { |
| public void apply(final ITreeAppendable it) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("new ArrayList<String>()"); |
| it.append(_builder); |
| } |
| }; |
| ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.setInitializer(it, _function); |
| } |
| }; |
| JvmField _field = this._jvmTypesBuilder.toField(chart, "dataColumnList", _newTypeRef_1, _function); |
| this._jvmTypesBuilder.<JvmField>operator_add(_members, _field); |
| } |
| |
| public void toChartStateFields(final JvmDeclaredType type, final Chart chart) { |
| EList<JvmMember> _members = type.getMembers(); |
| JvmTypeReference _newTypeRef = this._jvmTypesBuilder.newTypeRef(chart, String.class); |
| final Procedure1<JvmField> _function = new Procedure1<JvmField>() { |
| public void apply(final JvmField it) { |
| it.setVisibility(JvmVisibility.PUBLIC); |
| final Procedure1<ITreeAppendable> _function = new Procedure1<ITreeAppendable>() { |
| public void apply(final ITreeAppendable it) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("\"\""); |
| it.append(_builder); |
| } |
| }; |
| ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.setInitializer(it, _function); |
| } |
| }; |
| JvmField _field = this._jvmTypesBuilder.toField(chart, "jsonData", _newTypeRef, _function); |
| this._jvmTypesBuilder.<JvmField>operator_add(_members, _field); |
| EList<JvmMember> _members_1 = type.getMembers(); |
| JvmTypeReference _newTypeRef_1 = this._jvmTypesBuilder.newTypeRef(chart, String.class); |
| final Procedure1<JvmField> _function_1 = new Procedure1<JvmField>() { |
| public void apply(final JvmField it) { |
| it.setVisibility(JvmVisibility.PUBLIC); |
| final Procedure1<ITreeAppendable> _function = new Procedure1<ITreeAppendable>() { |
| public void apply(final ITreeAppendable it) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("\"\""); |
| it.append(_builder); |
| } |
| }; |
| ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.setInitializer(it, _function); |
| } |
| }; |
| JvmField _field_1 = this._jvmTypesBuilder.toField(chart, "htmlTagId", _newTypeRef_1, _function_1); |
| this._jvmTypesBuilder.<JvmField>operator_add(_members_1, _field_1); |
| EList<JvmMember> _members_2 = type.getMembers(); |
| JvmTypeReference _newTypeRef_2 = this._jvmTypesBuilder.newTypeRef(chart, String.class); |
| final Procedure1<JvmField> _function_2 = new Procedure1<JvmField>() { |
| public void apply(final JvmField it) { |
| it.setVisibility(JvmVisibility.PUBLIC); |
| final Procedure1<ITreeAppendable> _function = new Procedure1<ITreeAppendable>() { |
| public void apply(final ITreeAppendable it) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("\"\""); |
| it.append(_builder); |
| } |
| }; |
| ChartDSLD3JavaComponentsCreator.this._jvmTypesBuilder.setInitializer(it, _function); |
| } |
| }; |
| JvmField _field_2 = this._jvmTypesBuilder.toField(chart, "inputValue", _newTypeRef_2, _function_2); |
| this._jvmTypesBuilder.<JvmField>operator_add(_members_2, _field_2); |
| } |
| |
| public CharSequence createD3Chart(final Chart chart) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("CellSetToD3JsonConverter jsonConverter = new CellSetToD3JsonConverter();"); |
| _builder.newLine(); |
| _builder.append("return new "); |
| final String d3ChartFileName = this._d3JsJavaUtil.createChartFilename(chart); |
| _builder.append(d3ChartFileName, ""); |
| _builder.append("(\""); |
| _builder.append(d3ChartFileName, ""); |
| _builder.append("\", jsonConverter.getD3JsonString(cxCellSet)"); |
| { |
| boolean _isTreeMap = this._d3JsJavaUtil.isTreeMap(chart); |
| if (_isTreeMap) { |
| _builder.append(", jsonConverter.getDataColumnNameList(cxCellSet)"); |
| } |
| } |
| _builder.append(");"); |
| return _builder; |
| } |
| } |