1 11 12 package org.eclipse.ui.texteditor; 13 14 import org.eclipse.swt.graphics.Image; 15 16 import org.eclipse.core.runtime.Assert; 17 18 19 import org.eclipse.jface.action.IStatusLineManager; 20 import org.eclipse.jface.viewers.ISelectionChangedListener; 21 import org.eclipse.jface.viewers.ISelectionProvider; 22 import org.eclipse.jface.viewers.SelectionChangedEvent; 23 24 29 class EditorStatusLine implements IEditorStatusLine { 30 31 34 private class StatusLineClearer implements ISelectionChangedListener { 35 38 public void selectionChanged(SelectionChangedEvent event) { 39 fStatusLineManager.setErrorMessage(null, null); 40 fStatusLineManager.setMessage(null, null); 41 42 Assert.isTrue(this == fStatusLineClearer); 43 uninstallStatusLineClearer(); 44 } 45 } 46 47 48 private final IStatusLineManager fStatusLineManager; 49 50 51 private final ISelectionProvider fSelectionProvider; 52 53 54 private StatusLineClearer fStatusLineClearer; 55 56 62 public EditorStatusLine(IStatusLineManager statusLineManager, ISelectionProvider selectionProvider) { 63 64 Assert.isNotNull(statusLineManager); 65 Assert.isNotNull(selectionProvider); 66 67 fStatusLineManager= statusLineManager; 68 fSelectionProvider= selectionProvider; 69 } 70 71 76 public IStatusLineManager getStatusLineManager() { 77 return fStatusLineManager; 78 } 79 80 85 public ISelectionProvider getSelectionProvider() { 86 return fSelectionProvider; 87 } 88 89 92 public void setMessage(boolean error, String message, Image image) { 93 94 if (error) 95 fStatusLineManager.setErrorMessage(image, message); 96 else { 97 fStatusLineManager.setErrorMessage(null, null); 99 100 fStatusLineManager.setMessage(image, message); 101 } 102 103 if (isMessageEmpty(message)) 104 uninstallStatusLineClearer(); 105 else 106 installStatusLineClearer(); 107 } 108 109 115 private static boolean isMessageEmpty(String message) { 116 return message == null || message.trim().length() == 0; 117 } 118 119 122 private void uninstallStatusLineClearer() { 123 if (fStatusLineClearer == null) 124 return; 125 126 fSelectionProvider.removeSelectionChangedListener(fStatusLineClearer); 127 fStatusLineClearer= null; 128 } 129 130 133 private void installStatusLineClearer() { 134 if (fStatusLineClearer != null) 135 return; 136 137 StatusLineClearer statusLineClearer= new StatusLineClearer(); 138 fSelectionProvider.addSelectionChangedListener(statusLineClearer); 139 fStatusLineClearer= statusLineClearer; 140 } 141 } 142 | Popular Tags |