1 11 12 package org.eclipse.help.ui.internal.views; 13 14 import org.eclipse.help.IContext; 15 import org.eclipse.help.ui.internal.IHelpUIConstants; 16 import org.eclipse.jface.action.IAction; 17 import org.eclipse.jface.action.IMenuManager; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.graphics.Point; 20 import org.eclipse.swt.graphics.Rectangle; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Control; 23 import org.eclipse.swt.widgets.Layout; 24 import org.eclipse.ui.IMemento; 25 import org.eclipse.ui.IWorkbenchPart; 26 import org.eclipse.ui.forms.AbstractFormPart; 27 import org.eclipse.ui.forms.ManagedForm; 28 import org.eclipse.ui.forms.widgets.FormToolkit; 29 import org.eclipse.ui.forms.widgets.ILayoutExtension; 30 import org.eclipse.ui.forms.widgets.ScrolledForm; 31 32 public class RelatedTopicsPart extends AbstractFormPart implements IHelpPart { 33 private ManagedForm mform; 34 35 private ContextHelpPart contextHelpPart; 36 37 private DynamicHelpPart dynamicHelpPart; 38 39 private ReusableHelpPart parent; 40 41 private String id; 42 43 private int VSPACE = 10; 44 45 class RelatedLayout extends Layout implements ILayoutExtension { 46 47 protected Point computeSize(Composite composite, int wHint, int hHint, 48 boolean flushCache) { 49 Point topSize = contextHelpPart.getControl().computeSize(wHint, 50 hHint, flushCache); 51 Point botSize = dynamicHelpPart.getControl().computeSize(wHint, 52 hHint, flushCache); 53 Point size = new Point(0, 0); 54 size.x = Math.max(topSize.x, botSize.x); 55 size.y = VSPACE + topSize.y + VSPACE + botSize.y; 56 return size; 57 } 58 59 protected void layout(Composite composite, boolean flushCache) { 60 Rectangle carea = composite.getClientArea(); 61 Point topSize = contextHelpPart.getControl().computeSize( 62 carea.width, SWT.DEFAULT, flushCache); 63 Point botSize = dynamicHelpPart.getControl().computeSize( 64 carea.width, SWT.DEFAULT, flushCache); 65 int y = VSPACE; 66 contextHelpPart.getControl().setBounds(0, y, carea.width, topSize.y); 67 y += topSize.y + VSPACE; 68 dynamicHelpPart.getControl().setBounds(0, y, carea.width, botSize.y); 69 } 70 71 public int computeMinimumWidth(Composite parent, boolean changed) { 72 int top = computeMinimumWidth(contextHelpPart, parent, changed); 73 int bot = computeMinimumWidth(dynamicHelpPart, parent, changed); 74 return Math.max(top, bot); 75 } 76 77 private int computeMinimumWidth(IHelpPart part, Composite parent, boolean changed) { 78 ILayoutExtension le = (ILayoutExtension)((Composite)part.getControl()).getLayout(); 79 return le.computeMinimumWidth(parent, changed); 80 } 81 82 public int computeMaximumWidth(Composite parent, boolean changed) { 83 return computeSize(parent, SWT.DEFAULT, SWT.DEFAULT, changed).x; 84 } 85 } 86 87 public RelatedTopicsPart(Composite parent, FormToolkit toolkit) { 88 ScrolledForm form = toolkit.createScrolledForm(parent); 89 mform = new ManagedForm(toolkit, form) { 90 public void reflow(boolean changed) { 91 super.reflow(changed); 92 RelatedTopicsPart.this.parent.reflow(); 93 } 94 }; 95 form.getBody().setLayout(new RelatedLayout()); 96 contextHelpPart = new ContextHelpPart(form.getBody(), toolkit); 97 dynamicHelpPart = new DynamicHelpPart(form.getBody(), toolkit); 98 } 99 100 public void init(ReusableHelpPart parent, String id, IMemento memento) { 101 this.parent = parent; 102 this.id = id; 103 contextHelpPart.init(parent, IHelpUIConstants.HV_CONTEXT_HELP, memento); 104 dynamicHelpPart.init(parent, IHelpUIConstants.HV_SEARCH_RESULT, memento); 105 mform.addPart(contextHelpPart); 106 mform.addPart(dynamicHelpPart); 107 mform.initialize(); 108 } 109 110 public void dispose() { 111 mform.dispose(); 112 } 113 114 public void handleActivation(Control c, IWorkbenchPart wpart) { 115 contextHelpPart.handleActivation(c, wpart); 116 } 117 118 public void setDefaultText(String defaultText) { 119 contextHelpPart.setDefaultText(defaultText); 120 } 121 122 public Control getControl() { 123 return mform.getForm(); 124 } 125 126 public String getId() { 127 return id; 128 } 129 130 public void setVisible(boolean visible) { 131 mform.getForm().setVisible(visible); 132 } 133 134 public boolean hasFocusControl(Control control) { 135 return contextHelpPart.hasFocusControl(control) 136 || dynamicHelpPart.hasFocusControl(control); 137 } 138 139 public boolean fillContextMenu(IMenuManager manager) { 140 Control focusControl = mform.getForm().getDisplay().getFocusControl(); 141 if (contextHelpPart.hasFocusControl(focusControl)) 142 return contextHelpPart.fillContextMenu(manager); 143 return dynamicHelpPart.fillContextMenu(manager); 144 } 145 146 public IAction getGlobalAction(String id) { 147 return contextHelpPart.getGlobalAction(id); 148 } 149 150 public void stop() { 151 contextHelpPart.stop(); 152 dynamicHelpPart.stop(); 153 } 154 155 public void toggleRoleFilter() { 156 contextHelpPart.toggleRoleFilter(); 157 dynamicHelpPart.toggleRoleFilter(); 158 } 159 160 public void refilter() { 161 contextHelpPart.refilter(); 162 dynamicHelpPart.refilter(); 163 } 164 public boolean setFormInput(Object input) { 165 return mform.setInput(input); 166 } 167 public void startSearch(String newPhrase, IContext excludeContext) { 168 dynamicHelpPart.startSearch(newPhrase, excludeContext); 169 } 170 171 public void saveState(IMemento memento) { 172 } 173 174 public void setFocus() { 175 if (contextHelpPart!=null) 176 contextHelpPart.setFocus(); 177 } 178 } 179 | Popular Tags |