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

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(....).

Related

How to add the new unity uxml(via ui builder) to game screen?

I installed the new Unity UI Builder. Everything works just fine...
But how do I add the uxml to my scene or how do I attache it to camera?
I tried to drag and drop the uxml to camera and I searched for a component, but I couldn't find anything... Is there any official documentation?
You must use an gameObject with PanelRenderer.cs attached to it:
For now, I only know you have to set UXML file and USS file. In play mode, by magic (I still don't understand how unity does it), it will render.
In the Github project you can see how things are for now. UIElementsUniteCPH2019RuntimeDemo
EDIT:
The project linked above uses UI Builder 0.8.
Runtime support is still not available using the packet manager.
You can add the preview version to your project by adding the following line to your manifest.json (it's located in the projects Packages-folder)
"com.unity.ui.runtime": "0.0.4-preview"
You may want to check whether a newer version is available.
Keep in mind that the preview version is intended for previews only. The api and workflow might change with newer versions.
Once runtime support is enabled you can use the Panel Renderer as described above.
In Unity 2021.2, when you add a UI Document to the hierarchy, a PanelSettings asset is automatically created and assigned to the that UI Document.
Simply add your uxml file to the UI Document -- there is no Panel Renderer component anymore.
Even though the UI Builder offers a preview of the menu over the actual game scene, there is no way to use that menu in a game using Unity's functionality or packages. To do that we need to use the code that comes with the demo by Damian Campeanu from Unite Copenhagen 2019 that you can find here: https://github.com/Unity-Technologies/UIElementsUniteCPH2019RuntimeDemo.
The demo has following structure.
Structure of the project
The files that we are interested in are located in Assets/UIRuntime folder. Simply copy this folder into Assets folder of your project.
After copying the the folder,create empty game object, and add two components in the inspector. Panel Scaler and Panel Renderer.
Game menu object with panel scaler and panel renderer components
Panel Scaller is responsible for scalling your menu for the display. Choose "Constant Physical Size" and 96 for both Reference and Fallback DPI. Those are the values from the original demo and 96 DPI is a typical pixel density for most computer screens (it is different on mobiles and high density screens).
Panel Renderer is the place where you will set your UXML and USS (Unity Style Sheet) files (Uxml and Unity Style Sheet fields. Leave the last two of fields empty, and tick the "Enable Live Updates" checkbox. This will enable you to show the updates in the game viewport as you make them.
I wanted to comment under existing answer by Pablo but I'm new so I can't.

How can I only display projects inside a treeviewer eclipse plugin?

I am making a tree viewer in Eclipse which would be used to pick a project and then I would find out the location of the project and zip it up.
I can currently display a tree which shows all the projects but it also allows you to expand the tree.
I am doing this in a wizard so I am unable to any dialogs.
I think I would need a filter but after using Google for a while I was unable to figure out how I could do this.
This is how I am currently making the viewer.
TreeViewer view = new TreeViewer(composite,new WorkbenchLabelProvider(),new BaseWorkbenchContentProvider());
view.setInput(ResourcesPlugin.getWorkspace().getRoot());
It's showing you exactly what that content provider is written to show.
The short answer is to setInput(ResourcesPlugin.getWorkspace().getRoot().getProjects()) and use the ArrayContentProvider with a ListViewer rather than the TableViewer.
The long answer is that the content provider you were using returns both the top level elements for the tree control using getElements() and any resource's children via getChildren(), and your case is not interested in the results of getChildren().
Projects are never nested so you only really need a TableViewer to show them. You can get the list of projects using:
IProject [] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
The same label provider will work.

how to inspect gwt screen?

GWT screens are composed of a hierarchy of Widgets each implemented by various application classes. In order to maintain (add/change) these screens it is required to understand its structure, namely to discover which screen element is rendered by which Widget implementation.
Currently, I am trying to read the "suspected" class source while peeking at the DOM structure of the screen.
I am looking for a tool, or method, to aid with discovering which Widget class renders a specific screen element.
Such a tool would monitor the mouse position on screen and provide the class name of the hovered element (for example, in a tooltip).
Alternatively, I would be happy to find a programming method that allows adding a generic mouse event handler, most desirable to the RootPanel, further displaying the class name of currently hovered element.
Unfortunately AFAIK ,as of now there is no such tool for GWT( will be more happy if any ) .
As on browser side there is no such information available related to class files of java available since it compiled to javascript.
So , what's the fix??
Though very common and tradational.
1)Proper naming conventions
2)Proper package structure
3)Documentation etc ...
Check out the GWT-Instrumental project for an example of how this can be achieved. This is not a new project and may need to be updated to be properly useful in some cases, but seems to work with GWT 2.4 and GWT 2.5.1 projects just fine. The Inspector bookmarklet/instructions can be found at http://gwt-instrumental.googlecode.com/svn/latest/inspectorwidget/index.html.
This isn't doing exactly what you are describing, but could be modified fairly simply. What it does do is this:
When launched (or refreshed), look at every element on the page to see what widget might be references, and what css classes it has, what id it has, and what DOM events are sunk on it.
When expanded, renders a firebug-like tree of the DOM elements in the body, along with the details mentioned above
When the user hovers over a element in the tree, draws a yellow overlay on where that item is drawn on the page so you can find it.

How to implement Quick Fix / Quick Assist for custom eclipse editor?

I have extended org.eclipse.ui.editors.text.TextEditor to implement a custom editor.
For this editor, I have defined a marker type (org.eclipse.core.resources.markers extension point) and an annotation type (org.eclipse.ui.editors.annotationTypes extension point) to mark specific parts of code in my editor. I use a reconciler to update my annotation model.
Now I want to add a quick fix / quick assist feature. I simply want eclipse, to show a box with proposals, when I hover over an annotated part of the code and replace that part with a given string, when I click on a proposal. Just like the quick fix feature for the java editor.
So, what is the best way to implement this behavior?
I read about marker resolution generators and quick assist processors, but I'm still confused how it all works together...
I would be glad, if someone could point me to the right direction.
EDIT: From what I've understood so far, a MarkerResolutionGenerator is responsible for showing quick fixes in the problems view. To get quick fixes in the source viewer, I would have to set a QuickAssistAssistant for my SourceViewer and implement a QuickAssistProcessor which returns CompletionProposals.
Is this the right way to do it?
EDIT2: I'm wondering if I need Markers at all, or only Annotations, I'm confused...
I finally found out how to get Quick Fix to work for my editor.
I use the annotationTypes extension point to register my own annotation type and the markerAnnotationSpecification extension point to specify the look and feel. In my custom SourceViewerConfiguration class I override getAnnotationHover(...) to return a DefaultAnnotationHover object and getTextHover(...) to return a DefaultTextHover object, so the annotations are shown in my source viewer.
Then I override getReconciler(...) to return a MonoReconciler with my own implementation of IReconcilingStrategy to create the annotations in its reconcile(...) method. And finally I override getQuickAssistAssistant(...) to return a QuickAssistAssistant with my own implementation of IQuickAssistProcessor. The computeQuickAssistProposals(...) method in the processor class computes the quick fix proposals which show up, when I press CTRL+1.
I don't create any Marker objects and don't use a MarkerResolutionGenerator, since the marker concept is much more heavyweight than using only annotations and the functionality which annotations provide fits my needs.
You have to register an extension to the extension point org.eclipse.ui.ide.markerResolution. This extension refers to a markerType (using the markerId), and also a resolution generator.
The latter component is responsible for calculating the possible fixes: it reads the marker, it can check the related files, etc., and creates marker resolution instances. These resolution instances basically process the erroneous files, and hopefully fix the original problem.
During marker resolution, you should not worry about removing the markers, as after the fix is executed, sometimes the validation would run again (e.g. during the build, or if no automatic validation is available, then manually - but it is not the task of the marker resolution to update the list of markers).

how to zoom a graph using zest?

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.