1 11 12 package org.eclipse.ui.internal; 13 14 import java.util.ArrayList ; 15 16 import org.eclipse.ui.IEditorPart; 17 import org.eclipse.ui.IMemento; 18 import org.eclipse.ui.INavigationLocation; 19 import org.eclipse.ui.INavigationLocationProvider; 20 import org.eclipse.ui.IWorkbenchPage; 21 import org.eclipse.ui.PartInitException; 22 import org.eclipse.ui.XMLMemento; 23 24 27 public class NavigationHistoryEntry { 28 29 private IWorkbenchPage page; 30 31 NavigationHistoryEditorInfo editorInfo; 32 33 String historyText; 34 35 36 INavigationLocation location; 37 38 private IMemento locationMemento; 39 40 43 public NavigationHistoryEntry(NavigationHistoryEditorInfo editorInfo, 44 IWorkbenchPage page, IEditorPart part, INavigationLocation location) { 45 this.editorInfo = editorInfo; 46 this.page = page; 47 this.location = location; 48 if (location != null) { 49 historyText = location.getText(); 50 } 51 if (historyText == null || historyText.length() == 0) { 53 if (part != null) { 54 historyText = part.getTitle(); 55 } 56 } 57 } 58 59 63 void restoreLocation() { 64 if (editorInfo.editorInput != null && editorInfo.editorID != null) { 65 try { 66 IEditorPart editor = page.openEditor(editorInfo.editorInput, 67 editorInfo.editorID, true); 68 if (location == null) { 69 if (editor instanceof INavigationLocationProvider) { 70 location = ((INavigationLocationProvider) editor) 71 .createEmptyNavigationLocation(); 72 } 73 } 74 75 if (location != null) { 76 if (locationMemento != null) { 77 location.setInput(editorInfo.editorInput); 78 location.restoreState(locationMemento); 79 locationMemento = null; 80 } 81 location.restoreLocation(); 82 } 83 } catch (PartInitException e) { 84 } 86 } 87 } 88 89 93 String getHistoryText() { 94 if (location != null) { 95 String text = location.getText(); 100 if ((text == null) || text.equals("")) { text = historyText; 102 } else { 103 historyText = text; 104 } 105 return text; 106 } else { 107 return historyText; 108 } 109 } 110 111 115 boolean handlePartClosed() { 116 if (!editorInfo.isPersistable()) { 117 return false; 118 } 119 if (location != null) { 120 locationMemento = XMLMemento 121 .createWriteRoot(IWorkbenchConstants.TAG_POSITION); 122 location.saveState(locationMemento); 123 location.releaseState(); 124 } 125 return true; 126 } 127 128 131 void saveState(IMemento mem, ArrayList entries) { 132 mem.putString(IWorkbenchConstants.TAG_HISTORY_LABEL, getHistoryText()); 133 if (locationMemento != null) { 134 IMemento childMem = mem 135 .createChild(IWorkbenchConstants.TAG_POSITION); 136 childMem.putMemento(locationMemento); 137 } else if (location != null) { 138 IMemento childMem = mem 139 .createChild(IWorkbenchConstants.TAG_POSITION); 140 location.saveState(childMem); 141 } 142 } 143 144 147 void restoreState(IMemento mem) { 148 historyText = mem.getString(IWorkbenchConstants.TAG_HISTORY_LABEL); 149 locationMemento = mem.getChild(IWorkbenchConstants.TAG_POSITION); 150 } 151 152 156 public String toString() { 157 return "Input<" + editorInfo.editorInput + "> Details<" + location + ">"; } 159 160 163 void dispose() { 164 if (location != null) { 165 location.dispose(); 166 } 167 editorInfo = null; 168 } 169 170 174 boolean mergeInto(NavigationHistoryEntry currentEntry) { 175 if (editorInfo.editorInput != null 176 && editorInfo.editorInput 177 .equals(currentEntry.editorInfo.editorInput)) { 178 if (location != null) { 179 if (currentEntry.location == null) { 180 currentEntry.location = location; 181 return true; 182 } else { 183 return location.mergeInto(currentEntry.location); 184 } 185 } else if (currentEntry.location == null) { 186 return true; 187 } 188 } 189 return false; 190 } 191 } 192 | Popular Tags |