Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 267590 - NavigationProcessor.fireForwardHistoryEvent() fires backwards data
Summary: NavigationProcessor.fireForwardHistoryEvent() fires backwards data
Status: RESOLVED FIXED
Alias: None
Product: Riena
Classification: RT
Component: navigation (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-09 04:42 EDT by Stefan Flick CLA
Modified: 2011-05-19 06:56 EDT (History)
1 user (show)

See Also:


Attachments
patch ased on riena 1.1.0m6 (4.74 KB, patch)
2009-03-25 08:38 EDT, Stefan Flick CLA
no flags Details | Diff
patch in eclipse format (5.00 KB, text/plain)
2009-03-25 08:57 EDT, Stefan Flick CLA
no flags Details
latest cumulated changes (4.00 KB, patch)
2009-03-30 05:48 EDT, Stefan Flick CLA
christian.campo: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Flick CLA 2009-03-09 04:42:22 EDT
see fixed method below

    /**
     * Fires a INavigationHistoryEvent when the forward history changes.
     */
    private void fireForewardHistoryChangedEvent() {
        if (navigationListener.size() == 0) {
            return;
        }
        INavigationHistoryEvent event = new NavigationHistoryEvent(histForward.subList(0, histForward.size()));
        for (INavigationHistoryListener listener : navigationListener) {
            listener.forwardHistoryChanged(event);
        }
    }
Comment 1 Christian Campo CLA 2009-03-09 06:16:26 EDT
fixed method above.....however not clear why historyForward and historyBackward throw multiple events....need to investigate
Comment 2 Stefan Flick CLA 2009-03-24 11:05:43 EDT
applied patch for riena 1.1.0m6

* fired foreward history changed event content
* fixed, history changed events are fired when a new listener is registered exclusivly for this new listener. so the listener can initialize corresponding widgets prior to the first navigation
applied patch below

Index: src/org/eclipse/riena/navigation/model/NavigationProcessor.java
===================================================================
RCS file: /cvsroot/rt/org.eclipse.riena/org.eclipse.riena.navigation/src/org/eclipse/riena/navigation/model/NavigationProcessor.java,v
retrieving revision 1.27
diff -u -r1.27 NavigationProcessor.java
--- src/org/eclipse/riena/navigation/model/NavigationProcessor.java	9 Mar 2009 10:14:50 -0000	1.27
+++ src/org/eclipse/riena/navigation/model/NavigationProcessor.java	24 Mar 2009 15:03:18 -0000
@@ -20,6 +20,8 @@
 import java.util.Stack;
 import java.util.Vector;
 
+import org.eclipse.equinox.log.Logger;
+
 import org.eclipse.riena.core.Log4r;
 import org.eclipse.riena.core.marker.IMarker;
 import org.eclipse.riena.internal.navigation.Activator;
@@ -37,15 +39,13 @@
 import org.eclipse.riena.ui.core.marker.DisabledMarker;
 import org.eclipse.riena.ui.core.marker.HiddenMarker;
 
-import org.eclipse.equinox.log.Logger;
-
 /**
  * Default implementation for the navigation processor
  */
 public class NavigationProcessor implements INavigationProcessor, INavigationHistory {
 
 	private static final Logger LOGGER = Log4r.getLogger(Activator.getDefault(), NavigationProcessor.class);
-	private static int maxStacksize = 20;
+	private static int maxStacksize = 40;
 	private Stack<INavigationNode<?>> histBack = new Stack<INavigationNode<?>>();
 	private Stack<INavigationNode<?>> histForward = new Stack<INavigationNode<?>>();
 	private Map<INavigationNode<?>, INavigationNode<?>> navigationMap = new HashMap<INavigationNode<?>, INavigationNode<?>>();
@@ -917,7 +917,7 @@
 		if (navigationListener.size() == 0) {
 			return;
 		}
-		INavigationHistoryEvent event = new NavigationHistoryEvent(histBack.subList(0, histForward.size()));
+		INavigationHistoryEvent event = new NavigationHistoryEvent(histForward.subList(0, histForward.size()));
 		for (INavigationHistoryListener listener : navigationListener) {
 			listener.forwardHistoryChanged(event);
 		}
@@ -977,6 +977,11 @@
 	public synchronized void addNavigationHistoryListener(INavigationHistoryListener listener) {
 		if (!navigationListener.contains(listener)) {
 			navigationListener.add(listener);
+			INavigationHistoryEvent event = new NavigationHistoryEvent(histBack.subList(0,
+					(histBack.size() > 0 ? histBack.size() - 1 : 0)));
+			listener.backHistoryChanged(event);
+			event = new NavigationHistoryEvent(histForward.subList(0, histForward.size()));
+			listener.forwardHistoryChanged(event);
 		}
 	}
 
Index: .project
===================================================================
RCS file: /cvsroot/rt/org.eclipse.riena/org.eclipse.riena.navigation/.project,v
retrieving revision 1.2
diff -u -r1.2 .project
--- .project	10 Dec 2008 12:51:06 -0000	1.2
+++ .project	24 Mar 2009 15:03:17 -0000
@@ -20,15 +20,9 @@
 			<arguments>
 			</arguments>
 		</buildCommand>
-		<buildCommand>
-			<name>com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
 	</buildSpec>
 	<natures>
 		<nature>org.eclipse.pde.PluginNature</nature>
 		<nature>org.eclipse.jdt.core.javanature</nature>
-		<nature>com.atlassw.tools.eclipse.checkstyle.CheckstyleNature</nature>
 	</natures>
 </projectDescription>
Comment 3 Stefan Flick CLA 2009-03-24 13:22:10 EDT
modifications for .project file in the patch was a mistake. 
please ignore.
Comment 4 Stefan Flick CLA 2009-03-25 06:11:20 EDT
firing of history navigation changed events are occurs at the wrong place. that causes the problems.
here is the fix that will build a correct history and fires the correct events.

Index: src/org/eclipse/riena/navigation/model/NavigationProcessor.java
===================================================================
RCS file: /cvsroot/rt/org.eclipse.riena/org.eclipse.riena.navigation/src/org/eclipse/riena/navigation/model/NavigationProcessor.java,v
retrieving revision 1.27
diff -u -r1.27 NavigationProcessor.java
--- src/org/eclipse/riena/navigation/model/NavigationProcessor.java	9 Mar 2009 10:14:50 -0000	1.27
+++ src/org/eclipse/riena/navigation/model/NavigationProcessor.java	25 Mar 2009 09:57:49 -0000
@@ -20,6 +20,8 @@
 import java.util.Stack;
 import java.util.Vector;
 
+import org.eclipse.equinox.log.Logger;
+
 import org.eclipse.riena.core.Log4r;
 import org.eclipse.riena.core.marker.IMarker;
 import org.eclipse.riena.internal.navigation.Activator;
@@ -37,15 +39,13 @@
 import org.eclipse.riena.ui.core.marker.DisabledMarker;
 import org.eclipse.riena.ui.core.marker.HiddenMarker;
 
-import org.eclipse.equinox.log.Logger;
-
 /**
  * Default implementation for the navigation processor
  */
 public class NavigationProcessor implements INavigationProcessor, INavigationHistory {
 
 	private static final Logger LOGGER = Log4r.getLogger(Activator.getDefault(), NavigationProcessor.class);
-	private static int maxStacksize = 20;
+	private static int maxStacksize = 40;
 	private Stack<INavigationNode<?>> histBack = new Stack<INavigationNode<?>>();
 	private Stack<INavigationNode<?>> histForward = new Stack<INavigationNode<?>>();
 	private Map<INavigationNode<?>, INavigationNode<?>> navigationMap = new HashMap<INavigationNode<?>, INavigationNode<?>>();
@@ -61,7 +61,6 @@
 				// if toActivate is module, module group or sub application
 				// the same sub module will be activated on activation of
 				// the toActivate, in any case there is nothing to do
-				buildHistory(toActivate);
 			} else {
 				if (!toActivate.isVisible() || !toActivate.isEnabled()) {
 					return;
@@ -79,7 +78,6 @@
 				if (allowsDeactivate(navigationContext)) {
 					if (allowsActivate(navigationContext)) {
 						deactivate(navigationContext);
-						buildHistory(toActivate);
 						activate(navigationContext);
 					}
 				}
@@ -815,6 +813,8 @@
 		for (INavigationNode<?> next : parent.getChildren()) {
 			if (next.equals(child)) {
 				next.setSelected(true);
+				//We have a new selected child. Remember in history.
+				buildHistory(next);
 			} else {
 				next.setSelected(false);
 			}
@@ -917,7 +917,7 @@
 		if (navigationListener.size() == 0) {
 			return;
 		}
-		INavigationHistoryEvent event = new NavigationHistoryEvent(histBack.subList(0, histForward.size()));
+		INavigationHistoryEvent event = new NavigationHistoryEvent(histForward.subList(0, histForward.size()));
 		for (INavigationHistoryListener listener : navigationListener) {
 			listener.forwardHistoryChanged(event);
 		}
@@ -934,6 +934,17 @@
 	}
 
 	/**
+	 * Answers the currently selected SubModuleNode in the NavigationTree
+	 * 
+	 * @return the currently selected SubModuleNode in the NavigationTree or
+	 *         null
+	 */
+	public INavigationNode<?> getSelectedChild() {
+		//always the top most histback item is the currently selected
+		return histBack.peek();
+	}
+
+	/**
 	 * Answer the current size of the previous navigation history
 	 * 
 	 * @see org.eclipse.riena.navigation.INavigationNode#getHistorySize()
@@ -977,6 +988,11 @@
 	public synchronized void addNavigationHistoryListener(INavigationHistoryListener listener) {
 		if (!navigationListener.contains(listener)) {
 			navigationListener.add(listener);
+			INavigationHistoryEvent event = new NavigationHistoryEvent(histBack.subList(0,
+					(histBack.size() > 0 ? histBack.size() - 1 : 0)));
+			listener.backHistoryChanged(event);
+			event = new NavigationHistoryEvent(histForward.subList(0, histForward.size()));
+			listener.forwardHistoryChanged(event);
 		}
 	}
 
Comment 5 Stefan Liebig CLA 2009-03-25 08:32:31 EDT
Please provide a patch as an attachment.
Comment 6 Stefan Flick CLA 2009-03-25 08:38:08 EDT
Created attachment 129837 [details]
patch ased on riena 1.1.0m6

changed sources
Comment 7 Stefan Flick CLA 2009-03-25 08:57:17 EDT
Created attachment 129838 [details]
patch in eclipse format
Comment 8 Stefan Flick CLA 2009-03-30 05:48:57 EDT
Created attachment 130214 [details]
latest cumulated changes

ther was another bug for building the history. we have to change the history only for the active and selected node. see NavigationProcesseor#setSelectedchild() line 817ff.
setSelectedChild is called for every node in the chain, but if we have nested subModules, only the active subModule node must be added to the history
Comment 9 Stefan Liebig CLA 2009-03-31 07:31:52 EDT
Accepted last patch:
- renamed getSelectedChild() to getSelectedNode()
- also added this method to the INavigationProcessor interface

Thanks!