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.team.internal.ccvs.ui.subscriber.WorkspaceCommitOperation.java

License:Open Source License

/**
 * Prompts the user to determine how conflicting changes should be handled.
 * Note: This method is designed to be overridden by test cases.
 * @return 0 to sync conflicts, 1 to sync all non-conflicts, 2 to cancel
 *///from www  .jav a  2  s  .  c om
protected int promptForConflicts(SyncInfoSet syncSet) {
    String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
            IDialogConstants.CANCEL_LABEL };
    String question = CVSUIMessages.CommitSyncAction_questionRelease;
    String title = CVSUIMessages.CommitSyncAction_titleRelease;
    String[] tips = new String[] { CVSUIMessages.CommitSyncAction_releaseAll,
            CVSUIMessages.CommitSyncAction_releasePart, CVSUIMessages.CommitSyncAction_cancelRelease };
    Shell shell = getShell();
    final ToolTipMessageDialog dialog = new ToolTipMessageDialog(shell, title, null, question,
            MessageDialog.QUESTION, buttons, tips, 0);
    shell.getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode();
}

From source file:org.eclipse.team.internal.ccvs.ui.wizards.GenerateDiffFileWizard.java

License:Open Source License

public boolean validateFile(File file) {

    if (file == null)
        return false;

    /**//from w  w  w .  jav  a  2 s  .c om
     * Consider file valid if it doesn't exist for now.
     */
    if (!file.exists())
        return true;

    /**
     * The file exists.
     */
    if (!file.canWrite()) {
        final String title = CVSUIMessages.GenerateCVSDiff_1;
        final String msg = CVSUIMessages.GenerateCVSDiff_2;
        final MessageDialog dialog = new MessageDialog(getShell(), title, null, msg, MessageDialog.ERROR,
                new String[] { IDialogConstants.OK_LABEL }, 0);
        dialog.open();
        return false;
    }

    final String title = CVSUIMessages.GenerateCVSDiff_overwriteTitle;
    final String msg = CVSUIMessages.GenerateCVSDiff_overwriteMsg;
    final MessageDialog dialog = new MessageDialog(getShell(), title, null, msg, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
    dialog.open();
    if (dialog.getReturnCode() != 0)
        return false;

    return true;
}

From source file:org.eclipse.team.internal.ui.dialogs.MultipleYesNoPrompter.java

License:Open Source License

/**
 * Opens the confirmation dialog based on the prompt condition settings.
 *//*from w  ww .  ja  va2  s.c  o  m*/
private boolean confirmOverwrite(String msg) throws InterruptedException {
    Shell shell = shellProvider.getShell();
    if (shell == null)
        return false;
    final MessageDialog dialog = new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION, buttons, 0);

    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    shell.getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    if (hasMultiple) {
        switch (dialog.getReturnCode()) {
        case 0://Yes
            return true;
        case 1://Yes to all
            confirmation = YES_TO_ALL;
            return true;
        case 2://No (or CANCEL for all-or-nothing)
            if (allOrNothing) {
                throw new InterruptedException();
            }
            return false;
        case 3://No to all
            confirmation = NO_TO_ALL;
            return false;
        case 4://Cancel
        default:
            throw new InterruptedException();
        }
    } else {
        switch (dialog.getReturnCode()) {
        case 0:// Yes
            return true;
        case 1:// No
            return false;
        case 2:// Cancel
        default:
            throw new InterruptedException();
        }
    }
}

From source file:org.eclipse.team.internal.ui.history.LocalHistoryPage.java

License:Open Source License

private boolean confirmOverwrite() {
    if (file != null && file.exists()) {
        String title = TeamUIMessages.LocalHistoryPage_OverwriteTitle;
        String msg = TeamUIMessages.LocalHistoryPage_OverwriteMessage;
        IHistoryPageSite parentSite = getHistoryPageSite();
        final MessageDialog dialog = new MessageDialog(parentSite.getShell(), title, null, msg,
                MessageDialog.QUESTION,
                new String[] { IDialogConstants.YES_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
        final int[] result = new int[1];
        parentSite.getShell().getDisplay().syncExec(new Runnable() {
            public void run() {
                result[0] = dialog.open();
            }//from   ww w  .ja v  a2s . c o m
        });
        if (result[0] != 0) {
            // cancel
            return false;
        }
    }
    return true;
}

From source file:org.eclipse.team.internal.ui.ProjectSetImporter.java

License:Open Source License

private static IProject[] importProjectSet(XMLMemento xmlMemento, String filename, Shell shell,
        IProgressMonitor monitor) throws InvocationTargetException {
    try {//  w  w  w .  j a  va 2s . com
        String version = xmlMemento.getString("version"); //$NON-NLS-1$

        List newProjects = new ArrayList();
        if (version.equals("1.0")) { //$NON-NLS-1$
            IProjectSetSerializer serializer = Team.getProjectSetSerializer("versionOneSerializer"); //$NON-NLS-1$
            if (serializer != null) {
                IProject[] projects = serializer.addToWorkspace(new String[0], filename, shell, monitor);
                if (projects != null)
                    newProjects.addAll(Arrays.asList(projects));
            }
        } else {
            UIProjectSetSerializationContext context = new UIProjectSetSerializationContext(shell, filename);
            List errors = new ArrayList();
            IMemento[] providers = xmlMemento.getChildren("provider"); //$NON-NLS-1$
            for (int i = 0; i < providers.length; i++) {
                ArrayList referenceStrings = new ArrayList();
                IMemento[] projects = providers[i].getChildren("project"); //$NON-NLS-1$
                for (int j = 0; j < projects.length; j++) {
                    referenceStrings.add(projects[j].getString("reference")); //$NON-NLS-1$
                }
                try {
                    String id = providers[i].getString("id"); //$NON-NLS-1$
                    TeamCapabilityHelper.getInstance().processRepositoryId(id,
                            PlatformUI.getWorkbench().getActivitySupport());
                    RepositoryProviderType providerType = RepositoryProviderType.getProviderType(id);
                    if (providerType == null) {
                        // The provider type is absent. Perhaps there is another provider that can import this type
                        providerType = TeamPlugin.getAliasType(id);
                    }
                    if (providerType == null) {
                        throw new TeamException(new Status(IStatus.ERROR, TeamUIPlugin.ID, 0,
                                NLS.bind(TeamUIMessages.ProjectSetImportWizard_0, new String[] { id }), null));
                    }
                    ProjectSetCapability serializer = providerType.getProjectSetCapability();
                    ProjectSetCapability.ensureBackwardsCompatible(providerType, serializer);
                    if (serializer != null) {
                        IProject[] allProjects = serializer.addToWorkspace(
                                (String[]) referenceStrings.toArray(new String[referenceStrings.size()]),
                                context, monitor);
                        if (allProjects != null)
                            newProjects.addAll(Arrays.asList(allProjects));
                    }
                } catch (TeamException e) {
                    errors.add(e);
                }
            }
            if (!errors.isEmpty()) {
                TeamException[] exceptions = (TeamException[]) errors.toArray(new TeamException[errors.size()]);
                IStatus[] status = new IStatus[exceptions.length];
                for (int i = 0; i < exceptions.length; i++) {
                    status[i] = exceptions[i].getStatus();
                }
                throw new TeamException(new MultiStatus(TeamUIPlugin.ID, 0, status,
                        TeamUIMessages.ProjectSetImportWizard_1, null));
            }

            //try working sets
            IMemento[] sets = xmlMemento.getChildren("workingSets"); //$NON-NLS-1$
            IWorkingSetManager wsManager = TeamUIPlugin.getPlugin().getWorkbench().getWorkingSetManager();
            boolean replaceAll = false;
            boolean mergeAll = false;
            boolean skipAll = false;

            for (int i = 0; i < sets.length; i++) {
                IWorkingSet newWs = wsManager.createWorkingSet(sets[i]);
                if (newWs != null) {
                    IWorkingSet oldWs = wsManager.getWorkingSet(newWs.getName());
                    if (oldWs == null) {
                        wsManager.addWorkingSet(newWs);
                    } else if (replaceAll) {
                        replaceWorkingSet(wsManager, newWs, oldWs);
                    } else if (mergeAll) {
                        mergeWorkingSets(newWs, oldWs);
                    } else if (!skipAll) {
                        // a working set with the same name has been found
                        String title = TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_title;
                        String msg = NLS.bind(
                                TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_message,
                                newWs.getName());
                        String[] buttons = new String[] {
                                TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_replace,
                                TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_merge,
                                TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_skip,
                                IDialogConstants.CANCEL_LABEL };
                        final AdviceDialog dialog = new AdviceDialog(shell, title, null, msg,
                                MessageDialog.QUESTION, buttons, 0);

                        shell.getDisplay().syncExec(new Runnable() {
                            public void run() {
                                dialog.open();
                            }
                        });

                        switch (dialog.getReturnCode()) {
                        case 0: // overwrite
                            replaceWorkingSet(wsManager, newWs, oldWs);
                            replaceAll = dialog.applyToAll;
                            break;
                        case 1: // combine
                            mergeWorkingSets(newWs, oldWs);
                            mergeAll = dialog.applyToAll;
                            break;
                        case 2: // skip
                            skipAll = dialog.applyToAll;
                            break;
                        case 3: // cancel
                        default:
                            throw new OperationCanceledException();
                        }
                    }
                }
            }
        }

        return (IProject[]) newProjects.toArray(new IProject[newProjects.size()]);
    } catch (TeamException e) {
        throw new InvocationTargetException(e);
    }
}

From source file:org.eclipse.team.internal.ui.synchronize.actions.RemoveSynchronizeParticipantAction.java

License:Open Source License

private boolean promptToSave(List dirtyModels) {
    if (dirtyModels.size() == 1) {
        Saveable model = (Saveable) dirtyModels.get(0);
        String message = NLS.bind(TeamUIMessages.RemoveSynchronizeParticipantAction_2, model.getName());
        // Show a dialog.
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };
        MessageDialog d = new MessageDialog(view.getSite().getShell(),
                TeamUIMessages.RemoveSynchronizeParticipantAction_3, null, message, MessageDialog.QUESTION,
                buttons, 0);//  w  w  w.j  av  a 2 s . c o  m

        int choice = d.open();

        // Branch on the user choice.
        // The choice id is based on the order of button labels
        // above.
        switch (choice) {
        case 0: // yes
            break;
        case 1: // no
            return true;
        default:
        case 2: // cancel
            return false;
        }
    } else {
        ListSelectionDialog dlg = new ListSelectionDialog(view.getSite().getShell(), dirtyModels,
                new ArrayContentProvider(), new WorkbenchPartLabelProvider(),
                TeamUIMessages.RemoveSynchronizeParticipantAction_4);
        dlg.setInitialSelections(dirtyModels.toArray());
        dlg.setTitle(TeamUIMessages.RemoveSynchronizeParticipantAction_5);

        int result = dlg.open();
        //Just return false to prevent the operation continuing
        if (result == IDialogConstants.CANCEL_ID)
            return false;

        dirtyModels = Arrays.asList(dlg.getResult());
    }

    // If the editor list is empty return.
    if (dirtyModels.isEmpty())
        return true;

    // Create save block.
    final List finalModels = dirtyModels;
    IRunnableWithProgress progressOp = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            monitor.beginTask(null, finalModels.size());
            for (Iterator i = finalModels.iterator(); i.hasNext();) {
                Saveable model = (Saveable) i.next();
                if (model.isDirty()) {
                    try {
                        model.doSave(new SubProgressMonitor(monitor, 1));
                    } catch (CoreException e) {
                        ErrorDialog.openError(view.getSite().getShell(), null, e.getMessage(), e.getStatus());
                    }
                }
                if (monitor.isCanceled())
                    break;
            }
            monitor.done();
        }
    };
    try {
        PlatformUI.getWorkbench().getProgressService().run(true, true, progressOp);
    } catch (InvocationTargetException e) {
        Utils.handleError(view.getSite().getShell(), e, null, null);
        return false;
    } catch (InterruptedException e) {
        // Ignore
    }
    // TODO: How do we handle a cancel during save?
    return true;
}

From source file:org.eclipse.team.internal.ui.synchronize.LocalResourceSaveableComparison.java

License:Open Source License

/**
 * Check whether there is a conflicting save on the file.
 * @return <code>true</code> if there was and the user chose to cancel the operation
 *///from   www. j  av a  2s  .co  m
private boolean checkForUpdateConflicts() {
    if (hasSaveConflict()) {
        if (Utils.RUNNING_TESTS)
            return !Utils.TESTING_FLUSH_ON_COMPARE_INPUT_CHANGE;
        final MessageDialog dialog = new MessageDialog(TeamUIPlugin.getStandardDisplay().getActiveShell(),
                TeamUIMessages.SyncInfoCompareInput_0, null, TeamUIMessages.SyncInfoCompareInput_1,
                MessageDialog.QUESTION,
                new String[] { TeamUIMessages.SyncInfoCompareInput_2, IDialogConstants.CANCEL_LABEL }, 0);

        int retval = dialog.open();
        switch (retval) {
        // save
        case 0:
            return false;
        // cancel
        case 1:
            return true;
        }
    }
    return false;
}

From source file:org.eclipse.team.svn.revision.graph.operation.CheckRepositoryConnectionOperation.java

License:Open Source License

protected void runImpl(IProgressMonitor monitor) throws Exception {
    this.isServerSupportsMergeInfo = this.canIncludeMergeInfo;

    IRepositoryRoot root = this.resource.getRepositoryLocation().getRepositoryRoot();
    try {/*from ww w  . jav  a  2 s . co m*/
        this.lastRepositoryRevision = root.getRevision();
        this.hasConnection = this.lastRepositoryRevision != SVNRevision.INVALID_REVISION_NUMBER;
    } catch (SVNConnectorException e) {
        if (e instanceof SVNConnectorCancelException) {
            throw e;
        } else {
            this.hasConnection = false;
        }
    }

    if (!this.hasConnection) {
        final boolean[] isProceedWithoutConnection = new boolean[] { false };
        //ask if there's no connection
        UIMonitorUtility.getDisplay().syncExec(new Runnable() {
            public void run() {
                MessageDialog dlg = new MessageDialog(UIMonitorUtility.getShell(),
                        SVNRevisionGraphMessages.Dialog_GraphTitle, null,
                        SVNRevisionGraphMessages.CheckRepositoryConnectionOperation_DialogMessage,
                        MessageDialog.QUESTION,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);

                isProceedWithoutConnection[0] = dlg.open() == 0;
            }
        });

        if (!isProceedWithoutConnection[0]) {
            throw new ActivityCancelledException();
        }
    } else if (this.isValidateMergeInfo && this.canIncludeMergeInfo) {
        this.checkMergeInfo(monitor);
    }
}

From source file:org.eclipse.team.svn.revision.graph.preferences.SVNTeamRevisionGraphPage.java

License:Open Source License

protected void removeCaches() {
    MessageDialog dlg = new MessageDialog(this.getShell(),
            SVNRevisionGraphMessages.SVNTeamRevisionGraphPage_RemoveConfirm_Title, null,
            SVNRevisionGraphMessages.SVNTeamRevisionGraphPage_RemoveConfirm_Description, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
    if (dlg.open() == 0) {
        RepositoryCacheInfo[] caches = this.getSelectedCaches();
        this.cachesManager.remove(caches);
    }/*from  w ww  .ja va2s . c o  m*/
}

From source file:org.eclipse.team.svn.ui.crashrecovery.UpgradeWorkingCopyHelper.java

License:Open Source License

public boolean acquireResolution(ErrorDescription description) {
    if (description.code == ErrorDescription.WORKING_COPY_REQUIRES_UPGRADE) {
        final IProject project = (IProject) description.context;
        final boolean[] solved = new boolean[] { false };
        UIMonitorUtility.parallelSyncExec(new Runnable() {
            public void run() {
                String title = SVNUIMessages.format(SVNUIMessages.UpgradeWorkingCopyDialog_Title,
                        new String[] { project.getName() });
                MessageDialog dlg = new MessageDialog(UIMonitorUtility.getShell(), title, null,
                        SVNUIMessages.UpgradeWorkingCopyDialog_Message, MessageDialog.QUESTION,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
                if (dlg.open() == 0) {
                    UIMonitorUtility.doTaskNowDefault(UIMonitorUtility.getShell(),
                            new UpgradeWorkingCopyOperation(new IResource[] { project }), false);
                    solved[0] = true;//from   ww w.  j a v a 2 s  .c om
                }
            }
        });
        return solved[0];
    }
    return false;
}