Skip to content

Commit

Permalink
[GUI] Bugfix: Some search fields wouldn't validate yoVariables.
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainBertrand committed Apr 4, 2024
1 parent 318f551 commit 87f4966
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class DoubleSearchField extends PropertySearchField<DoubleProperty>
Expand All @@ -42,22 +43,34 @@ protected boolean isTextValid(String text)
{
if (text == null || text.isEmpty())
return false;
if (CompositePropertyTools.isParsableAsDouble(text))
return true;
else
return findYoComposite(text) != null;
}

private YoComposite findYoComposite(String name)
{
YoCompositeCollection yoVariableCollection = searchManager.getYoVariableCollection();
YoComposite yoComposite = yoVariableCollection.getYoCompositeFromUniqueName(text);
if (yoComposite == null)
yoComposite = yoVariableCollection.getYoCompositeFromFullname(text);
return yoComposite != null || CompositePropertyTools.isParsableAsDouble(text);
YoComposite yoComposite = yoVariableCollection.getYoCompositeFromFullname(name);
if (yoComposite != null)
return yoComposite;
else
return yoVariableCollection.getYoCompositeFromUniqueName(name);
}

@Override
protected String simplifyText(String text)
{
YoCompositeCollection yoVariableCollection = searchManager.getYoVariableCollection();
YoComposite yoComposite = yoVariableCollection.getYoCompositeFromFullname(text);
if (CompositePropertyTools.isParsableAsDouble(text))
return null;

YoComposite yoComposite = findYoComposite(text);

if (yoComposite == null)
yoComposite = yoVariableCollection.getYoCompositeFromUniqueName(text);
return yoComposite == null ? null : yoComposite.getUniqueShortName();
return null;
else
return !Objects.equals(yoComposite.getUniqueShortName(), text) ? yoComposite.getUniqueShortName() : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class IntegerSearchField extends PropertySearchField<IntegerProperty>
Expand Down Expand Up @@ -53,20 +54,34 @@ protected boolean isTextValid(String text)
{
if (text == null || text.isEmpty())
return isInputOptional;
if (CompositePropertyTools.isParsableAsInteger(text))
return true;
else
return findYoComposite(text) != null;
}

private YoComposite findYoComposite(String name)
{
YoCompositeCollection yoIntegerCollection = searchManager.getYoIntegerCollection();
YoComposite yoComposite = yoIntegerCollection.getYoCompositeFromUniqueName(text);
if (yoComposite == null)
yoComposite = yoIntegerCollection.getYoCompositeFromFullname(text); // TODO Happens when loading file, needs to update TextField to use unique name.
return yoComposite != null || CompositePropertyTools.isParsableAsInteger(text);
YoComposite yoComposite = yoIntegerCollection.getYoCompositeFromFullname(name);
if (yoComposite != null)
return yoComposite;
else
return yoIntegerCollection.getYoCompositeFromUniqueName(name);
}

@Override
protected String simplifyText(String text)
{
YoCompositeCollection yoIntegerCollection = searchManager.getYoIntegerCollection();
YoComposite yoComposite = yoIntegerCollection.getYoCompositeFromFullname(text);
return yoComposite == null ? null : yoComposite.getUniqueShortName();
if (CompositePropertyTools.isParsableAsInteger(text))
return null;

YoComposite yoComposite = findYoComposite(text);

if (yoComposite == null)
return null;
else
return !Objects.equals(yoComposite.getUniqueShortName(), text) ? yoComposite.getUniqueShortName() : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public PropertySearchField(TextField textField, ImageView validImageView)
return;

String simplifiedText = simplifyText(newValue);
if (simplifiedText != null)
if (simplifiedText != null && !simplifiedText.equals(newValue))
{
textField.setText(simplifiedText);
return;
Expand All @@ -71,6 +71,16 @@ public PropertySearchField(TextField textField, ImageView validImageView)

protected abstract boolean isTextValid(String text);

/**
* Simplify the text to be displayed in the text field.
* <p>
* This method is useful to simplify the text displayed in the text field when the user types.
* It is expected to return {@code null} if the text is already in a simplified form.
* </p>
*
* @param text the text to simplify.
* @return the simplified text, or {@code null} if the text is already in a simplified form.
*/
protected abstract String simplifyText(String text);

protected abstract Callback<ISuggestionRequest, Collection<String>> createSuggestions();
Expand Down

0 comments on commit 87f4966

Please sign in to comment.