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

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

Introduction

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

Prototype

protected Dialog(IShellProvider parentShell) 

Source Link

Document

Creates a dialog with the given parent.

Usage

From source file:eu.udig.imagegeoreferencing.DeleteImageTool.java

License:Open Source License

/**
 * Show a dialog with the error explaining why the delete would not process
 *//*from  w  ww  .  j a v  a 2 s  . c  om*/
private int showDialog(final boolean error) {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    final Dialog dialog = new Dialog(shell) {
        @Override
        protected Control createDialogArea(Composite parent) {
            Composite container = (Composite) super.createDialogArea(parent);
            GridLayout layout = new GridLayout(1, true);
            container.setLayout(layout);
            GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
            layoutData.widthHint = 450;
            container.setLayoutData(layoutData);

            Label descLabel = new Label(container, SWT.WRAP);
            if (error) {
                descLabel.setText(Messages.DeleteDialog_errordesc);
            } else {
                descLabel.setText(Messages.DeleteDialog_desc);
            }
            layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
            layoutData.verticalSpan = 1;
            layoutData.horizontalSpan = 1;
            descLabel.setLayoutData(layoutData);

            return container;
        }

        @Override
        protected void configureShell(Shell newShell) {
            super.configureShell(newShell);
            newShell.setText(Messages.DeleteDialog_title);
            GridLayout layout = new GridLayout();
            layout.numColumns = 1;
            newShell.setLayout(layout);
        }
    };
    dialog.setBlockOnOpen(true);
    int result = dialog.open();
    return result;
}

From source file:eu.udig.imagegeoreferencing.LoadImageTool.java

License:Open Source License

/**
 * Show the error dialog/*from  w  w w.  ja va 2s  . c  om*/
 */
private void showErrorDialog() {
    try {
        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        final Dialog dialog = new Dialog(shell) {
            @Override
            protected Control createDialogArea(Composite parent) {
                Composite container = (Composite) super.createDialogArea(parent);
                GridLayout layout = new GridLayout(1, true);
                container.setLayout(layout);
                GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
                layoutData.widthHint = 450;
                container.setLayoutData(layoutData);

                Label descLabel = new Label(container, SWT.WRAP);
                descLabel.setText(Messages.LoadImageError_desc);
                layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
                layoutData.verticalSpan = 1;
                layoutData.horizontalSpan = 1;
                descLabel.setLayoutData(layoutData);

                return container;
            }

            @Override
            protected void configureShell(Shell newShell) {
                super.configureShell(newShell);
                newShell.setText(Messages.LoadImageError_title);
                GridLayout layout = new GridLayout();
                layout.numColumns = 1;
                newShell.setLayout(layout);
            }
        };
        dialog.setBlockOnOpen(true);
        dialog.open();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:eu.udig.imagegeoreferencing.WarpImageTool.java

License:Open Source License

/**
 * Show a dialog with the error explaining why the warp would not process
 */// www  .  j  a v  a 2  s  . c o m
private void showErrorDialog() {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    final Dialog dialog = new Dialog(shell) {
        @Override
        protected Control createDialogArea(Composite parent) {
            Composite container = (Composite) super.createDialogArea(parent);
            GridLayout layout = new GridLayout(1, true);
            container.setLayout(layout);
            GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
            layoutData.widthHint = 450;
            container.setLayoutData(layoutData);

            Label descLabel = new Label(container, SWT.WRAP);
            descLabel
                    .setText(MessageFormat.format(Messages.WarpDialog_desc, PlaceMarkersTool.MIN_PLACEMARKERS));
            layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
            layoutData.verticalSpan = 1;
            layoutData.horizontalSpan = 1;
            descLabel.setLayoutData(layoutData);

            return container;
        }

        @Override
        protected void configureShell(Shell newShell) {
            super.configureShell(newShell);
            newShell.setText(Messages.WarpDialog_title);
            GridLayout layout = new GridLayout();
            layout.numColumns = 1;
            newShell.setLayout(layout);
        }
    };
    dialog.setBlockOnOpen(true);
    dialog.open();
}

From source file:eu.udig.omsbox.ui.CoverageChooserDialog.java

License:Open Source License

public void open(Shell parentShell, final int selectionType) {

    dialog = new Dialog(parentShell) {

        @Override//  ww  w .  j a  va2  s .  co m
        protected void configureShell(Shell shell) {
            super.configureShell(shell);
            shell.setText("");
        }

        @Override
        protected Point getInitialSize() {
            return new Point(320, 450);
        }

        @Override
        protected Control createDialogArea(Composite parent) {
            parentPanel = (Composite) super.createDialogArea(parent);
            GridLayout gLayout = (GridLayout) parentPanel.getLayout();
            gLayout.numColumns = 1;
            active = new CoverageLayersTreeViewer(parentPanel, SWT.BORDER, selectionType);
            makeCheckPanel();
            return parentPanel;
        }

        @Override
        protected void buttonPressed(int buttonId) {
            if (buttonId == OK) {
                resourcesList = active.getSelectedResources();
            } else {
                resourcesList = null;
            }
            super.buttonPressed(buttonId);
        }
    };
    dialog.setBlockOnOpen(true);
    dialog.open();
}

From source file:eu.udig.omsbox.ui.RunningProcessListDialog.java

License:Open Source License

public void open(Shell parentShell, final int selectionType) {

    runningProcessesMap = OmsBoxPlugin.getDefault().getRunningProcessesMap();

    dialog = new Dialog(parentShell) {

        @Override/*from   w w  w  . j av a2 s .  c om*/
        protected void configureShell(Shell shell) {
            super.configureShell(shell);
            shell.setText("Kill selected process"); //$NON-NLS-1$
        }

        @Override
        protected Point getInitialSize() {
            return new Point(640, 450);
        }

        @Override
        protected Control createDialogArea(Composite parent) {
            Composite parentPanel = (Composite) super.createDialogArea(parent);
            GridLayout gLayout = (GridLayout) parentPanel.getLayout();
            gLayout.numColumns = 1;

            createTableViewer(parentPanel);

            return parentPanel;
        }

        @Override
        protected void buttonPressed(int buttonId) {
            if (buttonId == OK) {
                OmsBoxPlugin.getDefault().killProcess(currentSelectedProcessId);
            }
            super.buttonPressed(buttonId);
        }
    };
    dialog.setBlockOnOpen(true);
    dialog.open();
}

From source file:eu.udig.omsbox.ui.SettingsDialog.java

License:Open Source License

public void open(Shell parentShell, final int selectionType) {

    resourcesList = new ArrayList<String>();

    String[] retrieveSavedJars = OmsBoxPlugin.getDefault().retrieveSavedJars();
    for (String jarPath : retrieveSavedJars) {
        resourcesList.add(jarPath);/*from  w w  w  .ja va 2s  .  c  om*/
    }

    dialog = new Dialog(parentShell) {

        @Override
        protected void configureShell(Shell shell) {
            super.configureShell(shell);
            shell.setText(""); //$NON-NLS-1$
        }

        @Override
        protected Point getInitialSize() {
            return new Point(640, 450);
        }

        @Override
        protected Control createDialogArea(Composite parent) {
            Composite parentPanel = (Composite) super.createDialogArea(parent);

            final TabFolder tabFolder = new TabFolder(parentPanel, SWT.BORDER);
            GridData tabFolderGD = new GridData(SWT.FILL, SWT.FILL, true, true);
            tabFolder.setLayoutData(tabFolderGD);

            TabItem librariesTabItem = new TabItem(tabFolder, SWT.NULL);
            librariesTabItem.setText("Modules Libraries ");
            Composite librariesPanel = new Composite(tabFolder, SWT.NONE);
            librariesPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
            librariesPanel.setLayout(new GridLayout(2, true));
            createTableViewer(librariesPanel);
            createAddRemoveButtons(librariesPanel);
            librariesTabItem.setControl(librariesPanel);

            TabItem grassTabItem = new TabItem(tabFolder, SWT.NULL);
            grassTabItem.setText("Grass settings");
            Composite grassPanel = new Composite(tabFolder, SWT.NONE);
            grassPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
            grassPanel.setLayout(new GridLayout(1, false));
            grassTabItem.setControl(grassPanel);

            createGrassPanel(grassPanel);

            return parentPanel;
        }

        @Override
        protected void buttonPressed(int buttonId) {
            if (buttonId == OK) {
                OmsBoxPlugin.getDefault().saveJars(resourcesList);
                cancelPressed = false;
            } else {
                cancelPressed = true;
            }
            super.buttonPressed(buttonId);
        }
    };
    dialog.setBlockOnOpen(true);
    dialog.open();
}

From source file:eu.udig.omsbox.view.widgets.GuiTextField.java

License:Open Source License

@Override
public Control makeGui(Composite parent) {
    int cols = 1;
    if (isInFile || isInFolder || isOutFile || isOutFolder || isCrs || isMultiline) {
        cols = 2;//  w ww .  ja v a2  s  . c om
    }

    final boolean isFile = isInFile || isOutFile;
    final boolean isFolder = isInFolder || isOutFolder;

    parent = new Composite(parent, SWT.NONE);
    parent.setLayoutData(constraints);
    GridLayout layout = new GridLayout(cols, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    parent.setLayout(layout);

    if (!isMultiline) {
        text = new StyledText(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
        GridData textGD = new GridData(SWT.FILL, SWT.CENTER, true, false);
        textGD.widthHint = 100;
        text.setLayoutData(textGD);
    } else if (isMapcalc) {
        text = MapcalculatorUtils.createMapcalcPanel(parent, rows);
    } else {
        text = new StyledText(parent, SWT.MULTI | SWT.WRAP | SWT.LEAD | SWT.BORDER | SWT.V_SCROLL);
        GridData textGD = new GridData(SWT.FILL, SWT.FILL, true, true);
        textGD.verticalSpan = rows;
        textGD.widthHint = 100;
        text.setLayoutData(textGD);
    }
    if (data.fieldValue != null) {
        data.fieldValue = checkBackSlash(data.fieldValue, isFile);
        text.setText(data.fieldValue);
    }
    text.addModifyListener(this);
    text.addFocusListener(this);

    if (isMultiline) {
        for (int i = 0; i < rows; i++) {
            Label dummyLabel = new Label(parent, SWT.NONE);
            dummyLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
            // dummyLabel.setText("");

        }
    }

    if (isFile) {
        final Button browseButton = new Button(parent, SWT.PUSH);
        browseButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
        browseButton.setText("...");
        browseButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                FileDialog fileDialog = new FileDialog(text.getShell(), isInFile ? SWT.OPEN : SWT.SAVE);
                String lastFolderChosen = OmsBoxPlugin.getDefault().getLastFolderChosen();
                fileDialog.setFilterPath(lastFolderChosen);
                String path = fileDialog.open();

                if (path == null || path.length() < 1) {
                    text.setText("");
                } else {
                    path = checkBackSlash(path, isFile);
                    text.setText(path);
                    setDataValue();
                }
                OmsBoxPlugin.getDefault().setLastFolderChosen(fileDialog.getFilterPath());
            }
        });
    }

    if (isFolder) {
        final Button browseButton = new Button(parent, SWT.PUSH);
        browseButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
        browseButton.setText("...");
        browseButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                DirectoryDialog directoryDialog = new DirectoryDialog(text.getShell(),
                        isInFolder ? SWT.OPEN : SWT.SAVE);
                String lastFolderChosen = OmsBoxPlugin.getDefault().getLastFolderChosen();
                directoryDialog.setFilterPath(lastFolderChosen);
                String path = directoryDialog.open();

                if (path == null || path.length() < 1) {
                    text.setText("");
                } else {
                    path = checkBackSlash(path, isFile);
                    text.setText(path);
                    setDataValue();
                }
                OmsBoxPlugin.getDefault().setLastFolderChosen(directoryDialog.getFilterPath());
            }
        });
    }
    if (isCrs) {
        // the crs choice group
        final Button crsButton = new Button(parent, SWT.BORDER);
        crsButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
        crsButton.setText("..."); //$NON-NLS-1$
        crsButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {

            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                Shell shell = new Shell(text.getShell(), SWT.SHELL_TRIM);
                Dialog dialog = new Dialog(shell) {

                    private CRSChooser chooser;
                    private CoordinateReferenceSystem crs;

                    @Override
                    protected void configureShell(Shell shell) {
                        super.configureShell(shell);
                        shell.setText("Choose CRS");
                    }

                    @Override
                    protected Control createDialogArea(Composite parent) {
                        Composite comp = (Composite) super.createDialogArea(parent);
                        GridLayout gLayout = (GridLayout) comp.getLayout();

                        gLayout.numColumns = 1;

                        chooser = new CRSChooser(new Controller() {

                            public void handleClose() {
                                buttonPressed(OK);
                            }

                            public void handleOk() {
                                buttonPressed(OK);
                            }

                        });

                        return chooser.createControl(parent);
                    }

                    @Override
                    protected void buttonPressed(int buttonId) {
                        if (buttonId == OK) {
                            crs = chooser.getCRS();

                            try {
                                String codeFromCrs = OmsBoxUtils.getCodeFromCrs(crs);
                                text.setText(codeFromCrs);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }

                        }
                        close();
                    }

                };

                dialog.setBlockOnOpen(true);
                dialog.open();
            }
        });

        // initially set to map's crs
        IMap activeMap = ApplicationGIS.getActiveMap();
        if (activeMap != null) {
            try {
                CoordinateReferenceSystem crs = activeMap.getViewportModel().getCRS();
                String codeFromCrs = OmsBoxUtils.getCodeFromCrs(crs);
                text.setText(codeFromCrs);
                setDataValue();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    if (isNorthing || isEasting || isEastingNorthing) {
        addMapMouseListener();
    }

    if (isProcessing()) {
        addRegionListener();
        ILayer processingRegionLayer = OmsBoxPlugin.getDefault().getProcessingRegionMapGraphic();
        IStyleBlackboard blackboard = processingRegionLayer.getStyleBlackboard();
        Object object = blackboard.get(ProcessingRegionStyleContent.ID);
        if (object instanceof ProcessingRegionStyle) {
            ProcessingRegionStyle processingStyle = (ProcessingRegionStyle) object;
            setRegion(processingStyle);
        }
    }

    text.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            if (isNorthing || isEasting || isEastingNorthing) {
                removeMapMouseListener();
            }
            if (isProcessing()) {
                removeRegionListener();
            }
        }
    });

    addDrop();

    return text;
}

From source file:net.refractions.udig.tools.edit.EditBlackboardUtil.java

License:Open Source License

public static void openDataChangedDialog(final ILayer layer, final Envelope dirtyArea) {
    Display d = Display.getCurrent();//from   ww  w  .  jav a2s  . c om
    if (d == null)
        d = Display.getDefault();

    Condition condition = blackboardLock.newCondition();
    try {
        blackboardLock.lock();
        if (dialog != null) {
            // we're in the display thread, which means that the viewport is repainting since the dialog has any other input blocked.
            // so just return
            if (Display.getCurrent() != null)
                return;
            // the issue is being resolved we should wait for it to be resolved.
            while (dialog != null) {
                try {
                    condition.await(500, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                    return;
                }
            }
            return;
        }
    } finally {
        blackboardLock.unlock();
    }

    PlatformGIS.syncInDisplayThread(d, new Runnable() {
        public void run() {
            try {
                blackboardLock.lock();
                if (dirtyAreas.get(layer) == null)
                    return;

                dialog = new Dialog(Display.getCurrent().getActiveShell()) {
                    private final int UPDATE = 1;
                    private final int CLEAR = 2;
                    private final int IGNORE = 3;

                    public Control createDialogArea(Composite parent) {
                        Composite comp = new Composite(parent, SWT.NONE);
                        comp.setLayout(new GridLayout(2, false));
                        Display display = Display.getCurrent();
                        Label label = new Label(comp, SWT.NONE);
                        label.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
                        label.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
                        label.setImage(Dialog.getImage(Dialog.DLG_IMG_WARNING));

                        label.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
                        Text text = new Text(comp, SWT.WRAP | SWT.READ_ONLY);
                        text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                        text.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
                        text.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
                        text.setText(Messages.EditBlackboardUtil_data_changed);
                        return comp;
                    }

                    public void createButtonsForButtonBar(Composite composite) {
                        createButton(composite, UPDATE, Messages.EditBlackboardUtil_update, false);
                        createButton(composite, CLEAR, Messages.EditBlackboardUtil_clear, true);
                        createButton(composite, IGNORE, Messages.EditBlackboardUtil_ignore, false);
                    }

                    public void buttonPressed(int button) {
                        switch (button) {
                        case UPDATE: {
                            boolean ok = MessageDialog.openConfirm(getParentShell(),
                                    Messages.EditBlackboardUtil_Update_Selection,
                                    Messages.EditBlackboardUtil_update_selection_confirmation);
                            if (ok) {
                                try {
                                    ProgressMonitorDialog d = new ProgressMonitorDialog(this.getParentShell());

                                    blackboardLock.unlock();
                                    d.run(false, false, new IRunnableWithProgress() {
                                        public void run(IProgressMonitor monitor) {
                                            updateFeatures(layer, monitor, dirtyArea);
                                        }
                                    });
                                    okPressed();
                                } catch (Exception e) {
                                    EditPlugin.log("", e); //$NON-NLS-1$
                                }
                            }
                            break;
                        }
                        case CLEAR: {
                            boolean ok = MessageDialog.openConfirm(getParentShell(),
                                    Messages.EditBlackboardUtil_clear_selection,
                                    Messages.EditBlackboardUtil_changes_will_be_lost);
                            if (ok) {
                                blackboardLock.unlock();
                                (getEditBlackBoardFromLayer(layer)).clear();
                                layer.getMap().getBlackboard().put(EditToolHandler.CURRENT_SHAPE, null);
                                ((EditManager) layer.getMap().getEditManager()).setEditFeature(null, null);
                                okPressed();
                            }
                            break;
                        }
                        case IGNORE:
                            boolean ok = MessageDialog.openConfirm(getParentShell(),
                                    Messages.EditBlackboardUtil_ignore_change,
                                    Messages.EditBlackboardUtil_changes_will_be_overwritten);
                            if (ok) {
                                okPressed();
                            }
                            break;

                        default:
                            cancelPressed();
                            break;
                        }
                    }

                    public void okPressed() {
                        dirtyAreas.remove(layer);
                        super.okPressed();
                    }
                };
                dialog.setBlockOnOpen(true);
                dialog.open();
            } finally {
                blackboardLock.unlock();
                dialog = null;
            }

        }
    });
}

From source file:net.refractions.udig.validation.ValidateNullZero.java

License:Open Source License

/**public for testing purposes only*/
public @Override Dialog getDialog(Shell shell, final SimpleFeatureType featureType) {
    if (featureType.getAttributeCount() == 0) {
        return null;
    }/*  w w  w  .ja  va2 s  . c o m*/
    final Dialog dialog = new Dialog(shell) {

        @Override
        protected Control createDialogArea(Composite parent) {
            Composite composite = (Composite) super.createDialogArea(parent);
            combo = new Combo(composite, SWT.DEFAULT);
            for (int i = 0; i < featureType.getAttributeCount(); i++) {
                combo.add(featureType.getDescriptor(i).getName().getLocalPart());
            }
            combo.addModifyListener(new ModifyListener() {

                public void modifyText(ModifyEvent e) {
                    setXpath(combo);
                }

            });
            combo.addSelectionListener(new SelectionListener() {

                public void widgetSelected(SelectionEvent e) {
                    setXpath(combo);
                }

                public void widgetDefaultSelected(SelectionEvent e) {
                    widgetSelected(e);
                    okPressed();
                }

            });
            combo.select(0);
            xPath = featureType.getDescriptor(0).getName().getLocalPart();
            return composite;
        }

        @Override
        protected void okPressed() {
            super.okPressed();
        }
    };
    return dialog;
}

From source file:org.bonitasoft.studio.tests.draw2d.TestLifeCycleWidget.java

License:Open Source License

private void testSelectionEvent(final String eventType, final ConnectorEvent eventTypeThatShouldBeselected,
        final int taskLifeCycle) {

    UIThreadRunnable.syncExec(new VoidResult() {
        public void run() {
            Dialog dialog = new Dialog(Display.getDefault().getActiveShell()) {
                @Override//from  w w  w .  j a v  a 2 s  . c o m
                protected Control createDialogArea(Composite parent) {
                    Control superParent = super.createDialogArea(parent);

                    lcw = new LifeCycleWidget(parent, eventType, null);
                    return superParent;
                }

                @Override
                protected void configureShell(Shell newShell) {
                    super.configureShell(newShell);
                    newShell.setText("Test Life cycle widget: " + eventType + eventTypeThatShouldBeselected
                            + taskLifeCycle);
                }
            };
            dialog.setBlockOnOpen(false);
            dialog.open();
            bot.waitUntil(Conditions.shellIsActive(
                    "Test Life cycle widget: " + eventType + eventTypeThatShouldBeselected + taskLifeCycle),
                    10000);
            bot.button(IDialogConstants.CANCEL_LABEL).click();
        }
    });

    final String eventTypeTheoric = eventTypeThatShouldBeselected.toString();
    for (EventCircle eventCircle : lcw.getEventFigures()) {
        final String event = eventCircle.getEvent();
        if (event.equals(eventTypeTheoric)) {
            assertEquals("The event circle" + event + " should be selected",
                    eventCircle.getLocalForegroundColor().getRed(), 73);
        } else {
            assertEquals("The event circle" + event + " should not be selected",
                    eventCircle.getLocalForegroundColor().getRed(), 235);
        }
    }

    bot.waitUntil(Conditions.shellIsActive("Bonita BPM"));

}