Example usage for org.eclipse.swt.widgets Tree setLayoutData

List of usage examples for org.eclipse.swt.widgets Tree setLayoutData

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Tree setLayoutData.

Prototype

public void setLayoutData(Object layoutData) 

Source Link

Document

Sets the layout data associated with the receiver to the argument.

Usage

From source file:HoverHelp.java

/**
 * Creates the example//from   w  w  w .  ja  v a  2s.c  om
 */
public void createPartControl(Composite frame) {
    final ToolTipHandler tooltip = new ToolTipHandler(frame.getShell());

    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    frame.setLayout(layout);

    ToolBar bar = new ToolBar(frame, SWT.BORDER);
    for (int i = 0; i < 5; i++) {
        ToolItem item = new ToolItem(bar, SWT.PUSH);
        item.setText(getResourceString("ToolItem.text", new Object[] { new Integer(i) }));
        item.setData("TIP_TEXT", getResourceString("ToolItem.tooltip", new Object[] { item.getText() }));
        item.setData("TIP_HELPTEXTHANDLER", new ToolTipHelpTextHandler() {
            public String getHelpText(Widget widget) {
                Item item = (Item) widget;
                return getResourceString("ToolItem.help", new Object[] { item.getText() });
            }
        });
    }
    GridData gridData = new GridData();
    gridData.horizontalSpan = 3;
    bar.setLayoutData(gridData);
    tooltip.activateHoverHelp(bar);

    Table table = new Table(frame, SWT.BORDER);
    for (int i = 0; i < 4; i++) {
        TableItem item = new TableItem(table, SWT.PUSH);
        item.setText(getResourceString("Item", new Object[] { new Integer(i) }));
        item.setData("TIP_IMAGE", images[hhiInformation]);
        item.setText(getResourceString("TableItem.text", new Object[] { new Integer(i) }));
        item.setData("TIP_TEXT", getResourceString("TableItem.tooltip", new Object[] { item.getText() }));
        item.setData("TIP_HELPTEXTHANDLER", new ToolTipHelpTextHandler() {
            public String getHelpText(Widget widget) {
                Item item = (Item) widget;
                return getResourceString("TableItem.help", new Object[] { item.getText() });
            }
        });
    }
    table.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL));
    tooltip.activateHoverHelp(table);

    Tree tree = new Tree(frame, SWT.BORDER);
    for (int i = 0; i < 4; i++) {
        TreeItem item = new TreeItem(tree, SWT.PUSH);
        item.setText(getResourceString("Item", new Object[] { new Integer(i) }));
        item.setData("TIP_IMAGE", images[hhiWarning]);
        item.setText(getResourceString("TreeItem.text", new Object[] { new Integer(i) }));
        item.setData("TIP_TEXT", getResourceString("TreeItem.tooltip", new Object[] { item.getText() }));
        item.setData("TIP_HELPTEXTHANDLER", new ToolTipHelpTextHandler() {
            public String getHelpText(Widget widget) {
                Item item = (Item) widget;
                return getResourceString("TreeItem.help", new Object[] { item.getText() });
            }
        });
    }
    tree.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL));
    tooltip.activateHoverHelp(tree);

    Button button = new Button(frame, SWT.PUSH);
    button.setText(getResourceString("Hello.text"));
    button.setData("TIP_TEXT", getResourceString("Hello.tooltip"));
    tooltip.activateHoverHelp(button);
}

From source file:fr.inria.soctrace.framesoc.ui.piechart.view.StatisticsPieChartView.java

@Override
public void createFramesocPartControl(Composite parent) {

    // parent layout
    GridLayout gl_parent = new GridLayout(1, false);
    gl_parent.verticalSpacing = 2;//from w  ww .j a va 2  s . c  om
    gl_parent.marginWidth = 0;
    gl_parent.horizontalSpacing = 0;
    gl_parent.marginHeight = 0;
    parent.setLayout(gl_parent);

    // -------------------------------
    // Base GUI: pie + table
    // -------------------------------

    SashForm sashForm = new SashForm(parent, SWT.BORDER | SWT.SMOOTH);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    // Composite Left: composite combo + composite pie
    Composite compositeLeft = new Composite(sashForm, SWT.NONE);
    GridLayout gl_compositeLeft = new GridLayout(1, false);
    gl_compositeLeft.marginBottom = 3;
    gl_compositeLeft.verticalSpacing = 0;
    gl_compositeLeft.marginHeight = 0;
    compositeLeft.setLayout(gl_compositeLeft);

    // Composite Combo
    Composite compositeCombo = new Composite(compositeLeft, SWT.NONE);
    compositeCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    GridLayout gl_compositeCombo = new GridLayout(1, false);
    gl_compositeCombo.marginWidth = 0;
    compositeCombo.setLayout(gl_compositeCombo);

    // combo
    combo = new Combo(compositeCombo, SWT.READ_ONLY);
    combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    combo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean firstTime = true;
            for (LoaderDescriptor d : loaderDescriptors) {
                firstTime = firstTime && !d.dataLoaded();
            }
            if (firstTime) {
                return;
            }
            currentDescriptor = loaderDescriptors.get(combo.getSelectionIndex());
            cleanTableFilter();
            refreshTableFilter();
            // use global load interval
            timeBar.setSelection(globalLoadInterval);
            loadPieChart();
        }
    });

    int position = 0;
    for (LoaderDescriptor descriptor : loaderDescriptors) {
        combo.add(descriptor.loader.getStatName(), position++);
    }
    combo.select(0);
    currentDescriptor = loaderDescriptors.get(0);
    combo.setEnabled(false);

    // Composite Pie
    compositePie = new Group(compositeLeft, SWT.NONE);
    // Fill layout with Grid Data (FILL) to allow correct resize
    compositePie.setLayout(new FillLayout());
    compositePie.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    txtDescription = new Text(compositePie, SWT.READ_ONLY | SWT.WRAP | SWT.CENTER | SWT.MULTI);
    txtDescription.setEnabled(false);
    txtDescription.setEditable(false);
    txtDescription.setText("Select one of the above metrics, then press the Load button.");
    txtDescription.setVisible(false);

    // Composite Table
    Composite compositeTable = new Composite(sashForm, SWT.NONE);
    GridLayout gl_compositeTable = new GridLayout(1, false);
    compositeTable.setLayout(gl_compositeTable);

    // filter
    textFilter = new Text(compositeTable, SWT.BORDER);
    textFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    textFilter.addFocusListener(new FocusListener() {
        @Override
        public void focusLost(FocusEvent e) {
            String filter = textFilter.getText().trim();
            if (filter.isEmpty()) {
                cleanTableFilter();
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
            String filter = textFilter.getText().trim();
            if (filter.equals(FILTER_HINT)) {
                textFilter.setText("");
                textFilter.setData("");
                textFilter.setForeground(blackColor);
            }
        }
    });
    textFilter.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.keyCode == SWT.CR || textFilter.getText().trim().isEmpty()) {
                textFilter.setData(textFilter.getText());
                refreshTableFilter();
            }
        }
    });

    // table
    tableTreeViewer = new TreeViewer(compositeTable,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL);
    tableTreeViewer.setContentProvider(new TreeContentProvider());
    comparator = new StatisticsColumnComparator();
    tableTreeViewer.setComparator(comparator);
    Tree table = tableTreeViewer.getTree();
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    createColumns();
    createContextMenu();

    // status bar
    Composite statusBar = new Composite(compositeTable, SWT.BORDER);
    GridLayout statusBarLayout = new GridLayout();
    GridData statusBarGridData = new GridData();
    statusBarGridData.horizontalAlignment = SWT.FILL;
    statusBarGridData.grabExcessHorizontalSpace = true;
    statusBar.setLayoutData(statusBarGridData);
    statusBarLayout.numColumns = 1;
    statusBar.setLayout(statusBarLayout);
    // text
    statusText = new Text(statusBar, SWT.NONE);
    statusText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    statusText.setText(getStatus(0, 0));

    // -------------------------------
    // TIME MANAGEMENT BAR
    // -------------------------------

    Composite timeComposite = new Composite(parent, SWT.BORDER);
    timeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    GridLayout gl_timeComposite = new GridLayout(1, false);
    gl_timeComposite.horizontalSpacing = 0;
    timeComposite.setLayout(gl_timeComposite);
    // time manager
    timeBar = new TimeBar(timeComposite, SWT.NONE, true, true);
    timeBar.setEnabled(false);
    combo.setEnabled(false);
    IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager();
    timeBar.setStatusLineManager(statusLineManager);

    // button to synch the timebar with the gantt
    timeBar.getSynchButton().addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (combo != null && timeBar != null && currentDescriptor != null) {
                if (currentDescriptor.dataLoaded()) {
                    timeBar.setSelection(currentDescriptor.interval.startTimestamp,
                            currentDescriptor.interval.endTimestamp);
                } else {
                    timeBar.setSelection(currentShownTrace.getMinTimestamp(),
                            currentShownTrace.getMaxTimestamp());
                }
            }
        }
    });
    timeBar.getSynchButton().setToolTipText("Synch Selection With Pie Chart");

    // load button
    timeBar.getLoadButton().addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (combo.getSelectionIndex() == -1)
                return;
            currentDescriptor = loaderDescriptors.get(combo.getSelectionIndex());
            cleanTableFilter();
            refreshTableFilter();
            loadPieChart();
        }
    });

    // ----------
    // TOOL BAR
    // ----------

    // filters and actions
    createFilterDialogs();
    createActions();

    // create SWT resources
    createResources();
    // clean the filter, after creating the font
    cleanTableFilter();

}