What are the best practices for using objectIsForced with controls bound to a shared user defaults controller? - interface-builder

In the Preferences window of a macOS app on which I'm working, I have a number of controls that are directly bound via Interface Builder to the shared user defaults controller.
This works well, however since this is an enterprise app, I'd like to add support for managed settings, or in other words I'd like to have the controls for settings which are managed disable.
In the documentation for UserDefaults, Apple recommends using the function objectIsForced to learn if a setting is managed and to manually disable its controls, but this does not fit the binding model since AFAIK binding a control's enabled state to a selector that takes an argument is not possible.
If I understand correctly, to disable those controls I'd either have to set up outlets for each of them and then manually set their enabled state on awakeFromNib, or, I'd have to create computed properties for each and bind to those.
I did test to see if the UserDefaults object would do the disabling automatically by taking advantage of the Conditionally Sets Enabled binding option but it appears that this is not the case.
Is there a way to achieve this using Cocoa bindings alone? If not, what are the best practices to disable controls bound to user defaults?

Related

How to apply access control to parts of my Joomla 2.5 component's preferences?

I am creating a MVC component in Joomla 2.5. I am using access control to restrict access to different backend views of this component. Each of these views have some option fields in the component's preferences (config.xml).
I know how to apply access control to restrict access to the preferences as a whole, but I am wondering if there is a possibility to apply different access control restrictions to some of the fields within the preferences.
If you're talking about the Preferences you add to your main view using:
JToolBarHelper::preferences('com_mycomponent', $height, $width, $alt, $path, $onClose);
Then no, there is nothing in the checks the access of a given field in com_config's default view (/administrator/components/com_config/views/component/tmpl/default.php)
One possible solution would be to only present the real Preferences button to Super Users or those with equivalent permissions and then create a customised version for all other users that only presents the fields from the form they have permission to use.
Of course this means you'll have to manage those additional meta-permissions yourself.

Save state and MVVM

How to save state (eg. by PhoneApplicationService) and don't break mvvm principles.
When application goes to "deactivated" state I want to preserve model object (eg. bounded to a form) and restore it when application will be resume.
Where I should place a logic of "save state mechanism". In view or viewmodel?
Disadvantage place in viewmodel:
I want to use my mvvm in other platform (Win8) and I want to make my mvvm to be maximum independent from platform.
I been thinking about one event in viewmodel where view can be handled moment of model object creaction and save it in platform specific storage.
or
make service to save state based on interface and register it in ViewModelLocator.
I recently wrote an article about exactly this, and I created a NuGet package for this:
Article: http://www.kenneth-truyers.net/2013/03/13/tombstoning-made-easy-in-windows-phone-mvvm/
NuGet: Install-Package WindowsPhone.MVVM.Tombstone
You can read the article to see how to use the package.
The package basically allows you to apply an attribute to save all the properties upon tombstoning and restores them automatically. You just need to handle two page events.

Event aggregator for conditional actions

I am involved in the development of a WPF Prism application which uses the event aggregator to send global type messages which are then picked up by the shell. For example, a viewmodel might want a toast message displayed but doesn't really care how it is displayed. In this instance the shell would be setup to process those events and act on them application wide.
The question I have is how do you do it if a particular view wants to display the toast messages differently. I like the global approach because it is very simple, but how to customize it for special cases?
I think this really depends upon how your application is setup and what standards/patterns you are using. In MVVM I see two approaches.
View-First
If your View-Model is injected into your view, then send the messages to your view, and let the View decide what to do with it. If it wants to display them itself, it can do that. If it wants to send them to your shell, it can do that through the event aggregator or injecting a Toast service interface. That keeps your View in control of the visual.
View-Model-First
If your View is injected into your View-Model, then your View Model should be asking for a different View, which should be bound to its own View Model. If it wants to send messages to another View-Model, it can do that through the event aggregator or injecting a Toast View-Model/service interface. That keeps your View-Model in control of the navigation between Views.
I prefer the View-First approach because it keeps your View in control of the visualization of your model. But I'm very interested in how other MVVM developers tackle this. This seems very closely aligned with the question of how to present dialogs in the MVVM View-First approach.
Using Eventaggregator for this purpose is not the right way I think, because the events are broadcasted to the entire application.
One possible way to handle the scenario is your viewmodels can get an IMessenger interface injected in the constructor. There is an application implementation of IMessenger(which is injected by default) and you can have customised implementations of IMessenger according to your needs. Your viewmodel just calls an interface function(say DisplayMessage()), but according to the Messenger injected to it, the behaviour is different.

How to use multiple themes at the same time

I'm looking for a way to use multiple themes in one XPages application, each theme active in a different section of the application. For instance to support an single .nsf application with both a public facing website (custom theme) and a CMS with a OneUI theme.
You can set which theme is used through the whole application on the XPage Properties tab in Application Properties. It's also possible to change the theme for a user's session with this code:
context.setSessionProperty("xsp.theme", <theme_id>)
But both options set the theme for all pages in the current .nsf, and I'm looking for a way to specify theme X for one part of the application and theme Y for a second part.
Is this possible?
On any page that should use an alternate theme, use the following syntax to apply the property directly to the view root:
<xp:view>
<xp:this.properties>
<xp:parameter name="xsp.theme" value="alternateThemeName" />
</xp:this.properties>
</xp:view>
I tried all of the above, but none of them worked for me. But I found a solution:
Paste this into the view's beforeRenderResponse event:
context.setSessionProperty("xsp.theme", "yourAlternateThemeName")
There is one issue: once you have used this way you have to use it always and on every page as this sets a session property which is stored as long as you are logged in.
Just talked with colleague Tony Mcguckin.
You can change the theme per page. Under all properties of the XPage select data-properties and create a new property with name "xsp.theme" and value "yourThemeName".
While I like the idea of having page-specific themes, based on the specific use case you're describing, the "right" way to do this is to have two separate XPage applications bound to the same back end data store. Not only does this make it simple to specify a different theme for each, it also simplifies the ACL (assuming you'll have different people accessing the public site vs. the CMS), makes it easier to tune performance by having different settings per application, and even without having application-specific settings, should improve performance slightly just because of Java class loader behavior: each NSF acts as a distinct ClassLoader, and each XPage or Custom Control in your NSF results in the storage of a separate class file. So, in theory, if the features of your public site require you to create 5 XPages and the CMS features span 10 XPages, simply splitting these into two separate apps makes it easier for the class loader to retrieve the class for any page a user loads, because it doesn't have to ignore the classes it will never need for that user just to find the one class it does need at the time. So I'm still tempted to find a way to get page-specific themes working just for the "cool" factor of it, but for this specific purpose, I'd recommend using two different applications entirely, with a different theme assigned to each.
I dont know that much about themes but cant you check in your theme (with some ssjs) at which viewroot ( by id? ) you are and according to that include the correct styles , css and other resources?

Intellij Debugging ? Customize data views for each collections

Is there a way to customize data views separately for each collection while debugging? The problem I have is, I can only do this universally ( and it affects every collection in scope.)
IntelliJ IDEA has debug renderers per type, if you can suggest a criterion how a renderer can be mapped to the particular collection, please submit a request and we'll be happy to implement it.
As a workaround you can have multiple different renderers defined and switch between them via View As context menu in the debugger panel.

Resources