Пример #1
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));
 }
Пример #2
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;
        }
    }
  }