Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Undo/Redo button, ignore scroll down/up events
Undo/Redo button, ignore scroll down/up events [message #1793872] Fri, 17 August 2018 15:45 Go to next message
João Pedro is currently offline João PedroFriend
Messages: 28
Registered: December 2014
Junior Member
When I run the MinMap example, I notice that the Undo/Redo buttons get active when I scroll down/up. How can this be changed?

The relevant piece of code is:


	private Node createButtonBar() {
		Button undoButton = new Button("Undo");
		undoButton.setDisable(true);
		undoButton.setOnAction((e) -> {
			try {
				domain.getOperationHistory().undo(domain.getUndoContext(), null, null);
			} catch (ExecutionException e1) {
				e1.printStackTrace();
			}
		});

		Button redoButton = new Button("Redo");
		redoButton.setDisable(true);
		redoButton.setOnAction((e) -> {
			try {
				domain.getOperationHistory().redo(domain.getUndoContext(), null, null);
			} catch (ExecutionException e1) {
				e1.printStackTrace();
			}
		});

		// add listener to the operation history of our domain
		// to enable/disable undo/redo buttons as needed
		domain.getOperationHistory().addOperationHistoryListener((e) -> {
			IUndoContext ctx = domain.getUndoContext();
			undoButton.setDisable(!e.getHistory().canUndo(ctx));
			redoButton.setDisable(!e.getHistory().canRedo(ctx));
		});

		return new HBox(10, undoButton, redoButton);
	}



I was looking at OperationHistoryEvent.getEventType() method but both all events are returning "5".

[Updated on: Fri, 17 August 2018 15:56]

Report message to a moderator

Re: Undo/Redo button, ignore scroll down/up events [message #1793874 is a reply to message #1793872] Fri, 17 August 2018 16:32 Go to previous messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 28
Registered: December 2014
Junior Member
Update:

I managed to distinguish the events, even though I would prefer a less hardcoded way (string comparison is not very robust)

domain.getOperationHistory().addOperationHistoryListener((e) -> {
        if(!e.getOperation().getLabel().contains("Change Viewport")) {
				IUndoContext ctx = domain.getUndoContext();
				undoButton.setDisable(!e.getHistory().canUndo(ctx));
				redoButton.setDisable(!e.getHistory().canRedo(ctx));
			}
			else {
				//How can I remove operation from history
			}
}


However, the scroll events still populate the domain.OperationHistory. How can I avoid this?
Re: Undo/Redo button, ignore scroll down/up events [message #1793935 is a reply to message #1793874] Mon, 20 August 2018 17:51 Go to previous messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 28
Registered: December 2014
Junior Member
Furthermore, I would like to know how can I delete/add nodes, connections, etc when pressing Undo/Redo. From what I understand the Undo/Redo only works graphically, but the Connections and Nodes are still in the model. I need to be able to delete them when Undoing and adding them when Redoing.

Thank you

[Updated on: Tue, 21 August 2018 10:10]

Report message to a moderator

Re: Undo/Redo button, ignore scroll down/up events [message #1793965 is a reply to message #1793874] Tue, 21 August 2018 10:01 Go to previous message
João Pedro is currently offline João PedroFriend
Messages: 28
Registered: December 2014
Junior Member
João Pedro wrote on Fri, 17 August 2018 17:32
Update:

I managed to distinguish the events, even though I would prefer a less hardcoded way (string comparison is not very robust)

domain.getOperationHistory().addOperationHistoryListener((e) -> {
        if(!e.getOperation().getLabel().contains("Change Viewport")) {
				IUndoContext ctx = domain.getUndoContext();
				undoButton.setDisable(!e.getHistory().canUndo(ctx));
				redoButton.setDisable(!e.getHistory().canRedo(ctx));
			}
			else {
				//How can I remove operation from history
			}
}


However, the scroll events still populate the domain.OperationHistory. How can I avoid this?


I think I managed to solve this:

domain.getOperationHistory().addOperationHistoryListener((e) -> {
			
			// If the user is just scrolling the window, Undo/redo buttons shall 
			// be kept greyed out
			if(!e.getOperation().getLabel().contains("Change Viewport")) {
				IUndoContext ctx = domain.getUndoContext();
				undoButton.setDisable(!e.getHistory().canUndo(ctx));
				redoButton.setDisable(!e.getHistory().canRedo(ctx));
			}
			else {
				IUndoableOperation operation = e.getOperation();
				IUndoContext[] contexts = operation.getContexts();
				for (int j = 0; j < contexts.length; j++) {
					if (contexts[j].matches(domain.getUndoContext())) {
						operation.removeContext(contexts[j]);
					}
				}
				operation.dispose();
			}
			
		});
Previous Topic:[GEF5] Using GEF5 without JavaFX
Next Topic:Add LayoutAlgorithm in MinMap example
Goto Forum:
  


Current Time: Tue Sep 25 01:10:47 GMT 2018

Powered by FUDForum. Page generated in 0.05420 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top