Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » job creates commands, until app freeze, why?(freez on DefaultOperationHistory)
job creates commands, until app freeze, why? [message #534151] Tue, 18 May 2010 08:47 Go to next message
AlexejS Mising name is currently offline AlexejS Mising nameFriend
Messages: 25
Registered: May 2010
Junior Member
I implement a simple Petrieditor.
After everything have worked fine, I decided to animate a Token Game. For this case, i created a Button, which Handler start a Command - Impletation. This Command has a Job - Implementation which call .getCommandStack to add new Commands, so I can see the Animation on my Editor.

Problem: after a few tasks, or new Commands my application freeze. I think the Problem has something todo with DefaultOperationHistory. After debugging, ithink it freeze on this position: in DefaultOperationHistory


private void notifyListeners(final OperationHistoryEvent event) {
		if (event.getOperation() instanceof IAdvancedUndoableOperation) {





import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.common.command.AbstractCommand;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.notation.View;

import petrinets.impl.PetrinetImpl;
import petrinets.impl.PlaceImpl;
import petrinets.impl.TransitionImpl;

public class TokenGameCommand extends Command {

	private IGraphicalEditPart part;
    private boolean switching = true;
    private TransitionImpl activeTransition;
    private PetrinetImpl myPetrinetImpl;
	public TokenGameCommand() {super("Run App");}
	public boolean canExecute() { return true;}
	public void redo() {redoModel();}
	public void execute() { redo();}
	public void undo() {undoModel();}
	protected void undoModel() {
		System.out.println("Here I am");
	}
	protected void redoModel() {
	  if (part != null) {
	     new Job("token game") {
	       public IStatus run(IProgressMonitor monitor) {
	          try {
	              monitor.beginTask("Animating", 100);
	              while (!monitor.isCanceled()) {
		        	  TransactionalEditingDomain domain = part.getEditingDomain();
		        	  int i = (int)(Math.random()*10);
		               part.getEditingDomain().getCommandStack().execute(
		               new RecordingCommand(domain, "Start TokenGame" +i){
		                    public void doExecute() {
		                    	if (switching){		
		                    		myPetrinetImpl = (PetrinetImpl) ((View) part.getModel()).getElement();
		                    		myPetrinetImpl.setAllTransitionNoActive();
		                    		activeTransition = myPetrinetImpl.getRandomActiveTransition();
			            		    activeTransition.setActive(true);
			            		    myPetrinetImpl.operateTransition(activeTransition); 
			            		    System.out.println(activeTransition.getName());
			            		    System.out.println("Hallo1");
		                    	}
		                    	else{
		                    		activeTransition.setActive(false);
		                    		System.out.println("Hallo");
		                    		switching = true;
		                    	}
		                    }
		                    protected boolean prepare() {return true;}
		               });
		               Thread.sleep(1000);
	              	}
	               monitor.done();
	          } catch (Exception e) {}
	          return new Status(IStatus.OK,
	                  "tokengame",
	                  "ended", null);
	       }
	     }.schedule();
	  }
	}

	public Command setCurrentPart(IGraphicalEditPart part) {
		  this.part = part;
		  return null;
		}
}

Re: job creates commands, until app freeze, why? [message #534626 is a reply to message #534151] Wed, 19 May 2010 16:41 Go to previous messageGo to next message
AlexejS Mising name is currently offline AlexejS Mising nameFriend
Messages: 25
Registered: May 2010
Junior Member
nobody an idea?

Other question: Is it possible to use a Command Implementation, which don't use Redo / Undo function

[Updated on: Wed, 19 May 2010 16:42]

Report message to a moderator

Re: job creates commands, until app freeze, why? [message #535640 is a reply to message #534151] Tue, 25 May 2010 05:26 Go to previous messageGo to next message
Jevon  is currently offline Jevon Friend
Messages: 164
Registered: July 2009
Senior Member
Hi AlexejS,

What exactly appears to be freezing - the entire of Eclipse, or the
animation? Have you tried starting your Eclipse instance through Debug
mode and halting execution when Eclipse appears to freeze, in order to
track down what it is doing?

Hope this helps
Jevon

AlexejS wrote:
> I implement a simple Petrieditor.
> After everything have worked fine, I decided to animate a Token Game.
> For this case, i created a Button, which Handler start a Command -
> Impletation. This Command has a Job - Implementation which call
> .getCommandStack to add new Commands, so I can see the Animation on my
> Editor.
> Problem: after a few tasks, or new Commands my application freeze. I
> think the Problem has something todo with DefaultOperationHistory. After
> debugging, ithink it freeze on this position: in DefaultOperationHistory
>
>
>
> private void notifyListeners(final OperationHistoryEvent event) {
> if (event.getOperation() instanceof IAdvancedUndoableOperation) {
>
>
>
>
>
>
> import org.eclipse.core.runtime.IProgressMonitor;
> import org.eclipse.core.runtime.IStatus;
> import org.eclipse.core.runtime.OperationCanceledException;
> import org.eclipse.core.runtime.Status;
> import org.eclipse.core.runtime.jobs.Job;
> import org.eclipse.emf.common.command.AbstractCommand;
> import org.eclipse.emf.transaction.RecordingCommand;
> import org.eclipse.emf.transaction.TransactionalEditingDomain;
> import org.eclipse.gef.commands.Command;
> import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art;
> import org.eclipse.gmf.runtime.notation.View;
>
> import petrinets.impl.PetrinetImpl;
> import petrinets.impl.PlaceImpl;
> import petrinets.impl.TransitionImpl;
>
> public class TokenGameCommand extends Command {
>
> private IGraphicalEditPart part;
> private boolean switching = true;
> private TransitionImpl activeTransition;
> private PetrinetImpl myPetrinetImpl;
> public TokenGameCommand() {super("Run App");}
> public boolean canExecute() { return true;}
> public void redo() {redoModel();}
> public void execute() { redo();}
> public void undo() {undoModel();}
> protected void undoModel() {
> System.out.println("Here I am");
> }
> protected void redoModel() {
> if (part != null) {
> new Job("token game") {
> public IStatus run(IProgressMonitor monitor) {
> try {
> monitor.beginTask("Animating", 100);
> while (!monitor.isCanceled()) {
> TransactionalEditingDomain domain =
> part.getEditingDomain();
> int i = (int)(Math.random()*10);
> part.getEditingDomain().getCommandStack().execute(
> new RecordingCommand(domain, "Start TokenGame" +i){
> public void doExecute() {
> if (switching){
> myPetrinetImpl = (PetrinetImpl)
> ((View) part.getModel()).getElement();
>
> myPetrinetImpl.setAllTransitionNoActive();
> activeTransition =
> myPetrinetImpl.getRandomActiveTransition();
> activeTransition.setActive(true);
>
> myPetrinetImpl.operateTransition(activeTransition);
>
> System.out.println(activeTransition.getName());
> System.out.println("Hallo1");
> }
> else{
> activeTransition.setActive(false);
> System.out.println("Hallo");
> switching = true;
> }
> }
> protected boolean prepare() {return true;}
> });
> Thread.sleep(1000);
> }
> monitor.done();
> } catch (Exception e) {}
> return new Status(IStatus.OK,
> "tokengame",
> "ended", null);
> }
> }.schedule();
> }
> }
>
> public Command setCurrentPart(IGraphicalEditPart part) {
> this.part = part;
> return null;
> }
> }
>
>
Re: job creates commands, until app freeze, why? [message #535658 is a reply to message #534151] Tue, 25 May 2010 07:57 Go to previous message
AlexejS Mising name is currently offline AlexejS Mising nameFriend
Messages: 25
Registered: May 2010
Junior Member
Two days ago I found out a work around for my case.
Instead of RecordingCommand, I used AbstractCommand with an emty undo() implemenatation, which i call after every AbstractCommand creation. So in fact the problem which appears by using RecordingCommand comes from the class DefaultOperationHistory, exactly from DEAFAULT_LIMIT = 20.
So in the past my animation did 20 steps and whole application freez.

The question now is: How to enlarge this Limit, or how to use RecordingCommand with more than 20 crations getEditingDomain().getCommandStack(). <- , or how to do a solution, that I can go 20 steps backwards, with RecordingCommand.
Previous Topic:[GMF] create a graphic Object with an RCP action
Next Topic:Can't delete a Component of diagram that I've create
Goto Forum:
  


Current Time: Tue Jun 25 21:48:53 GMT 2024

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

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

Back to the top