@PostConstruct
  public void init() {
    initWidget(uiBinder.createAndBindUi(this));

    accordion.setId(DOM.createUniqueId());
    formAccordionHeader.setDataParent(accordion.getId());
    formAccordionHeader.setDataTargetWidget(formAccordionCollapse);
    resultAccordionHeader.setDataParent(accordion.getId());
    resultAccordionHeader.setDataTargetWidget(resultAccordionCollapse);

    // TODO {porcelli} due a bug on bootstrap we can't use custom date formats
    createdAfter.setFormat(ApplicationPreferences.getDroolsDateFormat());
    createdBefore.setFormat(ApplicationPreferences.getDroolsDateFormat());
    lastModifiedAfter.setFormat(ApplicationPreferences.getDroolsDateFormat());
    lastModifiedBefore.setFormat(ApplicationPreferences.getDroolsDateFormat());

    formGroup.setStyleName(null);

    formatTypeahead.setDatasets(
        new StringDataset(
            new ArrayList<String>() {
              {
                for (final ClientResourceType resourceType :
                    clientTypeRegistry.getRegisteredTypes()) {
                  add(resourceType.getShortName());
                }
              }
            }));
  }
  @Before
  public void setup() {
    ApplicationPreferences.setUp(new HashMap<String, String>());

    // The BuildOptions widget is manipulated in the Presenter so we need some nasty mocking
    when(view.getBuildOptionsButton()).thenReturn(buildOptions);
    when(buildOptions.getWidget(eq(0))).thenReturn(buildOptionsButton1);
    when(buildOptions.getWidget(eq(1))).thenReturn(buildOptionsMenu);
    when(buildOptionsMenu.getWidget(eq(0))).thenReturn(buildOptionsMenuButton1);
    when(buildOptionsMenu.getWidget(eq(1))).thenReturn(buildOptionsMenuButton1);

    constructProjectScreenPresenter(
        new CallerMock<BuildService>(buildService),
        new CallerMock<AssetManagementService>(assetManagementServiceMock));

    // Mock ProjectScreenService
    final POM pom = new POM(new GAV("groupId", "artifactId", "version"));
    model = new ProjectScreenModel();
    model.setPOM(pom);
    when(projectScreenService.load(any(org.uberfire.backend.vfs.Path.class))).thenReturn(model);

    // Mock BuildService
    when(buildService.buildAndDeploy(any(Project.class))).thenReturn(new BuildResults());

    // Mock LockManager initialisation
    final Path path = mock(Path.class);
    final Metadata pomMetadata = mock(Metadata.class);
    model.setPOMMetaData(pomMetadata);
    when(pomMetadata.getPath()).thenReturn(path);
    final Metadata kmoduleMetadata = mock(Metadata.class);
    model.setKModuleMetaData(kmoduleMetadata);
    when(kmoduleMetadata.getPath()).thenReturn(path);
    final Metadata importsMetadata = mock(Metadata.class);
    model.setProjectImportsMetaData(importsMetadata);
    when(importsMetadata.getPath()).thenReturn(path);

    // Mock ProjectContext
    final Repository repository = mock(Repository.class);
    when(context.getActiveRepository()).thenReturn(repository);
    when(repository.getAlias()).thenReturn("repository");
    when(repository.getCurrentBranch()).thenReturn("master");

    final Project project = mock(Project.class);
    when(project.getProjectName()).thenReturn("project");

    when(context.getActiveProject()).thenReturn(project);

    // Trigger initialisation of view. Unfortunately this is the only way to initialise a Project in
    // the Presenter
    context.onProjectContextChanged(
        new ProjectContextChangeEvent(mock(OrganizationalUnit.class), repository, project));

    verify(view, times(1)).showBusyIndicator(eq(CommonConstants.INSTANCE.Loading()));
    verify(view, times(1)).hideBusyIndicator();
  }
  @Before
  public void setup() {
    ApplicationPreferences.setUp(new HashMap<String, String>());

    mockBuildOptions();

    final ProjectScreenModel model = new ProjectScreenModel();
    model.setPOMMetaData(new Metadata());
    model.setKModuleMetaData(new Metadata());
    model.setProjectImportsMetaData(new Metadata());
    mockProjectScreenService(model);

    mockProjectContext(new POM(), repository, project, pomPath);

    constructProjectScreenPresenter(
        project,
        new CallerMock<BuildService>(buildService),
        new CallerMock<SpecManagementService>(specManagementServiceMock));
    presenter.setupPathToPomXML();
  }
  @Before
  public void setUp() throws Exception {
    Map<String, String> preferences = new HashMap<String, String>();
    preferences.put(ApplicationPreferences.DATE_FORMAT, "dd-MMM-yyyy");
    ApplicationPreferences.setUp(preferences);

    when(oracle.getFieldType("LoanApplication", "amount"))
        .thenReturn(DataType.TYPE_NUMERIC_INTEGER);
    when(oracle.getFieldType("LoanApplication", "lengthYears"))
        .thenReturn(DataType.TYPE_NUMERIC_INTEGER);
    when(oracle.getFieldType("LoanApplication", "deposit"))
        .thenReturn(DataType.TYPE_NUMERIC_INTEGER);
    when(oracle.getFieldType("LoanApplication", "approved")).thenReturn(DataType.TYPE_BOOLEAN);
    when(oracle.getFieldType("LoanApplication", "insuranceCost"))
        .thenReturn(DataType.TYPE_NUMERIC_INTEGER);
    when(oracle.getFieldType("LoanApplication", "approvedRate"))
        .thenReturn(DataType.TYPE_NUMERIC_INTEGER);
    when(oracle.getFieldType("IncomeSource", "type")).thenReturn(DataType.TYPE_STRING);
    when(oracle.getFieldType("Person", "name")).thenReturn(DataType.TYPE_STRING);
  }
/** Base class for Pop-ups used by RuleModeller */
public abstract class AbstractRuleModellerSelectorPopup extends KieBaseModal {

  protected static final String SECTION_SEPARATOR = "..................";

  protected int MIN_WIDTH = 500;
  protected int MIN_HEIGHT = 200;

  protected boolean onlyShowDSLStatements =
      ApplicationPreferences.getBooleanPref("rule-modeller-onlyShowDSLStatements");

  protected final RuleModel model;
  protected final RuleModeller ruleModeller;
  protected final AsyncPackageDataModelOracle oracle;
  protected final Map<String, Command> cmds = new HashMap<String, Command>();
  protected Integer position;

  protected final SimplePanel choicesPanel = new SimplePanel();
  protected final FormStyleLayout layoutPanel = new FormStyleLayout();
  protected final ListBox positionCbo = new ListBox();
  protected ListBox choices;

  public AbstractRuleModellerSelectorPopup(
      final RuleModel model,
      final RuleModeller ruleModeller,
      final Integer position,
      final AsyncPackageDataModelOracle oracle) {
    this.model = model;
    this.position = position;
    this.ruleModeller = ruleModeller;
    this.oracle = oracle;
    this.setTitle(getPopupTitle());
    this.add(getContent());
  }

  /**
   * Get a title for the pop-up
   *
   * @return
   */
  protected abstract String getPopupTitle();

  /**
   * Get content for the pop-up
   *
   * @return
   */
  protected abstract Widget getContent();

  /** Executed when a selection has been made. Refreshes the underlying RuleModeller widget */
  protected void selectSomething() {
    int sel = choices.getSelectedIndex();
    if (sel != -1) {
      Command cmd = cmds.get(choices.getValue(sel));
      if (cmd != null) {
        cmd.execute();
        ruleModeller.refreshWidget();
      }
    }
  }

  /**
   * Width of pop-up, 1/4 of the client width or MIN_WIDTH
   *
   * @return
   */
  protected int getChoicesWidth() {
    int w = Window.getClientWidth() / 4;
    if (w < MIN_WIDTH) {
      w = MIN_WIDTH;
    }
    return w;
  }

  /**
   * Height of pop-up, 1/2 of the client height or MIN_HEIGHT
   *
   * @return
   */
  protected int getChoicesHeight() {
    int h = Window.getClientHeight() / 2;
    if (h < MIN_HEIGHT) {
      h = MIN_HEIGHT;
    }
    return h;
  }
}