KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > widgets > connection > ConnectionUniversalListener


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.common.widgets.connection;
22
23
24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
25 import org.apache.directory.ldapstudio.browser.core.events.BookmarkUpdateEvent;
26 import org.apache.directory.ldapstudio.browser.core.events.BookmarkUpdateListener;
27 import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateEvent;
28 import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateListener;
29 import org.apache.directory.ldapstudio.browser.core.events.EntryModificationEvent;
30 import org.apache.directory.ldapstudio.browser.core.events.EntryUpdateListener;
31 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
32 import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateEvent;
33 import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateListener;
34 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
35 import org.eclipse.jface.viewers.StructuredSelection;
36 import org.eclipse.jface.viewers.TableViewer;
37
38
39 /**
40  * The ConnectionUniversalListener manages all events for the connection widget.
41  *
42  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
43  * @version $Rev$, $Date$
44  */

45 public class ConnectionUniversalListener implements ConnectionUpdateListener, EntryUpdateListener,
46     SearchUpdateListener, BookmarkUpdateListener
47 {
48
49     /** The table viewer */
50     protected TableViewer viewer;
51
52
53     /**
54      * Creates a new instance of ConnectionUniversalListener.
55      *
56      * @param viewer the table viewer
57      */

58     public ConnectionUniversalListener( TableViewer viewer )
59     {
60         this.viewer = viewer;
61
62         EventRegistry.addConnectionUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner() );
63         EventRegistry.addEntryUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner() );
64         EventRegistry.addSearchUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner() );
65         EventRegistry.addBookmarkUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner() );
66     }
67
68
69     /**
70      * Disposes this universal listener.
71      */

72     public void dispose()
73     {
74         if ( viewer != null )
75         {
76             EventRegistry.removeConnectionUpdateListener( this );
77             EventRegistry.removeEntryUpdateListener( this );
78             EventRegistry.removeSearchUpdateListener( this );
79             EventRegistry.removeBookmarkUpdateListener( this );
80             viewer = null;
81         }
82     }
83
84
85     /**
86      * {@inheritDoc}
87      *
88      * This implementation refreshes the viewer. If a new connection was added
89      * this connection is selected.
90      */

91     public void connectionUpdated( ConnectionUpdateEvent connectionUpdateEvent )
92     {
93         if ( viewer != null )
94         {
95             viewer.refresh();
96             if ( connectionUpdateEvent.getDetail() == ConnectionUpdateEvent.EventDetail.CONNECTION_ADDED )
97             {
98                 viewer.setSelection( new StructuredSelection( connectionUpdateEvent.getConnection() ) );
99             }
100         }
101     }
102
103
104     /**
105      * {@inheritDoc}
106      *
107      * This implementation refreshes the viewer.
108      */

109     public void entryUpdated( EntryModificationEvent event )
110     {
111         if ( viewer != null )
112         {
113             viewer.refresh();
114         }
115     }
116
117
118     /**
119      * {@inheritDoc}
120      *
121      * This implementation refreshes the viewer.
122      */

123     public void searchUpdated( SearchUpdateEvent searchUpdateEvent )
124     {
125         if ( viewer != null )
126         {
127             viewer.refresh();
128
129             // select the right connection
130
ISearch search = searchUpdateEvent.getSearch();
131             viewer.setSelection( new StructuredSelection( search.getConnection() ), true );
132         }
133     }
134
135
136     /**
137      * {@inheritDoc}
138      *
139      * This implementation refreshes the viewer.
140      */

141     public void bookmarkUpdated( BookmarkUpdateEvent bookmarkUpdateEvent )
142     {
143         if ( viewer != null )
144         {
145             viewer.refresh();
146         }
147     }
148
149 }
150
Popular Tags