Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7ad095245e8fc3dc16e47a41f636a3870e577c97 (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2005, 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.viewers.update;

import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta;
import org.eclipse.jface.viewers.Viewer;

public class ProcessProxy extends EventHandlerModelProxy {

    private IProcess fProcess;

    private DebugEventHandler fProcessEventHandler = new DebugEventHandler(this) {
        @Override
		protected boolean handlesEvent(DebugEvent event) {
            return event.getSource().equals(fProcess);
        }

		@Override
		protected void handleChange(DebugEvent event) {
			fireProcessDelta(IModelDelta.STATE);        			
        }

        @Override
		protected void handleCreate(DebugEvent event) {
        	// do nothing - Launch change notification handles this
        }

		@Override
		protected void handleTerminate(DebugEvent event) {
			fireProcessDelta(IModelDelta.STATE | IModelDelta.UNINSTALL);
		}
        
        
    };

    private void fireProcessDelta(int flags) {
        ModelDelta delta = null;
        synchronized (ProcessProxy.this) {
            if (!isDisposed()) {
                delta = new ModelDelta(DebugPlugin.getDefault().getLaunchManager(), IModelDelta.NO_CHANGE);
                ModelDelta node = delta;
                node = node.addNode(fProcess.getLaunch(), IModelDelta.NO_CHANGE);
                node.addNode(fProcess, flags);                  
            }
        }
        if (delta != null && !isDisposed()) {
            fireModelChanged(delta);
        }           
    }

    /* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.viewers.update.EventHandlerModelProxy#dispose()
	 */
	@Override
	public synchronized void dispose() {
		super.dispose();
		fProcess = null;
	}

	public ProcessProxy(IProcess process) {
        fProcess = process;
    }

    @Override
	protected synchronized boolean containsEvent(DebugEvent event) {
        return event.getSource().equals(fProcess);
    }

    @Override
	protected DebugEventHandler[] createEventHandlers() {
        return new DebugEventHandler[] {fProcessEventHandler};
    }

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.viewers.AbstractModelProxy#installed()
	 */
	@Override
	public void installed(Viewer viewer) {
		super.installed(viewer);
		// select process if in run mode
		IProcess process = fProcess;
		if (process != null) {
		    if (process.isTerminated()) {
	            fireProcessDelta(IModelDelta.UNINSTALL);
		    } else {
    			ILaunch launch = process.getLaunch();
    			if (launch != null && ILaunchManager.RUN_MODE.equals(launch.getLaunchMode())) {
    				// select the process
    				ModelDelta delta = new ModelDelta(DebugPlugin.getDefault().getLaunchManager(), IModelDelta.NO_CHANGE);
    				ModelDelta node = delta.addNode(process.getLaunch(), IModelDelta.NO_CHANGE);
    				node = node.addNode(process, IModelDelta.SELECT);
    				fireModelChanged(delta);					
    			}
		    }
		}
	}
}

Back to the top