KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > viewers > update > LaunchManagerProxy


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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 package org.eclipse.debug.internal.ui.viewers.update;
12
13 import org.eclipse.debug.core.DebugPlugin;
14 import org.eclipse.debug.core.ILaunch;
15 import org.eclipse.debug.core.ILaunchManager;
16 import org.eclipse.debug.core.ILaunchesListener2;
17 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
18 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
19 import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta;
20 import org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy;
21 import org.eclipse.jface.viewers.Viewer;
22
23 /**
24  * Model proxy for launch manager.
25  */

26 public class LaunchManagerProxy extends AbstractModelProxy implements ILaunchesListener2 {
27
28     private ILaunchManager fLaunchManager;
29
30     /* (non-Javadoc)
31      * @see org.eclipse.debug.internal.ui.viewers.AbstractModelProxy#init(org.eclipse.debug.internal.ui.viewers.IPresentationContext)
32      */

33     public void init(IPresentationContext context) {
34         super.init(context);
35         fLaunchManager = DebugPlugin.getDefault().getLaunchManager();
36         fLaunchManager.addLaunchListener(this);
37     }
38     
39     /* (non-Javadoc)
40      * @see org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy#installed(org.eclipse.jface.viewers.Viewer)
41      */

42     public void installed(Viewer viewer) {
43         // expand existing launches
44
ILaunch[] launches = fLaunchManager.getLaunches();
45         launchesAdded(launches);
46     }
47
48     /* (non-Javadoc)
49      * @see org.eclipse.debug.internal.ui.viewers.AbstractModelProxy#dispose()
50      */

51     public void dispose() {
52         super.dispose();
53         fLaunchManager.removeLaunchListener(this);
54         fLaunchManager = null;
55     }
56
57     /* (non-Javadoc)
58      * @see org.eclipse.debug.core.ILaunchesListener2#launchesTerminated(org.eclipse.debug.core.ILaunch[])
59      */

60     public void launchesTerminated(ILaunch[] launches) {
61     }
62
63     /* (non-Javadoc)
64      * @see org.eclipse.debug.core.ILaunchesListener#launchesRemoved(org.eclipse.debug.core.ILaunch[])
65      */

66     public void launchesRemoved(ILaunch[] launches) {
67         fireDelta(launches, IModelDelta.REMOVED);
68     }
69
70     /* (non-Javadoc)
71      * @see org.eclipse.debug.core.ILaunchesListener#launchesAdded(org.eclipse.debug.core.ILaunch[])
72      */

73     public void launchesAdded(ILaunch[] launches) {
74         fireDelta(launches, IModelDelta.ADDED | IModelDelta.INSTALL | IModelDelta.EXPAND);
75     }
76
77     /* (non-Javadoc)
78      * @see org.eclipse.debug.core.ILaunchesListener#launchesChanged(org.eclipse.debug.core.ILaunch[])
79      */

80     public void launchesChanged(ILaunch[] launches) {
81     }
82     
83     /**
84      * Convenience method for firing a delta
85      * @param launches the launches to set in the delta
86      * @param launchFlags the flags for the delta
87      */

88     protected void fireDelta(ILaunch[] launches, int launchFlags) {
89         ModelDelta delta = new ModelDelta(fLaunchManager, IModelDelta.NO_CHANGE);
90         for (int i = 0; i < launches.length; i++) {
91             delta.addNode(launches[i], launchFlags);
92         }
93         fireModelChanged(delta);
94     }
95
96 }
97
Popular Tags