Example usage for org.eclipse.jface.dialogs Dialog close

List of usage examples for org.eclipse.jface.dialogs Dialog close

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs Dialog close.

Prototype

@Override
public boolean close() 

Source Link

Usage

From source file:eclipse.testframework.ui.util.DialogCheck.java

License:Open Source License

/**
 * Automated test that checks all the labels and buttons of a dialog
 * to make sure there is enough room to display all the text.  Any
 * text that wraps is only approximated and is currently not accurate.
 *
 * @param dialog the test dialog to be verified.
 *///from w  ww  . j  a  va  2  s . c om
public static void assertDialogTexts(Dialog dialog) {
    Assert.assertNotNull(dialog);
    dialog.setBlockOnOpen(false);
    dialog.open();
    Shell shell = dialog.getShell();
    verifyCompositeText(shell);
    dialog.close();
}

From source file:eu.numberfour.n4js.ui.binaries.IllegalBinaryStateDialog.java

License:Open Source License

/**
 * Creates a control with some message and with link to the Binaries preference page.
 *
 * @param parent/* w w  w. j ava2  s. c om*/
 *            the parent composite.
 * @param dialog
 *            the container dialog that has to be closed.
 * @param binary
 *            the binary with the illegal state.
 *
 * @return a control with error message and link that can be reused in dialogs.
 */
public static Control createCustomAreaWithLink(final Composite parent, final Dialog dialog,
        final Binary binary) {
    final String binaryLabel = binary.getLabel();
    final String prefix = "The requested operation cannot be performed due to invalid '" + binaryLabel
            + "' settings. Check your '" + binaryLabel
            + "' configuration and preferences under the corresponding ";
    final String link = "preference page";
    final String suffix = ".";
    final String text = prefix + link + suffix;

    final Composite control = new Composite(parent, NONE);
    control.setLayout(GridLayoutFactory.fillDefaults().create());
    final GridData gridData = GridDataFactory.fillDefaults().align(LEFT, TOP).grab(true, true).create();
    control.setLayoutData(gridData);

    final StyleRange style = new StyleRange();
    style.underline = true;
    style.underlineStyle = UNDERLINE_LINK;

    final StyledText styledText = new StyledText(control, MULTI | READ_ONLY | WRAP);
    styledText.setWordWrap(true);
    styledText.setJustify(true);
    styledText.setText(text);
    final GridData textGridData = GridDataFactory.fillDefaults().align(FILL, FILL).grab(true, true).create();
    textGridData.widthHint = TEXT_WIDTH_HINT;
    textGridData.heightHint = TEXT_HEIGHT_HINT;
    styledText.setLayoutData(textGridData);

    styledText.setEditable(false);
    styledText.setBackground(UIUtils.getSystemColor(COLOR_WIDGET_BACKGROUND));
    final int[] ranges = { text.indexOf(link), link.length() };
    final StyleRange[] styles = { style };
    styledText.setStyleRanges(ranges, styles);

    styledText.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(final MouseEvent event) {
            try {
                final int offset = styledText.getOffsetAtLocation(new Point(event.x, event.y));
                final StyleRange actualStyle = styledText.getStyleRangeAtOffset(offset);
                if (null != actualStyle && actualStyle.underline
                        && UNDERLINE_LINK == actualStyle.underlineStyle) {

                    dialog.close();
                    final PreferenceDialog preferenceDialog = createPreferenceDialogOn(UIUtils.getShell(),
                            BinariesPreferencePage.ID, FILTER_IDS, null);

                    if (null != preferenceDialog) {
                        preferenceDialog.open();
                    }

                }
            } catch (final IllegalArgumentException e) {
                // We are not over the actual text.
            }
        }

    });

    return control;
}

From source file:org.dawnsci.plotting.system.dialog.ImageTraceComposite.java

License:Open Source License

/**
 * /*from   w  w  w .j  a va  2  s .c om*/
 * @param dialog
 * @param plottingSystem - may be null!
 * @param imageTrace
 */
public ImageTraceComposite(final Composite parent, final Dialog dialog, final IPlottingSystem plottingSystem,
        final IImageTrace imageTrace) {

    super(parent, SWT.NONE);
    this.imageTrace = imageTrace;

    setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    setLayout(new GridLayout(1, false));

    Label label;

    final Composite top = new Composite(this, SWT.NONE);
    top.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
    top.setLayout(new GridLayout(2, false));

    //      label = new Label(top, SWT.NONE);
    //      label.setText("Name");
    //      label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

    //      nameText = new Text(top, SWT.BORDER | SWT.SINGLE);
    //      nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));      
    //        nameText.setText(imageTrace.getName());

    final Group group = new Group(this, SWT.NONE);
    group.setText("Histogramming");
    group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
    group.setLayout(new GridLayout(2, false));

    final int dType = ((Dataset) imageTrace.getData()).getDtype();
    boolean isInt = dType == Dataset.INT16 || dType == Dataset.INT32 || dType == Dataset.INT64;

    label = new Label(group, SWT.NONE);
    label.setText("Minimum Intensity");
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

    Text minimumBox = new Text(group, SWT.BORDER);
    minimumBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    this.minimum = isInt ? new IntegerDecorator(minimumBox) : new FloatDecorator(minimumBox);

    label = new Label(group, SWT.NONE);
    label.setText("Maximum Intensity");
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

    Text maximumBox = new Text(group, SWT.BORDER);
    maximumBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    this.maximum = isInt ? new IntegerDecorator(maximumBox) : new FloatDecorator(maximumBox);

    maximum.setMaximum(imageTrace.getData().max().doubleValue());
    maximum.setMinimum(minimum);
    minimum.setMaximum(maximum);
    minimum.setMinimum(imageTrace.getData().min().doubleValue());

    Number min = imageTrace.getMin();
    Number max = imageTrace.getMax();
    if (min != null)
        minimum.setValue(min.doubleValue());
    if (max != null)
        maximum.setValue(max.doubleValue());

    label = new Label(group, SWT.NONE);
    label.setText("Downsampling Type");
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

    this.downsampleChoice = new CCombo(group, SWT.READ_ONLY | SWT.BORDER);
    downsampleChoice.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    for (DownsampleType ds : DownsampleType.values()) {
        downsampleChoice.add(ds.getLabel());
    }
    downsampleChoice.setToolTipText("The algorithm used when downsampling the full image for display.");
    downsampleChoice.select(imageTrace.getDownsampleType().getIndex());

    Label histolabel = new Label(group, SWT.NONE);
    histolabel.setText("Histogram Type");
    histolabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

    this.histoChoice = new CCombo(group, SWT.READ_ONLY | SWT.BORDER);
    histoChoice.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    for (HistoType ht : HistoType.values()) {
        histoChoice.add(ht.getLabel());
    }
    histoChoice.setToolTipText(
            "The algorithm used when histogramming the downsampled image.\nNOTE: median is much slower. If you change this, max and min will be recalculated.");
    histoChoice.select(imageTrace.getHistoType().getIndex());

    final Composite outlierComp = new Composite(group, SWT.NONE);
    outlierComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    outlierComp.setLayout(new GridLayout(2, false));

    histoChoice.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            HistoType type = HistoType.values()[histoChoice.getSelectionIndex()];
            if (imageTrace.getHistoType() != type) {
                imageTrace.setHistoType(type);
                maximum.setValue(imageTrace.getMax().doubleValue());
                minimum.setValue(imageTrace.getMin().doubleValue());
            }
            GridUtils.setVisible(outlierComp, type == HistoType.OUTLIER_VALUES);
            outlierComp.getParent().layout(new Control[] { outlierComp });
            layout();
            getParent().layout(new Control[] { ImageTraceComposite.this });
            getShell().layout();
        }
    });

    if (imageTrace.getData() instanceof RGBDataset) {
        histoChoice.setEnabled(false);
    }

    label = new Label(outlierComp, SWT.NONE);
    label.setText("Outlier low");
    label.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));

    Text lowBox = new Text(outlierComp, SWT.BORDER);
    lowBox.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    this.lo = new FloatDecorator(lowBox);
    if (imageTrace.getImageServiceBean() != null)
        lo.setValue(imageTrace.getImageServiceBean().getLo());
    lo.addValueChangeListener(new IValueChangeListener() {
        @Override
        public void valueValidating(ValueChangeEvent evt) {
            if (lo.isError())
                return;
            final double orig = imageTrace.getImageServiceBean().getLo();
            if (orig == evt.getValue().doubleValue())
                return;
            try {
                HistoType type = HistoType.values()[histoChoice.getSelectionIndex()];
                imageTrace.getImageServiceBean().setLo(evt.getValue().doubleValue());
                boolean ok = imageTrace.setHistoType(type);
                if (!ok)
                    throw new Exception("Histo not working!");
                getPreferenceStore().setValue(BasePlottingConstants.HISTO_LO, evt.getValue().doubleValue());
                maximum.setValue(imageTrace.getMax().doubleValue());
                minimum.setValue(imageTrace.getMin().doubleValue());

                IMacroService mservice = (IMacroService) PlottingSystemActivator
                        .getService(IMacroService.class);
                if (mservice != null) {
                    TraceMacroEvent mevt = new TraceMacroEvent(imageTrace);
                    mevt.append(mevt.getVarName() + ".getImageServiceBean().setLo("
                            + evt.getValue().doubleValue() + ")\n");
                    mevt.append(mevt.getVarName() + ".rehistogram()");
                    mservice.publish(mevt);
                }

            } catch (Throwable ne) {
                imageTrace.getImageServiceBean().setLo(orig);
            }
        }
    });

    label = new Label(outlierComp, SWT.NONE);
    label.setText("Outlier high");
    label.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));

    Text hiBox = new Text(outlierComp, SWT.BORDER);
    hiBox.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    this.hi = new FloatDecorator(hiBox);
    if (imageTrace.getImageServiceBean() != null)
        hi.setValue(imageTrace.getImageServiceBean().getHi());
    hi.addValueChangeListener(new IValueChangeListener() {
        @Override
        public void valueValidating(ValueChangeEvent evt) {
            if (hi.isError())
                return;
            final double orig = imageTrace.getImageServiceBean().getHi();
            if (orig == evt.getValue().doubleValue())
                return;
            try {
                HistoType type = HistoType.values()[histoChoice.getSelectionIndex()];
                imageTrace.getImageServiceBean().setHi(evt.getValue().doubleValue());
                boolean ok = imageTrace.setHistoType(type);
                if (!ok)
                    throw new Exception("Histo not working!");
                getPreferenceStore().setValue(BasePlottingConstants.HISTO_HI, evt.getValue().doubleValue());
                maximum.setValue(imageTrace.getMax().doubleValue());
                minimum.setValue(imageTrace.getMin().doubleValue());

                IMacroService mservice = (IMacroService) PlottingSystemActivator
                        .getService(IMacroService.class);
                if (mservice != null) {
                    TraceMacroEvent mevt = new TraceMacroEvent(imageTrace);
                    mevt.append(mevt.getVarName() + ".getImageServiceBean().setHi("
                            + evt.getValue().doubleValue() + ")\n");
                    mevt.append(mevt.getVarName() + ".rehistogram()");
                    mservice.publish(mevt);
                }

            } catch (Throwable ne) {
                imageTrace.getImageServiceBean().setHi(orig);
            }
        }
    });

    hi.setMaximum(99.999);
    hi.setMinimum(lo);
    lo.setMaximum(hi);
    lo.setMinimum(0.001);

    if (imageTrace.getData() instanceof RGBDataset) {
        histolabel.setEnabled(false);
        histoChoice.setEnabled(false);
        hiBox.setEnabled(false);
        lowBox.setEnabled(false);
    }

    GridUtils.setVisible(outlierComp, imageTrace.getHistoType() == HistoType.OUTLIER_VALUES);

    if (plottingSystem != null) {
        label = new Label(group, SWT.NONE);
        label.setText("Open histogram tool");
        label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

        final Button openHisto = new Button(group, SWT.NONE);
        openHisto.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
        openHisto.setImage(PlottingSystemActivator.getImage("icons/brightness_contrast.gif"));
        openHisto.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                dialog.close();
                try {
                    final IToolPageSystem system = (IToolPageSystem) plottingSystem
                            .getAdapter(IToolPageSystem.class);
                    system.setToolVisible("org.dawnsci.plotting.histogram.histogram_tool_page",
                            ToolPageRole.ROLE_2D, "org.dawb.workbench.plotting.views.toolPageView.2D");
                } catch (Exception e1) {
                    logger.error("Cannot show histogram tool programatically!", e1);
                }

            }
        });
    }

    final Group cuts = new Group(this, SWT.NONE);
    cuts.setText("Invalid Bounds");
    cuts.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
    cuts.setLayout(new GridLayout(3, false));

    label = new Label(cuts, SWT.NONE);
    label.setText("Lower cut");
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

    Text minCutBox = new Text(cuts, SWT.BORDER);
    minCutBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    this.minCut = isInt ? new IntegerDecorator(minCutBox) : new FloatDecorator(minCutBox);
    if (imageTrace.getMinCut() != null)
        minCut.setValue(imageTrace.getMinCut().getBound().doubleValue());
    minCut.setMaximum(minimum);
    minCut.setMinimum(Double.NEGATIVE_INFINITY);

    minCutColor = new ColorSelector(cuts);
    minCutColor.getButton().setLayoutData(new GridData());
    if (imageTrace.getMinCut() != null)
        minCutColor.setColorValue(ColorUtility.getRGB(imageTrace.getMinCut().getColor()));

    label = new Label(cuts, SWT.NONE);
    label.setText("Upper cut");
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

    final Text maxCutBox = new Text(cuts, SWT.BORDER);
    maxCutBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    this.maxCut = isInt ? new IntegerDecorator(maxCutBox) : new FloatDecorator(maxCutBox);
    if (imageTrace.getMaxCut() != null)
        maxCut.setValue(imageTrace.getMaxCut().getBound().doubleValue());

    maxCut.setMinimum(maximum);
    maxCut.setMaximum(Double.POSITIVE_INFINITY);

    maxCutColor = new ColorSelector(cuts);
    maxCutColor.getButton().setLayoutData(new GridData());
    if (imageTrace.getMaxCut() != null)
        maxCutColor.setColorValue(ColorUtility.getRGB(imageTrace.getMaxCut().getColor()));

    label = new Label(cuts, SWT.NONE);
    label.setText("Invalid number color");
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

    nanColor = new ColorSelector(cuts);
    nanColor.getButton().setLayoutData(new GridData());
    if (imageTrace.getNanBound() != null)
        nanColor.setColorValue(ColorUtility.getRGB(imageTrace.getNanBound().getColor()));

    final Button reset = new Button(cuts, SWT.NONE);
    reset.setLayoutData(new GridData());
    reset.setImage(PlottingSystemActivator.getImage("icons/reset.gif"));
    reset.setText("Reset");
    reset.setToolTipText("Reset cut bounds");
    reset.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            imageTrace.setMinCut(HistogramBound.DEFAULT_MINIMUM);
            imageTrace.setMaxCut(HistogramBound.DEFAULT_MAXIMUM);
            imageTrace.setNanBound(HistogramBound.DEFAULT_NAN);
            minCut.setValue(Double.NEGATIVE_INFINITY);
            minCutColor.setColorValue(ColorUtility.getRGB(HistogramBound.DEFAULT_MINIMUM.getColor()));
            maxCut.setValue(Double.POSITIVE_INFINITY);
            maxCutColor.setColorValue(ColorUtility.getRGB(HistogramBound.DEFAULT_MAXIMUM.getColor()));
            maxCutBox.setText(String.valueOf(Double.POSITIVE_INFINITY));
            nanColor.setColorValue(ColorUtility.getRGB(HistogramBound.DEFAULT_NAN.getColor()));
        }
    });

    final Group info = new Group(this, SWT.NONE);
    info.setText("Current downsample");
    info.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
    info.setLayout(new GridLayout(2, false));

    label = new Label(info, SWT.NONE);
    label.setText("Bin size");
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

    Label value = new Label(info, SWT.NONE);
    value.setText(imageTrace.getDownsampleBin() + "x" + imageTrace.getDownsampleBin() + " pixels");
    value.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));

    label = new Label(info, SWT.NONE);
    label.setText("Shape");
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    value = new Label(info, SWT.NONE);
    value.setText(Arrays.toString(imageTrace.getDownsampled().getShape()));
    value.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

}

From source file:org.ebayopensource.turmeric.eclipse.test.util.DefaultDialogProcessor.java

License:Open Source License

@Override
public void processDialog(Object dialog) {

    /**//from w w w.j  a va2s  . co m
     * If this is a ProgressMonitorDialog, then ignore. The
     * ProgressMonitorDialog does not block the UI from running.
     */
    if (dialog instanceof ProgressMonitorDialog) {
        return;
    }

    System.out.println("Processing dialog: " + dialog.getClass().getName());

    // Handle jface dialog
    if (dialog instanceof org.eclipse.jface.dialogs.Dialog) {
        org.eclipse.jface.dialogs.Dialog jfaceDialog = (org.eclipse.jface.dialogs.Dialog) dialog;
        jfaceDialog.close();
        return;
    }

    // Handle swt dialog
    if (dialog instanceof org.eclipse.swt.widgets.Dialog) {
        Assert.fail("org.eclipse.swt.widgets.Dialog is currently not supported");
        return;
    }

    // Handle dialogPage. These are typically some sort of wizard
    if (dialog instanceof DialogPage) {
        Assert.fail("DialogPage is currently not supported");
        return;
    }

}

From source file:org.eclipse.compare.tests.TextMergeViewerTest.java

License:Open Source License

private void runInDialog(Object input, Runnable runnable, final CompareConfiguration cc) throws Exception {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    Dialog dialog = new Dialog(shell) {
        protected Control createDialogArea(Composite parent) {
            Composite composite = (Composite) super.createDialogArea(parent);
            viewer = new TestMergeViewer(composite, cc);
            return composite;
        }//from  w  w  w.  j  ava  2 s .c o m
    };
    dialog.setBlockOnOpen(false);
    dialog.open();
    viewer.setInput(input);
    try {
        runnable.run();
    } catch (WrappedException e) {
        e.throwException();
    }
    dialog.close();
    viewer = null;
}

From source file:org.eclipse.emf.ecp.ecoreeditor.internal.ui.CreateNewChildDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parentComposite) {
    final ChildrenDescriptorCollector childrenDescriptorCollector = new ChildrenDescriptorCollector();
    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(parent);

    final Dialog currentDialog = this;
    final List<Action> actions = getNewChildActions(childrenDescriptorCollector.getDescriptors(parent),
            editingDomain, parent);/*from  w w w  . j a  v a2s  .com*/

    final TableViewer list = new TableViewer(parentComposite);
    list.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    list.setContentProvider(new ArrayContentProvider());
    list.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            final Action action = (Action) element;
            final StringBuilder builder = new StringBuilder(action.getText());
            if (action.getAccelerator() > 0) {
                builder.append(" [");
                builder.append(Character.toUpperCase((char) action.getAccelerator()));
                builder.append("]");
            }
            return builder.toString();
        }

        @Override
        public Image getImage(Object element) {
            return ((Action) element).getImageDescriptor().createImage();
        }
    });
    list.setInput(actions.toArray());
    list.addOpenListener(new IOpenListener() {

        @Override
        public void open(OpenEvent event) {
            final Action action = (Action) ((StructuredSelection) event.getSelection()).getFirstElement();
            action.run();
            currentDialog.close();
        }
    });
    list.getControl().addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
            // NOP
        }

        @Override
        public void keyPressed(KeyEvent e) {
            for (final Action a : actions) {
                if (a.getAccelerator() == e.keyCode) {
                    a.run();
                    currentDialog.close();
                    break;
                }
            }
        }
    });
    return parentComposite;
}

From source file:org.eclipse.jst.server.tomcat.ui.tests.UITestHelper.java

License:Open Source License

/**
 * Automated test that checks all the labels and buttons of a dialog
 * to make sure there is enough room to display all the text.  Any
 * text that wraps is only approximated and is currently not accurate.
 * //www . j  a  va2  s.co  m
 * @param dialog the test dialog to be verified.
 */
public static void assertDialog(Dialog dialog) {
    Assert.assertNotNull(dialog);
    dialog.setBlockOnOpen(false);
    dialog.open();
    Shell shell = dialog.getShell();
    verifyCompositeText(shell);
    dialog.close();
}

From source file:org.eclipse.m2e.integration.tests.InputHistoryTest.java

License:Open Source License

@Test
public void testInputHistory() {

    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            // open the dialog once, set values, close
            Dialog d = new Dialog(new Shell());
            d.open();// w w w.  j  ava2 s. c o m
            d.combo.setText(COMBO_TEXT);
            d.ccombo.setText(CCOMBO_TEXT);
            d.close();

            // open the dialog again, make sure the history is there
            d = new Dialog(new Shell());
            d.open();
            try {
                assertEquals("Combo default value", COMBO_TEXT, d.combo.getText());
                assertEquals("Combo history length", 1, d.combo.getItemCount());
                assertEquals("Combo history value", COMBO_TEXT, d.combo.getItem(0));
                assertEquals("CCombo default value", "", d.ccombo.getText());
                assertEquals("CCombo history length", 1, d.ccombo.getItemCount());
                assertEquals("CCombo history value", CCOMBO_TEXT, d.ccombo.getItem(0));

                d.combo.setText(COMBO_TEXT2);
                d.ccombo.setText(CCOMBO_TEXT2);
            } finally {
                d.close();
            }

            // open the dialog the third time, make sure the history is updated
            d = new Dialog(new Shell());
            d.open();
            try {
                assertEquals("Combo default value", COMBO_TEXT2, d.combo.getText());
                assertEquals("Combo history length", 2, d.combo.getItemCount());
                assertEquals("Combo history value (new)", COMBO_TEXT2, d.combo.getItem(0));
                assertEquals("Combo history value (old)", COMBO_TEXT, d.combo.getItem(1));
                assertEquals("CCombo default value", "", d.ccombo.getText());
                assertEquals("CCombo history length", 2, d.ccombo.getItemCount());
                assertEquals("CCombo history value (new)", CCOMBO_TEXT2, d.ccombo.getItem(0));
                assertEquals("CCombo history value (old)", CCOMBO_TEXT, d.ccombo.getItem(1));
            } finally {
                d.close();
            }
        }
    });
}

From source file:org.eclipse.n4js.ui.binaries.IllegalBinaryStateDialog.java

License:Open Source License

/**
 * Creates a control with some message and with link to the Binaries preference page.
 *
 * @param parent//from   w w  w . j  a  v  a  2s .c o  m
 *            the parent composite.
 * @param dialog
 *            the container dialog that has to be closed.
 * @param binary
 *            the binary with the illegal state.
 *
 * @return a control with error message and link that can be reused in dialogs.
 */
public static Control createCustomAreaWithLink(final Composite parent, final Dialog dialog,
        final Binary binary) {
    final String binaryLabel = binary.getLabel();
    final String prefix = "The requested operation cannot be performed due to invalid '" + binaryLabel
            + "' settings. Check your '" + binaryLabel
            + "' configuration and preferences under the corresponding ";
    final String link = "preference page";
    final String suffix = ".";
    final String text = prefix + link + suffix;

    final Composite control = new Composite(parent, NONE);
    control.setLayout(GridLayoutFactory.fillDefaults().create());
    final GridData gridData = GridDataFactory.fillDefaults().align(LEFT, TOP).grab(true, true).create();
    control.setLayoutData(gridData);

    final StyleRange style = new StyleRange();
    style.underline = true;
    style.underlineStyle = UNDERLINE_LINK;

    final StyledText styledText = new StyledText(control, MULTI | READ_ONLY | WRAP);
    styledText.setWordWrap(true);
    styledText.setJustify(true);
    styledText.setText(text);
    final GridData textGridData = GridDataFactory.fillDefaults().align(FILL, FILL).grab(true, true).create();
    textGridData.widthHint = TEXT_WIDTH_HINT;
    textGridData.heightHint = TEXT_HEIGHT_HINT;
    styledText.setLayoutData(textGridData);

    styledText.setEditable(false);
    styledText.setBackground(UIUtils.getSystemColor(COLOR_WIDGET_BACKGROUND));
    final int[] ranges = { text.indexOf(link), link.length() };
    final StyleRange[] styles = { style };
    styledText.setStyleRanges(ranges, styles);

    styledText.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(final MouseEvent event) {
            try {
                final int offset = styledText.getOffsetAtPoint(new Point(event.x, event.y));
                final StyleRange actualStyle = offset >= 0 ? styledText.getStyleRangeAtOffset(offset) : null;
                if (null != actualStyle && actualStyle.underline
                        && UNDERLINE_LINK == actualStyle.underlineStyle) {

                    dialog.close();
                    final PreferenceDialog preferenceDialog = createPreferenceDialogOn(UIUtils.getShell(),
                            BinariesPreferencePage.ID, FILTER_IDS, null);

                    if (null != preferenceDialog) {
                        preferenceDialog.open();
                    }

                }
            } catch (final IllegalArgumentException e) {
                // We are not over the actual text.
            }
        }

    });

    return control;
}

From source file:org.eclipse.nebula.widgets.treemapper.tests.ProgrammaticTest.java

License:Open Source License

@Test
public void testBug365445_ok() {
    final String a = "a", b = "b", c = "c";
    final String[] treeContent = new String[] { a, b, c };
    final String[] mappings = new String[] { a, b, c };
    Dialog dialog = openMapperDialog(treeContent, mappings);
    dialog.close();
}