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 198385
Collapse All | Expand All

(-)a/spi.debugger.ui/apichanges.xml (+20 lines)
Lines 152-157 Link Here
152
        </description>
152
        </description>
153
        <issue number="171213"/>
153
        <issue number="171213"/>
154
    </change>
154
    </change>
155
    
156
    <change id="ViewFactory">
157
        <api name="DebuggerCoreSPI"/>
158
        <summary><code>ViewFactory</code> and <code>ViewLifecycle</code> classes added.</summary>
159
        <version major="2" minor="34"/>
160
        <date day="17" month="8" year="2012"/>
161
        <author login="mentlicher"/>
162
        <compatibility binary="compatible" source="compatible" addition="yes" semantic="compatible"/>
163
        <description>
164
            <p>
165
                <code>ViewFactory</code> class introduced to provide GUI views
166
                created from registered view models.
167
                <code>ViewLifecycle</code> class is a support class for a custom view
168
                based on registered view models.
169
            </p>
170
        </description>
171
        <class package="org.netbeans.spi.debugger.ui" name="ViewFactory"/>
172
        <class package="org.netbeans.spi.debugger.ui" name="ViewLifecycle"/>
173
        <issue number="198385"/>
174
    </change>
155
175
156
</changes>
176
</changes>
157
177
(-)a/spi.debugger.ui/manifest.mf (-1 / +1 lines)
Lines 2-7 Link Here
2
OpenIDE-Module: org.netbeans.spi.debugger.ui/1
2
OpenIDE-Module: org.netbeans.spi.debugger.ui/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/debugger/ui/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/debugger/ui/Bundle.properties
4
OpenIDE-Module-Layer: org/netbeans/modules/debugger/resources/mf-layer.xml
4
OpenIDE-Module-Layer: org/netbeans/modules/debugger/resources/mf-layer.xml
5
OpenIDE-Module-Specification-Version: 2.33
5
OpenIDE-Module-Specification-Version: 2.34
6
OpenIDE-Module-Provides: org.netbeans.spi.debugger.ui
6
OpenIDE-Module-Provides: org.netbeans.spi.debugger.ui
7
OpenIDE-Module-Install: org/netbeans/modules/debugger/ui/DebuggerModule.class
7
OpenIDE-Module-Install: org/netbeans/modules/debugger/ui/DebuggerModule.class
(-)a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/views/CustomView.java (+109 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.debugger.ui.views;
43
44
import java.io.Serializable;
45
import org.netbeans.spi.debugger.ui.ViewLifecycle.ModelUpdateListener;
46
47
/**
48
 * Additional view for custom model set.
49
 * 
50
 * @author Martin Entlicher
51
 */
52
public class CustomView extends View {
53
    
54
    private transient String icon;
55
    private transient String displayName;
56
    private transient String toolTip;
57
    
58
    public CustomView(String icon, String name, String helpID, String propertiesHelpID,
59
                      String displayName, String toolTip) {
60
        super(icon, name, helpID, propertiesHelpID, null, null);
61
        this.icon = icon;
62
        this.displayName = displayName;
63
        this.toolTip = toolTip;
64
    }
65
66
    @Override
67
    public String getName() {
68
        return displayName;
69
    }
70
71
    @Override
72
    public String getToolTipText() {
73
        return toolTip;
74
    }
75
    
76
    public static ViewModelListener createViewModelService(String name,
77
                                                           String propertiesHelpID,
78
                                                           ModelUpdateListener mul) {
79
        return new ViewModelListener(name, propertiesHelpID, mul);
80
    }
81
    
82
    @Override
83
    public Object writeReplace() {
84
        return new ResolvableHelper(icon, name, helpID, propertiesHelpID, displayName, toolTip);
85
    }
86
     
87
    /**
88
     * The serializing class.
89
     */
90
    private static final class ResolvableHelper implements Serializable {
91
        
92
        private String[] data;
93
        
94
        private static final long serialVersionUID = 1L;
95
        
96
        ResolvableHelper(String... data) {
97
            this.data = data;
98
        }
99
        
100
        public ResolvableHelper() {
101
            // Just for the purpose of deserialization
102
        }
103
        
104
        public Object readResolve() {
105
            return new CustomView(data[0], data[1], data[2], data[3], data[4], data[5]);
106
        }
107
    }
108
    
109
}
(-)a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/views/View.java (-5 / +8 lines)
Lines 45-50 Link Here
45
package org.netbeans.modules.debugger.ui.views;
45
package org.netbeans.modules.debugger.ui.views;
46
46
47
import java.awt.BorderLayout;
47
import java.awt.BorderLayout;
48
import java.awt.Image;
48
import java.io.Externalizable;
49
import java.io.Externalizable;
49
import java.io.IOException;
50
import java.io.IOException;
50
import java.io.ObjectInput;
51
import java.io.ObjectInput;
Lines 76-88 Link Here
76
    
77
    
77
    private transient JComponent contentComponent;
78
    private transient JComponent contentComponent;
78
    private transient ViewModelListener viewModelListener;
79
    private transient ViewModelListener viewModelListener;
79
    private String name; // Store just the name persistently, we'll create the component from that
80
    protected String name; // Store just the name persistently, we'll create the component from that
80
    private transient String helpID;
81
    protected transient String helpID;
81
    private transient String propertiesHelpID;
82
    protected transient String propertiesHelpID;
82
    private transient String displayNameResource;
83
    private transient String displayNameResource;
83
    private transient String toolTipResource;
84
    private transient String toolTipResource;
84
    
85
    
85
    private View (String icon, String name, String helpID, String propertiesHelpID,
86
    protected View (String icon, String name, String helpID, String propertiesHelpID,
86
                  String displayNameResource, String toolTipResource) {
87
                  String displayNameResource, String toolTipResource) {
87
        setIcon (ImageUtilities.loadImage (icon));
88
        setIcon (ImageUtilities.loadImage (icon));
88
        // Remember the location of the component when closed.
89
        // Remember the location of the component when closed.
Lines 112-118 Link Here
112
            contentComponent = new javax.swing.JPanel(new BorderLayout ());
113
            contentComponent = new javax.swing.JPanel(new BorderLayout ());
113
            
114
            
114
            //tree = Models.createView (Models.EMPTY_MODEL);
115
            //tree = Models.createView (Models.EMPTY_MODEL);
115
            contentComponent.setName (NbBundle.getMessage (View.class, toolTipResource));
116
            if (toolTipResource != null) {
117
                contentComponent.setName (NbBundle.getMessage (View.class, toolTipResource));
118
            }
116
            add (contentComponent, BorderLayout.CENTER);  //NOI18N
119
            add (contentComponent, BorderLayout.CENTER);  //NOI18N
117
            JToolBar toolBar = new JToolBar(JToolBar.VERTICAL);
120
            JToolBar toolBar = new JToolBar(JToolBar.VERTICAL);
118
            toolBar.setFloatable(false);
121
            toolBar.setFloatable(false);
(-)a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/views/ViewComponent.java (+110 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.debugger.ui.views;
43
44
import java.awt.BorderLayout;
45
import javax.swing.JComponent;
46
import javax.swing.JToolBar;
47
import javax.swing.UIManager;
48
import org.openide.util.HelpCtx;
49
import org.openide.util.ImageUtilities;
50
51
/**
52
 *
53
 * @author Martin Entlicher
54
 */
55
public class ViewComponent extends JComponent implements org.openide.util.HelpCtx.Provider {
56
    
57
    private String icon;
58
    private String name;
59
    private String helpID;
60
    private String propertiesHelpID;
61
    private transient JComponent contentComponent;
62
    private ViewModelListener viewModelListener;
63
    
64
    public ViewComponent(String icon, String name, String helpID, String propertiesHelpID) {
65
        this.icon = icon;
66
        this.name = name;
67
        this.helpID = helpID;
68
        this.propertiesHelpID = propertiesHelpID;
69
        initComponents();
70
    }
71
    
72
    private void initComponents() {
73
        setLayout (new BorderLayout ());
74
        contentComponent = new javax.swing.JPanel(new BorderLayout ());
75
        add (contentComponent, BorderLayout.CENTER);  //NOI18N
76
        JToolBar toolBar = new JToolBar(JToolBar.VERTICAL);
77
        toolBar.setFloatable(false);
78
        toolBar.setRollover(true);
79
        toolBar.setBorderPainted(true);
80
        if( "Aqua".equals(UIManager.getLookAndFeel().getID()) ) { //NOI18N
81
            toolBar.setBackground(UIManager.getColor("NbExplorerView.background")); //NOI18N
82
        }
83
        toolBar.setBorder(javax.swing.BorderFactory.createCompoundBorder(
84
                javax.swing.BorderFactory.createMatteBorder(0, 0, 0, 1,
85
                javax.swing.UIManager.getDefaults().getColor("Separator.background")),
86
                javax.swing.BorderFactory.createMatteBorder(0, 0, 0, 1,
87
                javax.swing.UIManager.getDefaults().getColor("Separator.foreground"))));
88
        add(toolBar, BorderLayout.WEST);
89
        JComponent buttonsPane = toolBar;
90
        viewModelListener = new ViewModelListener (
91
            name,
92
            contentComponent,
93
            buttonsPane,
94
            propertiesHelpID,
95
            ImageUtilities.loadImage(icon)
96
        );
97
    }
98
99
    @Override
100
    public void removeNotify() {
101
        if (viewModelListener != null) {
102
            viewModelListener.destroy ();
103
        }
104
    }
105
    
106
    @Override
107
    public HelpCtx getHelpCtx() {
108
        return new org.openide.util.HelpCtx(helpID);
109
    }
110
}
(-)a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/views/ViewModelListener.java (-17 / +47 lines)
Lines 75-80 Link Here
75
import org.netbeans.api.debugger.Session;
75
import org.netbeans.api.debugger.Session;
76
import org.netbeans.spi.debugger.ContextProvider;
76
import org.netbeans.spi.debugger.ContextProvider;
77
import org.netbeans.spi.debugger.SessionProvider;
77
import org.netbeans.spi.debugger.SessionProvider;
78
import org.netbeans.spi.debugger.ui.ViewLifecycle.ModelUpdateListener;
78
import org.netbeans.spi.viewmodel.AsynchronousModelFilter;
79
import org.netbeans.spi.viewmodel.AsynchronousModelFilter;
79
import org.netbeans.spi.viewmodel.CheckNodeModel;
80
import org.netbeans.spi.viewmodel.CheckNodeModel;
80
import org.netbeans.spi.viewmodel.CheckNodeModelFilter;
81
import org.netbeans.spi.viewmodel.CheckNodeModelFilter;
Lines 169-174 Link Here
169
    private Preferences viewPreferences;
170
    private Preferences viewPreferences;
170
    private MessageFormat viewTreeDisplayFormat;
171
    private MessageFormat viewTreeDisplayFormat;
171
    private ViewPreferenceChangeListener prefListener = new ViewPreferenceChangeListener();
172
    private ViewPreferenceChangeListener prefListener = new ViewPreferenceChangeListener();
173
    
174
    private ModelUpdateListener mul;
172
175
173
    private static final RequestProcessor RP = new RequestProcessor(ViewModelListener.class.getName(), 1);
176
    private static final RequestProcessor RP = new RequestProcessor(ViewModelListener.class.getName(), 1);
174
    
177
    
Lines 190-200 Link Here
190
        buttonsPane.setLayout(new GridBagLayout());
193
        buttonsPane.setLayout(new GridBagLayout());
191
        this.propertiesHelpID = propertiesHelpID;
194
        this.propertiesHelpID = propertiesHelpID;
192
        this.viewIcon = viewIcon;
195
        this.viewIcon = viewIcon;
193
        viewPreferences = NbPreferences.forModule(ContextProvider.class).node(VIEW_PREFERENCES_NAME).node(viewType);
196
        initView();
194
        setUp();
197
        setUp();
195
    }
198
    }
196
    // </RAVE>
199
    // </RAVE>
197
    
200
    
201
    ViewModelListener(String viewType, String propertiesHelpID, ModelUpdateListener mul) {
202
        this.viewType = viewType;
203
        this.propertiesHelpID = propertiesHelpID;
204
        this.mul = mul;
205
        setUp();
206
    }
207
    
208
    private void initView() {
209
        // To have reasonable preferred size
210
        view.add(Models.createView(Models.EMPTY_MODEL));
211
    }
212
    
198
    void setUp() {
213
    void setUp() {
199
        if (SwingUtilities.isEventDispatchThread()) {
214
        if (SwingUtilities.isEventDispatchThread()) {
200
            RP.post(new Runnable() {
215
            RP.post(new Runnable() {
Lines 204-209 Link Here
204
            });
219
            });
205
            return ;
220
            return ;
206
        }
221
        }
222
        viewPreferences = NbPreferences.forModule(ContextProvider.class).node(VIEW_PREFERENCES_NAME).node(viewType);
207
        DebuggerManager.getDebuggerManager ().addDebuggerListener (
223
        DebuggerManager.getDebuggerManager ().addDebuggerListener (
208
            DebuggerManager.PROP_CURRENT_ENGINE,
224
            DebuggerManager.PROP_CURRENT_ENGINE,
209
            this
225
            this
Lines 217-223 Link Here
217
        updateModelLazily ();
233
        updateModelLazily ();
218
    }
234
    }
219
235
220
    void destroy () {
236
    public void destroy () {
221
        if (SwingUtilities.isEventDispatchThread()) {
237
        if (SwingUtilities.isEventDispatchThread()) {
222
            RP.post(new Runnable() {
238
            RP.post(new Runnable() {
223
                @Override public void run() {
239
                @Override public void run() {
Lines 255-261 Link Here
255
                }
271
                }
256
            }
272
            }
257
            final boolean haveModels = haveTreeModels || haveNodeModels || tableModels != null && tableModels.size() > 0;
273
            final boolean haveModels = haveTreeModels || haveNodeModels || tableModels != null && tableModels.size() > 0;
258
            if (haveModels && view.getComponentCount() > 0) {
274
            if (haveModels && view != null && view.getComponentCount() > 0) {
259
                JComponent tree = (JComponent) view.getComponent(0);
275
                JComponent tree = (JComponent) view.getComponent(0);
260
                if (!(tree instanceof javax.swing.JTabbedPane)) {
276
                if (!(tree instanceof javax.swing.JTabbedPane)) {
261
                    Models.setModelsToView(tree, null);
277
                    Models.setModelsToView(tree, null);
Lines 281-302 Link Here
281
                currentSession = null;
297
                currentSession = null;
282
                providerToDisplay = null;
298
                providerToDisplay = null;
283
                buttons = null;
299
                buttons = null;
284
                SwingUtilities.invokeLater(new Runnable() {
300
                if (view != null) {
285
                    @Override
301
                    SwingUtilities.invokeLater(new Runnable() {
286
                    public void run() {
302
                        @Override
287
                        // Have to access UI in AWT
303
                        public void run() {
288
                        synchronized (destroyLock) {
304
                            // Have to access UI in AWT
289
                            if (buttons == null) { // Still destroyed. Might be re-created in between.
305
                            synchronized (destroyLock) {
290
                                buttonsPane.removeAll();
306
                                if (buttons == null) { // Still destroyed. Might be re-created in between.
291
                                view.removeAll();
307
                                    buttonsPane.removeAll();
308
                                    view.removeAll();
309
                                }
292
                            }
310
                            }
293
                        }
311
                        }
294
                    }
312
                    });
295
                });
313
                }
296
                sls = new ArrayList<ViewModelListener>(subListeners);
314
                sls = new ArrayList<ViewModelListener>(subListeners);
297
                subListeners.clear();
315
                subListeners.clear();
298
                isUp = false;
316
                isUp = false;
299
            }
317
            }
318
            mul = null;
300
        }
319
        }
301
        for (ViewModelListener l : sls) {
320
        for (ViewModelListener l : sls) {
302
            l.destroy();
321
            l.destroy();
Lines 463-469 Link Here
463
        buttons = theButtons;
482
        buttons = theButtons;
464
        tabbedPane = cp.lookupFirst(viewPath, javax.swing.JTabbedPane.class);
483
        tabbedPane = cp.lookupFirst(viewPath, javax.swing.JTabbedPane.class);
465
484
466
        ModelsChangeRefresher mcr = new ModelsChangeRefresher();
485
        ModelsChangeRefresher mcr = new ModelsChangeRefresher(e);
467
        Customizer[] modelListCustomizers = new Customizer[] {
486
        Customizer[] modelListCustomizers = new Customizer[] {
468
            //(Customizer) treeModels,
487
            //(Customizer) treeModels,
469
            //(Customizer) treeModelFilters,
488
            //(Customizer) treeModelFilters,
Lines 496-502 Link Here
496
            }
515
            }
497
        }
516
        }
498
517
499
        refreshModel();
518
        refreshModel(e);
500
    }
519
    }
501
520
502
    private static void addAsCustomizers(List<Customizer> modelListCustomizerLists, Object[] modelLists) {
521
    private static void addAsCustomizers(List<Customizer> modelListCustomizerLists, Object[] modelLists) {
Lines 519-525 Link Here
519
        return models;
538
        return models;
520
    }
539
    }
521
540
522
    private synchronized void refreshModel() {
541
    private synchronized void refreshModel(DebuggerEngine e) {
523
        models.clear();
542
        models.clear();
524
        if (mm == null) {
543
        if (mm == null) {
525
            // Destroyed
544
            // Destroyed
Lines 614-619 Link Here
614
        } else {
633
        } else {
615
            newModel = null;
634
            newModel = null;
616
        }
635
        }
636
        if (mul != null) {
637
            mul.modelUpdated(newModel, e);
638
        }
639
        if (view == null) {
640
            return;
641
        }
617
        SwingUtilities.invokeLater(new Runnable() {
642
        SwingUtilities.invokeLater(new Runnable() {
618
            @Override
643
            @Override
619
            public void run() {
644
            public void run() {
Lines 882-888 Link Here
882
907
883
    private class ModelsChangeRefresher implements PropertyChangeListener, Runnable {
908
    private class ModelsChangeRefresher implements PropertyChangeListener, Runnable {
884
        
909
        
910
        private DebuggerEngine e;
885
        private RequestProcessor.Task task;
911
        private RequestProcessor.Task task;
912
        
913
        ModelsChangeRefresher(DebuggerEngine e) {
914
            this.e = e;
915
        }
886
916
887
        @Override
917
        @Override
888
        public synchronized void propertyChange(PropertyChangeEvent evt) {
918
        public synchronized void propertyChange(PropertyChangeEvent evt) {
Lines 894-900 Link Here
894
924
895
        @Override
925
        @Override
896
        public void run() {
926
        public void run() {
897
            refreshModel();
927
            refreshModel(e);
898
        }
928
        }
899
        
929
        
900
    }
930
    }
(-)a/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/ViewFactory.java (+116 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.debugger.ui;
43
44
import javax.swing.JComponent;
45
import org.netbeans.modules.debugger.ui.views.CustomView;
46
import org.netbeans.modules.debugger.ui.views.ViewComponent;
47
import org.netbeans.modules.debugger.ui.views.ViewModelListener;
48
import org.openide.windows.TopComponent;
49
50
/**
51
 * Factory that produces debugger views created from registered view models
52
 * (see {@link org.netbeans.spi.viewmodel.Model} and it's extension interfaces).
53
 * 
54
 * @author Martin Entlicher
55
 * @since 2.34
56
 */
57
public class ViewFactory {
58
    
59
    private static ViewFactory vf;
60
    
61
    private ViewFactory() {}
62
    
63
    /**
64
     * Get the default implementation of view factory.
65
     * 
66
     * @return The view factory.
67
     */
68
    public static synchronized ViewFactory getDefault() {
69
        if (vf == null) {
70
            vf = new ViewFactory();
71
        }
72
        return vf;
73
    }
74
    
75
    /**
76
     * Create {@link TopComponent} view from models registered under 'name' path.
77
     * @param icon The icon resource of the TopComponent
78
     * @param name Name of the view, under which are the models registered
79
     * @param helpID The helpID of the created TopComponent
80
     * @param propertiesHelpID The helpID of properties displayed in the view
81
     * @param displayName Display name of the view
82
     * @param toolTip Tooltip of the view
83
     * @return TopComponent containing the view created from registered models.
84
     */
85
    public TopComponent createViewTC(String icon, String name, String helpID, String propertiesHelpID,
86
                                     String displayName, String toolTip) {
87
        CustomView v = new CustomView(icon, name, helpID, propertiesHelpID, displayName, toolTip);
88
        return v;
89
    }
90
    
91
    /**
92
     * Create {@link JComponent} view from models registered under 'name' path.
93
     * @param icon The icon resource, possibly used by the button toolbar in the view
94
     * @param name Name of the view, under which are the models registered
95
     * @param helpID The helpID of the created TopComponent
96
     * @param propertiesHelpID The helpID of properties displayed in the view
97
     * @return Component containing the view created from registered models.
98
     */
99
    public JComponent createViewComponent(String icon, String name, String helpID, String propertiesHelpID) {
100
        JComponent c = new ViewComponent(icon, name, helpID, propertiesHelpID);
101
        return c;
102
    }
103
    
104
    /**
105
     * Create a support for a custom view based on models registered under 'name' path.
106
     * @param name Name of the view, under which are the models registered
107
     * @param propertiesHelpID The helpID of properties displayed in the view
108
     * @return ViewLifecycle support object for the custom view
109
     */
110
    public ViewLifecycle createAbstractView(String name, String propertiesHelpID) {
111
        ViewLifecycle.CompoundModelUpdateListener cmul = new ViewLifecycle.CompoundModelUpdateListener();
112
        ViewModelListener vml = CustomView.createViewModelService(name, propertiesHelpID, cmul);
113
        return new ViewLifecycle(vml, cmul);
114
    }
115
    
116
}
(-)a/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/ViewLifecycle.java (+153 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.debugger.ui;
43
44
import java.util.LinkedList;
45
import java.util.List;
46
import org.netbeans.api.debugger.DebuggerEngine;
47
import org.netbeans.modules.debugger.ui.views.ViewModelListener;
48
import org.netbeans.spi.viewmodel.Models;
49
import org.netbeans.spi.viewmodel.Models.CompoundModel;
50
51
/**
52
 * Support class for a custom view based on registered view models.
53
 * 
54
 * @author Martin Entlicher
55
 * @since 2.34
56
 */
57
public final class ViewLifecycle {
58
    
59
    private ViewModelListener vml;
60
    private final CompoundModelUpdateListener cmul;
61
62
    ViewLifecycle(ViewModelListener vml, CompoundModelUpdateListener cmul) {
63
        this.vml = vml;
64
        this.cmul = cmul;
65
    }
66
    
67
    /**
68
     * Get the current compound model, that can be used to construct the custom
69
     * view.
70
     * @return The current compound model
71
     */
72
    public Models.CompoundModel getModel() {
73
        return cmul.getCurrentModel();
74
    }
75
    
76
    /**
77
     * Add a listener, which is called with the updated compound model.
78
     * @param mul The model update listener
79
     */
80
    public void addModelUpdateListener(ModelUpdateListener mul) {
81
        cmul.addModelUpdateListener(mul);
82
    }
83
    
84
    /**
85
     * Remove a model update listener
86
     * @param mul The model update listener
87
     */
88
    public void removeModelUpdateListener(ModelUpdateListener mul) {
89
        cmul.removeModelUpdateListener(mul);
90
    }
91
92
    /**
93
     * Destroy the underlying data, call this method when the view is closed.
94
     * Model updates will no longer be received after this method is called.
95
     */
96
    public void destroy() {
97
        vml.destroy();
98
    }
99
100
101
    /**
102
     * Model update listener, notified with updated compound model.
103
     */
104
    public static interface ModelUpdateListener {
105
        
106
        /**
107
         * Called when compound model is updated.
108
         * 
109
         * @param compoundModel The new compound model
110
         * @param de The associated debugger engine, whose models were used to create the
111
         * compound model. Can be <code>null</code>, when no active debugger engine
112
         * was found.
113
         */
114
        public void modelUpdated(Models.CompoundModel compoundModel, DebuggerEngine de);
115
        
116
    }
117
    
118
    static class CompoundModelUpdateListener implements ModelUpdateListener {
119
        
120
        private final List<ModelUpdateListener> muls = new LinkedList<ModelUpdateListener>();
121
        private CompoundModel currentCompoundModel;
122
123
        public void addModelUpdateListener(ModelUpdateListener mul) {
124
            synchronized(muls) {
125
                muls.add(mul);
126
            }
127
        }
128
129
        public void removeModelUpdateListener(ModelUpdateListener mul) {
130
            synchronized(muls) {
131
                muls.remove(mul);
132
            }
133
        }
134
        
135
        public CompoundModel getCurrentModel() {
136
            return currentCompoundModel;
137
        }
138
139
        @Override
140
        public void modelUpdated(CompoundModel compoundModel, DebuggerEngine de) {
141
            List<ModelUpdateListener> muls2;
142
            synchronized(muls) {
143
                currentCompoundModel = compoundModel;
144
                muls2 = new LinkedList<ModelUpdateListener>(muls);
145
            }
146
            for (ModelUpdateListener mul : muls2) {
147
                mul.modelUpdated(compoundModel, de);
148
            }
149
        }
150
        
151
    }
152
    
153
}

Return to bug 198385