Cuba - Set localized caption for Button - cuba-platform

I am trying, to set different localized messages for a button (depending on a state) in cuba.
In the xml I have
<button caption="msg://contact"
invoke="onContactBtnClick"
width="100%"/>
Now I would like to change the caption in the onContactBtnClick-Method.
But when I set the caption to "msg://hello" I do not get the localized Button, but just msg://hello.
How do I have to set this?
Thx

If you want to obtain a localized message from a Window controller you have to use getMessage method with the message key.
button.setCaption(getMessage("hello"));
Also you can use Messages infrastructure interface:
#Inject
private Messages messages;
...
messages.getMessage(YourClass.class, "hello")
See documentation on Messages here: https://doc.cuba-platform.com/manual-6.1/messages.html

Related

Why is return from MessageBox.Show not "DialogResult.Cancel" when the close button is pressed?

I'm using the following code:
Dim Reply As DialogResult = MessageBox.Show("GOT IT!")
If Reply = DialogResult.OK Then '...`
When I click the Close button (red "X" in corner) the condition looking for DialogResult.OK still evaluates to true and when I check the Reply variable's value at runtime after clicking the close button it is 1 {OK}.
From the documentation on MessageBox Class it says:
Displays a message window, also known as a dialog box, which
presents a message to the user. It is a modal window, blocking other
actions in the application until the user closes it. A MessageBox can
contain text, buttons, and symbols that inform and instruct the user.
While I find the documentation on DialogBoxes a little convoluted and confusing, it appears to me (and i could be bery wrong) that the Close button should by default set the return to IDCancel which, I must assume is somehow parsed by the MessageBox class into DialogReturn.Cancel.
So why does MessageBox not show the return form the close button as DialogResult.Cancel??
This is all very confusing to me because it seems the MessageBox class is not consistent with other forms from within the same Systems.Windows.Forms namespace.
For instance, if we look at the documentation from the Form Class's .DialogResult method, it specifically tells us the return from the close button is DialogResult.Cancel:
When a form is displayed as a modal dialog box, clicking the Close
button (the button with an X in the top-right corner of the form)
causes the form to be hidden and the DialogResult property to be set
to DialogResult.Cancel.
As already stated in the comments above, you could get IDCancel result when clicking the Close Red Button, only if you add a MessageBoxButtons enum that include the Cancel option For example MessageBoxButtons.OKCancel and others.
The MessageBox.Show method is indeed a wrapper around the WinApi MessageBox function. You could see this wrapping looking at the reference sources
The behavior of MessageBox.Show is different from the link that you have pointed. That one is relative to the WinForm engine and of course the behavior of the WinForm Form class is totally managed by the library to handle the scenarios presumed for a WinForm class.
In the WinApi documentation you could find a subtle reference in the section about the Return value where they talks about the behavior when the cancel button is present. Then trial and error confirms this assumption.
You need to pass in MessageBoxButtons as an override that includes a cancel button so like MessageBoxButtons.OKCancel.
Dim message As String = "GOT IT!"
Dim caption As String = "Fancy Caption"
Dim Reply As DialogResult = MessageBox.Show(message, caption, MessageBoxButtons.OKCancel)
If Reply = DialogResult.OK Then '...`
If you dont want the caption than skip it but you'll still need a comma, like:
MessageBox.Show("GOT IT!",,MessageBoxButtons.OKCancel)
See here for full enumeration of options for MessageBoxButtons.

Eclipse plug-in: syntax recoloring

I have a costum editor for my own languages and I want to change from the property menu between them and recolor the syntax accordingly. I don't know if I have to use a reconciler or something else. The only way that the syntax is recolored, is by closing and opening the current file.
In your editor you need to listen for property change events from your preference store.
In your initializeEditor method call setPreferenceStore(preferenceStore)
Override the handlePreferenceStoreChanged method:
#Override
protected void handlePreferenceStoreChanged(PropertyChangeEvent event)
{
// TODO update settings affected by the event
// TODO If required invalidate the current presentation to update the colors
getSourceViewer().invalidateTextPresentation();
super.handlePreferenceStoreChanged(event);
}
You need to add code to look at the property change event to see if it is one that you need to handle. If the event changes something (such as changing the colors) that needs to text to be redrawn call getSourceViewer().invalidateTextPresentation().
To support all the normal text editor preferences you need to use a chained preference store in the setPreferenceStore call:
IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
IPreferenceStore yourPreferenceStore = get your preference store
IPreferenceStore combinedPreferenceStore = new ChainedPreferenceStore(new IPreferenceStore[] {yourPreferenceStore, generalTextStore});
setPreferenceStore(combinedPreferenceStore);

Safari Extension: window.open(...) doesn't work sometimes?

I have an injected stylesheet that calls a popup with window...open() on two occasions. One when the user clicks an HTML button, and two, when a user clicks on a context menu item. To listen for the context menu item, I need to add a listener on the injected script like so
safari.self.addEventListener("message", messageCallBack, false); // Message comes from global.html when context menu item is clicked
And the following callback
function messageCallBack(msgEvent) {
...
window.open(...)
...
}
For some reason, the popup works when the button calls window.open, but NOT when the message callback calls window.open. I'm assuming it maybe have something to do with the window object.
I suspect this is due to restrictions on window.open designed to combat pop-up ads. This means it will only work in response to a click event.
To get around this, I would recommend you open the new window from your global page using the safari.application API:
safari.application.openBrowserWindow();
safari.application.activeBrowserWindow.activeTab.url = '...';
You can also open new tabs with:
safari.application.activeBrowserWindow.openTab('foreground').url = '...';
To achieve this, you may need to send a message from your injected script to the global page.

Durandal 2.0 Dialog Repositioning

At the bottom of the durandal docs for dialogs / modals (http://durandaljs.com/documentation/Showing-Message-Boxes-And-Modals.html) there's some syntax for repositioning a dialog. The dialog I have gets gradually bigger as the user selects stuff, so every time a selection is made, I'd like to call reposition(). I tried following along with this:
vm.compositionComplete = function (child, parent, context) {
var addEditDialog = dialog.getDialog(context.model); // resolves
// whenever something is selected:
addEditDialog.context.reposition(vm); // no method 'reposition'
}
But I get an error - there is no function reposition. What am I doing wrong?
You can set up a custom dialog context that responds to a reposition message (using Durandal's app.trigger()). You would trigger the message upon some event in your dialog (such as, as you say, the user's selecting stuff).
Also in that custom dialog context, create a method call reposition. In the activate or attached handler of that custom dialog context, subscribe to the message you use to trigger a reposition.
I'm advocating a messaging approach because you may wish to isolate your "selection viewModel" in its own viewModel, and then compose it into your custom dialog context. With this approach, your selection viewModel and your custom dialog context would be loosely bound. That way, you could use your selection viewModel elsewhere in your code (and even have some other viewModel, instead of the custom dialog context, respond to the reposition message).

XPages: how to create a dialog box with callback to the caller

I have an XPage with 2 custom controls. The 1st custom control has a repeat control and the second is used just as a dialog box.
The user can delete a row from the repeat control by clicking on a delete link. then i use rowVar.getDocument.getNoteID and i delete the document.
What i want is to ask the user first: "are you sure you want to delete it?"
I used "window.confirm()" in CSJS but i dont like the default prompt box. So then i used dojo dialog box but i cant use rowVar of repeat control in it to get the documentId.
Currently i have code in the OK button of the dialog but i want to use OK/Cancel buttons only as a true/false and execute the code in the main custom control. Is there a way of passing the value of the button back to the caller?
I have done this in many ways. Basically, write the information you need to find the document to delete to a viewScope variable. Then create a stand alone event handler that is called from the OK or Cancel buttons of the dialog.
So the eventHandler looks like this post by Jeremey Hodge:
<xp:eventHandler
event="onfubar"
id="eventHandler1"
submit="false">
<xp:this.action><![CDATA[#{javascript:
// write the ssjs to save the doc base on viewScope parameters
}]]></xp:this.action>
</xp:eventHandler>
Then the dialog buttons look something like this (based on the Mastering XPages book and many other sources):
XSP.partialRefreshGet("#{id:eventHandler1}", {
params : {action :"OK" },
onComplete : function () {
// do something else if needed
},
onError : function() {
alert("no soup for you!");
}
});