1 package org.simantics.sysdyn.ui.properties.widgets.factories;
\r
3 import org.eclipse.jface.dialogs.IInputValidator;
\r
4 import org.eclipse.jface.viewers.ISelection;
\r
5 import org.simantics.browsing.ui.swt.widgets.impl.Widget;
\r
6 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
7 import org.simantics.db.ReadGraph;
\r
8 import org.simantics.db.Resource;
\r
9 import org.simantics.db.exception.DatabaseException;
\r
10 import org.simantics.db.management.ISessionContext;
\r
11 import org.simantics.db.request.Read;
\r
12 import org.simantics.sysdyn.ui.properties.VariableNameUtils;
\r
13 import org.simantics.ui.SimanticsUI;
\r
14 import org.simantics.utils.ui.ISelectionUtils;
\r
16 public class VariableNameValidator implements IInputValidator, Widget {
\r
18 private Resource lastInput = null;
\r
20 public VariableNameValidator(WidgetSupport support) {
\r
21 support.register(this);
\r
25 * Checks that the syntax of the given name is valid and there
\r
26 * are no other components that have the same name in the configuration.
\r
29 public String isValid(final String newText) {
\r
30 if (!VariableNameUtils.isValid(newText))
\r
31 return "Sorry but spaces and special characters are not allowed for names right now";
\r
32 if(lastInput == null) return null;
\r
33 String result = null;
\r
35 result = SimanticsUI.getSession().syncRequest(new Read<String>(){
\r
38 public String perform(ReadGraph graph) throws DatabaseException {
\r
39 if(VariableNameUtils.nameIsTaken(graph, lastInput, newText)) {
\r
40 return "Name is taken.";
\r
46 } catch (DatabaseException e) {
\r
47 e.printStackTrace();
\r
54 public void setInput(ISessionContext context, Object input) {
\r
55 lastInput = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);
\r