Package net.sphene.goim.rcp.views

Source Code of net.sphene.goim.rcp.views.ChatView

/*
* Gamers Own Instant Messenger
* Copyright (C) 2005-2006 Herbert Poul (kahless@sphene.net)
* http://goim.sphene.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/

package net.sphene.goim.rcp.views;

import net.sphene.goim.rcp.beans.GOIMAccount;
import net.sphene.goim.rcp.extensionpoints.IChatGUI;
import net.sphene.goim.rcp.ui.ChatBrowserGUI;
import net.sphene.goim.rcp.ui.ChatBrowserWindow;
import net.sphene.goim.rcp.ui.MUCBrowserGUI;
import net.sphene.goim.rcp.ui.chat.GOIMChatObject;
import net.sphene.libs.SpheneEvent;
import net.sphene.libs.SpheneListener;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.part.ViewPart;
import org.jivesoftware.smackx.muc.MultiUserChat;

public class ChatView extends ViewPart {
  public static final String ID = "net.sphene.goim.rcp.views.chat";
  protected ChatBrowserGUI chatGUI;
 
  boolean isDirty = false;
  private ChatBrowserWindow chatBrowserWindow;
  private GOIMAccount account;
 
  protected Composite parent;
 
  protected String originalJID;

  public ChatView() {
    super();
  }

  @Override
  public void createPartControl(Composite parent) {
    this.parent = parent;
//    chatGUI.changeListener.addListener(new SpheneListener<SpheneEvent>() {
//      public void handleEvent(SpheneEvent arg0) {
//        getSite().getWorkbenchWindow().getShell().getDisplay().asyncExec(new Runnable() {
//          public void run() {
//            getSite().getPage().activate(ChatView.this);
//          }
//        });
//      }
//    });
  }

  @Override
  public void setFocus() {
    isDirty = false;
    changePartName();
    if(chatGUI != null)
      chatGUI.setCustomFocus();
  }

  @Override
  public void saveState(IMemento memento) {
    super.saveState(memento);
    System.out.println("ChatView.saveState");
    getSite().getPage().hideView(this);
//    if(getSite().getPage().getViewReferences().length < 1) {
//      IWorkbenchWindow window = getSite().getPage().getWorkbenchWindow();
//      getSite().getPage().close();
//      if(window.getPages().length < 1)
//        window.close();
//    }
  }

  public void changePartName() {
    if(chatGUI == null) return;
    String name;
    originalJID = chatGUI.getJID();
    if(isDirty) {
      name = "* " + originalJID;
    } else {
      name = originalJID;
    }
    System.out.println("Change PartName To " + name);
    setPartName(name);
  }
  public void init(GOIMAccount account, GOIMChatObject chat) {
    chatGUI = new ChatBrowserGUI(parent,SWT.NULL);
    this.account = account;
    chatGUI.init(account,chat);
    changePartName();
    chatGUI.layout(true,true);
    chatGUI.addChangeListener(new SpheneListener<SpheneEvent>() {
      public void handleEvent(final SpheneEvent event) {
        chatGUI.getDisplay().asyncExec(new Runnable() { public void run() {
          Object obj = event.getParam(ChatBrowserGUI.EVENT_PARAM_ALREADYHANDLED);
          chatBrowserWindow.setIsDirty(true,obj==null?false:((Boolean)obj).booleanValue());
          if(!chatGUI.isVisible()) {
            isDirty = true;
            changePartName();
          } else if(!originalJID.equals(chatGUI.getJID())) {
            changePartName();
          }
        }});
      } });
    myInit();
  }
  private void myInit() {
    Shell shell = getSite().getWorkbenchWindow().getShell();
    chatBrowserWindow =
      (ChatBrowserWindow)shell.getData("chatBrowserWindow");
    if(chatBrowserWindow == null) {
      shell.setData("chatBrowserWindow",chatBrowserWindow = new ChatBrowserWindow(shell,account));
      chatBrowserWindow.initListeners();
      chatBrowserWindow.setOriginalTitle(shell.getText());
    } else
      chatBrowserWindow.setIsDirty(true,false);
  }

  public void init(GOIMAccount account, MultiUserChat muc) {
    chatGUI = new MUCBrowserGUI(parent,SWT.NULL);
    this.account = account;
    ((MUCBrowserGUI)chatGUI).init(account,muc);
    changePartName();
    chatGUI.layout(true,true);
    chatGUI.addChangeListener(new SpheneListener<SpheneEvent>() {
      public void handleEvent(final SpheneEvent event) {
        chatGUI.getDisplay().asyncExec(new Runnable() { public void run() {
          Object obj = event.getParam(ChatBrowserGUI.EVENT_PARAM_ALREADYHANDLED);
          chatBrowserWindow.setIsDirty(true,obj==null?false:((Boolean)obj).booleanValue());
          if(!chatGUI.isVisible()) {
            isDirty = true;
            changePartName();
          }
        }});
      } });
    myInit();
  }
  public IChatGUI getChatGUI() {
    return chatGUI;
  }



}
TOP

Related Classes of net.sphene.goim.rcp.views.ChatView

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.