1 /*******************************************************************************
\r
2 * Copyright (c) 2010 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.properties.widgets.factories;
\r
14 import org.eclipse.jface.dialogs.IInputValidator;
\r
15 import org.eclipse.jface.viewers.ISelection;
\r
16 import org.simantics.browsing.ui.swt.widgets.impl.Widget;
\r
17 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
18 import org.simantics.db.Resource;
\r
19 import org.simantics.db.management.ISessionContext;
\r
20 import org.simantics.sysdyn.ui.utils.VariableNameUtils;
\r
21 import org.simantics.utils.ui.ISelectionUtils;
\r
23 public class VariableNameValidator implements IInputValidator, Widget {
\r
25 private Resource lastInput = null;
\r
27 public VariableNameValidator(WidgetSupport support) {
\r
28 support.register(this);
\r
32 * Checks that the syntax of the given name is valid and there
\r
33 * are no other components that have the same name in the configuration.
\r
36 public String isValid(final String newText) {
\r
37 if (!VariableNameUtils.isValid(lastInput, newText, true))
\r
42 if(lastInput == null) return null;
\r
43 String result = null;
\r
45 result = SimanticsUI.getSession().syncRequest(new Read<String>(){
\r
48 public String perform(ReadGraph graph) throws DatabaseException {
\r
49 if(VariableNameUtils.nameIsTaken(graph, lastInput, newText)) {
\r
50 return "Name is taken.";
\r
56 } catch (DatabaseException e) {
\r
57 e.printStackTrace();
\r
65 public void setInput(ISessionContext context, Object input) {
\r
66 lastInput = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);
\r