Files
JIMRI/java/test/jmri/jmrit/display/EditorFrameOperator.java
T
2026-06-17 14:00:51 +02:00

118 lines
3.8 KiB
Java

package jmri.jmrit.display;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ResourceBundle;
import javax.swing.JFrame;
import jmri.util.JmriJFrame;
import jmri.util.JUnitUtil;
import org.netbeans.jemmy.operators.*;
/**
* Jemmy Operator for Editor panels swing interfaces.
*
* @author Bob Jacobsen Copyright 2009, 2010
* @author Paul Bender Copyright 2017
*/
public class EditorFrameOperator extends JFrameOperator {
private static final String LABEL_EDITOR = ResourceBundle.getBundle("jmri.jmrit.display.DisplayBundle").
getString("LabelEditor");
public EditorFrameOperator(String title){
super(title);
}
public EditorFrameOperator(JFrame frame){
super(frame);
}
private static final String HIDE_THREAD_NAME = "EditorFrameOperator: Hide Dialog Close Thread";
private static final String DELETE_THREAD_NAME = "EditorFrameOperator: Delete Dialog Close Thread";
public void closeFrameWithConfirmations(){
// if OK to here, close window
// dispose of Hidden Switchboard Editor Frames
JFrame jf = JmriJFrame.getFrame(getTitle() + " " + LABEL_EDITOR);
if (jf != null) {
JUnitUtil.dispose(jf);
}
dismissClosingDialogs();
this.requestClose();
JUnitUtil.dispose( getWindow());
this.waitClosed();
}
public void deleteViaFileMenuWithConfirmations(){
JMenuOperator jmo = new JMenuOperator(this,Bundle.getMessage("MenuFile"));
dismissClosingDialogs();
jmo.pushMenu(Bundle.getMessage("MenuFile") +"/"+ Bundle.getMessage("DeletePanel"), "/");
}
private void dismissClosingDialogs(){
// the reminder dialog doesn't appear every time we close, so put
// pressing the button in that dialog into a thread by itself. If
// the dialog appears, it will get clicked, but it's not an error
// if it doesn't appear.
Thread t = new Thread( () -> {
triggerPanelHideOperators();
});
t.setName(HIDE_THREAD_NAME);
t.start();
Thread t2 = new Thread( () -> {
triggerDeleteYesOperators();
});
t2.setName(DELETE_THREAD_NAME);
t2.start();
}
@SuppressFBWarnings( value = {"DCN_NULLPOINTER_EXCEPTION"},
justification = "ok for JDialog not to be present")
private void triggerPanelHideOperators() {
try {
JDialogOperator d = new JDialogOperator(Bundle.getMessage("PanelHideTitle"));
// Find the button that deletes the panel
JButtonOperator bo = new JButtonOperator(d,Bundle.getMessage("ButtonHide"));
// Click button to delete panel and close window
bo.push();
} catch (NullPointerException e) {
// exceptions in this thread are not considered an error.
}
}
@SuppressFBWarnings( value = {"DCN_NULLPOINTER_EXCEPTION"},
justification = "ok for JDialog not to be present")
private void triggerDeleteYesOperators() {
try {
JDialogOperator d = new JDialogOperator(Bundle.getMessage("DeleteVerifyTitle"));
// Find the button that deletes the panel
JButtonOperator bo = new JButtonOperator(d,Bundle.getMessage("ButtonYesDelete"));
// Click button to delete panel and close window
bo.push();
} catch (NullPointerException e) {
// exceptions in this thread are not considered an error.
}
}
/**
* Call this at the end of tests that have invoked dismissClosingDialogs
* to clean up any threads that have been left hanging.
*/
public static void clearEditorFrameOperatorThreads() {
JUnitUtil.removeMatchingThreads(HIDE_THREAD_NAME);
JUnitUtil.removeMatchingThreads(DELETE_THREAD_NAME);
}
}