1 11 package org.eclipse.team.internal.ui.synchronize; 12 13 import org.eclipse.compare.CompareViewerSwitchingPane; 14 import org.eclipse.compare.internal.INavigatable; 15 import org.eclipse.compare.internal.IOpenable; 16 import org.eclipse.core.runtime.IAdaptable; 17 import org.eclipse.jface.viewers.Viewer; 18 import org.eclipse.swt.widgets.Control; 19 import org.eclipse.team.internal.ui.synchronize.actions.NavigateAction; 20 21 32 public class PartNavigator implements INavigatable { 33 34 private Object [] fPanes; 35 private boolean fNextFirstTime= true; 37 38 public PartNavigator(Object [] panes) { 39 fPanes= panes; 40 } 41 42 public boolean gotoDifference(boolean next) { 43 44 if (next && fNextFirstTime && mustOpen()) { 46 fNextFirstTime= false; 47 openElement(); 48 } 49 50 int n= 0; 52 INavigatable[] navigators= new INavigatable[4]; 53 for (int i= 0; i < fPanes.length; i++) { 54 navigators[n]= getNavigator(fPanes[i]); 55 if (navigators[n] != null) 56 n++; 57 } 58 59 while (n > 0) { 60 n--; 61 if (navigators[n].gotoDifference(next)) { 62 continue; 64 } else return false; 66 } 67 return true; 68 } 69 70 private static INavigatable getNavigator(Object p) { 71 if (p == null) 72 return null; 73 Control control = null; 74 if (p instanceof CompareViewerSwitchingPane) { 75 CompareViewerSwitchingPane pane = (CompareViewerSwitchingPane) p; 76 if (pane.isEmpty()) 77 return null; 78 Viewer viewer = pane.getViewer(); 79 if (viewer == null) 80 return null; 81 control = viewer.getControl(); 82 if (control == null) 83 return null; 84 Object data = control.getData(INavigatable.NAVIGATOR_PROPERTY); 85 if (data instanceof INavigatable) 86 return (INavigatable) data; 87 } else if(p instanceof IAdaptable) { 88 return (INavigatable)((IAdaptable)p).getAdapter(INavigatable.class); 89 } 90 return null; 91 } 92 93 96 private boolean mustOpen() { 97 if (fPanes == null || fPanes.length == 0) 98 return false; 99 for (int i= 1; i < fPanes.length; i++) { 100 Object p= fPanes[i]; 101 if (p instanceof CompareViewerSwitchingPane) { 102 CompareViewerSwitchingPane pane = (CompareViewerSwitchingPane) p; 103 if (pane != null && pane.getInput() != null) 104 return false; 105 } 106 } 107 return true; 108 } 109 110 113 private void openElement() { 114 if (fPanes == null || fPanes.length == 0) 115 return; 116 IOpenable openable= getOpenable(fPanes[0]); 117 if (openable != null) { 118 openable.openSelected(); 119 } 120 } 121 122 125 private static IOpenable getOpenable(Object p) { 126 if (p instanceof CompareViewerSwitchingPane) { 127 CompareViewerSwitchingPane pane = (CompareViewerSwitchingPane) p; 128 if (pane == null) 129 return null; 130 if (pane.isEmpty()) 131 return null; 132 Viewer viewer = pane.getViewer(); 133 if (viewer == null) 134 return null; 135 Control control = viewer.getControl(); 136 if (control == null) 137 return null; 138 Object data = control.getData(IOpenable.OPENABLE_PROPERTY); 139 if (data instanceof IOpenable) 140 return (IOpenable) data; 141 } 142 return null; 143 } 144 } 145 | Popular Tags |