Java Code Examples for javafx.event.Event#isConsumed()

The following examples show how to use javafx.event.Event#isConsumed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DockItem.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Programmatically close this tab
 *
 *  <p>Will invoke on-close-request handler that can abort the action,
 *  otherwise invoke the on-closed handler and remove the tab
 *
 *  @return <code>true</code> if tab closed, <code>false</code> if it remained open
 */
public boolean close()
{
    EventHandler<Event> handler = getOnCloseRequest();
    if (handler != null)
    {
        final Event event = new Event(Tab.TAB_CLOSE_REQUEST_EVENT);
        handler.handle(event);
        if (event.isConsumed())
            return false;
    }

    handleClosed(null);

    getDockPane().getTabs().remove(this);

    return true;
}
 
Example 2
Source File: FxEventManager.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * The process of handling a new event.
 */
@FxThread
private void notifyImpl(@NotNull Event event) {

    var eventHandlers = getEventHandlers();

    for (EventType<? extends Event> eventType = event.getEventType(); eventType != null; eventType = eventType.getSuperType()) {

        var handlers = eventHandlers.get(eventType);
        if (handlers == null || handlers.isEmpty()) {
            continue;
        }

        handlers.forEach(event, (handler, toHandle) ->
                handler.handle(ClassUtils.unsafeCast(event)));
    }

    if (event instanceof ConsumableEvent && !event.isConsumed()) {
        var executorManager = ExecutorManager.getInstance();
        executorManager.addFxTask(() -> notifyImpl(event));
    }
}
 
Example 3
Source File: FileEditorTabPane.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 6 votes vote down vote up
boolean closeEditor(FileEditor fileEditor, boolean save) {
	if (fileEditor == null)
		return true;

	Tab tab = fileEditor.getTab();

	if (save) {
		Event event = new Event(tab,tab,Tab.TAB_CLOSE_REQUEST_EVENT);
		Event.fireEvent(tab, event);
		if (event.isConsumed())
			return false;
	}

	runWithoutSavingEditorsState(() -> {
		tabPane.getTabs().remove(tab);
		if (tab.getOnClosed() != null)
			Event.fireEvent(tab, new Event(Tab.CLOSED_EVENT));
	});

	saveEditorsState();

	return true;
}
 
Example 4
Source File: ApplicationController.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
public void closeAllTabs(Event event) {
    ObservableList<Tab> tabs = FXCollections.observableArrayList(tabPane.getTabs());

    tabs.stream()
            .filter(t -> t instanceof MyTab)
            .map(t -> (MyTab) t).sorted((mo1, mo2) -> {
        if (mo1.isNew() && !mo2.isNew()) {
            return -1;
        } else if (mo2.isNew() && !mo1.isNew()) {
            return 1;
        }
        return 0;
    }).forEach(myTab -> {

        if (event.isConsumed()) {
            return;
        }

        ButtonType close = myTab.close();
        if (close == ButtonType.CANCEL) {
            event.consume();
        }
    });

    if (!event.isConsumed()) {
        if (nonNull(detachStage)) {
            detachStage.close();
        }
    }
}