1 /******************************************************************************* 2 * Copyright (c) 2000, 2007 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.ui.forms.examples.internal.rcp; 15 16 import org.eclipse.jface.dialogs.Dialog; 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.layout.*; 19 import org.eclipse.swt.widgets.*; 20 import org.eclipse.ui.ISharedImages; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.forms.*; 23 import org.eclipse.ui.forms.editor.*; 24 import org.eclipse.ui.forms.events.*; 25 import org.eclipse.ui.forms.examples.internal.ExamplesPlugin; 26 import org.eclipse.ui.forms.widgets.*; 27 28 /** 29 * @author dejan 30 * 31 * To change the template for this generated type comment go to Window - 32 * Preferences - Java - Code Generation - Code and Comments 33 */ 34 public class SecondPage extends FormPage { 35 /** 36 * @param id 37 * @param title 38 */ SecondPage(FormEditor editor)39 public SecondPage(FormEditor editor) { 40 super(editor, "second", "Section Page"); 41 } 42 43 @Override createFormContent(IManagedForm managedForm)44 protected void createFormContent(IManagedForm managedForm) { 45 ScrolledForm form = managedForm.getForm(); 46 FormToolkit toolkit = managedForm.getToolkit(); 47 form.setText("Title for the second page"); 48 form.setBackgroundImage(ExamplesPlugin.getDefault().getImage( 49 ExamplesPlugin.IMG_FORM_BG)); 50 GridLayout layout = new GridLayout(); 51 layout.makeColumnsEqualWidth = true; 52 layout.numColumns = 2; 53 form.getBody().setLayout(layout); 54 //This call is needed because the section will compute 55 // the bold version based on the parent. 56 Dialog.applyDialogFont(form.getBody()); 57 Section s1 = createTableSection(form, toolkit, "First Table Section", true); 58 Section s2 = createTableSection(form, toolkit, "Second Table Section", false); 59 // This call is needed for all the children 60 Dialog.applyDialogFont(form.getBody()); 61 s2.descriptionVerticalSpacing = s1.getTextClientHeightDifference(); 62 form.reflow(true); 63 } 64 createTableSection(final ScrolledForm form, FormToolkit toolkit, String title, boolean addTextClient)65 private Section createTableSection(final ScrolledForm form, 66 FormToolkit toolkit, String title, boolean addTextClient) { 67 Section section = toolkit.createSection(form.getBody(), Section.TWISTIE 68 | Section.TITLE_BAR); 69 section.setActiveToggleColor(toolkit.getHyperlinkGroup() 70 .getActiveForeground()); 71 section.setToggleColor(toolkit.getColors().getColor( 72 IFormColors.SEPARATOR)); 73 if (addTextClient) { 74 ToolBar tbar = new ToolBar(section, SWT.FLAT | SWT.HORIZONTAL); 75 ToolItem titem = new ToolItem(tbar, SWT.NULL); 76 titem.setImage(PlatformUI.getWorkbench().getSharedImages() 77 .getImage(ISharedImages.IMG_TOOL_CUT)); 78 titem = new ToolItem(tbar, SWT.PUSH); 79 titem.setImage(PlatformUI.getWorkbench().getSharedImages() 80 .getImage(ISharedImages.IMG_TOOL_COPY)); 81 titem = new ToolItem(tbar, SWT.SEPARATOR); 82 titem = new ToolItem(tbar, SWT.PUSH); 83 titem.setImage(PlatformUI.getWorkbench().getSharedImages() 84 .getImage(ISharedImages.IMG_TOOL_DELETE)); 85 section.setTextClient(tbar); 86 } 87 FormText description = toolkit.createFormText(section, false); 88 description 89 .setText( 90 "<form><p>This description uses FormText widget and as a result can have <b>bold</b> text.</p></form>", 91 true, false); 92 section.setDescriptionControl(description); 93 94 Composite client = toolkit.createComposite(section, SWT.WRAP); 95 GridLayout layout = new GridLayout(); 96 layout.numColumns = 2; 97 98 client.setLayout(layout); 99 Table t = toolkit.createTable(client, SWT.NULL); 100 GridData gd = new GridData(GridData.FILL_BOTH); 101 gd.heightHint = 200; 102 gd.widthHint = 100; 103 t.setLayoutData(gd); 104 toolkit.paintBordersFor(client); 105 Button b = toolkit.createButton(client, "Add...", SWT.PUSH); 106 gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); 107 b.setLayoutData(gd); 108 section.setText(title); 109 section 110 .setDescription("<form><p>This section has a <b>tree</b> and a button. It also has <a>a link</a> in the description.</p></form>"); 111 section.setClient(client); 112 section.setExpanded(true); 113 section.addExpansionListener(new ExpansionAdapter() { 114 @Override 115 public void expansionStateChanged(ExpansionEvent e) { 116 form.reflow(false); 117 } 118 }); 119 gd = new GridData(GridData.FILL_BOTH); 120 section.setLayoutData(gd); 121 return section; 122 } 123 } 124