Example usage for org.eclipse.jface.dialogs IDialogConstants YES_ID

List of usage examples for org.eclipse.jface.dialogs IDialogConstants YES_ID

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs IDialogConstants YES_ID.

Prototype

int YES_ID

To view the source code for org.eclipse.jface.dialogs IDialogConstants YES_ID.

Click Source Link

Document

Button id for a "Yes" button (value 2).

Usage

From source file:org.eclipse.debug.internal.ui.actions.breakpoints.RemoveAllTriggerPointsAction.java

License:Open Source License

@Override
public void run(IAction action) {
    IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
    if (window == null) {
        return;/* www .  j  a  v  a2  s . co m*/
    }
    IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
    boolean prompt = store.getBoolean(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_ALL_TRIGGER_BREAKPOINTS);
    boolean proceed = true;
    if (prompt) {
        MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(window.getShell(),
                ActionMessages.RemoveAllTriggerPointsAction_0, ActionMessages.RemoveAllTriggerPointsAction_1,
                ActionMessages.RemoveAllBreakpointsAction_3, !prompt, null, null);
        if (mdwt.getReturnCode() != IDialogConstants.YES_ID) {
            proceed = false;
        } else {
            store.setValue(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_ALL_TRIGGER_BREAKPOINTS,
                    !mdwt.getToggleState());
        }
    }
    if (proceed) {
        new Job(ActionMessages.RemoveAllTriggerPointsAction_1) {
            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    DebugPlugin.getDefault().getBreakpointManager().removeAllTriggerPoints();
                } catch (CoreException e) {
                    DebugUIPlugin.log(e);
                    return Status.CANCEL_STATUS;
                }
                return Status.OK_STATUS;
            }
        }.schedule();
    }
}

From source file:org.eclipse.debug.internal.ui.actions.expressions.RemoveAllExpressionsAction.java

License:Open Source License

public void run(IAction action) {
    IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
    if (window != null) {
        IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
        boolean prompt = store.getBoolean(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_ALL_EXPRESSIONS);
        boolean proceed = true;
        if (prompt) {
            MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(window.getShell(),
                    ActionMessages.RemoveAllExpressionsAction_0, ActionMessages.RemoveAllExpressionsAction_1,
                    ActionMessages.RemoveAllBreakpointsAction_3, !prompt, null, null);
            if (mdwt.getReturnCode() != IDialogConstants.YES_ID) {
                proceed = false;// w w w .  java2 s . c  o  m
            } else {
                store.setValue(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_ALL_EXPRESSIONS,
                        !mdwt.getToggleState());
            }
        }
        if (proceed) {
            IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager();
            IExpression[] expressions = manager.getExpressions();
            manager.removeExpressions(expressions);
        }
    }
}

From source file:org.eclipse.debug.internal.ui.DebugUIPlugin.java

License:Open Source License

/**
 * Saves and builds the workspace according to current preference settings and
 * launches the given launch configuration in the specified mode in the
 * foreground with a progress dialog. Reports any exceptions that occur
 * in an error dialog.// ww  w  .j a v a 2s  .  c o m
 * 
 * @param configuration the configuration to launch
 * @param mode launch mode
 * @since 3.0
 */
public static void launchInForeground(final ILaunchConfiguration configuration, final String mode) {
    final IJobManager jobManager = Job.getJobManager();
    IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
    boolean wait = false;

    if (jobManager.find(ResourcesPlugin.FAMILY_AUTO_BUILD).length > 0
            || jobManager.find(ResourcesPlugin.FAMILY_MANUAL_BUILD).length > 0) {
        String waitForBuild = store.getString(IInternalDebugUIConstants.PREF_WAIT_FOR_BUILD);

        if (waitForBuild.equals(MessageDialogWithToggle.PROMPT)) {
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(getShell(),
                    DebugUIMessages.DebugUIPlugin_23, DebugUIMessages.DebugUIPlugin_24, null, false, store,
                    IInternalDebugUIConstants.PREF_WAIT_FOR_BUILD); //

            switch (dialog.getReturnCode()) {
            case IDialogConstants.CANCEL_ID:
                return;
            case IDialogConstants.YES_ID:
                wait = false;
                break;
            case IDialogConstants.NO_ID:
                wait = true;
                break;
            }
        } else if (waitForBuild.equals(MessageDialogWithToggle.ALWAYS)) {
            wait = true;
        }
    }

    if (wait) {
        IWorkbench workbench = DebugUIPlugin.getDefault().getWorkbench();
        IProgressService progressService = workbench.getProgressService();
        final IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                /* Setup progress monitor
                 * - Waiting for jobs to finish (2)
                 * - Build & launch (98) */
                monitor.beginTask(MessageFormat.format(DebugUIMessages.DebugUIPlugin_25,
                        new Object[] { configuration.getName() }), 100);

                try {
                    jobManager.join(ResourcesPlugin.FAMILY_MANUAL_BUILD, new SubProgressMonitor(monitor, 1));
                    jobManager.join(ResourcesPlugin.FAMILY_AUTO_BUILD, new SubProgressMonitor(monitor, 1));
                } catch (InterruptedException e) {
                    /* continue*/}
                if (!monitor.isCanceled()) {
                    try {
                        buildAndLaunch(configuration, mode, new SubProgressMonitor(monitor, 98));
                    } catch (CoreException e) {
                        throw new InvocationTargetException(e);
                    }
                }
            }
        };
        try {
            progressService.busyCursorWhile(runnable);
        } catch (InterruptedException e) {
        } catch (InvocationTargetException e2) {
            handleInvocationTargetException(e2, configuration, mode);
        }
    } else {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                /* Setup progress monitor
                 * - Build & launch (1) */
                monitor.beginTask(MessageFormat.format(DebugUIMessages.DebugUIPlugin_25,
                        new Object[] { configuration.getName() }), 1);
                try {
                    buildAndLaunch(configuration, mode, new SubProgressMonitor(monitor, 1));
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
        } catch (InvocationTargetException e) {
            handleInvocationTargetException(e, configuration, mode);
        } catch (InterruptedException e) {
        }

    }
}

From source file:org.eclipse.debug.internal.ui.DebugUIPlugin.java

License:Open Source License

/**
 * Saves and builds the workspace according to current preference settings and
 * launches the given launch configuration in the specified mode in a background
 * Job with progress reported via the Job. Exceptions are reported in the Progress
 * view.//from www  .  j  ava  2 s.co m
 * 
 * @param configuration the configuration to launch
 * @param mode launch mode
 * @since 3.0
 */
public static void launchInBackground(final ILaunchConfiguration configuration, final String mode) {
    final IJobManager jobManager = Job.getJobManager();
    IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
    boolean wait = (jobManager.find(ResourcesPlugin.FAMILY_AUTO_BUILD).length > 0
            && ResourcesPlugin.getWorkspace().isAutoBuilding())
            || (jobManager.find(ResourcesPlugin.FAMILY_MANUAL_BUILD).length > 0);
    String waitPref = store.getString(IInternalDebugUIConstants.PREF_WAIT_FOR_BUILD);
    if (wait) { // if there are build jobs running, do we wait or not??
        if (waitPref.equals(MessageDialogWithToggle.PROMPT)) {
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(getShell(),
                    DebugUIMessages.DebugUIPlugin_23, DebugUIMessages.DebugUIPlugin_24, null, false, store,
                    IInternalDebugUIConstants.PREF_WAIT_FOR_BUILD); //
            switch (dialog.getReturnCode()) {
            case IDialogConstants.CANCEL_ID:
                return;
            case IDialogConstants.YES_ID:
                wait = true;
                break;
            case IDialogConstants.NO_ID:
                wait = false;
                break;
            }
        } else {
            wait = waitPref.equals(MessageDialogWithToggle.ALWAYS);
        }
    }
    final boolean waitInJob = wait;
    Job job = new Job(
            MessageFormat.format(DebugUIMessages.DebugUIPlugin_25, new Object[] { configuration.getName() })) {
        public IStatus run(final IProgressMonitor monitor) {
            /* Setup progress monitor
             * - Waiting for jobs to finish (2)
             * - Build & launch (98) */
            monitor.beginTask(DebugUIMessages.DebugUITools_3, 100);
            try {
                if (waitInJob) {
                    StringBuffer buffer = new StringBuffer(configuration.getName());
                    buffer.append(DebugUIMessages.DebugUIPlugin_0);
                    ILaunchConfigurationWorkingCopy workingCopy = configuration.copy(buffer.toString());
                    workingCopy.setAttribute(ATTR_LAUNCHING_CONFIG_HANDLE, configuration.getMemento());
                    final ILaunch pendingLaunch = new PendingLaunch(workingCopy, mode, this);
                    DebugPlugin.getDefault().getLaunchManager().addLaunch(pendingLaunch);
                    IJobChangeListener listener = new IJobChangeListener() {
                        public void sleeping(IJobChangeEvent event) {
                        }

                        public void scheduled(IJobChangeEvent event) {
                        }

                        public void running(IJobChangeEvent event) {
                        }

                        public void awake(IJobChangeEvent event) {
                        }

                        public void aboutToRun(IJobChangeEvent event) {
                        }

                        public void done(IJobChangeEvent event) {
                            DebugPlugin dp = DebugPlugin.getDefault();
                            if (dp != null) {
                                dp.getLaunchManager().removeLaunch(pendingLaunch);
                            }
                            removeJobChangeListener(this);
                        }
                    };
                    addJobChangeListener(listener);
                    try {
                        jobManager.join(ResourcesPlugin.FAMILY_MANUAL_BUILD,
                                new SubProgressMonitor(monitor, 1));
                        jobManager.join(ResourcesPlugin.FAMILY_AUTO_BUILD, new SubProgressMonitor(monitor, 1));
                    } catch (InterruptedException e) {
                        /*just continue.*/}
                    DebugPlugin.getDefault().getLaunchManager().removeLaunch(pendingLaunch);
                } else {
                    monitor.worked(2); /* don't wait for jobs to finish */
                }
                if (!monitor.isCanceled()) {
                    buildAndLaunch(configuration, mode, new SubProgressMonitor(monitor, 98));
                }
            } catch (CoreException e) {
                final IStatus status = e.getStatus();
                IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status);
                if (handler == null) {
                    return status;
                }
                final ILaunchGroup group = DebugUITools.getLaunchGroup(configuration, mode);
                if (group == null) {
                    return status;
                }
                Runnable r = new Runnable() {
                    public void run() {
                        DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(),
                                new StructuredSelection(configuration), group.getIdentifier(), status);
                    }
                };
                DebugUIPlugin.getStandardDisplay().asyncExec(r);
            } finally {
                monitor.done();
            }

            return Status.OK_STATUS;
        }
    };

    IWorkbench workbench = DebugUIPlugin.getDefault().getWorkbench();
    IProgressService progressService = workbench.getProgressService();

    job.setPriority(Job.INTERACTIVE);
    job.setProperty(IProgressConstants2.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
    job.setName(
            MessageFormat.format(DebugUIMessages.DebugUIPlugin_25, new Object[] { configuration.getName() }));

    if (wait) {
        progressService.showInDialog(workbench.getActiveWorkbenchWindow().getShell(), job);
    }
    job.schedule();
}

From source file:org.eclipse.debug.internal.ui.launchConfigurations.CompileErrorPromptStatusHandler.java

License:Open Source License

public Object handleStatus(IStatus status, Object source) throws CoreException {
    if (source instanceof ILaunchConfiguration) {
        ILaunchConfiguration config = (ILaunchConfiguration) source;
        if (DebugUITools.isPrivate(config)) {
            return Boolean.TRUE;
        }/* w w  w  .ja va  2  s .  c  o  m*/
    }

    Shell shell = DebugUIPlugin.getShell();
    String title = LaunchConfigurationsMessages.CompileErrorPromptStatusHandler_0;
    String message = LaunchConfigurationsMessages.CompileErrorPromptStatusHandler_1;
    IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();

    String pref = store.getString(IInternalDebugUIConstants.PREF_CONTINUE_WITH_COMPILE_ERROR);
    if (pref != null) {
        if (pref.equals(MessageDialogWithToggle.ALWAYS)) {
            return Boolean.TRUE;
        }
    }
    MessageDialogWithToggle dialog = new MessageDialogWithToggle(shell, title, null, message,
            MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1,
            LaunchConfigurationsMessages.CompileErrorProjectPromptStatusHandler_1, false);
    dialog.setPrefKey(IInternalDebugUIConstants.PREF_CONTINUE_WITH_COMPILE_ERROR);
    dialog.setPrefStore(store);
    dialog.open();

    int returnValue = dialog.getReturnCode();
    if (returnValue == IDialogConstants.YES_ID) {
        return Boolean.TRUE;
    }
    return Boolean.FALSE;
}

From source file:org.eclipse.debug.internal.ui.launchConfigurations.DebugModePromptStatusHandler.java

License:Open Source License

public Object handleStatus(IStatus status, Object source) throws CoreException {
    if (source instanceof ILaunchConfiguration) {
        ILaunchConfiguration config = (ILaunchConfiguration) source;
        if (DebugUITools.isPrivate(config)) {
            return Boolean.FALSE;
        }/* ww  w .j a  va  2 s.  co  m*/
    }

    IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
    ILaunchConfiguration configuration = (ILaunchConfiguration) source;
    String pref = store.getString(IInternalDebugUIConstants.PREF_RELAUNCH_IN_DEBUG_MODE);
    if (pref != null) {
        if (pref.equals(MessageDialogWithToggle.NEVER)) {
            return Boolean.FALSE;
        } else if (pref.equals(MessageDialogWithToggle.ALWAYS)) {
            relaunchInDebugMode(configuration);
            return Boolean.TRUE;
        }
    }

    Shell activeShell = DebugUIPlugin.getShell();
    String title = LaunchConfigurationsMessages.DebugModePromptStatusHandler_0;
    String message = LaunchConfigurationsMessages.DebugModePromptStatusHandler_1;

    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(activeShell, title,
            message, null, false, store, IInternalDebugUIConstants.PREF_RELAUNCH_IN_DEBUG_MODE);
    int buttonId = dialog.getReturnCode();
    if (buttonId == IDialogConstants.YES_ID) {
        relaunchInDebugMode(configuration);
        return Boolean.TRUE; // stops launch
    } else if (buttonId == IDialogConstants.NO_ID) {
        return Boolean.FALSE; // continue launch
    } else { //CANCEL 
        return Boolean.TRUE; // stops the launch
    }
}

From source file:org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationEditDialog.java

License:Open Source License

protected void buttonPressed(int buttonId) {
    switch (buttonId) {
    case ID_LAUNCH_BUTTON: {
        int status = shouldSaveCurrentConfig();
        if (status == IDialogConstants.YES_ID) {
            okPressed();/*www.  j  a  va  2s.  c  o m*/
        }
        setReturnCode(OK);
        if (status != IDialogConstants.CANCEL_ID) {
            close();
        }
        break;
    }
    case ID_CANCEL_BUTTON: {
        cancelPressed();
        break;
    }
    }
}

From source file:org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog.java

License:Open Source License

/**
 * Creates the launch configuration selection area of the dialog.
 * This area displays a tree of launch configurations that the user
 * may select, and allows users to create new configurations, and
 * delete and duplicate existing configurations.
 * /*from   w w  w . j  a  v  a2 s .  c  o m*/
 * @return the composite used for launch configuration selection area
 */
protected Control createLaunchConfigurationSelectionArea(Composite parent) {
    Composite comp = new Composite(parent, SWT.FLAT);
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    comp.setLayout(gridLayout);
    comp.setLayoutData(new GridData(GridData.FILL_BOTH));

    ViewForm viewForm = new ViewForm(comp, SWT.FLAT | SWT.BORDER);
    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolBar = toolBarManager.createControl(viewForm);
    toolBar.setBackground(parent.getBackground());
    viewForm.setTopLeft(toolBar);
    viewForm.setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite viewFormContents = new Composite(viewForm, SWT.FLAT);
    gridLayout = new GridLayout();
    gridLayout.marginHeight = 5;
    gridLayout.marginWidth = 5;
    viewFormContents.setLayout(gridLayout);
    viewFormContents.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    fLaunchConfigurationView = new LaunchConfigurationView(getLaunchGroup(), createViewerFilters());
    fLaunchConfigurationView.createLaunchDialogControl(viewFormContents);
    Text filterText = fLaunchConfigurationView.getFilteringTextControl();
    if (filterText != null) {
        filterText.setFocus();
    }

    //create toolbar actions, we reuse the actions from the view so we wait until after
    //the view is created to add them to the toolbar
    createToolbarActions(toolBarManager);
    fDoubleClickAction = new Action() {
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) fLaunchConfigurationView.getViewer()
                    .getSelection();
            Object target = selection.getFirstElement();
            if (target instanceof ILaunchConfiguration) {
                if (fTabViewer.canLaunch() & fTabViewer.canLaunchWithModes()
                        & !fTabViewer.hasDuplicateDelegates()) {
                    handleLaunchPressed();
                }
            } else {
                getNewAction().run();
            }
        }
    };
    fLaunchConfigurationView.setAction(IDebugView.DOUBLE_CLICK_ACTION, fDoubleClickAction);
    Viewer viewer = fLaunchConfigurationView.getViewer();

    Control control = viewer.getControl();
    GridData gd = new GridData(GridData.FILL_BOTH);
    control.setLayoutData(gd);
    viewForm.setContent(viewFormContents);
    AbstractLaunchConfigurationAction.IConfirmationRequestor requestor = new AbstractLaunchConfigurationAction.IConfirmationRequestor() {
        public boolean getConfirmation() {
            int status = shouldSaveCurrentConfig();
            if (status == IDialogConstants.YES_ID) {
                fTabViewer.handleApplyPressed();
                return true;
            } else if (status == IDialogConstants.NO_ID) {
                fTabViewer.handleRevertPressed();
                return true;
            }
            return false;
        }
    };
    getDuplicateAction().setConfirmationRequestor(requestor);
    getNewAction().setConfirmationRequestor(requestor);
    ((StructuredViewer) viewer).addPostSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            handleLaunchConfigurationSelectionChanged(event);
            getNewAction().setEnabled(getNewAction().isEnabled());
            getDeleteAction().setEnabled(getDeleteAction().isEnabled());
            getDuplicateAction().setEnabled(getDuplicateAction().isEnabled());
        }
    });
    return comp;
}

From source file:org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog.java

License:Open Source License

/**
 * Notification the 'Close' button has been pressed.
 *///  w w  w .  j  a v a2 s.  com
protected void handleClosePressed() {
    if (fTabViewer.canSave()) {
        int status = shouldSaveCurrentConfig();
        if (status != IDialogConstants.CANCEL_ID) {
            if (status != ID_DISCARD_BUTTON) {
                if (status == IDialogConstants.YES_ID) {
                    fTabViewer.handleApplyPressed();
                }
                cancelPressed();
            }
        }
    } else {
        cancelPressed();
    }
}

From source file:org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog.java

License:Open Source License

/**
 * Notification that selection has changed in the launch configuration tree.
 * <p>//from   w  ww.ja  va2 s . c  o  m
 * If the currently displayed configuration is not saved,
 * prompt for saving before moving on to the new selection.
 * </p>
 * 
 * @param event selection changed event
 */
protected void handleLaunchConfigurationSelectionChanged(SelectionChangedEvent event) {
    Object input = fTabViewer.getInput();
    Object newInput = null;
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    if (selection.size() == 1) {
        newInput = selection.getFirstElement();
    }
    if (!isEqual(input, newInput)) {
        ILaunchConfiguration original = fTabViewer.getOriginal();
        if (original != null && newInput == null && getLaunchManager().getMovedTo(original) != null) {
            return;
        }
        boolean deleted = false;
        if (original != null) {
            deleted = !original.exists();
        }
        boolean renamed = false;
        if (newInput instanceof ILaunchConfiguration) {
            renamed = getLaunchManager().getMovedFrom((ILaunchConfiguration) newInput) != null;
        }
        try {
            fSettingInput = true;
            if (fTabViewer.canSave() && fTabViewer.isDirty() && !deleted && !renamed) {
                if (fLaunchConfigurationView != null) {
                    fLaunchConfigurationView.setAutoSelect(false);
                }
                int ret = showUnsavedChangesDialog();
                if (ret == IDialogConstants.YES_ID) {
                    fTabViewer.handleApplyPressed();
                    fTabViewer.setInput(newInput);
                } else if (ret == IDialogConstants.NO_ID) {
                    fTabViewer.handleRevertPressed();
                    fTabViewer.setInput(newInput);
                } else {
                    fLaunchConfigurationView.getViewer().setSelection(new StructuredSelection(input));
                }
                fLaunchConfigurationView.setAutoSelect(true);
            } else {
                fTabViewer.setInput(newInput);
                if (fTabViewer.isDirty()) {
                    fTabViewer.handleApplyPressed();
                }
            }
        } finally {
            fSettingInput = false;
            updateButtons();
            updateMessage();
        }
        if (getShell() != null && getShell().isVisible()) {
            resize();
        }
    }
}