1 11 package org.eclipse.help.ui.internal.views; 12 13 import org.eclipse.help.ui.internal.HelpUIResources; 14 import org.eclipse.help.ui.internal.IHelpUIConstants; 15 import org.eclipse.help.ui.internal.Messages; 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.events.ControlAdapter; 20 import org.eclipse.swt.events.ControlEvent; 21 import org.eclipse.swt.graphics.GC; 22 import org.eclipse.swt.graphics.Image; 23 import org.eclipse.swt.graphics.Rectangle; 24 import org.eclipse.swt.layout.GridData; 25 import org.eclipse.swt.layout.GridLayout; 26 import org.eclipse.swt.layout.RowData; 27 import org.eclipse.swt.layout.RowLayout; 28 import org.eclipse.swt.widgets.Composite; 29 import org.eclipse.swt.widgets.Control; 30 import org.eclipse.swt.widgets.Label; 31 import org.eclipse.ui.IMemento; 32 import org.eclipse.ui.actions.ActionFactory; 33 import org.eclipse.ui.forms.AbstractFormPart; 34 import org.eclipse.ui.forms.FormColors; 35 import org.eclipse.ui.forms.HyperlinkGroup; 36 import org.eclipse.ui.forms.IFormColors; 37 import org.eclipse.ui.forms.events.HyperlinkAdapter; 38 import org.eclipse.ui.forms.events.HyperlinkEvent; 39 import org.eclipse.ui.forms.events.IHyperlinkListener; 40 import org.eclipse.ui.forms.widgets.FormToolkit; 41 import org.eclipse.ui.forms.widgets.ImageHyperlink; 42 43 public class SeeAlsoPart extends AbstractFormPart implements IHelpPart { 44 private Composite container; 45 private Composite linkContainer; 46 private ReusableHelpPart helpPart; 47 private String id; 48 private Image bgImage; 49 private HyperlinkGroup hyperlinkGroup; 50 51 56 public SeeAlsoPart(Composite parent, FormToolkit toolkit) { 57 container = new Composite(parent, SWT.NULL); 58 container.setBackgroundMode(SWT.INHERIT_DEFAULT); 59 container.addControlListener(new ControlAdapter() { 60 public void controlResized(ControlEvent e) { 61 updateBackgroundImage(); 62 } 63 }); 64 GridLayout layout = new GridLayout(); 65 layout.marginHeight = 0; 66 layout.verticalSpacing = 0; 68 layout.marginTop = 2; 69 container.setLayout(layout); 70 76 84 Label label = toolkit.createLabel(container, Messages.SeeAlsoPart_goto); 85 label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE)); 86 label.setBackground(null); 87 linkContainer = new Composite(container, SWT.NULL); 88 linkContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); 89 RowLayout rlayout = new RowLayout(); 90 rlayout.marginBottom = 0; 91 rlayout.marginTop = 0; 92 rlayout.marginLeft = 0; 93 rlayout.marginRight = 0; 94 rlayout.justify = false; 95 rlayout.wrap = true; 96 linkContainer.setLayout(rlayout); 97 98 hyperlinkGroup = new HyperlinkGroup(container.getDisplay()); 99 hyperlinkGroup.setHyperlinkUnderlineMode(toolkit.getHyperlinkGroup().getHyperlinkUnderlineMode()); 100 } 101 102 private void updateBackgroundImage() { 103 FormToolkit toolkit = helpPart.getForm().getToolkit(); 104 FormColors colors = toolkit.getColors(); 105 Rectangle carea = container.getClientArea(); 106 Image oldImage = bgImage; 107 if (bgImage!=null) { 108 Rectangle ibounds = bgImage.getBounds(); 109 if (carea.height==ibounds.height) 110 return; 111 } 112 bgImage = new Image(container.getDisplay(), 1, carea.height); 113 GC gc = new GC(bgImage); 114 gc.setBackground(colors.getColor(IFormColors.H_GRADIENT_END)); 115 gc.setForeground(colors.getColor(IFormColors.H_GRADIENT_START)); 116 gc.fillGradientRectangle(0, 0, 117 1, 118 carea.height, 119 true); 120 gc.setForeground(colors.getColor(IFormColors.H_BOTTOM_KEYLINE2)); 121 gc.drawLine(0, 0, 1, 0); 122 gc.setForeground(colors.getColor(IFormColors.H_BOTTOM_KEYLINE1)); 123 gc.drawLine(0, 1, 1, 1); 124 gc.dispose(); 125 container.setBackgroundImage(bgImage); 126 if (oldImage != null && !oldImage.isDisposed()) { 127 oldImage.dispose(); 128 } 129 } 130 131 private void updateLinks(String href) { 132 Control [] children = linkContainer.getChildren(); 133 for (int i=0; i<children.length; i++) { 134 ImageHyperlink link = (ImageHyperlink)children[i]; 135 RowData data = (RowData)link.getLayoutData(); 136 data.exclude = link.getHref().equals(href); 137 link.setVisible(!data.exclude); 138 } 139 linkContainer.layout(); 140 helpPart.reflow(); 141 } 142 143 private void addLinks(final Composite container, FormToolkit toolkit) { 144 IHyperlinkListener listener = new HyperlinkAdapter() { 145 public void linkActivated(final HyperlinkEvent e) { 146 container.getDisplay().asyncExec(new Runnable () { 147 public void run() { 148 SeeAlsoPart.this.helpPart.showPage((String ) e.getHref(), true); 149 } 150 }); 151 } 152 }; 153 if ((helpPart.getStyle() & ReusableHelpPart.ALL_TOPICS) != 0) 154 addPageLink(container, toolkit, Messages.SeeAlsoPart_allTopics, IHelpUIConstants.HV_ALL_TOPICS_PAGE, 155 IHelpUIConstants.IMAGE_ALL_TOPICS, listener); 156 if ((helpPart.getStyle() & ReusableHelpPart.SEARCH) != 0) { 157 addPageLink(container, toolkit, Messages.SeeAlsoPart_search, IHelpUIConstants.HV_FSEARCH_PAGE, 158 IHelpUIConstants.IMAGE_HELP_SEARCH, listener); 159 } 160 if ((helpPart.getStyle() & ReusableHelpPart.CONTEXT_HELP) != 0) { 161 addPageLink(container, toolkit, Messages.SeeAlsoPart_contextHelp, 162 IHelpUIConstants.HV_CONTEXT_HELP_PAGE, 163 IHelpUIConstants.IMAGE_RELATED_TOPICS, listener); 164 } 165 if ((helpPart.getStyle() & ReusableHelpPart.BOOKMARKS) != 0) { 166 addPageLink(container, toolkit, Messages.SeeAlsoPart_bookmarks, 167 IHelpUIConstants.HV_BOOKMARKS_PAGE, 168 IHelpUIConstants.IMAGE_BOOKMARKS, listener); 169 } 170 if ((helpPart.getStyle() & ReusableHelpPart.INDEX) != 0) { 171 addPageLink(container, toolkit, Messages.SeeAlsoPart_index, 172 IHelpUIConstants.HV_INDEX_PAGE, 173 IHelpUIConstants.IMAGE_INDEX, listener); 174 } 175 } 176 177 private void addPageLink(Composite container, FormToolkit toolkit, String text, String id, 178 String imgRef, IHyperlinkListener listener) { 179 String cid = helpPart.getCurrentPageId(); 180 if (cid!=null && cid.equals(id)) 181 return; 182 ImageHyperlink link = new ImageHyperlink(container, SWT.WRAP|toolkit.getOrientation()); 183 toolkit.adapt(link, true, true); 184 link.setImage(HelpUIResources.getImage(imgRef)); 185 link.setText(text); 186 link.setHref(id); 187 link.setBackground(null); 188 link.addHyperlinkListener(listener); 189 hyperlinkGroup.add(link); 190 RowData data = new RowData(); 191 data.exclude = false; 192 link.setLayoutData(data); 193 } 194 195 200 public Control getControl() { 201 return container; 202 } 203 204 209 public void init(ReusableHelpPart parent, String id, IMemento memento) { 210 this.helpPart = parent; 211 this.id = id; 212 addLinks(linkContainer, helpPart.getForm().getToolkit()); 213 } 214 215 public String getId() { 216 return id; 217 } 218 219 224 public void setVisible(boolean visible) { 225 container.setVisible(visible); 226 if (visible) 227 markStale(); 228 } 229 230 233 public void dispose() { 234 super.dispose(); 235 if (bgImage != null && !bgImage.isDisposed()) { 236 bgImage.dispose(); 237 } 238 } 239 240 245 public boolean fillContextMenu(IMenuManager manager) { 246 return false; 247 } 248 249 254 public boolean hasFocusControl(Control control) { 255 return control.getParent() == linkContainer; 256 } 257 258 public IAction getGlobalAction(String id) { 259 if (id.equals(ActionFactory.COPY.getId())) 260 return helpPart.getCopyAction(); 261 return null; 262 } 263 public void stop() { 264 } 265 public void refresh() { 266 if (linkContainer!=null && helpPart.getCurrentPageId()!=null) 267 updateLinks(helpPart.getCurrentPageId()); 268 super.refresh(); 269 } 270 271 public void toggleRoleFilter() { 272 } 273 274 public void refilter() { 275 } 276 277 public void saveState(IMemento memento) { 278 } 279 280 public void setFocus() { 281 if (linkContainer!=null) 282 linkContainer.setFocus(); 283 } 284 } 285 | Popular Tags |