This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 180558
Collapse All | Expand All

(-)a/api.debugger/src/org/netbeans/api/debugger/ActionsManager.java (+3 lines)
Lines 106-111 Link Here
106
    /** Action constant for Toggle Breakpoint Action. */
106
    /** Action constant for Toggle Breakpoint Action. */
107
    public static final Object              ACTION_TOGGLE_BREAKPOINT = "toggleBreakpoint";
107
    public static final Object              ACTION_TOGGLE_BREAKPOINT = "toggleBreakpoint";
108
    
108
    
109
    /** Action constant for Add Watch Action. */
110
    public static final Object              ACTION_ADD_WATCH = "addWatch";
111
109
    
112
    
110
    // variables ...............................................................
113
    // variables ...............................................................
111
    
114
    
(-)a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/actions/AddWatchAction.java (-21 / +94 lines)
Lines 45-51 Link Here
45
import java.util.ResourceBundle;
45
import java.util.ResourceBundle;
46
import java.util.prefs.Preferences;
46
import java.util.prefs.Preferences;
47
import javax.swing.*;
47
import javax.swing.*;
48
import org.netbeans.api.debugger.ActionsManager;
49
import org.netbeans.api.debugger.DebuggerEngine;
48
import org.netbeans.api.debugger.DebuggerManager;
50
import org.netbeans.api.debugger.DebuggerManager;
51
import org.netbeans.api.debugger.DebuggerManagerAdapter;
52
import org.netbeans.api.debugger.Watch;
49
import org.netbeans.modules.debugger.ui.WatchPanel;
53
import org.netbeans.modules.debugger.ui.WatchPanel;
50
54
51
import org.netbeans.modules.debugger.ui.views.VariablesViewButtons;
55
import org.netbeans.modules.debugger.ui.views.VariablesViewButtons;
Lines 55-60 Link Here
55
import org.openide.util.HelpCtx;
59
import org.openide.util.HelpCtx;
56
import org.openide.util.NbBundle;
60
import org.openide.util.NbBundle;
57
import org.openide.util.NbPreferences;
61
import org.openide.util.NbPreferences;
62
import org.openide.util.RequestProcessor;
63
import org.openide.util.Task;
58
import org.openide.util.actions.CallableSystemAction;
64
import org.openide.util.actions.CallableSystemAction;
59
import org.openide.windows.Mode;
65
import org.openide.windows.Mode;
60
import org.openide.windows.TopComponent;
66
import org.openide.windows.TopComponent;
Lines 101-107 Link Here
101
    }
107
    }
102
    
108
    
103
    public void performAction () {
109
    public void performAction () {
104
        ResourceBundle bundle = NbBundle.getBundle (AddWatchAction.class);
110
        final AddWatchListener addWatchListener = performEngineAddWatchAction();
111
        if (addWatchListener != null) {
112
            if (addWatchListener.getTask().isFinished()) {
113
                if (addWatchListener.isWatchAdded()) {
114
                    openWatchesView();
115
                }
116
                DebuggerManager.getDebuggerManager().removeDebuggerListener(addWatchListener);
117
            } else {
118
                RequestProcessor.getDefault().post(new Runnable() {
119
                    public @Override void run() {
120
                        addWatchListener.getTask().waitFinished();
121
                        if (addWatchListener.isWatchAdded()) {
122
                            SwingUtilities.invokeLater(new Runnable() {
123
                                public @Override void run() {
124
                                    openWatchesView();
125
                                }
126
                            });
127
                        }
128
                        DebuggerManager.getDebuggerManager().removeDebuggerListener(addWatchListener);
129
                    }
130
                });
131
            }
132
        } else {
133
            ResourceBundle bundle = NbBundle.getBundle (AddWatchAction.class);
105
134
106
        WatchPanel wp = new WatchPanel (watchHistory);
135
        WatchPanel wp = new WatchPanel (watchHistory);
107
        JComponent panel = wp.getPanel ();
136
        JComponent panel = wp.getPanel ();
Lines 128-154 Link Here
128
        dialog.setVisible (true);
157
        dialog.setVisible (true);
129
        dialog.dispose ();
158
        dialog.dispose ();
130
159
131
        if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION) return;
160
            if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION) return;
132
        String watch = wp.getExpression ();
161
            String watch = wp.getExpression ();
133
        if ( (watch == null) || 
162
            if ( (watch == null) ||
134
             (watch.trim ().length () == 0)
163
                 (watch.trim ().length () == 0)
135
        )   return;
164
            )   return;
136
        
165
137
        String s = watch;
166
            String s = watch;
138
        int i = s.indexOf (';');
167
            int i = s.indexOf (';');
139
        while (i > 0) {
168
            while (i > 0) {
140
            String ss = s.substring (0, i).trim ();
169
                String ss = s.substring (0, i).trim ();
141
            if (ss.length () > 0)
170
                if (ss.length () > 0)
142
                DebuggerManager.getDebuggerManager ().createWatch (ss);
171
                    DebuggerManager.getDebuggerManager ().createWatch (ss);
143
            s = s.substring (i + 1);
172
                s = s.substring (i + 1);
144
            i = s.indexOf (';');
173
                i = s.indexOf (';');
174
            }
175
            s = s.trim ();
176
            if (s.length () > 0)
177
                DebuggerManager.getDebuggerManager ().createWatch (s);
178
179
            watchHistory = watch;
180
181
            openWatchesView();
145
        }
182
        }
146
        s = s.trim ();
183
    }
147
        if (s.length () > 0)
184
148
            DebuggerManager.getDebuggerManager ().createWatch (s);
185
    private static void openWatchesView() {
149
        
150
        watchHistory = watch;
151
        
152
        // open watches view
186
        // open watches view
153
        TopComponent watchesView = WindowManager.getDefault().findTopComponent("watchesView"); // NOI18N
187
        TopComponent watchesView = WindowManager.getDefault().findTopComponent("watchesView"); // NOI18N
154
        if (watchesView != null && watchesView.isOpened()) {
188
        if (watchesView != null && watchesView.isOpened()) {
Lines 160-163 Link Here
160
        String viewName = VariablesViewButtons.isWatchesViewNested() ? "localsView" : "watchesView";
194
        String viewName = VariablesViewButtons.isWatchesViewNested() ? "localsView" : "watchesView";
161
        ViewActions.openComponent (viewName, false).requestVisible();
195
        ViewActions.openComponent (viewName, false).requestVisible();
162
    }
196
    }
197
198
    private static AddWatchListener performEngineAddWatchAction() {
199
        DebuggerEngine engine = DebuggerManager.getDebuggerManager().getCurrentEngine();
200
        if (engine != null) {
201
            ActionsManager manager = engine.getActionsManager();
202
            if (manager.isEnabled(ActionsManager.ACTION_ADD_WATCH)) {
203
                AddWatchListener addWatchListener = new AddWatchListener();
204
                DebuggerManager.getDebuggerManager().addDebuggerListener(addWatchListener);
205
                Task addWatchTask = manager.postAction(ActionsManager.ACTION_ADD_WATCH);
206
                addWatchListener.setTask(addWatchTask);
207
                return addWatchListener;
208
            }
209
        }
210
        return null;
211
    }
212
213
    private static final class AddWatchListener extends DebuggerManagerAdapter {
214
215
        private boolean watchAdded;
216
        private Task addWatchTask;
217
218
        @Override
219
        public void watchAdded(Watch watch) {
220
            watchAdded = true;
221
        }
222
223
        public boolean isWatchAdded() {
224
            return watchAdded;
225
        }
226
227
        public void setTask(Task addWatchTask) {
228
            this.addWatchTask = addWatchTask;
229
        }
230
231
        public Task getTask() {
232
            return addWatchTask;
233
        }
234
        
235
    }
163
}
236
}

Return to bug 180558