passing a object to a rcp view - java

I want to do something like this pseudo-code
MyView v = new MyView(); //yeah, I know i can't do this
v.setObject(myObject);
v.show();
my case is: i'm using swtjasperviewer to show my reports, and i have to instantiate the report in this jasperviewer, which leave the view opened if the report has no pages...
I want to use a command to open a view, and pass the report to a view, this way, I can use a generic view.
thanks a lot

There are basically two ways to do this:
If the object is somehow related to the selection of another view or an editor, then you could use write a SelectionListener that gets the current selection, and then sets the correct object using the following method: getViewSite().getPage().addSelectionListener(mySelectionListener)
Otherwise, define an object that both your code and the view can reach (e.g. using a static attribute, an OSGi service or an Eclipse extension), and you can use that object to pass information. Your data source updates this object, and you can define a change listener/callback that the view can register himself to.

Related

RCP 3.x editable PropertySheet view

I implemented a custom PropertySheet as described in here.
So I have a main view, which implements the selectionprovider and it works to show the properties in my custom PropertySheet view.
My problem is now, that I want to edit the some properties of the selection in the property view and prevent changing the selection in the main view, if there are unsaved changes in the property view.
What is the best way to solve that problem?
If I implement the ISaveablePart in my custom property view, I can mark it as dirty. How can I prevent to change the selection, if my property view is dirty?
Thanks in advance!
As a view is a non-modal (e.g. non-blocking) UI component, there is no real way to prevent selection changes outside the view. For this reason, the expected way of Properties view to work is to save as soon as possible.
The default, TreeViewer based implementation of EMF models uses a CellEditor to change its values; when the value in a CellEditor changes, the changed values are written back to the original model automatically to avoid the data loss scenarios you have mentioned.
In other words, you have to rely on your data source (e.g. the editor that provides the selection) to store the permanent changes, and the changes can be serialized through that source (editor).

How does the search view even get rendered?

I have been digging around in the search view source code for quite sometime now trying to understand how exactly does the search view even have a user interface to be rendered. First of all here is the source code:
SearchView source code
So what I don't understand is how does the user interface element of the search view even get rendered when the search view doesn't even have any onDraw() method. All that I can see is responsible for the display element is a bunch of view at the start which are in the constructor, the SearchView gets a reference to and change the background and set the image of these view. If all that I can see was done is getting references to some views and changing the background as well as the image without having it within the proper view hierarchy then how exactly does it even get rendered?
I understand what you are probably wondering why do I even need to understand this. Well I want to understand this so I can create my own custom search view. Since I only need like 2 function on my search view I figure it would be a lot better to make one that suits my need instead of the thousand of lines of code in the source one. Plus, I want to create one that I know I will understand how to use not the complex default one.

Listen to EObject changes in XText editor from another Eclipse view

I want to create an Eclipse view of the document that is in the current XtextEditor. To create the view I want to traverse the EObject's created by xtext from the document contents. I can get the current editor but I can't work out how to get the EObject's?
I assume that the EObject tree of the DSL is available as its what xtext uses internally and I'm also assuming that it's what is used to populate the eclipse outline view.
I thought that I would be able to get the XtextResource from the editor, but when I get the resource I just get a org.eclipse.core.internal.resources.File
Anyone know how to get a reference to the current ECore model that the editor is using?
you can use
XtextEditor.getDocument().readOnly(IUnitOfWork)
please note: you may not return the resource or contents in IUnitOfWork
another possibility is to simly load the resource separately into a resourceset

Eclipse plugin to view image while debugging

Is there an Eclipse plugin that will let me view an image variable while I'm paused at a breakpoint? e.g. I would like to see the image when inspecting a BufferedImage object instead of seeing it's toString value.
The extension point org.eclipse.jdt.debug.javaLogicalStructures is used to provide the structured view of variables in the "Variables" view... and unfortunately it can only give you a string based result.
In theory, you can add a new plug-in which adds a new command to the "Variables" view (the selection is of type JDILocalVariable)...

Eclipse RCP update a View after changes in the editor

i am new to Eclipse RCP and have the following Scenario:
One plugin which is the Application
Another witch is a view and does show
some Data
And a third which is the
editor.
in the view I can right click on a record and choose edit what does open the Editor and lets me change the data.
No I'd like to refresh the View when I save the Editor. I think this is a classical scenario to implement a Whiteboard pattern. Unfortunately I am not really familiar with it, may be some one could show a simple example how to implement it in Eclipse RCP.
Thanks in Advance
Johannes
Your view needs to implements IPartListener2 (http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/IPartListener2.html)
you can override the method partInputChanged(IWorkbenchPartReference partRef) to refresh thw view in two ways:
1) If the plug-in with view has dependency to plugin with editor
If (partRef instanceOf YourEditorClass){
YourData yourData = editor.getInput().getxxx();
}
2) If the plug-in with view doesn't have dependency to plugin with editor
you need to use an adapter. You override the getAdapter method in the editor to return the Data that you need and the view get the data from the adapter
If (partRef instanceOf EditorPart){
YourData yourData = Platform.getAdapterManager().getAdapter(this, YourData.class);
}
Two codes are just an example to show the idea!
I hope I helped you
The view has to listen to the editor or - even better - to the edited model. If it listens to the editor, look for some "save" events. Personally I would make the model itself observable and notify listeners (like your view) of actual changes.
The view then needs some logic to extract its information from the model. So instead of a whitboard - the observer pattern should be the right choice for your design.
This is worth a try: add an IPropertyListener to the IEditorPart instance of your editor and wait for property changes. The IEditorPart.PROP_DIRTY property should change from "is dirty" to "is not dirty" after a save. Snippets/code example for eclipse rcp stuff are hard to develop and to communicate. Use the buzzwords from my answer for some searches on the eclipse help, API and on google. And: good luck ;) - btw, consider buying some good books on eclipse plugin/rcp development, they're worth every €/$ spent.

Categories

Resources