ComposantsComponents

ComposantsComponents › DiversMisc

tMsgBox

tMsgBox

DiversMisc

Affiche une boîte de dialogue Java (Swing) avec un message ou une question, et attend que l'utilisateur la ferme. Le bouton cliqué, ou le texte saisi, est rangé dans la variable globale RESULT. Il lui faut un écran : en mode headless, comme sur un serveur sans affichage, il arrête le job en erreur. À réserver aux jobs lancés à la main, sur le poste de l'utilisateur. Displays a Java (Swing) dialog box with a message or a question, and waits for the user to close it. The button clicked, or the text typed, is stored in the RESULT global variable. It needs a screen: in headless mode, as on a server without a display, it stops the job with an error. Keep it for jobs started by hand, on the user's computer.

EntréeInput

Aucune : il peut commencer un sous-job. Sinon un lien Main (une boîte par ligne) ou Iterate (une boîte par itération). None: it can start a subjob. Otherwise one Main link (one box per row) or Iterate link (one box per iteration).

SortieOutput

Facultative : un lien Main ; les lignes repartent telles quelles. La réponse est dans la variable globale. Optional: one Main link; the rows go on unchanged. The answer is in the global variable.

Déclencheurs en sortieOutput triggers

On Subjob Ok On Subjob Error On Component Ok On Component Error Run if

On Subjob : seulement quand il commence son sous-job. On Subjob: only when it starts its subjob.

UtilisationUsage

Demander une confirmationAsk for a confirmation

If tMsgBox_1 tFileDelete_1

Boutons : Oui et Non. Oui donne "0" ; condition du Run if : "0".equals((String) globalMap.get("tMsgBox_1_RESULT")). Avec Non, la suppression n'est pas lancée. Buttons: Yes and No. Yes gives "0"; Run if condition: "0".equals((String) globalMap.get("tMsgBox_1_RESULT")). With No, the deletion is not started.

Demander une valeurAsk for a value

OnSubjobOk tMsgBox_1 tJava_1

Boutons : Question. Le texte saisi arrive dans RESULT, à lire dans le tJava ; null si l'utilisateur annule. Buttons: Question. The typed text arrives in RESULT, to read in the tJava; null if the user cancels.

  1. Déposez le tMsgBox depuis la famille Divers de la palette. Drop the tMsgBox from the Misc family of the palette.
  2. Choisissez les Boutons et l'Icône, puis écrivez le Titre et le Message (ou la Question), en expressions Java entre guillemets. Choose the Buttons and the Icon, then write the Title and the Message (or the Question), as Java expressions in quotes.
  3. Lisez la réponse après le composant, dans la condition d'un Run if ou dans un tJava : voir les valeurs de RESULT. Read the answer after the component, in the condition of a Run if or in a tJava: see the RESULT values.

Paramètres simplesBasic settings

Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Le composant n'a pas de paramètres avancés propres. Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file. The component has no advanced settings of its own.

ParamètreSetting DéfautDefault VisibleShown Description
TitreTitleTITLE "Talaxie Open Studio" ToujoursAlways Texte de la barre de titre de la boîte, expression Java. Text of the title bar of the box, Java expression.
BoutonsButtonsBUTTONS OK ToujoursAlways Le genre de boîte : OK, Ok et Annuler, Abandonner, Réessayer et Ignorer, Oui, Non et Annuler, Oui et Non, Réessayer et Annuler, ou Question (un champ de saisie). Les boutons affichés et la valeur de RESULT sont dans le tableau plus bas. The kind of box: OK, Ok and Cancel, Abort, Retry, and Ignore, Yes, No and Cancel, Yes and No, Retry and Cancel, or Question (an input field). The buttons shown and the value of RESULT are in the table below.
Masquer la réponseMask AnswerANSWER_MASK NonNo Boutons : QuestionButtons: Question Le champ de saisie affiche * au lieu des caractères tapés, comme pour un mot de passe. RESULT reçoit quand même le texte en clair. The input field shows * instead of the typed characters, as for a password. RESULT still receives the text in clear.
IcôneIconICON Icône d'informationIcon Information ToujoursAlways Icône standard de Java à gauche du texte : Icône stop (ERROR_MESSAGE), Icône de question (QUESTION_MESSAGE), Icône d'exclamation (WARNING_MESSAGE) ou Icône d'information (INFORMATION_MESSAGE). Standard Java icon left of the text: Icon Stop (ERROR_MESSAGE), Icon Question (QUESTION_MESSAGE), Icon Exclamation (WARNING_MESSAGE) or Icon Information (INFORMATION_MESSAGE).
MessageMESSAGE "Hello world!" Boutons autres que QuestionButtons other than Question Texte de la boîte, expression Java de type String. Dans un flux, il peut reprendre les valeurs de la ligne : "Order " + row1.id. Un retour à la ligne tapé entre les guillemets est gardé : le code généré l'écrit \n. Text of the box, Java expression of type String. In a flow, it can use the values of the row: "Order " + row1.id. A line break typed between the quotes is kept: the generated code writes it \n.
QuestionQUESTION_LABEL "Question ?" Boutons : QuestionButtons: Question Texte affiché au-dessus du champ de saisie, expression Java. Contrairement au Message, un retour à la ligne entre les guillemets ne compile pas (voir Pièges). Text shown above the input field, Java expression. Unlike the Message, a line break between the quotes does not compile (see Pitfalls).

La boîte et sa réponseThe box and its answer

Aucune boîte n'a pu être ouverte pour cette page : ce tableau est lu dans les modèles du composant (tMsgBox_java.xml, tMsgBox_main.javajet) et dans le code qu'ils génèrent. La boîte est un javax.swing.JOptionPane ; l'appel ne rend la main qu'à sa fermeture. No box could be opened for this page: this table is read from the templates of the component (tMsgBox_java.xml, tMsgBox_main.javajet) and from the code they generate. The box is a javax.swing.JOptionPane; the call only returns when it is closed.

BoutonsButtons Dans la boîteIn the box RESULT
OK le bouton OK de JavaJava's OK button "1", toujours : il n'y a pas de choix"1", always: there is no choice
Ok et AnnulerOk and Cancel OK Cancel "0" "1"
Abandonner, Réessayer et IgnorerAbort, Retry, and Ignore Abort Retry Ignore "0" "1" "2"
Oui, Non et AnnulerYes, No and Cancel Yes No Cancel "0" "1" "2"
Oui et NonYes and No Yes No "0" "1"
Réessayer et AnnulerRetry and Cancel Retry Cancel "0" "1"
Question la Question, un champ de saisie, les boutons OK et Annuler de Javathe Question, an input field, Java's OK and Cancel buttons le texte saisi ; null si l'utilisateur annulethe typed text; null if the user cancels
Question, Masquer la réponseQuestion, Mask Answer la même boîte, saisie masquée par *the same box, input masked with * le texte saisi si l'utilisateur clique sur OK, null sinonthe typed text if the user clicks OK, null otherwise

Le numéro du boutonThe number of the button

Pour les boîtes à choix, RESULT est la position du bouton cliqué, à partir de 0, écrite en texte. Fermer la boîte sans cliquer donne "-1" (JOptionPane.CLOSED_OPTION). Le code généré pour Oui et Non : For the boxes with choices, RESULT is the position of the clicked button, from 0, written as text. Closing the box without clicking gives "-1" (JOptionPane.CLOSED_OPTION). The code generated for Yes and No:

resulttMsgBox_1 = String.valueOf(javax.swing.JOptionPane.showOptionDialog(null,
    messagetMsgBox_1, titletMsgBox_1, javax.swing.JOptionPane.YES_NO_OPTION,
    messageIcontMsgBox_1, null, new String[] { "Yes", "No" }, null));

Variable globaleGlobal variable

RESULT String
La réponse, selon le tableau ci-dessus. Disponible après le composant.The answer, as in the table above. Available after the component.
((String) globalMap.get("tMsgBox_1_RESULT"))
// Run if: Yes was clicked
"0".equals((String) globalMap.get("tMsgBox_1_RESULT"))

C'est un texte, pas un nombre : comparez avec "0".equals(…), qui donne aussi false quand la valeur est null. It is a text, not a number: compare with "0".equals(…), which also gives false when the value is null.

Exemples : sans écranExamples: without a screen

Sous Windows, Java lancé en mode headless (-Djava.awt.headless=true, passé par la variable d'environnement JAVA_TOOL_OPTIONS : d'où la ligne Picked up…, écrite par Java), comme sur un serveur sans affichage. Dans les mêmes conditions, un tJava qui affiche java.awt.GraphicsEnvironment.isHeadless() écrit Headless: true. Sorties copiées depuis une exécution du job ; le nom du job est remplacé par MyJob et les traces sont abrégées. On Windows, Java started in headless mode (-Djava.awt.headless=true, passed through the JAVA_TOOL_OPTIONS environment variable: hence the Picked up… line, written by Java), as on a server without a display. In the same conditions, a tJava that prints java.awt.GraphicsEnvironment.isHeadless() writes Headless: true. Outputs copied from a run of the job; the job name is replaced with MyJob and the traces are shortened.

Réglages par défautDefault settings

OnSubjobOk tMsgBox_1 tJava_1

Le tJava doit afficher RESULT : The tJava is meant to print RESULT:

System.out.println("Result: " + globalMap.get("tMsgBox_1_RESULT"));
Picked up JAVA_TOOL_OPTIONS: -Djava.awt.headless=true
Exception in component tMsgBox_1 (MyJob)
java.awt.HeadlessException
	at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:164)
	…
	at java.desktop/javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:648)
	…

Java refuse d'ouvrir une fenêtre : le job s'arrête avec le code 1 et le tJava ne s'exécute pas. Même exception avec Oui et Non, Abandonner, Réessayer et Ignorer, Question avec ou sans Masquer la réponse, et dans un flux, dès la première ligne. Java refuses to open a window: the job stops with code 1 and the tJava does not run. Same exception with Yes and No, Abort, Retry, and Ignore, Question with or without Mask Answer, and in a flow, from the first row.

Avec On Component ErrorWith On Component Error

OnSubjobOk OnComponentError tJava_1 tMsgBox_1 tJava_2

tJava_1 écrit Before the message box. Un tJava_3, relié au tMsgBox par On Subjob Ok, écrit After the message box. tJava_2 : tJava_1 writes Before the message box. A tJava_3, connected to the tMsgBox with On Subjob Ok, writes After the message box. tJava_2:

System.out.println("On Component Error, RESULT = " + globalMap.get("tMsgBox_1_RESULT"));
Picked up JAVA_TOOL_OPTIONS: -Djava.awt.headless=true
Before the message box
Exception in component tMsgBox_1 (MyJob)
java.awt.HeadlessException
	at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:164)
	…
On Component Error, RESULT = null

L'exception est écrite, puis tJava_2 s'exécute ; RESULT vaut null. On Subjob Ok n'est pas suivi. Le job se termine cette fois avec le code 0 : l'erreur est traitée par le lien. The exception is written, then tJava_2 runs; RESULT is null. On Subjob Ok is not followed. This time the job ends with code 0: the error is handled by the link.

PiègesPitfalls

Retour à la ligne dans la QuestionLine break in the Question

Boutons : Question ; Question écrite sur deux lignes, "Line 1 puis Line 2". Message de compilation abrégé : Buttons: Question; Question written on two lines, "Line 1 then Line 2". Shortened compilation message:

MyJob.java:389: error: unclosed string literal
		resulttMsgBox_1 = javax.swing.JOptionPane.showInputDialog(null, "Line 1
		                                                                ^
MyJob.java:390: error: not a statement
Line 2" , titletMsgBox_1, messageIcontMsgBox_1);
^
…

La Question est recopiée telle quelle dans le code, retour à la ligne compris. Écrivez "Line 1\nLine 2" sur une seule ligne. Le Message, lui, accepte le retour à la ligne. The Question is copied as is into the code, line break included. Write "Line 1\nLine 2" on a single line. The Message does accept the line break.

Le job attend le clicThe job waits for the click

Tant que la boîte est ouverte, le job est arrêté, sans limite de temps. Un job planifié qui affiche une boîte sur un poste où personne ne la voit reste bloqué. As long as the box is open, the job is stopped, with no time limit. A scheduled job that shows a box on a computer where nobody sees it stays blocked.

Des boutons en anglaisButtons in English

Les boutons des boîtes à choix sont écrits en anglais dans le modèle ("Yes", "No", "Abort"…), quelle que soit la langue du Studio : la liste dit Oui et Non, la boîte affiche Yes et No. The buttons of the boxes with choices are written in English in the template ("Yes", "No", "Abort"…), whatever the language of the Studio: the list says Oui et Non in French, the box shows Yes and No.

Réponse masquée, variable en clairMasked answer, variable in clear

Masquer la réponse ne cache que l'écran : le texte est rangé en clair dans RESULT, lisible par tout le job. Ne l'écrivez pas dans un journal. Mask Answer only hides the screen: the text is stored in clear in RESULT, readable by the whole job. Do not write it to a log.

Une boîte par ligneOne box per row

Au milieu d'un flux, le composant ouvre une boîte pour chaque ligne, et RESULT ne garde que la dernière réponse. Pour un résumé, placez-le après le flux et construisez le message avec les variables du sous-job (NB_LINE…). In the middle of a flow, the component opens a box for each row, and RESULT only keeps the last answer. For a summary, place it after the flow and build the message from the variables of the subjob (NB_LINE…).

ConseilsTips

Pas de boîte sans écranNo box without a screen

Pour qu'un même job tourne aussi sur un serveur, placez un tJava avant le tMsgBox et reliez-les par un Run if de condition !java.awt.GraphicsEnvironment.isHeadless() : en mode headless, la boîte n'est pas demandée et l'exception n'a pas lieu. For the same job to also run on a server, place a tJava before the tMsgBox and connect them with a Run if whose condition is !java.awt.GraphicsEnvironment.isHeadless(): in headless mode, the box is not asked for and the exception does not happen.

Pour un job sans surveillanceFor an unattended job

Écrivez le message dans la console ou le journal plutôt que dans une boîte : tLogRow, tWarn, ou un tJava. Une valeur à demander peut venir d'une variable de contexte, passée au lancement du job. Write the message to the console or the log rather than to a box: tLogRow, tWarn, or a tJava. A value to ask for can come from a context variable, passed when the job is started.

Voir aussiSee also