KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > ui > PersistenceManager


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.debugger.ui;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import org.netbeans.api.debugger.Breakpoint;
24 import org.netbeans.api.debugger.DebuggerEngine;
25 import org.netbeans.api.debugger.DebuggerManager;
26 import org.netbeans.api.debugger.LazyDebuggerManagerListener;
27 import org.netbeans.api.debugger.Properties;
28 import org.netbeans.api.debugger.Session;
29 import org.netbeans.api.debugger.Watch;
30
31
32 /**
33  * Listens on DebuggerManager and:
34  * - loads all breakpoints & watches on startup
35  * - listens on all changes of breakpoints and watches (like breakoint / watch
36  * added / removed, or some property change) and saves a new values
37  *
38  * @author Jan Jancura
39  */

40 public class PersistenceManager implements LazyDebuggerManagerListener {
41     
42     public Breakpoint[] initBreakpoints () {
43         return new Breakpoint [0];
44     }
45     
46     public void initWatches () {
47         // As a side-effect, creates the watches. WatchesReader is triggered.
48
Properties p = Properties.getDefault ().getProperties ("debugger");
49         p.getArray (
50             DebuggerManager.PROP_WATCHES,
51             new Watch [0]
52         );
53     }
54     
55     public String JavaDoc[] getProperties () {
56         return new String JavaDoc [] {
57             DebuggerManager.PROP_WATCHES_INIT,
58             DebuggerManager.PROP_WATCHES
59         };
60     }
61     
62     public void breakpointAdded (Breakpoint breakpoint) {
63     }
64
65     public void breakpointRemoved (Breakpoint breakpoint) {
66     }
67     
68     public void watchAdded (Watch watch) {
69         Properties p = Properties.getDefault ().getProperties ("debugger");
70         p.setArray (
71             DebuggerManager.PROP_WATCHES,
72             DebuggerManager.getDebuggerManager ().getWatches ()
73         );
74         watch.addPropertyChangeListener (this);
75     }
76     
77     public void watchRemoved (Watch watch) {
78         Properties p = Properties.getDefault ().getProperties ("debugger");
79         p.setArray (
80             DebuggerManager.PROP_WATCHES,
81             DebuggerManager.getDebuggerManager ().getWatches ()
82         );
83         watch.removePropertyChangeListener(this);
84     }
85     
86     public void propertyChange (PropertyChangeEvent JavaDoc evt) {
87         if (evt.getSource() instanceof Watch) {
88             Properties.getDefault ().getProperties ("debugger").setArray (
89                 DebuggerManager.PROP_WATCHES,
90                 DebuggerManager.getDebuggerManager ().getWatches ()
91             );
92         }
93     }
94     
95     public void sessionAdded (Session session) {}
96     public void sessionRemoved (Session session) {}
97     public void engineAdded (DebuggerEngine engine) {}
98     public void engineRemoved (DebuggerEngine engine) {}
99 }
100
Popular Tags