1 11 package org.eclipse.ui.internal.intro.impl.swt; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.graphics.Image; 15 import org.eclipse.swt.layout.GridData; 16 import org.eclipse.swt.layout.GridLayout; 17 import org.eclipse.swt.widgets.Composite; 18 import org.eclipse.swt.widgets.Control; 19 import org.eclipse.swt.widgets.Label; 20 import org.eclipse.ui.forms.IFormColors; 21 import org.eclipse.ui.forms.widgets.Form; 22 import org.eclipse.ui.forms.widgets.FormToolkit; 23 import org.eclipse.ui.forms.widgets.ImageHyperlink; 24 import org.eclipse.ui.forms.widgets.ScrolledPageBook; 25 import org.eclipse.ui.internal.intro.impl.model.IntroLink; 26 import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot; 27 import org.eclipse.ui.internal.intro.impl.util.ImageUtil; 28 29 33 public class PageFormWithNavigation extends PageForm { 34 35 private PageStyleManager rootPageStyleManager; 36 37 public static String PAGE_FORM_WITH_NAVIGATION_ID = "pageFormWithNavigationId"; 41 42 45 public PageFormWithNavigation(FormToolkit toolkit, 46 IntroModelRoot modelRoot, Form parentForm) { 47 super(toolkit, modelRoot, parentForm); 48 } 49 50 55 public void createPartControl(ScrolledPageBook mainPageBook, 56 SharedStyleManager sharedStyleManager) { 57 58 super.createPartControl(mainPageBook, sharedStyleManager); 59 60 rootPageStyleManager = new PageStyleManager(model.getHomePage(), 63 sharedStyleManager.getProperties()); 64 65 Composite navigationComposite = toolkit.createComposite(pageForm 67 .getBody()); 68 navigationComposite.setLayoutData(new GridData( 69 GridData.HORIZONTAL_ALIGN_CENTER)); 70 int numberOfLinks = model.getHomePage().getLinks().length; 71 GridLayout layout = new GridLayout(); 72 layout.numColumns = numberOfLinks; 73 navigationComposite.setLayout(layout); 74 createSmallNavigator(navigationComposite, model.getHomePage() 75 .getLinks()); 76 77 pageForm.setText(rootPageStyleManager.getPageSubTitle()); 78 } 79 80 83 protected String getId() { 84 return PAGE_FORM_WITH_NAVIGATION_ID; 85 } 86 87 private void createSmallNavigator(Composite parent, IntroLink[] links) { 88 for (int i = 0; i < links.length; i++) { 89 Control c = createImageHyperlink(parent, links[i]); 90 c.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); 91 } 92 for (int i = 0; i < links.length; i++) { 93 Label text = toolkit.createLabel(parent, links[i].getLabel()); 94 text.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); 95 text.setForeground(toolkit.getColors().getColor(IFormColors.TITLE)); 96 } 97 } 98 99 105 private Control createImageHyperlink(Composite body, IntroLink link) { 106 ImageHyperlink imageLink = toolkit.createImageHyperlink(body, SWT.NULL); 107 108 Image image = rootPageStyleManager.getImage(link, "small-link-icon", ImageUtil.DEFAULT_SMALL_ROOT_LINK); 111 imageLink.setImage(image); 112 113 image = rootPageStyleManager.getImage(link, "small-hover-icon", null); imageLink.setHoverImage(image); 116 imageLink.setToolTipText(link.getLabel()); 117 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_CENTER); 119 imageLink.setLayoutData(gd); 120 imageLink.setHref(link.getUrl()); 121 imageLink.addHyperlinkListener(hyperlinkAdapter); 122 return imageLink; 123 } 124 125 126 } 127 | Popular Tags |