1 11 package org.eclipse.ui.internal.browser; 12 13 import java.net.MalformedURLException ; 14 import java.net.URL ; 15 16 import org.eclipse.core.runtime.IAdaptable; 17 import org.eclipse.jface.resource.ImageDescriptor; 18 import org.eclipse.ui.IEditorInput; 19 import org.eclipse.ui.IElementFactory; 20 import org.eclipse.ui.IMemento; 21 import org.eclipse.ui.IPersistableElement; 22 import org.eclipse.ui.browser.IWorkbenchBrowserSupport; 23 24 27 public class WebBrowserEditorInput implements IEditorInput, 28 IPersistableElement, IElementFactory { 29 31 34 36 39 44 49 private static final String ELEMENT_FACTORY_ID = "org.eclipse.ui.browser.elementFactory"; 51 private static final String MEMENTO_URL = "url"; 53 private static final String MEMENTO_STYLE = "style"; 55 private static final String MEMENTO_ID = "id"; 57 private static final String MEMENTO_NAME = "name"; 59 private static final String MEMENTO_TOOLTIP = "tooltip"; 61 private URL url; 62 63 private int style; 64 65 private String id = null; 66 67 private String name; 68 69 private String tooltip; 70 71 74 public WebBrowserEditorInput() { 75 this(null); 76 } 77 78 81 public WebBrowserEditorInput(URL url) { 82 this(url, 0); 83 } 84 85 88 public WebBrowserEditorInput(URL url, int style) { 89 super(); 90 this.url = url; 91 this.style = style; 92 } 93 94 97 public WebBrowserEditorInput(URL url, int style, String browserId) { 98 super(); 99 this.url = url; 100 this.style = style; 101 this.id = browserId; 102 } 103 104 107 public WebBrowserEditorInput(URL url, boolean b) { 108 this(url); 109 } 110 111 public void setName(String n) { 112 name = n; 113 } 114 115 public void setToolTipText(String t) { 116 tooltip = t; 117 } 118 119 127 public boolean canReplaceInput(WebBrowserEditorInput input) { 128 Trace.trace(Trace.FINEST, "canReplaceInput " + this + " " + input); if (input.isStatusbarVisible() != isStatusbarVisible()) 135 return false; 136 else if (id != null) { 137 String bid = input.getBrowserId(); 138 return id.equals(bid); 139 } else 140 return false; 141 } 142 143 152 public IAdaptable createElement(IMemento memento) { 153 int style = 0; 154 Integer integer = memento.getInteger(MEMENTO_STYLE); 155 if (integer != null) { 156 style = integer.intValue(); 157 } 158 159 URL url = null; 160 String str = memento.getString(MEMENTO_URL); 161 if (str != null) { 162 try { 163 url = new URL (str); 164 } 165 catch (MalformedURLException e) { 166 String msg = "Malformed URL while initializing browser editor"; WebBrowserUIPlugin.logError(msg, e); 168 } 169 } 170 171 String id = memento.getString(MEMENTO_ID); 172 String name = memento.getString(MEMENTO_NAME); 173 String tooltip = memento.getString(MEMENTO_TOOLTIP); 174 175 WebBrowserEditorInput input = new WebBrowserEditorInput(url, style, id); 176 input.setName(name); 177 input.setToolTipText(tooltip); 178 return input; 179 } 180 181 185 public boolean equals(Object obj) { 186 if (this == obj) 187 return true; 188 if (!(obj instanceof WebBrowserEditorInput)) 189 return false; 190 WebBrowserEditorInput other = (WebBrowserEditorInput) obj; 191 192 if (url != null && !url.equals(obj)) 193 return false; 194 195 return canReplaceInput(other); 196 } 197 198 201 public boolean exists() { 202 if ((style & IWorkbenchBrowserSupport.PERSISTENT) != 0) 203 return false; 204 205 return true; 206 } 207 208 217 public Object getAdapter(Class adapter) { 218 return null; 219 } 220 221 228 public String getFactoryId() { 229 return ELEMENT_FACTORY_ID; 230 } 231 232 public ImageDescriptor getImageDescriptor() { 233 return ImageResource 234 .getImageDescriptor(ImageResource.IMG_INTERNAL_BROWSER); 235 } 236 237 242 protected boolean isNameLocked() { 243 return (name != null); 244 } 245 246 255 public String getName() { 256 if (name != null) 257 return name; 258 259 return Messages.viewWebBrowserTitle; 260 } 261 262 267 public IPersistableElement getPersistable() { 268 if ((style & IWorkbenchBrowserSupport.PERSISTENT) == 0) 269 return null; 270 271 return this; 272 } 273 274 public String getToolTipText() { 275 if (tooltip != null) 276 return tooltip; 277 278 if (url != null) 279 return url.toExternalForm(); 280 281 return Messages.viewWebBrowserTitle; 282 } 283 284 289 public URL getURL() { 290 return url; 291 } 292 293 299 public String getBrowserId() { 300 return id; 301 } 302 303 308 public boolean isStatusbarVisible() { 309 return (style & IWorkbenchBrowserSupport.STATUS) != 0; 310 } 311 312 317 public boolean isLocationBarLocal() { 318 return (style & BrowserViewer.LOCATION_BAR) != 0; 319 } 320 321 325 326 public boolean isToolbarLocal() { 327 return (style & BrowserViewer.BUTTON_BAR) != 0; 328 } 329 330 334 335 341 public void saveState(IMemento memento) { 342 memento.putInteger(MEMENTO_STYLE, style); 343 if ((style & IWorkbenchBrowserSupport.PERSISTENT) != 0 && url != null) { 344 memento.putString(MEMENTO_URL, url.toExternalForm()); 345 } 346 if (id != null) { 347 memento.putString(MEMENTO_ID, id); 348 } 349 if (name != null) { 350 memento.putString(MEMENTO_NAME, name); 351 } 352 if (tooltip != null) { 353 memento.putString(MEMENTO_TOOLTIP, tooltip); 354 } 355 } 356 357 362 public String toString() { 363 return "WebBrowserEditorInput[" + url + " " + style + " " + id + "]"; } 365 } 366 | Popular Tags |