From: lempinen Date: Wed, 12 Sep 2012 07:27:43 +0000 (+0000) Subject: Modelled property tabs for SVG (svg code) and Document (css code) selections. (refs... X-Git-Tag: simantics-1.7~3^2~6 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=2dacd7dead70076558e2803e4138f675f5d64baa;p=simantics%2Fsysdyn.git Modelled property tabs for SVG (svg code) and Document (css code) selections. (refs #3511) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25714 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index 56e6f916..6576dd32 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -22,8 +22,9 @@ SYSDYN.ImportedOntologies : PROJ.NamespaceRequirement PROJ.RequiresNamespace "http://www.simantics.org/Sysdyn-1.1" : L0.URI "http://www.simantics.org/Layer0-1.1" : L0.URI -// "http://www.simantics.org/Documentation-1.1" : L0.URI // Experimental documentation tool "http://www.simantics.org/SelectionView-1.2" : L0.URI +// "http://www.simantics.org/Documentation-1.1" : L0.URI // Experimental documentation tool +// "http://www.simantics.org/DocumentWorkbench-1.0" : L0.URI // Experimental documentation tool SYSDYN.SharedFunctionOntology selectionTransformation = new BinaryFunction() { + + /* + private Key[] KEYS = new Key[] { SelectionHints.KEY_MAIN }; + + @Override + public Object[] call(GraphExplorer explorer, Object[] objects) { + Object[] result = new Object[objects.length]; + for (int i = 0; i < objects.length; i++) { + SelectionElement context = new SelectionElement(KEYS, objects[i]); + context.setHint(SelectionHints.KEY_MAIN, objects[i]); + result[i] = context; + } + return result; + } + */ + + class SelectionElement extends AdaptableHintContext { + + private Variable variable; + private Resource resource; + + public SelectionElement(Variable variable, Resource resource, Key... keys) { + super(keys); + this.variable = variable; + this.resource = resource; + } + + @SuppressWarnings("unchecked") + @Override + public T getContent(WorkbenchSelectionContentType contentType) { + if(contentType instanceof AnyResource) return (T)resource; + else if(contentType instanceof AnyVariable) { + AnyVariable type = (AnyVariable)contentType; + try { + + if(variable != null) return (T)variable; + + if(resource == null) return null; + + return (T) type.processor.sync(new ResourceRead(resource) { + @Override + public Variable perform(ReadGraph graph) throws DatabaseException { + return Variables.getPossibleVariable(graph, resource); + } + + }); + } catch (DatabaseException e) { + Logger.defaultLogError(e); + } + } + return null; + } + + } + @Override public Object[] call(GraphExplorer explorer, Object[] objects) { Object[] result = new Object[objects.length]; @@ -57,11 +121,12 @@ public class SysdynBrowser extends GraphExplorerView { VariableNode vn = (VariableNode) ctx.getAdapter(VariableNode.class); IHintContext context; if(vn != null && vn.getVariable() != null) { - context = new AdaptableHintContext(SelectionHints.KEY_MAIN, SelectionHints.KEY_SELECTION_PROPERTY); + context = new SelectionElement(vn.getVariable(),vn.data, SelectionHints.KEY_MAIN, SelectionHints.KEY_SELECTION_PROPERTY); context.setHint(SelectionHints.KEY_MAIN, new BrowserSelection(objects[i], vn)); context.setHint(SelectionHints.KEY_SELECTION_PROPERTY, vn.getVariable()); } else { - context = new AdaptableHintContext(SelectionHints.KEY_MAIN); + Object resource = ctx.getAdapter(Resource.class); + context = new SelectionElement(null, resource == null ? null : (Resource)resource, SelectionHints.KEY_MAIN); context.setHint(SelectionHints.KEY_MAIN, objects[i]); } result[i] = context; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java index c866309c..0b623ee4 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -60,410 +60,410 @@ import org.simantics.utils.ui.ISelectionUtils; */ public class ResourceSelectionProcessor implements SelectionProcessor { - private SpecialNodeType sharedFunctionsTestNode; - - @Override - public Collection process(Object selection, ReadGraph backend) { - Collection tabs = new ArrayList(); - SysdynResource sr = SysdynResource.getInstance(backend); - DiagramResource dr = DiagramResource.getInstance(backend); - ModelingResources mr = ModelingResources.getInstance(backend); - SimulationResource simu = SimulationResource.getInstance(backend); - JFreeChartResource jfree = JFreeChartResource.getInstance(backend); - - // Test nodes - if(sharedFunctionsTestNode == null) - sharedFunctionsTestNode = new SpecialNodeType(sr.ModelingBrowseContext_SharedFunctionsFolder, Resource.class); - - try { - // Many elements - if (selection instanceof ArrayList && ((ArrayList) selection).size() > 1) { - List independentVariables = new ArrayList(); - Resource model = null; - for(Object o : (ArrayList)selection) { - Resource r = AdaptionUtils.adaptToSingle(o, Resource.class); - if(r != null && backend.isInstanceOf(r, sr.IndependentVariable)) { - if(model == null) - model = backend.getSingleObject(r, Layer0.getInstance(backend).PartOf); - if(model.equals( backend.getSingleObject(r, Layer0.getInstance(backend).PartOf))) - independentVariables.add(r); - } - } - - tabs.add(new ComparableTabContributor( - new ArrayIndexesTab(), - 1, - independentVariables, - "Indexes")); - - return tabs; - } - - // Single element - Variable var = null; - WorkbenchSelectionElement wse = ISelectionUtils.filterSingleSelection(selection, WorkbenchSelectionElement.class); - if(wse != null) { - var = wse.getContent(new AnyVariable(backend)); - if(var == null) { - var = AdaptionUtils.adaptToSingle(selection, Variable.class); - if(var != null) { - Variable possibleActiveVariable = backend.syncRequest(new PossibleActiveVariableFromVariable(var)); - if(possibleActiveVariable != null) - var = possibleActiveVariable; - } - } - } - - Resource r = AdaptionUtils.adaptToSingle(selection, Resource.class); - if(r == null) { - // Selection is not directly a resource, try if it is a variable - var = AdaptionUtils.adaptToSingle(selection, Variable.class); - r = var.getRepresents(backend); - } - - if(r == null) { - // SharedFunctionsFolder has properties but no adapted resource - SharedFunctionsFolder sff = AdaptionUtils.adaptToSingle(selection, SharedFunctionsFolder.class); - if (sff != null) { - return Collections.singleton(new ComparableTabContributor( - new SharedFunctionLibrariesTab(), - 2, - sff.data, - "Shared Functions")); - } - - return Collections.emptyList(); - } - - NodeContext nc = AdaptionUtils.adaptToSingle(selection, NodeContext.class); - if(nc != null) { - NodeType type = nc.getConstant(NodeType.TYPE); - if(type != null && type.equals(sharedFunctionsTestNode)) { - return Collections.singleton(new ComparableTabContributor( - new SharedFunctionLibrariesTab(), - 2, - r, - "Shared Functions")); - } - } - - // SVG elements in symbol editor + private SpecialNodeType sharedFunctionsTestNode; + + @Override + public Collection process(Object selection, ReadGraph backend) { + Collection tabs = new ArrayList(); + SysdynResource sr = SysdynResource.getInstance(backend); + DiagramResource dr = DiagramResource.getInstance(backend); + ModelingResources mr = ModelingResources.getInstance(backend); + SimulationResource simu = SimulationResource.getInstance(backend); + JFreeChartResource jfree = JFreeChartResource.getInstance(backend); + + // Test nodes + if(sharedFunctionsTestNode == null) + sharedFunctionsTestNode = new SpecialNodeType(sr.ModelingBrowseContext_SharedFunctionsFolder, Resource.class); + + try { + // Many elements + if (selection instanceof ArrayList && ((ArrayList) selection).size() > 1) { + List independentVariables = new ArrayList(); + Resource model = null; + for(Object o : (ArrayList)selection) { + Resource r = AdaptionUtils.adaptToSingle(o, Resource.class); + if(r != null && backend.isInstanceOf(r, sr.IndependentVariable)) { + if(model == null) + model = backend.getSingleObject(r, Layer0.getInstance(backend).PartOf); + if(model.equals( backend.getSingleObject(r, Layer0.getInstance(backend).PartOf))) + independentVariables.add(r); + } + } + + tabs.add(new ComparableTabContributor( + new ArrayIndexesTab(), + 1, + independentVariables, + "Indexes")); + + return tabs; + } + + // Single element + Variable var = null; + WorkbenchSelectionElement wse = ISelectionUtils.filterSingleSelection(selection, WorkbenchSelectionElement.class); + if(wse != null) { + var = wse.getContent(new AnyVariable(backend)); + if(var == null) { + var = AdaptionUtils.adaptToSingle(selection, Variable.class); + if(var != null) { + Variable possibleActiveVariable = backend.syncRequest(new PossibleActiveVariableFromVariable(var)); + if(possibleActiveVariable != null) + var = possibleActiveVariable; + } + } + } + + Resource r = AdaptionUtils.adaptToSingle(selection, Resource.class); + if(r == null) { + // Selection is not directly a resource, try if it is a variable + var = AdaptionUtils.adaptToSingle(selection, Variable.class); + r = var.getRepresents(backend); + } + + if(r == null) { + // SharedFunctionsFolder has properties but no adapted resource + SharedFunctionsFolder sff = AdaptionUtils.adaptToSingle(selection, SharedFunctionsFolder.class); + if (sff != null) { + return Collections.singleton(new ComparableTabContributor( + new SharedFunctionLibrariesTab(), + 2, + sff.data, + "Shared Functions")); + } + + return Collections.emptyList(); + } + + NodeContext nc = AdaptionUtils.adaptToSingle(selection, NodeContext.class); + if(nc != null) { + NodeType type = nc.getConstant(NodeType.TYPE); + if(type != null && type.equals(sharedFunctionsTestNode)) { + return Collections.singleton(new ComparableTabContributor( + new SharedFunctionLibrariesTab(), + 2, + r, + "Shared Functions")); + } + } + + // SVG elements in symbol editor if (backend.isInstanceOf(r, dr.SVGElement)) return Collections.singleton(SVGElementComposite.make(r, 1, "SVG")); - // if r == diagram element, change it to component - if (backend.isInstanceOf(r, dr.Element)) { - Resource component = backend.getPossibleObject(r, mr.ElementToComponent); - if (component != null) { - r = component; - } else { - Resource connection = backend.getPossibleObject(r, mr.DiagramConnectionToConnection); - if(connection != null) - r = connection; - } - } - - // Independent variable - if (backend.isInstanceOf(r, sr.IndependentVariable)) { - Resource activeExpression = backend.getPossibleObject(r, sr.IndependentVariable_activeExpression); - Resource expression = null; - if(activeExpression != null) - // if variable has active expression, display it - expression = activeExpression; - else if (backend.hasStatement(r, sr.Variable_expressions)){ - // else display the first expression of the variable - Resource expressions = backend.getPossibleObject(r, sr.Variable_expressions); - List expressionList = OrderedSetUtils.toList(backend, expressions); - if(expressionList.isEmpty()) { - System.err.println("expressionList is empty for " + r); - return Collections.emptyList(); - } - expression = expressionList.get(0); - } - tabs.add(new ComparableTabContributor( - new EquationTab(), - 3, - var != null ? var : r, - "Equation")); - if(expression != null && backend.isInstanceOf(expression, sr.WithLookupExpression)) { - // WithLookupExpression has its own extra tab for visual configuration - tabs.add(new ComparableTabContributor( - new LookupTableTab(), - 2, - expression, - "Lookup Table")); - } - - tabs.add(new ComparableTabContributor( - new ArrayIndexesTab(), - 1, - r, - "Indexes")); - - tabs.add(new ComparableTabContributor( - new VariableInformationTab(), - 0, - r, - "Additional Information")); - return tabs; - } - - // Input variable - if (backend.isInstanceOf(r, sr.Input)) { - tabs.add(new ComparableTabContributor( - new InputVariableTab(), - 2, - r, - "Input")); - - tabs.add(new ComparableTabContributor( - new ArrayIndexesTab(), - 1, - r, - "Indexes")); - - tabs.add(new ComparableTabContributor( - new VariableInformationTab(), - 0, - r, - "Additional Information")); - return tabs; - } - - // Enumeration - if (backend.isInstanceOf(r, sr.Enumeration)) { - Object s = AdaptionUtils.adaptToSingle(selection, ISelection.class); - if(s == null) - s = r; - // give either variable or the actual resource - return Collections.singleton(new ComparableTabContributor( - new EnumerationTab(), - 2, - s, - "Enumeration")); - } - - // Configuration and model. They both show the properties of the configuration - if ( backend.isInstanceOf(r, sr.Configuration) || backend.isInstanceOf(r, sr.SysdynModel)) { - if(!backend.isInstanceOf(r, sr.SysdynModel)) - r = backend.getPossibleObject(r, SimulationResource.getInstance(backend).IsConfigurationOf); - if (r != null) - return Collections.singleton( - new ComparableTabContributor( - new ConfigurationTab(), - 0, - r, - "Model Properties")); - } - - // Module - if (backend.isInstanceOf(r, sr.Module)){ - tabs.add(new ComparableTabContributor( - new ModuleTab(), - 10, - r, - "Module Properties")); - tabs.add(new ComparableTabContributor( - new ModuleParameterTab(), - 9, - r, - "Parameters")); - tabs.add(new ComparableTabContributor( - new ModuleInputTab(), - 2, - r, - "Inputs")); - tabs.add(new ComparableTabContributor( - new ModuleOutputTab(), - 1, - r, - "Outputs")); - return tabs; - } - - // Playback experiment - if (backend.isInstanceOf(r, sr.PlaybackExperiment)) - return Collections.singleton( - new ComparableTabContributor( - new PlaybackExperimentTab(), - 0, - r, - "Experiment Properties")); - - // Game experiment - if (backend.isInstanceOf(r, sr.GameExperiment)) - return Collections.singleton( - new ComparableTabContributor( - new GameExperimentTab(), - 0, - r, - "Experiment Properties")); - - // Default experiment - if (backend.isInstanceOf(r, simu.Experiment)) - return Collections.singleton( - new ComparableTabContributor( - new ExperimentTab(), - 0, - r, - "Experiment Properties")); - - // History data - if (backend.isInstanceOf(r, sr.HistoryDataset)) - return Collections.singleton( - new ComparableTabContributor( - new HistoryDataTab(), - 0, - r, - "History Data Properties")); - - // Saved simulation result - if (backend.isInstanceOf(r, sr.Result)) - return Collections.singleton( - new ComparableTabContributor( - new ResultTab(), - 0, - r, - "Result Properties")); - - // Dependency - if (backend.isInstanceOf(r, sr.Dependency)) - if (backend.hasStatement(r, sr.Dependency_refersTo)) - return Collections.singleton( - new ComparableTabContributor( - new ReferenceDependencyTab(), - 0, - r, - "Reference Properties")); - else { - Resource diaConnection = backend.getPossibleObject(r, ModelingResources.getInstance(backend).ConnectionToDiagramConnection); - return Collections.singleton( - new ComparableTabContributor( - new DependencyTab(), - 0, - diaConnection, - "Dependency Properties")); - } - - // Module symbol. Modules in modules-folder are actually symbol resources - if (backend.isInheritedFrom(r, sr.ModuleSymbol)) { - // Find the component resource - r = backend.getPossibleObject(r, mr.SymbolToComponentType); - if(r != null) - return Collections.singleton( - new ComparableTabContributor( - new ModuleTypeTab(), - 0, - r, - "Module Type Properties")); - } - - // Function - if (backend.isInstanceOf(r, sr.SysdynModelicaFunction)) { - tabs.add(new ComparableTabContributor( - new FunctionTab(), - 2, - r, - "Function")); - tabs.add(new ComparableTabContributor( - new ExternalFilesTab(), - 1, - r, - "External files")); - return tabs; - } - - // Function library - if (backend.isInstanceOf(r, sr.SysdynModelicaFunctionLibrary)) { - Object s = AdaptionUtils.adaptToSingle(selection, ISelection.class); - if(s == null) - s = r; - // give either variable or the actual resource - return Collections.singleton(new ComparableTabContributor( - new FunctionLibraryTab(), - 2, - s, - "Function library")); - } - - // Chart Element - if(backend.isInstanceOf(r, jfree.ChartElement)) { - if(backend.hasStatement(r, jfree.ChartElement_component)) - r = backend.getSingleObject(r, jfree.ChartElement_component); - } - // Chart - if (backend.isInstanceOf(r, jfree.Chart)) { - - Collection plots = backend.syncRequest(new ObjectsWithType(r, Layer0.getInstance(backend).ConsistsOf, jfree.Plot)); - if(!plots.isEmpty()) { - Resource plot = plots.iterator().next(); - - if(backend.isInstanceOf(plot, jfree.XYPlot)) { - tabs.add(new ComparableTabContributor( - new XYLineGeneralPropertiesTab(), - 10, - r, - "General")); - tabs.add(new ComparableTabContributor( - new XYLineAxisAndVariablesTab(), - 9, - r, - "Axis and Variables")); - } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) { - tabs.add(new ComparableTabContributor( - new BarGeneralPropertiesTab(), - 10, - r, - "General")); - tabs.add(new ComparableTabContributor( - new BarSeriesTab(), - 9, - r, - "Variables")); - tabs.add(new ComparableTabContributor( - new BarAxisTab(), - 8, - r, - "Axis")); - } else if(backend.isInstanceOf(plot, jfree.PiePlot)) { - tabs.add(new ComparableTabContributor( - new PieGeneralPropertiesTab(), - 10, - r, - "General")); - tabs.add(new ComparableTabContributor( - new PieSeriesTab(), - 9, - r, - "Variables")); - } - - tabs.add(new ComparableTabContributor( - new ChartTab(), - 1, - r, - "Chart")); - return tabs; - - } - } - - // Default experiment - if (backend.isInstanceOf(r, sr.AdditionalSymbols_MultilineText)) - return Collections.singleton( - new ComparableTabContributor( - new CommentTab(), - 0, - r, - "Comment")); - - } catch (ServiceException e) { - e.printStackTrace(); - } catch (ManyObjectsForFunctionalRelationException e) { - e.printStackTrace(); - } catch (DatabaseException e) { - e.printStackTrace(); - } - return Collections.emptyList(); - } + // if r == diagram element, change it to component + if (backend.isInstanceOf(r, dr.Element)) { + Resource component = backend.getPossibleObject(r, mr.ElementToComponent); + if (component != null) { + r = component; + } else { + Resource connection = backend.getPossibleObject(r, mr.DiagramConnectionToConnection); + if(connection != null) + r = connection; + } + } + + // Independent variable + if (backend.isInstanceOf(r, sr.IndependentVariable)) { + Resource activeExpression = backend.getPossibleObject(r, sr.IndependentVariable_activeExpression); + Resource expression = null; + if(activeExpression != null) + // if variable has active expression, display it + expression = activeExpression; + else if (backend.hasStatement(r, sr.Variable_expressions)){ + // else display the first expression of the variable + Resource expressions = backend.getPossibleObject(r, sr.Variable_expressions); + List expressionList = OrderedSetUtils.toList(backend, expressions); + if(expressionList.isEmpty()) { + System.err.println("expressionList is empty for " + r); + return Collections.emptyList(); + } + expression = expressionList.get(0); + } + tabs.add(new ComparableTabContributor( + new EquationTab(), + 3, + var != null ? var : r, + "Equation")); + if(expression != null && backend.isInstanceOf(expression, sr.WithLookupExpression)) { + // WithLookupExpression has its own extra tab for visual configuration + tabs.add(new ComparableTabContributor( + new LookupTableTab(), + 2, + expression, + "Lookup Table")); + } + + tabs.add(new ComparableTabContributor( + new ArrayIndexesTab(), + 1, + r, + "Indexes")); + + tabs.add(new ComparableTabContributor( + new VariableInformationTab(), + 0, + r, + "Additional Information")); + return tabs; + } + + // Input variable + if (backend.isInstanceOf(r, sr.Input)) { + tabs.add(new ComparableTabContributor( + new InputVariableTab(), + 2, + r, + "Input")); + + tabs.add(new ComparableTabContributor( + new ArrayIndexesTab(), + 1, + r, + "Indexes")); + + tabs.add(new ComparableTabContributor( + new VariableInformationTab(), + 0, + r, + "Additional Information")); + return tabs; + } + + // Enumeration + if (backend.isInstanceOf(r, sr.Enumeration)) { + Object s = AdaptionUtils.adaptToSingle(selection, ISelection.class); + if(s == null) + s = r; + // give either variable or the actual resource + return Collections.singleton(new ComparableTabContributor( + new EnumerationTab(), + 2, + s, + "Enumeration")); + } + + // Configuration and model. They both show the properties of the configuration + if ( backend.isInstanceOf(r, sr.Configuration) || backend.isInstanceOf(r, sr.SysdynModel)) { + if(!backend.isInstanceOf(r, sr.SysdynModel)) + r = backend.getPossibleObject(r, SimulationResource.getInstance(backend).IsConfigurationOf); + if (r != null) + return Collections.singleton( + new ComparableTabContributor( + new ConfigurationTab(), + 0, + r, + "Model Properties")); + } + + // Module + if (backend.isInstanceOf(r, sr.Module)){ + tabs.add(new ComparableTabContributor( + new ModuleTab(), + 10, + r, + "Module Properties")); + tabs.add(new ComparableTabContributor( + new ModuleParameterTab(), + 9, + r, + "Parameters")); + tabs.add(new ComparableTabContributor( + new ModuleInputTab(), + 2, + r, + "Inputs")); + tabs.add(new ComparableTabContributor( + new ModuleOutputTab(), + 1, + r, + "Outputs")); + return tabs; + } + + // Playback experiment + if (backend.isInstanceOf(r, sr.PlaybackExperiment)) + return Collections.singleton( + new ComparableTabContributor( + new PlaybackExperimentTab(), + 0, + r, + "Experiment Properties")); + + // Game experiment + if (backend.isInstanceOf(r, sr.GameExperiment)) + return Collections.singleton( + new ComparableTabContributor( + new GameExperimentTab(), + 0, + r, + "Experiment Properties")); + + // Default experiment + if (backend.isInstanceOf(r, simu.Experiment)) + return Collections.singleton( + new ComparableTabContributor( + new ExperimentTab(), + 0, + r, + "Experiment Properties")); + + // History data + if (backend.isInstanceOf(r, sr.HistoryDataset)) + return Collections.singleton( + new ComparableTabContributor( + new HistoryDataTab(), + 0, + r, + "History Data Properties")); + + // Saved simulation result + if (backend.isInstanceOf(r, sr.Result)) + return Collections.singleton( + new ComparableTabContributor( + new ResultTab(), + 0, + r, + "Result Properties")); + + // Dependency + if (backend.isInstanceOf(r, sr.Dependency)) + if (backend.hasStatement(r, sr.Dependency_refersTo)) + return Collections.singleton( + new ComparableTabContributor( + new ReferenceDependencyTab(), + 0, + r, + "Reference Properties")); + else { + Resource diaConnection = backend.getPossibleObject(r, ModelingResources.getInstance(backend).ConnectionToDiagramConnection); + return Collections.singleton( + new ComparableTabContributor( + new DependencyTab(), + 0, + diaConnection, + "Dependency Properties")); + } + + // Module symbol. Modules in modules-folder are actually symbol resources + if (backend.isInheritedFrom(r, sr.ModuleSymbol)) { + // Find the component resource + r = backend.getPossibleObject(r, mr.SymbolToComponentType); + if(r != null) + return Collections.singleton( + new ComparableTabContributor( + new ModuleTypeTab(), + 0, + r, + "Module Type Properties")); + } + + // Function + if (backend.isInstanceOf(r, sr.SysdynModelicaFunction)) { + tabs.add(new ComparableTabContributor( + new FunctionTab(), + 2, + r, + "Function")); + tabs.add(new ComparableTabContributor( + new ExternalFilesTab(), + 1, + r, + "External files")); + return tabs; + } + + // Function library + if (backend.isInstanceOf(r, sr.SysdynModelicaFunctionLibrary)) { + Object s = AdaptionUtils.adaptToSingle(selection, ISelection.class); + if(s == null) + s = r; + // give either variable or the actual resource + return Collections.singleton(new ComparableTabContributor( + new FunctionLibraryTab(), + 2, + s, + "Function library")); + } + + // Chart Element + if(backend.isInstanceOf(r, jfree.ChartElement)) { + if(backend.hasStatement(r, jfree.ChartElement_component)) + r = backend.getSingleObject(r, jfree.ChartElement_component); + } + // Chart + if (backend.isInstanceOf(r, jfree.Chart)) { + + Collection plots = backend.syncRequest(new ObjectsWithType(r, Layer0.getInstance(backend).ConsistsOf, jfree.Plot)); + if(!plots.isEmpty()) { + Resource plot = plots.iterator().next(); + + if(backend.isInstanceOf(plot, jfree.XYPlot)) { + tabs.add(new ComparableTabContributor( + new XYLineGeneralPropertiesTab(), + 10, + r, + "General")); + tabs.add(new ComparableTabContributor( + new XYLineAxisAndVariablesTab(), + 9, + r, + "Axis and Variables")); + } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) { + tabs.add(new ComparableTabContributor( + new BarGeneralPropertiesTab(), + 10, + r, + "General")); + tabs.add(new ComparableTabContributor( + new BarSeriesTab(), + 9, + r, + "Variables")); + tabs.add(new ComparableTabContributor( + new BarAxisTab(), + 8, + r, + "Axis")); + } else if(backend.isInstanceOf(plot, jfree.PiePlot)) { + tabs.add(new ComparableTabContributor( + new PieGeneralPropertiesTab(), + 10, + r, + "General")); + tabs.add(new ComparableTabContributor( + new PieSeriesTab(), + 9, + r, + "Variables")); + } + + tabs.add(new ComparableTabContributor( + new ChartTab(), + 1, + r, + "Chart")); + return tabs; + + } + } + + // Default experiment + if (backend.isInstanceOf(r, sr.AdditionalSymbols_MultilineText)) + return Collections.singleton( + new ComparableTabContributor( + new CommentTab(), + 0, + r, + "Comment")); + + } catch (ServiceException e) { + e.printStackTrace(); + } catch (ManyObjectsForFunctionalRelationException e) { + e.printStackTrace(); + } catch (DatabaseException e) { + e.printStackTrace(); + } + return Collections.emptyList(); + } }