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

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

Introduction

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

Prototype

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

Source Link

Document

Convenience method to open a simple confirm (OK/Cancel) dialog.

Usage

From source file:com.vectrace.MercurialEclipse.dialogs.CommitDialog.java

License:Open Source License

private boolean confirmHistoryRewrite() {
    if (HgFeatures.PHASES.isEnabled()) {
        // For secret or draft silently allow amend
        if (Phase.PUBLIC == currentChangeset.getPhase()) {
            if (!MessageDialog.openConfirm(getShell(), Messages.getString("CommitDialog.amendPublic.title"),
                    Messages.getString("CommitDialog.amendPublic.message"))) {
                return false;
            }/*from  w ww  .j a v  a 2  s . c o  m*/

            currentChangeset.setDraft();
        }

        return true;
    }

    // Always prompt if phases are not supported
    MessageDialog dialog = new MessageDialog(getShell(),
            Messages.getString("CommitDialog.reallyAmendAndRewriteHistory"), //$NON-NLS-1$
            null, Messages.getString("CommitDialog.amendWarning1") //$NON-NLS-1$
                    + Messages.getString("CommitDialog.amendWarning2") //$NON-NLS-1$
                    + Messages.getString("CommitDialog.amendWarning3"), //$NON-NLS-1$
            MessageDialog.CONFIRM, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.CANCEL_LABEL }, 1 // default index - cancel
    );
    dialog.setBlockOnOpen(true); // if false then may show in background
    return dialog.open() == 0; // 0 means yes

}

From source file:com.vectrace.MercurialEclipse.dialogs.NewHeadsDialog.java

License:Open Source License

/**
 * Checks that working copy is clear and (if needed) asks user to revert dirty files
 * @return false if user cancelled operation or an error occured
 *//*from   w  w w  .  j av a2  s .co m*/
private boolean clearAndContinue() {
    if (HgStatusClient.isDirty(hgRoot)) {
        boolean clearAndContinue = cleanUpdateRequested || MessageDialog.openConfirm(getShell(),
                "Uncommited changes", Messages.getString("RevertDialog.uncommitedChanges"));
        if (clearAndContinue) {
            HgRevertClient.performRevertAll(new NullProgressMonitor(), hgRoot);
            return true;
        }
        return false;
    }
    return true; // no changes found
}

From source file:com.vectrace.MercurialEclipse.dialogs.RevertDialog.java

License:Open Source License

@Override
protected void okPressed() {
    if (resources.size() != 1) {
        selection = selectFilesList.getCheckedResources(FILE_ADDED, FILE_DELETED, FILE_MODIFIED, FILE_REMOVED);
    } else {/*  w  w w  .  ja  v a  2 s  . c om*/
        selection = selectFilesList.getCheckedResources(FILE_ADDED, FILE_DELETED, FILE_MODIFIED, FILE_REMOVED,
                FILE_CLEAN);
    }
    untrackedSelection = selectFilesList.getCheckedResources(FILE_UNTRACKED);
    changeset = csTable.getSelection();

    if (!untrackedSelection.isEmpty()) {
        boolean confirm = MessageDialog.openConfirm(getShell(),
                Messages.getString("RevertDialog.pleaseConfirmDelete"), //$NON-NLS-1$
                Messages.getString("RevertDialog.youHaveSelectedToRevertUntracked") + //$NON-NLS-1$
                        Messages.getString("RevertDialog.thisFilesWillNowBeDeleted")); //$NON-NLS-1$
        if (!confirm) {
            return;
        }
    }
    super.okPressed();
}

From source file:com.vectrace.MercurialEclipse.repository.actions.RemoveRootAction.java

License:Open Source License

@Override
public void run() {
    IHgRepositoryLocation[] roots = getSelectedRemoteRoots();
    if (roots.length == 0) {
        return;/*w ww .  j  av  a2s  . c o m*/
    }
    boolean confirm = MessageDialog.openConfirm(null, "Mercurial Repositories",
            "Remove repository (all authentication data will be lost)?");
    if (!confirm) {
        return;
    }
    for (IHgRepositoryLocation repo : roots) {
        MercurialEclipsePlugin.getRepoManager().disposeRepository(repo);
    }
}

From source file:com.vectrace.MercurialEclipse.team.ActionCommit.java

License:Open Source License

/**
 * The action has been activated. The argument of the method represents the 'real' action
 * sitting in the workbench UI.//from   ww  w  . j a  v a 2s .com
 *
 * @throws HgException
 *
 * @see IWorkbenchWindowActionDelegate#run
 */
@Override
public void run(IAction action) {
    try {
        List<IResource> resources = new ArrayList<IResource>();
        boolean merging = collectResourcesToCommit(resources);
        if (!merging) {
            if (resources.size() == 0) {
                resources = getSelectedHgProjects();
            }
            doRun(resources);
        } else {
            Shell shell = MercurialEclipsePlugin.getActiveShell();
            boolean doCommit = MessageDialog.openConfirm(shell, Messages.getString("ActionCommit.HgCommit"), //$NON-NLS-1$
                    Messages.getString("ActionCommit.mergeIsRunning")); //$NON-NLS-1$
            if (doCommit) {
                doRun(resources);
            }
        }
    } catch (HgException e) {
        MercurialEclipsePlugin.logError(e);
        MercurialEclipsePlugin.showError(e);
    }
}

From source file:com.vectrace.MercurialEclipse.team.ActionRemove.java

License:Open Source License

private static boolean confirmRemove(Shell shell) {
    return MessageDialog.openConfirm(shell, Messages.getString("ActionRemove.removeFileTitle"),
            Messages.getString("ActionRemove.removeFileConfirmation"));
}

From source file:com.vectrace.MercurialEclipse.team.ActionRevert.java

License:Open Source License

/**
 * The action has been activated. The argument of the method represents the
 * 'real' action sitting in the workbench UI.
 *
 * @see IWorkbenchWindowActionDelegate#run
 *///from   w w  w . j  a  v a 2 s  .  com
public void run(IAction action) {
    if (window == null) {
        window = MercurialEclipsePlugin.getActiveWindow();
    }
    IResource singleSelection = getSingleSelection();
    if (singleSelection != null) {
        if (changesetToRevert != null) {
            try {
                revertToGivenVersion(singleSelection, changesetToRevert, new NullProgressMonitor());
            } catch (final HgException e) {
                handleWithDialog(e);
            }
            return;
        }
        if (action != null
                && "com.vectrace.MercurialEclipse.team.ReplaceWithParentAction".equals(action.getId())) {
            revertToParentVersion(singleSelection);
            return;
        }
    }

    List<IResource> resources = new ArrayList<IResource>();
    boolean mergeIsRunning = collectResourcesToRevert(resources);
    if (resources.size() > 0 && !mergeIsRunning) {
        openRevertDialog(resources, false);
    } else {
        if (mergeIsRunning) {
            boolean doRevert = MessageDialog.openConfirm(getShell(),
                    Messages.getString("ActionRevert.HgRevert"), //$NON-NLS-1$
                    Messages.getString("ActionRevert.mergeIsRunning")); //$NON-NLS-1$
            if (doRevert) {
                openRevertDialog(resources, true);
            }
        } else {
            MessageDialog.openInformation(getShell(), Messages.getString("ActionRevert.HgRevert"), //$NON-NLS-1$
                    Messages.getString("ActionRevert.noFilesToRevert")); //$NON-NLS-1$
        }
    }
}

From source file:com.vectrace.MercurialEclipse.team.HgMoveDeleteHook.java

License:Open Source License

/**
 * @see org.eclipse.core.resources.team.IMoveDeleteHook#moveProject(org.eclipse.core.resources.team.IResourceTree, org.eclipse.core.resources.IProject, org.eclipse.core.resources.IProjectDescription, int, org.eclipse.core.runtime.IProgressMonitor)
 *//*from  w ww . jav  a 2 s . c  o m*/
public boolean moveProject(IResourceTree tree, final IProject source, IProjectDescription description,
        int flags, IProgressMonitor monitor) {

    // two cases: 1) project containing the repo or 2) project contained in the repo
    // for 1) we need to clean the cache
    // for the 2) we need to move if the project is relocated (not just renamed)
    boolean isPartOfRepo = isContainedInRepository(source);
    if (!isPartOfRepo) {
        // Eclipse will simply move *entire* repository by itself and change project name in .project file
        MercurialStatusCache.getInstance().clear(source, false);
        MercurialRootCache.getInstance().projectDeletedOrClosed(source);
        return false;
    }

    // project is located inside a (bigger) repository
    boolean locationChanged = isLocationChanged(source, description);
    if (!locationChanged) {
        // Don't care - only .project file will be changed due the name change
        return false;
    }

    // move all project related files inside a bigger hg repository
    final HgRoot hgRoot = MercurialRootCache.getInstance().getHgRoot(source);
    IPath from = source.getLocation();
    try {
        IPath to = computeDestination(description);
        HgRenameClient.renameResource(from, to, hgRoot, monitor);

        final boolean[] commitDone = new boolean[] { false };
        Display.getDefault().syncExec(new Runnable() {
            public void run() {
                boolean commitNow = MessageDialog.openConfirm(MercurialEclipsePlugin.getActiveShell(),
                        "Project moved",
                        "All project files are now moved inside the Mercurial repository.\n"
                                + "A commit NOW is highly recommended!\n"
                                + "(otherwise you would need command line to commit removed files).\n\n"
                                + "Commit ALL changed files NOW?");
                if (commitNow) {
                    CommitHandler ch = new CommitHandler();
                    Options options = new Options();
                    options.defaultCommitMessage = "Moved project '" + source.getName() + "'.";
                    options.filesSelectable = false;
                    options.showAmend = false;
                    options.showCloseBranch = false;
                    options.showDiff = false;
                    options.showRevert = false;
                    options.allowEmptyCommit = true;
                    options.hgRoot = hgRoot;
                    ch.setOptions(options);
                    try {
                        ch.run(new ArrayList<IResource>());
                    } catch (HgException e) {
                        MercurialEclipsePlugin.logError(e);
                    }
                    commitDone[0] = ch.getResult() == Window.OK;
                }
            }
        });

        if (tree.movedProjectSubtree(source, description)) {
            if (!commitDone[0]) {
                Display.getDefault().syncExec(new Runnable() {
                    public void run() {
                        MessageDialog.openInformation(MercurialEclipsePlugin.getActiveShell(), "Project moved",
                                "Source files are marked for delete but still not committed.\n"
                                        + "As the Eclipse project doesn't exist anymore at the original location, "
                                        + "please consider to commit from the command line.");
                    }
                });
            }
            boolean isDeep = (flags & IResource.SHALLOW) == 0;
            IProject destination = source.getWorkspace().getRoot().getProject(description.getName());
            updateTimestamps(destination, isDeep, tree);
            return true;
        }
    } catch (Exception e) {
        MercurialEclipsePlugin.logError(e);
    } finally {
        new RefreshStatusJob("Updating cache", hgRoot).schedule(300);
    }
    return false;
}

From source file:com.vectrace.MercurialEclipse.ui.HgProjectPropertyPage.java

License:Open Source License

private void createButtons(final HgRepositoryLocationManager mgr) {
    Composite buttonComposite = createComposite(reposGroup, 3);
    final Button addRepo = createPushButton(buttonComposite, "Add...", 1);
    addRepo.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            NewLocationWizard wizard = new NewLocationWizard();
            WizardDialog dialog = new WizardDialog(addRepo.getShell(), wizard);
            int result = dialog.open();
            if (result != Window.OK) {
                return;
            }/*  w  w  w  .ja va  2 s. com*/
            if (wizard.getRepository() != null) {
                updateSelection(mgr.getAllRepoLocations(), wizard.getRepository());
            }
        }

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

    final Button modifyRepo = createPushButton(buttonComposite, "Modify...", 1);
    modifyRepo.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            if (defTextField.getData() != null) {
                PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(addRepo.getShell(),
                        (IAdaptable) defTextField.getData(),
                        "com.vectrace.MercurialEclipse.repositoryProperties", null, null);
                dialog.open();
            }
        }

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

    final Button deleteRepo = createPushButton(buttonComposite, "Delete...", 1);
    deleteRepo.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            IHgRepositoryLocation repo = (IHgRepositoryLocation) defTextField.getData();
            if (repo != null) {
                Set<HgRoot> locationRoots = mgr.getAllRepoLocationRoots(repo);
                String message;
                if ((locationRoots.size() == 1 && !locationRoots.contains(hgRoot))
                        || locationRoots.size() > 1) {
                    message = "Delete repository '" + repo.getLocation() + "'?"
                            + "\nAt least one other project still uses this repository!";
                } else {
                    message = "Delete repository '" + repo.getLocation() + "'?";
                }
                boolean confirm = MessageDialog.openConfirm(getShell(), "Mercurial", message);
                if (confirm) {
                    mgr.disposeRepository(repo);
                    updateSelection(mgr.getAllRepoLocations(), null);
                }
            }
        }

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