Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8294863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:22:39+00:00 2026-06-08T14:22:39+00:00

The way I understand how eclipse validation framework works: generate an object with a

  • 0

The way I understand how eclipse validation framework works:

  • generate an object with a factory
  • set a value for an attribute in this object
  • check validation

For example:

public class ValidateNameTest {
public static void main(String[] args) {

    ExtlibraryPackageImpl.init();
    ExtlibraryFactory factory = ExtlibraryFactory.eINSTANCE;
    Writer writer = factory.createWriter();
    // comment next line for false result in console
    writer.setName("test");
    writer.setFirstName("test");
    writer.setLastName("test");

    boolean isNull = (writer.getName() == null) ? true : false;
    System.out.println("writer name is null : " + isNull);

    boolean result = validateObject(writer);
    System.err.println("result = " + result);

    boolean result2 = validateObject2(writer);
    System.err.println("result2 = " + result2);

    boolean result3 = validateObject3(writer);
    System.err.println("result3 = " + result3);

    boolean result4 = validateObject5(writer);
    System.out.println("result4 = " + result4);
}

public static boolean validateObject(Writer writer) {
    ExtlibraryValidator validator = ExtlibraryValidator.INSTANCE;
    if (!validator.validateWriter_hasValidName(writer, null, null)) {
        return false;
    }
    return true;
}

public static boolean validateObject2(EObject eObject) {
    EValidator validator = EValidator.Registry.INSTANCE
            .getEValidator(eObject.eClass().getEPackage());
    if (validator != null) {
        if (!validator.validate(eObject, null, null)) {
            return false;
        }
    }
    return true;
}

public static boolean validateObject3(EObject eObject) {
    Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
    return diagnostic.getSeverity() == Diagnostic.OK;
}

public static boolean validateObject5(EObject eObject)
  {
    Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);

    if (diagnostic.getSeverity() == Diagnostic.ERROR || diagnostic.getSeverity() == Diagnostic.WARNING)
    {
      System.err.println(diagnostic.getMessage());
      for (Diagnostic childDiagnostic : diagnostic.getChildren())
      {
        switch (childDiagnostic.getSeverity())
        {
          case Diagnostic.ERROR:
          case Diagnostic.WARNING:
            System.err.println("\t" + childDiagnostic.getMessage());
        }
      }
      return false;
    }
    return true;
  }
}

But I want to check if a value is valid for the model before I call the setter for the attribute. Is this possible with Eclipse EMF validation framework? Can somebody give an example please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:22:41+00:00Added an answer on June 8, 2026 at 2:22 pm

    I know of one common use case where this is possible: Data binding between model and UI controls.

    When you establish the EMF data binding between your model and the user interface, you can validate user input as follows. Create an update strategy (target to model) and override the method validateBeforeSet(Object). Here is an example:

        EMFDataBindingContext ctx = new EMFDataBindingContext();
        ISWTObservableValue notesObservableValue = prop.observe(swtTextViewer);
        IEMFValueProperty notesValueProperty = EMFProperties.value(ModelPackage.Literals.THING__NOTES);
        UpdateValueStrategy targetToModel = new UpdateValueStrategy() {
    
            @Override
            public IStatus validateBeforeSet(Object value) {
                if ("".equals(value)) {
                    MessageDialog.openError(Display.getCurrent()
                            .getActiveShell(), "Error",
                            "You should supply a description");
                    return ValidationStatus
                            .error("You should supply a description");
                }
                return super.validateBeforeSet(value);
            }
    
        };
    
        ctx.bindValue(notesObservableValue,
                notesValueProperty.observe(thing), targetToModel,
                new UpdateValueStrategy());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this is definitely a n00b question but here goes. The way I understand
I am tired of working this out myself , i cannot understand the way
I am new to eclipse and java. The way I understand the directory structure
Is there a way to set Eclipse report compile errors same as javac? I
The way I understand it, we are encouraged to name Ember instances lowercase: App.mailtruck
I am migrating an app to the High-Replication datastore. The way I understand that
I understand the way Mealy state machines work - the output logic is now
The basic way that I understand Shiro's SecurityUtils.getSubject() to work is that it returns
I have been trying to understand the way ActionScript's events are implemented, but I'm
I understand that the best way to develop a free and paid version of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.