1 /*******************************************************************************
\r
2 * Copyright (c) 2012 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.validation;
\r
14 import java.util.Collections;
\r
15 import java.util.List;
\r
17 import org.simantics.db.Issue;
\r
18 import org.simantics.db.ReadGraph;
\r
19 import org.simantics.db.Resource;
\r
20 import org.simantics.db.common.issue.StandardIssue;
\r
21 import org.simantics.db.common.utils.ListUtils;
\r
22 import org.simantics.db.exception.DatabaseException;
\r
23 import org.simantics.db.layer0.variable.Variable;
\r
24 import org.simantics.scl.reflection.annotations.SCLValue;
\r
25 import org.simantics.sysdyn.SysdynResource;
\r
28 * Functions for checking issues in Enumerations
\r
29 * @author Teemu Lempinen
\r
32 public class EnumerationFunction {
\r
34 private static String NO_INDEXES = "Enumeration does not contain indexes.";
\r
36 @SCLValue(type = "ReadGraph -> Resource -> [Issue]")
\r
37 public static List<Issue> enumerationIndexValidator(ReadGraph graph, Resource component) throws DatabaseException {
\r
39 SysdynResource sr = SysdynResource.getInstance(graph);
\r
41 if(!graph.isInstanceOf(component, sr.Enumeration)) {
\r
42 return Collections.emptyList();
\r
45 boolean noIndexes = false;
\r
48 Resource indexList = graph.getPossibleObject(component, sr.Enumeration_enumerationIndexList);
\r
49 List<Resource> indexes = ListUtils.toList(graph, indexList);
\r
50 if(indexes.size() == 0)
\r
52 } catch (DatabaseException e) {
\r
57 return Collections.<Issue>singletonList(new StandardIssue(sr.Validations_EmptyEnumerationIssue, component));
\r
59 return Collections.emptyList();
\r
62 @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")
\r
63 public static String emptyEnumerationIssueDescription(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {
\r