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.ide.ui.io.navigator.actions.FileSystemCopyAction.java

License:Open Source License

private void setClipboard(IFileStore[] fileStores, String[] fileNames, String names) {
    try {//from w w  w  .j a v  a  2s .  com
        // set the clipboard contents
        LocalSelectionTransfer selectionTransfer = LocalSelectionTransfer.getTransfer();
        selectionTransfer.setSelection(new StructuredSelection(fileStores));
        if (fileNames.length > 0) {
            fClipboard.setContents(new Object[] { fileStores, fileNames, names },
                    new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(),
                            TextTransfer.getInstance() });
        } else {
            fClipboard.setContents(new Object[] { fileStores, names },
                    new Transfer[] { LocalSelectionTransfer.getTransfer(), TextTransfer.getInstance() });
        }
    } catch (SWTError e) {
        if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
            throw e; // $codepro.audit.disable thrownExceptions
        }
        if (MessageDialog.openQuestion(fShell, "Problem with copy title", //$NON-NLS-1$
                "Problem with copy.")) { //$NON-NLS-1$
            setClipboard(fileStores, fileNames, names);
        }
    }
}

From source file:com.aptana.ide.ui.io.navigator.actions.FileSystemDeleteAction.java

License:Open Source License

public void run() {
    if (fFiles.isEmpty()) {
        return;/*from  w  ww.j a  v a  2 s  .co  m*/
    }

    String message;
    int count = fFiles.size();
    if (count == 1) {
        message = MessageFormat.format(Messages.FileSystemDeleteAction_Confirm_SingleFile, fFiles.get(0));
    } else {
        message = MessageFormat.format(Messages.FileSystemDeleteAction_Confirm_MultipleFiles, count);
    }
    if (MessageDialog.openQuestion(fShell, Messages.FileSystemDeleteAction_Confirm_Title, message)) {
        delete(fFiles.toArray(new IFileStore[fFiles.size()]));
    }
}

From source file:com.aptana.php.debug.ui.phpini.PHPIniEditor.java

License:Open Source License

/**
 * Removes entry./*  w w  w  .  ja  v a2s  .  c  o m*/
 */
private void removeEntry() {
    ISelection selection = viewer.getSelection();
    if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();

        if (element instanceof PHPIniEntry) {
            provider.removeEntry(((PHPIniEntry) element));
            viewer.refresh(true);
            viewer.getTree().getParent().layout(true, true);
        } else if (element instanceof INIFileSection) {
            INIFileSection section = (INIFileSection) element;
            if (section.equals(provider.getGlobalSection())) {
                MessageDialog.openInformation(viewer.getTree().getShell(), Messages.PHPIniEditor_11,
                        Messages.PHPIniEditor_12);
                return;
            }
            boolean result = MessageDialog.openQuestion(viewer.getTree().getShell(), Messages.PHPIniEditor_13,
                    Messages.PHPIniEditor_14 + section.getName() + Messages.PHPIniEditor_15);
            if (result) {
                provider.removeSection(section);
                viewer.refresh(true);
                viewer.getTree().getParent().layout(true, true);
            }
        }
    }
}

From source file:com.aptana.php.debug.ui.phpini.PHPIniEditor.java

License:Open Source License

/**
 * Validate the PHP extensions.//from   w w  w  .  j  a v  a2 s  .  com
 * 
 * @return True, if a validation process was initiated; False otherwise. A validation will not be initiated unless
 *         the {@link #openFile(String)} was called before.
 */
public boolean validateExtensions() {
    if (provider == null)
        return false;
    if (provider.isDirtyINI()) {
        // Inform the user that the ini should be saved before the validation starts
        if (!MessageDialog.openQuestion(viewer.getTree().getShell(),
                Messages.PHPIniEditor_extensionValidatorTitle,
                Messages.PHPIniEditor_extensionValidatorQuestion)) {
            return false;
        } else {
            try {
                provider.save();
            } catch (IOException e) {
                MessageDialog.openError(viewer.getTree().getShell(), Messages.PHPIniEditor_errorTitle,
                        Messages.PHPIniEditor_errorSavingIniMessage);
                IdeLog.logError(PHPDebugPlugin.getDefault(), "Error saving the php.ini", e, IDebugScopes.DEBUG); //$NON-NLS-1$

            }
        }
    }
    // Expand the tree
    Display.getDefault().asyncExec(new Runnable() {
        public void run() {
            viewer.expandAll();
        }
    });
    // Validate the extensions
    (new PHPIniValidator(provider, phpExePath, debuggerID)).validate();

    // Refresh
    viewer.refresh(true);
    viewer.getTree().getParent().layout(true, true);
    return true;
}

From source file:com.aptana.portal.ui.dispatch.configurationProcessors.JavaScriptLibraryInstallProcessor.java

License:Open Source License

/**
 * Install the library.<br>/*from  w  w w .  java2  s  . c  om*/
 * The installation will display a selection dialog, displaying the projects in the workspace, and selecting the
 * active project by default. It also takes into account the type of the project (nature) when suggesting the
 * location to save the JS libraries.
 * 
 * @param progressMonitor
 * @return A status indication of the process success or failure.
 */
protected IStatus install(IProgressMonitor progressMonitor) {
    Job job = new UIJob(Messages.JSLibraryInstallProcessor_directorySelection) {
        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            JavaScriptImporterOptionsDialog dialog = new JavaScriptImporterOptionsDialog(
                    Display.getDefault().getActiveShell(), libraryName);
            if (dialog.open() == Window.OK) {
                String selectedLocation = dialog.getSelectedLocation();
                IPath path = Path.fromOSString(selectedLocation);
                targetProject = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
                // Making sure that the project is not null, although this should never happen
                if (targetProject != null) {
                    String fullPath = targetProject.getLocation().append(path.removeFirstSegments(1))
                            .toOSString();
                    File targetFolder = new File(fullPath);
                    if (!targetFolder.exists() && !targetFolder.mkdirs()) {
                        // could not create the directories needed!
                        IdeLog.logError(PortalUIPlugin.getDefault(),
                                "Failed to create directories when importing JS slibrary!", //$NON-NLS-1$
                                new Exception("Failed to create '" + fullPath + '\'')); //$NON-NLS-1$
                        return new Status(IStatus.ERROR, PortalUIPlugin.PLUGIN_ID,
                                Messages.JSLibraryInstallProcessor_directoriesCreationFailed);
                    }
                    // Copy the downloaded content into the created directory
                    List<IStatus> errors = new ArrayList<IStatus>();
                    for (String f : downloadedPaths) {
                        try {
                            File sourceLocation = new File(f);
                            File targetLocation = new File(targetFolder, sourceLocation.getName());
                            if (targetLocation.exists()) {
                                if (!MessageDialog.openQuestion(Display.getDefault().getActiveShell(),
                                        Messages.JSLibraryInstallProcessor_fileConflictTitle,
                                        Messages.JSLibraryInstallProcessor_fileConflictMessage
                                                + sourceLocation.getName()
                                                + Messages.JSLibraryInstallProcessor_overwriteQuestion)) {
                                    continue;
                                }
                            }
                            IOUtil.copyFile(sourceLocation, targetLocation);
                        } catch (IOException e) {
                            errors.add(new Status(IStatus.ERROR, PortalUIPlugin.PLUGIN_ID, e.getMessage(), e));
                        }
                    }
                    if (!errors.isEmpty()) {
                        return new MultiStatus(PortalUIPlugin.PLUGIN_ID, 0,
                                errors.toArray(new IStatus[errors.size()]),
                                Messages.JSLibraryInstallProcessor_multipleErrorsWhileImportingJS, null);
                    }
                    // Since we don't cache the installed location for javascript libraries, we pass null here. This
                    // will only mark for deletion the downloaded content.
                    finalizeInstallation(null);
                } else {
                    IdeLog.logError(PortalUIPlugin.getDefault(),
                            "Unexpected null project when importing a JS library!", new Exception()); //$NON-NLS-1$
                    return new Status(IStatus.ERROR, PortalUIPlugin.PLUGIN_ID,
                            Messages.JSLibraryInstallProcessor_unexpectedNull);
                }
                try {
                    targetProject.refreshLocal(IResource.DEPTH_INFINITE, SubMonitor.convert(monitor));
                } catch (CoreException e) {
                    IdeLog.logError(PortalUIPlugin.getDefault(), "Error while refreshing the project.", e); //$NON-NLS-1$
                }
                return Status.OK_STATUS;
            } else {
                return Status.CANCEL_STATUS;
            }
        }
    };
    EclipseUtil.setSystemForJob(job);
    job.schedule();
    try {
        job.join();
    } catch (InterruptedException e) {
        IdeLog.logError(PortalUIPlugin.getDefault(), e);
    }
    return job.getResult();
}

From source file:com.aptana.preview.PreviewManager.java

License:Open Source License

public void openPreviewForEditor(final IEditorPart editorPart) {
    try {/*from   w  ww .j a  v  a 2 s.c  o m*/
        final IEditorInput editorInput = editorPart.getEditorInput();
        if (!editorPart.isDirty()) {
            openPreview(editorPart, editorInput, null);
        } else if (editorPart instanceof AbstractTextEditor) {
            IDocumentProvider documentProvider = ((AbstractTextEditor) editorPart).getDocumentProvider();
            if (documentProvider != null) {
                if (documentProvider.canSaveDocument(editorInput)) {
                    IDocument document = documentProvider.getDocument(editorInput);
                    if (document != null) {
                        try {
                            if (!openPreview(editorPart, editorInput, document.get())) {
                                final boolean[] openPreview = new boolean[1];
                                UIUtils.getDisplay().syncExec(new Runnable() {
                                    public void run() {
                                        openPreview[0] = MessageDialog.openQuestion(
                                                editorPart.getSite().getShell(),
                                                Messages.PreviewManager_UnsavedPrompt_Title,
                                                Messages.PreviewManager_UnsavedPrompt_Message);
                                    }
                                });
                                if (openPreview[0]) {
                                    openPreview(editorPart, editorInput, null);
                                }

                            }
                        } catch (CoreException e) {
                            PreviewPlugin.log(e);
                        }
                    }
                } else {
                    openPreview(editorPart, editorInput, null);
                }
            }
        }
    } catch (CoreException e) {
        PreviewPlugin.log(e);
    }
}

From source file:com.aptana.ui.PerspectiveChangeResetListener.java

License:Open Source License

private void resetPerspective(final IWorkbenchPage page) {
    UIJob job = new UIJob("Resetting Studio perspective...") //$NON-NLS-1$
    {//from   www  . jav a2  s .  c  o  m

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            if (MessageDialog.openQuestion(UIUtils.getActiveShell(),
                    com.aptana.ui.Messages.UIPlugin_ResetPerspective_Title,
                    com.aptana.ui.Messages.UIPlugin_ResetPerspective_Description)) {
                page.resetPerspective();
            }
            return Status.OK_STATUS;
        }
    };
    EclipseUtil.setSystemForJob(job);
    job.setPriority(Job.INTERACTIVE);
    job.schedule();
}

From source file:com.aptana.ui.properties.ProjectNaturesPage.java

License:Open Source License

/**
 * Ask to reset the project (e.g. Close and Open) to apply the changes.
 *//*from  w  ww  .  j ava 2  s  .c  om*/
protected void resetProject() {
    boolean reset = MessageDialog.openQuestion(getControl().getShell(),
            EplMessages.ProjectNaturesPage_ResetTitle, EplMessages.ProjectNaturesPage_ResetMessage);
    if (reset) {
        // close the project
        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_CloseProjectJob_Title + "...") //$NON-NLS-1$
                {
                    @Override
                    public IStatus runInUIThread(IProgressMonitor monitor) {
                        CloseResourceAction closeAction = new CloseResourceAction(new IShellProvider() {
                            public Shell getShell() {
                                return Display.getDefault().getActiveShell();
                            }
                        });
                        closeAction.selectionChanged(new StructuredSelection(new Object[] { fProject }));
                        closeAction.run();
                        monitor.done();
                        return Status.OK_STATUS;
                    }
                };
                job.schedule();
                try {
                    job.join();
                } catch (InterruptedException e) {
                    // ignore
                }
                monitor.done();
            }
        };
        try {
            new ProgressMonitorJobsDialog(getControl().getShell()).run(true, true, close);
        } catch (InterruptedException e) {
            // ignore
        } catch (InvocationTargetException e) {
            IdeLog.logError(UIEplPlugin.getDefault(), EplMessages.ProjectNaturesPage_ERR_CloseProject, e);
        }

        // re-open the project
        IRunnableWithProgress open = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                try {
                    fProject.open(monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            new ProgressMonitorJobsDialog(getControl().getShell()).run(true, true, open);
        } catch (InterruptedException e) {
            // ignore
        } catch (InvocationTargetException e) {
            IdeLog.logError(UIEplPlugin.getDefault(), EplMessages.ProjectNaturesPage_ERR_OpenProject, e);
        }
    }
}

From source file:com.aptana.ui.util.UIUtils.java

License:Open Source License

private static boolean showPromptDialogUI(String title, String message) {
    return MessageDialog.openQuestion(getActiveWorkbenchWindow().getShell(), title, message);
}

From source file:com.aptana.webserver.ui.internal.actions.DeleteServerHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {

    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
        return null;
    }//from www.  ja  va  2s  . com

    IServer server = (IServer) ((IStructuredSelection) selection).getFirstElement();
    if (server != null && MessageDialog.openQuestion(UIUtils.getActiveShell(),
            Messages.ServersPreferencePage_DeletePrompt_Title,
            Messages.ServersPreferencePage_DeletePrompt_Message)) {
        // TODO We should probably make sure server gets stopped before we remove it!
        WebServerCorePlugin.getDefault().getServerManager().remove(server);
    }
    return null;
}