How do I use an SWT Control to render the content of an SWT/JFace table? - eclipse

I have a JFace TableViewer with an SWT Table, and I would like to custom render the content of some cells. I would like to use an SWT Control to render the cell content.
I would prefer to have only one instance of the Control doing the rendering, but if I have to instantiate one for each row, that would be acceptable.
Next, the solution MUST be compatible with the ContentProvider/LabelProvider approach (I am using EMF). This means that I cannot use the solution described in Sniplet 126 (http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets).
Next, I though about using custom drawing. But here the catch is, that I have to send individual drawing operations to the graphics context. I was trying to have the Control render the content for me by calling redraw() or print(GC) upon SWT.PaintItem, but that just lead to uncontrollable flickering.
At this point, my best guess is to use SWT.PaintItem to do the drawing. This will result in duplicate code, as I already have a Control that can render the content the way I'd like it. I'd like to prevent this redundancy.
Any help is appreciated!

Well, after banging my head against a wall several times I made some progress. Specifically, I found this formu entry:
http://www.eclipsezone.com/eclipse/forums/t115489.html
It actually offers two solutions: The first solution actually uses widgets (not recommended due to performance, but I knew that before). I will try this out, and may post here how it goes.
The second solution suggests using StyledCellLabelProvider. I looked into this before, but it isn't powerful enough for my purposes. At least that's what I think right now.

Related

Best practice so switch between a grid and list layout at runtime

Im currently working on a project where I want to the user to be able to chose between two layouts (list and grid) at runtime. I was searching for examples in the UI5 documentation (Sample Apps) and on GitHub, I did not find examples for how to to this or best practice examples. So I thought about how I could achieve this behaviour and had multiple ideas, but somehow none of them feels like doing this would be best practice.
Idea 1 - Destroy the "old" controls and generate the new controls inside the Controller
My first idea was to destory the controls I do not longer need. For example if the user wants to switch to the grid layout, the list and every control related it to it gets destoyed. In the controller the needed controls for the grid are created and then rendered in the view. In my eyes this would mix up view and controller logic inside the controller and does not feel like best practice
Idea 2 - Create two views and switch between them
My second idea was to create two views, each for the layout I need and switch between them. This would mean a lot of code replication in both the controller and the view. Does not feel like this would be the right way.
So I would be glad if you have own experience on this or if there is really something like a best practice for such a behaviour.
Thank you and kind regards!
I would say, idea 2 because of the following reasons:
It is best practice to work according to the MVC methodology which means separating logic, view and data. Since the controls define your view it is best to instantiate your controls in the files that are meant for it (the XML Views).
Performance: Destroying all controls means that if the user decides to switch between views, the controls have to be re-instantiated by the controller every time. This is, even though you probably won't notice it, not performant.
You don't need code replication: The argument of code replication is not necessarily true. If you can execute the same actions in the list and grid-view, it should be enough to just link the controller to both views and in that case you'll hardly have to replicate any code. Just make sure that you split your logic in enough functions. That way you might need to write some extra public functions to handle events, but not much more.

Positioning a sap.m.list

I'd like to create a twitter like stream out of a sap.m.list, hence when I get more data with a pulltorefresh control, I'd like to update the list with the additional rows, but should not move the list at all, and be hidden until the user scrolls the list down.
Any standard ways of doing this, or alternatively, custom CSS/JS recommended ways of doing this?
Thanks,
Matt
There's no need to drop down to jQuery here as OpenUI5 already contains the awesome iScroll library.
I've just setup a test app for you to have a look at here: https://github.com/js1972/ui5_pull_to_refresh.
Clone this; check the readme; then just run grunt serve to open the app in your default browser. You can use Chrome dev tools to emulate an iphone or android, etc.
I think this does what you're after - it works just like the GMail mobile app. You pull down to refresh items and at the end of the refresh your still looking at the same items but can now scroll up to see the new ones.
Will be interesting to see the performance if you have a thousand items... iScroll gives you allot of settings to play that may help (which aren't discussed in the UI5 SDK).
One thing to be careful of with browser scrolling is paint times. If the browser is not 100% done painting then iScroll can't calculate all the element dimensions it needs and you get strange results - typically just no scrolling. Sometimes you've just got to give a little time back to the browser by wrapping things in setTimeout(scroll_stuff, 0).
Hope this helps...
While not quite the answer I was after, looked into doing it another way, and provided you can work with automatically generated Id's that you'll need to calculate based on the row number, the following is one brute force way of doing it (I've borrowed it from another SO question and kept the animation for fun - Referenced SO Link):
var pOffset = $("#__item0-App--Main--MyList-76").position().top;
$("#App--Main--myPage-cont").animate({scrollTop: ( pOffset)}, 800);

Alternative to dragdealer.js that suports interpolation?

I'm need to control the scrolling of an element, via an external handle, to do this, one can use the excellent dragdealer.js (http://code.ovidiu.ch/dragdealer/) but it seems it has not been updated since 2010, and there are some features that could need improving, for instance the ability to have "steps" in different sizes, and controlling the scroll-speed on the fly, if you for instance want to scroll the scrolling element between "slides" of different sizes.
Are there any more recent librarys/plugins that you think I should look at?

Keeping a view always in memory in Flex Mobile?

Is there a way to achieve this? At first I thought that desctructionPolicy = 'never' would allow me to do this, but after spending a lot of time struggling with it, it seems I was wrong and the feature doesn't work as I thought.
I could keep all the relevant data I need of that view and restore all components to the expected state, but I find that to be a bit cumbersome, and I'm a bit surprised there is no way to do this. When I navigate through several views, and then go back up to the view I'd like to persist, it is there with its last state.
Can't I restore the view in the same way?
I guess this is not possible. At the end I had to store and restore the whole view.
It would be nice if Adobe would allow for this, luckily this may be one of those things where Flex being donated to the Apache foundation would come handy.

How to use GdkPixBuf?

I want to display a simple GIF image in a VBox using GTK+ from C. I know that I need to use a GdkPixbuf. But as usual there are no example of doing it. Can anyone provide help?
Also: In GTK+ how can we add a PNG image as background to a widget? Can anyone provide an example?
Forgot something to add this:
forgot to tell u that i am using Glade to develop GUI...
And i have created vBox in Glade and in one of the blocks of the vBox i need to display FIG Image....
Sorry of this...
gdk_pixbuf_new_from_file() -- but see unwind's answer for a better way to do it using a GtkImage widget.
You need to set the background pixmap field in the widget's style structure:
GtkRcStyle *newstyle = gtk_widget_get_modifier_style(widget);
newstyle->bg_pixmap_name[GTK_STATE_NORMAL] = g_strdup(pngfilename);
gtk_widget_modify_style(widget, newstyle);
PS. You can often find code examples by doing a Google search for the function you need an example of. The GTK docs usually don't contain examples for every single function, because that would clutter them up, and the documentation of functions like gdk_pixbuf_new_from_file() is usually pretty straightforward. I've noticed you often post this kind of question and I'm wondering if you are looking for the documentation in the right place. For example, are you using the excellent reference tool DevHelp? On the other hand, the GTK documentation is really missing some important information in a few places. If you have some improvements, why not contribute to the documentation?
A vbox in GTK+ is a widget, that displays other widgets as its children, stacking them vertically.
Unsurprisingly, there is a GTK+ widget dedicated to displaying images; it's called GtkImage. You should use the gtk_image_new_from_file() call to create one, passing it your GIF filename, and then just add that to your vbox. There's no need to create the underlying GDK image yourself.