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.android.sdkuilib.internal.repository.RemotePackagesPage.java

License:Apache License

private void onRemoveSiteSelected() {
    boolean changed = false;

    ISelection sel = mTreeViewerSources.getSelection();
    if (mUpdaterData != null && sel instanceof ITreeSelection) {
        for (Object c : ((ITreeSelection) sel).toList()) {
            if (c instanceof SdkSource) {
                SdkSource source = (SdkSource) c;

                if (mUpdaterData.getSources().hasSourceUrl(SdkSourceCategory.USER_ADDONS, source)) {
                    String title = "Delete Add-on Site?";

                    String msg = String.format("Are you sure you want to delete the add-on site '%1$s'?",
                            source.getUrl());

                    if (MessageDialog.openQuestion(getShell(), title, msg)) {
                        mUpdaterData.getSources().remove(source);
                        changed = true;//from w w  w .  j  a v  a  2s  .  co m
                    }
                }
            }
        }
    }

    if (changed) {
        onRefreshSelected();
    }
}

From source file:com.android.sdkuilib.internal.repository.sdkman2.PackagesPage.java

License:Apache License

/**
 * Called when the Delete Package button is selected.
 * Collects the packages to be deleted, prompt the user for confirmation
 * and actually performs the deletion.//from w w  w .j  av a2s .  c  o m
 */
private void onButtonDelete() {
    final String title = "Delete SDK Package";
    StringBuilder msg = new StringBuilder("Are you sure you want to delete:");

    // A list of archives to delete
    final ArrayList<Archive> archives = new ArrayList<Archive>();

    getArchivesToDelete(msg, archives);

    if (!archives.isEmpty()) {
        msg.append("\n").append("This cannot be undone."); //$NON-NLS-1$
        if (MessageDialog.openQuestion(getShell(), title, msg.toString())) {
            try {
                beginOperationPending();

                mUpdaterData.getTaskFactory().start("Delete Package", new ITask() {
                    public void run(ITaskMonitor monitor) {
                        monitor.setProgressMax(archives.size() + 1);
                        for (Archive a : archives) {
                            monitor.setDescription("Deleting '%1$s' (%2$s)",
                                    a.getParentPackage().getShortDescription(), a.getLocalOsPath());

                            // Delete the actual package
                            a.deleteLocal();

                            monitor.incProgress(1);
                            if (monitor.isCancelRequested()) {
                                break;
                            }
                        }

                        monitor.incProgress(1);
                        monitor.setDescription("Done");
                    }
                });
            } finally {
                endOperationPending();

                // The local package list has changed, make sure to refresh it
                localReload();
            }
        }
    }
}

From source file:com.android.sdkuilib.internal.repository.SwtUpdaterData.java

License:Apache License

/**
 * Attempts to restart ADB./*from  www.j av a2  s  . co m*/
 * <p/>
 * If the "ask before restart" setting is set (the default), prompt the user whether
 * now is a good time to restart ADB.
 */
@Override
protected void askForAdbRestart(ITaskMonitor monitor) {
    final boolean[] canRestart = new boolean[] { true };

    if (getWindowShell() != null && getSettingsController().getSettings().getAskBeforeAdbRestart()) {
        // need to ask for permission first
        final Shell shell = getWindowShell();
        if (shell != null && !shell.isDisposed()) {
            shell.getDisplay().syncExec(new Runnable() {
                @Override
                public void run() {
                    if (!shell.isDisposed()) {
                        canRestart[0] = MessageDialog.openQuestion(shell, "ADB Restart",
                                "A package that depends on ADB has been updated. \n"
                                        + "Do you want to restart ADB now?");
                    }
                }
            });
        }
    }

    if (canRestart[0]) {
        AdbWrapper adb = new AdbWrapper(getOsSdkRoot(), monitor);
        adb.stopAdb();
        adb.startAdb();
    }
}

From source file:com.android.sdkuilib.internal.repository.ui.DeviceManagerPage.java

License:Apache License

private void onDeleteDevice() {
    CellInfo ci = getTableSelection();//from  w  ww . jav a  2s  .  co  m
    if (ci == null || ci.mDevice == null || !ci.mIsUser) {
        return;
    }

    final String name = getPrettyName(ci.mDevice, false /*leadZeroes*/);
    final AtomicBoolean result = new AtomicBoolean(false);
    getDisplay().syncExec(new Runnable() {
        @Override
        public void run() {
            Shell shell = getDisplay().getActiveShell();
            boolean ok = MessageDialog.openQuestion(shell, "Delete Device Definition", String.format(
                    "Please confirm that you want to delete the device definition named '%s'. This operation cannot be reverted.",
                    name));
            result.set(ok);
        }
    });

    if (result.get()) {
        mDeviceManager.removeUserDevice(ci.mDevice);
        mDeviceManager.saveUserDevices();
        onRefresh();
    }
}

From source file:com.android.sdkuilib.internal.repository.ui.PackagesPage.java

License:Apache License

/**
 * Called when the Delete Package button is selected.
 * Collects the packages to be deleted, prompt the user for confirmation
 * and actually performs the deletion./*from  w  w  w  .  j  a  v  a2  s .c om*/
 */
private void onButtonDelete() {
    final String title = "Delete SDK Package";
    StringBuilder msg = new StringBuilder("Are you sure you want to delete:");

    // A list of archives to delete
    final ArrayList<Archive> archives = new ArrayList<Archive>();

    getArchivesToDelete(msg, archives);

    if (!archives.isEmpty()) {
        msg.append("\n").append("This cannot be undone."); //$NON-NLS-1$
        if (MessageDialog.openQuestion(getShell(), title, msg.toString())) {
            try {
                beginOperationPending();

                mImpl.mSwtUpdaterData.getTaskFactory().start("Delete Package", new ITask() {
                    @Override
                    public void run(ITaskMonitor monitor) {
                        monitor.setProgressMax(archives.size() + 1);
                        for (Archive a : archives) {
                            monitor.setDescription("Deleting '%1$s' (%2$s)",
                                    a.getParentPackage().getShortDescription(), a.getLocalOsPath());

                            // Delete the actual package
                            a.deleteLocal();

                            monitor.incProgress(1);
                            if (monitor.isCancelRequested()) {
                                break;
                            }
                        }

                        monitor.incProgress(1);
                        monitor.setDescription("Done");
                    }
                });
            } finally {
                endOperationPending();

                // The local package list has changed, make sure to refresh it
                mImpl.localReload();
            }
        }
    }
}

From source file:com.android.sdkuilib.internal.repository.UpdaterData.java

License:Apache License

/**
 * Attempts to restart ADB./*from w ww .  j a  v a  2s  .c  o  m*/
 * <p/>
 * If the "ask before restart" setting is set (the default), prompt the user whether
 * now is a good time to restart ADB.
 *
 * @param monitor
 */
private void askForAdbRestart(ITaskMonitor monitor) {
    final boolean[] canRestart = new boolean[] { true };

    if (getWindowShell() != null && getSettingsController().getAskBeforeAdbRestart()) {
        // need to ask for permission first
        final Shell shell = getWindowShell();
        if (shell != null && !shell.isDisposed()) {
            shell.getDisplay().syncExec(new Runnable() {
                public void run() {
                    if (!shell.isDisposed()) {
                        canRestart[0] = MessageDialog.openQuestion(shell, "ADB Restart",
                                "A package that depends on ADB has been updated. \n"
                                        + "Do you want to restart ADB now?");
                    }
                }
            });
        }
    }

    if (canRestart[0]) {
        AdbWrapper adb = new AdbWrapper(getOsSdkRoot(), monitor);
        adb.stopAdb();
        adb.startAdb();
    }
}

From source file:com.android.sdkuilib.internal.tasks.ProgressTask.java

License:Apache License

/**
 * Display a yes/no question dialog box.
 *
 * This implementation allow this to be called from any thread, it
 * makes sure the dialog is opened synchronously in the ui thread.
 *
 * @param title The title of the dialog box
 * @param message The error message//  ww w  .  j a  va 2s  .com
 * @return true if YES was clicked.
 */
public boolean displayPrompt(final String title, final String message) {
    final Shell shell = mDialog.getParent();
    Display display = shell.getDisplay();

    // we need to ask the user what he wants to do.
    final boolean[] result = new boolean[] { false };
    display.syncExec(new Runnable() {
        public void run() {
            result[0] = MessageDialog.openQuestion(shell, title, message);
        }
    });
    return result[0];
}

From source file:com.android.sdkuilib.internal.tasks.ProgressTaskDialog.java

License:Apache License

/**
 * Display a yes/no question dialog box.
 *
 * This implementation allow this to be called from any thread, it
 * makes sure the dialog is opened synchronously in the ui thread.
 *
 * @param title The title of the dialog box
 * @param message The error message/*w ww. jav a2 s.  c  o m*/
 * @return true if YES was clicked.
 */
@Override
public boolean displayPrompt(final String title, final String message) {
    Display display = mDialogShell.getDisplay();

    // we need to ask the user what he wants to do.
    final boolean[] result = new boolean[] { false };
    display.syncExec(new Runnable() {
        @Override
        public void run() {
            result[0] = MessageDialog.openQuestion(mDialogShell, title, message);
        }
    });
    return result[0];
}

From source file:com.android.sdkuilib.internal.tasks.ProgressView.java

License:Apache License

@Override
public boolean displayPrompt(final String title, final String message) {
    final boolean[] result = new boolean[] { false };

    syncExec(mProgressBar, new Runnable() {
        @Override/*from w ww. j ava 2s  .c om*/
        public void run() {
            Shell shell = mProgressBar.getShell();
            result[0] = MessageDialog.openQuestion(shell, title, message);
        }
    });

    return result[0];
}

From source file:com.android.sdkuilib.internal.widgets.AvdSelector.java

License:Apache License

private void onDelete() {
    final AvdInfo avdInfo = getTableSelection();

    // get the current Display
    final Display display = mTable.getDisplay();

    // check if the AVD is running
    if (mAvdManager.isAvdRunning(avdInfo)) {
        display.asyncExec(new Runnable() {
            @Override//from  ww  w.j a v a 2 s  .co m
            public void run() {
                Shell shell = display.getActiveShell();
                MessageDialog.openError(shell, "Delete Android Virtual Device", String.format(
                        "The Android Virtual Device '%1$s' is currently running in an emulator and cannot be deleted.",
                        avdInfo.getName()));
            }
        });
        return;
    }

    // Confirm you want to delete this AVD
    final boolean[] result = new boolean[1];
    display.syncExec(new Runnable() {
        @Override
        public void run() {
            Shell shell = display.getActiveShell();
            result[0] = MessageDialog.openQuestion(shell, "Delete Android Virtual Device", String.format(
                    "Please confirm that you want to delete the Android Virtual Device named '%s'. This operation cannot be reverted.",
                    avdInfo.getName()));
        }
    });

    if (result[0] == false) {
        return;
    }

    // log for this action.
    ILogger log = mSdkLog;
    if (log == null || log instanceof MessageBoxLog) {
        // If the current logger is a message box, we use our own (to make sure
        // to display errors right away and customize the title).
        log = new MessageBoxLog(String.format("Result of deleting AVD '%s':", avdInfo.getName()), display,
                false /*logErrorsOnly*/);
    }

    // delete the AVD
    boolean success = mAvdManager.deleteAvd(avdInfo, log);

    // display the result
    if (log instanceof MessageBoxLog) {
        ((MessageBoxLog) log).displayResult(success);
    }

    if (success) {
        refresh(false /*reload*/);
    }
}