How do I disable/enable a handled toolitem based on which MPart is selected? - eclipse-juno

I have several toolitems that I want to enable/disable based on which MPart the user selected. How can I accomplish that ?

You can add the following code to the handler of your toolbar items:
#CanExecute
public boolean canExecute(#Named(IServiceConstants.ACTIVE_PART) MPart part) {
// enable item if active part is part with id "my.part.id"
if ("my.part.id".equals(part.getElementId())) {
return true;
}
// disable item if any other part is active
return false;
}
#CanExecute is called before the handled entry is shown in menus or toolbars. If an entry cannot be executed, its state is set to "disabled".
In the above code, the active part is injected and can then be used to determine the handler's executable state.

Related

Track Share events to FirebaseAnalytics

I have a share function on the app that allows users to share app to others, but I want to track number of shares. The share item is on the action bar, not on the app dropdown menu.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
//some other code here for items search item
//share menu item
MenuItem shareItem = menu.findItem(R.id.menu_item_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
String playStoreLink = Constants.PLAYSTORE_LINK + getPackageName();
String shareText = "Install app" + playStoreLink;
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setType("text/plain").setText(shareText).getIntent();
// Set the share Intent
mShareActionProvider.setShareIntent(shareIntent);
return true;
}
I have managed to implement tracking on other events by simply adding code in onClick() events but share event doesnt have onClick.
Code for tracking events example
Bundle param = new Bundle();
param.putString("call_data", "1");
mFirebaseAnalytics.logEvent("calls_made", param);
I've been strugling with the exact challenge, the quick answer is NO.
BUT, you can create your own share dialog in which you can detect on which app the user chose to share and then use analytics as desired:
Find the solution here
Another solution with ShareActionProvider

Windows Phone, Prism.StoreApps: How to avoid activation of a certain page after suspension or termination?

I do want to ensure that in case an app is navigated to a certain page, the app is on another (in my case the previous) page after it was suspended or terminated. In my case the page is for taking photos. I do not want the user to return to this page after the app was in the background since it has no context information. The context information is on the previuos page.
How could I achieve this with Prism.StoreApps?
Background: If an app was just suspended the state of the app remains after it was resumed, hence the last active page is active again. I have no real idea how to set another page active in this case. If an app was terminated Prim.StoreApps restores the navigation state and navigates to the last active view model (hence to the last active page). I do not know either how to alter the navigation state in this case so that another page is navigated to.
In the meantime I fond a working solution myself. Might not be the best and there might be better solutions, but it works.
For resuming the app I handle the Resuming event:
private void OnResuming(object sender, object o)
{
// Check if the current root frame contains the page we do not want to
// be activated after a resume
var rootFrame = Window.Current.Content as Frame;
if (rootFrame != null && rootFrame.CurrentSourcePageType == typeof (NotToBeResumedOnPage))
{
// In case the page we don't want to be activated after a resume would be activated:
// Go back to the previous page (or optionally to another page)
this.NavigationService.GoBack();
}
}
For the page restore after termination I firstly use a property in the App class:
public bool MustPreventNavigationToPageNotToBeResumedOn { get; set; }
public App()
{
this.InitializeComponent();
// We assume that the app was restored from termination and therefore we must prevent navigation
// to the page that should not be navigated to after suspension and termination.
// In OnLaunchApplicationAsync MustPreventNavigationToPageNotToBeResumedOn is set to false since
// OnLaunchApplicationAsync is not invoked when the app was restored from termination.
this.MustPreventNavigationToPageNotToBeResumedOn = true;
this.Resuming += this.OnResuming;
}
protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
{
// If the application is launched normally we do not prevent navigation to the
// page that should not be navigated to.
this.MustPreventNavigationToPageNotToBeResumedOn = false;
this.NavigationService.Navigate("Main", null);
return Task.FromResult<object>(null);
}
In OnNavigatedTo of the page I do not want to be activated on a resume I check this property and simply navigate back if it is true (and set the property to false to allow subsequent navigation):
public override void OnNavigatedTo(object navigationParameter, NavigationMode navigationMode,
Dictionary<string, object> viewModelState)
{
if (((App)Application.Current).MustPreventNavigationToPageNotToBeResumedOn)
{
// If must prevent navigation to this page (that should not be navigated to after
// suspension and termination) we reset the marker and just go back.
((App)Application.Current).MustPreventNavigationToPageNotToBeResumedOn = false;
this.navigationService.GoBack();
}
else
{
base.OnNavigatedTo(navigationParameter, navigationMode, viewModelState);
}
}

Synchronize UI thread (Pivot item from active to non active view)

I would like to synchronize the UI thread with changes in a view (pivot item 1 active view) which is active when the changes begin and switch to non active state (User interaction like changing the pivot item from the pivot item 1 to pivot item 2) before finishing the changes.
The changes never happens and the view is restored as the point when switching from active to non active state.
The UI stack composed from
ScrollViewer
Grid
List view
Grid
The grid controls contains progress bars to handle refresh
private async void scrollViewer_ViewChanged2(object sender, ScrollViewerViewChangedEventArgs e)
{
var listView = scrollViewer.GetDescendantsOfType<ListView>().FirstOrDefault();
var context = DataContext as IMainStreamViewModel;
if (e.IsIntermediate) return;
var dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
if (Math.Abs(scrollViewer.VerticalOffset) < 0.01 && _isPullRefresh)
{
// Adding item the Observable collection that is the
// the item source for the listview
// The method just add element using the core dispatcher
context.PullToRefreshInsertion_Top(dispatcher, listView);
}
else if (_scrollBar.Value >= _scrollBar.Maximum)
{
// same action but in bottom of the observable collection
// The method just add element using the core dispatcher
context.PullToRefreshAdd_Bottom(dispatcher, listView);
}
_isPullRefresh = false;
// Set the current element to be displayed in the list view
await dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() => listView.ScrollIntoView(listView.SelectedItem));
// Scroll to the the listview and hidding the progress control
await Task.FromResult(scrollViewer.ChangeView(null, 60, null));
}
Finally the element may be added but the scroll viewer dont reset his position and listview also
How to solve the sychronisation, i think the problem come from the IsActiveView state if the UI element is not in the ACTIVE VIEW it doesn't execute or skip the event.
UPDATE 1 :
The situation is as :
Pivot control that contain two pivot items :
Pivot item one contain :
***Scrollviewer
******Grid that contain a custom progress bar top refresh
******ListView containing the data that user can see and interact with
******Grid that contain a custom progress bar bottom refresh
Pivot item two contain some Richtextblock ...
When i'm doing the pull to refresh from the pivot item one and before the custom progress bar disappears do swipe to the next pivot item.
When i come back to the first pivot item, it was freezed at the state when i want to refresh and the top or bottom progress bar still visible.
I solved that by doing some trick and add some isVisible property in my view model and i fire the event whenever i'm in this pivot item i call updatelayout() and now it works.
I think the problem come from the fact when i'm doing swipe, the UI thread cancels all operations and start executing the operations attached to the active view this is why the update layout event for the first pivot item never fire.

how to identify JComboBox whether is disabled or enable inside its renderer class

I have a JComboBox contains following iems
{ "select" , "one" , "two" }
i need a separate background for first item so ,
i have made a condition in it's renderer like
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value != null){
Item item = (Item)value;
setText(item.getDescription());
}
if(index==-1){
setBackground(new Color(199,209,210));
setForeground(Color.BLACK);
}
return this;
}
}
so my question is if we disable a JComboBox, i have to made -1th index of component background color to someother color
like
if(index==-1){
setBackground(Color.RED);
}
please advice
The simplest way is always the best. Since you assigning renderer to a combobox, why don't you pass the combobox into it? Just create a custom renderer that holds the reference to a combobox then use the stored reference inside of your getListCellRendererComponent method
Maybe I'm missing something here, but if a JComboBox is disabled, then that means that it cannot popup its list of items. But if it is not showing its list of items, then that means it is not using the renderer for that list.
So, why do you need to get a reference to the combobox in the renderer?

ComboBox Bug in ActionScript

I was trying to filter a combo box dataprovider based on the values in the text boxes . When the contents of the dataprovider changes Combo box automatically calls change event method . Please find the sample code below.
Filter Utility Function:
private function filterLocations(event:FocusEvent):void {
locationsList1.filterFunction = filterUtility;
locationsList1.refresh();
}
public function filterUtility(item:Object):Boolean {
// pass back whether the location square foot is with in the range specified
if((item.SQUARE_FOOTAGE >= rangeText1.text) && (item.SQUARE_FOOTAGE rangeText2.text))
return item.SQUARE_FOOTAGE;
}
// THIS WOULD BE CALLED WHEN COMBO BOX SELECTION IS DONE
private function selectLocationsReports(event:ListEvent):void {
selectedItem =(event.currentTarget as ComboBox).selectedItem.LOCATION_ID;
}
When the DataProvider gets refreshed its automatically calls change method and was throwing Null Pointer function because its prematurely calling the above selectLocationsReports method and its throwing error.
Can somebody let me know how to stop the CHANGE event from propogation when the dataprovider is refreshed.
You can't stop a CHANGE event, just don't add an event listener unless you are prepared to get the event. I don't see where your event listener for Event.CHANGE is in the code above.
Just be sure that you don't addEventListener(Event.CHANGE, selectLocationsReports) until your ComboBox is ready for it.
The other thing to do (on top of Kekoa's response) is put an if statement in the event handler, and check to make sure the data is there before you begin working with it.
A handy syntax I use frequently for this is
if(dataprovidername) {
}