Example usage for org.eclipse.jface.dialogs MessageDialog openQuestion

List of usage examples for org.eclipse.jface.dialogs MessageDialog openQuestion

Introduction

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

Prototype

public static boolean openQuestion(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a simple Yes/No question dialog.

Usage

From source file:com.aptana.editor.common.util.EditorUtil.java

License:Open Source License

/**
 * Finds the editor for the specified file in the specified project and prompts a save if the editor is dirty
 * //  ww  w  .ja  va  2s. c om
 * @param project
 * @param fileName
 * @param promptQuestion
 * @return
 */
public static boolean verifySaveEditor(final IProject project, final String fileName,
        final String promptQuestion) {
    final boolean[] result = new boolean[] { true };
    UIUtils.getDisplay().syncExec(new Runnable() {
        public void run() {
            IEditorPart[] dirtyEditors = UIUtils.getDirtyEditors();
            if (dirtyEditors != null && dirtyEditors.length > 0) {
                IFile tiappFile = project.getFile(fileName);
                // Try to locate the tiapp resource
                for (IEditorPart editor : dirtyEditors) {
                    IFile file = (IFile) (editor.getEditorInput().getAdapter(IFile.class));
                    if (file != null && file.equals(tiappFile)) {
                        // prompt for save
                        if (MessageDialog.openQuestion(UIUtils.getActiveShell(),
                                Messages.EditorUtil_VerfiySavePromptTitle_lbl, promptQuestion)) {
                            editor.doSave(new NullProgressMonitor());
                        } else {
                            result[0] = false;
                        }
                        break;
                    }
                }
            }
        }
    });

    return result[0];
}

From source file:com.aptana.formatter.ui.preferences.AbstractFormatterSelectionBlock.java

License:Open Source License

protected Composite createSelectorBlock(Composite parent) {
    final int numColumns = 5;

    PixelConverter fPixConv = new PixelConverter(parent);
    fComposite = createComposite(parent, numColumns);

    Label profileLabel = new Label(fComposite, SWT.NONE);
    profileLabel.setText(FormatterMessages.AbstractFormatterSelectionBlock_activeProfile);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.horizontalSpan = numColumns;//from  ww  w . j av a  2s.c o  m
    profileLabel.setLayoutData(data);

    fProfileCombo = createProfileCombo(fComposite, 1, fPixConv.convertWidthInCharsToPixels(20));
    updateComboFromProfiles();
    fProfileCombo.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            updateSelection();
        }
    });

    fNewButton = createButton(fComposite, GridData.HORIZONTAL_ALIGN_BEGINNING);
    fNewButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/add.gif")); //$NON-NLS-1$
    fNewButton.setToolTipText(FormatterMessages.AbstractFormatterSelectionBlock_newProfile);
    fNewButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            createNewProfile(fComposite.getShell());
        }
    });

    fDeleteButton = createButton(fComposite, GridData.HORIZONTAL_ALIGN_BEGINNING);
    fDeleteButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/delete.gif")); //$NON-NLS-1$
    fDeleteButton.setToolTipText(FormatterMessages.AbstractFormatterSelectionBlock_removeProfile);
    fDeleteButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            doDelete();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            doDelete();
        }

        protected void doDelete() {
            IProfileManager profileManager = getProfileManager();
            IProfile selected = profileManager.getSelected(fProject);
            if (MessageDialog.openQuestion(fComposite.getShell(),
                    FormatterMessages.AbstractFormatterSelectionBlock_confirmRemoveLabel,
                    NLS.bind(FormatterMessages.AbstractFormatterSelectionBlock_confirmRemoveMessage,
                            selected.getName()))) {
                profileManager.deleteProfile(selected);
                updateComboFromProfiles();
                updateSelection();
            }
        }
    });

    // add a filler

    fLoadButton = createButton(fComposite, GridData.HORIZONTAL_ALIGN_BEGINNING);
    fLoadButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/import.gif")); //$NON-NLS-1$
    fLoadButton.setToolTipText(FormatterMessages.AbstractFormatterSelectionBlock_importProfile);
    fLoadButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            doImport(fComposite);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            doImport(fComposite);
        }

    });

    fSaveButton = createButton(fComposite, GridData.HORIZONTAL_ALIGN_BEGINNING);
    fSaveButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/export.gif")); //$NON-NLS-1$
    fSaveButton.setToolTipText(FormatterMessages.FormatterModifyDialog_export);
    fSaveButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            doExport();
        }
    });

    createLabel(fComposite, "", 3); //$NON-NLS-1$

    // Edit
    fEditButton = createButton(fComposite, GridData.HORIZONTAL_ALIGN_BEGINNING);
    fEditButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/pencil.gif")); //$NON-NLS-1$
    fEditButton.setToolTipText(FormatterMessages.AbstractFormatterSelectionBlock_edit);
    fEditButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            editButtonPressed();
        }
    });

    // Restore Defaults
    fDefaultButton = createButton(fComposite, GridData.HORIZONTAL_ALIGN_BEGINNING);
    fDefaultButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/arrow_undo.png")); //$NON-NLS-1$
    fDefaultButton.setToolTipText(FormatterMessages.AbstractFormatterSelectionBlock_defaults);
    fDefaultButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IScriptFormatterFactory formatter = getSelectedFormatter();
            if (formatter == null) {
                return;
            }
            PreferenceKey[] preferenceKeys = formatter.getPreferenceKeys();
            IProfileManager manager = getProfileManager();
            if (!MessageDialog.openQuestion(fDefaultButton.getShell(),
                    FormatterMessages.AbstractFormatterSelectionBlock_confirmDefaultsTitle,
                    NLS.bind(FormatterMessages.AbstractFormatterSelectionBlock_confirmDefaultsMessage,
                            formatter.getName()))) {
                return;
            }
            List<IProfile> builtInProfiles = manager.getBuiltInProfiles();
            String defaultProfileId = manager.getDefaultProfileID();
            IProfile defaultProfile = null;
            for (IProfile profile : builtInProfiles) {
                if (profile.getID().equals(defaultProfileId)) {
                    defaultProfile = profile;
                    break;
                }
            }
            if (defaultProfile != null) {
                Map<String, String> defaultSettings = defaultProfile.getSettings();
                Map<String, String> activeSettings = manager.getSelected(fProject).getSettings();
                IScopeContext context = EclipseUtil.instanceScope();
                for (PreferenceKey key : preferenceKeys) {
                    String name = key.getName();
                    if (defaultSettings.containsKey(name)) {
                        String value = defaultSettings.get(name);
                        activeSettings.put(name, value);
                        key.setStoredValue(context, value);
                    } else {
                        activeSettings.remove(name);
                    }
                }
                manager.getSelected(fProject).setSettings(activeSettings);
                manager.markDirty();
                // Apply the preferences. This will update the preview as well.
                applyPreferences();
            }
        }
    });
    IProfileManager profileManager = getProfileManager();
    fDefaultButton.setEnabled(!profileManager.getSelected(fProject).isBuiltInProfile());

    configurePreview(fComposite, numColumns);
    updateButtons();
    applyPreferences(true);

    return fComposite;
}

From source file:com.aptana.formatter.ui.preferences.AbstractFormatterSelectionBlock.java

License:Open Source License

/**
 * Export the formatter as an XML.//from w w w .j  a  v  a2  s  . co m
 */
private void doExport() {
    IProfileManager manager = getProfileManager();
    IProfileStore store = manager.getProfileStore();
    IProfile activeProfile = manager.getSelected(fProject);
    IProfile selected = manager.create(fProject, ProfileKind.TEMPORARY, activeProfile.getName(),
            activeProfile.getSettings(), activeProfile.getVersion());

    final FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
    dialog.setText(FormatterMessages.FormatterModifyDialog_exportProfile);
    dialog.setFilterExtensions(new String[] { "*.xml" }); //$NON-NLS-1$

    final String path = dialog.open();
    if (path == null)
        return;

    final File file = new File(path);
    String message = NLS.bind(FormatterMessages.FormatterModifyDialog_replaceFileQuestion,
            file.getAbsolutePath());
    if (file.exists() && !MessageDialog.openQuestion(getShell(),
            FormatterMessages.FormatterModifyDialog_exportProfile, message)) {
        return;
    }

    final Collection<IProfile> profiles = new ArrayList<IProfile>();
    profiles.add(selected);
    try {
        store.writeProfilesToFile(profiles, file);
    } catch (CoreException e) {
        final String title = FormatterMessages.FormatterModifyDialog_exportProfile;
        message = FormatterMessages.FormatterModifyDialog_exportProblem;
        ExceptionHandler.handle(e, getShell(), title, message);
    }
}

From source file:com.aptana.formatter.ui.preferences.FormatterModifyDialog.java

License:Open Source License

private void saveButtonPressed() {
    // IProfileStore store = formatterFactory.getProfileStore();
    IProfileStore store = ProfileManager.getInstance().getProfileStore();
    IProfile selected = manager.create(dialogOwner.getProject(), ProfileKind.TEMPORARY,
            fProfileNameField.getText(), getPreferences(), profile.getVersion());

    final FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
    dialog.setText(FormatterMessages.FormatterModifyDialog_exportProfile);
    dialog.setFilterExtensions(new String[] { "*.xml" }); //$NON-NLS-1$

    final String path = dialog.open();
    if (path == null)
        return;//from ww w  .j  ava2s  . c om

    final File file = new File(path);
    String message = NLS.bind(FormatterMessages.FormatterModifyDialog_replaceFileQuestion,
            file.getAbsolutePath());
    if (file.exists() && !MessageDialog.openQuestion(getShell(),
            FormatterMessages.FormatterModifyDialog_exportProfile, message)) {
        return;
    }

    final Collection<IProfile> profiles = new ArrayList<IProfile>();
    profiles.add(selected);
    try {
        // TODO - WRITE ALL PROFILES
        store.writeProfilesToFile(profiles, file);
    } catch (CoreException e) {
        final String title = FormatterMessages.FormatterModifyDialog_exportProfile;
        message = FormatterMessages.FormatterModifyDialog_exportProblem;
        ExceptionHandler.handle(e, getShell(), title, message);
    }
}

From source file:com.aptana.ide.core.ui.preferences.ProjectNaturesPage.java

License:Open Source License

/**
 * Ask to reset the project (e.g. Close and Open) to apply the changes.
 *///from   w w  w .  j a  v a 2s .c  o m
protected void resetProject() {
    boolean reset = MessageDialog.openQuestion(getControl().getShell(),
            EPLMessages.ProjectNaturesPage_ResetTitle, EPLMessages.ProjectNaturesPage_ResetMessage);
    if (reset) {
        IRunnableWithProgress close = new IRunnableWithProgress() {
            public void run(final IProgressMonitor monitor) throws InvocationTargetException {
                // Use the CloseResourceAction to provide a file saving dialog in case the project has some unsaved
                // files
                UIJob job = new UIJob(EPLMessages.ProjectNaturesPage_Job_CloseProject) {
                    public IStatus runInUIThread(IProgressMonitor monitor) {
                        CloseResourceAction closeAction = new CloseResourceAction(
                                Display.getDefault().getActiveShell());
                        closeAction.selectionChanged(new StructuredSelection(new Object[] { project }));
                        closeAction.run();
                        monitor.done();
                        return Status.OK_STATUS;
                    }
                };
                job.schedule();
                try {
                    job.join();
                } catch (InterruptedException e) {
                    IdeLog.logError(Activator.getDefault(), EPLMessages.ProjectNaturesPage_ERR_CloseProject, e);
                }
                monitor.done();
            }
        };
        try {
            // This will block until the progress is done
            new ProgressMonitorJobsDialog(getControl().getShell()).run(true, true, close);
        } catch (InterruptedException e) {
            // Ignore interrupted exceptions
        } catch (InvocationTargetException e) {
            handle(e);
        }

        IRunnableWithProgress open = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                try {
                    project.open(monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            // This will block until the progress is done
            new ProgressMonitorJobsDialog(getControl().getShell()).run(true, true, open);
        } catch (InterruptedException e) {
            // Ignore interrupted exceptions
        } catch (InvocationTargetException e) {
            handle(e);
        }
    }
}

From source file:com.aptana.ide.core.ui.WebPerspectiveFactory.java

License:Open Source License

/**
 * Resets the current perspective./*from w  w  w  .  java2  s  .com*/
 * 
 * @param page
 */
public static void resetPerspective(final IWorkbenchPage page) {
    if (Display.getCurrent() == null) {
        return;
    }

    final Shell shell = Display.getCurrent().getActiveShell();
    final IPreferenceStore p = CoreUIPlugin.getDefault().getPreferenceStore();
    if (p.getBoolean(IPreferenceConstants.WEB_PERSPECTIVE_RESET_PERSPECTIVE)) {
        return;
    }

    UIJob job = new UIJob("Resetting Aptana perspective") { //$NON-NLS-1$

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            if (shell != null) {
                p.setValue(IPreferenceConstants.WEB_PERSPECTIVE_RESETTING_PERSPECTIVE, true);

                boolean ret = MessageDialog.openQuestion(CoreUIUtils.getActiveShell(),
                        Messages.WebPerspectiveFactory_UpdatePerspectiveTitle,
                        Messages.WebPerspectiveFactory_UpdatePerspectiveConfirmation);
                p.setValue(IPreferenceConstants.WEB_PERSPECTIVE_LAST_VERSION, WebPerspectiveFactory.VERSION);
                if (!ret) {
                    return Status.OK_STATUS;
                }

                p.setValue(IPreferenceConstants.WEB_PERSPECTIVE_RESET_PERSPECTIVE, true);

                // fire all resetting handlers
                if (resettingHandlers != null) {
                    for (int i = 0; i < resettingHandlers.size(); i++) {
                        resettingHandlers.get(i).run();
                    }
                }

                page.resetPerspective();
            }
            return Status.OK_STATUS;
        }

    };
    job.setRule(MutexJobRule.getInstance());
    job.setSystem(true);
    job.schedule();
}

From source file:com.aptana.ide.core.ui.WindowActionDelegate.java

License:Open Source License

/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 *///from w  w w. j av  a  2 s .  c  om
public void run(IAction action) {
    String id = action.getId();
    if (id.equals(VIEW_LOG_ID)) {
        String logFile = getLogFile();

        try {
            WorkbenchHelper.openFile(new File(logFile), PlatformUI.getWorkbench().getActiveWorkbenchWindow());
        } catch (Exception e) {
            IdeLog.logError(CoreUIPlugin.getDefault(),
                    StringUtils.format(Messages.WindowActionDelegate_UnableToOpenLogFile, logFile), e);
        }
    } else if (id.equals(CLEAR_LOG_ID)) {
        if (!MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), Messages.ClearLogConfirmTitle,
                Messages.ClearLogConfirmDescription)) {
            return;
        }
        String logFile = getLogFile();

        try {
            File file = new File(logFile);
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            fileOutputStream.close();
        } catch (Exception e) {
            IdeLog.logError(CoreUIPlugin.getDefault(),
                    StringUtils.format(Messages.WindowActionDelegate_UnableToOpenLogFile, logFile), e);
        }
    } else if (id.equals("Overview.Action")) //$NON-NLS-1$
    {
        String currentPerspectiveID = WebPerspectiveFactory.PERSPECTIVE_ID;
        try {
            IPerspectiveDescriptor desc = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                    .getPerspective();
            // If it is not one of ours, then just show the default
            if (!WebPerspectiveFactory.isSameOrDescendantPerspective(desc)) {
                MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        Messages.WindowActionDelegate_AptanaOverviewErrorTitle,
                        Messages.WindowActionDelegate_AptanaOverviewErrorMessage);
                return;
            }
        } catch (Exception e) {
        }
    } else if (id.equals(CLEAN_CONFIG_ID)) {
        if (!MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                Messages.WindowActionDelegate_CleanConfigurationTitle,
                Messages.WindowActionDelegate_CleanConfigurationDescription)) {
            return;
        }

        IPreferenceStore prefs = CoreUIPlugin.getDefault().getPreferenceStore();
        prefs.setValue(IPreferenceConstants.PREF_CLEAN_RESTART, true);
        window.getWorkbench().restart();
    } else if (id.equals(LEARN_MORE_ID)) {
        PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(
                Display.getDefault().getActiveShell(), LICENSE_PREFERENCE_ID,
                new String[] { LICENSE_PREFERENCE_ID }, null);
        dialog.open();
    }
}

From source file:com.aptana.ide.logging.preferences.LoggingPreferenceWidget.java

License:Open Source License

/**
 * Styles the import/export section// w  w  w .j  ava 2s  . c  om
 */
private void styleImportExport() {
    Group io = new Group(displayArea, SWT.NONE);
    io.setText(Messages.LoggingColorizationWidget_60);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 5;
    layout.marginWidth = 5;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 2;
    io.setLayout(layout);
    io.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    importButton = new Button(io, SWT.PUSH);
    importButton.setEnabled(false);
    importButton.setText(StringUtils.ellipsify(Messages.LoggingColorizationWidget_27));
    importButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(displayArea.getShell(), SWT.OPEN);
            dialog.setFilterExtensions(new String[] { "*.col" }); //$NON-NLS-1$
            dialog.setText(Messages.LoggingColorizationWidget_63);
            String path = dialog.open();
            if (path != null) {
                if (!MessageDialog.openQuestion(LoggingPlugin.getActiveWorkbenchShell(),
                        Messages.LoggingColorizationWidget_ConfirmRewritingTitle,
                        Messages.LoggingColorizationWidget_ConfirmRewritingCurrentMessage)) {
                    return;
                }
                File file = new File(path);
                provider.importColorization(file);
                loadEditorOptions();
                initializeColorizerView();
                //regionViewer.refresh(); @regions
            }
        }

    });
    exportButton = new Button(io, SWT.PUSH);
    exportButton.setEnabled(false);
    exportButton.setText(StringUtils.ellipsify(Messages.LoggingColorizationWidget_64));
    exportButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(displayArea.getShell(), SWT.SAVE);
            dialog.setFilterExtensions(new String[] { "*.col" }); //$NON-NLS-1$
            dialog.setText(Messages.LoggingColorizationWidget_66);
            dialog.setFileName("colorization.col"); //$NON-NLS-1$
            String path = dialog.open();
            if (path != null) {
                File file = new File(path);
                if (file.exists()) {
                    if (!MessageDialog.openQuestion(LoggingPlugin.getActiveWorkbenchShell(),
                            Messages.LoggingColorizationWidget_ConfirmRewritingTitle,
                            Messages.LoggingColorizationWidget_ConfirmRewritingMessage)) {
                        return;
                    }
                }

                try {
                    provider.buildColorizationFile(file);
                } catch (LexerException e1) {
                    IdeLog.logError(UnifiedEditorsPlugin.getDefault(), Messages.LoggingColorizationWidget_68);
                }
            }
        }

    });
}

From source file:com.aptana.ide.logging.view.LogView.java

License:Open Source License

/**
 * Creates Clear action./*ww  w.j a  v a 2s  .  c  o m*/
 */
private void createClearLogFileAction() {
    actionLogFileClear = new Action() {
        public void run() {
            LogTab currentTab = getActiveTab();
            if (currentTab != null) {
                if (MessageDialog.openQuestion(LoggingPlugin.getActiveWorkbenchShell(),
                        com.aptana.ide.logging.view.Messages.EraseConfirmDialog_Title,
                        com.aptana.ide.logging.view.Messages.EraseConfirmDialog_Message)) {
                    currentTab.clearLogFile();
                }
            }
        }
    };

    actionLogFileClear.setText(com.aptana.ide.logging.view.Messages.LogView_9);
    actionLogFileClear.setToolTipText(com.aptana.ide.logging.view.Messages.LogView_10);
    actionLogFileClear.setImageDescriptor(fClearLogFileActionDescriptor);
}

From source file:com.aptana.ide.ui.editors.preferences.formatter.ModifyDialog.java

License:Open Source License

private void saveButtonPressed() {
    Profile selected = new CustomProfile(fProfileNameField.getText(), new HashMap(fWorkingValues),
            fProfile.getVersion(), ""); //$NON-NLS-1$

    final FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
    dialog.setText(FormatterMessages.CodingStyleConfigurationBlock_save_profile_dialog_title);
    dialog.setFilterExtensions(new String[] { "*.xml" }); //$NON-NLS-1$

    final String lastPath = Activator.getDefault().getDialogSettings().get(fLastSaveLoadPathKey + ".savepath"); //$NON-NLS-1$
    if (lastPath != null) {
        dialog.setFilterPath(lastPath);/*from   w w w.j a v a  2  s .co  m*/
    }
    final String path = dialog.open();
    if (path == null)
        return;

    Activator.getDefault().getDialogSettings().put(fLastSaveLoadPathKey + ".savepath", dialog.getFilterPath()); //$NON-NLS-1$

    final File file = new File(path);
    if (file.exists() && !MessageDialog.openQuestion(getShell(),
            FormatterMessages.CodingStyleConfigurationBlock_save_profile_overwrite_title, StringUtils.format(
                    FormatterMessages.CodingStyleConfigurationBlock_save_profile_overwrite_message, path))) {
        return;
    }
    String encoding = ProfileStore.ENCODING;
    final IContentType type = Platform.getContentTypeManager().getContentType("org.eclipse.core.runtime.xml"); //$NON-NLS-1$
    if (type != null)
        encoding = type.getDefaultCharset();
    final Collection profiles = new ArrayList();
    profiles.add(selected);
    try {
        fProfileStore.writeProfilesToFile(profiles, file, encoding);
    } catch (CoreException e) {
        //         final String title= FormatterMessages.CodingStyleConfigurationBlock_save_profile_error_title;
        //         final String message= FormatterMessages.CodingStyleConfigurationBlock_save_profile_error_message;
        //ExceptionHandler.handle(e, getShell(), title, message);
    }
}