I have List box in new Neon Scout and I would like to validate value that was set.
I have implemented execValidateValue method :
#Override
protected Set<String> execValidateValue(final Set<String> rawValue) {
if (rawValue.contains(CONSTANT.UNKNOWN)) {
final Set<String> unknownSet = new HashSet<String>();
unknownSet.add(CONSTANT.UNKNOWN);
return super.execValidateValue(unknownSet);
}
return super.execValidateValue(rawValue);
}
but it doesn't seams to have any effect. While debugging I see that inside setValue(VALUE rawValue) method updateDisplayText(validatedValue) is called with right list of strings.
Why is that? Is there something that I did wrong?
Marko
You are right... If a value is changed during the validation (in execValidateValue(VALUE rawValue)) as suggested by the JavaDoc, the value is stored correctly in the Scout Model but the change is not reflected in the HTML-UI.
With the help of Samuel Renold, I have asked the team about it: The HTML-UI will be fixed to reflect the change in the UI. See bug 493778.
Test code for the Demo Widgets Application. Change the DefaultField in the ListBoxForm.
#Order(20)
public class DefaultField extends AbstractListBox<Color> {
#Override
protected Class<? extends ICodeType<?, Color>> getConfiguredCodeType() {
return ColorsCodeType.class;
}
#Override
protected Set<Color> execValidateValue(Set<Color> rawValue) {
System.out.println(">> execValidateValue");
printColors(rawValue);
if (rawValue != null && rawValue.contains(Color.RED)) {
return super.execValidateValue(Collections.singleton(Color.RED));
}
return super.execValidateValue(rawValue);
}
private void printColors(Set<Color> rawValue) {
if (rawValue != null) {
for (Color color : rawValue) {
System.out.print(color + ", ");
}
System.out.println("");
}
else {
System.out.println("null");
}
}
#Override
protected void execChangedValue() {
System.out.println(">> execValidateValue");
printColors(getValue());
}
#Override
protected int getConfiguredGridH() {
return 5;
}
#Override
protected String getConfiguredLabel() {
return TEXTS.get("Default");
}
}
The wrong behaviour can also be reproduced in Scout 4 (this release is end-of-life)
Related
After hours of trying i finally somewhat managed to figure out how to hook a listener to TreeItems in a TreeView, it probably isn't at all the right way to do so but hey it works so far.
Although one thing isn't, that is the "label" or better said text in the TreeItems isn't showing up anymore.
Can anyone look at my code and tell me, if i'm either doing it completely wrong or why the text isn't showing up anymore?
Thanks in advance.
Code:
TreeView<String> tree = new TreeView<>();
TreeItem<String> treeRoot = new TreeItem<>(Login.name + " - " + Login.accountType);
treeRoot.getChildren().addAll(new TreeItem<>("Branches"),
new TreeItem<>("Planning"), new TreeItem<>("Courses"),
new TreeItem<>("Add new item"));
treeRoot.getChildren().get(1).getChildren().addAll(
new TreeItem<>("2014 - Q1"), new TreeItem<>("2014 - Q2"),
new TreeItem<>("2014 - Q3"), new TreeItem<>("2014 - Q4"));
treeRoot.getChildren().get(3).getChildren().addAll(
new TreeItem<>("Branch"), new TreeItem<>("Course"));
for(String str : loadBranchData()) {
treeRoot.getChildren().get(0).getChildren().add(
new TreeItem<>(str));
}
for(String str : loadCourseData()) {
treeRoot.getChildren().get(2).getChildren().add(
new TreeItem<>(str));
}
for(int c = 0; c <= 2; c++) {
treeRoot.getChildren().get(c).setExpanded(true);
}
treeRoot.setExpanded(true);
tree.setPrefWidth(PREFWIDTH);
tree.setRoot(treeRoot);
tree.setShowRoot(true);
tree.setCellFactory(new Callback<TreeView<String>,TreeCell<String>>(){
#Override
public TreeCell<String> call(TreeView<String> p) {
return new EpicTreeCell();
}
});
...
private final class EpicTreeCell extends TreeCell<String> {
#SuppressWarnings("unchecked")
super.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent evt) {
System.out.println("TEST?");
}
});
}
When the custom cell is defined, the setText() method should be called in its overridden updateItem() method.
private final class EpicTreeCell extends TreeCell<String> {
public EpicTreeCell() {
setOnMouseClicked (
new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent evt) {
System.out.println("TEST?");
}
}
);
}
#Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
} else {
setText(getItem() == null ? "" : getItem().toString());
}
setGraphic(null);
}
}
See the "Custom Java-fx cellfactory messes up the setCellValueFactory" for more information.
I upgraded my nuget package for the Web API 2 from the RC1 to 5.0.0, and was dumbfounded to find that HttpRouteBuilder, which used to be accessible, was made internal. Along with that, there is no longer an overload for HttpConfiguration.MapHttpAttributeRoutes that takes HttpRouteBuilder as an argument. Why?
I was using that, and it solves a major problem in my project. What do I use instead?
Background:
I am writing a server that uses Attribute Routing for Web API 2. I implemented a class that inherited from HttpRouteBuilder so that I could inject a couple extra path segments to every URI. For example, if the default route builder ended up creating a route for //myserver/user/update, my route builder would modify that route to //myserver/{instance}/user/update. I wanted this done automatically so that I didn't have to stick that in every single of my hundreds of HttpGet, HttpPost, etc. attributes. So now how do I handle that with this major change?
That internalling broke something I was working on as well.
A change set made on August 21st 2013 made this api alteration to fix this issue. According to that issue the only reason functionality was removed was to make Web Api closer to MVC's api. Not a particularly good justification in my opinion.
To resolve my issues I implemented a custom IHttpActionSelector derived from ApiControllerActionSelector. I hope it is not going to be my final solution since it really is far too much code for a simple thing. This approach should work for your problem too.
In my project each route needs to be modified according to which assembly it was found in. In following simplified code every route is prefixed with /Api (before a controller's RoutePrefixAttribute if present).
The actual IHttpActionSelector:
public class PrefixWithApiControllerActionSelector : WrappingApiControllerActionSelector {
protected override HttpActionDescriptor WrapHttpActionDescriptor(HttpActionDescriptor actionDescriptor) {
if (actionDescriptor is ReflectedHttpActionDescriptor)
return new PrefixWithApiReflectedHttpActionDescriptor((ReflectedHttpActionDescriptor)actionDescriptor);
return actionDescriptor;
}
}
public abstract class WrappingApiControllerActionSelector : ApiControllerActionSelector {
protected abstract HttpActionDescriptor WrapHttpActionDescriptor(HttpActionDescriptor actionDescriptor);
public override ILookup<string, HttpActionDescriptor> GetActionMapping(HttpControllerDescriptor controllerDescriptor) {
return base.GetActionMapping(controllerDescriptor).SelectMany(grouping => {
return grouping.Select(actionDescriptor => new KeyValuePair<string, HttpActionDescriptor>(grouping.Key, WrapHttpActionDescriptor(actionDescriptor)));
}).ToLookup(_ => _.Key, _ => _.Value);
}
}
The part that changes the route:
public class PrefixWithApiHttpRouteInfoProvider : WrappedHttpRouteInfoProvider {
public PrefixWithApiHttpRouteInfoProvider(IHttpRouteInfoProvider infoProvider, HttpControllerDescriptor controllerDescriptor) : base(infoProvider, controllerDescriptor) { }
public override string Template {
get {
var parts = new List<string>();
parts.Add("Api");
var prefix = ControllerDescriptor.GetCustomAttributes<RoutePrefixAttribute>().FirstOrDefault();
if (prefix != null && !string.IsNullOrEmpty(prefix.Prefix)) {
parts.Add(prefix.Prefix);
}
if (!string.IsNullOrEmpty(InfoProvider.Template)) {
parts.Add(InfoProvider.Template);
}
var route = "~/" + string.Join("/", parts);
if (route.Length > 2 && route.EndsWith("/", StringComparison.Ordinal)) {
route = route.Substring(0, route.Length - 1);
}
return route;
}
}
}
public abstract class WrappedHttpRouteInfoProvider : IHttpRouteInfoProvider {
private readonly IHttpRouteInfoProvider _infoProvider;
private readonly HttpControllerDescriptor _controllerDescriptor;
protected WrappedHttpRouteInfoProvider(IHttpRouteInfoProvider infoProvider, HttpControllerDescriptor controllerDescriptor) {
_infoProvider = infoProvider;
_controllerDescriptor = controllerDescriptor;
}
public virtual string Name {
get { return InfoProvider.Name; }
}
public virtual string Template {
get { return _infoProvider.Template; }
}
public virtual int Order {
get { return InfoProvider.Order; }
}
protected HttpControllerDescriptor ControllerDescriptor {
get { return _controllerDescriptor; }
}
protected IHttpRouteInfoProvider InfoProvider {
get { return _infoProvider; }
}
}
The glue:
public class PrefixWithApiReflectedHttpActionDescriptor : WrappedReflectedHttpActionDescriptor {
public PrefixWithApiReflectedHttpActionDescriptor(ReflectedHttpActionDescriptor descriptor) : base(descriptor) {}
public override Collection<T> GetCustomAttributes<T>(bool inherit) {
if (typeof(T) == typeof(IHttpRouteInfoProvider)) {
var attributes = Descriptor.GetCustomAttributes<T>(inherit).Cast<IHttpRouteInfoProvider>().Select(_ => new PrefixWithApiHttpRouteInfoProvider(_, Descriptor.ControllerDescriptor));
return new Collection<T>(attributes.Cast<T>().ToList());
}
return Descriptor.GetCustomAttributes<T>(inherit);
}
public override Collection<T> GetCustomAttributes<T>() {
if (typeof(T) == typeof(IHttpRouteInfoProvider)) {
var attributes = Descriptor.GetCustomAttributes<T>().Cast<IHttpRouteInfoProvider>().Select(_ => new PrefixWithApiHttpRouteInfoProvider(_, Descriptor.ControllerDescriptor));
return new Collection<T>(attributes.Cast<T>().ToList());
}
return Descriptor.GetCustomAttributes<T>();
}
}
public abstract class WrappedReflectedHttpActionDescriptor : ReflectedHttpActionDescriptor {
private readonly ReflectedHttpActionDescriptor _descriptor;
protected WrappedReflectedHttpActionDescriptor(ReflectedHttpActionDescriptor descriptor) : base(descriptor.ControllerDescriptor, descriptor.MethodInfo) {
_descriptor = descriptor;
}
public override HttpActionBinding ActionBinding {
get { return Descriptor.ActionBinding; }
set { Descriptor.ActionBinding = value; }
}
public override Collection<T> GetCustomAttributes<T>(bool inherit) {
return Descriptor.GetCustomAttributes<T>(inherit);
}
public override Collection<T> GetCustomAttributes<T>() {
return Descriptor.GetCustomAttributes<T>();
}
public override Collection<System.Web.Http.Filters.FilterInfo> GetFilterPipeline() {
return Descriptor.GetFilterPipeline();
}
public override Collection<System.Web.Http.Filters.IFilter> GetFilters() {
return Descriptor.GetFilters();
}
public override System.Collections.Concurrent.ConcurrentDictionary<object, object> Properties {
get { return Descriptor.Properties; }
}
public override IActionResultConverter ResultConverter {
get { return Descriptor.ResultConverter; }
}
public override Collection<HttpMethod> SupportedHttpMethods {
get { return Descriptor.SupportedHttpMethods; }
}
public override Collection<HttpParameterDescriptor> GetParameters() {
return Descriptor.GetParameters();
}
public override Task<object> ExecuteAsync(HttpControllerContext controllerContext, IDictionary<string, object> arguments, CancellationToken cancellationToken) {
return Descriptor.ExecuteAsync(controllerContext, arguments, cancellationToken);
}
public override string ActionName {
get { return Descriptor.ActionName; }
}
public override Type ReturnType {
get { return Descriptor.ReturnType; }
}
protected ReflectedHttpActionDescriptor Descriptor {
get { return _descriptor; }
}
}
To use this functionality just substitute the IHttpActionSelector service with PrefixWithApiControllerActionSelector in the config.
If you find a cleaner way of doing things please post your solution!
I'm investigating the best way to write a rich text editor in JavaFX - don't mention the HTMLEditor to me: we've spent literally months hacking at it and I could write reams about why it isn't suitable for our purposes! Choice at the moment is to extend AnchorPane and do all of the layout, navigation etc. from scratch or to extend TextInputArea, which looks as though it would help. Anyone have their own implementation of that or would like to propose a minimal implementation?
FWIW here's a scrap from me:
public class TryPain3 extends TextInputControl {
private AnchorPane rootNode = new AnchorPane();
public TryPain3() {
super(new Content() {
private String text = "";
#Override
public String get(int i, int i1) {
return text.substring(i, i1);
}
#Override
public void insert(int i, String string, boolean bln) {
}
#Override
public void delete(int i, int i1, boolean bln) {
}
#Override
public int length() {
return text.length();
}
#Override
public String get() {
return text;
}
#Override
public void addListener(ChangeListener<? super String> cl) {
}
#Override
public void removeListener(ChangeListener<? super String> cl) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
#Override
public String getValue() {
return text;
}
#Override
public void addListener(InvalidationListener il) {
}
#Override
public void removeListener(InvalidationListener il) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
});
setEditable(true);
Text text1 = new Text("fred was here");
text1.setFont(Font.font("Tahoma", FontWeight.NORMAL, 18));
text1.setTextAlignment(TextAlignment.LEFT);
text1.setFontSmoothingType(FontSmoothingType.LCD);
rootNode.getChildren().add(text1);
setSkin(new TP3Skin(this, rootNode));
}
class TP3Skin implements Skin<TryPain3> {
TryPain3 tp;
Node root;
public TP3Skin(TryPain3 tp, Node root) {
this.tp = tp;
this.root = root;
}
#Override
public TryPain3 getSkinnable() {
return tp;
}
#Override
public Node getNode() {
return root;
}
#Override
public void dispose() {
tp = null;
rootNode = null;
}
}
}
It looks as though the skin is not optional.
Questions I'd like to find out are things like:
how is the UI supposed to be drawn - I'm quite happy to code it from scratch but how to get benefit of calls to forward() as an example
should the UI creation be done in the Skin?
whether the base class deals with things like where to put the cursor if you click on a bit of text
I'm sure other questions will arise from this.
You may want to try next JavaFX 8.0 control TextFlow, which allows aggregation of various text styles. See examples here: https://wikis.oracle.com/display/OpenJDK/Rich+Text+API+Samples
JavaFX 8 is part of JDK8. So you can download developers build here http://jdk8.java.net/download.html and it will include JavaFX and new TextFlow control.
How to use relay command in set, I use the following way, throws interface bug on set method
public RelayCommand ChartCommand
{
set
{
ChartCommand = new RelayCommand<string>(e => ExecuteChartCommand(e));
}
}
public void ExecuteChartCommand(string vendor)
{
}
You should really be doing it this way:
private RelayCommand<string> m_ChartCommand;
public RelayCommand<string> ChartCommand
{
get
{
return m_ChartCommand ?? (m_ChartCommand = new RelayCommand<string>(e => ExecuteChartCommand(e));
}
}
public void ExecuteChartCommand(string vendor)
{
}
.
I'm trying to change the row highlighting in my FlexTable using KeyCodes.KEY_UP/DOWN. This doesn't seem to work (based on 1809155):
public class KeyAwareFlexTable extends FlexTable
implements KeyDownHandler, HasKeyDownHandlers {
public KeyAwareFlexTable() {
this.addKeyDownHandler(this);
}
#Override
public void onKeyDown(KeyDownEvent event) {
GWT.log("onKeyDown");
// check if up/down & do something useful
}
#Override
public HandlerRegistration addKeyDownHandler(KeyDownHandler handler) {
return addDomHandler(handler, KeyDownEvent.getType());
}
}
I've also tried this (based on this site):
FlexTable table = new FlexTable() {
#Override
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
GWT.log("Event type = " + DOM.eventGetType(event));
switch (DOM.eventGetType(event)) {
case Event.ONKEYDOWN:
if (DOM.eventGetKeyCode(event) == KeyCodes.KEY_UP) {
GWT.log("up");
} else if (DOM.eventGetKeyCode(event) == KeyCodes.KEY_DOWN) {
GWT.log("down");
}
break;
default:
break;
}
}
};
table.sinkEvents(Event.ONKEYDOWN);
I'm looking for a way to have this behavior more or less. Does anybody have a way to do this in GWT?
Got it
FocusPanel focus = new FocusPanel(flexTable);
focus.addKeyDownHandler(new KeyDownHandler() {
#Override
public void onKeyDown(KeyDownEvent event) {
int code = event.getNativeKeyCode();
if (KeyCodes.KEY_UP == code) {
GWT.log("Bed goes up");
} else if (KeyCodes.KEY_DOWN == code) {
GWT.log("Bed goes down");
}
}
});