// Path: src/main/java/org/robotframework/formslibrary/context/FormsContext.java
// public class FormsContext {
// 	private static String FORMS_TITLE = "Oracle Fusion Middleware Forms Services";
// 	private static ComponentWrapper context;
// 
// 	private static Boolean isFormServicesApp = null;
// 
// 	public static void setContext(ComponentWrapper operator) {
// 		context = operator;
// 		// TODO remove swing library context dependency if possible
// 		Context.setContext(context);
// 	}
// 
// 	/**
// 	 * Get current context. If no context is set, it will be defaulted to the
// 	 * first window.
// 	 */
// 	public static ComponentWrapper getContext() {
// 
// 		// set root context if no context exists
// 		if (context == null) {
// 			Logger.debug("No context found.");
// 			resetContext();
// 		}
// 
// 		if (isFormsServicesApp()) {
// 
// 			Component contextComponent = Context.getContext().getSource();
// 
// 			// verify that the current window context is still part of the
// 			// desktop
// 			if (!new FrameOperator().containsComponent(contextComponent) && !isActiveDialog(context)) {
// 				Logger.info("Context " + ComponentUtil.getFormattedComponentNames(contextComponent) + " is no longer part of desktop.");
// 				resetContext();
// 				return context;
// 			}
// 
// 			// verify the type of context
// 			// if (!ComponentType.JFRAME.matches(contextComponent) &&
// 			// !ComponentType.EXTENDED_FRAME.matches(contextComponent)
// 			// && !ComponentType.WINDOW.matches(contextComponent) &&
// 			// !ComponentType.BUFFERED_FRAME.matches(contextComponent)) {
// 			// throw new FormsLibraryException("Invalid context selected: " +
// 			// contextComponent.getClass().getSimpleName());
// 			// }
// 		}
// 
// 		return context;
// 	}
// 
// 	private static boolean isActiveDialog(ComponentWrapper context) {
// 		Component source = context.getSource();
// 		if (source instanceof Dialog) {
// 			Window[] windows = Window.getWindows();
// 			for (Window window : windows) {
// 				if (window == source) {
// 					return true;
// 				}
// 			}
// 		}
// 		return false;
// 	}
// 
// 	/**
// 	 * @return root context (the forms desktop window)
// 	 */
// 	public static ComponentWrapper getRootContext() {
// 		return new FrameOperator();
// 	}
// 
// 	/**
// 	 * @return root context (the forms desktop window)
// 	 */
// 	public static void listWindows() {
// 		Window[] windows = Window.getWindows();
// 		for (Window window : windows) {
// 			Logger.info(
// 					"Window  - " + window.getName() + " - " + window.getClass().getName() + " title=" + ObjectUtil.getFieldIfExists(window, "title"));
// 		}
// 	}
// 
// 	public static boolean isFormsServicesApp() {
// 		if (isFormServicesApp == null) {
// 			isFormServicesApp = checkFormServicesApp();
// 		}
// 		return isFormServicesApp;
// 	}
// 
// 	private static boolean checkFormServicesApp() {
// 		Window[] windows = Window.getWindows();
// 		for (Window window : windows) {
// 			Object title = ObjectUtil.getFieldIfExists(window, "title");
// 			if (title != null && title instanceof String) {
// 				if (((String) title).equals(FORMS_TITLE)) {
// 					return true;
// 				}
// 			}
// 		}
// 		return false;
// 	}
// 
// 	/**
// 	 * Change the context to the root context.
// 	 */
// 	public static void resetContext() {
// 		Logger.info("Changing context to main desktop window.");
// 		context = getRootContext();
// 		Context.setContext(context);
// 	}
// }


import java.awt.Component;
import java.awt.Dialog;
import org.netbeans.jemmy.ComponentChooser;
import org.netbeans.jemmy.operators.WindowOperator;
import org.robotframework.formslibrary.context.FormsContext;
import org.robotframework.swing.common.Identifier;
import org.robotframework.swing.operator.ComponentWrapper;

	}

	private static ComponentChooser createComponentChooser(final String title, boolean regex) {
		return new ComponentChooser() {

			@Override
			public String getDescription() {
				return "Dialog with name or title '" + title + "'";
			}

			@Override
			public boolean checkComponent(Component comp) {
				if (!(comp instanceof Dialog))
					return false;
				if (regex) {
					String val = comp == null ? "" : ((Dialog) comp).getTitle();
					return val.matches(title);
				} else {
					return eq(title, comp) || org.robotframework.swing.util.ObjectUtils.nullSafeEquals(((Dialog) comp).getTitle(), title);
				}

			}

			private boolean eq(final String title, Component comp) {
				return org.robotframework.swing.util.ObjectUtils.nullSafeEquals(comp.getName(), title);
			}
		};
	}

	public void setAsContext() {

// Path: src/main/java/org/robotframework/formslibrary/context/FormsContext.java
// public class FormsContext {
// 	private static String FORMS_TITLE = "Oracle Fusion Middleware Forms Services";
// 	private static ComponentWrapper context;
// 
// 	private static Boolean isFormServicesApp = null;
// 
// 	public static void setContext(ComponentWrapper operator) {
// 		context = operator;
// 		// TODO remove swing library context dependency if possible
// 		Context.setContext(context);
// 	}
// 
// 	/**
// 	 * Get current context. If no context is set, it will be defaulted to the
// 	 * first window.
// 	 */
// 	public static ComponentWrapper getContext() {
// 
// 		// set root context if no context exists
// 		if (context == null) {
// 			Logger.debug("No context found.");
// 			resetContext();
// 		}
// 
// 		if (isFormsServicesApp()) {
// 
// 			Component contextComponent = Context.getContext().getSource();
// 
// 			// verify that the current window context is still part of the
// 			// desktop
// 			if (!new FrameOperator().containsComponent(contextComponent) && !isActiveDialog(context)) {
// 				Logger.info("Context " + ComponentUtil.getFormattedComponentNames(contextComponent) + " is no longer part of desktop.");
// 				resetContext();
// 				return context;
// 			}
// 
// 			// verify the type of context
// 			// if (!ComponentType.JFRAME.matches(contextComponent) &&
// 			// !ComponentType.EXTENDED_FRAME.matches(contextComponent)
// 			// && !ComponentType.WINDOW.matches(contextComponent) &&
// 			// !ComponentType.BUFFERED_FRAME.matches(contextComponent)) {
// 			// throw new FormsLibraryException("Invalid context selected: " +
// 			// contextComponent.getClass().getSimpleName());
// 			// }
// 		}
// 
// 		return context;
// 	}
// 
// 	private static boolean isActiveDialog(ComponentWrapper context) {
// 		Component source = context.getSource();
// 		if (source instanceof Dialog) {
// 			Window[] windows = Window.getWindows();
// 			for (Window window : windows) {
// 				if (window == source) {
// 					return true;
// 				}
// 			}
// 		}
// 		return false;
// 	}
// 
// 	/**
// 	 * @return root context (the forms desktop window)
// 	 */
// 	public static ComponentWrapper getRootContext() {
// 		return new FrameOperator();
// 	}
// 
// 	/**
// 	 * @return root context (the forms desktop window)
// 	 */
// 	public static void listWindows() {
// 		Window[] windows = Window.getWindows();
// 		for (Window window : windows) {
// 			Logger.info(
// 					"Window  - " + window.getName() + " - " + window.getClass().getName() + " title=" + ObjectUtil.getFieldIfExists(window, "title"));
// 		}
// 	}
// 
// 	public static boolean isFormsServicesApp() {
// 		if (isFormServicesApp == null) {
// 			isFormServicesApp = checkFormServicesApp();
// 		}
// 		return isFormServicesApp;
// 	}
// 
// 	private static boolean checkFormServicesApp() {
// 		Window[] windows = Window.getWindows();
// 		for (Window window : windows) {
// 			Object title = ObjectUtil.getFieldIfExists(window, "title");
// 			if (title != null && title instanceof String) {
// 				if (((String) title).equals(FORMS_TITLE)) {
// 					return true;
// 				}
// 			}
// 		}
// 		return false;
// 	}
// 
// 	/**
// 	 * Change the context to the root context.
// 	 */
// 	public static void resetContext() {
// 		Logger.info("Changing context to main desktop window.");
// 		context = getRootContext();
// 		Context.setContext(context);
// 	}
// }


// Path: src/main/java/org/robotframework/formslibrary/operator/FormsDialogOperator.java
import java.awt.Component;
import java.awt.Dialog;
import org.netbeans.jemmy.ComponentChooser;
import org.netbeans.jemmy.operators.WindowOperator;
import org.robotframework.formslibrary.context.FormsContext;
import org.robotframework.swing.common.Identifier;
import org.robotframework.swing.operator.ComponentWrapper;

	}

	private static ComponentChooser createComponentChooser(final String title, boolean regex) {
		return new ComponentChooser() {

			@Override
			public String getDescription() {
				return "Dialog with name or title '" + title + "'";
			}

			@Override
			public boolean checkComponent(Component comp) {
				if (!(comp instanceof Dialog))
					return false;
				if (regex) {
					String val = comp == null ? "" : ((Dialog) comp).getTitle();
					return val.matches(title);
				} else {
					return eq(title, comp) || org.robotframework.swing.util.ObjectUtils.nullSafeEquals(((Dialog) comp).getTitle(), title);
				}

			}

			private boolean eq(final String title, Component comp) {
				return org.robotframework.swing.util.ObjectUtils.nullSafeEquals(comp.getName(), title);
			}
		};
	}

	public void setAsContext() {

		FormsContext.setContext(this);
