Organized imports
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.monitor.ui / src / net / sourceforge / phpdt / monitor / ui / internal / view / MonitorView.java
1 /**********************************************************************
2  * Copyright (c) 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *    IBM - Initial API and implementation
10  **********************************************************************/
11 package net.sourceforge.phpdt.monitor.ui.internal.view;
12
13 import java.text.SimpleDateFormat;
14 import java.util.Iterator;
15 import java.util.List;
16
17 import net.sourceforge.phpdt.monitor.core.IContentFilter;
18 import net.sourceforge.phpdt.monitor.core.IRequest;
19 import net.sourceforge.phpdt.monitor.core.IRequestListener;
20 import net.sourceforge.phpdt.monitor.core.MonitorCore;
21 import net.sourceforge.phpdt.monitor.ui.internal.ContextIds;
22 import net.sourceforge.phpdt.monitor.ui.internal.MonitorPrefrencesDialog;
23 import net.sourceforge.phpdt.monitor.ui.internal.MonitorUIPlugin;
24 import net.sourceforge.phpdt.monitor.ui.internal.Trace;
25
26 import org.eclipse.core.runtime.IConfigurationElement;
27 import org.eclipse.jface.action.Action;
28 import org.eclipse.jface.action.IAction;
29 import org.eclipse.jface.action.IMenuManager;
30 import org.eclipse.jface.action.IToolBarManager;
31 import org.eclipse.jface.viewers.ISelection;
32 import org.eclipse.jface.viewers.ISelectionChangedListener;
33 import org.eclipse.jface.viewers.IStructuredSelection;
34 import org.eclipse.jface.viewers.SelectionChangedEvent;
35 import org.eclipse.jface.viewers.StructuredSelection;
36 import org.eclipse.jface.viewers.TreeViewer;
37 import org.eclipse.jface.window.Window;
38 import org.eclipse.swt.SWT;
39 import org.eclipse.swt.custom.SashForm;
40 import org.eclipse.swt.events.ModifyEvent;
41 import org.eclipse.swt.events.ModifyListener;
42 import org.eclipse.swt.layout.GridData;
43 import org.eclipse.swt.layout.GridLayout;
44 import org.eclipse.swt.widgets.Combo;
45 import org.eclipse.swt.widgets.Composite;
46 import org.eclipse.swt.widgets.Display;
47 import org.eclipse.swt.widgets.Label;
48 import org.eclipse.swt.widgets.Tree;
49 import org.eclipse.ui.IViewPart;
50 import org.eclipse.ui.IWorkbench;
51 import org.eclipse.ui.IWorkbenchPage;
52 import org.eclipse.ui.IWorkbenchWindow;
53 import org.eclipse.ui.PlatformUI;
54 import org.eclipse.ui.help.WorkbenchHelp;
55 import org.eclipse.ui.part.ViewPart;
56 /**
57  * View of TCP/IP activity.
58  */
59 public class MonitorView extends ViewPart {
60         protected Tree tree;
61         protected TreeViewer treeViewer;
62         protected MonitorTreeContentProvider contentProvider;
63
64         protected IRequestListener listener;
65         protected IViewerManager vm;
66         protected List requestViewers;
67         protected List responseViewers;
68
69         protected static SimpleDateFormat format = new SimpleDateFormat(MonitorUIPlugin.getResource("%viewDateFormat"));
70         protected static final String VIEW_ID = "net.sourceforge.phpeclipse.monitor.core.view";
71         protected static final String DEFAULT_VIEWER = "net.sourceforge.phpeclipse.monitor.core.viewers.byteviewer";
72
73         protected IAction httpHeaderAction;
74         
75         protected static MonitorView view;
76
77         /**
78          * MonitorView constructor comment.
79          */
80         public MonitorView() {
81                 super();
82                 view = this;
83         }
84         
85         protected void addListener() {
86                 listener = new IRequestListener() {
87                         public void requestAdded(final IRequest rr) {
88                                 Display.getDefault().asyncExec(new Runnable() {
89                                         public void run() {
90                                                 Integer in = new Integer(rr.getLocalPort());
91                                                 treeViewer.add(MonitorTreeContentProvider.ROOT, in);
92                                                 treeViewer.add(in, rr);
93                                                 treeViewer.setSelection(new StructuredSelection(rr), true);
94                                         }
95                                 });
96                         }
97
98                         public void requestChanged(final IRequest rr) {
99                                 Display.getDefault().asyncExec(new Runnable() {
100                                         public void run() {
101                                                 IStructuredSelection sel = (IStructuredSelection) treeViewer.getSelection();
102                                                 
103                                                 treeViewer.refresh(rr);
104                                                 if (!sel.isEmpty())
105                                                         treeViewer.setSelection(sel);
106                                         }
107                                 });
108                         }
109
110                         public void requestRemoved(final IRequest rr) {
111                                 Display.getDefault().asyncExec(new Runnable() {
112                                         public void run() {
113                                                 treeViewer.remove(rr);
114                                         }
115                                 });
116                         }
117                 };
118         
119                 MonitorCore.addRequestListener(listener);
120         }
121
122         /**
123          * Clear the view.
124          */
125         protected void clear() {
126                 Display.getDefault().asyncExec(new Runnable() {
127                         public void run() {
128                                 treeViewer.setSelection(null);
129                                 treeViewer.setInput(MonitorTreeContentProvider.ROOT);
130                         }
131                 });
132         }
133         
134         protected void setSelection(IRequest request) {
135                 if (treeViewer != null)
136                         treeViewer.setSelection(new StructuredSelection(request));
137         }
138         
139
140         /**
141          * Returns the inner component in a desktop part.
142          */
143         public void createPartControl(Composite parent) {
144                 SashForm sashFparent = new SashForm(parent, SWT.VERTICAL);
145                 GridLayout layout = new GridLayout();
146                 layout.numColumns = 2;
147                 layout.horizontalSpacing = 4;
148                 layout.verticalSpacing = 4;
149                 sashFparent.setLayout(layout);
150                 sashFparent.setLayoutData(new GridData(GridData.FILL_BOTH));
151                 WorkbenchHelp.setHelp(sashFparent, ContextIds.VIEW);
152                 
153                 // create tree panel
154                 Composite treePanel = new Composite(sashFparent, SWT.NONE);
155                 layout = new GridLayout();
156                 layout.numColumns = 2;
157                 layout.marginHeight = 0;
158                 layout.marginWidth = 0;
159                 treePanel.setLayout(layout);
160                 GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
161                 data.heightHint = 110;
162                 data.horizontalSpan = 2;
163                 treePanel.setLayoutData(data);
164         
165                 tree = new Tree(treePanel, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
166                 data = new GridData(GridData.FILL_BOTH);
167                 //data.widthHint = 120;
168                 tree.setLayoutData(data);
169                 treeViewer = new TreeViewer(tree);
170                 contentProvider = new MonitorTreeContentProvider();
171                 treeViewer.setContentProvider(contentProvider);
172                 treeViewer.setInput(MonitorTreeContentProvider.ROOT);
173                 treeViewer.setLabelProvider(new TreeLabelProvider());
174                 WorkbenchHelp.setHelp(tree, ContextIds.VIEW_TREE);
175         
176                 Composite detailsPanel = new Composite(treePanel, SWT.NONE);
177                 layout = new GridLayout();
178                 layout.numColumns = 1;
179                 layout.marginHeight = 2;
180                 layout.marginWidth = 0;
181                 detailsPanel.setLayout(layout);
182                 data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
183                 data.widthHint = 200;
184                 detailsPanel.setLayoutData(data);
185
186                 final Label label = new Label(detailsPanel, SWT.NONE);
187                 label.setText(MonitorUIPlugin.getResource("%viewTime", ""));
188                 label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
189
190                 final Label label2 = new Label(detailsPanel, SWT.NONE);
191                 label2.setText(MonitorUIPlugin.getResource("%viewResponseTime", ""));
192                 label2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
193
194                 final Label label3 = new Label(detailsPanel, SWT.NONE);
195                 label3.setText(MonitorUIPlugin.getResource("%viewType", ""));
196                 label3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
197
198                 // create center and right panels
199                 SashForm sashFchild = new SashForm(sashFparent, SWT.NONE);
200                 layout = new GridLayout();
201                 layout.numColumns = 2;
202                 layout.horizontalSpacing = 2;
203                 layout.verticalSpacing = 4;
204                 sashFchild.setLayout(layout);
205                 sashFparent.setWeights(new int[] { 30, 70 });
206         
207                 // request panel
208                 Composite request = new Composite(sashFchild, SWT.NONE);
209                 layout = new GridLayout();
210                 layout.verticalSpacing = 3;
211                 layout.marginHeight = 2;
212                 layout.marginWidth = 0;
213                 request.setLayout(layout);
214                 request.setLayoutData(new GridData(GridData.FILL_BOTH));
215
216                 Composite requestHeader = new Composite(request, SWT.NONE);
217                 layout = new GridLayout();
218                 layout.verticalSpacing = 0;
219                 layout.numColumns = 2;
220                 layout.marginHeight = 0;
221                 layout.marginWidth = 2;
222                 data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
223                 data.heightHint = 30;
224                 requestHeader.setLayout(layout);
225                 requestHeader.setLayoutData(data);
226
227                 Composite requestHeaderLeft = new Composite(requestHeader, SWT.NONE);
228                 layout = new GridLayout();
229                 layout.verticalSpacing = 2;
230                 layout.marginHeight = 0;
231                 layout.marginWidth = 0;
232                 data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
233                 data.heightHint = 30;
234                 requestHeaderLeft.setLayout(layout);
235                 requestHeaderLeft.setLayoutData(data);
236
237                 Label empty1 = new Label(requestHeaderLeft, SWT.NONE);
238                 empty1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
239                 
240                 final Label requestLabel = new Label(requestHeaderLeft, SWT.NONE);
241                 requestLabel.setText(MonitorUIPlugin.getResource("%viewRequest", ""));
242                 requestLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_END));
243
244                 final Label requestSizeLabel = new Label(requestHeaderLeft, SWT.NONE);
245                 requestSizeLabel.setText(MonitorUIPlugin.getResource("%viewSize", ""));
246                 requestSizeLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_END));
247
248                 Composite requestHeaderRight = new Composite(requestHeader, SWT.NONE);
249                 layout = new GridLayout();
250                 layout.verticalSpacing = 0;
251                 layout.marginHeight = 0;
252                 layout.marginWidth = 0;
253                 data = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL);
254                 data.heightHint = 30;
255                 requestHeaderRight.setLayout(layout);
256                 requestHeaderRight.setLayoutData(data);
257                 
258                 Label empty2 = new Label(requestHeaderRight, SWT.NONE);
259                 empty2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
260                 
261                 Combo requestViewerCombo = new Combo(requestHeaderRight, SWT.DROP_DOWN | SWT.READ_ONLY);        
262                 requestViewerCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_END));
263
264                 // response panel
265                 Composite response = new Composite(sashFchild, SWT.NONE);
266                 layout = new GridLayout();
267                 layout.verticalSpacing = 3;
268                 layout.marginHeight = 2;
269                 layout.marginWidth = 0;
270                 response.setLayout(layout);
271                 response.setLayoutData(new GridData(GridData.FILL_BOTH));
272
273                 Composite responseHeader = new Composite(response, SWT.NONE);
274                 layout = new GridLayout();
275                 layout.verticalSpacing = 0;
276                 layout.numColumns = 2;
277                 layout.marginHeight = 0;
278                 layout.marginWidth = 2;
279                 data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
280                 data.heightHint = 30;
281                 responseHeader.setLayout(layout);
282                 responseHeader.setLayoutData(data);
283
284                 Composite responseHeaderLeft = new Composite(responseHeader, SWT.NONE);
285                 layout = new GridLayout();
286                 layout.verticalSpacing = 2;
287                 layout.marginHeight = 0;
288                 layout.marginWidth = 0;
289                 data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
290                 data.heightHint = 30;
291                 responseHeaderLeft.setLayout(layout);
292                 responseHeaderLeft.setLayoutData(data);
293
294                 Label empty3 = new Label(responseHeaderLeft, SWT.NONE);
295                 empty3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
296         
297                 final Label responseLabel = new Label(responseHeaderLeft, SWT.NONE);
298                 responseLabel.setText(MonitorUIPlugin.getResource("%viewResponse", ""));
299                 responseLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
300         
301                 final Label responseSizeLabel = new Label(responseHeaderLeft, SWT.NONE);
302                 responseSizeLabel.setText(MonitorUIPlugin.getResource("%viewSize", ""));
303                 responseSizeLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_END));
304
305                 Composite responseHeaderRight = new Composite(responseHeader, SWT.NONE);
306                 layout = new GridLayout();
307                 layout.verticalSpacing = 0;
308                 layout.marginHeight = 0;
309                 layout.marginWidth = 0;
310                 data = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL);
311                 data.heightHint = 30;
312                 responseHeaderRight.setLayout(layout);
313                 responseHeaderRight.setLayoutData(data);
314                 
315                 Label empty4 = new Label(responseHeaderRight, SWT.NONE);
316                 empty4.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
317                 
318                 Combo responseViewerCombo = new Combo(responseHeaderRight, SWT.DROP_DOWN | SWT.READ_ONLY);      
319                 responseViewerCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_END));
320         
321                 //Viewer manager
322                 vm = new ViewerManager(request, request, response, response);
323                 requestViewers = vm.getRequestViewers();
324                 responseViewers = vm.getResponseViewers();
325
326                 //Set up the viewer combo boxes
327                 Iterator iterator = requestViewers.iterator();
328                 int ctr = 0;
329                 while(iterator.hasNext()) {
330                         IConfigurationElement element = (IConfigurationElement) iterator.next();
331                         requestViewerCombo.add(element.getAttribute("label"), ctr);
332                         if (element.getAttribute("id").equals(DEFAULT_VIEWER)) {
333                                 requestViewerCombo.select(ctr); 
334                                 vm.setRequestViewer(element);
335                         }  
336                         ctr++;  
337                 }
338                 requestViewerCombo.addModifyListener(new ModifyListener() {
339                         public void modifyText(ModifyEvent arg0) {
340                                 Combo rvCombo = (Combo) arg0.getSource();
341                                 vm.setRequestViewer((IConfigurationElement) requestViewers.get(rvCombo.getSelectionIndex()));
342                         }
343                 });
344                 requestHeader.layout(true);
345                 
346                 iterator = responseViewers.iterator();
347                 ctr = 0;
348                 while(iterator.hasNext()) {
349                         IConfigurationElement element = (IConfigurationElement) iterator.next();
350                         responseViewerCombo.add(element.getAttribute("label"), ctr);
351                         if(element.getAttribute("id").equals(DEFAULT_VIEWER)) {
352                                 responseViewerCombo.select(ctr); 
353                                 vm.setResponseViewer(element);
354                         } 
355                         ctr++;
356                 }
357                 responseViewerCombo.addModifyListener(new ModifyListener() {
358                         public void modifyText(ModifyEvent arg0) {
359                                 Combo rvCombo = (Combo) arg0.getSource();
360                                 vm.setResponseViewer((IConfigurationElement) requestViewers.get(rvCombo.getSelectionIndex()));
361                         }
362                 });
363                 responseHeader.layout(true);
364
365                 // selection listener
366                 treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
367                         public void selectionChanged(SelectionChangedEvent event) {
368                                 ISelection selection = event.getSelection();
369
370                                 IRequest req = null;
371                                 if (selection != null && !selection.isEmpty()) {
372                                         StructuredSelection sel = (StructuredSelection) selection;
373                                         Object obj = sel.iterator().next();
374                                         if (obj instanceof IRequest)
375                                                 req = (IRequest) obj;
376                                 }
377         
378                                 if (req != null) {
379                                         label.setText(MonitorUIPlugin.getResource("%viewTime", format.format(req.getDate())));
380         
381                                         if (req.getResponseTime() == -1)
382                                                 label2.setText(MonitorUIPlugin.getResource("%viewResponseTime", ""));
383                                         else {
384                                                 String time = MonitorUIPlugin.getResource("%viewResponseTimeFormat", req.getResponseTime() + "");
385                                                 label2.setText(MonitorUIPlugin.getResource("%viewResponseTime", time));
386                                         }
387                                         label3.setText(MonitorUIPlugin.getResource("%viewType", req.getType().getName()));
388         
389                                         // request information
390                                         requestLabel.setText(MonitorUIPlugin.getResource("%viewRequest", "localhost:" + req.getLocalPort()));
391                                         requestSizeLabel.setText(getSizeString(req.getRequest(IRequest.CONTENT), req.getRequest(IRequest.ALL)));
392         
393                                         // response information
394                                         responseLabel.setText(MonitorUIPlugin.getResource("%viewResponse", req.getRemoteHost() + ":" + req.getRemotePort()));
395                                         responseSizeLabel.setText(getSizeString(req.getResponse(IRequest.CONTENT), req.getResponse(IRequest.ALL)));
396
397                                         vm.setRequest(req);
398                                 } else {
399                                         label.setText(MonitorUIPlugin.getResource("%viewTime", ""));
400                                         label2.setText(MonitorUIPlugin.getResource("%viewResponseTime", ""));
401                                         requestLabel.setText(MonitorUIPlugin.getResource("%viewRequest", ""));
402                                         requestSizeLabel.setText(MonitorUIPlugin.getResource("%viewSize", ""));
403                                         responseLabel.setText(MonitorUIPlugin.getResource("%viewResponse", ""));
404                                         responseSizeLabel.setText(MonitorUIPlugin.getResource("%viewSize", ""));
405                                         vm.setRequest(req);
406                                 }
407                         }
408                 });
409                 
410                 treeViewer.expandToLevel(2);
411         
412                 initializeActions();
413         
414                 addListener();
415         }
416         
417         protected String getSizeString(byte[] a, byte[] b) {
418                 String aa = "0";
419                 String bb = "0";
420                 if (a != null)
421                         aa = a.length + "";
422                 if (b != null)
423                         bb = b.length + "";
424                 String size = MonitorUIPlugin.getResource("%viewSizeFormat", new Object[] { aa, bb});
425                 return MonitorUIPlugin.getResource("%viewSize", size);
426         }
427
428         public void dispose() {
429                 super.dispose();
430                 treeViewer = null;
431                 MonitorCore.removeRequestListener(listener);
432         }
433
434         /**
435          * 
436          */
437         public void initializeActions() {
438                 final IAction sortByResponseTimeAction = new Action() {
439                         public void run() {
440                                 Display.getDefault().asyncExec(new Runnable() {
441                                         public void run() {
442                                                 boolean b = contentProvider.getSortByResponseTime();
443                                                 contentProvider.setSortByResponseTime(!b);
444                                                 treeViewer.refresh();
445                                                 setChecked(!b);
446                                         }
447                                 });
448                         }
449                 };
450                 sortByResponseTimeAction.setChecked(false);
451                 sortByResponseTimeAction.setToolTipText(MonitorUIPlugin.getResource("%actionSortByResponseTime"));
452                 sortByResponseTimeAction.setImageDescriptor(MonitorUIPlugin.getImageDescriptor(MonitorUIPlugin.IMG_ELCL_SORT_RESPONSE_TIME));
453                 sortByResponseTimeAction.setHoverImageDescriptor(MonitorUIPlugin.getImageDescriptor(MonitorUIPlugin.IMG_CLCL_SORT_RESPONSE_TIME));
454                 sortByResponseTimeAction.setDisabledImageDescriptor(MonitorUIPlugin.getImageDescriptor(MonitorUIPlugin.IMG_DLCL_SORT_RESPONSE_TIME));
455         
456                 IAction clearAction = new Action() {
457                         public void run() {
458                                 MonitorCore.removeAllRequests();
459                         }
460                 };
461                 clearAction.setToolTipText(MonitorUIPlugin.getResource("%actionClearToolTip"));
462                 clearAction.setImageDescriptor(MonitorUIPlugin.getImageDescriptor(MonitorUIPlugin.IMG_ELCL_CLEAR));
463                 clearAction.setHoverImageDescriptor(MonitorUIPlugin.getImageDescriptor(MonitorUIPlugin.IMG_CLCL_CLEAR));
464                 clearAction.setDisabledImageDescriptor(MonitorUIPlugin.getImageDescriptor(MonitorUIPlugin.IMG_DLCL_CLEAR));
465
466                 httpHeaderAction = new Action() {
467                         public void run() {
468                                 Display.getDefault().asyncExec(new Runnable() {
469                                         public void run() {
470                                                 boolean b = vm.getDisplayHeaderInfo();
471                                                 vm.setDisplayHeaderInfo(!b);
472                                                 setChecked(!b);
473                                         }
474                                 });
475                         }
476                 };
477                 httpHeaderAction.setChecked(vm.getDisplayHeaderInfo());
478                 httpHeaderAction.setText(MonitorUIPlugin.getResource("%actionShowHeader"));
479
480                 IAction preferenceAction = new Action() {
481                         public void run() {
482                                 IWorkbench workbench = PlatformUI.getWorkbench();
483                                 IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
484                                                                 
485                                 MonitorPrefrencesDialog monitorPrefDialog = new MonitorPrefrencesDialog(workbenchWindow.getShell());
486                                 if (monitorPrefDialog.open() == Window.CANCEL)
487                                         return;
488                         }
489                 };
490                 preferenceAction.setText(MonitorUIPlugin.getResource("%actionProperties"));
491                 
492                 
493                 IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
494                 tbm.add(sortByResponseTimeAction);
495                 tbm.add(clearAction);
496                 
497                 IContentFilter[] filters = MonitorCore.getContentFilters();
498                 IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
499                 menuManager.add(httpHeaderAction);
500                 int size = filters.length;
501                 for (int i = 0; i < size; i++) {
502                         FilterAction action = new FilterAction(vm, filters[i]);
503                         menuManager.add(action);
504                 }
505                 menuManager.add(preferenceAction);
506         }
507
508         /**
509          * 
510          */
511         public static void open(final IRequest request) {
512                 Display.getDefault().asyncExec(new Runnable() {
513                         public void run() {
514                                 try {
515                                         IWorkbench workbench = MonitorUIPlugin.getInstance().getWorkbench();
516                                         IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
517                                         //if (workbenchWindow == null)
518                                         //      workbenchWindow = workbench.getWorkbenchWindows()[0];
519         
520                                         IWorkbenchPage page = workbenchWindow.getActivePage();
521         
522                                         IViewPart view2 = page.findView(VIEW_ID);
523                                         
524                                         if (view2 != null)
525                                                 page.bringToTop(view2);
526                                         else
527                                                 page.showView(VIEW_ID);
528
529                                         if (view != null)
530                                                 view.setSelection(request);
531                                 } catch (Exception e) {
532                                         Trace.trace(Trace.SEVERE, "Error opening TCP/IP view", e);
533                                 }
534                         }
535                 });
536         }
537
538         /**
539          * 
540          */
541         public void setFocus() {
542                 if (tree != null)
543                         tree.setFocus();
544         }
545 }