What would be the best approach to implement a multi-select combo in SWT/JFace? - swt

I need to implement a multi-select combobox using SWT/JFace, What would be the best approach?should i go for changing the source code or i should try to extend the combo?

It is not possible to extend a Combo It is possible to extend Combo by overriding checkSubclass(), however it is highly disapproved of. The alternative is to create a wrapper for it. But that would be too much work.
Extending a CCombo is an option, but not a very good idea. Again, too much work for the functionality you need.
BUT
As sambi reddy mentioned, you could use a TableComboViewer from Nebula (scroll down to "TableCombo").
Another convenient solution (my favorite) is to have a CheckboxTreeViewer since you need to implement multi selection and such.

screenshot
https://github.com/lawhcd/SWTMultiCheckSelectionCombo
For anyone who is looking for a widget that allows user to select multiple options from a list of check box style options.
It is based on user1438038's idea and extended to provide nearly all of the api required of a widget similar to Combo.

Related

Hide and show the DOM elements

I have to switch between the views and i am using lot of ng-if's in my code. Can i have a better approach rather than using all ng-if's in angular ?
I don't know what to use apart from ng-if's
There is a better way if your view is switching on through one condition you can make you of ngSwitch
you can refer this link
If above is not your use-case then you can build a structural directive for it.

how to allow multi select on gwt combobox

I have combo-box and i want to allow multiple selection on it
how to do that??
newEmployee = new ComboBox<NctrUserDTO>();
newEmployee.setFieldLabel("Employee");
newEmployee.setDisplayField(NctrUserDTO.NAME);
newEmployee.setTriggerAction(TriggerAction.ALL);
newEmployee.setEditable(true);
newEmployee.setStore(employeeList);
newEmployee.setMaxHeight(200);
I don't know which API's ComboBox you're using since vanilla GWT doesn't have a ComboBox, but I'd guess it's not possible to do this unless you change the ComboBox class itself/write an actual MultiSelectComboBox class. Unless your version happens to have an "enableMultiSelect" method already in-built, but you probably wouldn't be asking here then.
If it helps, I found this thread which seems similar to what you're describing.

Multiple shortcuts for one action in GTK

What is the best way to bind multiple keyboard shortcuts to one action in GTK+ 3?
I have been searching for an answer to this for a few days and have come up with naught. The function gtk_accelerator_parse does not support comma-deliminated shortcuts. Putting multiple <accelerator> tags in a .ui file with the same action attribute and different key attributes also does not work.
I do not want to have to write a custom key press handler just so I can have two shortcuts for one action, but is that really the only way?
Since GTK version 3.12 (released on 2014-03-25) there is a new method called gtk_application_set_accels_for_action() that should help.
I have found a way, but it is truly terrible. Using gtk_accel_group_connect I can add additional accelerators for my own functions which can then trigger the action desired based off the key pressed and any modifiers. This however feels like a hack as I am basically creating my own accelerator-to-action map rather than using GTK's.
I would like to know a better way, if anyone knows of one.

GWT ValueListBox: can it support more than a single selection?

Can GWT's ValueListBox support multiple selections? Also, is there a way to get it to display more than a single value at a time (like ListBox.setVisibleItemCount()) ?
It seems like you'd need to get at the underlying ListBox (or somehow provide a custom one) in order to make this happen. Of course getListBox() is private, so that's out.
No. ValueListBox is intended to operate on single value. That's why it can be easily used as editor (from Editor framework) for wrapped type.
For multiple selection you can use ListBox, but AFAIK there's no straightforward way to use it as editor (you have to write your own custom editor based on ListBox).

GWT use of interface instead of widget

in a définition of a widget, what is a better practice, and why, use the widget himself or the type "higher", example, it's a better practice to do
1) Button myButton;
or
2) Hastext myButton; (and set a button later)
thanks for your answer.
It is usually a good idea to use "higher" types or interfaces. By doing this properly you can hide implementation details. The code that uses an object looks at it as the one of a higher type and it is not important what is actually hiding behind it. This is good because you can easily change an implementation of the object without breaking anything.
For example when defining a panel in an application you should use Panel class instead of its implementation e.g. HorizontalPanel or VerticalPanel.:
Panel myPanel;
Then you can create a proper implementation of it, e.g HorizontalPanel:
myPanel = new HorizontalPanel();
If you then later decide to change myPanel to be VerticalPanel you will not have to change anything in the code that uses myPanel. Everything will work just fine.
However you must remember that you will be only able to use methods available in Panel class. Additional methods defined in e.g. HorizontalPanel will not be accessible. And this is actually what you should remember when choosing the type of your widgets. Your widgets should be of types which provide methods which you want to use.
In your example using HasText instead of Button isn't probably a good idea because HasText has only methods for setting and getting a text and you probably also want to have access to addClickHandler method available in Button and a few more.
So to summarize it is good to use "higher types" but they should not be "too high" to be useful.
The answer to that lies in the Model-View-Presenter pattern, that was introduced in last years Google IO presentation by Ray Ryan. There's also an official tutorial/docs - part 1 and part 2. There are also a number of questions here on SO that cover that topic :)
And a quick answer to your question (that will make more sense once you get familiar with MVP): use interfaces in the Presenter and their implementations in the View :) That way your Presenter stays oblivious to the underlying implementation/Widget you actually used (was it a Button? Or a Label? It doesn't matter, they both implement HasText).