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

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

Introduction

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

Prototype

int ERROR

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

Click Source Link

Document

Constant for an error message (value 3).

Usage

From source file:org.eclipse.datatools.engagement.marklogic.ui.wizards.XPathChoosePage.java

License:Open Source License

/**
 * the xpath expression is valid or not/*from w w  w .jav  a2s.com*/
 * @return
 */
private boolean isValid() {
    if (this.getControl() == null || this.getControl().isDisposed())
        return true;

    if (!isRootPathValid()) {
        this.setMessage(Messages.getString("error.invalidXpath"), IMessageProvider.ERROR); //$NON-NLS-1$
        return false;
    } else {
        resetXPathPropInHandle(rootPath);
        return true;
    }
}

From source file:org.eclipse.datatools.sqltools.sqleditor.preferences.SQLEditorPage.java

License:Open Source License

private Control createAppearancePage(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout(1, true);
    composite.setLayout(gridLayout);/*from   www .j av  a2 s . c  o m*/

    // syntax validation group
    Group syntaxValidationGroup = SWTUtils.createGroup(composite,
            PreferenceMessages.SQLEditor_syntaxValidationGroup, 1);

    Composite composite1 = SWTUtils.createComposite(syntaxValidationGroup, 2);
    // Syntax validation
    _syntaxValidation = SWTUtils.createCheckBox(composite1, PreferenceMessages.SQLEditor_syntaxValidation, 2,
            0);
    _syntaxValidation.setToolTipText(PreferenceMessages.SQLEditor_syntaxValidation_tooltip);
    _syntaxValidation.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            update();
        }
    });
    createPortabilityCheckCombo(composite1);

    //syntax validation limitation group
    _maxLineButton = new Button(composite1, SWT.CHECK);
    _maxLineButton.setText(PreferenceMessages.SQLEditor_maxLineButton);
    _maxLineButton.setToolTipText(PreferenceMessages.SQLEditor_maxLineButton_tooltip);
    _maxLineButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            updateMaxLineText();
        }
    });
    _maxLineText = SWTUtils.createTextBox(composite1, 1, 40);
    _maxLineText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            try {
                int maxRow = 0;
                maxRow = Integer.parseInt(((Text) e.widget).getText().trim());
                if (maxRow <= 0) {
                    _preferencePage.setMessage(PreferenceMessages.General_max_row_num, IMessageProvider.ERROR);
                    _preferencePage.setValid(false);
                } else {
                    _preferencePage.setMessage(null);
                    _preferencePage.setValid(true);
                }
            } catch (NumberFormatException e1) {
                _preferencePage.setMessage(
                        (((Text) e.widget).getText().trim() + PreferenceMessages.General_invalid_int),
                        IMessageProvider.ERROR);
                _preferencePage.setValid(false);
            }

        }
    });

    _promptDisableButton = SWTUtils.createCheckBox(syntaxValidationGroup,
            PreferenceMessages.SQLEditor_showPromptDialog, 1, 20);

    _showSyntaxErorrDetail = SWTUtils.createCheckBox(syntaxValidationGroup,
            PreferenceMessages.SQLEditor_showSyntaxErorrDetail, 2, 5);
    _showSyntaxErorrDetail.setToolTipText(PreferenceMessages.SQLEditor_showSyntaxErorrDetail_tooltip);

    Group executeSelectedSQLGroup = SWTUtils.createGroup(composite,
            PreferenceMessages.SQLEditor_executeCurrentSQLGroup, 2);

    _executeBetweenDelimiter = new Button(executeSelectedSQLGroup, SWT.RADIO);
    _executeBetweenDelimiter.setText(PreferenceMessages.SQLEditor_executeSQLBetweenDelimiter);
    _executeBetweenDelimiter.setToolTipText(PreferenceMessages.SQLEditor_executeSQLBetweenDelimiter_tip);
    _executeBetweenDelimiter.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            _terminatorsCombo.setEnabled(_executeBetweenDelimiter.getSelection());
        }
    });
    _terminatorsCombo = SWTUtils.createCombo(executeSelectedSQLGroup, new String[] { "go", ";", "/" }, 1);

    _executeCurrentLine = new Button(executeSelectedSQLGroup, SWT.RADIO);
    _executeCurrentLine.setText(PreferenceMessages.SQLEditor_executeCurrentLine);
    _executeCurrentLine.setToolTipText(PreferenceMessages.SQLEditor_executeCurrentLine_tip);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    _executeCurrentLine.setLayoutData(data);

    _executeBetweenBlankLine = new Button(executeSelectedSQLGroup, SWT.RADIO);
    _executeBetweenBlankLine.setText(PreferenceMessages.SQLEditor_executeSQLBetweenBlankLine);
    _executeBetweenBlankLine.setToolTipText(PreferenceMessages.SQLEditor_executeSQLBetweenBlankLine_tip);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    _executeBetweenBlankLine.setLayoutData(data);

    return composite;
}

From source file:org.eclipse.dltk.freemarker.internal.ui.dialogs.OpenProjectLevelConfigurationDialog.java

License:Open Source License

public void addMessage(String messageText, int messageType) {
    if (messageType == IMessageProvider.ERROR) {
        setErrorMessage(messageText);//w ww .  jav  a  2s . c  o m
    } else {
        setMessage(messageText, messageType);
    }
}

From source file:org.eclipse.dltk.freemarker.internal.ui.editor.validation.AbstractControlValidator.java

License:Open Source License

/**
 * @param status//from   w  w  w.  j  a v  a2 s  .c  o m
 * @return
 */
public static int getMessageType(IStatus status) {
    int severity = status.getSeverity();
    // Translate severity to the equivalent message provider type
    if (severity == IStatus.OK) {
        return IMessageProvider.NONE;
    } else if (severity == IStatus.ERROR) {
        return IMessageProvider.ERROR;
    } else if (severity == IStatus.WARNING) {
        return IMessageProvider.WARNING;
    } else if (severity == IStatus.INFO) {
        return IMessageProvider.INFORMATION;
    }
    // IStatus.CANCEL
    return IMessageProvider.NONE;
}

From source file:org.eclipse.dltk.freemarker.internal.ui.editor.validation.ControlValidationUtility.java

License:Open Source License

/**
 * Validate class field.//from  w  w w .  ja v  a  2s .  co  m
 * 
 * @param text
 * @param validator
 * @param project
 * @return
 */
public static boolean validateClassField(String className, IValidatorMessageHandler validator, IProject project,
        boolean required) {

    if (StringUtils.isEmpty(className)) {
        if (required) {
            validator.addMessage(FreemarkerUIPluginMessages.ControlValidationUtility_errorMsgClassRequired,
                    IMessageProvider.ERROR);
            return false;
        }
        return true;
    }

    // Check to see if the class is on the plug-in classpath
    try {
        if (project.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject javaProject = JavaCore.create(project);
            // Look for this activator in the project's classpath
            if (!FreemarkerJavaHelper.isOnClasspath(className, javaProject)) {
                validator.addMessage(FreemarkerUIPluginMessages.ControlValidationUtility_errorMsgNotOnClasspath,
                        IMessageProvider.ERROR);
                return false;
            }
        }
    } catch (CoreException ce) {
        // Ignore
    }

    return true;
}

From source file:org.eclipse.dltk.freemarker.internal.ui.editor.validation.ControlValidationUtility.java

License:Open Source License

/***
 * Validate method field provider./*from  w  w  w  .j  av  a 2  s .  co  m*/
 * 
 * @param providerType
 * @param className
 * @param methodName
 * @param validator
 * @param project
 * @param required
 * @return
 */
public static boolean validateMethodProviderField(ProviderType providerType, String className,
        String methodName, IValidatorMessageHandler validator, IProject project, boolean required) {

    // Validate Required method
    if (!validateMethodField(className, methodName, validator, project, required)) {
        return false;
    }

    // Validate existing method
    try {
        if (project.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject javaProject = JavaCore.create(project);
            IMethod method = FreemarkerJavaHelper.getMethod(className, methodName, javaProject);
            if (method == null) {
                validator.addMessage(FreemarkerUIPluginMessages.ControlValidationUtility_errorMsgMethodNotExist,
                        IMessageProvider.ERROR);
                return false;
            } else {
                // Method exists
                // TODO : test return type switch the provider type.               
                return true;
            }
        } else {
            validator.addMessage(FreemarkerUIPluginMessages.ControlValidationUtility_errorMsgNotOnClasspath,
                    IMessageProvider.ERROR);
            return false;
        }
    } catch (CoreException ce) {
        // Ignore
    }

    return true;
}

From source file:org.eclipse.dltk.freemarker.internal.ui.editor.validation.ControlValidationUtility.java

License:Open Source License

private static boolean validateMethodField(String className, String methodName,
        IValidatorMessageHandler validator, IProject project, boolean required) {
    if (StringUtils.isEmpty(methodName)) {
        if (required) {
            validator.addMessage(FreemarkerUIPluginMessages.ControlValidationUtility_errorMsgMethodRequired,
                    IMessageProvider.ERROR);
            return false;
        }//from  ww  w. j  ava2s.  c o m
        return true;
    }
    return true;
}

From source file:org.eclipse.dltk.freemarker.internal.ui.editor.validation.ControlValidationUtility.java

License:Open Source License

/**
 * Validate name config./* ww  w  .  ja  v  a  2  s. c  o m*/
 * 
 * @param name
 * @param projectSettings
 * @param providerType
 * @param checkAlreadyExist
 * @param validator
 * @return
 */
public static boolean validateNameConfigField(String name, IFreemarkerProjectSettings projectSettings,
        ProviderType providerType, boolean checkAlreadyExist, IValidatorMessageHandler validator) {
    if (StringUtils.isEmpty(name)) {
        validator.addMessage(FreemarkerUIPluginMessages.ControlValidationUtility_nameConfigRequired,
                IMessageProvider.ERROR);
        return false;

    }
    if (!checkAlreadyExist)
        return true;
    if (projectSettings.isNameConfigExist(name, providerType)) {
        validator.addMessage(FreemarkerUIPluginMessages.ControlValidationUtility_nameConfigAlreadyExist,
                IMessageProvider.ERROR);
        return false;
    }
    return true;
}

From source file:org.eclipse.e4.demo.simpleide.handlers.NewProjectDialogHandler.java

License:Open Source License

@Execute
public void openNewProjectDialog(@Named(IServiceConstants.ACTIVE_SHELL) Shell parentShell, IWorkspace workspace,
        IProgressMonitor monitor, final ServiceRegistryComponent serviceRegistry, StatusReporter reporter,
        Logger logger, final INLSLookupFactoryService nlsFactory) {

    TitleAreaDialog dialog = new TitleAreaDialog(parentShell) {
        private Text projectName;
        private TableViewer projectType;
        private Messages messages = nlsFactory.createNLSLookup(Messages.class);

        @Override// ww w  .j av  a2 s .  co  m
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }

        @Override
        protected Control createDialogArea(Composite parent) {
            Composite comp = (Composite) super.createDialogArea(parent);
            getShell().setText(messages.NewProjectDialogHandler_ShellTitle());
            setTitle(messages.NewProjectDialogHandler_Title());
            setMessage(messages.NewProjectDialogHandler_Message());

            final Image titleImage = new Image(parent.getDisplay(),
                    getClass().getClassLoader().getResourceAsStream("/icons/wizard/newprj_wiz.png"));

            setTitleImage(titleImage);

            final Image shellImg = new Image(parent.getDisplay(),
                    getClass().getClassLoader().getResourceAsStream("/icons/newprj_wiz.gif"));
            getShell().setImage(shellImg);
            getShell().addDisposeListener(new DisposeListener() {

                public void widgetDisposed(DisposeEvent e) {
                    shellImg.dispose();
                    titleImage.dispose();
                }
            });

            Composite container = new Composite(comp, SWT.NONE);
            container.setLayoutData(new GridData(GridData.FILL_BOTH));
            container.setLayout(new GridLayout(2, false));

            Label l = new Label(container, SWT.NONE);
            l.setText(messages.NewProjectDialogHandler_Name());

            projectName = new Text(container, SWT.BORDER);
            projectName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

            l = new Label(container, SWT.NONE);
            l.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
            l.setText(messages.NewProjectDialogHandler_Type());

            projectType = new TableViewer(container);
            projectType.setContentProvider(new ArrayContentProvider());
            projectType.setLabelProvider(new LabelProvider() {
                @Override
                public String getText(Object element) {
                    IProjectService el = (IProjectService) element;
                    return el.getLabel();
                }

                @Override
                public Image getImage(Object element) {
                    IProjectService el = (IProjectService) element;
                    Image img = images.get(el);
                    if (img == null) {
                        URL url;
                        InputStream in = null;
                        try {
                            url = FileLocator.find(new URL(el.getIconURI()));
                            in = url.openStream();
                            img = new Image(getShell().getDisplay(), in);
                            images.put(el, img);
                        } catch (MalformedURLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } finally {
                            if (in != null) {
                                try {
                                    in.close();
                                } catch (IOException e) {
                                }
                            }
                        }
                    }
                    return img;
                }
            });

            Vector<IProjectService> creators = serviceRegistry.getCreators();
            projectType.setInput(creators);
            if (creators.size() > 0) {
                projectType.setSelection(new StructuredSelection(creators.get(0)));
            }
            projectType.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));

            getShell().addDisposeListener(new DisposeListener() {

                public void widgetDisposed(DisposeEvent e) {
                    for (Image img : images.values()) {
                        img.dispose();
                    }
                    images.clear();
                }
            });

            return comp;
        }

        @Override
        protected void okPressed() {
            if (projectType.getSelection().isEmpty()) {
                setMessage("Please select a project type", IMessageProvider.ERROR);
                return;
            }

            if (projectName.getText().trim().length() == 0) {
                setMessage("Please enter a projectname", IMessageProvider.ERROR);
                return;
            }

            NewProjectDialogHandler.this.creator = (IProjectService) ((IStructuredSelection) projectType
                    .getSelection()).getFirstElement();
            NewProjectDialogHandler.this.projectName = projectName.getText();

            super.okPressed();
        }
    };

    if (dialog.open() == IDialogConstants.OK_ID) {
        creator.createProject(parentShell, workspace, reporter, logger, monitor, projectName);
    }
}

From source file:org.eclipse.e4.tools.ui.designer.dialogs.ElementInitializeDialog.java

License:Open Source License

/**
 * In fact, severity of status is different from the type of messages.
 *///from  www  .j a va2 s.  c  o m
protected void setMessage(IStatus status) {
    if (status == null || status.isOK()) {
        setMessage((String) null);
    } else {
        int severity = status.getSeverity();
        String message = status.getMessage();
        switch (severity) {
        case IStatus.ERROR:
            setMessage(message, IMessageProvider.ERROR);
            break;
        case IStatus.INFO:
            setMessage(message, IMessageProvider.INFORMATION);
            break;
        case IStatus.WARNING:
            setMessage(message, IMessageProvider.WARNING);
            break;
        default:
            setMessage((String) null);
            break;
        }
    }
    Button button = getButton(IDialogConstants.OK_ID);
    if (button != null && !button.isDisposed()) {
        button.setEnabled(status == null || status.getSeverity() != IStatus.ERROR);
    }
}