Skip to content

Commit

Permalink
controlsfx#1283 Add revalidate method (controlsfx#1292)
Browse files Browse the repository at this point in the history
(cherry picked from commit dd11dc9)
  • Loading branch information
shollander authored Jul 28, 2020
1 parent d30549e commit 49e12cc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) 2020, ControlsFX
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of ControlsFX, any associated website, nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CONTROLSFX BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.controlsfx.validation;

import javafx.event.Event;
import javafx.event.EventType;

public class ValidateEvent extends Event {
private static final long serialVersionUID = 1L;

public static final EventType<Event> EVENT_TYPE = new EventType<>("VALIDATE_EVENT");

public ValidateEvent() {
super(EVENT_TYPE);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2014, 2015, ControlsFX
* Copyright (c) 2014, 2015, 2020, ControlsFX
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -159,6 +159,24 @@ public void redecorate() {
});
}
}

/**
* Triggers validation for all known components.
* It is only necessary to call this if it is needed to revalidate even if the value of the control has not changed.
*/
public void revalidate() {
for (Control target : getRegisteredControls()) {
target.fireEvent(new ValidateEvent());
}
}

/**
* Triggers validation for the given component.
* It is only necessary to call this if it is needed to revalidate even if the value of the control has not changed.
*/
public void revalidate(Control c) {
c.fireEvent(new ValidateEvent());
}

private BooleanProperty errorDecorationEnabledProperty = new SimpleBooleanProperty(true) {
protected void invalidated() {
Expand Down Expand Up @@ -292,6 +310,7 @@ public void onChanged(
dataChanged.set(true);
updateResults.accept(newValue);
});
c.addEventHandler(ValidateEvent.EVENT_TYPE, event -> updateResults.accept(observable.getValue()));
updateResults.accept(observable.getValue());

return e;
Expand Down

0 comments on commit 49e12cc

Please sign in to comment.