1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ide.eclipse.adt.internal.editors.ui; 18 19 import com.android.sdkuilib.ui.GridDataBuilder; 20 import com.android.sdkuilib.ui.GridLayoutBuilder; 21 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.custom.CLabel; 24 import org.eclipse.swt.graphics.Image; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Control; 27 import org.eclipse.swt.widgets.Label; 28 import org.eclipse.swt.widgets.ToolBar; 29 30 /** 31 * A composite that wraps a control, with a header composed of an image/label 32 * and a set of toolbar icons. 33 */ 34 public class DecorComposite extends Composite { 35 36 private CLabel mTitle; 37 private ToolBar mToolbar; 38 private IDecorContent mContent; 39 40 public DecorComposite(Composite parent, int style) { 41 super(parent, style); 42 43 GridLayoutBuilder.create(this).noMargins().columns(2).vSpacing(1); 44 45 mTitle = new CLabel(this, SWT.NONE); 46 GridDataBuilder.create(mTitle).hGrab().hFill().vCenter(); 47 48 mToolbar = new ToolBar(this, SWT.FLAT | SWT.RIGHT); 49 GridDataBuilder.create(mToolbar).fill(); 50 51 Label sep = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL); 52 GridDataBuilder.create(sep).hSpan(2).hFill(); 53 } 54 55 public DecorComposite setTitle(String title) { 56 mTitle.setText(title); 57 return this; 58 } 59 60 public DecorComposite setImage(Image image) { 61 mTitle.setImage(image); 62 return this; 63 } 64 65 public DecorComposite setContent(IDecorContent content) { 66 mContent = content; 67 content.createControl(this); 68 GridDataBuilder.create(content.getControl()).hSpan(2).grab().fill(); 69 70 String t = content.getTitle(); 71 if (t != null) { 72 setTitle(t); 73 } 74 75 Image i = content.getImage(); 76 if (i != null) { 77 setImage(i); 78 } 79 80 content.createToolbarItems(mToolbar); 81 82 return this; 83 } 84 85 public Control getContentControl() { 86 return mContent == null ? null : mContent.getControl(); 87 } 88 89 } 90