Example usage for org.eclipse.jface.dialogs IMessageProvider WARNING

List of usage examples for org.eclipse.jface.dialogs IMessageProvider WARNING

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs IMessageProvider WARNING.

Prototype

int WARNING

To view the source code for org.eclipse.jface.dialogs IMessageProvider WARNING.

Click Source Link

Document

Constant for a warning message (value 2).

Usage

From source file:org.eclipse.ui.dialogs.WizardNewFileCreationPage.java

License:Open Source License

/**
 * Returns whether this page's controls currently all contain valid values.
 * //from ww w.j  a  v  a  2s .  c o  m
 * @return <code>true</code> if all controls are valid, and
 *         <code>false</code> if at least one is invalid
 */
protected boolean validatePage() {
    boolean valid = true;

    if (!resourceGroup.areAllValuesValid()) {
        // if blank name then fail silently
        if (resourceGroup.getProblemType() == ResourceAndContainerGroup.PROBLEM_RESOURCE_EMPTY
                || resourceGroup.getProblemType() == ResourceAndContainerGroup.PROBLEM_CONTAINER_EMPTY) {
            setMessage(resourceGroup.getProblemMessage());
            setErrorMessage(null);
        } else {
            setErrorMessage(resourceGroup.getProblemMessage());
        }
        valid = false;
    }

    String resourceName = resourceGroup.getResource();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IStatus result = workspace.validateName(resourceName, IResource.FILE);
    if (!result.isOK()) {
        setErrorMessage(result.getMessage());
        return false;
    }

    IStatus linkedResourceStatus = null;
    if (valid) {
        linkedResourceStatus = validateLinkedResource();
        if (linkedResourceStatus.getSeverity() == IStatus.ERROR) {
            valid = false;
        }
    }
    // validateLinkedResource sets messages itself
    if (valid && (linkedResourceStatus == null || linkedResourceStatus.isOK())) {
        setMessage(null);
        setErrorMessage(null);

        // perform "resource exists" check if it was skipped in
        // ResourceAndContainerGroup
        if (resourceGroup.getAllowExistingResources()) {
            String problemMessage = NLS.bind(IDEWorkbenchMessages.ResourceGroup_nameExists, getFileName());
            IPath resourcePath = getContainerFullPath().append(getFileName());
            if (workspace.getRoot().getFolder(resourcePath).exists()) {
                setErrorMessage(problemMessage);
                valid = false;
            }
            if (workspace.getRoot().getFile(resourcePath).exists()) {
                setMessage(problemMessage, IMessageProvider.WARNING);
            }
        }
    }
    if (isFilteredByParent()) {
        setMessage(IDEWorkbenchMessages.WizardNewFileCreationPage_resourceWillBeFilteredWarning,
                IMessageProvider.ERROR);
        setupLinkedResourceTarget();
        valid = false;
    }
    return valid;
}

From source file:org.eclipse.ui.forms.examples.internal.rcp.ErrorMessagesPage.java

License:Open Source License

private void configureFormText(final Form form, FormText text) {
    text.addHyperlinkListener(new HyperlinkAdapter() {
        public void linkActivated(HyperlinkEvent e) {
            String is = (String) e.getHref();
            try {
                int index = Integer.parseInt(is);
                IMessage[] messages = form.getChildrenMessages();
                IMessage message = messages[index];
                Control c = message.getControl();
                ((FormText) e.widget).getShell().dispose();
                if (c != null)
                    c.setFocus();/*from w  w  w  .ja  v  a  2s . com*/
            } catch (NumberFormatException ex) {
            }
        }
    });
    text.setImage("error", getImage(IMessageProvider.ERROR));
    text.setImage("warning", getImage(IMessageProvider.WARNING));
    text.setImage("info", getImage(IMessageProvider.INFORMATION));
}

From source file:org.eclipse.ui.forms.examples.internal.rcp.ErrorMessagesPage.java

License:Open Source License

String createFormTextContent(IMessage[] messages) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    pw.println("<form>");
    for (int i = 0; i < messages.length; i++) {
        IMessage message = messages[i];//from w w  w.j  a v a2 s .c o m
        pw.print("<li vspace=\"false\" style=\"image\" indent=\"16\" value=\"");
        switch (message.getMessageType()) {
        case IMessageProvider.ERROR:
            pw.print("error");
            break;
        case IMessageProvider.WARNING:
            pw.print("warning");
            break;
        case IMessageProvider.INFORMATION:
            pw.print("info");
            break;
        }
        pw.print("\"> <a href=\"");
        pw.print(i + "");
        pw.print("\">");
        if (message.getPrefix() != null)
            pw.print(message.getPrefix());
        pw.print(message.getMessage());
        pw.println("</a></li>");
    }
    pw.println("</form>");
    pw.flush();
    return sw.toString();
}

From source file:org.eclipse.ui.forms.examples.internal.rcp.ErrorMessagesPage.java

License:Open Source License

private void createDecoratedTextField(String label, FormToolkit toolkit, Composite parent,
        final IMessageManager mmng) {
    toolkit.createLabel(parent, label);/* w  ww .j  av  a2s.  c  om*/
    final Text text = toolkit.createText(parent, "");
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = 150;
    text.setLayoutData(gd);
    text.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            String s = text.getText();
            // flag length
            if (s.length() > 0 && s.length() <= 5) {
                mmng.addMessage("textLength", "Text is longer than 0 characters", null,
                        IMessageProvider.INFORMATION, text);
            } else if (s.length() > 5 && s.length() <= 10) {
                mmng.addMessage("textLength", "Text is longer than 5 characters", null,
                        IMessageProvider.WARNING, text);
            } else if (s.length() > 10) {
                mmng.addMessage("textLength", "Text is longer than 10 characters", null, IMessageProvider.ERROR,
                        text);
            } else {
                mmng.removeMessage("textLength", text);
            }
            // flag type
            boolean badType = false;
            for (int i = 0; i < s.length(); i++) {
                if (!Character.isLetter(s.charAt(i))) {
                    badType = true;
                    break;
                }
            }
            if (badType) {
                mmng.addMessage("textType", "Text must only contain letters", null, IMessageProvider.ERROR,
                        text);
            } else {
                mmng.removeMessage("textType", text);
            }
        }
    });
}

From source file:org.eclipse.ui.forms.examples.internal.rcp.NewStylePage.java

License:Open Source License

protected void createFormContent(IManagedForm managedForm) {
    final ScrolledForm form = managedForm.getForm();
    final FormToolkit toolkit = managedForm.getToolkit();
    toolkit.getHyperlinkGroup().setHyperlinkUnderlineMode(HyperlinkSettings.UNDERLINE_HOVER);

    GridLayout layout = new GridLayout();
    layout.numColumns = 2;//from w w  w .  j  a v  a 2  s  .c o  m
    layout.marginHeight = 10;
    layout.marginWidth = 6;
    layout.horizontalSpacing = 20;
    form.getBody().setLayout(layout);

    Section section = toolkit.createSection(form.getBody(),
            ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
    Composite client = toolkit.createComposite(section);
    section.setClient(client);
    section.setText("Header features");
    section.setDescription("Use the switches below to control basic heading parameters.");
    GridData gd = new GridData(GridData.FILL_BOTH);
    section.setLayoutData(gd);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    client.setLayout(layout);
    final Button tbutton = toolkit.createButton(client, "Add title", SWT.CHECK);
    final Button sbutton = toolkit.createButton(client, "Short title", SWT.RADIO);
    sbutton.setSelection(true);
    sbutton.setEnabled(false);
    gd = new GridData();
    gd.horizontalIndent = 10;
    sbutton.setLayoutData(gd);
    final Button lbutton = toolkit.createButton(client, "Long title", SWT.RADIO);
    gd = new GridData();
    gd.horizontalIndent = 10;
    lbutton.setLayoutData(gd);
    lbutton.setEnabled(false);
    tbutton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            updateTitle(form, tbutton.getSelection(), sbutton.getSelection());
            sbutton.setEnabled(tbutton.getSelection());
            lbutton.setEnabled(tbutton.getSelection());
        }
    });
    sbutton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            updateTitle(form, tbutton.getSelection(), sbutton.getSelection());
        }
    });
    lbutton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            updateTitle(form, tbutton.getSelection(), sbutton.getSelection());
        }
    });
    final Button ibutton = toolkit.createButton(client, "Add image", SWT.CHECK);
    ibutton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            updateImage(form, ibutton.getSelection());
        }
    });

    final Button tbbutton = toolkit.createButton(client, "Add tool bar", SWT.CHECK);

    final Button albutton = toolkit.createButton(client, "Set tool bar allignment to SWT.BOTTOM", SWT.CHECK);
    albutton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            form.getForm().setToolBarVerticalAlignment(albutton.getSelection() ? SWT.BOTTOM : SWT.TOP);
            form.reflow(true);
        }
    });
    gd = new GridData();
    gd.horizontalIndent = 10;
    albutton.setLayoutData(gd);
    albutton.setEnabled(false);
    tbbutton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addToolBar(toolkit, form, tbbutton.getSelection());
            albutton.setEnabled(tbbutton.getSelection());
        }
    });

    final Button gbutton = toolkit.createButton(client, "Paint background gradient", SWT.CHECK);
    gbutton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addHeadingGradient(toolkit, form, gbutton.getSelection());
        }
    });

    final Button clbutton = toolkit.createButton(client, "Add head client", SWT.CHECK);
    clbutton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addHeadClient(toolkit, form, clbutton.getSelection());
        }
    });

    final Button mbutton = toolkit.createButton(client, "Add drop-down menu", SWT.CHECK);
    mbutton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addMenu(toolkit, form, mbutton.getSelection());
        }
    });

    final Button dbutton = toolkit.createButton(client, "Add drag support", SWT.CHECK);
    dbutton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (dbutton.getSelection()) {
                addDragSupport(form);
                dbutton.setEnabled(false);
            }
        }
    });

    section = toolkit.createSection(form.getBody(),
            ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
    Composite client2 = toolkit.createComposite(section);
    section.setClient(client2);
    section.setText("Messages and active state");
    section.setDescription("Use the buttons below to control messages and active state.");
    gd = new GridData(GridData.FILL_BOTH);
    section.setLayoutData(gd);

    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 4;
    client2.setLayout(layout);

    final Button shortMessage = toolkit.createButton(client2, "Short message", SWT.RADIO);
    shortMessage.setSelection(true);
    gd = new GridData();
    gd.horizontalSpan = 4;
    shortMessage.setLayoutData(gd);
    final Button longMessage = toolkit.createButton(client2, "Long message", SWT.RADIO);
    gd = new GridData();
    gd.horizontalSpan = 4;
    longMessage.setLayoutData(gd);

    final IHyperlinkListener listener = new HyperlinkAdapter() {
        public void linkActivated(HyperlinkEvent e) {
            String title = e.getLabel();
            String details = (String) e.getHref();
            if (details == null) {
                details = title;
                title = null;
            }
            switch (form.getForm().getMessageType()) {
            case IMessageProvider.NONE:
            case IMessageProvider.INFORMATION:
                if (title == null)
                    title = "Forms Information";
                MessageDialog.openInformation(form.getShell(), title, details);
                break;
            case IMessageProvider.WARNING:
                if (title == null)
                    title = "Forms Warning";
                MessageDialog.openWarning(form.getShell(), title, details);
                break;
            case IMessageProvider.ERROR:
                if (title == null)
                    title = "Forms Error";
                MessageDialog.openError(form.getShell(), title, details);
                break;
            }
        }
    };

    final Button hyperMessage = toolkit.createButton(client2, "Message as hyperlink", SWT.CHECK);
    gd = new GridData();
    gd.horizontalSpan = 4;
    hyperMessage.setLayoutData(gd);
    hyperMessage.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (hyperMessage.getSelection())
                form.getForm().addMessageHyperlinkListener(listener);
            else
                form.getForm().removeMessageHyperlinkListener(listener);
        }
    });

    Control[] children = client.getChildren();
    ArrayList buttons = new ArrayList();
    for (int i = 0; i < children.length; i++) {
        if (children[i] instanceof Button) {
            Button button = (Button) children[i];
            if ((button.getStyle() & SWT.CHECK) != 0 && !button.equals(dbutton)) {
                buttons.add(button);
            }
        }
    }
    final Button[] checkboxes = (Button[]) buttons.toArray(new Button[buttons.size()]);

    final Button manageMessage = toolkit.createButton(client2, "Use message manager", SWT.CHECK);
    gd = new GridData();
    gd.horizontalSpan = 4;
    manageMessage.setLayoutData(gd);

    SelectionAdapter mmListener = new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (manageMessage.getSelection() && e.widget instanceof Button)
                addRemoveMessage((Button) e.widget, form.getMessageManager());
        }
    };
    for (int i = 0; i < checkboxes.length; i++)
        checkboxes[i].addSelectionListener(mmListener);

    final Button autoUpdate = toolkit.createButton(client2, "Auto update message manager", SWT.CHECK);
    gd = new GridData();
    gd.horizontalSpan = 4;
    autoUpdate.setLayoutData(gd);
    autoUpdate.setSelection(true);
    autoUpdate.setEnabled(false);
    autoUpdate.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            form.getMessageManager().setAutoUpdate(autoUpdate.getSelection());
        }
    });

    shortMessage.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            form.setMessage(getErrorMessage(form.getMessageType(), longMessage.getSelection()),
                    form.getMessageType());
        }
    });
    longMessage.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            form.setMessage(getErrorMessage(form.getMessageType(), longMessage.getSelection()),
                    form.getMessageType());
        }
    });

    final Button error = toolkit.createButton(client2, "Error", SWT.PUSH);
    error.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            form.setMessage(getErrorMessage(IMessageProvider.ERROR, longMessage.getSelection()),
                    IMessageProvider.ERROR);

        }
    });
    final Button warning = toolkit.createButton(client2, "Warning", SWT.PUSH);
    warning.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            form.setMessage(getErrorMessage(IMessageProvider.WARNING, longMessage.getSelection()),
                    IMessageProvider.WARNING);
        }
    });
    final Button info = toolkit.createButton(client2, "Info", SWT.PUSH);
    info.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            form.setMessage(getErrorMessage(IMessageProvider.INFORMATION, longMessage.getSelection()),
                    IMessageProvider.INFORMATION);
        }
    });
    final Button cancel = toolkit.createButton(client2, "Cancel", SWT.PUSH);
    cancel.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            form.setMessage(null, 0);
        }
    });
    manageMessage.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            boolean selection = manageMessage.getSelection();
            if (!selection)
                autoUpdate.setSelection(true);
            autoUpdate.setEnabled(selection);
            IMessageManager mm = form.getMessageManager();
            mm.setAutoUpdate(false);
            if (selection) {
                for (int i = 0; i < checkboxes.length; i++) {
                    addRemoveMessage(checkboxes[i], mm);
                }
            } else {
                mm.removeAllMessages();
            }
            mm.setAutoUpdate(true);
            error.setEnabled(!selection);
            warning.setEnabled(!selection);
            info.setEnabled(!selection);
            cancel.setEnabled(!selection);
            if (selection) {
                hyperMessage.setSelection(false);
                form.getForm().removeMessageHyperlinkListener(listener);
            }
            hyperMessage.setEnabled(!selection);
        }
    });

    final Button busy = toolkit.createButton(client2, "Start Progress", SWT.PUSH);
    busy.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            // IWorkbenchSiteProgressService service =
            // (IWorkbenchSiteProgressService)getSite().getAdapter(IWorkbenchSiteProgressService.class);

            if (form.getForm().isBusy()) {
                form.getForm().setBusy(false);
                busy.setText("Start Progress");
            } else {
                form.getForm().setBusy(true);
                busy.setText("Stop Progress");
            }
        }
    });
    gd = new GridData();
    gd.horizontalSpan = 2;
    busy.setLayoutData(gd);
}

From source file:org.eclipse.ui.internal.editors.text.HyperlinkDetectorsConfigurationBlock.java

License:Open Source License

/**
 * Applies the status to the status line of a dialog page.
 *
 * @param status the status//from  w  ww  .  j  a va 2s.  c o m
 */
private void applyToStatusLine(IStatus status) {
    String message = status.getMessage();
    switch (status.getSeverity()) {
    case IStatus.OK:
        fPreferencePage.setMessage(message, IMessageProvider.NONE);
        fPreferencePage.setErrorMessage(null);
        break;
    case IStatus.WARNING:
        fPreferencePage.setMessage(message, IMessageProvider.WARNING);
        fPreferencePage.setErrorMessage(null);
        break;
    case IStatus.INFO:
        fPreferencePage.setMessage(message, IMessageProvider.INFORMATION);
        fPreferencePage.setErrorMessage(null);
        break;
    default:
        if (message.length() == 0) {
            message = null;
        }
        fPreferencePage.setMessage(null);
        fPreferencePage.setErrorMessage(message);
        break;
    }
}

From source file:org.eclipse.ui.internal.ide.dialogs.PathVariableDialog.java

License:Open Source License

/**
 * Validates the current variable value, and updates this dialog's message.
 * /*from  w  ww  .  j a  v  a2s.c  o m*/
 * @return true if the value is valid, false otherwise
 */
private boolean validateVariableValue() {
    boolean allowFinish = false;

    // if the current validationStatus is ERROR, no additional validation applies
    if (validationStatus == IMessageProvider.ERROR) {
        return false;
    }

    // assumes everything will be ok
    String message = standardMessage;
    int newValidationStatus = IMessageProvider.NONE;

    if (variableValue.length() == 0) {
        // the variable value is empty
        if (locationEntered) {
            // a location value was entered before and is now empty
            newValidationStatus = IMessageProvider.ERROR;
            message = IDEWorkbenchMessages.PathVariableDialog_variableValueEmptyMessage;
        }
    }
    if (currentResource != null) {
        // While editing project path variables, the variable value can
        // contain macros such as "${foo}\etc"
        allowFinish = true;
        String resolvedValue = getVariableResolvedValue();
        IPath resolvedPath = Path.fromOSString(resolvedValue);
        if (!IDEResourceInfoUtils.exists(resolvedPath.toOSString())) {
            // the path does not exist (warning)
            message = IDEWorkbenchMessages.PathVariableDialog_pathDoesNotExistMessage;
            newValidationStatus = IMessageProvider.WARNING;
        } else {
            IFileInfo info = IDEResourceInfoUtils.getFileInfo(resolvedPath.toOSString());
            if ((info.isDirectory() && ((variableType & IResource.FOLDER) == 0))
                    || (!info.isDirectory() && ((variableType & IResource.FILE) == 0))) {
                allowFinish = false;
                newValidationStatus = IMessageProvider.ERROR;
                if (((variableType & IResource.FOLDER) != 0))
                    message = IDEWorkbenchMessages.PathVariableDialog_variableValueIsWrongTypeFolder;
                else
                    message = IDEWorkbenchMessages.PathVariableDialog_variableValueIsWrongTypeFile;
            }
        }
    } else if (!Path.EMPTY.isValidPath(variableValue)) {
        // the variable value is an invalid path
        message = IDEWorkbenchMessages.PathVariableDialog_variableValueInvalidMessage;
        newValidationStatus = IMessageProvider.ERROR;
    } else if (!new Path(variableValue).isAbsolute()) {
        // the variable value is a relative path
        message = IDEWorkbenchMessages.PathVariableDialog_pathIsRelativeMessage;
        newValidationStatus = IMessageProvider.ERROR;
    } else if (!IDEResourceInfoUtils.exists(variableValue)) {
        // the path does not exist (warning)
        message = IDEWorkbenchMessages.PathVariableDialog_pathDoesNotExistMessage;
        newValidationStatus = IMessageProvider.WARNING;
        allowFinish = true;
    } else {
        allowFinish = true;
    }

    // overwrite the current validation status / message only if everything is ok (clearing them)
    // or if we have a more serious problem than the current one
    if (validationStatus == IMessageProvider.NONE || newValidationStatus > validationStatus) {
        validationStatus = newValidationStatus;
        validationMessage = message;
    }
    setMessage(validationMessage, validationStatus);
    return allowFinish;
}

From source file:org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.java

License:Open Source License

/**
 * This implementation asks the user for the workspace path of a file resource and saves the document there.
 *
 * @param progressMonitor the progress monitor to be used
 * @since 3.2//from ww w . j  a v a 2 s .co m
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
    final IEditorInput input = getEditorInput();

    IDocumentProvider provider = getDocumentProvider();
    final IEditorInput newInput;

    if (input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) {
        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        IPath oldPath = URIUtil.toPath(((IURIEditorInput) input).getURI());
        if (oldPath != null) {
            dialog.setFileName(oldPath.lastSegment());
            dialog.setFilterPath(oldPath.toOSString());
        }

        String path = dialog.open();
        if (path == null) {
            if (progressMonitor != null)
                progressMonitor.setCanceled(true);
            return;
        }

        // Check whether file exists and if so, confirm overwrite
        final File localFile = new File(path);
        if (localFile.exists()) {
            MessageDialog overwriteDialog = new MessageDialog(shell,
                    TextEditorMessages.AbstractDecoratedTextEditor_saveAs_overwrite_title, null,
                    NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_saveAs_overwrite_message,
                            path),
                    MessageDialog.WARNING,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No' is the default
            if (overwriteDialog.open() != Window.OK) {
                if (progressMonitor != null) {
                    progressMonitor.setCanceled(true);
                    return;
                }
            }
        }

        IFileStore fileStore;
        try {
            fileStore = EFS.getStore(localFile.toURI());
        } catch (CoreException ex) {
            EditorsPlugin.log(ex.getStatus());
            String title = TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_title;
            String msg = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_message,
                    ex.getMessage());
            MessageDialog.openError(shell, title, msg);
            return;
        }

        IFile file = getWorkspaceFile(fileStore);
        if (file != null)
            newInput = new FileEditorInput(file);
        else
            newInput = new FileStoreEditorInput(fileStore);

    } else {
        SaveAsDialog dialog = new SaveAsDialog(shell);

        IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile() : null;
        if (original != null)
            dialog.setOriginalFile(original);
        else
            dialog.setOriginalName(input.getName());

        dialog.create();

        if (provider.isDeleted(input) && original != null) {
            String message = NLSUtility.format(
                    TextEditorMessages.AbstractDecoratedTextEditor_warning_saveAs_deleted, original.getName());
            dialog.setErrorMessage(null);
            dialog.setMessage(message, IMessageProvider.WARNING);
        }

        if (dialog.open() == Window.CANCEL) {
            if (progressMonitor != null)
                progressMonitor.setCanceled(true);
            return;
        }

        IPath filePath = dialog.getResult();
        if (filePath == null) {
            if (progressMonitor != null)
                progressMonitor.setCanceled(true);
            return;
        }

        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IFile file = workspace.getRoot().getFile(filePath);
        newInput = new FileEditorInput(file);

    }

    if (provider == null) {
        // editor has programmatically been  closed while the dialog was open
        return;
    }

    boolean success = false;
    try {

        provider.aboutToChange(newInput);
        provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
        success = true;

    } catch (CoreException x) {
        final IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            String title = TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_title;
            String msg = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_message,
                    x.getMessage());
            MessageDialog.openError(shell, title, msg);
        }
    } finally {
        provider.changed(newInput);
        if (success)
            setInput(newInput);
    }

    if (progressMonitor != null)
        progressMonitor.setCanceled(!success);
}

From source file:org.eclipse.ui.texteditor.MessageRegion.java

License:Open Source License

/**
 * Show the new message in the message text and update the image. Base the background color on
 * whether or not there are errors.// w  ww.j a  v  a2 s  . c  o m
 *
 * @param newMessage The new value for the message
 * @param newType One of the IMessageProvider constants. If newType is IMessageProvider.NONE
 *            show the title.
 * @see IMessageProvider
 */
public void updateText(String newMessage, int newType) {
    Image newImage = null;
    boolean showingError = false;
    switch (newType) {
    case IMessageProvider.NONE:
        hideRegion();
        return;
    case IMessageProvider.INFORMATION:
        newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO);
        break;
    case IMessageProvider.WARNING:
        newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
        break;
    case IMessageProvider.ERROR:
        newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
        showingError = true;
        break;
    }

    if (newMessage == null) {//No message so clear the area
        hideRegion();
        return;
    }
    showRegion();
    // Any more updates required
    if (newMessage.equals(messageText.getText()) && newImage == messageImageLabel.getImage())
        return;
    messageImageLabel.setImage(newImage);
    messageText.setText(newMessage);
    if (showingError)
        setMessageColors(JFaceColors.getErrorBackground(messageComposite.getDisplay()));
    else {
        lastMessageText = newMessage;
        setMessageColors(JFaceColors.getBannerBackground(messageComposite.getDisplay()));
    }

}

From source file:org.eclipse.vex.ui.internal.editor.VexEditor.java

License:Open Source License

/**
 * Asks the user for the workspace path of a file resource and saves the document there.
 *
 * @param progressMonitor/* w  ww  .  j  ava 2 s .  c o m*/
 *            the monitor in which to run the operation
 */
protected void performSaveAs(final IProgressMonitor progressMonitor) {
    final Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
    final IDocumentProvider provider = getDocumentProvider();
    final IEditorInput input = getEditorInput();
    final IEditorInput newInput;

    if (input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) {
        final FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        final IPath oldPath = URIUtil.toPath(((IURIEditorInput) input).getURI());
        if (oldPath != null) {
            dialog.setFileName(oldPath.lastSegment());
            dialog.setFilterPath(oldPath.toOSString());
        }
        final String path = dialog.open();
        if (path == null) {
            if (progressMonitor != null) {
                progressMonitor.setCanceled(true);
            }
            return;
        }

        // Check whether file exists and if so, confirm overwrite
        final File localFile = new File(path);
        if (localFile.exists()) {
            final String title = Messages.getString("VexEditor.saveAs.overwrite.title");
            final String message = MessageFormat
                    .format(Messages.getString("VexEditor.saveAs.overwrite.message"), path);
            final MessageDialog overwriteDialog = new MessageDialog(shell, title, null, message,
                    MessageDialog.WARNING,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No' is the default
            if (overwriteDialog.open() != Window.OK) {
                if (progressMonitor != null) {
                    progressMonitor.setCanceled(true);
                    return;
                }
            }
        }

        IFileStore fileStore;
        try {
            fileStore = EFS.getStore(localFile.toURI());
        } catch (final CoreException ex) {
            VexPlugin.getDefault().log(IStatus.ERROR, ex.getLocalizedMessage(), ex);
            final String title = Messages.getString("VexEditor.saveAs.error.title");
            final String msg = MessageFormat.format(Messages.getString("VexEditor.saveAs.error.message"),
                    ex.getLocalizedMessage());
            MessageDialog.openError(shell, title, msg);
            return;
        }

        final IFile file = getWorkspaceFile(fileStore);
        if (file != null) {
            newInput = new FileEditorInput(file);
        } else {
            newInput = new FileStoreEditorInput(fileStore);
        }
    } else {
        final SaveAsDialog dialog = new SaveAsDialog(shell);

        final IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
        if (original != null) {
            dialog.setOriginalFile(original);
        } else {
            dialog.setOriginalName(input.getName());
        }

        dialog.create();

        if (provider.isDeleted(input) && original != null) {
            final String msg = MessageFormat.format(Messages.getString("VexEditor.saveAs.deleted"),
                    original.getName());
            dialog.setErrorMessage(null);
            dialog.setMessage(msg, IMessageProvider.WARNING);
        }

        if (dialog.open() == Window.CANCEL) {
            if (progressMonitor != null) {
                progressMonitor.setCanceled(true);
            }
            return;
        }

        final IPath filePath = dialog.getResult();
        if (filePath == null) {
            if (progressMonitor != null) {
                progressMonitor.setCanceled(true);
            }
            return;
        }

        final IWorkspace workspace = ResourcesPlugin.getWorkspace();
        final IFile file = workspace.getRoot().getFile(filePath);
        newInput = new FileEditorInput(file);
    }

    if (provider == null) {
        // editor has programmatically been  closed while the dialog was open
        return;
    }

    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        syncDocumentProvider();
        provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
        success = true;
    } catch (final CoreException ex) {
        final IStatus status = ex.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            VexPlugin.getDefault().log(IStatus.ERROR, ex.getLocalizedMessage(), ex);
            final String title = Messages.getString("VexEditor.saveAs.error.title");
            final String msg = MessageFormat.format(Messages.getString("VexEditor.saveAs.error.message"),
                    ex.getLocalizedMessage());
            MessageDialog.openError(shell, title, msg);
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
            setClean();
        }
    }

    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}