Package org.eclipse.twipse

Source Code of org.eclipse.twipse.TwipsePlugin

package org.eclipse.twipse;

import java.util.List;

import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.ContainerCreateException;
import org.eclipse.ecf.core.ContainerFactory;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.eclipse.swt.widgets.Display;
import org.eclipse.twipse.core.ITwitterClient;
import org.eclipse.twipse.core.TwitterClient;
import org.eclipse.twipse.model.*;


/**
* The activator class controls the plug-in life cycle
*/
public class TwipsePlugin extends AbstractUIPlugin {

  // The plug-in ID
  public static final String PLUGIN_ID = "TwipsePlugin";

  // The shared instance
  private static TwipsePlugin plugin; 
 
  private Thread updater;
  private ITwitterClient client = new TwitterClient();
  private StatusList statuses = new StatusList();
 
  public static String NAMESPACE_IDENTIFIER = "ecf.twitter";

  /**
   * The constructor
   */
  public TwipsePlugin() {
    plugin = this;
  //  client.authenticate("","");
    //Display.getDefault().syncExec(
    updater = new Thread(){
      public void run() {
        while(true){

          if(statuses==null)statuses=new StatusList();
          statuses.addAll(
              client.getFriendsLatest20Updates());
         
          statuses.notifyObservers();
          try {
            System.out.println(client.getRefreshTime()*1000);
            sleep(client.getRefreshTime()*1000);//TODO Refactor
          } catch (InterruptedException e) {         
            e.printStackTrace();
          }
        }
      }
    };
    updater.start();
    try {
      // make container instance
      IContainer cont = ContainerFactory.getDefault().createContainer("ecf.twitter");
      // make targetID      
      ID targetID;
      targetID = IDFactory.getDefault().createID(cont.getConnectNamespace(),"http://twitter.com/savino2");
      cont.connect(targetID,null);
    } catch (IDCreateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ContainerConnectException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ContainerCreateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

  /*
   * (non-Javadoc)
   * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
   */
  public void start(BundleContext context) throws Exception {
    super.start(context);
  }

  /*
   * (non-Javadoc)
   * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
   */
  public void stop(BundleContext context) throws Exception {
    plugin = null;
    statuses.deleteObservers();
    super.stop(context);
  }

  /**
   * Returns the shared instance
   *
   * @return the shared instance
   */
  public static TwipsePlugin getDefault() {
    return plugin;
  }

  /**
   * Returns an image descriptor for the image file at the given
   * plug-in relative path
   *
   * @param path the path
   * @return the image descriptor
   */
  public static ImageDescriptor getImageDescriptor(String path) {
    return imageDescriptorFromPlugin(PLUGIN_ID, path);
  }
 
  public StatusList getStatusList(){
    if(statuses==null){
      statuses=new StatusList();
      statuses.addAll(client.getFriendsLatest20Updates());
    }   
    return statuses;
  }

  public ITwitterClient getClient() {
    return client;
  }

  public void setClient(ITwitterClient client) {
    this.client = client;
  }
}
TOP

Related Classes of org.eclipse.twipse.TwipsePlugin

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.