sdkcreationmw/sdkconnectivityfw/emuconnectmanager/epdt_java/src/com/nokia/epdt/plugins/s60/pan/PanPlugin.java
changeset 1 ac50fd48361b
parent 0 b26acd06ea60
equal deleted inserted replaced
0:b26acd06ea60 1:ac50fd48361b
     1 /*
     1 /*
     2 * Copyright (c) 2000 - 2006 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2000 - 2006 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15  *
     8  *
    16 */
     9  * Initial Contributors:
    17 
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: 
       
    15  *
       
    16  */
    18 
    17 
    19 package com.nokia.epdt.plugins.s60.pan;
    18 package com.nokia.epdt.plugins.s60.pan;
    20 
    19 
    21 import org.apache.log4j.Logger;
       
    22 import java.awt.Image;
    20 import java.awt.Image;
       
    21 import java.io.IOException;
       
    22 
    23 import javax.swing.ImageIcon;
    23 import javax.swing.ImageIcon;
    24 import javax.swing.JPanel;
    24 import javax.swing.JPanel;
    25 import javax.swing.JOptionPane;
    25 
       
    26 import org.apache.log4j.Logger;
       
    27 
       
    28 import com.nokia.epdt.core.CoreController;
       
    29 import com.nokia.epdt.core.CoreUtils;
       
    30 import com.nokia.epdt.core.action.Action;
       
    31 import com.nokia.epdt.core.action.ActionEventQueue;
       
    32 import com.nokia.epdt.core.action.ActionInterface;
       
    33 import com.nokia.epdt.core.action.ActionListener;
       
    34 import com.nokia.epdt.core.messaging.MessageInterface;
       
    35 import com.nokia.epdt.core.messaging.MessageQueue;
    26 import com.nokia.epdt.core.plugin.CustomPlugin;
    36 import com.nokia.epdt.core.plugin.CustomPlugin;
    27 import com.nokia.epdt.core.plugin.PluginType;
    37 import com.nokia.epdt.core.plugin.PluginType;
    28 import com.nokia.epdt.core.messaging.MessageInterface;
       
    29 import com.nokia.epdt.core.messaging.MessageListener;
       
    30 import com.nokia.epdt.core.messaging.Message;
       
    31 import com.nokia.epdt.core.messaging.MessageQueue;
       
    32 import com.nokia.epdt.core.action.Action;
       
    33 import com.nokia.epdt.core.action.ActionInterface;
       
    34 import com.nokia.epdt.core.action.ActionListener;
       
    35 import com.nokia.epdt.core.action.ActionEventQueue;
       
    36 import com.nokia.epdt.core.CoreController;
       
    37 import com.nokia.epdt.core.CoreUtils;
       
    38 import com.nokia.epdt.core.connection.ConnectionStatus;
       
    39 import java.io.IOException;
       
    40 
    38 
    41 /**
    39 /**
    42  * PanPlugin
    40  * PanPlugin
    43  *
    41  *
    44  * @version 1.0
    42  * @version 1.0
    45  */
    43  */
    46 public class PanPlugin extends CustomPlugin
    44 public class PanPlugin extends CustomPlugin {
    47 {
       
    48 	private static Logger log = Logger.getLogger(PanPlugin.class);
    45 	private static Logger log = Logger.getLogger(PanPlugin.class);
    49 	private static final Integer UID = Integer.valueOf(PanResourceBundle
    46 	private static final Integer UID = Integer.valueOf(PanResourceBundle
    50 			.getInstance().getValue(PanConstants.PLUGIN_UID), 16);
    47 			.getInstance().getValue(PanConstants.PLUGIN_UID), 16);
    51 	private static final Integer TARGET_UID = Integer.valueOf(PanResourceBundle
    48 	private static final Integer TARGET_UID = Integer.valueOf(PanResourceBundle
    52 			.getInstance().getValue(PanConstants.TARGET_UID), 16);
    49 			.getInstance().getValue(PanConstants.TARGET_UID), 16);
    53 	private PanModel panModel;
    50 	private PanModel panModel;
    54 	private MessageQueue messageOutputQueue;
    51 	private MessageQueue messageOutputQueue;
    55 	private ActionEventQueue actionEventQueue;
    52 	private ActionEventQueue actionEventQueue;
    56 	private CoreController coreController;
    53 	private CoreController coreController;
    57 	private JPanel jPanel;
    54 	private JPanel jPanel;
       
    55 
    58 	/**
    56 	/**
    59 	 * A ActionListener object is used to receive synchronously delivered actions.
    57 	 * A ActionListener object is used to receive synchronously delivered actions.
    60 	 */
    58 	 */
    61 	private class PanPluginActionListener implements ActionListener
    59 	private class PanPluginActionListener implements ActionListener {
    62 	{
    60 		public void actionPerformed(Action e) {
    63 		public void actionPerformed(Action e)
    61 			if (e.getName() == Action.PREFERENCES_OK) {
    64 		{
       
    65 			if (e.getName() == Action.PREFERENCES_OK)
       
    66 			{
       
    67 				actionEventQueue.put(new Action(
    62 				actionEventQueue.put(new Action(
    68 						Action.PREFERENCES_REMOVE_PLUGIN_MODEL_CHANGED,
    63 						Action.PREFERENCES_REMOVE_PLUGIN_MODEL_CHANGED,
    69 						PanPlugin.UID, Action.CORE, new int[0]));
    64 						PanPlugin.UID, Action.CORE, new int[0]));
    70 				panModel.save();
    65 				panModel.save();
    71 				actionEventQueue.put(new Action(Action.PREFERENCES_HIDE_PLUGIN,
    66 				actionEventQueue.put(new Action(Action.PREFERENCES_HIDE_PLUGIN,
    72 						PanPlugin.UID, Action.CORE, new int[0]));
    67 						PanPlugin.UID, Action.CORE, new int[0]));
    73 			} else if (e.getName() == Action.PREFERENCES_APPLY)
    68 			} else if (e.getName() == Action.PREFERENCES_APPLY) {
    74 			{
       
    75 				actionEventQueue.put(new Action(
    69 				actionEventQueue.put(new Action(
    76 						Action.PREFERENCES_REMOVE_PLUGIN_MODEL_CHANGED,
    70 						Action.PREFERENCES_REMOVE_PLUGIN_MODEL_CHANGED,
    77 						PanPlugin.UID, Action.CORE, new int[0]));
    71 						PanPlugin.UID, Action.CORE, new int[0]));
    78 				panModel.save();
    72 				panModel.save();
    79 			} else if (e.getName() == Action.PREFERENCES_CANCEL)
    73 			} else if (e.getName() == Action.PREFERENCES_CANCEL) {
    80 			{
       
    81 			}
    74 			}
    82 		}
    75 		}
    83 	}
    76 	}
       
    77 
    84 	/**
    78 	/**
    85 	 * Creates a new instance of PanPlugin
    79 	 * Creates a new instance of PanPlugin
    86 	 */
    80 	 */
    87 	public PanPlugin()
    81 	public PanPlugin() {
    88 	{
       
    89 		super();
    82 		super();
    90 
    83 
    91 	}
    84 	}
    92 
    85 
    93 	/**
    86 	/**
    94 	 * Getter for property pluginUID.
    87 	 * Getter for property pluginUID.
    95 	 * @return Value of property pluginUID.
    88 	 * @return Value of property pluginUID.
    96 	 */
    89 	 */
    97 	public Integer getPluginUID()
    90 	public Integer getPluginUID() {
    98 	{
       
    99 		return PanPlugin.UID;
    91 		return PanPlugin.UID;
   100 	}
    92 	}
   101 
    93 
   102 	/**
    94 	/**
   103 	 * Getter for property pluginType.
    95 	 * Getter for property pluginType.
   104 	 * @return Value of property pluginType.
    96 	 * @return Value of property pluginType.
   105 	 */
    97 	 */
   106 	public PluginType getPluginType()
    98 	public PluginType getPluginType() {
   107 	{
       
   108 		return PluginType.PREFERENCES;
    99 		return PluginType.PREFERENCES;
   109 	}
   100 	}
   110 
   101 
   111 	/**
   102 	/**
   112 	 * Getter for property name.
   103 	 * Getter for property name.
   113 	 * @return Value of property name.
   104 	 * @return Value of property name.
   114 	 */
   105 	 */
   115 	public String getName()
   106 	public String getName() {
   116 	{
       
   117 		return PanResourceBundle.getInstance().getValue(
   107 		return PanResourceBundle.getInstance().getValue(
   118 				PanConstants.PLUGIN_NAME);
   108 				PanConstants.PLUGIN_NAME);
   119 	}
   109 	}
   120 
   110 
   121 	/**
   111 	/**
   122 	 * Getter for property icon.
   112 	 * Getter for property icon.
   123 	 * @return Value of property icon.
   113 	 * @return Value of property icon.
   124 	 */
   114 	 */
   125 	public Image getIcon(int type)
   115 	public Image getIcon(int type) {
   126 	{
       
   127 		return (new ImageIcon()).getImage();
   116 		return (new ImageIcon()).getImage();
   128 	}
   117 	}
   129 
   118 
   130 	/**
   119 	/**
   131 	 * Getter for property jPanelView.
   120 	 * Getter for property jPanelView.
   132 	 * @return plug-in module user interface
   121 	 * @return plug-in module user interface
   133 	 */
   122 	 */
   134 	public JPanel getJPanelView()
   123 	public JPanel getJPanelView() {
   135 	{
   124 		if (jPanel == null) {
   136 		if (jPanel == null)
       
   137 		{
       
   138 			jPanel = new PanPluginJPanel(this);
   125 			jPanel = new PanPluginJPanel(this);
   139 		}
   126 		}
   140 		return jPanel;
   127 		return jPanel;
   141 	}
   128 	}
   142 
   129 
   143 	/**
   130 	/**
   144 	 * Bind the plugin's with the epdt core.
   131 	 * Bind the plugin's with the epdt core.
   145 	 * @param c instance of CoreController that is assosiated with this plugin
   132 	 * @param c instance of CoreController that is assosiated with this plugin
   146 	 */
   133 	 */
   147 	public void bindCore(CoreController c)
   134 	public void bindCore(CoreController c) {
   148 	{
   135 		try {
   149 		try
       
   150 		{
       
   151 			panModel = new PanModel(CoreUtils.EpocRoot());
   136 			panModel = new PanModel(CoreUtils.EpocRoot());
   152 		} catch (IOException ex)
   137 		} catch (IOException ex) { //TODO: do something to prevent view from loading
   153 		{ //TODO: do something to prevent view from loading
   138 			log.error("Error loading BT ESK files: " + ex.getMessage());
   154 			log.error("Error loading BT or Irda ESK files: " + ex.getMessage());
       
   155 		}
   139 		}
   156 		coreController = c;
   140 		coreController = c;
   157 	}
   141 	}
   158 
   142 
   159 	/**
   143 	/**
   160 	 * Bind the plugin's with the message interface.
   144 	 * Bind the plugin's with the message interface.
   161 	 * @param m the message interface which is used to send and receive messages
   145 	 * @param m the message interface which is used to send and receive messages
   162 	 */
   146 	 */
   163 	public void bindMessageInterface(MessageInterface m)
   147 	public void bindMessageInterface(MessageInterface m) {
   164 	{
       
   165 	}
   148 	}
   166 
   149 
   167 	/**
   150 	/**
   168 	 * Bind the plugin's with the action interface.
   151 	 * Bind the plugin's with the action interface.
   169 	 * @param a the action interface which is used to mediate and receive actions
   152 	 * @param a the action interface which is used to mediate and receive actions
   170 	 */
   153 	 */
   171 	public void bindActionInterface(ActionInterface a)
   154 	public void bindActionInterface(ActionInterface a) {
   172 	{
       
   173 		a.setActionListener(new PanPlugin.PanPluginActionListener(),
   155 		a.setActionListener(new PanPlugin.PanPluginActionListener(),
   174 				PanPlugin.UID, ActionListener.PLUGIN);
   156 				PanPlugin.UID, ActionListener.PLUGIN);
   175 		this.actionEventQueue = a.getActionEventQueue();
   157 		this.actionEventQueue = a.getActionEventQueue();
   176 	}
   158 	}
   177 
   159 
   178 	/**
   160 	/**
   179 	 * Notifies the core that a plugin model is changed
   161 	 * Notifies the core that a plugin model is changed
   180 	 */
   162 	 */
   181 	public void pluginModelChangedAction()
   163 	public void pluginModelChangedAction() {
   182 	{
   164 		if (actionEventQueue != null) {
   183 		if (actionEventQueue != null)
       
   184 		{
       
   185 			actionEventQueue.put(new Action(
   165 			actionEventQueue.put(new Action(
   186 					Action.PREFERENCES_PLUGIN_MODEL_CHANGED, PanPlugin.UID,
   166 					Action.PREFERENCES_PLUGIN_MODEL_CHANGED, PanPlugin.UID,
   187 					Action.CORE, new int[0]));
   167 					Action.CORE, new int[0]));
   188 		}
   168 		}
   189 	}
   169 	}
   190 
   170 
   191 	/**
   171 	/**
   192 	 * Returns the data model for this plugin
   172 	 * Returns the data model for this plugin
   193 	 * @return the data model
   173 	 * @return the data model
   194 	 */
   174 	 */
   195 	PanModel getModel()
   175 	PanModel getModel() {
   196 	{
       
   197 		return panModel;
   176 		return panModel;
   198 	}
   177 	}
   199 }
   178 }