예제 #1
0
 @Override
 public String toString() {
   return "TextEditActivity("
       + this.offset
       + ",new:'"
       + Utils.escapeForLogging(StringUtils.abbreviate(this.text, 150))
       + "',old:'"
       + Utils.escapeForLogging(StringUtils.abbreviate(this.replacedText, 150))
       + "',path:"
       + this.path.toString()
       + ",src:"
       + this.source
       + ")";
 }
예제 #2
0
  /**
   * Shares given projects with given buddies.<br>
   * Does nothing if a {@link SarosSession} is already running.
   *
   * @param sarosSessionManager
   * @param projects
   * @param buddies
   * @nonBlocking
   */
  public static void shareProjectWith(
      final SarosSessionManager sarosSessionManager,
      final List<IProject> projects,
      final List<JID> buddies) {

    Utils.runSafeAsync(
        log,
        new Runnable() {
          public void run() {
            if (sarosSessionManager.getSarosSession() == null) {
              try {
                sarosSessionManager.startSession(projects, null);
              } catch (final XMPPException e) {
                Utils.runSafeSWTSync(
                    log,
                    new Runnable() {
                      public void run() {
                        MessageDialog.openError(
                            null, "Offline", getShareProjectFailureMessage(projects));
                        log.warn("Start share project failed", e);
                      }
                    });
              }

              addBuddiesToSarosSession(sarosSessionManager, buddies);
            } else {
              log.warn(
                  "Tried to start "
                      + SarosSession.class.getSimpleName()
                      + " although one is already running");
            }
          }
        });
  }
예제 #3
0
  /**
   * Remove the given users from the session.<br>
   * Does nothing if no {@link SarosSession} is running.
   *
   * @param sarosSessionManager the manager of the saros session
   * @param users the list of users to remove
   * @nonBlocking
   */
  public static void removeUsersFromSarosSession(
      final SarosSessionManager sarosSessionManager, final List<User> users) {

    // run the following code in a safe asynchronous utility command
    Utils.runSafeAsync(
        log,
        new Runnable() {
          // in the run method of the utility command, do the following:
          public void run() {
            // get the current sarosSession
            final ISarosSession session = sarosSessionManager.getSarosSession();

            // if the sarosSession is not null
            if (session != null) {
              // run the following code in a safe asynchronous utility
              // command
              Utils.runSafeAsync(
                  log,
                  new Runnable() {
                    // in the run method of the utility command, do the
                    // following:
                    public void run() {

                      // get the current saros session's parcipants, store
                      // it into a list of users
                      Collection<User> participants = session.getParticipants();
                      // create a new list of users to remove
                      List<User> toRemove = new ArrayList<User>();
                      // for all users that exist in the current saros
                      // session and are in the
                      // list of users passed into this method
                      for (User u : participants) {
                        // add those users to the list of users to
                        // remove
                        if (users.contains(u)) {
                          toRemove.add(u);
                        }
                      }

                      // if that list of users to remove has at least one
                      // user in it uninvite that list of users
                      if (toRemove.size() > 0) {
                        for (User u : toRemove) {
                          sarosSessionManager.uninvite(u);
                        }
                      }
                    }
                  });

            } else {
              // else (if the sarosSession is null)
              // log a warning about trying to remove a buddy from the
              // saros session
              log.warn("Tried to remove a buddy from a null saros session.");
            }
          }
        });
  } // end of removeUsersFromSarosSession method
예제 #4
0
  /**
   * Adds the given buddies to the session.<br>
   * Does nothing if no {@link SarosSession} is running.
   *
   * @param sarosSessionManager
   * @param buddies
   * @nonBlocking
   */
  public static void addBuddiesToSarosSession(
      final SarosSessionManager sarosSessionManager, final List<JID> buddies) {

    Utils.runSafeAsync(
        log,
        new Runnable() {
          public void run() {
            final ISarosSession sarosSession = sarosSessionManager.getSarosSession();
            if (sarosSession != null) {
              Utils.runSafeSync(
                  log,
                  new Runnable() {
                    public void run() {
                      Collection<User> addedUsers = sarosSession.getParticipants();
                      List<JID> buddiesToAdd = new LinkedList<JID>();
                      for (JID buddy : buddies) {
                        boolean addBuddyToSession = true;
                        for (User addedUser : addedUsers) {
                          JID addedBuddy = addedUser.getJID();
                          if (buddy.equals(addedBuddy)) {
                            addBuddyToSession = false;
                            break;
                          }
                        }
                        if (addBuddyToSession) {
                          buddiesToAdd.add(buddy);
                        }
                      }

                      String description =
                          getShareProjectDescription(
                              sarosSession.getHost().getJID(),
                              sarosSession.getProjects().toArray(new IProject[0]));

                      if (buddiesToAdd.size() > 0) {
                        sarosSessionManager.invite(buddiesToAdd, description);
                      }
                    }
                  });
            } else {
              log.warn(
                  "Tried to add buddies to "
                      + SarosSession.class.getSimpleName()
                      + " although there is no one running");
            }
          }
        });
  }
예제 #5
0
  /**
   * Leaves the currently running {@link SarosSession}<br>
   * Does nothing if no {@link SarosSession} is running.
   *
   * @param sarosSessionManager
   */
  public static void leaveSession(final SarosSessionManager sarosSessionManager) {
    ISarosSession sarosSession = sarosSessionManager.getSarosSession();

    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

    if (sarosSession != null) {
      boolean reallyLeave;

      if (sarosSession.isHost()) {
        if (sarosSession.getParticipants().size() == 1) {
          // Do not ask when host is alone...
          reallyLeave = true;
        } else {
          reallyLeave =
              MessageDialog.openQuestion(
                  shell,
                  "Confirm Closing Session",
                  "Are you sure that you want to close this Saros session? Since you are the creator of this session, it will be closed for all participants.");
        }
      } else {
        reallyLeave =
            MessageDialog.openQuestion(
                shell,
                "Confirm Leaving Session",
                "Are you sure that you want to leave this Saros session?");
      }

      if (!reallyLeave) return;

      Utils.runSafeAsync(
          log,
          new Runnable() {
            public void run() {
              try {
                sarosSessionManager.stopSarosSession();
              } catch (Exception e) {
                log.error("Session could not be left: ", e);
              }
            }
          });
    } else {
      log.warn(
          "Tried to leave "
              + SarosSession.class.getSimpleName()
              + " although there is no one running");
    }
  }
예제 #6
0
  /**
   * Adds the given projects to the session.<br>
   * Does nothing if no {@link SarosSession} is running.
   *
   * @param sarosSessionManager
   * @param projects
   * @nonBlocking
   */
  public static void addProjectsToSarosSession(
      final SarosSessionManager sarosSessionManager, final List<IProject> projects) {

    Utils.runSafeAsync(
        log,
        new Runnable() {
          public void run() {
            final ISarosSession sarosSession = sarosSessionManager.getSarosSession();
            if (sarosSession != null) {
              Utils.runSafeSync(
                  log,
                  new Runnable() {
                    public void run() {
                      Set<IProject> addedProjects = sarosSession.getProjects();

                      List<IProject> projectsToAdd = new LinkedList<IProject>();
                      for (IProject project : projects) {
                        if (!addedProjects.contains(project)) {
                          projectsToAdd.add(project);
                        }
                      }

                      if (projectsToAdd.size() > 0) {
                        sarosSessionManager.addProjectsToSession(projectsToAdd);
                      }
                    }
                  });
            } else {
              log.warn(
                  "Tried to add projects to "
                      + SarosSession.class.getSimpleName()
                      + " although there is no one running");
            }
          }
        });
  }
 @Override
 public String toString(Object obj) {
   return Utils.urlEscape((String) obj);
 }
 @Override
 public Object fromString(String s) {
   return Utils.urlUnescape(s);
 }
 protected String prefix() {
   return this.getMode().toString() + " " + Utils.prefix(peer);
 }