/*
  * If the view is opened after session start, we have to check the
  * permissions.
  *
  * (non-Javadoc)
  *
  * @see org.eclipse.gef.ui.parts.GraphicalEditor#initializeGraphicalViewer()
  */
 @Override
 protected void initializeGraphicalViewer() {
   ISarosSession session = sessionManager.getSarosSession();
   if (session != null) {
     setEnabled(session.getLocalUser().hasWriteAccess());
   }
 }
  /**
   * Preselect project names for the remote projects. This method will either use an existing shared
   * project and disable the option to change the preselected values or just generate a unique
   * project name for new projects.
   *
   * <p>This method does <b>not</b> preselect values for existing projects unless they are already
   * shared ! This can do more harm than indented when the user is so eager and just ignores all
   * warnings that will be presented before he can finish the wizard.
   */
  private void preselectProjectNames() {

    final Set<String> reservedProjectNames = new HashSet<String>();

    for (Entry<String, ProjectOptionComposite> entry : projectOptionComposites.entrySet()) {

      String projectID = entry.getKey();
      ProjectOptionComposite projectOptionComposite = entry.getValue();

      de.fu_berlin.inf.dpp.filesystem.IProject project = session.getProject(projectID);

      if (project == null) continue;

      projectOptionComposite.setProjectName(true, project.getName());
      projectOptionComposite.setEnabled(false);
      reservedProjectNames.add(project.getName());
    }

    for (Entry<String, ProjectOptionComposite> entry : projectOptionComposites.entrySet()) {

      String projectID = entry.getKey();
      ProjectOptionComposite projectOptionComposite = entry.getValue();

      de.fu_berlin.inf.dpp.filesystem.IProject project = session.getProject(projectID);

      if (project != null) continue;

      String projectNameProposal =
          findProjectNameProposal(
              remoteProjectNames.get(projectID), reservedProjectNames.toArray(new String[0]));

      projectOptionComposite.setProjectName(false, projectNameProposal);
      reservedProjectNames.add(projectNameProposal);
    }
  }
  @Override
  public void exec(IActivity activity) {
    if (!(activity instanceof NOPActivity)) {
      return;
    }

    NOPActivity nop = (NOPActivity) activity;

    ISarosSession session = this.session;
    IActivityListener listener = this.listener;

    if (session == null) return;

    if (listener == null) return;

    /*
     * if we have not send this message to ourself then reply back , do not
     * use our JID as source as this would cause a infinite loop
     */
    if (!nop.getSource().equals(session.getLocalUser())) {
      NOPActivity response = new NOPActivity(nop.getSource(), nop.getSource(), nop.getID());

      listener.created(response);

      return;
    }

    int id = nop.getID();

    CountDownLatch latch = synchronizeRequests.get(id);

    if (latch != null) latch.countDown();
  }
 @Override
 public void start() {
   collector.flushFollowModes();
   session.addActivityProducer(this);
   session.addActivityConsumer(consumer);
   session.addListener(sessionListener);
   editor.addSharedEditorListener(followModeListener);
 }
 @Override
 public void stop() {
   session.removeActivityProducer(this);
   session.removeActivityConsumer(consumer);
   session.removeListener(sessionListener);
   editor.removeSharedEditorListener(followModeListener);
   collector.flushFollowModes();
 }
        @Override
        public void followModeChanged(User target, boolean isFollowed) {

          if (isFollowed) {
            fireActivity(new StartFollowingActivity(session.getLocalUser(), target));
          } else {
            fireActivity(new StopFollowingActivity(session.getLocalUser()));
          }
        }
  @Override
  public void synchronizeOnActivityQueue(JID jid, long timeout) throws RemoteException {

    ISarosSession session = this.session;
    IActivityListener listener = this.listener;

    // this is too lazy, but ok for testing purposes

    if (session == null) throw new IllegalStateException("no session running");

    if (listener == null) throw new IllegalStateException("no session running");

    final CountDownLatch swtThreadSync = new CountDownLatch(1);

    UIThreadRunnable.asyncExec(
        new VoidResult() {
          @Override
          public void run() {
            swtThreadSync.countDown();
          }
        });

    try {
      if (!swtThreadSync.await(
          SarosSWTBotPreferences.SAROS_DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)) {
        LOG.warn("could not synchronize on the SWT EDT");
      }
    } catch (InterruptedException e1) {
      Thread.currentThread().interrupt();
    }

    int id = RANDOM.nextInt();

    NOPActivity activity = new NOPActivity(session.getLocalUser(), session.getUser(jid), id);

    CountDownLatch latch = new CountDownLatch(1);

    synchronizeRequests.put(id, latch);
    listener.created(activity);

    try {
      if (!latch.await(timeout, TimeUnit.MILLISECONDS))
        throw new TimeoutException("no reply from " + jid);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    } finally {
      synchronizeRequests.remove(id);
    }
  }
  public void runDeleteAction() {
    RosterEntry rosterEntry = null;
    List<RosterEntry> selectedRosterEntries =
        SelectionRetrieverFactory.getSelectionRetriever(RosterEntry.class).getSelection();
    if (selectedRosterEntries.size() == 1) {
      rosterEntry = selectedRosterEntries.get(0);
    }

    if (rosterEntry == null) {
      LOG.error("RosterEntry should not be null at this point!"); // $NON-NLS-1$
      return;
    }

    if (sessionManager != null) {
      // Is the chosen user currently in the session?
      ISarosSession sarosSession = sessionManager.getSarosSession();
      String entryJid = rosterEntry.getUser();

      if (sarosSession != null) {
        for (User p : sarosSession.getUsers()) {
          String pJid = p.getJID().getBase();

          // If so, stop the deletion from completing
          if (entryJid.equals(pJid)) {
            MessageDialog.openError(
                null, Messages.DeleteContactAction_error_title, DELETE_ERROR_IN_SESSION);
            return;
          }
        }
      }
    }

    if (MessageDialog.openQuestion(
        null,
        Messages.DeleteContactAction_confirm_title,
        MessageFormat.format(
            Messages.DeleteContactAction_confirm_message, toString(rosterEntry)))) {

      try {
        XMPPUtils.removeFromRoster(connectionService.getConnection(), rosterEntry);
      } catch (XMPPException e) {
        LOG.error(
            "could not delete contact "
                + toString(rosterEntry) // $NON-NLS-1$
                + ":",
            e); //$NON-NLS-1$
      }
    }
  }
Beispiel #9
0
 @Override
 public void sessionStarted(ISarosSession newSarosSession) {
   undoHistory.clear();
   newSarosSession.addActivityProvider(UndoManager.this);
   enabled = preferences.isConcurrentUndoActivated();
   eclipseHistory.addOperationApprover(operationBlocker);
   UndoManager.this.sarosSession = newSarosSession;
 }
Beispiel #10
0
  protected void redo(SPath editor) {

    Operation op = calcRedoOperation(editor);

    for (TextEditActivity activity : op.toTextEdit(editor, sarosSession.getLocalUser())) {
      log.debug("redone: " + activity + " in " + editor);
      fireActivity(activity);
    }
  }
Beispiel #11
0
 @Override
 public void sessionEnded(ISarosSession oldSarosSession) {
   oldSarosSession.removeActivityProvider(UndoManager.this);
   undoHistory.clear();
   enabled = false;
   eclipseHistory.removeOperationApprover(operationBlocker);
   UndoManager.this.sarosSession = null;
   currentLocalCompositeOperation = null;
   currentLocalAtomicOperation = null;
 }
Beispiel #12
0
  protected void undo(SPath editor) {

    Operation op = calcUndoOperation(editor);
    log.debug("calculated undo: " + op);

    // don't waste the network
    if (op instanceof NoOperation) {
      log.debug("nothing to undo in " + editor);
      return;
    }

    for (TextEditActivity activity : op.toTextEdit(editor, sarosSession.getLocalUser())) {
      log.debug("undone: " + activity + " in " + editor);
      fireActivity(activity);
    }
  }
 @Override
 public void sessionEnded(ISarosSession session, SessionEndReason reason) {
   session.removeListener(sessionListener);
   setEnabledInSWTThread(true);
 }
 @Override
 public void sessionStarted(ISarosSession session) {
   session.addListener(sessionListener);
   setEnabledInSWTThread(session.getLocalUser().hasWriteAccess());
 }
Beispiel #15
0
 @Override
 protected void doOnSessionStart(ISarosSession sarosSession) {
   editorManager.addSharedEditorListener(editorListener);
   // set local users JID at the beginning of the session
   localUser = sarosSession.getLocalUser();
 }