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.jubula.client.ui.utils.OpenViewUtils.java

License:Open Source License

/**
 * /*from  w  w w .j  av a 2  s . c om*/
 * @param preferenceKey
 *            the key for the preference to save the remembered value to
 * @param activeWindow
 *            the active {@link IWorkbenchWindow}
 * @param preferenceStore
 *            the instance of the {@link IPreferenceStore}
 * @param viewName
 *            the name of the view to activate
 * @return the return value of the dialog {@link IDialogConstants#NO_ID},
 *         {@link IDialogConstants#YES_ID} or <code>-1</code> if aborted
 */
private static int createQuestionDialog(final String preferenceKey, IWorkbenchWindow activeWindow,
        final IPreferenceStore preferenceStore, String viewName) {
    MessageDialogWithToggle dialog = new MessageDialogWithToggle(activeWindow.getShell(),
            Messages.UtilsOpenViewTitle, null, NLS.bind(Messages.UtilsViewQuestion, viewName),
            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0,
            Messages.UtilsRemember, false) {
        /**
         * {@inheritDoc}
         */
        protected void buttonPressed(int buttonId) {
            super.buttonPressed(buttonId);
            int val = Constants.UTILS_PROMPT;
            if (getToggleState() && getReturnCode() == IDialogConstants.NO_ID) {
                val = Constants.UTILS_NO;
            } else if (getToggleState() && getReturnCode() == IDialogConstants.YES_ID) {
                val = Constants.UTILS_YES;
            }
            preferenceStore.setValue(preferenceKey, val);
        }
    };
    dialog.create();
    DialogUtils.setWidgetNameForModalDialog(dialog);
    int i = dialog.open();
    return i;
}

From source file:org.eclipse.linuxtools.internal.systemtap.ui.ide.handlers.RunScriptHandler.java

License:Open Source License

private void executeAction(ExecutionEvent event) throws ExecutionException {
    cmdList.clear();/* w w  w.j  a va  2  s .co  m*/
    final boolean local = getRunLocal();
    findTargetEditor(event);
    findFilePath();
    tryEditorSave(event);
    if (!local) {
        prepareNonLocalScript();
    }
    final String[] script = buildStandardScript();
    final String[] envVars = EnvironmentVariablesPreferencePage.getEnvironmentVariables();
    Display.getDefault().asyncExec(() -> {
        String name = getConsoleName();
        if (ScriptConsole.instanceIsRunning(name)) {
            MessageDialog dialog = new MessageDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    Messages.RunScriptHandler_AlreadyRunningDialogTitle, null,
                    MessageFormat.format(Messages.RunScriptHandler_AlreadyRunningDialogMessage, fileName),
                    MessageDialog.QUESTION, new String[] { "Yes", "No" }, 0); //$NON-NLS-1$ //$NON-NLS-2$
            if (dialog.open() != Window.OK) {
                if (launch != null) {
                    launch.forceRemove();
                }
                return;
            }
        }
        final ScriptConsole console = ScriptConsole.getInstance(name);
        if (!local) {
            console.run(script, envVars, remoteOptions, new StapErrorParser());
        } else {
            console.runLocally(script, envVars, new StapErrorParser(), getProject());
        }
        scriptConsoleInitialized(console);
    });
}

From source file:org.eclipse.linuxtools.internal.systemtap.ui.ide.IDESessionSettings.java

License:Open Source License

private static STPEditor askForSTPEditor(IWorkbenchWindow window) {
    final List<STPEditor> allEditors = new LinkedList<>();
    for (IEditorReference editor : window.getActivePage().getEditorReferences()) {
        if (editor.getId().equals(STPEditor.ID)) {
            allEditors.add((STPEditor) editor.getEditor(true));
        }//from   w  ww  .  jav  a  2 s .  co m
    }

    switch (allEditors.size()) {
    // If only one file is found, open it. Give user the option to open another file.
    case 1:
        MessageDialog messageDialog = new MessageDialog(window.getShell(),
                Localization.getString("GetEditorAction.DialogTitle"), null, //$NON-NLS-1$
                MessageFormat.format(Localization.getString("GetEditorAction.AskBeforeOpenMessage"), //$NON-NLS-1$
                        allEditors.get(0).getEditorInput().getName()),
                MessageDialog.QUESTION,
                new String[] { Localization.getString("GetEditorAction.AskBeforeOpenCancel"), //$NON-NLS-1$
                        Localization.getString("GetEditorAction.AskBeforeOpenAnother"), //$NON-NLS-1$
                        Localization.getString("GetEditorAction.AskBeforeOpenYes") }, //$NON-NLS-1$
                2);

        switch (messageDialog.open()) {
        case 2:
            return allEditors.get(0);

        case 1:
            return openNewFile(window);

        default:
            return null;
        }

        // If no files found, prompt user to open a new file
    case 0:
        return openNewFile(window);

    // If multiple files found, prompt user to select one of them
    default:
        return openNewFileFromMultiple(window, allEditors);
    }
}

From source file:org.eclipse.linuxtools.internal.systemtap.ui.ide.launcher.SystemTapScriptGraphOptionsTab.java

License:Open Source License

private void createColumnSelector(Composite parent) {

    GridLayout layout = new GridLayout();
    parent.setLayout(layout);// w w w .j ava2s . c  o  m

    Composite topLayout = new Composite(parent, SWT.NONE);
    topLayout.setLayout(new GridLayout(1, false));
    topLayout.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

    Button generateExpsButton = new Button(topLayout, SWT.PUSH);
    generateExpsButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    generateExpsButton.setText(Messages.SystemTapScriptGraphOptionsTab_generateFromPrintsButton);
    generateExpsButton.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_generateFromPrintsTooltip);
    generateExpsButton.addSelectionListener(regexGenerator);

    Composite regexButtonLayout = new Composite(parent, SWT.NONE);
    regexButtonLayout.setLayout(new GridLayout(3, false));
    regexButtonLayout.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    Label selectedRegexLabel = new Label(regexButtonLayout, SWT.NONE);
    selectedRegexLabel.setText(Messages.SystemTapScriptGraphOptionsTab_regexLabel);
    selectedRegexLabel.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_regexTooltip);
    regularExpressionCombo = new Combo(regexButtonLayout, SWT.DROP_DOWN);
    regularExpressionCombo.setTextLimit(MAX_REGEX_LENGTH);
    regularExpressionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    regularExpressionCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int selected = regularExpressionCombo.getSelectionIndex();
            if (selected == selectedRegex) {
                return;
            }

            // If deselecting an empty regular expression, delete it automatically.
            if (regularExpressionCombo.getItem(selectedRegex).isEmpty()
                    && graphsDataList.get(selectedRegex).size() == 0
                    && outputList.get(selectedRegex).isEmpty()) {

                // If the deselected regex is the last one in the combo, just quit.
                // Otherwise, the deleted blank entry would be replaced by another blank entry.
                if (selected == regularExpressionCombo.getItemCount() - 1) {
                    regularExpressionCombo.select(selectedRegex); // To keep the text blank.
                    return;
                }
                removeRegex(false);
                if (selected > selectedRegex) {
                    selected--;
                }
            }

            // When selecting the "Add New Regex" item in the combo (which is always the last item),
            // update all appropriate values to make room for a new regular expression.
            if (selected == regularExpressionCombo.getItemCount() - 1
                    && getNumberOfRegexs() < MAX_NUMBER_OF_REGEXS) {
                outputList.add(""); //$NON-NLS-1$
                regexErrorMessages.add(null);
                columnNamesList.add(new ArrayList<String>());
                cachedNamesList.add(new Stack<String>());
                graphsDataList.add(new LinkedList<GraphData>());

                // Remove "Add New Regex" from the selected combo item; make it blank.
                regularExpressionCombo.setItem(selected, ""); //$NON-NLS-1$
                regularExpressionCombo.select(selected);
                updateRegexSelection(selected, false);
                updateLaunchConfigurationDialog();

                // Enable the "remove" button if only one item was present before.
                // (Don't do this _every_ time something is added.)
                if (getNumberOfRegexs() == 2) {
                    removeRegexButton.setEnabled(true);
                }
                if (getNumberOfRegexs() < MAX_NUMBER_OF_REGEXS) {
                    regularExpressionCombo.add(Messages.SystemTapScriptGraphOptionsTab_regexAddNew);
                }
            } else {
                updateRegexSelection(selected, false);
            }
        }
    });
    regularExpressionCombo.addModifyListener(regexListener);

    removeRegexButton = new Button(regexButtonLayout, SWT.PUSH);
    removeRegexButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
    removeRegexButton.setText(Messages.SystemTapScriptGraphOptionsTab_regexRemove);
    removeRegexButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IWorkbench workbench = PlatformUI.getWorkbench();
            MessageDialog dialog = new MessageDialog(workbench.getActiveWorkbenchWindow().getShell(),
                    Messages.SystemTapScriptGraphOptionsTab_removeRegexTitle, null,
                    MessageFormat.format(Messages.SystemTapScriptGraphOptionsTab_removeRegexAsk,
                            regularExpressionCombo.getItem(selectedRegex)),
                    MessageDialog.QUESTION, new String[] { "Yes", "No" }, 0); //$NON-NLS-1$ //$NON-NLS-2$
            int result = dialog.open();
            if (result == 0) { //Yes
                removeRegex(true);
            }
        }
    });

    GridLayout twoColumns = new GridLayout(2, false);

    Composite regexSummaryComposite = new Composite(parent, SWT.NONE);
    regexSummaryComposite.setLayout(twoColumns);
    regexSummaryComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Label sampleOutputLabel = new Label(regexSummaryComposite, SWT.NONE);
    sampleOutputLabel.setText(Messages.SystemTapScriptGraphOptionsTab_sampleOutputLabel);
    sampleOutputLabel.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_sampleOutputTooltip);
    this.sampleOutputText = new Text(regexSummaryComposite, SWT.BORDER);
    this.sampleOutputText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    this.sampleOutputText.addModifyListener(sampleOutputListener);
    sampleOutputText.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_sampleOutputTooltip);

    Composite expressionTableLabels = new Composite(parent, SWT.NONE);
    expressionTableLabels.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    expressionTableLabels.setLayout(twoColumns);

    Label label = new Label(expressionTableLabels, SWT.NONE);
    label.setText(Messages.SystemTapScriptGraphOptionsTab_columnTitle);
    label.setAlignment(SWT.LEFT);

    Label label2 = new Label(expressionTableLabels, SWT.NONE);
    label2.setAlignment(SWT.LEFT);
    label2.setText(Messages.SystemTapScriptGraphOptionsTab_extractedValueLabel);

    ScrolledComposite regexTextScrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.BORDER);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.heightHint = 200;
    regexTextScrolledComposite.setLayoutData(data);

    textFieldsComposite = new Composite(regexTextScrolledComposite, SWT.NONE);
    textFieldsComposite.setLayout(new GridLayout(4, false));
    regexTextScrolledComposite.setContent(textFieldsComposite);
    regexTextScrolledComposite.setExpandHorizontal(true);

    // To position the column labels properly, add a dummy column and use its children's sizes for reference.
    // This is necessary since expressionTableLabels can't share a layout with textFieldsComposite.
    textListenersEnabled = false;
    addColumn(null);
    data = new GridData(SWT.FILL, SWT.FILL, false, false);
    data.horizontalIndent = textFieldsComposite.getChildren()[2].getLocation().x;
    data.widthHint = textFieldsComposite.getChildren()[2].getSize().x;
    label.setLayoutData(data);
    label2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    removeColumn(false);
    textListenersEnabled = true;
}

From source file:org.eclipse.linuxtools.internal.tmf.ui.dialogs.ManageCustomParsersDialog.java

License:Open Source License

private boolean checkNameConflict(CustomTraceDefinition def) {
    for (TraceTypeHelper helper : TmfTraceType.getTraceTypeHelpers()) {
        if (def.categoryName.equals(helper.getCategoryName()) && def.definitionName.equals(helper.getName())) {
            String newName = findAvailableName(def);
            MessageDialog dialog = new MessageDialog(getShell(), null, null,
                    NLS.bind(Messages.ManageCustomParsersDialog_ConflictMessage,
                            new Object[] { def.categoryName, def.definitionName, newName }),
                    MessageDialog.QUESTION,
                    new String[] { Messages.ManageCustomParsersDialog_ConflictRenameButtonLabel,
                            Messages.ManageCustomParsersDialog_ConflictSkipButtonLabel },
                    0);/* w  w w  .j  a  va2s. c  o m*/
            int result = dialog.open();
            if (result == 0) {
                def.definitionName = newName;
                return true;
            }
            return false;
        }
    }
    return true;
}

From source file:org.eclipse.ltk.internal.ui.refactoring.scripting.CreateRefactoringScriptWizard.java

License:Open Source License

/**
 * Performs the actual refactoring script export.
 *
 * @return <code>true</code> if the wizard can be finished,
 *         <code>false</code> otherwise
 *//* w  w  w . j ava2  s . c  o m*/
private boolean performExport() {
    RefactoringDescriptorProxy[] writable = fRefactoringDescriptors;
    if (fScriptLocation != null) {
        final File file = new File(fScriptLocation);
        if (file.exists()) {
            final MessageDialog message = new MessageDialog(getShell(), getShell().getText(), null,
                    Messages.format(ScriptingMessages.CreateRefactoringScriptWizard_overwrite_query,
                            new String[] { ScriptingMessages.CreateRefactoringScriptWizard_merge_button,
                                    ScriptingMessages.CreateRefactoringScriptWizard_overwrite_button }),
                    MessageDialog.QUESTION,
                    new String[] { ScriptingMessages.CreateRefactoringScriptWizard_merge_button,
                            ScriptingMessages.CreateRefactoringScriptWizard_overwrite_button,
                            IDialogConstants.CANCEL_LABEL },
                    0);
            final int result = message.open();
            if (result == 0) {
                InputStream stream = null;
                try {
                    stream = new BufferedInputStream(new FileInputStream(file));
                    final RefactoringDescriptorProxy[] existing = RefactoringCore.getHistoryService()
                            .readRefactoringHistory(stream, RefactoringDescriptor.NONE).getDescriptors();
                    final Set set = new HashSet();
                    for (int index = 0; index < existing.length; index++)
                        set.add(existing[index]);
                    for (int index = 0; index < fRefactoringDescriptors.length; index++)
                        set.add(fRefactoringDescriptors[index]);
                    writable = new RefactoringDescriptorProxy[set.size()];
                    set.toArray(writable);
                } catch (FileNotFoundException exception) {
                    MessageDialog.openError(getShell(),
                            RefactoringUIMessages.ChangeExceptionHandler_refactoring,
                            exception.getLocalizedMessage());
                    return false;
                } catch (CoreException exception) {
                    handleCoreException(exception);
                    return false;
                } finally {
                    if (stream != null) {
                        try {
                            stream.close();
                        } catch (IOException exception) {
                            // Do nothing
                        }
                    }
                }
            } else if (result == 2)
                return false;
        }
        OutputStream stream = null;
        try {
            File parentFile = file.getParentFile();
            if (parentFile != null)
                parentFile.mkdirs();
            stream = new BufferedOutputStream(new FileOutputStream(file));
            writeRefactoringDescriptorProxies(writable, stream);
            return true;
        } catch (CoreException exception) {
            handleCoreException(exception);
            return false;
        } catch (FileNotFoundException exception) {
            MessageDialog.openError(getShell(), RefactoringUIMessages.ChangeExceptionHandler_refactoring,
                    exception.getLocalizedMessage());
            return false;
        } finally {
            if (stream != null) {
                try {
                    stream.close();
                } catch (IOException exception) {
                    // Do nothing
                }
            }
        }
    } else if (fUseClipboard) {
        try {
            final ByteArrayOutputStream stream = new ByteArrayOutputStream(2048);
            writeRefactoringDescriptorProxies(writable, stream);
            try {
                final String string = stream.toString(IRefactoringSerializationConstants.OUTPUT_ENCODING);
                Clipboard clipboard = null;
                try {
                    clipboard = new Clipboard(getShell().getDisplay());
                    try {
                        clipboard.setContents(new Object[] { string },
                                new Transfer[] { TextTransfer.getInstance() });
                        return true;
                    } catch (SWTError error) {
                        MessageDialog.openError(getShell(),
                                RefactoringUIMessages.ChangeExceptionHandler_refactoring,
                                error.getLocalizedMessage());
                        return false;
                    }
                } finally {
                    if (clipboard != null)
                        clipboard.dispose();
                }
            } catch (UnsupportedEncodingException exception) {
                // Does not happen
                return false;
            }
        } catch (CoreException exception) {
            handleCoreException(exception);
            return false;
        }
    }
    return false;
}

From source file:org.eclipse.m2m.atl.core.ui.launch.AtlLaunchConfigurationDelegate.java

License:Open Source License

/**
 * Shows the profiler views for a profiler VM.
 * /*from   w  w w.j a v a2 s  .c  o m*/
 * @param launcherName
 *            the launcher name (the VM id)
 */
private void showViewsForProfiler(String launcherName) {
    boolean isProfilerVm = false;
    // The launcher name tells us if this is a profiler VM
    for (String profilerVMId : PROFILER_VM_IDS) {
        if (launcherName.equals(profilerVMId))
            isProfilerVm = true;
    }
    if (!isProfilerVm)
        return;
    // We show the profiler views
    PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
        public void run() {
            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            String rulesViewId = "org.eclipse.m2m.atl.profiler.ui.profilingdatatable.ProfilingDataTableView"; //$NON-NLS-1$
            String executionViewId = "org.eclipse.m2m.atl.profiler.ui.executionviewer.view.ExecutionView"; //$NON-NLS-1$
            if (window != null) {
                if (window.getActivePage().findView(rulesViewId) == null
                        || window.getActivePage().findView(executionViewId) == null) {
                    MessageDialog dialog = new MessageDialog(null,
                            Messages.getString("AtlLaunchConfigurationDelegate.PROFILER_WINDOW_TITLE"), null, //$NON-NLS-1$
                            Messages.getString("AtlLaunchConfigurationDelegate.PROFILER_WINDOW_MSG"), //$NON-NLS-1$
                            MessageDialog.QUESTION,
                            new String[] {
                                    Messages.getString("AtlLaunchConfigurationDelegate.PROFILER_WINDOW_YES"), //$NON-NLS-1$
                                    Messages.getString("AtlLaunchConfigurationDelegate.PROFILER_WINDOW_NO"), }, //$NON-NLS-1$
                            0);
                    // TODO keep user's answer in preferences (add "Always" and "Never" buttons)
                    int result = dialog.open();
                    if (result == 1)
                        return;
                }
                try {
                    if (window.getActivePage().findView(rulesViewId) == null)
                        window.getActivePage().showView(rulesViewId);
                } catch (PartInitException e1) {
                    // The view is not found
                }
                try {
                    if (window.getActivePage().findView(executionViewId) == null)
                        window.getActivePage().showView(executionViewId);
                } catch (PartInitException e1) {
                    // The view is not found
                }
            }
        }
    });
    return;
}

From source file:org.eclipse.mdht.uml.ui.navigator.internal.actions.CloseModelAction.java

License:Open Source License

protected static void closeModel(Resource resource) {
    try {/*ww  w .j a  v  a2 s.co m*/
        ModelDocument saveable = ModelManager.getManager().getModelDocument(resource);
        if (saveable != null) {
            if (saveable.isDirty()) {
                String fileName = resource.getURI().lastSegment();
                String message = NLS.bind(Messages.CloseModelAction_dialogMessage, fileName);
                // Yes, No, Cancel
                MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(),
                        Messages.CloseModelAction_dialogTitle, null, // accept
                        message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                                IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                        0); // yes is the default

                int result = dialog.open();
                if (2 == result) {
                    // Cancel
                    return;
                }
                if (0 == result) {
                    // Yes
                    saveable.doSave(new NullProgressMonitor());
                }
            }

            // if not canceled, the resource is closed
            saveable.doClose(new NullProgressMonitor());

            return;
        }

        // if saveable not found, the resource is unloaded
        resource.unload();

    } catch (Exception e) {
        String message = NLS.bind(Messages.CloseModelAction_errorMessage,
                new String[] { e.getLocalizedMessage() });
        Logger.logException(message, e);
        MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.CloseModelAction_errorTitle,
                message);
    }
}

From source file:org.eclipse.mylyn.internal.context.ui.commands.CopyContextHandler.java

License:Open Source License

public static void run(ITask sourceTask) {
    if (sourceTask == null) {
        MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                TITLE_DIALOG, Messages.CopyContextHandler_No_source_task_selected);
        return;/*from ww  w.  java2s.  com*/
    }

    TaskSelectionDialog dialog = new TaskSelectionDialog(WorkbenchUtil.getShell());
    dialog.setNeedsCreateTask(false);
    dialog.setTitle(Messages.CopyContextHandler_Select_Target_Task);
    dialog.setMessage(Messages.CopyContextHandler_Select_the_target_task__);

    if (dialog.open() != Window.OK) {
        return;
    }

    Object result = dialog.getFirstResult();

    if (result instanceof ITask) {
        ITask targetTask = (ITask) result;
        TasksUi.getTaskActivityManager().deactivateActiveTask();
        if (targetTask.equals(sourceTask)) {
            MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    TITLE_DIALOG, Messages.CopyContextHandler_TARGET_TASK_CON_NOT_BE_THE_SAME_AS_SOURCE_TASK);
        } else {
            final int REPLACE = 0;
            final int MERGE = 1;
            final int CANCEL = 2;
            int action = REPLACE;
            if (ContextCorePlugin.getContextStore().hasContext(targetTask.getHandleIdentifier())) {
                MessageDialog dialog2 = new MessageDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), TITLE_DIALOG, null,
                        Messages.CopyContextHandler_SELECTED_TASK_ALREADY_HAS_CONTEXT, MessageDialog.QUESTION,
                        new String[] { Messages.CopyContextHandler_Replace, Messages.CopyContextHandler_Merge,
                                IDialogConstants.CANCEL_LABEL },
                        1);
                action = dialog2.open();
            }

            boolean shouldCopyEditorMemento = true;
            switch (action) {
            case REPLACE:
                IInteractionContext context = ContextCore.getContextStore()
                        .cloneContext(sourceTask.getHandleIdentifier(), targetTask.getHandleIdentifier());
                if (context == null) {
                    MessageDialog.openInformation(
                            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), TITLE_DIALOG,
                            Messages.CopyContextHandler_SOURCE_TASK_DOES_HAVE_A_CONTEXT);
                    return;
                }
                break;
            case MERGE:
                ContextCorePlugin.getContextStore().merge(sourceTask.getHandleIdentifier(),
                        targetTask.getHandleIdentifier());
                shouldCopyEditorMemento = !ContextUiPlugin.getEditorManager()
                        .hasEditorMemento(targetTask.getHandleIdentifier());
                break;
            case CANCEL:
                return;
            }

            if (shouldCopyEditorMemento) {
                ContextUiPlugin.getEditorManager().copyEditorMemento(sourceTask.getHandleIdentifier(),
                        targetTask.getHandleIdentifier());
            }
            TasksUiInternal.activateTaskThroughCommand(targetTask);
        }
    } else {
        MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                TITLE_DIALOG, Messages.CopyContextHandler_No_target_task_selected);
    }
}

From source file:org.eclipse.mylyn.internal.monitor.usage.CheckForUploadJob.java

License:Open Source License

synchronized void checkForStatisticsUpload() {

    Date currentTime = new Date();
    if (shouldAskForUpload(currentTime)) {

        String ending = getUserPromptDelay() == 1 ? "" : "s"; //$NON-NLS-1$//$NON-NLS-2$
        MessageDialog message = new MessageDialog(Display.getDefault().getActiveShell(),
                Messages.UiUsageMonitorPlugin_Send_Usage_Feedback, null,
                Messages.UiUsageMonitorPlugin_Help_Improve_Eclipse_And_Mylyn, MessageDialog.QUESTION,
                new String[] { Messages.UiUsageMonitorPlugin_Submit_Feedback, NLS
                        .bind(Messages.UiUsageMonitorPlugin_Remind_Me_In_X_Days, getUserPromptDelay(), ending),
                        Messages.UiUsageMonitorPlugin_Dont_Ask_Again, },
                0);/*from www.ja va 2  s .  co  m*/
        int result = message.open();
        if (result == 0) {
            // time must be stored right away into preferences, to prevent
            // other threads
            UiUsageMonitorPlugin.getDefault().getPreferenceStore()
                    .setValue(MonitorPreferenceConstants.PREF_PREVIOUS_TRANSMIT_DATE, currentTime.getTime());

            if (!UiUsageMonitorPlugin.getDefault().getPreferenceStore()
                    .contains(MonitorPreferenceConstants.PREF_MONITORING_MYLYN_ECLIPSE_ORG_CONSENT_VIEWED)
                    || !UiUsageMonitorPlugin.getDefault().getPreferenceStore().getBoolean(
                            MonitorPreferenceConstants.PREF_MONITORING_MYLYN_ECLIPSE_ORG_CONSENT_VIEWED)) {
                MessageDialog consentMessage = new MessageDialog(Display.getDefault().getActiveShell(),
                        Messages.UiUsageMonitorPlugin_Consent, null,
                        Messages.UiUsageMonitorPlugin_All_Data_Public, MessageDialog.INFORMATION,
                        new String[] { IDialogConstants.OK_LABEL }, 0);
                consentMessage.open();
                UiUsageMonitorPlugin.getDefault().getPreferenceStore().setValue(
                        MonitorPreferenceConstants.PREF_MONITORING_MYLYN_ECLIPSE_ORG_CONSENT_VIEWED, true);
            }

            UsageSubmissionWizard wizard = new UsageSubmissionWizard();
            wizard.init(PlatformUI.getWorkbench(), null);
            // Instantiates the wizard container with the wizard and
            // opens it
            WizardDialog dialog = new UsageSubmissionWizardDialog(Display.getDefault().getActiveShell(),
                    wizard);
            dialog.create();
            dialog.open();

            /*
             * the UI usage report is loaded asynchronously so there's no
             * synchronous way to know if it failed if (wizard.failed()) {
             * lastTransmit.setTime(currentTime.getTime() + DELAY_ON_FAILURE -
             * studyParameters.getTransmitPromptPeriod());
             * plugin.getPreferenceStore().setValue(MylynMonitorPreferenceConstants.PREF_PREVIOUS_TRANSMIT_DATE,
             * currentTime.getTime()); }
             */

        } else {
            if (result == 1) {
                UiUsageMonitorPlugin.getDefault().userCancelSubmitFeedback(currentTime, true);
            } else {
                UiUsageMonitorPlugin.getDefault().getPreferenceStore()
                        .setValue(MonitorPreferenceConstants.PREF_MONITORING_ENABLE_SUBMISSION, false);
            }
        }
        message.close();
    }
}