Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,24 @@ public void representModel(final Parent model_parent, final DisplayModel model)
app_instance.trackCurrentModel(model);
super.representModel(model_parent, model);
}

@Override
public void closeWindow(final DisplayModel model) throws Exception
{
// Is called from ScriptUtil, i.e. scripts, from background thread
final Parent model_parent = Objects.requireNonNull(model.getUserData(Widget.USER_DATA_TOOLKIT_PARENT));
if (model_parent.getProperties().get(DisplayRuntimeInstance.MODEL_PARENT_DISPLAY_RUNTIME) == app_instance)
{
// Prepare-to-close, which might take time and must be called off the UI thread
final DisplayRuntimeInstance instance = (DisplayRuntimeInstance) app_instance.getRepresentation().getModelParent().getProperties().get(DisplayRuntimeInstance.MODEL_PARENT_DISPLAY_RUNTIME);
if (instance != null)
instance.getDockItem().prepareToClose();
else
logger.log(Level.SEVERE, "Missing DisplayRuntimeInstance to prepare closing", new Exception("Stack Trace"));
// 'close' on the UI thread
execute(() -> app_instance.close());
}
else
throw new Exception("Wrong model");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ public static void openDisplay(final Widget widget, final String file, final Str
ActionUtil.handleAction(widget, open);
}

/** Close a display
*
* @param widget Widget within the display to close
*/
public static void closeDisplay(final Widget widget)
{
try
{
final DisplayModel model = widget.getTopDisplayModel();
final ToolkitRepresentation<Object, Object> toolkit = ToolkitRepresentation.getToolkit(model);
toolkit.closeWindow(model);
}
catch (Throwable ex)
{
logger.log(Level.WARNING, "Cannot close display", ex);
}
}

// ====================
// public alert dialog utils

Expand Down