1 11 12 package org.eclipse.ui.internal.navigator; 13 14 import java.util.HashSet ; 15 import java.util.Set ; 16 17 import org.eclipse.core.runtime.Assert; 18 import org.eclipse.core.runtime.ListenerList; 19 import org.eclipse.ui.navigator.IExtensionActivationListener; 20 import org.eclipse.ui.navigator.INavigatorActivationService; 21 import org.eclipse.ui.navigator.INavigatorContentDescriptor; 22 import org.eclipse.ui.navigator.INavigatorContentService; 23 import org.eclipse.ui.navigator.INavigatorViewerDescriptor; 24 25 29 public class VisibilityAssistant implements IExtensionActivationListener { 30 31 private final INavigatorViewerDescriptor viewerDescriptor; 32 33 private final Set programmaticVisibilityBindings = new HashSet (); 34 35 private final Set programmaticRootBindings = new HashSet (); 36 37 private final ListenerList listeners = new ListenerList(); 38 39 private final INavigatorActivationService activationService; 40 41 45 public interface VisibilityListener { 46 47 51 void onVisibilityOrActivationChange(); 52 } 53 54 62 public VisibilityAssistant(INavigatorViewerDescriptor aViewerDescriptor, 63 INavigatorActivationService anActivationService) { 64 Assert.isNotNull(aViewerDescriptor); 65 viewerDescriptor = aViewerDescriptor; 66 67 activationService = anActivationService; 68 activationService.addExtensionActivationListener(this); 69 } 70 71 75 public void dispose() { 76 activationService.removeExtensionActivationListener(this); 77 } 78 79 85 public void bindExtensions(String [] theExtensions, boolean isRoot) { 86 if (theExtensions == null) { 87 return; 88 } 89 for (int i = 0; i < theExtensions.length; i++) { 90 programmaticVisibilityBindings.add(theExtensions[i]); 91 if (isRoot) { 92 programmaticRootBindings.add(theExtensions[i]); 93 } 94 } 95 notifyClients(); 96 } 97 98 106 public void addListener(VisibilityListener aListener) { 107 listeners.add(aListener); 108 } 109 110 118 public void removeListener(VisibilityListener aListener) { 119 listeners.remove(aListener); 120 } 121 122 private void notifyClients() { 123 Object [] clients = listeners.getListeners(); 124 for (int i = 0; i < clients.length; i++) { 125 ((VisibilityListener) clients[i]).onVisibilityOrActivationChange(); 126 } 127 } 128 129 137 public boolean isVisibleAndActive( 138 INavigatorContentDescriptor aContentDescriptor) { 139 return isActive(aContentDescriptor) && isVisible(aContentDescriptor); 140 } 141 142 153 public boolean isActive(INavigatorContentDescriptor aContentDescriptor) { 154 return activationService.isNavigatorExtensionActive(aContentDescriptor 155 .getId()); 156 } 157 158 168 public boolean isActive(String aContentExtensionId) { 169 return activationService 170 .isNavigatorExtensionActive(aContentExtensionId); 171 } 172 173 182 public boolean isVisible(INavigatorContentDescriptor aContentDescriptor) { 183 return programmaticVisibilityBindings.contains(aContentDescriptor 184 .getId()) 185 || viewerDescriptor 186 .isVisibleContentExtension(aContentDescriptor.getId()); 187 } 188 189 198 public boolean isVisible(String aContentExtensionId) { 199 return programmaticVisibilityBindings.contains(aContentExtensionId) 200 || viewerDescriptor 201 .isVisibleContentExtension(aContentExtensionId); 202 } 203 204 211 public boolean isRootExtension(String aContentExtensionId) { 212 return programmaticRootBindings.contains(aContentExtensionId) 213 || viewerDescriptor.isRootExtension(aContentExtensionId); 214 } 215 216 222 public void onExtensionActivation(String aViewerId, 223 String [] theNavigatorExtensionIds, boolean isActive) { 224 if (aViewerId.equals(viewerDescriptor.getViewerId())) { 225 notifyClients(); 226 } 227 228 } 229 230 } 231 | Popular Tags |