KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > renderings > BasicDebugViewContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.debug.internal.ui.views.memory.renderings;
13
14 import org.eclipse.debug.core.DebugEvent;
15 import org.eclipse.debug.core.IDebugEventSetListener;
16 import org.eclipse.jface.viewers.IStructuredContentProvider;
17 import org.eclipse.jface.viewers.StructuredViewer;
18 import org.eclipse.jface.viewers.Viewer;
19 import org.eclipse.swt.widgets.Control;
20
21 /**
22  * @since 3.0
23  *
24  */

25 public abstract class BasicDebugViewContentProvider implements IStructuredContentProvider, IDebugEventSetListener {
26
27     protected StructuredViewer fViewer;
28     protected boolean fDisposed= false;
29
30     /* (non-Javadoc)
31      * @see org.eclipse.jface.viewers.IContentProvider#dispose()
32      */

33     public void dispose() {
34         fDisposed= true;
35     }
36     
37     /**
38      * Returns whether this content provider has already
39      * been disposed.
40      */

41     protected boolean isDisposed() {
42         return fDisposed;
43     }
44     
45     /* (non-Javadoc)
46      * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
47      */

48     public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
49         fViewer= (StructuredViewer) viewer;
50     }
51
52     protected void asyncExec(Runnable JavaDoc r) {
53         if (fViewer != null) {
54             Control ctrl= fViewer.getControl();
55             if (ctrl != null && !ctrl.isDisposed()) {
56                 ctrl.getDisplay().asyncExec(r);
57             }
58         }
59     }
60     
61     protected void syncExec(Runnable JavaDoc r) {
62         if (fViewer != null) {
63             Control ctrl= fViewer.getControl();
64             if (ctrl != null && !ctrl.isDisposed()) {
65                 ctrl.getDisplay().syncExec(r);
66             }
67         }
68     }
69     
70     /**
71      * Refreshes the viewer - must be called in UI thread.
72      */

73     protected void refresh() {
74         if (fViewer != null) {
75             fViewer.refresh();
76         }
77     }
78             
79     /**
80      * Refresh the given element in the viewer - must be called in UI thread.
81      */

82     protected void refresh(Object JavaDoc element) {
83         if (fViewer != null) {
84              fViewer.refresh(element);
85         }
86     }
87     
88     /**
89      * Handle debug events on the main thread.
90      * @param event
91      */

92     public void handleDebugEvent(final DebugEvent event) {
93         if (fViewer == null) {
94             return;
95         }
96         Object JavaDoc element= event.getSource();
97         if (element == null) {
98             return;
99         }
100         Runnable JavaDoc r= new Runnable JavaDoc() {
101             public void run() {
102                 if (!isDisposed()) {
103                     doHandleDebugEvent(event);
104                 }
105             }
106         };
107         
108         asyncExec(r);
109     }
110
111     /* (non-Javadoc)
112      * @see IDebugEventSetListener#handleDebugEvents(DebugEvent[])
113      */

114     public void handleDebugEvents(DebugEvent[] events) {
115         for (int i=0; i < events.length; i++)
116             handleDebugEvent(events[i]);
117     }
118     
119     /**
120      * Performs an update based on the event
121      */

122     protected abstract void doHandleDebugEvent(DebugEvent event);
123 }
124
Popular Tags