Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2009 Anyware Technologies All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: Jacques Lescot (Anyware Technologies) - initial API and implementation $Id: NavigationManager.java,v 1.2 2009/05/06 13:36:41 jlescot Exp $ /
 
 package org.eclipse.emf.ecoretools.diagram.part;
 
 import java.util.List;
 
 import  org.eclipse.gmf.runtime.notation.Diagram;

This class is responsible of the navigation through the diagrams. Then it stores the history of this navigation to allow next and previous actions.

Author(s):
Jacques LESCOT
 
 public class NavigationManager {
 
 
 	private int previousLimit = 30;
 
 	private Stack<Diagram> previousDiagrams = new Stack<Diagram>();
 
 	private Stack<Diagram> nextDiagrams = new Stack<Diagram>();
 
Constructor

Parameters:
editor the editor
 
 		super();
 		this. = editor;
 	}

Appends the listener to the list of navigation listeners. Multiple adds result in multiple notifications.

Parameters:
listener the event listener
 
 	public void addNavigationListener(INavigationListener listener) {
 		.add(listener);
 	}

Removes the first occurrence of the specified listener.

Parameters:
listener the listener
 
 	public void removeNavigationListener(INavigationListener listener) {
 		.remove(listener);
 	}

Notify the listeners that the active diagram as changed

Parameters:
newDiagram The new active diagram
 
 	public void notifyListeners(Diagram newDiagram) {
 		for (int i = 0; i < .size(); i++) {
 		}
 	}

Returns true if a previous action can be performed

Returns:
a boolean
 
 	public boolean canDoPrevious() {
 	}

Returns true if a next action can be performed

Returns:
a boolean
	public boolean canDoNext() {
	}

Go backward in the browse history
	public void previous() {
		Diagram oldDiagram = .getDiagram();
		// Add a new browse command to the editor command stack
		Diagram prevDiagram = .pop();
		.add(oldDiagram);
		// Send event
		notifyListeners(prevDiagram.getDiagram());
	}

Go forward in the browse history
	public void next() {
		Diagram oldDiagram = .getDiagram();
		// Add a new browse command to the editor command stack
		Diagram nextDiagram = .pop();
		.add(oldDiagram);
		// Send event
		notifyListeners(nextDiagram.getDiagram());
	}

Creates the navigation command for the given diagram

Parameters:
newDiagram the destination diagram
Returns:
the navigation command
	private Command createNavigateCommand(Diagram newDiagram) {
		return new ChangeActiveDiagramCommand(newDiagram);
	}

Change the current diagram

Parameters:
newDiagram the new active diagram
	public void set(Diagram newDiagram) {
		Diagram oldDiagram = .getDiagram();
		if (oldDiagram != newDiagram || (oldDiagram == null && newDiagram == null)) {
			// Add a new browse command to the editor command stack
			// Clear the next stack
			// Add a new previous diagram
			// Send event
			notifyListeners(newDiagram);
		}
	}
	private void addPreviousDiagram(EcoreDiagramEditor previousModeler, Diagram diag) {
		if (diag != null) {
			if (getPreviousLimit() > 0) {
				}
			}
		}
	}

Returns the depth of the browse stack

Returns:
the limit
	public int getPreviousLimit() {
	}

Returns the command stack of the editor

Returns:
the command stack
	}

The GEF command used to store the navigation actions in the editor's command stack

Author(s):
Jacques LESCOT
	private class ChangeActiveDiagramCommand extends Command {

The editor of the new diagram
The diagram which was replaced by the new
		private Diagram oldDiagram;

The diagram to activate
		private Diagram newDiagram;

Constructor in case of the new diagram to be activated in the same editor as the given one

Parameters:
ed the Editor
newDiag the new active diagram
		public ChangeActiveDiagramCommand(EcoreDiagramEditor ed, Diagram newDiag) {
			this. = ed;
			this. = newDiag;
		}

		public boolean canExecute() {
			return  != null;
		}

		public boolean canUndo() {
			return  != null;
		}

		public void execute() {
			 = .getDiagram();
		}

		public void redo() {
		}

		public void undo() {
		}
	}
New to GrepCode? Check out our FAQ X