Optimizes account info plugin, do not load panels and listeners on startup, load them on demand.

fix-message-formatting
Damian Minkov 12 years ago
parent c1c59400c9
commit 124e4e90e4

@ -22,6 +22,7 @@
import net.java.sip.communicator.service.globaldisplaydetails.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.ServerStoredDetails.*;
import net.java.sip.communicator.plugin.accountinfo.AccountInfoMenuItemComponent.*;
import net.java.sip.communicator.util.Logger;
@ -184,14 +185,22 @@ public class AccountDetailsPanel
private JScrollPane mainScrollPane;
/**
* The parent dialog.
*/
private AccountInfoDialog dialog;
/**
* Construct a panel containing all account details for the given protocol
* provider.
*
* @param protocolProvider the protocol provider service
*/
public AccountDetailsPanel(ProtocolProviderService protocolProvider)
public AccountDetailsPanel(AccountInfoDialog dialog,
ProtocolProviderService protocolProvider)
{
this.dialog = dialog;
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setOpaque(false);
this.setPreferredSize(new Dimension(600, 400));
@ -645,7 +654,7 @@ public void replace(FilterBypass fb, int offs,
@Override
public void actionPerformed(ActionEvent evt)
{
AccountInfoMenuItemComponent.dialog.setVisible(false);
dialog.close(false);
mainScrollPane.getVerticalScrollBar().setValue(0);
}
});
@ -829,6 +838,15 @@ else if (detail.getClass().equals(AboutMeDetail.class))
}
}
/**
* Returns the provider we represent.
* @return
*/
public ProtocolProviderService getProtocolProvider()
{
return protocolProvider;
}
/**
* Attempts to upload all <tt>ServerStoredDetails</tt> on the server using
* <tt>OperationSetServerStoredAccountInfo</tt>
@ -1157,8 +1175,8 @@ public void actionPerformed(ActionEvent e)
try
{
AccountInfoMenuItemComponent.dialog.setVisible(false);
mainScrollPane.getVerticalScrollBar().setValue(0);
dialog.close(false);
//mainScrollPane.getVerticalScrollBar().setValue(0);
accountInfoOpSet.save();
}
catch (OperationFailedException e1)

@ -24,32 +24,12 @@ public class AccountInfoMenuItemComponent
/**
* The "Account Info" menu item.
*/
JMenuItem accountInfoMenuItem;
private JMenuItem accountInfoMenuItem;
/**
* The dialog that appears when "Account Info" menu item is clicked.
* Currently set account id if any.
*/
static final SIPCommDialog dialog = new SIPCommDialog() {
/**
* Serial version UID.
*/
private static final long serialVersionUID = 1L;
/**
* Presses programmatically the cancel button, when Esc key is pressed.
*
* @param isEscaped indicates if the Esc button was pressed on close
*/
protected void close(boolean isEscaped)
{
this.setVisible(false);
}
};
/**
* The main panel containing account information.
*/
static final AccountInfoPanel accountInfoPanel = new AccountInfoPanel();
private AccountID accountID = null;
/**
* Initializes a new "Account Info" menu item.
@ -60,20 +40,14 @@ public AccountInfoMenuItemComponent(Container container,
PluginComponentFactory parentFactory)
{
super(container, parentFactory);
AccountInfoActivator.bundleContext.addServiceListener(accountInfoPanel);
dialog.setPreferredSize(new java.awt.Dimension(600, 400));
dialog.setTitle(Resources.getString("plugin.accountinfo.TITLE"));
dialog.add(accountInfoPanel);
}
public void setCurrentAccountID(AccountID accountID)
{
this.accountID = accountID;
accountInfoMenuItem.setEnabled(
accountID != null && accountID.isEnabled());
accountInfoPanel.getAccountsComboBox().setSelectedItem(
accountInfoPanel.getAccountsTable().get(accountID));
}
/**
@ -97,8 +71,10 @@ public Object getComponent()
{
public void actionPerformed(ActionEvent e)
{
AccountInfoDialog dialog
= new AccountInfoDialog(accountID);
dialog.setVisible(true);
accountInfoPanel.setVisible(true);
}
});
}
@ -129,4 +105,53 @@ public int getPositionIndex()
{
return 0;
}
/**
* The dialog that appears when "Account Info" menu item is clicked.
*/
static class AccountInfoDialog
extends SIPCommDialog
{
private AccountInfoPanel accountInfoPanel;
private AccountInfoDialog(AccountID accountID)
{
this.accountInfoPanel = new AccountInfoPanel(this);
this.setPreferredSize(new java.awt.Dimension(600, 400));
this.setTitle(Resources.getString("plugin.accountinfo.TITLE"));
if(accountID != null)
{
accountInfoPanel.getAccountsComboBox().setSelectedItem(
accountInfoPanel.getAccountsTable().get(accountID));
}
this.add(accountInfoPanel);
}
/**
* Presses programmatically the cancel button, when Esc key is pressed.
*
* @param isEscaped indicates if the Esc button was pressed on close
*/
@Override
protected void close(boolean isEscaped)
{
this.setVisible(false);
accountInfoPanel.dispose();
}
@Override
public void setVisible(boolean isVisible)
{
if(isVisible)
{
accountInfoPanel.setVisible(true);
}
super.setVisible(isVisible);
}
}
}

@ -14,6 +14,7 @@
import net.java.sip.communicator.plugin.desktoputil.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.plugin.accountinfo.AccountInfoMenuItemComponent.*;
import org.osgi.framework.*;
@ -26,7 +27,8 @@
*/
public class AccountInfoPanel
extends TransparentPanel
implements ServiceListener
implements ServiceListener,
RegistrationStateChangeListener
{
/**
* Serial version UID.
@ -58,13 +60,20 @@ public class AccountInfoPanel
accountsTable =
new HashMap<AccountID, AccountDetailsPanel>();
/**
* The parent dialog.
*/
private AccountInfoDialog dialog;
/**
* Creates an instance of <tt>AccountInfoPanel</tt> that contains combo box
* component with active user accounts and <tt>AccountDetailsPanel</tt> to
* display and edit account information.
*/
public AccountInfoPanel()
public AccountInfoPanel(AccountInfoDialog dialog)
{
this.dialog = dialog;
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
accountsComboBox = new JComboBox();
@ -112,8 +121,13 @@ public void itemStateChanged(ItemEvent e)
add(centerPanel);
}
/**
* Initialize.
*/
private void init()
{
AccountInfoActivator.bundleContext.addServiceListener(this);
for (ProtocolProviderFactory providerFactory : AccountInfoActivator
.getProtocolProviderFactories().values())
{
@ -130,19 +144,34 @@ private void init()
protocolProvider = (ProtocolProviderService)AccountInfoActivator
.bundleContext.getService(serRef);
currentDetailsPanel = new AccountDetailsPanel(protocolProvider);
currentDetailsPanel = new AccountDetailsPanel(
dialog,
protocolProvider);
accountsTable.put(
protocolProvider.getAccountID(), currentDetailsPanel);
accountsComboBox.addItem(currentDetailsPanel);
protocolProvider.addRegistrationStateChangeListener(
new RegistrationStateChangeListenerImpl());
protocolProvider.addRegistrationStateChangeListener(this);
}
}
}
/**
* Clears all listeners.
*/
public void dispose()
{
AccountInfoActivator.bundleContext.removeServiceListener(this);
for(AccountDetailsPanel pan : accountsTable.values())
{
pan.getProtocolProvider()
.removeRegistrationStateChangeListener(this);
}
}
/**
* A custom renderer to display properly <tt>AccountDetailsPanel</tt>
* in a combo box.
@ -179,57 +208,52 @@ public Component getListCellRendererComponent(
}
}
private class RegistrationStateChangeListenerImpl
implements RegistrationStateChangeListener
public void registrationStateChanged(final RegistrationStateChangeEvent evt)
{
public void registrationStateChanged(
final RegistrationStateChangeEvent evt)
if(!SwingUtilities.isEventDispatchThread())
{
if(!SwingUtilities.isEventDispatchThread())
SwingUtilities.invokeLater(new Runnable()
{
SwingUtilities.invokeLater(new Runnable()
public void run()
{
public void run()
{
registrationStateChanged(evt);
}
});
return;
}
registrationStateChanged(evt);
}
});
return;
}
ProtocolProviderService protocolProvider = evt.getProvider();
ProtocolProviderService protocolProvider = evt.getProvider();
if (evt.getNewState() == RegistrationState.REGISTERED)
if (evt.getNewState() == RegistrationState.REGISTERED)
{
if (accountsTable.containsKey(protocolProvider.getAccountID()))
{
if (accountsTable.containsKey(protocolProvider.getAccountID()))
{
AccountDetailsPanel detailsPanel
= accountsTable.get(protocolProvider.getAccountID());
detailsPanel.loadDetails();
}
else
{
AccountDetailsPanel panel =
new AccountDetailsPanel(protocolProvider);
accountsTable.put(protocolProvider.getAccountID(), panel);
accountsComboBox.addItem(panel);
}
AccountDetailsPanel detailsPanel
= accountsTable.get(protocolProvider.getAccountID());
detailsPanel.loadDetails();
}
else if (evt.getNewState() == RegistrationState.UNREGISTERING)
else
{
AccountDetailsPanel panel
= accountsTable.get(protocolProvider.getAccountID());
if (panel != null)
AccountDetailsPanel panel =
new AccountDetailsPanel(dialog, protocolProvider);
accountsTable.put(protocolProvider.getAccountID(), panel);
accountsComboBox.addItem(panel);
}
}
else if (evt.getNewState() == RegistrationState.UNREGISTERING)
{
AccountDetailsPanel panel
= accountsTable.get(protocolProvider.getAccountID());
if (panel != null)
{
accountsTable.remove(protocolProvider.getAccountID());
accountsComboBox.removeItem(panel);
if (currentDetailsPanel == panel)
{
accountsTable.remove(protocolProvider.getAccountID());
accountsComboBox.removeItem(panel);
if (currentDetailsPanel == panel)
{
currentDetailsPanel = null;
centerPanel.removeAll();
centerPanel.revalidate();
centerPanel.repaint();
}
currentDetailsPanel = null;
centerPanel.removeAll();
centerPanel.revalidate();
centerPanel.repaint();
}
}
}
@ -276,11 +300,10 @@ public void run()
if (accountsTable.get(protocolProvider.getAccountID()) == null)
{
AccountDetailsPanel panel =
new AccountDetailsPanel(protocolProvider);
new AccountDetailsPanel(dialog, protocolProvider);
accountsTable.put(protocolProvider.getAccountID(), panel);
accountsComboBox.addItem(panel);
protocolProvider.addRegistrationStateChangeListener(
new RegistrationStateChangeListenerImpl());
protocolProvider.addRegistrationStateChangeListener(this);
}
}
// If the protocol provider is being unregistered we have to remove

Loading…
Cancel
Save