Home | History | Annotate | Download | only in structure
      1 /*******************************************************************************
      2  * Copyright (c) 2011 Google, Inc.
      3  * All rights reserved. This program and the accompanying materials
      4  * are made available under the terms of the Eclipse Public License v1.0
      5  * which accompanies this distribution, and is available at
      6  * http://www.eclipse.org/legal/epl-v10.html
      7  *
      8  * Contributors:
      9  *    Google, Inc. - initial API and implementation
     10  *******************************************************************************/
     11 package org.eclipse.wb.internal.core.editor.structure;
     12 
     13 import org.eclipse.jface.action.ToolBarManager;
     14 import org.eclipse.swt.SWT;
     15 import org.eclipse.swt.graphics.Image;
     16 import org.eclipse.swt.widgets.Composite;
     17 import org.eclipse.swt.widgets.Label;
     18 import org.eclipse.swt.widgets.ToolBar;
     19 import org.eclipse.wb.core.controls.CImageLabel;
     20 import org.eclipse.wb.internal.core.utils.check.Assert;
     21 import org.eclipse.wb.internal.core.utils.ui.GridDataFactory;
     22 import org.eclipse.wb.internal.core.utils.ui.GridLayoutFactory;
     23 
     24 /**
     25  * The site {@link Composite} for {@link IPage}.
     26  *
     27  * @author scheglov_ke
     28  * @coverage core.editor.structure
     29  */
     30 public final class PageSiteComposite extends Composite {
     31   private final CImageLabel m_title;
     32   private final ToolBarManager m_toolBarManager;
     33   private final ToolBar m_toolBar;
     34   private IPage m_page;
     35 
     36   ////////////////////////////////////////////////////////////////////////////
     37   //
     38   // Constructor
     39   //
     40   ////////////////////////////////////////////////////////////////////////////
     41   public PageSiteComposite(Composite parent, int style) {
     42     super(parent, style);
     43     GridLayoutFactory.create(this).noMargins().spacingV(0).columns(2);
     44     // title
     45     {
     46       m_title = new CImageLabel(this, SWT.NONE);
     47       GridDataFactory.create(m_title).grabH().fill();
     48     }
     49     // toolbar
     50     {
     51       m_toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
     52       GridDataFactory.create(m_toolBar).fill();
     53       m_toolBarManager = new ToolBarManager(m_toolBar);
     54     }
     55     // separator
     56     {
     57       Label separator = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
     58       GridDataFactory.create(separator).spanH(2).grabH().fillH();
     59     }
     60   }
     61 
     62   ////////////////////////////////////////////////////////////////////////////
     63   //
     64   // Access
     65   //
     66   ////////////////////////////////////////////////////////////////////////////
     67   /**
     68    * Sets the {@link Image} for title;
     69    */
     70   public void setTitleImage(Image image) {
     71     m_title.setImage(image);
     72   }
     73 
     74   /**
     75    * Sets the text for title.
     76    */
     77   public void setTitleText(String title) {
     78     m_title.setText(title);
     79   }
     80 
     81   /**
     82    * Sets the {@link IPage} to display.
     83    */
     84   public void setPage(IPage page) {
     85     Assert.isNull(m_page);
     86     Assert.isNotNull(page);
     87     m_page = page;
     88     // create Control
     89     m_page.createControl(this);
     90     GridDataFactory.create(m_page.getControl()).spanH(2).grab().fill();
     91     // set toolbar
     92     m_page.setToolBar(m_toolBarManager);
     93   }
     94 
     95   // BEGIN ADT MODIFICATIONS
     96   public ToolBar getToolBar() {
     97       return m_toolBar;
     98   }
     99   // END ADT MODIFICATIONS
    100 
    101 }
    102