1 11 package org.eclipse.ui.help; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.Assert; 16 import org.eclipse.help.IContext; 17 import org.eclipse.swt.events.HelpEvent; 18 import org.eclipse.swt.widgets.Control; 19 import org.eclipse.ui.IViewPart; 20 21 28 public class ViewContextComputer implements IContextComputer { 29 private IViewPart view; 30 31 private ArrayList contextList; 32 33 private Object context; 34 35 42 public ViewContextComputer(IViewPart viewPart, Object helpContext) { 43 Assert.isTrue(helpContext instanceof String 44 || helpContext instanceof IContext); 45 view = viewPart; 46 context = helpContext; 47 } 48 49 55 private void addContexts(Object object, HelpEvent event) { 56 Assert.isTrue(object instanceof Object [] 57 || object instanceof IContextComputer 58 || object instanceof String ); 59 60 if (object instanceof String ) { 61 contextList.add(object); 62 return; 63 } 64 65 Object [] contexts; 66 if (object instanceof IContextComputer) { 67 contexts = ((IContextComputer) object).getLocalContexts(event); 69 } else { 70 contexts = (Object []) object; 71 } 72 73 for (int i = 0; i < contexts.length; i++) { 75 contextList.add(contexts[i]); 76 } 77 } 78 79 85 private void addContextsForControl(Control control, HelpEvent event) { 86 Object object = WorkbenchHelp.getHelp(control); 88 89 if (object == null || object == this) { 90 return; 92 } 93 94 addContexts(object, event); 95 } 96 97 100 public Object [] computeContexts(HelpEvent event) { 101 contextList = new ArrayList (); 102 103 contextList.add(context); 105 106 addContextsForControl(view.getSite().getShell(), event); 108 109 return contextList.toArray(); 111 } 112 113 116 public Object [] getLocalContexts(HelpEvent event) { 117 return new Object [] { context }; 118 } 119 } 120 | Popular Tags |