Eclipse Plug-in:Focus lost after activating a view via (controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE)); - eclipse-plugin

I have a view which is initialised via OleControlSite and invoked via OleAutomation. It is actually a media player which I call in a view after user right clicks the file and calls Play in the context menu. Whenever I play a file by first right clicking and calling Play, it plays absolutely fine. The problem is when user displays the view before doing a right click(Window->Show View->Other->MyView) and then tries to do a right click and Play, at this point of time ISelection returns null and hence nothing plays.
IWorkbenchPage iwPage=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ISelection selection=iwPage.getSelection();
The problem is the selections somehow loses focus if the view has been invoked in the fashion described.
This is how the view is initialised when the plugin is loaded
public void createPartControl(Composite parent) {
frame = new OleFrame(parent, SWT.APPLICATION_MODAL);
// OleControlSite controlSite;
try {
controlSite = new OleControlSite(frame, SWT.APPLICATION_MODAL,"WMPlayer.OCX.7");
controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
oleAutomation = new OleAutomation(controlSite);
makeActions();
fillActionBars();
} catch (SWTException ex) {
MessageBox box = new MessageBox(getSite().getShell(),SWT.ICON_INFORMATION);
box.setMessage("Failed to Initialise Media Player.");
box.setText("Error");
box.open();
ex.printStackTrace();
return;
}
}
Is there a way where we can force the focus to the Project Explorer where the current file is selected ?

Related

Libgdx Dialog buttons cannot be clicked

I have trouble properly implementing a dialog. It does not recognize button clicks - even the button down animation does not happen. However, it does recognize key presses (e.g. enter or esc in my case). Dialog does appear to be on top of the stage objects, so I'm confused why it isn't registering my clicks.
I have an InputMultiplexer with processors InputHandler class (implements InputProcessor) and stage, in that order:
InputMultiplexer im = new InputMultiplexer();
im.addProcessor(new InputHandler(stage));
im.addProcessor(stage);//trying to make dialog work by doing this
Gdx.input.setInputProcessor(im);
Here's my showDialog method defined in stage:
public void showDialog() {
Dialog dialog = new Dialog("Quit?", skin) {
#Override
protected void result(Object object) {
boolean exit = (Boolean) object;
if (exit) {
Gdx.app.exit();
} else {
remove();
}
}
};
dialog.button("Yes", true);
dialog.button("No", false);
dialog.key(Input.Keys.ENTER, true);
dialog.key(Input.Keys.ESCAPE, false);
dialog.show(this);
}
The showDialog() method is called from InputHandler when it recognizes that the game is over (I have it set so that the game state is checked and updated on touch up, since it's a touch based game). My understanding is that since the multiplexer receives false return from the InputHandler methods when the game is over, it then goes to the stage for input, which seems to be working only when I use key presses on the dialog, i.e. enter quits the game, esc removes the dialog, but clicking the buttons do nothing.
Here is my Screen's render function in case it's relevant:
#Override
public void render(float delta) {
Gdx.gl.glClearColor(1,1,1,1);
Gdx.graphics.getGL20().glEnable(GL20.GL_BLEND);
Gdx.graphics.getGL20().glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT | (Gdx.graphics.getBufferFormat().coverageSampling?GL20.GL_COVERAGE_BUFFER_BIT_NV:0));
stage.act();
stage.getCamera().update();
stage.draw();
}

How to implement correct Back behaviour when using Frame.Navigate?

I have a Windows 10 Universal Windows Platform app with multiple pages, a main page, a list page and a details page and use the following to navigate to List page:
this.Frame.Navigate(typeof(ListPage), parameter);
When you are on the list page you can select an item which will launch a details page like so:
this.Frame.Navigate(typeof(DetailsPage), parameter);
Which works fine, the parameter is a selected Id or information then when using the Back button which on a Desktop app or Phone uses:
this.Frame.GoBack();
This always returns to the MainPage, that is when go from Main, to List to Details hitting back goes to Main, how do I get the GoBack to Go back to the previous page, it always seems to go home rather than the user expected behaviour, an ideas how to resolve this?
I’ve seen this before when you subscribe to the HardwareButtons.BackPressed event (or whatever the equivalent is in a Win10 UWP app) on a page, but then don’t unsubscribe from it. This means two event handlers get called when pressing Back, and both event handlers call Frame.GoBack().
I always subscribe to the event in the page’s NavigatedTo event, and unsubscribe in the NavigatedFrom event.
Could this be happening with your app?
If every page in your app should have the same behaviour, i.e. go back to the previous page, then subscribe to the back button event in the app class as suggested by #RoguePlanetoid in the comments:
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
The OnLaunched method would be a good place to do this. Don't forget to tell the OS to display the back button when the app is running on a desktop or tablet:
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
Then, add an event handler in the app class like this:
private void OnBackRequested(object sender, BackRequestedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame.CanGoBack)
{
e.Handled = true;
rootFrame.GoBack();
}
}
If you want different behaviour on different pages when back is pressed, i.e. ask the user to confirm losing their changes or something, then subscribe to the back button event in a pages OnNavigatedTo method (the code will be same as above), but make sure you unsubscribe in the page's OnNavigatedFrom event:
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
SystemNavigationManager.GetForCurrentView().BackRequested -= this.OnBackPressed;
base.OnNavigatedFrom(e);
}

Android ViewPager and Camera Preview issue on Gingerbread

I did extensive documentation study on ViewPagers and on Camera apps, infact everything works quite fine, except for a major issue on GingerBread, which I haven't found any question about on S.O. so I'll try asking this one...
In my application there is a ViewPager (support library v4) which shows two fragments:
One, will call it the main fragment, the one showing when the activity starts, certain information are shown to the user, including an imageview, which is initially empty and hidden.
By swyping to the next fragment, the user sees the camera preview, which gets created when the activity is created (even if it not showing until the swype) and the button to take a picture.
When the picture is taken, the view is programmatically taken back to the main fragment, the
imageview is loaded with the new photo and unhidden so the user can see the image mixed with the other preexisting information.
If the user does not like picture, he can swype back again to the camera fragment and take another one, and so all over until he is satisfied with the result.
For this reason, before flipping back to the main fragment, I call mCamera.restartPreview() and ensure the camera is ready should the user swype back.
Everything works smoothly and fine on Android 4.x, but when I test this on a 2.3.3 (API Level 10) the camera preview remains in foreground when the main fragment is called back, and hides the view. You can see, and even scroll, the remainder of the view, in the portion of teh screen where the camerafragment shows the buttons, but the rest is overlapped by the camera preview.
Here is the code of the relevant functions:
CameraFragment onPictureTaken()
private PictureCallback mPicture = new PictureCallback() {
#Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
if (pictureFile == null){
Log.d(TAG, "Error creating media file, check storage permissions: ");
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
Log.e(TAG, "FILE " +pictureFile.getAbsoluteFile().toString());
Bitmap bitmap = rotated(data);
bitmap.compress(CompressFormat.JPEG, PICTURE_QUALITY, fos);
bitmap.recycle(); //devo davvero chiamarla esplicitamente ??
mediaFile = pictureFile;
mPreview.restartPreview();
// go back to newpin activity to show it
((NewPinActivity) myActivity).newPin.setMedia(mediaFile.getAbsoluteFile().toString());
((NewPinActivity) myActivity).takeBack();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
}
}
};
and the mainfragment takeBack() method
public void takeBack(){
mViewPager.setCurrentItem(0, true);
String mainFragTag = "android:switcher:"+R.id.newpinpager+":0";
Fragment fragMain = this.getSupportFragmentManager().findFragmentByTag(mainFragTag);
try {
((NewPinMainFragment)fragMain).showPhoto(newPin.getMedia());
} catch (NullPointerException e){
}
}
Does anybody have a clue if this is an issue with the ViewPager and GingerBread or with the CameraPreview and Gingerbread or what ?
I found the answer by myself, I'll post it here in case it's going to be useful to others.
Apparently the problem was cause by the smoothscroll option of setCurrentItem method.
The issue was fixed by changing
mViewPager.setCurrentItem(0, true);
to
mViewPager.setCurrentItem(0, false);

Windows Phone 7 Control Caching - 'Element is already the child of another element'

I'm trying to speed up my windows phone 7 page load times. I have a 'static' page that has a dynamically created in a Panorama control - static meaning that the content never changes.
On the first load I look at my config file, create the individual PanoramaItem controls and add them to the main Panorama control. I'm trying to keep a List in a static place so that the initial creation would only happen once and I could just add a fully rendered version to my Panorama control when the page was rendered.
Works fine on first load, but when I try to add the cached PanoramaItems to the Panorama control I get the message "Element is already the child of another element". This makes sense since I already added before. But I can see a way to disconnect the PanoramaItems with the first Panorama control...
I could be going about the control caching thing all wrong as well... Let me know if there's another way to do this.
You can use Panorama.Items.Remove(pivotItem) for this
As an example
With the following page fields
PanoramaItem pi;
bool blahShown = false;
On the press of this button, the control is first instantiated and displayed and on subsequent presses removed and readded without instantiation.
private void button1_Click(object sender, RoutedEventArgs e)
{
if (pi == null) {
pi = new PanoramaItem();
pi.Header = "blah";
}
if (blahShown) {
Pano.Items.Remove(pi);
blahShown = false;
} else {
Pano.Items.Add(pi);
blahShown = true;
}
}

Silverlight Navigation and Authentication service

I am creating a silver light application using Navigation app template. It is for internal use and hence uses windows authenticatoin. There is a dashboard page which shows couple of records filtered by logged in users id. To get the user id (which is an int) I call a web service by overriding the GetAuthenticatedUser and pass the username (from IPrincipal). This service takes some time to return the details.
When I navigate to dashboard app, it renders completely with no data because the user service is a async operation and I am not able to make the rendering wait till my GetAuthenticatedUser finishes completely. So I created a Login page which just shows a progress bar till I get the user object and then navigate to dashboard. If someone tries to access the dashboard directly by using the URL, i want them to navigate back to Login page.
So in the dashboard constructor I added the following code
if (!UserService.Current.User.IsAuthenticated)
{
MessageBox.Show("Navigating away");
Frame objContainer = this.Parent as Frame;
objContainer.Navigate(new Uri("/Views/Login.xaml", UriKind.Relative));
}
Thogh I get the message box prompt, it does not actually take me to Login page but stays in dashboard page. I also tried putting this code in OnNavigatedTo override with no luck.
I also tried using NavigationService instead of Frame as below, with no luck
if (!UserService.Current.User.IsAuthenticated)
{
MessageBox.Show("Navigating away");
this.NavigationService.Navigate(new Uri("/Views/Login.xaml", UriKind.Relative));
}
it still does not work. Does anyone know how to make some page accessible only if I have fully valid user object? if they try to access the restricted page without this, I want them to be able to redirected to Login page, how can this be achieved?
I am using Silverlight 3 Beta
Shreedhar
I finally found a way around this. In the Constructo i Hooked up the Loaded event handler and in the event handler I am navigating to a different page and it works fine now.
public Dashboard()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Dashboard_Loaded);
}
void Dashboard_Loaded(object sender, RoutedEventArgs e)
{
if (!UserService.Current.User.IsAuthenticated)
{
Frame objContainer = this.Parent as Frame;
if (objContainer != null)
{
objContainer.Navigate(new Uri("/Views/Login.xaml", UriKind.Relative));
}
}
}
This piece of code works just fine!
Shreedhar