Comboviewer Databinding with dynamic combo items - eclipse

I have a comboviewer, and i need to have the databinding on it, so that the combo selection is automatically updated in the Model.
Also i need to add the combo items dynamically (to the exisitng combo items). With databinding how can i acheive this?
As am new to databinding, please point me to some good tutorial on comboviewer databinding with dynamic items (combo items).
The below code is for binding the comboviewer selection to the model:
final IObservableValue entityComboObservable = ViewersObservables.
observeSingleSelection(myComboViewer);
final IObservableValue modelSelectedEntityObservable = BeansObservables.
observeValue (cmpObj, Company.EMP_SELCTION);
bindingCntxt.bindValue(modelSelectedEntityObservable, entityComboObservable);
where "cmpObj" is my model object which contains the list of objects which will be set as the input to the comboviewer

You can do something like
comboViewer.setContentProvider(new ObservableListContentProvider());
comboViewer.setLabelProvider(labelProvider);
// input must be a List
comboViewer.setInput(input);
IViewerObservableValue swtObs = ViewersObservables.observeSingleSelection(comboViewer);
Now create a model-ovservable and bind it with swtObs

you need to use below input observable.
org.eclipse.jface.databinding.viewers.ViewersObservables.observeInput(Viewer)
bind input observable with the ListObservable.

Related

How to display a custom attribute on Cart Page in hybris?

I have a custom attribute whose value I have to display for every item in the cart on the Cart Page. I want to add the attribute in cartItem.tag. Can someone please tell me where should I add the value? I tried adding it in the CartPageController, but could not find an appropriate place to add the value.
I'm completely new to Hybris, any help would be appreciated.
Thanks, in advance.
I am guessing this new attribute belongs to the OrderEntryData type. You can use or create some Populator to add value to this attribute. You should use populators when you want to copy some value from modelObject to dataObject in order to show it whithin the presentantion layer.
Steps you need to follow:
Add new attribute on CartEntryModel at item level where, your new attribute value will get store on model
Add new attribute in CartData using **beans.xml, which will hold and show value on cart page
Create new custom populator by extending commercefacades's "CartPopulator" and populate new attribute value
Finally, you can use new attribute directly on cartPage via. cartEntry.newAttribute

Apps script: use a form as a template for other forms creation

I have a form with a set of questions, and I want to use it for other forms creation. In other words, I want to iterate through this template form items, choose those that I need and append them to another, newly created form.
I had no problem with getting the items and choosing those that I need; however, I can't find the way to append these items to another form - all of the Form.addSomethingItem() methods don't take arguments (docs for example). Is it really impossible, or do I miss something foolishly simple?
There are two ways to achieve this:
Make a copy of the form using DriveApp and remove/modify items in-place on the new form copy.
Iterate over existing items, check it's type and add them to the new form. For example, The following gets Item1's enum and converts it to a camelCase string and executes add{Type}Item method, where Type is MultipleChoice in case of MULTIPLE_CHOICE Enum Item type.
const newForm2Item0 = Form2[
`add${String(Form1.getItems()[0].getType())
.toLowerCase()
.replace(/(^|_)[A-Z]/gi, match =>
match.toUpperCase().replace('_', '')
)}Item`
]();//equivalent to Form2.addMultipleChoiceItem()
You would then add choices and other configurations as needed in a similar manner.
Form methods like addTextItem() don't take arguments, rather they return Items classes (e.g. TextItem). Those Item classes have their own methods for assigning properties to a question on a form.
Examples
here's an example of adding a text item with a specific title
form.addTextItem().setTitle('I am a text question title');
here's an example of adding a multiple choice item to a form with some choices
var item = form.addMultipleChoiceItem();
var choices = ['choice 1', 'choice 2', 'choice 3'];
choices.forEach(function(choice) {
item.createChoice(choice);
})

Angular2 model-based parent/children form

I'm a newbie with Angular2 (beta1) and I'd like to implement a sort of simple editable grid, built of 2 components. Here I use two fake-data components to keep things simple. They are (see this Plunker: http://plnkr.co/edit/5cZfLTIlhLc82wWV4PQI):
the parent component, named contact. Say it represents a contact with a name.
the child component, named entry. Say it represents an entry for a contact, where each contact can include 0 or more entries. Each entry has an address and a zip code.
I'd like to create a form where the user can edit the contact's properties, and also its children entries: he could add a new entry, delete an existing entry, or edit an existing entry.
To this end, the views for both these components provide a form-based template.
I can think of this data flow:
contact: the user edits the form and then clicks a submit button to save
the whole thing. Thus, I can just have some code handling the submit button
and emitting an event as the component output. The contact has an entries
array property: I can thus use an ngFor directive in its template to render
an entry component for each of them.
entry: the entry has properties addressCtl and zipCtl which represent
the control directives included in the ControlGroup representing the whole
form. Also, I need a couple of properties to be bound as the input of the
component (address and zip), so that in the parent template I can do something like:
<tr *ngFor="#e of entries">
<td><my-entry [address]="e.address" [zip]="e.zip"></my-entry></td>
</tr>
Now, it's not clear to me how to shape the relation between the "model" properties representing the control's input, and the "form" directives properties. I should be able to get the address and zip values from the parent component through the [...] binding, and pass the updated values up through an event fired by the child component (e.g. blur?). Does this make sense in the NG2 world? Anyway, I'm missing a piece here: how can I connect the form controls values to the model properties values? Could anyone make this clearer or point to some good docs?
In fact, using the [...] binding only corresponds to a one-way binding. When the parent property is updated in the parent component, the value is also updated in the child component.
But if you want to update parent attributes from the child, you need to leverage events and #Ouput attribute.
Here is a sample with a labels component:
export class LabelsComponent implements OnInit {
#Input()
labels:string[];
#Output()
labelsChange: EventEmitter;
(...)
removeLabel(label:string) {
var index = this.labels.indexOf(label, 0);
if (index != undefined) {
this.labels.splice(index, 1);
this.labelsChange.emit(this.labels);
}
}
addLabel(label:string) {
this.labels.push(this.labelToAdd);
this.labelsChange.emit(this.labels);
this.labelToAdd = '';
this.addAreaDisplayed = false;
}
}
This way you can leverage two way binding on this component:
<labels [(labels)]="company.labels"></labels>
Hope it answers your question,
Thierry
Just moved the comment to answer...
You can pass the object e, instead of passing string.
i.e
<my-entry [entry] = "e"></my-entry>
then in your my-entry component, use ng-model for each input. so you automatically gets 2 way bindings.

Adding a form filter

I'm currently working on a form in Microsoft Dynamics AX.
The form consists of a grid with about 10 fields from 4 different tables.
As the form is now it returns too many values so I need to include some sort of filter, it doesn't need to be dynamic, just a static filter saying only show the lines with value X in column Y.
Has anyone here got some experience with this sort of thing? Where do I start?
I must say I'm not experienced with Microsof AX at all, I've been working with it for about a month now.
I've tried to follow this guide: How to: Add Filter Controls to a Simple List Form [AX 2012]
But I got stuck at the second part (To add a control to the custom filter group) Step 2: I dont know which type of control to chose, and ik i pick lets say a ComboBox i cant get Step 3 to work because I dont see the 'Override Methods' they mention.
Well, I usually do it this way:
In ClassDeclaration, create as many QueryBuildRanges variables as fields to filter. Let's name them Criteria1, Criteria2, etc (name them properly, please, not as here)
QueryBuildRange criteria1, criteria2;
In each Datasource you need to filter, override method Init, an add code similar to this:
super();
criteria1 = this.query().datasource(tablenum(tableofdatasource)).addQueryRange(fieldNum(fieldtofilter))
//criteria1.status(RangeStatus::locked); //optional - this way you can hide filter field to user, have it readonly for users, etc
Create a control of type StringEdit or ListBox in form to be used as filter. Change their AutoDeclaration property to Yes. Override modified() method. In it, I use to put something similar to:
super();
element.changeFilters();
In form, add method changeFilters();
range rangeFromStringControl = StringEditControlName.text(); //Put in rangeFromStringControl the string to be used as filter, as a user would write it
range rangeFromListBoxControl;
criteria1.value(rangeFromStringControl);
switch (listBoxControl.Selection())
{
case NoYesAll::All:
rangeFromListBoxControl = ''; //Empty filter string - No filter at all
break;
case NoYesAll::No:
rangeFromListBoxControl = QueryValue(NoYes::No); //Or whatever string filter value you want
break;
//Etc
}
//We have all filter strs done; let's filter for each main DataSource required with new filters
DataSource1.executeQuery();
//If there is other datasources joined to this one, it's usually no necessary to call their executeQuery;
//If there are others with filters and not joined to it, call their executeQuery()
If you need this filter to be applied when form is open, set appropiate initial values to controls, and then in form's run() method:
run();
element.changeFilters();

GXT - Pissed off with ComobBox in Grid (different Display Label and Value)

I am trying to add a CobmoBox in EditorGrid
I have a class Vehicle with fields
Integer vehicleId;
String plateNo;
Integer vehicleType; //1=Car,2=Truck
I want the combo box to show vehicle's type in text form i.e if vehicleType is 1, "Car" would be displayed. And when the user select any other option - like "Truck" the corresponding integer value should be populated into the bean.
This is pretty standard stuff with plain old JSP and HTML.
However I couldn't find a simple way the do this in Ext GWT.
If you are using a GXT ComboBox, the easiest way to is create a model representing your vehicle object if you haven't already. This is basically a class that extends GXT's BaseModelData class.
Once you have your model, you create a combo box using that type:
ComboBox<VehicleModel> box = new ComboBox<VehicleModel>();
The last step is to tell the combo box which fields to use for values and for display, which is done with 2 method calls:
box.setDisplayField("field name for display");
box.setValueField("field name for value");
When you load up a store of vehicle models, GXT will take care of the rest. You will, however, need to convert the model back to the vehicle object itself to be persisted.