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

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

Introduction

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

Prototype

String NO_LABEL

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

Click Source Link

Document

The label for no buttons.

Usage

From source file:org.eclipse.php.internal.ui.dialogs.saveFiles.SaveAsDialog.java

License:Open Source License

protected void okPressed() {
    IPath path = resourceGroup.getContainerFullPath().append(resourceGroup.getResource());

    // If the user does not supply a file extension and if the save
    // as dialog was provided a default file name append the extension
    // of the default filename to the new name
    if (path.getFileExtension() == null) {
        if (originalFile != null && originalFile.getFileExtension() != null) {
            path = path.addFileExtension(originalFile.getFileExtension());
        } else if (originalName != null) {
            int pos = originalName.lastIndexOf('.');
            if (++pos > 0 && pos < originalName.length()) {
                path = path.addFileExtension(originalName.substring(pos));
            }/*w w  w. j a  v  a2 s . c  om*/
        }
    }

    // If the path already exists then confirm overwrite.
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    if (file.exists()) {
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };
        String question = PHPUIMessages.SaveAsDialog_6 + file.getFullPath().toString()
                + PHPUIMessages.SaveAsDialog_7;
        MessageDialog d = new MessageDialog(getShell(), PHPUIMessages.SaveAsDialog_saveFileMessage, null,
                question, MessageDialog.QUESTION, buttons, 0);
        int overwrite = d.open();
        switch (overwrite) {
        case 0: // Yes
            break;
        case 1: // No
            return;
        case 2: // Cancel
        default:
            cancelPressed();
            return;
        }
    }

    // Store path and close.
    result = path;
    close();
}

From source file:org.eclipse.php.internal.ui.editor.PHPStructuredTextViewer.java

License:Open Source License

/**
 * This method overrides WST since sometimes we get a subset of the document
 * and NOT the whole document, although the case is FORMAT_DOCUMENT. In all
 * other cases we call the parent method.
 *///from ww  w. java2s . c  om
@Override
public void doOperation(int operation) {
    Point selection = getTextWidget().getSelection();
    int cursorPosition = selection.x;
    // save the last cursor position and the top visible line.
    int selectionLength = selection.y - selection.x;
    int topLine = getTextWidget().getTopIndex();

    switch (operation) {
    case FORMAT_DOCUMENT:
        try {
            setRedraw(false);
            // begin recording
            beginRecording(FORMAT_DOCUMENT_TEXT, FORMAT_DOCUMENT_TEXT, cursorPosition, selectionLength);

            // format the whole document !
            IRegion region;
            if (selectionLength != 0) {
                region = new Region(cursorPosition, selectionLength);
            } else {
                region = new Region(0, getDocument().getLength());
            }
            if (fContentFormatter instanceof IContentFormatterExtension) {
                IContentFormatterExtension extension = (IContentFormatterExtension) fContentFormatter;
                IFormattingContext context = new FormattingContext();
                context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
                context.setProperty(FormattingContextProperties.CONTEXT_REGION, region);
                extension.format(getDocument(), context);
            } else {
                fContentFormatter.format(getDocument(), region);
            }
        } finally {
            // end recording
            selection = getTextWidget().getSelection();

            selectionLength = selection.y - selection.x;
            endRecording(cursorPosition, selectionLength);
            // return the cursor to its original position after the
            // formatter change its position.
            getTextWidget().setSelection(cursorPosition);
            getTextWidget().setTopIndex(topLine);
            setRedraw(true);
        }
        return;

    case CONTENTASSIST_PROPOSALS:
        // Handle javascript content assist when there is no support
        // (instead of printing the stack trace)
        if (fViewerConfiguration != null) {
            IProject project = null;
            boolean isJavaScriptRegion = false;
            boolean hasJavaScriptNature = true;
            try {
                // Resolve the partition type
                IStructuredDocument sDoc = (IStructuredDocument) getDocument();
                // get the "real" offset - adjusted according to the
                // projection
                int selectionOffset = getSelectedRange().x;
                IStructuredDocumentRegion sdRegion = sDoc.getRegionAtCharacterOffset(selectionOffset);
                if (sdRegion == null) {
                    super.doOperation(operation);
                    return;
                }
                ITextRegion textRegion = sdRegion.getRegionAtCharacterOffset(selectionOffset);
                if (textRegion instanceof ForeignRegion) {
                    ForeignRegion foreignRegion = (ForeignRegion) textRegion;
                    isJavaScriptRegion = "script" //$NON-NLS-1$
                            .equalsIgnoreCase(foreignRegion.getSurroundingTag());
                }

                // Check if the containing project has JS nature or not
                if (fTextEditor instanceof PHPStructuredEditor) {
                    PHPStructuredEditor phpEditor = (PHPStructuredEditor) fTextEditor;
                    IModelElement modelElement = phpEditor.getModelElement();

                    if (modelElement != null) {
                        IScriptProject scriptProject = modelElement.getScriptProject();
                        project = scriptProject.getProject();
                        if (project != null && project.isAccessible()
                                && project.getNature(JavaScriptCore.NATURE_ID) == null) {
                            hasJavaScriptNature = false;
                        }
                    }
                }

                // open dialog if required
                if (isJavaScriptRegion && !hasJavaScriptNature) {
                    Shell activeWorkbenchShell = PHPUiPlugin.getActiveWorkbenchShell();
                    // Pop a question dialog - if the user selects 'Yes' JS
                    // Support is added, otherwise no change
                    int addJavaScriptSupport = OptionalMessageDialog.open("PROMPT_ADD_JAVASCRIPT_SUPPORT", //$NON-NLS-1$
                            activeWorkbenchShell, PHPUIMessages.PHPStructuredTextViewer_0, null,
                            PHPUIMessages.PHPStructuredTextViewer_1, OptionalMessageDialog.QUESTION,
                            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0); //$NON-NLS-1$

                    // run the JSDT action for adding the JS nature
                    if (addJavaScriptSupport == 0 && project != null) {
                        SetupProjectsWizzard wiz = new SetupProjectsWizzard();
                        wiz.setActivePart(null, this.getTextEditor());
                        wiz.selectionChanged(null, new StructuredSelection(project));
                        wiz.run(null);
                    }
                    return;
                }

            } catch (CoreException e) {
                Logger.logException(e);
            }
        }

        // notifing the processors that the next request for completion is
        // an explicit request
        if (fViewerConfiguration != null) {
            PHPStructuredTextViewerConfiguration structuredTextViewerConfiguration = (PHPStructuredTextViewerConfiguration) fViewerConfiguration;
            IContentAssistProcessor[] all = structuredTextViewerConfiguration.getContentAssistProcessors(this,
                    PHPPartitionTypes.PHP_DEFAULT);
            for (IContentAssistProcessor element : all) {
                if (element instanceof PHPCompletionProcessor) {
                    ((PHPCompletionProcessor) element).setExplicit(true);
                }
            }
        }
        super.doOperation(operation);
        return;

    case SHOW_OUTLINE:
        if (fOutlinePresenter != null) {
            fOutlinePresenter.showInformation();
        }
        return;

    case SHOW_HIERARCHY:
        if (fHierarchyPresenter != null) {
            fHierarchyPresenter.showInformation();
        }
        return;

    case DELETE:
        StyledText textWidget = getTextWidget();
        if (textWidget == null)
            return;
        ITextSelection textSelection = null;
        if (redraws()) {
            try {
                textSelection = (ITextSelection) getSelection();
                int length = textSelection.getLength();
                if (!textWidget.getBlockSelection()
                        && (length == 0 || length == textWidget.getSelectionRange().y))
                    getTextWidget().invokeAction(ST.DELETE_NEXT);
                else
                    deleteSelection(textSelection, textWidget);

                if (fFireSelectionChanged) {
                    Point range = textWidget.getSelectionRange();
                    fireSelectionChanged(range.x, range.y);
                }

            } catch (BadLocationException x) {
                // ignore
            }
        }
        return;
    }

    super.doOperation(operation);
}

From source file:org.eclipse.php.internal.ui.preferences.includepath.VariableBlock.java

License:Open Source License

public boolean performOk() {
    ArrayList removedVariables = new ArrayList();
    ArrayList changedVariables = new ArrayList();
    // removedVariables.addAll(Arrays.asList(PHPProjectOptions.getIncludePathVariableNames()));

    // remove all unchanged
    List changedElements = fVariablesList.getElements();
    List unchangedElements = fVariablesList.getElements();

    for (int i = changedElements.size() - 1; i >= 0; i--) {
        IPVariableElement curr = (IPVariableElement) changedElements.get(i);
        if (curr.isReserved()) {
            changedElements.remove(curr);
        } else {/* www  . j  a  v  a2  s.  c o m*/
            IPath path = curr.getPath();
            IPath prevPath = null; // PHPProjectOptions.getIncludePathVariable(curr.getName());
            if (prevPath != null && prevPath.equals(path)) {
                changedElements.remove(curr);
            } else {
                changedVariables.add(curr.getName());
                unchangedElements.remove(curr);
            }
        }
        removedVariables.remove(curr.getName());

    }
    int steps = changedElements.size() + removedVariables.size();
    if (steps > 0) {

        boolean needsBuild = false;
        if (fAskToBuild && doesChangeRequireFullBuild(removedVariables, changedVariables)) {
            String title = PHPUIMessages.VariableBlock_needsbuild_title;
            String message = PHPUIMessages.VariableBlock_needsbuild_message;

            MessageDialog buildDialog = new MessageDialog(getShell(), title, null, message,
                    MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                            IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                    2);
            int res = buildDialog.open();
            if (res != 0 && res != 1) {
                return false;
            }
            needsBuild = (res == 0);
        }

        final VariableBlockRunnable runnable = new VariableBlockRunnable(removedVariables, changedElements,
                unchangedElements, needsBuild);
        Job buildJob = new Job(PHPUIMessages.VariableBlock_job_description) {
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    runnable.setVariables(monitor);
                } catch (CoreException e) {
                    return e.getStatus();
                } catch (OperationCanceledException e) {
                    return Status.CANCEL_STATUS;
                } finally {
                    monitor.done();
                }
                return Status.OK_STATUS;
            }
        };

        buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
        buildJob.setUser(true);
        buildJob.schedule();
        return true;
    }
    // ProgressMonitorDialog dialog= new ProgressMonitorDialog(getShell());
    // try {
    // dialog.run(true, true, runnable);
    // } catch (InvocationTargetException e) {
    //            ExceptionHandler.handle(e, getShell(), PHPUIMessages.getString("VariableBlock.operation_errror.title"), PHPUIMessages.getString("VariableBlock.operation_errror.message")); 
    // return false;
    // } catch (InterruptedException e) {
    // return false;
    // }
    // }
    return true;
}

From source file:org.eclipse.php.internal.ui.preferences.OptionsConfigurationBlock.java

License:Open Source License

protected boolean processChanges(IWorkbenchPreferenceContainer container) {

    IScopeContext currContext = fLookupOrder[0];

    List<Key> changedOptions = new ArrayList<Key>();
    boolean needsBuild = getChanges(currContext, changedOptions);
    if (changedOptions.isEmpty()) {
        hasChanges = false;//from w  ww . j  a  v a  2s .c  om
        return true;
    } else {
        hasChanges = true;
    }

    if (!this.checkChanges(currContext)) {
        // check failed
        return false;
    }

    boolean doBuild = false;
    if (needsBuild) {
        String[] strings = getFullBuildDialogStrings(fProject == null);
        if (strings != null) {
            MessageDialog dialog = new MessageDialog(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; // cancel pressed
            }
        }
    }
    if (doBuild) {
        prepareForBuild();
    }
    if (container != null) {
        // no need to apply the changes to the original store: will be done
        // by the page container
        if (doBuild) { // post build
            container.registerUpdateJob(CoreUtility.getBuildJob(fProject));
        }
    } else {
        // apply changes right away
        try {
            fManager.applyChanges();
        } catch (BackingStoreException e) {
            PHPUiPlugin.log(e);
            return false;
        }
        if (doBuild) {
            CoreUtility.getBuildJob(fProject).schedule();
        }

    }
    return true;
}

From source file:org.eclipse.rcptt.ui.actions.edit.PasteAction.java

License:Open Source License

/**
 * Check if the user wishes to overwrite the supplied resource or all
 * resources. Copied from//  ww w .  j  av  a  2  s  .c o m
 * org.eclipse.ui.actions.CopyFilesAndFoldersOperation.
 * 
 * @param source
 *            the source resource
 * @param destination
 *            the resource to be overwritten
 * @return one of IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID,
 *         IDialogConstants.NO_ID, IDialogConstants.CANCEL_ID indicating
 *         whether the current resource or all resources can be overwritten,
 *         or if the operation should be canceled.
 */
private int checkOverwrite(final IResource source, final IResource destination) {
    final int[] result = new int[1];

    // Dialogs need to be created and opened in the UI thread
    Runnable query = new Runnable() {
        public void run() {
            String message;
            int resultId[] = { IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.NO_ID,
                    IDialogConstants.CANCEL_ID };
            String labels[] = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };

            String[] bindings = new String[] { IDEResourceInfoUtils.getLocationText(destination),
                    IDEResourceInfoUtils.getDateStringValue(destination),
                    IDEResourceInfoUtils.getLocationText(source),
                    IDEResourceInfoUtils.getDateStringValue(source) };
            message = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteWithDetailsQuestion,
                    bindings);

            MessageDialog dialog = new MessageDialog(shell,
                    IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceExists, null, message,
                    MessageDialog.QUESTION, labels, 0) {
                protected int getShellStyle() {
                    return super.getShellStyle() | SWT.SHEET;
                }
            };
            dialog.open();
            if (dialog.getReturnCode() == SWT.DEFAULT) {
                // A window close returns SWT.DEFAULT, which has to be
                // mapped to a cancel
                result[0] = IDialogConstants.CANCEL_ID;
            } else {
                result[0] = resultId[dialog.getReturnCode()];
            }
        }
    };
    shell.getDisplay().syncExec(query);
    return result[0];
}

From source file:org.eclipse.rcptt.ui.actions.edit.Q7CopyFilesAndFoldersOperation.java

License:Open Source License

/**
 * Check if the user wishes to overwrite the supplied resource or all
 * resources.//from   ww w .  j  ava  2  s. co  m
 * 
 * @param source
 *            the source resource
 * @param destination
 *            the resource to be overwritten
 * @return one of IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID,
 *         IDialogConstants.NO_ID, IDialogConstants.CANCEL_ID indicating
 *         whether the current resource or all resources can be overwritten,
 *         or if the operation should be canceled.
 */
private int checkOverwrite(final IResource source, final IResource destination) {
    final int[] result = new int[1];

    // Dialogs need to be created and opened in the UI thread
    Runnable query = new Runnable() {
        @SuppressWarnings("restriction")
        public void run() {
            String message;
            int resultId[] = { IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.NO_ID,
                    IDialogConstants.CANCEL_ID };
            String labels[] = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };

            if (destination.getType() == IResource.FOLDER) {
                if (homogenousResources(source, destination)) {
                    message = NLS.bind(
                            org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteMergeQuestion,
                            destination.getFullPath().makeRelative());
                } else {
                    if (destination.isLinked()) {
                        message = NLS.bind(
                                org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeLinkQuestion,
                                destination.getFullPath().makeRelative());
                    } else {
                        message = NLS.bind(
                                org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeNoLinkQuestion,
                                destination.getFullPath().makeRelative());
                    }
                    resultId = new int[] { IDialogConstants.YES_ID, IDialogConstants.NO_ID,
                            IDialogConstants.CANCEL_ID };
                    labels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                            IDialogConstants.CANCEL_LABEL };
                }
            } else {
                String[] bindings = new String[] {
                        org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils.getLocationText(destination),
                        org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils
                                .getDateStringValue(destination),
                        org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils.getLocationText(source),
                        org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils.getDateStringValue(source) };
                message = NLS.bind(
                        org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteWithDetailsQuestion,
                        bindings);
            }
            MessageDialog dialog = new MessageDialog(messageShell,
                    org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceExists,
                    null, message, MessageDialog.QUESTION, labels, 0) {
                protected int getShellStyle() {
                    return super.getShellStyle() | SWT.SHEET;
                }
            };
            dialog.open();
            if (dialog.getReturnCode() == SWT.DEFAULT) {
                // A window close returns SWT.DEFAULT, which has to be
                // mapped to a cancel
                result[0] = IDialogConstants.CANCEL_ID;
            } else {
                result[0] = resultId[dialog.getReturnCode()];
            }
        }
    };
    messageShell.getDisplay().syncExec(query);
    return result[0];
}

From source file:org.eclipse.rcptt.ui.actions.edit.Q7CopyFilesAndFoldersOperation.java

License:Open Source License

/**
 * Performs an import of the given stores into the provided container.
 * Returns a status indicating if the import was successful.
 * /*from  w  w w. ja v  a 2 s .  c om*/
 * @param stores
 *            stores that are to be imported
 * @param target
 *            container to which the import will be done
 * @param monitor
 *            a progress monitor for showing progress and for cancelation
 */
private void performFileImport(IFileStore[] stores, IContainer target, IProgressMonitor monitor) {
    IOverwriteQuery query = new IOverwriteQuery() {
        @SuppressWarnings("restriction")
        public String queryOverwrite(String pathString) {
            if (alwaysOverwrite) {
                return ALL;
            }

            final String returnCode[] = { CANCEL };
            final String msg = NLS.bind(
                    org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteQuestion,
                    pathString);
            final String[] options = { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
            messageShell.getDisplay().syncExec(new Runnable() {
                public void run() {
                    MessageDialog dialog = new MessageDialog(messageShell,
                            org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_question,
                            null, msg, MessageDialog.QUESTION, options, 0) {
                        protected int getShellStyle() {
                            return super.getShellStyle() | SWT.SHEET;
                        }
                    };
                    dialog.open();
                    int returnVal = dialog.getReturnCode();
                    String[] returnCodes = { YES, ALL, NO, CANCEL };
                    returnCode[0] = returnVal == -1 ? CANCEL : returnCodes[returnVal];
                }
            });
            if (returnCode[0] == ALL) {
                alwaysOverwrite = true;
            } else if (returnCode[0] == CANCEL) {
                canceled = true;
            }
            return returnCode[0];
        }
    };

    ImportOperation op = new ImportOperation(target.getFullPath(), stores[0].getParent(),
            FileStoreStructureProvider.INSTANCE, query, Arrays.asList(stores));
    op.setContext(messageShell);
    op.setCreateContainerStructure(false);
    op.setVirtualFolders(createVirtualFoldersAndLinks);
    op.setCreateLinks(createLinks);
    op.setRelativeVariable(relativeVariable);
    try {
        op.run(monitor);
    } catch (InterruptedException e) {
        return;
    } catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof CoreException) {
            displayError(((CoreException) e.getTargetException()).getStatus());
        } else {
            display(e);
        }
        return;
    }
    // Special case since ImportOperation doesn't throw a CoreException on
    // failure.
    IStatus status = op.getStatus();
    if (!status.isOK()) {
        if (errorStatus == null) {
            errorStatus = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.ERROR, getProblemsMessage(), null);
        }
        errorStatus.merge(status);
    }
}

From source file:org.eclipse.rcptt.ui.dialogs.AddProjectReferencesDialog.java

License:Open Source License

private AddProjectReferencesDialog(Shell parentShell, IProject project,
        Map<IProject, Set<IQ7NamedElement>> references) {
    super(parentShell, Messages.AddProjectReferencesDialog_Title, null, null, MessageDialog.NONE,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0,
            Messages.AddProjectReferencesDialog_ToggleText, false);
    this.project = project;
    this.references = references;
    this.message = generateMessage(references);
    setShellStyle(SWT.SHEET);/*from   w  ww  .  j  av a  2 s .com*/
}

From source file:org.eclipse.rcptt.ui.dialogs.RemoveAllProjectReferencesDialog.java

License:Open Source License

private RemoveAllProjectReferencesDialog(Shell parentShell, IQ7Project project,
        List<IQ7NamedElement> references) {
    super(parentShell, "Project Context and Verification References", null, null, MessageDialog.NONE,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0,
            "Always remove default project context and verification references automatically.", false);
    this.project = project;
    this.references = references;
    this.message = generateMessage(references);
    setShellStyle(SWT.SHEET);//w w  w . jav  a 2 s  .c  o  m
}

From source file:org.eclipse.rcptt.ui.dialogs.RemoveProjectReferencesDialog.java

License:Open Source License

private RemoveProjectReferencesDialog(Shell parentShell, IQ7NamedElement element, List<String> references) {
    super(parentShell, "Project Context and Verification References", null, null, MessageDialog.NONE,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0,
            "Always remove default project context and verification references automatically.", false);
    this.element = element;
    this.references = references;
    this.message = generateMessage(references);
    setShellStyle(SWT.SHEET);//  www . j a v a 2 s  .  c  om
}