Eclipse RCP fireSelectionChanged from Non-SWT client - eclipse-rcp

I have the following problem:
I have a framework in which arbitrary clients can run. Imagine you have a non-swt/non-swing client and you want to invoke a fireselectionchanged event to the Workbench. Is that possible somehow.
Once again. I am not able to get the edior/viewer or something else in my plugin!
Thank you very much

At any given time there can be only one selection provider per workbench window/page and it's the one provided by active workbench part. Hence, it's only possible to provide selection and notify selection change from a view or an editor.
While it is possible to access the selection provider of current active part and set selection to it...
workbenchWindow.getActivePage().getActivePart().getSite().
getSelectionProvider().setSelection(ISelection);
...it's not guaranteed that (1) there is an active part at the time and that (2) the selection provider of the active part supports the type of selection that you want to provide.

Related

How to check if a form is fully loaded?

I have forms that contain controls in my application under test. These controls load data in their own threads.
I would like to add a block until the form is fully loaded.
How is this done?
I think the cleanest way to do that is to listen to AsyncContentLoadedEvent.
An other way, which assumes you know which components needs to be loaded, is to search the UI Automation Tree for the AutomationElement(s) directly (FindAll, FindFirst, TreeWalker).
If all AElements are available it means it's loaded. You could consider the childCount or various AutomationElementProperties to verify that. Of course several Patterns (e.g. ValuePattern) could be additionally used to verify the state of the AElements.
Alternativly to AsyncContentLoadedEvent, you could check out if your application uses some kind of UI Element for showing the current status of the loading process (HelpTextProperty, Icon, Label, etc..).
In such case I would simple query this certain AElement for it's current value/name/.. (or also color (not directly supported by UI Automation and requires some workaround)). and wait until it has the required state

Stopping Ember.js Controller

My question is very basic on one hand but on the other hand the general situation is more complex, plus I cannot really get any working sample.
I'm developing/maintaing a web-application which is currently in transition from GWT code base into Ember.js.
Most of the newer code already relies on Ember.js and I think it's really awesome.
The problem is we cannot use Ember Router as all the request are being handled by the GWT.
In order to enabled the application run in this unusual configuration we have special JavaScript files that create our Ember main objects (Controllers & Models) for us.
As you can imagine navigation between tabs is cumbersome and is handled by GWT who creates Ember objects when needed. We are in transit toward a brave new world Ember Router and all.
But in the meantime, this is the problem I'm facing right now.
The user clicks a link which opens a page that contains some Ember based table.
The data is retrieved form the server using some Ajax code. Upon success it spawns a forEach loop which tries to pushObject all the received date into our Ember based components.
My problem happens when the user quickly switches between tabs. In this case the first list of object has not finished rendering yet and suddenly there's a new set of objects to handle. This causes Ember to throw errors like:
"Uncaught Error: Cannot perform operations on a Metamorph that is not in the DOM. "
and
"Uncaught NotFoundError: An attempt was made to reference a Node in a context where it does not exist."
Is it possible to prevent the loop from trying to render?
I've tried checking if the controller in question is already inDOM and it is, is there a way to notify Ember this object is no longer valid?
Sorry for a lengthy question and lack of running sample.
I'd probably modify the switch tab code to only execute afterRender has completed, that way you aren't mucking with ember objects while they are being used.
Ember.run.scheduleOnce('afterRender', this, function(){
// call GWT switch tab routine
});
Thank you Daniel and Márcio Rodrigues Correa Júnior. eventually what I did is to add a patch that would check the current context of the application (in my case the currently selected tab). If upon receiving the AJAX response the application is in the correct context (meaning the user haven't change the tab) go on. Otherwise just ignore the response and do not try to render it.
Now it seems to be working

Eclipse RCP : how to get currently selected node in preference dialog

I have added a new preference page in my application. and performing some task when user press ok button. problem is my code is executing even other node(preference page) is selected in the preference dialog.now i need to check whether currently selected node is my preference page before executing my code inside ok button. any help will be appreciated.
Sorry to say, but I think your problem have started a bit earlier. If done without too many hooks and nooks, you should only be called when necessary, so it sounds a bit odd to me.
I can usually just override performOk or in some cases performApply without these problems.
Have a look at the docs, just in case

how to change browser history without going to place/ starting activity (gwt)

in my app i have a relative complex activity/place. Resolving the state (from history token to model) on start of activity causes some server interactions.
On user interactions the activity only updates the necessary parts of the model and therefore safes some server interactions - the activity/model has an inner state.
Is there a way to reflect the state in browser history without (re)starting the activity? (History.newItem(token) also causes start of activity)
UPDATE
Chris' solution "nearly" works but another problem rose: in my ui i have a reset-button (a link to the place with empty token). If i click around the ui the token is updated fine but now the reset button doesn't work. gwt thinks it is in the same place and so it ignores the reset click.
Before this the problem was nearly the same: the token and place didn't change and so the reset button didn't work either.
GWT logs this as "Asked to return to the same place"
So is there a way to let gwt restart the activity regardless of place equivalence?
Go to a new place, but have your ActivityMapper return the same activity instance. That way, the activity is not restarted.
You have to find a mean of updating the activity when the place changes from some other mean though (e.g. browser history). See GWT MVP updating Activity state on Place change for instance.
There is a semi-solution, and although I don't want to recommend it, I'd like to add it here - just to warn against the drawbacks of this solution:
You could add tokens to the History without firing an event by calling History.newItem(token, false).
This is a semi-solution, because:
It works correctly (as long as you build your tokens correctly).
A part of the performance problem is also solved: The activity won't be re-started when adding the token to the history.
However, if the user goes back and forward through the history, the performance problem would still be there (because then, the events will be fired again).

Prevent closing the Application if file not saved

We have an application based on Eclipse-RCP. The problem I am trying to fix is as follows:
Say the user has an unsaved model file, and tries to close the application. The application rightly prompts the user for options to Save the file, Ignore it, or Cancel closing the application. Ignore and cancel are no-brainers. If the user decides to save the file, there is another dialog box that gives the user an option to either save the file or cancel the save (its a custom editor, similar to a Save-As dialog).
Now, the question:
How do I prevent killing the application when the user selects "Yes" in the first prompt, but cancels the save in the second? I thought of looking up the base class of the application, but couldn't find it. Or should I be looking at the custom-editor for the model file?
Thanks in advance, any help is appreciated...
If you are in RCP you have the luxury of returning false from WorkbenchAdvisor.preShutdown()
Let a workbench part holding the model implement org.eclipse.ui.ISaveablePart2 interface meant for cases like yours.