How can I have two editors for the same property on a switch? - gwt

I am trying to create an editor where the user can either select an existing item or create a new one inline. For example, imagine the typical person-address relationship. I want a form where the user, when editing a person, can either select an address from a set of existing addresses or create a new address without moving to a separate form.
Naively, this seems to require two different editors for the same property. Say I have a Person which has Address getAddress() and setAddress(Address). My PersonEditor class would need to have two sub-editors named address of differing types; one to select an existing person and the another a composite of editors to descend into the Address type and allow editing of its properties.
From reading the documentation on CompositeEditor, it seems like I have to make use of it to dynamically select the sub-editor. However, the documentation isn't detailed enough for me to really understand how I should implement the interface. I've tried looking at how ListEditor and OptionalFieldEditor are implemented for clues, but to avail. ListEditor doesn't seem like a straight fit as my sub-editors edit different paths.
For instance, trying to use CompositeEditor, I'm unclear on what createEditorForTraversal and getPathElement should return in my case.
How do I dynamically attach one of two different types of editors to one property?

I managed to do this in the end. I simply added two editors with the same #Path annotation. I was not expecting the editor framework to allow this, but it seems to work!

Related

NSComboBox with alternative ways of writing

I'm trying to implement a autocomplete function into a small app. I want to give the user the possibility to write down a city (from a long long list of cities) into a NSComboBox. That works fine, as long as the user is using the exact writing of the city inside my array of city names. But if they use, for whatever reason, a different spelling, it fails and the city is not found.
So if the user is looking for "Köln" for example, it's not a problem, but if he is looking for "Cologne" he wouldn't be able to find it.
For this I have, for each city an additional array of alternative spellings.
Now I would love NSComboBox (or any other type of TextField) to look not only in "city.name" but also within the array "city.alternativeNames". The shown value should as well represent what the user is writing.
I don't want to create an entry in the list of the pop-up part of NSComboBox for each alternative name, as that would make the list even longer than it is and would confuse people (cologne alone has 85 different spellings).
Thanks for your suggestions, I'm completely new to NSComboBox.
Interesting problem. I think probably you need to choose a different way to structure your data to make it easier.
Consider the lookup method (matching a string). Structuring your data for this case should account for the preferred spelling of each city (preferred by you, for the scrolled list).
How about a flat array of cities (to allow a simple search based on user spelling without also having to check each possible array of alternates and manage sorting them properly) but each has an optional (can be nil) "preferred spelling" pointer to the "correct" one. When displaying the options in the combo box, show the array filtered by those with no optional preferred spellings plus the currently-typed partial/full completion of the alternate spelling?
So a City has a name property and an optional preferred property. In your case, if Cologne is preferred, the Köln instance would have Cologne set as preferred. Köln would only appear in the list if the user typed it (even partially) and it would automatically be in the correct alpha-sorted position (assuming your cities are kept sorted).
Does this make sense or do I need to rephrase? Haven't had enough coffee this morning. :-)

API.AI Intent won't save when adding Required Action

I'm trying to create a chat bot that will help users search up motorcycles.
I'm new to API.AI and have set up my entities and their synonyms, my intent and user expressions, as well as references to the entities (#engineSize, #make, #bikeType).
My problem is when I try to add a required action and prompt, and then try to save the intent, I get the following message:
"The following entities reference each other and form an infinite loop: [engineSize]."
Initially I thought I was using the references wrong in the user expressions. I deleted every reference except for one expression which uses all three entities.
I can't figure out what I'm doing wrong. Any help would be greatly appreciated, thanks! Pix below for further details.
EDIT: I fixed one of the issues of trying to pass a template expression as an example. However, I still get the same error message. I will replace and update my image links to include the edits.
Annotated User expressions
Required Actions
Interestingly enough, the answer to this post would have been difficult to find because the problem was in defining my entities.
In the entity definitions, I included an #ref to the entity itself. ie the bikeType entity contained #bikeType as one of its definitions.
This is not to be mistaken with the User Expressions. As long as the user expression is marked as a Template (the entire line is denoted with an '#' on the far left, as opposed to a large " ), there should be no issues.
Edited for clarity to get at root problem
In the provided user input examples you give the intent, you are supposed to provide general examples and then highlight any text belonging to an entity to map where entities appear in user's inquiries.
In your case, you have input the actual entity reference '#engineSize' as an example belonging to the engineSize entity, creating a self reference.
A proper provided user example would look like:
Also note though that if you are just using entities to store generic information like numbers, addresses, times, etc. it generally makes far more sense to use prebuilt system entities for those categories than create a custom entity, for example #sys.number-integer might be exactly what you need
It looks like you need to get a firmer understanding of entities, for which I would recommend the documentation:
https://docs.api.ai/docs/concept-entities

Is "Part Decomposition" supported in EA?

I am trying to draw a part decomposition diagram with EA10. It should look like below.
But I couldn't find how. Is this UML diagram ever supported by EA?
Found it. I need to activate the "More tools..." -> "Composite" first. And choose "Port".
BTW, this is really a bad user experience.
You're doing it wrong. Sorry, but there's no kinder way to say it. :)
If the lifeline (:Class) is associated with a classifier (Class) which has properly defined ports (as it should be), then the following applies:
If you create the lifeline by dropping the classifier onto the sequence diagram, you get the option of displaying the ports (aka "structural elements") immediately.
Regardless of how the lifeline was created, you can right-click it and select "Structural Elements" which allows you to select the ports from the classifier (which may have been added since the lifeline was created).
If you want to create ports under a lifeline which has no classifier, you can do that too. Simply right-click and select "Structural Elements". The dialog allows you to create new ports.
The :Class lifeline presumably gets its type information from a Class element, so the first thing you need to do is find the Class element and give it two ports. Once you have done that, you can right-click the lifeline, select the Embedded Elements dialog and include the ports on the lifeline. (The Embedded Elements dialog may have been renamed Structural Elements in recent versions).

Dynamic form with binding in GXT

What would be the best approach to implement a form with a variable number of text fields? I'm thinking something like this:
textField1 (removeButton)
textField2 (removeButton)
textField3 (removeButton)
addNewTextFieldButton
I would like this to bind to a list of strings.
I achieved this with an editable grid with a single column and buttons to add/delete rows.
This component is very well integrated with GWT Editor framework so you can bind your grid to a list of objects using a ListStoreEditor
The best approach would be to use the GWT Editor framework. GXT's fields are very well integrated with the Editor framework.
Here is a very rough example of how you might approach this problem.
You would start by creating one Editor for the thing you are wanting to bind to. In your case, I think a composite which contains a TextField (which is bound to the string) and a button. The button won't actually bind to anything, but you will provide a way for something which uses this class to register a SelectHandler against it. Let's call this editor SubEditor.
Once you create a UI component which is designed to bind to one string, you will next create a ListEditor<String, SubEditor> which will bind to a List<String> which will compose a view, consisting of one SubEditor per each String in the bound list.
You don't really need to create the SubEditor, as you could construct something as simple as what you want within your ListEditor's EditorSource class (read through the tutorials on ListEditors).
Again, I want to emphasize the this is a ROUGH example on how to get started. I hope there is enough information here for you to fill in the pieces.
The following SO question has helped me out a lot:
Using GWT Editors with a complex usecase

Drupal - dynamic options for text_list field

I have a custom node type for which I want to have a field that uses a special combobox based on list_text. When one chooses the type list_text it is normally possible to enter a static list of selectable texts, however, I want this list to be dynamic, i.e. based on the results of a db_query. What is the best way to do this using Drupal 7?
A simple example for clarification: A node of this custom type X contains a field that points to another node, so whenever a node of type X is created I want a combobox that contains all other nodes.
(Best solution would be to only display the combobox during node creation, and no longer during edit. But I could also live with it if the combobox was shown during the edit as well.)
I have tried to customize options_select by defining my own data type and implementing hook_options_list accordingly. The combobox was displayed during creation with the correct values, however, I could not save it.. I have no idea what went wrong there, but on the first submit it would change to a different theme, and when I tried again I got an internal server error. Am I on the right track at all with defining a completely new data type for the field? there surely must be a simpler way?
You're right in that you don't need a new datatype. Here's a good tutorial on how to do this. It's not specifically for D7 but I didn't see much that wasn't still applicable. There may be a better way to do it in D7 specifically but I would love to know it too if so :)
The tutorial linked by allegroconmolto sent me on the right way. Thanks for that.
Here's the simpler way of doing it: tutorial
Basically, it is, as I assumed, a common problem and hence a simple solution for it was included in the webform module by now. It provides a hook_webform_select_options_info which can be used to register a callback method. The callback method is then called each time a corresponding option select of a webform is shown, so that you can easily fill it with the results of a dbquery or anything else. Works like a charm and takes next to no time to implement.