summaryrefslogtreecommitdiff
path: root/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java
blob: 527fc67be3b5999c73bae1cd00dbec0cf50e8c85 (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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */
package org.apache.qpid.management.ui.views;

import static org.apache.qpid.management.ui.Constants.ATTRIBUTES;
import static org.apache.qpid.management.ui.Constants.CONNECTION;
import static org.apache.qpid.management.ui.Constants.EXCHANGE;
import static org.apache.qpid.management.ui.Constants.EXCHANGE_TYPE;
import static org.apache.qpid.management.ui.Constants.NOTIFICATIONS;
import static org.apache.qpid.management.ui.Constants.QUEUE;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

import javax.management.MBeanServerConnection;

import org.apache.qpid.management.ui.ApplicationRegistry;
import org.apache.qpid.management.ui.ManagedServer;
import org.apache.qpid.management.ui.ServerRegistry;
import org.apache.qpid.management.ui.jmx.JMXManagedObject;
import org.apache.qpid.management.ui.jmx.MBeanUtility;
import org.apache.qpid.management.ui.model.NotificationInfoModel;
import org.apache.qpid.management.ui.model.OperationData;
import org.apache.qpid.management.ui.model.OperationDataModel;
import org.apache.qpid.management.ui.views.queue.QueueOperationsTabControl;
import org.apache.qpid.management.ui.views.type.ConnectionTypeTabControl;
import org.apache.qpid.management.ui.views.type.ExchangeTypeTabControl;
import org.apache.qpid.management.ui.views.type.QueueTypeTabControl;
import org.apache.qpid.management.ui.views.users.UserManagementTabControl;
import org.apache.qpid.management.ui.views.vhost.VHostTabControl;
import org.apache.qpid.management.ui.views.connection.ConnectionOperationsTabControl;
import org.apache.qpid.management.ui.views.exchange.ExchangeOperationsTabControl;
import org.apache.qpid.management.ui.views.exchange.HeadersExchangeOperationsTabControl;
import org.apache.qpid.management.ui.views.logging.ConfigurationFileTabControl;
import org.apache.qpid.management.ui.views.logging.RuntimeTabControl;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

public class MBeanTabFolderFactory
{
    private static final String MBEANTYPE_QUEUE = "VirtualHost.Queue";
    private static final String MBEANTYPE_CONNECTION = "VirtualHost.Connection";
    private static final String MBEANTYPE_EXCHANGE = "VirtualHost.Exchange";
    private static final String MBEANTYPE_VHOST_MANAGER = "VirtualHost.VirtualHostManager";
    private static final String MBEANTYPE_LOGGING_MANAGEMENT = "LoggingManagement";
    private static final String MBEANTYPE_USER_MANAGEMENT = "UserManagement";
    private static final String MBEANTYPE_CONFIGURATION_MANAGEMENT = "ConfigurationManagement";    

    private MBeanTabFolderFactory()
    {
        //no instances
    }

    public static TabFolder generateMBeanTabFolder(final Composite parent, final JMXManagedObject mbean, final MBeanServerConnection mbsc)
    {
        TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
        FormData layoutData = new FormData();
        layoutData.left = new FormAttachment(0);
        layoutData.top = new FormAttachment(0);
        layoutData.right = new FormAttachment(100);
        layoutData.bottom = new FormAttachment(100);
        tabFolder.setLayoutData(layoutData);

        TabItem tab;
        TabControl controller;
        QpidMBeanType mbeanType = QpidMBeanType.get(mbean.getType());

        switch(mbeanType)
        {
            case QUEUE:
                createAttributesTab(tabFolder, mbean);
                
                tab = new TabItem(tabFolder, SWT.NONE);
                tab.setText("Operations");
                controller = new QueueOperationsTabControl(tabFolder, mbean, mbsc);
                tab.setControl(controller.getControl());
                tab.setData(TabControl.CONTROLLER, controller);
                break;
            case CONNECTION:
                createAttributesTab(tabFolder, mbean);
                
                tab = new TabItem(tabFolder, SWT.NONE);
                tab.setText("Operations");
                controller = new ConnectionOperationsTabControl(tabFolder, mbean, mbsc);
                tab.setControl(controller.getControl());
                tab.setData(TabControl.CONTROLLER, controller);
                break;
            case EXCHANGE:
                createAttributesTab(tabFolder, mbean);
                
                if (mbean.getProperty(EXCHANGE_TYPE).equalsIgnoreCase("headers"))
                {
                    tab = new TabItem(tabFolder, SWT.NONE);
                    tab.setText("Operations");
                    controller = new HeadersExchangeOperationsTabControl(tabFolder, mbean, mbsc);
                    tab.setControl(controller.getControl());
                    tab.setData(TabControl.CONTROLLER, controller);
                }
                else
                {
                    tab = new TabItem(tabFolder, SWT.NONE);
                    tab.setText("Operations");
                    controller = new ExchangeOperationsTabControl(tabFolder, mbean, mbsc);
                    tab.setControl(controller.getControl());
                    tab.setData(TabControl.CONTROLLER, controller);
                }
                break;
            case VHOST_MANAGER:
                createAttributesTab(tabFolder, mbean);

                tab = new TabItem(tabFolder, SWT.NONE);
                tab.setText("Operations");
                controller = new VHostTabControl(tabFolder, mbean, mbsc);
                tab.setControl(controller.getControl());
                tab.setData(TabControl.CONTROLLER, controller);
                break;
            case LOGGING_MANAGEMENT:
                tab = new TabItem(tabFolder, SWT.NONE);
                tab.setText("Runtime Options");
                controller = new RuntimeTabControl(tabFolder, mbean, mbsc);
                tab.setControl(controller.getControl());
                tab.setData(TabControl.CONTROLLER, controller);

                tab = new TabItem(tabFolder, SWT.NONE);
                tab.setText("ConfigurationFile Options");
                controller = new ConfigurationFileTabControl(tabFolder, mbean, mbsc);
                tab.setControl(controller.getControl());
                tab.setData(TabControl.CONTROLLER, controller);
                break;
            case USER_MANAGEMENT:
                tab = new TabItem(tabFolder, SWT.NONE);
                tab.setText("Operations");
                controller = new UserManagementTabControl(tabFolder, mbean, mbsc);
                tab.setControl(controller.getControl());
                tab.setData(TabControl.CONTROLLER, controller);
                break;
            case CONFIGURATION_MANAGEMENT:
                createGenericTabFolder(tabFolder, mbean);
                break;
            case UNKNOWN:
                createGenericTabFolder(tabFolder, mbean);
                break;
        }
        
        createNotificationsTabIfNecessary(tabFolder, mbean);
        
        tabFolder.addListener(SWT.Selection, new Listener()
        {
            public void handleEvent(Event evt)
            {
                TabItem tab = (TabItem)evt.item;        
                TabControl controller = (TabControl)tab.getData(TabControl.CONTROLLER);
                if(controller != null)
                {
                    controller.refresh(mbean);
                }
            }
        });
        
        return tabFolder;
    }
    
    private static void createGenericTabFolder(TabFolder tabFolder, JMXManagedObject mbean)
    {
        createAttributesTab(tabFolder, mbean);
        createOperationTabs(tabFolder, mbean);
    }

    private static void createAttributesTab(TabFolder tabFolder, JMXManagedObject mbean)
    {
        ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(mbean);
        if(serverRegistry.getAttributeModel(mbean).getCount() == 0)
        {
            return;
        }
        
        TabItem tab = new TabItem(tabFolder, SWT.NONE);
        tab.setText(ATTRIBUTES);
        AttributesTabControl controller = new AttributesTabControl(tabFolder);
        tab.setControl(controller.getControl());
        tab.setData(TabControl.CONTROLLER, controller);
    }
    
    private static void createOperationTabs(TabFolder tabFolder, JMXManagedObject mbean)
    {
        ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(mbean);        
        int operationsCount = serverRegistry.getOperationModel(mbean).getCount();
        if(operationsCount == 0)
        {
            return;
        }
        
        OperationDataModel operationModel = serverRegistry.getOperationModel(mbean);
        for(OperationData operationData : operationModel.getOperations())
        {
            TabItem operationTab = new TabItem(tabFolder, SWT.NONE);
            operationTab.setText(ViewUtility.getDisplayText(operationData.getName()));
            operationTab.setData(operationData);
            OperationTabControl control = new OperationTabControl(tabFolder, operationData);
            operationTab.setData(TabControl.CONTROLLER, control);
            operationTab.setControl(control.getControl());
        }
    }
    
    private static void createNotificationsTabIfNecessary(TabFolder tabFolder, JMXManagedObject mbean)
    {
        NotificationInfoModel[] items = MBeanUtility.getNotificationInfo(mbean);
        if(items == null || items.length == 0)
        {
            //the mbean has no notifications to subscribe for, do not create the tab.
            return;
        }
        
        NotificationsTabControl controller = new NotificationsTabControl(tabFolder, mbean);
        
        TabItem tab = new TabItem(tabFolder, SWT.NONE);
        tab.setText(NOTIFICATIONS);
        tab.setData(TabControl.CONTROLLER, controller);
        tab.setControl(controller.getControl());
    }
    
    /**
     * Creates TabFolder and tabs for all mbeantype (Connection, Queue, and Exchange)
     */
    public static TabFolder generateMBeanTypeTabFolder(final Composite parent, ManagedServer server, String virtualHost)
    {
        TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
        FormData layoutData = new FormData();
        layoutData.left = new FormAttachment(0);
        layoutData.top = new FormAttachment(0);
        layoutData.right = new FormAttachment(100);
        layoutData.bottom = new FormAttachment(100);
        tabFolder.setLayoutData(layoutData);

        
        TabItem tab;
        TabControl controller;
              
        tab = new TabItem(tabFolder, SWT.NONE);
        tab.setText(CONNECTION); 
        controller = new ConnectionTypeTabControl(tabFolder,server,virtualHost);
        tab.setData(TabControl.CONTROLLER, controller);
        tab.setControl(controller.getControl());
        
        tab = new TabItem(tabFolder, SWT.NONE);
        tab.setText(EXCHANGE);      
        controller = new ExchangeTypeTabControl(tabFolder,server,virtualHost);
        tab.setData(TabControl.CONTROLLER, controller);
        tab.setControl(controller.getControl());
        
        tab = new TabItem(tabFolder, SWT.NONE);
        tab.setText(QUEUE);  
        controller = new QueueTypeTabControl(tabFolder,server,virtualHost);
        tab.setData(TabControl.CONTROLLER, controller);
        tab.setControl(controller.getControl());
        
        tabFolder.addListener(SWT.Selection, new Listener()
        {
            public void handleEvent(Event evt)
            {
                TabItem tab = (TabItem)evt.item;        
                TabControl controller = (TabControl)tab.getData(TabControl.CONTROLLER);
                if(controller != null)
                {
                    controller.refresh(null);
                }
            }
        });
        
        return tabFolder;
    }

    /**
     * Creates TabFolder and tab for the Connection selection view
     */
    public static TabFolder generateConnectionTypeTabFolder(final Composite parent, ManagedServer server, String virtualHost)
    {
        TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
        FormData layoutData = new FormData();
        layoutData.left = new FormAttachment(0);
        layoutData.top = new FormAttachment(0);
        layoutData.right = new FormAttachment(100);
        layoutData.bottom = new FormAttachment(100);
        tabFolder.setLayoutData(layoutData);

        TabItem tab;
        TabControl controller;
              
        tab = new TabItem(tabFolder, SWT.NONE);
        tab.setText(CONNECTION); 
        controller = new ConnectionTypeTabControl(tabFolder,server,virtualHost);
        tab.setData(TabControl.CONTROLLER, controller);
        tab.setControl(controller.getControl());
                
        tabFolder.addListener(SWT.Selection, new Listener()
        {
            public void handleEvent(Event evt)
            {
                TabItem tab = (TabItem)evt.item;        
                TabControl controller = (TabControl)tab.getData(TabControl.CONTROLLER);
                if(controller != null)
                {
                    controller.refresh(null);
                }
            }
        });
        
        return tabFolder;
    }
    
    /**
     * Creates TabFolder and tab for the Exchange selection view
     */
    public static TabFolder generateExchangeTypeTabFolder(final Composite parent, ManagedServer server, String virtualHost)
    {
        TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
        FormData layoutData = new FormData();
        layoutData.left = new FormAttachment(0);
        layoutData.top = new FormAttachment(0);
        layoutData.right = new FormAttachment(100);
        layoutData.bottom = new FormAttachment(100);
        tabFolder.setLayoutData(layoutData);

        TabItem tab;
        TabControl controller;

        tab = new TabItem(tabFolder, SWT.NONE);
        tab.setText(EXCHANGE);      
        controller = new ExchangeTypeTabControl(tabFolder,server,virtualHost);
        tab.setData(TabControl.CONTROLLER, controller);
        tab.setControl(controller.getControl());
        
        tabFolder.addListener(SWT.Selection, new Listener()
        {
            public void handleEvent(Event evt)
            {
                TabItem tab = (TabItem)evt.item;        
                TabControl controller = (TabControl)tab.getData(TabControl.CONTROLLER);
                if(controller != null)
                {
                    controller.refresh(null);
                }
            }
        });
        
        return tabFolder;
    }
    
    /**
     * Creates TabFolder and tab for the Queue selection view
     */
    public static TabFolder generateQueueTypeTabFolder(final Composite parent, ManagedServer server, String virtualHost)
    {
        TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
        FormData layoutData = new FormData();
        layoutData.left = new FormAttachment(0);
        layoutData.top = new FormAttachment(0);
        layoutData.right = new FormAttachment(100);
        layoutData.bottom = new FormAttachment(100);
        tabFolder.setLayoutData(layoutData);

        TabItem tab;
        TabControl controller;
        
        tab = new TabItem(tabFolder, SWT.NONE);
        tab.setText(QUEUE);  
        controller = new QueueTypeTabControl(tabFolder,server,virtualHost);
        tab.setData(TabControl.CONTROLLER, controller);
        tab.setControl(controller.getControl());
        
        tabFolder.addListener(SWT.Selection, new Listener()
        {
            public void handleEvent(Event evt)
            {
                TabItem tab = (TabItem)evt.item;        
                TabControl controller = (TabControl)tab.getData(TabControl.CONTROLLER);
                if(controller != null)
                {
                    controller.refresh(null);
                }
            }
        });
        
        return tabFolder;
    }
    
    private enum QpidMBeanType
    {
        QUEUE (MBEANTYPE_QUEUE),
        CONNECTION (MBEANTYPE_CONNECTION),
        EXCHANGE (MBEANTYPE_EXCHANGE),
        VHOST_MANAGER (MBEANTYPE_VHOST_MANAGER),
        LOGGING_MANAGEMENT (MBEANTYPE_LOGGING_MANAGEMENT),
        USER_MANAGEMENT (MBEANTYPE_USER_MANAGEMENT),
        CONFIGURATION_MANAGEMENT (MBEANTYPE_CONFIGURATION_MANAGEMENT),
        UNKNOWN (null);

        private static final Map<String,QpidMBeanType> lookup = new HashMap<String,QpidMBeanType>();

        static
        {
            for(QpidMBeanType m : EnumSet.allOf(QpidMBeanType.class))
            {
                lookup.put(m.getType(), m);
            }
        }

        private String type;
        
        private QpidMBeanType()
        {
            
        }

        private QpidMBeanType(String type)
        {
            this.type = type;
        }

        public String getType()
        {
            return type;
        }

        public static QpidMBeanType get(String type)
        {
            QpidMBeanType t= lookup.get(type);
            if (t != null)
            {
                return t;
            }
            else
            {
                return UNKNOWN;
            }

        }
    }


}