Esempio n. 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));
 }
Esempio n. 2
0
  private void rebuildIcons() {

    if (mode != Mode.LAUNCHERS) {
      return;
    }

    context.clearLoadQueue();
    flinger.getContent().getChildren().clear();

    // Type lastType = null;
    for (Map.Entry<ResourceGroupKey, ResourceGroupList> ig : icons.entrySet()) {
      Type type = ig.getKey().getType();
      // if (lastType != null && type != lastType) {
      // shortcuts
      // .getChildren()
      // .add(new Separator(
      // cfg.topProperty().get()
      // || cfg.bottomProperty().get() ? Orientation.VERTICAL
      // : Orientation.HORIZONTAL));
      // }
      switch (type) {
        case SSO:
          if (!ssoResources.isSelected()) continue;
          break;
        case BROWSER:
          if (!browserResources.isSelected()) continue;
          break;
        case FILE:
          if (!fileResources.isSelected()) continue;
          break;
        case NETWORK:
          if (!networkResources.isSelected()) continue;
          break;
        default:
          break;
      }

      List<ResourceGroupList> groupsAdded = new ArrayList<ResourceGroupList>();
      for (ResourceItem item : ig.getValue().getItems()) {
        ResourceGroupKey gk =
            new ResourceGroupKey(item.getResource().getType(), item.getResource().getGroup());
        ResourceGroupList groups = icons.get(gk);
        if (groups == null || groups.getItems().size() < 2) {
          flinger
              .getContent()
              .getChildren()
              .add(
                  new IconButton(resources, item, context, ig.getValue()) {

                    @Override
                    protected void onFinishLaunch() {
                      super.onFinishLaunch();

                      if (launchWait != null
                          && launchWait.getStatus() == javafx.animation.Animation.Status.RUNNING)
                        launchWait.stop();

                      launchWait = new Timeline(new KeyFrame(Duration.millis(Dock.LAUNCH_WAIT)));
                      launchWait.play();
                    }
                  });
        } else {
          if (!groupsAdded.contains(groups)) {
            flinger
                .getContent()
                .getChildren()
                .add(
                    new GroupButton(resources, context, groups) {

                      @Override
                      protected void onFinishLaunch() {
                        super.onFinishLaunch();

                        if (launchWait != null
                            && launchWait.getStatus() == javafx.animation.Animation.Status.RUNNING)
                          launchWait.stop();

                        launchWait = new Timeline(new KeyFrame(Duration.millis(Dock.LAUNCH_WAIT)));
                        launchWait.play();
                      }
                    });
            groupsAdded.add(groups);
          }
        }
      }

      // lastType = type;
    }
  }
Esempio n. 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;
        }
    }
  }