diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/files/ArchiveFilePanel.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/files/ArchiveFilePanel.java index 8e0fbe8cb..f66f27a1f 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/files/ArchiveFilePanel.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/files/ArchiveFilePanel.java @@ -696,6 +696,8 @@ import com.jdimension.jlawyer.client.events.DocumentAddedEvent; import com.jdimension.jlawyer.client.events.Event; import com.jdimension.jlawyer.client.events.EventBroker; +import com.jdimension.jlawyer.client.events.InstantMessageDeletedEvent; +import com.jdimension.jlawyer.client.events.NewInstantMessagesEvent; import com.jdimension.jlawyer.client.events.ReviewAddedEvent; import com.jdimension.jlawyer.client.launcher.CaseDocumentStore; import com.jdimension.jlawyer.client.launcher.CustomLauncher; @@ -989,6 +991,8 @@ public ArchiveFilePanel() { EventBroker b = EventBroker.getInstance(); b.subscribeConsumer(this, Event.TYPE_DOCUMENTADDED); b.subscribeConsumer(this, Event.TYPE_REVIEWADDED); + b.subscribeConsumer(this, Event.TYPE_INSTANTMESSAGING_MESSAGEDELETED); + b.subscribeConsumer(this, Event.TYPE_INSTANTMESSAGING_NEWMESSAGES); } @@ -3715,6 +3719,17 @@ public void showDocumentsPopup(MouseEvent evt) { } public void addMessageToView(InstantMessage msg) { + // check if message has already been added + for(Component c: this.pnlMessages.getComponents()) { + if(c instanceof MessagePanel) { + InstantMessage existingMessage=((MessagePanel)c).getMessage(); + if(existingMessage.getId().equals(msg.getId())) { + return; + } + } + } + + MessagePanel mp1 = new MessagePanel(UserSettings.getInstance().getLoginEnabledUsers(), UserSettings.getInstance().getCurrentUser().getPrincipalId(), UserSettings.getInstance().getCurrentUser().getPrincipalId().equalsIgnoreCase(msg.getSender()), msg); mp1.setAlignmentX(JPanel.LEFT_ALIGNMENT); mp1.setContextForeground(DefaultColorTheme.COLOR_DARK_GREY); @@ -5917,9 +5932,10 @@ private void mnuSendMessageForDocumentActionPerformed(java.awt.event.ActionEvent if(selectedDocs.isEmpty()) return; - SendInstantMessageDialog dlg=new SendInstantMessageDialog(EditorsRegistry.getInstance().getMainWindow(), true, this.dto, selectedDocs, this); + SendInstantMessageDialog dlg=new SendInstantMessageDialog(EditorsRegistry.getInstance().getMainWindow(), true, this.dto, selectedDocs); FrameUtils.centerDialog(dlg, EditorsRegistry.getInstance().getMainWindow()); dlg.setVisible(true); + }//GEN-LAST:event_mnuSendMessageForDocumentActionPerformed @@ -6169,6 +6185,36 @@ public void onEvent(Event e) { } } } + } else if (e instanceof InstantMessageDeletedEvent) { + + boolean removed = false; + for (int i = 0; i < this.pnlMessages.getComponentCount(); i++) { + if (this.pnlMessages.getComponent(i) instanceof MessagePanel) { + if (((MessagePanel) this.pnlMessages.getComponent(i)).getMessage().getId().equals(((InstantMessageDeletedEvent)e).getMessageId())) { + this.pnlMessages.remove(this.pnlMessages.getComponent(i)); + removed = true; + break; + } + } + } + if (removed) { + this.pnlMessages.revalidate(); + } + + + + } else if (e instanceof NewInstantMessagesEvent) { + SwingUtilities.invokeLater(() -> { + if (((NewInstantMessagesEvent) e).getNewMessages() != null) { + for (InstantMessage msg : ((NewInstantMessagesEvent) e).getNewMessages()) { + if(msg.getCaseContext() != null && this.dto!=null) { + if (msg.getCaseContext().getId().equals(this.dto.getId())) { + this.addMessageToView(msg); + } + } + } + } + }); } } diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/MessagePollingTimerTask.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/MessagePollingTimerTask.java index 784f2dbac..b89702ba6 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/MessagePollingTimerTask.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/MessagePollingTimerTask.java @@ -686,8 +686,6 @@ public class MessagePollingTimerTask extends java.util.TimerTask { private long lastMessageTimestamp=-1; private long lastMentionStatusChangedTimestamp=-1; - protected static long unseenByUser=0; - /** * Creates a new instance of MessagePollingTimerTask * @param latestMessage @@ -740,18 +738,4 @@ public void run() { } } - /** - * @return the unseenByUser - */ - public static synchronized long getUnseenByUser() { - return unseenByUser; - } - - /** - * @param aUnseenByUser the unseenByUser to set - */ - public static synchronized void setUnseenByUser(long aUnseenByUser) { - unseenByUser = aUnseenByUser; - } - } diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/MessagingCenterPanel.form b/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/MessagingCenterPanel.form index f01b19453..6aa052a31 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/MessagingCenterPanel.form +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/MessagingCenterPanel.form @@ -188,6 +188,11 @@ + + + + + diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/MessagingCenterPanel.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/MessagingCenterPanel.java index ff5ed917d..6fef12c26 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/MessagingCenterPanel.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/MessagingCenterPanel.java @@ -676,6 +676,8 @@ import com.jdimension.jlawyer.client.settings.ServerSettings; import com.jdimension.jlawyer.client.settings.UserSettings; import com.jdimension.jlawyer.client.utils.FrameUtils; +import com.jdimension.jlawyer.client.utils.StringUtils; +import com.jdimension.jlawyer.persistence.ArchiveFileBean; import com.jdimension.jlawyer.persistence.InstantMessage; import com.jdimension.jlawyer.persistence.InstantMessageMention; import com.jdimension.jlawyer.services.JLawyerServiceLocator; @@ -713,6 +715,7 @@ public class MessagingCenterPanel extends javax.swing.JPanel implements Themeabl private static final Logger log = Logger.getLogger(MessagingCenterPanel.class.getName()); private static final int SCROLLPANE_VERTICAL_INCREMENT = 16; + private static final String CLIENTPROPERTY_CASECONTEXT="tab.casecontext"; private Image backgroundImage = null; @@ -732,6 +735,8 @@ public MessagingCenterPanel() { this.initializing = true; initComponents(); + + this.tabsPane.putClientProperty("JTabbedPane.maximumTabWidth", 200); this.jScrollPane1.getViewport().setOpaque(false); this.jScrollPane1.getVerticalScrollBar().setUnitIncrement(SCROLLPANE_VERTICAL_INCREMENT); @@ -916,6 +921,7 @@ public void valueChanged(javax.swing.event.ListSelectionEvent evt) { jScrollPane1.setViewportView(lstHashtags); tabsPane.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT); + tabsPane.setFont(tabsPane.getFont()); jScrollPane3.setBorder(null); jScrollPane3.setOpaque(false); @@ -1015,7 +1021,7 @@ public void mouseClicked(java.awt.event.MouseEvent evt) { .add(cmbDownloadInstantMessages, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) - .add(jScrollPane1) + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE) .add(lblClearHashtagSelection, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) @@ -1232,9 +1238,12 @@ private void addToTabIfRequired(InstantMessage msg) { int existingTab = -1; for (int i = 0; i < this.tabsPane.getTabCount(); i++) { - if (tabsPane.getTitleAt(i).equals(msg.getCaseContext().getFileNumber())) { - existingTab = i; - break; + Object caseContext=((JScrollPane)tabsPane.getComponentAt(i)).getClientProperty(CLIENTPROPERTY_CASECONTEXT); + if(caseContext!=null && caseContext instanceof ArchiveFileBean) { + if(((ArchiveFileBean)caseContext).getId().equals(msg.getCaseContext().getId())) { + existingTab = i; + break; + } } } @@ -1253,7 +1262,9 @@ private void addToTabIfRequired(InstantMessage msg) { targetScroll.getViewport().setOpaque(false); targetScroll.setBorder(null); targetScroll.setOpaque(false); - tabsPane.addTab(msg.getCaseContext().getFileNumber(), targetScroll); + targetScroll.putClientProperty(CLIENTPROPERTY_CASECONTEXT, msg.getCaseContext()); + tabsPane.addTab(getTabTitleForMessage(msg), targetScroll); + tabsPane.setToolTipTextAt(tabsPane.getTabCount()-1, this.getTooltipForTab(msg.getCaseContext())); existingTab = tabsPane.getTabCount() - 1; } else { @@ -1272,7 +1283,7 @@ private void addToTabIfRequired(InstantMessage msg) { if (msg.getSent().getTime() > tab4latest.getTime()) { // move tab to the left tabsPane.removeTabAt(existingTab); - tabsPane.insertTab(msg.getCaseContext().getFileNumber(), null, targetScroll, null, 3); + tabsPane.insertTab(getTabTitleForMessage(msg), null, targetScroll, null, 3); } } } @@ -1290,6 +1301,23 @@ private void addToTabIfRequired(InstantMessage msg) { } } + + private String getTabTitleForMessage(InstantMessage m) { + StringBuilder sb=new StringBuilder(); + String name=m.getCaseContext().getName(); + name=StringUtils.cutoff(name,20); + sb.append("").append(m.getCaseContext().getFileNumber()).append("
").append(name).append(""); + return sb.toString(); + } + + private String getTooltipForTab(ArchiveFileBean caseContext) { + if(caseContext==null) + return null; + StringBuilder sb=new StringBuilder(); + //sb.append("").append(caseContext.getFileNumber()).append("
").append(caseContext.getName()).append("
").append(caseContext.getReason()).append(""); + sb.append(caseContext.getFileNumber()).append(System.lineSeparator()).append(caseContext.getName()).append(System.lineSeparator()).append(caseContext.getReason()); + return sb.toString(); + } private void addToMentioningTabsIfRequired(InstantMessage msg) { @@ -1349,14 +1377,11 @@ public void newMessageForSubmission(InstantMessage msg) { JScrollPane sp = (JScrollPane) this.tabsPane.getComponentAt(tabIndex); JPanel messagesInTab = (JPanel) sp.getViewport().getComponent(0); - for (int i = 0; i < messagesInTab.getComponentCount(); i++) { - if (messagesInTab.getComponent(i) instanceof MessagePanel) { - if (((MessagePanel) messagesInTab.getComponent(i)).getMessage().getCaseContext()!=null) { - msg.setCaseContext(((MessagePanel) messagesInTab.getComponent(i)).getMessage().getCaseContext()); - break; - } - } + Object caseContext=sp.getClientProperty(CLIENTPROPERTY_CASECONTEXT); + if(caseContext!=null) { + msg.setCaseContext((ArchiveFileBean)caseContext); } + } diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/OpenMessageMentionsTimerTask.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/OpenMessageMentionsTimerTask.java index 443d1b96f..c145de20f 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/OpenMessageMentionsTimerTask.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/OpenMessageMentionsTimerTask.java @@ -666,6 +666,7 @@ import com.jdimension.jlawyer.client.events.EventBroker; import com.jdimension.jlawyer.client.events.OpenMentionsEvent; import com.jdimension.jlawyer.client.settings.ClientSettings; +import com.jdimension.jlawyer.client.settings.UserSettings; import com.jdimension.jlawyer.services.JLawyerServiceLocator; import org.apache.log4j.Logger; @@ -691,7 +692,7 @@ public void run() { try { ClientSettings settings = ClientSettings.getInstance(); JLawyerServiceLocator locator = JLawyerServiceLocator.getInstance(settings.getLookupProperties()); - int openMentions = locator.lookupMessagingServiceRemote().getNumberOfOpenMentions(); + int openMentions = locator.lookupMessagingServiceRemote().getNumberOfOpenMentions(UserSettings.getInstance().getCurrentUser().getPrincipalId()); EventBroker eb = EventBroker.getInstance(); eb.publishEvent(new OpenMentionsEvent(openMentions)); diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/SendInstantMessageDialog.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/SendInstantMessageDialog.java index e4c3bf810..abdccad69 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/SendInstantMessageDialog.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/messenger/SendInstantMessageDialog.java @@ -685,7 +685,6 @@ public class SendInstantMessageDialog extends javax.swing.JDialog implements New private ArrayList documentContexts = null; private ArchiveFileBean caseContext=null; - /** * Creates new form SendInstantMessageDialog * @@ -846,4 +845,5 @@ public void newMessageForSubmission(InstantMessage msg) { this.setVisible(false); this.dispose(); } + } diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/utils/StringUtils.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/utils/StringUtils.java index 98b7e97f8..bd4bbc3f0 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/utils/StringUtils.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/utils/StringUtils.java @@ -700,6 +700,12 @@ public static String nonNull(String s) { s=""; return s; } + + public static String cutoff(String name, int maxLength) { + if(name.length()>maxLength) + name=name.substring(0,maxLength-1) + "..."; + return name; + } static class SortIgnoreCase implements Comparator { public int compare(Object o1, Object o2) { diff --git a/j-lawyer-server-api/src/com/jdimension/jlawyer/services/MessagingServiceRemote.java b/j-lawyer-server-api/src/com/jdimension/jlawyer/services/MessagingServiceRemote.java index 2c4231098..cff8a4aad 100644 --- a/j-lawyer-server-api/src/com/jdimension/jlawyer/services/MessagingServiceRemote.java +++ b/j-lawyer-server-api/src/com/jdimension/jlawyer/services/MessagingServiceRemote.java @@ -689,6 +689,7 @@ public interface MessagingServiceRemote { InstantMessage getMessage(String id) throws Exception; int getNumberOfOpenMentions() throws Exception; + int getNumberOfOpenMentions(String principalId) throws Exception; List getUpdatedMentionsSince(Date since) throws Exception; diff --git a/j-lawyer-server-entities/src/java/com/jdimension/jlawyer/persistence/InstantMessageMention.java b/j-lawyer-server-entities/src/java/com/jdimension/jlawyer/persistence/InstantMessageMention.java index 2e73c4fbf..5d1d0d622 100644 --- a/j-lawyer-server-entities/src/java/com/jdimension/jlawyer/persistence/InstantMessageMention.java +++ b/j-lawyer-server-entities/src/java/com/jdimension/jlawyer/persistence/InstantMessageMention.java @@ -680,6 +680,7 @@ @NamedQuery(name = "InstantMessageMention.findSince", query = "SELECT a FROM InstantMessageMention a WHERE a.statusChanged > :since order by a.statusChanged asc"), @NamedQuery(name = "InstantMessageMention.findById", query = "SELECT a FROM InstantMessageMention a WHERE a.id = :id"), @NamedQuery(name = "InstantMessageMention.findOpen", query = "SELECT a FROM InstantMessageMention a WHERE a.done = 0"), + @NamedQuery(name = "InstantMessageMention.findOpenByPrincipal", query = "SELECT a FROM InstantMessageMention a WHERE a.done = 0 and a.principal = :principal"), @NamedQuery(name = "InstantMessageMention.findByMessage", query = "SELECT a FROM InstantMessageMention a WHERE a.message = :message")}) public class InstantMessageMention implements Serializable { diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/InstantMessageMentionFacade.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/InstantMessageMentionFacade.java index 11cef95ab..e49f1f3ed 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/InstantMessageMentionFacade.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/InstantMessageMentionFacade.java @@ -695,6 +695,13 @@ public List findOpen() { } + @Override + public List findOpen(String principalId) { + + return (List) em.createNamedQuery("InstantMessageMention.findOpenByPrincipal").setParameter("principal", principalId).getResultList(); + + } + @Override public List findSince(Date since) { diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/InstantMessageMentionFacadeLocal.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/InstantMessageMentionFacadeLocal.java index cf7ffa2ce..dd7170b9b 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/InstantMessageMentionFacadeLocal.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/InstantMessageMentionFacadeLocal.java @@ -687,6 +687,7 @@ public interface InstantMessageMentionFacadeLocal { List findRange(int[] range); List findOpen(); + List findOpen(String principalId); int count(); diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/MessagingService.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/MessagingService.java index 415bc24c1..db0fc3d48 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/MessagingService.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/MessagingService.java @@ -800,7 +800,8 @@ public List getMessagesSince(Date since) throws Exception { } else { this.singleton.setLatestInstantMessageReceived(since.getTime()); } - return messages; + + return filterForRelevantMessages(messages, this.context.getCallerPrincipal().getName()); } else if(since.getTime() messages=this.messageFacade.findSince(since); @@ -809,11 +810,41 @@ public List getMessagesSince(Date since) throws Exception { } else { this.singleton.setLatestInstantMessageReceived(since.getTime()); } - return messages; + return filterForRelevantMessages(messages, this.context.getCallerPrincipal().getName()); } else { return null; } } + + private List filterForRelevantMessages(List unfiltered, String principalId) { + ArrayList filtered=new ArrayList<>(); + for(InstantMessage m: unfiltered) { + if(messageRelevantForUser(m, principalId)) + filtered.add(m); + } + return filtered; + } + + private boolean messageRelevantForUser(InstantMessage m, String principalId) { + // message sent in a case context + if(m.getCaseContext()!=null) + return true; + + // message sent by the user + if(m.getSender()!=null && m.getSender().equals(principalId)) + return true; + + // user has been mentioned + if(m.getMentionFor(principalId)!=null) + return true; + + // no case context, sent to all + if(m.getCaseContext()==null && !m.hasMentions()) + return true; + + return false; + + } @Override @RolesAllowed({"loginRole"}) @@ -862,6 +893,17 @@ public int getNumberOfOpenMentions() throws Exception { } return openCount; } + + @Override + @RolesAllowed({"loginRole"}) + public int getNumberOfOpenMentions(String principalId) throws Exception { + List open=this.mentionFacade.findOpen(principalId); + int openCount=0; + if(open!=null) { + openCount=open.size(); + } + return openCount; + } @Override @RolesAllowed({"loginRole"})