001: /*******************************************************************************
002: * Copyright (c) 2004, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.intro.impl.swt;
011:
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.graphics.Image;
014: import org.eclipse.swt.layout.GridData;
015: import org.eclipse.swt.layout.GridLayout;
016: import org.eclipse.swt.widgets.Composite;
017: import org.eclipse.swt.widgets.Control;
018: import org.eclipse.swt.widgets.Label;
019: import org.eclipse.ui.forms.IFormColors;
020: import org.eclipse.ui.forms.widgets.Form;
021: import org.eclipse.ui.forms.widgets.FormToolkit;
022: import org.eclipse.ui.forms.widgets.ImageHyperlink;
023: import org.eclipse.ui.forms.widgets.ScrolledPageBook;
024: import org.eclipse.ui.internal.intro.impl.model.IntroLink;
025: import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot;
026: import org.eclipse.ui.internal.intro.impl.util.ImageUtil;
027:
028: /**
029: * Extends the UI of a PageForm and adds a navigation toolbar UI for the root
030: * page links.
031: */
032: public class PageFormWithNavigation extends PageForm {
033:
034: private PageStyleManager rootPageStyleManager;
035:
036: // Id to this page. There is only a single instance of this page in the
037: // main page book.
038: public static String PAGE_FORM_WITH_NAVIGATION_ID = "pageFormWithNavigationId"; //$NON-NLS-1$
039:
040: /**
041: *
042: */
043: public PageFormWithNavigation(FormToolkit toolkit,
044: IntroModelRoot modelRoot, Form parentForm) {
045: super (toolkit, modelRoot, parentForm);
046: }
047:
048: /**
049: * Extend parent behavior and add navigation.
050: *
051: * @param pageBook
052: */
053: public void createPartControl(ScrolledPageBook mainPageBook,
054: SharedStyleManager sharedStyleManager) {
055:
056: super .createPartControl(mainPageBook, sharedStyleManager);
057:
058: // Create a style manager from shared style manager. We only need it
059: // for the UI navigation composite.
060: rootPageStyleManager = new PageStyleManager(
061: model.getHomePage(), sharedStyleManager.getProperties());
062:
063: // Now create Navigation bar.
064: Composite navigationComposite = toolkit
065: .createComposite(pageForm.getBody());
066: navigationComposite.setLayoutData(new GridData(
067: GridData.HORIZONTAL_ALIGN_CENTER));
068: int numberOfLinks = model.getHomePage().getLinks().length;
069: GridLayout layout = new GridLayout();
070: layout.numColumns = numberOfLinks;
071: navigationComposite.setLayout(layout);
072: createSmallNavigator(navigationComposite, model.getHomePage()
073: .getLinks());
074:
075: pageForm.setText(rootPageStyleManager.getPageSubTitle());
076: }
077:
078: /**
079: * Override parent id.
080: */
081: protected String getId() {
082: return PAGE_FORM_WITH_NAVIGATION_ID;
083: }
084:
085: private void createSmallNavigator(Composite parent,
086: IntroLink[] links) {
087: for (int i = 0; i < links.length; i++) {
088: Control c = createImageHyperlink(parent, links[i]);
089: c.setLayoutData(new GridData(
090: GridData.HORIZONTAL_ALIGN_CENTER));
091: }
092: for (int i = 0; i < links.length; i++) {
093: Label text = toolkit.createLabel(parent, links[i]
094: .getLabel());
095: text.setLayoutData(new GridData(
096: GridData.HORIZONTAL_ALIGN_CENTER));
097: text.setForeground(toolkit.getColors().getColor(
098: IFormColors.TITLE));
099: }
100: }
101:
102: /**
103: * Creates an Image Hyperlink from an IntroLink. Model object is NOT cached.
104: *
105: * @param body
106: * @param link
107: */
108: private Control createImageHyperlink(Composite body, IntroLink link) {
109: ImageHyperlink imageLink = toolkit.createImageHyperlink(body,
110: SWT.NULL);
111:
112: // set link image.
113: Image image = rootPageStyleManager.getImage(link,
114: "small-link-icon", //$NON-NLS-1$
115: ImageUtil.DEFAULT_SMALL_ROOT_LINK);
116: imageLink.setImage(image);
117:
118: // set link hover image.
119: image = rootPageStyleManager.getImage(link,
120: "small-hover-icon", null); //$NON-NLS-1$
121: imageLink.setHoverImage(image);
122: imageLink.setToolTipText(link.getLabel());
123: // each link is centered in cell.
124: GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
125: imageLink.setLayoutData(gd);
126: imageLink.setHref(link.getUrl());
127: imageLink.addHyperlinkListener(hyperlinkAdapter);
128: return imageLink;
129: }
130:
131: }
|