Esempio n. 1
0
  /**
   * Adds the plugin component given by <tt>event</tt> to this panel if it's its container.
   *
   * @param event the <tt>PluginComponentEvent</tt> that notified us
   */
  public void pluginComponentAdded(PluginComponentEvent event) {
    PluginComponentFactory factory = event.getPluginComponentFactory();

    // If the container id doesn't correspond to the id of the plugin
    // container we're not interested.
    if (!factory.getContainer().equals(Container.CONTAINER_CONTACT_LIST)) return;

    Object constraints =
        UIServiceImpl.getBorderLayoutConstraintsFromContainer(factory.getConstraints());

    if (constraints == null) constraints = BorderLayout.SOUTH;

    PluginComponent pluginComponent = factory.getPluginComponentInstance(this);
    this.add((Component) pluginComponent.getComponent(), constraints);

    Object selectedValue = getContactList().getSelectedValue();

    if (selectedValue instanceof MetaContact) {
      pluginComponent.setCurrentContact((MetaContact) selectedValue);
    } else if (selectedValue instanceof MetaContactGroup) {
      pluginComponent.setCurrentContactGroup((MetaContactGroup) selectedValue);
    }

    this.revalidate();
    this.repaint();
  }
Esempio n. 2
0
  /**
   * Implements ChatSessionChangeListener#currentChatTransportChanged(ChatSession).
   *
   * @param chatSession the <tt>ChatSession</tt>, which transport has changed
   */
  public void currentChatTransportChanged(ChatSession chatSession) {
    if (chatSession == null) return;

    ChatTransport currentTransport = chatSession.getCurrentChatTransport();
    Object currentDescriptor = currentTransport.getDescriptor();

    if (currentDescriptor instanceof Contact) {
      Contact contact = (Contact) currentDescriptor;

      for (PluginComponent c : pluginContainer.getPluginComponents()) c.setCurrentContact(contact);
    }
  }
Esempio n. 3
0
  /**
   * Runs clean-up for associated resources which need explicit disposal (e.g. listeners keeping
   * this instance alive because they were added to the model which operationally outlives this
   * instance).
   */
  public void dispose() {
    GuiActivator.getUIService().removePluginComponentListener(this);

    /*
     * Explicitly remove the components of the PluginComponent instances
     * because the latter are registered with OSGi and are thus global.
     */
    synchronized (this) {
      for (PluginComponent pluginComponent : pluginComponents)
        container.remove((Component) pluginComponent.getComponent());
      pluginComponents.clear();
    }
  }
Esempio n. 4
0
  /**
   * Adds the component of a specific <tt>PluginComponent</tt> to the associated <tt>Container</tt>.
   *
   * @param c the <tt>PluginComponent</tt> which is to have its component added to the
   *     <tt>Container</tt> associated with this <tt>PluginContainer</tt>
   */
  private synchronized void addPluginComponent(PluginComponent c) {
    /*
     * Try to respect positionIndex of PluginComponent to some extent:
     * PluginComponents with positionIndex equal to 0 go at the beginning,
     * these with positionIndex equal to -1 follow them and then go these
     * with positionIndex greater than 0.
     */
    int cIndex = c.getPositionIndex();
    int index = -1;
    int i = 0;

    for (PluginComponent pluginComponent : pluginComponents) {
      if (pluginComponent.equals(c)) return;

      if (-1 == index) {
        int pluginComponentIndex = pluginComponent.getPositionIndex();

        if ((0 == cIndex) || (-1 == cIndex)) {
          if ((0 != pluginComponentIndex) && (cIndex != pluginComponentIndex)) index = i;
        } else if (cIndex < pluginComponentIndex) index = i;
      }

      i++;
    }

    int pluginComponentCount = pluginComponents.size();

    if (-1 == index) index = pluginComponents.size();

    /*
     * The container may have added Components of its own apart from the
     * ones this PluginContainer has added to it. Since the common case for
     * the additional Components is to have them appear at the beginning,
     * adjust the index so it gets correct in the common case.
     */
    int containerComponentCount = getComponentCount(container);

    addComponentToContainer(
        (Component) c.getComponent(),
        container,
        (containerComponentCount > pluginComponentCount)
            ? (index + (containerComponentCount - pluginComponentCount))
            : index);
    pluginComponents.add(index, c);

    container.revalidate();
    container.repaint();
  }
Esempio n. 5
0
  private void initPluginComponents() {
    // Search for plugin components registered through the OSGI bundle
    // context.
    ServiceReference[] serRefs = null;

    String osgiFilter =
        "(" + Container.CONTAINER_ID + "=" + Container.CONTAINER_CONTACT_LIST.getID() + ")";

    try {
      serRefs =
          GuiActivator.bundleContext.getServiceReferences(
              PluginComponentFactory.class.getName(), osgiFilter);
    } catch (InvalidSyntaxException exc) {
      logger.error("Could not obtain plugin reference.", exc);
    }

    if (serRefs != null) {
      for (ServiceReference serRef : serRefs) {
        PluginComponentFactory factory =
            (PluginComponentFactory) GuiActivator.bundleContext.getService(serRef);
        PluginComponent component = factory.getPluginComponentInstance(this);

        Object selectedValue = getContactList().getSelectedValue();

        if (selectedValue instanceof MetaContact) {
          component.setCurrentContact((MetaContact) selectedValue);
        } else if (selectedValue instanceof MetaContactGroup) {
          component.setCurrentContactGroup((MetaContactGroup) selectedValue);
        }

        String pluginConstraints = factory.getConstraints();
        Object constraints;

        if (pluginConstraints != null)
          constraints = UIServiceImpl.getBorderLayoutConstraintsFromContainer(pluginConstraints);
        else constraints = BorderLayout.SOUTH;

        this.add((Component) component.getComponent(), constraints);

        this.repaint();
      }
    }

    GuiActivator.getUIService().addPluginComponentListener(this);
  }
Esempio n. 6
0
  /**
   * Implements ChatChangeListener#chatChanged(ChatPanel).
   *
   * @param chatPanel the <tt>ChatPanel</tt>, which changed
   */
  public void chatChanged(ChatPanel chatPanel) {
    if (chatPanel == null) {
      setChatSession(null);
    } else {
      MetaContact contact = GuiActivator.getUIService().getChatContact(chatPanel);

      for (PluginComponent c : pluginContainer.getPluginComponents()) c.setCurrentContact(contact);

      ChatSession chatSession = chatPanel.getChatSession();
      setChatSession(chatSession);

      leaveChatRoomButton.setEnabled(chatSession instanceof ConferenceChatSession);

      desktopSharingButton.setEnabled(!(chatSession instanceof ConferenceChatSession));

      inviteButton.setEnabled(chatPanel.findInviteChatTransport() != null);

      sendFileButton.setEnabled(chatPanel.findFileTransferChatTransport() != null);
      inviteButton.setEnabled(!chatPanel.isPrivateMessagingChat());

      if (chatSession instanceof ConferenceChatSession) {
        updateInviteContactButton();

        callButton.setVisible(false);
        callVideoButton.setVisible(false);
        callButton.setEnabled(true);
        callVideoButton.setEnabled(true);
      } else if (contact != null) {
        callButton.setVisible(true);
        callVideoButton.setVisible(true);
        new UpdateCallButtonWorker(contact).start();
      }

      changeHistoryButtonsState(chatPanel);

      setCallButtonsName();
      setCallButtonsIcons();

      currentChatTransportChanged(chatSession);
    }
  }
Esempio n. 7
0
  /**
   * Implements ChatChangeListener#chatChanged(ChatPanel).
   *
   * @param chatPanel the <tt>ChatPanel</tt>, which changed
   */
  public void chatChanged(ChatPanel chatPanel) {
    if (chatPanel == null) {
      setChatSession(null);
    } else {
      MetaContact contact = GuiActivator.getUIService().getChatContact(chatPanel);

      for (PluginComponent c : pluginContainer.getPluginComponents()) c.setCurrentContact(contact);

      setChatSession(chatPanel.chatSession);

      leaveChatRoomButton.setEnabled(chatPanel.chatSession instanceof ConferenceChatSession);

      inviteButton.setEnabled(chatPanel.findInviteChatTransport() != null);

      sendFileButton.setEnabled(chatPanel.findFileTransferChatTransport() != null);

      new UpdateCallButtonWorker(contact).start();

      changeHistoryButtonsState(chatPanel);
    }
  }
Esempio n. 8
0
 /**
  * Removes the component of a specific <code>PluginComponent</code> from this <code>
  * PluginContainer</code>.
  *
  * @param c the <code>PluginComponent</code> which is to have its component removed from this
  *     <code>PluginContainer</code>
  */
 private synchronized void removePluginComponent(PluginComponent c) {
   container.remove((Component) c.getComponent());
   pluginComponents.remove(c);
 }
Esempio n. 9
0
  /**
   * Implements {@link PluginComponentListener#pluginComponentRemoved(PluginComponentEvent)}.
   *
   * @param event a <tt>PluginComponentEvent</tt> which specifies the <tt>PluginComponent</tt> which
   *     has been added
   */
  public void pluginComponentRemoved(PluginComponentEvent event) {
    PluginComponent c = event.getPluginComponent();

    if (c.getContainer().equals(containerId)) removePluginComponent(c);
  }
Esempio n. 10
0
  /**
   * Implements {@link PluginComponentListener#pluginComponentAdded(PluginComponentEvent)}.
   *
   * @param event a <tt>PluginComponentEvent</tt> which specifies the <tt>PluginComponent</tt> which
   *     has been added
   */
  public void pluginComponentAdded(PluginComponentEvent event) {
    PluginComponent c = event.getPluginComponent();

    if (c.getContainer().equals(containerId)) addPluginComponent(c);
  }