| /** |
| * |
| * 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 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| * |
| * This copyright notice shows up in the generated Java code |
| * |
| */ |
| |
| package org.eclipse.osbp.xtext.gridsource.ui.contentassist |
| |
| import org.eclipse.emf.ecore.EObject |
| import org.eclipse.jface.viewers.StyledString |
| import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropButtonStyle |
| import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropImageStyle |
| import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridStyleConfigNumericToResource |
| import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridStyleConfigStringToResource |
| import org.eclipse.osbp.xtext.basic.ui.contentassist.BasicDSLProposalProviderHelper |
| import org.eclipse.osbp.xtext.gridsource.ui.GridSourceDocumentationTranslator |
| import org.eclipse.xtext.Assignment |
| import org.eclipse.xtext.Keyword |
| import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext |
| import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor |
| import org.eclipse.xtext.RuleCall |
| |
| class GridSourceProposalProvider extends AbstractGridSourceProposalProvider { |
| |
| static String DEMO_TOPIC = "\"org/my/topic/*\"" |
| static String DEMO_RESOURCE = "theme:/common/etc/my.png" |
| static String DEMO_NUMERIC_VALUE = "123.45" |
| static String DEMO_STRING_VALUE = "aBcDeF" |
| |
| override StyledString getKeywordDisplayString(Keyword keyword) { |
| val keyString = keyword.value |
| if (keyString.equals("=") || keyString.equals("(") || keyString.equals(")")) { |
| return new StyledString(keyString) |
| } |
| |
| return BasicDSLProposalProviderHelper.getKeywordDisplayString(keyword, |
| GridSourceDocumentationTranslator.instance()) |
| } |
| |
| override void completePropertyButtonStyle_EventTopic(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyButtonStyle_EventTopic(model, assignment, context, acceptor) |
| |
| doCompletePropertyButtonStyle_EventTopic(acceptor, model, context); |
| } |
| |
| def doCompletePropertyButtonStyle_EventTopic(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept( |
| doCreateProposal(DEMO_TOPIC, createStyledString(model as CxGridPropButtonStyle), model.image, 1000, context)) |
| } |
| |
| override void completePropertyImageStyle_EventTopic(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyImageStyle_EventTopic(model, assignment, context, acceptor) |
| |
| doCompletePropertyImageStyle_EventTopic(acceptor, model, context); |
| } |
| |
| def doCompletePropertyImageStyle_EventTopic(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept( |
| doCreateProposal(DEMO_TOPIC, createStyledString(model as CxGridPropImageStyle), model.image, 1000, context)) |
| } |
| |
| override void completeStringToResourceStyleConfig_Value(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completeStringToResourceStyleConfig_Value(model, assignment, context, acceptor); |
| |
| doCompleteStringToResourceStyleConfig_Value(acceptor, model, context); |
| } |
| |
| def doCompleteStringToResourceStyleConfig_Value(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept( |
| doCreateProposal("\"" + DEMO_STRING_VALUE + "\"", |
| createStyledString_Value(model as CxGridStyleConfigStringToResource), model.image, 1000, context)) |
| } |
| |
| override void completeStringToResourceStyleConfig_ResourceThemePath(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completeStringToResourceStyleConfig_ResourceThemePath(model, assignment, context, acceptor); |
| |
| doCompleteStringToResourceStyleConfig_ResourceThemePath(acceptor, model, context); |
| } |
| |
| def doCompleteStringToResourceStyleConfig_ResourceThemePath(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept( |
| doCreateProposal(DEMO_RESOURCE, createStyledString_Resource(model as CxGridStyleConfigStringToResource), |
| model.image, 1000, context)) |
| } |
| |
| override void completeNumericToResourceStyleConfig_ResourceThemePath(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completeStringToResourceStyleConfig_ResourceThemePath(model, assignment, context, acceptor); |
| |
| doCompleteNumericToResourceStyleConfig_ResourceThemePath(acceptor, model, context); |
| } |
| |
| def doCompleteNumericToResourceStyleConfig_ResourceThemePath(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept( |
| doCreateProposal(DEMO_RESOURCE, createStyledString_Resource(model as CxGridStyleConfigNumericToResource), |
| model.image, 1000, context)) |
| } |
| |
| override void completeNumericToResourceStyleConfig_Value(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completeNumericToResourceStyleConfig_Value(model, assignment, context, acceptor); |
| |
| doCompleteNumericToResourceStyleConfig_Value(acceptor, model, context); |
| } |
| |
| def doCompleteNumericToResourceStyleConfig_Value(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept( |
| doCreateProposal("123.45", createStyledString_Value(model as CxGridStyleConfigNumericToResource), |
| model.image, 1000, context)) |
| } |
| |
| override void completeGridPropIndicatorStyle_RedEnds(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyDateStyle_DateFormat(model, assignment, context, acceptor); |
| |
| doCompleteGridPropIndicatorStyle_RedEnds(acceptor, model, context); |
| } |
| |
| def doCompleteGridPropIndicatorStyle_RedEnds(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept(doCreateProposal(" 40 ", createStyledString_RedUntil(), model.image, 1000, context)) |
| } |
| |
| override void completeGridPropIndicatorStyle_GreenStarts(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyDateStyle_DateFormat(model, assignment, context, acceptor); |
| |
| dompleteGridPropIndicatorStyle_GreenStarts(acceptor, model, context); |
| } |
| |
| def dompleteGridPropIndicatorStyle_GreenStarts(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept(doCreateProposal(" 70 ", createStyledString_GreenFrom(), model.image, 1000, context)) |
| } |
| |
| override void completePropertyQuantityStyle_ValuePropertyPath(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyQuantityStyle_ValuePropertyPath(model, assignment, context, acceptor); |
| |
| doCompletePropertyQuantityStyle_ValuePropertyPath(model, assignment, context, acceptor); |
| } |
| |
| def void doCompletePropertyQuantityStyle_ValuePropertyPath(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| val result = new StyledString("Specify property path to the value attribute like "); |
| result.append("'value = amount'", StyledString.QUALIFIER_STYLER); |
| acceptor.accept( |
| doCreateProposal("amount", result, model.image, 1000, context)) |
| } |
| |
| override void completePropertyQuantityStyle_UomPropertyPath(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyQuantityStyle_ValuePropertyPath(model, assignment, context, acceptor); |
| |
| doCompletePropertyQuantityStyle_ValuePropertyPath(model, assignment, context, acceptor); |
| } |
| |
| def void doCompletePropertyQuantityStyle_UomPropertyPath(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| val result = new StyledString("Specify property path to the unit of measure attribute like "); |
| result.append("'uom = uom.code'", StyledString.QUALIFIER_STYLER); |
| acceptor.accept( |
| doCreateProposal("uom.code", result, model.image, 1000, context)) |
| } |
| |
| override void completePropertyPriceStyle_ValuePropertyPath(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyQuantityStyle_ValuePropertyPath(model, assignment, context, acceptor); |
| |
| doCompletePropertyQuantityStyle_ValuePropertyPath(model, assignment, context, acceptor); |
| } |
| |
| def void doCompletePropertyPriceStyle_ValuePropertyPath(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| val result = new StyledString("Specify property path to the value attribute like "); |
| result.append("'value = amount'", StyledString.QUALIFIER_STYLER); |
| acceptor.accept( |
| doCreateProposal("amount", result, model.image, 1000, context)) |
| } |
| |
| override void completePropertyPriceStyle_CurrencyPropertyPath(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyQuantityStyle_ValuePropertyPath(model, assignment, context, acceptor); |
| |
| doCompletePropertyQuantityStyle_ValuePropertyPath(model, assignment, context, acceptor); |
| } |
| |
| def void doCompletePropertyPriceStyle_CurrencyPropertyPath(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| val result = new StyledString("Specify property path to the currency attribute like "); |
| result.append("'currency = currency.isoCode'", StyledString.QUALIFIER_STYLER); |
| acceptor.accept( |
| doCreateProposal("currency.isoCode", result, model.image, 1000, context)) |
| } |
| |
| override void completePropertyNumberStyle_NumberFormat(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyDateStyle_DateFormat(model, assignment, context, acceptor); |
| |
| doCompletePropertyNumberStyle_NumberFormat(acceptor, model, context); |
| } |
| |
| def doCompletePropertyNumberStyle_NumberFormat(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept( |
| doCreateProposal("'#,##0.00'", createStyledString_NumberFormat(), model.image, 1000, context)) |
| } |
| |
| override void completePropertyDateStyle_DateFormat(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyDateStyle_DateFormat(model, assignment, context, acceptor); |
| |
| doCompletePropertyDateStyle_DateFormat(acceptor, model, context); |
| } |
| |
| def doCompletePropertyDateStyle_DateFormat(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept( |
| doCreateProposal("'yyyy.MM.dd HH:mm:ss'", createStyledString_DateFormat(), model.image, 1000, context)) |
| } |
| |
| override void completePropertyProgressbarStyle_MaxValue(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyProgressbarStyle_MaxValue(model, assignment, context, acceptor); |
| |
| doCompletePropertyProgressbarStyle_MaxValue(acceptor, model, context); |
| } |
| |
| def doCompletePropertyProgressbarStyle_MaxValue(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept( |
| doCreateProposal(DEMO_NUMERIC_VALUE, createStyledString_MaxNumber(), model.image, 1000, context)) |
| } |
| |
| override completePropertyPriceStyle_HtmlPattern(EObject model, Assignment assignment, ContentAssistContext context, |
| ICompletionProposalAcceptor acceptor) { |
| super.completePropertyPriceStyle_HtmlPattern(model, assignment, context, acceptor); |
| |
| doCompletePropertyPriceStyle_HtmlPattern(acceptor, model, context); |
| } |
| |
| def doCompletePropertyPriceStyle_HtmlPattern(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept( |
| doCreateProposal("\"<b>{@value}</b> <i>{@currency}</i>\"", createStyledString_CurrencyHtmlPattern(), |
| model.image, 1000, context)) |
| } |
| |
| override void completePropertyPriceStyle_ValueNumberFormat(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyPriceStyle_ValueNumberFormat(model, assignment, context, acceptor); |
| |
| doCompletePropertyPriceStyle_ValueNumberFormat(acceptor, model, context); |
| } |
| |
| def doCompletePropertyPriceStyle_ValueNumberFormat(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept( |
| doCreateProposal("'#,##0.00'", createStyledString_NumberFormat(), model.image, 1000, context)) |
| } |
| |
| override completePropertyQuantityStyle_HtmlPattern(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyQuantityStyle_HtmlPattern(model, assignment, context, acceptor); |
| |
| doCompletePropertyQuantityStyle_HtmlPattern(acceptor, model, context); |
| } |
| |
| def doCompletePropertyQuantityStyle_HtmlPattern(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept( |
| doCreateProposal("\"<b>{@value}</b> <i>{@uom}</i>\"", createStyledString_QuantityHtmlPattern(), model.image, |
| 1000, context)) |
| } |
| |
| override void completePropertyQuantityStyle_ValueNumberFormat(EObject model, Assignment assignment, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| super.completePropertyQuantityStyle_ValueNumberFormat(model, assignment, context, acceptor); |
| |
| doCompletePropertyQuantityStyle_ValueNumberFormat(acceptor, model, context); |
| } |
| |
| def doCompletePropertyQuantityStyle_ValueNumberFormat(ICompletionProposalAcceptor acceptor, EObject model, |
| ContentAssistContext context) { |
| acceptor.accept( |
| doCreateProposal("'#,##0.00'", createStyledString_NumberFormat(), model.image, 1000, context)) |
| } |
| |
| def dispatch createStyledString(CxGridPropButtonStyle object) { |
| val result = new StyledString("Specify a topic like "); |
| result.append(DEMO_TOPIC, StyledString.QUALIFIER_STYLER); |
| return result |
| } |
| |
| def dispatch createStyledString(CxGridPropImageStyle object) { |
| val result = new StyledString("Specify a topic like "); |
| result.append(DEMO_TOPIC, StyledString.QUALIFIER_STYLER); |
| return result |
| } |
| |
| def dispatch createStyledString_Resource(CxGridStyleConfigStringToResource object) { |
| val result = new StyledString("Specify an image like "); |
| result.append(DEMO_RESOURCE, StyledString.QUALIFIER_STYLER); |
| return result |
| } |
| |
| def dispatch createStyledString_Resource(CxGridStyleConfigNumericToResource object) { |
| val result = new StyledString("Specify an image like "); |
| result.append(DEMO_RESOURCE, StyledString.QUALIFIER_STYLER); |
| return result |
| } |
| |
| def dispatch createStyledString_Value(CxGridStyleConfigStringToResource object) { |
| val result = new StyledString("Specify any String to compare against. Like "); |
| result.append(DEMO_STRING_VALUE, StyledString.QUALIFIER_STYLER); |
| return result |
| } |
| |
| def dispatch createStyledString_Value(CxGridStyleConfigNumericToResource object) { |
| val result = new StyledString("Specify any number to compare against. Like "); |
| result.append(DEMO_NUMERIC_VALUE, StyledString.QUALIFIER_STYLER); |
| return result |
| } |
| |
| def StyledString createStyledString_DateFormat() { |
| val result = new StyledString("Specify any date format to be used. Like "); |
| result.append("'yyyy.MM.dd G 'at' HH:mm:ss z'", StyledString.QUALIFIER_STYLER); |
| return result |
| } |
| |
| def StyledString createStyledString_CurrencyHtmlPattern() { |
| val result = new StyledString("Specify a HTML pattern including two placeholders. Like "); |
| result.append("<b>{@value}</b> <i>{@currency}</i>", StyledString.QUALIFIER_STYLER); |
| return result |
| } |
| |
| def StyledString createStyledString_QuantityHtmlPattern() { |
| val result = new StyledString("Specify a HTML pattern including two placeholders. Like "); |
| result.append("<b>{@value}</b> <i>{@uom}</i>", StyledString.QUALIFIER_STYLER); |
| return result |
| } |
| |
| def StyledString createStyledString_NumberFormat() { |
| val result = new StyledString("Specify any number format to be used. Like "); |
| result.append("'#,##0.00'", StyledString.QUALIFIER_STYLER); |
| return result |
| } |
| |
| def StyledString createStyledString_MaxNumber() { |
| val result = new StyledString("Specify any number as the max value. Like "); |
| result.append(DEMO_NUMERIC_VALUE, StyledString.QUALIFIER_STYLER); |
| return result |
| } |
| |
| def StyledString createStyledString_RedUntil() { |
| val result = new StyledString( |
| "Specify any integer as the threshold value. Values below will be displayed red. Example: "); |
| result.append("40", StyledString.QUALIFIER_STYLER); |
| return result |
| } |
| |
| def StyledString createStyledString_GreenFrom() { |
| val result = new StyledString( |
| "Specify any integer as the threshold value. Values above will be displayed green. Example: "); |
| result.append("70", StyledString.QUALIFIER_STYLER); |
| return result |
| } |
| |
| } |