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.jface.dialogs.IDialogPage; 18 import org.eclipse.swt.events.HelpEvent; 19 import org.eclipse.swt.widgets.Control; 20 21 28 public class DialogPageContextComputer implements IContextComputer { 29 private IDialogPage page; 30 31 private ArrayList contextList; 32 33 private Object context; 34 35 42 public DialogPageContextComputer(IDialogPage page, Object helpContext) { 43 Assert.isTrue(helpContext instanceof String 44 || helpContext instanceof IContext); 45 this.page = page; 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(page.getControl(), event); 108 109 addContextsForControl(page.getControl().getShell(), event); 111 112 return contextList.toArray(); 114 } 115 116 119 public Object [] getLocalContexts(HelpEvent event) { 120 return new Object [] { context }; 121 } 122 } 123 | Popular Tags |