Exemple #1
0
  private void rebuildResources() {

    serviceResources.clear();
    icons.clear();
    log.info("Rebuilding resources");
    if (context.getBridge().isConnected() && !context.getBridge().isServiceUpdating()) {
      ResourceService resourceService = context.getBridge().getResourceService();

      try {
        serviceResources.addAll(resourceService.getServiceResources());
      } catch (Exception e) {
        log.error("Failed to get service resources.", e);
      }

      try {
        for (ResourceRealm resourceRealm : resourceService.getResourceRealms()) {
          for (Resource r : resourceRealm.getResources()) {
            if (r.getType() != Type.ENDPOINT) {
              rebuildResourceIcon(resourceRealm, r);
            }
          }
        }
      } catch (Exception e) {
        log.error("Failed to get resources.", e);
      }
      log.info(String.format("Found %d top level launchers", icons.size()));
    }
  }
Exemple #2
0
 private void rebuildResourceIcon(ResourceRealm resourceRealm, Resource r) {
   ResourceGroupKey igk = new ResourceGroupKey(r.getType(), r.getGroup());
   ResourceGroupList ig = icons.get(igk);
   if (ig == null) {
     ig = new ResourceGroupList(resourceRealm, igk, r.getGroupIcon());
     icons.put(igk, ig);
   }
   ig.getItems().add(new ResourceItem(r, resourceRealm));
 }
Exemple #3
0
  @Override
  public void updateResource(ResourceUpdateType type, Resource resource) {
    switch (type) {
      case CREATE:
        {
          rebuildResourceIcon(resource.getRealm(), resource);
          rebuildIcons();

          Action[] actions = new Action[0];

          // Find the button so we can launch on clicking the notify
          ResourceGroupKey key = new ResourceGroupKey(resource.getType(), resource.getGroup());
          ResourceGroupList list = icons.get(key);
          if (list != null) {
            ResourceItem rit = list.getItemForResource(resource);
            if (rit != null) {
              LauncherButton lb = getButtonForResourceItem(rit);
              if (lb != null) {
                actions =
                    new Action[] {
                      new Action(
                          resources.getString("resources.launch"),
                          new Consumer<ActionEvent>() {
                            @Override
                            public void accept(ActionEvent t) {
                              lb.launch();
                            }
                          })
                    };
              }
            }
          }

          notify(
              MessageFormat.format(resources.getString("resources.created"), resource.getName()),
              GUICallback.NOTIFY_INFO,
              actions);
          break;
        }
      case DELETE:
        {
          ResourceGroupKey key = new ResourceGroupKey(resource.getType(), resource.getIcon());
          ResourceGroupList list = icons.get(key);
          if (list != null) {
            ResourceItem rit = list.getItemForResource(resource);
            if (rit != null) {
              list.getItems().remove(rit);
              rebuildIcons();
              notify(
                  MessageFormat.format(
                      resources.getString("resources.deleted"), resource.getName()),
                  GUICallback.NOTIFY_INFO);
              break;
            }
          }
          break;
        }
      default:
        {
          ResourceGroupKey key = new ResourceGroupKey(resource.getType(), resource.getGroup());
          ResourceGroupList list = icons.get(key);
          if (list != null) {
            ResourceItem rit = list.getItemForResource(resource);
            if (rit != null) {
              rit.setResource(resource);
              rebuildIcons();
              notify(
                  MessageFormat.format(
                      resources.getString("resources.updated"), resource.getName()),
                  GUICallback.NOTIFY_INFO);
              break;
            } else {
              log.warn(
                  String.format(
                      "Could not find icon in icon group for resource %s (%s)",
                      resource.getUid(), resource.getName()));
            }
          } else {
            log.warn(
                String.format(
                    "Could not find icon group for resource %s (%s)",
                    resource.getUid(), resource.getName()));
          }
          break;
        }
    }
  }