Adempiere 380 Webui doesn't show popup for process error message and on complete error messages

137 Views Asked by At

I am using adempiere 380 webui, i would like to show error message on any failure of adempiere process or onComplete of any document.

The code which i have written to show error popup working in desktop application. But in webui - jboss it printing in console of jboss.

I have accomplished this using AbstractADWindowPanel.java where i am checking process id or table then execute particular code in that and if error codition is true then i am displaying FDialog.ask("Print Message"); .

Is there any generic way to do this by which it can be used for all classes.

1

There are 1 best solutions below

0
Michael McKay On

Since processes can be fully automated and run on the server, your code needs to be aware of the GUI being used so that the correct dialog script can be called. There are three options, a server process (no dialog), swing (ADialog) or ZK (FDialog). Generally, its discouraged to use dialogs in this way. Certainly, you wouldn't want a server process to block waiting for user input. But, if you know what your doing and really need to...

In the most recent releases, the process code includes a flag that tests which of the states its in so it can display errors. An example of how this is used is with the Migration Script saves to XML format. In the process, the GUI info is used to open the correct file dialog in swing or, in ZK, pass the request to the browser.

Here is a snippet of how it works from ProcessInfo.java in the current release

/**
 * 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);
    }
}

The call to setInterfaceType() is made when the process is launched by the ProcessModalDialog in swing or the AbstractZKForm or ProcessPanel in zk.

For other processes, the value is set by the AbstractFormController which is used by both interfaces. If the interface type is not set the loadProcessInfo method will try to figure it out as follows:

    //  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);
    }

Finally, this can be used to control the dialogs within your process with a call similar to

    if (ProcessInfo.INTERFACE_TYPE_SWING.equals(this.getProcessInfo().getInterfaceType()))
    {
    ... Do something on a swing...
    }
    else ...