1 11 package org.eclipse.ui.internal.navigator.extensions; 12 13 import org.eclipse.core.runtime.IProgressMonitor; 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.Status; 16 import org.eclipse.jface.viewers.IStructuredContentProvider; 17 import org.eclipse.jface.viewers.Viewer; 18 import org.eclipse.swt.widgets.Display; 19 import org.eclipse.ui.internal.navigator.CommonNavigatorMessages; 20 import org.eclipse.ui.internal.navigator.NavigatorPlugin; 21 import org.eclipse.ui.progress.UIJob; 22 23 45 public class StructuredViewerManager { 46 47 private Viewer viewer; 48 49 private Object cachedOldInput; 50 51 private Object cachedNewInput; 52 53 private UIJob refreshJob = new UIJob( 54 CommonNavigatorMessages.StructuredViewerManager_0) { 55 public IStatus runInUIThread(IProgressMonitor monitor) { 56 if(viewer != null) { 57 try { 58 if (viewer.getControl().isDisposed()) { 59 return Status.OK_STATUS; 60 } 61 62 63 Display display = viewer.getControl().getDisplay(); 64 if (!display.isDisposed() && viewer != null) { 65 try { 66 viewer.getControl().setRedraw(false); 67 viewer.refresh(); 68 } finally { 69 viewer.getControl().setRedraw(true); 70 } 71 72 } 73 } catch (RuntimeException e) { 74 NavigatorPlugin.logError(0, e.toString(), e); 75 } 76 } 77 return Status.OK_STATUS; 78 } 79 }; 80 81 85 public StructuredViewerManager(Viewer aViewer) { 86 super(); 87 viewer = aViewer; 88 refreshJob.setSystem(true); 89 } 90 91 95 public Viewer getViewer() { 96 return viewer; 97 } 98 99 104 public void inputChanged(Object anOldInput, Object aNewInput) { 105 cachedOldInput = anOldInput; 106 cachedNewInput = aNewInput; 107 } 108 109 115 public void inputChanged(Viewer aViewer, Object anOldInput, Object aNewInput) { 116 viewer = aViewer; 117 cachedOldInput = anOldInput; 118 cachedNewInput = aNewInput; 119 } 120 121 126 public boolean initialize(IStructuredContentProvider aContentProvider) { 127 boolean result = true; 128 try { 129 if (aContentProvider != null) { 130 aContentProvider.inputChanged(viewer, cachedOldInput, 131 cachedNewInput); 132 } 133 } catch (RuntimeException e) { 134 NavigatorPlugin.logError(0, e.toString(), e); 135 result = false; 136 } 137 return result; 138 } 139 140 143 public void safeRefresh() { 144 refreshJob.schedule(10); 145 146 } 147 148 } 149 | Popular Tags |