Java + Reflection + @Annotations

I will to show a simple example how to list all methods that are using a given @annotation.

We will use the lib: http://code.google.com/p/reflections/

Reflections reflection = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("com.myapplication.mypackage"))
.setScanners(new MethodAnnotationsScanner()));

Set methods = reflection.getMethodsAnnotatedWith(MyAnnotation.class);

That lib is really powerful and you get to do a lot of things with less code.

Take a look at its documentation and fill what you can to do.

Dropdown Component: Select2 JQuery + Angular JS + Repeater

Particulary the Select2 is a great component dropdown selection.

I have created a directive to work together with Select2 it in my projects with Angular JS and I want to share it.

Below is the directive code.

If you want to se a example running I have made the following example.

http://runnable.com/VQsds4gTWxdNH63n/componente-select2-jquery-%2B-angular-js-%2B-repeater-for-javascript

index.html

<html>
  <head>
    <script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>    
    <script src="select2.js"></script>    
    
    <link rel="stylesheet" href="runnable.css" />
    <link rel="stylesheet" href="select2.css" />
  </head>
  <body ng-app="app">
    <h1>Componente Select2 JQuery + Angular JS + Repeater</h1>
    
    <div ng-controller="veiculoController">
        <table class="table table-bordered">
          <thead>
            <tr>
              <th width="60%">Nome Veiculo</th>
              <th>Tipo de pneu</th>
            </tr>
          </thead>
          <tbody>
            <tr ng-repeat="veiculo in listaVeiculos">
              <td>{{veiculo.nome}}</td>
              <td style="width: 200px">
                <div drop-down-auto-complete="listaTipoPenu" style="width: 200px"
                   drop-down-auto-complete-property="veiculo.idTipoPneu">
                </div>
              </td>
            </tr>
          </tbody>
        </table>
    <div>
    
  </body>
</html>
<script src="script.js"></script>

script.js

var app = angular.module("app", []);
app.directive('dropDownAutoComplete',[
  function() {
    return {
      link: function(scope, element, attr) {
          var dataList = scope.$parent[attr.dropDownAutoComplete];
          var currentObject = scope[attr.dropDownAutoCompleteProperty.split(".")[0]];
          var propertyChange = attr.dropDownAutoCompleteProperty.split(".")[1];
          $(element[0]).select2({
              data: dataList
            });
          $(element[0]).on("change", function (e) {
            currentObject[propertyChange] = $(element[0]).val();
          });
          for(var x = 0; x < dataList.length; x++){
              if (dataList[x].id == currentObject[propertyChange]){
                $(element[0]).select2('data', dataList[x]);
              }
          }
          }
        };
   }
]);
app.controller('veiculoController', function($scope) {
  $scope.listaVeiculos = [{id: 1, nome: "Fusca", idTipoPneu: 3},
                          {id: 2, nome: "Hilux", idTipoPneu: 2},
                          {id: 3, nome: "Saveiro", idTipoPneu: 1}];
  $scope.listaTipoPenu = [{id: 1, text: "ARO 15"}, {id: 2, text: "ARO 16"}, {id: 3, text: "ARO 17"}];
});