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

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

Introduction

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

Prototype

public int open() 

Source Link

Document

Opens this window, creating it first if it has not yet been created.

Usage

From source file:org.eclipse.ui.tests.harness.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.
 * //w  w  w  .  ja  v a2 s  .c  om
 * @param dialog the test dialog to be verified.
 * @param assert this is the test case object, assertions will be
 * executed on this object.
 */
public static void assertDialogTexts(Dialog dialog, Assert assertion) {
    Assert.assertNotNull(dialog);
    dialog.setBlockOnOpen(false);
    dialog.open();
    Shell shell = dialog.getShell();
    verifyCompositeText(shell, assertion);
    dialog.close();
}

From source file:org.eclipse.ui.tests.leaks.LeakTests.java

License:Open Source License

/**
 * Test for leaks if dialog is disposed before it is closed.
 * This is really testing the framework rather than individual
 * dialogs, since many dialogs or windows will fail if the shell
 * is destroyed prior to closing them./*from   www  .ja  v a2 s.co m*/
 * See bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=123296
 */
public void testDestroyedDialogLeaks() throws Exception {
    ReferenceQueue queue = new ReferenceQueue();
    // Use SaveAs dialog because it's simple to invoke and utilizes
    // framework function such as storing dialog bounds.  
    // We are really testing the framework itself here.
    Dialog newDialog = new SaveAsDialog(fWin.getShell());
    newDialog.setBlockOnOpen(false);
    newDialog.open();
    assertNotNull(newDialog);
    Reference ref = createReference(queue, newDialog);
    try {
        // Dispose the window before closing it.  
        newDialog.getShell().dispose();
        newDialog.close();
        newDialog = null;
        checkRef(queue, ref);
    } finally {
        ref.clear();
    }
}

From source file:org.eclipse.ui.texteditor.ChangeEncodingAction.java

License:Open Source License

public void run() {
    final IResource resource = getResource();
    final Shell parentShell = getTextEditor().getSite().getShell();
    final IEncodingSupport encodingSupport = getEncodingSupport();
    if (resource == null && encodingSupport == null) {
        MessageDialog.openInformation(parentShell, fDialogTitle,
                TextEditorMessages.ChangeEncodingAction_message_noEncodingSupport);
        return;/*from www .  j  a v  a  2s. co  m*/
    }

    Dialog dialog = new Dialog(parentShell) {
        private AbstractEncodingFieldEditor fEncodingEditor;
        private IPreferenceStore store = null;

        /*
         * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
         */
        protected void configureShell(Shell newShell) {
            super.configureShell(newShell);
            newShell.setText(fDialogTitle);
        }

        /*
         * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
         */
        protected Control createDialogArea(Composite parent) {
            Composite composite = (Composite) super.createDialogArea(parent);

            composite = new Composite(composite, SWT.NONE);
            GridLayout layout = new GridLayout();
            layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
            layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
            layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
            layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
            composite.setLayout(layout);

            GridData data = new GridData(GridData.FILL_BOTH);
            composite.setLayoutData(data);
            composite.setFont(parent.getFont());

            DialogPage page = new MessageDialogPage(composite) {
                public void setErrorMessage(String newMessage) {
                    super.setErrorMessage(newMessage);
                    setButtonEnabledState(IDialogConstants.OK_ID, newMessage == null);
                    setButtonEnabledState(APPLY_ID, newMessage == null);
                }

                private void setButtonEnabledState(int id, boolean state) {
                    Button button = getButton(id);
                    if (button != null)
                        button.setEnabled(state);
                }
            };

            if (resource != null) {
                fEncodingEditor = new ResourceEncodingFieldEditor("", composite, resource, null); //$NON-NLS-1$
                fEncodingEditor.setPage(page);
                fEncodingEditor.load();
            } else {
                fEncodingEditor = new EncodingFieldEditor(ENCODING_PREF_KEY, "", null, composite); //$NON-NLS-1$
                store = new PreferenceStore();
                String defaultEncoding = encodingSupport.getDefaultEncoding();
                store.setDefault(ENCODING_PREF_KEY, defaultEncoding);
                String encoding = encodingSupport.getEncoding();
                if (encoding != null)
                    store.setValue(ENCODING_PREF_KEY, encoding);
                fEncodingEditor.setPreferenceStore(store);

                fEncodingEditor.setPage(page);
                fEncodingEditor.load();

                if (encoding == null || encoding.equals(defaultEncoding) || encoding.length() == 0)
                    fEncodingEditor.loadDefault();
            }

            return composite;
        }

        /*
         * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
         */
        protected void createButtonsForButtonBar(Composite parent) {
            createButton(parent, APPLY_ID, TextEditorMessages.ChangeEncodingAction_button_apply_label, false);
            super.createButtonsForButtonBar(parent);
        }

        /*
         * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
         */
        protected void buttonPressed(int buttonId) {
            if (buttonId == APPLY_ID)
                apply();
            else
                super.buttonPressed(buttonId);
        }

        /*
         * @see org.eclipse.jface.dialogs.Dialog#okPressed()
         */
        protected void okPressed() {
            apply();
            super.okPressed();
        }

        private void apply() {
            fEncodingEditor.store();

            if (resource == null) {
                String encoding = fEncodingEditor.getPreferenceStore()
                        .getString(fEncodingEditor.getPreferenceName());
                encodingSupport.setEncoding(encoding);
            }
        }
    };
    dialog.open();
}

From source file:org.eclipse.ui.views.markers.internal.ActionResolveMarker.java

License:Open Source License

/**
 * Displays a list of resolutions and performs the selection.
 *//*from   w w  w  .  jav a2s. com*/
public void run() {

    IRunnableContext context = new ProgressMonitorDialog(view.getSite().getShell());
    final Object[] resolutions = new Object[1];

    IRunnableWithProgress resolutionsRunnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            monitor.beginTask(
                    NLS.bind(MarkerMessages.resolveMarkerAction_computationAction, getMarkerDescription()),
                    100);
            monitor.worked(25);
            resolutions[0] = IDE.getMarkerHelpRegistry().getResolutions(getSelectedMarker());
            monitor.done();
        }
    };

    Object service = view.getSite().getAdapter(IWorkbenchSiteProgressService.class);

    try {
        if (service == null) {
            PlatformUI.getWorkbench().getProgressService().runInUI(context, resolutionsRunnable, null);
        } else {
            ((IWorkbenchSiteProgressService) service).runInUI(context, resolutionsRunnable, null);
        }
    } catch (InvocationTargetException exception) {
        handleException(exception);
        return;
    } catch (InterruptedException exception) {
        handleException(exception);
        return;
    }

    IMarkerResolution[] foundResolutions = (IMarkerResolution[]) resolutions[0];
    if (foundResolutions.length == 0)
        MessageDialog.openInformation(view.getSite().getShell(),
                MarkerMessages.MarkerResolutionDialog_CannotFixTitle,
                NLS.bind(MarkerMessages.MarkerResolutionDialog_CannotFixMessage, getMarkerDescription()));
    else {
        Dialog dialog = new MarkerResolutionDialog(view.getSite().getShell(), getSelectedMarker(),
                foundResolutions, view);
        dialog.open();
    }

}

From source file:org.eclipse.ui.views.markers.internal.MarkerView.java

License:Open Source License

/**
 * Open a dialog to set the preferences.
 * //from w  ww .  j  a  va 2  s . com
 * @param markerEnablementPreferenceName
 * @param markerLimitPreferenceName
 */
private void openPreferencesDialog(String markerEnablementPreferenceName, String markerLimitPreferenceName) {

    Dialog dialog = new MarkerViewPreferenceDialog(getSite().getWorkbenchWindow().getShell(),
            markerEnablementPreferenceName, markerLimitPreferenceName,
            MarkerMessages.MarkerPreferences_DialogTitle);
    if (dialog.open() == Window.OK) {
        refreshViewer();
    }

}

From source file:org.eclipse.wst.css.ui.internal.edit.ui.CleanupActionCSSDelegate.java

License:Open Source License

public void run(IAction action) {
    if (fEditor instanceof ITextEditor) {
        final ITextEditor editor = (ITextEditor) fEditor;
        Dialog cleanupDialog = new CleanupDialogCSS(editor.getSite().getShell());
        if (cleanupDialog.open() == Window.OK) {
            // setup runnable
            Runnable runnable = new Runnable() {
                public void run() {
                    IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
                    if (cleanupProcessor != null) {
                        IStructuredModel model = null;
                        try {
                            model = StructuredModelManager.getModelManager().getExistingModelForEdit(
                                    editor.getDocumentProvider().getDocument(editor.getEditorInput()));
                            if (model != null)
                                cleanupProcessor.cleanupModel(model);
                        } finally {
                            if (model != null)
                                model.releaseFromEdit();
                        }//  www .j a  v  a  2 s.co  m
                    }
                }
            };

            // TODO: make independent of 'model'.
            IStructuredModel model = null;
            try {
                model = StructuredModelManager.getModelManager().getExistingModelForEdit(
                        editor.getDocumentProvider().getDocument(editor.getEditorInput()));
                if (model != null) {
                    // begin recording
                    ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
                    model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_,
                            SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength()); //$NON-NLS-1$ //$NON-NLS-2$

                    // tell the model that we are about to make a big
                    // model change
                    model.aboutToChangeModel();

                    // run
                    BusyIndicator.showWhile(
                            fEditor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable);
                }
            } finally {
                if (model != null) {
                    // tell the model that we are done with the big
                    // model
                    // change
                    model.changedModel();

                    // end recording
                    ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
                    model.endRecording(this, selection.getOffset(), selection.getLength());
                    model.releaseFromEdit();
                }
            }
        }
    }
}

From source file:org.eclipse.wst.css.ui.internal.handlers.CleanupDocumentHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
    ITextEditor textEditor = null;//from   w w w .  ja  va  2s.  com
    if (editorPart instanceof ITextEditor)
        textEditor = (ITextEditor) editorPart;
    else {
        Object o = editorPart.getAdapter(ITextEditor.class);
        if (o != null)
            textEditor = (ITextEditor) o;
    }

    if (textEditor != null) {
        final ITextEditor editor = textEditor;
        Dialog cleanupDialog = new CleanupDialogCSS(editor.getSite().getShell());
        if (cleanupDialog.open() == Window.OK) {
            // setup runnable
            Runnable runnable = new Runnable() {
                public void run() {
                    IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
                    if (cleanupProcessor != null) {
                        IStructuredModel model = null;
                        try {
                            model = StructuredModelManager.getModelManager().getExistingModelForEdit(
                                    editor.getDocumentProvider().getDocument(editor.getEditorInput()));
                            if (model != null)
                                cleanupProcessor.cleanupModel(model);
                        } finally {
                            if (model != null)
                                model.releaseFromEdit();
                        }
                    }
                }
            };

            // TODO: make independent of 'model'.
            IStructuredModel model = null;
            try {
                model = StructuredModelManager.getModelManager().getExistingModelForEdit(
                        editor.getDocumentProvider().getDocument(editor.getEditorInput()));
                if (model != null) {
                    // begin recording
                    ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
                    model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_,
                            SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength()); //$NON-NLS-1$ //$NON-NLS-2$

                    // tell the model that we are about to make a big
                    // model change
                    model.aboutToChangeModel();

                    // run
                    BusyIndicator.showWhile(editor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(),
                            runnable);
                }
            } finally {
                if (model != null) {
                    // tell the model that we are done with the big
                    // model
                    // change
                    model.changedModel();

                    // end recording
                    ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
                    model.endRecording(this, selection.getOffset(), selection.getLength());
                    model.releaseFromEdit();
                }
            }
        }
    }
    return null;
}

From source file:org.eclipse.wst.server.ui.internal.view.servers.PropertiesAction.java

License:Open Source License

public void perform(IServer server) {
    if (propertyPageId == null)
        propertyPageId = "org.eclipse.wst.server.ui.properties";
    Dialog dialog = PreferencesUtil.createPropertyDialogOn(shell, server, propertyPageId, null, null);
    dialog.open();
}

From source file:org.eclipse.wst.sse.ui.internal.actions.CleanupAction.java

License:Open Source License

public void run() {
    if (getTextEditor() instanceof StructuredTextEditor) {
        final StructuredTextEditor editor = (StructuredTextEditor) getTextEditor();
        Dialog cleanupDialog = getCleanupDialog(editor.getSite().getShell());
        if (cleanupDialog != null) {
            if (cleanupDialog.open() == Window.OK) {
                // setup runnable
                Runnable runnable = new Runnable() {
                    public void run() {
                        IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
                        if (cleanupProcessor != null)
                            cleanupProcessor.cleanupModel(editor.getModel());
                    }/* w  ww  .j  ava 2  s  . c  o  m*/
                };

                // TODO: make independent of 'model'.
                IStructuredModel model = editor.getModel();
                if (model != null) {
                    try {
                        // begin recording
                        ITextSelection selection = (ITextSelection) editor.getSelectionProvider()
                                .getSelection();
                        model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_,
                                SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(),
                                selection.getLength()); //$NON-NLS-1$ //$NON-NLS-2$

                        // tell the model that we are about to make a big
                        // model change
                        model.aboutToChangeModel();

                        // run
                        BusyIndicator.showWhile(editor.getTextViewer().getControl().getDisplay(), runnable);
                    } finally {
                        // tell the model that we are done with the big
                        // model
                        // change
                        model.changedModel();

                        // end recording
                        ITextSelection selection = (ITextSelection) editor.getSelectionProvider()
                                .getSelection();
                        model.endRecording(this, selection.getOffset(), selection.getLength());
                    }
                }
            }

        }
    }
}

From source file:org.eclipse.wst.xml.ui.internal.actions.CleanupActionXMLDelegate.java

License:Open Source License

public void run(IAction action) {
    if (fEditor instanceof ITextEditor) {
        final ITextEditor editor = (ITextEditor) fEditor;
        Dialog cleanupDialog = new CleanupDialogXML(editor.getSite().getShell());
        if (cleanupDialog.open() == Window.OK) {
            // setup runnable
            Runnable runnable = new Runnable() {
                public void run() {
                    IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
                    if (cleanupProcessor != null) {
                        IStructuredModel model = null;
                        try {
                            model = StructuredModelManager.getModelManager().getExistingModelForEdit(
                                    editor.getDocumentProvider().getDocument(editor.getEditorInput()));
                            if (model != null) {
                                cleanupProcessor.cleanupModel(model);
                            }/*from   w w  w .j a  v  a 2 s .  c om*/
                        } finally {
                            if (model != null) {
                                model.releaseFromEdit();
                            }
                        }
                    }
                }
            };

            // TODO: make independent of 'model'.
            IStructuredModel model = null;
            try {
                model = StructuredModelManager.getModelManager().getExistingModelForEdit(
                        editor.getDocumentProvider().getDocument(editor.getEditorInput()));
                if (model != null) {
                    // begin recording
                    ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
                    model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_,
                            SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength());

                    // tell the model that we are about to make a big
                    // model change
                    model.aboutToChangeModel();

                    // run
                    BusyIndicator.showWhile(
                            fEditor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable);
                }
            } finally {
                if (model != null) {
                    // tell the model that we are done with the big
                    // model
                    // change
                    model.changedModel();

                    // end recording
                    ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
                    model.endRecording(this, selection.getOffset(), selection.getLength());
                    model.releaseFromEdit();
                }
            }
        }
    }
}