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: 52
Registered: December 2014
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: 52
Registered: December 2014
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: 52
Registered: December 2014
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 messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
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();
			}
			
		});
Re: Undo/Redo button, ignore scroll down/up events [message #1803076 is a reply to message #1793965] Thu, 21 February 2019 21:02 Go to previous message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Hi Joao,

glad you figured something out!

Another attempt could be to prevent execution of these operations on the domain, so that they will not be added on to the operation history. In order to do that, you would need to exchange the corresponding handlers.

Regarding content changes, you can take a look at CreationPolicy and DeletionPolicy. They are both used in the Logo example.

Best regards and happy coding :-)
Matthias
Previous Topic:GEF application is slow with Java 11
Next Topic:Question for Documentation
Goto Forum:
  


Current Time: Thu Apr 25 15:57:19 GMT 2024

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

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

Back to the top