CDI Properties add-on


CDI Properties
contains individual annotations for each Vaadin core component that allow you to define a set of properties right above the injection point.

…so instead of:

TextField textField = new TextField("Name");
textField.setMaxLength(15);
textField.setNullRepresentation("");
textField.setWidth("100%");

…you can:

@Inject
@TextFieldProperties(caption = "Name", maxLength = 15, nullRepresentation = "", width = "100%")
private TextField textField;

Use properties “captionKey” and “labelValueKey” to assign text values provided by your own TextBundle bean. Fire a @TextBundleUpdated event to utilize the built-in i18n functionality allowing you to change your applications language run-time.


Link to an example project

[/b]The add-on can only be used in
Vaadin CDI
enabled projects.
[/b]

attached(or not) is a little utility to help porting a project from cdi-utils to the new cdi-properties
to use:

for f in $( grep -rl "@Preconfigured" $( find src/ -iname "*.java" | grep -v ".svn" ) ) ; do
perl -f preconfigrured.pl $f -inline ;
done

remove the -inline pramater to print the result to stdout instead of modifing the source file.

preconfigrured.pl:

#! /opt/local/bin/perl
use strict;
use warnings;


sub checkImport {
    my $className = shift;
    my @source =@{$_[0]
};
    foreach(@source) {
        if ( $_ =~ m/^\s*import\s+org[.]
vaadin[.]
addon[.]
cdiproperties[.]
annotation[.]
${className}Properties;/ ) {
           return 1;
        }
    }
    return 0;
}

sub isAnnotation {
    my $line = shift;
    return ($line =~ m/^\s*\@([A-Za-z0-9_]
)+/ );
}

sub getLastImport {
    my @source =@{$_[0]
};
    my $lastimportLine = 0;
    for(my $n = 0; $n < @source; $n++) {
        if ( $source[$n]
 =~ m/^import / ) {
            $lastimportLine = $n;
        }
    }
    return $lastimportLine +1;
}


sub getClassName {
    my $line = shift;
    while ($line =~ /([A-Z]
[A-Za-z0-9]
+)/) {
#          print "Matched $1\n\tfrom: $line\n";
          return $1;
    }
    print "NO className Matched found !!!!!\nfrom: $line\n";
    exit(0);
}


sub reWritePreeconfigured {
    my @source =@{$_[0]
};
    my @imports = ();
    for(my $n = 0; $n < @source; $n++) {
        my $oldLine = $source[$n]
;
        if($source[$n]
 =~ m/\@Preconfigured\s*/) {
            # Find the first none annotation line , this will be the declation we need to find
            my $declarationLine = $n+1;
            while(isAnnotation($source[$declarationLine]
)) {
                $declarationLine++;
            }            
            my $className = getClassName($source[$declarationLine]
);
            if (!checkImport($className, \@source)) {
                push @imports, "import org.vaadin.addon.cdiproperties.annotation.".$className."Properties;";
            }
            $source[$n]
 =~ s/\@Preconfigured/\@${className}Properties/;
        }
    }
    # Check if we need to insert some imports
    if (scalar(@imports) > 0) {
       splice(@source, getLastImport(\@source), 0, @imports);
    }
    return @source;
}

my ($filename , $param) = @ARGV;
my @source;
open(my $fh, "<", $filename)
    or die "Failed to open file: $!\n";
while(<$fh>) {
    chomp;
    push @source, $_;
}
close $fh;

my @newsource = reWritePreeconfigured(\@source);

if ( $param =~ /-inline/ ) {
    open(DQ, '>',   $filename) or die "Failed to open file for writing: $!\n";

    foreach(@newsource) {
        print DQ $_."\n";
    }
    close(DQ);
} else {
    foreach(@newsource) {
        print $_."\n";
    }
}

Awesome! Thanks Petrus.

I made i small patch to handle SplitPanel splitPosition,minSplitPosition,maxSplitPosition like the width and height properties, ( but I cannot seems to attach them )

You have somewhere where I can send the patch ?

Great. Well you could use Dropbox or such and send me the public link to the patch file. If you prefer an email attachment that’s fine. My email can be found
here

ziped the patch…

Not sure why the original patch would not attach ( Tori simply says soemthing went wrong with the database )…

With this patch splitposition can be managed like the width and height properties.
examples:

@VerticalSplitPanelProperties(splitPosition = "30px",splitPositionReverse = true)
@VerticalSplitPanelProperties(splitPositionValue = 30 , splitPositionUnits = Unit.PIXELS)

13270.zip (2.12 KB)