From b6f35ec2d656155e51bc4b8e33c4a80b83628b34 Mon Sep 17 00:00:00 2001 From: melander Date: Fri, 19 Aug 2011 11:03:51 +0000 Subject: [PATCH] Get available function-list from resource. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@21827 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../properties/widgets/ShortcutTabWidget.java | 86 ++++++++++++++----- 1 file changed, 66 insertions(+), 20 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java index cbe8af81..4edaba63 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java @@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.properties.widgets; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.concurrent.CopyOnWriteArrayList; @@ -32,6 +33,8 @@ import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.AsyncReadGraph; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; import org.simantics.db.procedure.AsyncListener; @@ -49,6 +52,7 @@ public class ShortcutTabWidget implements Widget { Table variableTable; Table functionTable; Composite composite; + TableItem item2; CopyOnWriteArrayList dependencyListeners = new CopyOnWriteArrayList(); @@ -71,28 +75,70 @@ public class ShortcutTabWidget implements Widget { functions = new TabItem(tabFolder, SWT.NULL); functions.setText("Functions"); + functionTable = new Table (tabFolder, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); TableItem item = new TableItem(functionTable, SWT.NONE); - item.setText("min()"); - item.setData("min({ })"); - item = new TableItem(functionTable, SWT.NONE); - item.setText("max()"); - item.setData("max({ })"); - item = new TableItem(functionTable, SWT.NONE); - item.setText("abs()"); - item.setData("abs({ })"); - item = new TableItem(functionTable, SWT.NONE); - item.setText("if then else"); - item.setData("if then else"); - item = new TableItem(functionTable, SWT.NONE); - item.setText("xidz()"); - item.setData("xidz( number, divisor , x)"); - item = new TableItem(functionTable, SWT.NONE); - item.setText("interpolate()"); - item.setData("interpolate( x, table)"); - item = new TableItem(functionTable, SWT.NONE); - item.setText("delay()"); - item.setData("delay( expression, delayTime)"); + + //Finding functions + ArrayList funktio = new ArrayList(); + try { + funktio = SimanticsUI.getSession().syncRequest(new Read>() { + @Override + public ArrayList perform(ReadGraph graph) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + ArrayList funktiot = new ArrayList(); + + Resource funktionlibrary = graph.getPossibleResource("http://www.simantics.org/Sysdyn-1.0/Built-in%20Functions"); + for(Resource r : graph.syncRequest(new ObjectsWithType(funktionlibrary, l0.ConsistsOf, sr.SysdynModelicaFunction))) { + String name = NameUtils.getSafeName(graph, r); + funktiot.add(name); + } + + Resource subfunktionlibrary = graph.getPossibleResource("http://www.simantics.org/Sysdyn-1.0/Built-in%20Functions/Vensim%20Functions"); + for(Resource r : graph.syncRequest(new ObjectsWithType(subfunktionlibrary, l0.ConsistsOf, sr.SysdynModelicaFunction))) { + String name = NameUtils.getSafeName(graph, r); + funktiot.add(name); + } + + return funktiot; + } + }); + } + catch (DatabaseException e) { + e.printStackTrace(); + } + + Collections.sort(funktio); + + for(int a=0; a < funktio.size(); a++){ + item.setText(funktio.get(a)+"()"); + item.setData(funktio.get(a)+"({})"); + item = new TableItem(functionTable, SWT.NONE); + } + +// TableItem item = new TableItem(functionTable, SWT.NONE); +// item.setText("min()"); +// item.setData("min({ })"); +// item = new TableItem(functionTable, SWT.NONE); +// item.setText("max()"); +// item.setData("max({ })"); +// item = new TableItem(functionTable, SWT.NONE); +// item.setText("abs()"); +// item.setData("abs({ })"); +// item = new TableItem(functionTable, SWT.NONE); +// item.setText("if then else"); +// item.setData("if then else"); +// item = new TableItem(functionTable, SWT.NONE); +// item.setText("xidz()"); +// item.setData("xidz( number, divisor , x)"); +// item = new TableItem(functionTable, SWT.NONE); +// item.setText("interpolate()"); +// item.setData("interpolate( x, table)"); +// item = new TableItem(functionTable, SWT.NONE); +// item.setText("delay()"); +// item.setData("delay( expression, delayTime)"); functions.setControl(functionTable); } -- 2.47.1