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:es.cv.gvcase.mdt.common.part.MOSKittMultiPageEditor.java

License:Open Source License

/**
 * {@link ISaveablePart2} implementation. <br>
 * Will ask nested editors that implement ISaveablePart2 to perform their
 * prompt./*from  ww w. j  a v a 2s  . c  o  m*/
 * 
 */
public int promptToSaveOnClose() {
    // clear the previous map
    mapEditorIndex2SaveOnClose.clear();
    int saveOption = ISaveablePart2.DEFAULT;
    boolean saveNeeded = false;
    ISaveablePart saveablePart1 = null;
    ISaveablePart2 saveablePart2 = null;
    String partsNamesToSave = ""; //$NON-NLS-1$
    for (int i = 0; i < getPageCount(); i++) {
        IEditorPart editor = getEditor(i);
        if (editor == null) {
            continue;
        }
        saveablePart1 = (ISaveablePart) Platform.getAdapterManager().getAdapter(editor, ISaveablePart.class);
        saveablePart2 = (ISaveablePart2) Platform.getAdapterManager().getAdapter(editor, ISaveablePart2.class);
        if (saveablePart2 != null) {
            saveOption = saveablePart2.promptToSaveOnClose();
        } else if (saveablePart1 != null) {
            saveOption = saveablePart1.isSaveOnCloseNeeded() ? ISaveablePart2.YES : ISaveablePart2.NO;
        } else {
            saveOption = ISaveablePart2.DEFAULT;
        }
        mapEditorIndex2SaveOnClose.put(i, saveOption);
        if (saveOption == ISaveablePart2.YES) {
            saveNeeded = true;
            partsNamesToSave += ((partsNamesToSave.length() == 0 ? "" //$NON-NLS-1$
                    : ", ") + getPageText(i)); //$NON-NLS-1$
        }
    }

    if (saveNeeded) {
        String message = Messages.MOSKittMultiPageEditor_15;
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };
        MessageDialog dialog = new MessageDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                Messages.MOSKittMultiPageEditor_16, null, message, MessageDialog.QUESTION, buttons, 0) {
            protected int getShellStyle() {
                return SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL | getDefaultOrientation();
            }
        };
        int choice = ISaveablePart2.NO;
        choice = dialog.open();
        // map value of choice back to ISaveablePart2 values
        switch (choice) {
        case 0: // Yes
            choice = ISaveablePart2.YES;
            break;
        case 1: // No
            choice = ISaveablePart2.NO;
            break;
        case 2: // Cancel
            choice = ISaveablePart2.CANCEL;
            break;
        default: // ??
            choice = ISaveablePart2.DEFAULT;
            break;
        }
        return choice;
    } else {
        return ISaveablePart2.NO;
    }
}

From source file:eu.geclipse.ui.internal.actions.DeleteGridElementAction.java

License:Open Source License

private ConfirmChoice confirmDeleteJobs(final List<IGridJob> selectedJobs) {
    ConfirmChoice choice = ConfirmChoice.cancel;
    String question = null, warning = null;

    if (selectedJobs.size() == 1) {
        IGridJob job = selectedJobs.iterator().next();
        question = String.format(Messages.getString("DeleteGridElementAction.confirmationOne"), //$NON-NLS-1$
                job.getJobName());//from w w w  .  j av  a  2 s .co m
        if (job.getJobStatus().canChange()) {
            warning = String.format(Messages.getString("DeleteGridElementAction.warningOne"), job.getJobName()); //$NON-NLS-1$
        }
    } else {
        question = String.format(Messages.getString("DeleteGridElementAction.confirmationMany"), //$NON-NLS-1$
                Integer.valueOf(selectedJobs.size()));

        for (IGridJob job : selectedJobs) {
            if (job.getJobStatus().canChange()) {
                warning = Messages.getString("DeleteGridElementAction.warningMany"); //$NON-NLS-1$
                break;
            }
        }
    }

    String msg = question;

    if (warning != null) {
        msg += "\n\n" + warning; //$NON-NLS-1$
    }

    ConfirmDeleteJobsDialog dialog = new ConfirmDeleteJobsDialog(msg,
            warning == null ? MessageDialog.QUESTION : MessageDialog.WARNING);

    if (dialog.open() == 0) {
        if (dialog.isDeleteFromGrid()) {
            choice = ConfirmChoice.deleteFromGrid;
        } else {
            choice = ConfirmChoice.deleteOnlyFromWorkspace;
        }
    }

    return choice;
}

From source file:eu.geclipse.ui.internal.transfer.GridElementTransferOperation.java

License:Open Source License

private void askOverwrite(final TransferParams data, final IFileInfo targetInfo) {

    class Runner implements Runnable {
        int exitCode;
        private final Display display;

        Runner(final Display display) {
            this.display = display;
        }//ww w.  j  a  v  a2 s .c om

        public void run() {
            Shell shell = null;
            String[] labels = { Messages.getString("GridElementTransferOperation.buttonYes"), //$NON-NLS-1$
                    Messages.getString("GridElementTransferOperation.buttonYesAll"), //$NON-NLS-1$
                    Messages.getString("GridElementTransferOperation.buttonNo"), //$NON-NLS-1$
                    Messages.getString("GridElementTransferOperation.buttonNoAll"), //$NON-NLS-1$
                    Messages.getString("GridElementTransferOperation.buttonCancel") }; //$NON-NLS-1$

            if (this.display != null) {
                shell = this.display.getActiveShell();
            }

            String message = String.format(Messages.getString("GridElementTransferOperation.overwriteMsg"), //$NON-NLS-1$
                    data.targetFile.getName(), formatURI(data.targetFile.toURI()),
                    formatDate(targetInfo.getLastModified()), formatURI(data.sourceFile.toURI()), "" //$NON-NLS-1$
            );

            MessageDialog dialog = new MessageDialog(shell,
                    Messages.getString("GridElementTransferOperation.overwriteTitle"), //$NON-NLS-1$
                    null, message, MessageDialog.QUESTION, labels, 0);
            this.exitCode = dialog.open();
        }
    }

    Display display = PlatformUI.getWorkbench().getDisplay();
    Runner runner = new Runner(display);
    display.syncExec(runner);

    switch (runner.exitCode) {
    case 0:
        deleteTarget(data);
        break;

    case 1:
        this.overwriteMode = OverwriteMode.OVERWRITE_ALL;
        deleteTarget(data);
        break;

    case 2:
        ignoreTransfer(data);
        break;

    case 3:
        this.overwriteMode = OverwriteMode.IGNORE_ALL;
        ignoreTransfer(data);
        break;

    case 4:
        data.status = Status.CANCEL_STATUS;
        data.monitor.setCanceled(true);
        break;
    }
}

From source file:eu.geclipse.workflow.ui.edit.policies.WorkflowJobDragDropEditPolicy.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  ww  w .java 2s  .com*/
public Command getDropObjectsCommand(DropObjectsRequest dropRequest) {
    List objects = dropRequest.getObjects();
    CompoundCommand cmd = new CompoundCommand();
    JSDLJobDescription jsdl = null;

    for (Object o : objects) {

        if (o instanceof JSDLJobDescription) {
            jsdl = (JSDLJobDescription) o;
            this.selectedElement = (WorkflowJobEditPart) getHost();
            IWorkflowJob selectedJob = (IWorkflowJob) this.selectedElement.resolveSemanticElement();

            CopyJobDescToWorkflowCommand copyCmd = new CopyJobDescToWorkflowCommand(
                    this.selectedElement.resolveSemanticElement(), jsdl);
            UpdateJobPortsCommand updatePortsCmd = new UpdateJobPortsCommand(this.selectedElement, jsdl);

            if (!(selectedJob.getName() == null && selectedJob.getJobDescription() == null)) {
                MessageDialog confirmDialog = new MessageDialog(null,
                        Messages.getString("WorkflowJobDragDropEditPolicy_confirmationTitle"), //$NON-NLS-1$
                        null, Messages.getString("WorkflowJobDragDropEditPolicy_userPrompt"), //$NON-NLS-1$
                        true ? MessageDialog.QUESTION : MessageDialog.WARNING,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
                int result = confirmDialog.open();
                if (result == 0) {
                    cmd.add(new ICommandProxy(copyCmd));
                    cmd.add(new ICommandProxy(updatePortsCmd));
                }
            } else {
                cmd.add(new ICommandProxy(copyCmd));
                cmd.add(new ICommandProxy(updatePortsCmd));
            }
        }

        return cmd;
    }
    return super.getDropObjectsCommand(dropRequest);
}

From source file:eu.geclipse.workflow.ui.internal.actions.GetJobDescriptionFromFileAction.java

License:Open Source License

/**
 * Fires up a GridFileDialog and fetches the contents of a user-chosen JSDL
 * file./*from w w  w.ja  v  a  2s. c o  m*/
 */
public void run(final IAction action) {
    FileDialog dialog = new FileDialog(this.myShell, SWT.OPEN);
    String[] exts = { "*.jsdl" }; //$NON-NLS-1$
    dialog.setFilterExtensions(exts);
    // this bit find the root directory of the workflow
    TransactionalEditingDomain domain = this.mySelectedElement.getEditingDomain();
    ResourceSet resourceSet = domain.getResourceSet();
    Resource res = resourceSet.getResources().get(0);
    URI wfRootUri = res.getURI();
    String wfRootPath = wfRootUri.path();
    this.dirs = wfRootPath.split("/"); //$NON-NLS-1$
    String projectName = this.dirs[2];
    this.wfRootFileStore = GridModel.getRoot().getFileStore().getChild(projectName);
    dialog.setFilterPath(this.wfRootFileStore.toString());
    if (dialog.open() != null) {
        String result = dialog.getFileName();
        if ((result != null) && (result.length() > 0)) {
            String filePath = dialog.getFilterPath() + "/" + result; //$NON-NLS-1$
            // filePath = filePath.replace(' ', '+');
            java.net.URI filePathUri = null;
            filePathUri = URIUtil.toURI(filePath);
            IFile jsdlFile = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(filePathUri)[0];
            IWorkflowJob selectedJob = (IWorkflowJob) this.mySelectedElement.resolveSemanticElement();
            if (!(selectedJob.getName() == null && selectedJob.getJobDescription() == null)) {
                MessageDialog confirmDialog = new MessageDialog(null,
                        Messages.getString("WorkflowJobDragDropEditPolicy_confirmationTitle"), //$NON-NLS-1$
                        null, Messages.getString("WorkflowJobDragDropEditPolicy_userPrompt"), //$NON-NLS-1$
                        true ? MessageDialog.QUESTION : MessageDialog.WARNING,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
                int confirmResult = confirmDialog.open();
                if (confirmResult == 0) {
                    JSDLJobDescription jsdl = new JSDLJobDescription(jsdlFile);
                    AbstractTransactionalCommand copyCommand = new CopyJobDescToWorkflowCommand(
                            this.mySelectedElement.resolveSemanticElement(), jsdl);
                    AbstractTransactionalCommand updatePortsCommand = new UpdateJobPortsCommand(
                            GetJobDescriptionFromFileAction.this.mySelectedElement, jsdl);
                    try {
                        OperationHistoryFactory.getOperationHistory().execute(copyCommand,
                                new NullProgressMonitor(), null);
                        OperationHistoryFactory.getOperationHistory().execute(updatePortsCommand,
                                new NullProgressMonitor(), null);
                    } catch (ExecutionException eE) {
                        eE.printStackTrace();
                    }
                }
            }
        }
    }
}

From source file:eu.numberfour.n4js.ui.dialog.ModuleSpecifierSelectionDialog.java

License:Open Source License

/**
 * Processes the initial string selection.
 *
 * For existing resources it just sets the initial selection to the specified file system resource.
 *
 * In the case that the initial module specifier points to a non-existing location, a dialog is displayed which
 * allows the user to automatically create not yet existing folders.
 *
 * @param initialModuleSpecifier/* w ww. ja  v  a 2  s  . c o  m*/
 *            The module specifier
 * @return A {@link IWorkbenchAdapter} adaptable object or null on failure
 */
private Object processInitialSelection(String initialModuleSpecifier) {

    IPath sourceFolderPath = sourceFolder.getFullPath();
    IPath initialModulePath = new Path(initialModuleSpecifier);

    // Use the root element source folder for an empty initial selection
    if (initialModuleSpecifier.isEmpty()) {
        return this.sourceFolder;
    }

    // Use the root element source folder for invalid module specifiers
    if (!WorkspaceWizardValidatorUtils.isValidFolderPath(initialModulePath)) {
        return this.sourceFolder;
    }

    // The project relative path of a module specifier
    IPath fullPath = sourceFolderPath.append(new Path(initialModuleSpecifier));

    // If the module specifier refers to an existing n4js resource
    if (!fullPath.hasTrailingSeparator()) {
        IFile n4jsModuleFile = workspaceRoot
                .getFile(fullPath.addFileExtension(N4JSGlobals.N4JS_FILE_EXTENSION));
        IFile n4jsdModuleFile = workspaceRoot
                .getFile(fullPath.addFileExtension(N4JSGlobals.N4JSD_FILE_EXTENSION));

        // Just use it as initial selection
        if (n4jsModuleFile.exists()) {
            return n4jsModuleFile;
        }
        if (n4jsdModuleFile.exists()) {
            return n4jsdModuleFile;
        }

    }

    //// Otherwise use the existing part of the path as initial selection:

    // If the module specifier specifies the module name, extract it and remove its segment.
    if (isModuleFileSpecifier(initialModulePath)) {
        initialModuleName = initialModulePath.lastSegment();
        initialModulePath = initialModulePath.removeLastSegments(1);
    }

    IResource selection = this.sourceFolder;

    // Accumulate path segments to search for the longest existing path
    IPath accumulatedPath = sourceFolderPath;

    // Collect the paths of all non-existing segments
    // These are relative to the last existing segment of the path
    List<IPath> nonExistingSegmentPaths = new ArrayList<>();

    for (Iterator<String> segmentIterator = Arrays.asList(initialModulePath.segments())
            .iterator(); segmentIterator.hasNext(); /**/) {

        accumulatedPath = accumulatedPath.append(segmentIterator.next());

        // Results in null if non-existing
        IResource nextSegmentResource = workspaceRoot.findMember(accumulatedPath);

        // If the current segment is an existing file and not the last specifier segment
        // show a file overlap error message
        if (null != nextSegmentResource && !(nextSegmentResource instanceof IContainer)
                && segmentIterator.hasNext()) {

            MessageDialog.open(MessageDialog.ERROR, getShell(), SPECIFIER_OVERLAPS_WITH_FILE_TITLE, String
                    .format(SPECIFIER_OVERLAPS_WITH_FILE_MESSAGE, initialModuleSpecifier, accumulatedPath),
                    SWT.NONE);

            return selection;
        }

        // If the segment exist go ahead with the next one
        if (null != nextSegmentResource && nextSegmentResource.exists()) {
            selection = nextSegmentResource;
        } else { // If not add it to the list of non existing segments.
            nonExistingSegmentPaths.add(accumulatedPath.makeRelativeTo(selection.getFullPath()));
        }
    }

    // If any non-existing folders need to be created
    if (nonExistingSegmentPaths.size() > 0) {
        // Ask the user if he wants to create the missing folders
        boolean create = MessageDialog.open(MessageDialog.QUESTION, getShell(),
                NON_EXISTING_MODULE_LOCATION_TITLE, NON_EXISTING_MODULE_LOCATION_MESSAGE, SWT.NONE);

        // Create the missing folders
        if (create) {
            ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(getShell());
            progressMonitorDialog.open();
            IProgressMonitor progressMonitor = progressMonitorDialog.getProgressMonitor();

            IPath deepestPath = nonExistingSegmentPaths.get(nonExistingSegmentPaths.size() - 1);
            selection = createFolderPath(deepestPath, (IContainer) selection, progressMonitor);

            progressMonitor.done();
            progressMonitorDialog.close();
        }

    }
    return selection;
}

From source file:eu.numberfour.n4js.ui.export.AbstractExportToSingleFileWizardPage.java

License:Open Source License

/**
 * The default implementation of this <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 *
 * @param pathString//w  w  w. j a v  a 2s . c  o  m
 *            the path of the archive
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, <code>"ALL"</code>, or
 *         <code>"CANCEL"</code>
 */
@Override
public String queryOverwrite(String pathString) {

    IPath path = Path.fromOSString(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
    } else {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
                path.lastSegment(), path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question,
            null, messageString, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        @Override
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:eu.numberfour.n4js.ui.preferences.N4JSBuilderPreferencePage.java

License:Open Source License

/**
 * This method has been copied and adapted from org.eclipse.xtext.ui.preferences.OptionsConfigurationBlock.
 *//*from   ww  w .  j ava  2 s .co  m*/
@Override
protected boolean processChanges(IWorkbenchPreferenceContainer container) {
    boolean needsBuild = !getPreferenceChanges().isEmpty() | projectSpecificChanged;
    boolean doBuild = false;
    if (needsBuild) {
        int count = getRebuildCount();
        if (count > rebuildCount) {
            needsBuild = false;
            rebuildCount = count;
        }
    }
    if (needsBuild) {
        String[] strings = getFullBuildDialogStrings(project == null);
        if (strings != null) {
            MessageDialog dialog = new MessageDialog(this.getShell(), strings[0], null, strings[1],
                    MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                            IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                    2);
            int res = dialog.open();
            if (res == 0) {
                doBuild = true;
            } else if (res != 1) {
                return false;
            }
        }
    }
    if (container != null) {
        if (doBuild) {
            incrementRebuildCount();
            container.registerUpdateJob(getBuildJob(getProject()));
        }
    } else {
        if (doBuild) {
            getBuildJob(getProject()).schedule();
        }
    }
    return true;
}

From source file:ext.org.eclipse.jdt.internal.ui.javadocexport.JavadocWizard.java

License:Open Source License

private void setAllJavadocLocations(IJavaProject[] projects, URL newURL) {
    Shell shell = getShell();/*from  www  . j  ava  2  s .  co  m*/
    String[] buttonlabels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
            IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL };

    for (int j = 0; j < projects.length; j++) {
        IJavaProject iJavaProject = projects[j];
        String message = Messages.format(JavadocExportMessages.JavadocWizard_updatejavadoclocation_message,
                new String[] { BasicElementLabels.getJavaElementName(iJavaProject.getElementName()),
                        BasicElementLabels.getPathLabel(fDestination, true) });
        MessageDialog dialog = new MessageDialog(shell,
                JavadocExportMessages.JavadocWizard_updatejavadocdialog_label, null, message,
                MessageDialog.QUESTION, buttonlabels, 1);

        switch (dialog.open()) {
        case YES:
            JavaUI.setProjectJavadocLocation(iJavaProject, newURL);
            break;
        case YES_TO_ALL:
            for (int i = j; i < projects.length; i++) {
                iJavaProject = projects[i];
                JavaUI.setProjectJavadocLocation(iJavaProject, newURL);
                j++;
            }
            break;
        case NO_TO_ALL:
            j = projects.length;
            break;
        case NO:
        default:
            break;
        }
    }
}

From source file:ext.org.eclipse.jdt.internal.ui.preferences.BuildPathsPropertyPage.java

License:Open Source License

@Override
public boolean okToLeave() {
    if (fBuildPathsBlock != null && fBuildPathsBlock.hasChangesInDialog()) {
        String title = PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_title;
        String message = PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_message;
        String[] buttonLabels = new String[] {
                PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_button_save,
                PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_button_discard,
                PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_button_ignore };
        MessageDialog dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.QUESTION,
                buttonLabels, 0);/*from w ww . j  ava  2 s  .  c o m*/
        int res = dialog.open();
        if (res == 0) { //save
            fBlockOnApply = true;
            performOk();
        } else if (res == 1) { // discard
            fBuildPathsBlock.init(JavaCore.create(getProject()), null, null);
        } else {
            // keep unsaved
        }
    }
    return super.okToLeave();
}