FileDocCategorySizeDatePackage
SectionHelper.javaAPI DocAndroid 1.5 API14441Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.ui

SectionHelper

public final class SectionHelper extends Object
Helper for the AndroidManifest form editor. Helps create a new SectionPart with sensible default parameters, create default layout or add typical widgets. IMPORTANT: This is NOT a generic class. It makes a lot of assumptions on the UI as used by the form editor for the AndroidManifest. TODO: Consider moving to a common package.

Fields Summary
Constructors Summary
Methods Summary
public static voidaddControlTooltip(org.eclipse.swt.widgets.Control control, java.lang.String tooltip)
Associates a tooltip with a control. This mirrors the behavior from org.eclipse.pde.internal.ui.editor.text.PDETextHover

param
control The control to which associate the tooltip.
param
tooltip The tooltip string. Can use \n for multi-lines. Will not display if null.

        if (control == null || tooltip == null || tooltip.length() == 0) {
            return;
        }
        
        // Some kinds of controls already properly implement tooltip display. 
        if (control instanceof Button) {
            control.setToolTipText(tooltip);
            return;
        }

        control.setToolTipText(null);

        final DefaultInformationControl ic = new DefaultInformationControl(control.getShell());
        ic.setInformation(tooltip);
        Point sz = ic.computeSizeHint();
        ic.setSize(sz.x, sz.y);
        ic.setVisible(false); // initially hidden
        
        control.addMouseTrackListener(new MouseTrackListener() {
            public void mouseEnter(MouseEvent e) {
            }

            public void mouseExit(MouseEvent e) {
                ic.setVisible(false);
            }

            public void mouseHover(MouseEvent e) {
                ic.setLocation(control.toDisplay(10, 25));  // same offset as in PDETextHover
                ic.setVisible(true);
            }
        });
    
public static org.eclipse.ui.forms.widgets.FormTextcreateFormText(org.eclipse.swt.widgets.Composite parent, org.eclipse.ui.forms.widgets.FormToolkit toolkit, boolean isHtml, java.lang.String label, boolean setupLayoutData)
Creates a FormText widget. This expects the parent composite to have a TableWrapLayout with 2 columns.

param
parent The parent (e.g. composite from CreateTableLayout())
param
toolkit Form Toolkit
param
isHtml True if the form text will contain HTML that must be interpreted as rich text (i.e. parse tags & expand URLs).
param
label The string for the label.
param
setupLayoutData indicates whether the created form text receives a TableWrapData through the setLayoutData method. In some case, creating it will make the table parent huge, which we don't want.
return
The new created FormText.

        FormText text = toolkit.createFormText(parent, true /* track focus */);
        if (setupLayoutData) {
            TableWrapData twd = new TableWrapData(TableWrapData.FILL_GRAB);
            twd.maxWidth = AndroidEditor.TEXT_WIDTH_HINT;
            if (parent.getLayout() instanceof TableWrapLayout) {
                twd.colspan = ((TableWrapLayout) parent.getLayout()).numColumns;
            }
            text.setLayoutData(twd);
        }
        text.setWhitespaceNormalized(true);
        text.setText(label, isHtml /* parseTags */, isHtml /* expandURLs */);
        return text;
    
public static org.eclipse.swt.widgets.CompositecreateGridLayout(org.eclipse.swt.widgets.Composite composite, org.eclipse.ui.forms.widgets.FormToolkit toolkit, int numColumns)
Creates a new composite with a GridLayout set with a given number of columns. If the parent composite is a Section, the new composite is set as a client.

param
composite The parent (e.g. a Section or SectionPart)
param
toolkit Form Toolkit
param
numColumns Desired number of columns.
return
The new composite.

        Composite grid = toolkit.createComposite(composite);
        GridLayout layout = new GridLayout();
        layout.numColumns = numColumns;
        grid.setLayout(layout);
        toolkit.paintBordersFor(grid);
        if (composite instanceof Section) {
            ((Section) composite).setClient(grid);
        }
        return grid;
    
public static org.eclipse.swt.widgets.LabelcreateLabel(org.eclipse.swt.widgets.Composite parent, org.eclipse.ui.forms.widgets.FormToolkit toolkit, java.lang.String label_text, java.lang.String tooltip)
Creates a label widget. If the parent layout if a TableWrapLayout, maximize it to span over all columns.

param
parent The parent (e.g. composite from CreateTableLayout())
param
toolkit Form Toolkit
param
label_text The string for the label.
param
tooltip An optional tooltip for the label and text. Can be null.
return
The new created label

        Label label = toolkit.createLabel(parent, label_text);

        TableWrapData twd = new TableWrapData(TableWrapData.FILL_GRAB);
        if (parent.getLayout() instanceof TableWrapLayout) {
            twd.colspan = ((TableWrapLayout) parent.getLayout()).numColumns;
        }
        label.setLayoutData(twd);

        addControlTooltip(label, tooltip);
        return label;
    
public static org.eclipse.swt.widgets.TextcreateLabelAndText(org.eclipse.swt.widgets.Composite parent, org.eclipse.ui.forms.widgets.FormToolkit toolkit, java.lang.String label_text, java.lang.String value, java.lang.String tooltip)
Creates two widgets: a label and a text field. This expects the parent composite to have a TableWrapLayout with 2 columns.

param
parent The parent (e.g. composite from CreateTableLayout())
param
toolkit Form Toolkit
param
label_text The string for the label.
param
value The initial value of the text field. Can be null.
param
tooltip An optional tooltip for the label and text. Can be null.
return
The new created Text field (the label is not returned)

        Label label = toolkit.createLabel(parent, label_text);
        label.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE));
        Text text = toolkit.createText(parent, value);
        text.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE));

        addControlTooltip(label, tooltip);
        return text;
    
public static org.eclipse.swt.widgets.CompositecreateTableLayout(org.eclipse.swt.widgets.Composite composite, org.eclipse.ui.forms.widgets.FormToolkit toolkit, int numColumns)
Creates a new composite with a TableWrapLayout set with a given number of columns. If the parent composite is a Section, the new composite is set as a client.

param
composite The parent (e.g. a Section or SectionPart)
param
toolkit Form Toolkit
param
numColumns Desired number of columns.
return
The new composite.

        Composite table = toolkit.createComposite(composite);
        TableWrapLayout layout = new TableWrapLayout();
        layout.numColumns = numColumns;
        table.setLayout(layout);
        toolkit.paintBordersFor(table);
        if (composite instanceof Section) {
            ((Section) composite).setClient(table);
        }
        return table;