aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/ShowMoreContact.java
blob: d3ed3da01ed5f184af753b574df8554c7e9e326b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.gui.main.contactlist.contactsource;

import java.util.*;

import javax.swing.*;

import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.main.contactlist.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactsource.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.gui.event.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.swing.*;

/**
 * 
 * @author Yana Stamcheva
 */
public class ShowMoreContact
    extends UIContactImpl
    implements ContactListListener
{
    /**
     * The string associated with this contact.
     */
    private final String showMoreString
        = GuiActivator.getResources().getI18NString("service.gui.SHOW_MORE");

    /**
     * The parent group.
     */
    private UIGroup parentGroup;

    /**
     * The contact node corresponding to this contact.
     */
    private ContactNode contactNode;

    /**
     * The parent contact query, which added the contact.
     */
    private final ContactQuery contactQuery;

    /**
     * The query results.
     */
    private final List<SourceContact> queryResults;

    /**
     * The count of shown contacts corresponding to the underlying query.
     */
    private int shownResultsCount = UIFilterQuery.MAX_EXTERNAL_RESULT_COUNT;

    /**
     * Creates an instance of <tt>MoreInfoContact</tt>.
     *
     * @param contactQuery
     * @param queryResults
     */
    public ShowMoreContact( ContactQuery contactQuery,
                            List<SourceContact> queryResults)
    {
        this.contactQuery = contactQuery;
        this.queryResults = queryResults;

        GuiActivator.getContactList().addContactListListener(this);
    }

    /**
     * Returns the descriptor of this contact.
     *
     * @return the descriptor of this contact
     */
    public Object getDescriptor()
    {
        return showMoreString;
    }

    /**
     * Returns an empty string to indicate that this contact has no display
     * name.
     *
     * @return an empty string
     */
    public String getDisplayName()
    {
        return "";
    }

    /**
     * Returns null to indicate that there are no display details.
     *
     * @return null
     */
    public String getDisplayDetails()
    {
        return null;
    }

    /**
     * Returns Integer.MAX_VALUE to indicate that this contact should be placed
     * at the end of its parent group.
     *
     * @return Integer.MAX_VALUE
     */
    public int getSourceIndex()
    {
        return Integer.MAX_VALUE;
    }

    /**
     * Returns null to indicate that this contact has no avatar.
     *
     * @param isSelected indicates if the contact is selected
     * @param width avatar width
     * @param height avatar height
     * @return null
     */
    public ImageIcon getAvatar(boolean isSelected, int width, int height)
    {
        return null;
    }

    /**
     * Returns null to indicate that this contact has no status icon.
     *
     * @return null
     */
    public ImageIcon getStatusIcon()
    {
        return null;
    }

    /**
     * Returns an extended tooltip for this contact.
     *
     * @return the created tooltip
     */
    public ExtendedTooltip getToolTip()
    {
        ExtendedTooltip tooltip = new ExtendedTooltip(
            GuiActivator.getUIService().getMainFrame(), false);

        tooltip.setTitle(GuiActivator.getResources()
            .getI18NString("service.gui.SHOW_MORE_TOOLTIP"));

        return tooltip;
    }

    /**
     * Returns null to indicate that this contact has no right button menu.
     *
     * @return null
     */
    public JPopupMenu getRightButtonMenu()
    {
        return null;
    }

    /**
     * Returns the parent group of this contact.
     *
     * @return the parent group of this contact
     */
    public UIGroup getParentGroup()
    {
        return parentGroup;
    }

    /**
     * Sets the parent group of this contact
     *
     * @param parentGroup the parent group of this contact
     */
    public void setParentGroup(UIGroup parentGroup)
    {
        this.parentGroup = parentGroup;
    }

    /**
     * Returns null to indicate that this contact cannot be searched.
     *
     * @return null
     */
    public Iterator<String> getSearchStrings()
    {
        return null;
    }

    /**
     * Returns the corresponding contact node.
     *
     * @return the corresponding contact node
     */
    public ContactNode getContactNode()
    {
        return contactNode;
    }

    /**
     * Sets the corresponding contact node.
     *
     * @param contactNode the contact node to set
     */
    public void setContactNode(ContactNode contactNode)
    {
        this.contactNode = contactNode;
    }

    /**
     * Returns null to indicate that this contact has no contact details.
     *
     * @param opSetClass the <tt>OperationSet</tt> class, which details we're
     * looking for
     * @return null
     */
    public UIContactDetail getDefaultContactDetail(
        Class<? extends OperationSet> opSetClass)
    {
        return null;
    }

    /**
     * Returns null to indicate that this contact has no contact details.
     *
     * @return null
     */
    public List<UIContactDetail> getContactDetails()
    {
        return null;
    }

    /**
     * Returns null to indicate that this contact has no contact details.
     *
     * @param opSetClass the <tt>OperationSet</tt> class, which details we're
     * looking for
     * @return null
     */
    public List<UIContactDetail> getContactDetailsForOperationSet(
        Class<? extends OperationSet> opSetClass)
    {
        return null;
    }

    /**
     * Indicates that a contact has been clicked in the contact list. Show some
     * more contacts after the "show more" has been clicked
     *
     * @param evt the <tt>ContactListEvent</tt> that notified us
     */
    public void contactClicked(ContactListEvent evt)
    {
        if (evt.getSourceContact().equals(this))
        {
            List<SourceContact> contacts
                = new ArrayList<SourceContact>(queryResults);

            int newCount
                = shownResultsCount + UIFilterQuery.MAX_EXTERNAL_RESULT_COUNT;

            int resultSize = contacts.size();

            int maxCount = (resultSize > newCount) ? newCount : resultSize;

            GuiActivator.getContactList().removeContact(this);

            for (int i = shownResultsCount; i < maxCount; i++)
            {
                GuiActivator.getContactList().contactReceived(
                    new ContactReceivedEvent(contactQuery, contacts.get(i)));
            }

            shownResultsCount = maxCount;

            if (shownResultsCount < resultSize
                || contactQuery.getStatus() != ContactQuery.QUERY_COMPLETED)
                GuiActivator.getContactList().addContact(
                    contactQuery,
                    this,
                    GuiActivator.getContactList().getContactSource(
                        contactQuery.getContactSource()).getUIGroup(),
                    false);

        }
    }

    public void groupClicked(ContactListEvent evt) {}

    /**
     * We're not interested in group selection events here.
     */
    public void groupSelected(ContactListEvent evt) {}

    /**
     * We're not interested in contact selection events here.
     */
    public void contactSelected(ContactListEvent evt) {}

    /**
     * Returns all custom action buttons for this meta contact.
     *
     * @return a list of all custom action buttons for this meta contact
     */
    public Collection<SIPCommButton> getContactCustomActionButtons()
    {
        return null;
    }
}