how to zoom a graph using zest? - eclipse

I am using RCP and ZEST to create an application to visualize graphs. My question is: is it possible to zoom a graph drawn on ZEST (any ZEST or RCP api or plug-in)?
Thanks in advance
-rajit

I had a look at the ZestZoomContributionViewItem and it seems to put a drop down list specifying "page width" and 200% options for zoom. I wanted to be able to use the mouse wheel to zoom in and out of my graph.
The following code will zet the zoom level to 500% on your Zest graph and give you fine grain control (it's a bit deprecated as these are internal eclipse classes.)
Graph myGraph = new Graph(parent, SWT.NONE);
ZoomManager zoomManager = new ZoomManager(
graph.getRootLayer(),
graph.getViewport() );
zoomManager.setZoomAsText("500%");

The simplest solution is to create a ZoomContributionViewItem. This item can be added to Menumanagers (in theory to toolbarmanagers also, but there is a nasty null-pointer exception related in Zest 1.1).
The constructor needs an IZoomableWorkbenchPart, where you need to provide a single method that returns the graph viewer.
If you need something more specific, look at the code of the Zest ZoomContributionViewItem code, how they had implemented it.

Related

How to make window centered in GTK4?

In GTK3 there was a property on the Gtk.Window class called window-position. By setting this property to Gtk.WindowPosition.CENTER it was possible to tell the window to render in the center of the screen.
In GTK4 this property has been removed. How to achieve the same behavior in GTK4, i.e. how to make the main window of my application to be rendered in the center of the screen?
I checked the migration guide but I couldn't find the solution.
There is no replacement API, since it can't possibly work cross-platform, so it is broken API by definition. As such, it was removed.
For example: this is impossible to implement when running on top of a Wayland session, since the protocol doesn't allow getting/setting global coordinates. If you still want to have something similar working, you'll have to call the specific platform API (for example, X11) for those platforms that you want to support.

How to call Javascript code from ScalaJS leafletJS

I am working with the ScalaJS library
https://github.com/fancellu/scalajs-leaflet and I am looking to incorporate some custom javascript from https://jackzoushao.github.io/leaflet-marker-direction
The key functionality is the ability to rotate the markers based on the direction of travel.
Any tips on how to achieve this will be greatly appreciated.
Look at
https://github.com/fancellu/scalajs-leaflet/blob/master/core/src/main/scala/com/felstar/scalajs/leaflet/Leaflet.scala
Note the Marker, they create an AngleMarker
Try creating appropriae AngleMarker scala code, and pull in the js
Also look at how I pulled in some GeoJSON.js object
https://github.com/fancellu/scalajs-leaflet/commit/1ebbbdc40ef8cdde7aee362864b5f2812d9be5b6

Im working on an application using eclipse RCP. I have a graphical editor and I would like to draw a figure on it programmatically?

I do not want to use an editPart or have any connection with the model. An other solution that would work for me is to draw a figure that is out of bounds of its parent
I haven't tried this, but you could get the GraphicalViewer of the editor, pull out the LightweightSystem and draw directly over it.
Since GraphicalViewer does not expose this directly (check GraphicalViewerImpl where it is protected) you would need to create your own implementation that does expose it.

How to get the screen dimension of a eclipse view and IJavaElement

I writed an eclipse plugin that visualize some Java classes as UML in a view part. You choose a package in the Package Explorer and after rigth click on the package you can visualized it by clicking on a self created command menuitem in the menu. The visualization is created with the prefuse library.
My next goal was to make it possible to use it for multitouch. I use the Multitouch Library from PQLabs multitouch SDK. Now, on a multitouch screen, I can move my UML model, resize it etc.
But I was not able to get the informations from the Package Explorer. I tried to find out the location of the Package Explorer and IJavaElements on the screen but failed. My idea was to compare the x and y points from my finger (which I get from the PQL Labs SDK) with the x and y coordinates from the IJavaElements. I failed from the start, I could not be able that a touch point recognizes if it is in the border of the Package Explorer view or not. The only thing I got was the bounds of the whole Display. I searched the internet and stackoverflow but did not find something that was useful.
I do not know if it is possible or not but I will appreciate when somebody can give me information or directed me to good links.
I don't know much about the Package Explorer, but with the Project Explorer (Common Navigator) (which you should also address), there is a TreeViewer associated with it (in this case the class is CommonViewer). You can get that by doing CommonNavigator.getCommonViewer(). Once you have the TreeViewer, you can then get to the underlying SWT Tree and from there use the standard SWT methods to get the position of the tree relative to the enclosing window. There are also methods where you can get the bounds of a tree cell. Have a look at the SWT Snippets (Google it) to help you work with the Tree.
For the Package Explorer it will be similar; you will have to look at the source code.
As described in Francis' answer you should be able to get the TreeViewer, and TreeViewer#getControl() would provide the underlying control.
When you fetch the position and size of a control via control.getBounds(), those would be relative to the coordinates of the shell/window. If you need the absolute display/screen coordinates, see control.toDisplay(some_x, some_y)
I want to share my steps on how I solved my problem. After the advices I digged deeper into the jdt Java infrastructure of the Java IDE. To get the TreeViewer of the Package Explorer I had to cast the "PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("org.eclipse.jdt.ui.PackageExplorer")" into a "PackageExplorerPart" which is in the "org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart". The further steps I did were:
treeViewer = packageExplorerPart.getTreeViewer();
tree = (Tree) treeViewer.getControl();
After that I created a "Point" with the coordinates x and y, which were passed by touching the screen. But, the point location were representing the whole screen and to get the correct coordinates for the Package Explorer I converted the point with the method tree.toControl(...). At last, I checked if an item was given with method tree.getItem(....).

Ext-GWT / GXT (Not So) Simple Layout Issue?

I have posted this question on the Ext-GWT forums, I am just hoping that someone here might have an answer for me!
I am struggling to do something I initially thought was simple but am beginning to believe is impossible...
I have got a "layout template" of sorts - simply consisting of a few GWT DockLayoutPanel's within each other and finally ending in LayoutPanels. GWT's LayoutPanel is designed to size the widget (or Composite) that's added to it to its full size and does so perfectly with pure GWT widgets.
The idea of my "layout template" is that I don't know the EXACT height and width of the very inner LayoutPanel's because I may set certain panels sizes (of the outer DockLayoutPanels) differently when instantiating this template. All I would like is to add a Grid component to one of the inner most LayoutPanels and have it size itself (height AND width) to fit as normal GWT widgets do (works perfectly with a GWT Label for instance).
I am VERY new to GXT (as in I started using it earlier today) and I do realize that GXT builds its Components differently to the way GWT builds its Widgets on the DOM.
Is there anyway to achieve the desired result? I have tried adding the grid to a ContentPanel with a Layout of FitLayout, I have tried AnchorLayout, I have tried adding the grid directly... Nothing seems to work... Any advice or even a push in the right direction would be greatly appreciated!
Thanks in advance!
Xandel
Just a note on this post and the direction I have taken. When I started my GWT project and I was learning the basics and reading through others posts and concerns and advice, the one bit of advice I overlooked initially was quite simple - when using the GWT framework use pure 100% GWT components only.
I initially ignored these fair warnings of fellow developers because in the age of open source tools, and open source projects, one develops the mind set of "Instead of building a tool which will give me certain functionality, let me rather see if someone else has done it already". This mindset speeds up development and almost standardizes projects and methods of implementation.
However, I have found over the last two months, that when working with GWT it is best to not follow this principle. Maybe because its not as widely spread as other frameworks, or demands a very certain type of coding style but non the less my search for a (simple, sortable, JSON loadable) grid component and (validating, neatly styled) form component has been nothing short of a nightmare.
This isn't because they don't exist. They do. I tried ext-gwt, gwt-ext, gwt-mosaic, and gwt-incubator. It is because many of the components break away from the very simple layout foundation that GWT provides (in other words, the panels that you place the widgets on mostly need to be the panels provided with the tools). This in turn makes mixing components and getting the desired result near impossible. Which in turn breaks away from the let-me-find-a-useful-component mindset.
Just an interesting and final point which I think might be worth mentioning. So due to my realisation of the above mentioned point, I set about to write my own grid and form components. Which I have completed and are working fine for me (obviously, because I wrote them , I don't suspect they will be useful to everybody else). But in the process of writing the grid component, and needing the columns to size and space themselves out automatically once drawn in their parent panel, I found that knowledge of the panels final width is not known until finally being drawn (this happens long after all your code executes). So ironically I set about building a set of panels that communicate to each other, from the parent panel (who ultimately NEEDS to have knowledge of its size) right down to the most inner panels so that when my grid component finally gets drawn, I can fire a method called onSizeKnown(int width, int height) and do whatever sizing is required.
After I completed this I could do nothing but laugh. Because it suddenly became clear to me why all the other GWT components out there require their own panels. I in essence had to do the same to get what I needed working.
So in short, if you are a newbie GWT developer like I was and are (is?) looking for cool stuff to make your project look awesome - this is my advice - if you are going to use an external framework such as some of the above mentioned - use ONLY that framework. Do not mix its components with other frameworks. Learn to love that framework, and build your project from the bottom up using their panels and design methods. If this scares you and makes you feel nervous and limited then do what I did and write your own using pure vanilla GWT components. You will save yourself A LOT of time in the long run by following this advice.
Xandel
This solution is for GXT 2.2.0 and GWT 2.0.4 *
While the original poster has since moved on I recently ran into this issue and thought I would post my solution in case anyone else stumbles on this.
There is no reason you can't add a GXT Grid directly to a GWT LayoutPanel. The problem is that the styling/positioning approach of the two libraries conflicts. Basically it boils down to the fact that the Grid is sized based on its parent's height attribute, which is not set meaning that the grid's body get assigned a height of 0 and the grid itself gets a height equal to that of the grid header (if present).
So the solution is to undo what GXT does once flow has passed back to GWT. Here is a template solution:
class MyGridWrapper extends Composite {
private LayoutPanel widget;
private Grid<?> grid;
public MyGridWrapper(Grid<? extends ModelData> grid) {
this.grid = grid;
widget = new LayoutPanel();
initWidget(widget);
widget.add(grid);
// Set the grid's vertical and horizontal constraints
// ... populate the rest of the panel
}
#Override
protected void onLoad() {
// onLoad is called after GXT is finished so we can do what we need to
// Redo what the LayoutPanel did originally
grid.el().setStyleAttribute("position", "absolute");
grid.el().setStyleAttribute("top", "0");
grid.el().setStyleAttribute("bottom", "0");
grid.el().setStyleAttribute("left", "0");
grid.el().setStyleAttribute("right", "0");
// Undo any height settings on the .x-grid3 element
El mainWrap = grid.el().firstChild();
assert mainWrap.hasStyleName("x-grid3") : "Wrong Element: " + mainWrap.getStyleName();
mainWrap.setStyleAttribute("height", "auto");
// Undo any height settings on the .x-grid3-scroller element
El scroller = grid.el().firstChild().firstChild().getChild(1); // FUN!
assert scroller.hasStyleName("x-grid3-scroller") : "Wrong Element: " + scroller.getStyleName();
scroller.setStyleAttribute("height", "auto");
}
}
The assertions are there to help protect against what is obviously very fragile code so beware that this is a GIANT, GIANT hack.
--
Just in case you're wondering where the GXT Grid's structure is defined, you can find it in a template file in the GXT JAR under com/extjs/gxt/ui/client/widget/grid/GridTemplates#master.html
Have a look at com.extjs.gxt.ui.client.widget.grid.GridView#renderUI() to get an idea of how the grid is built.