KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004 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 Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.debug.internal.ui.views.memory;
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     /**
53      * @see org.eclipse.swt.widgets.Display.asyncExec(java.lang.Runnable)
54      */

55     protected void asyncExec(Runnable JavaDoc r) {
56         if (fViewer != null) {
57             Control ctrl= fViewer.getControl();
58             if (ctrl != null && !ctrl.isDisposed()) {
59                 ctrl.getDisplay().asyncExec(r);
60             }
61         }
62     }
63     
64     /**
65      * @see org.eclipse.swt.widgets.Display.syncExec(java.lang.Runnable)
66      */

67     protected void syncExec(Runnable JavaDoc r) {
68         if (fViewer != null) {
69             Control ctrl= fViewer.getControl();
70             if (ctrl != null && !ctrl.isDisposed()) {
71                 ctrl.getDisplay().syncExec(r);
72             }
73         }
74     }
75     
76     /**
77      * Refreshes the viewer - must be called in UI thread.
78      */

79     protected void refresh() {
80         if (fViewer != null) {
81             fViewer.refresh();
82         }
83     }
84             
85     /**
86      * Refresh the given element in the viewer - must be called in UI thread.
87      */

88     protected void refresh(Object JavaDoc element) {
89         if (fViewer != null) {
90              fViewer.refresh(element);
91         }
92     }
93     
94     /**
95      * Handle debug events on the main thread.
96      * @param event
97      */

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

120     public void handleDebugEvents(DebugEvent[] events) {
121         for (int i=0; i < events.length; i++)
122             handleDebugEvent(events[i]);
123     }
124     
125     /**
126      * Performs an update based on the event
127      */

128     protected abstract void doHandleDebugEvent(DebugEvent event);
129 }
Popular Tags