Example #1
0
  @PostConstruct
  public void init() {

    final ClickEvent ce =
        new ClickEvent() {
          public void selected(String text) {
            drlEditor.insertAtCursor(text);
          }
        };

    this.factTypeBrowser = new FactTypeBrowserWidget(ce);
    this.dslConditionsBrowser =
        new DSLSentenceBrowserWidget(
            ce,
            DRLTextEditorConstants.INSTANCE.showDSLConditions(),
            DRLTextEditorConstants.INSTANCE.dslConditions());
    this.dslActionsBrowser =
        new DSLSentenceBrowserWidget(
            ce,
            DRLTextEditorConstants.INSTANCE.showDSLActions(),
            DRLTextEditorConstants.INSTANCE.dslActions());
    initWidget(uiBinder.createAndBindUi(this));

    columnBrowsers.add(factTypeBrowser);
    columnBrowsers.add(dslConditionsBrowser);
    columnBrowsers.add(dslActionsBrowser);
  }
  public FactTypeBrowserWidget(final ClickEvent ev) {
    this.tree = new Tree();

    final VerticalPanel panel = new VerticalPanel();
    final HorizontalPanel hpFactsAndHide = new HorizontalPanel();
    final HorizontalPanel hpShow = new HorizontalPanel();

    hpShow.add(
        new ClickableLabel(
            DRLTextEditorConstants.INSTANCE.ShowFactTypes(),
            new ClickHandler() {
              public void onClick(com.google.gwt.event.dom.client.ClickEvent event) {
                hpShow.setVisible(false);
                hpFactsAndHide.setVisible(true);
                tree.setVisible(true);
              }
            }));
    panel.add(hpShow);

    hpFactsAndHide.add(new SmallLabel(DRLTextEditorConstants.INSTANCE.FactTypes()));
    hpFactsAndHide.add(
        new ClickableLabel(
            DRLTextEditorConstants.INSTANCE.hide(),
            new ClickHandler() {
              public void onClick(com.google.gwt.event.dom.client.ClickEvent event) {
                hpShow.setVisible(true);
                hpFactsAndHide.setVisible(false);
                tree.setVisible(false);
              }
            }));
    panel.add(hpFactsAndHide);

    panel.add(tree);

    tree.setStyleName(DRLTextEditorResources.INSTANCE.CSS().categoryExplorerTree());
    tree.addSelectionHandler(
        new SelectionHandler<TreeItem>() {
          public void onSelection(SelectionEvent<TreeItem> event) {
            Object o = event.getSelectedItem().getUserObject();
            if (o instanceof ClassUserObject) {
              ev.selected(((ClassUserObject) o).textToInsert);
            } else if (o instanceof String) {
              ev.selected((String) o);
            }
          }
        });

    tree.addOpenHandler(
        new OpenHandler<TreeItem>() {
          @Override
          public void onOpen(final OpenEvent<TreeItem> event) {
            final TreeItem item = event.getTarget();
            if (needsLoading(item)) {
              final Object userObject = event.getTarget().getUserObject();
              presenter.loadClassFields(
                  ((ClassUserObject) userObject).fullyQualifiedClassName,
                  new Callback<List<String>>() {
                    @Override
                    public void callback(final List<String> fields) {
                      item.getChild(0).remove();
                      if (fields != null) {
                        for (String field : fields) {
                          final TreeItem fi = new TreeItem();
                          fi.setHTML(
                              AbstractImagePrototype.create(
                                          DRLTextEditorResources.INSTANCE.images().fieldImage())
                                      .getHTML()
                                  + "<small>"
                                  + field
                                  + "</small>");
                          fi.setUserObject(field);
                          item.addItem(fi);
                        }
                      }
                    }
                  });
            }
          }
        });

    tree.setVisible(false);
    hpFactsAndHide.setVisible(false);
    hpShow.setVisible(true);

    initWidget(panel);
  }