diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties index 1cc64b94c..9175b608c 100644 --- a/resources/languages/resources.properties +++ b/resources/languages/resources.properties @@ -334,6 +334,7 @@ service.gui.MISSED_CALLS_TOOL_TIP=Missed calls from: service.gui.MISSED_CALLS_MORE_TOOL_TIP= and {0} more service.gui.MODERATOR=moderator service.gui.MORE=See more +service.gui.MORE_LABEL=More service.gui.MOVE=Move service.gui.MOVE_SUBCONTACT=M&ove contact service.gui.MOVE_SUBCONTACT_MSG=Select the contact or the group, where you would like to move the selected contact. diff --git a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableDialog.java b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableDialog.java index f574f66ae..cf563a0d1 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableDialog.java @@ -9,18 +9,17 @@ import java.awt.*; import java.awt.event.*; import java.util.*; -import java.util.List; import javax.swing.*; +import javax.swing.border.*; import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.main.*; import net.java.sip.communicator.impl.gui.main.chat.*; import net.java.sip.communicator.plugin.desktoputil.*; -import net.java.sip.communicator.plugin.desktoputil.SwingWorker; -import net.java.sip.communicator.plugin.desktoputil.chat.*; import net.java.sip.communicator.service.muc.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.*; /** @@ -46,13 +45,6 @@ public class ChatRoomTableDialog */ private JComboBox providersCombo; - /** - * An editable JComboBox which will allow to set a room name, and gives - * suggestions regarding to its content. - */ - private JComboBox roomsCombo = null; - - /** * The ok button. */ @@ -71,10 +63,28 @@ public class ChatRoomTableDialog /** * The editor for the chat room name. */ - private JTextField editor = null; - -// private final ChatRoomList chatRoomList -// = GuiActivator.getMUCService().getChatRoomList(); + private JTextField chatRoomNameField = null; + + /** + * Label that hides and shows the more fields panel on click. + */ + private JLabel cmdExpandMoreFields; + + /** + * Panel that holds the subject field and the nickname field. + */ + private JPanel moreFieldsPannel = new JPanel(new BorderLayout(5, 5)); + + /** + * The field for the nickname. + */ + private JTextField nicknameField = new JTextField(); + + /** + * Text field for the subject. + */ + private SIPCommTextField subject = new SIPCommTextField(DesktopUtilActivator + .getResources().getI18NString("service.gui.SUBJECT")); /** * The ChatRoomList.ChatRoomProviderWrapperListener instance which @@ -164,46 +174,16 @@ private void init() .getI18NString("service.gui.ACCOUNT"))); labels.add(new JLabel(GuiActivator.getResources() .getI18NString("service.gui.ROOM_NAME"))); + JPanel valuesPanel = new TransparentPanel(new GridLayout(2, 2, 5, 5)); providersCombo = createProvidersCombobox(); - - roomsCombo = new JComboBox(); - roomsCombo.setEditable(true); - roomsCombo.setPreferredSize(providersCombo.getPreferredSize()); - editor = ((JTextField)roomsCombo.getEditor().getEditorComponent()); - - // when provider is changed we load providers rooms list - // so we can show them in the combobox below - providersCombo.addItemListener(new ItemListener(){ - public void itemStateChanged(ItemEvent e) - { - if(e.getStateChange() == ItemEvent.SELECTED) - loadProviderRooms(); - } - }); - - // if a room is selected enable buttons - roomsCombo.addItemListener(new ItemListener(){ - public void itemStateChanged(ItemEvent e) - { - if(e.getStateChange() == ItemEvent.SELECTED - && roomsCombo.getSelectedIndex() > -1) - { - okButton.setEnabled(true); - } - else if((roomsCombo.getSelectedIndex() == -1 - || e.getStateChange() == ItemEvent.DESELECTED) - && editor.getText().trim().length() <= 0) - { - okButton.setEnabled(false); - } - } - }); + + chatRoomNameField = new JTextField(); valuesPanel.add(providersCombo); - valuesPanel.add(roomsCombo); - + valuesPanel.add(chatRoomNameField); + northPanel.add(labels, BorderLayout.WEST); northPanel.add(valuesPanel, BorderLayout.CENTER); northPanel.setPreferredSize(new Dimension(600, 80)); @@ -222,15 +202,13 @@ else if((roomsCombo.getSelectedIndex() == -1 eastButtonPanel.add(okButton); buttonPanel.add(eastButtonPanel, BorderLayout.EAST); - this.getContentPane().add(northPanel, BorderLayout.NORTH); - this.getContentPane().add(buttonPanel, BorderLayout.CENTER); - - loadProviderRooms(); + this.getContentPane().add(initMoreFields(), BorderLayout.CENTER); + this.getContentPane().add(buttonPanel, BorderLayout.SOUTH); // when we are typing we clear any selection in the available and saved // rooms - editor.addKeyListener(new KeyListener() { + chatRoomNameField.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent e) {} @@ -240,16 +218,94 @@ public void keyPressed(KeyEvent e) public void keyReleased(KeyEvent e) { - okButton.setEnabled((editor.getText().trim().length() > 0)); + okButton.setEnabled( + (chatRoomNameField.getText() != null + && chatRoomNameField.getText().trim().length() > 0) + && (nicknameField.getText() != null + && nicknameField.getText().trim().length() > 0)); + } + }); + + providersCombo.addItemListener(new ItemListener() + { + + @Override + public void itemStateChanged(ItemEvent event) + { + setNickname( + (ChatRoomProviderWrapper)providersCombo.getSelectedItem()); } }); - //register listener to listen for newly added chat room providers // and for removed ones GuiActivator.getMUCService().addChatRoomProviderWrapperListener( chatRoomProviderWrapperListener); } + + /** + * Sets the default value in the nickname field based on chat room provider. + * @param provider the provider + */ + private void setNickname(ChatRoomProviderWrapper provider) + { + nicknameField.setText( + GuiActivator.getMUCService().getDefaultNickname( + provider.getProtocolProvider())); + } + /** + * Constructs the more label and the fields related to the label and returns + * them. + * @return the more label and the fields related to the label + */ + private Component initMoreFields() + { + JPanel morePanel = new TransparentPanel(new BorderLayout()); + morePanel.setOpaque(false); + morePanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 5, 15)); + moreFieldsPannel.setBorder( + BorderFactory.createEmptyBorder(10, 30, 0, 0)); + moreFieldsPannel.setOpaque(false); + moreFieldsPannel.setVisible(false); + JPanel subjectPanel = new TransparentPanel(new BorderLayout()); + subject.setFont(getFont().deriveFont(12f)); + subjectPanel.add(subject,BorderLayout.NORTH); + moreFieldsPannel.add(subjectPanel, BorderLayout.CENTER); + JPanel nicknamePanel = new TransparentPanel(new BorderLayout(5, 5)); + setNickname((ChatRoomProviderWrapper)providersCombo.getSelectedItem()); + nicknamePanel.add(nicknameField, BorderLayout.CENTER); + nicknamePanel.add(new JLabel( + GuiActivator.getResources().getI18NString("service.gui.NICKNAME")), + BorderLayout.WEST); + moreFieldsPannel.add(nicknamePanel,BorderLayout.NORTH); + cmdExpandMoreFields = new JLabel(); + cmdExpandMoreFields.setBorder(new EmptyBorder(0, 5, 0, 0)); + cmdExpandMoreFields.setIcon(DesktopUtilActivator.getResources() + .getImage("service.gui.icons.RIGHT_ARROW_ICON")); + cmdExpandMoreFields.setText(DesktopUtilActivator + .getResources().getI18NString("service.gui.MORE_LABEL")); + cmdExpandMoreFields.addMouseListener(new MouseAdapter() + { + @Override + public void mouseClicked(MouseEvent e) + { + cmdExpandMoreFields.setIcon( + GuiActivator.getResources().getImage( + moreFieldsPannel.isVisible() + ? "service.gui.icons.RIGHT_ARROW_ICON" + : "service.gui.icons.DOWN_ARROW_ICON")); + + moreFieldsPannel.setVisible( + !moreFieldsPannel.isVisible()); + + pack(); + } + }); + morePanel.add(cmdExpandMoreFields,BorderLayout.NORTH); + morePanel.add(moreFieldsPannel,BorderLayout.CENTER); + return morePanel; + } + /** * Creates the providers combobox and filling its content. * @return @@ -274,18 +330,19 @@ private JComboBox createProvidersCombobox() */ public void actionPerformed(ActionEvent e) { - String[] joinOptions; String subject = null; JButton sourceButton = (JButton) e.getSource(); if(sourceButton.equals(okButton)) { - if(editor.getText() != null - && editor.getText().trim().length() > 0) + if((chatRoomNameField.getText() != null + && chatRoomNameField.getText().trim().length() > 0) + && (nicknameField.getText() != null + && nicknameField.getText().trim().length() > 0)) { ChatRoomWrapper chatRoomWrapper = GuiActivator.getMUCService().createChatRoom( - editor.getText().trim(), + chatRoomNameField.getText().trim(), getSelectedProvider().getProtocolProvider(), new ArrayList(), "", @@ -293,11 +350,11 @@ public void actionPerformed(ActionEvent e) false, false); - joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions( - chatRoomWrapper.getParentProvider().getProtocolProvider(), - chatRoomWrapper.getChatRoomID()); - String nickName = joinOptions[0]; - subject = joinOptions[1]; + String nickName = nicknameField.getText().trim(); + ConfigurationUtils.updateChatRoomProperty( + chatRoomWrapper.getParentProvider().getProtocolProvider(), + chatRoomWrapper.getChatRoomID(), "userNickName", nickName); + subject = this.subject.getText(); if(nickName == null) return; @@ -343,17 +400,6 @@ public void dispose() super.dispose(); } - /** - * Loads the rooms hosted on the selected provider. - * Loads it in different thread so it won't block the caller. - */ - public void loadProviderRooms() - { - okButton.setEnabled(false); - roomsCombo.setEnabled(false); - - new LoadProvidersWorker().start(); - } /** * Returns the selected provider in the providers combo box. @@ -412,61 +458,4 @@ public Component getListCellRendererComponent(JList list, Object value, return this; } } - - /** - * SwingWorker that will load rooms list and show them in the ui. - */ - private class LoadProvidersWorker - extends SwingWorker - { - /** - * List of rooms. - */ - private List rooms; - - /** - * Worker thread. - * @return - * @throws Exception - */ - @Override - protected Object construct() - throws - Exception - { - rooms = GuiActivator.getMUCService() - .getExistingChatRooms(getSelectedProvider()); - - return null; - } - - /** - * Called on the event dispatching thread (not on the worker thread) - * after the construct method has returned. - */ - @Override - protected void finished() - { - roomsCombo.removeAllItems(); - - // if there is no room list coming from provider - if(rooms == null) - { - roomsCombo.setEnabled(true); - //okButton.setEnabled(true); - return; - } - - Collections.sort(rooms); - - for(String room : rooms) - roomsCombo.addItem(room); - - // select nothing - roomsCombo.setSelectedIndex(-1); - - roomsCombo.setEnabled(true); - chatRoomTableDialog.pack(); - } - } } diff --git a/src/net/java/sip/communicator/impl/muc/MUCActivator.java b/src/net/java/sip/communicator/impl/muc/MUCActivator.java index cd75c8cfc..2a3642e04 100644 --- a/src/net/java/sip/communicator/impl/muc/MUCActivator.java +++ b/src/net/java/sip/communicator/impl/muc/MUCActivator.java @@ -11,6 +11,7 @@ import net.java.sip.communicator.service.contactsource.*; import net.java.sip.communicator.service.credentialsstorage.*; import net.java.sip.communicator.service.customcontactactions.*; +import net.java.sip.communicator.service.globaldisplaydetails.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.muc.*; import net.java.sip.communicator.service.protocol.*; @@ -97,6 +98,11 @@ public class MUCActivator private static ProtocolProviderRegListener protocolProviderRegListener = null; + /** + * The global display details service instance. + */ + private static GlobalDisplayDetailsService globalDisplayDetailsService; + /** * Starts this bundle. * @@ -383,4 +389,22 @@ public static UIService getUIService() } return uiService; } + + /** + * Returns the GlobalDisplayDetailsService obtained from the bundle + * context. + * @return the GlobalDisplayDetailsService obtained from the bundle + * context + */ + public static GlobalDisplayDetailsService getGlobalDisplayDetailsService() + { + if(globalDisplayDetailsService == null) + { + globalDisplayDetailsService + = ServiceUtils.getService( + bundleContext, + GlobalDisplayDetailsService.class); + } + return globalDisplayDetailsService; + } } diff --git a/src/net/java/sip/communicator/impl/muc/MUCCustomContactActionService.java b/src/net/java/sip/communicator/impl/muc/MUCCustomContactActionService.java index b0fa9427b..6b560fb28 100644 --- a/src/net/java/sip/communicator/impl/muc/MUCCustomContactActionService.java +++ b/src/net/java/sip/communicator/impl/muc/MUCCustomContactActionService.java @@ -473,6 +473,9 @@ public boolean isVisible(SourceContact actionSource) = (ChatRoomSourceContact) actionSource; ChatRoomWrapper room = MUCActivator.getMUCService() .findChatRoomWrapperFromSourceContact(contact); + if(room == null) + return false; + if(name.equals("autojoin")) return !room.isAutojoin(); diff --git a/src/net/java/sip/communicator/impl/muc/MUCServiceImpl.java b/src/net/java/sip/communicator/impl/muc/MUCServiceImpl.java index 5efeeca8d..f773d7d89 100644 --- a/src/net/java/sip/communicator/impl/muc/MUCServiceImpl.java +++ b/src/net/java/sip/communicator/impl/muc/MUCServiceImpl.java @@ -1007,4 +1007,40 @@ public void openChatRoom(ChatRoomWrapper room) MUCActivator.getUIService().openChatRoomWindow(room); } + + /** + * Returns default nickname for chat room based on the given provider. + * @param pps the given protocol provider service + * @return default nickname for chat room based on the given provider. + */ + public String getDefaultNickname(ProtocolProviderService pps) + { + final OperationSetServerStoredAccountInfo accountInfoOpSet + = pps.getOperationSet( + OperationSetServerStoredAccountInfo.class); + + String displayName = ""; + if (accountInfoOpSet != null) + { + displayName = AccountInfoUtils.getDisplayName(accountInfoOpSet); + } + + if(displayName == null || displayName.length() == 0) + { + displayName = MUCActivator.getGlobalDisplayDetailsService() + .getGlobalDisplayName(); + if(displayName == null || displayName.length() == 0) + { + displayName = pps.getAccountID().getUserID(); + if(displayName != null) + { + int atIndex = displayName.lastIndexOf("@"); + if (atIndex > 0) + displayName = displayName.substring(0, atIndex); + } + } + } + + return displayName; + } } diff --git a/src/net/java/sip/communicator/impl/muc/muc.manifest.mf b/src/net/java/sip/communicator/impl/muc/muc.manifest.mf index 21c5d9a5e..0cc32e017 100644 --- a/src/net/java/sip/communicator/impl/muc/muc.manifest.mf +++ b/src/net/java/sip/communicator/impl/muc/muc.manifest.mf @@ -16,5 +16,6 @@ Import-Package: org.osgi.framework, net.java.sip.communicator.service.gui, net.java.sip.communicator.service.customcontactactions, net.java.sip.communicator.plugin.desktoputil, - net.java.sip.communicator.plugin.desktoputil.chat + net.java.sip.communicator.plugin.desktoputil.chat, + net.java.sip.communicator.service.globaldisplaydetails Export-Package: net.java.sip.communicator.service.muc diff --git a/src/net/java/sip/communicator/plugin/desktoputil/DesktopUtilActivator.java b/src/net/java/sip/communicator/plugin/desktoputil/DesktopUtilActivator.java index 2be0ca1aa..780f82ce5 100644 --- a/src/net/java/sip/communicator/plugin/desktoputil/DesktopUtilActivator.java +++ b/src/net/java/sip/communicator/plugin/desktoputil/DesktopUtilActivator.java @@ -13,6 +13,7 @@ import net.java.sip.communicator.service.globaldisplaydetails.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.keybindings.*; +import net.java.sip.communicator.service.muc.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; @@ -57,6 +58,8 @@ public class DesktopUtilActivator static BundleContext bundleContext; + private static MUCService mucService; + /** * Calls Thread.setUncaughtExceptionHandler() * @@ -346,4 +349,21 @@ public static GlobalDisplayDetailsService getGlobalDisplayDetailsService() } return globalDisplayDetailsService; } + + /** + * Returns the MUCService obtained from the bundle context. + * + * @return the MUCService obtained from the bundle context + */ + public static MUCService getMUCService() + { + if (mucService == null) + { + mucService + = ServiceUtils.getService( + bundleContext, + MUCService.class); + } + return mucService; + } } \ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomJoinOptionsDialog.java b/src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomJoinOptionsDialog.java index cd7ed11b4..81f13ba59 100644 --- a/src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomJoinOptionsDialog.java +++ b/src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomJoinOptionsDialog.java @@ -152,32 +152,9 @@ public static String[] getJoinOptions(boolean dontDisplaySubjectFields, reasonDialog.setIcon(new ImageIcon(DesktopUtilActivator.getImage( "service.gui.icons.CHANGE_NICKNAME_16x16"))); - final OperationSetServerStoredAccountInfo accountInfoOpSet - = pps.getOperationSet( - OperationSetServerStoredAccountInfo.class); - String displayName = ""; - if (accountInfoOpSet != null) - { - displayName = AccountInfoUtils.getDisplayName(accountInfoOpSet); - } - - if(displayName == null || displayName.length() == 0) - { - displayName = DesktopUtilActivator.getGlobalDisplayDetailsService() - .getGlobalDisplayName(); - if(displayName == null || displayName.length() == 0) - { - displayName = pps.getAccountID().getUserID(); - if(displayName != null) - { - int atIndex = displayName.lastIndexOf("@"); - if (atIndex > 0) - displayName = displayName.substring(0, atIndex); - } - } - } - reasonDialog.setReasonFieldText(displayName); + reasonDialog.setReasonFieldText( + DesktopUtilActivator.getMUCService().getDefaultNickname(pps)); int result = reasonDialog.showDialog(); diff --git a/src/net/java/sip/communicator/plugin/desktoputil/desktoputil.manifest.mf b/src/net/java/sip/communicator/plugin/desktoputil/desktoputil.manifest.mf index 91f2af6ff..9a912fbf9 100644 --- a/src/net/java/sip/communicator/plugin/desktoputil/desktoputil.manifest.mf +++ b/src/net/java/sip/communicator/plugin/desktoputil/desktoputil.manifest.mf @@ -60,7 +60,8 @@ Import-Package: com.sun.awt, sun.awt.shell, sun.net.dns, sun.net.util, - net.java.sip.communicator.service.globaldisplaydetails + net.java.sip.communicator.service.globaldisplaydetails, + net.java.sip.communicator.service.muc Export-Package: net.java.sip.communicator.plugin.desktoputil, net.java.sip.communicator.plugin.desktoputil.border, net.java.sip.communicator.plugin.desktoputil.event, diff --git a/src/net/java/sip/communicator/service/muc/MUCService.java b/src/net/java/sip/communicator/service/muc/MUCService.java index 646a30c16..3f93ea933 100644 --- a/src/net/java/sip/communicator/service/muc/MUCService.java +++ b/src/net/java/sip/communicator/service/muc/MUCService.java @@ -287,5 +287,13 @@ public abstract ChatRoomWrapper findChatRoomWrapperFromChatRoom( * @param room the chat room. */ public abstract void openChatRoom(ChatRoomWrapper room); + + /** + * Returns default nickname for chat room based on the given provider. + * @param pps the given protocol provider service + * @return default nickname for chat room based on the given provider. + */ + public abstract String getDefaultNickname( + ProtocolProviderService pps); }