From 2cfc45eb83bbf555ce1cd9107a73997d3756bcf1 Mon Sep 17 00:00:00 2001 From: miettinen Date: Wed, 20 Feb 2013 11:19:53 +0000 Subject: [PATCH] Added additionalProposalInfo to CompeltionProposals; in assistive text feed, when a function with a description is selected, a popup window will pop up on the right of the text feed assistant and print the description of the function. (refs #3965) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26817 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../expressions/CompletionProcessor.java | 19 ++-- .../ExpressionFieldConfiguration.java | 19 +++- .../widgets/expressions/Function.java | 94 ++++++++++++------- 3 files changed, 82 insertions(+), 50 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/CompletionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/CompletionProcessor.java index a8276262..90b4d4ba 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/CompletionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/CompletionProcessor.java @@ -104,8 +104,8 @@ public class CompletionProcessor implements IContentAssistProcessor { variable.length(), imageVariable, variable, - null/*new ContextInformation("ContextInformation1", "ContextInformation2")*/, - ""/*"additional Proposal Info"*/)); + null, + null)); } } for (String variable : timeAndSelfVariables) { @@ -116,8 +116,8 @@ public class CompletionProcessor implements IContentAssistProcessor { variable.length(), imageVariableGray, variable, - null/*new ContextInformation("ContextInformation1", "ContextInformation2")*/, - ""/*"additional Proposal Info"*/)); + null, + null)); } } } @@ -145,8 +145,8 @@ public class CompletionProcessor implements IContentAssistProcessor { function.getName().length() + 1, image, function.getName() + "(" + function.getParameterList() + ")", - null/*new ContextInformation("ContextInformation1", "ContextInformation2")*/, - ""/*"additional Proposal Info"*/)); + null, + function.getDescriptionHTML())); } } } @@ -213,12 +213,6 @@ public class CompletionProcessor implements IContentAssistProcessor { @Override public IContextInformation[] computeContextInformation( ITextViewer viewer, int offset) { - - /*IContextInformation[] result = new IContextInformation[1]; - for (int i = 0; i < result.length; ++i) { - result[i] = new ContextInformation("String1", "String2"); - } - return result;*/ return null; } @@ -229,7 +223,6 @@ public class CompletionProcessor implements IContentAssistProcessor { @Override public char[] getContextInformationAutoActivationCharacters() { - //return allowedCharacters; return null; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java index ce741b54..ee4c8e96 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java @@ -11,8 +11,12 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.properties.widgets.expressions; +import org.eclipse.jface.internal.text.html.HTMLTextPresenter; +import org.eclipse.jface.text.DefaultInformationControl; import org.eclipse.jface.text.DefaultTextHover; import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IInformationControl; +import org.eclipse.jface.text.IInformationControlCreator; import org.eclipse.jface.text.ITextHover; import org.eclipse.jface.text.TextAttribute; import org.eclipse.jface.text.contentassist.ContentAssistEvent; @@ -36,9 +40,11 @@ import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.simantics.sysdyn.ui.utils.VariableNameUtils; +@SuppressWarnings("restriction") public class ExpressionFieldConfiguration extends SourceViewerConfiguration { private final long WAIT_BEFORE_STATUS_CHANGE = 100; @@ -137,8 +143,9 @@ public class ExpressionFieldConfiguration extends SourceViewerConfiguration { public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { ContentAssistant assistant = new ContentAssistant(); completionProcessor = new CompletionProcessor(allowedVariables, allowFunctions); - assistant.setContentAssistProcessor(completionProcessor, "__dftl_partition_content_type"); + assistant.setContentAssistProcessor(completionProcessor, IDocument.DEFAULT_CONTENT_TYPE); assistant.enableAutoActivation(true); + assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer)); assistant.enableAutoInsert(true); assistant.setAutoActivationDelay(0); assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY); @@ -147,6 +154,16 @@ public class ExpressionFieldConfiguration extends SourceViewerConfiguration { return assistant; } + @Override + public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) { + return new IInformationControlCreator() { + @Override + public IInformationControl createInformationControl(Shell parent) { + return new DefaultInformationControl(parent,new HTMLTextPresenter(false)); + } + }; + } + private class CompletionListener implements ICompletionListener { @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/Function.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/Function.java index 902c24f7..7e711018 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/Function.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/Function.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Device; import org.eclipse.swt.graphics.Image; +import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.ObjectsWithType; @@ -29,6 +30,7 @@ public class Function implements Comparable{ private final String name; private final Type type; private final String parameterList; + private final String description; public enum Type { USER_DEFINED, @@ -64,13 +66,20 @@ public class Function implements Comparable{ } } - public Function(String name, String parameterList, Type type){ + public Function(String name, String parameterList, Type type, String description){ this.name = new String(name); + this.type = type; + if (parameterList != null) this.parameterList = new String(parameterList); else this.parameterList = new String(""); + + if (description != null) + this.description = new String(description); + else + this.description = null; } public String getParameterList() { @@ -85,6 +94,10 @@ public class Function implements Comparable{ return type; } + public String getDescription() { + return description; + } + @Override public int compareTo(Function f) { // Sorting is done first in the order of Types and then alphabetically. @@ -130,6 +143,33 @@ public class Function implements Comparable{ return inputStr; } + private static String getFunctionDescription(ReadGraph graph, Resource r) throws DatabaseException { + String descriptionStr = null; + Layer0 l0 = Layer0.getInstance(graph); + Resource description = graph.getPossibleObject(r, l0.HasDescription); + if (description != null) { + descriptionStr = graph.getPossibleRelatedValue(r, l0.HasDescription, Bindings.STRING); + } + + return descriptionStr; + } + + private static ArrayList getFunctionsOfType(ReadGraph graph, String functionTypeUri, Type functionType) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + ArrayList functions = new ArrayList(); + + // Add functions + Resource functionLibrary = graph.getPossibleResource(functionTypeUri); + for(Resource r : graph.syncRequest(new ObjectsWithType(functionLibrary, l0.ConsistsOf, sr.SysdynModelicaFunction))) { + String name = NameUtils.getSafeName(graph, r); + String inputStr = getFunctionInputs(graph, sr, r); + String description = getFunctionDescription(graph, r); + functions.add(new Function(name, inputStr, functionType, description)); + } + return functions; + } + /** * Get all (atm. only built-in) Modelica functions. * @return ArrayList containing all functions. @@ -143,42 +183,13 @@ public class Function implements Comparable{ @Override public ArrayList perform(ReadGraph graph) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); ArrayList functions = new ArrayList(); - - // Add Sysdyn functions - Resource functionLibrary = graph.getPossibleResource(SysdynResource.URIs.Built$in_Functions); - for(Resource r : graph.syncRequest(new ObjectsWithType(functionLibrary, l0.ConsistsOf, sr.SysdynModelicaFunction))) { - String name = NameUtils.getSafeName(graph, r); - String inputStr = getFunctionInputs(graph, sr, r); - functions.add(new Function(name, inputStr, Type.SYSDYN)); - } - - // Add Vensim functions - Resource subFunctionLibrary = graph.getPossibleResource(SysdynResource.URIs.Built$in_Functions_Vensim_Functions); - for(Resource r : graph.syncRequest(new ObjectsWithType(subFunctionLibrary, l0.ConsistsOf, sr.SysdynModelicaFunction))) { - String name = NameUtils.getSafeName(graph, r); - String inputStr = getFunctionInputs(graph, sr, r); - functions.add(new Function(name, inputStr, Type.VENSIM)); - } - - // Add Modelica functions - subFunctionLibrary = graph.getPossibleResource(SysdynResource.URIs.Built$in_Functions_Modelica_Functions); - for(Resource r : graph.syncRequest(new ObjectsWithType(subFunctionLibrary, l0.ConsistsOf, sr.SysdynModelicaFunction))) { - String name = NameUtils.getSafeName(graph, r); - String inputStr = getFunctionInputs(graph, sr, r); - functions.add(new Function(name, inputStr, Type.MODELICA)); - } - - // Add Modelica array functions - subFunctionLibrary = graph.getPossibleResource(SysdynResource.URIs.Built$in_Functions_Modelica_Array_Functions); - for(Resource r : graph.syncRequest(new ObjectsWithType(subFunctionLibrary, l0.ConsistsOf, sr.SysdynModelicaFunction))) { - String name = NameUtils.getSafeName(graph, r); - String inputStr = getFunctionInputs(graph, sr, r); - functions.add(new Function(name, inputStr, Type.MODELICA_ARRAY)); - } - + + // Add different types of functions. + functions.addAll(getFunctionsOfType(graph, SysdynResource.URIs.Built$in_Functions, Type.SYSDYN)); + functions.addAll(getFunctionsOfType(graph, SysdynResource.URIs.Built$in_Functions_Vensim_Functions, Type.VENSIM)); + functions.addAll(getFunctionsOfType(graph, SysdynResource.URIs.Built$in_Functions_Modelica_Functions, Type.MODELICA)); + functions.addAll(getFunctionsOfType(graph, SysdynResource.URIs.Built$in_Functions_Modelica_Array_Functions, Type.MODELICA_ARRAY)); return functions; } }); @@ -189,4 +200,15 @@ public class Function implements Comparable{ return result; } + + /** + * Converts the description string to HTML-format + * @return HMTL-formatted description. + */ + public String getDescriptionHTML() { + if (description == null) + return null; + return description.replaceAll("<", "<").replaceAll(">", ">").replaceAll("\n", "
"); + } + } -- 2.47.1