KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > CompareEditorInputNavigator


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.compare.internal;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.compare.*;
17
18 /**
19  * Supports cross-pane navigation through the differences contained in a {@link CompareEditorInput}
20  * or a similar type of compare container.
21  * @see INavigatable
22  */

23 public class CompareEditorInputNavigator extends CompareNavigator {
24
25     // Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20106
26
private boolean fNextFirstTime= true;
27     private Object JavaDoc[] fPanes;
28     
29     /**
30      * Create a navigator for navigating the given panes
31      * @param panes the panes to navigate.
32      */

33     public CompareEditorInputNavigator(Object JavaDoc[] panes) {
34         fPanes= panes;
35     }
36     
37     /**
38      * Return the set of panes that this navigator is navigating.
39      * The {@link INavigatable} is obtain from each pane using the
40      * adaptable mechanism.
41      * @return the set of panes that this navigator is navigating
42      */

43     public Object JavaDoc[] getPanes() {
44         return fPanes;
45     }
46     
47     protected INavigatable[] getNavigatables() {
48         List JavaDoc result = new ArrayList JavaDoc();
49         Object JavaDoc[] panes = getPanes();
50         for (int i = 0; i < panes.length; i++) {
51             Object JavaDoc pane = panes[i];
52             INavigatable navigator= getNavigator(pane);
53             if (navigator != null)
54                 result.add(navigator);
55         }
56         return (INavigatable[]) result.toArray(new INavigatable[result.size()]);
57     }
58     
59     /* (non-Javadoc)
60      * @see org.eclipse.compare.ICompareNavigator#selectChange(boolean)
61      */

62     public boolean selectChange(boolean next) {
63         // Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20106
64
if (next && fNextFirstTime && mustOpen()) {
65             fNextFirstTime= false;
66             if (openElement())
67                 return false;
68         }
69         return super.selectChange(next);
70     }
71     
72     /*
73      * Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20106
74      */

75     private boolean mustOpen() {
76         Object JavaDoc[] panes = getPanes();
77         if (panes == null || panes.length == 0)
78             return false;
79         for (int i= 1; i < panes.length; i++) {
80             Object JavaDoc pane= panes[i];
81             INavigatable nav = getNavigator(pane);
82             if (nav != null && nav.getInput() != null)
83                 return false;
84         }
85         return true;
86     }
87     
88     /*
89      * Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20106
90      */

91     private boolean openElement() {
92         Object JavaDoc[] panes = getPanes();
93         if (panes == null || panes.length == 0)
94             return false;
95         INavigatable nav = getNavigator(panes[0]);
96         if (nav != null)
97             return nav.openSelectedChange();
98         return false;
99     }
100 }
101
Popular Tags