1 11 package org.eclipse.ui.internal.intro.impl.swt; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.layout.GridData; 15 import org.eclipse.swt.layout.GridLayout; 16 import org.eclipse.swt.widgets.Composite; 17 import org.eclipse.swt.widgets.Control; 18 import org.eclipse.ui.forms.events.HyperlinkAdapter; 19 import org.eclipse.ui.forms.events.HyperlinkEvent; 20 import org.eclipse.ui.forms.widgets.Form; 21 import org.eclipse.ui.forms.widgets.FormToolkit; 22 import org.eclipse.ui.forms.widgets.ScrolledPageBook; 23 import org.eclipse.ui.internal.intro.impl.IIntroConstants; 24 import org.eclipse.ui.internal.intro.impl.Messages; 25 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage; 26 import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot; 27 import org.eclipse.ui.internal.intro.impl.model.url.IntroURLParser; 28 import org.eclipse.ui.internal.intro.impl.util.DialogUtil; 29 import org.eclipse.ui.internal.intro.impl.util.Util; 30 import org.eclipse.ui.intro.config.IIntroContentProviderSite; 31 32 37 public class PageForm implements IIntroConstants { 38 39 protected FormToolkit toolkit; 40 private ScrolledPageBook categoryPageBook; 41 protected IntroModelRoot model; 42 private Form parentForm; 43 protected Form pageForm; 44 46 public static String PAGE_FORM_ID = "pageFormId"; 50 private IIntroContentProviderSite site; 53 54 protected HyperlinkAdapter hyperlinkAdapter = new HyperlinkAdapter() { 55 56 public void linkActivated(HyperlinkEvent e) { 57 String url = (String ) e.getHref(); 58 IntroURLParser parser = new IntroURLParser(url); 59 if (parser.hasIntroUrl()) { 60 parser.getIntroURL().execute(); 62 return; 63 } else if (parser.hasProtocol()) { 64 Util.openBrowser(url); 65 return; 66 } 67 DialogUtil.displayInfoMessage(((Control) e.getSource()).getShell(), 68 Messages.HyperlinkAdapter_urlIs + " " + url); } 70 71 public void linkEntered(HyperlinkEvent e) { 72 } 73 74 public void linkExited(HyperlinkEvent e) { 75 } 76 }; 77 78 81 public PageForm(FormToolkit toolkit, IntroModelRoot modelRoot, 82 Form parentForm) { 83 this.toolkit = toolkit; 84 this.model = modelRoot; 85 this.parentForm = parentForm; 86 } 87 88 93 public void createPartControl(ScrolledPageBook mainPageBook, 94 SharedStyleManager sharedStyleManager) { 95 96 100 pageForm = toolkit.createForm(mainPageBook.getContainer()); 102 mainPageBook.registerPage(getId(), pageForm); 103 GridLayout layout = new GridLayout(); 104 layout.marginWidth = 0; 105 layout.marginHeight = 0; 106 pageForm.getBody().setLayout(layout); 107 109 categoryPageBook = toolkit.createPageBook(pageForm.getBody(), 112 SWT.H_SCROLL | SWT.V_SCROLL); 113 categoryPageBook.setLayoutData(new GridData(GridData.FILL_BOTH)); 114 115 } 117 118 119 protected String getId() { 120 return PAGE_FORM_ID; 121 } 122 123 124 125 132 public void showPage(AbstractIntroPage page, 133 SharedStyleManager sharedStyleManager) { 134 135 if (!categoryPageBook.hasPage(page.getId())) { 136 PageContentForm categoryForm = new PageContentForm(toolkit, model, 138 page); 139 categoryForm.setContentProviderSite(site); 140 PageStyleManager styleManager = new PageStyleManager(page, 142 sharedStyleManager.getProperties()); 143 categoryForm.createPartControl(categoryPageBook, styleManager); 144 } 145 categoryPageBook.showPage(page.getId()); 146 147 Composite pageComposite = (Composite) categoryPageBook.getCurrentPage(); 149 parentForm.setText(model.getCurrentPage().getTitle()); 151 pageForm.setText((String ) pageComposite.getData(PAGE_SUBTITLE)); 153 154 } 159 160 public void reflow() { 161 categoryPageBook.reflow(true); 162 } 163 164 public boolean hasPage(String pageId) { 165 return categoryPageBook.hasPage(pageId); 166 } 167 168 public void removePage(String pageId) { 169 categoryPageBook.removePage(pageId); 170 } 171 172 public void setContentProviderSite(IIntroContentProviderSite site) { 173 this.site = site; 174 } 175 176 177 } 178 | Popular Tags |