由于流程可以完全自动化并在服务器上运行,因此您的代码需要了解正在使用的 GUI,以便可以调用正确的对话脚本。有三个选项,一个服务器进程(无对话框)、swing(ADialog)或ZK(FDialog)。通常,不鼓励以这种方式使用对话框。当然,您不希望服务器进程阻塞等待用户输入。但是,如果您知道自己在做什么并且真正需要...
在最新版本中,流程代码包含一个标志,用于测试其处于哪些状态,以便显示错误。如何使用它的一个例子是迁移脚本保存为 XML 格式。在此过程中,GUI 信息用于在 swing 中打开正确的文件对话框,或者在 ZK 中,将请求传递给浏览器。
这是当前版本中 ProcessInfo.java 的工作原理片段
/**
* Get the interface type this process is being run from. The interface type
* can be used by the process to perform UI type actions from within the process
* or in the {@link #postProcess(boolean)}
* @return The InterfaceType which will be one of
* <li> {@link #INTERFACE_TYPE_NOT_SET}
* <li> {@link #INTERFACE_TYPE_SWING} or
* <li> {@link #INTERFACE_TYPE_ZK}
*/
public String getInterfaceType() {
if (interfaceType == null || interfaceType.isEmpty())
interfaceType = INTERFACE_TYPE_NOT_SET;
return interfaceType;
}
/**
* Sets the Interface Type
* @param uiType which must equal one of the following:
* <li> {@link #INTERFACE_TYPE_NOT_SET} (default)
* <li> {@link #INTERFACE_TYPE_SWING} or
* <li> {@link #INTERFACE_TYPE_ZK}
* The interface should be set by UI dialogs that start the process.
* @throws IllegalArgumentException if the interfaceType is not recognized.
*/
public void setInterfaceType(String uiType) {
// Limit value to known types
if (uiType.equals(INTERFACE_TYPE_NOT_SET)
||uiType.equals(INTERFACE_TYPE_ZK)
||uiType.equals(INTERFACE_TYPE_SWING) )
{
this.interfaceType = uiType;
}
else
{
throw new IllegalArgumentException("Unknown interface type " + uiType);
}
}
setInterfaceType()
当进程由ProcessModalDialog
in swing 或AbstractZKForm
or ProcessPanel
in zk启动时调用 to 。
对于其他进程,该值AbstractFormController
由两个接口使用的 设置。如果未设置接口类型,该loadProcessInfo
方法将尝试如下计算:
// Determine the interface type being used. Its set explicitly in the ProcessInfo data
// but we will fallback to testing the stack trace in case it wasn't. Note that the
// stack trace test may not be accurate as it depends on the calling class names.
// TODO Also note that we are only testing for ZK or Swing. If another UI is added, we'll
// have to fix this logic.
if (processInfo == null || processInfo.getInterfaceType().equals(ProcessInfo.INTERFACE_TYPE_NOT_SET))
{
// Need to know which interface is being used as the events may be different and the proper
// listeners have to be activated. Test the calling stack trace for "webui".
// If not found, assume the SWING interface
isSwing = true;
StackTraceElement[] stElements = Thread.currentThread().getStackTrace();
for (int i=1; i<stElements.length; i++) {
StackTraceElement ste = stElements[i];
if (ste.getClassName().contains("webui")
|| ste.getClassName().contains("zk.ui")) {
isSwing = false;
break;
}
}
log.warning("Process Info is null or interface type is not set. Testing isSwing = " + isSwing);
}
else
{
isSwing = processInfo.getInterfaceType().equals(ProcessInfo.INTERFACE_TYPE_SWING);
}
最后,这可用于控制进程中的对话框,调用类似于
if (ProcessInfo.INTERFACE_TYPE_SWING.equals(this.getProcessInfo().getInterfaceType()))
{
... Do something on a swing...
}
else ...