@Override
 public void onShowMetadata() {
   view.showBusyIndicator(CommonConstants.INSTANCE.Loading());
   metadataService
       .call(getMetadataSuccessCallback(), new HasBusyIndicatorDefaultErrorCallback(view))
       .getMetadata(path);
 }
  @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();
  }
  @OnStartup
  public void init(final Path path) {
    this.path = checkNotNull("path", path);

    makeMenuBar();

    view.showBusyIndicator(CommonConstants.INSTANCE.Loading());

    projectService
        .call(getModelSuccessCallback(), new HasBusyIndicatorDefaultErrorCallback(view))
        .load(path);
  }
 private void openDataObject(final DataObject dataObject) {
   final Path objectPath = getContext().getDataObjectPath(dataObject.getClassName());
   if (objectPath != null) {
     BusyPopup.showMessage(
         org.kie.workbench.common.widgets.client.resources.i18n.CommonConstants.INSTANCE
             .Loading());
     modelerService
         .call(
             new RemoteCallback<Boolean>() {
               @Override
               public void callback(Boolean exists) {
                 BusyPopup.close();
                 if (Boolean.TRUE.equals(exists)) {
                   placeManager.goTo(new PathPlaceRequest(objectPath));
                 } else {
                   YesNoCancelPopup yesNoCancelPopup =
                       YesNoCancelPopup.newYesNoCancelPopup(
                           CommonConstants.INSTANCE.Warning(),
                           Constants.INSTANCE.objectBrowser_message_file_not_exists_or_renamed(
                               objectPath.toURI()),
                           new Command() {
                             @Override
                             public void execute() {
                               // do nothing.
                             }
                           },
                           CommonConstants.INSTANCE.Close(),
                           ButtonType.WARNING,
                           null,
                           null,
                           null,
                           null,
                           null,
                           null);
                   yesNoCancelPopup.setClosable(false);
                   yesNoCancelPopup.show();
                 }
               }
             },
             new DataModelerErrorCallback(
                 CommonConstants.INSTANCE.ExceptionNoSuchFile0(objectPath.toURI())))
         .exists(objectPath);
   }
 }
  @Override
  public void activeFolderItemSelected(final FolderItem item) {
    if (Utils.hasFolderItemChanged(item, activeFolderItem)) {
      activeFolderItem = item;
      fireContextChangeEvent();

      // Show busy popup. Once Items are loaded it is closed
      getView().showBusyIndicator(CommonConstants.INSTANCE.Loading());
      explorerService
          .call(
              new RemoteCallback<FolderListing>() {
                @Override
                public void callback(final FolderListing folderListing) {
                  loadContent(folderListing);
                  getView().setItems(folderListing);
                  getView().hideBusyIndicator();
                }
              },
              new HasBusyIndicatorDefaultErrorCallback(getView()))
          .getFolderListing(
              activeOrganizationalUnit, activeRepository, activeProject, item, getActiveOptions());
    }
  }
  private void doInitialiseViewForActiveContext(
      final OrganizationalUnit organizationalUnit,
      final Repository repository,
      final Project project,
      final Package pkg,
      final FolderItem folderItem,
      final boolean showLoadingIndicator) {

    if (showLoadingIndicator) {
      getView().showBusyIndicator(CommonConstants.INSTANCE.Loading());
    }

    explorerService
        .call(
            new RemoteCallback<ProjectExplorerContent>() {
              @Override
              public void callback(final ProjectExplorerContent content) {

                boolean signalChange = false;
                boolean buildSelectedProject = false;

                if (Utils.hasOrganizationalUnitChanged(
                    content.getOrganizationalUnit(), activeOrganizationalUnit)) {
                  signalChange = true;
                  activeOrganizationalUnit = content.getOrganizationalUnit();
                  getView().getExplorer().clear();
                }
                if (Utils.hasRepositoryChanged(content.getRepository(), activeRepository)) {
                  signalChange = true;
                  activeRepository = content.getRepository();
                  getView().getExplorer().clear();
                }
                if (Utils.hasProjectChanged(content.getProject(), activeProject)) {
                  signalChange = true;
                  buildSelectedProject = true;
                  activeProject = content.getProject();
                  getView().getExplorer().clear();
                }
                if (Utils.hasFolderItemChanged(
                    content.getFolderListing().getItem(), activeFolderItem)) {
                  signalChange = true;
                  activeFolderItem = content.getFolderListing().getItem();
                  if (activeFolderItem != null
                      && activeFolderItem.getItem() != null
                      && activeFolderItem.getItem() instanceof Package) {
                    activePackage = (Package) activeFolderItem.getItem();
                  } else if (activeFolderItem == null || activeFolderItem.getItem() == null) {
                    activePackage = null;
                  }
                }

                if (signalChange) {
                  fireContextChangeEvent();
                }

                if (buildSelectedProject) {
                  buildProject(activeProject);
                }

                activeContent = content.getFolderListing();

                getView()
                    .setContent(
                        content.getOrganizationalUnits(),
                        activeOrganizationalUnit,
                        content.getRepositories(),
                        activeRepository,
                        content.getProjects(),
                        activeProject,
                        content.getFolderListing());

                getView().hideBusyIndicator();
              }
            },
            new HasBusyIndicatorDefaultErrorCallback(getView()))
        .getContent(organizationalUnit, repository, project, pkg, folderItem, getActiveOptions());
  }
 @Override
 public void showLoadingIndicator() {
   showBusyIndicator(CommonConstants.INSTANCE.Loading());
 }
public class FactTypeBrowserWidget extends Composite implements UberView<DRLEditorPresenter> {

  private static final String LAZY_LOAD = CommonConstants.INSTANCE.Loading();

  private DRLEditorPresenter presenter;

  private final Tree tree;

  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);
  }

  @Override
  public void init(final DRLEditorPresenter presenter) {
    this.presenter = presenter;
  }

  public void setFullyQualifiedClassNames(final List<String> fullyQualifiedClassNames) {
    if (tree.getItem(0) != null) {
      tree.clear();
    }

    if (fullyQualifiedClassNames != null) {
      for (String type : fullyQualifiedClassNames) {
        final TreeItem it = new TreeItem();
        it.setHTML(
            AbstractImagePrototype.create(DRLTextEditorResources.INSTANCE.images().classImage())
                    .getHTML()
                + "<small>"
                + type
                + "</small>");
        it.setUserObject(new ClassUserObject(type + "( )", type));
        tree.addItem(it);
        it.addItem(Util.toSafeHtml(LAZY_LOAD));
      }
    }
  }

  private boolean needsLoading(final TreeItem item) {
    return item.getChildCount() == 1 && LAZY_LOAD.equals(item.getChild(0).getText());
  }

  public static interface ClickEvent {

    public void selected(String text);
  }

  private static class ClassUserObject {

    private String textToInsert;
    private String fullyQualifiedClassName;

    ClassUserObject(final String textToInsert, final String fullyQualifiedClassName) {
      this.textToInsert = textToInsert;
      this.fullyQualifiedClassName = fullyQualifiedClassName;
    }
  }
}
 private void reload() {
   changeTitleNotification.fire(new ChangeTitleWidgetEvent(place, getTitle(), null));
   view.showBusyIndicator(CommonConstants.INSTANCE.Loading());
   loadContent();
 }
  @OnStartup
  public void onStartup(final ObservablePath path, final PlaceRequest place) {
    this.path = path;
    this.place = place;
    this.isReadOnly = place.getParameter("readOnly", null) == null ? false : true;
    this.version = place.getParameter("version", null);

    this.path.onRename(
        new Command() {
          @Override
          public void execute() {
            changeTitleNotification.fire(new ChangeTitleWidgetEvent(place, getTitle(), null));
          }
        });
    this.path.onConcurrentUpdate(
        new ParameterizedCommand<ObservablePath.OnConcurrentUpdateEvent>() {
          @Override
          public void execute(final ObservablePath.OnConcurrentUpdateEvent eventInfo) {
            concurrentUpdateSessionInfo = eventInfo;
          }
        });

    this.path.onConcurrentRename(
        new ParameterizedCommand<ObservablePath.OnConcurrentRenameEvent>() {
          @Override
          public void execute(final ObservablePath.OnConcurrentRenameEvent info) {
            newConcurrentRename(
                    info.getSource(),
                    info.getTarget(),
                    info.getIdentity(),
                    new Command() {
                      @Override
                      public void execute() {
                        disableMenus();
                      }
                    },
                    new Command() {
                      @Override
                      public void execute() {
                        reload();
                      }
                    })
                .show();
          }
        });

    this.path.onConcurrentDelete(
        new ParameterizedCommand<ObservablePath.OnConcurrentDelete>() {
          @Override
          public void execute(final ObservablePath.OnConcurrentDelete info) {
            newConcurrentDelete(
                    info.getPath(),
                    info.getIdentity(),
                    new Command() {
                      @Override
                      public void execute() {
                        disableMenus();
                      }
                    },
                    new Command() {
                      @Override
                      public void execute() {
                        placeManager.closePlace(place);
                      }
                    })
                .show();
          }
        });

    makeMenuBar();

    view.showBusyIndicator(CommonConstants.INSTANCE.Loading());

    multiPage.addWidget(view, DSLTextEditorConstants.INSTANCE.DSL());

    multiPage.addPage(
        new Page(metadataWidget, CommonConstants.INSTANCE.MetadataTabTitle()) {
          @Override
          public void onFocus() {
            metadataWidget.showBusyIndicator(CommonConstants.INSTANCE.Loading());
            metadataService
                .call(
                    new MetadataSuccessCallback(metadataWidget, isReadOnly),
                    new HasBusyIndicatorDefaultErrorCallback(metadataWidget))
                .getMetadata(path);
          }

          @Override
          public void onLostFocus() {
            // Nothing to do
          }
        });

    loadContent();
  }