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

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

Introduction

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

Prototype

int QUESTION

To view the source code for org.eclipse.jface.dialogs MessageDialog QUESTION.

Click Source Link

Document

Constant for the question image, or a simple dialog with the question image and Yes/No buttons (value 3).

Usage

From source file:org.eclipse.tm.te.tcf.filesystem.internal.handlers.OpenWithMenu.java

License:Open Source License

/**
 * Synchronize and open the file using the specified editor descriptor. If openUsingDescriptor
 * is true, it will try to use an external editor to open it if an eclipse editor is not
 * available./*from  www  .  jav a2s . c  o  m*/
 * 
 * @param editorDescriptor The editor descriptor used to open the node.
 * @param openUsingDescriptor If an external editor should be used to open the node.
 */
protected void syncOpen(IEditorDescriptor editorDescriptor, boolean openUsingDescriptor) {
    File file = CacheManager.getInstance().getCacheFile(node);
    if (!file.exists()) {
        // If the file node's local cache does not exist yet, download it.
        boolean successful = CacheManager.getInstance().download(node);
        if (!successful) {
            return;
        }
    }
    if (!PersistenceManager.getInstance().isAutoSaving()) {
        openInEditor(editorDescriptor, openUsingDescriptor);
    } else {
        try {
            StateManager.getInstance().refreshState(node);
        } catch (TCFException e) {
            Shell parent = page.getWorkbenchWindow().getShell();
            MessageDialog.openError(parent, Messages.StateManager_RefreshFailureTitle, e.getLocalizedMessage());
            return;
        }
        CacheState state = StateManager.getInstance().getCacheState(node);
        switch (state) {
        case consistent:
            openInEditor(editorDescriptor, openUsingDescriptor);
            break;
        case modified: {
            // If the file node's local cache has been modified, upload it
            // before open it.
            boolean successful = CacheManager.getInstance().upload(node);
            if (successful)
                openInEditor(editorDescriptor, openUsingDescriptor);
        }
            break;
        case outdated: {
            // If the file node's local cache does not exist yet, download
            // it.
            boolean successful = CacheManager.getInstance().download(node);
            if (successful)
                openInEditor(editorDescriptor, openUsingDescriptor);
        }
            break;
        case conflict: {
            String title = Messages.OpenFileHandler_ConflictingTitle;
            String message = NLS.bind(Messages.OpenFileHandler_ConflictingMessage, node.name);
            Shell parent = page.getWorkbenchWindow().getShell();
            MessageDialog msgDialog = new MessageDialog(parent, title, null, message, MessageDialog.QUESTION,
                    new String[] { Messages.OpenFileHandler_Merge, Messages.OpenFileHandler_OpenAnyway,
                            Messages.OpenFileHandler_Cancel },
                    0);
            int index = msgDialog.open();
            if (index == 0) {
                LocalTypedElement local = new LocalTypedElement(node);
                RemoteTypedElement remote = new RemoteTypedElement(node);
                MergeEditorInput input = new MergeEditorInput(local, remote, page);
                CompareUI.openCompareDialog(input);
            } else if (index == 1) {
                openInEditor(editorDescriptor, openUsingDescriptor);
            }
        }
            break;
        }
    }
}

From source file:org.eclipse.tm.te.tcf.filesystem.internal.handlers.UpdateHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
    FSTreeNode node = (FSTreeNode) selection.getFirstElement();
    try {/*from  ww  w.j  a  v  a2s . c o  m*/
        StateManager.getInstance().refreshState(node);
    } catch (TCFException e) {
        Shell parent = HandlerUtil.getActiveShell(event);
        MessageDialog.openError(parent, Messages.StateManager_RefreshFailureTitle, e.getLocalizedMessage());
        return null;
    }
    Shell parent = HandlerUtil.getActiveShell(event);
    File file = CacheManager.getInstance().getCacheFile(node);
    if (file.exists()) {
        CacheState state = StateManager.getInstance().getCacheState(node);
        switch (state) {
        case conflict:
            String title = Messages.UpdateHandler_StateChangedDialogTitle;
            String message = NLS.bind(Messages.UpdateHandler_StateChangedMessage, node.name);
            MessageDialog msgDialog = new MessageDialog(parent, title, null, message, MessageDialog.QUESTION,
                    new String[] { Messages.UpdateHandler_Merge, Messages.UpdateHandler_UpdateAnyway,
                            Messages.UpdateHandler_Cancel },
                    0);
            int index = msgDialog.open();
            if (index == 0) {
                LocalTypedElement local = new LocalTypedElement(node);
                RemoteTypedElement remote = new RemoteTypedElement(node);
                IWorkbenchPage page = HandlerUtil.getActiveSite(event).getPage();
                MergeEditorInput input = new MergeEditorInput(local, remote, page);
                CompareUI.openCompareDialog(input);
            } else if (index == 1) {
                CacheManager.getInstance().download(node);
            }
            break;
        case modified:
            break;
        case consistent:
            break;
        case outdated:
            CacheManager.getInstance().download(node);
            break;
        }
    } else {
        CacheManager.getInstance().download(node);
    }
    return null;
}

From source file:org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportConflictHandler.java

License:Open Source License

private int promptForOverwrite(IPath tracePath) {
    final MessageDialog dialog = new MessageDialog(fShell, null, null,
            NLS.bind(Messages.ImportTraceWizard_TraceAlreadyExists,
                    tracePath.makeRelativeTo(fTraceFolderElement.getProject().getPath())),
            MessageDialog.QUESTION,
            new String[] { ImportConfirmation.RENAME.getInName(), ImportConfirmation.RENAME_ALL.getInName(),
                    ImportConfirmation.OVERWRITE.getInName(), ImportConfirmation.OVERWRITE_ALL.getInName(),
                    ImportConfirmation.SKIP.getInName(), ImportConfirmation.SKIP_ALL.getInName(), },
            4) {// ww w .  j a va2  s .  c om
        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };

    final int[] returnValue = new int[1];
    fShell.getDisplay().syncExec(new Runnable() {

        @Override
        public void run() {
            returnValue[0] = dialog.open();
        }
    });
    return returnValue[0];
}

From source file:org.eclipse.tracecompass.totalads.ui.models.delete.DeleteModelHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    String msgTitle = "TotalADS"; //$NON-NLS-1$
    //  MessageBox msgBoxYesNo = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
    //        SWT.ICON_INFORMATION | SWT.YES | SWT.NO);

    //msgBoxYesNo.setText(msgTitle);

    try {//from   w  w w  . ja  va 2  s  . com

        // checking if a model is selected
        if (fSelectedModels.size() <= 0) {
            MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), msgTitle,
                    Messages.DeleteModelHandler_SelModel);
            return null;
        }
        //
        // Get confirmation
        //
        Iterator<String> it = fSelectedModels.iterator();
        String message = Messages.DeleteModelHandler_WantToDel;
        int count = 1;
        while (it.hasNext()) {
            if (count == 1 && fSelectedModels.size() <= 2) {
                message += it.next() + " "; //$NON-NLS-1$
            } else if (count == 1 && fSelectedModels.size() > 2) {
                message += it.next() + ", "; //$NON-NLS-1$
            } else if (count > 1 && count < fSelectedModels.size()) {
                message += it.next() + ", "; //$NON-NLS-1$
            } else if (count > 1 && count == fSelectedModels.size()) {
                message += Messages.DeleteModelHandler_And + it.next();
            }

            count++;
        }
        message += "?"; //$NON-NLS-1$
        MessageDialog msgBoxYesNo = new MessageDialog(Display.getDefault().getActiveShell(), msgTitle, null,
                message, MessageDialog.QUESTION,
                new String[] { IDialogConstants.NO_LABEL, IDialogConstants.YES_LABEL, }, 0);

        if (msgBoxYesNo.open() == 1) {//YES
            // Delete models now
            it = fSelectedModels.iterator();
            while (it.hasNext()) {
                String err = DBMSFactory.INSTANCE.deleteDatabase(it.next());
                if (!err.isEmpty()) { // if the database is not connected
                    MessageDialog.openError(
                            org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                            msgTitle, err);
                    break;
                }
            }
        }

    } catch (Exception ex) {
        if (ex.getMessage() != null) {
            MessageDialog.openError(
                    org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), msgTitle,
                    ex.getMessage());
        } else {
            MessageDialog.openError(
                    org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), msgTitle,
                    Messages.DeleteModelHandler_ErrDel);
        }

        Logger.getLogger(DeleteModelHandler.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
        // Check if connection still exists and all the views are notified
        // of the presence and absence of connection
        DBMSFactory.INSTANCE.verifyConnection();
    }

    return null;
}

From source file:org.eclipse.ui.actions.CopyFilesAndFoldersOperation.java

License:Open Source License

/**
 * Check if the user wishes to overwrite the supplied resource or all
 * resources.// w  w w  . j  ava2  s .co m
 * 
 * @param source
 *            the source resource
 * @param destination
 *            the resource to be overwritten
 * @return one of IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID,
 *         IDialogConstants.NO_ID, IDialogConstants.CANCEL_ID indicating
 *         whether the current resource or all resources can be overwritten,
 *         or if the operation should be canceled.
 */
private int checkOverwrite(final IResource source, final IResource destination) {
    final int[] result = new int[1];

    // Dialogs need to be created and opened in the UI thread
    Runnable query = new Runnable() {
        public void run() {
            String message;
            int resultId[] = { IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.NO_ID,
                    IDialogConstants.CANCEL_ID };
            String labels[] = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };

            if (destination.getType() == IResource.FOLDER) {
                if (homogenousResources(source, destination)) {
                    message = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteMergeQuestion,
                            destination.getFullPath().makeRelative());
                } else {
                    if (destination.isLinked()) {
                        message = NLS.bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeLinkQuestion,
                                destination.getFullPath().makeRelative());
                    } else {
                        message = NLS.bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeNoLinkQuestion,
                                destination.getFullPath().makeRelative());
                    }
                    resultId = new int[] { IDialogConstants.YES_ID, IDialogConstants.NO_ID,
                            IDialogConstants.CANCEL_ID };
                    labels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                            IDialogConstants.CANCEL_LABEL };
                }
            } else {
                String[] bindings = new String[] { IDEResourceInfoUtils.getLocationText(destination),
                        IDEResourceInfoUtils.getDateStringValue(destination),
                        IDEResourceInfoUtils.getLocationText(source),
                        IDEResourceInfoUtils.getDateStringValue(source) };
                message = NLS.bind(
                        IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteWithDetailsQuestion,
                        bindings);
            }
            MessageDialog dialog = new MessageDialog(messageShell,
                    IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceExists, null, message,
                    MessageDialog.QUESTION, labels, 0) {
                protected int getShellStyle() {
                    return super.getShellStyle() | SWT.SHEET;
                }
            };
            dialog.open();
            if (dialog.getReturnCode() == SWT.DEFAULT) {
                // A window close returns SWT.DEFAULT, which has to be
                // mapped to a cancel
                result[0] = IDialogConstants.CANCEL_ID;
            } else {
                result[0] = resultId[dialog.getReturnCode()];
            }
        }
    };
    messageShell.getDisplay().syncExec(query);
    return result[0];
}

From source file:org.eclipse.ui.actions.CopyFilesAndFoldersOperation.java

License:Open Source License

/**
 * Performs an import of the given stores into the provided container.
 * Returns a status indicating if the import was successful.
 * //w  w  w.ja va2s. c  om
 * @param stores
 *            stores that are to be imported
 * @param target
 *            container to which the import will be done
 * @param monitor
 *            a progress monitor for showing progress and for cancelation
 */
private void performFileImport(IFileStore[] stores, IContainer target, IProgressMonitor monitor) {
    IOverwriteQuery query = new IOverwriteQuery() {
        public String queryOverwrite(String pathString) {
            if (alwaysOverwrite) {
                return ALL;
            }

            final String returnCode[] = { CANCEL };
            final String msg = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteQuestion,
                    pathString);
            final String[] options = { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
            messageShell.getDisplay().syncExec(new Runnable() {
                public void run() {
                    MessageDialog dialog = new MessageDialog(messageShell,
                            IDEWorkbenchMessages.CopyFilesAndFoldersOperation_question, null, msg,
                            MessageDialog.QUESTION, options, 0) {
                        protected int getShellStyle() {
                            return super.getShellStyle() | SWT.SHEET;
                        }
                    };
                    dialog.open();
                    int returnVal = dialog.getReturnCode();
                    String[] returnCodes = { YES, ALL, NO, CANCEL };
                    returnCode[0] = returnVal == -1 ? CANCEL : returnCodes[returnVal];
                }
            });
            if (returnCode[0] == ALL) {
                alwaysOverwrite = true;
            } else if (returnCode[0] == CANCEL) {
                canceled = true;
            }
            return returnCode[0];
        }
    };

    ImportOperation op = new ImportOperation(target.getFullPath(), stores[0].getParent(),
            FileStoreStructureProvider.INSTANCE, query, Arrays.asList(stores));
    op.setContext(messageShell);
    op.setCreateContainerStructure(false);
    op.setVirtualFolders(createVirtualFoldersAndLinks);
    op.setCreateLinks(createLinks);
    op.setRelativeVariable(relativeVariable);
    try {
        op.run(monitor);
    } catch (InterruptedException e) {
        return;
    } catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof CoreException) {
            displayError(((CoreException) e.getTargetException()).getStatus());
        } else {
            display(e);
        }
        return;
    }
    // Special case since ImportOperation doesn't throw a CoreException on
    // failure.
    IStatus status = op.getStatus();
    if (!status.isOK()) {
        if (errorStatus == null) {
            errorStatus = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.ERROR, getProblemsMessage(), null);
        }
        errorStatus.merge(status);
    }
}

From source file:org.eclipse.ui.actions.ReadOnlyStateChecker.java

License:Open Source License

/**
  * Open a message dialog with Yes No, Yes To All and Cancel buttons. Return the
  * code that indicates the selection./*from  w  w  w. jav a 2  s.  c o  m*/
  * @return int 
  *   one of
  *      YES_TO_ALL_ID
  *      YES_ID
  *      NO_ID
  *      CANCEL_ID
  *       
  * @param resource - the resource being queried.
  */
private int queryYesToAllNoCancel(IResource resource) {

    final MessageDialog dialog = new MessageDialog(this.shell, this.titleMessage, null,
            MessageFormat.format(this.mainMessage, new Object[] { resource.getName() }), MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            0) {
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    shell.getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    int result = dialog.getReturnCode();
    if (result == 0) {
        return IDialogConstants.YES_ID;
    }
    if (result == 1) {
        return IDialogConstants.YES_TO_ALL_ID;
    }
    if (result == 2) {
        return IDialogConstants.NO_ID;
    }
    return IDialogConstants.CANCEL_ID;
}

From source file:org.eclipse.ui.actions.RefreshAction.java

License:Open Source License

/**
 * Checks whether the given project's location has been deleted. If so,
 * prompts the user with whether to delete the project or not.
 *///from w ww. jav a  2s. c  o m
void checkLocationDeleted(IProject project) throws CoreException {
    if (!project.exists()) {
        return;
    }
    IFileInfo location = IDEResourceInfoUtils.getFileInfo(project.getLocationURI());
    if (!location.exists()) {
        String message = NLS.bind(IDEWorkbenchMessages.RefreshAction_locationDeletedMessage, project.getName(),
                location.toString());

        final MessageDialog dialog = new MessageDialog(getShell(),
                IDEWorkbenchMessages.RefreshAction_dialogTitle, // dialog
                // title
                null, // use default window icon
                message, MessageDialog.QUESTION,
                new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) {
            protected int getShellStyle() {
                return super.getShellStyle() | SWT.SHEET;
            }
        }; // yes is the
           // default

        // Must prompt user in UI thread (we're in the operation thread
        // here).
        getShell().getDisplay().syncExec(new Runnable() {
            public void run() {
                dialog.open();
            }
        });

        // Do the deletion back in the operation thread
        if (dialog.getReturnCode() == 0) { // yes was chosen
            project.delete(true, true, null);
        }
    }
}

From source file:org.eclipse.ui.dialogs.SaveAsDialog.java

License:Open Source License

protected void okPressed() {
    // Get new path.
    IPath path = resourceGroup.getContainerFullPath().append(resourceGroup.getResource());

    //If the user does not supply a file extension and if the save 
    //as dialog was provided a default file name append the extension 
    //of the default filename to the new name
    if (path.getFileExtension() == null) {
        if (originalFile != null && originalFile.getFileExtension() != null) {
            path = path.addFileExtension(originalFile.getFileExtension());
        } else if (originalName != null) {
            int pos = originalName.lastIndexOf('.');
            if (++pos > 0 && pos < originalName.length()) {
                path = path.addFileExtension(originalName.substring(pos));
            }//from   w w  w.ja v a2  s.  c o m
        }
    }

    // If the path already exists then confirm overwrite.
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    if (file.exists()) {
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };
        String question = NLS.bind(IDEWorkbenchMessages.SaveAsDialog_overwriteQuestion, path.toString());
        MessageDialog d = new MessageDialog(getShell(), IDEWorkbenchMessages.Question, null, question,
                MessageDialog.QUESTION, buttons, 0) {
            protected int getShellStyle() {
                return super.getShellStyle() | SWT.SHEET;
            }
        };
        int overwrite = d.open();
        switch (overwrite) {
        case 0: // Yes
            break;
        case 1: // No
            return;
        case 2: // Cancel
        default:
            cancelPressed();
            return;
        }
    }

    // Store path and close.
    result = path;
    close();
}

From source file:org.eclipse.ui.dialogs.WizardDataTransferPage.java

License:Open Source License

/**
 * The <code>WizardDataTransfer</code> implementation of this 
 * <code>IOverwriteQuery</code> method asks the user whether the existing 
 * resource at the given path should be overwritten.
 *
 * @param pathString /*from w  w  w .j ava2s .  c o m*/
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, <code>"ALL"</code>, 
 *   or <code>"CANCEL"</code>
 */
public String queryOverwrite(String pathString) {

    Path path = new Path(pathString);

    String messageString;
    //Break the message up if there is a file name and a directory
    //and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
    } else {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
                path.lastSegment(), path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question,
            null, messageString, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    //run in syncExec because callback is from an operation,
    //which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}