Example usage for org.eclipse.swt.widgets Label setText

List of usage examples for org.eclipse.swt.widgets Label setText

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Label setText.

Prototype

public void setText(String text) 

Source Link

Document

Sets the receiver's text.

Usage

From source file:at.ac.tuwien.inso.subcat.ui.widgets.TrendView.java

public void addConfiguration(TrendChartConfigData config) {
    assert (config != null);

    LinkedList<Combo> combos = new LinkedList<Combo>();

    // Title Row:
    Label lblGrpTitle = new Label(optionComposite, SWT.NONE);
    lblGrpTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    Helper.setLabelStyle(lblGrpTitle, SWT.BOLD);
    lblGrpTitle.setText(config.getName());

    Composite topOptions = new Composite(optionComposite, SWT.NONE);
    topOptions.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    topOptions.setLayout(new GridLayout(config.getDropDowns().size(), true));

    for (DropDownData dropData : config.getDropDowns()) {
        Combo comboDropDown = new Combo(topOptions, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
        comboDropDown.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
        comboDropDown.setData(dropData);
        combos.add(comboDropDown);/* ww  w .ja va2  s .c  o m*/

        for (DropDownData.Pair data : dropData.getData()) {
            comboDropDown.add(data.name);
        }

        comboDropDown.select(0);

        comboDropDown.addSelectionListener(this.comboListener);
    }

    // Separator:
    Helper.separator(optionComposite, 3);

    // Left Option Labels:
    new Label(optionComposite, SWT.NONE);

    Composite leftOptions = new Composite(optionComposite, SWT.NONE);
    leftOptions.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    leftOptions.setLayout(new GridLayout(1, true));
    for (OptionListConfigData.Pair pair : config.getOptionList().getData()) {
        Label lblOpt = new Label(leftOptions, SWT.NONE);
        lblOpt.setText(pair.name);
    }

    // Check Boxes:
    Composite selectionComposite = new Composite(optionComposite, SWT.NONE);
    selectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    selectionComposite.setLayout(new GridLayout(combos.size(), true));

    OptionListConfig leftConfig = config.getOptionList().getConfig();
    int x = 0;

    for (Combo combo : combos) {
        TrendChartPlotConfig topConfig = (TrendChartPlotConfig) config.getDropDowns().get(x).getConfig();

        for (OptionListConfigData.Pair pair : config.getOptionList().getData()) {
            Button button = new Button(selectionComposite, SWT.CHECK);
            button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
            button.setData(new ChartIdentifier(topConfig, combo, leftConfig, pair.id, boxWeight++));
            button.addSelectionListener(boxListener);
        }

        x++;
    }

    // Scrolling area size update:
    scrolledComposite.setMinSize(optionComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}

From source file:at.ac.tuwien.inso.subcat.ui.widgets.TrendChart.java

public void addConfiguration(TrendChartConfigData config, List<String> flags) {
    assert (config != null);

    ArrayList<Combo> combos = new ArrayList<Combo>();

    // Title Row:
    Label lblGrpTitle = new Label(optionComposite, SWT.NONE);
    lblGrpTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    Helper.setLabelStyle(lblGrpTitle, SWT.BOLD);
    lblGrpTitle.setText(config.getName());

    Composite topOptions = new Composite(optionComposite, SWT.NONE);
    topOptions.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    topOptions.setLayout(new GridLayout(config.getDropDowns().size(), true));

    for (DropDownData dropData : config.getDropDowns()) {
        if (dropData.getConfig().show(flags)) {
            Combo comboDropDown = new Combo(topOptions, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
            comboDropDown.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
            comboDropDown.setData(dropData);
            combos.add(comboDropDown);//www  .  j a  v  a 2  s .  c o  m

            for (DropDownData.Pair data : dropData.getData()) {
                comboDropDown.add(data.name);
            }

            comboDropDown.select(0);

            comboDropDown.addSelectionListener(this.comboListener);
        }
    }

    // Separator:
    Helper.separator(optionComposite, 3);

    // Left Option Labels:
    new Label(optionComposite, SWT.NONE);

    Composite leftOptions = new Composite(optionComposite, SWT.NONE);
    leftOptions.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    leftOptions.setLayout(new GridLayout(1, true));
    for (OptionListConfigData.Pair pair : config.getOptionList().getData()) {
        Label lblOpt = new Label(leftOptions, SWT.NONE);
        lblOpt.setText(pair.name);
    }

    // Check Boxes:
    Composite selectionComposite = new Composite(optionComposite, SWT.NONE);
    selectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    selectionComposite.setLayout(new GridLayout(combos.size(), true));

    OptionListConfig leftConfig = config.getOptionList().getConfig();

    for (OptionListConfigData.Pair pair : config.getOptionList().getData()) {
        int x = 0;
        for (Combo combo : combos) {
            TrendChartPlotConfig topConfig = (TrendChartPlotConfig) config.getDropDowns().get(x).getConfig();

            Button button = new Button(selectionComposite, SWT.CHECK);
            button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
            button.setData(new ChartIdentifier(topConfig, combo, leftConfig, pair.id, boxWeight++));
            button.addSelectionListener(boxListener);
            x++;
        }
    }

    // Scrolling area size update:
    scrolledComposite.setMinSize(optionComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}

From source file:org.eclipse.swt.examples.clipboard.ClipboardExample.java

void createImageTransfer(Composite copyParent, Composite pasteParent) {
    final Image[] copyImage = new Image[] { null };
    Label l = new Label(copyParent, SWT.NONE);
    l.setText("ImageTransfer:"); //$NON-NLS-1$
    GridData data = new GridData();
    data.verticalSpan = 2;/*w w  w. j  a v a 2 s . c  o  m*/
    l.setLayoutData(data);

    final Canvas copyImageCanvas = new Canvas(copyParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_BOTH);
    data.verticalSpan = 2;
    data.widthHint = HSIZE;
    data.heightHint = VSIZE;
    copyImageCanvas.setLayoutData(data);

    final Point copyOrigin = new Point(0, 0);
    final ScrollBar copyHBar = copyImageCanvas.getHorizontalBar();
    copyHBar.setEnabled(false);
    copyHBar.addListener(SWT.Selection, e -> {
        if (copyImage[0] != null) {
            int hSelection = copyHBar.getSelection();
            int destX = -hSelection - copyOrigin.x;
            Rectangle rect = copyImage[0].getBounds();
            copyImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false);
            copyOrigin.x = -hSelection;
        }
    });
    final ScrollBar copyVBar = copyImageCanvas.getVerticalBar();
    copyVBar.setEnabled(false);
    copyVBar.addListener(SWT.Selection, e -> {
        if (copyImage[0] != null) {
            int vSelection = copyVBar.getSelection();
            int destY = -vSelection - copyOrigin.y;
            Rectangle rect = copyImage[0].getBounds();
            copyImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false);
            copyOrigin.y = -vSelection;
        }
    });
    copyImageCanvas.addListener(SWT.Paint, e -> {
        if (copyImage[0] != null) {
            GC gc = e.gc;
            gc.drawImage(copyImage[0], copyOrigin.x, copyOrigin.y);
            Rectangle rect = copyImage[0].getBounds();
            Rectangle client = copyImageCanvas.getClientArea();
            int marginWidth = client.width - rect.width;
            if (marginWidth > 0) {
                gc.fillRectangle(rect.width, 0, marginWidth, client.height);
            }
            int marginHeight = client.height - rect.height;
            if (marginHeight > 0) {
                gc.fillRectangle(0, rect.height, client.width, marginHeight);
            }
            gc.dispose();
        }
    });
    Button openButton = new Button(copyParent, SWT.PUSH);
    openButton.setText("Open Image");
    openButton.addSelectionListener(widgetSelectedAdapter(e -> {
        FileDialog dialog = new FileDialog(shell, SWT.OPEN);
        dialog.setText("Open an image file or cancel");
        String string = dialog.open();
        if (string != null) {
            if (copyImage[0] != null) {
                System.out.println("CopyImage");
                copyImage[0].dispose();
            }
            copyImage[0] = new Image(e.display, string);
            copyVBar.setEnabled(true);
            copyHBar.setEnabled(true);
            copyOrigin.x = 0;
            copyOrigin.y = 0;
            Rectangle rect = copyImage[0].getBounds();
            Rectangle client = copyImageCanvas.getClientArea();
            copyHBar.setMaximum(rect.width);
            copyVBar.setMaximum(rect.height);
            copyHBar.setThumb(Math.min(rect.width, client.width));
            copyVBar.setThumb(Math.min(rect.height, client.height));
            copyImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true);
            copyVBar.setSelection(0);
            copyHBar.setSelection(0);
            copyImageCanvas.redraw();
        }
    }));
    Button b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        if (copyImage[0] != null) {
            status.setText("");
            // Fetch ImageData at current zoom and save in the clip-board.
            clipboard.setContents(new Object[] { copyImage[0].getImageDataAtCurrentZoom() },
                    new Transfer[] { ImageTransfer.getInstance() });
        } else {
            status.setText("No image to copy");
        }
    }));

    final Image[] pasteImage = new Image[] { null };
    l = new Label(pasteParent, SWT.NONE);
    l.setText("ImageTransfer:");
    final Canvas pasteImageCanvas = new Canvas(pasteParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_BOTH);
    data.widthHint = HSIZE;
    data.heightHint = VSIZE;
    pasteImageCanvas.setLayoutData(data);
    final Point pasteOrigin = new Point(0, 0);
    final ScrollBar pasteHBar = pasteImageCanvas.getHorizontalBar();
    pasteHBar.setEnabled(false);
    pasteHBar.addListener(SWT.Selection, e -> {
        if (pasteImage[0] != null) {
            int hSelection = pasteHBar.getSelection();
            int destX = -hSelection - pasteOrigin.x;
            Rectangle rect = pasteImage[0].getBounds();
            pasteImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false);
            pasteOrigin.x = -hSelection;
        }
    });
    final ScrollBar pasteVBar = pasteImageCanvas.getVerticalBar();
    pasteVBar.setEnabled(false);
    pasteVBar.addListener(SWT.Selection, e -> {
        if (pasteImage[0] != null) {
            int vSelection = pasteVBar.getSelection();
            int destY = -vSelection - pasteOrigin.y;
            Rectangle rect = pasteImage[0].getBounds();
            pasteImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false);
            pasteOrigin.y = -vSelection;
        }
    });
    pasteImageCanvas.addListener(SWT.Paint, e -> {
        if (pasteImage[0] != null) {
            GC gc = e.gc;
            gc.drawImage(pasteImage[0], pasteOrigin.x, pasteOrigin.y);
            Rectangle rect = pasteImage[0].getBounds();
            Rectangle client = pasteImageCanvas.getClientArea();
            int marginWidth = client.width - rect.width;
            if (marginWidth > 0) {
                gc.fillRectangle(rect.width, 0, marginWidth, client.height);
            }
            int marginHeight = client.height - rect.height;
            if (marginHeight > 0) {
                gc.fillRectangle(0, rect.height, client.width, marginHeight);
            }
        }
    });
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        ImageData imageData = (ImageData) clipboard.getContents(ImageTransfer.getInstance());
        if (imageData != null) {
            if (pasteImage[0] != null) {
                System.out.println("PasteImage");
                pasteImage[0].dispose();
            }
            status.setText("");
            // Consume the ImageData at current zoom as-is.
            pasteImage[0] = new Image(e.display, new AutoScaleImageDataProvider(imageData));
            pasteVBar.setEnabled(true);
            pasteHBar.setEnabled(true);
            pasteOrigin.x = 0;
            pasteOrigin.y = 0;
            Rectangle rect = pasteImage[0].getBounds();
            Rectangle client = pasteImageCanvas.getClientArea();
            pasteHBar.setMaximum(rect.width);
            pasteVBar.setMaximum(rect.height);
            pasteHBar.setThumb(Math.min(rect.width, client.width));
            pasteVBar.setThumb(Math.min(rect.height, client.height));
            pasteImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true);
            pasteVBar.setSelection(0);
            pasteHBar.setSelection(0);
            pasteImageCanvas.redraw();
        } else {
            status.setText("No image to paste");
        }
    }));
}

From source file:org.pentaho.di.ui.spoon.trans.TransPerfDelegate.java

public void setupContent() {
    // there is a potential infinite loop below if this method
    // is called when the transgraph is not running, so we check
    // early to make sure it won't happen (see PDI-5009)
    if (!transGraph.isRunning() || transGraph.trans == null
            || !transGraph.trans.getTransMeta().isCapturingStepPerformanceSnapShots()) {
        showEmptyGraph();//from  w w w  . j  a v  a  2  s .  c  o m
        return; // TODO: display help text and rerty button
    }

    if (perfComposite.isDisposed()) {
        return;
    }

    // Remove anything on the perf composite, like an empty page message
    //
    for (Control control : perfComposite.getChildren()) {
        if (!control.isDisposed()) {
            control.dispose();
        }
    }

    emptyGraph = false;

    this.title = transGraph.trans.getTransMeta().getName();
    this.timeDifference = transGraph.trans.getTransMeta().getStepPerformanceCapturingDelay();
    this.stepPerformanceSnapShots = transGraph.trans.getStepPerformanceSnapShots();

    // Wait a second for the first data to pour in...
    // TODO: make this wait more elegant...
    //
    while (this.stepPerformanceSnapShots == null || stepPerformanceSnapShots.isEmpty()) {
        this.stepPerformanceSnapShots = transGraph.trans.getStepPerformanceSnapShots();
        try {
            Thread.sleep(100L);
        } catch (InterruptedException e) {
            // Ignore errors
        }
    }

    Set<String> stepsSet = stepPerformanceSnapShots.keySet();
    steps = stepsSet.toArray(new String[stepsSet.size()]);
    Arrays.sort(steps);

    // Display 2 lists with the data types and the steps on the left side.
    // Then put a canvas with the graph on the right side
    //
    Label dataListLabel = new Label(perfComposite, SWT.NONE);
    dataListLabel.setText(BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.Metrics.Label"));
    spoon.props.setLook(dataListLabel);
    FormData fdDataListLabel = new FormData();

    fdDataListLabel.left = new FormAttachment(0, 0);
    fdDataListLabel.right = new FormAttachment(spoon.props.getMiddlePct() / 2, Const.MARGIN);
    fdDataListLabel.top = new FormAttachment(0, Const.MARGIN + 5);
    dataListLabel.setLayoutData(fdDataListLabel);

    dataList = new org.eclipse.swt.widgets.List(perfComposite,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.LEFT | SWT.BORDER);
    spoon.props.setLook(dataList);
    dataList.setItems(dataChoices);
    dataList.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {

            // If there are multiple selections here AND there are multiple selections in the steps list, we only take the
            // first step in the selection...
            //
            if (dataList.getSelectionCount() > 1 && stepsList.getSelectionCount() > 1) {
                stepsList.setSelection(stepsList.getSelectionIndices()[0]);
            }

            updateGraph();
        }
    });

    FormData fdDataList = new FormData();
    fdDataList.left = new FormAttachment(0, 0);
    fdDataList.right = new FormAttachment(spoon.props.getMiddlePct() / 2, Const.MARGIN);
    fdDataList.top = new FormAttachment(dataListLabel, Const.MARGIN);
    fdDataList.bottom = new FormAttachment(40, Const.MARGIN);
    dataList.setLayoutData(fdDataList);

    Label stepsListLabel = new Label(perfComposite, SWT.NONE);
    stepsListLabel.setText(BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.Steps.Label"));

    spoon.props.setLook(stepsListLabel);

    FormData fdStepsListLabel = new FormData();
    fdStepsListLabel.left = new FormAttachment(0, 0);
    fdStepsListLabel.right = new FormAttachment(spoon.props.getMiddlePct() / 2, Const.MARGIN);
    fdStepsListLabel.top = new FormAttachment(dataList, Const.MARGIN);
    stepsListLabel.setLayoutData(fdStepsListLabel);

    stepsList = new org.eclipse.swt.widgets.List(perfComposite,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.LEFT | SWT.BORDER);
    spoon.props.setLook(stepsList);
    stepsList.setItems(steps);
    stepsList.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {

            // If there are multiple selections here AND there are multiple selections in the data list, we only take the
            // first data item in the selection...
            //
            if (dataList.getSelectionCount() > 1 && stepsList.getSelectionCount() > 1) {
                dataList.setSelection(dataList.getSelectionIndices()[0]);
            }

            updateGraph();
        }
    });
    FormData fdStepsList = new FormData();
    fdStepsList.left = new FormAttachment(0, 0);
    fdStepsList.right = new FormAttachment(spoon.props.getMiddlePct() / 2, Const.MARGIN);
    fdStepsList.top = new FormAttachment(stepsListLabel, Const.MARGIN);
    fdStepsList.bottom = new FormAttachment(100, Const.MARGIN);
    stepsList.setLayoutData(fdStepsList);

    canvas = new Canvas(perfComposite, SWT.NONE);
    spoon.props.setLook(canvas);
    FormData fdCanvas = new FormData();
    fdCanvas.left = new FormAttachment(spoon.props.getMiddlePct() / 2, Const.MARGIN);
    fdCanvas.right = new FormAttachment(100, 0);
    fdCanvas.top = new FormAttachment(0, Const.MARGIN);
    fdCanvas.bottom = new FormAttachment(100, 0);
    canvas.setLayoutData(fdCanvas);

    perfComposite.addControlListener(new ControlAdapter() {
        public void controlResized(ControlEvent event) {
            updateGraph();
        }
    });

    perfComposite.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent event) {
            if (image != null) {
                image.dispose();
            }
        }
    });

    canvas.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent event) {
            if (image != null && !image.isDisposed()) {
                event.gc.drawImage(image, 0, 0);
            }
        }
    });

    // Refresh automatically every 5 seconds as well.
    //
    final Timer timer = new Timer("TransPerfDelegate Timer");
    timer.schedule(new TimerTask() {
        public void run() {
            updateGraph();
        }
    }, 0, 5000);

    // When the tab is closed, we remove the update timer
    //
    transPerfTab.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent arg0) {
            timer.cancel();
        }
    });
}

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

/**
 * Creates a page to allow users to create a traceability link.
 *///from   ww w .jav  a 2 s  .c o  m
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:edu.isistan.carcha.plugin.editors.TraceabilityEditor.java

/**
 * Creates the impact list page.// w w w. j  a va  2s  .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:org.ewhoxford.swt.bloodpressure.ui.MeasurePageTab.java

/**
 * Creates the control widgets.//from ww  w. ja v a 2s .  c o  m
 */
void createControlWidgets() {

    /* Controls the type of FillLayout */
    Group bpGroup = new Group(controlGroup, SWT.NONE);
    bpGroup.setText(BPMainWindow.getResourceString("BP_and_HR"));
    bpGroup.setLayout(new GridLayout(2, true));
    bpGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    messageLabel = new Label(controlGroup, SWT.NONE);
    messageLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    messageLabel.setText("");

    Label label1 = new Label(bpGroup, SWT.NONE);
    label1.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    label1.setText("SBP");

    sbpTextbox = new Text(bpGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
    sbpTextbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    sbpTextbox.setText("0");
    sbpTextbox.setEditable(false);

    Label label2 = new Label(bpGroup, SWT.NONE);
    label2.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    label2.setText("DBP");

    dbpTextbox = new Text(bpGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
    dbpTextbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    dbpTextbox.setText("0");
    dbpTextbox.setEditable(false);

    Label label3 = new Label(bpGroup, SWT.NONE);
    label3.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    label3.setText("HR");

    hrTextbox = new Text(bpGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
    hrTextbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    hrTextbox.setText("0");
    hrTextbox.setEditable(false);

    Label label5 = new Label(controlGroup, SWT.NONE);
    label5.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    label5.setText("");

    Label label4 = new Label(controlGroup, SWT.NONE);
    label4.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    label4.setText("Notes:");

    notesText = new Text(controlGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    notesText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    notesText.setText("Comment on the blood pressure");
    notesText.computeSize(100, 500);
    notesText.setEnabled(true);
    final Group optionGroup = new Group(controlGroup, SWT.NONE);
    optionGroup.setText(BPMainWindow.getResourceString("Options"));
    optionGroup.setLayout(new GridLayout());
    optionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    newMeasure = new Button(optionGroup, SWT.BUTTON1);
    newMeasure.setText("New Measure");
    newMeasure.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    newMeasure.setSelection(true);
    newMeasure.addSelectionListener(selectionListener);

    createCSV = new Button(optionGroup, SWT.CHECK);
    createCSV.setText("create CSV File");
    createCSV.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    saveButton = new Button(optionGroup, SWT.BUTTON1);
    saveButton.setText("Save");
    saveButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    saveButton.setEnabled(false);
    saveButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String savedFileName = "";
            String notes = "";

            if (notesText.getText().length() != 0) {
                notes = notesText.getText();
            }

            Long time = System.currentTimeMillis();

            if (createCSV.getSelection()) {

                try {
                    savedFileName = FileManager.saveFile(bloodPressureValue, arrayPressure, arrayTime, time,
                            notes);
                } catch (Exception e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } finally {
                    addNewMeasureAndFile(savedFileName, bloodPressureValue, notes, time);
                }

            } else {
                addNewMeasureAndFile(savedFileName, bloodPressureValue, notes, time);

                if (createCSV.getSelection()) {

                    MessageDialog.openInformation(optionGroup.getShell(), "Saved",
                            BPMainWindow.getResourceString("alert_dialog_data_saved_to_database_and_csv"));

                } else {

                    MessageDialog.openInformation(optionGroup.getShell(), "Saved",
                            BPMainWindow.getResourceString("alert_dialog_data_saved_to_database"));
                }
            }
        }
    });
    // #### End of Set up click listeners for all the buttons
}

From source file:org.eclipse.swt.examples.layoutexample.Tab.java

/**
 * Refreshes the composite and draws all controls
 * in the layout example.//from   w  ww  .j a  v a  2 s.  c  o  m
 */
void refreshLayoutComposite() {
    /* Remove children that are already laid out */
    children = layoutComposite.getChildren();
    for (Control child : children) {
        child.dispose();
    }
    /* Add all children listed in the table */
    TableItem[] items = table.getItems();
    children = new Control[items.length];
    String[] itemValues = new String[] { LayoutExample.getResourceString("Item", new String[] { "1" }),
            LayoutExample.getResourceString("Item", new String[] { "2" }),
            LayoutExample.getResourceString("Item", new String[] { "3" }) };
    for (int i = 0; i < items.length; i++) {
        String control = items[i].getText(1);
        String controlName = items[i].getText(0);
        if (control.equals("Button")) {
            Button button = new Button(layoutComposite, SWT.PUSH);
            button.setText(controlName);
            children[i] = button;
        } else if (control.equals("Canvas")) {
            Canvas canvas = new Canvas(layoutComposite, SWT.BORDER);
            children[i] = canvas;
        } else if (control.equals("Combo")) {
            Combo combo = new Combo(layoutComposite, SWT.NONE);
            combo.setItems(itemValues);
            combo.setText(controlName);
            children[i] = combo;
        } else if (control.equals("Composite")) {
            Composite composite = new Composite(layoutComposite, SWT.BORDER);
            children[i] = composite;
        } else if (control.equals("CoolBar")) {
            CoolBar coolBar = new CoolBar(layoutComposite, SWT.NONE);
            ToolBar toolBar = new ToolBar(coolBar, SWT.BORDER);
            ToolItem item = new ToolItem(toolBar, 0);
            item.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
            item = new ToolItem(toolBar, 0);
            item.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
            CoolItem coolItem1 = new CoolItem(coolBar, 0);
            coolItem1.setControl(toolBar);
            toolBar = new ToolBar(coolBar, SWT.BORDER);
            item = new ToolItem(toolBar, 0);
            item.setText(LayoutExample.getResourceString("Item", new String[] { "3" }));
            item = new ToolItem(toolBar, 0);
            item.setText(LayoutExample.getResourceString("Item", new String[] { "4" }));
            CoolItem coolItem2 = new CoolItem(coolBar, 0);
            coolItem2.setControl(toolBar);
            Point size = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            coolItem1.setSize(coolItem1.computeSize(size.x, size.y));
            coolItem2.setSize(coolItem2.computeSize(size.x, size.y));
            coolBar.setSize(coolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            children[i] = coolBar;
        } else if (control.equals("Group")) {
            Group group = new Group(layoutComposite, SWT.NONE);
            group.setText(controlName);
            children[i] = group;
        } else if (control.equals("Label")) {
            Label label = new Label(layoutComposite, SWT.NONE);
            label.setText(controlName);
            children[i] = label;
        } else if (control.equals("Link")) {
            Link link = new Link(layoutComposite, SWT.NONE);
            link.setText(controlName);
            children[i] = link;
        } else if (control.equals("List")) {
            org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(layoutComposite, SWT.BORDER);
            list.setItems(itemValues);
            children[i] = list;
        } else if (control.equals("ProgressBar")) {
            ProgressBar progress = new ProgressBar(layoutComposite, SWT.NONE);
            progress.setSelection(50);
            children[i] = progress;
        } else if (control.equals("Scale")) {
            Scale scale = new Scale(layoutComposite, SWT.NONE);
            children[i] = scale;
        } else if (control.equals("Slider")) {
            Slider slider = new Slider(layoutComposite, SWT.NONE);
            children[i] = slider;
        } else if (control.equals("StyledText")) {
            StyledText styledText = new StyledText(layoutComposite,
                    SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
            styledText.setText(controlName);
            children[i] = styledText;
        } else if (control.equals("Table")) {
            Table table = new Table(layoutComposite, SWT.BORDER);
            table.setLinesVisible(true);
            TableItem item1 = new TableItem(table, 0);
            item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
            TableItem item2 = new TableItem(table, 0);
            item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
            children[i] = table;
        } else if (control.equals("Text")) {
            Text text = new Text(layoutComposite, SWT.BORDER);
            text.setText(controlName);
            children[i] = text;
        } else if (control.equals("ToolBar")) {
            ToolBar toolBar = new ToolBar(layoutComposite, SWT.BORDER);
            ToolItem item1 = new ToolItem(toolBar, 0);
            item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
            ToolItem item2 = new ToolItem(toolBar, 0);
            item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
            children[i] = toolBar;
        } else {
            Tree tree = new Tree(layoutComposite, SWT.BORDER);
            TreeItem item1 = new TreeItem(tree, 0);
            item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
            TreeItem item2 = new TreeItem(tree, 0);
            item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
            children[i] = tree;
        }
    }
}

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;/*  www.  j a  v  a  2s . co 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);
}

From source file:ControlListenerExample.java

/**
 * Creates the main window's contents//from  w w w. j a  va  2  s . c o  m
 * 
 * @param shell the main window
 * @param image the image
 */
private void createContents(Shell shell, Image image) {
    shell.setLayout(new GridLayout());

    // Create a label to hold the image
    Label label = new Label(shell, SWT.NONE);
    label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    label.setImage(image);
    shell.setData(label);

    // Add the listener
    shell.addControlListener(new ControlAdapter() {
        public void controlResized(ControlEvent event) {
            // Get the event source (the shell)
            Shell shell = (Shell) event.getSource();

            // Get the source's data (the label)
            Label label = (Label) shell.getData();

            // Determine how big the shell should be to fit the image
            Rectangle rect = shell.getClientArea();
            ImageData data = label.getImage().getImageData();

            // If the shell is too small, hide the image
            if (rect.width < data.width || rect.height < data.height) {
                shell.setText("Too small.");
                label.setText("I'm melting!");
            } else {
                // He fits!
                shell.setText("Happy Guy Fits!");
                label.setImage(label.getImage());
            }
        }
    });
}