Example usage for org.eclipse.swt.widgets Composite getShell

List of usage examples for org.eclipse.swt.widgets Composite getShell

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Composite getShell.

Prototype

public Shell getShell() 

Source Link

Document

Returns the receiver's shell.

Usage

From source file:edu.isistan.carcha.plugin.editors.TraceabilityEditor.java

/**
 * Creates a page to allow users to create a traceability link.
 *//*from  www  .  ja  v  a2  s .  com*/
void createTraceabilityLinkPage() {
    final Composite composite = new Composite(getContainer(), SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 5));
    composite.setLayout(new GridLayout());

    Label concernLabel = new Label(composite, SWT.BORDER);
    concernLabel.setText("Crosscuttings Concerns(CCC)");
    concernLabel.setToolTipText("This are the Crosscuttings Concerns detected on the requierement document");
    GridData gridData = new GridData(SWT.LEFT, SWT.TOP, false, false);
    concernLabel.setLayoutData(gridData);

    topNewLink = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    createColumns(composite, topNewLink);

    final Table table = topNewLink.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    topNewLink.setContentProvider(new ArrayContentProvider());
    getSite().setSelectionProvider(topNewLink);
    // define layout for the viewer
    gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    topNewLink.getControl().setLayoutData(gridData);

    Button button = new Button(composite, SWT.PUSH);
    button.setText("Link");
    button.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent event) {
        }

        public void widgetSelected(SelectionEvent event) {
            IStructuredSelection topSelection = (IStructuredSelection) topNewLink.getSelection();
            IStructuredSelection bottomSelection = (IStructuredSelection) bottomNewLink.getSelection();

            String[] crosscuttingConcern = (String[]) topSelection.getFirstElement();
            String[] designDecision = (String[]) bottomSelection.getFirstElement();

            if ((crosscuttingConcern != null) && (designDecision != null)) {
                // create dialog with ok and cancel button and info icon
                MessageBox dialog = new MessageBox(composite.getShell(),
                        SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
                dialog.setText("Link confirmation");
                dialog.setMessage("Do you want to link the selected items?");

                // open dialog and await user selection
                int response = dialog.open();
                if (response == SWT.OK) {
                    PluginUtil.createNewLink(crosscuttingConcern, designDecision, cp);
                    dirty = true;
                    firePropertyChange(IEditorPart.PROP_DIRTY);
                }
            } else {
                MessageDialog.openError(composite.getShell(), "Error", "Please select item(s) to link");
            }
        }
    });

    gridData = new GridData(SWT.CENTER, SWT.TOP, false, false, 2, 1);
    button.setLayoutData(gridData);

    Label ddsLabel = new Label(composite, SWT.BORDER);
    ddsLabel.setText("Architectural design decisions");
    ddsLabel.setToolTipText("This are the design decisions detected in the architectural document");
    gridData = new GridData(SWT.LEFT, SWT.TOP, false, false);
    ddsLabel.setLayoutData(gridData);
    bottomNewLink = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    createColumns(composite, bottomNewLink);

    Table table2 = bottomNewLink.getTable();
    table2.setHeaderVisible(true);
    table2.setLinesVisible(true);

    bottomNewLink.setContentProvider(new ArrayContentProvider());

    getSite().setSelectionProvider(bottomNewLink);
    gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    bottomNewLink.getControl().setLayoutData(gridData);

    int index = addPage(composite);
    setPageText(index, "New Link");
}

From source file:widgetTest3.java

/** * Coolbar ** */

public CoolBar createCoolBar(Composite composite) {
    //       Create CoolBar
    final CoolBar coolbar = new CoolBar(composite, SWT.NULL);
    //       Create ToolBar as a component of CoolBar
    final ToolBar toolbar1 = new ToolBar(coolbar, SWT.NULL);
    //       Create pushbutton
    final ToolItem toolitem1 = new ToolItem(toolbar1, SWT.PUSH);
    toolitem1.setText("Push");
    toolitem1.setToolTipText("Push button");
    //       Create event processing for pushbutton
    toolitem1.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println("Tool button was pressed: " + toolitem1.getText());
        }/*from   ww  w.ja v a2s .  c o m*/
    });
    //       Create check button
    final ToolItem toolitem2 = new ToolItem(toolbar1, SWT.CHECK);
    toolitem2.setText("Check");
    toolitem2.setToolTipText("Check button");
    //       Create CoolItem instance
    final CoolItem coolitem1 = new CoolItem(coolbar, SWT.NULL);
    //       Assign this tool bar to the CoolItem instance
    coolitem1.setControl(toolbar1);
    //       Compute size of tool bar
    Point size = toolbar1.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    //       Compute required size of CoolItems instance
    size = coolitem1.computeSize(size.x, size.y);
    //       Set size for this CoolItem instance
    coolitem1.setSize(size);
    //       The minimum size of the CoolItem is the width of the first button
    coolitem1.setMinimumSize(toolitem1.getWidth(), size.y);

    //       Create second ToolBar instance
    final ToolBar toolbar2 = new ToolBar(coolbar, SWT.NULL);
    //       Create two radio buttons
    final ToolItem toolitem3a = new ToolItem(toolbar2, SWT.RADIO);
    toolitem3a.setText("Radio");
    toolitem3a.setToolTipText("Radio button a");
    final ToolItem toolitem3b = new ToolItem(toolbar2, SWT.RADIO);
    toolitem3b.setText("Radio");
    toolitem3b.setToolTipText("Radio button b");
    //       Create separator
    new ToolItem(toolbar2, SWT.SEPARATOR);
    //       Create drop-down menu button
    final ToolItem toolitem5 = new ToolItem(toolbar2, SWT.DROP_DOWN);
    toolitem5.setText("Drop-down-Menu");
    //       Add event processing to drop-down menu button
    toolitem5.addSelectionListener(
            // In class DropDownSelectionListener we construct the menu
            new DropDownSelectionListener(composite.getShell()));
    // Create second CoolItem, assing Toolbar to it and set size
    final CoolItem coolitem2 = new CoolItem(coolbar, SWT.NULL);
    coolitem2.setControl(toolbar2);
    size = toolbar2.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    size = coolitem2.computeSize(size.x, size.y);
    coolitem2.setSize(size);
    coolitem2.setMinimumSize(toolitem3a.getWidth(), size.y);
    return coolbar;
}

From source file:edu.isistan.carcha.plugin.editors.TraceabilityEditor.java

/**
 * Creates the impact list page./*from ww  w  .  ja v a2s .c o m*/
 */
void impactListPage() {
    final Composite composite = new Composite(getContainer(), SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    composite.setLayout(new GridLayout());

    Label concernLabel = new Label(composite, SWT.BORDER);
    concernLabel.setText("Crosccuting Concerns(CCC)");
    concernLabel.setToolTipText("This are the concern detected on the requierement document.");
    GridData gridData = new GridData(SWT.LEFT, SWT.TOP, false, false);
    concernLabel.setLayoutData(gridData);

    /////////////////////
    ScrolledComposite sc = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite parent = new Composite(sc, SWT.NONE);
    parent.setLayout(new GridLayout());

    topViewLink = new TableViewer(parent, SWT.BORDER);
    createColumns(parent, topViewLink);

    final Table table = topViewLink.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    topViewLink.setContentProvider(new ArrayContentProvider());

    getSite().setSelectionProvider(topViewLink);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.heightHint = 10 * table.getItemHeight();
    table.setLayoutData(data);

    sc.setContent(parent);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));

    /////////////////////

    Button button = new Button(composite, SWT.PUSH);
    button.setText("Remove");
    button.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent event) {
        }

        public void widgetSelected(SelectionEvent event) {
            IStructuredSelection topSelection = (IStructuredSelection) topViewLink.getSelection();
            IStructuredSelection bottomSelection = (IStructuredSelection) bottomViewLink.getSelection();

            String[] crosscuttingConcern = (String[]) topSelection.getFirstElement();
            String[] designDecision = (String[]) bottomSelection.getFirstElement();
            if (topSelection.size() > 1) {
                MessageDialog.openError(composite.getShell(), "Error",
                        "Please select one crosscutting concern");
            } else {
                if ((crosscuttingConcern != null) && (designDecision != null)) {
                    // create dialog with ok and cancel button and info icon
                    MessageBox dialog = new MessageBox(composite.getShell(),
                            SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
                    dialog.setText("Link confirmation");
                    dialog.setMessage("Do you want to remove the link between the selected items?");

                    // open dialog and await user selection
                    int response = dialog.open();
                    if (response == SWT.OK) {
                        PluginUtil.removeLink(crosscuttingConcern, designDecision, cp);
                        dirty = true;
                        firePropertyChange(IEditorPart.PROP_DIRTY);
                        // update the list after the remove
                        generateLinkViewData();
                        bottomViewLink.getTable().clearAll();
                    }
                } else {
                    MessageDialog.openError(composite.getShell(), "Error",
                            "Please select a crosscutting concern and a design decision to remove a traceability link");
                }
            }
        }
    });
    gridData = new GridData(SWT.CENTER, SWT.TOP, false, false, 2, 1);
    button.setLayoutData(gridData);

    Label ddsLabel = new Label(composite, SWT.BORDER);
    ddsLabel.setText("Architectural design decisions");
    ddsLabel.setToolTipText("This are the design decisions detected on the architectural document");

    gridData = new GridData(SWT.LEFT, SWT.TOP, false, false);
    ddsLabel.setLayoutData(gridData);

    bottomViewLink = new TableViewer(composite,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    createColumns(composite, bottomViewLink);
    Table table2 = bottomViewLink.getTable();
    table2.setHeaderVisible(true);
    table2.setLinesVisible(true);
    bottomViewLink.setContentProvider(new ArrayContentProvider());
    topViewLink.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (!selection.isEmpty()) {
                String[] cccs = (String[]) selection.getFirstElement();
                List<DesignDecision> dds = PluginUtil.getDesignDecisionsForCrossCuttingConcern(cp, cccs[1],
                        cccs[0]);
                logger.info("Impact List for CCC (" + dds.size() + " DDD): " + cccs[0] + " - " + cccs[1]);
                List<String[]> designDecisions = new ArrayList<String[]>();

                for (DesignDecision dd : dds) {
                    String[] designDecision = { dd.getKind(), dd.getName() };
                    designDecisions.add(designDecision);
                }
                bottomViewLink.setInput(designDecisions);
            }
        }
    });
    getSite().setSelectionProvider(bottomViewLink);
    gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    bottomViewLink.getControl().setLayoutData(gridData);

    int index = addPage(composite);
    setPageText(index, "Links");
}

From source file:GraphicsExample.java

void createToolBar(final Composite parent) {
    final Display display = parent.getDisplay();

    toolBar = new ToolBar(parent, SWT.FLAT);
    Listener toolBarListener = new Listener() {
        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.Selection: {
                if (event.widget == playItem) {
                    animate = true;/*from w  ww .  j  a v  a2s  .c o m*/
                    playItem.setEnabled(!animate);
                    pauseItem.setEnabled(animate);
                } else if (event.widget == pauseItem) {
                    animate = false;
                    playItem.setEnabled(!animate);
                    pauseItem.setEnabled(animate);
                } else if (event.widget == backItem) {
                    final ToolItem toolItem = (ToolItem) event.widget;
                    final ToolBar toolBar = toolItem.getParent();
                    Rectangle toolItemBounds = toolItem.getBounds();
                    Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y));
                    backMenu.setLocation(point.x, point.y + toolItemBounds.height);
                    backMenu.setVisible(true);
                }
            }
                break;
            }
        }
    };

    playItem = new ToolItem(toolBar, SWT.PUSH);
    playItem.setText(getResourceString("Play")); //$NON-NLS-1$
    playItem.setImage(loadImage(display, "play.gif")); //$NON-NLS-1$
    playItem.addListener(SWT.Selection, toolBarListener);

    pauseItem = new ToolItem(toolBar, SWT.PUSH);
    pauseItem.setText(getResourceString("Pause")); //$NON-NLS-1$
    pauseItem.setImage(loadImage(display, "pause.gif")); //$NON-NLS-1$
    pauseItem.addListener(SWT.Selection, toolBarListener);

    backItem = new ToolItem(toolBar, SWT.PUSH);
    backItem.setText(getResourceString("Background")); //$NON-NLS-1$
    backItem.addListener(SWT.Selection, toolBarListener);
    String[] names = new String[] { getResourceString("White"), //$NON-NLS-1$
            getResourceString("Black"), //$NON-NLS-1$
            getResourceString("Red"), //$NON-NLS-1$
            getResourceString("Green"), //$NON-NLS-1$
            getResourceString("Blue"), //$NON-NLS-1$
            getResourceString("CustomColor"), //$NON-NLS-1$
    };
    Color[] colors = new Color[] { display.getSystemColor(SWT.COLOR_WHITE),
            display.getSystemColor(SWT.COLOR_BLACK), display.getSystemColor(SWT.COLOR_RED),
            display.getSystemColor(SWT.COLOR_GREEN), display.getSystemColor(SWT.COLOR_BLUE), null, };
    backMenu = new Menu(parent);
    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            MenuItem item = (MenuItem) event.widget;
            if (customMI == item) {
                ColorDialog dialog = new ColorDialog(parent.getShell());
                RGB rgb = dialog.open();
                if (rgb == null)
                    return;
                if (customColor != null)
                    customColor.dispose();
                customColor = new Color(display, rgb);
                if (customImage != null)
                    customImage.dispose();
                customImage = createImage(display, customColor);
                item.setData(new Object[] { customColor, customImage });
                item.setImage(customImage);
            }
            tabBackground = (Object[]) item.getData();
            backItem.setImage((Image) tabBackground[1]);
            canvas.redraw();
        }
    };
    for (int i = 0; i < names.length; i++) {
        MenuItem item = new MenuItem(backMenu, SWT.NONE);
        item.setText(names[i]);
        item.addListener(SWT.Selection, listener);
        Image image = null;
        if (colors[i] != null) {
            image = createImage(display, colors[i]);
            images.addElement(image);
            item.setImage(image);
        } else {
            // custom menu item
            customMI = item;
        }
        item.setData(new Object[] { colors[i], image });
        if (tabBackground == null) {
            tabBackground = (Object[]) item.getData();
            backItem.setImage((Image) tabBackground[1]);
        }
    }

    dbItem = new ToolItem(toolBar, SWT.CHECK);
    dbItem.setText(getResourceString("DoubleBuffer")); //$NON-NLS-1$
    dbItem.setImage(loadImage(display, "db.gif")); //$NON-NLS-1$

    ToolItem separator = new ToolItem(toolBar, SWT.SEPARATOR);
    Composite comp = new Composite(toolBar, SWT.NONE);
    GridData data;
    GridLayout layout = new GridLayout(1, false);
    layout.verticalSpacing = 0;
    layout.marginWidth = layout.marginHeight = 3;
    comp.setLayout(layout);
    timerSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    data = new GridData(SWT.CENTER, SWT.CENTER, false, false);
    timerSpinner.setLayoutData(data);
    Label label = new Label(comp, SWT.NONE);
    label.setText(getResourceString("Animation")); //$NON-NLS-1$
    data = new GridData(SWT.CENTER, SWT.CENTER, false, false);
    label.setLayoutData(data);
    timerSpinner.setMaximum(1000);
    timerSpinner.setSelection(TIMER);
    timerSpinner.setSelection(TIMER);
    separator.setControl(comp);
    separator.setWidth(comp.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);
}