1 11 package org.eclipse.ui.internal.misc; 12 13 import org.eclipse.core.runtime.Platform; 14 import org.eclipse.ui.IPerspectiveDescriptor; 15 import org.eclipse.ui.IWorkbenchPage; 16 import org.eclipse.ui.IWorkbenchPart; 17 import org.eclipse.ui.IWorkbenchPartConstants; 18 import org.eclipse.ui.IWorkbenchPartReference; 19 import org.eclipse.ui.IWorkbenchWindow; 20 import org.eclipse.ui.PlatformUI; 21 import org.eclipse.ui.internal.util.Util; 22 23 24 28 public class UIListenerLogging { 29 30 private final static String LISTENER_EVENTS = PlatformUI.PLUGIN_ID + "/debug"; public final static String PAGE_PARTLISTENER_EVENTS = PlatformUI.PLUGIN_ID + "/listeners/IWorkbenchPage.IPartListener"; public final static String PAGE_PARTLISTENER2_EVENTS = PlatformUI.PLUGIN_ID + "/listeners/IWorkbenchPage.IPartListener2"; private final static String PAGE_PROPERTY_EVENTS = PlatformUI.PLUGIN_ID + "/listeners/IWorkbenchPage.IPropertyChangeListener"; private final static String WINDOW_PAGE_EVENTS = PlatformUI.PLUGIN_ID + "/listeners/IWorkbenchWindow.IPageListener"; private final static String WINDOW_PERSPECTIVE_EVENTS = PlatformUI.PLUGIN_ID + "/listeners/IWorkbenchWindow.IPerspectiveListener"; public final static String WINDOW_PARTLISTENER_EVENTS = PlatformUI.PLUGIN_ID + "/listeners/IWorkbenchWindow.IPartListener"; public final static String WINDOW_PARTLISTENER2_EVENTS = PlatformUI.PLUGIN_ID + "/listeners/IWorkbenchWindow.IPartListener2"; private final static String PARTREFERENCE_PROPERTY_EVENTS = PlatformUI.PLUGIN_ID + "/listeners/IWorkbenchPartReference"; 41 public final static boolean enabled = internal_isEnabled(LISTENER_EVENTS); 42 43 public final static String PE_ACTIVATED = "partActivated"; public final static String PE_PART_BROUGHT_TO_TOP = "partBroughtToTop"; public final static String PE_PART_CLOSED = "partClosed"; public final static String PE_PART_DEACTIVATED = "partDeactivated"; public final static String PE_PART_OPENED = "partOpened"; 50 public final static String PE2_ACTIVATED = "partActivated"; public final static String PE2_PART_VISIBLE = "partVisible"; public final static String PE2_PART_HIDDEN = "partHidden"; public final static String PE2_PART_BROUGHT_TO_TOP = "partBroughtToTop"; public final static String PE2_PART_CLOSED = "partClosed"; public final static String PE2_PART_DEACTIVATED = "partDectivated"; public final static String PE2_PART_OPENED = "partOpened"; public static final String PE2_PART_INPUT_CHANGED = "partInputChanged"; 60 public final static String WPE_PAGE_ACTIVATED = "pageActivated"; public final static String WPE_PAGE_OPENED = "pageOpened"; public final static String WPE_PAGE_CLOSED = "pageClosed"; 65 public static final String PLE_PERSP_PRE_DEACTIVATE = "perspectivePreDeactivate"; public static final String PLE_PERSP_DEACTIVATED = "perspectiveDeactivated"; public static final String PLE_PERSP_ACTIVATED = "perspectiveActivated"; public static final String PLE_PERSP_OPENED = "perspectiveOpened"; public static final String PLE_PERSP_CLOSED = "perspectiveClosed"; public static final String PLE_PERSP_SAVED_AS = "perspectiveSavedAs"; 73 private static String getSourceId(Object source) { 74 return Util.safeString(Integer.toString(source.hashCode() % 1000)); 75 } 76 77 private static String getWindowId(IWorkbenchWindow source) { 78 return "window " + Util.safeString(Integer.toString(source.hashCode() % 1000)); } 80 81 private static String getPageId(IWorkbenchPage page) { 82 return "page " + Util.safeString(Integer.toString(page.hashCode() % 1000)); } 84 85 private static String getPerspectiveId(IPerspectiveDescriptor descriptor) { 86 return Util.safeString(descriptor.getId()); 87 } 88 89 public static final void logPageEvent(IWorkbenchWindow window, IWorkbenchPage page, String eventId) { 90 if (isEnabled(WINDOW_PAGE_EVENTS)) { 91 System.out.println(WINDOW_PAGE_EVENTS 92 + " " + getWindowId(window) + " " + eventId + " (" + getPageId(page) + ")"); } 95 } 96 97 public static final void logPerspectiveEvent(IWorkbenchWindow window, IWorkbenchPage page, 98 IPerspectiveDescriptor descriptor, String eventId) { 99 100 if (isEnabled(WINDOW_PERSPECTIVE_EVENTS)) { 101 System.out.println(WINDOW_PERSPECTIVE_EVENTS 102 + " " + getWindowId(window) + " " + eventId + " (" + getPageId(page) + ", " + getPerspectiveId(descriptor) + ")"); } 105 } 106 107 public static final void logPerspectiveChangedEvent(IWorkbenchWindow window, IWorkbenchPage page, 108 IPerspectiveDescriptor descriptor, IWorkbenchPartReference ref, String changeId) { 109 110 if (isEnabled(WINDOW_PERSPECTIVE_EVENTS)) { 111 System.out.println(WINDOW_PERSPECTIVE_EVENTS 112 + " "+ getWindowId(window) + " perspectiveChanged (" + getPageId(page) + ", " + getPerspectiveId(descriptor) + ", " + getPartId(ref) + ", " + changeId + ")"); 116 } 117 } 118 119 public static final void logPerspectiveSavedAs(IWorkbenchWindow window, IWorkbenchPage page, 120 IPerspectiveDescriptor oldDescriptor, IPerspectiveDescriptor newDescriptor) { 121 122 if (isEnabled(WINDOW_PERSPECTIVE_EVENTS)) { 123 System.out.println(WINDOW_PERSPECTIVE_EVENTS 124 + " " + getWindowId(window) + " " + PLE_PERSP_SAVED_AS + " (" + getPageId(page) + ", " + getPerspectiveId(oldDescriptor) + ", " + getPerspectiveId(newDescriptor) + ")"); } 127 } 128 129 130 private static String getPartId(IWorkbenchPart part) { 131 if (part == null) { 132 return "null part"; } 134 135 return Util.safeString(part.getTitle()) + " - " + Util.safeString(part.getSite().getId()); 137 } 138 139 private static String getPartId(IWorkbenchPartReference ref) { 140 if (ref == null) { 141 return "null part"; } 143 144 return Util.safeString(ref.getPartName()) + " - " + Util.safeString(ref.getId()); 146 } 147 148 154 public static final void logPartListenerEvent(String sourceType, Object source, IWorkbenchPart part, String eventId) { 155 if (isEnabled(sourceType)) { 156 System.out.println(sourceType + " " + getSourceId(source) + ", " + eventId + "(" + getPartId(part) + ")"); } 159 } 160 161 167 public static final void logPartListener2Event(String sourceType, Object source, IWorkbenchPartReference part, String eventId) { 168 if (isEnabled(sourceType)) { 169 System.out.println(sourceType + " " + getSourceId(source) + ", " + eventId + "(" + getPartId(part) + ")"); } 172 } 173 174 180 public static final void logPartListenerEvent(IWorkbenchPage page, IWorkbenchPart part, String eventId) { 181 if (isEnabled(PAGE_PARTLISTENER_EVENTS)) { 182 System.out.println(PAGE_PARTLISTENER_EVENTS + " page " + Util.safeString(page.getLabel()) 184 + ", " + eventId + "(" + getPartId(part) + ")"); } 186 } 187 188 194 public static final void logPartListener2Event(IWorkbenchPage page, IWorkbenchPartReference part, String eventId) { 195 if (isEnabled(PAGE_PARTLISTENER2_EVENTS)) { 196 System.out.println(PAGE_PARTLISTENER2_EVENTS + " page " + Util.safeString(page.getLabel()) 198 + ", " + eventId + "(" + getPartId(part) + ")"); } 200 } 201 202 208 public static final void logPagePropertyChanged(IWorkbenchPage page, String changeId, Object oldValue, Object newValue) { 209 if (isEnabled(PAGE_PROPERTY_EVENTS)) { 210 System.out.println(PAGE_PROPERTY_EVENTS + " page " + Util.safeString(page.getLabel()) 212 + ", " + changeId + " = " + Util.safeString(newValue.toString()) + "( old value = " + newValue.toString() + " )"); } 214 } 215 216 public static final void logPartReferencePropertyChange(IWorkbenchPartReference ref, int changeId) { 217 if (isEnabled(PARTREFERENCE_PROPERTY_EVENTS)) { 218 String eventDescription; 219 220 switch(changeId) { 221 case IWorkbenchPartConstants.PROP_TITLE: eventDescription = "title"; break; case IWorkbenchPartConstants.PROP_DIRTY: eventDescription = "dirty"; break; case IWorkbenchPartConstants.PROP_INPUT: eventDescription = "input"; break; case IWorkbenchPartConstants.PROP_PART_NAME: eventDescription = "part_name"; break; case IWorkbenchPartConstants.PROP_CONTENT_DESCRIPTION: eventDescription = "content_description"; break; default: 227 eventDescription = "unknown event id = " + changeId; } 229 230 System.out.println(PARTREFERENCE_PROPERTY_EVENTS + " " + getPartId(ref) 232 + ", property " + eventDescription); } 234 } 235 236 private static boolean isEnabled(String eventName) { 237 return enabled && internal_isEnabled(eventName); 238 } 239 240 private static boolean internal_isEnabled(String eventName) { 241 String option = Platform.getDebugOption(eventName); 242 return option != null && !option.equalsIgnoreCase("false") && !option.equalsIgnoreCase("-1"); } 244 } 245 | Popular Tags |