Hi Matt,
What I have done with Prompts (and Alerts) is attach a close
listener that gets invoked when one or the other button gets pressed
which closes the dialog, and then invoke the action in that listener.
That way you don't have to worry about skins. Something like this:
Alert alert = new Alert(MessageType.QUESTION,
Intl.getString("optionsDialog.warnReset"), null);
Alert.OptionSequence options = alert.getOptions();
options.remove(0, 1);
options.add(Intl.getString("saveFilePrompt.yes"));
options.add(Intl.getString("saveFilePrompt.no"));
alert.setSelectedOptionIndex(0);
alert.open(getWindow(), new DialogCloseListener() {
@Override
public void dialogClosed(Dialog dialog, boolean modal) {
Alert alert = (Alert)dialog;
int index = alert.getSelectedOptionIndex();
switch (index) {
case 0: // Yes
... do your work here ...
break;
case 1: // No
break;
}
}
});
Though this is an Alert, the same principle applies for Prompt as well.
HTH,
~Roger
On 5/18/12 10:55 AM, mattux wrote:
Ok so to add a bit to this:
I tried to override the TerraPromptSkin (TerraExtendedPromptSkin.java) class
so I could have some control on the buttonPressed event.
Here is an extract of the mock class:
private ButtonPressListener optionButtonPressListener = new
ButtonPressListener() {
public void buttonPressed(Button button) {
int optionIndex = optionButtonBoxPane.indexOf(button);
if (optionIndex>= 0) {
//Prompt prompt = (Prompt)getComponent();
//prompt.setSelectedOptionIndex(optionIndex);
//prompt.close(true);
}
}
};
@Override
public void install(Component component) {
ExtendedPrompt prompt = (ExtendedPrompt) component;
// We backup the options
ArrayList options = new ArrayList(prompt.getOptions());
// We reset the options so the subclass doesn't create the
buttons that we
want to override
prompt.getOptions().remove(0, options.getLength());
super.install(component);
BXMLSerializer bxmlSerializer = new BXMLSerializer();
try {
bxmlSerializer.readObject(TerraPromptSkin.class,
"terra_prompt_skin.bxml");
} catch(Exception exception) {
throw new RuntimeException(exception);
}
optionButtonBoxPane = (BoxPane)
bxmlSerializer.getNamespace().get("optionButtonBoxPane");
// We set the options back and create buttons with our custom
listeners
prompt.setOptions(options);
for (Object option : options) {
PushButton optionButton = new PushButton(option);
optionButton.setStyleName(TerraPromptSkin.class.getPackage().getName() +
"." + TerraTheme.COMMAND_BUTTON_STYLE);
for (ButtonPressListener listener :
optionButton.getButtonPressListeners()) {
optionButton.getButtonPressListeners().remove(listener);
}
optionButton.getButtonPressListeners().add(optionButtonPressListener);
optionButtonBoxPane.add(optionButton);
}
}
When putting a breakpoint in both the listener (at int optionIndex =
optionButtonBoxPane.indexOf(button);) and the install function (at
ExtendedPrompt prompt = (ExtendedPrompt) component;). The code definitely
goes through my install function. However, if I click on the prompt button,
it doesn't stop at my listener breakpoint and the prompt just closes.
Any ideas on what I'm doing wrong here would be much appreciated.
Regards,
Matt
--
View this message in context:
http://apache-pivot-users.399431.n3.nabble.com/Prompt-override-option-click-event-tp3999325p4001268.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.