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

(-)/home/enrico/Lavoro/releases/spi.viewmodel/build/classes/org/netbeans/modules/viewmodel2/Bundle.properties (+49 lines)
Line 0 Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
4
#
5
# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
# Other names may be trademarks of their respective owners.
7
#
8
# The contents of this file are subject to the terms of either the GNU
9
# General Public License Version 2 only ("GPL") or the Common
10
# Development and Distribution License("CDDL") (collectively, the
11
# "License"). You may not use this file except in compliance with the
12
# License. You can obtain a copy of the License at
13
# http://www.netbeans.org/cddl-gplv2.html
14
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15
# specific language governing permissions and limitations under the
16
# License.  When distributing the software, include this License Header
17
# Notice in each file and include the License file at
18
# nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
19
# particular file as subject to the "Classpath" exception as provided
20
# by Oracle in the GPL Version 2 section of the License file that
21
# accompanied this code. If applicable, add the following below the
22
# License Header, with the fields enclosed by brackets [] replaced by
23
# your own identifying information:
24
# "Portions Copyrighted [year] [name of copyright owner]"
25
#
26
# Contributor(s):
27
#
28
# The Original Software is NetBeans. The Initial Developer of the Original
29
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
# Microsystems, Inc. All Rights Reserved.
31
#
32
# If you wish your version of this file to be governed by only the CDDL
33
# or only the GPL Version 2, indicate your decision by adding
34
# "[Contributor] elects to include this software in this distribution
35
# under the [CDDL or GPL Version 2] license." If you do not indicate a
36
# single choice of license, a recipient has the option to distribute
37
# your version of this file under either the CDDL, the GPL Version 2 or
38
# to extend the choice of license to its licensees as provided above.
39
# However, if you add GPL Version 2 code and therefore, elected the GPL
40
# Version 2 license, then the option applies only if the new code is
41
# made subject to such option by the copyright holder.
42
43
OpenIDE-Module-Name=TreeTableView Model (Streamsim)
44
OpenIDE-Module-Display-Category=Infrastructure
45
OpenIDE-Module-Short-Description=TreeTableView Model
46
OpenIDE-Module-Long-Description=TreeTableView Model
47
48
EvaluatingProp=Evaluating...
49
WaitNode=Please wait...
(-)/home/enrico/Lavoro/releases/spi.viewmodel/build/no-license.txt (+1 lines)
Line 0 Link Here
1
[NO LICENSE SPECIFIED]
(-)/home/enrico/Lavoro/releases/spi.viewmodel/examples/TreeModelExample1.java (-71 / +32 lines)
Lines 1-47 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-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
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
import java.io.File;
1
import java.io.File;
46
import java.util.ArrayList;
2
import java.util.ArrayList;
47
import javax.swing.JComponent;
3
import javax.swing.JComponent;
Lines 51-88 Link Here
51
import org.netbeans.spi.viewmodel.TreeModelListener;
7
import org.netbeans.spi.viewmodel.TreeModelListener;
52
8
53
public class TreeModelExample1 implements TreeModel {
9
public class TreeModelExample1 implements TreeModel {
54
        
10
55
    public Object[] getChildren (Object parent, int from, int to) {
11
    public Object[] getChildren(Object parent, int from, int to) {
56
        if (parent == ROOT)
12
        if (parent == ROOT) {
57
            return File.listRoots ();
13
            return File.listRoots();
58
        return ((File) parent).listFiles ();
14
        }
15
        return ((File) parent).listFiles();
59
    }
16
    }
60
    
17
61
    public Object getRoot () {
18
    public Object getRoot() {
62
        return ROOT;
19
        return ROOT;
63
    }
20
    }
64
    
21
65
    public boolean isLeaf (Object node) {
22
    public boolean isLeaf(Object node) {
66
        if (node == ROOT)
23
        if (node == ROOT) {
67
            return false;
24
            return false;
68
        return ((File) node).isFile ();
25
        }
26
        return ((File) node).isFile();
69
    }
27
    }
70
    
28
71
    public void addTreeModelListener (TreeModelListener l) {}
29
    public void addTreeModelListener(TreeModelListener l) {
72
    public void removeTreeModelListener (TreeModelListener l) {}
30
    }
73
    
31
74
    public static void main (String[] args) {
32
    public void removeTreeModelListener(TreeModelListener l) {
75
        TreeModelExample1 tme = new TreeModelExample1 ();
33
    }
76
        JComponent ttv = Models.createView (
34
77
            tme,              // TreeModel
35
    public static void main(String[] args) {
78
            null,             // NodeModel
36
        TreeModelExample1 tme = new TreeModelExample1();
79
            null,             // TableModel
37
        JComponent ttv = Models.createView(
80
            null,             // NodeActionsProvider
38
                tme, // TreeModel
81
            new ArrayList ()  // list of ColumnModels
39
                null, // NodeModel
40
                null, // TableModel
41
                null, // NodeActionsProvider
42
                new ArrayList() // list of ColumnModels
82
        );
43
        );
83
        JFrame f = new JFrame ("Tree Model Example 1");
44
        JFrame f = new JFrame("Tree Model Example 1");
84
        f.getContentPane ().add (ttv);
45
        f.getContentPane().add(ttv);
85
        f.pack ();
46
        f.pack();
86
        f.show ();
47
        f.show();
87
    }
48
    }
88
}
49
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/examples/TreeModelExample2.java (-87 / +57 lines)
Lines 1-47 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-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
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
import java.awt.event.ActionEvent;
1
import java.awt.event.ActionEvent;
46
import java.io.File;
2
import java.io.File;
47
import java.net.MalformedURLException;
3
import java.net.MalformedURLException;
Lines 57-114 Link Here
57
import org.netbeans.spi.viewmodel.TreeModel;
13
import org.netbeans.spi.viewmodel.TreeModel;
58
import org.netbeans.spi.viewmodel.TreeModelListener;
14
import org.netbeans.spi.viewmodel.TreeModelListener;
59
15
16
public class TreeModelExample2 implements TreeModel, NodeModel {
60
17
61
public class TreeModelExample2 implements TreeModel, NodeModel {    
18
    public Object[] getChildren(Object parent, int from, int to) {
62
    
19
        if (parent == ROOT) {
63
    public Object[] getChildren (Object parent, int from, int to) {
20
            return File.listRoots();
64
        if (parent == ROOT)
21
        }
65
            return File.listRoots ();
22
        return ((File) parent).listFiles();
66
        return ((File) parent).listFiles ();
67
    }
23
    }
68
    
24
69
    public Object getRoot () {
25
    public Object getRoot() {
70
        return ROOT;
26
        return ROOT;
71
    }
27
    }
72
    
28
73
    public boolean isLeaf (Object node) {
29
    public boolean isLeaf(Object node) {
74
        if (node == ROOT)
30
        if (node == ROOT) {
75
            return false;
31
            return false;
76
        return ((File) node).isFile ();
32
        }
33
        return ((File) node).isFile();
34
    }
35
36
    public void addTreeModelListener(TreeModelListener l) {
37
    }
38
39
    public void removeTreeModelListener(TreeModelListener l) {
77
    }
40
    }
78
    
41
79
    public void addTreeModelListener (TreeModelListener l) {}
42
    public String getDisplayName(Object node) {
80
    public void removeTreeModelListener (TreeModelListener l) {}
43
        if (node == ROOT) {
81
    
44
            return "Name";
82
    public String getDisplayName (Object node) {
45
        }
83
        if (node == ROOT) return "Name";
46
        String name = ((File) node).getName();
84
        String name = ((File) node).getName ();
47
        if (name.length() < 1) {
85
        if (name.length () < 1) return ((File) node).getAbsolutePath ();
48
            return ((File) node).getAbsolutePath();
49
        }
86
        return name;
50
        return name;
87
    }
51
    }
88
    
52
89
    public String getIconBase (Object node) {
53
    public String getIconBase(Object node) {
90
        if (node == ROOT) return "folder";
54
        if (node == ROOT) {
91
        if (((File) node).isDirectory ()) return "folder";
55
            return "folder";
56
        }
57
        if (((File) node).isDirectory()) {
58
            return "folder";
59
        }
92
        return "file";
60
        return "file";
93
    }
61
    }
94
    
62
95
    public String getShortDescription (Object node) {
63
    public String getShortDescription(Object node) {
96
        if (node == ROOT) return "Name";
64
        if (node == ROOT) {
97
        return ((File) node).getAbsolutePath ();
65
            return "Name";
98
    }
66
        }
99
    
67
        return ((File) node).getAbsolutePath();
100
    public static void main (String[] args) {
68
    }
101
        TreeModelExample2 tme = new TreeModelExample2 ();
69
102
        JComponent ttv = Models.createView (
70
    public static void main(String[] args) {
103
            tme,              // TreeModel
71
        TreeModelExample2 tme = new TreeModelExample2();
104
            tme,              // NodeModel
72
        JComponent ttv = Models.createView(
105
            null,             // TableModel
73
                tme, // TreeModel
106
            null,             // NodeActionsProvider
74
                tme, // NodeModel
107
            new ArrayList ()  // list of ColumnModels
75
                null, // TableModel
76
                null, // NodeActionsProvider
77
                new ArrayList() // list of ColumnModels
108
        );
78
        );
109
        JFrame f = new JFrame ("Tree Model Example 2");
79
        JFrame f = new JFrame("Tree Model Example 2");
110
        f.getContentPane ().add (ttv);
80
        f.getContentPane().add(ttv);
111
        f.pack ();
81
        f.pack();
112
        f.show ();
82
        f.show();
113
    }    
83
    }
114
}
84
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/examples/TreeModelExample3.java (-102 / +73 lines)
Lines 1-47 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-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
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
import java.awt.event.ActionEvent;
1
import java.awt.event.ActionEvent;
46
import java.io.File;
2
import java.io.File;
47
import java.net.MalformedURLException;
3
import java.net.MalformedURLException;
Lines 58-140 Link Here
58
import org.netbeans.spi.viewmodel.TreeModel;
14
import org.netbeans.spi.viewmodel.TreeModel;
59
import org.netbeans.spi.viewmodel.TreeModelListener;
15
import org.netbeans.spi.viewmodel.TreeModelListener;
60
16
61
public class TreeModelExample3 implements TreeModel, NodeModel, NodeActionsProvider {    
17
public class TreeModelExample3 implements TreeModel, NodeModel, NodeActionsProvider {
62
    
18
63
    public Object[] getChildren (Object parent, int from, int to) {
19
    public Object[] getChildren(Object parent, int from, int to) {
64
        if (parent == ROOT)
20
        if (parent == ROOT) {
65
            return File.listRoots ();
21
            return File.listRoots();
66
        return ((File) parent).listFiles ();
22
        }
23
        return ((File) parent).listFiles();
67
    }
24
    }
68
    
25
69
    public Object getRoot () {
26
    public Object getRoot() {
70
        return ROOT;
27
        return ROOT;
71
    }
28
    }
72
    
29
73
    public boolean isLeaf (Object node) {
30
    public boolean isLeaf(Object node) {
74
        if (node == ROOT)
31
        if (node == ROOT) {
75
            return false;
32
            return false;
76
        return ((File) node).isFile ();
33
        }
34
        return ((File) node).isFile();
77
    }
35
    }
78
    
36
79
    public void addTreeModelListener (TreeModelListener l) {}
37
    public void addTreeModelListener(TreeModelListener l) {
80
    public void removeTreeModelListener (TreeModelListener l) {}
38
    }
81
    
39
82
    public String getDisplayName (Object node) {
40
    public void removeTreeModelListener(TreeModelListener l) {
83
        if (node == ROOT) return "Name";
41
    }
84
        String name = ((File) node).getName ();
42
85
        if (name.length () < 1) return ((File) node).getAbsolutePath ();
43
    public String getDisplayName(Object node) {
44
        if (node == ROOT) {
45
            return "Name";
46
        }
47
        String name = ((File) node).getName();
48
        if (name.length() < 1) {
49
            return ((File) node).getAbsolutePath();
50
        }
86
        return name;
51
        return name;
87
    }
52
    }
88
    
53
89
    public String getIconBase (Object node) {
54
    public String getIconBase(Object node) {
90
        if (node == ROOT) return "folder";
55
        if (node == ROOT) {
91
        if (((File) node).isDirectory ()) return "folder";
56
            return "folder";
57
        }
58
        if (((File) node).isDirectory()) {
59
            return "folder";
60
        }
92
        return "file";
61
        return "file";
93
    }
62
    }
94
    
63
95
    public String getShortDescription (Object node) {
64
    public String getShortDescription(Object node) {
96
        if (node == ROOT) return "Name";
65
        if (node == ROOT) {
97
        return ((File) node).getAbsolutePath ();
66
            return "Name";
98
    }
67
        }
99
    
68
        return ((File) node).getAbsolutePath();
100
    public Action[] getActions (final Object node) {
69
    }
101
        return new Action [] {
70
102
            new AbstractAction ("Open") {
71
    public Action[] getActions(final Object node) {
103
                public void actionPerformed (ActionEvent e) {
72
        return new Action[]{
104
                    performDefaultAction (node);
73
            new AbstractAction("Open") {
74
                public void actionPerformed(ActionEvent e) {
75
                    performDefaultAction(node);
105
                }
76
                }
106
            },
77
            },
107
            new AbstractAction ("Delete") {
78
            new AbstractAction("Delete") {
108
                public void actionPerformed (ActionEvent e) {
79
                public void actionPerformed(ActionEvent e) {
109
                    ((File) node).delete ();
80
                    ((File) node).delete();
110
                }
81
                }
111
            }
82
            }
112
        };
83
        };
113
    }
84
    }
114
    
85
115
    public void performDefaultAction (Object node) {
86
    public void performDefaultAction(Object node) {
116
        try {
87
        try {
117
            JFrame f = new JFrame ("View");
88
            JFrame f = new JFrame("View");
118
            f.getContentPane ().add (new JEditorPane (((File) node).toURL ()));
89
            f.getContentPane().add(new JEditorPane(((File) node).toURL()));
119
            f.pack ();
90
            f.pack();
120
            f.show ();
91
            f.show();
121
        } catch (Exception e) {
92
        } catch (Exception e) {
122
            e.printStackTrace();
93
            e.printStackTrace();
123
        }
94
        }
124
    }
95
    }
125
    
96
126
    public static void main (String[] args) {
97
    public static void main(String[] args) {
127
        TreeModelExample3 tme = new TreeModelExample3 ();
98
        TreeModelExample3 tme = new TreeModelExample3();
128
        JComponent ttv = Models.createView (
99
        JComponent ttv = Models.createView(
129
            tme,              // TreeModel
100
                tme, // TreeModel
130
            tme,              // NodeModel
101
                tme, // NodeModel
131
            null,             // TableModel
102
                null, // TableModel
132
            tme,              // NodeActionsProvider
103
                tme, // NodeActionsProvider
133
            new ArrayList ()  // list of ColumnModels
104
                new ArrayList() // list of ColumnModels
134
        );
105
        );
135
        JFrame f = new JFrame ("Tree Model Example 3");
106
        JFrame f = new JFrame("Tree Model Example 3");
136
        f.getContentPane ().add (ttv);
107
        f.getContentPane().add(ttv);
137
        f.pack ();
108
        f.pack();
138
        f.show ();
109
        f.show();
139
    }    
110
    }
140
}
111
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/examples/TreeModelExample4.java (-124 / +97 lines)
Lines 1-181 Link Here
1
/*
1
import com.streamsim.commonsgui.viewmodel.DefaultColumnModel;
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-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
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
import java.awt.event.ActionEvent;
2
import java.awt.event.ActionEvent;
46
import java.io.File;
3
import java.io.File;
47
import java.io.FileInputStream;
4
import java.io.FileInputStream;
48
import java.net.MalformedURLException;
49
import java.util.ArrayList;
5
import java.util.ArrayList;
50
import java.util.Date;
51
import javax.swing.AbstractAction;
6
import javax.swing.AbstractAction;
52
import javax.swing.Action;
7
import javax.swing.Action;
53
import javax.swing.JComponent;
8
import javax.swing.JComponent;
54
import javax.swing.JDialog;
55
import javax.swing.JEditorPane;
9
import javax.swing.JEditorPane;
56
import javax.swing.JFrame;
10
import javax.swing.JFrame;
57
58
import org.netbeans.spi.viewmodel.Models;
11
import org.netbeans.spi.viewmodel.Models;
59
import org.netbeans.spi.viewmodel.ColumnModel;
60
import org.netbeans.spi.viewmodel.NodeActionsProvider;
12
import org.netbeans.spi.viewmodel.NodeActionsProvider;
61
import org.netbeans.spi.viewmodel.NodeModel;
13
import org.netbeans.spi.viewmodel.NodeModel;
62
import org.netbeans.spi.viewmodel.TableModel;
14
import org.netbeans.spi.viewmodel.TableModel;
63
import org.netbeans.spi.viewmodel.TreeModel;
15
import org.netbeans.spi.viewmodel.TreeModel;
64
import org.netbeans.spi.viewmodel.TreeModelListener;
16
import org.netbeans.spi.viewmodel.TreeModelListener;
65
17
18
public class TreeModelExample4 implements TreeModel, NodeModel,
19
        NodeActionsProvider, TableModel {
66
20
67
public class TreeModelExample4 implements TreeModel, NodeModel, 
21
    public Object[] getChildren(Object parent, int from, int to) {
68
NodeActionsProvider, TableModel {    
22
        if (parent == ROOT) {
69
    
23
            return File.listRoots();
70
    public Object[] getChildren (Object parent, int from, int to) {
24
        }
71
        if (parent == ROOT)
25
        return ((File) parent).listFiles();
72
            return File.listRoots ();
73
        return ((File) parent).listFiles ();
74
    }
26
    }
75
    
27
76
    public Object getRoot () {
28
    public Object getRoot() {
77
        return ROOT;
29
        return ROOT;
78
    }
30
    }
79
    
31
80
    public boolean isLeaf (Object node) {
32
    public boolean isLeaf(Object node) {
81
        if (node == ROOT)
33
        if (node == ROOT) {
82
            return false;
34
            return false;
83
        return ((File) node).isFile ();
35
        }
36
        return ((File) node).isFile();
37
    }
38
39
    public void addTreeModelListener(TreeModelListener l) {
84
    }
40
    }
85
    
41
86
    public void addTreeModelListener (TreeModelListener l) {}
42
    public void removeTreeModelListener(TreeModelListener l) {
87
    public void removeTreeModelListener (TreeModelListener l) {}
43
    }
88
    
44
89
    public String getDisplayName (Object node) {
45
    public String getDisplayName(Object node) {
90
        if (node == ROOT) return "Name";
46
        if (node == ROOT) {
91
        String name = ((File) node).getName ();
47
            return "Name";
92
        if (name.length () < 1) return ((File) node).getAbsolutePath ();
48
        }
49
        String name = ((File) node).getName();
50
        if (name.length() < 1) {
51
            return ((File) node).getAbsolutePath();
52
        }
93
        return name;
53
        return name;
94
    }
54
    }
95
    
55
96
    public String getIconBase (Object node) {
56
    public String getIconBase(Object node) {
97
        if (node == ROOT) return "folder";
57
        if (node == ROOT) {
98
        if (((File) node).isDirectory ()) return "folder";
58
            return "folder";
59
        }
60
        if (((File) node).isDirectory()) {
61
            return "folder";
62
        }
99
        return "file";
63
        return "file";
100
    }
64
    }
101
    
65
102
    public String getShortDescription (Object node) {
66
    public String getShortDescription(Object node) {
103
        if (node == ROOT) return "Name";
67
        if (node == ROOT) {
104
        return ((File) node).getAbsolutePath ();
68
            return "Name";
105
    }
69
        }
106
    
70
        return ((File) node).getAbsolutePath();
107
    public Action[] getActions (final Object node) {
71
    }
108
        return new Action [] {
72
109
            new AbstractAction ("Open") {
73
    public Action[] getActions(final Object node) {
110
                public void actionPerformed (ActionEvent e) {
74
        return new Action[]{
111
                    performDefaultAction (node);
75
            new AbstractAction("Open") {
76
                public void actionPerformed(ActionEvent e) {
77
                    performDefaultAction(node);
112
                }
78
                }
113
            },
79
            },
114
            new AbstractAction ("Delete") {
80
            new AbstractAction("Delete") {
115
                public void actionPerformed (ActionEvent e) {
81
                public void actionPerformed(ActionEvent e) {
116
                    ((File) node).delete ();
82
                    ((File) node).delete();
117
                }
83
                }
118
            }
84
            }
119
        };
85
        };
120
    }
86
    }
121
    
87
122
    public void performDefaultAction (Object node) {
88
    public void performDefaultAction(Object node) {
123
        try {
89
        try {
124
            JFrame f = new JFrame ("View");
90
            JFrame f = new JFrame("View");
125
            f.getContentPane ().add (new JEditorPane (((File) node).toURL ()));
91
            f.getContentPane().add(new JEditorPane(((File) node).toURL()));
126
            f.pack ();
92
            f.pack();
127
            f.show ();
93
            f.show();
128
        } catch (Exception e) {
94
        } catch (Exception e) {
129
            e.printStackTrace();
95
            e.printStackTrace();
130
        }
96
        }
131
    }
97
    }
132
    
98
133
    public Object getValueAt (Object row, String columnID) {
99
    public Object getValueAt(Object row, String columnID) {
134
        try {
100
        try {
135
            if (row == ROOT) return null;
101
            if (row == ROOT) {
136
            if (columnID.equals ("sizeID")) {
102
                return null;
137
                if (((File) row).isDirectory ()) return "<dir>";
103
            }
138
                return "" + new FileInputStream ((File) row).getChannel ().size ();
104
            if (columnID.equals("sizeID")) {
105
                if (((File) row).isDirectory()) {
106
                    return "<dir>";
107
                }
108
                return "" + new FileInputStream((File) row).getChannel().size();
139
            }
109
            }
140
        } catch (Exception e) {
110
        } catch (Exception e) {
141
            e.printStackTrace ();
111
            e.printStackTrace();
142
        }
112
        }
143
        return "";
113
        return "";
144
    }
114
    }
145
    
115
146
    public boolean isReadOnly (Object row, String columnID) {
116
    public boolean isReadOnly(Object row, String columnID) {
147
        return true;
117
        return true;
148
    }
118
    }
149
    
119
150
    public void setValueAt (Object row, String columnID, Object value) {
120
    public void setValueAt(Object row, String columnID, Object value) {
151
    }
121
    }
152
    
122
153
    public static void main (String[] args) {
123
    public static void main(String[] args) {
154
        TreeModelExample4 tme = new TreeModelExample4 ();
124
        TreeModelExample4 tme = new TreeModelExample4();
155
        ArrayList columns = new ArrayList ();
125
        ArrayList columns = new ArrayList();
156
        columns.add (new ColumnModel () {
126
        columns.add(new DefaultColumnModel() {
157
            public String getID () {
127
            @Override
128
            public String getID() {
158
                return "sizeID";
129
                return "sizeID";
159
            }
130
            }
160
131
161
            public String getDisplayName () {
132
            @Override
133
            public String getDisplayName() {
162
                return "size";
134
                return "size";
163
            }
135
            }
164
136
165
            public Class getType () {
137
            @Override
138
            public Class getType() {
166
                return String.class;
139
                return String.class;
167
            }
140
            }
168
        });
141
        });
169
        JComponent ttv = Models.createView (
142
        JComponent ttv = Models.createView(
170
            tme,              // TreeModel
143
                tme, // TreeModel
171
            tme,              // NodeModel
144
                tme, // NodeModel
172
            tme,              // TableModel
145
                tme, // TableModel
173
            tme,              // NodeActionsProvider
146
                tme, // NodeActionsProvider
174
            columns           // list of ColumnModels
147
                columns // list of ColumnModels
175
        );
148
        );
176
        JFrame f = new JFrame ("Tree Model Example 4");
149
        JFrame f = new JFrame("Tree Model Example 4");
177
        f.getContentPane ().add (ttv);
150
        f.getContentPane().add(ttv);
178
        f.pack ();
151
        f.pack();
179
        f.show ();
152
        f.show();
180
    }    
153
    }
181
}
154
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/AsynchronousModel.java (-6 / +6 lines)
Lines 39-45 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.viewmodel;
42
package org.netbeans.modules.viewmodel;
44
43
45
import java.util.concurrent.Executor;
44
import java.util.concurrent.Executor;
Lines 47-67 Link Here
47
import org.netbeans.spi.viewmodel.UnknownTypeException;
46
import org.netbeans.spi.viewmodel.UnknownTypeException;
48
47
49
/**
48
/**
50
 * Not in public API, AsynchronousModelFilter is sufficient, since we have a default.
49
 * Not in public API, AsynchronousModelFilter is sufficient, since we have a
50
 * default.
51
 *
51
 *
52
 * @author Martin Entlicher
52
 * @author Martin Entlicher
53
 */
53
 */
54
public interface AsynchronousModel {
54
public interface AsynchronousModel {
55
55
56
    /**
56
    /**
57
     * Provide the threading information for view models method calls.
57
     * Provide the threading information for view models method calls. The
58
     * The returned Executor is used to call methods identified by
58
     * returned Executor is used to call methods identified by {@link CALL}
59
     * {@link CALL} enum.
59
     * enum.
60
     *
60
     *
61
     * @param asynchCall Identification of the method call
61
     * @param asynchCall Identification of the method call
62
     * @param node Object node
62
     * @param node Object node
63
     * @return an instance of Executor
63
     * @return an instance of Executor
64
     */
64
     */
65
    Executor asynchronous(CALL asynchCall, Object node) throws UnknownTypeException;
65
    Executor asynchronous(CALL asynchCall, Object node) throws UnknownTypeException;
66
    
66
67
}
67
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/Bundle.properties (-2 / +2 lines)
Lines 40-49 Link Here
40
# Version 2 license, then the option applies only if the new code is
40
# Version 2 license, then the option applies only if the new code is
41
# made subject to such option by the copyright holder.
41
# made subject to such option by the copyright holder.
42
42
43
OpenIDE-Module-Name=TreeTableView Model
43
OpenIDE-Module-Name=TreeTableView Model (Streamsim)
44
OpenIDE-Module-Display-Category=Infrastructure
44
OpenIDE-Module-Display-Category=Infrastructure
45
OpenIDE-Module-Short-Description=TreeTableView Model
45
OpenIDE-Module-Short-Description=TreeTableView Model
46
OpenIDE-Module-Long-Description=TreeTableView Model. For the list of included fixed bugs please check http://wiki.netbeans.org/NetBeans8.1PatchesInfo.
46
OpenIDE-Module-Long-Description=TreeTableView Model
47
47
48
EvaluatingProp=Evaluating...
48
EvaluatingProp=Evaluating...
49
WaitNode=Please wait...
49
WaitNode=Please wait...
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/Column.java (-25 / +32 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.viewmodel;
44
package org.netbeans.modules.viewmodel;
46
45
47
import java.beans.PropertyEditor;
46
import java.beans.PropertyEditor;
Lines 61-91 Link Here
61
60
62
    public static final String PROP_ORDER_NUMBER = "OrderNumberOutline"; // NOI18N
61
    public static final String PROP_ORDER_NUMBER = "OrderNumberOutline"; // NOI18N
63
62
64
    private PropertyEditor propertyEditor;
63
    private final PropertyEditor propertyEditor;
65
    private ColumnModel columnModel;
64
    private final ColumnModel columnModel;
66
65
67
    Column (
66
    Column (
68
        ColumnModel columnModel
67
        ColumnModel columnModel
69
    ) {
68
    ) {
70
        super (
69
        super (
71
            columnModel.getID (),
70
            columnModel.getID (),
72
            columnModel.getType () == null ? 
71
                columnModel.getType() == null
73
                String.class : 
72
                ? String.class
74
                columnModel.getType (),
73
                : columnModel.getType(),
75
            Actions.cutAmpersand(columnModel.getDisplayName ()),
74
            Actions.cutAmpersand(columnModel.getDisplayName ()),
76
            columnModel.getShortDescription ()
75
            columnModel.getShortDescription ()
77
        );
76
        );
78
        this.columnModel = columnModel;
77
        this.columnModel = columnModel;
79
        setValue (
78
        setValue (
80
            "SortableColumn",
79
            "SortableColumn",
81
            Boolean.valueOf (columnModel.isSortable ())
80
                columnModel.isSortable()
82
        );
81
        );
83
        if (columnModel.getType () == null)
82
        if (columnModel.getType() == null) // Default column!
84
            // Default column!
83
        {
85
            setValue (
84
            setValue (
86
                "TreeColumnTTV", 
85
                "TreeColumnTTV", 
87
                Boolean.TRUE
86
                Boolean.TRUE
88
            );
87
            );
88
        }
89
        if (Mnemonics.findMnemonicAmpersand(columnModel.getDisplayName()) >= 0) {
89
        if (Mnemonics.findMnemonicAmpersand(columnModel.getDisplayName()) >= 0) {
90
            setValue("ColumnDisplayNameWithMnemonicTTV", columnModel.getDisplayName ()); // NOI18N
90
            setValue("ColumnDisplayNameWithMnemonicTTV", columnModel.getDisplayName ()); // NOI18N
91
        }
91
        }
Lines 106-113 Link Here
106
    
106
    
107
    int getOrderNumber () {
107
    int getOrderNumber () {
108
        Object o = getValue ("OrderNumberTTV");
108
        Object o = getValue ("OrderNumberTTV");
109
        if (o == null) return -1;
109
        if (o == null) {
110
        return ((Integer) o).intValue ();
110
            return -1;
111
        }
112
        return ((Integer) o);
111
    }
113
    }
112
    
114
    
113
    int getModelOrderNumber() {
115
    int getModelOrderNumber() {
Lines 128-172 Link Here
128
        columnModel.setVisible(!hidden);
130
        columnModel.setVisible(!hidden);
129
    }
131
    }
130
132
133
    @Override
131
    public Object getValue () {
134
    public Object getValue () {
132
        return null;
135
        return null;
133
    }
136
    }
134
    
137
    
138
    @Override
135
    public void setValue (Object obj) {
139
    public void setValue (Object obj) {
136
    }
140
    }
137
141
142
    @Override
138
    public Object getValue (String propertyName) {
143
    public Object getValue (String propertyName) {
139
        if (PROP_ORDER_NUMBER.equals (propertyName)) {
144
        if (PROP_ORDER_NUMBER.equals (propertyName)) {
140
            int index = columnModel.getCurrentOrderNumber();
145
            int index = columnModel.getCurrentOrderNumber();
141
            return new Integer(index);
146
            return index;
147
        }
148
        if ("InvisibleInTreeTableView".equals(propertyName)) {
149
            return !columnModel.isVisible();
142
        }
150
        }
143
        if ("InvisibleInTreeTableView".equals (propertyName)) 
144
            return Boolean.valueOf (!columnModel.isVisible ());
145
        if ("SortableColumn".equals (propertyName)) {
151
        if ("SortableColumn".equals (propertyName)) {
146
            return Boolean.valueOf (columnModel.isSortable());
152
            return columnModel.isSortable();
153
        }
154
        if ("DescendingOrderTTV".equals(propertyName)) {
155
            return columnModel.isSortedDescending();
147
        }
156
        }
148
        if ("DescendingOrderTTV".equals (propertyName)) 
149
            return Boolean.valueOf (columnModel.isSortedDescending ());
150
        return super.getValue (propertyName);
157
        return super.getValue (propertyName);
151
    }
158
    }
152
    
159
    
160
    @Override
153
    public void setValue (String propertyName, Object newValue) {
161
    public void setValue (String propertyName, Object newValue) {
154
        if (PROP_ORDER_NUMBER.equals (propertyName)) {
162
        if (PROP_ORDER_NUMBER.equals (propertyName)) {
155
            int index = ((Integer) newValue).intValue();
163
            int index = ((Integer) newValue);
156
            columnModel.setCurrentOrderNumber(index);
164
            columnModel.setCurrentOrderNumber(index);
157
        } else
165
        } else /*if ("SortableColumn".equals (propertyName))
158
        /*if ("SortableColumn".equals (propertyName))
159
            columnModel.setSorted (
166
            columnModel.setSorted (
160
                ((Boolean) newValue).booleanValue ()
167
                ((Boolean) newValue).booleanValue ()
161
            );
168
            );
162
        else*/
169
         else*/ if ("DescendingOrderTTV".equals(propertyName)) {
163
        if ("DescendingOrderTTV".equals (propertyName)) 
164
            columnModel.setSortedDescending (
170
            columnModel.setSortedDescending (
165
                ((Boolean) newValue).booleanValue ()
171
                    ((Boolean) newValue));
166
            );
172
        } else {
167
        else
168
        super.setValue (propertyName, newValue);
173
        super.setValue (propertyName, newValue);
169
    }
174
    }
175
    }
170
176
171
    boolean isSorted() {
177
    boolean isSorted() {
172
        return columnModel.isSorted();
178
        return columnModel.isSorted();
Lines 184-189 Link Here
184
        columnModel.setSortedDescending(descending);
190
        columnModel.setSortedDescending(descending);
185
    }
191
    }
186
192
193
    @Override
187
    public PropertyEditor getPropertyEditor () {
194
    public PropertyEditor getPropertyEditor () {
188
        return propertyEditor;
195
        return propertyEditor;
189
    }
196
    }
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/DefaultColumn.java (-21 / +18 lines)
Lines 41-85 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.viewmodel;
44
package org.netbeans.modules.viewmodel;
46
45
47
import java.beans.PropertyEditor;
48
import org.netbeans.spi.viewmodel.ColumnModel;
49
import org.openide.nodes.PropertySupport;
46
import org.openide.nodes.PropertySupport;
50
47
51
/**
48
/**
52
 *
49
 *
53
 * @author   Jan Jancura
50
 * @author Jan Jancura
54
 */
51
 */
55
public class DefaultColumn extends PropertySupport.ReadWrite {
52
public class DefaultColumn extends PropertySupport.ReadWrite {
56
53
57
54
    DefaultColumn() {
58
    DefaultColumn () {
55
        super(
59
        super (
56
                "default",
60
            "default",
57
                String.class,
61
            String.class,
58
                "DN",
62
            "DN",
59
                "SDN"
63
            "SDN"
64
        );
60
        );
65
        setValue (
61
        setValue(
66
            "SortableColumn",
62
                "SortableColumn",
67
            Boolean.TRUE
63
                Boolean.TRUE
68
        );
64
        );
69
        setValue (
65
        setValue(
70
            "TreeColumnTTV",
66
                "TreeColumnTTV",
71
            Boolean.TRUE
67
                Boolean.TRUE
72
        );
68
        );
73
    }
69
    }
74
70
75
    public Object getValue () {
71
    @Override
72
    public Object getValue() {
76
        return null;
73
        return null;
77
    }
74
    }
78
    
75
79
    public void setValue (Object obj) {
76
    @Override
77
    public void setValue(Object obj) {
80
    }
78
    }
81
//    public PropertyEditor getPropertyEditor () {
79
//    public PropertyEditor getPropertyEditor () {
82
//        return propertyEditor;
80
//        return propertyEditor;
83
//    }
81
//    }
84
}
82
}
85
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/DefaultTreeExpansionManager.java (-22 / +35 lines)
Lines 39-70 Link Here
39
 * 
39
 * 
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.viewmodel;
42
package org.netbeans.modules.viewmodel;
44
43
45
import java.util.HashMap;
44
import java.util.HashMap;
46
import java.util.Map;
45
import java.util.Map;
47
import java.util.Set;
46
import java.util.Set;
48
import java.util.WeakHashMap;
47
import java.util.WeakHashMap;
49
50
import org.netbeans.spi.viewmodel.Models;
48
import org.netbeans.spi.viewmodel.Models;
51
import org.openide.util.WeakSet;
49
import org.openide.util.WeakSet;
52
50
53
/**
51
/**
54
 * Ugly class, that takes care that the expansion state is always managed for the object under the given node.
52
 * Ugly class, that takes care that the expansion state is always managed for
55
 * This is necessary for trees that have equal nodes under various branches, or for recursive trees.
53
 * the object under the given node. This is necessary for trees that have equal
56
 * 
54
 * nodes under various branches, or for recursive trees.
55
 *
57
 * @author Martin
56
 * @author Martin
58
 */
57
 */
59
public class DefaultTreeExpansionManager {
58
public class DefaultTreeExpansionManager {
60
    
59
61
    private static Map<Models.CompoundModel, DefaultTreeExpansionManager> managers = new WeakHashMap<Models.CompoundModel, DefaultTreeExpansionManager>();
60
    private static final Map<Models.CompoundModel, DefaultTreeExpansionManager> managers = new WeakHashMap<>();
62
61
63
    private Object currentChildren;
62
    private Object currentChildren;
64
    private Map<Object, Set<Object>> expandedNodes = new HashMap<Object, Set<Object>>();
63
    private final Map<Object, Set<Object>> expandedNodes = new HashMap<>();
65
    
64
66
    public static synchronized DefaultTreeExpansionManager get(Models.CompoundModel model) {
65
    public static synchronized DefaultTreeExpansionManager get(Models.CompoundModel model) {
67
        if (model == null) throw new NullPointerException();
66
        if (model == null) {
67
            throw new NullPointerException();
68
        }
68
        DefaultTreeExpansionManager manager = managers.get(model);
69
        DefaultTreeExpansionManager manager = managers.get(model);
69
        if (manager == null) {
70
        if (manager == null) {
70
            manager = new DefaultTreeExpansionManager();
71
            manager = new DefaultTreeExpansionManager();
Lines 72-100 Link Here
72
        }
73
        }
73
        return manager;
74
        return manager;
74
    }
75
    }
75
    
76
76
    public static synchronized void copyExpansions(Models.CompoundModel oldCM, Models.CompoundModel newCM) {
77
    public static synchronized void copyExpansions(Models.CompoundModel oldCM, Models.CompoundModel newCM) {
77
        DefaultTreeExpansionManager oldManager = get(oldCM);
78
        DefaultTreeExpansionManager oldManager = get(oldCM);
78
        DefaultTreeExpansionManager newManager = get(newCM);
79
        DefaultTreeExpansionManager newManager = get(newCM);
79
        Map<Object, Set<Object>> expandedNodes;
80
        Map<Object, Set<Object>> expandedNodes;
80
        synchronized (oldManager) {
81
        synchronized (oldManager) {
81
            expandedNodes = new java.util.HashMap<Object, Set<Object>>(oldManager.expandedNodes);
82
            expandedNodes = new java.util.HashMap<>(oldManager.expandedNodes);
82
        }
83
        }
83
        synchronized (newManager) {
84
        synchronized (newManager) {
84
            newManager.expandedNodes.putAll(expandedNodes);
85
            newManager.expandedNodes.putAll(expandedNodes);
85
        }
86
        }
86
    }
87
    }
87
    
88
88
    private DefaultTreeExpansionManager() {}
89
    private DefaultTreeExpansionManager() {
89
    
90
    }
90
    /** Must be called before every query, external synchronization with the model call is required. */
91
92
    /**
93
     * Must be called before every query, external synchronization with the
94
     * model call is required.
95
     */
91
    public void setChildrenToActOn(Object ch) {
96
    public void setChildrenToActOn(Object ch) {
92
        currentChildren = ch;
97
        currentChildren = ch;
93
    }
98
    }
94
    
99
95
    /** External synchronization with currentNode required. */
100
    /**
101
     * External synchronization with currentNode required.
102
     */
96
    public synchronized boolean isExpanded(Object child) {
103
    public synchronized boolean isExpanded(Object child) {
97
        if (currentChildren == null) throw new NullPointerException("Call setChildrenToActOn() before!!!");
104
        if (currentChildren == null) {
105
            throw new NullPointerException("Call setChildrenToActOn() before!!!");
106
        }
98
        try {
107
        try {
99
            Set<Object> expanded = expandedNodes.get(currentChildren);
108
            Set<Object> expanded = expandedNodes.get(currentChildren);
100
            if (expanded != null && expanded.contains(child)) {
109
            if (expanded != null && expanded.contains(child)) {
Lines 107-117 Link Here
107
    }
116
    }
108
117
109
    public synchronized void setExpanded(Object child) {
118
    public synchronized void setExpanded(Object child) {
110
        if (currentChildren == null) throw new NullPointerException("Call setChildrenToActOn() before!!!");
119
        if (currentChildren == null) {
120
            throw new NullPointerException("Call setChildrenToActOn() before!!!");
121
        }
111
        try {
122
        try {
112
            Set<Object> expanded = expandedNodes.get(currentChildren);
123
            Set<Object> expanded = expandedNodes.get(currentChildren);
113
            if (expanded == null) {
124
            if (expanded == null) {
114
                expanded = new WeakSet<Object>();
125
                expanded = new WeakSet<>();
115
                expandedNodes.put(currentChildren, expanded);
126
                expandedNodes.put(currentChildren, expanded);
116
            }
127
            }
117
            expanded.add(child);
128
            expanded.add(child);
Lines 121-127 Link Here
121
    }
132
    }
122
133
123
    public synchronized void setCollapsed(Object child) {
134
    public synchronized void setCollapsed(Object child) {
124
        if (currentChildren == null) throw new NullPointerException("Call setChildrenToActOn() before!!!");
135
        if (currentChildren == null) {
136
            throw new NullPointerException("Call setChildrenToActOn() before!!!");
137
        }
125
        try {
138
        try {
126
            Set<Object> expanded = expandedNodes.get(currentChildren);
139
            Set<Object> expanded = expandedNodes.get(currentChildren);
127
            if (expanded != null) {
140
            if (expanded != null) {
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/DelegatingCellEditor.java (-9 / +8 lines)
Lines 41-53 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.viewmodel;
44
package org.netbeans.modules.viewmodel;
46
45
47
import java.awt.Component;
46
import java.awt.Component;
48
import java.awt.Point;
47
import java.awt.Point;
49
import java.awt.Rectangle;
50
import java.awt.event.KeyEvent;
51
import java.awt.event.MouseEvent;
48
import java.awt.event.MouseEvent;
52
import java.lang.ref.Reference;
49
import java.lang.ref.Reference;
53
import java.lang.ref.WeakReference;
50
import java.lang.ref.WeakReference;
Lines 58-64 Link Here
58
import org.netbeans.spi.viewmodel.TableRendererModel;
55
import org.netbeans.spi.viewmodel.TableRendererModel;
59
import org.netbeans.spi.viewmodel.UnknownTypeException;
56
import org.netbeans.spi.viewmodel.UnknownTypeException;
60
import org.netbeans.swing.outline.Outline;
57
import org.netbeans.swing.outline.Outline;
61
import org.netbeans.swing.outline.OutlineModel;
62
import org.openide.nodes.Node;
58
import org.openide.nodes.Node;
63
import org.openide.util.Exceptions;
59
import org.openide.util.Exceptions;
64
60
Lines 68-75 Link Here
68
 */
64
 */
69
class DelegatingCellEditor implements TableCellEditor {
65
class DelegatingCellEditor implements TableCellEditor {
70
66
71
    private String columnID;
67
    private final String columnID;
72
    private TableCellEditor defaultEditor;
68
    private final TableCellEditor defaultEditor;
73
    private TableCellEditor currentEditor;
69
    private TableCellEditor currentEditor;
74
    private Reference<TableCellEditor> canceledEditorRef;
70
    private Reference<TableCellEditor> canceledEditorRef;
75
71
Lines 126-131 Link Here
126
        if (anEvent instanceof MouseEvent) {
122
        if (anEvent instanceof MouseEvent) {
127
            MouseEvent event = (MouseEvent) anEvent;
123
            MouseEvent event = (MouseEvent) anEvent;
128
            Point p = event.getPoint();
124
            Point p = event.getPoint();
125
129
            // Locate the editor under the event location
126
            // Locate the editor under the event location
130
            //int column = outline.columnAtPoint(p);
127
            //int column = outline.columnAtPoint(p);
131
            row = outline.rowAtPoint(p);
128
            row = outline.rowAtPoint(p);
Lines 186-196 Link Here
186
        if (currentEditor != null) {
183
        if (currentEditor != null) {
187
            boolean status = currentEditor.stopCellEditing();
184
            boolean status = currentEditor.stopCellEditing();
188
            if (status) {
185
            if (status) {
189
                canceledEditorRef = new WeakReference<TableCellEditor>(currentEditor);
186
                canceledEditorRef = new WeakReference<>(currentEditor);
190
                currentEditor = null;
187
                currentEditor = null;
191
            }
188
            }
192
            return status;
189
            return status;
193
        }
190
        }
191
        Exceptions.printStackTrace(new IllegalStateException("No current editor."));
194
        return true;
192
        return true;
195
    }
193
    }
196
194
Lines 198-207 Link Here
198
    public void cancelCellEditing() {
196
    public void cancelCellEditing() {
199
        if (currentEditor != null) {
197
        if (currentEditor != null) {
200
            currentEditor.cancelCellEditing();
198
            currentEditor.cancelCellEditing();
201
            canceledEditorRef = new WeakReference<TableCellEditor>(currentEditor);
199
            canceledEditorRef = new WeakReference<>(currentEditor);
202
            currentEditor = null;
200
            currentEditor = null;
203
            return ;
201
            return;
204
        }
202
        }
203
        Exceptions.printStackTrace(new IllegalStateException("No current editor."));
205
    }
204
    }
206
205
207
    @Override
206
    @Override
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/DelegatingCellRenderer.java (-4 / +2 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.viewmodel;
44
package org.netbeans.modules.viewmodel;
46
45
47
import java.awt.Component;
46
import java.awt.Component;
Lines 54-60 Link Here
54
import org.netbeans.swing.outline.OutlineModel;
53
import org.netbeans.swing.outline.OutlineModel;
55
import org.openide.explorer.view.Visualizer;
54
import org.openide.explorer.view.Visualizer;
56
import org.openide.nodes.Node;
55
import org.openide.nodes.Node;
57
import org.openide.util.Exceptions;
58
56
59
/**
57
/**
60
 *
58
 *
Lines 62-69 Link Here
62
 */
60
 */
63
class DelegatingCellRenderer implements TableCellRenderer {
61
class DelegatingCellRenderer implements TableCellRenderer {
64
62
65
    private String columnID;
63
    private final String columnID;
66
    private TableCellRenderer defaultRenderer;
64
    private final TableCellRenderer defaultRenderer;
67
65
68
    public DelegatingCellRenderer(String columnID, TableCellRenderer defaultRenderer) {
66
    public DelegatingCellRenderer(String columnID, TableCellRenderer defaultRenderer) {
69
        this.columnID = columnID;
67
        this.columnID = columnID;
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/ExceptionNode.java (-42 / +21 lines)
Lines 41-109 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.viewmodel;
44
package org.netbeans.modules.viewmodel;
46
45
47
import java.awt.event.ActionEvent;
48
import java.beans.PropertyEditor;
49
import java.lang.IllegalAccessException;
50
import java.lang.ref.WeakReference;
51
import java.lang.reflect.InvocationTargetException;
52
import java.util.ArrayList;
53
import java.util.Collections;
54
import java.util.HashMap;
55
import javax.swing.AbstractAction;
56
import javax.swing.Action;
57
58
import org.netbeans.spi.viewmodel.ColumnModel;
59
import org.netbeans.spi.viewmodel.TreeModel;
60
import org.netbeans.spi.viewmodel.TableModel;
61
import org.netbeans.spi.viewmodel.UnknownTypeException;
62
63
import org.openide.nodes.AbstractNode;
46
import org.openide.nodes.AbstractNode;
64
import org.openide.nodes.Children;
47
import org.openide.nodes.Children;
65
import org.openide.nodes.Node;
66
import org.openide.nodes.PropertySupport;
67
import org.openide.nodes.Sheet;
68
import org.openide.util.HelpCtx;
48
import org.openide.util.HelpCtx;
69
import org.openide.util.lookup.Lookups;
49
import org.openide.util.lookup.Lookups;
70
50
71
72
/**
51
/**
73
 *
52
 *
74
 * @author   Jan Jancura
53
 * @author Jan Jancura
75
 */
54
 */
76
public class ExceptionNode extends AbstractNode {
55
public class ExceptionNode extends AbstractNode {
77
56
78
    
57
    private final Exception exception;
79
    private Exception exception;
80
    
81
    // init ....................................................................
82
58
59
    // init ....................................................................
83
    /**
60
    /**
84
    * Creates root of call stack for given producer.
61
     * Creates root of call stack for given producer.
85
    */
62
     */
86
    public ExceptionNode ( 
63
    public ExceptionNode(
87
        Exception exception
64
            Exception exception
88
    ) {
65
    ) {
89
        super (
66
        super(
90
            Children.LEAF,
67
                Children.LEAF,
91
            Lookups.singleton (exception)
68
                Lookups.singleton(exception)
92
        );
69
        );
93
        this.exception = exception;
70
        this.exception = exception;
94
        setIconBaseWithExtension ("org/openide/resources/actions/empty.gif");
71
        setIconBaseWithExtension("org/openide/resources/actions/empty.gif");
95
    }
72
    }
96
    
73
97
    public String getName () {
74
    @Override
98
        return exception.getLocalizedMessage ();
75
    public String getName() {
76
        return exception.getLocalizedMessage();
99
    }
77
    }
100
    
78
101
    public String getDisplayName () {
79
    @Override
102
        return exception.getLocalizedMessage ();
80
    public String getDisplayName() {
81
        return exception.getLocalizedMessage();
103
    }
82
    }
104
83
84
    @Override
105
    public HelpCtx getHelpCtx() {
85
    public HelpCtx getHelpCtx() {
106
        return new HelpCtx (getClass ());
86
        return new HelpCtx(getClass());
107
    }
87
    }
108
}
88
}
109
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/HyperColumnModel.java (-5 / +4 lines)
Lines 39-45 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.viewmodel;
42
package org.netbeans.modules.viewmodel;
44
43
45
import java.util.HashSet;
44
import java.util.HashSet;
Lines 47-54 Link Here
47
import org.netbeans.spi.viewmodel.ColumnModel;
46
import org.netbeans.spi.viewmodel.ColumnModel;
48
47
49
/**
48
/**
50
 * Represents a binding of specific column model of inner view
49
 * Represents a binding of specific column model of inner view to the main colum
51
 * to the main colum model of the enclosing view.
50
 * model of the enclosing view.
52
 *
51
 *
53
 * @author Martin Entlicher
52
 * @author Martin Entlicher
54
 */
53
 */
Lines 63-69 Link Here
63
        this.specific = specific;
62
        this.specific = specific;
64
        ids = createAllIDs(main, specific);
63
        ids = createAllIDs(main, specific);
65
    }
64
    }
66
    
65
67
    private static Set<String> createAllIDs(ColumnModel... cms) {
66
    private static Set<String> createAllIDs(ColumnModel... cms) {
68
        Set<String> allIds = new HashSet<String>();
67
        Set<String> allIds = new HashSet<String>();
69
        for (ColumnModel cm : cms) {
68
        for (ColumnModel cm : cms) {
Lines 103-109 Link Here
103
    public Class getType() {
102
    public Class getType() {
104
        return specific.getType();
103
        return specific.getType();
105
    }
104
    }
106
    
105
107
    Set<String> getAllIDs() {
106
    Set<String> getAllIDs() {
108
        return ids;
107
        return ids;
109
    }
108
    }
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/HyperCompoundModel.java (-6 / +5 lines)
Lines 39-45 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.viewmodel;
42
package org.netbeans.modules.viewmodel;
44
43
45
import java.awt.datatransfer.Transferable;
44
import java.awt.datatransfer.Transferable;
Lines 54-66 Link Here
54
 */
53
 */
55
public class HyperCompoundModel implements Model {
54
public class HyperCompoundModel implements Model {
56
55
57
    private Models.CompoundModel main;
56
    private final Models.CompoundModel main;
58
    private Models.CompoundModel[] models;
57
    private final Models.CompoundModel[] models;
59
    private TreeModelFilter treeFilter;
58
    private final TreeModelFilter treeFilter;
60
59
61
    public HyperCompoundModel(Models.CompoundModel main,
60
    public HyperCompoundModel(Models.CompoundModel main,
62
                              Models.CompoundModel[] models,
61
            Models.CompoundModel[] models,
63
                              TreeModelFilter treeFilter) {
62
            TreeModelFilter treeFilter) {
64
        this.main = main;
63
        this.main = main;
65
        this.models = models;
64
        this.models = models;
66
        this.treeFilter = treeFilter;
65
        this.treeFilter = treeFilter;
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/ModelRootChangeListener.java (-3 / +2 lines)
Lines 39-54 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.viewmodel;
42
package org.netbeans.modules.viewmodel;
44
43
45
import org.netbeans.spi.viewmodel.ModelListener;
44
import org.netbeans.spi.viewmodel.ModelListener;
46
45
47
/**
46
/**
48
 * A marker interface for model root change listener.
47
 * A marker interface for model root change listener.
49
 * 
48
 *
50
 * @author Martin Entlicher
49
 * @author Martin Entlicher
51
 */
50
 */
52
public interface ModelRootChangeListener extends ModelListener {
51
public interface ModelRootChangeListener extends ModelListener {
53
    
52
54
}
53
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/OutlineTable.java (-330 / +335 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.viewmodel;
44
package org.netbeans.modules.viewmodel;
46
45
47
import java.awt.BorderLayout;
46
import java.awt.BorderLayout;
Lines 71-97 Link Here
71
import javax.swing.event.ListSelectionEvent;
70
import javax.swing.event.ListSelectionEvent;
72
import javax.swing.event.TableColumnModelEvent;
71
import javax.swing.event.TableColumnModelEvent;
73
import javax.swing.event.TableColumnModelListener;
72
import javax.swing.event.TableColumnModelListener;
73
import javax.swing.table.TableCellEditor;
74
import javax.swing.table.TableCellRenderer;
74
import javax.swing.table.TableColumn;
75
import javax.swing.table.TableColumn;
75
import javax.swing.table.TableColumnModel;
76
import javax.swing.table.TableColumnModel;
76
import javax.swing.text.DefaultEditorKit;
77
import javax.swing.text.DefaultEditorKit;
77
import javax.swing.tree.TreeNode;
78
import javax.swing.tree.TreeNode;
78
import javax.swing.tree.TreePath;
79
import javax.swing.tree.TreePath;
79
80
import org.netbeans.spi.viewmodel.Models;
81
import org.netbeans.spi.viewmodel.ColumnModel;
80
import org.netbeans.spi.viewmodel.ColumnModel;
82
83
import org.netbeans.spi.viewmodel.DnDNodeModel;
81
import org.netbeans.spi.viewmodel.DnDNodeModel;
82
import org.netbeans.spi.viewmodel.Models;
84
import org.netbeans.swing.etable.ETableColumn;
83
import org.netbeans.swing.etable.ETableColumn;
85
import org.netbeans.swing.etable.ETableColumnModel;
84
import org.netbeans.swing.etable.ETableColumnModel;
86
import org.netbeans.swing.outline.DefaultOutlineModel;
85
import org.netbeans.swing.outline.DefaultOutlineModel;
87
import org.netbeans.swing.outline.Outline;
86
import org.netbeans.swing.outline.Outline;
88
import org.netbeans.swing.outline.OutlineModel;
87
import org.netbeans.swing.outline.OutlineModel;
89
import org.openide.awt.Actions;
88
import org.openide.awt.Actions;
90
import org.openide.explorer.ExplorerUtils;
91
import org.openide.explorer.ExplorerManager;
89
import org.openide.explorer.ExplorerManager;
90
import org.openide.explorer.ExplorerUtils;
92
import org.openide.explorer.view.OutlineView;
91
import org.openide.explorer.view.OutlineView;
93
import org.openide.explorer.view.Visualizer;
92
import org.openide.explorer.view.Visualizer;
94
95
import org.openide.nodes.AbstractNode;
93
import org.openide.nodes.AbstractNode;
96
import org.openide.nodes.Children;
94
import org.openide.nodes.Children;
97
import org.openide.nodes.Node;
95
import org.openide.nodes.Node;
Lines 102-145 Link Here
102
import org.openide.util.Exceptions;
100
import org.openide.util.Exceptions;
103
import org.openide.windows.TopComponent;
101
import org.openide.windows.TopComponent;
104
102
105
106
/**
103
/**
107
 * Implements table visual representation of the data from models, using Outline view.
104
 * Implements table visual representation of the data from models, using Outline
105
 * view.
108
 *
106
 *
109
 * @author   Martin Entlicher
107
 * @author Martin Entlicher
110
 */
108
 */
111
public class OutlineTable extends JPanel implements
109
public class OutlineTable extends JPanel implements
112
ExplorerManager.Provider, PropertyChangeListener {
110
        ExplorerManager.Provider, PropertyChangeListener {
113
111
114
    private static final Logger logger = Logger.getLogger(OutlineTable.class.getName());
112
    private static final Logger logger = Logger.getLogger(OutlineTable.class.getName());
115
    
113
116
    private ExplorerManager     explorerManager;
114
    private ExplorerManager explorerManager;
117
    final MyTreeTable           treeTable; // Accessed from tests
115
    final MyTreeTable treeTable; // Accessed from tests
118
    Node.Property[]             columns; // Accessed from tests
116
    Node.Property[] columns; // Accessed from tests
119
    private TableColumn[]       tableColumns;
117
    private TableColumn[] tableColumns;
120
    private int[]               columnVisibleMap; // Column index -> visible index
118
    private int[] columnVisibleMap; // Column index -> visible index
121
    private boolean             ignoreCreateDefaultColumnsFromModel;
119
    private boolean ignoreCreateDefaultColumnsFromModel;
122
    //private IndexedColumn[]     icolumns;
120
    //private IndexedColumn[]     icolumns;
123
    private boolean             isDefaultColumnAdded;
121
    private boolean isDefaultColumnAdded;
124
    private int                 defaultColumnIndex; // The index of the tree column
122
    private int defaultColumnIndex; // The index of the tree column
125
    private boolean             ignoreMove; // Whether to ignore column movement events
123
    private boolean ignoreMove; // Whether to ignore column movement events
126
    private boolean             isSettingModelUp; // Whether a model is being set up
124
    private boolean isSettingModelUp; // Whether a model is being set up
127
    //private List                expandedPaths = new ArrayList ();
125
    //private List                expandedPaths = new ArrayList ();
128
    TreeModelRoot               currentTreeModelRoot; // Accessed from test
126
    TreeModelRoot currentTreeModelRoot; // Accessed from test
129
    
127
130
    //private TreeTableView       ttv;
128
    //private TreeTableView       ttv;
131
    //private TreeView            tv;
129
    //private TreeView            tv;
132
    
130
    public OutlineTable() {
133
    public OutlineTable () {
131
        setLayout(new BorderLayout());
134
        setLayout (new BorderLayout ());
132
        treeTable = new MyTreeTable();
135
            treeTable = new MyTreeTable ();
133
        treeTable.getOutline().setRootVisible(false);
136
            treeTable.getOutline().setRootVisible (false);
134
        treeTable.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
137
            treeTable.setVerticalScrollBarPolicy 
135
        treeTable.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
138
                (JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
136
        treeTable.setTreeHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
139
            treeTable.setHorizontalScrollBarPolicy 
137
        treeTable.setBorder(new JScrollPane().getBorder());
140
                (JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
138
        add(treeTable, "Center");  //NOI18N
141
            treeTable.setTreeHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
142
        add (treeTable, "Center");  //NOI18N
143
//        ttv = new TreeTableView(); // To test only
139
//        ttv = new TreeTableView(); // To test only
144
//        add(ttv, "East");
140
//        add(ttv, "East");
145
//        tv = new BeanTreeView(); // To test only
141
//        tv = new BeanTreeView(); // To test only
Lines 150-163 Link Here
150
            // Track column visibility changes.
146
            // Track column visibility changes.
151
            //   No impact on order property
147
            //   No impact on order property
152
            //   Change visibility map
148
            //   Change visibility map
153
154
            @Override
149
            @Override
155
            public void columnAdded(TableColumnModelEvent e) {
150
            public void columnAdded(TableColumnModelEvent e) {
156
                if (logger.isLoggable(Level.FINE)) {
151
                if (logger.isLoggable(Level.FINE)) {
157
                    logger.fine("columnAdded("+e+") to = "+e.getToIndex());
152
                    logger.fine("columnAdded(" + e + ") to = " + e.getToIndex());
158
                    //logger.log(Level.FINE, "  called from", new IllegalStateException("TEST"));
153
                    //logger.log(Level.FINE, "  called from", new IllegalStateException("TEST"));
159
                    TableColumnModel tcme = (TableColumnModel) e.getSource();
154
                    TableColumnModel tcme = (TableColumnModel) e.getSource();
160
                    logger.fine(" column header = '"+tcme.getColumn(e.getToIndex()).getHeaderValue()+"'");
155
                    logger.fine(" column header = '" + tcme.getColumn(e.getToIndex()).getHeaderValue() + "'");
161
                    dumpColumnVisibleMap();
156
                    dumpColumnVisibleMap();
162
                }
157
                }
163
                if (tableColumns != null && e.getToIndex() >= 0) {
158
                if (tableColumns != null && e.getToIndex() >= 0) {
Lines 177-183 Link Here
177
                        }
172
                        }
178
                    }
173
                    }
179
                    if (logger.isLoggable(Level.FINE)) {
174
                    if (logger.isLoggable(Level.FINE)) {
180
                        logger.fine("  to index = "+visibleIndex+", column index = "+columnIndex);
175
                        logger.fine("  to index = " + visibleIndex + ", column index = " + columnIndex);
181
                    }
176
                    }
182
                    if (columnIndex != -1) {
177
                    if (columnIndex != -1) {
183
                        int prefferedVisibleIndex = columnVisibleMap[columnIndex];
178
                        int prefferedVisibleIndex = columnVisibleMap[columnIndex];
Lines 193-206 Link Here
193
                            }
188
                            }
194
                        }
189
                        }
195
                        if (logger.isLoggable(Level.FINE)) {
190
                        if (logger.isLoggable(Level.FINE)) {
196
                            logger.fine("  to index = "+visibleIndex+", column = "+columns[columnIndex].getDisplayName()+", columnVisibleIndex = "+columnVisibleIndex+", prefferedVisibleIndex = "+prefferedVisibleIndex);
191
                            logger.fine("  to index = " + visibleIndex + ", column = " + columns[columnIndex].getDisplayName() + ", columnVisibleIndex = " + columnVisibleIndex + ", prefferedVisibleIndex = " + prefferedVisibleIndex);
197
                        }
192
                        }
198
                        columns[columnIndex].setHidden(false);
193
                        columns[columnIndex].setHidden(false);
199
                        columnVisibleMap[columnIndex] = prefferedVisibleIndex;
194
                        columnVisibleMap[columnIndex] = prefferedVisibleIndex;
200
                        for (int i = 0; i < columnVisibleMap.length; i++) {
195
                        for (int i = 0; i < columnVisibleMap.length; i++) {
201
                            if (columnVisibleMap[i] >= columnVisibleIndex && i != columnIndex &&
196
                            if (columnVisibleMap[i] >= columnVisibleIndex && i != columnIndex
202
                                getColumnOrder(columns[i]) >= corder) {
197
                                    && getColumnOrder(columns[i]) >= corder) {
203
                                
198
204
                                columnVisibleMap[i]++;
199
                                columnVisibleMap[i]++;
205
                            }
200
                            }
206
                        }
201
                        }
Lines 209-215 Link Here
209
                        }
204
                        }
210
                        if (prefferedVisibleIndex >= 0 && prefferedVisibleIndex != visibleIndex) {
205
                        if (prefferedVisibleIndex >= 0 && prefferedVisibleIndex != visibleIndex) {
211
                            if (logger.isLoggable(Level.FINE)) {
206
                            if (logger.isLoggable(Level.FINE)) {
212
                                logger.fine("moveColumn("+visibleIndex+", "+prefferedVisibleIndex+")");
207
                                logger.fine("moveColumn(" + visibleIndex + ", " + prefferedVisibleIndex + ")");
213
                            }
208
                            }
214
                            ignoreMove = true;
209
                            ignoreMove = true;
215
                            try {
210
                            try {
Lines 229-235 Link Here
229
            @Override
224
            @Override
230
            public void columnRemoved(TableColumnModelEvent e) {
225
            public void columnRemoved(TableColumnModelEvent e) {
231
                if (logger.isLoggable(Level.FINE)) {
226
                if (logger.isLoggable(Level.FINE)) {
232
                    logger.fine("columnRemoved("+e+") from = "+e.getFromIndex());
227
                    logger.fine("columnRemoved(" + e + ") from = " + e.getFromIndex());
233
                    //logger.log(Level.FINE, "  called from", new IllegalStateException("TEST"));
228
                    //logger.log(Level.FINE, "  called from", new IllegalStateException("TEST"));
234
                    dumpColumnVisibleMap();
229
                    dumpColumnVisibleMap();
235
                }
230
                }
Lines 255-279 Link Here
255
            @Override
250
            @Override
256
            public void columnMoved(TableColumnModelEvent e) {
251
            public void columnMoved(TableColumnModelEvent e) {
257
                if (tableColumns == null || ignoreMove) {
252
                if (tableColumns == null || ignoreMove) {
258
                    return ;
253
                    return;
259
                }
254
                }
260
                int from = e.getFromIndex();
255
                int from = e.getFromIndex();
261
                int to = e.getToIndex();
256
                int to = e.getToIndex();
262
                if (from == to) {
257
                if (from == to) {
263
                    // Ignore Swing strangeness
258
                    // Ignore Swing strangeness
264
                    return ;
259
                    return;
265
                }
260
                }
266
                int fc = getColumnIndex(from);
261
                int fc = getColumnIndex(from);
267
                int tc = getColumnIndex(to);
262
                int tc = getColumnIndex(to);
268
                if (logger.isLoggable(Level.FINE)) {
263
                if (logger.isLoggable(Level.FINE)) {
269
                    logger.fine("columnMoved("+e+") from = "+from+", to = "+to);
264
                    logger.fine("columnMoved(" + e + ") from = " + from + ", to = " + to);
270
                    logger.fine("  from = "+from+", to = "+to);
265
                    logger.fine("  from = " + from + ", to = " + to);
271
                    logger.fine("  fc = "+fc+", tc = "+tc);
266
                    logger.fine("  fc = " + fc + ", tc = " + tc);
272
                    TableColumnModel tcme = (TableColumnModel) e.getSource();
267
                    TableColumnModel tcme = (TableColumnModel) e.getSource();
273
                    logger.fine(" column headers = '"+tcme.getColumn(e.getFromIndex()).getHeaderValue()+"' => '"+tcme.getColumn(e.getToIndex()).getHeaderValue()+"'");
268
                    logger.fine(" column headers = '" + tcme.getColumn(e.getFromIndex()).getHeaderValue() + "' => '" + tcme.getColumn(e.getToIndex()).getHeaderValue() + "'");
274
                    dumpColumnVisibleMap();
269
                    dumpColumnVisibleMap();
275
                }
270
                }
276
                
271
277
                int toColumnOrder = getColumnOrder(columns[tc]);
272
                int toColumnOrder = getColumnOrder(columns[tc]);
278
                int fromColumnOrder = getColumnOrder(columns[fc]);
273
                int fromColumnOrder = getColumnOrder(columns[fc]);
279
                setColumnOrder(columns[fc], toColumnOrder);
274
                setColumnOrder(columns[fc], toColumnOrder);
Lines 287-297 Link Here
287
                    dumpColumnVisibleMap();
282
                    dumpColumnVisibleMap();
288
                }
283
                }
289
            }
284
            }
290
            
285
291
            @Override
286
            @Override
292
            public void columnMarginChanged(ChangeEvent e) {}
287
            public void columnMarginChanged(ChangeEvent e) {
288
            }
289
293
            @Override
290
            @Override
294
            public void columnSelectionChanged(ListSelectionEvent e) {}
291
            public void columnSelectionChanged(ListSelectionEvent e) {
292
            }
295
        });
293
        });
296
        ActionMap map = getActionMap();
294
        ActionMap map = getActionMap();
297
        ExplorerManager manager = getExplorerManager();
295
        ExplorerManager manager = getExplorerManager();
Lines 304-312 Link Here
304
302
305
    private void dumpColumnVisibleMap() {
303
    private void dumpColumnVisibleMap() {
306
        logger.fine("");
304
        logger.fine("");
307
        logger.fine("Column Visible Map ("+columnVisibleMap.length+"):");
305
        logger.fine("Column Visible Map (" + columnVisibleMap.length + "):");
308
        for (int i = 0; i < columnVisibleMap.length; i++) {
306
        for (int i = 0; i < columnVisibleMap.length; i++) {
309
            logger.fine(" {"+columns[i].getDisplayName()+"} \tvisible map["+i+"] = "+columnVisibleMap[i]+"; columnOrder["+i+"] = "+getColumnOrder(columns[i])+"\t"+(columns[i].isHidden() ? "hidden" : ""));
307
            logger.fine(" {" + columns[i].getDisplayName() + "} \tvisible map[" + i + "] = " + columnVisibleMap[i] + "; columnOrder[" + i + "] = " + getColumnOrder(columns[i]) + "\t" + (columns[i].isHidden() ? "hidden" : ""));
310
        }
308
        }
311
        logger.fine("");
309
        logger.fine("");
312
    }
310
    }
Lines 316-329 Link Here
316
        if (order == null) {
314
        if (order == null) {
317
            return -1;
315
            return -1;
318
        } else {
316
        } else {
319
            return order.intValue();
317
            return order;
320
        }
318
        }
321
    }
319
    }
322
320
323
    private void setColumnOrder(Node.Property column, int order) {
321
    private void setColumnOrder(Node.Property column, int order) {
324
        column.setValue(Column.PROP_ORDER_NUMBER, order);
322
        column.setValue(Column.PROP_ORDER_NUMBER, order);
325
        if (order != getColumnOrder(column)) {
323
        if (order != getColumnOrder(column)) {
326
            Exceptions.printStackTrace(new IllegalStateException("The order "+order+" could not be set to column "+column));
324
            Exceptions.printStackTrace(new IllegalStateException("The order " + order + " could not be set to column " + column));
327
        }
325
        }
328
    }
326
    }
329
327
Lines 337-435 Link Here
337
    }
335
    }
338
336
339
    /**
337
    /**
340
     * Set list of models.
338
     * Set list of models. Columns are taken from the first model. Children are
341
     * Columns are taken from the first model. Children are listed
339
     * listed
340
     *
342
     * @param models
341
     * @param models
343
     */
342
     */
344
    public void setModel (Models.CompoundModel model) {
343
    public void setModel(Models.CompoundModel model) {
345
        setModel(model, null);
344
        setModel(model, null);
346
    }
345
    }
347
    
346
348
    /**
347
    /**
349
     * Set list of models.
348
     * Set list of models. Columns are taken from the first model. Children are
350
     * Columns are taken from the first model. Children are listed
349
     * listed
350
     *
351
     * @param models
351
     * @param models
352
     */
352
     */
353
    public void setModel (Models.CompoundModel model, MessageFormat treeNodeDisplayFormat) {
353
    public void setModel(Models.CompoundModel model, MessageFormat treeNodeDisplayFormat) {
354
        isSettingModelUp = true;
354
        isSettingModelUp = true;
355
        try {
355
        try {
356
        // 2) save current settings (like columns, expanded paths)
356
            // 2) save current settings (like columns, expanded paths)
357
        //List ep = treeTable.getExpandedPaths ();
357
            //List ep = treeTable.getExpandedPaths ();
358
        if (currentTreeModelRoot == null || currentTreeModelRoot.getTreeNodeDisplayFormat() == null) {
358
            if (currentTreeModelRoot == null || currentTreeModelRoot.getTreeNodeDisplayFormat() == null) {
359
            saveWidths ();
359
                saveWidths();
360
            saveSortedState();
360
                saveSortedState();
361
        }
361
            }
362
        
362
363
        //this.model = model;
363
            //this.model = model;
364
        
364
            // 1) destroy old model
365
        // 1) destroy old model
365
            if (currentTreeModelRoot != null) {
366
        if (currentTreeModelRoot != null) {
366
                currentTreeModelRoot.destroy();
367
            currentTreeModelRoot.destroy ();
367
                currentTreeModelRoot = null;
368
            currentTreeModelRoot = null;
368
            }
369
        }
369
370
        
370
            // 3) no model => set empty root node & return
371
        // 3) no model => set empty root node & return
371
            if (model == null) {
372
        if (model == null) {
372
                getExplorerManager().setRootContext(
373
            getExplorerManager ().setRootContext (
373
                        new AbstractNode(Children.LEAF)
374
                new AbstractNode (Children.LEAF)
374
                );
375
            );
375
                return;
376
            return;
376
            }
377
        }
377
378
        
378
            // 4) set columns for given model
379
        // 4) set columns for given model
379
            String[] nodesColumnName = new String[]{null, null};
380
        String[] nodesColumnName = new String[] { null, null };
380
            ColumnModel[] cs = model.getColumns();
381
        ColumnModel[] cs = model.getColumns ();
381
            if (logger.isLoggable(Level.FINE)) {
382
        if (logger.isLoggable(Level.FINE)) {
382
                logger.fine("setModel(): creating columns: (" + cs.length + ")");
383
            logger.fine("setModel(): creating columns: ("+cs.length+")");
383
                for (int i = 0; i < cs.length; i++) {
384
            for (int i = 0; i < cs.length; i++) {
384
                    logger.fine("  ColumnModel[" + i + "] = " + cs[i].getDisplayName() + ", ID = " + cs[i].getID() + ", visible = " + cs[i].isVisible());
385
                logger.fine("  ColumnModel["+i+"] = "+cs[i].getDisplayName()+", ID = "+cs[i].getID()+", visible = "+cs[i].isVisible());
385
                }
386
            }
386
            }
387
        }
387
            Node.Property[] columnsToSet = createColumns(cs, nodesColumnName);
388
        Node.Property[] columnsToSet = createColumns (cs, nodesColumnName);
388
            ignoreCreateDefaultColumnsFromModel = true;
389
        ignoreCreateDefaultColumnsFromModel = true;
389
            treeTable.setNodesColumnName(nodesColumnName[0], nodesColumnName[1]);
390
        treeTable.setNodesColumnName(nodesColumnName[0], nodesColumnName[1]);
390
            if (logger.isLoggable(Level.FINE)) {
391
        if (logger.isLoggable(Level.FINE)) {
391
                logger.fine("setModel(): setNodesColumnName(" + Arrays.toString(nodesColumnName) + ") done");
392
            logger.fine("setModel(): setNodesColumnName("+Arrays.toString(nodesColumnName)+") done");
392
            }
393
        }
393
            currentTreeModelRoot = new TreeModelRoot(model, treeTable);
394
        currentTreeModelRoot = new TreeModelRoot (model, treeTable);
394
            currentTreeModelRoot.setTreeNodeDisplayFormat(treeNodeDisplayFormat);
395
        currentTreeModelRoot.setTreeNodeDisplayFormat(treeNodeDisplayFormat);
395
            TreeModelNode rootNode = currentTreeModelRoot.getRootNode();
396
        TreeModelNode rootNode = currentTreeModelRoot.getRootNode ();
396
            getExplorerManager().setRootContext(rootNode);
397
        getExplorerManager ().setRootContext (rootNode);
397
            // The root node must be ready when setting the columns
398
        // The root node must be ready when setting the columns
398
            if (logger.isLoggable(Level.FINE)) {
399
        if (logger.isLoggable(Level.FINE)) {
399
                logger.fine("setModel(): setProperties(" + Arrays.toString(columnsToSet) + ")");
400
            logger.fine("setModel(): setProperties("+Arrays.toString(columnsToSet)+")");
400
            }
401
        }
401
            if (treeNodeDisplayFormat == null) {
402
        if (treeNodeDisplayFormat == null) {
402
                treeTable.setProperties(columnsToSet);
403
            treeTable.setProperties (columnsToSet);
403
                updateTableColumns(columnsToSet, null);
404
            updateTableColumns(columnsToSet, null);
404
            } else {
405
        } else {
405
                treeTable.setProperties(new Property[]{});
406
            treeTable.setProperties (new Property[]{});
406
            }
407
        }
407
            ignoreCreateDefaultColumnsFromModel = false;
408
        ignoreCreateDefaultColumnsFromModel = false;
408
            treeTable.setAllowedDragActions(model.getAllowedDragActions());
409
        treeTable.setAllowedDragActions(model.getAllowedDragActions());
409
            treeTable.setAllowedDropActions(model.getAllowedDropActions(null));
410
        treeTable.setAllowedDropActions(model.getAllowedDropActions(null));
410
            treeTable.setDynamicDropActions(model);
411
        treeTable.setDynamicDropActions(model);
411
412
412
            //treeTable.getTable().tableChanged(new TableModelEvent(treeTable.getOutline().getModel()));
413
        //treeTable.getTable().tableChanged(new TableModelEvent(treeTable.getOutline().getModel()));
413
            //getExplorerManager ().setRootContext (rootNode);
414
        //getExplorerManager ().setRootContext (rootNode);
414
            // 5) set root node for given model
415
        
415
            // Moved to 4), because the new root node must be ready when setting columns
416
        // 5) set root node for given model
416
            // 6) update column widths & expanded nodes
417
        // Moved to 4), because the new root node must be ready when setting columns
417
            if (treeNodeDisplayFormat == null) {
418
418
                updateColumnWidthsAndSorting();
419
        // 6) update column widths & expanded nodes
419
            }
420
        if (treeNodeDisplayFormat == null) {
420
            //treeTable.expandNodes (expandedPaths);
421
            updateColumnWidthsAndSorting();
421
            // TODO: this is a workaround, we should find a better way later
422
        }
422
            /* We must not call children here - it can take a long time...
423
        //treeTable.expandNodes (expandedPaths);
424
        // TODO: this is a workaround, we should find a better way later
425
        /* We must not call children here - it can take a long time...
426
         * the expansion is performed in TreeModelNode.TreeModelChildren.applyChildren()
423
         * the expansion is performed in TreeModelNode.TreeModelChildren.applyChildren()
427
        final List backupPath = new ArrayList (expandedPaths);
424
        final List backupPath = new ArrayList (expandedPaths);
428
        if (backupPath.size () == 0)
425
        if (backupPath.size () == 0)
429
            TreeModelNode.getRequestProcessor ().post (new Runnable () {
426
            TreeModelNode.getRequestProcessor ().post (new Runnable () {
430
                public void run () {
427
                public void run () {
431
                    try {
428
                    try {
432
                        final Object[] ch = TreeTable.this.model.getChildren 
429
                        final Object[] ch = TreeTable.this.model.getChildren
433
                            (TreeTable.this.model.getRoot (), 0, 0);
430
                            (TreeTable.this.model.getRoot (), 0, 0);
434
                        SwingUtilities.invokeLater (new Runnable () {
431
                        SwingUtilities.invokeLater (new Runnable () {
435
                            public void run () {
432
                            public void run () {
Lines 445-559 Link Here
445
                    treeTable.expandNodes (backupPath);
442
                    treeTable.expandNodes (backupPath);
446
                }
443
                }
447
            });
444
            });
448
         */
445
             */
449
        //if (ep.size () > 0) expandedPaths = ep;
446
            //if (ep.size () > 0) expandedPaths = ep;
450
447
451
        // Sort of hack(?) After close/open of the view the table becomes empty,
448
            // Sort of hack(?) After close/open of the view the table becomes empty,
452
        // it looks like the root node stays unexpanded for some reason.
449
            // it looks like the root node stays unexpanded for some reason.
453
        //treeTable.expandNode(rootNode);
450
            //treeTable.expandNode(rootNode);
454
        } finally {
451
        } finally {
455
            isSettingModelUp = false;
452
            isSettingModelUp = false;
456
        }
453
        }
457
    }
454
    }
458
    
455
459
    /**
456
    /**
460
     * Set list of models.
457
     * Set list of models. Columns are taken from the first model. Children are
461
     * Columns are taken from the first model. Children are listed
458
     * listed
459
     *
462
     * @param models
460
     * @param models
463
     */
461
     */
464
    public void setModel (HyperCompoundModel model, MessageFormat treeNodeDisplayFormat) {
462
    public void setModel(HyperCompoundModel model, MessageFormat treeNodeDisplayFormat) {
465
        isSettingModelUp = true;
463
        isSettingModelUp = true;
466
        try {
464
        try {
467
        // 2) save current settings (like columns, expanded paths)
465
            // 2) save current settings (like columns, expanded paths)
468
        //List ep = treeTable.getExpandedPaths ();
466
            //List ep = treeTable.getExpandedPaths ();
469
        if (currentTreeModelRoot == null || currentTreeModelRoot.getTreeNodeDisplayFormat() == null) {
467
            if (currentTreeModelRoot == null || currentTreeModelRoot.getTreeNodeDisplayFormat() == null) {
470
            saveWidths ();
468
                saveWidths();
471
            saveSortedState();
469
                saveSortedState();
472
        }
470
            }
473
471
474
        //this.model = model;
472
            //this.model = model;
475
473
            // 1) destroy old model
476
        // 1) destroy old model
474
            if (currentTreeModelRoot != null) {
477
        if (currentTreeModelRoot != null) {
475
                currentTreeModelRoot.destroy();
478
            currentTreeModelRoot.destroy ();
476
                currentTreeModelRoot = null;
479
            currentTreeModelRoot = null;
477
            }
480
        }
478
481
479
            // 3) no model => set empty root node & return
482
        // 3) no model => set empty root node & return
480
            if (model == null) {
483
        if (model == null) {
481
                getExplorerManager().setRootContext(
484
            getExplorerManager ().setRootContext (
482
                        new AbstractNode(Children.LEAF)
485
                new AbstractNode (Children.LEAF)
483
                );
486
            );
484
                return;
487
            return;
485
            }
488
        }
486
489
487
            // 4) set columns for given model
490
        // 4) set columns for given model
488
            String[] nodesColumnName = new String[]{null, null};
491
        String[] nodesColumnName = new String[] { null, null };
489
            ColumnModel[] cs = model.getColumns();
492
        ColumnModel[] cs = model.getColumns ();
490
            Node.Property[] columnsToSet = createColumns(cs, nodesColumnName);
493
        Node.Property[] columnsToSet = createColumns (cs, nodesColumnName);
491
            ignoreCreateDefaultColumnsFromModel = true;
494
        ignoreCreateDefaultColumnsFromModel = true;
492
            treeTable.setNodesColumnName(nodesColumnName[0], nodesColumnName[1]);
495
        treeTable.setNodesColumnName(nodesColumnName[0], nodesColumnName[1]);
493
            currentTreeModelRoot = new TreeModelRoot(model, treeTable);
496
        currentTreeModelRoot = new TreeModelRoot (model, treeTable);
494
            currentTreeModelRoot.setTreeNodeDisplayFormat(treeNodeDisplayFormat);
497
        currentTreeModelRoot.setTreeNodeDisplayFormat(treeNodeDisplayFormat);
495
            TreeModelNode rootNode = currentTreeModelRoot.getRootNode();
498
        TreeModelNode rootNode = currentTreeModelRoot.getRootNode ();
496
            getExplorerManager().setRootContext(rootNode);
499
        getExplorerManager ().setRootContext (rootNode);
497
            // The root node must be ready when setting the columns
500
        // The root node must be ready when setting the columns
498
            if (treeNodeDisplayFormat == null) {
501
        if (treeNodeDisplayFormat == null) {
499
                treeTable.setProperties(columnsToSet);
502
            treeTable.setProperties (columnsToSet);
500
                updateTableColumns(columnsToSet, null);
503
            updateTableColumns(columnsToSet, null);
501
            } else {
504
        } else {
502
                treeTable.setProperties(new Property[]{});
505
            treeTable.setProperties (new Property[]{});
503
            }
506
        }
504
            ignoreCreateDefaultColumnsFromModel = false;
507
        ignoreCreateDefaultColumnsFromModel = false;
505
            treeTable.setAllowedDragActions(model.getAllowedDragActions());
508
        treeTable.setAllowedDragActions(model.getAllowedDragActions());
506
            treeTable.setAllowedDropActions(model.getAllowedDropActions(null));
509
        treeTable.setAllowedDropActions(model.getAllowedDropActions(null));
507
510
508
            // 5) set root node for given model
511
        // 5) set root node for given model
509
            // Moved to 4), because the new root node must be ready when setting columns
512
        // Moved to 4), because the new root node must be ready when setting columns
510
            // 6) update column widths & expanded nodes
513
511
            if (treeNodeDisplayFormat == null) {
514
        // 6) update column widths & expanded nodes
512
                updateColumnWidthsAndSorting();
515
        if (treeNodeDisplayFormat == null) {
513
            }
516
            updateColumnWidthsAndSorting();
514
            /* We must not call children here - it can take a long time...
517
        }
518
        /* We must not call children here - it can take a long time...
519
         * the expansion is performed in TreeModelNode.TreeModelChildren.applyChildren()
515
         * the expansion is performed in TreeModelNode.TreeModelChildren.applyChildren()
520
         */
516
             */
521
        } finally {
517
        } finally {
522
            isSettingModelUp = false;
518
            isSettingModelUp = false;
523
        }
519
        }
524
    }
520
    }
525
521
526
    @Override
522
    @Override
527
    public ExplorerManager getExplorerManager () {
523
    public ExplorerManager getExplorerManager() {
528
        if (explorerManager == null) {
524
        if (explorerManager == null) {
529
            explorerManager = new ExplorerManager ();
525
            explorerManager = new ExplorerManager();
530
        }
526
        }
531
        return explorerManager;
527
        return explorerManager;
532
    }
528
    }
533
    
529
534
    @Override
530
    @Override
535
    public void propertyChange (PropertyChangeEvent evt) {
531
    public void propertyChange(PropertyChangeEvent evt) {
536
        String propertyName = evt.getPropertyName ();
532
        String propertyName = evt.getPropertyName();
537
        TopComponent tc = (TopComponent) SwingUtilities.
533
        TopComponent tc = (TopComponent) SwingUtilities.
538
            getAncestorOfClass (TopComponent.class, this);
534
                getAncestorOfClass(TopComponent.class, this);
539
        if (tc == null) {
535
        if (tc == null) {
540
            return;
536
            return;
541
        }
537
        }
542
        if (propertyName.equals (TopComponent.Registry.PROP_CURRENT_NODES)) {
538
        if (propertyName.equals(TopComponent.Registry.PROP_CURRENT_NODES)) {
543
            ExplorerUtils.activateActions(getExplorerManager(), equalNodes());
539
            ExplorerUtils.activateActions(getExplorerManager(), equalNodes());
544
        } else
540
        } else if (propertyName.equals(ExplorerManager.PROP_SELECTED_NODES)) {
545
        if (propertyName.equals (ExplorerManager.PROP_SELECTED_NODES)) {
541
            tc.setActivatedNodes((Node[]) evt.getNewValue());
546
            tc.setActivatedNodes ((Node[]) evt.getNewValue ());
547
        }
542
        }
548
    }
543
    }
549
    
544
550
    private boolean equalNodes () {
545
    private boolean equalNodes() {
551
        Node[] ns1 = TopComponent.getRegistry ().getCurrentNodes ();
546
        Node[] ns1 = TopComponent.getRegistry().getCurrentNodes();
552
        Node[] ns2 = getExplorerManager ().getSelectedNodes ();
547
        Node[] ns2 = getExplorerManager().getSelectedNodes();
553
        if (ns1 == ns2) {
548
        if (ns1 == ns2) {
554
            return true;
549
            return true;
555
        }
550
        }
556
        if ( (ns1 == null) || (ns2 == null) ) {
551
        if ((ns1 == null) || (ns2 == null)) {
557
            return false;
552
            return false;
558
        }
553
        }
559
        if (ns1.length != ns2.length) {
554
        if (ns1.length != ns2.length) {
Lines 561-583 Link Here
561
        }
556
        }
562
        int i, k = ns1.length;
557
        int i, k = ns1.length;
563
        for (i = 0; i < k; i++) {
558
        for (i = 0; i < k; i++) {
564
            if (!ns1 [i].equals (ns2 [i])) {
559
            if (!ns1[i].equals(ns2[i])) {
565
                return false;
560
                return false;
566
            }
561
            }
567
        }
562
        }
568
        return true;
563
        return true;
569
    }
564
    }
570
    
565
571
    private Node.Property[] createColumns (ColumnModel[] cs, String[] nodesColumnNameAndDescription) {
566
    private Node.Property[] createColumns(ColumnModel[] cs, String[] nodesColumnNameAndDescription) {
572
        int i, k = cs.length;
567
        int i, k = cs.length;
573
        // Check column IDs:
568
        // Check column IDs:
574
        {
569
        {
575
            Map<String, ColumnModel> IDs = new HashMap<String, ColumnModel>(k);
570
            Map<String, ColumnModel> IDs = new HashMap<>(k);
576
            for (i = 0; i < k; i++) {
571
            for (i = 0; i < k; i++) {
577
                String id = cs[i].getID();
572
                String id = cs[i].getID();
578
                if (IDs.containsKey(id)) {
573
                if (IDs.containsKey(id)) {
579
                    ColumnModel csi = IDs.get(id);
574
                    ColumnModel csi = IDs.get(id);
580
                    logger.severe("\nHave two columns with identical IDs \""+id+"\": "+csi+" ["+csi.getDisplayName()+"] and "+cs[i]+" ["+cs[i].getDisplayName()+"]\n");
575
                    logger.severe("\nHave two columns with identical IDs \"" + id + "\": " + csi + " [" + csi.getDisplayName() + "] and " + cs[i] + " [" + cs[i].getDisplayName() + "]\n");
581
                } else {
576
                } else {
582
                    IDs.put(id, cs[i]);
577
                    IDs.put(id, cs[i]);
583
                }
578
                }
Lines 589-605 Link Here
589
        isDefaultColumnAdded = false;
584
        isDefaultColumnAdded = false;
590
        ColumnModel treeColumn = null;
585
        ColumnModel treeColumn = null;
591
        boolean addDefaultColumn = true;
586
        boolean addDefaultColumn = true;
592
        List<Node.Property> columnList = new ArrayList<Node.Property>(k);
587
        List<Node.Property> columnList = new ArrayList<>(k);
593
        int d = 0;
588
        int d = 0;
594
        boolean[] originalOrder = new boolean[k];
589
        boolean[] originalOrder = new boolean[k];
595
        for (i = 0; i < k; i++) {
590
        for (i = 0; i < k; i++) {
596
            Column c = new Column(cs [i]);
591
            Column c = new Column(cs[i]);
597
            columns[i] = c;
592
            columns[i] = c;
598
            //IndexedColumn ic = new IndexedColumn(c, i, cs[i].getCurrentOrderNumber());
593
            //IndexedColumn ic = new IndexedColumn(c, i, cs[i].getCurrentOrderNumber());
599
            //icolumns[i] = ic;
594
            //icolumns[i] = ic;
600
            int order = cs[i].getCurrentOrderNumber();
595
            int order = cs[i].getCurrentOrderNumber();
601
            if (logger.isLoggable(Level.FINE)) {
596
            if (logger.isLoggable(Level.FINE)) {
602
                logger.fine("createColumns(): column {"+c.getDisplayName()+"}: order = "+order+", i = "+i+", d = "+d);
597
                logger.fine("createColumns(): column {" + c.getDisplayName() + "}: order = " + order + ", i = " + i + ", d = " + d);
603
            }
598
            }
604
            if (order == -1) {
599
            if (order == -1) {
605
                order = i;
600
                order = i;
Lines 628-637 Link Here
628
            }
623
            }
629
        }
624
        }
630
        if (addDefaultColumn) {
625
        if (addDefaultColumn) {
631
            PropertySupport.ReadWrite[] columns2 =
626
            PropertySupport.ReadWrite[] columns2
632
                new PropertySupport.ReadWrite [columns.length + 1];
627
                    = new PropertySupport.ReadWrite[columns.length + 1];
633
            System.arraycopy (columns, 0, columns2, 1, columns.length);
628
            System.arraycopy(columns, 0, columns2, 1, columns.length);
634
            columns2 [0] = new DefaultColumn ();
629
            columns2[0] = new DefaultColumn();
635
            nodesColumnNameAndDescription[0] = columns2[0].getDisplayName();
630
            nodesColumnNameAndDescription[0] = columns2[0].getDisplayName();
636
            nodesColumnNameAndDescription[1] = columns2[0].getShortDescription();
631
            nodesColumnNameAndDescription[1] = columns2[0].getShortDescription();
637
            columns = columns2;
632
            columns = columns2;
Lines 683-689 Link Here
683
        return columnProps;
678
        return columnProps;
684
    }
679
    }
685
680
686
    /** Squeeze gaps and split duplicities to make it a permutation. */
681
    /**
682
     * Squeeze gaps and split duplicities to make it a permutation.
683
     */
687
    private void checkOrder(int[] orders, boolean[] originalOrder) {
684
    private void checkOrder(int[] orders, boolean[] originalOrder) {
688
        if (logger.isLoggable(Level.FINE)) {
685
        if (logger.isLoggable(Level.FINE)) {
689
            StringBuilder msg = new StringBuilder("checkOrder(");
686
            StringBuilder msg = new StringBuilder("checkOrder(");
Lines 786-808 Link Here
786
            if (ci < columnsToSet.length && columns[i] == columnsToSet[ci] && i != defaultColumnIndex) {
783
            if (ci < columnsToSet.length && columns[i] == columnsToSet[ci] && i != defaultColumnIndex) {
787
                TableColumn tc = allColumns.get(tci); //tcm.getColumn(tci);
784
                TableColumn tc = allColumns.get(tci); //tcm.getColumn(tci);
788
                tableColumns[i] = tc;
785
                tableColumns[i] = tc;
789
                if (columns[i] instanceof Column && tci < tcm.getColumnCount()) {
786
                if (columns[i] instanceof Column) {
790
                    Column c = (Column) columns[i];
787
                    Column c = (Column) columns[i];
788
                    TableCellEditor cellEditor = tc.getCellEditor();
789
                    if (cellEditor == null) {
790
                        cellEditor = treeTable.getTable().getDefaultEditor(Node.Property.class);
791
                    }
791
                    tc.setCellEditor(new DelegatingCellEditor(
792
                    tc.setCellEditor(new DelegatingCellEditor(
792
                            c.getName(),
793
                            c.getName(),
793
                            treeTable.getTable().getCellEditor(0, tci)));
794
                            cellEditor));
795
                    TableCellRenderer cellRenderer = tc.getCellRenderer();
796
                    if (cellRenderer == null) {
797
                        cellRenderer = treeTable.getTable().getDefaultRenderer(Node.Property.class);
798
                    }
794
                    tc.setCellRenderer(new DelegatingCellRenderer(
799
                    tc.setCellRenderer(new DelegatingCellRenderer(
795
                            c.getName(),
800
                            c.getName(),
796
                            treeTable.getTable().getCellRenderer(0, tci)));
801
                            cellRenderer));
797
                    tc.setPreferredWidth(c.getColumnWidth());
802
                    tc.setPreferredWidth(c.getColumnWidth());
798
                }
803
                }
799
                if (columns[i].isHidden()) {
804
                if (columns[i].isHidden()) {
800
                    ecm.setColumnHidden(tc, true);
805
                    ecm.setColumnHidden(tc, true);
801
                } else {
806
                } else if (columns[i] instanceof Column) {
802
                    if (columns[i] instanceof Column) {
807
                    Column c = (Column) columns[i];
803
                        Column c = (Column) columns[i];
808
                    tc.setPreferredWidth(c.getColumnWidth());
804
                        tc.setPreferredWidth(c.getColumnWidth());
805
                    }
806
                }
809
                }
807
                tci++;
810
                tci++;
808
                ci++;
811
                ci++;
Lines 827-841 Link Here
827
            }
830
            }
828
        }
831
        }
829
        if (logger.isLoggable(Level.FINE)) {
832
        if (logger.isLoggable(Level.FINE)) {
830
            logger.fine("updateTableColumns("+columns.length+"):");
833
            logger.fine("updateTableColumns(" + columns.length + "):");
831
            for (int i = 0; i < columns.length; i++) {
834
            for (int i = 0; i < columns.length; i++) {
832
                logger.fine("Column["+i+"] ("+columns[i].getDisplayName()+") = "+((tableColumns[i] != null) ? tableColumns[i].getHeaderValue() : "null")+"\t"+(columns[i].isHidden() ? "hidden" : ""));
835
                logger.fine("Column[" + i + "] (" + columns[i].getDisplayName() + ") = " + ((tableColumns[i] != null) ? tableColumns[i].getHeaderValue() : "null") + "\t" + (columns[i].isHidden() ? "hidden" : ""));
833
            }
836
            }
834
        }
837
        }
835
        setColumnsOrder();
838
        setColumnsOrder();
836
        this.tableColumns = tableColumns;
839
        this.tableColumns = tableColumns;
837
    }
840
    }
838
    
841
839
    private List<TableColumn> getAllColumns(ETableColumnModel etcm) {
842
    private List<TableColumn> getAllColumns(ETableColumnModel etcm) {
840
        try {
843
        try {
841
            Method getAllColumnsMethod = ETableColumnModel.class.getDeclaredMethod("getAllColumns");
844
            Method getAllColumnsMethod = ETableColumnModel.class.getDeclaredMethod("getAllColumns");
Lines 899-905 Link Here
899
            logger.log(Level.FINE, "  order[{0}] = {1}", new Object[]{j, i});
902
            logger.log(Level.FINE, "  order[{0}] = {1}", new Object[]{j, i});
900
            if (j != i) {
903
            if (j != i) {
901
                for (int k = j; k > i; k--) {
904
                for (int k = j; k > i; k--) {
902
                    order[k] = order[k-1];
905
                    order[k] = order[k - 1];
903
                }
906
                }
904
                order[i] = i;
907
                order[i] = i;
905
                logger.log(Level.FINE, " move column({0}, {1})", new Object[]{j, i});
908
                logger.log(Level.FINE, " move column({0}, {1})", new Object[]{j, i});
Lines 933-954 Link Here
933
            logger.log(Level.FINE, "  visibleOrder[{0}] = {1}, ", new Object[]{i, visibleOrder});
936
            logger.log(Level.FINE, "  visibleOrder[{0}] = {1}, ", new Object[]{i, visibleOrder});
934
            ETableColumn tc;
937
            ETableColumn tc;
935
            try {
938
            try {
936
                tc = (ETableColumn) tcm.getColumn (visibleOrder);
939
                tc = (ETableColumn) tcm.getColumn(visibleOrder);
937
            } catch (ArrayIndexOutOfBoundsException aioobex) {
940
            } catch (ArrayIndexOutOfBoundsException aioobex) {
938
                logger.log(Level.SEVERE,
941
                logger.log(Level.SEVERE,
939
                        "Column("+i+") "+columns[i].getName()+" visible index = "+visibleOrder+
942
                        "Column(" + i + ") " + columns[i].getName() + " visible index = " + visibleOrder
940
                        ", columnVisibleMap = "+java.util.Arrays.toString(columnVisibleMap)+
943
                        + ", columnVisibleMap = " + java.util.Arrays.toString(columnVisibleMap)
941
                        ", num of columns = "+tcm.getColumnCount(),
944
                        + ", num of columns = " + tcm.getColumnCount(),
942
                        aioobex);
945
                        aioobex);
943
                continue ;
946
                continue;
944
            }
947
            }
945
            if (logger.isLoggable(Level.FINE)) {
948
            if (logger.isLoggable(Level.FINE)) {
946
                logger.fine("  GUI column = "+tc.getHeaderValue());
949
                logger.fine("  GUI column = " + tc.getHeaderValue());
947
            }
950
            }
948
            if (columns[i] instanceof Column) {
951
            if (columns[i] instanceof Column) {
949
                Column c = (Column) columns[i];
952
                Column c = (Column) columns[i];
950
                if (logger.isLoggable(Level.FINE)) {
953
                if (logger.isLoggable(Level.FINE)) {
951
                    logger.fine("    Retrieved width "+c.getColumnWidth()+" from "+columns[i].getDisplayName()+"["+i+"] for "+tc.getHeaderValue());
954
                    logger.fine("    Retrieved width " + c.getColumnWidth() + " from " + columns[i].getDisplayName() + "[" + i + "] for " + tc.getHeaderValue());
952
                }
955
                }
953
                tc.setPreferredWidth(c.getColumnWidth());
956
                tc.setPreferredWidth(c.getColumnWidth());
954
                if (c.isSorted()) {
957
                if (c.isSorted()) {
Lines 958-976 Link Here
958
        }
961
        }
959
    }
962
    }
960
963
961
    private void saveWidths () {
964
    private void saveWidths() {
962
        if (columns == null) {
965
        if (columns == null) {
963
            return;
966
            return;
964
        }
967
        }
965
        int i, k = columns.length;
968
        int i, k = columns.length;
966
        if (k == 0) {
969
        if (k == 0) {
967
            return ;
970
            return;
968
        }
971
        }
969
        TableColumnModel tcm = treeTable.getTable().getColumnModel();
972
        TableColumnModel tcm = treeTable.getTable().getColumnModel();
970
        ETableColumnModel ecm = (ETableColumnModel) tcm;
973
        ETableColumnModel ecm = (ETableColumnModel) tcm;
971
        Enumeration<TableColumn> etc = tcm.getColumns();
974
        Enumeration<TableColumn> etc = tcm.getColumns();
972
        boolean defaultState = true;
975
        boolean defaultState = true;
973
        while(etc.hasMoreElements()) {
976
        while (etc.hasMoreElements()) {
974
            if (etc.nextElement().getWidth() != 75) {
977
            if (etc.nextElement().getWidth() != 75) {
975
                defaultState = false;
978
                defaultState = false;
976
                break;
979
                break;
Lines 979-985 Link Here
979
        if (defaultState) {
982
        if (defaultState) {
980
            // All columns have the default width 75.
983
            // All columns have the default width 75.
981
            // It's very likely that the table was not fully initialized => do not save anything.
984
            // It's very likely that the table was not fully initialized => do not save anything.
982
            return ;
985
            return;
983
        }
986
        }
984
        logger.fine("\nsaveWidths():");
987
        logger.fine("\nsaveWidths():");
985
        for (i = 0; i < k; i++) {
988
        for (i = 0; i < k; i++) {
Lines 993-1026 Link Here
993
            }
996
            }
994
            TableColumn tc;
997
            TableColumn tc;
995
            try {
998
            try {
996
                tc = tcm.getColumn (visibleOrder);
999
                tc = tcm.getColumn(visibleOrder);
997
            } catch (ArrayIndexOutOfBoundsException aioobex) {
1000
            } catch (ArrayIndexOutOfBoundsException aioobex) {
998
                logger.log(Level.SEVERE,
1001
                logger.log(Level.SEVERE,
999
                        "Column("+i+") "+columns[i].getName()+" visible index = "+visibleOrder+
1002
                        "Column(" + i + ") " + columns[i].getName() + " visible index = " + visibleOrder
1000
                        ", columnVisibleMap = "+java.util.Arrays.toString(columnVisibleMap)+
1003
                        + ", columnVisibleMap = " + java.util.Arrays.toString(columnVisibleMap)
1001
                        ", num of columns = "+tcm.getColumnCount(),
1004
                        + ", num of columns = " + tcm.getColumnCount(),
1002
                        aioobex);
1005
                        aioobex);
1003
                continue ;
1006
                continue;
1004
            }
1007
            }
1005
            if (logger.isLoggable(Level.FINE)) {
1008
            if (logger.isLoggable(Level.FINE)) {
1006
                logger.log(Level.FINE, "  GUI column = {0}", tc.getHeaderValue());
1009
                logger.log(Level.FINE, "  GUI column = {0}", tc.getHeaderValue());
1007
            }
1010
            }
1008
            if (columns[i] instanceof Column) {
1011
            if (columns[i] instanceof Column) {
1009
                if (logger.isLoggable(Level.FINE)) {
1012
                if (logger.isLoggable(Level.FINE)) {
1010
                    logger.fine("    Setting width "+tc.getWidth()+" from "+tc.getHeaderValue()+" to "+columns[i].getDisplayName()+"["+i+"]");
1013
                    logger.fine("    Setting width " + tc.getWidth() + " from " + tc.getHeaderValue() + " to " + columns[i].getDisplayName() + "[" + i + "]");
1011
                }
1014
                }
1012
                ((Column) columns[i]).setColumnWidth(tc.getWidth());
1015
                ((Column) columns[i]).setColumnWidth(tc.getWidth());
1013
            }
1016
            }
1014
        }
1017
        }
1015
    }
1018
    }
1016
    
1019
1017
    private void saveSortedState () {
1020
    private void saveSortedState() {
1018
        if (columns == null) {
1021
        if (columns == null) {
1019
            return;
1022
            return;
1020
        }
1023
        }
1021
        int i, k = columns.length;
1024
        int i, k = columns.length;
1022
        if (k == 0) {
1025
        if (k == 0) {
1023
            return ;
1026
            return;
1024
        }
1027
        }
1025
        TableColumnModel tcm = treeTable.getTable().getColumnModel();
1028
        TableColumnModel tcm = treeTable.getTable().getColumnModel();
1026
        ETableColumnModel ecm = (ETableColumnModel) tcm;
1029
        ETableColumnModel ecm = (ETableColumnModel) tcm;
Lines 1037-1057 Link Here
1037
            }
1040
            }
1038
            ETableColumn tc;
1041
            ETableColumn tc;
1039
            try {
1042
            try {
1040
                tc = (ETableColumn) tcm.getColumn (visibleOrder);
1043
                tc = (ETableColumn) tcm.getColumn(visibleOrder);
1041
            } catch (ArrayIndexOutOfBoundsException aioobex) {
1044
            } catch (ArrayIndexOutOfBoundsException aioobex) {
1042
                logger.log(Level.SEVERE,
1045
                logger.log(Level.SEVERE,
1043
                        "Column("+i+") "+columns[i].getName()+" visible index = "+visibleOrder+
1046
                        "Column(" + i + ") " + columns[i].getName() + " visible index = " + visibleOrder
1044
                        ", columnVisibleMap = "+java.util.Arrays.toString(columnVisibleMap)+
1047
                        + ", columnVisibleMap = " + java.util.Arrays.toString(columnVisibleMap)
1045
                        ", num of columns = "+tcm.getColumnCount(),
1048
                        + ", num of columns = " + tcm.getColumnCount(),
1046
                        aioobex);
1049
                        aioobex);
1047
                continue ;
1050
                continue;
1048
            }
1051
            }
1049
            if (logger.isLoggable(Level.FINE)) {
1052
            if (logger.isLoggable(Level.FINE)) {
1050
                logger.fine("  GUI column = "+tc.getHeaderValue());
1053
                logger.fine("  GUI column = " + tc.getHeaderValue());
1051
            }
1054
            }
1052
            if (columns[i] instanceof Column) {
1055
            if (columns[i] instanceof Column) {
1053
                if (logger.isLoggable(Level.FINE)) {
1056
                if (logger.isLoggable(Level.FINE)) {
1054
                    logger.fine("    Setting sorted "+tc.isSorted()+" descending "+(!tc.isAscending())+" to "+columns[i].getDisplayName()+"["+i+"]");
1057
                    logger.fine("    Setting sorted " + tc.isSorted() + " descending " + (!tc.isAscending()) + " to " + columns[i].getDisplayName() + "[" + i + "]");
1055
                }
1058
                }
1056
                ((Column) columns[i]).setSorted(tc.isSorted());
1059
                ((Column) columns[i]).setSorted(tc.isSorted());
1057
                ((Column) columns[i]).setSortedDescending(!tc.isAscending());
1060
                ((Column) columns[i]).setSortedDescending(!tc.isAscending());
Lines 1059-1110 Link Here
1059
        }
1062
        }
1060
    }
1063
    }
1061
1064
1062
    /** Requests focus for the tree component. Overrides superclass method. */
1065
    /**
1066
     * Requests focus for the tree component. Overrides superclass method.
1067
     */
1063
    @Override
1068
    @Override
1064
    public boolean requestFocusInWindow () {
1069
    public boolean requestFocusInWindow() {
1065
        super.requestFocusInWindow();
1070
        super.requestFocusInWindow();
1066
        return treeTable.requestFocusInWindow ();
1071
        return treeTable.requestFocusInWindow();
1067
    }
1072
    }
1068
    
1073
1069
    @Override
1074
    @Override
1070
    public void addNotify () {
1075
    public void addNotify() {
1071
        TopComponent.getRegistry ().addPropertyChangeListener (this);
1076
        TopComponent.getRegistry().addPropertyChangeListener(this);
1072
        ExplorerUtils.activateActions(getExplorerManager (), true);
1077
        ExplorerUtils.activateActions(getExplorerManager(), true);
1073
        getExplorerManager ().addPropertyChangeListener (this);
1078
        getExplorerManager().addPropertyChangeListener(this);
1074
        super.addNotify ();
1079
        super.addNotify();
1075
    }
1080
    }
1076
    
1081
1077
    @Override
1082
    @Override
1078
    public void removeNotify () {
1083
    public void removeNotify() {
1079
        super.removeNotify ();
1084
        super.removeNotify();
1080
        TopComponent.getRegistry ().removePropertyChangeListener (this);
1085
        TopComponent.getRegistry().removePropertyChangeListener(this);
1081
        ExplorerUtils.activateActions(getExplorerManager (), false);
1086
        ExplorerUtils.activateActions(getExplorerManager(), false);
1082
        getExplorerManager ().removePropertyChangeListener (this);
1087
        getExplorerManager().removePropertyChangeListener(this);
1083
        setModel(null);
1088
        //setModel(null);
1084
    }
1089
    }
1085
    
1090
1086
    public boolean isExpanded (Object node) {
1091
    public boolean isExpanded(Object node) {
1087
        Node[] ns = currentTreeModelRoot.findNode (node);
1092
        Node[] ns = currentTreeModelRoot.findNode(node);
1088
        if (ns.length == 0) {
1093
        if (ns.length == 0) {
1089
            return false; // Something what does not exist is not expanded ;-)
1094
            return false; // Something what does not exist is not expanded ;-)
1090
        }
1095
        }
1091
        return treeTable.isExpanded (ns[0]);
1096
        return treeTable.isExpanded(ns[0]);
1092
    }
1097
    }
1093
1098
1094
    public void expandNode (Object node) {
1099
    public void expandNode(Object node) {
1095
        Node[] ns = currentTreeModelRoot.findNode (node);
1100
        Node[] ns = currentTreeModelRoot.findNode(node);
1096
        for (Node n : ns) {
1101
        for (Node n : ns) {
1097
            treeTable.expandNode (n);
1102
            treeTable.expandNode(n);
1098
        }
1103
        }
1099
    }
1104
    }
1100
1105
1101
    public void collapseNode (Object node) {
1106
    public void collapseNode(Object node) {
1102
        Node[] ns = currentTreeModelRoot.findNode (node);
1107
        Node[] ns = currentTreeModelRoot.findNode(node);
1103
        for (Node n : ns) {
1108
        for (Node n : ns) {
1104
            treeTable.collapseNode (n);
1109
            treeTable.collapseNode(n);
1105
        }
1110
        }
1106
    }
1111
    }
1107
    
1112
1108
    private class CreatedDefaultColumnsFromModel implements PropertyChangeListener {
1113
    private class CreatedDefaultColumnsFromModel implements PropertyChangeListener {
1109
1114
1110
        @Override
1115
        @Override
Lines 1124-1148 Link Here
1124
                }
1129
                }
1125
            }
1130
            }
1126
        }
1131
        }
1127
        
1132
1128
    }
1133
    }
1129
    
1134
1130
    static class MyTreeTable extends OutlineView {  // Accessed from tests
1135
    static class MyTreeTable extends OutlineView {  // Accessed from tests
1131
1136
1132
        private Reference dndModelRef = new WeakReference(null);
1137
        private Reference dndModelRef = new WeakReference(null);
1133
        private Property[] properties;
1138
        private Property[] properties;
1134
1139
1135
        MyTreeTable () {
1140
        MyTreeTable() {
1136
            super ();
1141
            super();
1137
            Outline outline = getOutline();
1142
            Outline outline = getOutline();
1138
            outline.setShowHorizontalLines (true);
1143
            outline.setShowHorizontalLines(true);
1139
            outline.setShowVerticalLines (false);
1144
            outline.setShowVerticalLines(false);
1140
            filterInputMap(outline, JComponent.WHEN_FOCUSED);
1145
            filterInputMap(outline, JComponent.WHEN_FOCUSED);
1141
            filterInputMap(outline, JComponent.WHEN_IN_FOCUSED_WINDOW);
1146
            filterInputMap(outline, JComponent.WHEN_IN_FOCUSED_WINDOW);
1142
            filterInputMap(outline, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1147
            filterInputMap(outline, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1143
            outline.putClientProperty("PropertyToolTipShortDescription", Boolean.TRUE);
1148
            outline.putClientProperty("PropertyToolTipShortDescription", Boolean.TRUE);
1144
        }
1149
        }
1145
        
1150
1146
        private void filterInputMap(JComponent component, int condition) {
1151
        private void filterInputMap(JComponent component, int condition) {
1147
            InputMap imap = component.getInputMap(condition);
1152
            InputMap imap = component.getInputMap(condition);
1148
            if (imap instanceof ComponentInputMap) {
1153
            if (imap instanceof ComponentInputMap) {
Lines 1152-1159 Link Here
1152
            }
1157
            }
1153
            component.setInputMap(condition, imap);
1158
            component.setInputMap(condition, imap);
1154
        }
1159
        }
1155
        
1160
1156
        JTable getTable () {
1161
        JTable getTable() {
1157
            return getOutline();
1162
            return getOutline();
1158
        }
1163
        }
1159
1164
Lines 1162-1172 Link Here
1162
            this.properties = newProperties;
1167
            this.properties = newProperties;
1163
            super.setProperties(newProperties);
1168
            super.setProperties(newProperties);
1164
        }
1169
        }
1165
        
1170
1166
        Property[] getProperties() {
1171
        Property[] getProperties() {
1167
            return properties;
1172
            return properties;
1168
        }
1173
        }
1169
        
1174
1170
        void setNodesColumnName(String name, String description) {
1175
        void setNodesColumnName(String name, String description) {
1171
            OutlineModel m = getOutline().getOutlineModel();
1176
            OutlineModel m = getOutline().getOutlineModel();
1172
            if (m instanceof DefaultOutlineModel) {
1177
            if (m instanceof DefaultOutlineModel) {
Lines 1183-1190 Link Here
1183
                em.getRootContext ()
1188
                em.getRootContext ()
1184
            );
1189
            );
1185
            TreePath tp = new TreePath (rtn); // Get the root
1190
            TreePath tp = new TreePath (rtn); // Get the root
1186
            
1191
1187
            Enumeration exPaths = tree.getExpandedDescendants (tp); 
1192
            Enumeration exPaths = tree.getExpandedDescendants (tp);
1188
            if (exPaths == null) return result;
1193
            if (exPaths == null) return result;
1189
            for (;exPaths.hasMoreElements ();) {
1194
            for (;exPaths.hasMoreElements ();) {
1190
                TreePath ep = (TreePath) exPaths.nextElement ();
1195
                TreePath ep = (TreePath) exPaths.nextElement ();
Lines 1195-1207 Link Here
1195
            return result;
1200
            return result;
1196
        }
1201
        }
1197
         */
1202
         */
1198
        
1203
        /**
1199
        /** Expands all the paths, when exists
1204
         * Expands all the paths, when exists
1200
         */
1205
         */
1201
        public void expandNodes (List exPaths) {
1206
        public void expandNodes(List exPaths) {
1202
            for (Iterator it = exPaths.iterator (); it.hasNext ();) {
1207
            for (Iterator it = exPaths.iterator(); it.hasNext();) {
1203
                String[] sp = (String[]) it.next ();
1208
                String[] sp = (String[]) it.next();
1204
                TreePath tp = stringPath2TreePath (sp);
1209
                TreePath tp = stringPath2TreePath(sp);
1205
                if (tp != null) {
1210
                if (tp != null) {
1206
                    getOutline().expandPath(tp);
1211
                    getOutline().expandPath(tp);
1207
                    Rectangle rect = getOutline().getPathBounds(tp);
1212
                    Rectangle rect = getOutline().getPathBounds(tp);
Lines 1212-1232 Link Here
1212
            }
1217
            }
1213
        }
1218
        }
1214
1219
1215
        /** Converts path of strings to TreePath if exists null otherwise
1220
        /**
1221
         * Converts path of strings to TreePath if exists null otherwise
1216
         */
1222
         */
1217
        private TreePath stringPath2TreePath (String[] sp) {
1223
        private TreePath stringPath2TreePath(String[] sp) {
1218
            ExplorerManager em = ExplorerManager.find (this);
1224
            ExplorerManager em = ExplorerManager.find(this);
1219
            try {
1225
            try {
1220
                Node n = NodeOp.findPath (em.getRootContext (), sp); 
1226
                Node n = NodeOp.findPath(em.getRootContext(), sp);
1221
                
1227
1222
                // Create the tree path
1228
                // Create the tree path
1223
                TreeNode tns[] = new TreeNode [sp.length + 1];
1229
                TreeNode tns[] = new TreeNode[sp.length + 1];
1224
                
1230
1225
                for (int i = sp.length; i >= 0; i--) {
1231
                for (int i = sp.length; i >= 0; i--) {
1226
                    tns[i] = Visualizer.findVisualizer (n);
1232
                    tns[i] = Visualizer.findVisualizer(n);
1227
                    n = n.getParentNode ();
1233
                    n = n.getParentNode();
1228
                }                
1234
                }
1229
                return new TreePath (tns);
1235
                return new TreePath(tns);
1230
            } catch (NodeNotFoundException e) {
1236
            } catch (NodeNotFoundException e) {
1231
                return null;
1237
                return null;
1232
            }
1238
            }
Lines 1253-1263 Link Here
1253
        }
1259
        }
1254
1260
1255
    }
1261
    }
1256
    
1262
1257
    private static final class F8FilterComponentInputMap extends ComponentInputMap {
1263
    private static final class F8FilterComponentInputMap extends ComponentInputMap {
1258
        
1264
1259
        private KeyStroke f8 = KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0);
1265
        private KeyStroke f8 = KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0);
1260
        
1266
1261
        public F8FilterComponentInputMap(JComponent component, InputMap imap) {
1267
        public F8FilterComponentInputMap(JComponent component, InputMap imap) {
1262
            super(component);
1268
            super(component);
1263
            setParent(imap);
1269
            setParent(imap);
Lines 1272-1282 Link Here
1272
            }
1278
            }
1273
        }
1279
        }
1274
    }
1280
    }
1275
    
1281
1276
    private static final class F8FilterInputMap extends InputMap {
1282
    private static final class F8FilterInputMap extends InputMap {
1277
        
1283
1278
        private KeyStroke f8 = KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0);
1284
        private KeyStroke f8 = KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0);
1279
        
1285
1280
        public F8FilterInputMap(InputMap imap) {
1286
        public F8FilterInputMap(InputMap imap) {
1281
            setParent(imap);
1287
            setParent(imap);
1282
        }
1288
        }
Lines 1290-1295 Link Here
1290
            }
1296
            }
1291
        }
1297
        }
1292
    }
1298
    }
1293
    
1294
}
1295
1299
1300
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/TreeModelHyperNode.java (-64 / +69 lines)
Lines 39-45 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.viewmodel;
42
package org.netbeans.modules.viewmodel;
44
43
45
import java.awt.datatransfer.Transferable;
44
import java.awt.datatransfer.Transferable;
Lines 47-53 Link Here
47
import java.util.HashMap;
46
import java.util.HashMap;
48
import java.util.HashSet;
47
import java.util.HashSet;
49
import java.util.Set;
48
import java.util.Set;
50
51
import java.util.concurrent.Executor;
49
import java.util.concurrent.Executor;
52
import java.util.logging.Level;
50
import java.util.logging.Level;
53
import java.util.logging.Logger;
51
import java.util.logging.Logger;
Lines 70-102 Link Here
70
 */
68
 */
71
public class TreeModelHyperNode extends TreeModelNode {
69
public class TreeModelHyperNode extends TreeModelNode {
72
70
73
    private HyperCompoundModel model;
71
    private final HyperCompoundModel model;
74
    
72
75
    public TreeModelHyperNode(
73
    public TreeModelHyperNode(
76
        final HyperCompoundModel model,
74
            final HyperCompoundModel model,
77
        final TreeModelRoot treeModelRoot,
75
            final TreeModelRoot treeModelRoot,
78
        final Object object
76
            final Object object
79
    ) {
77
    ) {
80
        super(
78
        super(
81
            model.getMain(),
79
                model.getMain(),
82
            model.getColumns(),
80
                model.getColumns(),
83
            null,
81
                null,
84
            createChildren(model, treeModelRoot, object),
82
                createChildren(model, treeModelRoot, object),
85
            treeModelRoot,
83
                treeModelRoot,
86
            object
84
                object
87
        );
85
        );
88
        this.model = model;
86
        this.model = model;
89
    }
87
    }
90
88
91
    private static Children createChildren (
89
    private static Children createChildren(
92
        HyperCompoundModel model,
90
            HyperCompoundModel model,
93
        TreeModelRoot treeModelRoot,
91
            TreeModelRoot treeModelRoot,
94
        Object object
92
            Object object
95
    ) {
93
    ) {
96
        if (object == null) {
94
        if (object == null) {
97
            throw new NullPointerException ();
95
            throw new NullPointerException();
98
        }
96
        }
99
        return new HyperModelChildren (model, treeModelRoot, object);
97
        return new HyperModelChildren(model, treeModelRoot, object);
100
    }
98
    }
101
99
102
    @Override
100
    @Override
Lines 109-115 Link Here
109
            //hch.cleanCachedChildren(model);
107
            //hch.cleanCachedChildren(model);
110
            hch.refreshChildren(hch.new HyperRefreshingInfo(refreshInfo, models));
108
            hch.refreshChildren(hch.new HyperRefreshingInfo(refreshInfo, models));
111
        } else {
109
        } else {
112
            setChildren(new HyperModelChildren (this.model, treeModelRoot, object));
110
            setChildren(new HyperModelChildren(this.model, treeModelRoot, object));
113
        }
111
        }
114
    }
112
    }
115
113
Lines 130-136 Link Here
130
                    if (m != mm) {
128
                    if (m != mm) {
131
                        try {
129
                        try {
132
                            p = m.getDropType(object, t, action, index);
130
                            p = m.getDropType(object, t, action, index);
133
                            if (p != null) break;
131
                            if (p != null) {
132
                                break;
133
                            }
134
                        } catch (UnknownTypeException ex) {
134
                        } catch (UnknownTypeException ex) {
135
                        }
135
                        }
136
                    }
136
                    }
Lines 143-153 Link Here
143
            PasteType p = null;
143
            PasteType p = null;
144
            HyperModelChildren hch = (HyperModelChildren) getChildren();
144
            HyperModelChildren hch = (HyperModelChildren) getChildren();
145
            int index1 = (index > 0) ? index - 1 : index; // node above
145
            int index1 = (index > 0) ? index - 1 : index; // node above
146
            int[] modelIndexPtr = new int[] { -1 };
146
            int[] modelIndexPtr = new int[]{-1};
147
            CompoundModel cm1 = hch.getRootModelByIndex(index1, modelIndexPtr);
147
            CompoundModel cm1 = hch.getRootModelByIndex(index1, modelIndexPtr);
148
            if (cm1 != null) {
148
            if (cm1 != null) {
149
                try {
149
                try {
150
                    if (index1 < index) modelIndexPtr[0]++;
150
                    if (index1 < index) {
151
                        modelIndexPtr[0]++;
152
                    }
151
                    //System.err.println("\nTreeModelHyperNode.getDropType("+cm1+", \n"+action+", "+modelIndexPtr[0]+")");
153
                    //System.err.println("\nTreeModelHyperNode.getDropType("+cm1+", \n"+action+", "+modelIndexPtr[0]+")");
152
                    p = cm1.getDropType(object, t, action, modelIndexPtr[0]);
154
                    p = cm1.getDropType(object, t, action, modelIndexPtr[0]);
153
                } catch (UnknownTypeException e) {
155
                } catch (UnknownTypeException e) {
Lines 169-184 Link Here
169
    }
171
    }
170
172
171
    private static final class HyperModelChildren extends TreeModelChildren {
173
    private static final class HyperModelChildren extends TreeModelChildren {
172
        
174
173
        private HyperCompoundModel model;
175
        private final HyperCompoundModel model;
174
        private final java.util.Map<Object, Models.CompoundModel> rootModelsByChildren = new HashMap<Object, Models.CompoundModel>();
176
        private final java.util.Map<Object, Models.CompoundModel> rootModelsByChildren = new HashMap<>();
175
        private final java.util.Map<Models.CompoundModel, Object[]> rootChildrenByModels = new HashMap<Models.CompoundModel, Object[]>();
177
        private final java.util.Map<Models.CompoundModel, Object[]> rootChildrenByModels = new HashMap<>();
176
        private final int[] rootModelIndexes; // Children indexes of root models. First is 0.
178
        private final int[] rootModelIndexes; // Children indexes of root models. First is 0.
177
179
178
        public HyperModelChildren (
180
        public HyperModelChildren(
179
            HyperCompoundModel model,
181
                HyperCompoundModel model,
180
            TreeModelRoot   treeModelRoot,
182
                TreeModelRoot treeModelRoot,
181
            Object          object
183
                Object object
182
        ) {
184
        ) {
183
            super(null, model.getColumns(), treeModelRoot, object);
185
            super(null, model.getColumns(), treeModelRoot, object);
184
            this.model = model;
186
            this.model = model;
Lines 200-206 Link Here
200
                        }
202
                        }
201
                    }
203
                    }
202
                } catch (UnknownTypeException ex) {
204
                } catch (UnknownTypeException ex) {
203
                    Exceptions.printStackTrace(Exceptions.attachMessage(ex, "model = "+model+", object = "+object));
205
                    Exceptions.printStackTrace(Exceptions.attachMessage(ex, "model = " + model + ", object = " + object));
204
                }
206
                }
205
            }
207
            }
206
            if (exec == null) {
208
            if (exec == null) {
Lines 237-263 Link Here
237
                }
239
                }
238
                if (mch == null) {
240
                if (mch == null) {
239
                    if (tf != null) {
241
                    if (tf != null) {
240
                        int count = tf.getChildrenCount (m, object);
242
                        int count = tf.getChildrenCount(m, object);
241
                        mch = tf.getChildren (
243
                        mch = tf.getChildren(
242
                            m,
244
                                m,
243
                            object,
245
                                object,
244
                            0,
246
                                0,
245
                            count
247
                                count
246
                        );
248
                        );
247
                        if (mch == null) {
249
                        if (mch == null) {
248
                            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+tf+"\nreturned null children for parent '"+object+"'");
250
                            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + tf + "\nreturned null children for parent '" + object + "'");
249
                            mch = new Object[] {};
251
                            mch = new Object[]{};
250
                        }
252
                        }
251
                    } else {
253
                    } else {
252
                        int count = m.getChildrenCount (object);
254
                        int count = m.getChildrenCount(object);
253
                        mch = m.getChildren (
255
                        mch = m.getChildren(
254
                            object,
256
                                object,
255
                            0,
257
                                0,
256
                            count
258
                                count
257
                        );
259
                        );
258
                        if (mch == null) {
260
                        if (mch == null) {
259
                            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+m+"\nreturned null children for parent '"+object+"'");
261
                            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + m + "\nreturned null children for parent '" + object + "'");
260
                            mch = new Object[] {};
262
                            mch = new Object[]{};
261
                        }
263
                        }
262
                    }
264
                    }
263
                    synchronized (rootModelsByChildren) {
265
                    synchronized (rootModelsByChildren) {
Lines 305-318 Link Here
305
            synchronized (rootModelsByChildren) {
307
            synchronized (rootModelsByChildren) {
306
                model = rootModelsByChildren.get(child);
308
                model = rootModelsByChildren.get(child);
307
            }
309
            }
308
            if (model == null) return ;
310
            if (model == null) {
311
                return;
312
            }
309
            try {
313
            try {
310
                DefaultTreeExpansionManager.get(model).setChildrenToActOn(getTreeDepth());
314
                DefaultTreeExpansionManager.get(model).setChildrenToActOn(getTreeDepth());
311
                if (model.isExpanded (child)) {
315
                if (model.isExpanded(child)) {
312
                    TreeFeatures treeTable = treeModelRoot.getTreeFeatures ();
316
                    TreeFeatures treeTable = treeModelRoot.getTreeFeatures();
313
                    if (treeTable != null && treeTable.isExpanded(object)) {
317
                    if (treeTable != null && treeTable.isExpanded(object)) {
314
                        // Expand the child only if the parent is expanded
318
                        // Expand the child only if the parent is expanded
315
                        treeTable.expandNode (child);
319
                        treeTable.expandNode(child);
316
                    }
320
                    }
317
                }
321
                }
318
            } catch (UnknownTypeException ex) {
322
            } catch (UnknownTypeException ex) {
Lines 320-350 Link Here
320
        }
324
        }
321
325
322
        @Override
326
        @Override
323
        public Node[] createNodes (Object object) {
327
        public Node[] createNodes(Object object) {
324
            if (object == WAIT_KEY) {
328
            if (object == WAIT_KEY) {
325
                return super.createNodes(object);
329
                return super.createNodes(object);
326
            }
330
            }
327
            if (object instanceof Exception)
331
            if (object instanceof Exception) {
328
                return new Node[] {
332
                return new Node[]{
329
                    new ExceptionNode ((Exception) object)
333
                    new ExceptionNode((Exception) object)
330
                };
334
                };
335
            }
331
            Models.CompoundModel m;
336
            Models.CompoundModel m;
332
            synchronized (rootModelsByChildren) {
337
            synchronized (rootModelsByChildren) {
333
                m = rootModelsByChildren.get(object);
338
                m = rootModelsByChildren.get(object);
334
            }
339
            }
335
            if (m == null) {
340
            if (m == null) {
336
                //System.err.println("\n\n\n\n!!! NO NODE for object "+object+"!!!\n\n\n");
341
                //System.err.println("\n\n\n\n!!! NO NODE for object "+object+"!!!\n\n\n");
337
                return new Node[] {};
342
                return new Node[]{};
338
            }
343
            }
339
            TreeModelNode tmn = new TreeModelNode (
344
            TreeModelNode tmn = new TreeModelNode(
340
                m,
345
                    m,
341
                createHyperColumns(model.getColumns(), m.getColumns()),
346
                    createHyperColumns(model.getColumns(), m.getColumns()),
342
                treeModelRoot,
347
                    treeModelRoot,
343
                object
348
                    object
344
            );
349
            );
345
            //System.err.println("created node for ("+object+") = "+tmn);
350
            //System.err.println("created node for ("+object+") = "+tmn);
346
            objectToNode.put (object, new WeakReference<TreeModelNode>(tmn));
351
            objectToNode.put(object, new WeakReference<>(tmn));
347
            return new Node[] {tmn};
352
            return new Node[]{tmn};
348
        }
353
        }
349
354
350
        private static ColumnModel[] createHyperColumns(ColumnModel[] mainColumns, ColumnModel[] columns) {
355
        private static ColumnModel[] createHyperColumns(ColumnModel[] mainColumns, ColumnModel[] columns) {
Lines 372-378 Link Here
372
                        this.models.addAll(((HyperRefreshingInfo) rinfo).models);
377
                        this.models.addAll(((HyperRefreshingInfo) rinfo).models);
373
                    } catch (UnsupportedOperationException uoex) {
378
                    } catch (UnsupportedOperationException uoex) {
374
                        // add not supported, probably a non-modifiable set
379
                        // add not supported, probably a non-modifiable set
375
                        this.models = new HashSet<CompoundModel>(models);
380
                        this.models = new HashSet<>(models);
376
                        this.models.addAll(((HyperRefreshingInfo) rinfo).models);
381
                        this.models.addAll(((HyperRefreshingInfo) rinfo).models);
377
                    }
382
                    }
378
                }
383
                }
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/TreeModelNode.java (-563 / +607 lines)
Lines 41-58 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.viewmodel;
44
package org.netbeans.modules.viewmodel;
46
45
47
import java.awt.Component;
48
import java.awt.Image;
46
import java.awt.Image;
49
import java.awt.datatransfer.Transferable;
47
import java.awt.datatransfer.Transferable;
50
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionEvent;
51
import java.beans.PropertyChangeEvent;
49
import java.beans.PropertyChangeEvent;
52
import java.beans.PropertyChangeListener;
50
import java.beans.PropertyChangeListener;
53
import java.beans.PropertyEditor;
51
import java.beans.PropertyEditor;
54
import java.lang.ref.WeakReference;
55
import java.io.IOException;
52
import java.io.IOException;
53
import java.lang.ref.WeakReference;
56
import java.lang.reflect.InvocationTargetException;
54
import java.lang.reflect.InvocationTargetException;
57
import java.security.PrivilegedAction;
55
import java.security.PrivilegedAction;
58
import java.text.Format;
56
import java.text.Format;
Lines 62-69 Link Here
62
import java.util.Enumeration;
60
import java.util.Enumeration;
63
import java.util.HashMap;
61
import java.util.HashMap;
64
import java.util.HashSet;
62
import java.util.HashSet;
65
import java.util.Iterator;
66
import java.util.LinkedList;
67
import java.util.List;
63
import java.util.List;
68
import java.util.Map;
64
import java.util.Map;
69
import java.util.Set;
65
import java.util.Set;
Lines 75-87 Link Here
75
import java.util.logging.Logger;
71
import java.util.logging.Logger;
76
import javax.swing.AbstractAction;
72
import javax.swing.AbstractAction;
77
import javax.swing.Action;
73
import javax.swing.Action;
78
import javax.swing.JTable;
79
import javax.swing.KeyStroke;
74
import javax.swing.KeyStroke;
80
import javax.swing.SwingUtilities;
75
import javax.swing.SwingUtilities;
81
82
import javax.swing.event.ChangeEvent;
76
import javax.swing.event.ChangeEvent;
83
import javax.swing.event.ChangeListener;
77
import javax.swing.event.ChangeListener;
84
import javax.swing.table.TableCellRenderer;
85
import javax.swing.table.TableColumn;
78
import javax.swing.table.TableColumn;
86
import javax.swing.table.TableColumnModel;
79
import javax.swing.table.TableColumnModel;
87
import org.netbeans.spi.viewmodel.AsynchronousModelFilter;
80
import org.netbeans.spi.viewmodel.AsynchronousModelFilter;
Lines 92-98 Link Here
92
import org.netbeans.spi.viewmodel.Models.TreeFeatures;
85
import org.netbeans.spi.viewmodel.Models.TreeFeatures;
93
import org.netbeans.spi.viewmodel.UnknownTypeException;
86
import org.netbeans.spi.viewmodel.UnknownTypeException;
94
import org.netbeans.swing.etable.ETableColumn;
87
import org.netbeans.swing.etable.ETableColumn;
95
96
import org.openide.awt.Actions;
88
import org.openide.awt.Actions;
97
import org.openide.explorer.view.CheckableNode;
89
import org.openide.explorer.view.CheckableNode;
98
import org.openide.nodes.AbstractNode;
90
import org.openide.nodes.AbstractNode;
Lines 106-222 Link Here
106
import org.openide.util.NbBundle;
98
import org.openide.util.NbBundle;
107
import org.openide.util.RequestProcessor;
99
import org.openide.util.RequestProcessor;
108
import org.openide.util.RequestProcessor.Task;
100
import org.openide.util.RequestProcessor.Task;
109
import org.openide.util.actions.CallableSystemAction;
110
import org.openide.util.datatransfer.PasteType;
101
import org.openide.util.datatransfer.PasteType;
111
import org.openide.util.lookup.Lookups;
102
import org.openide.util.lookup.Lookups;
112
103
import org.openide.util.lookup.ProxyLookup;
113
104
114
/**
105
/**
115
 *
106
 *
116
 * @author   Jan Jancura
107
 * @author Jan Jancura
117
 */
108
 */
118
public class TreeModelNode extends AbstractNode {
109
public class TreeModelNode extends AbstractNode {
119
110
120
    /**
111
    /**
121
     * The maximum length of text that is interpreted as HTML.
112
     * The maximum length of text that is interpreted as HTML. This is
122
     * This is documented at openide/explorer/src/org/openide/explorer/doc-files/propertyViewCustomization.html
113
     * documented at
114
     * openide/explorer/src/org/openide/explorer/doc-files/propertyViewCustomization.html
123
     */
115
     */
124
    private static final int MAX_HTML_LENGTH = 511;
116
    private static final int MAX_HTML_LENGTH = 511;
125
    private static final String HTML_START_TAG = "<html>";
117
    private static final String HTML_START_TAG = "<html>";
126
    private static final String HTML_END_TAG = "</html>";
118
    private static final String HTML_END_TAG = "</html>";
127
    
128
    // variables ...............................................................
129
119
120
    // variables ...............................................................
130
    private Models.CompoundModel model;
121
    private Models.CompoundModel model;
131
    private final ColumnModel[]  columns;
122
    private final ColumnModel[] columns;
132
    protected TreeModelRoot      treeModelRoot;
123
    protected TreeModelRoot treeModelRoot;
133
    protected Object             object;
124
    protected Object object;
134
125
135
    private final LazyChildrenFactory lazyChildren;
126
    private final LazyChildrenFactory lazyChildren;
136
    private String              displayName, oldDisplayName;
127
    private String displayName, oldDisplayName;
137
    private String              htmlDisplayName;
128
    private String htmlDisplayName;
138
    private final Object        displayNameLock = new Object();
129
    private final Object displayNameLock = new Object();
139
    private boolean             iconLoaded;
130
    private boolean iconLoaded;
140
    private String              shortDescription;
131
    private String shortDescription;
141
    private final Object        shortDescriptionLock = new Object();
132
    private final Object shortDescriptionLock = new Object();
142
    private final Map<String, Object> properties = new HashMap<String, Object>();
133
    private final Map<String, Object> properties = new HashMap<String, Object>();
143
    private final Map<String, String> columnIDsMap;
134
    private final Map<String, String> columnIDsMap;
144
    private static final String EVALUATING_STR = NbBundle.getMessage(TreeModelNode.class, "EvaluatingProp");
135
    private static final String EVALUATING_STR = NbBundle.getMessage(TreeModelNode.class, "EvaluatingProp");
145
136
146
    
147
    // init ....................................................................
137
    // init ....................................................................
148
149
    /**
138
    /**
150
    * Creates root of call stack for given producer.
139
     * Creates root of call stack for given producer.
151
    */
140
     */
152
    public TreeModelNode (
141
    public TreeModelNode(
153
        final Models.CompoundModel model, 
142
            final Models.CompoundModel model,
154
        final TreeModelRoot treeModelRoot,
143
            final TreeModelRoot treeModelRoot,
155
        final Object object
144
            final Object object
156
    ) {
145
    ) {
157
        this(
146
        this(
158
            model,
147
                model,
159
            model.getColumns (),
148
                model.getColumns(),
160
            treeModelRoot,
149
                treeModelRoot,
161
            object
150
                object
162
        );
151
        );
163
    }
152
    }
164
153
165
    /**
154
    /**
166
    * Creates root of call stack for given producer.
155
     * Creates root of call stack for given producer.
167
    */
156
     */
168
    public TreeModelNode (
157
    public TreeModelNode(
169
        final Models.CompoundModel model,
158
            final Models.CompoundModel model,
170
        final ColumnModel[] columns,
159
            final ColumnModel[] columns,
171
        final TreeModelRoot treeModelRoot,
160
            final TreeModelRoot treeModelRoot,
172
        final Object object
161
            final Object object
173
    ) {
162
    ) {
174
        this(
163
        this(
175
            model,
164
                model,
176
            columns,
165
                columns,
177
            object != model.getRoot() ?
166
                object != model.getRoot()
178
                new LazyChildrenFactory(model, columns, treeModelRoot, object) : null,
167
                        ? new LazyChildrenFactory(model, columns, treeModelRoot, object) : null,
179
            object != model.getRoot() ?
168
                object != model.getRoot()
180
                null : createChildren (model, columns, treeModelRoot, object),
169
                        ? null : createChildren(model, columns, treeModelRoot, object),
181
            treeModelRoot,
170
                treeModelRoot,
182
            object
171
                object
183
        );
172
        );
184
    }
173
    }
185
174
186
    /**
175
    /**
187
    * Creates root of call stack for given producer.
176
     * Creates root of call stack for given producer.
188
    */
177
     */
189
    protected TreeModelNode (
178
    protected TreeModelNode(
190
        final Models.CompoundModel model,
179
            final Models.CompoundModel model,
191
        final ColumnModel[] columns,
180
            final ColumnModel[] columns,
192
        final LazyChildrenFactory lazyChildren,
181
            final LazyChildrenFactory lazyChildren,
193
        final Children children,
182
            final Children children,
194
        final TreeModelRoot treeModelRoot,
183
            final TreeModelRoot treeModelRoot,
195
        final Object object
184
            final Object object
196
    ) {
185
    ) {
197
        this(
186
        this(
198
            model,
187
                model,
199
            columns,
188
                columns,
200
            lazyChildren,
189
                lazyChildren,
201
            children,
190
                children,
202
            treeModelRoot,
191
                treeModelRoot,
203
            object,
192
                object,
204
            new Index[] { null });
193
                new Index[]{null});
205
    }
194
    }
206
195
207
    private TreeModelNode (
196
    private TreeModelNode(
208
        final Models.CompoundModel model,
197
            final Models.CompoundModel model,
209
        final ColumnModel[] columns,
198
            final ColumnModel[] columns,
210
        final LazyChildrenFactory lazyChildren,
199
            final LazyChildrenFactory lazyChildren,
211
        final Children children,
200
            final Children children,
212
        final TreeModelRoot treeModelRoot,
201
            final TreeModelRoot treeModelRoot,
213
        final Object object,
202
            final Object object,
214
        final Index[] indexPtr  // Hack, because we can not declare variables before call to super() :-(
203
            final Index[] indexPtr // Hack, because we can not declare variables before call to super() :-(
215
    ) {
204
    ) {
216
        super (
205
        super(
217
            (lazyChildren != null) ?
206
                (lazyChildren != null)
218
                Children.createLazy(lazyChildren) : children,
207
                        ? Children.createLazy(lazyChildren) : children,
219
            createLookup(object, model, children, indexPtr)
208
                createLookup(object, model, children, indexPtr)
220
        );
209
        );
221
        this.model = model;
210
        this.model = model;
222
        this.treeModelRoot = treeModelRoot;
211
        this.treeModelRoot = treeModelRoot;
Lines 226-273 Link Here
226
            ((IndexImpl) indexPtr[0]).setNode(this);
215
            ((IndexImpl) indexPtr[0]).setNode(this);
227
            setIndexWatcher(indexPtr[0]);
216
            setIndexWatcher(indexPtr[0]);
228
        }
217
        }
229
        
218
230
        // <RAVE>
219
        // <RAVE>
231
        // Use the modified CompoundModel class's field to set the 
220
        // Use the modified CompoundModel class's field to set the
232
        // propertiesHelpID for properties sheets if the model's helpID
221
        // propertiesHelpID for properties sheets if the model's helpID
233
        // has been set
222
        // has been set
234
        if (model.getHelpId() != null) {
223
        if (model.getHelpId() != null) {
235
            this.setValue("propertiesHelpID", model.getHelpId()); // NOI18N
224
            this.setValue("propertiesHelpID", model.getHelpId()); // NOI18N
236
        }
225
        }
237
        // </RAVE>
226
        // </RAVE>
238
        
227
239
        treeModelRoot.registerNode (object, this);
228
        treeModelRoot.registerNode(object, this);
240
        this.columnIDsMap = createColumnIDsMap(columns);
229
        this.columnIDsMap = createColumnIDsMap(columns);
241
        this.columns = columns;
230
        this.columns = columns;
242
    }
231
    }
243
232
244
    private static Lookup createLookup(Object object, Models.CompoundModel model,
233
    private static Lookup createLookup(Object object, Models.CompoundModel model,
245
                                       Children ch, Index[] indexPtr) {
234
            Children ch, Index[] indexPtr) {
246
        CheckNodeCookieImpl cnc = new CheckNodeCookieImpl(model, object);
235
        CheckNodeCookieImpl cnc = new CheckNodeCookieImpl(model, object);
247
        boolean canReorder;
236
        boolean canReorder;
248
        try {
237
        try {
249
            canReorder = model.canReorder(object);
238
            canReorder = model.canReorder(object);
250
        } catch (UnknownTypeException ex) {
239
        } catch (UnknownTypeException ex) {
251
            if (!(object instanceof String)) {
240
            if (!(object instanceof String)) {
252
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, ex);
241
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, ex);
253
            }
242
            }
254
            canReorder = false;
243
            canReorder = false;
255
        }
244
        }
245
246
        Lookup additional;
247
        try {
248
            additional = model.getLookup(object);
249
        } catch (UnknownTypeException ex) {
250
            additional = Lookup.EMPTY;
251
        }
252
256
        if (canReorder) {
253
        if (canReorder) {
257
            Index i = new IndexImpl(model, object);
254
            Index i = new IndexImpl(model, object);
258
            indexPtr[0] = i;
255
            indexPtr[0] = i;
259
            return Lookups.fixed(object, cnc, i);
256
            return new ProxyLookup(Lookups.fixed(object, cnc, i), additional);
260
        } else {
257
        } else {
261
            return Lookups.fixed(object, cnc);
258
            return new ProxyLookup(Lookups.fixed(object, cnc), additional);
262
        }
259
        }
263
    }
260
    }
264
    
261
265
    private static Map<String, String> createColumnIDsMap(ColumnModel[] columns) {
262
    private static Map<String, String> createColumnIDsMap(ColumnModel[] columns) {
266
        Map<String, String> cids = null;
263
        Map<String, String> cids = null;
267
        for (ColumnModel cm : columns) {
264
        for (ColumnModel cm : columns) {
268
            if (cm instanceof HyperColumnModel) {
265
            if (cm instanceof HyperColumnModel) {
269
                if (cids == null) {
266
                if (cids == null) {
270
                    cids = new HashMap<String, String>();
267
                    cids = new HashMap<>();
271
                }
268
                }
272
                HyperColumnModel hcm = (HyperColumnModel) cm;
269
                HyperColumnModel hcm = (HyperColumnModel) cm;
273
                String mainID = cm.getID();
270
                String mainID = cm.getID();
Lines 291-297 Link Here
291
        childrenIndex.addChangeListener(new ChangeListener() {
288
        childrenIndex.addChangeListener(new ChangeListener() {
292
            public void stateChanged(ChangeEvent e) {
289
            public void stateChanged(ChangeEvent e) {
293
                if (!areChildrenInitialized()) {
290
                if (!areChildrenInitialized()) {
294
                    return ;
291
                    return;
295
                }
292
                }
296
                Children ch = getChildren();
293
                Children ch = getChildren();
297
                if (ch instanceof TreeModelChildren) {
294
                if (ch instanceof TreeModelChildren) {
Lines 307-358 Link Here
307
            exec = model.asynchronous(asynchCall, object);
304
            exec = model.asynchronous(asynchCall, object);
308
            //System.err.println("Asynchronous("+asynchCall+", "+object+") = "+exec);
305
            //System.err.println("Asynchronous("+asynchCall+", "+object+") = "+exec);
309
            if (exec == null) {
306
            if (exec == null) {
310
                Exceptions.printStackTrace(Exceptions.attachMessage(new NullPointerException("Provided executor is null."), "model = "+model+", object = "+object));
307
                Exceptions.printStackTrace(Exceptions.attachMessage(new NullPointerException("Provided executor is null."), "model = " + model + ", object = " + object));
311
                exec = AsynchronousModelFilter.CURRENT_THREAD;
308
                exec = AsynchronousModelFilter.CURRENT_THREAD;
312
            }
309
            }
313
        } catch (Exception ex) {
310
        } catch (Exception ex) {
314
            Exceptions.printStackTrace(Exceptions.attachMessage(ex, "model = "+model+", object = "+object));
311
            Exceptions.printStackTrace(Exceptions.attachMessage(ex, "model = " + model + ", object = " + object));
315
            exec = AsynchronousModelFilter.CURRENT_THREAD;
312
            exec = AsynchronousModelFilter.CURRENT_THREAD;
316
        }
313
        }
317
        return exec;
314
        return exec;
318
    }
315
    }
319
316
320
321
    // Node implementation .....................................................
317
    // Node implementation .....................................................
322
323
    @Override
318
    @Override
324
    protected Sheet createSheet() {
319
    protected Sheet createSheet() {
325
        Sheet sheet = Sheet.createDefault();
320
        Sheet sheet = Sheet.createDefault();
326
        Sheet.Set ps = Sheet.createPropertiesSet ();
321
        Sheet.Set ps = Sheet.createPropertiesSet();
327
        int i, k = columns.length;
322
        int i, k = columns.length;
328
        for (i = 0; i < k; i++)
323
        for (i = 0; i < k; i++) {
329
            ps.put (new MyProperty (columns [i], treeModelRoot));
324
            ps.put(new MyProperty(columns[i], treeModelRoot));
330
        sheet.put (ps);
325
        }
326
        sheet.put(ps);
331
        return sheet;
327
        return sheet;
332
    }
328
    }
333
329
334
    private static Children createChildren (
330
    private static Children createChildren(
335
        Models.CompoundModel model,
331
            Models.CompoundModel model,
336
        ColumnModel[] columns,
332
            ColumnModel[] columns,
337
        TreeModelRoot treeModelRoot,
333
            TreeModelRoot treeModelRoot,
338
        Object object
334
            Object object
339
    ) {
335
    ) {
340
        if (object == null) 
336
        if (object == null) {
341
            throw new NullPointerException ();
337
            throw new NullPointerException();
338
        }
342
        try {
339
        try {
343
            return model.isLeaf (object) ? 
340
            return model.isLeaf(object)
344
                Children.LEAF :
341
                    ? Children.LEAF
345
                new TreeModelChildren (model, columns, treeModelRoot, object);
342
                    : new TreeModelChildren(model, columns, treeModelRoot, object);
346
        } catch (UnknownTypeException e) {
343
        } catch (UnknownTypeException e) {
347
            if (!(object instanceof String)) {
344
            if (!(object instanceof String)) {
348
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e);
345
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, e);
349
            }
346
            }
350
            return Children.LEAF;
347
            return Children.LEAF;
351
        }
348
        }
352
    }
349
    }
353
350
354
    @Override
351
    @Override
355
    public String getShortDescription () {
352
    public String getShortDescription() {
356
        synchronized (shortDescriptionLock) {
353
        synchronized (shortDescriptionLock) {
357
            if (shortDescription != null) {
354
            if (shortDescription != null) {
358
                return shortDescription;
355
                return shortDescription;
Lines 374-380 Link Here
374
371
375
    private String updateShortDescription() {
372
    private String updateShortDescription() {
376
        try {
373
        try {
377
            String sd = model.getShortDescription (object);
374
            String sd = model.getShortDescription(object);
378
            if (sd != null) {
375
            if (sd != null) {
379
                sd = adjustHTML(sd);
376
                sd = adjustHTML(sd);
380
            }
377
            }
Lines 384-390 Link Here
384
            return sd;
381
            return sd;
385
        } catch (UnknownTypeException e) {
382
        } catch (UnknownTypeException e) {
386
            if (!(object instanceof String)) {
383
            if (!(object instanceof String)) {
387
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e);
384
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, e);
388
            }
385
            }
389
            return null;
386
            return null;
390
        }
387
        }
Lines 396-411 Link Here
396
        }
393
        }
397
        fireShortDescriptionChange(null, null);
394
        fireShortDescriptionChange(null, null);
398
    }
395
    }
399
    
396
400
    @Override
397
    @Override
401
    public String getHtmlDisplayName () {
398
    public String getHtmlDisplayName() {
402
        synchronized (displayNameLock) {
399
        synchronized (displayNameLock) {
403
            // Compute the HTML display name if the ordinary display name is not available (e.g. was reset)
400
            // Compute the HTML display name if the ordinary display name is not available (e.g. was reset)
404
            if (displayName == null) {
401
            if (displayName == null) {
405
                try {
402
                try {
406
                    setModelDisplayName();
403
                    setModelDisplayName();
407
                } catch (UnknownTypeException ex) {
404
                } catch (UnknownTypeException ex) {
408
                    Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, ex);
405
                    Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, ex);
409
                }
406
                }
410
            }
407
            }
411
            if (displayName == null) {
408
            if (displayName == null) {
Lines 414-435 Link Here
414
            return htmlDisplayName;
411
            return htmlDisplayName;
415
        }
412
        }
416
    }
413
    }
417
    
414
418
    @Override
415
    @Override
419
    public Action[] getActions (boolean context) {
416
    public Action[] getActions(boolean context) {
420
        Action[] actions;
417
        Action[] actions;
421
        if (context) 
418
        if (context) {
422
            actions = treeModelRoot.getRootNode ().getActions (false);
419
            actions = treeModelRoot.getRootNode().getActions(false);
420
        }
423
        try {
421
        try {
424
            actions = filterActionsWhenSorted(model.getActions (object));
422
            actions = filterActionsWhenSorted(model.getActions(object));
425
        } catch (UnknownTypeException e) {
423
        } catch (UnknownTypeException e) {
426
            // NodeActionsProvider is voluntary
424
            // NodeActionsProvider is voluntary
427
            actions = new Action [0];
425
            actions = new Action[0];
428
        }
426
        }
429
        presetActionNodes(actions);
427
        presetActionNodes(actions);
430
        return actions;
428
        return actions;
431
    }
429
    }
432
    
430
433
    private void presetActionNodes(Action[] actions) {
431
    private void presetActionNodes(Action[] actions) {
434
        for (Action a : actions) {
432
        for (Action a : actions) {
435
            if (a instanceof ActionOnPresetNodes) {
433
            if (a instanceof ActionOnPresetNodes) {
Lines 456-462 Link Here
456
        }
454
        }
457
        for (int i = 0; i < actions.length; i++) {
455
        for (int i = 0; i < actions.length; i++) {
458
            Action a = actions[i];
456
            Action a = actions[i];
459
            if (a == null) continue;
457
            if (a == null) {
458
                continue;
459
            }
460
            boolean disabled = Boolean.TRUE.equals(a.getValue("DisabledWhenInSortedTable"));    // NOI18N
460
            boolean disabled = Boolean.TRUE.equals(a.getValue("DisabledWhenInSortedTable"));    // NOI18N
461
            if (disabled) {
461
            if (disabled) {
462
                if (a instanceof DisableableAction) {
462
                if (a instanceof DisableableAction) {
Lines 476-504 Link Here
476
    }
476
    }
477
477
478
    @Override
478
    @Override
479
    public Action getPreferredAction () {
479
    public Action getPreferredAction() {
480
        return new AbstractAction () {
480
        return new AbstractAction() {
481
            public void actionPerformed (ActionEvent e) {
481
            public void actionPerformed(ActionEvent e) {
482
                try {
482
                try {
483
                    model.performDefaultAction (object);
483
                    model.performDefaultAction(object);
484
                } catch (UnknownTypeException ex) {
484
                } catch (UnknownTypeException ex) {
485
                    // NodeActionsProvider is voluntary
485
                    // NodeActionsProvider is voluntary
486
                }
486
                }
487
            }
487
            }
488
        };
488
        };
489
    }
489
    }
490
    
490
491
    @Override
491
    @Override
492
    public boolean canDestroy () {
492
    public boolean canDestroy() {
493
        try {
493
        try {
494
            Action[] as = model.getActions (object);
494
            Action[] as = model.getActions(object);
495
            int i, k = as.length;
495
            int i, k = as.length;
496
            for (i = 0; i < k; i++) {
496
            for (i = 0; i < k; i++) {
497
                if (as [i] == null) continue;
497
                if (as[i] == null) {
498
                Object key = as [i].getValue (Action.ACCELERATOR_KEY);
498
                    continue;
499
                if ( (key != null) &&
499
                }
500
                     (key.equals (KeyStroke.getKeyStroke ("DELETE")))
500
                Object key = as[i].getValue(Action.ACCELERATOR_KEY);
501
                ) return as [i].isEnabled ();
501
                if ((key != null)
502
                        && (key.equals(KeyStroke.getKeyStroke("DELETE")))) {
503
                    return as[i].isEnabled();
504
                }
502
            }
505
            }
503
            return false;
506
            return false;
504
        } catch (UnknownTypeException e) {
507
        } catch (UnknownTypeException e) {
Lines 506-577 Link Here
506
            return false;
509
            return false;
507
        }
510
        }
508
    }
511
    }
509
    
512
510
    @Override
513
    @Override
511
    public boolean canCopy () {
514
    public boolean canCopy() {
512
        try {
515
        try {
513
            return model.canCopy(object);
516
            return model.canCopy(object);
514
        } catch (UnknownTypeException e) {
517
        } catch (UnknownTypeException e) {
515
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e);
518
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, e);
516
            return false;
519
            return false;
517
        }
520
        }
518
    }
521
    }
519
    
522
520
    @Override
523
    @Override
521
    public boolean canCut () {
524
    public boolean canCut() {
522
        try {
525
        try {
523
            return model.canCut(object);
526
            return model.canCut(object);
524
        } catch (UnknownTypeException e) {
527
        } catch (UnknownTypeException e) {
525
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e);
528
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, e);
526
            return false;
529
            return false;
527
        }
530
        }
528
    }
531
    }
529
    
532
530
    @Override
533
    @Override
531
    public void destroy () {
534
    public void destroy() {
532
        try {
535
        try {
533
            Action[] as = model.getActions (object);
536
            Action[] as = model.getActions(object);
534
            int i, k = as.length;
537
            int i, k = as.length;
535
            for (i = 0; i < k; i++) {
538
            for (i = 0; i < k; i++) {
536
                if (as [i] == null) continue;
539
                if (as[i] == null) {
537
                Object key = as [i].getValue (Action.ACCELERATOR_KEY);
540
                    continue;
538
                if ( (key != null) &&
541
                }
539
                     (key.equals (KeyStroke.getKeyStroke ("DELETE")))
542
                Object key = as[i].getValue(Action.ACCELERATOR_KEY);
540
                ) {
543
                if ((key != null)
541
                    as [i].actionPerformed (null);
544
                        && (key.equals(KeyStroke.getKeyStroke("DELETE")))) {
545
                    as[i].actionPerformed(null);
542
                    return;
546
                    return;
543
                }
547
                }
544
            }
548
            }
545
        } catch (UnknownTypeException e) {
549
        } catch (UnknownTypeException e) {
546
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e);
550
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, e);
547
        }
551
        }
548
        if (model.getRoot() == object) {
552
        if (model.getRoot() == object) {
549
            treeModelRoot.destroy();
553
            treeModelRoot.destroy();
550
        }
554
        }
551
    }
555
    }
552
556
553
    
554
    // other methods ...........................................................
557
    // other methods ...........................................................
555
    
558
    void setObject(Object o) {
556
    void setObject (Object o) {
557
        setObject(model, o);
559
        setObject(model, o);
558
    }
560
    }
559
    
561
560
    void setObject (Models.CompoundModel model, Object o) {
562
    void setObject(Models.CompoundModel model, Object o) {
561
        setObjectNoRefresh (o);
563
        setObjectNoRefresh(o);
562
        refresh (model);
564
        refresh(model);
563
    }
565
    }
564
566
565
    private void setObjectNoRefresh (Object o) {
567
    private void setObjectNoRefresh(Object o) {
566
        object = o;
568
        object = o;
567
        if (areChildrenInitialized()) {
569
        if (areChildrenInitialized()) {
568
            Children ch = getChildren ();
570
            Children ch = getChildren();
569
            if (ch instanceof TreeModelChildren)
571
            if (ch instanceof TreeModelChildren) {
570
                ((TreeModelChildren) ch).object = o;
572
                ((TreeModelChildren) ch).object = o;
573
            }
571
        }
574
        }
572
    }
575
    }
573
    
576
574
    public Object getObject () {
577
    public Object getObject() {
575
        return object;
578
        return object;
576
    }
579
    }
577
580
Lines 582-605 Link Here
582
    private Task refreshTask;
585
    private Task refreshTask;
583
    private final Object refreshTaskLock = new Object();
586
    private final Object refreshTaskLock = new Object();
584
    private final Set<Models.CompoundModel> childrenRefreshModels = new HashSet<Models.CompoundModel>();
587
    private final Set<Models.CompoundModel> childrenRefreshModels = new HashSet<Models.CompoundModel>();
585
    
588
586
    void refresh (Models.CompoundModel model) {
589
    void refresh(Models.CompoundModel model) {
587
        //System.err.println("TreeModelNode.refresh("+model+") on "+object);
590
        //System.err.println("TreeModelNode.refresh("+model+") on "+object);
588
        //Thread.dumpStack();
591
        //Thread.dumpStack();
589
        // 1) empty cache
592
        // 1) empty cache
590
        synchronized (properties) {
593
        synchronized (properties) {
591
            properties.clear();
594
            properties.clear();
592
        }
595
        }
593
        
596
594
        
595
        // 2) refresh name, displayName and iconBase
597
        // 2) refresh name, displayName and iconBase
596
        synchronized (childrenRefreshModels) {
598
        synchronized (childrenRefreshModels) {
597
            childrenRefreshModels.add(model);
599
            childrenRefreshModels.add(model);
598
        }
600
        }
599
        synchronized (refreshTaskLock) {
601
        synchronized (refreshTaskLock) {
600
            if (refreshTask == null) {
602
            if (refreshTask == null) {
601
                refreshTask = getRequestProcessor ().create (new Runnable () {
603
                refreshTask = getRequestProcessor().create(new Runnable() {
602
                    public void run () {
604
                    public void run() {
603
                        if (!SwingUtilities.isEventDispatchThread()) {
605
                        if (!SwingUtilities.isEventDispatchThread()) {
604
                            try {
606
                            try {
605
                                SwingUtilities.invokeAndWait(this);
607
                                SwingUtilities.invokeAndWait(this);
Lines 607-615 Link Here
607
                            } catch (InvocationTargetException ex) {
609
                            } catch (InvocationTargetException ex) {
608
                                Exceptions.printStackTrace(ex);
610
                                Exceptions.printStackTrace(ex);
609
                            }
611
                            }
610
                            return ;
612
                            return;
611
                        }
613
                        }
612
                        refreshNode ();
614
                        refreshNode();
613
                        doFireShortDescriptionChange();
615
                        doFireShortDescriptionChange();
614
616
615
                        // 3) refresh children
617
                        // 3) refresh children
Lines 627-637 Link Here
627
            refreshTask.schedule(10);
629
            refreshTask.schedule(10);
628
        }
630
        }
629
    }
631
    }
630
    
632
631
    void refresh (final Models.CompoundModel model, int changeMask) {
633
    void refresh(final Models.CompoundModel model, int changeMask) {
632
        if (changeMask == 0xFFFFFFFF) {
634
        if (changeMask == 0xFFFFFFFF) {
633
            refresh(model);
635
            refresh(model);
634
            return ;
636
            return;
635
        }
637
        }
636
        boolean refreshed = false;
638
        boolean refreshed = false;
637
        if ((ModelEvent.NodeChanged.DISPLAY_NAME_MASK & changeMask) != 0) {
639
        if ((ModelEvent.NodeChanged.DISPLAY_NAME_MASK & changeMask) != 0) {
Lines 664-671 Link Here
664
                doRefresh = childrenRefreshModels.add(model);
666
                doRefresh = childrenRefreshModels.add(model);
665
            }
667
            }
666
            if (doRefresh) {
668
            if (doRefresh) {
667
                SwingUtilities.invokeLater (new Runnable () {
669
                SwingUtilities.invokeLater(new Runnable() {
668
                    public void run () {
670
                    public void run() {
669
                        synchronized (childrenRefreshModels) {
671
                        synchronized (childrenRefreshModels) {
670
                            childrenRefreshModels.remove(model);
672
                            childrenRefreshModels.remove(model);
671
                        }
673
                        }
Lines 676-683 Link Here
676
            refreshed = true;
678
            refreshed = true;
677
        }
679
        }
678
        if ((ModelEvent.NodeChanged.EXPANSION_MASK & changeMask) != 0) {
680
        if ((ModelEvent.NodeChanged.EXPANSION_MASK & changeMask) != 0) {
679
            SwingUtilities.invokeLater (new Runnable () {
681
            SwingUtilities.invokeLater(new Runnable() {
680
                public void run () {
682
                public void run() {
681
                    expandIfSetToExpanded();
683
                    expandIfSetToExpanded();
682
                }
684
                }
683
            });
685
            });
Lines 686-717 Link Here
686
            refresh(model);
688
            refresh(model);
687
        }
689
        }
688
    }
690
    }
689
    
691
690
    private static RequestProcessor requestProcessor;
692
    private static RequestProcessor requestProcessor;
693
691
    // Accessed from test
694
    // Accessed from test
692
    RequestProcessor getRequestProcessor () {
695
    RequestProcessor getRequestProcessor() {
693
        /*RequestProcessor rp = treeModelRoot.getRequestProcessor();
696
        /*RequestProcessor rp = treeModelRoot.getRequestProcessor();
694
        if (rp != null) {
697
         if (rp != null) {
695
            return rp;
698
         return rp;
696
        }*/
699
         }*/
697
        synchronized (TreeModelNode.class) {
700
        synchronized (TreeModelNode.class) {
698
            if (requestProcessor == null)
701
            if (requestProcessor == null) {
699
                requestProcessor = new RequestProcessor ("TreeModel", 1);
702
                requestProcessor = new RequestProcessor("TreeModel", 1);
703
            }
700
            return requestProcessor;
704
            return requestProcessor;
701
        }
705
        }
702
    }
706
    }
703
707
704
    private boolean setName (String name, boolean italics) {
708
    private boolean setName(String name, boolean italics) {
705
        // XXX HACK: HTMLDisplayName is missing in the models!
709
        // XXX HACK: HTMLDisplayName is missing in the models!
706
        synchronized (displayNameLock) {
710
        synchronized (displayNameLock) {
707
            String oldHtmlDisplayName = htmlDisplayName;
711
            String oldHtmlDisplayName = htmlDisplayName;
708
            String _oldDisplayName = oldDisplayName;
712
            String _oldDisplayName = oldDisplayName;
709
713
710
            String newDisplayName;
714
            String newDisplayName;
711
            if (name.startsWith (HTML_START_TAG)) {
715
            if (name.startsWith(HTML_START_TAG)) {
712
                htmlDisplayName = name;
716
                htmlDisplayName = name;
713
                newDisplayName = removeHTML(name);
717
                newDisplayName = removeHTML(name);
714
            } else if (name.startsWith ("<_html>")) { //[TODO] use empty string as name in the case of <_html> tag
718
            } else if (name.startsWith("<_html>")) { //[TODO] use empty string as name in the case of <_html> tag
715
                htmlDisplayName = '<' + name.substring(2);
719
                htmlDisplayName = '<' + name.substring(2);
716
                newDisplayName = "";
720
                newDisplayName = "";
717
            } else {
721
            } else {
Lines 720-730 Link Here
720
            }
724
            }
721
            displayName = newDisplayName;
725
            displayName = newDisplayName;
722
            oldDisplayName = newDisplayName;
726
            oldDisplayName = newDisplayName;
723
            return _oldDisplayName == null || !_oldDisplayName.equals(newDisplayName) ||
727
            return _oldDisplayName == null || !_oldDisplayName.equals(newDisplayName)
724
                   oldHtmlDisplayName == null || !oldHtmlDisplayName.equals(htmlDisplayName);
728
                    || oldHtmlDisplayName == null || !oldHtmlDisplayName.equals(htmlDisplayName);
725
        }
729
        }
726
    }
730
    }
727
    
731
728
    private String parseDisplayFormat(String name) {
732
    private String parseDisplayFormat(String name) {
729
        MessageFormat treeNodeDisplayFormat = treeModelRoot.getTreeNodeDisplayFormat();
733
        MessageFormat treeNodeDisplayFormat = treeModelRoot.getTreeNodeDisplayFormat();
730
        if (treeNodeDisplayFormat == null) {
734
        if (treeNodeDisplayFormat == null) {
Lines 742-754 Link Here
742
        String[] argsHTML = new String[n];
746
        String[] argsHTML = new String[n];
743
        boolean nonEmptyArgs = false;
747
        boolean nonEmptyArgs = false;
744
        for (int i = 0; i < n; i++) {
748
        for (int i = 0; i < n; i++) {
745
            if (pattern.indexOf("{"+i) >= 0) {
749
            if (pattern.indexOf("{" + i) >= 0) {
746
            //if (formatsByArgumentIndex[i] != null) {
750
                //if (formatsByArgumentIndex[i] != null) {
747
                if (columns[i].getType() == null) {
751
                if (columns[i].getType() == null) {
748
                    if (name.startsWith (HTML_START_TAG)) {
752
                    if (name.startsWith(HTML_START_TAG)) {
749
                        argsHTML[i] = name;
753
                        argsHTML[i] = name;
750
                        args[i] = removeHTML(name);
754
                        args[i] = removeHTML(name);
751
                    } else if (name.startsWith ("<_html>")) {
755
                    } else if (name.startsWith("<_html>")) {
752
                        argsHTML[i] = '<' + name.substring(2);
756
                        argsHTML[i] = '<' + name.substring(2);
753
                        args[i] = removeHTML((String) argsHTML[i]);
757
                        args[i] = removeHTML((String) argsHTML[i]);
754
                    } else {
758
                    } else {
Lines 792-805 Link Here
792
            }
796
            }
793
            String format = treeNodeDisplayFormat.format(args);
797
            String format = treeNodeDisplayFormat.format(args);
794
            if (isHTML) {
798
            if (isHTML) {
795
                format = HTML_START_TAG+format+HTML_END_TAG;
799
                format = HTML_START_TAG + format + HTML_END_TAG;
796
            }
800
            }
797
            return format; //new Object[] { name });
801
            return format; //new Object[] { name });
798
        } else {
802
        } else {
799
            return name;
803
            return name;
800
        }
804
        }
801
    }
805
    }
802
    
806
803
    private static String stripHTMLTags(String str) {
807
    private static String stripHTMLTags(String str) {
804
        if (str.startsWith(HTML_START_TAG)) {
808
        if (str.startsWith(HTML_START_TAG)) {
805
            str = str.substring(HTML_START_TAG.length());
809
            str = str.substring(HTML_START_TAG.length());
Lines 809-824 Link Here
809
        }
813
        }
810
        return str;
814
        return str;
811
    }
815
    }
812
    
816
813
    private PropertyDisplayNameListener propertyDisplayNameListener;
817
    private PropertyDisplayNameListener propertyDisplayNameListener;
814
    
818
815
    private class PropertyDisplayNameListener implements PropertyChangeListener {
819
    private class PropertyDisplayNameListener implements PropertyChangeListener {
816
        
820
817
        private Set<String> propertyNames = new HashSet<String>();
821
        private Set<String> propertyNames = new HashSet<String>();
818
        
822
819
        PropertyDisplayNameListener() {
823
        PropertyDisplayNameListener() {
820
        }
824
        }
821
        
825
822
        void addPropertyName(String propertyName) {
826
        void addPropertyName(String propertyName) {
823
            propertyNames.add(propertyName);
827
            propertyNames.add(propertyName);
824
        }
828
        }
Lines 830-856 Link Here
830
                    setModelDisplayName();
834
                    setModelDisplayName();
831
                    fireDisplayNameChange(null, null);
835
                    fireDisplayNameChange(null, null);
832
                } catch (UnknownTypeException ex) {
836
                } catch (UnknownTypeException ex) {
833
                    Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, ex);
837
                    Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, ex);
834
                }
838
                }
835
            }
839
            }
836
        }
840
        }
837
        
841
838
    }
842
    }
839
843
840
    private void setModelDisplayName() throws UnknownTypeException {
844
    private void setModelDisplayName() throws UnknownTypeException {
841
        Executor exec = asynchronous(model, CALL.DISPLAY_NAME, object);
845
        Executor exec = asynchronous(model, CALL.DISPLAY_NAME, object);
842
        if (exec == AsynchronousModelFilter.CURRENT_THREAD) {
846
        if (exec == AsynchronousModelFilter.CURRENT_THREAD) {
843
            String name = model.getDisplayName (object);
847
            String name = model.getDisplayName(object);
844
            if (name == null) {
848
            if (name == null) {
845
                Throwable t =
849
                Throwable t
846
                    new NullPointerException (
850
                        = new NullPointerException(
847
                        "Model: " + model + ".getDisplayName (" + object +
851
                                "Model: " + model + ".getDisplayName (" + object
848
                        ") = null!"
852
                                + ") = null!"
849
                    );
853
                        );
850
                Exceptions.printStackTrace(t);
854
                Exceptions.printStackTrace(t);
851
            } else {
855
            } else {
852
                name = parseDisplayFormat(name);
856
                name = parseDisplayFormat(name);
853
                setName (name, false);
857
                setName(name, false);
854
            }
858
            }
855
        } else {
859
        } else {
856
            final String originalDisplayName = (oldDisplayName != null) ? oldDisplayName : "";
860
            final String originalDisplayName = (oldDisplayName != null) ? oldDisplayName : "";
Lines 861-884 Link Here
861
                    try {
865
                    try {
862
                        name = model.getDisplayName(object);
866
                        name = model.getDisplayName(object);
863
                    } catch (UnknownTypeException ex) {
867
                    } catch (UnknownTypeException ex) {
864
                        Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, ex);
868
                        Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, ex);
865
                        setName(originalDisplayName, false);
869
                        setName(originalDisplayName, false);
866
                        fireDisplayNameChange(null, originalDisplayName);
870
                        fireDisplayNameChange(null, originalDisplayName);
867
                        return ;
871
                        return;
868
                    }
872
                    }
869
                    if (name == null) {
873
                    if (name == null) {
870
                        Throwable t =
874
                        Throwable t
871
                            new NullPointerException (
875
                                = new NullPointerException(
872
                                "Model: " + model + ".getDisplayName (" + object +
876
                                        "Model: " + model + ".getDisplayName (" + object
873
                                ") = null!"
877
                                        + ") = null!"
874
                            );
878
                                );
875
                        Exceptions.printStackTrace(t);
879
                        Exceptions.printStackTrace(t);
876
                        setName(originalDisplayName, false);
880
                        setName(originalDisplayName, false);
877
                        fireDisplayNameChange(null, originalDisplayName);
881
                        fireDisplayNameChange(null, originalDisplayName);
878
                    } else {
882
                    } else if (setName(name, false)) {
879
                        if (setName (name, false)) {
883
                        fireDisplayNameChange(null, name);
880
                            fireDisplayNameChange(null, name);
881
                        }
882
                    }
884
                    }
883
                }
885
                }
884
            });
886
            });
Lines 892-898 Link Here
892
                try {
894
                try {
893
                    setModelDisplayName();
895
                    setModelDisplayName();
894
                } catch (UnknownTypeException ex) {
896
                } catch (UnknownTypeException ex) {
895
                    Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, ex);
897
                    Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, ex);
896
                }
898
                }
897
            }
899
            }
898
            if (displayName == null) {
900
            if (displayName == null) {
Lines 907-913 Link Here
907
        String sOld;
909
        String sOld;
908
        synchronized (displayNameLock) {
910
        synchronized (displayNameLock) {
909
            if ((displayName != null) && displayName.equals(s)) {
911
            if ((displayName != null) && displayName.equals(s)) {
910
                return ;
912
                return;
911
            }
913
            }
912
            sOld = displayName;
914
            sOld = displayName;
913
            displayName = oldDisplayName = s;
915
            displayName = oldDisplayName = s;
Lines 918-938 Link Here
918
    private void setModelIcon() throws UnknownTypeException {
920
    private void setModelIcon() throws UnknownTypeException {
919
        String iconBase = null;
921
        String iconBase = null;
920
        if (model.getRoot() != object) {
922
        if (model.getRoot() != object) {
921
            iconBase = model.getIconBaseWithExtension (object);
923
            iconBase = model.getIconBaseWithExtension(object);
924
        }
925
        if (iconBase != null) {
926
            setIconBaseWithExtension(iconBase);
927
        } else {
928
            setIconBaseWithExtension("org/openide/resources/actions/empty.gif");
922
        }
929
        }
923
        if (iconBase != null)
924
            setIconBaseWithExtension (iconBase);
925
        else
926
            setIconBaseWithExtension ("org/openide/resources/actions/empty.gif");
927
    }
930
    }
928
931
929
    @Override
932
    @Override
930
    public Image getIcon(int type) {
933
    public Image getIcon(int type) {
934
935
        try {
936
            Image icon = model.getIcon(object, type);
937
            if (icon != null) {
938
                return icon;
939
            }
940
        } catch (UnknownTypeException ex) {
941
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.FINE, "no icon from model"); // NOI18N
942
        }
943
931
        if (!iconLoaded) {
944
        if (!iconLoaded) {
932
            try {
945
            try {
933
                setModelIcon();
946
                setModelIcon();
934
            } catch (UnknownTypeException ex) {
947
            } catch (UnknownTypeException ex) {
935
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, ex);
948
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, ex);
936
            }
949
            }
937
            iconLoaded = true;
950
            iconLoaded = true;
938
        }
951
        }
Lines 941-958 Link Here
941
954
942
    @Override
955
    @Override
943
    public Image getOpenedIcon(int type) {
956
    public Image getOpenedIcon(int type) {
957
        try {
958
            Image icon = model.getOpenedIcon(object, type);
959
            if (icon != null) {
960
                return icon;
961
            }
962
        } catch (UnknownTypeException ex) {
963
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.FINE, "no openedIcon from model"); // NOI18N
964
        }
965
944
        if (!iconLoaded) {
966
        if (!iconLoaded) {
945
            try {
967
            try {
946
                setModelIcon();
968
                setModelIcon();
947
            } catch (UnknownTypeException ex) {
969
            } catch (UnknownTypeException ex) {
948
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, ex);
970
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, ex);
949
            }
971
            }
950
            iconLoaded = true;
972
            iconLoaded = true;
951
        }
973
        }
952
        return super.getOpenedIcon(type);
974
        return super.getOpenedIcon(type);
953
    }
975
    }
954
976
955
    private void refreshNode () {
977
    private void refreshNode() {
956
        boolean doFireDisplayNameChange;
978
        boolean doFireDisplayNameChange;
957
        synchronized (displayNameLock) {
979
        synchronized (displayNameLock) {
958
            doFireDisplayNameChange = displayName != null;
980
            doFireDisplayNameChange = displayName != null;
Lines 969-975 Link Here
969
        }
991
        }
970
        firePropertyChange(null, null, null);
992
        firePropertyChange(null, null, null);
971
    }
993
    }
972
    
994
973
    void refreshColumn(String column, int changeMask) {
995
    void refreshColumn(String column, int changeMask) {
974
        String visualColumn = column;
996
        String visualColumn = column;
975
        if (columnIDsMap != null) {
997
        if (columnIDsMap != null) {
Lines 989-995 Link Here
989
                properties.remove(column + "#canWrite");
1011
                properties.remove(column + "#canWrite");
990
            }
1012
            }
991
        }
1013
        }
992
        
1014
993
        firePropertyChange(visualColumn, null, null);
1015
        firePropertyChange(visualColumn, null, null);
994
    }
1016
    }
995
1017
Lines 998-1014 Link Here
998
     * @param refreshSubNodes If recursively refresh subnodes.
1020
     * @param refreshSubNodes If recursively refresh subnodes.
999
     */
1021
     */
1000
    protected void refreshTheChildren(Set<Models.CompoundModel> models, TreeModelChildren.RefreshingInfo refreshInfo) {
1022
    protected void refreshTheChildren(Set<Models.CompoundModel> models, TreeModelChildren.RefreshingInfo refreshInfo) {
1001
        for (Models.CompoundModel model: models) {
1023
        for (Models.CompoundModel model : models) {
1002
            refreshTheChildren(model, refreshInfo);
1024
            refreshTheChildren(model, refreshInfo);
1003
        }
1025
        }
1004
    }
1026
    }
1027
1005
    /**
1028
    /**
1006
     * @param model The associated model - necessary for hyper node.
1029
     * @param model The associated model - necessary for hyper node.
1007
     * @param refreshSubNodes If recursively refresh subnodes.
1030
     * @param refreshSubNodes If recursively refresh subnodes.
1008
     */
1031
     */
1009
    private void refreshTheChildren(Models.CompoundModel model, TreeModelChildren.RefreshingInfo refreshInfo) {
1032
    private void refreshTheChildren(Models.CompoundModel model, TreeModelChildren.RefreshingInfo refreshInfo) {
1010
        if (!areChildrenInitialized()) {
1033
        if (!areChildrenInitialized()) {
1011
            return ;
1034
            return;
1012
        }
1035
        }
1013
        Children ch = getChildren();
1036
        Children ch = getChildren();
1014
        try {
1037
        try {
Lines 1018-1037 Link Here
1018
                } else {
1041
                } else {
1019
                    ((TreeModelChildren) ch).refreshChildren(refreshInfo);
1042
                    ((TreeModelChildren) ch).refreshChildren(refreshInfo);
1020
                }
1043
                }
1021
            } else if (!model.isLeaf (object)) {
1044
            } else if (!model.isLeaf(object)) {
1022
                setChildren(new TreeModelChildren (model, columns, treeModelRoot, object));
1045
                setChildren(new TreeModelChildren(model, columns, treeModelRoot, object));
1023
            }
1046
            }
1024
        } catch (UnknownTypeException utex) {
1047
        } catch (UnknownTypeException utex) {
1025
            // not known - do not change children
1048
            // not known - do not change children
1026
            if (!(object instanceof String)) {
1049
            if (!(object instanceof String)) {
1027
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, utex);
1050
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, utex);
1028
            }
1051
            }
1029
            setChildren(Children.LEAF);
1052
            setChildren(Children.LEAF);
1030
        }
1053
        }
1031
    }
1054
    }
1032
    
1055
1033
    private static String htmlValue (String name) {
1056
    private static String htmlValue(String name) {
1034
        if (!(name.length() > 6 && name.substring(0, 6).equalsIgnoreCase(HTML_START_TAG))) return null;
1057
        if (!(name.length() > 6 && name.substring(0, 6).equalsIgnoreCase(HTML_START_TAG))) {
1058
            return null;
1059
        }
1035
        if (name.length() > MAX_HTML_LENGTH) {
1060
        if (name.length() > MAX_HTML_LENGTH) {
1036
            int endTagsPos = findEndTagsPos(name);
1061
            int endTagsPos = findEndTagsPos(name);
1037
            String ending = name.substring(endTagsPos + 1);
1062
            String ending = name.substring(endTagsPos + 1);
Lines 1051-1093 Link Here
1051
        }
1076
        }
1052
        return adjustHTML(name);
1077
        return adjustHTML(name);
1053
    }
1078
    }
1054
    
1079
1055
    private static int findEndTagsPos(String s) {
1080
    private static int findEndTagsPos(String s) {
1056
        int openings = 0;
1081
        int openings = 0;
1057
        int i;
1082
        int i;
1058
        for (i = s.length() - 1; i >= 0; i--) {
1083
        for (i = s.length() - 1; i >= 0; i--) {
1059
            if (s.charAt(i) == '>') openings++;
1084
            if (s.charAt(i) == '>') {
1060
            else if (s.charAt(i) == '<') openings--;
1085
                openings++;
1061
            else if (openings == 0) break;
1086
            } else if (s.charAt(i) == '<') {
1087
                openings--;
1088
            } else if (openings == 0) {
1089
                break;
1090
            }
1062
        }
1091
        }
1063
        return i;
1092
        return i;
1064
    }
1093
    }
1065
    
1094
1066
    private static String removeHTML (String text) {
1095
    private static String removeHTML(String text) {
1067
        if (!(text.length() > 6 && text.substring(0, 6).equalsIgnoreCase(HTML_START_TAG))) {
1096
        if (!(text.length() > 6 && text.substring(0, 6).equalsIgnoreCase(HTML_START_TAG))) {
1068
            return text;
1097
            return text;
1069
        }
1098
        }
1070
        text = text.replaceAll ("<i>", "");
1099
        text = text.replaceAll("<i>", "");
1071
        text = text.replaceAll ("</i>", "");
1100
        text = text.replaceAll("</i>", "");
1072
        text = text.replaceAll ("<b>", "");
1101
        text = text.replaceAll("<b>", "");
1073
        text = text.replaceAll ("</b>", "");
1102
        text = text.replaceAll("</b>", "");
1074
        text = text.replaceAll (HTML_START_TAG, "");
1103
        text = text.replaceAll(HTML_START_TAG, "");
1075
        text = text.replaceAll (HTML_END_TAG, "");
1104
        text = text.replaceAll(HTML_END_TAG, "");
1076
        text = text.replaceAll ("</font>", "");
1105
        text = text.replaceAll("</font>", "");
1077
        int i = text.indexOf ("<font");
1106
        int i = text.indexOf("<font");
1078
        while (i >= 0) {
1107
        while (i >= 0) {
1079
            int j = text.indexOf (">", i);
1108
            int j = text.indexOf(">", i);
1080
            text = text.substring (0, i) + text.substring (j + 1);
1109
            text = text.substring(0, i) + text.substring(j + 1);
1081
            i = text.indexOf ("<font");
1110
            i = text.indexOf("<font");
1082
        }
1111
        }
1083
        text = text.replaceAll ("&lt;", "<");
1112
        text = text.replaceAll("&lt;", "<");
1084
        text = text.replaceAll ("&gt;", ">");
1113
        text = text.replaceAll("&gt;", ">");
1085
        text = text.replaceAll ("&amp;", "&");
1114
        text = text.replaceAll("&amp;", "&");
1086
        return text;
1115
        return text;
1087
    }
1116
    }
1088
    
1117
1089
    /** Adjusts HTML text so that it's rendered correctly.
1118
    /**
1090
     * In particular, this assures that white characters are visible.
1119
     * Adjusts HTML text so that it's rendered correctly. In particular, this
1120
     * assures that white characters are visible.
1091
     */
1121
     */
1092
    private static String adjustHTML(String text) {
1122
    private static String adjustHTML(String text) {
1093
        text = text.replaceAll(java.util.regex.Matcher.quoteReplacement("\\"), "\\\\\\\\");
1123
        text = text.replaceAll(java.util.regex.Matcher.quoteReplacement("\\"), "\\\\\\\\");
Lines 1112-1118 Link Here
1112
                    sb.append(text.substring(j, i));
1142
                    sb.append(text.substring(j, i));
1113
                }
1143
                }
1114
                sb.append(replacement);
1144
                sb.append(replacement);
1115
                j = i+1;
1145
                j = i + 1;
1116
            }
1146
            }
1117
        }
1147
        }
1118
        if (sb == null) {
1148
        if (sb == null) {
Lines 1122-1135 Link Here
1122
            return sb.toString();
1152
            return sb.toString();
1123
        }
1153
        }
1124
    }
1154
    }
1125
    
1155
1126
    
1127
    @Override
1156
    @Override
1128
    public boolean canRename() {
1157
    public boolean canRename() {
1129
        try {
1158
        try {
1130
            return model.canRename(object);
1159
            return model.canRename(object);
1131
        } catch (UnknownTypeException e) {
1160
        } catch (UnknownTypeException e) {
1132
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e);
1161
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, e);
1133
            return false;
1162
            return false;
1134
        }
1163
        }
1135
    }
1164
    }
Lines 1140-1156 Link Here
1140
            model.setName(object, s);
1169
            model.setName(object, s);
1141
            super.setName(s);
1170
            super.setName(s);
1142
        } catch (UnknownTypeException e) {
1171
        } catch (UnknownTypeException e) {
1143
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e);
1172
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, e);
1144
        }
1173
        }
1145
    }
1174
    }
1146
    
1175
1147
    @Override
1176
    @Override
1148
    public Transferable clipboardCopy() throws IOException {
1177
    public Transferable clipboardCopy() throws IOException {
1149
        Transferable t;
1178
        Transferable t;
1150
        try {
1179
        try {
1151
            t = model.clipboardCopy(object);
1180
            t = model.clipboardCopy(object);
1152
        } catch (UnknownTypeException e) {
1181
        } catch (UnknownTypeException e) {
1153
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e);
1182
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, e);
1154
            t = null;
1183
            t = null;
1155
        }
1184
        }
1156
        if (t == null) {
1185
        if (t == null) {
Lines 1159-1172 Link Here
1159
            return t;
1188
            return t;
1160
        }
1189
        }
1161
    }
1190
    }
1162
    
1191
1163
    @Override
1192
    @Override
1164
    public Transferable clipboardCut() throws IOException {
1193
    public Transferable clipboardCut() throws IOException {
1165
        Transferable t;
1194
        Transferable t;
1166
        try {
1195
        try {
1167
            t = model.clipboardCut(object);
1196
            t = model.clipboardCut(object);
1168
        } catch (UnknownTypeException e) {
1197
        } catch (UnknownTypeException e) {
1169
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e);
1198
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, e);
1170
            t = null;
1199
            t = null;
1171
        }
1200
        }
1172
        if (t == null) {
1201
        if (t == null) {
Lines 1175-1188 Link Here
1175
            return t;
1204
            return t;
1176
        }
1205
        }
1177
    }
1206
    }
1178
    
1207
1179
    @Override
1208
    @Override
1180
    public Transferable drag() throws IOException {
1209
    public Transferable drag() throws IOException {
1181
        Transferable t;
1210
        Transferable t;
1182
        try {
1211
        try {
1183
            t = model.drag(object);
1212
            t = model.drag(object);
1184
        } catch (UnknownTypeException e) {
1213
        } catch (UnknownTypeException e) {
1185
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e);
1214
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, e);
1186
            t = null;
1215
            t = null;
1187
        }
1216
        }
1188
        if (t == null) {
1217
        if (t == null) {
Lines 1191-1204 Link Here
1191
            return t;
1220
            return t;
1192
        }
1221
        }
1193
    }
1222
    }
1194
    
1223
1195
    @Override
1224
    @Override
1196
    public void createPasteTypes(Transferable t, List<PasteType> l) {
1225
    public void createPasteTypes(Transferable t, List<PasteType> l) {
1197
        PasteType[] p;
1226
        PasteType[] p;
1198
        try {
1227
        try {
1199
            p = model.getPasteTypes(object, t);
1228
            p = model.getPasteTypes(object, t);
1200
        } catch (UnknownTypeException e) {
1229
        } catch (UnknownTypeException e) {
1201
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e);
1230
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, e);
1202
            p = null;
1231
            p = null;
1203
        }
1232
        }
1204
        if (p == null) {
1233
        if (p == null) {
Lines 1207-1220 Link Here
1207
            l.addAll(Arrays.asList(p));
1236
            l.addAll(Arrays.asList(p));
1208
        }
1237
        }
1209
    }
1238
    }
1210
    
1239
1211
    @Override
1240
    @Override
1212
    public PasteType getDropType(Transferable t, int action, int index) {
1241
    public PasteType getDropType(Transferable t, int action, int index) {
1213
        PasteType p;
1242
        PasteType p;
1214
        try {
1243
        try {
1215
            p = model.getDropType(object, t, action, index);
1244
            p = model.getDropType(object, t, action, index);
1216
        } catch (UnknownTypeException e) {
1245
        } catch (UnknownTypeException e) {
1217
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e);
1246
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, e);
1218
            p = null;
1247
            p = null;
1219
        }
1248
        }
1220
        if (p == null) {
1249
        if (p == null) {
Lines 1223-1236 Link Here
1223
            return p;
1252
            return p;
1224
        }
1253
        }
1225
    }
1254
    }
1226
    
1255
1227
    private final void expandIfSetToExpanded() {
1256
    private final void expandIfSetToExpanded() {
1228
        try {
1257
        try {
1229
            DefaultTreeExpansionManager.get(model).setChildrenToActOn(getTreeDepth());
1258
            DefaultTreeExpansionManager.get(model).setChildrenToActOn(getTreeDepth());
1230
            if (model.isExpanded (object)) {
1259
            if (model.isExpanded(object)) {
1231
                TreeFeatures treeTable = treeModelRoot.getTreeFeatures ();
1260
                TreeFeatures treeTable = treeModelRoot.getTreeFeatures();
1232
                if (treeTable != null) {
1261
                if (treeTable != null) {
1233
                    treeTable.expandNode (object);
1262
                    treeTable.expandNode(object);
1234
                }
1263
                }
1235
            }
1264
            }
1236
        } catch (UnknownTypeException ex) {
1265
        } catch (UnknownTypeException ex) {
Lines 1247-1279 Link Here
1247
            return depth;
1276
            return depth;
1248
        } else {
1277
        } else {
1249
            int d = 1;
1278
            int d = 1;
1250
            while ((p = p.getParentNode()) != null) d++;
1279
            while ((p = p.getParentNode()) != null) {
1280
                d++;
1281
            }
1251
            depth = new Integer(d);
1282
            depth = new Integer(d);
1252
            return depth;
1283
            return depth;
1253
        }
1284
        }
1254
    }
1285
    }
1255
1286
1256
    // innerclasses ............................................................
1287
    // innerclasses ............................................................
1257
1258
    public static interface DisableableAction extends Action {
1288
    public static interface DisableableAction extends Action {
1259
1289
1260
        Action createDisableable(PrivilegedAction enabledTest);
1290
        Action createDisableable(PrivilegedAction enabledTest);
1261
        
1291
1262
    }
1292
    }
1263
    
1293
1264
    /**
1294
    /**
1265
     * An action, that can act on a pre-set set of nodes.
1295
     * An action, that can act on a pre-set set of nodes.
1266
     */
1296
     */
1267
    public static interface ActionOnPresetNodes extends Action {
1297
    public static interface ActionOnPresetNodes extends Action {
1268
        
1298
1269
        /**
1299
        /**
1270
         * Add a node to act on.
1300
         * Add a node to act on. The set of nodes is cleared in the next cycle
1271
         * The set of nodes is cleared in the next cycle of event dispatch loop.
1301
         * of event dispatch loop. When no nodes are provided, the
1272
         * When no nodes are provided, the TopComponent.getRegistry ().getActivatedNodes () are used.
1302
         * TopComponent.getRegistry ().getActivatedNodes () are used.
1303
         *
1273
         * @param n a node to act on
1304
         * @param n a node to act on
1274
         */
1305
         */
1275
        void addNode(Node n);
1306
        void addNode(Node n);
1276
        
1307
1277
    }
1308
    }
1278
1309
1279
    private class DisabledWhenSortedAction implements Action {
1310
    private class DisabledWhenSortedAction implements Action {
Lines 1338-1344 Link Here
1338
            try {
1369
            try {
1339
                return model.isCheckable(object);
1370
                return model.isCheckable(object);
1340
            } catch (UnknownTypeException ex) {
1371
            } catch (UnknownTypeException ex) {
1341
                Exceptions.printStackTrace(Exceptions.attachMessage(ex, "Model = "+model));
1372
                Exceptions.printStackTrace(Exceptions.attachMessage(ex, "Model = " + model));
1342
                return false;
1373
                return false;
1343
            }
1374
            }
1344
        }
1375
        }
Lines 1347-1353 Link Here
1347
            try {
1378
            try {
1348
                return model.isCheckEnabled(object);
1379
                return model.isCheckEnabled(object);
1349
            } catch (UnknownTypeException ex) {
1380
            } catch (UnknownTypeException ex) {
1350
                Exceptions.printStackTrace(Exceptions.attachMessage(ex, "Model = "+model));
1381
                Exceptions.printStackTrace(Exceptions.attachMessage(ex, "Model = " + model));
1351
                return false;
1382
                return false;
1352
            }
1383
            }
1353
        }
1384
        }
Lines 1356-1362 Link Here
1356
            try {
1387
            try {
1357
                return model.isSelected(object);
1388
                return model.isSelected(object);
1358
            } catch (UnknownTypeException ex) {
1389
            } catch (UnknownTypeException ex) {
1359
                Exceptions.printStackTrace(Exceptions.attachMessage(ex, "Model = "+model));
1390
                Exceptions.printStackTrace(Exceptions.attachMessage(ex, "Model = " + model));
1360
                return false;
1391
                return false;
1361
            }
1392
            }
1362
        }
1393
        }
Lines 1365-1432 Link Here
1365
            try {
1396
            try {
1366
                model.setSelected(object, selected);
1397
                model.setSelected(object, selected);
1367
            } catch (UnknownTypeException ex) {
1398
            } catch (UnknownTypeException ex) {
1368
                Exceptions.printStackTrace(Exceptions.attachMessage(ex, "Model = "+model));
1399
                Exceptions.printStackTrace(Exceptions.attachMessage(ex, "Model = " + model));
1369
            }
1400
            }
1370
        }
1401
        }
1371
1402
1372
    }
1403
    }
1373
    
1404
1374
    /** Special locals subnodes (children) */
1405
    /**
1406
     * Special locals subnodes (children)
1407
     */
1375
    static class TreeModelChildren extends Children.Keys<Object>
1408
    static class TreeModelChildren extends Children.Keys<Object>
1376
                                   implements Runnable {// LazyEvaluator.Evaluable {
1409
            implements Runnable {// LazyEvaluator.Evaluable {
1377
            
1410
1378
        private boolean             initialezed = false;
1411
        private boolean initialezed = false;
1379
        private final Models.CompoundModel model;
1412
        private final Models.CompoundModel model;
1380
        private final ColumnModel[]   columns;
1413
        private final ColumnModel[] columns;
1381
        protected final TreeModelRoot      treeModelRoot;
1414
        protected final TreeModelRoot treeModelRoot;
1382
        protected Object            object;
1415
        protected Object object;
1383
        protected final WeakHashMap<Object, WeakReference<TreeModelNode>> objectToNode = new WeakHashMap<Object, WeakReference<TreeModelNode>>();
1416
        protected final WeakHashMap<Object, WeakReference<TreeModelNode>> objectToNode = new WeakHashMap<Object, WeakReference<TreeModelNode>>();
1384
        private final int[]         evaluated = { 0 }; // 0 - not yet, 1 - evaluated, -1 - timeouted
1417
        private final int[] evaluated = {0}; // 0 - not yet, 1 - evaluated, -1 - timeouted
1385
        private RefreshingInfo      evaluatingRefreshingInfo;
1418
        private RefreshingInfo evaluatingRefreshingInfo;
1386
        private Object[]            children_evaluated;
1419
        private Object[] children_evaluated;
1387
        private RefreshingInfo      refreshInfo = null;
1420
        private RefreshingInfo refreshInfo = null;
1388
        private boolean             refreshingStarted = true;
1421
        private boolean refreshingStarted = true;
1389
1422
1390
        private RequestProcessor.Task   task;
1423
        private RequestProcessor.Task task;
1391
        private RequestProcessor        lastRp;
1424
        private RequestProcessor lastRp;
1392
        
1425
1393
        protected static final Object WAIT_KEY = new Object();
1426
        protected static final Object WAIT_KEY = new Object();
1394
        
1427
1395
        
1428
        TreeModelChildren(
1396
        TreeModelChildren (
1429
                Models.CompoundModel model,
1397
            Models.CompoundModel model,
1430
                ColumnModel[] columns,
1398
            ColumnModel[]   columns,
1431
                TreeModelRoot treeModelRoot,
1399
            TreeModelRoot   treeModelRoot,
1432
                Object object
1400
            Object          object
1401
        ) {
1433
        ) {
1402
            this.model = model;
1434
            this.model = model;
1403
            this.columns = columns;
1435
            this.columns = columns;
1404
            this.treeModelRoot = treeModelRoot;
1436
            this.treeModelRoot = treeModelRoot;
1405
            this.object = object;
1437
            this.object = object;
1406
        }
1438
        }
1407
        
1439
1408
        @Override
1440
        @Override
1409
        protected void addNotify () {
1441
        protected void addNotify() {
1410
            if (initialezed) {
1442
            if (initialezed) {
1411
                //System.err.println("\n\nTreeModelChildren.addNotify() called more that once! Parent = "+getNode()+"\n\n");
1443
                //System.err.println("\n\nTreeModelChildren.addNotify() called more that once! Parent = "+getNode()+"\n\n");
1412
                return ;
1444
                return;
1413
            }
1445
            }
1414
            initialezed = true;
1446
            initialezed = true;
1415
            refreshChildren (new RefreshingInfo(true));
1447
            refreshChildren(new RefreshingInfo(true));
1416
        }
1448
        }
1417
        
1449
1418
        @Override
1450
        @Override
1419
        protected void removeNotify () {
1451
        protected void removeNotify() {
1420
            initialezed = false;
1452
            initialezed = false;
1421
            setKeys (Collections.emptySet());
1453
            setKeys(Collections.emptySet());
1422
        }
1454
        }
1423
        
1455
1424
        void refreshChildren (RefreshingInfo refreshSubNodes) {
1456
        void refreshChildren(RefreshingInfo refreshSubNodes) {
1425
            if (!initialezed) return;
1457
            if (!initialezed) {
1458
                return;
1459
            }
1426
1460
1427
            refreshLazyChildren(refreshSubNodes);
1461
            refreshLazyChildren(refreshSubNodes);
1428
        }
1462
        }
1429
        
1463
1430
        public void run() {
1464
        public void run() {
1431
            RefreshingInfo rinfo;
1465
            RefreshingInfo rinfo;
1432
            synchronized (evaluated) {
1466
            synchronized (evaluated) {
Lines 1434-1443 Link Here
1434
                rinfo = refreshInfo;
1468
                rinfo = refreshInfo;
1435
                if (evaluatingRefreshingInfo == null) {
1469
                if (evaluatingRefreshingInfo == null) {
1436
                    evaluatingRefreshingInfo = refreshInfo;
1470
                    evaluatingRefreshingInfo = refreshInfo;
1437
                } else {
1471
                } else if (refreshInfo != null) {
1438
                    if (refreshInfo != null) {
1472
                    evaluatingRefreshingInfo = evaluatingRefreshingInfo.mergeWith(refreshInfo);
1439
                        evaluatingRefreshingInfo = evaluatingRefreshingInfo.mergeWith(refreshInfo);
1440
                    }
1441
                }
1473
                }
1442
                refreshInfo = null; // reset after use
1474
                refreshInfo = null; // reset after use
1443
            }
1475
            }
Lines 1445-1453 Link Here
1445
            try {
1477
            try {
1446
                ch = getModelChildren(rinfo);
1478
                ch = getModelChildren(rinfo);
1447
            } catch (UnknownTypeException e) {
1479
            } catch (UnknownTypeException e) {
1448
                ch = new Object [0];
1480
                ch = new Object[0];
1449
                if (!(object instanceof String)) {
1481
                if (!(object instanceof String)) {
1450
                    Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e);
1482
                    Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, e);
1451
                }
1483
                }
1452
            } catch (ThreadDeath td) {
1484
            } catch (ThreadDeath td) {
1453
                throw td;
1485
                throw td;
Lines 1482-1496 Link Here
1482
1514
1483
        protected Object[] getModelChildren(RefreshingInfo refreshInfo) throws UnknownTypeException {
1515
        protected Object[] getModelChildren(RefreshingInfo refreshInfo) throws UnknownTypeException {
1484
            //System.err.println("! getModelChildren("+object+", "+getNode()+")");
1516
            //System.err.println("! getModelChildren("+object+", "+getNode()+")");
1485
            int count = model.getChildrenCount (object);
1517
            int count = model.getChildrenCount(object);
1486
            Object[] ch = model.getChildren (
1518
            Object[] ch = model.getChildren(
1487
                object,
1519
                    object,
1488
                0,
1520
                    0,
1489
                count
1521
                    count
1490
            );
1522
            );
1491
            if (ch == null) {
1523
            if (ch == null) {
1492
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model+"\nreturned null children for parent '"+object+"'");
1524
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model + "\nreturned null children for parent '" + object + "'");
1493
                ch = new Object[] {};
1525
                ch = new Object[]{};
1494
            }
1526
            }
1495
            return ch;
1527
            return ch;
1496
        }
1528
        }
Lines 1498-1505 Link Here
1498
        protected Executor getModelAsynchronous() {
1530
        protected Executor getModelAsynchronous() {
1499
            return asynchronous(model, CALL.CHILDREN, object);
1531
            return asynchronous(model, CALL.CHILDREN, object);
1500
        }
1532
        }
1501
        
1533
1502
        private void refreshLazyChildren (RefreshingInfo refreshInfo) {
1534
        private void refreshLazyChildren(RefreshingInfo refreshInfo) {
1503
            //System.err.println("\n!! refreshLazyChildren("+getNode()+") from:");
1535
            //System.err.println("\n!! refreshLazyChildren("+getNode()+") from:");
1504
            //Thread.dumpStack();
1536
            //Thread.dumpStack();
1505
            //System.err.println("");
1537
            //System.err.println("");
Lines 1509-1521 Link Here
1509
                try {
1541
                try {
1510
                    ch = getModelChildren(refreshInfo);
1542
                    ch = getModelChildren(refreshInfo);
1511
                } catch (UnknownTypeException ex) {
1543
                } catch (UnknownTypeException ex) {
1512
                    ch = new Object [0];
1544
                    ch = new Object[0];
1513
                    if (!(object instanceof String)) {
1545
                    if (!(object instanceof String)) {
1514
                        Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, ex);
1546
                        Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, ex);
1515
                    }
1547
                    }
1516
                }
1548
                }
1517
                applyChildren(ch, refreshInfo, true);
1549
                applyChildren(ch, refreshInfo, true);
1518
                return ;
1550
                return;
1519
            }
1551
            }
1520
            synchronized (evaluated) {
1552
            synchronized (evaluated) {
1521
                evaluated[0] = 0;
1553
                evaluated[0] = 0;
Lines 1528-1542 Link Here
1528
                //System.err.println(this.hashCode()+" refreshLazyChildren() started = true, evaluated = 0");
1560
                //System.err.println(this.hashCode()+" refreshLazyChildren() started = true, evaluated = 0");
1529
            }
1561
            }
1530
            /*if (exec instanceof RequestProcessor) {
1562
            /*if (exec instanceof RequestProcessor) {
1531
                // Have a single task for RP
1563
             // Have a single task for RP
1532
                RequestProcessor rp = (RequestProcessor) exec;
1564
             RequestProcessor rp = (RequestProcessor) exec;
1533
                if (rp != lastRp) {
1565
             if (rp != lastRp) {
1534
                    task = rp.create(this);
1566
             task = rp.create(this);
1535
                    lastRp = rp;
1567
             lastRp = rp;
1536
                }
1568
             }
1537
                task.schedule(0);
1569
             task.schedule(0);
1538
            } else {*/
1570
             } else {*/
1539
                exec.execute(this);
1571
            exec.execute(this);
1540
            //}
1572
            //}
1541
            // It's refresh => do not check for this children already being evaluated
1573
            // It's refresh => do not check for this children already being evaluated
1542
            //treeModelRoot.getChildrenEvaluator().evaluate(this, false);
1574
            //treeModelRoot.getChildrenEvaluator().evaluate(this, false);
Lines 1545-1551 Link Here
1545
                if (evaluated[0] != 1) {
1577
                if (evaluated[0] != 1) {
1546
                    try {
1578
                    try {
1547
                        evaluated.wait(getChildrenRefreshWaitTime());
1579
                        evaluated.wait(getChildrenRefreshWaitTime());
1548
                    } catch (InterruptedException iex) {}
1580
                    } catch (InterruptedException iex) {
1581
                    }
1549
                    if (evaluated[0] != 1) {
1582
                    if (evaluated[0] != 1) {
1550
                        evaluated[0] = -1; // timeout
1583
                        evaluated[0] = -1; // timeout
1551
                        ch = null;
1584
                        ch = null;
Lines 1557-1563 Link Here
1557
                }
1590
                }
1558
                //System.err.println(this.hashCode()+" refreshLazyChildren() ending, evaluated[0] = "+evaluated[0]+", refreshingStarted = "+refreshingStarted+", children_evaluated = "+(children_evaluated != null)+", ch = "+(ch != null));
1591
                //System.err.println(this.hashCode()+" refreshLazyChildren() ending, evaluated[0] = "+evaluated[0]+", refreshingStarted = "+refreshingStarted+", children_evaluated = "+(children_evaluated != null)+", ch = "+(ch != null));
1559
                // Do nothing when it's evaluated, but already unset.
1592
                // Do nothing when it's evaluated, but already unset.
1560
                if (children_evaluated == null && evaluated[0] == 1) return;
1593
                if (children_evaluated == null && evaluated[0] == 1) {
1594
                    return;
1595
                }
1561
                children_evaluated = null;
1596
                children_evaluated = null;
1562
                if (ch != null) {
1597
                if (ch != null) {
1563
                    refreshInfo = evaluatingRefreshingInfo;
1598
                    refreshInfo = evaluatingRefreshingInfo;
Lines 1574-1580 Link Here
1574
        }
1609
        }
1575
1610
1576
        private static AtomicLong lastChildrenRefresh = new AtomicLong(0);
1611
        private static AtomicLong lastChildrenRefresh = new AtomicLong(0);
1577
        
1612
1578
        private static long getChildrenRefreshWaitTime() {
1613
        private static long getChildrenRefreshWaitTime() {
1579
            long now = System.currentTimeMillis();
1614
            long now = System.currentTimeMillis();
1580
            long last = lastChildrenRefresh.getAndSet(now);
1615
            long last = lastChildrenRefresh.getAndSet(now);
Lines 1585-1641 Link Here
1585
                return 200;
1620
                return 200;
1586
            }
1621
            }
1587
        }
1622
        }
1588
        
1623
1589
        private void applyChildren(final Object[] ch, RefreshingInfo refreshInfo, boolean doSetObject) {
1624
        private void applyChildren(final Object[] ch, RefreshingInfo refreshInfo, boolean doSetObject) {
1590
            //System.err.println(this.hashCode()+" applyChildren("+refreshSubNodes+")");
1625
            //System.err.println(this.hashCode()+" applyChildren("+refreshSubNodes+")");
1591
            //System.err.println("applyChildren("+Arrays.toString(ch)+", "+doSetObject+")");
1626
            //System.err.println("applyChildren("+Arrays.toString(ch)+", "+doSetObject+")");
1592
            int i, k = ch.length; 
1627
            int i, k = ch.length;
1593
            for (i = 0; i < k; i++) {
1628
            for (i = 0; i < k; i++) {
1594
                if (ch [i] == null) {
1629
                if (ch[i] == null) {
1595
                    throw new NullPointerException("Null child at index "+i+", parent: "+object+", model: "+model+"\nAll children are: "+Arrays.toString(ch));
1630
                    throw new NullPointerException("Null child at index " + i + ", parent: " + object + ", model: " + model + "\nAll children are: " + Arrays.toString(ch));
1596
                }
1631
                }
1597
                if (doSetObject) {
1632
                if (doSetObject) {
1598
                    WeakReference<TreeModelNode> wr;
1633
                    WeakReference<TreeModelNode> wr;
1599
                    synchronized (objectToNode) {
1634
                    synchronized (objectToNode) {
1600
                        wr = objectToNode.get(ch [i]);
1635
                        wr = objectToNode.get(ch[i]);
1636
                    }
1637
                    if (wr == null) {
1638
                        continue;
1639
                    }
1640
                    TreeModelNode tmn = wr.get();
1641
                    if (tmn == null) {
1642
                        continue;
1601
                    }
1643
                    }
1602
                    if (wr == null) continue;
1603
                    TreeModelNode tmn = wr.get ();
1604
                    if (tmn == null) continue;
1605
                    if (refreshInfo == null || refreshInfo.isRefreshSubNodes(ch[i])) {
1644
                    if (refreshInfo == null || refreshInfo.isRefreshSubNodes(ch[i])) {
1606
                        tmn.setObject (ch [i]);
1645
                        tmn.setObject(ch[i]);
1607
                    } else {
1646
                    } else {
1608
                        tmn.setObjectNoRefresh(ch[i]);
1647
                        tmn.setObjectNoRefresh(ch[i]);
1609
                    }
1648
                    }
1610
                }
1649
                }
1611
            }
1650
            }
1612
            setKeys (ch);
1651
            setKeys(ch);
1613
1652
1614
            SwingUtilities.invokeLater (new Runnable () {
1653
            SwingUtilities.invokeLater(new Runnable() {
1615
                public void run () {
1654
                public void run() {
1616
                    int i, k = ch.length;
1655
                    int i, k = ch.length;
1617
                    for (i = 0; i < k; i++)
1656
                    for (i = 0; i < k; i++) {
1618
                        expandIfSetToExpanded(ch[i]);
1657
                        expandIfSetToExpanded(ch[i]);
1658
                    }
1619
                }
1659
                }
1620
            });
1660
            });
1621
        }
1661
        }
1622
        
1662
1623
        protected void expandIfSetToExpanded(Object child) {
1663
        protected void expandIfSetToExpanded(Object child) {
1624
            try {
1664
            try {
1625
                DefaultTreeExpansionManager.get(model).setChildrenToActOn(getTreeDepth());
1665
                DefaultTreeExpansionManager.get(model).setChildrenToActOn(getTreeDepth());
1626
                if (model.isExpanded (child)) {
1666
                if (model.isExpanded(child)) {
1627
                    TreeFeatures treeTable = treeModelRoot.getTreeFeatures ();
1667
                    TreeFeatures treeTable = treeModelRoot.getTreeFeatures();
1628
                    if (treeTable != null && treeTable.isExpanded(object)) {
1668
                    if (treeTable != null && treeTable.isExpanded(object)) {
1629
                        // Expand the child only if the parent is expanded
1669
                        // Expand the child only if the parent is expanded
1630
                        treeTable.expandNode (child);
1670
                        treeTable.expandNode(child);
1631
                    }
1671
                    }
1632
                }
1672
                }
1633
            } catch (UnknownTypeException ex) {
1673
            } catch (UnknownTypeException ex) {
1634
            }
1674
            }
1635
        }
1675
        }
1636
        
1676
1637
        private Integer depth;
1677
        private Integer depth;
1638
        
1678
1639
        Integer getTreeDepth() {
1679
        Integer getTreeDepth() {
1640
            Node p = getNode();
1680
            Node p = getNode();
1641
            if (p == null) {
1681
            if (p == null) {
Lines 1644-1660 Link Here
1644
                return depth;
1684
                return depth;
1645
            } else {
1685
            } else {
1646
                int d = 1;
1686
                int d = 1;
1647
                while ((p = p.getParentNode()) != null) d++;
1687
                while ((p = p.getParentNode()) != null) {
1688
                    d++;
1689
                }
1648
                depth = new Integer(d);
1690
                depth = new Integer(d);
1649
                return depth;
1691
                return depth;
1650
            }
1692
            }
1651
        }
1693
        }
1652
        
1694
1653
        private void applyWaitChildren() {
1695
        private void applyWaitChildren() {
1654
            //System.err.println(this.hashCode()+" applyWaitChildren()");
1696
            //System.err.println(this.hashCode()+" applyWaitChildren()");
1655
            setKeys(new Object[] { WAIT_KEY });
1697
            setKeys(new Object[]{WAIT_KEY});
1656
        }
1698
        }
1657
        
1699
1658
//        protected void destroyNodes (Node[] nodes) {
1700
//        protected void destroyNodes (Node[] nodes) {
1659
//            int i, k = nodes.length;
1701
//            int i, k = nodes.length;
1660
//            for (i = 0; i < k; i++) {
1702
//            for (i = 0; i < k; i++) {
Lines 1668-1696 Link Here
1668
//                    nameToChild.remove (name);
1710
//                    nameToChild.remove (name);
1669
//            }
1711
//            }
1670
//        }
1712
//        }
1671
        
1713
        public Node[] createNodes(Object object) {
1672
        public Node[] createNodes (Object object) {
1673
            if (object == WAIT_KEY) {
1714
            if (object == WAIT_KEY) {
1674
                AbstractNode n = new AbstractNode(Children.LEAF);
1715
                AbstractNode n = new AbstractNode(Children.LEAF);
1675
                n.setName(NbBundle.getMessage(TreeModelNode.class, "WaitNode"));
1716
                n.setName(NbBundle.getMessage(TreeModelNode.class, "WaitNode"));
1676
                n.setIconBaseWithExtension("org/netbeans/modules/viewmodel/wait.gif");
1717
                n.setIconBaseWithExtension("org/netbeans/modules/viewmodel/wait.gif");
1677
                return new Node[] { n };
1718
                return new Node[]{n};
1678
            }
1719
            }
1679
            if (object instanceof Exception)
1720
            if (object instanceof Exception) {
1680
                return new Node[] {
1721
                return new Node[]{
1681
                    new ExceptionNode ((Exception) object)
1722
                    new ExceptionNode((Exception) object)
1682
                };
1723
                };
1683
            TreeModelNode tmn = new TreeModelNode (
1724
            }
1684
                model,
1725
            TreeModelNode tmn = new TreeModelNode(
1685
                columns,
1726
                    model,
1686
                treeModelRoot, 
1727
                    columns,
1687
                object
1728
                    treeModelRoot,
1729
                    object
1688
            );
1730
            );
1689
            //System.err.println("created node for ("+object+") = "+tmn);
1731
            //System.err.println("created node for ("+object+") = "+tmn);
1690
            synchronized (objectToNode) {
1732
            synchronized (objectToNode) {
1691
                objectToNode.put (object, new WeakReference<TreeModelNode>(tmn));
1733
                objectToNode.put(object, new WeakReference<TreeModelNode>(tmn));
1692
            }
1734
            }
1693
            return new Node[] {tmn};
1735
            return new Node[]{tmn};
1694
        }
1736
        }
1695
1737
1696
        @Override
1738
        @Override
Lines 1699-1705 Link Here
1699
            for (Node n : nodes) {
1741
            for (Node n : nodes) {
1700
                if (n instanceof TreeModelNode) {
1742
                if (n instanceof TreeModelNode) {
1701
                    TreeModelNode tmn = (TreeModelNode) n;
1743
                    TreeModelNode tmn = (TreeModelNode) n;
1702
                    treeModelRoot.unregisterNode (tmn.object, tmn);
1744
                    treeModelRoot.unregisterNode(tmn.object, tmn);
1703
                    if (tmn.areChildrenInitialized()) {
1745
                    if (tmn.areChildrenInitialized()) {
1704
                        Node[] childrenNodes;
1746
                        Node[] childrenNodes;
1705
                        try {
1747
                        try {
Lines 1771-1777 Link Here
1771
                fireChangeEvent(new ChangeEvent(this));
1813
                fireChangeEvent(new ChangeEvent(this));
1772
            } catch (UnknownTypeException ex) {
1814
            } catch (UnknownTypeException ex) {
1773
                if (!(object instanceof String)) {
1815
                if (!(object instanceof String)) {
1774
                    Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, ex);
1816
                    Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model, ex);
1775
                }
1817
                }
1776
            }
1818
            }
1777
        }
1819
        }
Lines 1791-1799 Link Here
1791
        private volatile boolean childrenCreated = false;
1833
        private volatile boolean childrenCreated = false;
1792
1834
1793
        LazyChildrenFactory(final Models.CompoundModel model,
1835
        LazyChildrenFactory(final Models.CompoundModel model,
1794
                            final ColumnModel[] columns,
1836
                final ColumnModel[] columns,
1795
                            final TreeModelRoot treeModelRoot,
1837
                final TreeModelRoot treeModelRoot,
1796
                            final Object object) {
1838
                final Object object) {
1797
            this.model = model;
1839
            this.model = model;
1798
            this.columns = columns;
1840
            this.columns = columns;
1799
            this.treeModelRoot = treeModelRoot;
1841
            this.treeModelRoot = treeModelRoot;
Lines 1809-1815 Link Here
1809
        boolean areChildrenCreated() {
1851
        boolean areChildrenCreated() {
1810
            return childrenCreated;
1852
            return childrenCreated;
1811
        }
1853
        }
1812
        
1854
1813
    }
1855
    }
1814
1856
1815
    // Adaptive property refresh time. Belongs to MyProperty, but can not be there since it's static :-(
1857
    // Adaptive property refresh time. Belongs to MyProperty, but can not be there since it's static :-(
Lines 1827-1877 Link Here
1827
    }
1869
    }
1828
1870
1829
    private class MyProperty extends PropertySupport implements Runnable { //LazyEvaluator.Evaluable {
1871
    private class MyProperty extends PropertySupport implements Runnable { //LazyEvaluator.Evaluable {
1830
        
1872
1831
        private final String      id;
1873
        private final String id;
1832
        private final String      propertyId;
1874
        private final String propertyId;
1833
        private final ColumnModel columnModel;
1875
        private final ColumnModel columnModel;
1834
        private final boolean nodeColumn;
1876
        private final boolean nodeColumn;
1835
        private TreeModelRoot treeModelRoot;
1877
        private TreeModelRoot treeModelRoot;
1836
        private final int[] evaluated = { 1 }; // 0 - not yet, 1 - evaluated, -1 - timeouted
1878
        private final int[] evaluated = {1}; // 0 - not yet, 1 - evaluated, -1 - timeouted
1837
        
1879
1838
        
1880
        MyProperty(
1839
        MyProperty (
1881
                ColumnModel columnModel, TreeModelRoot treeModelRoot
1840
            ColumnModel columnModel, TreeModelRoot treeModelRoot
1841
        ) {
1882
        ) {
1842
            super (
1883
            super(
1843
                columnModel.getID (),
1884
                    columnModel.getID(),
1844
                (columnModel.getType() == null) ? String.class : columnModel.getType (),
1885
                    (columnModel.getType() == null) ? String.class : columnModel.getType(),
1845
                Actions.cutAmpersand(columnModel.getDisplayName ()),
1886
                    Actions.cutAmpersand(columnModel.getDisplayName()),
1846
                columnModel.getShortDescription (), 
1887
                    columnModel.getShortDescription(),
1847
                true,
1888
                    true,
1848
                true
1889
                    true
1849
            );
1890
            );
1850
            this.nodeColumn = columnModel.getType() == null;
1891
            this.nodeColumn = columnModel.getType() == null;
1851
            this.treeModelRoot = treeModelRoot;
1892
            this.treeModelRoot = treeModelRoot;
1852
            if (columnModel instanceof HyperColumnModel) {
1893
            if (columnModel instanceof HyperColumnModel) {
1853
                propertyId = columnModel.getID(); // main column ID
1894
                propertyId = columnModel.getID(); // main column ID
1854
                this.columnModel = ((HyperColumnModel) columnModel).getSpecific();
1895
                this.columnModel = ((HyperColumnModel) columnModel).getSpecific();
1855
                id = this.columnModel.getID ();   // specific column ID
1896
                id = this.columnModel.getID();   // specific column ID
1856
            } else {
1897
            } else {
1857
                id = propertyId = columnModel.getID ();
1898
                id = propertyId = columnModel.getID();
1858
                this.columnModel = columnModel;
1899
                this.columnModel = columnModel;
1859
            }
1900
            }
1860
            //System.err.println("new MyProperty("+TreeModelNode.this+", "+id+") = "+this);
1901
            //System.err.println("new MyProperty("+TreeModelNode.this+", "+id+") = "+this);
1861
        }
1902
        }
1862
        
1903
1863
        // A hack - see org/netbeans/modules/debugger/jpda/ui/models/ValuePropertyEditor.java
1904
        // A hack - see org/netbeans/modules/debugger/jpda/ui/models/ValuePropertyEditor.java
1864
        boolean forcedReadOnly;
1905
        boolean forcedReadOnly;
1906
1865
        void forceNotEditable() {
1907
        void forceNotEditable() {
1866
            forcedReadOnly = true;
1908
            forcedReadOnly = true;
1867
        }
1909
        }
1868
1910
1869
        /* Can write the value of the property.
1911
        /* Can write the value of the property.
1870
        * Returns the value passed into constructor.
1912
         * Returns the value passed into constructor.
1871
        * @return <CODE>true</CODE> if the read of the value is supported
1913
         * @return <CODE>true</CODE> if the read of the value is supported
1872
        */
1914
         */
1873
        @Override
1915
        @Override
1874
        public boolean canWrite () {
1916
        public boolean canWrite() {
1875
            if (forcedReadOnly) {
1917
            if (forcedReadOnly) {
1876
                return false;
1918
                return false;
1877
            }
1919
            }
Lines 1892-1901 Link Here
1892
                    canEdit = false;
1934
                    canEdit = false;
1893
                } else {
1935
                } else {
1894
                    try {
1936
                    try {
1895
                        canEdit = !model.isReadOnly (object, columnModel.getID ());
1937
                        canEdit = !model.isReadOnly(object, columnModel.getID());
1896
                    } catch (UnknownTypeException e) {
1938
                    } catch (UnknownTypeException e) {
1897
                        if (!(object instanceof String)) {
1939
                        if (!(object instanceof String)) {
1898
                            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Column id:" + columnModel.getID ()+"\nModel: "+model, e);
1940
                            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Column id:" + columnModel.getID() + "\nModel: " + model, e);
1899
                        }
1941
                        }
1900
                        canEdit = false;
1942
                        canEdit = false;
1901
                    }
1943
                    }
Lines 1906-1919 Link Here
1906
            }
1948
            }
1907
            return canEdit;
1949
            return canEdit;
1908
        }
1950
        }
1909
        
1951
1910
        public void run() {
1952
        public void run() {
1911
            Object value = "";
1953
            Object value = "";
1912
            String htmlValue = null;
1954
            String htmlValue = null;
1913
            Object nonHtmlValue = null;
1955
            Object nonHtmlValue = null;
1914
            try {
1956
            try {
1915
                //System.err.println("getValueAt("+object+", "+id+") of node "+TreeModelNode.this);
1957
                //System.err.println("getValueAt("+object+", "+id+") of node "+TreeModelNode.this);
1916
                value = model.getValueAt (object, id);
1958
                value = model.getValueAt(object, id);
1917
                nonHtmlValue = value;
1959
                nonHtmlValue = value;
1918
                boolean hasHTML = model.hasHTMLValueAt(object, id);
1960
                boolean hasHTML = model.hasHTMLValueAt(object, id);
1919
                if (hasHTML) {
1961
                if (hasHTML) {
Lines 1923-1937 Link Here
1923
                //System.out.println("  evaluateLazily("+TreeModelNode.this.getDisplayName()+", "+id+"): have value = "+value);
1965
                //System.out.println("  evaluateLazily("+TreeModelNode.this.getDisplayName()+", "+id+"): have value = "+value);
1924
                //System.out.println("      object = "+object+" class = "+((object != null) ? object.getClass().toString() : "null"));
1966
                //System.out.println("      object = "+object+" class = "+((object != null) ? object.getClass().toString() : "null"));
1925
                if (!hasHTML && (value instanceof String)) { // For backward compatibility
1967
                if (!hasHTML && (value instanceof String)) { // For backward compatibility
1926
                    htmlValue = htmlValue ((String) value);
1968
                    htmlValue = htmlValue((String) value);
1927
                    nonHtmlValue = removeHTML ((String) value);
1969
                    nonHtmlValue = removeHTML((String) value);
1928
                }
1970
                }
1929
            } catch (UnknownTypeException e) {
1971
            } catch (UnknownTypeException e) {
1930
                if (!(object instanceof String)) {
1972
                if (!(object instanceof String)) {
1931
                    e.printStackTrace ();
1973
                    e.printStackTrace();
1932
                    System.out.println("  Column id:" + columnModel.getID ());
1974
                    System.out.println("  Column id:" + columnModel.getID());
1933
                    System.out.println (model);
1975
                    System.out.println(model);
1934
                    System.out.println ();
1976
                    System.out.println();
1935
                }
1977
                }
1936
            } catch (Throwable t) {
1978
            } catch (Throwable t) {
1937
                Exceptions.printStackTrace(t);
1979
                Exceptions.printStackTrace(t);
Lines 1939-1946 Link Here
1939
                //evaluatedNotify.run();
1981
                //evaluatedNotify.run();
1940
                boolean fire;
1982
                boolean fire;
1941
                synchronized (properties) {
1983
                synchronized (properties) {
1942
                    properties.put (id, nonHtmlValue);
1984
                    properties.put(id, nonHtmlValue);
1943
                    properties.put (id + "#html", htmlValue);
1985
                    properties.put(id + "#html", htmlValue);
1944
                    synchronized (evaluated) {
1986
                    synchronized (evaluated) {
1945
                        fire = evaluated[0] == -1;
1987
                        fire = evaluated[0] == -1;
1946
                        evaluated[0] = 1;
1988
                        evaluated[0] = 1;
Lines 1950-1962 Link Here
1950
                }
1992
                }
1951
                //System.out.println("\nTreeModelNode.evaluateLazily("+TreeModelNode.this.getDisplayName()+", "+id+"): value = "+value+", fire = "+fire);
1993
                //System.out.println("\nTreeModelNode.evaluateLazily("+TreeModelNode.this.getDisplayName()+", "+id+"): value = "+value+", fire = "+fire);
1952
                if (fire) {
1994
                if (fire) {
1953
                    firePropertyChange (propertyId, null, value);
1995
                    firePropertyChange(propertyId, null, value);
1954
                }
1996
                }
1955
                
1997
1956
            }
1998
            }
1957
        }
1999
        }
1958
        
2000
1959
        public synchronized Object getValue () { // Sync the calls
2001
        public synchronized Object getValue() { // Sync the calls
1960
            //System.err.println("TreeModelNode("+object+").getValue("+id+")...");
2002
            //System.err.println("TreeModelNode("+object+").getValue("+id+")...");
1961
            if (nodeColumn) {
2003
            if (nodeColumn) {
1962
                return TreeModelNode.this.getDisplayName();
2004
                return TreeModelNode.this.getDisplayName();
Lines 1964-1971 Link Here
1964
            // 1) return value from cache
2006
            // 1) return value from cache
1965
            synchronized (properties) {
2007
            synchronized (properties) {
1966
                //System.err.println("getValue("+TreeModelNode.this.getDisplayName()+", "+id+"): contains = "+properties.containsKey (id)+", value = "+properties.get (id)+" property object = "+this);
2008
                //System.err.println("getValue("+TreeModelNode.this.getDisplayName()+", "+id+"): contains = "+properties.containsKey (id)+", value = "+properties.get (id)+" property object = "+this);
1967
                if (properties.containsKey (id)) {
2009
                if (properties.containsKey(id)) {
1968
                    return properties.get (id);
2010
                    return properties.get(id);
1969
                }
2011
                }
1970
                synchronized (evaluated) {
2012
                synchronized (evaluated) {
1971
                    //System.err.println("  value of ("+TreeModelNode.this.getDisplayName()+", "+id+") is being evaluated = "+(evaluated[0] != 1)+", evaluated = "+evaluated[0]);
2013
                    //System.err.println("  value of ("+TreeModelNode.this.getDisplayName()+", "+id+") is being evaluated = "+(evaluated[0] != 1)+", evaluated = "+evaluated[0]);
Lines 1979-1985 Link Here
1979
                    }
2021
                    }
1980
                }
2022
                }
1981
            }
2023
            }
1982
            
2024
1983
            Executor exec = asynchronous(model, CALL.VALUE, object);
2025
            Executor exec = asynchronous(model, CALL.VALUE, object);
1984
2026
1985
            if (exec == AsynchronousModelFilter.CURRENT_THREAD) {
2027
            if (exec == AsynchronousModelFilter.CURRENT_THREAD) {
Lines 1991-2015 Link Here
1991
                //System.err.println("Evaluated of ("+TreeModelNode.this.getDisplayName()+", "+id+"): evaluated = "+evaluated[0]);
2033
                //System.err.println("Evaluated of ("+TreeModelNode.this.getDisplayName()+", "+id+"): evaluated = "+evaluated[0]);
1992
            }
2034
            }
1993
            /*if (exec instanceof RequestProcessor) {
2035
            /*if (exec instanceof RequestProcessor) {
1994
                RequestProcessor rp = (RequestProcessor) exec;
2036
             RequestProcessor rp = (RequestProcessor) exec;
1995
                if (rp != lastRp) {
2037
             if (rp != lastRp) {
1996
                    task = rp.create(this);
2038
             task = rp.create(this);
1997
                    lastRp = rp;
2039
             lastRp = rp;
1998
                }
2040
             }
1999
                task.schedule(0);
2041
             task.schedule(0);
2000
            } else {*/
2042
             } else {*/
2001
            //System.err.println("getTheValue of ("+object+", "+id+") executed in "+exec);
2043
            //System.err.println("getTheValue of ("+object+", "+id+") executed in "+exec);
2002
                exec.execute(this);
2044
            exec.execute(this);
2003
            //}
2045
            //}
2004
            //treeModelRoot.getValuesEvaluator().evaluate(this);
2046
            //treeModelRoot.getValuesEvaluator().evaluate(this);
2005
            
2047
2006
            Object ret = null;
2048
            Object ret = null;
2007
            
2049
2008
            synchronized (evaluated) {
2050
            synchronized (evaluated) {
2009
                if (evaluated[0] != 1) {
2051
                if (evaluated[0] != 1) {
2010
                    try {
2052
                    try {
2011
                        evaluated.wait(getPropertyRefreshWaitTime());
2053
                        evaluated.wait(getPropertyRefreshWaitTime());
2012
                    } catch (InterruptedException iex) {}
2054
                    } catch (InterruptedException iex) {
2055
                    }
2013
                    if (evaluated[0] != 1) {
2056
                    if (evaluated[0] != 1) {
2014
                        evaluated[0] = -1; // timeout
2057
                        evaluated[0] = -1; // timeout
2015
                        //System.err.println("Timeout of ("+TreeModelNode.this.getDisplayName()+", "+id+"): evaluated = "+evaluated[0]);
2058
                        //System.err.println("Timeout of ("+TreeModelNode.this.getDisplayName()+", "+id+"): evaluated = "+evaluated[0]);
Lines 2022-2032 Link Here
2022
                    ret = properties.get(id);
2065
                    ret = properties.get(id);
2023
                }
2066
                }
2024
            }
2067
            }
2025
            
2068
2026
            if (ret == EVALUATING_STR &&
2069
            if (ret == EVALUATING_STR
2027
                    getValueType() != null && getValueType() != String.class) {
2070
                    && getValueType() != null && getValueType() != String.class) {
2028
                ret = null; // Must not provide String when the property type is different.
2071
                ret = null; // Must not provide String when the property type is different.
2029
                            // htmlDisplayValue attr will assure that the Evaluating str is there.
2072
                // htmlDisplayValue attr will assure that the Evaluating str is there.
2030
            }
2073
            }
2031
            return ret;
2074
            return ret;
2032
        }
2075
        }
Lines 2036-2042 Link Here
2036
            String htmlValue = null;
2079
            String htmlValue = null;
2037
            Object nonHtmlValue = null;
2080
            Object nonHtmlValue = null;
2038
            try {
2081
            try {
2039
                value = model.getValueAt (object, id);
2082
                value = model.getValueAt(object, id);
2040
                nonHtmlValue = value;
2083
                nonHtmlValue = value;
2041
                boolean hasHTML = model.hasHTMLValueAt(object, id);
2084
                boolean hasHTML = model.hasHTMLValueAt(object, id);
2042
                if (hasHTML) {
2085
                if (hasHTML) {
Lines 2046-2080 Link Here
2046
                //System.out.println("  evaluateLazily("+TreeModelNode.this.getDisplayName()+", "+id+"): have value = "+value);
2089
                //System.out.println("  evaluateLazily("+TreeModelNode.this.getDisplayName()+", "+id+"): have value = "+value);
2047
                //System.out.println("      object = "+object+" class = "+((object != null) ? object.getClass().toString() : "null"));
2090
                //System.out.println("      object = "+object+" class = "+((object != null) ? object.getClass().toString() : "null"));
2048
                if (!hasHTML && (value instanceof String)) { // For backward compatibility
2091
                if (!hasHTML && (value instanceof String)) { // For backward compatibility
2049
                    htmlValue = htmlValue ((String) value);
2092
                    htmlValue = htmlValue((String) value);
2050
                    nonHtmlValue = removeHTML ((String) value);
2093
                    nonHtmlValue = removeHTML((String) value);
2051
                }
2094
                }
2052
            } catch (UnknownTypeException e) {
2095
            } catch (UnknownTypeException e) {
2053
                if (!(object instanceof String)) {
2096
                if (!(object instanceof String)) {
2054
                    Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model+"\n,Column id:" + columnModel.getID (), e);
2097
                    Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: " + model + "\n,Column id:" + columnModel.getID(), e);
2055
                }
2098
                }
2056
            } finally {
2099
            } finally {
2057
                synchronized (properties) {
2100
                synchronized (properties) {
2058
                    properties.put (id, nonHtmlValue);
2101
                    properties.put(id, nonHtmlValue);
2059
                    properties.put (id + "#html", htmlValue);
2102
                    properties.put(id + "#html", htmlValue);
2060
                }
2103
                }
2061
            }
2104
            }
2062
            return value;
2105
            return value;
2063
        }
2106
        }
2064
        
2107
2065
        @Override
2108
        @Override
2066
        public Object getValue (String attributeName) {
2109
        public Object getValue(String attributeName) {
2067
            if (attributeName.equals ("htmlDisplayValue")) {
2110
            if (attributeName.equals("htmlDisplayValue")) {
2068
                if (nodeColumn) {
2111
                if (nodeColumn) {
2069
                    return TreeModelNode.this.getHtmlDisplayName();
2112
                    return TreeModelNode.this.getHtmlDisplayName();
2070
                }
2113
                }
2071
                synchronized (evaluated) {
2114
                synchronized (evaluated) {
2072
                    if (evaluated[0] != 1) {
2115
                    if (evaluated[0] != 1) {
2073
                        return HTML_START_TAG+"<font color=\"0000CC\">"+EVALUATING_STR+"</font>"+HTML_END_TAG;
2116
                        return HTML_START_TAG + "<font color=\"0000CC\">" + EVALUATING_STR + "</font>" + HTML_END_TAG;
2074
                    }
2117
                    }
2075
                }
2118
                }
2076
                synchronized (properties) {
2119
                synchronized (properties) {
2077
                    return properties.get (id + "#html");
2120
                    return properties.get(id + "#html");
2078
                }
2121
                }
2079
            }
2122
            }
2080
            if (attributeName.equals("suppressCustomEditor")) {
2123
            if (attributeName.equals("suppressCustomEditor")) {
Lines 2086-2092 Link Here
2086
                } catch (UnknownTypeException ex) {
2129
                } catch (UnknownTypeException ex) {
2087
                }
2130
                }
2088
            }
2131
            }
2089
            return super.getValue (attributeName);
2132
            return super.getValue(attributeName);
2090
        }
2133
        }
2091
2134
2092
        @Override
2135
        @Override
Lines 2098-2110 Link Here
2098
                if (!properties.containsKey(id)) {
2141
                if (!properties.containsKey(id)) {
2099
                    return null; // The same as value => EVALUATING_STR
2142
                    return null; // The same as value => EVALUATING_STR
2100
                }
2143
                }
2101
                String shortDescription = (String) properties.get (id + "#shortDescription");
2144
                String shortDescription = (String) properties.get(id + "#shortDescription");
2102
                if (shortDescription != null) {
2145
                if (shortDescription != null) {
2103
                    return shortDescription;
2146
                    return shortDescription;
2104
                }
2147
                }
2105
            }
2148
            }
2106
            Executor exec = asynchronous(model, CALL.SHORT_DESCRIPTION, object);
2149
            Executor exec = asynchronous(model, CALL.SHORT_DESCRIPTION, object);
2107
            
2150
2108
            if (exec == AsynchronousModelFilter.CURRENT_THREAD) {
2151
            if (exec == AsynchronousModelFilter.CURRENT_THREAD) {
2109
                return updateShortDescription();
2152
                return updateShortDescription();
2110
            } else {
2153
            } else {
Lines 2124-2130 Link Here
2124
                String sd = null;
2167
                String sd = null;
2125
                try {
2168
                try {
2126
                    tooltip.putClientProperty("getShortDescription", object); // NOI18N
2169
                    tooltip.putClientProperty("getShortDescription", object); // NOI18N
2127
                    Object tooltipObj = model.getValueAt(tooltip, id);
2170
                    Object tooltipObj = model.getValueAt(object, id);
2128
                    if (tooltipObj != null) {
2171
                    if (tooltipObj != null) {
2129
                        sd = adjustHTML(tooltipObj.toString());
2172
                        sd = adjustHTML(tooltipObj.toString());
2130
                    }
2173
                    }
Lines 2133-2139 Link Here
2133
                    // We MUST clear the client property, Swing holds this in a static reference!
2176
                    // We MUST clear the client property, Swing holds this in a static reference!
2134
                    tooltip.putClientProperty("getShortDescription", null); // NOI18N
2177
                    tooltip.putClientProperty("getShortDescription", null); // NOI18N
2135
                    synchronized (properties) {
2178
                    synchronized (properties) {
2136
                        properties.put (id + "#shortDescription", sd);
2179
                        properties.put(id + "#shortDescription", sd);
2137
                    }
2180
                    }
2138
                }
2181
                }
2139
            } catch (UnknownTypeException e) {
2182
            } catch (UnknownTypeException e) {
Lines 2141-2149 Link Here
2141
                return null;
2184
                return null;
2142
            }
2185
            }
2143
        }
2186
        }
2144
        
2187
2145
        public void setValue (final Object value) throws IllegalAccessException,
2188
        public void setValue(final Object value) throws IllegalAccessException,
2146
        IllegalArgumentException, java.lang.reflect.InvocationTargetException {
2189
                IllegalArgumentException, java.lang.reflect.InvocationTargetException {
2147
            Executor exec = asynchronous(model, CALL.VALUE, object);
2190
            Executor exec = asynchronous(model, CALL.VALUE, object);
2148
            if (exec == AsynchronousModelFilter.CURRENT_THREAD) {
2191
            if (exec == AsynchronousModelFilter.CURRENT_THREAD) {
2149
                try {
2192
                try {
Lines 2165-2171 Link Here
2165
        private void setTheValue(final Object value) {
2208
        private void setTheValue(final Object value) {
2166
            try {
2209
            try {
2167
                Object v = value;
2210
                Object v = value;
2168
                model.setValueAt (object, id, v);
2211
                model.setValueAt(object, id, v);
2169
                v = model.getValueAt(object, id); // Store the new value
2212
                v = model.getValueAt(object, id); // Store the new value
2170
                String htmlValue = null;
2213
                String htmlValue = null;
2171
                Object nonHtmlValue = v;
2214
                Object nonHtmlValue = v;
Lines 2174-2202 Link Here
2174
                    htmlValue = model.getHTMLValueAt(object, id);
2217
                    htmlValue = model.getHTMLValueAt(object, id);
2175
                }
2218
                }
2176
                if (!hasHTML && (v instanceof String)) { // For backward compatibility
2219
                if (!hasHTML && (v instanceof String)) { // For backward compatibility
2177
                    htmlValue = htmlValue ((String) v);
2220
                    htmlValue = htmlValue((String) v);
2178
                    nonHtmlValue = removeHTML ((String) v);
2221
                    nonHtmlValue = removeHTML((String) v);
2179
                }
2222
                }
2180
                synchronized (properties) {
2223
                synchronized (properties) {
2181
                    properties.put (id, nonHtmlValue);
2224
                    properties.put(id, nonHtmlValue);
2182
                    properties.put (id + "#html", htmlValue);
2225
                    properties.put(id + "#html", htmlValue);
2183
                }
2226
                }
2184
                firePropertyChange (propertyId, null, null);
2227
                firePropertyChange(propertyId, null, null);
2185
            } catch (UnknownTypeException e) {
2228
            } catch (UnknownTypeException e) {
2186
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Column id:" + columnModel.getID ()+"\nModel: "+model, e);
2229
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Column id:" + columnModel.getID() + "\nModel: " + model, e);
2187
            }
2230
            }
2188
        }
2231
        }
2189
        
2232
2190
        @Override
2233
        @Override
2191
        public PropertyEditor getPropertyEditor () {
2234
        public PropertyEditor getPropertyEditor() {
2192
            PropertyEditor pe = null;
2235
            PropertyEditor pe = null;
2193
            try {
2236
            try {
2194
                pe = model.getPropertyEditor(object, id);
2237
                pe = model.getPropertyEditor(object, id);
2195
            } catch (UnknownTypeException ex) {
2238
            } catch (UnknownTypeException ex) {
2196
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Column id:" + columnModel.getID ()+"\nModel: "+model, ex);
2239
                Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Column id:" + columnModel.getID() + "\nModel: " + model, ex);
2197
            }
2240
            }
2198
            if (pe == null) {
2241
            if (pe == null) {
2199
                pe = columnModel.getPropertyEditor ();
2242
                pe = columnModel.getPropertyEditor();
2200
            }
2243
            }
2201
            if (pe != null) {
2244
            if (pe != null) {
2202
                return pe;
2245
                return pe;
Lines 2207-2287 Link Here
2207
2250
2208
        @Override
2251
        @Override
2209
        public String toString() {
2252
        public String toString() {
2210
            return super.toString() + ", Value = "+properties.get(id);
2253
            return super.toString() + ", Value = " + properties.get(id);
2211
        }
2254
        }
2212
        
2213
    }
2214
2255
2215
    /** The single-threaded evaluator of lazy models. *//*
2256
    }
2216
    static class LazyEvaluator implements Runnable {
2217
        
2218
        /** Release the evaluator task after this time. *//*
2219
        private static final long EXPIRE_TIME = 1000L;
2220
2221
        private final List<Object> objectsToEvaluate = new LinkedList<Object>();
2222
        private Evaluable currentlyEvaluating;
2223
        private Task evalTask;
2224
        
2225
        public LazyEvaluator(RequestProcessor prefferedRequestProcessor) {
2226
            if (prefferedRequestProcessor == null) {
2227
                prefferedRequestProcessor = new RequestProcessor("Debugger Values Evaluator", 1); // NOI18N
2228
            }
2229
            evalTask = prefferedRequestProcessor.create(this, true);
2230
        }
2231
        
2232
        public void evaluate(Evaluable eval) {
2233
            evaluate(eval, true);
2234
        }
2235
        
2236
        public void evaluate(Evaluable eval, boolean checkForEvaluating) {
2237
            synchronized (objectsToEvaluate) {
2238
                for (Iterator it = objectsToEvaluate.iterator(); it.hasNext(); ) {
2239
                    if (eval == it.next()) return ; // Already scheduled
2240
                }
2241
                if (checkForEvaluating && currentlyEvaluating == eval) return ; // Is being evaluated
2242
                objectsToEvaluate.add(eval);
2243
                objectsToEvaluate.notify();
2244
                if (evalTask.isFinished()) {
2245
                    evalTask.schedule(0);
2246
                }
2247
            }
2248
        }
2249
2257
2250
        public void run() {
2258
    /**
2251
            while(true) {
2259
     * The single-threaded evaluator of lazy models.
2252
                Evaluable eval;
2260
     *//*
2253
                synchronized (objectsToEvaluate) {
2261
     static class LazyEvaluator implements Runnable {
2254
                    if (objectsToEvaluate.size() == 0) {
2262
2255
                        try {
2263
     /** Release the evaluator task after this time. *//*
2256
                            objectsToEvaluate.wait(EXPIRE_TIME);
2264
     private static final long EXPIRE_TIME = 1000L;
2257
                        } catch (InterruptedException iex) {
2265
2258
                            return ;
2266
     private final List<Object> objectsToEvaluate = new LinkedList<Object>();
2259
                        }
2267
     private Evaluable currentlyEvaluating;
2260
                        if (objectsToEvaluate.size() == 0) { // Expired
2268
     private Task evalTask;
2261
                            return ;
2269
2262
                        }
2270
     public LazyEvaluator(RequestProcessor prefferedRequestProcessor) {
2263
                    }
2271
     if (prefferedRequestProcessor == null) {
2264
                    eval = (Evaluable) objectsToEvaluate.remove(0);
2272
     prefferedRequestProcessor = new RequestProcessor("Debugger Values Evaluator", 1); // NOI18N
2265
                    currentlyEvaluating = eval;
2273
     }
2266
                }
2274
     evalTask = prefferedRequestProcessor.create(this, true);
2267
                Runnable evaluatedNotify = new Runnable() {
2275
     }
2268
                    public void run() {
2276
2269
                        synchronized (objectsToEvaluate) {
2277
     public void evaluate(Evaluable eval) {
2270
                            currentlyEvaluating = null;
2278
     evaluate(eval, true);
2271
                        }
2279
     }
2272
                    }
2280
2273
                };
2281
     public void evaluate(Evaluable eval, boolean checkForEvaluating) {
2274
                eval.evaluateLazily(evaluatedNotify);
2282
     synchronized (objectsToEvaluate) {
2275
            }
2283
     for (Iterator it = objectsToEvaluate.iterator(); it.hasNext(); ) {
2276
        }
2284
     if (eval == it.next()) return ; // Already scheduled
2285
     }
2286
     if (checkForEvaluating && currentlyEvaluating == eval) return ; // Is being evaluated
2287
     objectsToEvaluate.add(eval);
2288
     objectsToEvaluate.notify();
2289
     if (evalTask.isFinished()) {
2290
     evalTask.schedule(0);
2291
     }
2292
     }
2293
     }
2294
2295
     public void run() {
2296
     while(true) {
2297
     Evaluable eval;
2298
     synchronized (objectsToEvaluate) {
2299
     if (objectsToEvaluate.size() == 0) {
2300
     try {
2301
     objectsToEvaluate.wait(EXPIRE_TIME);
2302
     } catch (InterruptedException iex) {
2303
     return ;
2304
     }
2305
     if (objectsToEvaluate.size() == 0) { // Expired
2306
     return ;
2307
     }
2308
     }
2309
     eval = (Evaluable) objectsToEvaluate.remove(0);
2310
     currentlyEvaluating = eval;
2311
     }
2312
     Runnable evaluatedNotify = new Runnable() {
2313
     public void run() {
2314
     synchronized (objectsToEvaluate) {
2315
     currentlyEvaluating = null;
2316
     }
2317
     }
2318
     };
2319
     eval.evaluateLazily(evaluatedNotify);
2320
     }
2321
     }
2277
2322
2278
        public interface Evaluable {
2323
     public interface Evaluable {
2279
2324
2280
            public void evaluateLazily(Runnable evaluatedNotify);
2325
     public void evaluateLazily(Runnable evaluatedNotify);
2281
2326
2282
        }
2327
     }
2283
2328
2284
    }*/
2329
     }*/
2285
2330
2286
}
2331
}
2287
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/modules/viewmodel/TreeModelRoot.java (-100 / +129 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.viewmodel;
44
package org.netbeans.modules.viewmodel;
46
45
47
import java.beans.PropertyVetoException;
46
import java.beans.PropertyVetoException;
Lines 50-55 Link Here
50
import java.text.MessageFormat;
49
import java.text.MessageFormat;
51
import java.util.ArrayList;
50
import java.util.ArrayList;
52
import java.util.Arrays;
51
import java.util.Arrays;
52
import java.util.Collection;
53
import java.util.List;
53
import java.util.List;
54
import java.util.WeakHashMap;
54
import java.util.WeakHashMap;
55
import java.util.logging.Level;
55
import java.util.logging.Level;
Lines 58-64 Link Here
58
import javax.swing.SwingUtilities;
58
import javax.swing.SwingUtilities;
59
import javax.swing.event.TreeExpansionEvent;
59
import javax.swing.event.TreeExpansionEvent;
60
import javax.swing.event.TreeExpansionListener;
60
import javax.swing.event.TreeExpansionListener;
61
62
import org.netbeans.spi.viewmodel.ModelEvent;
61
import org.netbeans.spi.viewmodel.ModelEvent;
63
import org.netbeans.spi.viewmodel.Models;
62
import org.netbeans.spi.viewmodel.Models;
64
import org.netbeans.spi.viewmodel.Models.TreeFeatures;
63
import org.netbeans.spi.viewmodel.Models.TreeFeatures;
Lines 70-88 Link Here
70
import org.openide.nodes.Node;
69
import org.openide.nodes.Node;
71
import org.openide.util.Exceptions;
70
import org.openide.util.Exceptions;
72
71
73
74
/**
72
/**
75
 * Implements root node of hierarchy created for given TreeModel.
73
 * Implements root node of hierarchy created for given TreeModel.
76
 *
74
 *
77
 * @author   Jan Jancura
75
 * @author Jan Jancura
78
 */
76
 */
79
public class TreeModelRoot {
77
public class TreeModelRoot {
80
    /** generated Serialized Version UID */
81
    static final long                 serialVersionUID = -1259352660663524178L;
82
    
83
    
84
    // variables ...............................................................
85
78
79
    /**
80
     * generated Serialized Version UID
81
     */
82
    static final long serialVersionUID = -1259352660663524178L;
83
84
    // variables ...............................................................
86
    private Models.CompoundModel model;
85
    private Models.CompoundModel model;
87
    private HyperCompoundModel hyperModel;
86
    private HyperCompoundModel hyperModel;
88
    private final ModelChangeListener[] modelListeners;
87
    private final ModelChangeListener[] modelListeners;
Lines 93-116 Link Here
93
    private ExplorerManager manager;
92
    private ExplorerManager manager;
94
    private OutlineView outlineView;
93
    private OutlineView outlineView;
95
    private MessageFormat treeNodeDisplayFormat;
94
    private MessageFormat treeNodeDisplayFormat;
96
    
97
    /** The children evaluator for view of this root. *
98
    private final Map<RequestProcessor, TreeModelNode.LazyEvaluator> childrenEvaluators
99
            = new WeakHashMap<RequestProcessor, TreeModelNode.LazyEvaluator>();
100
    /** The values evaluator for view of this root. *
101
    private final Map<RequestProcessor, TreeModelNode.LazyEvaluator> valuesEvaluators
102
            = new WeakHashMap<RequestProcessor, TreeModelNode.LazyEvaluator>();
103
     */
104
95
105
    public TreeModelRoot (Models.CompoundModel model, TreeView treeView) {
96
    /**
97
     * The children evaluator for view of this root. * private final
98
     * Map<RequestProcessor, TreeModelNode.LazyEvaluator> childrenEvaluators =
99
     * new WeakHashMap<RequestProcessor, TreeModelNode.LazyEvaluator>(); /** The
100
     * values evaluator for view of this root. * private final
101
     * Map<RequestProcessor, TreeModelNode.LazyEvaluator> valuesEvaluators = new
102
     * WeakHashMap<RequestProcessor, TreeModelNode.LazyEvaluator>();
103
     */
104
    public TreeModelRoot(Models.CompoundModel model, TreeView treeView) {
106
        this.model = model;
105
        this.model = model;
107
        this.manager = ExplorerManager.find(treeView);
106
        this.manager = ExplorerManager.find(treeView);
108
        this.treeFeatures = new DefaultTreeFeatures(treeView);
107
        this.treeFeatures = new DefaultTreeFeatures(treeView);
109
        modelListeners = new ModelChangeListener[] { new ModelChangeListener(model) };
108
        modelListeners = new ModelChangeListener[]{new ModelChangeListener(model)};
110
        model.addModelListener (modelListeners[0]);
109
        model.addModelListener(modelListeners[0]);
111
    }
110
    }
112
111
113
    public TreeModelRoot (HyperCompoundModel model, TreeView treeView) {
112
    public TreeModelRoot(HyperCompoundModel model, TreeView treeView) {
114
        this.hyperModel = model;
113
        this.hyperModel = model;
115
        this.model = model.getMain();
114
        this.model = model.getMain();
116
        this.manager = ExplorerManager.find(treeView);
115
        this.manager = ExplorerManager.find(treeView);
Lines 124-139 Link Here
124
        }
123
        }
125
    }
124
    }
126
125
127
    public TreeModelRoot (Models.CompoundModel model, OutlineView outlineView) {
126
    public TreeModelRoot(Models.CompoundModel model, OutlineView outlineView) {
128
        this.model = model;
127
        this.model = model;
129
        this.manager = ExplorerManager.find(outlineView);
128
        this.manager = ExplorerManager.find(outlineView);
130
        this.treeFeatures = new DefaultTreeFeatures(outlineView);
129
        this.treeFeatures = new DefaultTreeFeatures(outlineView);
131
        this.outlineView = outlineView;
130
        this.outlineView = outlineView;
132
        modelListeners = new ModelChangeListener[] { new ModelChangeListener(model) };
131
        modelListeners = new ModelChangeListener[]{new ModelChangeListener(model)};
133
        model.addModelListener (modelListeners[0]);
132
        model.addModelListener(modelListeners[0]);
134
    }
133
    }
135
134
136
    public TreeModelRoot (HyperCompoundModel model, OutlineView outlineView) {
135
    public TreeModelRoot(HyperCompoundModel model, OutlineView outlineView) {
137
        this.hyperModel = model;
136
        this.hyperModel = model;
138
        this.model = model.getMain();
137
        this.model = model.getMain();
139
        this.manager = ExplorerManager.find(outlineView);
138
        this.manager = ExplorerManager.find(outlineView);
Lines 148-154 Link Here
148
        }
147
        }
149
    }
148
    }
150
149
151
    public TreeFeatures getTreeFeatures () {
150
    public TreeFeatures getTreeFeatures() {
152
        return treeFeatures;
151
        return treeFeatures;
153
    }
152
    }
154
153
Lines 156-201 Link Here
156
        return outlineView;
155
        return outlineView;
157
    }
156
    }
158
157
159
    public TreeModelNode getRootNode () {
158
    public TreeModelNode getRootNode() {
160
        synchronized (rootNodeLock) {
159
        synchronized (rootNodeLock) {
161
            TreeModelNode rn = rootNode;
160
            TreeModelNode rn = rootNode;
162
            if (rn == null) {
161
            if (rn == null) {
163
                if (hyperModel != null) {
162
                if (hyperModel != null) {
164
                    rn = new TreeModelHyperNode (hyperModel, this, model.getRoot ());
163
                    rn = new TreeModelHyperNode(hyperModel, this, model.getRoot());
165
                } else {
164
                } else {
166
                    rn = new TreeModelNode (model, this, model.getRoot ());
165
                    rn = new TreeModelNode(model, this, model.getRoot());
167
                }
166
                }
168
                rootNode = rn;
167
                rootNode = rn;
169
            }
168
            }
170
            return rn;
169
            return rn;
171
        }
170
        }
172
    }
171
    }
173
    
172
174
    void registerNode (Object o, TreeModelNode n) {
173
    void registerNode(Object o, TreeModelNode n) {
175
        synchronized (objectToNode) {
174
        synchronized (objectToNode) {
176
            WeakReference<TreeModelNode>[] wrs = objectToNode.get(o);
175
            WeakReference<TreeModelNode>[] wrs = objectToNode.get(o);
177
            if (wrs == null) {
176
            if (wrs == null) {
178
                objectToNode.put (o, new WeakReference[] { new WeakReference<TreeModelNode>(n) });
177
                objectToNode.put(o, new WeakReference[]{new WeakReference<TreeModelNode>(n)});
179
            } else {
178
            } else {
180
                for (int i = 0; i < wrs.length; i++) {
179
                for (int i = 0; i < wrs.length; i++) {
181
                    WeakReference<TreeModelNode> wr = wrs[i];
180
                    WeakReference<TreeModelNode> wr = wrs[i];
182
                    TreeModelNode tn = wr.get();
181
                    TreeModelNode tn = wr.get();
183
                    if (tn == n) {
182
                    if (tn == n) {
184
                        return ;
183
                        return;
185
                    } else if (tn == null) {
184
                    } else if (tn == null) {
186
                        wrs[i] = new WeakReference<TreeModelNode>(n);
185
                        wrs[i] = new WeakReference<TreeModelNode>(n);
187
                        return ;
186
                        return;
188
                    }
187
                    }
189
                }
188
                }
190
                WeakReference<TreeModelNode>[] wrs2 = new WeakReference[wrs.length + 1];
189
                WeakReference<TreeModelNode>[] wrs2 = new WeakReference[wrs.length + 1];
191
                System.arraycopy(wrs, 0, wrs2, 0, wrs.length);
190
                System.arraycopy(wrs, 0, wrs2, 0, wrs.length);
192
                wrs2[wrs.length] = new WeakReference<TreeModelNode>(n);
191
                wrs2[wrs.length] = new WeakReference<TreeModelNode>(n);
193
                objectToNode.put (o, wrs2);
192
                objectToNode.put(o, wrs2);
194
            }
193
            }
195
        }
194
        }
196
    }
195
    }
197
    
196
198
    void unregisterNode (Object o, TreeModelNode n) {
197
    void unregisterNode(Object o, TreeModelNode n) {
199
        synchronized (objectToNode) {
198
        synchronized (objectToNode) {
200
            WeakReference<TreeModelNode>[] wrs = objectToNode.get(o);
199
            WeakReference<TreeModelNode>[] wrs = objectToNode.get(o);
201
            if (wrs != null) {
200
            if (wrs != null) {
Lines 206-244 Link Here
206
                        if (wrs.length == 1) { // The only item
205
                        if (wrs.length == 1) { // The only item
207
                            objectToNode.remove(o);
206
                            objectToNode.remove(o);
208
                        } else if (wrs.length == 2) { // Leave only the other item
207
                        } else if (wrs.length == 2) { // Leave only the other item
209
                            wrs = new WeakReference[] { wrs[(i + 1) % 2] };
208
                            wrs = new WeakReference[]{wrs[(i + 1) % 2]};
210
                            objectToNode.put (o, wrs);
209
                            objectToNode.put(o, wrs);
211
                        } else {    // Leave only the other items
210
                        } else {    // Leave only the other items
212
                            WeakReference[] nwrs = new WeakReference[wrs.length - 1];
211
                            WeakReference[] nwrs = new WeakReference[wrs.length - 1];
213
                            if (i > 0) {
212
                            if (i > 0) {
214
                                System.arraycopy(wrs, 0, nwrs, 0, i);
213
                                System.arraycopy(wrs, 0, nwrs, 0, i);
215
                            }
214
                            }
216
                            if (i < (wrs.length - 1)) {
215
                            if (i < (wrs.length - 1)) {
217
                                System.arraycopy(wrs, i+1, nwrs, i, wrs.length - i - 1);
216
                                System.arraycopy(wrs, i + 1, nwrs, i, wrs.length - i - 1);
218
                            }
217
                            }
219
                            objectToNode.put (o, nwrs);
218
                            objectToNode.put(o, nwrs);
220
                        }
219
                        }
221
                        return ;
220
                        return;
222
                    }
221
                    }
223
                }
222
                }
224
            }
223
            }
225
        }
224
        }
226
    }
225
    }
227
226
228
    TreeModelNode[] findNode (Object o) {
227
    TreeModelNode[] findNode(Object o) {
229
        WeakReference<TreeModelNode>[] wrs;
228
        WeakReference<TreeModelNode>[] wrs;
230
        synchronized (objectToNode) {
229
        synchronized (objectToNode) {
231
            wrs = objectToNode.get (o);
230
            wrs = objectToNode.get(o);
232
        }
231
        }
233
        TreeModelNode[] tns = null;
232
        TreeModelNode[] tns = null;
234
        if (wrs != null) {
233
        if (wrs != null) {
235
            for (int i = 0; i < wrs.length; i++) {
234
            for (int i = 0; i < wrs.length; i++) {
236
                // Suppose that it's unlikely that wrs.length > 1
235
                // Suppose that it's unlikely that wrs.length > 1
237
                WeakReference<TreeModelNode> wr = wrs[i];
236
                WeakReference<TreeModelNode> wr = wrs[i];
238
                TreeModelNode tn = wr.get ();
237
                TreeModelNode tn = wr.get();
239
                if (tn == null) continue;
238
                if (tn == null) {
239
                    continue;
240
                }
240
                if (tns == null) {
241
                if (tns == null) {
241
                    tns = new TreeModelNode[] { tn };
242
                    tns = new TreeModelNode[]{tn};
242
                } else {
243
                } else {
243
                    TreeModelNode[] ntns = new TreeModelNode[tns.length + 1];
244
                    TreeModelNode[] ntns = new TreeModelNode[tns.length + 1];
244
                    System.arraycopy(tns, 0, ntns, 0, tns.length);
245
                    System.arraycopy(tns, 0, ntns, 0, tns.length);
Lines 253-259 Link Here
253
            return tns;
254
            return tns;
254
        }
255
        }
255
    }
256
    }
256
    
257
257
//    public void treeNodeChanged (Object parent) {
258
//    public void treeNodeChanged (Object parent) {
258
//        final TreeModelNode tmn = findNode (parent);
259
//        final TreeModelNode tmn = findNode (parent);
259
//        if (tmn == null) return;
260
//        if (tmn == null) return;
Lines 283-290 Link Here
283
        return valuesEvaluator;
284
        return valuesEvaluator;
284
    }
285
    }
285
     */
286
     */
286
287
    public void destroy() {
287
    public void destroy () {
288
        boolean doRemoveModelListeners = false;
288
        boolean doRemoveModelListeners = false;
289
        DefaultTreeFeatures tf = null;
289
        DefaultTreeFeatures tf = null;
290
        synchronized (this) {
290
        synchronized (this) {
Lines 305-311 Link Here
305
            for (ModelChangeListener mchl : modelListeners) {
305
            for (ModelChangeListener mchl : modelListeners) {
306
                Models.CompoundModel cm = mchl.getModel();
306
                Models.CompoundModel cm = mchl.getModel();
307
                if (cm != null) {
307
                if (cm != null) {
308
                    cm.removeModelListener (mchl);
308
                    cm.removeModelListener(mchl);
309
                }
309
                }
310
            }
310
            }
311
        }
311
        }
Lines 321-327 Link Here
321
    void setTreeNodeDisplayFormat(MessageFormat treeNodeDisplayFormat) {
321
    void setTreeNodeDisplayFormat(MessageFormat treeNodeDisplayFormat) {
322
        this.treeNodeDisplayFormat = treeNodeDisplayFormat;
322
        this.treeNodeDisplayFormat = treeNodeDisplayFormat;
323
    }
323
    }
324
    
324
325
    MessageFormat getTreeNodeDisplayFormat() {
325
    MessageFormat getTreeNodeDisplayFormat() {
326
        return treeNodeDisplayFormat;
326
        return treeNodeDisplayFormat;
327
    }
327
    }
Lines 329-355 Link Here
329
    private final class ModelChangeListener implements ModelRootChangeListener {
329
    private final class ModelChangeListener implements ModelRootChangeListener {
330
330
331
        //private final Logger logger = Logger.getLogger(ModelChangeListener.class.getName());
331
        //private final Logger logger = Logger.getLogger(ModelChangeListener.class.getName());
332
333
        private final Reference<Models.CompoundModel> modelRef;
332
        private final Reference<Models.CompoundModel> modelRef;
334
333
335
        public ModelChangeListener(Models.CompoundModel model) {
334
        public ModelChangeListener(Models.CompoundModel model) {
336
            this.modelRef = new WeakReference<Models.CompoundModel>(model);
335
            this.modelRef = new WeakReference<Models.CompoundModel>(model);
337
        }
336
        }
338
        
337
339
        Models.CompoundModel getModel() {
338
        Models.CompoundModel getModel() {
340
            return modelRef.get();
339
            return modelRef.get();
341
        }
340
        }
342
341
343
        public void modelChanged (final ModelEvent event) {
342
        public void modelChanged(final ModelEvent event) {
344
            //System.err.println("TreeModelRoot.modelChanged("+event.getClass()+") from "+model);
343
            //System.err.println("TreeModelRoot.modelChanged("+event.getClass()+") from "+model);
345
            //Thread.dumpStack();
344
            //Thread.dumpStack();
346
            //logger.fine("TreeModelRoot.modelChanged("+event+")");
345
            //logger.fine("TreeModelRoot.modelChanged("+event+")");
347
            //logger.log(Level.FINE, "Called from ", new IllegalStateException("TEST_MODEL_CHANGED"));
346
            //logger.log(Level.FINE, "Called from ", new IllegalStateException("TEST_MODEL_CHANGED"));
348
            SwingUtilities.invokeLater (new Runnable () {
347
            SwingUtilities.invokeLater(new Runnable() {
349
                public void run () {
348
                public void run() {
350
                    Models.CompoundModel model = getModel();
349
                    Models.CompoundModel model = getModel();
351
                    if (model == null)
350
                    if (model == null) {
352
                        return; // already disposed
351
                        return; // already disposed
352
                    }
353
                    if (event instanceof ModelEvent.TableValueChanged) {
353
                    if (event instanceof ModelEvent.TableValueChanged) {
354
                        ModelEvent.TableValueChanged tvEvent = (ModelEvent.TableValueChanged) event;
354
                        ModelEvent.TableValueChanged tvEvent = (ModelEvent.TableValueChanged) event;
355
                        Object node = tvEvent.getNode();
355
                        Object node = tvEvent.getNode();
Lines 359-372 Link Here
359
                            //System.err.println("  nodes = "+Arrays.toString(tmNodes));
359
                            //System.err.println("  nodes = "+Arrays.toString(tmNodes));
360
                            int change = tvEvent.getChange();
360
                            int change = tvEvent.getChange();
361
                            for (TreeModelNode tmNode : tmNodes) {
361
                            for (TreeModelNode tmNode : tmNodes) {
362
                                String column = tvEvent.getColumnID();
362
                                Collection<String> columnIDs = tvEvent.getColumnIDs();
363
                                if (column != null) {
363
                                if (columnIDs.isEmpty() || (columnIDs.size() == 1 && columnIDs.contains(null))) {
364
                                    tmNode.refreshColumn(column, change);
364
                                    tmNode.refresh(model);
365
                                } else {
365
                                } else {
366
                                    for (String column : columnIDs) {
367
                                        if (column != null) {
368
                                            tmNode.refreshColumn(column, change);
369
                                        }
370
                                    }
371
                                }
372
                            }
373
                            return; // We're done
374
                        } else { // Refresh all nodes
375
                            List<TreeModelNode> nodes = new ArrayList<TreeModelNode>(objectToNode.size());
376
                            for (WeakReference<TreeModelNode>[] wrs : objectToNode.values()) {
377
                                for (WeakReference<TreeModelNode> wr : wrs) {
378
                                    TreeModelNode tm = wr.get();
379
                                    if (tm != null) {
380
                                        nodes.add(tm);
381
                                    }
382
                                }
383
                            }
384
                            int change = tvEvent.getChange();
385
                            for (TreeModelNode tmNode : nodes) {
386
                                Collection<String> columnIDs = tvEvent.getColumnIDs();
387
                                if (columnIDs.isEmpty() || (columnIDs.size() == 1 && columnIDs.contains(null))) {
366
                                    tmNode.refresh(model);
388
                                    tmNode.refresh(model);
389
                                } else {
390
                                    for (String column : columnIDs) {
391
                                        if (column != null) {
392
                                            tmNode.refreshColumn(column, change);
393
                                        }
394
                                    }
367
                                }
395
                                }
368
                            }
396
                            }
369
                            return ; // We're done
397
                            return; // We're done
370
                        }
398
                        }
371
                    }
399
                    }
372
                    if (event instanceof ModelEvent.NodeChanged) {
400
                    if (event instanceof ModelEvent.NodeChanged) {
Lines 381-387 Link Here
381
                            for (TreeModelNode tmNode : tmNodes) {
409
                            for (TreeModelNode tmNode : tmNodes) {
382
                                tmNode.refresh(model, nchEvent.getChange());
410
                                tmNode.refresh(model, nchEvent.getChange());
383
                            }
411
                            }
384
                            return ; // We're done
412
                            return; // We're done
385
                        } else { // Refresh all nodes
413
                        } else { // Refresh all nodes
386
                            List<TreeModelNode> nodes = new ArrayList<TreeModelNode>(objectToNode.size());
414
                            List<TreeModelNode> nodes = new ArrayList<TreeModelNode>(objectToNode.size());
387
                            for (WeakReference<TreeModelNode>[] wrs : objectToNode.values()) {
415
                            for (WeakReference<TreeModelNode>[] wrs : objectToNode.values()) {
Lines 395-401 Link Here
395
                            for (TreeModelNode tmNode : nodes) {
423
                            for (TreeModelNode tmNode : nodes) {
396
                                tmNode.refresh(model, nchEvent.getChange());
424
                                tmNode.refresh(model, nchEvent.getChange());
397
                            }
425
                            }
398
                            return ; // We're done
426
                            return; // We're done
399
                        }
427
                        }
400
                    }
428
                    }
401
                    if (event instanceof ModelEvent.SelectionChanged) {
429
                    if (event instanceof ModelEvent.SelectionChanged) {
Lines 410-424 Link Here
410
                                    }
438
                                    }
411
                                }
439
                                }
412
                                try {
440
                                try {
413
                                    manager.setSelectedNodes(tmNodes.toArray(new Node[] {}));
441
                                    manager.setSelectedNodes(tmNodes.toArray(new Node[]{}));
414
                                } catch (PropertyVetoException ex) {
442
                                } catch (PropertyVetoException ex) {
415
                                    Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Selection of "+Arrays.toString(nodes)+" vetoed.", ex); // NOI18N
443
                                    Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Selection of " + Arrays.toString(nodes) + " vetoed.", ex); // NOI18N
416
                                }
444
                                }
417
                            }
445
                            }
418
                        });
446
                        });
419
                        return ;
447
                        return;
420
                    }
448
                    }
421
                    getRootNode().setObject (model, model.getRoot ());
449
                    getRootNode().setObject(model, model.getRoot());
422
                }
450
                }
423
            });
451
            });
424
        }
452
        }
Lines 429-439 Link Here
429
     * Implements set of tree view features.
457
     * Implements set of tree view features.
430
     */
458
     */
431
    private final class DefaultTreeFeatures extends TreeFeatures implements TreeExpansionListener {
459
    private final class DefaultTreeFeatures extends TreeFeatures implements TreeExpansionListener {
432
        
460
433
        private TreeView view;
461
        private TreeView view;
434
        private OutlineView outline;
462
        private OutlineView outline;
435
        
463
436
        private DefaultTreeFeatures (TreeView view) {
464
        private DefaultTreeFeatures(TreeView view) {
437
            this.view = view;
465
            this.view = view;
438
            JTree tree;
466
            JTree tree;
439
            try {
467
            try {
Lines 442-457 Link Here
442
                tree = (JTree) treeField.get(view);
470
                tree = (JTree) treeField.get(view);
443
            } catch (Exception ex) {
471
            } catch (Exception ex) {
444
                Exceptions.printStackTrace(ex);
472
                Exceptions.printStackTrace(ex);
445
                return ;
473
                return;
446
            }
474
            }
447
            tree.addTreeExpansionListener(this);
475
            tree.addTreeExpansionListener(this);
448
        }
476
        }
449
477
450
        private DefaultTreeFeatures (OutlineView view) {
478
        private DefaultTreeFeatures(OutlineView view) {
451
            this.outline = view;
479
            this.outline = view;
452
            view.addTreeExpansionListener(this);
480
            view.addTreeExpansionListener(this);
453
        }
481
        }
454
        
482
455
        public void destroy() {
483
        public void destroy() {
456
            if (outline != null) {
484
            if (outline != null) {
457
                outline.removeTreeExpansionListener(this);
485
                outline.removeTreeExpansionListener(this);
Lines 463-489 Link Here
463
                    tree = (JTree) treeField.get(view);
491
                    tree = (JTree) treeField.get(view);
464
                } catch (Exception ex) {
492
                } catch (Exception ex) {
465
                    Exceptions.printStackTrace(ex);
493
                    Exceptions.printStackTrace(ex);
466
                    return ;
494
                    return;
467
                }
495
                }
468
                tree.removeTreeExpansionListener(this);
496
                tree.removeTreeExpansionListener(this);
469
            }
497
            }
470
        }
498
        }
471
        
499
472
        /**
500
        /**
473
         * Returns <code>true</code> if given node is expanded.
501
         * Returns <code>true</code> if given node is expanded.
474
         *
502
         *
475
         * @param node a node to be checked
503
         * @param node a node to be checked
476
         * @return <code>true</code> if given node is expanded
504
         * @return <code>true</code> if given node is expanded
477
         */
505
         */
478
        public boolean isExpanded (
506
        public boolean isExpanded(
479
            Object node
507
                Object node
480
        ) {
508
        ) {
481
            Node[] ns = findNode (node);
509
            Node[] ns = findNode(node);
482
            if (ns.length == 0) return false; // Something what does not exist is not expanded ;-)
510
            if (ns.length == 0) {
511
                return false; // Something what does not exist is not expanded ;-)
512
            }
483
            if (outline != null) {
513
            if (outline != null) {
484
                return outline.isExpanded(ns[0]);
514
                return outline.isExpanded(ns[0]);
485
            } else {
515
            } else {
486
                return view.isExpanded (ns[0]);
516
                return view.isExpanded(ns[0]);
487
            }
517
            }
488
518
489
        }
519
        }
Lines 493-507 Link Here
493
         *
523
         *
494
         * @param node a list of nodes to be expanded
524
         * @param node a list of nodes to be expanded
495
         */
525
         */
496
        public void expandNode (
526
        public void expandNode(
497
            Object node
527
                Object node
498
        ) {
528
        ) {
499
            Node[] ns = findNode (node);
529
            Node[] ns = findNode(node);
500
            for (Node n : ns) {
530
            for (Node n : ns) {
501
                if (outline != null) {
531
                if (outline != null) {
502
                    outline.expandNode(n);
532
                    outline.expandNode(n);
503
                } else {
533
                } else {
504
                    view.expandNode (n);
534
                    view.expandNode(n);
505
                }
535
                }
506
            }
536
            }
507
        }
537
        }
Lines 511-551 Link Here
511
         *
541
         *
512
         * @param node a node to be expanded
542
         * @param node a node to be expanded
513
         */
543
         */
514
        public void collapseNode (
544
        public void collapseNode(
515
            Object node
545
                Object node
516
        ) {
546
        ) {
517
            Node[] ns = findNode (node);
547
            Node[] ns = findNode(node);
518
            for (Node n : ns) {
548
            for (Node n : ns) {
519
                if (outline != null) {
549
                if (outline != null) {
520
                    outline.collapseNode(n);
550
                    outline.collapseNode(n);
521
                } else {
551
                } else {
522
                    view.collapseNode (n);
552
                    view.collapseNode(n);
523
                }
553
                }
524
            }
554
            }
525
        }
555
        }
526
        
556
527
        /**
557
        /**
528
          * Called whenever an item in the tree has been expanded.
558
         * Called whenever an item in the tree has been expanded.
529
          */
559
         */
530
        public void treeExpanded (TreeExpansionEvent event) {
560
        public void treeExpanded(TreeExpansionEvent event) {
531
            Models.CompoundModel model = getModel();
561
            Models.CompoundModel model = getModel();
532
            if (model != null) {
562
            if (model != null) {
533
                model.nodeExpanded (initExpandCollapseNotify(event));
563
                model.nodeExpanded(initExpandCollapseNotify(event));
534
            }
564
            }
535
        }
565
        }
536
566
537
        /**
567
        /**
538
          * Called whenever an item in the tree has been collapsed.
568
         * Called whenever an item in the tree has been collapsed.
539
          */
569
         */
540
        public void treeCollapsed (TreeExpansionEvent event) {
570
        public void treeCollapsed(TreeExpansionEvent event) {
541
            Models.CompoundModel model = getModel();
571
            Models.CompoundModel model = getModel();
542
            if (model != null) {
572
            if (model != null) {
543
                model.nodeCollapsed (initExpandCollapseNotify(event));
573
                model.nodeCollapsed(initExpandCollapseNotify(event));
544
            }
574
            }
545
        }
575
        }
546
576
547
        private Object initExpandCollapseNotify(TreeExpansionEvent event) {
577
        private Object initExpandCollapseNotify(TreeExpansionEvent event) {
548
            Node node = Visualizer.findNode(event.getPath ().getLastPathComponent());
578
            Node node = Visualizer.findNode(event.getPath().getLastPathComponent());
549
            Object obj = node.getLookup().lookup(Object.class);
579
            Object obj = node.getLookup().lookup(Object.class);
550
            Object actOn;
580
            Object actOn;
551
            node = node.getParentNode();
581
            node = node.getParentNode();
Lines 569-572 Link Here
569
    }
599
    }
570
600
571
}
601
}
572
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/AsynchronousModelFilter.java (-26 / +29 lines)
Lines 39-59 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.spi.viewmodel;
42
package org.netbeans.spi.viewmodel;
44
43
45
import java.util.concurrent.Executor;
44
import java.util.concurrent.Executor;
46
47
import org.openide.util.RequestProcessor;
45
import org.openide.util.RequestProcessor;
48
46
49
/**
47
/**
50
 * Change threading of implemented models.
48
 * Change threading of implemented models. Methods implemented in
51
 * Methods implemented in {@link TreeModel}, {@link NodeModel} ({@link ExtendedNodeModel})
49
 * {@link TreeModel}, {@link NodeModel} ({@link ExtendedNodeModel}) and
52
 * and {@link TableModel} can be called synchronously in AWT thread as a direct
50
 * {@link TableModel} can be called synchronously in AWT thread as a direct
53
 * response to user action (this is the default behavior),
51
 * response to user action (this is the default behavior), or asynchronously in
54
 * or asynchronously in a Request Processor or other thread.
52
 * a Request Processor or other thread. Register an implementation of this along
55
 * Register an implementation of this along with other models,
53
 * with other models, if you need to change the original threading.
56
 * if you need to change the original threading.
57
 *
54
 *
58
 * @author Martin Entlicher
55
 * @author Martin Entlicher
59
 * @since 1.20
56
 * @since 1.20
Lines 61-73 Link Here
61
public interface AsynchronousModelFilter extends Model {
58
public interface AsynchronousModelFilter extends Model {
62
59
63
    /**
60
    /**
64
     * This enumeration identifies method(s) of view models for which
61
     * This enumeration identifies method(s) of view models for which threading
65
     * threading information is provided by
62
     * information is provided by
66
     * {@link #asynchronous(java.util.concurrent.Executor, org.netbeans.spi.viewmodel.AsynchronousModelFilter.CALL, java.lang.Object)} method.
63
     * {@link #asynchronous(java.util.concurrent.Executor, org.netbeans.spi.viewmodel.AsynchronousModelFilter.CALL, java.lang.Object)}
64
     * method.
67
     * <br>
65
     * <br>
68
     * <b>CHILDREN</b> for TreeModel.getChildrenCount() and TreeModel.getChildren()
66
     * <b>CHILDREN</b> for TreeModel.getChildrenCount() and
67
     * TreeModel.getChildren()
69
     * <br>
68
     * <br>
70
     * <b>DISPLAY_NAME</b> is for NodeModel.getDisplayName() and ExtendedNodeModel.setName()
69
     * <b>DISPLAY_NAME</b> is for NodeModel.getDisplayName() and
70
     * ExtendedNodeModel.setName()
71
     * <br>
71
     * <br>
72
     * <b>SHORT_DESCRIPTION</b> for NodeModel.getShortDescription()
72
     * <b>SHORT_DESCRIPTION</b> for NodeModel.getShortDescription()
73
     * <br>
73
     * <br>
Lines 76-92 Link Here
76
     * The rest of the methods on models are called synchronously, or additional
76
     * The rest of the methods on models are called synchronously, or additional
77
     * enums can be added in the future.
77
     * enums can be added in the future.
78
     */
78
     */
79
    static enum CALL { CHILDREN, DISPLAY_NAME, SHORT_DESCRIPTION, VALUE }
79
    static enum CALL {
80
81
        CHILDREN, DISPLAY_NAME, SHORT_DESCRIPTION, VALUE
82
    }
80
83
81
    /**
84
    /**
82
     * Executor for invocation of models method calls in the current thread.
85
     * Executor for invocation of models method calls in the current thread.
83
     * This will make method invocation synchronous. It's important that the
86
     * This will make method invocation synchronous. It's important that the
84
     * methods execute fast so that they do not block AWT thread.
87
     * methods execute fast so that they do not block AWT thread. This is the
85
     * This is the default executor for {@link CALL#DISPLAY_NAME} and
88
     * default executor for {@link CALL#DISPLAY_NAME} and
86
     * {@link CALL#SHORT_DESCRIPTION}.
89
     * {@link CALL#SHORT_DESCRIPTION}.
87
     */
90
     */
88
    static final Executor CURRENT_THREAD = new Executor() {
91
    static final Executor CURRENT_THREAD = new Executor() {
89
92
93
        @Override
90
        public void execute(Runnable command) {
94
        public void execute(Runnable command) {
91
            command.run();
95
            command.run();
92
        }
96
        }
Lines 94-112 Link Here
94
    };
98
    };
95
99
96
    /**
100
    /**
97
     * Executor, which uses a shared {@link RequestProcessor} with
101
     * Executor, which uses a shared {@link RequestProcessor} with throughoutput
98
     * throughoutput = 1 for models method calls, making the method invocation
102
     * = 1 for models method calls, making the method invocation asynchronous.
99
     * asynchronous. The UI gives a visual feedback to the user if models method
103
     * The UI gives a visual feedback to the user if models method calls take a
100
     * calls take a long time. Use this to keep the UI responsive.
104
     * long time. Use this to keep the UI responsive. This is the default
101
     * This is the default executor for {@link CALL#CHILDREN} and
105
     * executor for {@link CALL#CHILDREN} and {@link CALL#VALUE}.
102
     * {@link CALL#VALUE}.
103
     */
106
     */
104
    static final Executor DEFAULT = new RequestProcessor("Asynchronous view model", 1);   // NOI18N
107
    static final Executor DEFAULT = new RequestProcessor("Asynchronous view model", 1);   // NOI18N
105
108
106
    /**
109
    /**
107
     * Change the threading information for view models method calls.
110
     * Change the threading information for view models method calls. The
108
     * The returned Executor is used to call methods identified by
111
     * returned Executor is used to call methods identified by {@link CALL}
109
     * {@link CALL} enum.
112
     * enum.
110
     *
113
     *
111
     * @param original The original {@link Executor}
114
     * @param original The original {@link Executor}
112
     * @param asynchCall Identification of the method call
115
     * @param asynchCall Identification of the method call
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/CachedChildrenTreeModel.java (-42 / +49 lines)
Lines 23-29 Link Here
23
 * License Header, with the fields enclosed by brackets [] replaced by
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 * 
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
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
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
29
 * "[Contributor] elects to include this software in this distribution
Lines 34-45 Link Here
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
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
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
36
 * made subject to such option by the copyright holder.
37
 * 
37
 *
38
 * Contributor(s):
38
 * Contributor(s):
39
 * 
39
 *
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.spi.viewmodel;
42
package org.netbeans.spi.viewmodel;
44
43
45
import java.util.HashSet;
44
import java.util.HashSet;
Lines 50-65 Link Here
50
import org.netbeans.spi.viewmodel.AsynchronousModelFilter.CALL;
49
import org.netbeans.spi.viewmodel.AsynchronousModelFilter.CALL;
51
50
52
/**
51
/**
53
 * A TreeModel, which caches children objects and allow seamless update of children objects.
52
 * A TreeModel, which caches children objects and allow seamless update of
54
 * 
53
 * children objects.
54
 *
55
 * @author Martin Entlicher
55
 * @author Martin Entlicher
56
 * @since 1.49
56
 * @since 1.49
57
 */
57
 */
58
public abstract class CachedChildrenTreeModel extends Object implements TreeModel, AsynchronousModelFilter {
58
public abstract class CachedChildrenTreeModel extends Object implements TreeModel, AsynchronousModelFilter {
59
59
60
    private final Map<Object, ChildrenTree> childrenCache = new WeakHashMap<Object, ChildrenTree>();
60
    private final Map<Object, ChildrenTree> childrenCache = new WeakHashMap<Object, ChildrenTree>();
61
    private final Set<Object>   childrenToRefresh = new HashSet<Object>();
61
    private final Set<Object> childrenToRefresh = new HashSet<Object>();
62
    
62
63
    @Override
63
    @Override
64
    public Executor asynchronous(Executor original, CALL asynchCall, Object node) throws UnknownTypeException {
64
    public Executor asynchronous(Executor original, CALL asynchCall, Object node) throws UnknownTypeException {
65
        if (CALL.CHILDREN.equals(asynchCall)) {
65
        if (CALL.CHILDREN.equals(asynchCall)) {
Lines 80-87 Link Here
80
    }
80
    }
81
81
82
    @Override
82
    @Override
83
    public final Object[] getChildren (Object o, int from, int to)
83
    public final Object[] getChildren(Object o, int from, int to)
84
    throws UnknownTypeException {
84
            throws UnknownTypeException {
85
        Object[] ch;
85
        Object[] ch;
86
        boolean cache = cacheChildrenOf(o);
86
        boolean cache = cacheChildrenOf(o);
87
        if (cache) {
87
        if (cache) {
Lines 95-112 Link Here
95
            } else {
95
            } else {
96
                ch = null;
96
                ch = null;
97
            }
97
            }
98
        } else ch = null;
98
        } else {
99
            ch = null;
100
        }
99
        if (ch == null) {
101
        if (ch == null) {
100
            ch = computeChildren(o);
102
            ch = computeChildren(o);
101
            if (ch == null) {
103
            if (ch == null) {
102
                throw new UnknownTypeException (o);
104
                throw new UnknownTypeException(o);
103
            } else {
105
            } else if (cache) {
104
                if (cache) {
106
                ChildrenTree cht = new ChildrenTree(o);
105
                    ChildrenTree cht = new ChildrenTree(o);
107
                cht.setChildren(ch);
106
                    cht.setChildren(ch);
108
                synchronized (childrenCache) {
107
                    synchronized (childrenCache) {
109
                    childrenCache.put(o, cht);
108
                        childrenCache.put(o, cht);
109
                    }
110
                }
110
                }
111
            }
111
            }
112
        }
112
        }
Lines 123-145 Link Here
123
        }
123
        }
124
        return ch;
124
        return ch;
125
    }
125
    }
126
    
126
127
    /**
127
    /**
128
     * Compute the children nodes. This is called when there are no children
128
     * Compute the children nodes. This is called when there are no children
129
     * cached for this node only.
129
     * cached for this node only.
130
     *
130
     * @param node The node to compute the children for
131
     * @param node The node to compute the children for
131
     * @return The list of children
132
     * @return The list of children
132
     * @throws UnknownTypeException When this implementation is not able to
133
     * @throws UnknownTypeException When this implementation is not able to
133
     *         resolve children for given node type
134
     * resolve children for given node type
134
     */
135
     */
135
    protected abstract Object[] computeChildren(Object node) throws UnknownTypeException;
136
    protected abstract Object[] computeChildren(Object node) throws UnknownTypeException;
136
    
137
137
    /**
138
    /**
138
     * Can be overridden to decide which nodes to cache and which not.
139
     * Can be overridden to decide which nodes to cache and which not.
140
     *
139
     * @param node The node
141
     * @param node The node
140
     * @return <code>true</code> when the children of this node should be cached,
142
     * @return <code>true</code> when the children of this node should be
141
     *         <code>false</code> otherwise. The default implementation returns
143
     * cached, <code>false</code> otherwise. The default implementation returns
142
     *         <code>true</code> always.
144
     * <code>true</code> always.
143
     */
145
     */
144
    protected boolean cacheChildrenOf(Object node) {
146
    protected boolean cacheChildrenOf(Object node) {
145
        return true;
147
        return true;
Lines 147-152 Link Here
147
149
148
    /**
150
    /**
149
     * Force a refresh of the cache.
151
     * Force a refresh of the cache.
152
     *
150
     * @param node The node to refresh the cache for.
153
     * @param node The node to refresh the cache for.
151
     */
154
     */
152
    protected final void refreshCache(Object node) {
155
    protected final void refreshCache(Object node) {
Lines 164-195 Link Here
164
            childrenToRefresh.clear();
167
            childrenToRefresh.clear();
165
        }
168
        }
166
    }
169
    }
167
    
170
168
    /**
171
    /**
169
     * Allows to reorder the children. This is called each time the children
172
     * Allows to reorder the children. This is called each time the children are
170
     * are requested, even when they're cached.
173
     * requested, even when they're cached.
171
     * @param nodes The original nodes returned by {@link #computeChildren(java.lang.Object)}
174
     *
172
     *              or by the cache.
175
     * @param nodes The original nodes returned by
173
     * @return The reordered nodes. The default implementation returns the original nodes.
176
     * {@link #computeChildren(java.lang.Object)} or by the cache.
177
     * @return The reordered nodes. The default implementation returns the
178
     * original nodes.
174
     */
179
     */
175
    protected Object[] reorder(Object[] nodes) {
180
    protected Object[] reorder(Object[] nodes) {
176
        return nodes;
181
        return nodes;
177
    }
182
    }
178
    
183
179
    /**
184
    /**
180
     * Force to recompute all cached children.
185
     * Force to recompute all cached children.
186
     *
181
     * @throws UnknownTypeException When this implementation is not able to
187
     * @throws UnknownTypeException When this implementation is not able to
182
     *         resolve children for some node type
188
     * resolve children for some node type
183
     */
189
     */
184
    protected final void recomputeChildren() throws UnknownTypeException {
190
    protected final void recomputeChildren() throws UnknownTypeException {
185
        recomputeChildren(getRoot());
191
        recomputeChildren(getRoot());
186
    }
192
    }
187
    
193
188
    /**
194
    /**
189
     * Force to recompute children cached for the given node.
195
     * Force to recompute children cached for the given node.
196
     *
190
     * @param node The node to recompute the children for
197
     * @param node The node to recompute the children for
191
     * @throws UnknownTypeException When this implementation is not able to
198
     * @throws UnknownTypeException When this implementation is not able to
192
     *         resolve children for the given node type
199
     * resolve children for the given node type
193
     */
200
     */
194
    protected final void recomputeChildren(Object node) throws UnknownTypeException {
201
    protected final void recomputeChildren(Object node) throws UnknownTypeException {
195
        ChildrenTree cht;
202
        ChildrenTree cht;
Lines 209-232 Link Here
209
            }
216
            }
210
        }
217
        }
211
    }
218
    }
212
    
219
213
    private final static class ChildrenTree {
220
    private final static class ChildrenTree {
214
        
221
215
        //private Object node;
222
        //private Object node;
216
        private Object[] ch;
223
        private Object[] ch;
217
        
224
218
        public ChildrenTree(Object node) {
225
        public ChildrenTree(Object node) {
219
            //this.node = node;
226
            //this.node = node;
220
        }
227
        }
221
        
228
222
        public void setChildren(Object[] ch) {
229
        public void setChildren(Object[] ch) {
223
            this.ch = ch;
230
            this.ch = ch;
224
        }
231
        }
225
        
232
226
        public Object[] getChildren() {
233
        public Object[] getChildren() {
227
            return ch;
234
            return ch;
228
        }
235
        }
229
        
236
230
    }
237
    }
231
    
238
232
}
239
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/CheckNodeModelFilter.java (-9 / +13 lines)
Lines 39-51 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.spi.viewmodel;
42
package org.netbeans.spi.viewmodel;
44
43
45
/**
44
/**
46
 * A model filter for {@link CheckNodeModel}.
45
 * A model filter for {@link CheckNodeModel}. Can be also used to add the
47
 * Can be also used to add the check-boxes to an ordinary {@link NodeModel}.
46
 * check-boxes to an ordinary {@link NodeModel}.
48
 * 
47
 *
49
 * @author Martin Entlicher
48
 * @author Martin Entlicher
50
 * @since 1.17
49
 * @since 1.17
51
 */
50
 */
Lines 56-62 Link Here
56
     *
55
     *
57
     * @param original the original node model
56
     * @param original the original node model
58
     * @param node the tree node object
57
     * @param node the tree node object
59
     * @return <code>true</code> if the check-box should be displayed, <code>false</code> otherwise.
58
     * @return <code>true</code> if the check-box should be displayed,
59
     * <code>false</code> otherwise.
60
     */
60
     */
61
    boolean isCheckable(NodeModel original, Object node) throws UnknownTypeException;
61
    boolean isCheckable(NodeModel original, Object node) throws UnknownTypeException;
62
62
Lines 65-71 Link Here
65
     *
65
     *
66
     * @param original the original node model
66
     * @param original the original node model
67
     * @param node the tree node object
67
     * @param node the tree node object
68
     * @return <code>true</code> if the check-box should be enabled, <code>false</code> otherwise.
68
     * @return <code>true</code> if the check-box should be enabled,
69
     * <code>false</code> otherwise.
69
     */
70
     */
70
    boolean isCheckEnabled(NodeModel original, Object node) throws UnknownTypeException;
71
    boolean isCheckEnabled(NodeModel original, Object node) throws UnknownTypeException;
71
72
Lines 75-82 Link Here
75
     * @param original the original node model
76
     * @param original the original node model
76
     * @param node the tree node object
77
     * @param node the tree node object
77
     * @return <code>true</code> if the check-box should be selected,
78
     * @return <code>true</code> if the check-box should be selected,
78
     *         <code>false</code> if it should be unselected and
79
     * <code>false</code> if it should be unselected and <code>null</code> if
79
     *         <code>null</code> if the state is unknown.
80
     * the state is unknown.
80
     */
81
     */
81
    Boolean isSelected(NodeModel original, Object node) throws UnknownTypeException;
82
    Boolean isSelected(NodeModel original, Object node) throws UnknownTypeException;
82
83
Lines 86-93 Link Here
86
     * @param original the original node model
87
     * @param original the original node model
87
     * @param node the tree node object
88
     * @param node the tree node object
88
     * @param selected <code>true</code> if the check-box was selected,
89
     * @param selected <code>true</code> if the check-box was selected,
89
     *                 <code>false</code> if the check-box was unselected.
90
     * <code>false</code> if the check-box was unselected.
90
     */
91
     */
91
    void setSelected(NodeModel original, Object node, Boolean selected) throws UnknownTypeException;
92
    void setSelected(NodeModel original, Object node, Boolean selected) throws UnknownTypeException;
92
93
94
    void setSelected(NodeModel original, Object... nodes) throws UnknownTypeException;
95
96
    void setUnselected(NodeModel original, Object... nodes) throws UnknownTypeException;
93
}
97
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/CheckNodeModel.java (-9 / +12 lines)
Lines 39-52 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.spi.viewmodel;
42
package org.netbeans.spi.viewmodel;
44
43
45
/**
44
/**
46
 * The extension of {@link NodeModel} that can display check-boxes next to the
45
 * The extension of {@link NodeModel} that can display check-boxes next to the
47
 * node display name.
46
 * node display name. Instead of a special column with check-boxes, this
48
 * Instead of a special column with check-boxes, this extension can be used.
47
 * extension can be used. It will make the UI cleaner and more usable.
49
 * It will make the UI cleaner and more usable.
50
 *
48
 *
51
 * @author Martin Entlicher
49
 * @author Martin Entlicher
52
 * @since 1.17
50
 * @since 1.17
Lines 57-63 Link Here
57
     * Tell the renderer to display the check-box.
55
     * Tell the renderer to display the check-box.
58
     *
56
     *
59
     * @param node the tree node object
57
     * @param node the tree node object
60
     * @return <code>true</code> if the check-box should be displayed, <code>false</code> otherwise.
58
     * @return <code>true</code> if the check-box should be displayed,
59
     * <code>false</code> otherwise.
61
     */
60
     */
62
    boolean isCheckable(Object node) throws UnknownTypeException;
61
    boolean isCheckable(Object node) throws UnknownTypeException;
63
62
Lines 65-71 Link Here
65
     * Provide the enabled state of the check-box.
64
     * Provide the enabled state of the check-box.
66
     *
65
     *
67
     * @param node the tree node object
66
     * @param node the tree node object
68
     * @return <code>true</code> if the check-box should be enabled, <code>false</code> otherwise.
67
     * @return <code>true</code> if the check-box should be enabled,
68
     * <code>false</code> otherwise.
69
     */
69
     */
70
    boolean isCheckEnabled(Object node) throws UnknownTypeException;
70
    boolean isCheckEnabled(Object node) throws UnknownTypeException;
71
71
Lines 74-81 Link Here
74
     *
74
     *
75
     * @param node the tree node object
75
     * @param node the tree node object
76
     * @return <code>true</code> if the check-box should be selected,
76
     * @return <code>true</code> if the check-box should be selected,
77
     *         <code>false</code> if it should be unselected and
77
     * <code>false</code> if it should be unselected and <code>null</code> if
78
     *         <code>null</code> if the state is unknown.
78
     * the state is unknown.
79
     */
79
     */
80
    Boolean isSelected(Object node) throws UnknownTypeException;
80
    Boolean isSelected(Object node) throws UnknownTypeException;
81
81
Lines 84-91 Link Here
84
     *
84
     *
85
     * @param node the tree node object
85
     * @param node the tree node object
86
     * @param selected <code>true</code> if the check-box was selected,
86
     * @param selected <code>true</code> if the check-box was selected,
87
     *                 <code>false</code> if the check-box was unselected.
87
     * <code>false</code> if the check-box was unselected.
88
     */
88
     */
89
    void setSelected(Object node, Boolean selected) throws UnknownTypeException;
89
    void setSelected(Object node, Boolean selected) throws UnknownTypeException;
90
90
91
    void setSelected(Object... nodes) throws UnknownTypeException;
92
93
    void setUnselected(Object... nodes) throws UnknownTypeException;
91
}
94
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/ColumnModel.java (-100 / +107 lines)
Lines 41-79 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
import java.beans.PropertyEditor;
46
import java.beans.PropertyEditor;
48
47
49
50
/**
48
/**
51
 * Defines model for one table view column. Can be used together with
49
 * Defines model for one table view column. Can be used together with
52
 * {@link TreeModel} for tree table view representation.
50
 * {@link TreeModel} for tree table view representation.
53
 *
51
 *
54
 * @author   Jan Jancura
52
 * @author Jan Jancura
55
 */
53
 */
56
public abstract class ColumnModel implements Model {
54
public abstract class ColumnModel implements Model {
57
55
58
59
    /**
56
    /**
60
     * Returns unique ID of this column.
57
     * Returns unique ID of this column.
61
     *
58
     *
62
     * @return unique ID of this column
59
     * @return unique ID of this column
63
     */
60
     */
64
    public abstract String getID ();
61
    public abstract String getID();
65
62
66
    /**
63
    /**
67
     * Returns display name of this column. The returned String can contain an
64
     * Returns display name of this column. The returned String can contain an
68
     * ampersand marking the location of the mnemonic.
65
     * ampersand marking the location of the mnemonic.
69
     *
66
     *
70
     * @return display name of this column, including an optional ampersand for mnemonic location.
67
     * @return display name of this column, including an optional ampersand for
68
     * mnemonic location.
71
     */
69
     */
72
    public abstract String getDisplayName ();
70
    public abstract String getDisplayName();
73
    
71
74
    /** 
72
    /**
75
     * Returns the character, that indicates a mnemonic key
73
     * Returns the character, that indicates a mnemonic key for this column
76
     * for this column name. Can be <code>null</code>.
74
     * name. Can be <code>null</code>.
77
     *
75
     *
78
     * @return the mnemonic key or <code>null</code>.
76
     * @return the mnemonic key or <code>null</code>.
79
     * @since 1.11
77
     * @since 1.11
Lines 82-265 Link Here
82
    public Character getDisplayedMnemonic() {
80
    public Character getDisplayedMnemonic() {
83
        return null;
81
        return null;
84
    }
82
    }
85
    
83
86
    /**
84
    /**
87
     * Returns type of column items.
85
     * Returns type of column items.
88
     *
86
     *
89
     * @return type of column items
87
     * @return type of column items
90
     */
88
     */
91
    public abstract Class getType ();
89
    public abstract Class getType();
92
    
90
93
    /**
91
    /**
94
     * Returns ID of column this column should be installed before or 
92
     * Returns ID of column this column should be installed before or
95
     * <code>null</code>. Defines default order of columns only. 
93
     * <code>null</code>. Defines default order of columns only. This default
96
     * This default order can be changed by user, and 
94
     * order can be changed by user, and {@link #getCurrentOrderNumber} and
97
     * {@link #getCurrentOrderNumber} and {@link #setCurrentOrderNumber} are
95
     * {@link #setCurrentOrderNumber} are used for sorting after that.
98
     * used for sorting after that.
99
     *
96
     *
100
     * @return ID of column this column should be installed before or 
97
     * @return ID of column this column should be installed before or
101
     * <code>null</code>
98
     * <code>null</code>
102
     * @deprecated Not used. See {@link #getCurrentOrderNumber}.
99
     * @deprecated Not used. See {@link #getCurrentOrderNumber}.
103
     */
100
     */
104
    public String getPreviuosColumnID () {
101
    public String getPreviuosColumnID() {
105
        return null;
102
        return null;
106
    }
103
    }
107
    
104
108
    /**
105
    /**
109
     * Returns ID of column this column should be installed after or 
106
     * Returns ID of column this column should be installed after or
110
     * <code>null</code>. Defines default order of columns only. 
107
     * <code>null</code>. Defines default order of columns only. This default
111
     * This default order can be changed by user, and 
108
     * order can be changed by user, and {@link #getCurrentOrderNumber} and
112
     * {@link #getCurrentOrderNumber} and {@link #setCurrentOrderNumber} are
109
     * {@link #setCurrentOrderNumber} are used for sorting after that.
113
     * used for sorting after that.
114
     *
110
     *
115
     * @return ID of column next to this one or <code>null</code>
111
     * @return ID of column next to this one or <code>null</code>
116
     * @deprecated Not used. See {@link #getCurrentOrderNumber}.
112
     * @deprecated Not used. See {@link #getCurrentOrderNumber}.
117
     */
113
     */
118
    public String getNextColumnID () {
114
    public String getNextColumnID() {
119
        return null;
115
        return null;
120
    }
116
    }
121
    
117
122
    /**
118
    /**
123
     * Returns tooltip for given column. Default implementation returns 
119
     * Returns tooltip for given column. Default implementation returns
124
     * <code>null</code> - do not use tooltip.
120
     * <code>null</code> - do not use tooltip.
125
     *
121
     *
126
     * @return  tooltip for given node or <code>null</code>
122
     * @return tooltip for given node or <code>null</code>
127
     */
123
     */
128
    public String getShortDescription () {
124
    public String getShortDescription() {
129
        return null;
125
        return null;
130
    }
126
    }
131
    
127
132
    /**
128
    /**
133
     * True if column can be sorted. Default implementation returns 
129
     * True if column can be sorted. Default implementation returns
134
     * <code>true</code>.
130
     * <code>true</code>.
135
     *
131
     *
136
     * @return true if column can be sorted
132
     * @return true if column can be sorted
137
     */
133
     */
138
    public boolean isSortable () {
134
    public boolean isSortable() {
139
        return true;
135
        return true;
140
    }
136
    }
141
    
137
142
    /**
138
    /**
143
     * True if column should be visible. Default implementation 
139
     * True if column should be visible. Default implementation returns
144
     * returns <code>true</code>.
140
     * <code>true</code>.
145
     *
141
     *
146
     * @return <code>true</code> if column should be visible
142
     * @return <code>true</code> if column should be visible
147
     */
143
     */
148
    public boolean isVisible () {
144
    public boolean isVisible() {
149
        return true;
145
        return true;
150
    }
146
    }
151
    
147
152
    /**
148
    /**
153
     * Set true if column is to be visible. Default implementation does nothing.
149
     * Set true if column is to be visible. Default implementation does nothing.
154
     *
150
     *
155
     * @param visible set true if column is to be visible
151
     * @param visible set true if column is to be visible
156
     */
152
     */
157
    public void setVisible (boolean visible) {}
153
    public void setVisible(boolean visible) {
158
    
154
    }
155
159
    /**
156
    /**
160
     * True if column is sorted.
157
     * True if column is sorted. Default implementation returns
161
     * Default implementation returns <code>false</code>.
158
     * <code>false</code>.
162
     *
159
     *
163
     * @return <code>true</code> if column is sorted.
160
     * @return <code>true</code> if column is sorted.
164
     */
161
     */
165
    public boolean isSorted () {
162
    public boolean isSorted() {
166
        return false;
163
        return false;
167
    }
164
    }
168
    
165
169
    /**
166
    /**
170
     * Set true if column is to be sorted. Default implementation does nothing.
167
     * Set true if column is to be sorted. Default implementation does nothing.
171
     *
168
     *
172
     * @param sorted set true if column is to be sorted
169
     * @param sorted set true if column is to be sorted
173
     */
170
     */
174
    public void setSorted (boolean sorted) {}
171
    public void setSorted(boolean sorted) {
175
    
172
    }
173
176
    /**
174
    /**
177
     * True if column should be sorted in descending order.
175
     * True if column should be sorted in descending order. Default
178
     * Default implementation returns <code>false</code>.
176
     * implementation returns <code>false</code>.
179
     *
177
     *
180
     * @return <code>true</code> if column should be sorted
178
     * @return <code>true</code> if column should be sorted in descending order
181
     *         in descending order
182
     */
179
     */
183
    public boolean isSortedDescending () {
180
    public boolean isSortedDescending() {
184
        return false;
181
        return false;
185
    }
182
    }
186
    
183
187
    /**
188
     * Set true if column is to be sorted in descending order.
189
     * Default implementation does nothing.
190
     *
191
     * @param sortedDescending set true if column is to be sorted
192
     *        in descending order
193
     */
194
    public void setSortedDescending (boolean sortedDescending) {}
195
    
196
    /**
184
    /**
197
     * Should return current order number of this column. Default value is 
185
     * Set true if column is to be sorted in descending order. Default
198
     * <code>-1</code>.
186
     * implementation does nothing.
199
     *
187
     *
200
     * @return current order number of this column or <code>-1</code>
188
     * @param sortedDescending set true if column is to be sorted in descending
189
     * order
201
     */
190
     */
202
    public int getCurrentOrderNumber () {
191
    public void setSortedDescending(boolean sortedDescending) {
203
        return -1;
204
    }
192
    }
205
    
193
//
206
    /**
194
//    /**
207
     * Is called when current order number of this column is changed.
195
//     * Should return current order number of this column. Default value is
208
     * Default implementation does nothing.
196
//     * <code>-1</code>.
209
     *
197
//     *
210
     * @param newOrderNumber new order number
198
//     * @return current order number of this column or <code>-1</code>
211
     */
199
//     */
212
    public void setCurrentOrderNumber (int newOrderNumber) {}
200
//    public final int getCurrentOrderNumber() {
213
    
201
//        return -1;
202
//    }
203
//
204
//    /**
205
//     * Is called when current order number of this column is changed. Default
206
//     * implementation does nothing.
207
//     *
208
//     * @param newOrderNumber new order number
209
//     */
210
//    public final void setCurrentOrderNumber(int newOrderNumber) {
211
//    }
212
213
    private int currentOrderNumber = -1;
214
215
    public final int getCurrentOrderNumber() {
216
        return currentOrderNumber;
217
    }
218
219
    public final void setCurrentOrderNumber(int newOrderNumber) {
220
        this.currentOrderNumber = newOrderNumber;
221
    }
222
214
    /**
223
    /**
215
     * Return column width of this column.
224
     * Return column width of this column.
216
     *
225
     *
217
     * @return column width of this column
226
     * @return column width of this column
218
     */
227
     */
219
    public int getColumnWidth () {
228
    public int getColumnWidth() {
220
        return 20;
229
        return 20;
221
    }
230
    }
222
    
231
223
    /**
232
    /**
224
     * Is called when column width of this column is changed.
233
     * Is called when column width of this column is changed. Default
225
     * Default implementation does nothing.
234
     * implementation does nothing.
226
     *
235
     *
227
     * @param newColumnWidth a new column width
236
     * @param newColumnWidth a new column width
228
     */
237
     */
229
    public void setColumnWidth (int newColumnWidth) {}
238
    public void setColumnWidth(int newColumnWidth) {
230
    
239
    }
240
231
    /**
241
    /**
232
     * Returns {@link java.beans.PropertyEditor} to be used for 
242
     * Returns {@link java.beans.PropertyEditor} to be used for this column.
233
     * this column. Default implementation returns <code>null</code> - 
243
     * Default implementation returns <code>null</code> - means use default
234
     * means use default PropertyEditor.
244
     * PropertyEditor.
235
     *
245
     *
236
     * @return {@link java.beans.PropertyEditor} to be used for 
246
     * @return {@link java.beans.PropertyEditor} to be used for this column
237
     *         this column
238
     */
247
     */
239
    public PropertyEditor getPropertyEditor () {
248
    public PropertyEditor getPropertyEditor() {
240
        return null;
249
        return null;
241
    }
250
    }
242
    
251
243
    /**
252
    /**
244
     * Rerturns {@link javax.swing.table.TableCellEditor} to be used for 
253
     * Rerturns {@link javax.swing.table.TableCellEditor} to be used for this
245
     * this column.
254
     * column.
246
     *
255
     *
247
     * @return {@link javax.swing.table.TableCellEditor} to be used for 
256
     * @return {@link javax.swing.table.TableCellEditor} to be used for this
248
     *         this column
257
     * column
249
     */
258
     */
250
//    public TableCellEditor getTableCellEditor () {
259
//    public TableCellEditor getTableCellEditor () {
251
//        return null;
260
//        return null;
252
//    }
261
//    }
253
    
254
    /**
262
    /**
255
     * Rerturns {@link javax.swing.table.TableCellRenderer} to be used for 
263
     * Rerturns {@link javax.swing.table.TableCellRenderer} to be used for this
256
     * this column.
264
     * column.
257
     *
265
     *
258
     * @return {@link javax.swing.table.TableCellRenderer} to be used for 
266
     * @return {@link javax.swing.table.TableCellRenderer} to be used for this
259
     *         this column
267
     * column
260
     */
268
     */
261
//    public TableCellRenderer getTableCellRenderer () {
269
//    public TableCellRenderer getTableCellRenderer () {
262
//        return null;
270
//        return null;
263
//    }
271
//    }
264
    
265
}
272
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/ColumnsModel.java (+84 lines)
Line 0 Link Here
1
//<editor-fold defaultstate="collapsed" desc="CDDL">
2
/*COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
3
*
4
* 1. Definitions.
5
* 1.1. "Contributor" means each individual or entity that creates or contributes to the creation of Modifications.
6
* 1.2. "Contributor Version" means the combination of the Original Software, prior Modifications used by a Contributor (if any), and the Modifications made by that particular Contributor.
7
* 1.3. "Covered Software" means (a) the Original Software, or (b) Modifications, or (c) the combination of files containing Original Software with files containing Modifications, in each case including portions thereof.
8
* 1.4. "Executable" means the Covered Software in any form other than Source Code.
9
* 1.5. "Initial Developer" means the individual or entity that first makes Original Software available under this License.
10
* 1.6. "Larger Work" means a work which combines Covered Software or portions thereof with code not governed by the terms of this License.
11
* 1.7. "License" means this document.
12
* 1.8. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein.
13
* 1.9 "Modifications" means the Source Code and Executable form of any of the following:
14
* A. Any file that results from an addition to, deletion from or modification of the contents of a file containing Original Software or previous Modifications;
15
* B. Any new file that contains any part of the Original Software or previous Modification; or
16
* C. Any new file that is contributed or otherwise made available under the terms of this License.
17
* 1.10. "Original Software" means the Source Code and Executable form of computer software code that is originally released under this License.
18
* 1.11. "Patent Claims" means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor.
19
* 1.12. "Source Code" means (a) the common form of computer software code in which modifications are made and (b) associated documentation included in or with such code.
20
* 1.13. "You" (or "Your") means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
21
* 2. License Grants.
22
* 2.1. The Initial Developer Grant.
23
* Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, the Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license:
24
* (a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer, to use, reproduce, modify, display, perform, sublicense and distribute the Original Software (or portions thereof), with or without Modifications, and/or as part of a Larger Work; and
25
* (b) under Patent Claims infringed by the making, using or selling of Original Software, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Software (or portions thereof).
26
* (c) The licenses granted in Sections 2.1(a) and (b) are effective on the date Initial Developer first distributes or otherwise makes the Original Software available to a third party under the terms of this License.
27
* (d) Notwithstanding Section 2.1(b) above, no patent license is granted: (1) for code that You delete from the Original Software, or (2) for infringements caused by: (i) the modification of the Original Software, or (ii) the combination of the Original Software with other software or devices.
28
* 2.2. Contributor Grant.
29
* Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
30
* (a) under intellectual property rights (other than patent or trademark) Licensable by Contributor to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof), either on an unmodified basis, with other Modifications, as Covered Software and/or as part of a Larger Work; and
31
* (b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: (1) Modifications made by that Contributor (or portions thereof); and (2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination).
32
* (c) The licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first distributes or otherwise makes the Modifications available to a third party.
33
* (d) Notwithstanding Section 2.2(b) above, no patent license is granted: (1) for any code that Contributor has deleted from the Contributor Version; (2) for infringements caused by: (i) third party modifications of Contributor Version, or (ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or (3) under Patent Claims infringed by Covered Software in the absence of Modifications made by that Contributor.
34
* 3. Distribution Obligations.
35
* 3.1. Availability of Source Code.
36
* Any Covered Software that You distribute or otherwise make available in Executable form must also be made available in Source Code form and that Source Code form must be distributed only under the terms of this License. You must include a copy of this License with every copy of the Source Code form of the Covered Software You distribute or otherwise make available. You must inform recipients of any such Covered Software in Executable form as to how they can obtain such Covered Software in Source Code form in a reasonable manner on or through a medium customarily used for software exchange.
37
* 3.2. Modifications.
38
* The Modifications that You create or to which You contribute are governed by the terms of this License. You represent that You believe Your Modifications are Your original creation(s) and/or You have sufficient rights to grant the rights conveyed by this License.
39
* 3.3. Required Notices.
40
* You must include a notice in each of Your Modifications that identifies You as the Contributor of the Modification. You may not remove or alter any copyright, patent or trademark notices contained within the Covered Software, or any notices of licensing or any descriptive text giving attribution to any Contributor or the Initial Developer.
41
* 3.4. Application of Additional Terms.
42
* You may not offer or impose any terms on any Covered Software in Source Code form that alters or restricts the applicable version of this License or the recipients� rights hereunder. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, you may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear that any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer.
43
* 3.5. Distribution of Executable Versions.
44
* You may distribute the Executable form of the Covered Software under the terms of this License or under the terms of a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable form does not attempt to limit or alter the recipient�s rights in the Source Code form from the rights set forth in this License. If You distribute the Covered Software in Executable form under a different license, You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer.
45
* 3.6. Larger Works.
46
* You may create a Larger Work by combining Covered Software with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Software.
47
* 4. Versions of the License.
48
* 4.1. New Versions.
49
* Oracle Corp. is the initial license steward and may publish revised and/or new versions of this License from time to time. Each version will be given a distinguishing version number. Except as provided in Section 4.3, no one other than the license steward has the right to modify this License.
50
* 4.2. Effect of New Versions.
51
* You may always continue to use, distribute or otherwise make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. If the Initial Developer includes a notice in the Original Software prohibiting it from being distributed or otherwise made available under any subsequent version of the License, You must distribute and make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. Otherwise, You may also choose to use, distribute or otherwise make the Covered Software available under the terms of any subsequent version of the License published by the license steward.
52
* 4.3. Modified Versions.
53
* When You are an Initial Developer and You want to create a new license for Your Original Software, You may create and use a modified version of this License if You: (a) rename the license and remove any references to the name of the license steward (except to note that the license differs from this License); and (b) otherwise make it clear that the license contains terms which differ from this License.
54
* 5. DISCLAIMER OF WARRANTY.
55
* COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
56
* 6. TERMINATION.
57
* 6.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive.
58
* 6.2. If You assert a patent infringement claim (excluding declaratory judgment actions) against Initial Developer or a Contributor (the Initial Developer or Contributor against whom You assert such claim is referred to as "Participant") alleging that the Participant Software (meaning the Contributor Version where the Participant is a Contributor or the Original Software where the Participant is the Initial Developer) directly or indirectly infringes any patent, then any and all rights granted directly or indirectly to You by such Participant, the Initial Developer (if the Initial Developer is not the Participant) and all Contributors under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively and automatically at the expiration of such 60 day notice period, unless if within such 60 day period You withdraw Your claim with respect to the Participant Software against such Participant either unilaterally or pursuant to a written agreement with Participant.
59
* 6.3. In the event of termination under Sections 6.1 or 6.2 above, all end user licenses that have been validly granted by You or any distributor hereunder prior to termination (excluding licenses granted to You by any distributor) shall survive termination.
60
* 7. LIMITATION OF LIABILITY.
61
* UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTY�S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
62
* 8. U.S. GOVERNMENT END USERS.
63
* The Covered Software is a "commercial item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" (as that term is defined at 48 C.F.R. �252.227-7014(a)(1)) and "commercial computer software documentation" as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Software with only those rights set forth herein. This U.S. Government Rights clause is in lieu of, and supersedes, any other FAR, DFAR, or other clause or provision that addresses Government rights in computer software under this License.
64
* 9. MISCELLANEOUS.
65
* This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by the law of the jurisdiction specified in a notice contained within the Original Software (except to the extent applicable law, if any, provides otherwise), excluding such jurisdiction�s conflict-of-law provisions. Any litigation relating to this License shall be subject to the jurisdiction of the courts located in the jurisdiction and venue specified in a notice contained within the Original Software, with the losing party responsible for costs, including, without limitation, court costs and reasonable attorneys� fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. You agree that You alone are responsible for compliance with the United States export administration regulations (and the export control laws and regulation of any other countries) when You use, distribute or otherwise make available any Covered Software.
66
* 10. RESPONSIBILITY FOR CLAIMS.
67
* As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability.
68
* NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL)
69
* The code released under the CDDL shall be governed by the laws of the State of California (excluding conflict-of-law provisions). Any litigation relating to this License shall be subject to the jurisdiction of the Federal Courts of the Northern District of California and the state courts of the State of California, with venue lying in Santa Clara County, California.
70
 */
71
//</editor-fold>
72
package org.netbeans.spi.viewmodel;
73
74
import java.util.List;
75
76
/**
77
 *
78
 * @author paolo
79
 */
80
public interface ColumnsModel extends Model {
81
82
    List<? extends ColumnModel> getColumnModels();
83
84
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/DnDNodeModelFilter.java (-18 / +24 lines)
Lines 39-45 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.spi.viewmodel;
42
package org.netbeans.spi.viewmodel;
44
43
45
import java.awt.datatransfer.Transferable;
44
import java.awt.datatransfer.Transferable;
Lines 55-74 Link Here
55
public interface DnDNodeModelFilter extends NodeModelFilter {
54
public interface DnDNodeModelFilter extends NodeModelFilter {
56
55
57
    /**
56
    /**
58
     * Action constants from {@link java.awt.dnd.DnDConstants}.
57
     * Action constants from {@link java.awt.dnd.DnDConstants}. No actions are
59
     * No actions are allowed by default.
58
     * allowed by default.
59
     *
60
     * @param original The original DnDNodeModel to filter
60
     * @param original The original DnDNodeModel to filter
61
     * @return int representing set of actions which are allowed when dragging from
61
     * @return int representing set of actions which are allowed when dragging
62
     * asociated component.
62
     * from asociated component.
63
     */
63
     */
64
    int getAllowedDragActions(DnDNodeModel original);
64
    int getAllowedDragActions(DnDNodeModel original);
65
65
66
    /**
66
    /**
67
     * Action constants from {@link java.awt.dnd.DnDConstants}.
67
     * Action constants from {@link java.awt.dnd.DnDConstants}. No actions are
68
     * No actions are allowed by default.
68
     * allowed by default.
69
     *
69
     * @param original The original DnDNodeModel to filter
70
     * @param original The original DnDNodeModel to filter
70
     * @param t The transferable for which the allowed drop actions are requested,
71
     * @param t The transferable for which the allowed drop actions are
71
     *          or <code>null</code> to get actions for the creation of DropTarget for the view.
72
     * requested, or <code>null</code> to get actions for the creation of
73
     * DropTarget for the view.
72
     * @return int representing set of actions which are allowed when dropping
74
     * @return int representing set of actions which are allowed when dropping
73
     * the transferable into the asociated component.
75
     * the transferable into the asociated component.
74
     */
76
     */
Lines 76-102 Link Here
76
78
77
    /**
79
    /**
78
     * Initiate a drag operation.
80
     * Initiate a drag operation.
81
     *
79
     * @param original The original DnDNodeModel to filter
82
     * @param original The original DnDNodeModel to filter
80
     * @param node The node to drag
83
     * @param node The node to drag
81
     * @return transferable to represent this node during a drag
84
     * @return transferable to represent this node during a drag
82
     * @throws IOException when the drag cannot be performed
85
     * @throws IOException when the drag cannot be performed
83
     * @throws UnknownTypeException if this model implementation is not
86
     * @throws UnknownTypeException if this model implementation is not able to
84
     *          able to perform drag for given node type
87
     * perform drag for given node type
85
     */
88
     */
86
    Transferable drag(DnDNodeModel original, Object node) throws IOException, UnknownTypeException;
89
    Transferable drag(DnDNodeModel original, Object node) throws IOException, UnknownTypeException;
87
90
88
    /**
91
    /**
89
     * Determines if there is a paste operation that can be performed
92
     * Determines if there is a paste operation that can be performed on
90
     * on provided transferable when drop is done.
93
     * provided transferable when drop is done.
91
     *
94
     *
92
     * @param original The original DnDNodeModel to filter
95
     * @param original The original DnDNodeModel to filter
93
     * @param node The node where to drop
96
     * @param node The node where to drop
94
     * @param t the transferable to drop
97
     * @param t the transferable to drop
95
     * @param action the Drag and Drop action from {@link java.awt.dnd.DnDConstants}
98
     * @param action the Drag and Drop action from
96
     * @param index index between children the drop occured at or -1 if not specified
99
     * {@link java.awt.dnd.DnDConstants}
97
     * @return the paste type or <code>null</code> when the transferable cannot be accepted
100
     * @param index index between children the drop occured at or -1 if not
98
     * @throws UnknownTypeException if this model implementation is not
101
     * specified
99
     *          able to perform drop for given node type
102
     * @return the paste type or <code>null</code> when the transferable cannot
103
     * be accepted
104
     * @throws UnknownTypeException if this model implementation is not able to
105
     * perform drop for given node type
100
     */
106
     */
101
    PasteType getDropType(DnDNodeModel original, Object object, Transferable t, int action, int index)
107
    PasteType getDropType(DnDNodeModel original, Object object, Transferable t, int action, int index)
102
            throws UnknownTypeException;
108
            throws UnknownTypeException;
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/DnDNodeModel.java (-17 / +22 lines)
Lines 39-45 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.spi.viewmodel;
42
package org.netbeans.spi.viewmodel;
44
43
45
import java.awt.datatransfer.Transferable;
44
import java.awt.datatransfer.Transferable;
Lines 55-72 Link Here
55
public interface DnDNodeModel extends NodeModel {
54
public interface DnDNodeModel extends NodeModel {
56
55
57
    /**
56
    /**
58
     * Action constants from {@link java.awt.dnd.DnDConstants}.
57
     * Action constants from {@link java.awt.dnd.DnDConstants}. No actions are
59
     * No actions are allowed by default.
58
     * allowed by default.
60
     * @return int representing set of actions which are allowed when dragging from
59
     *
61
     * asociated component.
60
     * @return int representing set of actions which are allowed when dragging
61
     * from asociated component.
62
     */
62
     */
63
    int getAllowedDragActions();
63
    int getAllowedDragActions();
64
64
65
    /**
65
    /**
66
     * Action constants from {@link java.awt.dnd.DnDConstants}.
66
     * Action constants from {@link java.awt.dnd.DnDConstants}. No actions are
67
     * No actions are allowed by default.
67
     * allowed by default.
68
     * @param t The transferable for which the allowed drop actions are requested,
68
     *
69
     *          or <code>null</code> to get actions for the creation of DropTarget for the view.
69
     * @param t The transferable for which the allowed drop actions are
70
     * requested, or <code>null</code> to get actions for the creation of
71
     * DropTarget for the view.
70
     * @return int representing set of actions which are allowed when dropping
72
     * @return int representing set of actions which are allowed when dropping
71
     * the transferable into the asociated component.
73
     * the transferable into the asociated component.
72
     */
74
     */
Lines 74-98 Link Here
74
76
75
    /**
77
    /**
76
     * Initiate a drag operation.
78
     * Initiate a drag operation.
79
     *
77
     * @param node The node to drag
80
     * @param node The node to drag
78
     * @return transferable to represent this node during a drag
81
     * @return transferable to represent this node during a drag
79
     * @throws IOException when the drag cannot be performed
82
     * @throws IOException when the drag cannot be performed
80
     * @throws UnknownTypeException if this model implementation is not
83
     * @throws UnknownTypeException if this model implementation is not able to
81
     *          able to perform drag for given node type
84
     * perform drag for given node type
82
     */
85
     */
83
    Transferable drag(Object node) throws IOException, UnknownTypeException;
86
    Transferable drag(Object node) throws IOException, UnknownTypeException;
84
87
85
    /**
88
    /**
86
     * Determines if there is a paste operation that can be performed
89
     * Determines if there is a paste operation that can be performed on
87
     * on provided transferable when drop is done.
90
     * provided transferable when drop is done.
88
     *
91
     *
89
     * @param node The node where to drop
92
     * @param node The node where to drop
90
     * @param t the transferable to drop
93
     * @param t the transferable to drop
91
     * @param action the Drag and Drop action from {@link java.awt.dnd.DnDConstants}
94
     * @param action the Drag and Drop action from
92
     * @param index index between children the drop occured at or -1 if not specified
95
     * {@link java.awt.dnd.DnDConstants}
96
     * @param index index between children the drop occured at or -1 if not
97
     * specified
93
     * @return null if the transferable cannot be accepted
98
     * @return null if the transferable cannot be accepted
94
     * @throws UnknownTypeException if this model implementation is not
99
     * @throws UnknownTypeException if this model implementation is not able to
95
     *          able to perform drop for given node type
100
     * perform drop for given node type
96
     */
101
     */
97
    PasteType getDropType(Object node, Transferable t, int action, int index)
102
    PasteType getDropType(Object node, Transferable t, int action, int index)
98
            throws UnknownTypeException;
103
            throws UnknownTypeException;
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/ExtendedNodeModelFilter.java (-29 / +38 lines)
Lines 41-83 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
import java.awt.datatransfer.Transferable;
46
import java.awt.datatransfer.Transferable;
48
import java.io.IOException;
47
import java.io.IOException;
49
import org.openide.util.datatransfer.PasteType;
48
import org.openide.util.datatransfer.PasteType;
50
49
51
52
/**
50
/**
53
 * Provides extension to {@link NodeModelFilter},
51
 * Provides extension to {@link NodeModelFilter}, filters content of some
54
 * filters content of some existing {@link ExtendedNodeModel}.
52
 * existing {@link ExtendedNodeModel}.
55
 *
53
 *
56
 * @author   Martin Entlicher
54
 * @author Martin Entlicher
57
 * @since 1.12
55
 * @since 1.12
58
 */
56
 */
59
public interface ExtendedNodeModelFilter extends NodeModelFilter {
57
public interface ExtendedNodeModelFilter extends NodeModelFilter {
60
    
58
61
    /**
59
    /**
62
     * Test whether this node permits renaming.
60
     * Test whether this node permits renaming.
61
     *
63
     * @return <code>true</code> if so
62
     * @return <code>true</code> if so
64
     */
63
     */
65
    public abstract boolean canRename(ExtendedNodeModel original, Object node) throws UnknownTypeException;
64
    public abstract boolean canRename(ExtendedNodeModel original, Object node) throws UnknownTypeException;
66
65
67
    /**
66
    /**
68
     * Test whether this node permits copying.
67
     * Test whether this node permits copying.
68
     *
69
     * @return <code>true</code> if so
69
     * @return <code>true</code> if so
70
     */
70
     */
71
    public abstract boolean canCopy(ExtendedNodeModel original, Object node) throws UnknownTypeException;
71
    public abstract boolean canCopy(ExtendedNodeModel original, Object node) throws UnknownTypeException;
72
72
73
    /**
73
    /**
74
     * Test whether this node permits cutting.
74
     * Test whether this node permits cutting.
75
     *
75
     * @return <code>true</code> if so
76
     * @return <code>true</code> if so
76
     */
77
     */
77
    public abstract boolean canCut(ExtendedNodeModel original, Object node) throws UnknownTypeException;
78
    public abstract boolean canCut(ExtendedNodeModel original, Object node) throws UnknownTypeException;
78
79
79
    /**
80
    /**
80
     * Called when a node is to be copied to the clipboard.
81
     * Called when a node is to be copied to the clipboard.
82
     *
81
     * @param node The node object
83
     * @param node The node object
82
     * @return the transferable object representing the content of the clipboard
84
     * @return the transferable object representing the content of the clipboard
83
     * @exception IOException when the copy cannot be performed
85
     * @exception IOException when the copy cannot be performed
Lines 86-91 Link Here
86
88
87
    /**
89
    /**
88
     * Called when a node is to be cut to the clipboard.
90
     * Called when a node is to be cut to the clipboard.
91
     *
89
     * @param node The node object
92
     * @param node The node object
90
     * @return the transferable object representing the content of the clipboard
93
     * @return the transferable object representing the content of the clipboard
91
     * @exception IOException when the cut cannot be performed
94
     * @exception IOException when the cut cannot be performed
Lines 93-149 Link Here
93
    public abstract Transferable clipboardCut(ExtendedNodeModel original, Object node) throws IOException, UnknownTypeException;
96
    public abstract Transferable clipboardCut(ExtendedNodeModel original, Object node) throws IOException, UnknownTypeException;
94
97
95
    /**
98
    /**
96
     * Called when a drag is started with this node.
99
     * Called when a drag is started with this node. The node can attach a
97
     * The node can attach a transfer listener to ExTransferable and
100
     * transfer listener to ExTransferable and will be then notified about
98
     * will be then notified about progress of the drag (accept/reject).
101
     * progress of the drag (accept/reject).
99
     *
102
     *
100
     * @param node The node object
103
     * @param node The node object
101
     * @return transferable to represent this node during a drag
104
     * @return transferable to represent this node during a drag
102
     * @exception IOException if a drag cannot be started
105
     * @exception IOException if a drag cannot be started
103
     *
106
     *
104
    public abstract Transferable drag(ExtendedNodeModel original, Object node) throws IOException, UnknownTypeException;
107
     * public abstract Transferable drag(ExtendedNodeModel original, Object
108
     * node) throws IOException, UnknownTypeException;
105
     */
109
     */
106
107
    /**
110
    /**
108
     * Determine which paste operations are allowed when a given transferable is in the clipboard.
111
     * Determine which paste operations are allowed when a given transferable is
109
     * For example, a node representing a Java package will permit classes to be pasted into it.
112
     * in the clipboard. For example, a node representing a Java package will
113
     * permit classes to be pasted into it.
114
     *
110
     * @param node The node object
115
     * @param node The node object
111
     * @param t the transferable in the clipboard
116
     * @param t the transferable in the clipboard
112
     * @return array of operations that are allowed
117
     * @return array of operations that are allowed
113
     */
118
     */
114
    public abstract PasteType[] getPasteTypes(ExtendedNodeModel original, Object node, Transferable t) throws UnknownTypeException;
119
    public abstract PasteType[] getPasteTypes(ExtendedNodeModel original, Object node, Transferable t) throws UnknownTypeException;
115
120
116
    /** Determine if there is a paste operation that can be performed
121
    /**
117
     * on provided transferable. Used by drag'n'drop code to check
122
     * Determine if there is a paste operation that can be performed on provided
118
     * whether the drop is possible.
123
     * transferable. Used by drag'n'drop code to check whether the drop is
124
     * possible.
119
     *
125
     *
120
     * @param node The node object
126
     * @param node The node object
121
     * @param t the transferable
127
     * @param t the transferable
122
     * @param action the drag'n'drop action to do DnDConstants.ACTION_MOVE, ACTION_COPY, ACTION_LINK
128
     * @param action the drag'n'drop action to do DnDConstants.ACTION_MOVE,
123
     * @param index index between children the drop occurred at or -1 if not specified
129
     * ACTION_COPY, ACTION_LINK
124
     * @return null if the transferable cannot be accepted or the paste type
130
     * @param index index between children the drop occurred at or -1 if not
125
     *    to execute when the drop occurs
131
     * specified
132
     * @return null if the transferable cannot be accepted or the paste type to
133
     * execute when the drop occurs
126
     *
134
     *
127
    public abstract PasteType getDropType(ExtendedNodeModel original, Object node, Transferable t, int action, int index) throws UnknownTypeException;
135
     * public abstract PasteType getDropType(ExtendedNodeModel original, Object
136
     * node, Transferable t, int action, int index) throws UnknownTypeException;
128
     */
137
     */
129
130
    /**
138
    /**
131
     * Sets a new name for given node.
139
     * Sets a new name for given node.
132
     *
140
     *
133
     * @param node The object to set the new name to.
141
     * @param node The object to set the new name to.
134
     * @param name The new name for the given node
142
     * @param name The new name for the given node
135
     */
143
     */
136
    public abstract void setName (ExtendedNodeModel original, Object node, String name) throws UnknownTypeException;
144
    public abstract void setName(ExtendedNodeModel original, Object node, String name) throws UnknownTypeException;
137
145
138
    /**
146
    /**
139
     * Returns icon resource with extension for given node.
147
     * Returns icon resource with extension for given node. This is the
140
     * This is the preferred way of icon specification over {@link org.netbeans.spi.viewmodel.NodeModel.getIconBase}
148
     * preferred way of icon specification over
149
     * {@link org.netbeans.spi.viewmodel.NodeModel.getIconBase}
141
     *
150
     *
142
     * @param node The node object
151
     * @param node The node object
143
     * @return The base resouce name with extension (no initial slash)
152
     * @return The base resouce name with extension (no initial slash)
144
     * @throws  UnknownTypeException if this NodeModel implementation is not
153
     * @throws UnknownTypeException if this NodeModel implementation is not able
145
     *          able to resolve icon for given node type
154
     * to resolve icon for given node type
146
     */
155
     */
147
    public abstract String getIconBaseWithExtension (ExtendedNodeModel original, Object node) throws UnknownTypeException;
156
    public abstract String getIconBaseWithExtension(ExtendedNodeModel original, Object node) throws UnknownTypeException;
148
    
157
149
}
158
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/ExtendedNodeModel.java (-28 / +36 lines)
Lines 41-84 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
import java.awt.datatransfer.Transferable;
46
import java.awt.datatransfer.Transferable;
48
import java.io.IOException;
47
import java.io.IOException;
49
50
import org.openide.util.datatransfer.PasteType;
48
import org.openide.util.datatransfer.PasteType;
51
49
52
53
/**
50
/**
54
 * Provides extension to {@link NodeModel} with cut/copy/paste and rename
51
 * Provides extension to {@link NodeModel} with cut/copy/paste and rename
55
 * functionality, and also allowing to set icons with extension.
52
 * functionality, and also allowing to set icons with extension.
56
 *
53
 *
57
 * @author   Martin Entlicher
54
 * @author Martin Entlicher
58
 * @since 1.12
55
 * @since 1.12
59
 */
56
 */
60
public interface ExtendedNodeModel extends NodeModel {
57
public interface ExtendedNodeModel extends NodeModel {
61
    
58
62
    /**
59
    /**
63
     * Test whether this node permits renaming.
60
     * Test whether this node permits renaming.
61
     *
64
     * @return <code>true</code> if so
62
     * @return <code>true</code> if so
65
     */
63
     */
66
    public abstract boolean canRename(Object node) throws UnknownTypeException;
64
    public abstract boolean canRename(Object node) throws UnknownTypeException;
67
65
68
    /**
66
    /**
69
     * Test whether this node permits copying.
67
     * Test whether this node permits copying.
68
     *
70
     * @return <code>true</code> if so
69
     * @return <code>true</code> if so
71
     */
70
     */
72
    public abstract boolean canCopy(Object node) throws UnknownTypeException;
71
    public abstract boolean canCopy(Object node) throws UnknownTypeException;
73
72
74
    /**
73
    /**
75
     * Test whether this node permits cutting.
74
     * Test whether this node permits cutting.
75
     *
76
     * @return <code>true</code> if so
76
     * @return <code>true</code> if so
77
     */
77
     */
78
    public abstract boolean canCut(Object node) throws UnknownTypeException;
78
    public abstract boolean canCut(Object node) throws UnknownTypeException;
79
79
80
    /**
80
    /**
81
     * Called when a node is to be copied to the clipboard.
81
     * Called when a node is to be copied to the clipboard.
82
     *
82
     * @param node The node object
83
     * @param node The node object
83
     * @return the transferable object representing the content of the clipboard
84
     * @return the transferable object representing the content of the clipboard
84
     * @exception IOException when the copy cannot be performed
85
     * @exception IOException when the copy cannot be performed
Lines 87-92 Link Here
87
88
88
    /**
89
    /**
89
     * Called when a node is to be cut to the clipboard.
90
     * Called when a node is to be cut to the clipboard.
91
     *
90
     * @param node The node object
92
     * @param node The node object
91
     * @return the transferable object representing the content of the clipboard
93
     * @return the transferable object representing the content of the clipboard
92
     * @exception IOException when the cut cannot be performed
94
     * @exception IOException when the cut cannot be performed
Lines 94-150 Link Here
94
    public abstract Transferable clipboardCut(Object node) throws IOException, UnknownTypeException;
96
    public abstract Transferable clipboardCut(Object node) throws IOException, UnknownTypeException;
95
97
96
    /**
98
    /**
97
     * Called when a drag is started with this node.
99
     * Called when a drag is started with this node. The node can attach a
98
     * The node can attach a transfer listener to ExTransferable and
100
     * transfer listener to ExTransferable and will be then notified about
99
     * will be then notified about progress of the drag (accept/reject).
101
     * progress of the drag (accept/reject).
100
     *
102
     *
101
     * @param node The node object
103
     * @param node The node object
102
     * @return transferable to represent this node during a drag
104
     * @return transferable to represent this node during a drag
103
     * @exception IOException if a drag cannot be started
105
     * @exception IOException if a drag cannot be started
104
     *
106
     *
105
    public abstract Transferable drag(Object node) throws IOException, UnknownTypeException;
107
     * public abstract Transferable drag(Object node) throws IOException,
108
     * UnknownTypeException;
106
     */
109
     */
107
108
    /**
110
    /**
109
     * Determine which paste operations are allowed when a given transferable is in the clipboard.
111
     * Determine which paste operations are allowed when a given transferable is
110
     * For example, a node representing a Java package will permit classes to be pasted into it.
112
     * in the clipboard. For example, a node representing a Java package will
113
     * permit classes to be pasted into it.
114
     *
111
     * @param node The node object
115
     * @param node The node object
112
     * @param t the transferable in the clipboard
116
     * @param t the transferable in the clipboard
113
     * @return array of operations that are allowed
117
     * @return array of operations that are allowed
114
     */
118
     */
115
    public abstract PasteType[] getPasteTypes(Object node, Transferable t) throws UnknownTypeException;
119
    public abstract PasteType[] getPasteTypes(Object node, Transferable t) throws UnknownTypeException;
116
120
117
    /** Determine if there is a paste operation that can be performed
121
    /**
118
     * on provided transferable. Used by drag'n'drop code to check
122
     * Determine if there is a paste operation that can be performed on provided
119
     * whether the drop is possible.
123
     * transferable. Used by drag'n'drop code to check whether the drop is
124
     * possible.
120
     *
125
     *
121
     * @param node The node object
126
     * @param node The node object
122
     * @param t the transferable
127
     * @param t the transferable
123
     * @param action the drag'n'drop action to do DnDConstants.ACTION_MOVE, ACTION_COPY, ACTION_LINK
128
     * @param action the drag'n'drop action to do DnDConstants.ACTION_MOVE,
124
     * @param index index between children the drop occurred at or -1 if not specified
129
     * ACTION_COPY, ACTION_LINK
125
     * @return null if the transferable cannot be accepted or the paste type
130
     * @param index index between children the drop occurred at or -1 if not
126
     *    to execute when the drop occurs
131
     * specified
132
     * @return null if the transferable cannot be accepted or the paste type to
133
     * execute when the drop occurs
127
     *
134
     *
128
    public abstract PasteType getDropType(Object node, Transferable t, int action, int index) throws UnknownTypeException;
135
     * public abstract PasteType getDropType(Object node, Transferable t, int
136
     * action, int index) throws UnknownTypeException;
129
     */
137
     */
130
131
    /**
138
    /**
132
     * Sets a new name for given node.
139
     * Sets a new name for given node.
133
     *
140
     *
134
     * @param node The object to set the new name to.
141
     * @param node The object to set the new name to.
135
     * @param name The new name for the given node
142
     * @param name The new name for the given node
136
     */
143
     */
137
    public abstract void setName (Object node, String name) throws UnknownTypeException;
144
    public abstract void setName(Object node, String name) throws UnknownTypeException;
138
145
139
    /**
146
    /**
140
     * Returns icon resource with extension for given node.
147
     * Returns icon resource with extension for given node. This is the
141
     * This is the preferred way of icon specification over {@link org.netbeans.spi.viewmodel.NodeModel.getIconBase}
148
     * preferred way of icon specification over
149
     * {@link org.netbeans.spi.viewmodel.NodeModel.getIconBase}
142
     *
150
     *
143
     * @param node The node object
151
     * @param node The node object
144
     * @return The base resouce name with extension (no initial slash)
152
     * @return The base resouce name with extension (no initial slash)
145
     * @throws  UnknownTypeException if this NodeModel implementation is not
153
     * @throws UnknownTypeException if this NodeModel implementation is not able
146
     *          able to resolve icon for given node type
154
     * to resolve icon for given node type
147
     */
155
     */
148
    public abstract String getIconBaseWithExtension (Object node) throws UnknownTypeException;
156
    public abstract String getIconBaseWithExtension(Object node) throws UnknownTypeException;
149
    
157
150
}
158
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/IconNodeModel.java (+69 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.viewmodel;
43
44
import java.awt.Image;
45
46
/**
47
 *
48
 * @author matteo
49
 */
50
public interface IconNodeModel extends Model {
51
52
    /**
53
     * Find an icon for this node. Uses an {@link #setIconBase icon set}.
54
     *
55
     * @param type constants from {@link java.beans.BeanInfo}
56
     *
57
     * @return icon to use to represent the bean
58
     */
59
    public Image getIcon(Object node, int type) throws UnknownTypeException;
60
61
    /**
62
     * Finds an icon for this node when opened. This icon should represent the
63
     * node only when it is opened (when it can have children).
64
     *
65
     * @param type as in {@link #getIcon}
66
     * @return icon to use to represent the bean when opened
67
     */
68
    public Image getOpenedIcon(Object node, int type) throws UnknownTypeException;
69
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/LookupNodeModel.java (+83 lines)
Line 0 Link Here
1
//<editor-fold defaultstate="collapsed" desc="CDDL">
2
/*COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
3
*
4
* 1. Definitions.
5
* 1.1. "Contributor" means each individual or entity that creates or contributes to the creation of Modifications.
6
* 1.2. "Contributor Version" means the combination of the Original Software, prior Modifications used by a Contributor (if any), and the Modifications made by that particular Contributor.
7
* 1.3. "Covered Software" means (a) the Original Software, or (b) Modifications, or (c) the combination of files containing Original Software with files containing Modifications, in each case including portions thereof.
8
* 1.4. "Executable" means the Covered Software in any form other than Source Code.
9
* 1.5. "Initial Developer" means the individual or entity that first makes Original Software available under this License.
10
* 1.6. "Larger Work" means a work which combines Covered Software or portions thereof with code not governed by the terms of this License.
11
* 1.7. "License" means this document.
12
* 1.8. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein.
13
* 1.9 "Modifications" means the Source Code and Executable form of any of the following:
14
* A. Any file that results from an addition to, deletion from or modification of the contents of a file containing Original Software or previous Modifications;
15
* B. Any new file that contains any part of the Original Software or previous Modification; or
16
* C. Any new file that is contributed or otherwise made available under the terms of this License.
17
* 1.10. "Original Software" means the Source Code and Executable form of computer software code that is originally released under this License.
18
* 1.11. "Patent Claims" means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor.
19
* 1.12. "Source Code" means (a) the common form of computer software code in which modifications are made and (b) associated documentation included in or with such code.
20
* 1.13. "You" (or "Your") means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
21
* 2. License Grants.
22
* 2.1. The Initial Developer Grant.
23
* Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, the Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license:
24
* (a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer, to use, reproduce, modify, display, perform, sublicense and distribute the Original Software (or portions thereof), with or without Modifications, and/or as part of a Larger Work; and
25
* (b) under Patent Claims infringed by the making, using or selling of Original Software, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Software (or portions thereof).
26
* (c) The licenses granted in Sections 2.1(a) and (b) are effective on the date Initial Developer first distributes or otherwise makes the Original Software available to a third party under the terms of this License.
27
* (d) Notwithstanding Section 2.1(b) above, no patent license is granted: (1) for code that You delete from the Original Software, or (2) for infringements caused by: (i) the modification of the Original Software, or (ii) the combination of the Original Software with other software or devices.
28
* 2.2. Contributor Grant.
29
* Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
30
* (a) under intellectual property rights (other than patent or trademark) Licensable by Contributor to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof), either on an unmodified basis, with other Modifications, as Covered Software and/or as part of a Larger Work; and
31
* (b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: (1) Modifications made by that Contributor (or portions thereof); and (2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination).
32
* (c) The licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first distributes or otherwise makes the Modifications available to a third party.
33
* (d) Notwithstanding Section 2.2(b) above, no patent license is granted: (1) for any code that Contributor has deleted from the Contributor Version; (2) for infringements caused by: (i) third party modifications of Contributor Version, or (ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or (3) under Patent Claims infringed by Covered Software in the absence of Modifications made by that Contributor.
34
* 3. Distribution Obligations.
35
* 3.1. Availability of Source Code.
36
* Any Covered Software that You distribute or otherwise make available in Executable form must also be made available in Source Code form and that Source Code form must be distributed only under the terms of this License. You must include a copy of this License with every copy of the Source Code form of the Covered Software You distribute or otherwise make available. You must inform recipients of any such Covered Software in Executable form as to how they can obtain such Covered Software in Source Code form in a reasonable manner on or through a medium customarily used for software exchange.
37
* 3.2. Modifications.
38
* The Modifications that You create or to which You contribute are governed by the terms of this License. You represent that You believe Your Modifications are Your original creation(s) and/or You have sufficient rights to grant the rights conveyed by this License.
39
* 3.3. Required Notices.
40
* You must include a notice in each of Your Modifications that identifies You as the Contributor of the Modification. You may not remove or alter any copyright, patent or trademark notices contained within the Covered Software, or any notices of licensing or any descriptive text giving attribution to any Contributor or the Initial Developer.
41
* 3.4. Application of Additional Terms.
42
* You may not offer or impose any terms on any Covered Software in Source Code form that alters or restricts the applicable version of this License or the recipients� rights hereunder. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, you may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear that any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer.
43
* 3.5. Distribution of Executable Versions.
44
* You may distribute the Executable form of the Covered Software under the terms of this License or under the terms of a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable form does not attempt to limit or alter the recipient�s rights in the Source Code form from the rights set forth in this License. If You distribute the Covered Software in Executable form under a different license, You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer.
45
* 3.6. Larger Works.
46
* You may create a Larger Work by combining Covered Software with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Software.
47
* 4. Versions of the License.
48
* 4.1. New Versions.
49
* Oracle Corp. is the initial license steward and may publish revised and/or new versions of this License from time to time. Each version will be given a distinguishing version number. Except as provided in Section 4.3, no one other than the license steward has the right to modify this License.
50
* 4.2. Effect of New Versions.
51
* You may always continue to use, distribute or otherwise make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. If the Initial Developer includes a notice in the Original Software prohibiting it from being distributed or otherwise made available under any subsequent version of the License, You must distribute and make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. Otherwise, You may also choose to use, distribute or otherwise make the Covered Software available under the terms of any subsequent version of the License published by the license steward.
52
* 4.3. Modified Versions.
53
* When You are an Initial Developer and You want to create a new license for Your Original Software, You may create and use a modified version of this License if You: (a) rename the license and remove any references to the name of the license steward (except to note that the license differs from this License); and (b) otherwise make it clear that the license contains terms which differ from this License.
54
* 5. DISCLAIMER OF WARRANTY.
55
* COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
56
* 6. TERMINATION.
57
* 6.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive.
58
* 6.2. If You assert a patent infringement claim (excluding declaratory judgment actions) against Initial Developer or a Contributor (the Initial Developer or Contributor against whom You assert such claim is referred to as "Participant") alleging that the Participant Software (meaning the Contributor Version where the Participant is a Contributor or the Original Software where the Participant is the Initial Developer) directly or indirectly infringes any patent, then any and all rights granted directly or indirectly to You by such Participant, the Initial Developer (if the Initial Developer is not the Participant) and all Contributors under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively and automatically at the expiration of such 60 day notice period, unless if within such 60 day period You withdraw Your claim with respect to the Participant Software against such Participant either unilaterally or pursuant to a written agreement with Participant.
59
* 6.3. In the event of termination under Sections 6.1 or 6.2 above, all end user licenses that have been validly granted by You or any distributor hereunder prior to termination (excluding licenses granted to You by any distributor) shall survive termination.
60
* 7. LIMITATION OF LIABILITY.
61
* UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTY�S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
62
* 8. U.S. GOVERNMENT END USERS.
63
* The Covered Software is a "commercial item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" (as that term is defined at 48 C.F.R. �252.227-7014(a)(1)) and "commercial computer software documentation" as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Software with only those rights set forth herein. This U.S. Government Rights clause is in lieu of, and supersedes, any other FAR, DFAR, or other clause or provision that addresses Government rights in computer software under this License.
64
* 9. MISCELLANEOUS.
65
* This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by the law of the jurisdiction specified in a notice contained within the Original Software (except to the extent applicable law, if any, provides otherwise), excluding such jurisdiction�s conflict-of-law provisions. Any litigation relating to this License shall be subject to the jurisdiction of the courts located in the jurisdiction and venue specified in a notice contained within the Original Software, with the losing party responsible for costs, including, without limitation, court costs and reasonable attorneys� fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. You agree that You alone are responsible for compliance with the United States export administration regulations (and the export control laws and regulation of any other countries) when You use, distribute or otherwise make available any Covered Software.
66
* 10. RESPONSIBILITY FOR CLAIMS.
67
* As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability.
68
* NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL)
69
* The code released under the CDDL shall be governed by the laws of the State of California (excluding conflict-of-law provisions). Any litigation relating to this License shall be subject to the jurisdiction of the Federal Courts of the Northern District of California and the state courts of the State of California, with venue lying in Santa Clara County, California.
70
 */
71
//</editor-fold>
72
package org.netbeans.spi.viewmodel;
73
74
import org.openide.util.Lookup;
75
76
/**
77
 *
78
 * @author matteo
79
 */
80
public interface LookupNodeModel extends Model {
81
82
    public Lookup getLookup(Object node) throws UnknownTypeException;
83
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/ModelEvent.java (-54 / +104 lines)
Lines 41-64 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
import java.util.Arrays;
46
import java.util.Arrays;
47
import java.util.Collection;
48
import java.util.EventObject;
48
import java.util.EventObject;
49
49
import java.util.LinkedHashSet;
50
50
51
/**
51
/**
52
 * Encapsulates information describing changes to a model, and
52
 * Encapsulates information describing changes to a model, and used to notify
53
 * used to notify model listeners of the change.
53
 * model listeners of the change.
54
 *
54
 *
55
 * @author   Jan Jancura
55
 * @author Jan Jancura
56
 * @since 1.4
56
 * @since 1.4
57
 */
57
 */
58
public class ModelEvent extends EventObject {
58
public class ModelEvent extends EventObject {
59
59
60
    private ModelEvent (Object source) {
60
    private ModelEvent(Object source) {
61
        super (source);
61
        super(source);
62
    }
62
    }
63
63
64
    /**
64
    /**
Lines 75-112 Link Here
75
         *
75
         *
76
         * @since 1.4
76
         * @since 1.4
77
         */
77
         */
78
        public TreeChanged (Object source) {
78
        public TreeChanged(Object source) {
79
            super (source);
79
            super(source);
80
        }
80
        }
81
    }
81
    }
82
    
82
83
    /**
83
    /**
84
     * Used to notify that one cell in table has been changed.
84
     * Used to notify that one cell in table has been changed.
85
     *
85
     *
86
     * @since 1.4
86
     * @since 1.4
87
     */
87
     */
88
    public static class TableValueChanged extends ModelEvent {
88
    public static class TableValueChanged extends ModelEvent {
89
        
89
90
        /**
90
        /**
91
         * The mask for value change.
91
         * The mask for value change.
92
         *
92
         * @since 1.42
93
         * @since 1.42
93
         */
94
         */
94
        public static final int VALUE_MASK = 1;
95
        public static final int VALUE_MASK = 1;
95
        /**
96
        /**
96
         * The mask for HTML value change.
97
         * The mask for HTML value change.
98
         *
97
         * @since 1.42
99
         * @since 1.42
98
         */
100
         */
99
        public static final int HTML_VALUE_MASK = 2;
101
        public static final int HTML_VALUE_MASK = 2;
100
        /**
102
        /**
101
         * The mask for change of the read only state.
103
         * The mask for change of the read only state.
104
         *
102
         * @since 1.42
105
         * @since 1.42
103
         */
106
         */
104
        public static final int IS_READ_ONLY_MASK = 4;
107
        public static final int IS_READ_ONLY_MASK = 4;
105
        
108
106
        private Object node;
109
        private Object node;
107
        private String columnID;
110
        private Collection<String> columnIDs = new LinkedHashSet<>();
108
        private int change;
111
        private int change;
109
        
112
113
        @Deprecated
114
        public TableValueChanged(
115
                Object source,
116
                Object node
117
        ) {
118
            super(source);
119
            this.node = node;
120
            this.columnIDs.add(null);
121
            this.change = 0xffffffff;
122
        }
123
110
        /**
124
        /**
111
         * Creates a new instance of TableValueChanged event.
125
         * Creates a new instance of TableValueChanged event.
112
         *
126
         *
Lines 116-129 Link Here
116
         *
130
         *
117
         * @since 1.4
131
         * @since 1.4
118
         */
132
         */
119
        public TableValueChanged (
133
        public TableValueChanged(
120
            Object source, 
134
                Object source,
121
            Object node,
135
                Object node,
122
            String columnID
136
                String columnID
123
        ) {
137
        ) {
124
            this(source, node, columnID, 0xffffffff);
138
            this(source, node, columnID, 0xffffffff);
125
        }
139
        }
126
        
140
141
        public TableValueChanged(
142
                Object source,
143
                Object node,
144
                Collection<String> columnIDs
145
        ) {
146
            this(source, node, columnIDs, 0xffffffff);
147
        }
148
127
        /**
149
        /**
128
         * Creates a new instance of TableValueChanged event.
150
         * Creates a new instance of TableValueChanged event.
129
         *
151
         *
Lines 133-150 Link Here
133
         * @param change one of the *_MASK constants or their aggregation.
155
         * @param change one of the *_MASK constants or their aggregation.
134
         * @since 1.42
156
         * @since 1.42
135
         */
157
         */
136
        public TableValueChanged (
158
        public TableValueChanged(
137
            Object source, 
159
                Object source,
138
            Object node,
160
                Object node,
139
            String columnID,
161
                String columnID,
140
            int change
162
                int change
141
        ) {
163
        ) {
142
            super (source);
164
            super(source);
143
            this.node = node;
165
            this.node = node;
144
            this.columnID = columnID;
166
            this.columnIDs.add(columnID);
145
            this.change = change;
167
            this.change = change;
146
        }
168
        }
147
        
169
170
        /**
171
         * Creates a new instance of TableValueChanged event.
172
         *
173
         * @param source a source if event.
174
         * @param node a changed node instance
175
         * @param columnID a changed column name
176
         * @param change one of the *_MASK constants or their aggregation.
177
         * @since 1.42
178
         */
179
        public TableValueChanged(
180
                Object source,
181
                Object node,
182
                Collection<String> columnIDs,
183
                int change
184
        ) {
185
            super(source);
186
            this.node = node;
187
            this.columnIDs.addAll(columnIDs);
188
            this.change = change;
189
        }
190
148
        /**
191
        /**
149
         * Returns changed node instance.
192
         * Returns changed node instance.
150
         *
193
         *
Lines 152-161 Link Here
152
         *
195
         *
153
         * @since 1.4
196
         * @since 1.4
154
         */
197
         */
155
        public Object getNode () {
198
        public Object getNode() {
156
            return node;
199
            return node;
157
        }
200
        }
158
        
201
159
        /**
202
        /**
160
         * Returns changed column name.
203
         * Returns changed column name.
161
         *
204
         *
Lines 163-220 Link Here
163
         *
206
         *
164
         * @since 1.4
207
         * @since 1.4
165
         */
208
         */
166
        public String getColumnID () {
209
        public Collection<String> getColumnIDs() {
167
            return columnID;
210
            return columnIDs;
168
        }
211
        }
169
        
212
170
        /**
213
        /**
171
         * Get the change mask.
214
         * Get the change mask.
172
         *
215
         *
173
         * @return the change mask, one of the *_MASK constants or their aggregation.
216
         * @return the change mask, one of the *_MASK constants or their
217
         * aggregation.
174
         * @since 1.42
218
         * @since 1.42
175
         */
219
         */
176
        public int getChange() {
220
        public int getChange() {
177
            return change;
221
            return change;
178
        }
222
        }
179
    }
223
    }
180
    
224
181
    /**
225
    /**
182
     * Used to notify that one node has been changed (icon, displayName and 
226
     * Used to notify that one node has been changed (icon, displayName and
183
     * children).
227
     * children).
184
     *
228
     *
185
     * @since 1.4
229
     * @since 1.4
186
     */
230
     */
187
    public static class NodeChanged extends ModelEvent {
231
    public static class NodeChanged extends ModelEvent {
188
        
232
189
        /**
233
        /**
190
         * The mask for display name change.
234
         * The mask for display name change.
235
         *
191
         * @since 1.6
236
         * @since 1.6
192
         */
237
         */
193
        public static final int DISPLAY_NAME_MASK = 1;
238
        public static final int DISPLAY_NAME_MASK = 1;
194
        /**
239
        /**
195
         * The mask for icon change.
240
         * The mask for icon change.
241
         *
196
         * @since 1.6
242
         * @since 1.6
197
         */
243
         */
198
        public static final int ICON_MASK = 2;
244
        public static final int ICON_MASK = 2;
199
        /**
245
        /**
200
         * The mask for short description change.
246
         * The mask for short description change.
247
         *
201
         * @since 1.6
248
         * @since 1.6
202
         */
249
         */
203
        public static final int SHORT_DESCRIPTION_MASK = 4;
250
        public static final int SHORT_DESCRIPTION_MASK = 4;
204
        /**
251
        /**
205
         * The mask for children change.
252
         * The mask for children change.
253
         *
206
         * @since 1.6
254
         * @since 1.6
207
         */
255
         */
208
        public static final int CHILDREN_MASK = 8;
256
        public static final int CHILDREN_MASK = 8;
209
        /**
257
        /**
210
         * The mask for expansion change.
258
         * The mask for expansion change.
259
         *
211
         * @since 1.15
260
         * @since 1.15
212
         */
261
         */
213
        public static final int EXPANSION_MASK = 16;
262
        public static final int EXPANSION_MASK = 16;
214
        
263
215
        private Object node;
264
        private Object node;
216
        private int change;
265
        private int change;
217
        
266
218
        /**
267
        /**
219
         * Creates a new instance of NodeChanged event.
268
         * Creates a new instance of NodeChanged event.
220
         *
269
         *
Lines 223-235 Link Here
223
         *
272
         *
224
         * @since 1.4
273
         * @since 1.4
225
         */
274
         */
226
        public NodeChanged (
275
        public NodeChanged(
227
            Object source, 
276
                Object source,
228
            Object node
277
                Object node
229
        ) {
278
        ) {
230
            this (source, node, 0xFFFFFFFF);
279
            this(source, node, 0xFFFFFFFF);
231
        }
280
        }
232
        
281
233
        /**
282
        /**
234
         * Creates a new instance of NodeChanged event.
283
         * Creates a new instance of NodeChanged event.
235
         *
284
         *
Lines 240-250 Link Here
240
         * @since 1.6
289
         * @since 1.6
241
         */
290
         */
242
        public NodeChanged(Object source, Object node, int change) {
291
        public NodeChanged(Object source, Object node, int change) {
243
            super (source);
292
            super(source);
244
            this.node = node;
293
            this.node = node;
245
            this.change = change;
294
            this.change = change;
246
        }
295
        }
247
        
296
248
        /**
297
        /**
249
         * Returns changed node instance.
298
         * Returns changed node instance.
250
         *
299
         *
Lines 252-265 Link Here
252
         *
301
         *
253
         * @since 1.4
302
         * @since 1.4
254
         */
303
         */
255
        public Object getNode () {
304
        public Object getNode() {
256
            return node;
305
            return node;
257
        }
306
        }
258
        
307
259
        /**
308
        /**
260
         * Get the change mask.
309
         * Get the change mask.
261
         *
310
         *
262
         * @return the change mask, one of the *_MASK constant or their aggregation.
311
         * @return the change mask, one of the *_MASK constant or their
312
         * aggregation.
263
         * @since 1.6
313
         * @since 1.6
264
         */
314
         */
265
        public int getChange() {
315
        public int getChange() {
Lines 268-274 Link Here
268
318
269
        @Override
319
        @Override
270
        public String toString() {
320
        public String toString() {
271
            return super.toString()+"(node = "+node+", change = "+getChangeString(change)+")";
321
            return super.toString() + "(node = " + node + ", change = " + getChangeString(change) + ")";
272
        }
322
        }
273
323
274
        private static String getChangeString(int change) {
324
        private static String getChangeString(int change) {
Lines 304-319 Link Here
304
    public static class SelectionChanged extends ModelEvent {
354
    public static class SelectionChanged extends ModelEvent {
305
355
306
        private Object[] nodes;
356
        private Object[] nodes;
307
        
357
308
        /**
358
        /**
309
         * Creates a new instance of SelectionChanged event.
359
         * Creates a new instance of SelectionChanged event.
310
         *
360
         *
311
         * @param source the source of the event.
361
         * @param source the source of the event.
312
         * @param nodes list of selected node instances. All nodes are deselected
362
         * @param nodes list of selected node instances. All nodes are
313
         * when this list is empty.
363
         * deselected when this list is empty.
314
         */
364
         */
315
        public SelectionChanged(Object source, Object... nodes) {
365
        public SelectionChanged(Object source, Object... nodes) {
316
            super (source);
366
            super(source);
317
            this.nodes = nodes;
367
            this.nodes = nodes;
318
        }
368
        }
319
369
Lines 328-334 Link Here
328
378
329
        @Override
379
        @Override
330
        public String toString() {
380
        public String toString() {
331
            return super.toString()+"(nodes = "+Arrays.toString(nodes)+")"; // NOI18N
381
            return super.toString() + "(nodes = " + Arrays.toString(nodes) + ")"; // NOI18N
332
        }
382
        }
333
383
334
    }
384
    }
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/Model.java (-4 / +1 lines)
Lines 41-55 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
48
49
/**
46
/**
50
 * Marker interface for all models.
47
 * Marker interface for all models.
51
 *
48
 *
52
 * @author   Jan Jancura
49
 * @author Jan Jancura
53
 */
50
 */
54
public interface Model {
51
public interface Model {
55
}
52
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/ModelListener.java (-4 / +2 lines)
Lines 41-56 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
import java.util.EventListener;
46
import java.util.EventListener;
48
47
49
50
/**
48
/**
51
 * Notifies about changes in view model.
49
 * Notifies about changes in view model.
52
 *
50
 *
53
 * @author   Jan Jancura
51
 * @author Jan Jancura
54
 * @since 1.4
52
 * @since 1.4
55
 */
53
 */
56
public interface ModelListener extends EventListener {
54
public interface ModelListener extends EventListener {
Lines 61-65 Link Here
61
     * @param event an event object describing change
59
     * @param event an event object describing change
62
     * @since 1.4
60
     * @since 1.4
63
     */
61
     */
64
    public void modelChanged (ModelEvent event);
62
    public void modelChanged(ModelEvent event);
65
}
63
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/Models.java (-1436 / +1544 lines)
Lines 41-50 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
import java.awt.Component;
46
import java.awt.Component;
47
import java.awt.Image;
48
import java.awt.datatransfer.Transferable;
48
import java.awt.datatransfer.Transferable;
49
import java.awt.dnd.DnDConstants;
49
import java.awt.dnd.DnDConstants;
50
import java.awt.event.ActionEvent;
50
import java.awt.event.ActionEvent;
Lines 75-81 Link Here
75
import javax.swing.SwingUtilities;
75
import javax.swing.SwingUtilities;
76
import javax.swing.table.TableCellEditor;
76
import javax.swing.table.TableCellEditor;
77
import javax.swing.table.TableCellRenderer;
77
import javax.swing.table.TableCellRenderer;
78
79
import org.netbeans.modules.viewmodel.AsynchronousModel;
78
import org.netbeans.modules.viewmodel.AsynchronousModel;
80
import org.netbeans.modules.viewmodel.DefaultTreeExpansionManager;
79
import org.netbeans.modules.viewmodel.DefaultTreeExpansionManager;
81
import org.netbeans.modules.viewmodel.HyperCompoundModel;
80
import org.netbeans.modules.viewmodel.HyperCompoundModel;
Lines 84-90 Link Here
84
import org.netbeans.modules.viewmodel.TreeModelNode.ActionOnPresetNodes;
83
import org.netbeans.modules.viewmodel.TreeModelNode.ActionOnPresetNodes;
85
import org.netbeans.modules.viewmodel.TreeModelNode.DisableableAction;
84
import org.netbeans.modules.viewmodel.TreeModelNode.DisableableAction;
86
import org.netbeans.modules.viewmodel.TreeModelRoot;
85
import org.netbeans.modules.viewmodel.TreeModelRoot;
87
88
import org.netbeans.spi.viewmodel.AsynchronousModelFilter.CALL;
86
import org.netbeans.spi.viewmodel.AsynchronousModelFilter.CALL;
89
import org.openide.awt.Actions;
87
import org.openide.awt.Actions;
90
import org.openide.explorer.ExplorerManager;
88
import org.openide.explorer.ExplorerManager;
Lines 92-239 Link Here
92
import org.openide.explorer.view.TreeView;
90
import org.openide.explorer.view.TreeView;
93
import org.openide.nodes.Node;
91
import org.openide.nodes.Node;
94
import org.openide.util.Exceptions;
92
import org.openide.util.Exceptions;
93
import org.openide.util.Lookup;
95
import org.openide.util.datatransfer.PasteType;
94
import org.openide.util.datatransfer.PasteType;
96
import org.openide.windows.TopComponent;
95
import org.openide.windows.TopComponent;
97
96
98
99
/**
97
/**
100
 * Contains various utility methods for various models.
98
 * Contains various utility methods for various models.
101
 *
99
 *
102
 * @author   Jan Jancura
100
 * @author Jan Jancura
103
 */
101
 */
104
public final class Models {
102
public final class Models {
105
103
106
    /** Cached default implementations of expansion models. */
104
    /**
105
     * Cached default implementations of expansion models.
106
     */
107
    private static final WeakHashMap<Object, DefaultTreeExpansionModel> defaultExpansionModels = new WeakHashMap<Object, DefaultTreeExpansionModel>();
107
    private static final WeakHashMap<Object, DefaultTreeExpansionModel> defaultExpansionModels = new WeakHashMap<Object, DefaultTreeExpansionModel>();
108
    
108
109
    /**
109
    /**
110
     * Empty model - returns default root node with no children.
110
     * Empty model - returns default root node with no children.
111
     */
111
     */
112
    public static CompoundModel EMPTY_MODEL = createCompoundModel 
112
    public static CompoundModel EMPTY_MODEL = createCompoundModel(new ArrayList());
113
        (new ArrayList ());
113
114
    
115
    
116
    public static int MULTISELECTION_TYPE_EXACTLY_ONE = 1;
114
    public static int MULTISELECTION_TYPE_EXACTLY_ONE = 1;
117
    public static int MULTISELECTION_TYPE_ALL = 2;
115
    public static int MULTISELECTION_TYPE_ALL = 2;
118
    public static int MULTISELECTION_TYPE_ANY = 3;
116
    public static int MULTISELECTION_TYPE_ANY = 3;
119
117
120
    private static final int DEFAULT_DRAG_DROP_ALLOWED_ACTIONS = DnDConstants.ACTION_NONE;
118
    private static final int DEFAULT_DRAG_DROP_ALLOWED_ACTIONS = DnDConstants.ACTION_NONE;
121
    
119
122
    private static boolean verbose = 
120
    private static boolean verbose
123
        System.getProperty ("netbeans.debugger.models") != null;
121
            = System.getProperty("netbeans.debugger.models") != null;
124
    
122
125
    
126
    /**
123
    /**
127
     * Creates a new instance of TreeTableView
124
     * Creates a new instance of TreeTableView for given
128
     * for given {@link org.netbeans.spi.viewmodel.Models.CompoundModel}.
125
     * {@link org.netbeans.spi.viewmodel.Models.CompoundModel}.
129
     *
126
     *
130
     * @param compoundModel a compound model instance
127
     * @param compoundModel a compound model instance
131
     *
128
     *
132
     * @return new instance of complete model view
129
     * @return new instance of complete model view
133
     */
130
     */
134
    public static JComponent createView (
131
    public static JComponent createView(
135
        CompoundModel compoundModel
132
            CompoundModel compoundModel
136
    ) {
133
    ) {
137
        /*if (compoundModel.isTree()) {
134
        /*if (compoundModel.isTree()) {
138
            OutlineTree ot = new OutlineTree();
135
            OutlineTree ot = new OutlineTree();
139
            ot.setModel (compoundModel);
136
            ot.setModel (compoundModel);
140
            return ot;
137
            return ot;
141
        } else {*/
138
        } else {*/
142
        OutlineTable ot = new OutlineTable ();
139
        OutlineTable ot = new OutlineTable();
143
        if (compoundModel != null && compoundModel.isHyperModel()) {
140
        if (compoundModel != null && compoundModel.isHyperModel()) {
144
            ot.setModel(compoundModel.createHyperModel(), compoundModel.getTreeNodeDisplayFormat());
141
            ot.setModel(compoundModel.createHyperModel(), compoundModel.getTreeNodeDisplayFormat());
145
        } else {
142
        } else {
146
            ot.setModel (compoundModel, (compoundModel != null) ? compoundModel.getTreeNodeDisplayFormat() : null);
143
            ot.setModel(compoundModel, (compoundModel != null) ? compoundModel.getTreeNodeDisplayFormat() : null);
147
        }
144
        }
148
        return ot;
145
        return ot;
149
        //}
146
        //}
150
    }
147
    }
151
    
148
152
    /**
149
    /**
153
     * Creates a root node of the nodes tree structure
150
     * Creates a root node of the nodes tree structure for given
154
     * for given {@link org.netbeans.spi.viewmodel.Models.CompoundModel}.
151
     * {@link org.netbeans.spi.viewmodel.Models.CompoundModel}.
155
     *
152
     *
156
     * @param compoundModel a compound model instance
153
     * @param compoundModel a compound model instance
157
     * @param treeView The tree view component where nodes are going to be displayed.
154
     * @param treeView The tree view component where nodes are going to be
155
     * displayed.
158
     *
156
     *
159
     * @return new instance root node
157
     * @return new instance root node
160
     * @since 1.15
158
     * @since 1.15
161
     */
159
     */
162
    public static Node createNodes (
160
    public static Node createNodes(
163
        CompoundModel compoundModel,
161
            CompoundModel compoundModel,
164
        TreeView treeView
162
            TreeView treeView
165
    ) {
163
    ) {
166
        if (compoundModel != null && compoundModel.isHyperModel()) {
164
        if (compoundModel != null && compoundModel.isHyperModel()) {
167
            return new TreeModelRoot (compoundModel.createHyperModel(), treeView).getRootNode();
165
            return new TreeModelRoot(compoundModel.createHyperModel(), treeView).getRootNode();
168
        } else {
166
        } else {
169
            return new TreeModelRoot (compoundModel, treeView).getRootNode();
167
            return new TreeModelRoot(compoundModel, treeView).getRootNode();
170
        }
168
        }
171
    }
169
    }
172
    
170
173
    /**
171
    /**
174
     * Set given models to given view instance.
172
     * Set given models to given view instance.
175
     *
173
     *
176
     * @param view a view instance - must be an instance created by {@link #createView} method.
174
     * @param view a view instance - must be an instance created by
175
     * {@link #createView} method.
177
     * @param compoundModel a compound model instance
176
     * @param compoundModel a compound model instance
178
     */
177
     */
179
    public static void setModelsToView (
178
    public static void setModelsToView(
180
        final JComponent view,
179
            final JComponent view,
181
        final CompoundModel compoundModel
180
            final CompoundModel compoundModel
182
    ) {
181
    ) {
183
        if (!(view instanceof OutlineTable)) {
182
        if (!(view instanceof OutlineTable)) {
184
            throw new IllegalArgumentException("Expecting an instance of "+OutlineTable.class.getName()+", which can be obtained from Models.createView(). view = "+view);
183
            throw new IllegalArgumentException("Expecting an instance of " + OutlineTable.class.getName() + ", which can be obtained from Models.createView(). view = " + view);
185
        }
184
        }
186
        if (verbose) {
185
        if (verbose) {
187
            System.out.println (compoundModel);
186
            System.out.println(compoundModel);
188
        }
187
        }
189
        SwingUtilities.invokeLater (new Runnable () {
188
        SwingUtilities.invokeLater(new Runnable() {
190
            @Override
189
            @Override
191
            public void run () {
190
            public void run() {
192
                if (compoundModel != null && compoundModel.isHyperModel()) {
191
                if (compoundModel != null && compoundModel.isHyperModel()) {
193
                    ((OutlineTable) view).setModel (compoundModel.createHyperModel(), compoundModel.getTreeNodeDisplayFormat());
192
                    ((OutlineTable) view).setModel(compoundModel.createHyperModel(), compoundModel.getTreeNodeDisplayFormat());
193
                } else if (compoundModel != null) {
194
                    ((OutlineTable) view).setModel(compoundModel, compoundModel.getTreeNodeDisplayFormat());
194
                } else {
195
                } else {
195
                    if (compoundModel != null) {
196
                    ((OutlineTable) view).setModel(compoundModel);
196
                        ((OutlineTable) view).setModel (compoundModel, compoundModel.getTreeNodeDisplayFormat());
197
                    } else {
198
                        ((OutlineTable) view).setModel (compoundModel);
199
                    }
200
                }
197
                }
201
            }
198
            }
202
        });
199
        });
203
    }
200
    }
204
    
201
205
    /**
202
    /**
206
     * Creates one {@link CompoundModel} from given list of models.
203
     * Creates one {@link CompoundModel} from given list of models.
207
     * <p>
204
     * <p>
208
     * If this list does not include any instance of TreeModel or
205
     * If this list does not include any instance of TreeModel or
209
     * TreeExpansionModel, a default implementation of these models is created
206
     * TreeExpansionModel, a default implementation of these models is created
210
     * based on the instance of this list. Thus you get one implementation
207
     * based on the instance of this list. Thus you get one implementation per
211
     * per provided instance of the models list.
208
     * provided instance of the models list.
212
     * 
209
     *
213
     * @param models a list of models
210
     * @param models a list of models
214
     * @return {@link CompoundModel} encapsulating given list of models
211
     * @return {@link CompoundModel} encapsulating given list of models
215
     */
212
     */
216
    public static CompoundModel createCompoundModel (List models) {
213
    public static CompoundModel createCompoundModel(List models) {
217
        return createCompoundModel(models, null);
214
        return createCompoundModel(models, null);
218
    }
215
    }
219
    
216
220
    /**
217
    /**
221
     * Creates one {@link CompoundModel} from given list of models.
218
     * Creates one {@link CompoundModel} from given list of models.
222
     * <p>
219
     * <p>
223
     * If this list does not include any instance of TreeModel or
220
     * If this list does not include any instance of TreeModel or
224
     * TreeExpansionModel, a default implementation of these models is created
221
     * TreeExpansionModel, a default implementation of these models is created
225
     * based on the instance of this list. Thus you get one implementation
222
     * based on the instance of this list. Thus you get one implementation per
226
     * per provided instance of the models list.
223
     * provided instance of the models list.
227
     * 
224
     *
228
     * @param models a list of models
225
     * @param models a list of models
229
     * @param propertiesHelpID The help ID, which is set for the properties
226
     * @param propertiesHelpID The help ID, which is set for the properties
230
     *        sheets created from this model.
227
     * sheets created from this model.
231
     * @return {@link CompoundModel} encapsulating given list of models
228
     * @return {@link CompoundModel} encapsulating given list of models
232
     * @since 1.7
229
     * @since 1.7
233
     */
230
     */
234
    // TODO: Add createCompoundModel(List models, String propertiesHelpID, RequestProcessor rp)
231
    // TODO: Add createCompoundModel(List models, String propertiesHelpID, RequestProcessor rp)
235
    // Or instead of RP use some interface that could provide the desired thread to run in (current, AWT, RP thread,...)
232
    // Or instead of RP use some interface that could provide the desired thread to run in (current, AWT, RP thread,...)
236
    public static CompoundModel createCompoundModel (List models, String propertiesHelpID) {
233
    public static CompoundModel createCompoundModel(List models, String propertiesHelpID) {
237
        if (models.size() > 1 && models.get(0) instanceof CompoundModel && models.get(1) instanceof CompoundModel) {
234
        if (models.size() > 1 && models.get(0) instanceof CompoundModel && models.get(1) instanceof CompoundModel) {
238
            // Hypermodel
235
            // Hypermodel
239
            ArrayList<CompoundModel> subModels = new ArrayList<CompoundModel>();
236
            ArrayList<CompoundModel> subModels = new ArrayList<CompoundModel>();
Lines 261-277 Link Here
261
            treeNodeDisplayFormat = (MessageFormat) models.remove(models.size() - 1);
258
            treeNodeDisplayFormat = (MessageFormat) models.remove(models.size() - 1);
262
        }
259
        }
263
        ModelLists ml = new ModelLists();
260
        ModelLists ml = new ModelLists();
264
        List<? extends Model>           otherModels;
261
        List<? extends Model> otherModels;
265
        
262
266
        // Either the list contains 10 lists of individual models + one list of mixed models
263
        // Either the list contains 10 lists of individual models + one list of mixed models
267
        //  + optional TreeExpansionModelFilter(s) + optional AsynchronousModelFilter(s)
264
        //  + optional TreeExpansionModelFilter(s) + optional AsynchronousModelFilter(s)
268
        // ; or the models directly
265
        // ; or the models directly
269
        boolean hasLists = false;
266
        boolean hasLists = false;
270
        int modelsSize = models.size();
267
        int modelsSize = models.size();
271
        if (11 <= modelsSize && modelsSize <= 18) {
268
        if (11 <= modelsSize && modelsSize <= 18) {
272
            Iterator it = models.iterator ();
269
            Iterator it = models.iterator();
273
            boolean failure = false;
270
            boolean failure = false;
274
            while (it.hasNext ()) {
271
            while (it.hasNext()) {
275
                Object model = it.next();
272
                Object model = it.next();
276
                if (!(model instanceof List)) {
273
                if (!(model instanceof List)) {
277
                    failure = true;
274
                    failure = true;
Lines 283-333 Link Here
283
            }
280
            }
284
        }
281
        }
285
        if (hasLists) { // We have 11 or 12 lists of individual models + optional RP
282
        if (hasLists) { // We have 11 or 12 lists of individual models + optional RP
286
            ml.treeModels =            (List<TreeModel>)       models.get(0);
283
            ml.treeModels = (List<TreeModel>) models.get(0);
287
            ml.treeModelFilters =      (List<TreeModelFilter>) models.get(1);
284
            ml.treeModelFilters = (List<TreeModelFilter>) models.get(1);
288
            revertOrder(ml.treeModelFilters);
285
            revertOrder(ml.treeModelFilters);
289
            ml.treeExpansionModels =   (List<TreeExpansionModel>) models.get(2);
286
            ml.treeExpansionModels = (List<TreeExpansionModel>) models.get(2);
290
            ml.nodeModels =            (List<NodeModel>) models.get(3);
287
            ml.nodeModels = (List<NodeModel>) models.get(3);
291
            ml.nodeModelFilters =      (List<NodeModelFilter>) models.get(4);
288
            ml.nodeModelFilters = (List<NodeModelFilter>) models.get(4);
292
            revertOrder(ml.nodeModelFilters);
289
            revertOrder(ml.nodeModelFilters);
293
            ml.tableModels =           (List<TableModel>) models.get(5);
290
            ml.tableModels = (List<TableModel>) models.get(5);
294
            ml.tableModelFilters =     (List<TableModelFilter>) models.get(6);
291
            ml.tableModelFilters = (List<TableModelFilter>) models.get(6);
295
            revertOrder(ml.tableModelFilters);
292
            revertOrder(ml.tableModelFilters);
296
            ml.nodeActionsProviders =  (List<NodeActionsProvider>) models.get(7);
293
            ml.nodeActionsProviders = (List<NodeActionsProvider>) models.get(7);
297
            ml.nodeActionsProviderFilters = (List<NodeActionsProviderFilter>) models.get(8);
294
            ml.nodeActionsProviderFilters = (List<NodeActionsProviderFilter>) models.get(8);
298
            revertOrder(ml.nodeActionsProviderFilters);
295
            revertOrder(ml.nodeActionsProviderFilters);
299
            ml.columnModels =          (List<ColumnModel>) models.get(9);
296
            ml.columnModels = (List<ColumnModel>) models.get(9);
300
            otherModels =           (List<? extends Model>) models.get(10);
297
            otherModels = (List<? extends Model>) models.get(10);
301
            if (modelsSize > 11) { // TreeExpansionModelFilter
298
            if (modelsSize > 11) { // TreeExpansionModelFilter
302
                ml.treeExpansionModelFilters = (List<TreeExpansionModelFilter>) models.get(11);
299
                ml.treeExpansionModelFilters = (List<TreeExpansionModelFilter>) models.get(11);
303
                //if (modelsSize > 12) { // AsynchronousModel
300
                //if (modelsSize > 12) { // AsynchronousModel
304
                //    ml.asynchModels = (List<AsynchronousModel>) models.get(12);
301
                //    ml.asynchModels = (List<AsynchronousModel>) models.get(12);
305
                    if (modelsSize > 12) { // AsynchronousModelFilter
302
                if (modelsSize > 12) { // AsynchronousModelFilter
306
                        ml.asynchModelFilters = (List<AsynchronousModelFilter>) models.get(12);
303
                    ml.asynchModelFilters = (List<AsynchronousModelFilter>) models.get(12);
307
                        if (modelsSize > 13) {
304
                    if (modelsSize > 13) {
308
                            ml.tableRendererModels = (List<TableRendererModel>) models.get(13);
305
                        ml.tableRendererModels = (List<TableRendererModel>) models.get(13);
309
                            if (modelsSize > 14) {
306
                        if (modelsSize > 14) {
310
                                ml.tableRendererModelFilters = (List<TableRendererModelFilter>) models.get(14);
307
                            ml.tableRendererModelFilters = (List<TableRendererModelFilter>) models.get(14);
311
                                //if (modelsSize > 15) {
308
                            //if (modelsSize > 15) {
312
                                //    ml.tableHtmlModels = (List<TableHTMLModel>) models.get(15);
309
                            //    ml.tableHtmlModels = (List<TableHTMLModel>) models.get(15);
313
                                    if (modelsSize > 15) {
310
                            if (modelsSize > 15) {
314
                                        ml.tableHtmlModelFilters = (List<TableHTMLModelFilter>) models.get(15);
311
                                ml.tableHtmlModelFilters = (List<TableHTMLModelFilter>) models.get(15);
315
                                        if (modelsSize > 16) {
312
                                if (modelsSize > 16) {
316
                                            ml.tablePropertyEditorsModels = (List<TablePropertyEditorsModel>) models.get(16);
313
                                    ml.tablePropertyEditorsModels = (List<TablePropertyEditorsModel>) models.get(16);
317
                                            if (modelsSize > 17) {
314
                                    if (modelsSize > 17) {
318
                                                ml.tablePropertyEditorsModelFilters = (List<TablePropertyEditorsModelFilter>) models.get(17);
315
                                        ml.tablePropertyEditorsModelFilters = (List<TablePropertyEditorsModelFilter>) models.get(17);
319
                                            }
320
                                        }
321
                                    }
316
                                    }
322
                                //}
317
                                }
323
                            }
318
                            }
319
                            //}
324
                        }
320
                        }
325
                    }
321
                    }
322
                }
326
                //}
323
                //}
327
            }
324
            }
328
            //treeExpansionModelFilters = (models.size() > 11) ? (List<TreeExpansionModelFilter>) models.get(11) : (List<TreeExpansionModelFilter>) Collections.EMPTY_LIST;
325
            //treeExpansionModelFilters = (models.size() > 11) ? (List<TreeExpansionModelFilter>) models.get(11) : (List<TreeExpansionModelFilter>) Collections.EMPTY_LIST;
329
        } else { // We have the models, need to find out what they implement
326
        } else { // We have the models, need to find out what they implement
330
            otherModels =          (List<? extends Model>) models;
327
            otherModels = (List<? extends Model>) models;
331
        }
328
        }
332
329
333
        ml.addOtherModels(otherModels);
330
        ml.addOtherModels(otherModels);
Lines 362-369 Link Here
362
        return cm;
359
        return cm;
363
    }
360
    }
364
361
365
    private  static CompoundModel createCompoundModel (ModelLists ml, String propertiesHelpID) {
362
    private static CompoundModel createCompoundModel(ModelLists ml, String propertiesHelpID) {
366
        if (ml.treeModels.isEmpty ()) {
363
        if (ml.treeModels.isEmpty()) {
367
            TreeModel etm = new EmptyTreeModel();
364
            TreeModel etm = new EmptyTreeModel();
368
            ml.treeModels = Collections.singletonList(etm);
365
            ml.treeModels = Collections.singletonList(etm);
369
        }
366
        }
Lines 387-479 Link Here
387
        /*if (ml.asynchModels.isEmpty()) {
384
        /*if (ml.asynchModels.isEmpty()) {
388
            ml.asynchModels = Collections.singletonList((AsynchronousModel) new DefaultAsynchronousModel());
385
            ml.asynchModels = Collections.singletonList((AsynchronousModel) new DefaultAsynchronousModel());
389
        }*/
386
        }*/
390
        
387
391
        CompoundModel cm;
388
        CompoundModel cm;
392
        if (ml.columnModels == null && ml.tableModels == null && ml.tableModelFilters == null &&
389
        if (ml.columnModels == null && ml.tableModels == null && ml.tableModelFilters == null
393
            ml.tableRendererModels == null && ml.tableRendererModelFilters == null) {
390
                && ml.tableRendererModels == null && ml.tableRendererModelFilters == null) {
394
            
391
395
            cm = new CompoundModel (
392
            cm = new CompoundModel(
396
            createCompoundTreeModel (
393
                    createCompoundTreeModel(
397
                new DelegatingTreeModel (ml.treeModels),
394
                            new DelegatingTreeModel(ml.treeModels),
398
                ml.treeModelFilters
395
                            ml.treeModelFilters
399
            ),
396
                    ),
400
            createCompoundTreeExpansionModel(
397
                    createCompoundTreeExpansionModel(
401
                new DelegatingTreeExpansionModel (ml.treeExpansionModels),
398
                            new DelegatingTreeExpansionModel(ml.treeExpansionModels),
402
                ml.treeExpansionModelFilters
399
                            ml.treeExpansionModelFilters
403
            ),
400
                    ),
404
            createCompoundNodeModel (
401
                    createCompoundNodeModel(
405
                new DelegatingNodeModel (ml.nodeModels),
402
                            new DelegatingNodeModel(ml.nodeModels),
406
                ml.nodeModelFilters
403
                            ml.nodeModelFilters
407
            ),
404
                    ),
408
            createCompoundNodeActionsProvider (
405
                    createCompoundNodeActionsProvider(
409
                new DelegatingNodeActionsProvider (ml.nodeActionsProviders),
406
                            new DelegatingNodeActionsProvider(ml.nodeActionsProviders),
410
                ml.nodeActionsProviderFilters
407
                            ml.nodeActionsProviderFilters
411
            ),
408
                    ),
412
            null, null,
409
                    null, null,
413
            createCompoundAsynchronousModel (
410
                    createCompoundAsynchronousModel(
414
                new DefaultAsynchronousModel(),//new DelegatingAsynchronousModel (ml.asynchModels),
411
                            new DefaultAsynchronousModel(),//new DelegatingAsynchronousModel (ml.asynchModels),
415
                ml.asynchModelFilters
412
                            ml.asynchModelFilters
416
            ),
413
                    ),
417
            null, null,
414
                    null, null,
418
            propertiesHelpID
415
                    ml.iconNodeModel,
419
        );
416
                    ml.lookupNodeModel,
417
                    propertiesHelpID
418
            );
420
        } else {
419
        } else {
421
            cm = new CompoundModel (
420
            cm = new CompoundModel(
422
            createCompoundTreeModel (
421
                    createCompoundTreeModel(
423
                new DelegatingTreeModel (ml.treeModels),
422
                            new DelegatingTreeModel(ml.treeModels),
424
                ml.treeModelFilters
423
                            ml.treeModelFilters
425
            ),
424
                    ),
426
            createCompoundTreeExpansionModel(
425
                    createCompoundTreeExpansionModel(
427
                new DelegatingTreeExpansionModel (ml.treeExpansionModels),
426
                            new DelegatingTreeExpansionModel(ml.treeExpansionModels),
428
                ml.treeExpansionModelFilters
427
                            ml.treeExpansionModelFilters
429
            ),
428
                    ),
430
            createCompoundNodeModel (
429
                    createCompoundNodeModel(
431
                new DelegatingNodeModel (ml.nodeModels),
430
                            new DelegatingNodeModel(ml.nodeModels),
432
                ml.nodeModelFilters
431
                            ml.nodeModelFilters
433
            ),
432
                    ),
434
            createCompoundNodeActionsProvider (
433
                    createCompoundNodeActionsProvider(
435
                new DelegatingNodeActionsProvider (ml.nodeActionsProviders),
434
                            new DelegatingNodeActionsProvider(ml.nodeActionsProviders),
436
                ml.nodeActionsProviderFilters
435
                            ml.nodeActionsProviderFilters
437
            ),
436
                    ),
438
            ml.columnModels,
437
                    ml.columnModels,
439
            createCompoundTableModel (
438
                    createCompoundTableModel(
440
                new DelegatingTableModel (ml.tableModels),
439
                            new DelegatingTableModel(ml.tableModels),
441
                ml.tableModelFilters,
440
                            ml.tableModelFilters,
442
                ml.tableHtmlModelFilters
441
                            ml.tableHtmlModelFilters
443
            ),
442
                    ),
444
            createCompoundAsynchronousModel (
443
                    createCompoundAsynchronousModel(
445
                new DefaultAsynchronousModel(),//new DelegatingAsynchronousModel (ml.asynchModels),
444
                            new DefaultAsynchronousModel(),//new DelegatingAsynchronousModel (ml.asynchModels),
446
                ml.asynchModelFilters
445
                            ml.asynchModelFilters
447
            ),
446
                    ),
448
            createCompoundTableRendererModel (
447
                    createCompoundTableRendererModel(
449
                new DelegatingTableRendererModel(ml.tableRendererModels),
448
                            new DelegatingTableRendererModel(ml.tableRendererModels),
450
                ml.tableRendererModelFilters
449
                            ml.tableRendererModelFilters
451
            ),
450
                    ),
452
            /*createCompoundTableHTMLModel (
451
                    /*createCompoundTableHTMLModel (
453
                new DelegatingTableHTMLModel(ml.tableHtmlModels),
452
                new DelegatingTableHTMLModel(ml.tableHtmlModels),
454
                ml.tableHtmlModelFilters
453
                ml.tableHtmlModelFilters
455
            ),*/
454
            ),*/
456
            createCompoundTablePropertyEditorModel (
455
                    createCompoundTablePropertyEditorModel(
457
                new DelegatingTablePropertyEditorsModel(ml.tablePropertyEditorsModels),
456
                            new DelegatingTablePropertyEditorsModel(ml.tablePropertyEditorsModels),
458
                ml.tablePropertyEditorsModelFilters
457
                            ml.tablePropertyEditorsModelFilters
459
            ),
458
                    ),
460
            propertiesHelpID
459
                    ml.iconNodeModel,
461
        );
460
                    ml.lookupNodeModel,
461
                    propertiesHelpID
462
            );
462
        }
463
        }
463
        if (defaultExpansionModel != null) {
464
        if (defaultExpansionModel != null) {
464
            defaultExpansionModel.setCompoundModel(cm);
465
            defaultExpansionModel.setCompoundModel(cm);
465
        }
466
        }
466
        return cm;
467
        return cm;
467
    }
468
    }
468
    
469
469
    private static <T> void revertOrder(List<T> filters) {
470
    private static <T> void revertOrder(List<T> filters) {
470
        int n = filters.size();
471
        int n = filters.size();
471
        // [TODO] do not remove the following line, prevents null to be returned by filters.remove(i);
472
        // [TODO] do not remove the following line, prevents null to be returned by filters.remove(i);
472
        // needs deeper investigation why it can occure
473
        // needs deeper investigation why it can occure
473
        filters.toString();
474
        filters.toString();
474
        for (int i = 0; i < n; ) {
475
        for (int i = 0; i < n;) {
475
            T filter = filters.remove(i);
476
            T filter = filters.remove(i);
476
            boolean first = filter.getClass ().getName ().endsWith ("First");
477
            boolean first = filter.getClass().getName().endsWith("First");
477
            if (first) { // The "First" should be the last one in this list
478
            if (first) { // The "First" should be the last one in this list
478
                filters.add(filter);
479
                filters.add(filter);
479
                n--;
480
                n--;
Lines 483-718 Link Here
483
            }
484
            }
484
        }
485
        }
485
    }
486
    }
486
    
487
487
    
488
    /**
488
    /**
489
     * Returns {@link javax.swing.Action} for given parameters.
489
     * Returns {@link javax.swing.Action} for given parameters.
490
     *
490
     *
491
     * @param displayName a display name for action
491
     * @param displayName a display name for action
492
     * @param performer a performer for action
492
     * @param performer a performer for action
493
     * @param multiselectionType The type of the multi selection - one of the
493
     * @param multiselectionType The type of the multi selection - one of the
494
     *        MULTISELECTION_TYPE_* constants.
494
     * MULTISELECTION_TYPE_* constants.
495
     *
495
     *
496
     * @return a new instance of {@link javax.swing.Action} for given parameters
496
     * @return a new instance of {@link javax.swing.Action} for given parameters
497
     */
497
     */
498
    public static Action createAction (
498
    public static Action createAction(
499
        String displayName, 
499
            String displayName,
500
        ActionPerformer performer,
500
            ActionPerformer performer,
501
        int multiselectionType
501
            int multiselectionType
502
    ) {
502
    ) {
503
        return new ActionSupport (
503
        return new ActionSupport(
504
            displayName, 
504
                displayName,
505
            performer, 
505
                performer,
506
            multiselectionType
506
                multiselectionType
507
        );
507
        );
508
    }
508
    }
509
    
509
510
    /**
510
    /**
511
     * Returns implementation of tree view features for given view.
511
     * Returns implementation of tree view features for given view.
512
     *
512
     *
513
     * @param view a view created by this Models class
513
     * @param view a view created by this Models class
514
     * @throws UnsupportedOperationException in the case that given 
514
     * @throws UnsupportedOperationException in the case that given view is not
515
     *        view is not tree view
515
     * tree view
516
     * @return implementation of tree view features
516
     * @return implementation of tree view features
517
     */
517
     */
518
    public static TreeFeatures treeFeatures (JComponent view) 
518
    public static TreeFeatures treeFeatures(JComponent view)
519
    throws UnsupportedOperationException {
519
            throws UnsupportedOperationException {
520
        return new DefaultTreeFeatures (view);
520
        return new DefaultTreeFeatures(view);
521
    }
521
    }
522
    
522
523
    
524
    // private methods .........................................................
523
    // private methods .........................................................
525
    
526
    /**
524
    /**
527
     * Creates {@link org.netbeans.spi.viewmodel.TreeModel} for given TreeModel and
525
     * Creates {@link org.netbeans.spi.viewmodel.TreeModel} for given TreeModel
528
     * {@link org.netbeans.spi.viewmodel.TreeModelFilter}.
526
     * and {@link org.netbeans.spi.viewmodel.TreeModelFilter}.
529
     * 
527
     *
530
     * @param originalTreeModel a original tree model
528
     * @param originalTreeModel a original tree model
531
     * @param treeModelFilter a list of tree model filters
529
     * @param treeModelFilter a list of tree model filters
532
     *
530
     *
533
     * @returns compund tree model
531
     * @returns compund tree model
534
     */
532
     */
535
    private static ReorderableTreeModel createCompoundTreeModel (
533
    private static ReorderableTreeModel createCompoundTreeModel(
536
        ReorderableTreeModel originalTreeModel,
534
            ReorderableTreeModel originalTreeModel,
537
        List treeModelFilters
535
            List treeModelFilters
538
    ) {
536
    ) {
539
        ReorderableTreeModel tm = originalTreeModel;
537
        ReorderableTreeModel tm = originalTreeModel;
540
        int i, k = treeModelFilters.size ();
538
        int i, k = treeModelFilters.size();
541
        for (i = 0; i < k; i++) {
539
        for (i = 0; i < k; i++) {
542
            tm = new CompoundTreeModel (
540
            tm = new CompoundTreeModel(
543
                tm,
541
                    tm,
544
                (TreeModelFilter) treeModelFilters.get (i)
542
                    (TreeModelFilter) treeModelFilters.get(i)
545
            );
543
            );
546
        }
544
        }
547
        return tm;
545
        return tm;
548
    }
546
    }
549
    
547
550
    /**
548
    /**
551
     * Creates {@link org.netbeans.spi.viewmodel.NodeModel} for given NodeModel and
549
     * Creates {@link org.netbeans.spi.viewmodel.NodeModel} for given NodeModel
552
     * {@link org.netbeans.spi.viewmodel.NodeModelFilter}.
550
     * and {@link org.netbeans.spi.viewmodel.NodeModelFilter}.
553
     * 
551
     *
554
     * @param originalNodeModel a original node model
552
     * @param originalNodeModel a original node model
555
     * @param nodeModelFilters a list of node model filters
553
     * @param nodeModelFilters a list of node model filters
556
     *
554
     *
557
     * @returns compound tree model
555
     * @returns compound tree model
558
     */
556
     */
559
    private static SuperNodeModel createCompoundNodeModel (
557
    private static SuperNodeModel createCompoundNodeModel(
560
        SuperNodeModel originalNodeModel,
558
            SuperNodeModel originalNodeModel,
561
        List treeNodeModelFilters
559
            List treeNodeModelFilters
562
    ) {
560
    ) {
563
        SuperNodeModel nm = originalNodeModel;
561
        SuperNodeModel nm = originalNodeModel;
564
        int i, k = treeNodeModelFilters.size ();
562
        int i, k = treeNodeModelFilters.size();
565
        for (i = 0; i < k; i++) {
563
        for (i = 0; i < k; i++) {
566
            nm = new CompoundNodeModel (
564
            nm = new CompoundNodeModel(
567
                nm,
565
                    nm,
568
                (NodeModelFilter) treeNodeModelFilters.get (i)
566
                    (NodeModelFilter) treeNodeModelFilters.get(i)
569
            );
567
            );
570
        }
568
        }
571
        return nm;
569
        return nm;
572
    }
570
    }
573
    
571
574
    /**
572
    /**
575
     * Creates {@link org.netbeans.spi.viewmodel.TableModel} for given TableModel and
573
     * Creates {@link org.netbeans.spi.viewmodel.TableModel} for given
576
     * {@link org.netbeans.spi.viewmodel.TableModelFilter}.
574
     * TableModel and {@link org.netbeans.spi.viewmodel.TableModelFilter}.
577
     * 
575
     *
578
     * @param originalTableModel a original table model
576
     * @param originalTableModel a original table model
579
     * @param tableModelFilters a list of table model filters
577
     * @param tableModelFilters a list of table model filters
580
     *
578
     *
581
     * @returns compound table model
579
     * @returns compound table model
582
     */
580
     */
583
    private static TableHTMLModel createCompoundTableModel (
581
    private static TableHTMLModel createCompoundTableModel(
584
        TableHTMLModel originalTableModel,
582
            TableHTMLModel originalTableModel,
585
        List tableModelFilters,
583
            List tableModelFilters,
586
        List tableHtmlModelFilters
584
            List tableHtmlModelFilters
587
    ) {
585
    ) {
588
        TableHTMLModel tm = originalTableModel;
586
        TableHTMLModel tm = originalTableModel;
589
        int i, k = tableModelFilters.size ();
587
        int i, k = tableModelFilters.size();
590
        for (i = 0; i < k; i++) {
588
        for (i = 0; i < k; i++) {
591
            tm = new CompoundTableModel (
589
            tm = new CompoundTableModel(
592
                tm,
590
                    tm,
593
                (TableModelFilter) tableModelFilters.get (i)
591
                    (TableModelFilter) tableModelFilters.get(i)
594
            );
592
            );
595
        }
593
        }
596
        k = tableHtmlModelFilters.size ();
594
        k = tableHtmlModelFilters.size();
597
        for (i = 0; i < k; i++) {
595
        for (i = 0; i < k; i++) {
598
            tm = new CompoundTableModel (
596
            tm = new CompoundTableModel(
599
                tm,
597
                    tm,
600
                (TableHTMLModelFilter) tableHtmlModelFilters.get (i)
598
                    (TableHTMLModelFilter) tableHtmlModelFilters.get(i)
601
            );
599
            );
602
        }
600
        }
603
        return tm;
601
        return tm;
604
    }
602
    }
605
    
603
606
    /**
604
    /**
607
     * Creates {@link org.netbeans.spi.viewmodel.TableModel} for given TableModel and
605
     * Creates {@link org.netbeans.spi.viewmodel.TableModel} for given
608
     * {@link org.netbeans.spi.viewmodel.TableModelFilter}.
606
     * TableModel and {@link org.netbeans.spi.viewmodel.TableModelFilter}.
609
     *
607
     *
610
     * @param originalTableModel a original table model
608
     * @param originalTableModel a original table model
611
     * @param tableModelFilters a list of table model filters
609
     * @param tableModelFilters a list of table model filters
612
     *
610
     *
613
     * @returns compound table model
611
     * @returns compound table model
614
     */
612
     */
615
    private static TableRendererModel createCompoundTableRendererModel (
613
    private static TableRendererModel createCompoundTableRendererModel(
616
        TableRendererModel originalTableModel,
614
            TableRendererModel originalTableModel,
617
        List tableModelFilters
615
            List tableModelFilters
618
    ) {
616
    ) {
619
        TableRendererModel tm = originalTableModel;
617
        TableRendererModel tm = originalTableModel;
620
        int i, k = tableModelFilters.size ();
618
        int i, k = tableModelFilters.size();
621
        for (i = 0; i < k; i++) {
619
        for (i = 0; i < k; i++) {
622
            tm = new CompoundTableRendererModel (
620
            tm = new CompoundTableRendererModel(
623
                tm,
621
                    tm,
624
                (TableRendererModelFilter) tableModelFilters.get (i)
622
                    (TableRendererModelFilter) tableModelFilters.get(i)
625
            );
623
            );
626
        }
624
        }
627
        return tm;
625
        return tm;
628
    }
626
    }
629
    
627
630
    private static TablePropertyEditorsModel createCompoundTablePropertyEditorModel (
628
    private static TablePropertyEditorsModel createCompoundTablePropertyEditorModel(
631
        TablePropertyEditorsModel originalTableModel,
629
            TablePropertyEditorsModel originalTableModel,
632
        List tableModelFilters
630
            List tableModelFilters
633
    ) {
631
    ) {
634
        TablePropertyEditorsModel tm = originalTableModel;
632
        TablePropertyEditorsModel tm = originalTableModel;
635
        int i, k = tableModelFilters.size ();
633
        int i, k = tableModelFilters.size();
636
        for (i = 0; i < k; i++) {
634
        for (i = 0; i < k; i++) {
637
            tm = new CompoundTablePropertyEditorsModel (
635
            tm = new CompoundTablePropertyEditorsModel(
638
                tm,
636
                    tm,
639
                (TablePropertyEditorsModelFilter) tableModelFilters.get (i)
637
                    (TablePropertyEditorsModelFilter) tableModelFilters.get(i)
640
            );
638
            );
641
        }
639
        }
642
        return tm;
640
        return tm;
643
    }
641
    }
644
642
645
    /**
643
    /**
646
     * Creates {@link org.netbeans.spi.viewmodel.NodeActionsProvider} for given NodeActionsProvider and
644
     * Creates {@link org.netbeans.spi.viewmodel.NodeActionsProvider} for given
645
     * NodeActionsProvider and
647
     * {@link org.netbeans.spi.viewmodel.NodeActionsProviderFilter}.
646
     * {@link org.netbeans.spi.viewmodel.NodeActionsProviderFilter}.
648
     * 
647
     *
649
     * @param originalNodeActionsProvider a original node actions provider
648
     * @param originalNodeActionsProvider a original node actions provider
650
     * @param nodeActionsProviderFilters a list of node actions provider filters
649
     * @param nodeActionsProviderFilters a list of node actions provider filters
651
     *
650
     *
652
     * @returns compound node actions provider
651
     * @returns compound node actions provider
653
     */
652
     */
654
    private static NodeActionsProvider createCompoundNodeActionsProvider (
653
    private static NodeActionsProvider createCompoundNodeActionsProvider(
655
        NodeActionsProvider originalNodeActionsProvider,
654
            NodeActionsProvider originalNodeActionsProvider,
656
        List nodeActionsProviderFilters
655
            List nodeActionsProviderFilters
657
    ) {
656
    ) {
658
        NodeActionsProvider nap = originalNodeActionsProvider;
657
        NodeActionsProvider nap = originalNodeActionsProvider;
659
        int i, k = nodeActionsProviderFilters.size ();
658
        int i, k = nodeActionsProviderFilters.size();
660
        for (i = 0; i < k; i++) {
659
        for (i = 0; i < k; i++) {
661
            nap = new CompoundNodeActionsProvider (
660
            nap = new CompoundNodeActionsProvider(
662
                nap,
661
                    nap,
663
                (NodeActionsProviderFilter) nodeActionsProviderFilters.get (i)
662
                    (NodeActionsProviderFilter) nodeActionsProviderFilters.get(i)
664
            );
663
            );
665
        }
664
        }
666
        return nap;
665
        return nap;
667
    }
666
    }
668
    
667
669
    private static TreeExpansionModel createCompoundTreeExpansionModel (
668
    private static TreeExpansionModel createCompoundTreeExpansionModel(
670
            TreeExpansionModel expansionModel,
669
            TreeExpansionModel expansionModel,
671
            List<TreeExpansionModelFilter> filters
670
            List<TreeExpansionModelFilter> filters
672
    ) {
671
    ) {
673
        for (TreeExpansionModelFilter filter : filters) {
672
        for (TreeExpansionModelFilter filter : filters) {
674
            expansionModel = new CompoundTreeExpansionModel (expansionModel, filter);
673
            expansionModel = new CompoundTreeExpansionModel(expansionModel, filter);
675
        }
674
        }
676
        return expansionModel;
675
        return expansionModel;
677
    }
676
    }
678
677
679
    private static AsynchronousModel createCompoundAsynchronousModel (
678
    private static AsynchronousModel createCompoundAsynchronousModel(
680
            AsynchronousModel asynchModel,
679
            AsynchronousModel asynchModel,
681
            List<AsynchronousModelFilter> filters
680
            List<AsynchronousModelFilter> filters
682
    ) {
681
    ) {
683
        for (AsynchronousModelFilter filter : filters) {
682
        for (AsynchronousModelFilter filter : filters) {
684
            asynchModel = new CompoundAsynchronousModel (asynchModel, filter);
683
            asynchModel = new CompoundAsynchronousModel(asynchModel, filter);
685
        }
684
        }
686
        return asynchModel;
685
        return asynchModel;
687
    }
686
    }
688
    
687
689
    
690
    // innerclasses ............................................................
688
    // innerclasses ............................................................
691
    
692
    /**
689
    /**
693
     * @author   Jan Jancura
690
     * @author Jan Jancura
694
     */
691
     */
695
    private static class ActionSupport extends AbstractAction implements DisableableAction,
692
    private static class ActionSupport extends AbstractAction implements DisableableAction,
696
                                                                         ActionOnPresetNodes {
693
            ActionOnPresetNodes {
697
694
698
        private ActionPerformer     performer;
695
        private ActionPerformer performer;
699
        private int                 multiselectionType;
696
        private int multiselectionType;
700
        private String              displayName;
697
        private String displayName;
701
        private PrivilegedAction    enabledTest;
698
        private PrivilegedAction enabledTest;
702
        private List<Node>          presetNodes;
699
        private List<Node> presetNodes;
703
700
704
 
701
        ActionSupport(
705
        ActionSupport (
702
                String displayName,
706
            String displayName, 
703
                ActionPerformer performer,
707
            ActionPerformer performer,
704
                int multiselectionType
708
            int multiselectionType
709
        ) {
705
        ) {
710
            super (displayName);
706
            super(displayName);
711
            this.performer = performer;
707
            this.performer = performer;
712
            this.displayName = displayName;
708
            this.displayName = displayName;
713
            this.multiselectionType = multiselectionType;
709
            this.multiselectionType = multiselectionType;
714
        }
710
        }
715
        
711
716
        @Override
712
        @Override
717
        public void addNode(Node n) {
713
        public void addNode(Node n) {
718
            if (SwingUtilities.isEventDispatchThread()) {
714
            if (SwingUtilities.isEventDispatchThread()) {
Lines 723-742 Link Here
723
                presetNodes.add(n);
719
                presetNodes.add(n);
724
            }
720
            }
725
        }
721
        }
726
        
722
727
        private Node[] getActiveNodes(ActionEvent e) {
723
        private Node[] getActiveNodes(ActionEvent e) {
728
            Node[] nodes = null;
724
            Node[] nodes = null;
729
            if (e != null) {
725
            if (e != null) {
730
                nodes = getOutlineViewSelection(e);
726
                nodes = getOutlineViewSelection(e);
731
            } else if (presetNodes != null) {
727
            } else if (presetNodes != null) {
732
                nodes = presetNodes.toArray(new Node[] {});
728
                nodes = presetNodes.toArray(new Node[]{});
733
            }
729
            }
734
            if (nodes == null) {
730
            if (nodes == null) {
735
                nodes = TopComponent.getRegistry().getActivatedNodes();
731
                nodes = TopComponent.getRegistry().getActivatedNodes();
736
            }
732
            }
737
            return nodes;
733
            return nodes;
738
        }
734
        }
739
        
735
740
        private Node[] getOutlineViewSelection(ActionEvent e) {
736
        private Node[] getOutlineViewSelection(ActionEvent e) {
741
            Object source = e.getSource();
737
            Object source = e.getSource();
742
            if (source instanceof Component) {
738
            if (source instanceof Component) {
Lines 762-770 Link Here
762
            }
758
            }
763
            return null;
759
            return null;
764
        }
760
        }
765
        
761
766
        @Override
762
        @Override
767
        public boolean isEnabled () {
763
        public boolean isEnabled() {
768
            if (enabledTest != null) {
764
            if (enabledTest != null) {
769
                if (Boolean.FALSE.equals(enabledTest.run())) {
765
                if (Boolean.FALSE.equals(enabledTest.run())) {
770
                    return false;
766
                    return false;
Lines 776-783 Link Here
776
                if (ns.length != 1) {
772
                if (ns.length != 1) {
777
                    return false;
773
                    return false;
778
                }
774
                }
779
                return performer.isEnabled (
775
                return performer.isEnabled(
780
                    ns[0].getLookup().lookup(Object.class)
776
                        ns[0].getLookup().lookup(Object.class)
781
                );
777
                );
782
            }
778
            }
783
            int i, k = ns.length;
779
            int i, k = ns.length;
Lines 803-825 Link Here
803
        }
799
        }
804
800
805
        @Override
801
        @Override
806
        public void actionPerformed (ActionEvent e) {
802
        public void actionPerformed(ActionEvent e) {
807
            //System.err.println("Models.ActionSupport.actionPerformed("+e+")");
803
            //System.err.println("Models.ActionSupport.actionPerformed("+e+")");
808
            Node[] ns = getActiveNodes(e);
804
            Node[] ns = getActiveNodes(e);
809
            int i, k = ns.length;
805
            int i, k = ns.length;
810
            IdentityHashMap<Action, ArrayList<Object>> h = new IdentityHashMap<Action, ArrayList<Object>>();
806
            IdentityHashMap<Action, ArrayList<Object>> h = new IdentityHashMap<Action, ArrayList<Object>>();
811
            for (i = 0; i < k; i++) {
807
            for (i = 0; i < k; i++) {
812
                Object node = ns[i].getLookup().lookup(Object.class);
808
                Object node = ns[i].getLookup().lookup(Object.class);
813
                Action[] as = ns [i].getActions (false);
809
                Action[] as = ns[i].getActions(false);
814
                int j, jj = as.length;
810
                int j, jj = as.length;
815
                for (j = 0; j < jj; j++) {
811
                for (j = 0; j < jj; j++) {
816
                    if (equals (as [j])) {
812
                    if (equals(as[j])) {
817
                        ArrayList<Object> l = h.get (as [j]);
813
                        ArrayList<Object> l = h.get(as[j]);
818
                        if (l == null) {
814
                        if (l == null) {
819
                            l = new ArrayList<Object>();
815
                            l = new ArrayList<Object>();
820
                            h.put (as [j], l);
816
                            h.put(as[j], l);
821
                        }
817
                        }
822
                        l.add (node);
818
                        l.add(node);
823
                    }
819
                    }
824
                }
820
                }
825
            }
821
            }
Lines 830-855 Link Here
830
                }
826
                }
831
            } else {
827
            } else {
832
                //System.err.println("  h = "+h);
828
                //System.err.println("  h = "+h);
833
                Iterator<Action> it = h.keySet ().iterator ();
829
                Iterator<Action> it = h.keySet().iterator();
834
                while (it.hasNext ()) {
830
                while (it.hasNext()) {
835
                    ActionSupport a = (ActionSupport) it.next ();
831
                    ActionSupport a = (ActionSupport) it.next();
836
                    //System.err.println("  "+a.performer+".perform("+((ArrayList) h.get (a)));
832
                    //System.err.println("  "+a.performer+".perform("+((ArrayList) h.get (a)));
837
                    a.performer.perform (
833
                    a.performer.perform(
838
                        ((ArrayList) h.get (a)).toArray ()
834
                            ((ArrayList) h.get(a)).toArray()
839
                    );
835
                    );
840
                }
836
                }
841
            }
837
            }
842
        }
838
        }
843
        
839
844
        @Override
840
        @Override
845
        public int hashCode () {
841
        public int hashCode() {
846
            return displayName.hashCode ();
842
            return displayName.hashCode();
847
        }
843
        }
848
        
844
849
        @Override
845
        @Override
850
        public boolean equals (Object o) {
846
        public boolean equals(Object o) {
851
            return (o instanceof ActionSupport) && 
847
            return (o instanceof ActionSupport)
852
                displayName.equals (((ActionSupport) o).displayName);
848
                    && displayName.equals(((ActionSupport) o).displayName);
853
        }
849
        }
854
850
855
        @Override
851
        @Override
Lines 864-882 Link Here
864
            }
860
            }
865
            return a;
861
            return a;
866
        }
862
        }
867
        
863
868
        private class PresetNodesCleaner implements Runnable {
864
        private class PresetNodesCleaner implements Runnable {
869
865
870
            @Override
866
            @Override
871
            public void run() {
867
            public void run() {
872
                presetNodes = null;
868
                presetNodes = null;
873
            }
869
            }
874
            
870
875
        }
871
        }
876
    }
872
    }
877
873
878
    /**
874
    /**
879
     * Support interface for 
875
     * Support interface for
880
     * {@link #createAction(String,Models.ActionPerformer,int)} method.
876
     * {@link #createAction(String,Models.ActionPerformer,int)} method.
881
     */
877
     */
882
    public static interface ActionPerformer {
878
    public static interface ActionPerformer {
Lines 889-985 Link Here
889
         *
885
         *
890
         * @see #createAction(String,Models.ActionPerformer,int)
886
         * @see #createAction(String,Models.ActionPerformer,int)
891
         */
887
         */
892
        public boolean isEnabled (Object node);
888
        public boolean isEnabled(Object node);
893
889
894
        /**
890
        /**
895
         * Called when action <code>action</code> is performed for 
891
         * Called when action <code>action</code> is performed for nodes.
896
         * nodes.
897
         *
892
         *
898
         * @param nodes nodes the action should be applied to
893
         * @param nodes nodes the action should be applied to
899
         *
894
         *
900
         * @see #createAction(String,Models.ActionPerformer,int)
895
         * @see #createAction(String,Models.ActionPerformer,int)
901
         */
896
         */
902
        public void perform (Object[] nodes);
897
        public void perform(Object[] nodes);
903
    }
898
    }
904
899
905
    /**
900
    /**
906
     * Creates {@link org.netbeans.spi.viewmodel.TreeModel} for given TreeModel and
901
     * Creates {@link org.netbeans.spi.viewmodel.TreeModel} for given TreeModel
907
     * {@link org.netbeans.spi.viewmodel.TreeModelFilter}.
902
     * and {@link org.netbeans.spi.viewmodel.TreeModelFilter}.
908
     * 
903
     *
909
     * @author   Jan Jancura
904
     * @author Jan Jancura
910
     */
905
     */
911
    private final static class CompoundTreeModel implements ReorderableTreeModel, ModelListener {
906
    private final static class CompoundTreeModel implements ReorderableTreeModel, ModelListener {
912
907
913
914
        private ReorderableTreeModel model;
908
        private ReorderableTreeModel model;
915
        private TreeModelFilter filter;
909
        private TreeModelFilter filter;
916
        
910
917
        private final Collection<ModelListener> modelListeners = new HashSet<ModelListener>();
911
        private final Collection<ModelListener> modelListeners = new HashSet<ModelListener>();
918
912
919
        
920
        /**
913
        /**
921
         * Creates {@link org.netbeans.spi.viewmodel.TreeModel} for given TreeModel and
914
         * Creates {@link org.netbeans.spi.viewmodel.TreeModel} for given
922
         * {@link org.netbeans.spi.viewmodel.TreeModelFilter}.
915
         * TreeModel and {@link org.netbeans.spi.viewmodel.TreeModelFilter}.
923
         */
916
         */
924
        CompoundTreeModel (ReorderableTreeModel model, TreeModelFilter filter) {
917
        CompoundTreeModel(ReorderableTreeModel model, TreeModelFilter filter) {
925
            this.model = model;
918
            this.model = model;
926
            this.filter = filter;
919
            this.filter = filter;
927
        }
920
        }
928
921
929
        /** 
922
        /**
930
         * Returns the root node of the tree or null, if the tree is empty.
923
         * Returns the root node of the tree or null, if the tree is empty.
931
         *
924
         *
932
         * @return the root node of the tree or null
925
         * @return the root node of the tree or null
933
         */
926
         */
934
        @Override
927
        @Override
935
        public Object getRoot () {
928
        public Object getRoot() {
936
            return filter.getRoot (model);
929
            return filter.getRoot(model);
937
        }
930
        }
938
931
939
        /** 
932
        /**
940
         * Returns children for given parent on given indexes.
933
         * Returns children for given parent on given indexes.
941
         *
934
         *
942
         * @param   parent a parent of returned nodes
935
         * @param parent a parent of returned nodes
943
         * @throws  NoInformationException if the set of children can not be 
936
         * @throws NoInformationException if the set of children can not be
944
         *          resolved
937
         * resolved
945
         * @throws  UnknownTypeException if this TreeModel implementation is not
938
         * @throws UnknownTypeException if this TreeModel implementation is not
946
         *          able to resolve children for given node type
939
         * able to resolve children for given node type
947
         *
940
         *
948
         * @return  children for given parent on given indexes
941
         * @return children for given parent on given indexes
949
         */
942
         */
950
        @Override
943
        @Override
951
        public Object[] getChildren (Object parent, int from, int to) 
944
        public Object[] getChildren(Object parent, int from, int to)
952
            throws UnknownTypeException {
945
                throws UnknownTypeException {
953
946
954
            return filter.getChildren (model, parent, from, to);
947
            return filter.getChildren(model, parent, from, to);
955
        }
948
        }
956
    
949
957
        /**
950
        /**
958
         * Returns number of children for given node.
951
         * Returns number of children for given node.
959
         * 
960
         * @param   node the parent node
961
         * @throws  NoInformationException if the set of children can not be 
962
         *          resolved
963
         * @throws  UnknownTypeException if this TreeModel implementation is not
964
         *          able to resolve children for given node type
965
         *
952
         *
966
         * @return  true if node is leaf
953
         * @param node the parent node
954
         * @throws NoInformationException if the set of children can not be
955
         * resolved
956
         * @throws UnknownTypeException if this TreeModel implementation is not
957
         * able to resolve children for given node type
958
         *
959
         * @return true if node is leaf
967
         */
960
         */
968
        @Override
961
        @Override
969
        public int getChildrenCount (Object node) throws UnknownTypeException {
962
        public int getChildrenCount(Object node) throws UnknownTypeException {
970
            return filter.getChildrenCount (model, node);
963
            return filter.getChildrenCount(model, node);
971
        }
964
        }
972
965
973
        /**
966
        /**
974
         * Returns true if node is leaf.
967
         * Returns true if node is leaf.
975
         * 
968
         *
976
         * @throws  UnknownTypeException if this TreeModel implementation is not
969
         * @throws UnknownTypeException if this TreeModel implementation is not
977
         *          able to resolve children for given node type
970
         * able to resolve children for given node type
978
         * @return  true if node is leaf
971
         * @return true if node is leaf
979
         */
972
         */
980
        @Override
973
        @Override
981
        public boolean isLeaf (Object node) throws UnknownTypeException {
974
        public boolean isLeaf(Object node) throws UnknownTypeException {
982
            return filter.isLeaf (model, node);
975
            return filter.isLeaf(model, node);
983
        }
976
        }
984
977
985
        @Override
978
        @Override
Lines 1000-1083 Link Here
1000
            }
993
            }
1001
        }
994
        }
1002
995
1003
        /** 
996
        /**
1004
         * Registers given listener.
997
         * Registers given listener.
1005
         * 
998
         *
1006
         * @param l the listener to add
999
         * @param l the listener to add
1007
         */
1000
         */
1008
        @Override
1001
        @Override
1009
        public void addModelListener (ModelListener l) {
1002
        public void addModelListener(ModelListener l) {
1010
            synchronized (modelListeners) {
1003
            synchronized (modelListeners) {
1011
                if (modelListeners.isEmpty()) {
1004
                if (modelListeners.isEmpty()) {
1012
                    filter.addModelListener (this);
1005
                    filter.addModelListener(this);
1013
                    model.addModelListener (this);
1006
                    model.addModelListener(this);
1014
                }
1007
                }
1015
                modelListeners.add(l);
1008
                modelListeners.add(l);
1016
            }
1009
            }
1017
        }
1010
        }
1018
1011
1019
        /** 
1012
        /**
1020
         * Unregisters given listener.
1013
         * Unregisters given listener.
1021
         *
1014
         *
1022
         * @param l the listener to remove
1015
         * @param l the listener to remove
1023
         */
1016
         */
1024
        @Override
1017
        @Override
1025
        public void removeModelListener (ModelListener l) {
1018
        public void removeModelListener(ModelListener l) {
1026
            synchronized (modelListeners) {
1019
            synchronized (modelListeners) {
1027
                modelListeners.remove(l);
1020
                modelListeners.remove(l);
1028
                removeLonelyModelRootChangelisteners(modelListeners);
1021
                removeLonelyModelRootChangelisteners(modelListeners);
1029
                if (modelListeners.isEmpty()) {
1022
                if (modelListeners.isEmpty()) {
1030
                    filter.removeModelListener (this);
1023
                    filter.removeModelListener(this);
1031
                    model.removeModelListener (this);
1024
                    model.removeModelListener(this);
1032
                }
1025
                }
1033
            }
1026
            }
1034
        }
1027
        }
1035
1028
1036
        @Override
1029
        @Override
1037
        public void modelChanged(ModelEvent event) {
1030
        public void modelChanged(ModelEvent event) {
1038
            if (event instanceof ModelEvent.NodeChanged &&
1031
            if (event instanceof ModelEvent.NodeChanged
1039
                    (event.getSource() instanceof NodeModel || event.getSource() instanceof NodeModelFilter)) {
1032
                    && (event.getSource() instanceof NodeModel || event.getSource() instanceof NodeModelFilter)) {
1040
                // CompoundNodeModel.modelChanged() takes this.
1033
                // CompoundNodeModel.modelChanged() takes this.
1041
                return ;
1034
                return;
1042
            }
1035
            }
1043
            if (event instanceof ModelEvent.TableValueChanged &&
1036
            if (event instanceof ModelEvent.TableValueChanged
1044
                    (event.getSource() instanceof TableModel || event.getSource() instanceof TableModelFilter)) {
1037
                    && (event.getSource() instanceof TableModel || event.getSource() instanceof TableModelFilter)) {
1045
                // CompoundTableModel.modelChanged() takes this.
1038
                // CompoundTableModel.modelChanged() takes this.
1046
                return ;
1039
                return;
1047
            }
1040
            }
1048
            ModelEvent newEvent = translateEvent(event, this);
1041
            ModelEvent newEvent = translateEvent(event, this);
1049
            Collection<ModelListener> listeners;
1042
            Collection<ModelListener> listeners;
1050
            synchronized (modelListeners) {
1043
            synchronized (modelListeners) {
1051
                listeners = new ArrayList<ModelListener>(modelListeners);
1044
                listeners = new ArrayList<ModelListener>(modelListeners);
1052
            }
1045
            }
1053
            for (Iterator<ModelListener> it = listeners.iterator(); it.hasNext(); ) {
1046
            for (Iterator<ModelListener> it = listeners.iterator(); it.hasNext();) {
1054
                it.next().modelChanged(newEvent);
1047
                it.next().modelChanged(newEvent);
1055
            }
1048
            }
1056
        }
1049
        }
1057
        
1050
1058
        @Override
1051
        @Override
1059
        public String toString () {
1052
        public String toString() {
1060
            return super.toString () + "\n" + toString ("    ");
1053
            return super.toString() + "\n" + toString("    ");
1061
        }
1054
        }
1062
        
1055
1063
        public String toString (String n) {
1056
        public String toString(String n) {
1064
            if (model instanceof CompoundTreeModel) {
1057
            if (model instanceof CompoundTreeModel) {
1065
                return n + filter + "\n" +
1058
                return n + filter + "\n"
1066
                    ((CompoundTreeModel) model).toString (n + "  ");
1059
                        + ((CompoundTreeModel) model).toString(n + "  ");
1067
            }
1060
            }
1068
            return n + filter + "\n" + 
1061
            return n + filter + "\n"
1069
                   n + "  " + model;
1062
                    + n + "  " + model;
1070
        }
1063
        }
1071
1064
1072
    }
1065
    }
1073
    
1066
1074
    private static void removeLonelyModelRootChangelisteners(Collection<ModelListener> listeners) {
1067
    private static void removeLonelyModelRootChangelisteners(Collection<ModelListener> listeners) {
1075
        if (listeners.isEmpty()) {
1068
        if (listeners.isEmpty()) {
1076
            return ;
1069
            return;
1077
        }
1070
        }
1078
        for (ModelListener ml : listeners) {
1071
        for (ModelListener ml : listeners) {
1079
            if (!(ml instanceof ModelRootChangeListener)) {
1072
            if (!(ml instanceof ModelRootChangeListener)) {
1080
                return ;
1073
                return;
1081
            }
1074
            }
1082
        }
1075
        }
1083
        listeners.clear();
1076
        listeners.clear();
Lines 1092-1098 Link Here
1092
        } else if (event instanceof ModelEvent.TableValueChanged) {
1085
        } else if (event instanceof ModelEvent.TableValueChanged) {
1093
            newEvent = new ModelEvent.TableValueChanged(newSource,
1086
            newEvent = new ModelEvent.TableValueChanged(newSource,
1094
                    ((ModelEvent.TableValueChanged) event).getNode(),
1087
                    ((ModelEvent.TableValueChanged) event).getNode(),
1095
                    ((ModelEvent.TableValueChanged) event).getColumnID(),
1088
                    ((ModelEvent.TableValueChanged) event).getColumnIDs(),
1096
                    ((ModelEvent.TableValueChanged) event).getChange());
1089
                    ((ModelEvent.TableValueChanged) event).getChange());
1097
        } else if (event instanceof ModelEvent.TreeChanged) {
1090
        } else if (event instanceof ModelEvent.TreeChanged) {
1098
            newEvent = new ModelEvent.TreeChanged(newSource);
1091
            newEvent = new ModelEvent.TreeChanged(newSource);
Lines 1101-1116 Link Here
1101
        }
1094
        }
1102
        return newEvent;
1095
        return newEvent;
1103
    }
1096
    }
1104
    
1097
1105
    /**
1098
    /**
1106
     * Creates {@link org.netbeans.spi.viewmodel.TreeModel} for given TreeModel and
1099
     * Creates {@link org.netbeans.spi.viewmodel.TreeModel} for given TreeModel
1107
     * {@link org.netbeans.spi.viewmodel.TreeModelFilter}.
1100
     * and {@link org.netbeans.spi.viewmodel.TreeModelFilter}.
1108
     * 
1101
     *
1109
     * @author   Jan Jancura
1102
     * @author Jan Jancura
1110
     */
1103
     */
1111
    private final static class CompoundNodeModel implements SuperNodeModel,
1104
    private final static class CompoundNodeModel implements SuperNodeModel,
1112
                                                            ModelListener {
1105
            ModelListener {
1113
1114
1106
1115
        private SuperNodeModel model;
1107
        private SuperNodeModel model;
1116
        private NodeModelFilter filter;
1108
        private NodeModelFilter filter;
Lines 1119-1130 Link Here
1119
1111
1120
        private final Collection<ModelListener> modelListeners = new HashSet<ModelListener>();
1112
        private final Collection<ModelListener> modelListeners = new HashSet<ModelListener>();
1121
1113
1122
1123
        /**
1114
        /**
1124
         * Creates {@link org.netbeans.spi.viewmodel.TreeModel} for given TreeModel and
1115
         * Creates {@link org.netbeans.spi.viewmodel.TreeModel} for given
1125
         * {@link org.netbeans.spi.viewmodel.TreeModelFilter}.
1116
         * TreeModel and {@link org.netbeans.spi.viewmodel.TreeModelFilter}.
1126
         */
1117
         */
1127
        CompoundNodeModel (SuperNodeModel model, NodeModelFilter filter) {
1118
        CompoundNodeModel(SuperNodeModel model, NodeModelFilter filter) {
1128
            this.model = model;
1119
            this.model = model;
1129
            this.filter = filter;
1120
            this.filter = filter;
1130
            if (filter instanceof CheckNodeModelFilter) {
1121
            if (filter instanceof CheckNodeModelFilter) {
Lines 1134-1253 Link Here
1134
                this.dndfilter = (DnDNodeModelFilter) filter;
1125
                this.dndfilter = (DnDNodeModelFilter) filter;
1135
            }
1126
            }
1136
        }
1127
        }
1137
    
1128
1138
        /**
1129
        /**
1139
         * Returns display name for given node.
1130
         * Returns display name for given node.
1140
         *
1131
         *
1141
         * @throws  UnknownTypeException if this NodeModel implementation is not
1132
         * @throws UnknownTypeException if this NodeModel implementation is not
1142
         *          able to resolve display name for given node type
1133
         * able to resolve display name for given node type
1143
         * @return  display name for given node
1134
         * @return display name for given node
1144
         */
1135
         */
1145
        @Override
1136
        @Override
1146
        public String getDisplayName (Object node) 
1137
        public String getDisplayName(Object node)
1147
        throws UnknownTypeException {
1138
                throws UnknownTypeException {
1148
            return filter.getDisplayName (model, node);
1139
            return filter.getDisplayName(model, node);
1149
        }
1140
        }
1150
1141
1151
        /**
1142
        /**
1152
         * Returns icon for given node.
1143
         * Returns icon for given node.
1153
         *
1144
         *
1154
         * @throws  UnknownTypeException if this NodeModel implementation is not
1145
         * @throws UnknownTypeException if this NodeModel implementation is not
1155
         *          able to resolve icon for given node type
1146
         * able to resolve icon for given node type
1156
         * @return  icon for given node
1147
         * @return icon for given node
1157
         */
1148
         */
1158
        @Override
1149
        @Override
1159
        public String getIconBase (Object node) 
1150
        public String getIconBase(Object node)
1160
        throws UnknownTypeException {
1151
                throws UnknownTypeException {
1161
            return filter.getIconBase (model, node);
1152
            return filter.getIconBase(model, node);
1162
        }
1153
        }
1163
1154
1164
        /**
1155
        /**
1165
         * Returns tool tip for given node.
1156
         * Returns tool tip for given node.
1166
         *
1157
         *
1167
         * @throws  UnknownTypeException if this NodeModel implementation is not
1158
         * @throws UnknownTypeException if this NodeModel implementation is not
1168
         *          able to resolve tool tip for given node type
1159
         * able to resolve tool tip for given node type
1169
         * @return  tool tip for given node
1160
         * @return tool tip for given node
1170
         */
1161
         */
1171
        @Override
1162
        @Override
1172
        public String getShortDescription (Object node) 
1163
        public String getShortDescription(Object node)
1173
        throws UnknownTypeException {
1164
                throws UnknownTypeException {
1174
            return filter.getShortDescription (model, node);
1165
            return filter.getShortDescription(model, node);
1175
        }
1166
        }
1176
1167
1177
1168
        /**
1178
        /** 
1179
         * Registers given listener.
1169
         * Registers given listener.
1180
         * 
1170
         *
1181
         * @param l the listener to add
1171
         * @param l the listener to add
1182
         */
1172
         */
1183
        @Override
1173
        @Override
1184
        public void addModelListener (ModelListener l) {
1174
        public void addModelListener(ModelListener l) {
1185
            synchronized (modelListeners) {
1175
            synchronized (modelListeners) {
1186
                if (modelListeners.isEmpty()) {
1176
                if (modelListeners.isEmpty()) {
1187
                    filter.addModelListener (this);
1177
                    filter.addModelListener(this);
1188
                    model.addModelListener (this);
1178
                    model.addModelListener(this);
1189
                }
1179
                }
1190
                modelListeners.add(l);
1180
                modelListeners.add(l);
1191
            }
1181
            }
1192
        }
1182
        }
1193
1183
1194
        /** 
1184
        /**
1195
         * Unregisters given listener.
1185
         * Unregisters given listener.
1196
         *
1186
         *
1197
         * @param l the listener to remove
1187
         * @param l the listener to remove
1198
         */
1188
         */
1199
        @Override
1189
        @Override
1200
        public void removeModelListener (ModelListener l) {
1190
        public void removeModelListener(ModelListener l) {
1201
            synchronized (modelListeners) {
1191
            synchronized (modelListeners) {
1202
                modelListeners.remove(l);
1192
                modelListeners.remove(l);
1203
                removeLonelyModelRootChangelisteners(modelListeners);
1193
                removeLonelyModelRootChangelisteners(modelListeners);
1204
                if (modelListeners.isEmpty()) {
1194
                if (modelListeners.isEmpty()) {
1205
                    filter.removeModelListener (this);
1195
                    filter.removeModelListener(this);
1206
                    model.removeModelListener (this);
1196
                    model.removeModelListener(this);
1207
                }
1197
                }
1208
            }
1198
            }
1209
        }
1199
        }
1210
1200
1211
        @Override
1201
        @Override
1212
        public void modelChanged(ModelEvent event) {
1202
        public void modelChanged(ModelEvent event) {
1213
            if (event instanceof ModelEvent.TableValueChanged &&
1203
            if (event instanceof ModelEvent.TableValueChanged
1214
                    (event.getSource() instanceof TableModel || event.getSource() instanceof TableModelFilter)) {
1204
                    && (event.getSource() instanceof TableModel || event.getSource() instanceof TableModelFilter)) {
1215
                // CompoundTableModel.modelChanged() takes this.
1205
                // CompoundTableModel.modelChanged() takes this.
1216
                return ;
1206
                return;
1217
            }
1207
            }
1218
            if (event instanceof ModelEvent.TreeChanged &&
1208
            if (event instanceof ModelEvent.TreeChanged
1219
                    (event.getSource() instanceof TreeModel || event.getSource() instanceof TreeModelFilter)) {
1209
                    && (event.getSource() instanceof TreeModel || event.getSource() instanceof TreeModelFilter)) {
1220
                // CompoundTreeModel.modelChanged() takes this.
1210
                // CompoundTreeModel.modelChanged() takes this.
1221
                return ;
1211
                return;
1222
            }
1212
            }
1223
            ModelEvent newEvent = translateEvent(event, this);
1213
            ModelEvent newEvent = translateEvent(event, this);
1224
            Collection<ModelListener> listeners;
1214
            Collection<ModelListener> listeners;
1225
            synchronized (modelListeners) {
1215
            synchronized (modelListeners) {
1226
                listeners = new ArrayList<ModelListener>(modelListeners);
1216
                listeners = new ArrayList<ModelListener>(modelListeners);
1227
            }
1217
            }
1228
            for (Iterator<ModelListener> it = listeners.iterator(); it.hasNext(); ) {
1218
            for (Iterator<ModelListener> it = listeners.iterator(); it.hasNext();) {
1229
                it.next().modelChanged(newEvent);
1219
                it.next().modelChanged(newEvent);
1230
            }
1220
            }
1231
        }
1221
        }
1232
        
1222
1233
        @Override
1223
        @Override
1234
        public String toString () {
1224
        public String toString() {
1235
            return super.toString () + "\n" + toString ("    ");
1225
            return super.toString() + "\n" + toString("    ");
1236
        }
1226
        }
1237
        
1227
1238
        public String toString (String n) {
1228
        public String toString(String n) {
1239
            if (model instanceof CompoundNodeModel) {
1229
            if (model instanceof CompoundNodeModel) {
1240
                return n + filter + "\n" +
1230
                return n + filter + "\n"
1241
                    ((CompoundNodeModel) model).toString (n + "  ");
1231
                        + ((CompoundNodeModel) model).toString(n + "  ");
1242
            }
1232
            }
1243
            if (model instanceof DelegatingNodeModel) {
1233
            if (model instanceof DelegatingNodeModel) {
1244
                return n + filter + "\n" +
1234
                return n + filter + "\n"
1245
                    ((DelegatingNodeModel) model).toString (n + "  ");
1235
                        + ((DelegatingNodeModel) model).toString(n + "  ");
1246
            }
1236
            }
1247
            return n + filter + "\n" + 
1237
            return n + filter + "\n"
1248
                   n + "  " + model;
1238
                    + n + "  " + model;
1249
        }
1239
        }
1250
    
1240
1251
        @Override
1241
        @Override
1252
        public boolean canRename(Object node) throws UnknownTypeException {
1242
        public boolean canRename(Object node) throws UnknownTypeException {
1253
            if (filter instanceof ExtendedNodeModelFilter) {
1243
            if (filter instanceof ExtendedNodeModelFilter) {
Lines 1277-1283 Link Here
1277
1267
1278
        @Override
1268
        @Override
1279
        public Transferable clipboardCopy(Object node) throws IOException,
1269
        public Transferable clipboardCopy(Object node) throws IOException,
1280
                                                              UnknownTypeException {
1270
                UnknownTypeException {
1281
            if (filter instanceof ExtendedNodeModelFilter) {
1271
            if (filter instanceof ExtendedNodeModelFilter) {
1282
                return ((ExtendedNodeModelFilter) filter).clipboardCopy(model, node);
1272
                return ((ExtendedNodeModelFilter) filter).clipboardCopy(model, node);
1283
            } else {
1273
            } else {
Lines 1287-1293 Link Here
1287
1277
1288
        @Override
1278
        @Override
1289
        public Transferable clipboardCut(Object node) throws IOException,
1279
        public Transferable clipboardCut(Object node) throws IOException,
1290
                                                             UnknownTypeException {
1280
                UnknownTypeException {
1291
            if (filter instanceof ExtendedNodeModelFilter) {
1281
            if (filter instanceof ExtendedNodeModelFilter) {
1292
                return ((ExtendedNodeModelFilter) filter).clipboardCut(model, node);
1282
                return ((ExtendedNodeModelFilter) filter).clipboardCut(model, node);
1293
            } else {
1283
            } else {
Lines 1315-1321 Link Here
1315
1305
1316
        @Override
1306
        @Override
1317
        public Transferable drag(Object node) throws IOException,
1307
        public Transferable drag(Object node) throws IOException,
1318
                                                     UnknownTypeException {
1308
                UnknownTypeException {
1319
            if (dndfilter != null) {
1309
            if (dndfilter != null) {
1320
                return dndfilter.drag(model, node);
1310
                return dndfilter.drag(model, node);
1321
            } else {
1311
            } else {
Lines 1334-1340 Link Here
1334
1324
1335
        @Override
1325
        @Override
1336
        public PasteType getDropType(Object node, Transferable t, int action,
1326
        public PasteType getDropType(Object node, Transferable t, int action,
1337
                                     int index) throws UnknownTypeException {
1327
                int index) throws UnknownTypeException {
1338
            if (dndfilter != null) {
1328
            if (dndfilter != null) {
1339
                return dndfilter.getDropType(model, node, t, action, index);
1329
                return dndfilter.getDropType(model, node, t, action, index);
1340
            } else {
1330
            } else {
Lines 1366-1374 Link Here
1366
                    // The filter can not process the icon base filtering
1356
                    // The filter can not process the icon base filtering
1367
                    // Perhaps it needs to be upgraded to ExtendedNodeModelFilter
1357
                    // Perhaps it needs to be upgraded to ExtendedNodeModelFilter
1368
                    Logger.getLogger(Models.class.getName()).log(Level.CONFIG,
1358
                    Logger.getLogger(Models.class.getName()).log(Level.CONFIG,
1369
                            "The filter "+filter+" does not perform icon base filtering for "+node+".\n"+
1359
                            "The filter " + filter + " does not perform icon base filtering for " + node + ".\n"
1370
                            "If this is a problem, it should be upgraded to "+
1360
                            + "If this is a problem, it should be upgraded to "
1371
                            "ExtendedNodeModelFilter and getIconBaseWithExtension() implemented.",
1361
                            + "ExtendedNodeModelFilter and getIconBaseWithExtension() implemented.",
1372
                            utex);
1362
                            utex);
1373
                    base = model.getIconBaseWithExtension(node);
1363
                    base = model.getIconBaseWithExtension(node);
1374
                }
1364
                }
Lines 1412-1467 Link Here
1412
            }
1402
            }
1413
        }
1403
        }
1414
1404
1405
        @Override
1406
        public void setSelected(Object... nodes) throws UnknownTypeException {
1407
            if (cfilter != null) {
1408
                cfilter.setSelected(model, nodes);
1409
            } else {
1410
                model.setSelected(nodes);
1411
            }
1412
        }
1413
1414
        @Override
1415
        public void setUnselected(Object... nodes) throws UnknownTypeException {
1416
            if (cfilter != null) {
1417
                cfilter.setUnselected(model, nodes);
1418
            } else {
1419
                model.setUnselected(nodes);
1420
            }
1421
        }
1415
    }
1422
    }
1416
    
1423
1417
    /**
1424
    /**
1418
     * Creates {@link org.netbeans.spi.viewmodel.TableModel} for given TableModel and
1425
     * Creates {@link org.netbeans.spi.viewmodel.TableModel} for given
1419
     * {@link org.netbeans.spi.viewmodel.TableModelFilter}.
1426
     * TableModel and {@link org.netbeans.spi.viewmodel.TableModelFilter}.
1420
     * 
1427
     *
1421
     * @author   Jan Jancura
1428
     * @author Jan Jancura
1422
     */
1429
     */
1423
    private final static class CompoundTableModel implements TableHTMLModel, ModelListener {
1430
    private final static class CompoundTableModel implements TableHTMLModel, ModelListener {
1424
1431
1425
1426
        private TableHTMLModel model;
1432
        private TableHTMLModel model;
1427
        private TableModelFilter filter;
1433
        private TableModelFilter filter;
1428
        private TableHTMLModelFilter htmlFilter;
1434
        private TableHTMLModelFilter htmlFilter;
1429
1435
1430
        private final Collection<ModelListener> modelListeners = new HashSet<ModelListener>();
1436
        private final Collection<ModelListener> modelListeners = new HashSet<ModelListener>();
1431
1437
1432
1433
        /**
1438
        /**
1434
         * Creates {@link org.netbeans.spi.viewmodel.TableModel} for given TableModel and
1439
         * Creates {@link org.netbeans.spi.viewmodel.TableModel} for given
1435
         * {@link org.netbeans.spi.viewmodel.TableModelFilter}.
1440
         * TableModel and {@link org.netbeans.spi.viewmodel.TableModelFilter}.
1436
         */
1441
         */
1437
        CompoundTableModel (TableHTMLModel model, TableModelFilter filter) {
1442
        CompoundTableModel(TableHTMLModel model, TableModelFilter filter) {
1438
            this.model = model;
1443
            this.model = model;
1439
            this.filter = filter;
1444
            this.filter = filter;
1440
        }
1445
        }
1441
    
1446
1442
        CompoundTableModel (TableHTMLModel model, TableHTMLModelFilter htmlFilter) {
1447
        CompoundTableModel(TableHTMLModel model, TableHTMLModelFilter htmlFilter) {
1443
            this.model = model;
1448
            this.model = model;
1444
            this.htmlFilter = htmlFilter;
1449
            this.htmlFilter = htmlFilter;
1445
        }
1450
        }
1446
    
1451
1447
        /**
1452
        /**
1448
         * Returns value to be displayed in column <code>columnID</code>
1453
         * Returns value to be displayed in column <code>columnID</code> and row
1449
         * and row <code>node</code>. Column ID is defined in by 
1454
         * <code>node</code>. Column ID is defined in by
1450
         * {@link ColumnModel#getID}, and rows are defined by values returned from 
1455
         * {@link ColumnModel#getID}, and rows are defined by values returned
1451
         * {@TreeModel#getChildren}.
1456
         * from {
1452
         *
1457
         *
1453
         * @param node a object returned from {@TreeModel#getChildren} for this row
1458
         * @TreeModel#getChildren}.
1459
         *
1460
         * @param node a object returned from {
1461
         * @TreeModel#getChildren} for this row
1454
         * @param columnID a id of column defined by {@link ColumnModel#getID}
1462
         * @param columnID a id of column defined by {@link ColumnModel#getID}
1455
         * @throws UnknownTypeException if there is no TableModel defined for given
1463
         * @throws UnknownTypeException if there is no TableModel defined for
1456
         *         parameter type
1464
         * given parameter type
1457
         *
1465
         *
1458
         * @return value of variable representing given position in tree table.
1466
         * @return value of variable representing given position in tree table.
1459
         */
1467
         */
1460
        @Override
1468
        @Override
1461
        public Object getValueAt (Object node, String columnID) throws 
1469
        public Object getValueAt(Object node, String columnID) throws
1462
        UnknownTypeException {
1470
                UnknownTypeException {
1463
            if (filter != null) {
1471
            if (filter != null) {
1464
                return filter.getValueAt (model, node, columnID);
1472
                return filter.getValueAt(model, node, columnID);
1465
            } else {
1473
            } else {
1466
                return model.getValueAt(node, columnID);
1474
                return model.getValueAt(node, columnID);
1467
            }
1475
            }
Lines 1486-1568 Link Here
1486
        }
1494
        }
1487
1495
1488
        /**
1496
        /**
1489
         * Returns true if value displayed in column <code>columnID</code>
1497
         * Returns true if value displayed in column <code>columnID</code> and
1490
         * and row <code>node</code> is read only. Column ID is defined in by 
1498
         * row <code>node</code> is read only. Column ID is defined in by
1491
         * {@link ColumnModel#getID}, and rows are defined by values returned from 
1499
         * {@link ColumnModel#getID}, and rows are defined by values returned
1492
         * {@TreeModel#getChildren}.
1500
         * from {
1501
         *
1502
         * @TreeModel#getChildren}.
1493
         *
1503
         *
1494
         * @param node a object returned from {@TreeModel#getChildren} for this row
1504
         * @param node a object returned from {
1505
         * @TreeModel#getChildren} for this row
1495
         * @param columnID a id of column defined by {@link ColumnModel#getID}
1506
         * @param columnID a id of column defined by {@link ColumnModel#getID}
1496
         * @throws UnknownTypeException if there is no TableModel defined for given
1507
         * @throws UnknownTypeException if there is no TableModel defined for
1497
         *         parameter type
1508
         * given parameter type
1498
         *
1509
         *
1499
         * @return true if variable on given position is read only
1510
         * @return true if variable on given position is read only
1500
         */
1511
         */
1501
        @Override
1512
        @Override
1502
        public boolean isReadOnly (Object node, String columnID) throws 
1513
        public boolean isReadOnly(Object node, String columnID) throws
1503
        UnknownTypeException {
1514
                UnknownTypeException {
1504
            if (filter != null) {
1515
            if (filter != null) {
1505
                return filter.isReadOnly (model, node, columnID);
1516
                return filter.isReadOnly(model, node, columnID);
1506
            } else {
1517
            } else {
1507
                return model.isReadOnly(node, columnID);
1518
                return model.isReadOnly(node, columnID);
1508
            }
1519
            }
1509
        }
1520
        }
1510
1521
1511
        /**
1522
        /**
1512
         * Changes a value displayed in column <code>columnID</code>
1523
         * Changes a value displayed in column <code>columnID</code> and row
1513
         * and row <code>node</code>. Column ID is defined in by 
1524
         * <code>node</code>. Column ID is defined in by
1514
         * {@link ColumnModel#getID}, and rows are defined by values returned from 
1525
         * {@link ColumnModel#getID}, and rows are defined by values returned
1515
         * {@TreeModel#getChildren}.
1526
         * from {
1516
         *
1527
         *
1517
         * @param node a object returned from {@TreeModel#getChildren} for this row
1528
         * @TreeModel#getChildren}.
1529
         *
1530
         * @param node a object returned from {
1531
         * @TreeModel#getChildren} for this row
1518
         * @param columnID a id of column defined by {@link ColumnModel#getID}
1532
         * @param columnID a id of column defined by {@link ColumnModel#getID}
1519
         * @param value a new value of variable on given position
1533
         * @param value a new value of variable on given position
1520
         * @throws UnknownTypeException if there is no TableModel defined for given
1534
         * @throws UnknownTypeException if there is no TableModel defined for
1521
         *         parameter type
1535
         * given parameter type
1522
         */
1536
         */
1523
        @Override
1537
        @Override
1524
        public void setValueAt (Object node, String columnID, Object value) 
1538
        public void setValueAt(Object node, String columnID, Object value)
1525
        throws UnknownTypeException {
1539
                throws UnknownTypeException {
1526
            if (filter != null) {
1540
            if (filter != null) {
1527
                filter.setValueAt (model, node, columnID, value);
1541
                filter.setValueAt(model, node, columnID, value);
1528
            } else {
1542
            } else {
1529
                model.setValueAt(node, columnID, value);
1543
                model.setValueAt(node, columnID, value);
1530
            }
1544
            }
1531
        }
1545
        }
1532
1546
1533
        /** 
1547
        /**
1534
         * Registers given listener.
1548
         * Registers given listener.
1535
         * 
1549
         *
1536
         * @param l the listener to add
1550
         * @param l the listener to add
1537
         */
1551
         */
1538
        @Override
1552
        @Override
1539
        public void addModelListener (ModelListener l) {
1553
        public void addModelListener(ModelListener l) {
1540
            synchronized (modelListeners) {
1554
            synchronized (modelListeners) {
1541
                if (modelListeners.isEmpty()) {
1555
                if (modelListeners.isEmpty()) {
1542
                    if (filter != null) {
1556
                    if (filter != null) {
1543
                        filter.addModelListener (this);
1557
                        filter.addModelListener(this);
1544
                    }
1558
                    }
1545
                    model.addModelListener (this);
1559
                    model.addModelListener(this);
1546
                }
1560
                }
1547
                modelListeners.add(l);
1561
                modelListeners.add(l);
1548
            }
1562
            }
1549
        }
1563
        }
1550
1564
1551
        /** 
1565
        /**
1552
         * Unregisters given listener.
1566
         * Unregisters given listener.
1553
         *
1567
         *
1554
         * @param l the listener to remove
1568
         * @param l the listener to remove
1555
         */
1569
         */
1556
        @Override
1570
        @Override
1557
        public void removeModelListener (ModelListener l) {
1571
        public void removeModelListener(ModelListener l) {
1558
            synchronized (modelListeners) {
1572
            synchronized (modelListeners) {
1559
                modelListeners.remove(l);
1573
                modelListeners.remove(l);
1560
                removeLonelyModelRootChangelisteners(modelListeners);
1574
                removeLonelyModelRootChangelisteners(modelListeners);
1561
                if (modelListeners.isEmpty()) {
1575
                if (modelListeners.isEmpty()) {
1562
                    if (filter != null) {
1576
                    if (filter != null) {
1563
                        filter.removeModelListener (this);
1577
                        filter.removeModelListener(this);
1564
                    }
1578
                    }
1565
                    model.removeModelListener (this);
1579
                    model.removeModelListener(this);
1566
                }
1580
                }
1567
            }
1581
            }
1568
        }
1582
        }
Lines 1571-1631 Link Here
1571
        public void modelChanged(ModelEvent event) {
1585
        public void modelChanged(ModelEvent event) {
1572
            if (event instanceof ModelEvent.NodeChanged && (event.getSource() instanceof NodeModel || event.getSource() instanceof NodeModelFilter)) {
1586
            if (event instanceof ModelEvent.NodeChanged && (event.getSource() instanceof NodeModel || event.getSource() instanceof NodeModelFilter)) {
1573
                // CompoundNodeModel.modelChanged() takes this.
1587
                // CompoundNodeModel.modelChanged() takes this.
1574
                return ;
1588
                return;
1575
            }
1589
            }
1576
            if (event instanceof ModelEvent.TreeChanged &&
1590
            if (event instanceof ModelEvent.TreeChanged
1577
                    (event.getSource() instanceof TreeModel || event.getSource() instanceof TreeModelFilter)) {
1591
                    && (event.getSource() instanceof TreeModel || event.getSource() instanceof TreeModelFilter)) {
1578
                // CompoundTreeModel.modelChanged() takes this.
1592
                // CompoundTreeModel.modelChanged() takes this.
1579
                return ;
1593
                return;
1580
            }
1594
            }
1581
            ModelEvent newEvent = translateEvent(event, this);
1595
            ModelEvent newEvent = translateEvent(event, this);
1582
            Collection<ModelListener> listeners;
1596
            Collection<ModelListener> listeners;
1583
            synchronized (modelListeners) {
1597
            synchronized (modelListeners) {
1584
                listeners = new ArrayList<ModelListener>(modelListeners);
1598
                listeners = new ArrayList<ModelListener>(modelListeners);
1585
            }
1599
            }
1586
            for (Iterator<ModelListener> it = listeners.iterator(); it.hasNext(); ) {
1600
            for (Iterator<ModelListener> it = listeners.iterator(); it.hasNext();) {
1587
                it.next().modelChanged(newEvent);
1601
                it.next().modelChanged(newEvent);
1588
            }
1602
            }
1589
        }
1603
        }
1590
        
1604
1591
        @Override
1605
        @Override
1592
        public String toString () {
1606
        public String toString() {
1593
            return super.toString () + "\n" + toString ("    ");
1607
            return super.toString() + "\n" + toString("    ");
1594
        }
1608
        }
1595
        
1609
1596
        public String toString (String n) {
1610
        public String toString(String n) {
1597
            Model theFilter = (filter != null) ? filter : htmlFilter;
1611
            Model theFilter = (filter != null) ? filter : htmlFilter;
1598
            if (model instanceof CompoundTableModel) {
1612
            if (model instanceof CompoundTableModel) {
1599
                return n + theFilter + "\n" +
1613
                return n + theFilter + "\n"
1600
                    ((CompoundTableModel) model).toString (n + "  ");
1614
                        + ((CompoundTableModel) model).toString(n + "  ");
1601
            }
1615
            }
1602
            if (model instanceof DelegatingTableModel) {
1616
            if (model instanceof DelegatingTableModel) {
1603
                return n + theFilter + "\n" +
1617
                return n + theFilter + "\n"
1604
                    ((DelegatingTableModel) model).toString (n + "  ");
1618
                        + ((DelegatingTableModel) model).toString(n + "  ");
1605
            }
1619
            }
1606
            return n + theFilter + "\n" + 
1620
            return n + theFilter + "\n"
1607
                   n + "  " + model;
1621
                    + n + "  " + model;
1608
        }
1622
        }
1609
    }
1623
    }
1610
1624
1611
    /**
1625
    /**
1612
     * Creates {@link org.netbeans.spi.viewmodel.TableRendererModel} for given TableRendererModel and
1626
     * Creates {@link org.netbeans.spi.viewmodel.TableRendererModel} for given
1627
     * TableRendererModel and
1613
     * {@link org.netbeans.spi.viewmodel.TableRendererModelFilter}.
1628
     * {@link org.netbeans.spi.viewmodel.TableRendererModelFilter}.
1614
     */
1629
     */
1615
    private final static class CompoundTableRendererModel implements TableRendererModel, ModelListener {
1630
    private final static class CompoundTableRendererModel implements TableRendererModel, ModelListener {
1616
1631
1617
1618
        private TableRendererModel model;
1632
        private TableRendererModel model;
1619
        private TableRendererModelFilter filter;
1633
        private TableRendererModelFilter filter;
1620
1634
1621
        private final Collection<ModelListener> modelListeners = new HashSet<ModelListener>();
1635
        private final Collection<ModelListener> modelListeners = new HashSet<ModelListener>();
1622
1636
1623
1624
        /**
1637
        /**
1625
         * Creates {@link org.netbeans.spi.viewmodel.TableRendererModel} for given TableRendererModel and
1638
         * Creates {@link org.netbeans.spi.viewmodel.TableRendererModel} for
1639
         * given TableRendererModel and
1626
         * {@link org.netbeans.spi.viewmodel.TableRendererModelFilter}.
1640
         * {@link org.netbeans.spi.viewmodel.TableRendererModelFilter}.
1627
         */
1641
         */
1628
        CompoundTableRendererModel (TableRendererModel model, TableRendererModelFilter filter) {
1642
        CompoundTableRendererModel(TableRendererModel model, TableRendererModelFilter filter) {
1629
            this.model = model;
1643
            this.model = model;
1630
            this.filter = filter;
1644
            this.filter = filter;
1631
        }
1645
        }
Lines 1649-1666 Link Here
1649
        public TableCellEditor getCellEditor(Object node, String columnID) throws UnknownTypeException {
1663
        public TableCellEditor getCellEditor(Object node, String columnID) throws UnknownTypeException {
1650
            return filter.getCellEditor(model, node, columnID);
1664
            return filter.getCellEditor(model, node, columnID);
1651
        }
1665
        }
1652
        
1666
1653
        /**
1667
        /**
1654
         * Registers given listener.
1668
         * Registers given listener.
1655
         *
1669
         *
1656
         * @param l the listener to add
1670
         * @param l the listener to add
1657
         */
1671
         */
1658
        @Override
1672
        @Override
1659
        public void addModelListener (ModelListener l) {
1673
        public void addModelListener(ModelListener l) {
1660
            synchronized (modelListeners) {
1674
            synchronized (modelListeners) {
1661
                if (modelListeners.isEmpty()) {
1675
                if (modelListeners.isEmpty()) {
1662
                    filter.addModelListener (this);
1676
                    filter.addModelListener(this);
1663
                    model.addModelListener (this);
1677
                    model.addModelListener(this);
1664
                }
1678
                }
1665
                modelListeners.add(l);
1679
                modelListeners.add(l);
1666
            }
1680
            }
Lines 1672-1684 Link Here
1672
         * @param l the listener to remove
1686
         * @param l the listener to remove
1673
         */
1687
         */
1674
        @Override
1688
        @Override
1675
        public void removeModelListener (ModelListener l) {
1689
        public void removeModelListener(ModelListener l) {
1676
            synchronized (modelListeners) {
1690
            synchronized (modelListeners) {
1677
                modelListeners.remove(l);
1691
                modelListeners.remove(l);
1678
                removeLonelyModelRootChangelisteners(modelListeners);
1692
                removeLonelyModelRootChangelisteners(modelListeners);
1679
                if (modelListeners.isEmpty()) {
1693
                if (modelListeners.isEmpty()) {
1680
                    filter.removeModelListener (this);
1694
                    filter.removeModelListener(this);
1681
                    model.removeModelListener (this);
1695
                    model.removeModelListener(this);
1682
                }
1696
                }
1683
            }
1697
            }
1684
        }
1698
        }
Lines 1687-1887 Link Here
1687
        public void modelChanged(ModelEvent event) {
1701
        public void modelChanged(ModelEvent event) {
1688
            if (event instanceof ModelEvent.NodeChanged && (event.getSource() instanceof NodeModel || event.getSource() instanceof NodeModelFilter)) {
1702
            if (event instanceof ModelEvent.NodeChanged && (event.getSource() instanceof NodeModel || event.getSource() instanceof NodeModelFilter)) {
1689
                // CompoundNodeModel.modelChanged() takes this.
1703
                // CompoundNodeModel.modelChanged() takes this.
1690
                return ;
1704
                return;
1691
            }
1705
            }
1692
            if (event instanceof ModelEvent.TreeChanged &&
1706
            if (event instanceof ModelEvent.TreeChanged
1693
                    (event.getSource() instanceof TreeModel || event.getSource() instanceof TreeModelFilter)) {
1707
                    && (event.getSource() instanceof TreeModel || event.getSource() instanceof TreeModelFilter)) {
1694
                // CompoundTreeModel.modelChanged() takes this.
1708
                // CompoundTreeModel.modelChanged() takes this.
1695
                return ;
1709
                return;
1696
            }
1710
            }
1697
            ModelEvent newEvent = translateEvent(event, this);
1711
            ModelEvent newEvent = translateEvent(event, this);
1698
            Collection<ModelListener> listeners;
1712
            Collection<ModelListener> listeners;
1699
            synchronized (modelListeners) {
1713
            synchronized (modelListeners) {
1700
                listeners = new ArrayList<ModelListener>(modelListeners);
1714
                listeners = new ArrayList<ModelListener>(modelListeners);
1701
            }
1715
            }
1702
            for (Iterator<ModelListener> it = listeners.iterator(); it.hasNext(); ) {
1716
            for (Iterator<ModelListener> it = listeners.iterator(); it.hasNext();) {
1703
                it.next().modelChanged(newEvent);
1717
                it.next().modelChanged(newEvent);
1704
            }
1718
            }
1705
        }
1719
        }
1706
1720
1707
        @Override
1721
        @Override
1708
        public String toString () {
1722
        public String toString() {
1709
            return super.toString () + "\n" + toString ("    ");
1723
            return super.toString() + "\n" + toString("    ");
1710
        }
1724
        }
1711
1725
1712
        public String toString (String n) {
1726
        public String toString(String n) {
1713
            if (model instanceof CompoundTableRendererModel) {
1727
            if (model instanceof CompoundTableRendererModel) {
1714
                return n + filter + "\n" +
1728
                return n + filter + "\n"
1715
                    ((CompoundTableRendererModel) model).toString (n + "  ");
1729
                        + ((CompoundTableRendererModel) model).toString(n + "  ");
1716
            }
1730
            }
1717
            if (model instanceof DelegatingTableRendererModel) {
1731
            if (model instanceof DelegatingTableRendererModel) {
1718
                return n + filter + "\n" +
1732
                return n + filter + "\n"
1719
                    ((DelegatingTableRendererModel) model).toString (n + "  ");
1733
                        + ((DelegatingTableRendererModel) model).toString(n + "  ");
1720
            }
1734
            }
1721
            return n + filter + "\n" +
1735
            return n + filter + "\n"
1722
                   n + "  " + model;
1736
                    + n + "  " + model;
1723
        }
1737
        }
1724
1738
1725
    }
1739
    }
1726
1740
1727
    /**
1741
    /**
1728
     * Creates one {@link org.netbeans.spi.viewmodel.TreeModel}
1742
     * Creates one {@link org.netbeans.spi.viewmodel.TreeModel} from given list
1729
     * from given list of TreeModels. DelegatingTreeModel asks all underlaying 
1743
     * of TreeModels. DelegatingTreeModel asks all underlaying models for each
1730
     * models for each concrete parameter, and returns first returned value.
1744
     * concrete parameter, and returns first returned value.
1731
     *
1745
     *
1732
     * @author   Jan Jancura
1746
     * @author Jan Jancura
1733
     */
1747
     */
1734
    private final static class DelegatingTreeModel implements ReorderableTreeModel {
1748
    private final static class DelegatingTreeModel implements ReorderableTreeModel {
1735
1749
1736
        private TreeModel[] models;
1750
        private TreeModel[] models;
1737
        private HashMap<String, TreeModel> classNameToModel = new HashMap<String, TreeModel>();
1751
        private HashMap<String, TreeModel> classNameToModel = new HashMap<String, TreeModel>();
1738
1752
1739
1740
        /**
1753
        /**
1741
         * Creates new instance of DelegatingTreeModel for given list of 
1754
         * Creates new instance of DelegatingTreeModel for given list of
1742
         * TableModels.
1755
         * TableModels.
1743
         *
1756
         *
1744
         * @param models a list of TableModels
1757
         * @param models a list of TableModels
1745
         */
1758
         */
1746
        DelegatingTreeModel (List<TreeModel> models) {
1759
        DelegatingTreeModel(List<TreeModel> models) {
1747
            this (convert (models));
1760
            this(convert(models));
1748
        }
1761
        }
1749
1762
1750
        private static TreeModel[] convert (List<TreeModel> l) {
1763
        private static TreeModel[] convert(List<TreeModel> l) {
1751
            TreeModel[] models = new TreeModel [l.size ()];
1764
            TreeModel[] models = new TreeModel[l.size()];
1752
                return l.toArray (models);
1765
            return l.toArray(models);
1753
            }
1766
        }
1754
1767
1755
        /**
1768
        /**
1756
         * Creates new instance of DelegatingTreeModel for given array of 
1769
         * Creates new instance of DelegatingTreeModel for given array of
1757
         * TableModels.
1770
         * TableModels.
1758
         *
1771
         *
1759
         * @param models a array of TreeModel
1772
         * @param models a array of TreeModel
1760
         */
1773
         */
1761
        private DelegatingTreeModel (TreeModel[] models) {
1774
        private DelegatingTreeModel(TreeModel[] models) {
1762
            this.models = models;        
1775
            this.models = models;
1763
        }
1776
        }
1764
        
1777
1765
        /** 
1778
        /**
1766
         * Returns the root node of the tree or null, if the tree is empty.
1779
         * Returns the root node of the tree or null, if the tree is empty.
1767
         *
1780
         *
1768
         * @return the root node of the tree or null
1781
         * @return the root node of the tree or null
1769
         */
1782
         */
1770
        @Override
1783
        @Override
1771
        public Object getRoot () {
1784
        public Object getRoot() {
1772
            return models [0].getRoot ();
1785
            return models[0].getRoot();
1773
        }
1786
        }
1774
1787
1775
        /** 
1788
        /**
1776
         * Returns children for given parent on given indexes.
1789
         * Returns children for given parent on given indexes.
1777
         *
1790
         *
1778
         * @param   parent a parent of returned nodes
1791
         * @param parent a parent of returned nodes
1779
         * @param   from a start index
1792
         * @param from a start index
1780
         * @param   to a end index
1793
         * @param to a end index
1781
         *
1794
         *
1782
         * @throws  UnknownTypeException if this TreeModel implementation is not
1795
         * @throws UnknownTypeException if this TreeModel implementation is not
1783
         *          able to resolve children for given node type
1796
         * able to resolve children for given node type
1784
         *
1797
         *
1785
         * @return  children for given parent on given indexes
1798
         * @return children for given parent on given indexes
1786
         */
1799
         */
1787
        @Override
1800
        @Override
1788
        public Object[] getChildren (Object node, int from, int to)
1801
        public Object[] getChildren(Object node, int from, int to)
1789
        throws UnknownTypeException {
1802
                throws UnknownTypeException {
1790
            TreeModel model = classNameToModel.get (
1803
            TreeModel model = classNameToModel.get(
1791
                node.getClass ().getName ()
1804
                    node.getClass().getName()
1792
            );
1805
            );
1793
            if (model != null) {
1806
            if (model != null) {
1794
                try {
1807
                try {
1795
                    return model.getChildren (node, from, to);
1808
                    return model.getChildren(node, from, to);
1796
                } catch (UnknownTypeException e) {
1809
                } catch (UnknownTypeException e) {
1797
                }
1810
                }
1798
            }
1811
            }
1799
            int i, k = models.length;
1812
            int i, k = models.length;
1800
            for (i = 0; i < k; i++) {
1813
            for (i = 0; i < k; i++) {
1801
                try {
1814
                try {
1802
                    Object[] v = models [i].getChildren (node, from, to);
1815
                    Object[] v = models[i].getChildren(node, from, to);
1803
                    classNameToModel.put (node.getClass ().getName (), models [i]);
1816
                    classNameToModel.put(node.getClass().getName(), models[i]);
1804
                    return v;
1817
                    return v;
1805
                } catch (UnknownTypeException e) {
1818
                } catch (UnknownTypeException e) {
1806
                }
1819
                }
1807
            }
1820
            }
1808
            throw new UnknownTypeException (node);
1821
            throw new UnknownTypeException(node);
1809
        }    
1822
        }
1810
1823
1811
        /**
1824
        /**
1812
         * Returns number of children for given node.
1825
         * Returns number of children for given node.
1813
         * 
1814
         * @param   node the parent node
1815
         * @throws  UnknownTypeException if this TreeModel implementation is not
1816
         *          able to resolve children for given node type
1817
         *
1826
         *
1818
         * @return  true if node is leaf
1827
         * @param node the parent node
1828
         * @throws UnknownTypeException if this TreeModel implementation is not
1829
         * able to resolve children for given node type
1830
         *
1831
         * @return true if node is leaf
1819
         * @since 1.1
1832
         * @since 1.1
1820
         */
1833
         */
1821
        @Override
1834
        @Override
1822
        public int getChildrenCount (Object node) 
1835
        public int getChildrenCount(Object node)
1823
        throws UnknownTypeException {
1836
                throws UnknownTypeException {
1824
            TreeModel model = (TreeModel) classNameToModel.get (
1837
            TreeModel model = (TreeModel) classNameToModel.get(
1825
                node.getClass ().getName ()
1838
                    node.getClass().getName()
1826
            );
1839
            );
1827
            if (model != null) {
1840
            if (model != null) {
1828
                try {
1841
                try {
1829
                    return model.getChildrenCount (node);
1842
                    return model.getChildrenCount(node);
1830
                } catch (UnknownTypeException e) {
1843
                } catch (UnknownTypeException e) {
1831
                }
1844
                }
1832
            }
1845
            }
1833
            int i, k = models.length;
1846
            int i, k = models.length;
1834
            for (i = 0; i < k; i++) {
1847
            for (i = 0; i < k; i++) {
1835
                try {
1848
                try {
1836
                    int result = models [i].getChildrenCount (node);
1849
                    int result = models[i].getChildrenCount(node);
1837
                    classNameToModel.put (node.getClass ().getName (), models [i]);
1850
                    classNameToModel.put(node.getClass().getName(), models[i]);
1838
                    return result;
1851
                    return result;
1839
                } catch (UnknownTypeException e) {
1852
                } catch (UnknownTypeException e) {
1840
                }
1853
                }
1841
            }
1854
            }
1842
            throw new UnknownTypeException (node);
1855
            throw new UnknownTypeException(node);
1843
        }    
1856
        }
1844
1857
1845
        /**
1858
        /**
1846
         * Returns true if node is leaf.
1859
         * Returns true if node is leaf.
1847
         * 
1860
         *
1848
         * @throws  UnknownTypeException if this TreeModel implementation is not
1861
         * @throws UnknownTypeException if this TreeModel implementation is not
1849
         *          able to resolve children for given node type
1862
         * able to resolve children for given node type
1850
         * @return  true if node is leaf
1863
         * @return true if node is leaf
1851
         */
1864
         */
1852
        @Override
1865
        @Override
1853
        public boolean isLeaf (Object node) throws UnknownTypeException {
1866
        public boolean isLeaf(Object node) throws UnknownTypeException {
1854
            TreeModel model = classNameToModel.get (
1867
            TreeModel model = classNameToModel.get(
1855
                node.getClass ().getName ()
1868
                    node.getClass().getName()
1856
            );
1869
            );
1857
            if (model != null) {
1870
            if (model != null) {
1858
                try {
1871
                try {
1859
                    return model.isLeaf (node);
1872
                    return model.isLeaf(node);
1860
                } catch (UnknownTypeException e) {
1873
                } catch (UnknownTypeException e) {
1861
                }
1874
                }
1862
            }
1875
            }
1863
            int i, k = models.length;
1876
            int i, k = models.length;
1864
            for (i = 0; i < k; i++) {
1877
            for (i = 0; i < k; i++) {
1865
                try {
1878
                try {
1866
                    boolean result = models [i].isLeaf (node);
1879
                    boolean result = models[i].isLeaf(node);
1867
                    classNameToModel.put (node.getClass ().getName (), models [i]);
1880
                    classNameToModel.put(node.getClass().getName(), models[i]);
1868
                    return result;
1881
                    return result;
1869
                } catch (UnknownTypeException e) {
1882
                } catch (UnknownTypeException e) {
1870
                }
1883
                }
1871
            }
1884
            }
1872
            throw new UnknownTypeException (node);
1885
            throw new UnknownTypeException(node);
1873
        }
1886
        }
1874
1887
1875
        @Override
1888
        @Override
1876
        public boolean canReorder(Object parent) throws UnknownTypeException {
1889
        public boolean canReorder(Object parent) throws UnknownTypeException {
1877
            UnknownTypeException uex = null;
1890
            UnknownTypeException uex = null;
1878
            TreeModel model = classNameToModel.get (
1891
            TreeModel model = classNameToModel.get(
1879
                parent.getClass ().getName ()
1892
                    parent.getClass().getName()
1880
            );
1893
            );
1881
            if (model != null) {
1894
            if (model != null) {
1882
                if (model instanceof ReorderableTreeModel) {
1895
                if (model instanceof ReorderableTreeModel) {
1883
                    try {
1896
                    try {
1884
                        return ((ReorderableTreeModel) model).canReorder (parent);
1897
                        return ((ReorderableTreeModel) model).canReorder(parent);
1885
                    } catch (UnknownTypeException e) {
1898
                    } catch (UnknownTypeException e) {
1886
                        uex = e;
1899
                        uex = e;
1887
                    }
1900
                    }
Lines 1892-1898 Link Here
1892
            for (i = 0; i < k; i++) {
1905
            for (i = 0; i < k; i++) {
1893
                if (models[i] instanceof ReorderableTreeModel) {
1906
                if (models[i] instanceof ReorderableTreeModel) {
1894
                    try {
1907
                    try {
1895
                        boolean cr = ((ReorderableTreeModel) models [i]).canReorder (parent);
1908
                        boolean cr = ((ReorderableTreeModel) models[i]).canReorder(parent);
1896
                        //classNameToModel.put (parent.getClass ().getName (), models [i]);
1909
                        //classNameToModel.put (parent.getClass ().getName (), models [i]);
1897
                        return cr;
1910
                        return cr;
1898
                    } catch (UnknownTypeException e) {
1911
                    } catch (UnknownTypeException e) {
Lines 1907-1925 Link Here
1907
            if (uex != null) {
1920
            if (uex != null) {
1908
                throw uex;
1921
                throw uex;
1909
            } else {
1922
            } else {
1910
                throw new UnknownTypeException (parent);
1923
                throw new UnknownTypeException(parent);
1911
            }
1924
            }
1912
        }
1925
        }
1913
1926
1914
        @Override
1927
        @Override
1915
        public void reorder(Object parent, int[] perm) throws UnknownTypeException {
1928
        public void reorder(Object parent, int[] perm) throws UnknownTypeException {
1916
            TreeModel model = (TreeModel) classNameToModel.get (
1929
            TreeModel model = (TreeModel) classNameToModel.get(
1917
                parent.getClass ().getName ()
1930
                    parent.getClass().getName()
1918
            );
1931
            );
1919
            if (model instanceof ReorderableTreeModel) {
1932
            if (model instanceof ReorderableTreeModel) {
1920
                try {
1933
                try {
1921
                    ((ReorderableTreeModel) model).reorder(parent, perm);
1934
                    ((ReorderableTreeModel) model).reorder(parent, perm);
1922
                    return ;
1935
                    return;
1923
                } catch (UnknownTypeException e) {
1936
                } catch (UnknownTypeException e) {
1924
                }
1937
                }
1925
            }
1938
            }
Lines 1929-1952 Link Here
1929
                    try {
1942
                    try {
1930
                        ((ReorderableTreeModel) models[i]).reorder(parent, perm);
1943
                        ((ReorderableTreeModel) models[i]).reorder(parent, perm);
1931
                        //classNameToModel.put (parent.getClass ().getName (), models [i]);
1944
                        //classNameToModel.put (parent.getClass ().getName (), models [i]);
1932
                        return ;
1945
                        return;
1933
                    } catch (UnknownTypeException e) {
1946
                    } catch (UnknownTypeException e) {
1934
                    }
1947
                    }
1935
                }
1948
                }
1936
            }
1949
            }
1937
            throw new UnknownTypeException (parent);
1950
            throw new UnknownTypeException(parent);
1938
        }
1951
        }
1939
1952
1940
        /** 
1953
        /**
1941
         * Registers given listener.
1954
         * Registers given listener.
1942
         * 
1955
         *
1943
         * @param l the listener to add
1956
         * @param l the listener to add
1944
         */
1957
         */
1945
        @Override
1958
        @Override
1946
        public void addModelListener (ModelListener l) {
1959
        public void addModelListener(ModelListener l) {
1947
            int i, k = models.length;
1960
            int i, k = models.length;
1948
            for (i = 0; i < k; i++) {
1961
            for (i = 0; i < k; i++) {
1949
                models [i].addModelListener (l);
1962
                models[i].addModelListener(l);
1950
            }
1963
            }
1951
        }
1964
        }
1952
1965
Lines 1955-2015 Link Here
1955
         *
1968
         *
1956
         * @param l the listener to add
1969
         * @param l the listener to add
1957
         */
1970
         */
1958
        void addModelListener (ModelListener l, Set<Model> modelsListenersAddedTo) {
1971
        void addModelListener(ModelListener l, Set<Model> modelsListenersAddedTo) {
1959
            int i, k = models.length;
1972
            int i, k = models.length;
1960
            for (i = 0; i < k; i++) {
1973
            for (i = 0; i < k; i++) {
1961
                TreeModel m = models [i];
1974
                TreeModel m = models[i];
1962
                if (!modelsListenersAddedTo.add(m)) {
1975
                if (!modelsListenersAddedTo.add(m)) {
1963
                    continue;
1976
                    continue;
1964
                }
1977
                }
1965
                if (m instanceof DelegatingTreeModel) {
1978
                if (m instanceof DelegatingTreeModel) {
1966
                    ((DelegatingTreeModel) m).addModelListener(l, modelsListenersAddedTo);
1979
                    ((DelegatingTreeModel) m).addModelListener(l, modelsListenersAddedTo);
1967
                } else {
1980
                } else {
1968
                    m.addModelListener (l);
1981
                    m.addModelListener(l);
1969
                }
1982
                }
1970
            }
1983
            }
1971
        }
1984
        }
1972
1985
1973
        /** 
1986
        /**
1974
         * Unregisters given listener.
1987
         * Unregisters given listener.
1975
         *
1988
         *
1976
         * @param l the listener to remove
1989
         * @param l the listener to remove
1977
         */
1990
         */
1978
        @Override
1991
        @Override
1979
        public void removeModelListener (ModelListener l) {
1992
        public void removeModelListener(ModelListener l) {
1980
            int i, k = models.length;
1993
            int i, k = models.length;
1981
            for (i = 0; i < k; i++) {
1994
            for (i = 0; i < k; i++) {
1982
                models [i].removeModelListener (l);
1995
                models[i].removeModelListener(l);
1983
            }
1996
            }
1984
        }
1997
        }
1985
1998
1986
        @Override
1999
        @Override
1987
        public String toString () {
2000
        public String toString() {
1988
            return super.toString () + "\n" + toString ("    ");
2001
            return super.toString() + "\n" + toString("    ");
1989
        }
2002
        }
1990
        
2003
1991
        public String toString (String n) {
2004
        public String toString(String n) {
1992
            int i, k = models.length - 1;
2005
            int i, k = models.length - 1;
1993
            if (k == -1) {
2006
            if (k == -1) {
1994
                return "";
2007
                return "";
1995
            }
2008
            }
1996
            StringBuffer sb = new StringBuffer ();
2009
            StringBuffer sb = new StringBuffer();
1997
            for (i = 0; i < k; i++) {
2010
            for (i = 0; i < k; i++) {
1998
                sb.append (n);
2011
                sb.append(n);
1999
                sb.append (models [i]);
2012
                sb.append(models[i]);
2000
                sb.append ('\n');
2013
                sb.append('\n');
2001
            }
2014
            }
2002
            sb.append (n);
2015
            sb.append(n);
2003
            sb.append (models [i]);
2016
            sb.append(models[i]);
2004
            return new String (sb);
2017
            return new String(sb);
2005
        }
2018
        }
2006
    }
2019
    }
2007
    
2020
2008
    private final static class CompoundTablePropertyEditorsModel implements TablePropertyEditorsModel {
2021
    private final static class CompoundTablePropertyEditorsModel implements TablePropertyEditorsModel {
2009
        
2022
2010
        private TablePropertyEditorsModel model;
2023
        private TablePropertyEditorsModel model;
2011
        private TablePropertyEditorsModelFilter filter;
2024
        private TablePropertyEditorsModelFilter filter;
2012
        
2025
2013
        CompoundTablePropertyEditorsModel(TablePropertyEditorsModel model, TablePropertyEditorsModelFilter filter) {
2026
        CompoundTablePropertyEditorsModel(TablePropertyEditorsModel model, TablePropertyEditorsModelFilter filter) {
2014
            this.model = model;
2027
            this.model = model;
2015
            this.filter = filter;
2028
            this.filter = filter;
Lines 2019-2125 Link Here
2019
        public PropertyEditor getPropertyEditor(Object node, String columnID) throws UnknownTypeException {
2032
        public PropertyEditor getPropertyEditor(Object node, String columnID) throws UnknownTypeException {
2020
            return filter.getPropertyEditor(model, node, columnID);
2033
            return filter.getPropertyEditor(model, node, columnID);
2021
        }
2034
        }
2022
        
2035
2023
        @Override
2036
        @Override
2024
        public String toString () {
2037
        public String toString() {
2025
            return super.toString () + "\n" + toString ("    ");
2038
            return super.toString() + "\n" + toString("    ");
2026
        }
2039
        }
2027
2040
2028
        public String toString (String n) {
2041
        public String toString(String n) {
2029
            if (model instanceof CompoundTablePropertyEditorsModel) {
2042
            if (model instanceof CompoundTablePropertyEditorsModel) {
2030
                return n + filter + "\n" +
2043
                return n + filter + "\n"
2031
                    ((CompoundTablePropertyEditorsModel) model).toString (n + "  ");
2044
                        + ((CompoundTablePropertyEditorsModel) model).toString(n + "  ");
2032
            }
2045
            }
2033
            if (model instanceof DelegatingTablePropertyEditorsModel) {
2046
            if (model instanceof DelegatingTablePropertyEditorsModel) {
2034
                return n + filter + "\n" +
2047
                return n + filter + "\n"
2035
                    ((DelegatingTablePropertyEditorsModel) model).toString (n + "  ");
2048
                        + ((DelegatingTablePropertyEditorsModel) model).toString(n + "  ");
2036
            }
2049
            }
2037
            return n + filter + "\n" +
2050
            return n + filter + "\n"
2038
                   n + "  " + model;
2051
                    + n + "  " + model;
2039
        }
2052
        }
2040
    }
2053
    }
2041
    
2054
2042
    /**
2055
    /**
2043
     * Creates {@link org.netbeans.spi.viewmodel.NodeActionsProvider} 
2056
     * Creates {@link org.netbeans.spi.viewmodel.NodeActionsProvider} for given
2044
     * for given NodeActionsProvider and
2057
     * NodeActionsProvider and
2045
     * {@link org.netbeans.spi.viewmodel.NodeActionsProviderFilter}.
2058
     * {@link org.netbeans.spi.viewmodel.NodeActionsProviderFilter}.
2046
     * 
2059
     *
2047
     * @author   Jan Jancura
2060
     * @author Jan Jancura
2048
     */
2061
     */
2049
    private final static class CompoundNodeActionsProvider 
2062
    private final static class CompoundNodeActionsProvider
2050
    implements NodeActionsProvider {
2063
            implements NodeActionsProvider {
2051
2052
2064
2053
        private NodeActionsProvider model;
2065
        private NodeActionsProvider model;
2054
        private NodeActionsProviderFilter filter;
2066
        private NodeActionsProviderFilter filter;
2055
2067
2056
2057
        /**
2068
        /**
2058
         * Creates {@link org.netbeans.spi.viewmodel.NodeActionsProvider} 
2069
         * Creates {@link org.netbeans.spi.viewmodel.NodeActionsProvider} for
2059
         * for given NodeActionsProvider and
2070
         * given NodeActionsProvider and
2060
         * {@link org.netbeans.spi.viewmodel.NodeActionsProviderFilter}.
2071
         * {@link org.netbeans.spi.viewmodel.NodeActionsProviderFilter}.
2061
         */
2072
         */
2062
        CompoundNodeActionsProvider (
2073
        CompoundNodeActionsProvider(
2063
            NodeActionsProvider model, 
2074
                NodeActionsProvider model,
2064
            NodeActionsProviderFilter filter
2075
                NodeActionsProviderFilter filter
2065
        ) {
2076
        ) {
2066
            this.model = model;
2077
            this.model = model;
2067
            this.filter = filter;
2078
            this.filter = filter;
2068
        }
2079
        }
2069
    
2080
2070
        /**
2081
        /**
2071
         * Performs default action for given node.
2082
         * Performs default action for given node.
2072
         *
2083
         *
2073
         * @throws  UnknownTypeException if this NodeActionsProvider 
2084
         * @throws UnknownTypeException if this NodeActionsProvider
2074
         *          implementation is not able to resolve actions 
2085
         * implementation is not able to resolve actions for given node type
2075
         *          for given node type
2086
         * @return display name for given node
2076
         * @return  display name for given node
2077
         */
2087
         */
2078
        @Override
2088
        @Override
2079
        public void performDefaultAction (Object node) 
2089
        public void performDefaultAction(Object node)
2080
        throws UnknownTypeException {
2090
                throws UnknownTypeException {
2081
            filter.performDefaultAction (model, node);
2091
            filter.performDefaultAction(model, node);
2082
        }
2092
        }
2083
2093
2084
        /**
2094
        /**
2085
         * Returns set of actions for given node.
2095
         * Returns set of actions for given node.
2086
         *
2096
         *
2087
         * @throws  UnknownTypeException if this NodeActionsProvider implementation 
2097
         * @throws UnknownTypeException if this NodeActionsProvider
2088
         *          is not able to resolve actions for given node type
2098
         * implementation is not able to resolve actions for given node type
2089
         * @return  display name for given node
2099
         * @return display name for given node
2090
         */
2100
         */
2091
        @Override
2101
        @Override
2092
        public Action[] getActions (Object node) 
2102
        public Action[] getActions(Object node)
2093
        throws UnknownTypeException {
2103
                throws UnknownTypeException {
2094
            return filter.getActions (model, node);
2104
            return filter.getActions(model, node);
2095
        }
2105
        }
2096
2106
2097
        @Override
2107
        @Override
2098
        public String toString () {
2108
        public String toString() {
2099
            return super.toString () + "\n" + toString ("    ");
2109
            return super.toString() + "\n" + toString("    ");
2100
        }
2110
        }
2101
        
2111
2102
        public String toString (String n) {
2112
        public String toString(String n) {
2103
            if (model instanceof CompoundNodeActionsProvider) {
2113
            if (model instanceof CompoundNodeActionsProvider) {
2104
                return n + filter + "\n" +
2114
                return n + filter + "\n"
2105
                    ((CompoundNodeActionsProvider) model).toString (n + "  ");
2115
                        + ((CompoundNodeActionsProvider) model).toString(n + "  ");
2106
            }
2116
            }
2107
            if (model instanceof DelegatingNodeActionsProvider) {
2117
            if (model instanceof DelegatingNodeActionsProvider) {
2108
                return n + filter + "\n" +
2118
                return n + filter + "\n"
2109
                    ((DelegatingNodeActionsProvider) model).toString (n + "  ");
2119
                        + ((DelegatingNodeActionsProvider) model).toString(n + "  ");
2110
            }
2120
            }
2111
            return n + filter + "\n" + 
2121
            return n + filter + "\n"
2112
                   n + "  " + model;
2122
                    + n + "  " + model;
2113
        }
2123
        }
2114
    }
2124
    }
2115
    
2125
2116
    private final static class CompoundTreeExpansionModel implements TreeExpansionModel, ModelListener {
2126
    private final static class CompoundTreeExpansionModel implements TreeExpansionModel, ModelListener {
2117
        
2127
2118
        private TreeExpansionModel expansionModel;
2128
        private TreeExpansionModel expansionModel;
2119
        private TreeExpansionModelFilter expansionFilter;
2129
        private TreeExpansionModelFilter expansionFilter;
2120
        
2130
2121
        private final Collection<ModelListener> modelListeners = new HashSet<ModelListener>();
2131
        private final Collection<ModelListener> modelListeners = new HashSet<ModelListener>();
2122
        
2132
2123
        CompoundTreeExpansionModel(TreeExpansionModel expansionModel, TreeExpansionModelFilter expansionFilter) {
2133
        CompoundTreeExpansionModel(TreeExpansionModel expansionModel, TreeExpansionModelFilter expansionFilter) {
2124
            this.expansionModel = expansionModel;
2134
            this.expansionModel = expansionModel;
2125
            this.expansionFilter = expansionFilter;
2135
            this.expansionFilter = expansionFilter;
Lines 2141-2173 Link Here
2141
            expansionModel.nodeCollapsed(node);
2151
            expansionModel.nodeCollapsed(node);
2142
            expansionFilter.nodeCollapsed(node);
2152
            expansionFilter.nodeCollapsed(node);
2143
        }
2153
        }
2144
        
2154
2145
        /** 
2155
        /**
2146
         * Registers given listener.
2156
         * Registers given listener.
2147
         * 
2157
         *
2148
         * @param l the listener to add
2158
         * @param l the listener to add
2149
         */
2159
         */
2150
        public void addModelListener (ModelListener l) {
2160
        public void addModelListener(ModelListener l) {
2151
            synchronized (modelListeners) {
2161
            synchronized (modelListeners) {
2152
                if (modelListeners.isEmpty()) {
2162
                if (modelListeners.isEmpty()) {
2153
                    expansionFilter.addModelListener (this);
2163
                    expansionFilter.addModelListener(this);
2154
                    //model.addModelListener (this);
2164
                    //model.addModelListener (this);
2155
                }
2165
                }
2156
                modelListeners.add(l);
2166
                modelListeners.add(l);
2157
            }
2167
            }
2158
        }
2168
        }
2159
2169
2160
        /** 
2170
        /**
2161
         * Unregisters given listener.
2171
         * Unregisters given listener.
2162
         *
2172
         *
2163
         * @param l the listener to remove
2173
         * @param l the listener to remove
2164
         */
2174
         */
2165
        public void removeModelListener (ModelListener l) {
2175
        public void removeModelListener(ModelListener l) {
2166
            synchronized (modelListeners) {
2176
            synchronized (modelListeners) {
2167
                modelListeners.remove(l);
2177
                modelListeners.remove(l);
2168
                removeLonelyModelRootChangelisteners(modelListeners);
2178
                removeLonelyModelRootChangelisteners(modelListeners);
2169
                if (modelListeners.isEmpty()) {
2179
                if (modelListeners.isEmpty()) {
2170
                    expansionFilter.removeModelListener (this);
2180
                    expansionFilter.removeModelListener(this);
2171
                    //model.removeModelListener (this);
2181
                    //model.removeModelListener (this);
2172
                }
2182
                }
2173
            }
2183
            }
Lines 2177-2202 Link Here
2177
        public void modelChanged(ModelEvent event) {
2187
        public void modelChanged(ModelEvent event) {
2178
            if (event instanceof ModelEvent.NodeChanged && (event.getSource() instanceof NodeModel || event.getSource() instanceof NodeModelFilter)) {
2188
            if (event instanceof ModelEvent.NodeChanged && (event.getSource() instanceof NodeModel || event.getSource() instanceof NodeModelFilter)) {
2179
                // CompoundNodeModel.modelChanged() takes this.
2189
                // CompoundNodeModel.modelChanged() takes this.
2180
                return ;
2190
                return;
2181
            }
2191
            }
2182
            if (event instanceof ModelEvent.TableValueChanged &&
2192
            if (event instanceof ModelEvent.TableValueChanged
2183
                    (event.getSource() instanceof TableModel || event.getSource() instanceof TableModelFilter)) {
2193
                    && (event.getSource() instanceof TableModel || event.getSource() instanceof TableModelFilter)) {
2184
                // CompoundTableModel.modelChanged() takes this.
2194
                // CompoundTableModel.modelChanged() takes this.
2185
                return ;
2195
                return;
2186
            }
2196
            }
2187
            ModelEvent newEvent = translateEvent(event, this);
2197
            ModelEvent newEvent = translateEvent(event, this);
2188
            Collection<ModelListener> listeners;
2198
            Collection<ModelListener> listeners;
2189
            synchronized (modelListeners) {
2199
            synchronized (modelListeners) {
2190
                listeners = new ArrayList<ModelListener>(modelListeners);
2200
                listeners = new ArrayList<ModelListener>(modelListeners);
2191
            }
2201
            }
2192
            for (Iterator<ModelListener> it = listeners.iterator(); it.hasNext(); ) {
2202
            for (Iterator<ModelListener> it = listeners.iterator(); it.hasNext();) {
2193
                it.next().modelChanged(newEvent);
2203
                it.next().modelChanged(newEvent);
2194
            }
2204
            }
2195
        }
2205
        }
2196
        
2206
2197
    }
2207
    }
2198
2208
2199
    private final static class  CompoundAsynchronousModel implements AsynchronousModel {
2209
    private final static class CompoundAsynchronousModel implements AsynchronousModel {
2210
2200
        private AsynchronousModel asynchModel;
2211
        private AsynchronousModel asynchModel;
2201
        private AsynchronousModelFilter asynchModelFilter;
2212
        private AsynchronousModelFilter asynchModelFilter;
2202
2213
Lines 2213-2350 Link Here
2213
    }
2224
    }
2214
2225
2215
    /**
2226
    /**
2216
     * Creates one {@link org.netbeans.spi.viewmodel.TableModel}
2227
     * Creates one {@link org.netbeans.spi.viewmodel.TableModel} from given
2217
     * from given list of TableModels. DelegatingTableModel asks all underlaying 
2228
     * list of TableModels. DelegatingTableModel asks all underlaying models for
2218
     * models for each concrete parameter, and returns first returned value.
2229
     * each concrete parameter, and returns first returned value.
2219
     *
2230
     *
2220
     * @author   Jan Jancura
2231
     * @author Jan Jancura
2221
     */
2232
     */
2222
    private final static class DelegatingTableModel implements TableModel, TableHTMLModel {
2233
    private final static class DelegatingTableModel implements TableModel, TableHTMLModel {
2223
2234
2224
        private TableModel[] models;
2235
        private TableModel[] models;
2225
        private HashMap<String, TableModel> classNameToModel = new HashMap<String, TableModel>();
2236
        private HashMap<String, TableModel> classNameToModel = new HashMap<>();
2226
2227
2237
2228
        /**
2238
        /**
2229
         * Creates new instance of DelegatingTableModel for given list of 
2239
         * Creates new instance of DelegatingTableModel for given list of
2230
         * TableModels.
2240
         * TableModels.
2231
         *
2241
         *
2232
         * @param models a list of TableModels
2242
         * @param models a list of TableModels
2233
         */
2243
         */
2234
        DelegatingTableModel (List<TableModel> models) {
2244
        DelegatingTableModel(List<TableModel> models) {
2235
            this (convert (models));
2245
            this(convert(models));
2236
        }
2246
        }
2237
2247
2238
        private static TableModel[] convert (List<TableModel> l) {
2248
        private static TableModel[] convert(List<TableModel> l) {
2239
            TableModel[] models = new TableModel [l.size ()];
2249
            TableModel[] models = new TableModel[l.size()];
2240
            return l.toArray (models);
2250
            return l.toArray(models);
2241
        }
2251
        }
2242
2252
2243
        /**
2253
        /**
2244
         * Creates new instance of DelegatingTableModel for given array of 
2254
         * Creates new instance of DelegatingTableModel for given array of
2245
         * TableModels.
2255
         * TableModels.
2246
         *
2256
         *
2247
         * @param models a array of TableModels
2257
         * @param models a array of TableModels
2248
         */
2258
         */
2249
        DelegatingTableModel (TableModel[] models) {
2259
        DelegatingTableModel(TableModel[] models) {
2250
            this.models = models;        
2260
            this.models = models;
2251
        }
2261
        }
2252
2262
2253
        /**
2263
        /**
2254
         * Returns value to be displayed in column <code>columnID</code>
2264
         * Returns value to be displayed in column <code>columnID</code> and row
2255
         * and row <code>node</code>. Column ID is defined in by 
2265
         * <code>node</code>. Column ID is defined in by
2256
         * {@link ColumnModel#getID}, and rows are defined by values returned from 
2266
         * {@link ColumnModel#getID}, and rows are defined by values returned
2257
         * {@TreeModel#getChildren}.
2267
         * from {
2268
         *
2269
         * @TreeModel#getChildren}.
2258
         *
2270
         *
2259
         * @param node a object returned from {@TreeModel#getChildren} for this row
2271
         * @param node a object returned from {
2272
         * @TreeModel#getChildren} for this row
2260
         * @param columnID a id of column defined by {@link ColumnModel#getID}
2273
         * @param columnID a id of column defined by {@link ColumnModel#getID}
2261
         * @throws UnknownTypeException if there is no TableModel defined for given
2274
         * @throws UnknownTypeException if there is no TableModel defined for
2262
         *         parameter type
2275
         * given parameter type
2263
         *
2276
         *
2264
         * @return value of variable representing given position in tree table.
2277
         * @return value of variable representing given position in tree table.
2265
         */
2278
         */
2266
        @Override
2279
        @Override
2267
        public Object getValueAt (Object node, String columnID)
2280
        public Object getValueAt(Object node, String columnID)
2268
        throws UnknownTypeException {
2281
                throws UnknownTypeException {
2269
            TableModel model = classNameToModel.get (
2282
            TableModel model = classNameToModel.get(
2270
                node.getClass ().getName ()
2283
                    node.getClass().getName()
2271
            );
2284
            );
2272
            if (model != null)  {
2285
            if (model != null) {
2273
                try {
2286
                try {
2274
                    return model.getValueAt (node, columnID);
2287
                    return model.getValueAt(node, columnID);
2275
                } catch (UnknownTypeException e) {
2288
                } catch (UnknownTypeException e) {
2276
                }
2289
                }
2277
            }
2290
            }
2278
            int i, k = models.length;
2291
            int i, k = models.length;
2279
            for (i = 0; i < k; i++) {
2292
            for (i = 0; i < k; i++) {
2280
                try {
2293
                try {
2281
                    Object v = models [i].getValueAt (node, columnID);
2294
                    Object v = models[i].getValueAt(node, columnID);
2282
                    classNameToModel.put (node.getClass ().getName (), models [i]);
2295
                    classNameToModel.put(node.getClass().getName(), models[i]);
2283
                    return v;
2296
                    return v;
2284
                } catch (UnknownTypeException e) {
2297
                } catch (UnknownTypeException e) {
2285
                }
2298
                }
2286
            }
2299
            }
2287
            throw new UnknownTypeException (node);
2300
            throw new UnknownTypeException(node);
2288
        }    
2301
        }
2289
2302
2290
        /**
2303
        /**
2291
         * Returns true if value displayed in column <code>columnID</code>
2304
         * Returns true if value displayed in column <code>columnID</code> and
2292
         * and row <code>node</code> is read only. Column ID is defined in by 
2305
         * row <code>node</code> is read only. Column ID is defined in by
2293
         * {@link ColumnModel#getID}, and rows are defined by values returned from 
2306
         * {@link ColumnModel#getID}, and rows are defined by values returned
2294
         * {@TreeModel#getChildren}.
2307
         * from {
2308
         *
2309
         * @TreeModel#getChildren}.
2295
         *
2310
         *
2296
         * @param node a object returned from {@TreeModel#getChildren} for this row
2311
         * @param node a object returned from {
2312
         * @TreeModel#getChildren} for this row
2297
         * @param columnID a id of column defined by {@link ColumnModel#getID}
2313
         * @param columnID a id of column defined by {@link ColumnModel#getID}
2298
         * @throws UnknownTypeException if there is no TableModel defined for given
2314
         * @throws UnknownTypeException if there is no TableModel defined for
2299
         *         parameter type
2315
         * given parameter type
2300
         *
2316
         *
2301
         * @return true if variable on given position is read only
2317
         * @return true if variable on given position is read only
2302
         */
2318
         */
2303
        @Override
2319
        @Override
2304
        public boolean isReadOnly (Object node, String columnID) throws 
2320
        public boolean isReadOnly(Object node, String columnID) throws
2305
        UnknownTypeException {
2321
                UnknownTypeException {
2306
            TableModel model = classNameToModel.get (
2322
            TableModel model = classNameToModel.get(
2307
                node.getClass ().getName ()
2323
                    node.getClass().getName()
2308
            );
2324
            );
2309
            if (model != null) {
2325
            if (model != null) {
2310
                try {
2326
                try {
2311
                    return model.isReadOnly (node, columnID);
2327
                    return model.isReadOnly(node, columnID);
2312
                } catch (UnknownTypeException e) {
2328
                } catch (UnknownTypeException e) {
2313
                }
2329
                }
2314
            }
2330
            }
2315
            int i, k = models.length;
2331
            int i, k = models.length;
2316
            for (i = 0; i < k; i++) {
2332
            for (i = 0; i < k; i++) {
2317
                try {
2333
                try {
2318
                    boolean ro = models [i].isReadOnly (node, columnID);
2334
                    boolean ro = models[i].isReadOnly(node, columnID);
2319
                    classNameToModel.put (node.getClass ().getName (), models [i]);
2335
                    classNameToModel.put(node.getClass().getName(), models[i]);
2320
                    return ro;
2336
                    return ro;
2321
                } catch (UnknownTypeException e) {
2337
                } catch (UnknownTypeException e) {
2322
                }
2338
                }
2323
            }
2339
            }
2324
            throw new UnknownTypeException (node);
2340
            throw new UnknownTypeException(node);
2325
        }
2341
        }
2326
2342
2327
        /**
2343
        /**
2328
         * Changes a value displayed in column <code>columnID</code>
2344
         * Changes a value displayed in column <code>columnID</code> and row
2329
         * and row <code>node</code>. Column ID is defined in by 
2345
         * <code>node</code>. Column ID is defined in by
2330
         * {@link ColumnModel#getID}, and rows are defined by values returned from 
2346
         * {@link ColumnModel#getID}, and rows are defined by values returned
2331
         * {@TreeModel#getChildren}.
2347
         * from {
2348
         *
2349
         * @TreeModel#getChildren}.
2332
         *
2350
         *
2333
         * @param node a object returned from {@TreeModel#getChildren} for this row
2351
         * @param node a object returned from {
2352
         * @TreeModel#getChildren} for this row
2334
         * @param columnID a id of column defined by {@link ColumnModel#getID}
2353
         * @param columnID a id of column defined by {@link ColumnModel#getID}
2335
         * @param value a new value of variable on given position
2354
         * @param value a new value of variable on given position
2336
         * @throws UnknownTypeException if there is no TableModel defined for given
2355
         * @throws UnknownTypeException if there is no TableModel defined for
2337
         *         parameter type
2356
         * given parameter type
2338
         */
2357
         */
2339
        @Override
2358
        @Override
2340
        public void setValueAt (Object node, String columnID, Object value)
2359
        public void setValueAt(Object node, String columnID, Object value)
2341
        throws UnknownTypeException {
2360
                throws UnknownTypeException {
2342
            TableModel model = classNameToModel.get (
2361
            TableModel model = classNameToModel.get(
2343
                node.getClass ().getName ()
2362
                    node.getClass().getName()
2344
            );
2363
            );
2345
            if (model != null) {
2364
            if (model != null) {
2346
                try {
2365
                try {
2347
                    model.setValueAt (node, columnID, value);
2366
                    model.setValueAt(node, columnID, value);
2348
                    return;
2367
                    return;
2349
                } catch (UnknownTypeException e) {
2368
                } catch (UnknownTypeException e) {
2350
                }
2369
                }
Lines 2352-2376 Link Here
2352
            int i, k = models.length;
2371
            int i, k = models.length;
2353
            for (i = 0; i < k; i++) {
2372
            for (i = 0; i < k; i++) {
2354
                try {
2373
                try {
2355
                    models [i].setValueAt (node, columnID, value);
2374
                    models[i].setValueAt(node, columnID, value);
2356
                    classNameToModel.put (node.getClass ().getName (), models [i]);
2375
                    classNameToModel.put(node.getClass().getName(), models[i]);
2357
                    return;
2376
                    return;
2358
                } catch (UnknownTypeException e) {
2377
                } catch (UnknownTypeException e) {
2359
                }
2378
                }
2360
            }
2379
            }
2361
            throw new UnknownTypeException (node);
2380
            throw new UnknownTypeException(node);
2362
        }
2381
        }
2363
2382
2364
        /** 
2383
        /**
2365
         * Registers given listener.
2384
         * Registers given listener.
2366
         * 
2385
         *
2367
         * @param l the listener to add
2386
         * @param l the listener to add
2368
         */
2387
         */
2369
        @Override
2388
        @Override
2370
        public void addModelListener (ModelListener l) {
2389
        public void addModelListener(ModelListener l) {
2371
            int i, k = models.length;
2390
            int i, k = models.length;
2372
            for (i = 0; i < k; i++) {
2391
            for (i = 0; i < k; i++) {
2373
                models [i].addModelListener (l);
2392
                models[i].addModelListener(l);
2374
            }
2393
            }
2375
        }
2394
        }
2376
2395
Lines 2379-2444 Link Here
2379
         *
2398
         *
2380
         * @param l the listener to add
2399
         * @param l the listener to add
2381
         */
2400
         */
2382
        void addModelListener (ModelListener l, Set<Model> modelsListenersAddedTo) {
2401
        void addModelListener(ModelListener l, Set<Model> modelsListenersAddedTo) {
2383
            int i, k = models.length;
2402
            int i, k = models.length;
2384
            for (i = 0; i < k; i++) {
2403
            for (i = 0; i < k; i++) {
2385
                TableModel m = models [i];
2404
                TableModel m = models[i];
2386
                if (!modelsListenersAddedTo.add(m)) {
2405
                if (!modelsListenersAddedTo.add(m)) {
2387
                    continue;
2406
                    continue;
2388
                }
2407
                }
2389
                if (m instanceof DelegatingTableModel) {
2408
                if (m instanceof DelegatingTableModel) {
2390
                    ((DelegatingTableModel) m).addModelListener(l, modelsListenersAddedTo);
2409
                    ((DelegatingTableModel) m).addModelListener(l, modelsListenersAddedTo);
2391
                } else {
2410
                } else {
2392
                    m.addModelListener (l);
2411
                    m.addModelListener(l);
2393
                }
2412
                }
2394
            }
2413
            }
2395
        }
2414
        }
2396
2415
2397
        /** 
2416
        /**
2398
         * Unregisters given listener.
2417
         * Unregisters given listener.
2399
         *
2418
         *
2400
         * @param l the listener to remove
2419
         * @param l the listener to remove
2401
         */
2420
         */
2402
        @Override
2421
        @Override
2403
        public void removeModelListener (ModelListener l) {
2422
        public void removeModelListener(ModelListener l) {
2404
            int i, k = models.length;
2423
            int i, k = models.length;
2405
            for (i = 0; i < k; i++) {
2424
            for (i = 0; i < k; i++) {
2406
                models [i].removeModelListener (l);
2425
                models[i].removeModelListener(l);
2407
            }
2426
            }
2408
        }
2427
        }
2409
2428
2410
        @Override
2429
        @Override
2411
        public String toString () {
2430
        public String toString() {
2412
            return super.toString () + "\n" + toString ("    ");
2431
            return super.toString() + "\n" + toString("    ");
2413
        }
2432
        }
2414
        
2433
2415
        public String toString (String n) {
2434
        public String toString(String n) {
2416
            int i, k = models.length - 1;
2435
            int i, k = models.length - 1;
2417
            if (k == -1) {
2436
            if (k == -1) {
2418
                return "";
2437
                return "";
2419
            }
2438
            }
2420
            StringBuffer sb = new StringBuffer ();
2439
            StringBuffer sb = new StringBuffer();
2421
            for (i = 0; i < k; i++) {
2440
            for (i = 0; i < k; i++) {
2422
                sb.append (n);
2441
                sb.append(n);
2423
                sb.append (models [i]);
2442
                sb.append(models[i]);
2424
                sb.append ('\n');
2443
                sb.append('\n');
2425
            }
2444
            }
2426
            sb.append (n);
2445
            sb.append(n);
2427
            sb.append (models [i]);
2446
            sb.append(models[i]);
2428
            return new String (sb);
2447
            return new String(sb);
2429
        }
2448
        }
2430
        
2431
        // HTML extension:
2432
2449
2450
        // HTML extension:
2433
        private boolean defaultHasHTMLValueAt() {
2451
        private boolean defaultHasHTMLValueAt() {
2434
            return false;
2452
            return false;
2435
        }
2453
        }
2436
        
2454
2437
        @Override
2455
        @Override
2438
        public boolean hasHTMLValueAt(Object node, String columnID) throws UnknownTypeException {
2456
        public boolean hasHTMLValueAt(Object node, String columnID) throws UnknownTypeException {
2439
            UnknownTypeException uex = null;
2457
            UnknownTypeException uex = null;
2440
            TableModel model = classNameToModel.get (
2458
            TableModel model = classNameToModel.get(
2441
                node.getClass ().getName ()
2459
                    node.getClass().getName()
2442
            );
2460
            );
2443
            if (model != null) {
2461
            if (model != null) {
2444
                if (model instanceof TableHTMLModel) {
2462
                if (model instanceof TableHTMLModel) {
Lines 2456-2463 Link Here
2456
            for (i = 0; i < k; i++) {
2474
            for (i = 0; i < k; i++) {
2457
                if (models[i] instanceof TableHTMLModel) {
2475
                if (models[i] instanceof TableHTMLModel) {
2458
                    try {
2476
                    try {
2459
                        boolean has = ((TableHTMLModel) models [i]).hasHTMLValueAt(node, columnID);
2477
                        boolean has = ((TableHTMLModel) models[i]).hasHTMLValueAt(node, columnID);
2460
                        classNameToModel.put (node.getClass ().getName (), models [i]);
2478
                        classNameToModel.put(node.getClass().getName(), models[i]);
2461
                        return has;
2479
                        return has;
2462
                    } catch (UnknownTypeException e) {
2480
                    } catch (UnknownTypeException e) {
2463
                        uex = e;
2481
                        uex = e;
Lines 2471-2485 Link Here
2471
            if (uex != null) {
2489
            if (uex != null) {
2472
                throw uex;
2490
                throw uex;
2473
            } else {
2491
            } else {
2474
                throw new UnknownTypeException (node);
2492
                throw new UnknownTypeException(node);
2475
            }
2493
            }
2476
        }
2494
        }
2477
2495
2478
        @Override
2496
        @Override
2479
        public String getHTMLValueAt(Object node, String columnID) throws UnknownTypeException {
2497
        public String getHTMLValueAt(Object node, String columnID) throws UnknownTypeException {
2480
            UnknownTypeException uex = null;
2498
            UnknownTypeException uex = null;
2481
            TableModel model = classNameToModel.get (
2499
            TableModel model = classNameToModel.get(
2482
                node.getClass ().getName ()
2500
                    node.getClass().getName()
2483
            );
2501
            );
2484
            if (model != null) {
2502
            if (model != null) {
2485
                if (model instanceof TableHTMLModel) {
2503
                if (model instanceof TableHTMLModel) {
Lines 2497-2504 Link Here
2497
            for (i = 0; i < k; i++) {
2515
            for (i = 0; i < k; i++) {
2498
                if (models[i] instanceof TableHTMLModel) {
2516
                if (models[i] instanceof TableHTMLModel) {
2499
                    try {
2517
                    try {
2500
                        String htmlValue = ((TableHTMLModel) models [i]).getHTMLValueAt(node, columnID);
2518
                        String htmlValue = ((TableHTMLModel) models[i]).getHTMLValueAt(node, columnID);
2501
                        classNameToModel.put (node.getClass ().getName (), models [i]);
2519
                        classNameToModel.put(node.getClass().getName(), models[i]);
2502
                        return htmlValue;
2520
                        return htmlValue;
2503
                    } catch (UnknownTypeException e) {
2521
                    } catch (UnknownTypeException e) {
2504
                        uex = e;
2522
                        uex = e;
Lines 2512-2546 Link Here
2512
            if (uex != null) {
2530
            if (uex != null) {
2513
                throw uex;
2531
                throw uex;
2514
            } else {
2532
            } else {
2515
                throw new UnknownTypeException (node);
2533
                throw new UnknownTypeException(node);
2516
            }
2534
            }
2517
        }
2535
        }
2518
    }
2536
    }
2519
2537
2520
    /**
2538
    /**
2521
     * Creates one {@link org.netbeans.spi.viewmodel.TableRendererModel}
2539
     * Creates one {@link org.netbeans.spi.viewmodel.TableRendererModel} from
2522
     * from given list of TableRendererModel. DelegatingTableRendererModel asks all underlaying
2540
     * given list of TableRendererModel. DelegatingTableRendererModel asks all
2523
     * models for each concrete parameter, and returns first returned value.
2541
     * underlaying models for each concrete parameter, and returns first
2542
     * returned value.
2524
     */
2543
     */
2525
    private final static class DelegatingTableRendererModel implements TableRendererModel {
2544
    private final static class DelegatingTableRendererModel implements TableRendererModel {
2526
2545
2527
        private TableRendererModel[] models;
2546
        private TableRendererModel[] models;
2528
        private HashMap<String, TableRendererModel> classNameToModel = new HashMap<String, TableRendererModel>();
2547
        private HashMap<String, TableRendererModel> classNameToModel = new HashMap<String, TableRendererModel>();
2529
2548
2530
2531
        /**
2549
        /**
2532
         * Creates new instance of DelegatingTableModel for given list of
2550
         * Creates new instance of DelegatingTableModel for given list of
2533
         * TableModels.
2551
         * TableModels.
2534
         *
2552
         *
2535
         * @param models a list of TableModels
2553
         * @param models a list of TableModels
2536
         */
2554
         */
2537
        DelegatingTableRendererModel (List<TableRendererModel> models) {
2555
        DelegatingTableRendererModel(List<TableRendererModel> models) {
2538
            this (convert (models));
2556
            this(convert(models));
2539
        }
2557
        }
2540
2558
2541
        private static TableRendererModel[] convert (List<TableRendererModel> l) {
2559
        private static TableRendererModel[] convert(List<TableRendererModel> l) {
2542
            TableRendererModel[] models = new TableRendererModel [l.size ()];
2560
            TableRendererModel[] models = new TableRendererModel[l.size()];
2543
            return l.toArray (models);
2561
            return l.toArray(models);
2544
        }
2562
        }
2545
2563
2546
        /**
2564
        /**
Lines 2549-2660 Link Here
2549
         *
2567
         *
2550
         * @param models a array of TableModels
2568
         * @param models a array of TableModels
2551
         */
2569
         */
2552
        DelegatingTableRendererModel (TableRendererModel[] models) {
2570
        DelegatingTableRendererModel(TableRendererModel[] models) {
2553
            this.models = models;
2571
            this.models = models;
2554
        }
2572
        }
2555
2573
2556
        @Override
2574
        @Override
2557
        public boolean canRenderCell(Object node, String columnID) throws UnknownTypeException {
2575
        public boolean canRenderCell(Object node, String columnID) throws UnknownTypeException {
2558
            TableRendererModel model = classNameToModel.get (
2576
            TableRendererModel model = classNameToModel.get(
2559
                node.getClass ().getName ()
2577
                    node.getClass().getName()
2560
            );
2578
            );
2561
            if (model != null) {
2579
            if (model != null) {
2562
                try {
2580
                try {
2563
                    return model.canRenderCell (node, columnID);
2581
                    return model.canRenderCell(node, columnID);
2564
                } catch (UnknownTypeException e) {
2582
                } catch (UnknownTypeException e) {
2565
                }
2583
                }
2566
            }
2584
            }
2567
            int i, k = models.length;
2585
            int i, k = models.length;
2568
            for (i = 0; i < k; i++) {
2586
            for (i = 0; i < k; i++) {
2569
                try {
2587
                try {
2570
                    boolean cr = models [i].canRenderCell (node, columnID);
2588
                    boolean cr = models[i].canRenderCell(node, columnID);
2571
                    classNameToModel.put (node.getClass ().getName (), models [i]);
2589
                    classNameToModel.put(node.getClass().getName(), models[i]);
2572
                    return cr;
2590
                    return cr;
2573
                } catch (UnknownTypeException e) {
2591
                } catch (UnknownTypeException e) {
2574
                }
2592
                }
2575
            }
2593
            }
2576
            throw new UnknownTypeException (node);
2594
            throw new UnknownTypeException(node);
2577
        }
2595
        }
2578
2596
2579
        @Override
2597
        @Override
2580
        public TableCellRenderer getCellRenderer(Object node, String columnID) throws UnknownTypeException {
2598
        public TableCellRenderer getCellRenderer(Object node, String columnID) throws UnknownTypeException {
2581
            TableRendererModel model = classNameToModel.get (
2599
            TableRendererModel model = classNameToModel.get(
2582
                node.getClass ().getName ()
2600
                    node.getClass().getName()
2583
            );
2601
            );
2584
            if (model != null) {
2602
            if (model != null) {
2585
                try {
2603
                try {
2586
                    return model.getCellRenderer (node, columnID);
2604
                    return model.getCellRenderer(node, columnID);
2587
                } catch (UnknownTypeException e) {
2605
                } catch (UnknownTypeException e) {
2588
                }
2606
                }
2589
            }
2607
            }
2590
            int i, k = models.length;
2608
            int i, k = models.length;
2591
            for (i = 0; i < k; i++) {
2609
            for (i = 0; i < k; i++) {
2592
                try {
2610
                try {
2593
                    TableCellRenderer cr = models [i].getCellRenderer (node, columnID);
2611
                    TableCellRenderer cr = models[i].getCellRenderer(node, columnID);
2594
                    classNameToModel.put (node.getClass ().getName (), models [i]);
2612
                    classNameToModel.put(node.getClass().getName(), models[i]);
2595
                    return cr;
2613
                    return cr;
2596
                } catch (UnknownTypeException e) {
2614
                } catch (UnknownTypeException e) {
2597
                }
2615
                }
2598
            }
2616
            }
2599
            throw new UnknownTypeException (node);
2617
            throw new UnknownTypeException(node);
2600
        }
2618
        }
2601
2619
2602
        @Override
2620
        @Override
2603
        public boolean canEditCell(Object node, String columnID) throws UnknownTypeException {
2621
        public boolean canEditCell(Object node, String columnID) throws UnknownTypeException {
2604
            TableRendererModel model = classNameToModel.get (
2622
            TableRendererModel model = classNameToModel.get(
2605
                node.getClass ().getName ()
2623
                    node.getClass().getName()
2606
            );
2624
            );
2607
            if (model != null) {
2625
            if (model != null) {
2608
                try {
2626
                try {
2609
                    return model.canEditCell (node, columnID);
2627
                    return model.canEditCell(node, columnID);
2610
                } catch (UnknownTypeException e) {
2628
                } catch (UnknownTypeException e) {
2611
                }
2629
                }
2612
            }
2630
            }
2613
            int i, k = models.length;
2631
            int i, k = models.length;
2614
            for (i = 0; i < k; i++) {
2632
            for (i = 0; i < k; i++) {
2615
                try {
2633
                try {
2616
                    boolean ce = models [i].canEditCell (node, columnID);
2634
                    boolean ce = models[i].canEditCell(node, columnID);
2617
                    classNameToModel.put (node.getClass ().getName (), models [i]);
2635
                    classNameToModel.put(node.getClass().getName(), models[i]);
2618
                    return ce;
2636
                    return ce;
2619
                } catch (UnknownTypeException e) {
2637
                } catch (UnknownTypeException e) {
2620
                }
2638
                }
2621
            }
2639
            }
2622
            throw new UnknownTypeException (node);
2640
            throw new UnknownTypeException(node);
2623
        }
2641
        }
2624
2642
2625
        @Override
2643
        @Override
2626
        public TableCellEditor getCellEditor(Object node, String columnID) throws UnknownTypeException {
2644
        public TableCellEditor getCellEditor(Object node, String columnID) throws UnknownTypeException {
2627
            TableRendererModel model = classNameToModel.get (
2645
            TableRendererModel model = classNameToModel.get(
2628
                node.getClass ().getName ()
2646
                    node.getClass().getName()
2629
            );
2647
            );
2630
            if (model != null) {
2648
            if (model != null) {
2631
                try {
2649
                try {
2632
                    return model.getCellEditor (node, columnID);
2650
                    return model.getCellEditor(node, columnID);
2633
                } catch (UnknownTypeException e) {
2651
                } catch (UnknownTypeException e) {
2634
                }
2652
                }
2635
            }
2653
            }
2636
            int i, k = models.length;
2654
            int i, k = models.length;
2637
            for (i = 0; i < k; i++) {
2655
            for (i = 0; i < k; i++) {
2638
                try {
2656
                try {
2639
                    TableCellEditor ce = models [i].getCellEditor (node, columnID);
2657
                    TableCellEditor ce = models[i].getCellEditor(node, columnID);
2640
                    classNameToModel.put (node.getClass ().getName (), models [i]);
2658
                    classNameToModel.put(node.getClass().getName(), models[i]);
2641
                    return ce;
2659
                    return ce;
2642
                } catch (UnknownTypeException e) {
2660
                } catch (UnknownTypeException e) {
2643
                }
2661
                }
2644
            }
2662
            }
2645
            throw new UnknownTypeException (node);
2663
            throw new UnknownTypeException(node);
2646
        }
2664
        }
2647
        
2665
2648
        /**
2666
        /**
2649
         * Registers given listener.
2667
         * Registers given listener.
2650
         *
2668
         *
2651
         * @param l the listener to add
2669
         * @param l the listener to add
2652
         */
2670
         */
2653
        @Override
2671
        @Override
2654
        public void addModelListener (ModelListener l) {
2672
        public void addModelListener(ModelListener l) {
2655
            int i, k = models.length;
2673
            int i, k = models.length;
2656
            for (i = 0; i < k; i++) {
2674
            for (i = 0; i < k; i++) {
2657
                models [i].addModelListener (l);
2675
                models[i].addModelListener(l);
2658
            }
2676
            }
2659
        }
2677
        }
2660
2678
Lines 2663-2679 Link Here
2663
         *
2681
         *
2664
         * @param l the listener to add
2682
         * @param l the listener to add
2665
         */
2683
         */
2666
        void addModelListener (ModelListener l, Set<Model> modelsListenersAddedTo) {
2684
        void addModelListener(ModelListener l, Set<Model> modelsListenersAddedTo) {
2667
            int i, k = models.length;
2685
            int i, k = models.length;
2668
            for (i = 0; i < k; i++) {
2686
            for (i = 0; i < k; i++) {
2669
                TableRendererModel m = models [i];
2687
                TableRendererModel m = models[i];
2670
                if (!modelsListenersAddedTo.add(m)) {
2688
                if (!modelsListenersAddedTo.add(m)) {
2671
                    continue;
2689
                    continue;
2672
                }
2690
                }
2673
                if (m instanceof DelegatingTableRendererModel) {
2691
                if (m instanceof DelegatingTableRendererModel) {
2674
                    ((DelegatingTableRendererModel) m).addModelListener(l, modelsListenersAddedTo);
2692
                    ((DelegatingTableRendererModel) m).addModelListener(l, modelsListenersAddedTo);
2675
                } else {
2693
                } else {
2676
                    m.addModelListener (l);
2694
                    m.addModelListener(l);
2677
                }
2695
                }
2678
            }
2696
            }
2679
        }
2697
        }
Lines 2684-2733 Link Here
2684
         * @param l the listener to remove
2702
         * @param l the listener to remove
2685
         */
2703
         */
2686
        @Override
2704
        @Override
2687
        public void removeModelListener (ModelListener l) {
2705
        public void removeModelListener(ModelListener l) {
2688
            int i, k = models.length;
2706
            int i, k = models.length;
2689
            for (i = 0; i < k; i++) {
2707
            for (i = 0; i < k; i++) {
2690
                models [i].removeModelListener (l);
2708
                models[i].removeModelListener(l);
2691
            }
2709
            }
2692
        }
2710
        }
2693
2711
2694
        @Override
2712
        @Override
2695
        public String toString () {
2713
        public String toString() {
2696
            return super.toString () + "\n" + toString ("    ");
2714
            return super.toString() + "\n" + toString("    ");
2697
        }
2715
        }
2698
2716
2699
        public String toString (String n) {
2717
        public String toString(String n) {
2700
            int i, k = models.length - 1;
2718
            int i, k = models.length - 1;
2701
            if (k == -1) {
2719
            if (k == -1) {
2702
                return "";
2720
                return "";
2703
            }
2721
            }
2704
            StringBuffer sb = new StringBuffer ();
2722
            StringBuffer sb = new StringBuffer();
2705
            for (i = 0; i < k; i++) {
2723
            for (i = 0; i < k; i++) {
2706
                sb.append (n);
2724
                sb.append(n);
2707
                sb.append (models [i]);
2725
                sb.append(models[i]);
2708
                sb.append ('\n');
2726
                sb.append('\n');
2709
            }
2727
            }
2710
            sb.append (n);
2728
            sb.append(n);
2711
            sb.append (models [i]);
2729
            sb.append(models[i]);
2712
            return new String (sb);
2730
            return new String(sb);
2713
        }
2731
        }
2714
2732
2715
    }
2733
    }
2716
    
2734
2717
    private final static class DelegatingTablePropertyEditorsModel implements TablePropertyEditorsModel {
2735
    private final static class DelegatingTablePropertyEditorsModel implements TablePropertyEditorsModel {
2718
        
2736
2719
        private TablePropertyEditorsModel[] models;
2737
        private TablePropertyEditorsModel[] models;
2720
        private HashMap<String, TablePropertyEditorsModel> classNameToModel = new HashMap<String, TablePropertyEditorsModel>();
2738
        private HashMap<String, TablePropertyEditorsModel> classNameToModel = new HashMap<String, TablePropertyEditorsModel>();
2721
        
2739
2722
        DelegatingTablePropertyEditorsModel(List<TablePropertyEditorsModel> models) {
2740
        DelegatingTablePropertyEditorsModel(List<TablePropertyEditorsModel> models) {
2723
            this(convert(models));
2741
            this(convert(models));
2724
        }
2742
        }
2725
        
2743
2726
        private static TablePropertyEditorsModel[] convert(List<TablePropertyEditorsModel> l) {
2744
        private static TablePropertyEditorsModel[] convert(List<TablePropertyEditorsModel> l) {
2727
            TablePropertyEditorsModel[] models = new TablePropertyEditorsModel[l.size()];
2745
            TablePropertyEditorsModel[] models = new TablePropertyEditorsModel[l.size()];
2728
            return l.toArray(models);
2746
            return l.toArray(models);
2729
        }
2747
        }
2730
        
2748
2731
        DelegatingTablePropertyEditorsModel(TablePropertyEditorsModel[] models) {
2749
        DelegatingTablePropertyEditorsModel(TablePropertyEditorsModel[] models) {
2732
            this.models = models;
2750
            this.models = models;
2733
        }
2751
        }
Lines 2748-2755 Link Here
2748
            int i, k = models.length;
2766
            int i, k = models.length;
2749
            for (i = 0; i < k; i++) {
2767
            for (i = 0; i < k; i++) {
2750
                try {
2768
                try {
2751
                    PropertyEditor pe = models [i].getPropertyEditor(node, columnID);
2769
                    PropertyEditor pe = models[i].getPropertyEditor(node, columnID);
2752
                    classNameToModel.put (node.getClass ().getName (), models [i]);
2770
                    classNameToModel.put(node.getClass().getName(), models[i]);
2753
                    return pe;
2771
                    return pe;
2754
                } catch (UnknownTypeException e) {
2772
                } catch (UnknownTypeException e) {
2755
                    utex = e;
2773
                    utex = e;
Lines 2761-2828 Link Here
2761
            if (utex != null) {
2779
            if (utex != null) {
2762
                throw utex;
2780
                throw utex;
2763
            } else {
2781
            } else {
2764
                throw new UnknownTypeException (node);
2782
                throw new UnknownTypeException(node);
2765
            }
2783
            }
2766
        }
2784
        }
2767
2785
2768
        @Override
2786
        @Override
2769
        public String toString () {
2787
        public String toString() {
2770
            return super.toString () + "\n" + toString ("    ");
2788
            return super.toString() + "\n" + toString("    ");
2771
        }
2789
        }
2772
2790
2773
        public String toString (String n) {
2791
        public String toString(String n) {
2774
            int i, k = models.length - 1;
2792
            int i, k = models.length - 1;
2775
            if (k == -1) {
2793
            if (k == -1) {
2776
                return "";
2794
                return "";
2777
            }
2795
            }
2778
            StringBuffer sb = new StringBuffer ();
2796
            StringBuffer sb = new StringBuffer();
2779
            for (i = 0; i < k; i++) {
2797
            for (i = 0; i < k; i++) {
2780
                sb.append (n);
2798
                sb.append(n);
2781
                sb.append (models [i]);
2799
                sb.append(models[i]);
2782
                sb.append ('\n');
2800
                sb.append('\n');
2783
            }
2801
            }
2784
            sb.append (n);
2802
            sb.append(n);
2785
            sb.append (models [i]);
2803
            sb.append(models[i]);
2786
            return new String (sb);
2804
            return new String(sb);
2787
        }
2805
        }
2788
    }
2806
    }
2789
2807
2790
    /**
2808
    /**
2791
     * Creates one {@link org.netbeans.spi.viewmodel.TableModel}
2809
     * Creates one {@link org.netbeans.spi.viewmodel.TableModel} from given
2792
     * from given list of TableModels. DelegatingTableModel asks all underlaying 
2810
     * list of TableModels. DelegatingTableModel asks all underlaying models for
2793
     * models for each concrete parameter, and returns first returned value.
2811
     * each concrete parameter, and returns first returned value.
2794
     *
2812
     *
2795
     * @author   Jan Jancura
2813
     * @author Jan Jancura
2796
     */
2814
     */
2797
    private final static class DelegatingTreeExpansionModel implements TreeExpansionModel {
2815
    private final static class DelegatingTreeExpansionModel implements TreeExpansionModel {
2798
2816
2799
        private TreeExpansionModel[] models;
2817
        private TreeExpansionModel[] models;
2800
        private HashMap<String, TreeExpansionModel> classNameToModel = new HashMap<String, TreeExpansionModel>();
2818
        private HashMap<String, TreeExpansionModel> classNameToModel = new HashMap<String, TreeExpansionModel>();
2801
2819
2802
2803
        /**
2820
        /**
2804
         * Creates new instance of DelegatingTableModel for given list of 
2821
         * Creates new instance of DelegatingTableModel for given list of
2805
         * TableModels.
2822
         * TableModels.
2806
         *
2823
         *
2807
         * @param models a list of TableModels
2824
         * @param models a list of TableModels
2808
         */
2825
         */
2809
        DelegatingTreeExpansionModel (List<TreeExpansionModel> models) {
2826
        DelegatingTreeExpansionModel(List<TreeExpansionModel> models) {
2810
            this (convert (models));
2827
            this(convert(models));
2811
        }
2828
        }
2812
2829
2813
        private static TreeExpansionModel[] convert (List<TreeExpansionModel> l) {
2830
        private static TreeExpansionModel[] convert(List<TreeExpansionModel> l) {
2814
            TreeExpansionModel[] models = new TreeExpansionModel [l.size()];
2831
            TreeExpansionModel[] models = new TreeExpansionModel[l.size()];
2815
            return l.toArray (models);
2832
            return l.toArray(models);
2816
        }
2833
        }
2817
2834
2818
        /**
2835
        /**
2819
         * Creates new instance of DelegatingTableModel for given array of 
2836
         * Creates new instance of DelegatingTableModel for given array of
2820
         * TableModels.
2837
         * TableModels.
2821
         *
2838
         *
2822
         * @param models a array of TableModels
2839
         * @param models a array of TableModels
2823
         */
2840
         */
2824
        private DelegatingTreeExpansionModel (TreeExpansionModel[] models) {
2841
        private DelegatingTreeExpansionModel(TreeExpansionModel[] models) {
2825
            this.models = models;        
2842
            this.models = models;
2826
        }
2843
        }
2827
2844
2828
        /**
2845
        /**
Lines 2832-2861 Link Here
2832
         * @return default state (collapsed, expanded) of given node
2849
         * @return default state (collapsed, expanded) of given node
2833
         */
2850
         */
2834
        @Override
2851
        @Override
2835
        public boolean isExpanded (Object node) 
2852
        public boolean isExpanded(Object node)
2836
        throws UnknownTypeException {
2853
                throws UnknownTypeException {
2837
            TreeExpansionModel model = 
2854
            TreeExpansionModel model
2838
                classNameToModel.get (
2855
                    = classNameToModel.get(
2839
                    node.getClass ().getName ()
2856
                            node.getClass().getName()
2840
                );
2857
                    );
2841
            if (model != null) {
2858
            if (model != null) {
2842
                try {
2859
                try {
2843
                    return model.isExpanded (node);
2860
                    return model.isExpanded(node);
2844
                } catch (UnknownTypeException e) {
2861
                } catch (UnknownTypeException e) {
2845
                }
2862
                }
2846
            }
2863
            }
2847
            int i, k = models.length;
2864
            int i, k = models.length;
2848
            for (i = 0; i < k; i++) {
2865
            for (i = 0; i < k; i++) {
2849
                try {
2866
                try {
2850
                    boolean result = models [i].isExpanded (node);
2867
                    boolean result = models[i].isExpanded(node);
2851
                    classNameToModel.put (node.getClass ().getName (), models [i]);
2868
                    classNameToModel.put(node.getClass().getName(), models[i]);
2852
                    return result;
2869
                    return result;
2853
                } catch (UnknownTypeException e) {
2870
                } catch (UnknownTypeException e) {
2854
                }
2871
                }
2855
            }
2872
            }
2856
            throw new UnknownTypeException (node);
2873
            throw new UnknownTypeException(node);
2857
        }    
2874
        }
2858
2859
2875
2860
        /**
2876
        /**
2861
         * Called when given node is expanded.
2877
         * Called when given node is expanded.
Lines 2863-2874 Link Here
2863
         * @param node a expanded node
2879
         * @param node a expanded node
2864
         */
2880
         */
2865
        @Override
2881
        @Override
2866
        public void nodeExpanded (Object node) {
2882
        public void nodeExpanded(Object node) {
2867
            int i, k = models.length;
2883
            int i, k = models.length;
2868
            for (i = 0; i < k; i++) {
2884
            for (i = 0; i < k; i++) {
2869
                models [i].nodeExpanded (node);
2885
                models[i].nodeExpanded(node);
2870
            }
2886
            }
2871
        }    
2887
        }
2872
2888
2873
        /**
2889
        /**
2874
         * Called when given node is collapsed.
2890
         * Called when given node is collapsed.
Lines 2876-2922 Link Here
2876
         * @param node a collapsed node
2892
         * @param node a collapsed node
2877
         */
2893
         */
2878
        @Override
2894
        @Override
2879
        public void nodeCollapsed (Object node) {
2895
        public void nodeCollapsed(Object node) {
2880
            int i, k = models.length;
2896
            int i, k = models.length;
2881
            for (i = 0; i < k; i++) {
2897
            for (i = 0; i < k; i++) {
2882
                models [i].nodeCollapsed (node);
2898
                models[i].nodeCollapsed(node);
2883
            }
2899
            }
2884
        }    
2900
        }
2885
2901
2886
        @Override
2902
        @Override
2887
        public String toString () {
2903
        public String toString() {
2888
            return super.toString () + "\n" + toString ("    ");
2904
            return super.toString() + "\n" + toString("    ");
2889
        }
2905
        }
2890
        
2906
2891
        public String toString (String n) {
2907
        public String toString(String n) {
2892
            int i, k = models.length - 1;
2908
            int i, k = models.length - 1;
2893
            if (k == -1) {
2909
            if (k == -1) {
2894
                return "";
2910
                return "";
2895
            }
2911
            }
2896
            StringBuffer sb = new StringBuffer ();
2912
            StringBuffer sb = new StringBuffer();
2897
            for (i = 0; i < k; i++) {
2913
            for (i = 0; i < k; i++) {
2898
                sb.append (n);
2914
                sb.append(n);
2899
                sb.append (models [i]);
2915
                sb.append(models[i]);
2900
                sb.append ('\n');
2916
                sb.append('\n');
2901
            }
2917
            }
2902
            sb.append (n);
2918
            sb.append(n);
2903
            sb.append (models [i]);
2919
            sb.append(models[i]);
2904
            return new String (sb);
2920
            return new String(sb);
2905
        }
2921
        }
2906
    }
2922
    }
2907
2923
2908
    private static class DefaultTreeExpansionModel implements TreeExpansionModel {
2924
    private static class DefaultTreeExpansionModel implements TreeExpansionModel {
2909
        
2925
2910
        private Reference<CompoundModel> cmRef;
2926
        private Reference<CompoundModel> cmRef;
2911
        private CompoundModel oldCM;
2927
        private CompoundModel oldCM;
2912
        
2928
2913
        public DefaultTreeExpansionModel() {
2929
        public DefaultTreeExpansionModel() {
2914
        }
2930
        }
2915
        
2931
2916
        private DefaultTreeExpansionModel(CompoundModel oldCM) {
2932
        private DefaultTreeExpansionModel(CompoundModel oldCM) {
2917
            this.oldCM = oldCM;
2933
            this.oldCM = oldCM;
2918
        }
2934
        }
2919
        
2935
2920
        /**
2936
        /**
2921
         * Defines default state (collapsed, expanded) of given node.
2937
         * Defines default state (collapsed, expanded) of given node.
2922
         *
2938
         *
Lines 2924-2931 Link Here
2924
         * @return default state (collapsed, expanded) of given node
2940
         * @return default state (collapsed, expanded) of given node
2925
         */
2941
         */
2926
        @Override
2942
        @Override
2927
        public boolean isExpanded (Object node) 
2943
        public boolean isExpanded(Object node)
2928
        throws UnknownTypeException {
2944
                throws UnknownTypeException {
2929
            CompoundModel cm = cmRef.get();
2945
            CompoundModel cm = cmRef.get();
2930
            if (cm == null) {
2946
            if (cm == null) {
2931
                return false;
2947
                return false;
Lines 2939-2948 Link Here
2939
         * @param node a expanded node
2955
         * @param node a expanded node
2940
         */
2956
         */
2941
        @Override
2957
        @Override
2942
        public void nodeExpanded (Object node) {
2958
        public void nodeExpanded(Object node) {
2943
            CompoundModel cm = cmRef.get();
2959
            CompoundModel cm = cmRef.get();
2944
            if (cm == null) {
2960
            if (cm == null) {
2945
                return ;
2961
                return;
2946
            }
2962
            }
2947
            DefaultTreeExpansionManager.get(cm).setExpanded(node);
2963
            DefaultTreeExpansionManager.get(cm).setExpanded(node);
2948
        }
2964
        }
Lines 2953-2962 Link Here
2953
         * @param node a collapsed node
2969
         * @param node a collapsed node
2954
         */
2970
         */
2955
        @Override
2971
        @Override
2956
        public void nodeCollapsed (Object node) {
2972
        public void nodeCollapsed(Object node) {
2957
            CompoundModel cm = cmRef.get();
2973
            CompoundModel cm = cmRef.get();
2958
            if (cm == null) {
2974
            if (cm == null) {
2959
                return ;
2975
                return;
2960
            }
2976
            }
2961
            DefaultTreeExpansionManager.get(cm).setCollapsed(node);
2977
            DefaultTreeExpansionManager.get(cm).setCollapsed(node);
2962
        }
2978
        }
Lines 2968-2974 Link Here
2968
            }
2984
            }
2969
            cmRef = new WeakReference<CompoundModel>(cm);
2985
            cmRef = new WeakReference<CompoundModel>(cm);
2970
        }
2986
        }
2971
        
2987
2972
        private DefaultTreeExpansionModel cloneForNewModel() {
2988
        private DefaultTreeExpansionModel cloneForNewModel() {
2973
            return new DefaultTreeExpansionModel(cmRef.get());
2989
            return new DefaultTreeExpansionModel(cmRef.get());
2974
        }
2990
        }
Lines 2986-3037 Link Here
2986
                return AsynchronousModelFilter.CURRENT_THREAD;
3002
                return AsynchronousModelFilter.CURRENT_THREAD;
2987
            }
3003
            }
2988
        }
3004
        }
2989
        
3005
2990
    }
3006
    }
2991
3007
2992
    /**
3008
    /**
2993
     * Creates one {@link org.netbeans.spi.viewmodel.NodeModel}
3009
     * Creates one {@link org.netbeans.spi.viewmodel.NodeModel} from given list
2994
     * from given list of NodeModels. DelegatingNodeModel asks all underlaying 
3010
     * of NodeModels. DelegatingNodeModel asks all underlaying models for each
2995
     * models for each concrete parameter, and returns first returned value.
3011
     * concrete parameter, and returns first returned value.
2996
     *
3012
     *
2997
     * @author   Jan Jancura
3013
     * @author Jan Jancura
2998
     */
3014
     */
2999
    private static final class DelegatingNodeModel implements SuperNodeModel {
3015
    private static final class DelegatingNodeModel implements SuperNodeModel {
3000
3016
3001
        private NodeModel[] models;
3017
        private NodeModel[] models;
3002
        private HashMap<String, NodeModel> classNameToModel = new HashMap<String, NodeModel>();
3018
        private HashMap<String, NodeModel> classNameToModel = new HashMap<>();
3003
3004
3019
3005
        /**
3020
        /**
3006
         * Creates new instance of DelegatingNodeModel for given list of 
3021
         * Creates new instance of DelegatingNodeModel for given list of
3007
         * NodeModels.
3022
         * NodeModels.
3008
         *
3023
         *
3009
         * @param models a list of NodeModels
3024
         * @param models a list of NodeModels
3010
         */
3025
         */
3011
        DelegatingNodeModel (
3026
        DelegatingNodeModel(
3012
            List<NodeModel> models
3027
                List<NodeModel> models
3013
        ) {
3028
        ) {
3014
            this (convert (models));
3029
            this(convert(models));
3015
        }
3030
        }
3016
3031
3017
        private static NodeModel[] convert (List<NodeModel> l) {
3032
        private static NodeModel[] convert(List<NodeModel> l) {
3018
            NodeModel[] models = new NodeModel [l.size ()];
3033
            NodeModel[] models = new NodeModel[l.size()];
3019
            return l.toArray (models);
3034
            return l.toArray(models);
3020
        }
3035
        }
3021
3036
3022
        /**
3037
        /**
3023
         * Creates new instance of DelegatingNodeModel for given array of 
3038
         * Creates new instance of DelegatingNodeModel for given array of
3024
         * NodeModels.
3039
         * NodeModels.
3025
         *
3040
         *
3026
         * @param models a array of NodeModels
3041
         * @param models a array of NodeModels
3027
         */
3042
         */
3028
        DelegatingNodeModel (
3043
        DelegatingNodeModel(
3029
            NodeModel[] models
3044
                NodeModel[] models
3030
        ) {
3045
        ) {
3031
            this.models = models;
3046
            this.models = models;
3032
3047
3033
        }
3048
        }
3034
        
3049
3035
        NodeModel[] getModels() {
3050
        NodeModel[] getModels() {
3036
            return models;
3051
            return models;
3037
        }
3052
        }
Lines 3039-3144 Link Here
3039
        /**
3054
        /**
3040
         * Returns display name for given node.
3055
         * Returns display name for given node.
3041
         *
3056
         *
3042
         * @throws  UnknownTypeException if this NodeModel implementation is not
3057
         * @throws UnknownTypeException if this NodeModel implementation is not
3043
         *          able to resolve display name for given node type
3058
         * able to resolve display name for given node type
3044
         * @return  display name for given node
3059
         * @return display name for given node
3045
         */
3060
         */
3046
        @Override
3061
        @Override
3047
        public String getDisplayName (Object node) 
3062
        public String getDisplayName(Object node)
3048
        throws UnknownTypeException {
3063
                throws UnknownTypeException {
3049
            NodeModel model = classNameToModel.get (
3064
            NodeModel model = classNameToModel.get(
3050
                node.getClass ().getName ()
3065
                    node.getClass().getName()
3051
            );
3066
            );
3052
            if (model != null) {
3067
            if (model != null) {
3053
                try {
3068
                try {
3054
                    return model.getDisplayName (node);
3069
                    return model.getDisplayName(node);
3055
                } catch (UnknownTypeException e) {
3070
                } catch (UnknownTypeException e) {
3056
                }
3071
                }
3057
            }
3072
            }
3058
            int i, k = models.length;
3073
            int i, k = models.length;
3059
            for (i = 0; i < k; i++) {
3074
            for (i = 0; i < k; i++) {
3060
                try {
3075
                try {
3061
                    String dn = models [i].getDisplayName (node);
3076
                    String dn = models[i].getDisplayName(node);
3062
                    classNameToModel.put (node.getClass ().getName (), models [i]);
3077
                    classNameToModel.put(node.getClass().getName(), models[i]);
3063
                    return dn;
3078
                    return dn;
3064
                } catch (UnknownTypeException e) {
3079
                } catch (UnknownTypeException e) {
3065
                }
3080
                }
3066
            }
3081
            }
3067
            throw new UnknownTypeException (node);
3082
            throw new UnknownTypeException(node);
3068
        }
3083
        }
3069
3084
3070
        /**
3085
        /**
3071
         * Returns tool tip for given node.
3086
         * Returns tool tip for given node.
3072
         *
3087
         *
3073
         * @throws  UnknownTypeException if this NodeModel implementation is not
3088
         * @throws UnknownTypeException if this NodeModel implementation is not
3074
         *          able to resolve tool tip for given node type
3089
         * able to resolve tool tip for given node type
3075
         * @return  tool tip for given node
3090
         * @return tool tip for given node
3076
         */
3091
         */
3077
        @Override
3092
        @Override
3078
        public String getShortDescription (Object node) 
3093
        public String getShortDescription(Object node)
3079
        throws UnknownTypeException {
3094
                throws UnknownTypeException {
3080
            NodeModel model = classNameToModel.get (
3095
            NodeModel model = classNameToModel.get(
3081
                node.getClass ().getName ()
3096
                    node.getClass().getName()
3082
            );
3097
            );
3083
            if (model != null) {
3098
            if (model != null) {
3084
                try {
3099
                try {
3085
                    return model.getShortDescription (node);
3100
                    return model.getShortDescription(node);
3086
                } catch (UnknownTypeException e) {
3101
                } catch (UnknownTypeException e) {
3087
                }
3102
                }
3088
            }
3103
            }
3089
            int i, k = models.length;
3104
            int i, k = models.length;
3090
            for (i = 0; i < k; i++) {
3105
            for (i = 0; i < k; i++) {
3091
                try {
3106
                try {
3092
                    String dn = models [i].getShortDescription (node);
3107
                    String dn = models[i].getShortDescription(node);
3093
                    classNameToModel.put (node.getClass ().getName (), models [i]);
3108
                    classNameToModel.put(node.getClass().getName(), models[i]);
3094
                    return dn;
3109
                    return dn;
3095
                } catch (UnknownTypeException e) {
3110
                } catch (UnknownTypeException e) {
3096
                }
3111
                }
3097
            }
3112
            }
3098
            throw new UnknownTypeException (node);
3113
            throw new UnknownTypeException(node);
3099
        }
3114
        }
3100
3115
3101
        /**
3116
        /**
3102
         * Returns icon for given node.
3117
         * Returns icon for given node.
3103
         *
3118
         *
3104
         * @throws  UnknownTypeException if this NodeModel implementation is not
3119
         * @throws UnknownTypeException if this NodeModel implementation is not
3105
         *          able to resolve icon for given node type
3120
         * able to resolve icon for given node type
3106
         * @return  icon for given node
3121
         * @return icon for given node
3107
         */
3122
         */
3108
        @Override
3123
        @Override
3109
        public String getIconBase (Object node) 
3124
        public String getIconBase(Object node)
3110
        throws UnknownTypeException {
3125
                throws UnknownTypeException {
3111
            NodeModel model = classNameToModel.get (
3126
            NodeModel model = classNameToModel.get(
3112
                node.getClass ().getName ()
3127
                    node.getClass().getName()
3113
            );
3128
            );
3114
            if (model != null) {
3129
            if (model != null) {
3115
                try {
3130
                try {
3116
                    return model.getIconBase (node);
3131
                    return model.getIconBase(node);
3117
                } catch (UnknownTypeException e) {
3132
                } catch (UnknownTypeException e) {
3118
                }
3133
                }
3119
            }
3134
            }
3120
            int i, k = models.length;
3135
            int i, k = models.length;
3121
            for (i = 0; i < k; i++) {
3136
            for (i = 0; i < k; i++) {
3122
                try {
3137
                try {
3123
                    String dn = models [i].getIconBase (node);
3138
                    String dn = models[i].getIconBase(node);
3124
                    classNameToModel.put (node.getClass ().getName (), models [i]);
3139
                    classNameToModel.put(node.getClass().getName(), models[i]);
3125
                    return dn;
3140
                    return dn;
3126
                } catch (UnknownTypeException e) {
3141
                } catch (UnknownTypeException e) {
3127
                }
3142
                }
3128
            }
3143
            }
3129
            throw new UnknownTypeException (node);
3144
            throw new UnknownTypeException(node);
3130
        }
3145
        }
3131
3146
3132
        /** 
3147
        /**
3133
         * Registers given listener.
3148
         * Registers given listener.
3134
         * 
3149
         *
3135
         * @param l the listener to add
3150
         * @param l the listener to add
3136
         */
3151
         */
3137
        @Override
3152
        @Override
3138
        public void addModelListener (ModelListener l) {
3153
        public void addModelListener(ModelListener l) {
3139
            int i, k = models.length;
3154
            int i, k = models.length;
3140
            for (i = 0; i < k; i++) {
3155
            for (i = 0; i < k; i++) {
3141
                models [i].addModelListener (l);
3156
                models[i].addModelListener(l);
3142
            }
3157
            }
3143
        }
3158
        }
3144
3159
Lines 3147-3215 Link Here
3147
         *
3162
         *
3148
         * @param l the listener to add
3163
         * @param l the listener to add
3149
         */
3164
         */
3150
        void addModelListener (ModelListener l, Set<Model> modelsListenersAddedTo) {
3165
        void addModelListener(ModelListener l, Set<Model> modelsListenersAddedTo) {
3151
            int i, k = models.length;
3166
            int i, k = models.length;
3152
            for (i = 0; i < k; i++) {
3167
            for (i = 0; i < k; i++) {
3153
                NodeModel m = models [i];
3168
                NodeModel m = models[i];
3154
                if (!modelsListenersAddedTo.add(m)) {
3169
                if (!modelsListenersAddedTo.add(m)) {
3155
                    continue;
3170
                    continue;
3156
                }
3171
                }
3157
                if (m instanceof DelegatingNodeModel) {
3172
                if (m instanceof DelegatingNodeModel) {
3158
                    ((DelegatingNodeModel) m).addModelListener(l, modelsListenersAddedTo);
3173
                    ((DelegatingNodeModel) m).addModelListener(l, modelsListenersAddedTo);
3159
                } else {
3174
                } else {
3160
                    m.addModelListener (l);
3175
                    m.addModelListener(l);
3161
                }
3176
                }
3162
            }
3177
            }
3163
        }
3178
        }
3164
3179
3165
        /** 
3180
        /**
3166
         * Unregisters given listener.
3181
         * Unregisters given listener.
3167
         *
3182
         *
3168
         * @param l the listener to remove
3183
         * @param l the listener to remove
3169
         */
3184
         */
3170
        @Override
3185
        @Override
3171
        public void removeModelListener (ModelListener l) {
3186
        public void removeModelListener(ModelListener l) {
3172
            int i, k = models.length;
3187
            int i, k = models.length;
3173
            for (i = 0; i < k; i++) {
3188
            for (i = 0; i < k; i++) {
3174
                models [i].removeModelListener (l);
3189
                models[i].removeModelListener(l);
3175
            }
3190
            }
3176
        }
3191
        }
3177
3192
3178
        @Override
3193
        @Override
3179
        public String toString () {
3194
        public String toString() {
3180
            return toString ("    ");
3195
            return toString("    ");
3181
        }
3196
        }
3182
        
3197
3183
        public String toString (String n) {
3198
        public String toString(String n) {
3184
            int i, k = models.length - 1;
3199
            int i, k = models.length - 1;
3185
            if (k == -1) {
3200
            if (k == -1) {
3186
                return "";
3201
                return "";
3187
            }
3202
            }
3188
            StringBuffer sb = new StringBuffer ();
3203
            StringBuffer sb = new StringBuffer();
3189
            for (i = 0; i < k; i++) {
3204
            for (i = 0; i < k; i++) {
3190
                sb.append (n);
3205
                sb.append(n);
3191
                sb.append (models [i]);
3206
                sb.append(models[i]);
3192
                sb.append ('\n');
3207
                sb.append('\n');
3193
            }
3208
            }
3194
            sb.append (n);
3209
            sb.append(n);
3195
            sb.append (models [i]);
3210
            sb.append(models[i]);
3196
            return new String (sb);
3211
            return new String(sb);
3197
        }
3212
        }
3198
        
3213
3199
        // Extensions:
3214
        // Extensions:
3200
        
3201
        private boolean defaultCanRename() {
3215
        private boolean defaultCanRename() {
3202
            return false;
3216
            return false;
3203
        }
3217
        }
3204
        
3218
3205
        private boolean defaultCanCopy() {
3219
        private boolean defaultCanCopy() {
3206
            return false;
3220
            return false;
3207
        }
3221
        }
3208
    
3222
3209
        private boolean defaultCanCut() {
3223
        private boolean defaultCanCut() {
3210
            return false;
3224
            return false;
3211
        }
3225
        }
3212
    
3226
3213
        private Transferable defaultClipboardCopy() throws IOException {
3227
        private Transferable defaultClipboardCopy() throws IOException {
3214
            return null;
3228
            return null;
3215
        }
3229
        }
Lines 3227-3233 Link Here
3227
        }
3241
        }
3228
3242
3229
        private PasteType defaultGetDropType(Transferable t, int action,
3243
        private PasteType defaultGetDropType(Transferable t, int action,
3230
                                            int index) {
3244
                int index) {
3231
            return null;
3245
            return null;
3232
        }
3246
        }
3233
3247
Lines 3238-3250 Link Here
3238
        @Override
3252
        @Override
3239
        public boolean canRename(Object node) throws UnknownTypeException {
3253
        public boolean canRename(Object node) throws UnknownTypeException {
3240
            UnknownTypeException uex = null;
3254
            UnknownTypeException uex = null;
3241
            NodeModel model = classNameToModel.get (
3255
            NodeModel model = classNameToModel.get(
3242
                node.getClass ().getName ()
3256
                    node.getClass().getName()
3243
            );
3257
            );
3244
            if (model != null) {
3258
            if (model != null) {
3245
                if (model instanceof ExtendedNodeModel) {
3259
                if (model instanceof ExtendedNodeModel) {
3246
                    try {
3260
                    try {
3247
                        return ((ExtendedNodeModel) model).canRename (node);
3261
                        return ((ExtendedNodeModel) model).canRename(node);
3248
                    } catch (UnknownTypeException e) {
3262
                    } catch (UnknownTypeException e) {
3249
                        uex = e;
3263
                        uex = e;
3250
                    }
3264
                    }
Lines 3257-3264 Link Here
3257
            for (i = 0; i < k; i++) {
3271
            for (i = 0; i < k; i++) {
3258
                if (models[i] instanceof ExtendedNodeModel) {
3272
                if (models[i] instanceof ExtendedNodeModel) {
3259
                    try {
3273
                    try {
3260
                        boolean cr = ((ExtendedNodeModel) models [i]).canRename (node);
3274
                        boolean cr = ((ExtendedNodeModel) models[i]).canRename(node);
3261
                        classNameToModel.put (node.getClass ().getName (), models [i]);
3275
                        classNameToModel.put(node.getClass().getName(), models[i]);
3262
                        return cr;
3276
                        return cr;
3263
                    } catch (UnknownTypeException e) {
3277
                    } catch (UnknownTypeException e) {
3264
                        uex = e;
3278
                        uex = e;
Lines 3272-3291 Link Here
3272
            if (uex != null) {
3286
            if (uex != null) {
3273
                throw uex;
3287
                throw uex;
3274
            } else {
3288
            } else {
3275
                throw new UnknownTypeException (node);
3289
                throw new UnknownTypeException(node);
3276
            }
3290
            }
3277
        }
3291
        }
3278
3292
3279
        @Override
3293
        @Override
3280
        public boolean canCopy(Object node) throws UnknownTypeException {
3294
        public boolean canCopy(Object node) throws UnknownTypeException {
3281
            UnknownTypeException uex = null;
3295
            UnknownTypeException uex = null;
3282
            NodeModel model = classNameToModel.get (
3296
            NodeModel model = classNameToModel.get(
3283
                node.getClass ().getName ()
3297
                    node.getClass().getName()
3284
            );
3298
            );
3285
            if (model != null) {
3299
            if (model != null) {
3286
                if (model instanceof ExtendedNodeModel) {
3300
                if (model instanceof ExtendedNodeModel) {
3287
                    try {
3301
                    try {
3288
                        return ((ExtendedNodeModel) model).canCopy (node);
3302
                        return ((ExtendedNodeModel) model).canCopy(node);
3289
                    } catch (UnknownTypeException e) {
3303
                    } catch (UnknownTypeException e) {
3290
                        uex = e;
3304
                        uex = e;
3291
                    }
3305
                    }
Lines 3298-3305 Link Here
3298
            for (i = 0; i < k; i++) {
3312
            for (i = 0; i < k; i++) {
3299
                if (models[i] instanceof ExtendedNodeModel) {
3313
                if (models[i] instanceof ExtendedNodeModel) {
3300
                    try {
3314
                    try {
3301
                        boolean cr = ((ExtendedNodeModel) models [i]).canCopy (node);
3315
                        boolean cr = ((ExtendedNodeModel) models[i]).canCopy(node);
3302
                        classNameToModel.put (node.getClass ().getName (), models [i]);
3316
                        classNameToModel.put(node.getClass().getName(), models[i]);
3303
                        return cr;
3317
                        return cr;
3304
                    } catch (UnknownTypeException e) {
3318
                    } catch (UnknownTypeException e) {
3305
                        uex = e;
3319
                        uex = e;
Lines 3313-3332 Link Here
3313
            if (uex != null) {
3327
            if (uex != null) {
3314
                throw uex;
3328
                throw uex;
3315
            } else {
3329
            } else {
3316
                throw new UnknownTypeException (node);
3330
                throw new UnknownTypeException(node);
3317
            }
3331
            }
3318
        }
3332
        }
3319
3333
3320
        @Override
3334
        @Override
3321
        public boolean canCut(Object node) throws UnknownTypeException {
3335
        public boolean canCut(Object node) throws UnknownTypeException {
3322
            UnknownTypeException uex = null;
3336
            UnknownTypeException uex = null;
3323
            NodeModel model = classNameToModel.get (
3337
            NodeModel model = classNameToModel.get(
3324
                node.getClass ().getName ()
3338
                    node.getClass().getName()
3325
            );
3339
            );
3326
            if (model != null) {
3340
            if (model != null) {
3327
                if (model instanceof ExtendedNodeModel) {
3341
                if (model instanceof ExtendedNodeModel) {
3328
                    try {
3342
                    try {
3329
                        return ((ExtendedNodeModel) model).canCut (node);
3343
                        return ((ExtendedNodeModel) model).canCut(node);
3330
                    } catch (UnknownTypeException e) {
3344
                    } catch (UnknownTypeException e) {
3331
                        uex = e;
3345
                        uex = e;
3332
                    }
3346
                    }
Lines 3339-3346 Link Here
3339
            for (i = 0; i < k; i++) {
3353
            for (i = 0; i < k; i++) {
3340
                if (models[i] instanceof ExtendedNodeModel) {
3354
                if (models[i] instanceof ExtendedNodeModel) {
3341
                    try {
3355
                    try {
3342
                        boolean cr = ((ExtendedNodeModel) models [i]).canCut (node);
3356
                        boolean cr = ((ExtendedNodeModel) models[i]).canCut(node);
3343
                        classNameToModel.put (node.getClass ().getName (), models [i]);
3357
                        classNameToModel.put(node.getClass().getName(), models[i]);
3344
                        return cr;
3358
                        return cr;
3345
                    } catch (UnknownTypeException e) {
3359
                    } catch (UnknownTypeException e) {
3346
                        uex = e;
3360
                        uex = e;
Lines 3354-3374 Link Here
3354
            if (uex != null) {
3368
            if (uex != null) {
3355
                throw uex;
3369
                throw uex;
3356
            } else {
3370
            } else {
3357
                throw new UnknownTypeException (node);
3371
                throw new UnknownTypeException(node);
3358
            }
3372
            }
3359
        }
3373
        }
3360
3374
3361
        @Override
3375
        @Override
3362
        public Transferable clipboardCopy(Object node) throws IOException,
3376
        public Transferable clipboardCopy(Object node) throws IOException,
3363
                                                              UnknownTypeException {
3377
                UnknownTypeException {
3364
            UnknownTypeException uex = null;
3378
            UnknownTypeException uex = null;
3365
            NodeModel model = classNameToModel.get (
3379
            NodeModel model = classNameToModel.get(
3366
                node.getClass ().getName ()
3380
                    node.getClass().getName()
3367
            );
3381
            );
3368
            if (model != null) {
3382
            if (model != null) {
3369
                if (model instanceof ExtendedNodeModel) {
3383
                if (model instanceof ExtendedNodeModel) {
3370
                    try {
3384
                    try {
3371
                        return ((ExtendedNodeModel) model).clipboardCopy (node);
3385
                        return ((ExtendedNodeModel) model).clipboardCopy(node);
3372
                    } catch (UnknownTypeException e) {
3386
                    } catch (UnknownTypeException e) {
3373
                        uex = e;
3387
                        uex = e;
3374
                    }
3388
                    }
Lines 3381-3388 Link Here
3381
            for (i = 0; i < k; i++) {
3395
            for (i = 0; i < k; i++) {
3382
                if (models[i] instanceof ExtendedNodeModel) {
3396
                if (models[i] instanceof ExtendedNodeModel) {
3383
                    try {
3397
                    try {
3384
                        Transferable t = ((ExtendedNodeModel) models [i]).clipboardCopy (node);
3398
                        Transferable t = ((ExtendedNodeModel) models[i]).clipboardCopy(node);
3385
                        classNameToModel.put (node.getClass ().getName (), models [i]);
3399
                        classNameToModel.put(node.getClass().getName(), models[i]);
3386
                        return t;
3400
                        return t;
3387
                    } catch (UnknownTypeException e) {
3401
                    } catch (UnknownTypeException e) {
3388
                        uex = e;
3402
                        uex = e;
Lines 3396-3416 Link Here
3396
            if (uex != null) {
3410
            if (uex != null) {
3397
                throw uex;
3411
                throw uex;
3398
            } else {
3412
            } else {
3399
                throw new UnknownTypeException (node);
3413
                throw new UnknownTypeException(node);
3400
            }
3414
            }
3401
        }
3415
        }
3402
3416
3403
        @Override
3417
        @Override
3404
        public Transferable clipboardCut(Object node) throws IOException,
3418
        public Transferable clipboardCut(Object node) throws IOException,
3405
                                                             UnknownTypeException {
3419
                UnknownTypeException {
3406
            UnknownTypeException uex = null;
3420
            UnknownTypeException uex = null;
3407
            NodeModel model = classNameToModel.get (
3421
            NodeModel model = classNameToModel.get(
3408
                node.getClass ().getName ()
3422
                    node.getClass().getName()
3409
            );
3423
            );
3410
            if (model != null) {
3424
            if (model != null) {
3411
                if (model instanceof ExtendedNodeModel) {
3425
                if (model instanceof ExtendedNodeModel) {
3412
                    try {
3426
                    try {
3413
                        return ((ExtendedNodeModel) model).clipboardCut (node);
3427
                        return ((ExtendedNodeModel) model).clipboardCut(node);
3414
                    } catch (UnknownTypeException e) {
3428
                    } catch (UnknownTypeException e) {
3415
                        uex = e;
3429
                        uex = e;
3416
                    }
3430
                    }
Lines 3423-3430 Link Here
3423
            for (i = 0; i < k; i++) {
3437
            for (i = 0; i < k; i++) {
3424
                if (models[i] instanceof ExtendedNodeModel) {
3438
                if (models[i] instanceof ExtendedNodeModel) {
3425
                    try {
3439
                    try {
3426
                        Transferable t = ((ExtendedNodeModel) models [i]).clipboardCut (node);
3440
                        Transferable t = ((ExtendedNodeModel) models[i]).clipboardCut(node);
3427
                        classNameToModel.put (node.getClass ().getName (), models [i]);
3441
                        classNameToModel.put(node.getClass().getName(), models[i]);
3428
                        return t;
3442
                        return t;
3429
                    } catch (UnknownTypeException e) {
3443
                    } catch (UnknownTypeException e) {
3430
                        uex = e;
3444
                        uex = e;
Lines 3438-3444 Link Here
3438
            if (uex != null) {
3452
            if (uex != null) {
3439
                throw uex;
3453
                throw uex;
3440
            } else {
3454
            } else {
3441
                throw new UnknownTypeException (node);
3455
                throw new UnknownTypeException(node);
3442
            }
3456
            }
3443
        }
3457
        }
3444
3458
Lines 3466-3480 Link Here
3466
3480
3467
        @Override
3481
        @Override
3468
        public Transferable drag(Object node) throws IOException,
3482
        public Transferable drag(Object node) throws IOException,
3469
                                                     UnknownTypeException {
3483
                UnknownTypeException {
3470
            UnknownTypeException uex = null;
3484
            UnknownTypeException uex = null;
3471
            NodeModel model = (NodeModel) classNameToModel.get (
3485
            NodeModel model = (NodeModel) classNameToModel.get(
3472
                node.getClass ().getName ()
3486
                    node.getClass().getName()
3473
            );
3487
            );
3474
            if (model != null) {
3488
            if (model != null) {
3475
                if (model instanceof DnDNodeModel) {
3489
                if (model instanceof DnDNodeModel) {
3476
                    try {
3490
                    try {
3477
                        return ((DnDNodeModel) model).drag (node);
3491
                        return ((DnDNodeModel) model).drag(node);
3478
                    } catch (UnknownTypeException e) {
3492
                    } catch (UnknownTypeException e) {
3479
                        uex = e;
3493
                        uex = e;
3480
                    }
3494
                    }
Lines 3487-3494 Link Here
3487
            for (i = 0; i < k; i++) {
3501
            for (i = 0; i < k; i++) {
3488
                if (models[i] instanceof DnDNodeModel) {
3502
                if (models[i] instanceof DnDNodeModel) {
3489
                    try {
3503
                    try {
3490
                        Transferable t = ((DnDNodeModel) models [i]).drag (node);
3504
                        Transferable t = ((DnDNodeModel) models[i]).drag(node);
3491
                        classNameToModel.put (node.getClass ().getName (), models [i]);
3505
                        classNameToModel.put(node.getClass().getName(), models[i]);
3492
                        return t;
3506
                        return t;
3493
                    } catch (UnknownTypeException e) {
3507
                    } catch (UnknownTypeException e) {
3494
                        uex = e;
3508
                        uex = e;
Lines 3502-3521 Link Here
3502
            if (uex != null) {
3516
            if (uex != null) {
3503
                throw uex;
3517
                throw uex;
3504
            } else {
3518
            } else {
3505
                throw new UnknownTypeException (node);
3519
                throw new UnknownTypeException(node);
3506
            }
3520
            }
3507
        }
3521
        }
3508
3522
3509
        @Override
3523
        @Override
3510
        public PasteType[] getPasteTypes(Object node, Transferable t) throws UnknownTypeException {
3524
        public PasteType[] getPasteTypes(Object node, Transferable t) throws UnknownTypeException {
3511
            UnknownTypeException uex = null;
3525
            UnknownTypeException uex = null;
3512
            NodeModel model = classNameToModel.get (
3526
            NodeModel model = classNameToModel.get(
3513
                node.getClass ().getName ()
3527
                    node.getClass().getName()
3514
            );
3528
            );
3515
            if (model != null) {
3529
            if (model != null) {
3516
                if (model instanceof ExtendedNodeModel) {
3530
                if (model instanceof ExtendedNodeModel) {
3517
                    try {
3531
                    try {
3518
                        return ((ExtendedNodeModel) model).getPasteTypes (node, t);
3532
                        return ((ExtendedNodeModel) model).getPasteTypes(node, t);
3519
                    } catch (UnknownTypeException e) {
3533
                    } catch (UnknownTypeException e) {
3520
                        uex = e;
3534
                        uex = e;
3521
                    }
3535
                    }
Lines 3528-3535 Link Here
3528
            for (i = 0; i < k; i++) {
3542
            for (i = 0; i < k; i++) {
3529
                if (models[i] instanceof ExtendedNodeModel) {
3543
                if (models[i] instanceof ExtendedNodeModel) {
3530
                    try {
3544
                    try {
3531
                        PasteType[] p = ((ExtendedNodeModel) models [i]).getPasteTypes (node, t);
3545
                        PasteType[] p = ((ExtendedNodeModel) models[i]).getPasteTypes(node, t);
3532
                        classNameToModel.put (node.getClass ().getName (), models [i]);
3546
                        classNameToModel.put(node.getClass().getName(), models[i]);
3533
                        return p;
3547
                        return p;
3534
                    } catch (UnknownTypeException e) {
3548
                    } catch (UnknownTypeException e) {
3535
                        uex = e;
3549
                        uex = e;
Lines 3543-3563 Link Here
3543
            if (uex != null) {
3557
            if (uex != null) {
3544
                throw uex;
3558
                throw uex;
3545
            } else {
3559
            } else {
3546
                throw new UnknownTypeException (node);
3560
                throw new UnknownTypeException(node);
3547
            }
3561
            }
3548
        }
3562
        }
3549
3563
3550
        @Override
3564
        @Override
3551
        public PasteType getDropType(Object node, Transferable t, int action,
3565
        public PasteType getDropType(Object node, Transferable t, int action,
3552
                                     int index) throws UnknownTypeException {
3566
                int index) throws UnknownTypeException {
3553
            UnknownTypeException uex = null;
3567
            UnknownTypeException uex = null;
3554
            NodeModel model = (NodeModel) classNameToModel.get (
3568
            NodeModel model = (NodeModel) classNameToModel.get(
3555
                node.getClass ().getName ()
3569
                    node.getClass().getName()
3556
            );
3570
            );
3557
            if (model != null) {
3571
            if (model != null) {
3558
                if (model instanceof DnDNodeModel) {
3572
                if (model instanceof DnDNodeModel) {
3559
                    try {
3573
                    try {
3560
                        return ((DnDNodeModel) model).getDropType (node, t, action, index);
3574
                        return ((DnDNodeModel) model).getDropType(node, t, action, index);
3561
                    } catch (UnknownTypeException e) {
3575
                    } catch (UnknownTypeException e) {
3562
                        uex = e;
3576
                        uex = e;
3563
                    }
3577
                    }
Lines 3570-3577 Link Here
3570
            for (i = 0; i < k; i++) {
3584
            for (i = 0; i < k; i++) {
3571
                if (models[i] instanceof DnDNodeModel) {
3585
                if (models[i] instanceof DnDNodeModel) {
3572
                    try {
3586
                    try {
3573
                        PasteType p = ((DnDNodeModel) models [i]).getDropType (node, t, action, index);
3587
                        PasteType p = ((DnDNodeModel) models[i]).getDropType(node, t, action, index);
3574
                        classNameToModel.put (node.getClass ().getName (), models [i]);
3588
                        classNameToModel.put(node.getClass().getName(), models[i]);
3575
                        return p;
3589
                        return p;
3576
                    } catch (UnknownTypeException e) {
3590
                    } catch (UnknownTypeException e) {
3577
                        uex = e;
3591
                        uex = e;
Lines 3585-3611 Link Here
3585
            if (uex != null) {
3599
            if (uex != null) {
3586
                throw uex;
3600
                throw uex;
3587
            } else {
3601
            } else {
3588
                throw new UnknownTypeException (node);
3602
                throw new UnknownTypeException(node);
3589
            }
3603
            }
3590
        }
3604
        }
3591
3605
3592
        @Override
3606
        @Override
3593
        public void setName(Object node, String name) throws UnknownTypeException {
3607
        public void setName(Object node, String name) throws UnknownTypeException {
3594
            UnknownTypeException uex = null;
3608
            UnknownTypeException uex = null;
3595
            NodeModel model = classNameToModel.get (
3609
            NodeModel model = classNameToModel.get(
3596
                node.getClass ().getName ()
3610
                    node.getClass().getName()
3597
            );
3611
            );
3598
            if (model != null) {
3612
            if (model != null) {
3599
                if (model instanceof ExtendedNodeModel) {
3613
                if (model instanceof ExtendedNodeModel) {
3600
                    try {
3614
                    try {
3601
                        ((ExtendedNodeModel) model).setName (node, name);
3615
                        ((ExtendedNodeModel) model).setName(node, name);
3602
                        return ;
3616
                        return;
3603
                    } catch (UnknownTypeException e) {
3617
                    } catch (UnknownTypeException e) {
3604
                        uex = e;
3618
                        uex = e;
3605
                    }
3619
                    }
3606
                } else {
3620
                } else {
3607
                    defaultSetName(name);
3621
                    defaultSetName(name);
3608
                    return ;
3622
                    return;
3609
                }
3623
                }
3610
            }
3624
            }
3611
            int i, k = models.length;
3625
            int i, k = models.length;
Lines 3613-3621 Link Here
3613
            for (i = 0; i < k; i++) {
3627
            for (i = 0; i < k; i++) {
3614
                if (models[i] instanceof ExtendedNodeModel) {
3628
                if (models[i] instanceof ExtendedNodeModel) {
3615
                    try {
3629
                    try {
3616
                        ((ExtendedNodeModel) models [i]).setName (node, name);
3630
                        ((ExtendedNodeModel) models[i]).setName(node, name);
3617
                        classNameToModel.put (node.getClass ().getName (), models [i]);
3631
                        classNameToModel.put(node.getClass().getName(), models[i]);
3618
                        return ;
3632
                        return;
3619
                    } catch (UnknownTypeException e) {
3633
                    } catch (UnknownTypeException e) {
3620
                        uex = e;
3634
                        uex = e;
3621
                    }
3635
                    }
Lines 3624-3648 Link Here
3624
            }
3638
            }
3625
            if (!isExtended) {
3639
            if (!isExtended) {
3626
                defaultSetName(name);
3640
                defaultSetName(name);
3627
                return ;
3641
                return;
3628
            }
3642
            }
3629
            if (uex != null) {
3643
            if (uex != null) {
3630
                throw uex;
3644
                throw uex;
3631
            } else {
3645
            } else {
3632
                throw new UnknownTypeException (node);
3646
                throw new UnknownTypeException(node);
3633
            }
3647
            }
3634
        }
3648
        }
3635
3649
3636
        @Override
3650
        @Override
3637
        public String getIconBaseWithExtension(Object node) throws UnknownTypeException {
3651
        public String getIconBaseWithExtension(Object node) throws UnknownTypeException {
3638
            UnknownTypeException uex = null;
3652
            UnknownTypeException uex = null;
3639
            NodeModel model = classNameToModel.get (
3653
            NodeModel model = classNameToModel.get(
3640
                node.getClass ().getName ()
3654
                    node.getClass().getName()
3641
            );
3655
            );
3642
            if (model != null) {
3656
            if (model != null) {
3643
                try {
3657
                try {
3644
                    if (model instanceof ExtendedNodeModel) {
3658
                    if (model instanceof ExtendedNodeModel) {
3645
                        return ((ExtendedNodeModel) model).getIconBaseWithExtension (node);
3659
                        return ((ExtendedNodeModel) model).getIconBaseWithExtension(node);
3646
                    } else {
3660
                    } else {
3647
                        String base = model.getIconBase(node);
3661
                        String base = model.getIconBase(node);
3648
                        if (base != null) {
3662
                        if (base != null) {
Lines 3660-3666 Link Here
3660
                try {
3674
                try {
3661
                    String ib;
3675
                    String ib;
3662
                    if (models[i] instanceof ExtendedNodeModel) {
3676
                    if (models[i] instanceof ExtendedNodeModel) {
3663
                        ib = ((ExtendedNodeModel) models [i]).getIconBaseWithExtension (node);
3677
                        ib = ((ExtendedNodeModel) models[i]).getIconBaseWithExtension(node);
3664
                    } else {
3678
                    } else {
3665
                        String base = models[i].getIconBase(node);
3679
                        String base = models[i].getIconBase(node);
3666
                        if (base != null) {
3680
                        if (base != null) {
Lines 3669-3675 Link Here
3669
                            ib = null;
3683
                            ib = null;
3670
                        }
3684
                        }
3671
                    }
3685
                    }
3672
                    classNameToModel.put (node.getClass ().getName (), models [i]);
3686
                    classNameToModel.put(node.getClass().getName(), models[i]);
3673
                    return ib;
3687
                    return ib;
3674
                } catch (UnknownTypeException e) {
3688
                } catch (UnknownTypeException e) {
3675
                    uex = e;
3689
                    uex = e;
Lines 3678-3686 Link Here
3678
            if (uex != null) {
3692
            if (uex != null) {
3679
                throw uex;
3693
                throw uex;
3680
            } else {
3694
            } else {
3681
                throw new UnknownTypeException (node);
3695
                throw new UnknownTypeException(node);
3682
            }
3696
            }
3683
            
3697
3684
        }
3698
        }
3685
3699
3686
        @Override
3700
        @Override
Lines 3691-3697 Link Here
3691
            for (i = 0; i < k; i++) {
3705
            for (i = 0; i < k; i++) {
3692
                if (models[i] instanceof CheckNodeModel) {
3706
                if (models[i] instanceof CheckNodeModel) {
3693
                    try {
3707
                    try {
3694
                        Boolean checkable = ((CheckNodeModel) models [i]).isCheckable(node);
3708
                        Boolean checkable = ((CheckNodeModel) models[i]).isCheckable(node);
3695
                        return checkable;
3709
                        return checkable;
3696
                    } catch (UnknownTypeException e) {
3710
                    } catch (UnknownTypeException e) {
3697
                        uex = e;
3711
                        uex = e;
Lines 3705-3711 Link Here
3705
            if (uex != null) {
3719
            if (uex != null) {
3706
                throw uex;
3720
                throw uex;
3707
            } else {
3721
            } else {
3708
                throw new UnknownTypeException (node);
3722
                throw new UnknownTypeException(node);
3709
            }
3723
            }
3710
        }
3724
        }
3711
3725
Lines 3716-3722 Link Here
3716
            for (i = 0; i < k; i++) {
3730
            for (i = 0; i < k; i++) {
3717
                if (models[i] instanceof CheckNodeModel) {
3731
                if (models[i] instanceof CheckNodeModel) {
3718
                    try {
3732
                    try {
3719
                        boolean checkEnabled = ((CheckNodeModel) models [i]).isCheckEnabled(node);
3733
                        boolean checkEnabled = ((CheckNodeModel) models[i]).isCheckEnabled(node);
3720
                        return checkEnabled;
3734
                        return checkEnabled;
3721
                    } catch (UnknownTypeException e) {
3735
                    } catch (UnknownTypeException e) {
3722
                        uex = e;
3736
                        uex = e;
Lines 3738-3744 Link Here
3738
            for (i = 0; i < k; i++) {
3752
            for (i = 0; i < k; i++) {
3739
                if (models[i] instanceof CheckNodeModel) {
3753
                if (models[i] instanceof CheckNodeModel) {
3740
                    try {
3754
                    try {
3741
                        Boolean selected = ((CheckNodeModel) models [i]).isSelected(node);
3755
                        Boolean selected = ((CheckNodeModel) models[i]).isSelected(node);
3742
                        return selected;
3756
                        return selected;
3743
                    } catch (UnknownTypeException e) {
3757
                    } catch (UnknownTypeException e) {
3744
                        uex = e;
3758
                        uex = e;
Lines 3752-3758 Link Here
3752
            if (uex != null) {
3766
            if (uex != null) {
3753
                throw uex;
3767
                throw uex;
3754
            } else {
3768
            } else {
3755
                throw new UnknownTypeException (node);
3769
                throw new UnknownTypeException(node);
3756
            }
3770
            }
3757
        }
3771
        }
3758
3772
Lines 3764-3771 Link Here
3764
            for (i = 0; i < k; i++) {
3778
            for (i = 0; i < k; i++) {
3765
                if (models[i] instanceof CheckNodeModel) {
3779
                if (models[i] instanceof CheckNodeModel) {
3766
                    try {
3780
                    try {
3767
                        ((CheckNodeModel) models [i]).setSelected (node, selected);
3781
                        ((CheckNodeModel) models[i]).setSelected(node, selected);
3768
                        return ;
3782
                        return;
3769
                    } catch (UnknownTypeException e) {
3783
                    } catch (UnknownTypeException e) {
3770
                        uex = e;
3784
                        uex = e;
3771
                    }
3785
                    }
Lines 3773-3828 Link Here
3773
                }
3787
                }
3774
            }
3788
            }
3775
            if (!isChecked) {
3789
            if (!isChecked) {
3776
                Exceptions.printStackTrace(new IllegalStateException("Can not set selected state to model "+this));
3790
                Exceptions.printStackTrace(new IllegalStateException("Can not set selected state to model " + this));
3777
                return ;
3791
                return;
3778
            }
3792
            }
3779
            if (uex != null) {
3793
            if (uex != null) {
3780
                throw uex;
3794
                throw uex;
3781
            } else {
3795
            } else {
3782
                throw new UnknownTypeException (node);
3796
                throw new UnknownTypeException(node);
3783
            }
3797
            }
3784
        }
3798
        }
3785
3799
3800
        @Override
3801
        public void setSelected(Object... nodes) throws UnknownTypeException {
3802
            UnknownTypeException uex = null;
3803
            int i, k = models.length;
3804
            boolean isChecked = false;
3805
            for (i = 0; i < k; i++) {
3806
                if (models[i] instanceof CheckNodeModel) {
3807
                    try {
3808
                        ((CheckNodeModel) models[i]).setSelected(nodes);
3809
                        return;
3810
                    } catch (UnknownTypeException e) {
3811
                        uex = e;
3812
                    }
3813
                    isChecked = true;
3814
                }
3815
            }
3816
            if (!isChecked) {
3817
                Exceptions.printStackTrace(new IllegalStateException("Can not set selected state to model " + this));
3818
                return;
3819
            }
3820
            if (uex != null) {
3821
                throw uex;
3822
            } else {
3823
                throw new UnknownTypeException(nodes);
3824
            }
3825
        }
3826
3827
        @Override
3828
        public void setUnselected(Object... nodes) throws UnknownTypeException {
3829
            UnknownTypeException uex = null;
3830
            int i, k = models.length;
3831
            boolean isChecked = false;
3832
            for (i = 0; i < k; i++) {
3833
                if (models[i] instanceof CheckNodeModel) {
3834
                    try {
3835
                        ((CheckNodeModel) models[i]).setUnselected(nodes);
3836
                        return;
3837
                    } catch (UnknownTypeException e) {
3838
                        uex = e;
3839
                    }
3840
                    isChecked = true;
3841
                }
3842
            }
3843
            if (!isChecked) {
3844
                Exceptions.printStackTrace(new IllegalStateException("Can not set selected state to model " + this));
3845
                return;
3846
            }
3847
            if (uex != null) {
3848
                throw uex;
3849
            } else {
3850
                throw new UnknownTypeException(nodes);
3851
            }
3852
        }
3786
    }
3853
    }
3787
3854
3788
    /**
3855
    /**
3789
     * Empty implementation of {@link org.netbeans.spi.viewmodel.TreeModel}.
3856
     * Empty implementation of {@link org.netbeans.spi.viewmodel.TreeModel}.
3790
     *
3857
     *
3791
     * @author   Jan Jancura
3858
     * @author Jan Jancura
3792
     */
3859
     */
3793
    private static final class EmptyTreeModel implements TreeModel {
3860
    private static final class EmptyTreeModel implements TreeModel {
3794
3861
3795
        /** 
3862
        /**
3796
         * Returns {@link org.netbeans.spi.viewmodel.TreeModel#ROOT}.
3863
         * Returns {@link org.netbeans.spi.viewmodel.TreeModel#ROOT}.
3797
         *
3864
         *
3798
         * @return {@link org.netbeans.spi.viewmodel.TreeModel#ROOT}
3865
         * @return {@link org.netbeans.spi.viewmodel.TreeModel#ROOT}
3799
         */
3866
         */
3800
        @Override
3867
        @Override
3801
        public Object getRoot () {
3868
        public Object getRoot() {
3802
            return ROOT;
3869
            return ROOT;
3803
        }
3870
        }
3804
3871
3805
        /** 
3872
        /**
3806
         * Returns empty array.
3873
         * Returns empty array.
3807
         *
3874
         *
3808
         * @return empty array
3875
         * @return empty array
3809
         */
3876
         */
3810
        @Override
3877
        @Override
3811
        public Object[] getChildren (Object parent, int from, int to) {
3878
        public Object[] getChildren(Object parent, int from, int to) {
3812
            return new Object [0];
3879
            return new Object[0];
3813
        }
3880
        }
3814
    
3881
3815
        /**
3882
        /**
3816
         * Returns number of children for given node.
3883
         * Returns number of children for given node.
3817
         * 
3818
         * @param   node the parent node
3819
         * @throws  UnknownTypeException if this TreeModel implementation is not
3820
         *          able to resolve children for given node type
3821
         *
3884
         *
3822
         * @return  true if node is leaf
3885
         * @param node the parent node
3886
         * @throws UnknownTypeException if this TreeModel implementation is not
3887
         * able to resolve children for given node type
3888
         *
3889
         * @return true if node is leaf
3823
         */
3890
         */
3824
        @Override
3891
        @Override
3825
        public int getChildrenCount (Object node) {
3892
        public int getChildrenCount(Object node) {
3826
            return 0;
3893
            return 0;
3827
        }
3894
        }
3828
3895
Lines 3832-4134 Link Here
3832
         * @return false
3899
         * @return false
3833
         */
3900
         */
3834
        @Override
3901
        @Override
3835
        public boolean isLeaf (Object node) {
3902
        public boolean isLeaf(Object node) {
3836
            return false;
3903
            return false;
3837
        }
3904
        }
3838
3905
3839
        /** 
3906
        /**
3840
         * Do nothing.
3907
         * Do nothing.
3841
         *
3908
         *
3842
         * @param l the listener to be added
3909
         * @param l the listener to be added
3843
         */
3910
         */
3844
        @Override
3911
        @Override
3845
        public void addModelListener (ModelListener l) {
3912
        public void addModelListener(ModelListener l) {
3846
        }
3913
        }
3847
3914
3848
        /** 
3915
        /**
3849
         * Do nothing.
3916
         * Do nothing.
3850
         *
3917
         *
3851
         * @param l the listener to be removed
3918
         * @param l the listener to be removed
3852
         */
3919
         */
3853
        @Override
3920
        @Override
3854
        public void removeModelListener (ModelListener l) {
3921
        public void removeModelListener(ModelListener l) {
3855
        }
3922
        }
3856
    }
3923
    }
3857
3924
3858
    /**
3925
    /**
3859
     * Empty implementation of {@link org.netbeans.spi.viewmodel.NodeModel}.
3926
     * Empty implementation of {@link org.netbeans.spi.viewmodel.NodeModel}.
3860
     *
3927
     *
3861
     * @author   Jan Jancura
3928
     * @author Jan Jancura
3862
     */
3929
     */
3863
    private static final class EmptyNodeModel implements NodeModel {
3930
    private static final class EmptyNodeModel implements NodeModel {
3864
3931
3865
        /**
3932
        /**
3866
         * Returns display name for given node.
3933
         * Returns display name for given node.
3867
         *
3934
         *
3868
         * @throws  UnknownTypeException if this NodeModel implementation is not
3935
         * @throws UnknownTypeException if this NodeModel implementation is not
3869
         *          able to resolve display name for given node type
3936
         * able to resolve display name for given node type
3870
         * @return  display name for given node
3937
         * @return display name for given node
3871
         */
3938
         */
3872
        @Override
3939
        @Override
3873
        public String getDisplayName (Object node) 
3940
        public String getDisplayName(Object node)
3874
        throws UnknownTypeException {
3941
                throws UnknownTypeException {
3875
            throw new UnknownTypeException (node);
3942
            throw new UnknownTypeException(node);
3876
        }
3943
        }
3877
3944
3878
        /**
3945
        /**
3879
         * Returns icon for given node.
3946
         * Returns icon for given node.
3880
         *
3947
         *
3881
         * @throws  UnknownTypeException if this NodeModel implementation is not
3948
         * @throws UnknownTypeException if this NodeModel implementation is not
3882
         *          able to resolve icon for given node type
3949
         * able to resolve icon for given node type
3883
         * @return  icon for given node
3950
         * @return icon for given node
3884
         */
3951
         */
3885
        @Override
3952
        @Override
3886
        public String getIconBase (Object node) 
3953
        public String getIconBase(Object node)
3887
        throws UnknownTypeException {
3954
                throws UnknownTypeException {
3888
            throw new UnknownTypeException (node);
3955
            throw new UnknownTypeException(node);
3889
        }
3956
        }
3890
3957
3891
        /**
3958
        /**
3892
         * Returns tool tip for given node.
3959
         * Returns tool tip for given node.
3893
         *
3960
         *
3894
         * @throws  UnknownTypeException if this NodeModel implementation is not
3961
         * @throws UnknownTypeException if this NodeModel implementation is not
3895
         *          able to resolve tool tip for given node type
3962
         * able to resolve tool tip for given node type
3896
         * @return  tool tip for given node
3963
         * @return tool tip for given node
3897
         */
3964
         */
3898
        @Override
3965
        @Override
3899
        public String getShortDescription (Object node) 
3966
        public String getShortDescription(Object node)
3900
        throws UnknownTypeException {
3967
                throws UnknownTypeException {
3901
            throw new UnknownTypeException (node);
3968
            throw new UnknownTypeException(node);
3902
        }
3969
        }
3903
3970
3904
        /** 
3971
        /**
3905
         * Do nothing.
3972
         * Do nothing.
3906
         *
3973
         *
3907
         * @param l the listener to be added
3974
         * @param l the listener to be added
3908
         */
3975
         */
3909
        @Override
3976
        @Override
3910
        public void addModelListener (ModelListener l) {
3977
        public void addModelListener(ModelListener l) {
3911
        }
3978
        }
3912
3979
3913
        /** 
3980
        /**
3914
         * Do nothing.
3981
         * Do nothing.
3915
         *
3982
         *
3916
         * @param l the listener to be removed
3983
         * @param l the listener to be removed
3917
         */
3984
         */
3918
        @Override
3985
        @Override
3919
        public void removeModelListener (ModelListener l) {
3986
        public void removeModelListener(ModelListener l) {
3920
        }
3987
        }
3921
    }
3988
    }
3922
3989
3923
    /**
3990
    /**
3924
     * Empty implemntation of {@link org.netbeans.spi.viewmodel.TableModel}.
3991
     * Empty implemntation of {@link org.netbeans.spi.viewmodel.TableModel}.
3925
     *
3992
     *
3926
     * @author   Jan Jancura
3993
     * @author Jan Jancura
3927
     */
3994
     */
3928
    private static final class EmptyTableModel implements TableModel {
3995
    private static final class EmptyTableModel implements TableModel {
3929
 
3996
3930
        /**
3997
        /**
3931
         * Returns value to be displayed in column <code>columnID</code>
3998
         * Returns value to be displayed in column <code>columnID</code> and row
3932
         * and row identified by <code>node</code>. Column ID is defined in by 
3999
         * identified by <code>node</code>. Column ID is defined in by
3933
         * {@link ColumnModel#getID}, and rows are defined by values returned from 
4000
         * {@link ColumnModel#getID}, and rows are defined by values returned
3934
         * {@link org.netbeans.spi.viewmodel.TreeModel#getChildren}.
4001
         * from {@link org.netbeans.spi.viewmodel.TreeModel#getChildren}.
3935
         *
4002
         *
3936
         * @param node a object returned from 
4003
         * @param node a object returned from
3937
         *         {@link org.netbeans.spi.viewmodel.TreeModel#getChildren} for this row
4004
         * {@link org.netbeans.spi.viewmodel.TreeModel#getChildren} for this
4005
         * row
3938
         * @param columnID a id of column defined by {@link ColumnModel#getID}
4006
         * @param columnID a id of column defined by {@link ColumnModel#getID}
3939
         * @throws UnknownTypeException if there is no TableModel defined for given
4007
         * @throws UnknownTypeException if there is no TableModel defined for
3940
         *         parameter type
4008
         * given parameter type
3941
         *
4009
         *
3942
         * @return value of variable representing given position in tree table.
4010
         * @return value of variable representing given position in tree table.
3943
         */
4011
         */
3944
        @Override
4012
        @Override
3945
        public Object getValueAt (Object node, String columnID) throws 
4013
        public Object getValueAt(Object node, String columnID) throws
3946
        UnknownTypeException {
4014
                UnknownTypeException {
3947
            throw new UnknownTypeException (node);
4015
            throw new UnknownTypeException(node);
3948
        }
4016
        }
3949
4017
3950
        /**
4018
        /**
3951
         * Returns true if value displayed in column <code>columnID</code>
4019
         * Returns true if value displayed in column <code>columnID</code> and
3952
         * and row <code>node</code> is read only. Column ID is defined in by 
4020
         * row <code>node</code> is read only. Column ID is defined in by
3953
         * {@link ColumnModel#getID}, and rows are defined by values returned from 
4021
         * {@link ColumnModel#getID}, and rows are defined by values returned
3954
         * {@link TreeModel#getChildren}.
4022
         * from {@link TreeModel#getChildren}.
3955
         *
4023
         *
3956
         * @param node a object returned from {@link TreeModel#getChildren} for this row
4024
         * @param node a object returned from {@link TreeModel#getChildren} for
4025
         * this row
3957
         * @param columnID a id of column defined by {@link ColumnModel#getID}
4026
         * @param columnID a id of column defined by {@link ColumnModel#getID}
3958
         * @throws UnknownTypeException if there is no TableModel defined for given
4027
         * @throws UnknownTypeException if there is no TableModel defined for
3959
         *         parameter type
4028
         * given parameter type
3960
         *
4029
         *
3961
         * @return true if variable on given position is read only
4030
         * @return true if variable on given position is read only
3962
         */
4031
         */
3963
        @Override
4032
        @Override
3964
        public boolean isReadOnly (Object node, String columnID) throws 
4033
        public boolean isReadOnly(Object node, String columnID) throws
3965
        UnknownTypeException {
4034
                UnknownTypeException {
3966
            throw new UnknownTypeException (node);
4035
            throw new UnknownTypeException(node);
3967
        }
4036
        }
3968
4037
3969
        /**
4038
        /**
3970
         * Changes a value displayed in column <code>columnID</code>
4039
         * Changes a value displayed in column <code>columnID</code> and row
3971
         * and row <code>node</code>. Column ID is defined in by 
4040
         * <code>node</code>. Column ID is defined in by
3972
         * {@link ColumnModel#getID}, and rows are defined by values returned from 
4041
         * {@link ColumnModel#getID}, and rows are defined by values returned
3973
         * {@link TreeModel#getChildren}.
4042
         * from {@link TreeModel#getChildren}.
3974
         *
4043
         *
3975
         * @param node a object returned from {@link TreeModel#getChildren} for this row
4044
         * @param node a object returned from {@link TreeModel#getChildren} for
4045
         * this row
3976
         * @param columnID a id of column defined by {@link ColumnModel#getID}
4046
         * @param columnID a id of column defined by {@link ColumnModel#getID}
3977
         * @param value a new value of variable on given position
4047
         * @param value a new value of variable on given position
3978
         * @throws UnknownTypeException if there is no TableModel defined for given
4048
         * @throws UnknownTypeException if there is no TableModel defined for
3979
         *         parameter type
4049
         * given parameter type
3980
         */
4050
         */
3981
        @Override
4051
        @Override
3982
        public void setValueAt (Object node, String columnID, Object value) 
4052
        public void setValueAt(Object node, String columnID, Object value)
3983
        throws UnknownTypeException {
4053
                throws UnknownTypeException {
3984
            throw new UnknownTypeException (node);
4054
            throw new UnknownTypeException(node);
3985
        }
4055
        }
3986
        
4056
3987
        /** 
4057
        /**
3988
         * Do nothing.
4058
         * Do nothing.
3989
         *
4059
         *
3990
         * @param l the listener to be added
4060
         * @param l the listener to be added
3991
         */
4061
         */
3992
        @Override
4062
        @Override
3993
        public void addModelListener (ModelListener l) {
4063
        public void addModelListener(ModelListener l) {
3994
        }
4064
        }
3995
4065
3996
        /** 
4066
        /**
3997
         * Do nothing.
4067
         * Do nothing.
3998
         *
4068
         *
3999
         * @param l the listener to be removed
4069
         * @param l the listener to be removed
4000
         */
4070
         */
4001
        @Override
4071
        @Override
4002
        public void removeModelListener (ModelListener l) {
4072
        public void removeModelListener(ModelListener l) {
4003
        }
4073
        }
4004
    }
4074
    }
4005
4075
4006
    /**
4076
    /**
4007
     * Empty implementation of {@link org.netbeans.spi.viewmodel.TableModel}.
4077
     * Empty implementation of {@link org.netbeans.spi.viewmodel.TableModel}.
4008
     *
4078
     *
4009
     * @author   Jan Jancura
4079
     * @author Jan Jancura
4010
     */
4080
     */
4011
    private static final class EmptyNodeActionsProvider implements 
4081
    private static final class EmptyNodeActionsProvider implements
4012
    NodeActionsProvider {
4082
            NodeActionsProvider {
4013
    
4083
4014
        /**
4084
        /**
4015
         * Performs default action for given node.
4085
         * Performs default action for given node.
4016
         *
4086
         *
4017
         * @throws  UnknownTypeException if this NodeActionsProvider implementation 
4087
         * @throws UnknownTypeException if this NodeActionsProvider
4018
         *          is not able to resolve actions for given node type
4088
         * implementation is not able to resolve actions for given node type
4019
         * @return  display name for given node
4089
         * @return display name for given node
4020
         */
4090
         */
4021
        @Override
4091
        @Override
4022
        public void performDefaultAction (Object node) 
4092
        public void performDefaultAction(Object node)
4023
        throws UnknownTypeException {
4093
                throws UnknownTypeException {
4024
            throw new UnknownTypeException (node);
4094
            throw new UnknownTypeException(node);
4025
        }
4095
        }
4026
4096
4027
        /**
4097
        /**
4028
         * Returns set of actions for given node.
4098
         * Returns set of actions for given node.
4029
         *
4099
         *
4030
         * @throws  UnknownTypeException if this NodeActionsProvider implementation 
4100
         * @throws UnknownTypeException if this NodeActionsProvider
4031
         *          is not able to resolve actions for given node type
4101
         * implementation is not able to resolve actions for given node type
4032
         * @return  display name for given node
4102
         * @return display name for given node
4033
         */
4103
         */
4034
        @Override
4104
        @Override
4035
        public Action[] getActions (Object node) 
4105
        public Action[] getActions(Object node)
4036
        throws UnknownTypeException {
4106
                throws UnknownTypeException {
4037
            throw new UnknownTypeException (node);
4107
            throw new UnknownTypeException(node);
4038
        }
4108
        }
4039
    }
4109
    }
4040
    
4110
4041
    /**
4111
    /**
4042
     * Creates one {@link org.netbeans.spi.viewmodel.NodeActionsProvider}
4112
     * Creates one {@link org.netbeans.spi.viewmodel.NodeActionsProvider} from
4043
     * from given list of NodeActionsProviders. DelegatingNodeActionsProvider asks all 
4113
     * given list of NodeActionsProviders. DelegatingNodeActionsProvider asks
4044
     * underlaying models for each concrete parameter, and returns first 
4114
     * all underlaying models for each concrete parameter, and returns first
4045
     * returned value.
4115
     * returned value.
4046
     *
4116
     *
4047
     * @author   Jan Jancura
4117
     * @author Jan Jancura
4048
     */
4118
     */
4049
    static final class DelegatingNodeActionsProvider implements NodeActionsProvider {
4119
    static final class DelegatingNodeActionsProvider implements NodeActionsProvider {
4050
4120
4051
        private NodeActionsProvider[] models;
4121
        private NodeActionsProvider[] models;
4052
        private HashMap<String, NodeActionsProvider> classNameToModel = new HashMap<String, NodeActionsProvider>();
4122
        private HashMap<String, NodeActionsProvider> classNameToModel = new HashMap<String, NodeActionsProvider>();
4053
4123
4054
4055
        /**
4124
        /**
4056
         * Creates new instance of DelegatingNodeActionsProvider for given list of 
4125
         * Creates new instance of DelegatingNodeActionsProvider for given list
4057
         * NodeActionsProvider.
4126
         * of NodeActionsProvider.
4058
         *
4127
         *
4059
         * @param models a list of NodeActionsProvider
4128
         * @param models a list of NodeActionsProvider
4060
         */
4129
         */
4061
        public DelegatingNodeActionsProvider (
4130
        public DelegatingNodeActionsProvider(
4062
            List<NodeActionsProvider> models
4131
                List<NodeActionsProvider> models
4063
        ) {
4132
        ) {
4064
            this (convert (models));
4133
            this(convert(models));
4065
        }
4134
        }
4066
4135
4067
        private static NodeActionsProvider[] convert (List<NodeActionsProvider> l) {
4136
        private static NodeActionsProvider[] convert(List<NodeActionsProvider> l) {
4068
            NodeActionsProvider[] models = new NodeActionsProvider [l.size ()];
4137
            NodeActionsProvider[] models = new NodeActionsProvider[l.size()];
4069
            return l.toArray (models);
4138
            return l.toArray(models);
4070
        }
4139
        }
4071
4140
4072
        /**
4141
        /**
4073
         * Creates new instance of DelegatingNodeActionsProvider for given array of 
4142
         * Creates new instance of DelegatingNodeActionsProvider for given array
4074
         * NodeActionsProvider.
4143
         * of NodeActionsProvider.
4075
         *
4144
         *
4076
         * @param models a array of NodeActionsProvider
4145
         * @param models a array of NodeActionsProvider
4077
         */
4146
         */
4078
        public DelegatingNodeActionsProvider (NodeActionsProvider[] models) {
4147
        public DelegatingNodeActionsProvider(NodeActionsProvider[] models) {
4079
            this.models = models;
4148
            this.models = models;
4080
        }
4149
        }
4081
4150
4082
        /**
4151
        /**
4083
         * Returns set of actions for given node.
4152
         * Returns set of actions for given node.
4084
         *
4153
         *
4085
         * @throws  UnknownTypeException if this NodeActionsProvider implementation 
4154
         * @throws UnknownTypeException if this NodeActionsProvider
4086
         *          is not able to resolve actions for given node type
4155
         * implementation is not able to resolve actions for given node type
4087
         * @return  display name for given node
4156
         * @return display name for given node
4088
         */
4157
         */
4089
        @Override
4158
        @Override
4090
        public Action[] getActions (Object node) 
4159
        public Action[] getActions(Object node)
4091
        throws UnknownTypeException {
4160
                throws UnknownTypeException {
4092
            NodeActionsProvider model = classNameToModel.get (
4161
            NodeActionsProvider model = classNameToModel.get(
4093
                node.getClass ().getName ()
4162
                    node.getClass().getName()
4094
            );
4163
            );
4095
            if (model != null) {
4164
            if (model != null) {
4096
                try {
4165
                try {
4097
                    return model.getActions (node);
4166
                    return model.getActions(node);
4098
                } catch (UnknownTypeException e) {
4167
                } catch (UnknownTypeException e) {
4099
                }
4168
                }
4100
            }
4169
            }
4101
            int i, k = models.length;
4170
            int i, k = models.length;
4102
            for (i = 0; i < k; i++) {
4171
            for (i = 0; i < k; i++) {
4103
                try {
4172
                try {
4104
                    Action[] dn = models [i].getActions (node);
4173
                    Action[] dn = models[i].getActions(node);
4105
                    classNameToModel.put (node.getClass ().getName (), models [i]);
4174
                    classNameToModel.put(node.getClass().getName(), models[i]);
4106
                    return dn;
4175
                    return dn;
4107
                } catch (UnknownTypeException e) {
4176
                } catch (UnknownTypeException e) {
4108
                }
4177
                }
4109
            }
4178
            }
4110
            if (k == 0) {
4179
            if (k == 0) {
4111
                return new Action[] {};
4180
                return new Action[]{};
4112
            } else {
4181
            } else {
4113
                throw new UnknownTypeException (node);
4182
                throw new UnknownTypeException(node);
4114
            }
4183
            }
4115
        }
4184
        }
4116
4185
4117
        /**
4186
        /**
4118
         * Performs default action for given node.
4187
         * Performs default action for given node.
4119
         *
4188
         *
4120
         * @throws  UnknownTypeException if this NodeActionsProvider implementation 
4189
         * @throws UnknownTypeException if this NodeActionsProvider
4121
         *          is not able to resolve actions for given node type
4190
         * implementation is not able to resolve actions for given node type
4122
         * @return  display name for given node
4191
         * @return display name for given node
4123
         */
4192
         */
4124
        @Override
4193
        @Override
4125
        public void performDefaultAction (Object node) throws UnknownTypeException {
4194
        public void performDefaultAction(Object node) throws UnknownTypeException {
4126
            NodeActionsProvider model = classNameToModel.get (
4195
            NodeActionsProvider model = classNameToModel.get(
4127
                node.getClass ().getName ()
4196
                    node.getClass().getName()
4128
            );
4197
            );
4129
            if (model != null) {
4198
            if (model != null) {
4130
                try {
4199
                try {
4131
                    model.performDefaultAction (node);
4200
                    model.performDefaultAction(node);
4132
                    return;
4201
                    return;
4133
                } catch (UnknownTypeException e) {
4202
                } catch (UnknownTypeException e) {
4134
                }
4203
                }
Lines 4136-4213 Link Here
4136
            int i, k = models.length;
4205
            int i, k = models.length;
4137
            for (i = 0; i < k; i++) {
4206
            for (i = 0; i < k; i++) {
4138
                try {
4207
                try {
4139
                    models [i].performDefaultAction (node);
4208
                    models[i].performDefaultAction(node);
4140
                    classNameToModel.put (node.getClass ().getName (), models [i]);
4209
                    classNameToModel.put(node.getClass().getName(), models[i]);
4141
                    return;
4210
                    return;
4142
                } catch (UnknownTypeException e) {
4211
                } catch (UnknownTypeException e) {
4143
                }
4212
                }
4144
            }
4213
            }
4145
            throw new UnknownTypeException (node);
4214
            throw new UnknownTypeException(node);
4146
        }
4215
        }
4147
4216
4148
        @Override
4217
        @Override
4149
        public String toString () {
4218
        public String toString() {
4150
            return super.toString () + "\n" + toString ("    ");
4219
            return super.toString() + "\n" + toString("    ");
4151
        }
4220
        }
4152
        
4221
4153
        public String toString (String n) {
4222
        public String toString(String n) {
4154
            int i, k = models.length - 1;
4223
            int i, k = models.length - 1;
4155
            if (k == -1) {
4224
            if (k == -1) {
4156
                return "";
4225
                return "";
4157
            }
4226
            }
4158
            StringBuffer sb = new StringBuffer ();
4227
            StringBuffer sb = new StringBuffer();
4159
            for (i = 0; i < k; i++) {
4228
            for (i = 0; i < k; i++) {
4160
                sb.append (n);
4229
                sb.append(n);
4161
                sb.append (models [i]);
4230
                sb.append(models[i]);
4162
                sb.append ('\n');
4231
                sb.append('\n');
4163
            }
4232
            }
4164
            sb.append (n);
4233
            sb.append(n);
4165
            sb.append (models [i]);
4234
            sb.append(models[i]);
4166
            return new String (sb);
4235
            return new String(sb);
4167
        }
4236
        }
4168
    }
4237
    }
4169
    
4238
4170
    /**
4239
    /**
4171
     * Tree expansion control.
4240
     * Tree expansion control.
4241
     *
4172
     * @since 1.15
4242
     * @since 1.15
4173
     */
4243
     */
4174
    public static abstract class TreeFeatures {
4244
    public static abstract class TreeFeatures {
4175
        
4245
4176
        /**
4246
        /**
4177
         * Returns <code>true</code> if given node is expanded.
4247
         * Returns <code>true</code> if given node is expanded.
4178
         *
4248
         *
4179
         * @param node a node to be checked
4249
         * @param node a node to be checked
4180
         * @return <code>true</code> if given node is expanded
4250
         * @return <code>true</code> if given node is expanded
4181
         */
4251
         */
4182
        public abstract boolean isExpanded (Object node);
4252
        public abstract boolean isExpanded(Object node);
4183
        
4253
4184
        /**
4254
        /**
4185
         * Expands given list of nodes.
4255
         * Expands given list of nodes.
4186
         *
4256
         *
4187
         * @param node a list of nodes to be expanded
4257
         * @param node a list of nodes to be expanded
4188
         */
4258
         */
4189
        public abstract void expandNode (Object node);
4259
        public abstract void expandNode(Object node);
4190
        
4260
4191
        /**
4261
        /**
4192
         * Collapses given node.
4262
         * Collapses given node.
4193
         *
4263
         *
4194
         * @param node a node to be expanded
4264
         * @param node a node to be expanded
4195
         */
4265
         */
4196
        public abstract void collapseNode (Object node);
4266
        public abstract void collapseNode(Object node);
4197
        
4267
4198
    }
4268
    }
4199
    
4269
4200
    /**
4270
    /**
4201
     * Implements set of tree view features.
4271
     * Implements set of tree view features.
4202
     */
4272
     */
4203
    private static final class DefaultTreeFeatures extends TreeFeatures {
4273
    private static final class DefaultTreeFeatures extends TreeFeatures {
4204
        
4274
4205
        private JComponent view;
4275
        private JComponent view;
4206
        
4276
4207
        private DefaultTreeFeatures (JComponent view) {
4277
        private DefaultTreeFeatures(JComponent view) {
4208
            this.view = view;
4278
            this.view = view;
4209
        }
4279
        }
4210
        
4280
4211
        /**
4281
        /**
4212
         * Returns <code>true</code> if given node is expanded.
4282
         * Returns <code>true</code> if given node is expanded.
4213
         *
4283
         *
Lines 4215-4224 Link Here
4215
         * @return <code>true</code> if given node is expanded
4285
         * @return <code>true</code> if given node is expanded
4216
         */
4286
         */
4217
        @Override
4287
        @Override
4218
        public boolean isExpanded (
4288
        public boolean isExpanded(
4219
            Object node
4289
                Object node
4220
        ) {
4290
        ) {
4221
            return ((OutlineTable) view).isExpanded (node);
4291
            return ((OutlineTable) view).isExpanded(node);
4222
        }
4292
        }
4223
4293
4224
        /**
4294
        /**
Lines 4227-4236 Link Here
4227
         * @param node a list of nodes to be expanded
4297
         * @param node a list of nodes to be expanded
4228
         */
4298
         */
4229
        @Override
4299
        @Override
4230
        public void expandNode (
4300
        public void expandNode(
4231
            Object node
4301
                Object node
4232
        ) {
4302
        ) {
4233
            ((OutlineTable) view).expandNode (node);
4303
            ((OutlineTable) view).expandNode(node);
4234
        }
4304
        }
4235
4305
4236
        /**
4306
        /**
Lines 4239-4248 Link Here
4239
         * @param node a node to be expanded
4309
         * @param node a node to be expanded
4240
         */
4310
         */
4241
        @Override
4311
        @Override
4242
        public void collapseNode (
4312
        public void collapseNode(
4243
            Object node
4313
                Object node
4244
        ) {
4314
        ) {
4245
            ((OutlineTable) view).collapseNode (node);
4315
            ((OutlineTable) view).collapseNode(node);
4246
        }
4316
        }
4247
    }
4317
    }
4248
4318
Lines 4250-4292 Link Here
4250
     * This model encapsulates all currently supported models.
4320
     * This model encapsulates all currently supported models.
4251
     *
4321
     *
4252
     * @see Models#createCompoundModel
4322
     * @see Models#createCompoundModel
4253
     * @author   Jan Jancura
4323
     * @author Jan Jancura
4254
     */
4324
     */
4255
    public static final class CompoundModel implements ReorderableTreeModel,
4325
    public static final class CompoundModel implements ReorderableTreeModel,
4256
                                                       ExtendedNodeModel,
4326
            ExtendedNodeModel,
4257
                                                       CheckNodeModel,
4327
            CheckNodeModel,
4258
                                                       DnDNodeModel,
4328
            DnDNodeModel,
4259
                                                       NodeActionsProvider,
4329
            NodeActionsProvider,
4260
                                                       TableHTMLModel,
4330
            TableHTMLModel,
4261
                                                       TreeExpansionModel,
4331
            TreeExpansionModel,
4262
                                                       TableRendererModel,
4332
            TableRendererModel,
4263
                                                       TablePropertyEditorsModel {
4333
            TablePropertyEditorsModel,
4334
            IconNodeModel,
4335
            LookupNodeModel {
4264
4336
4265
        private ReorderableTreeModel treeModel;
4337
        private ReorderableTreeModel treeModel;
4266
        private ExtendedNodeModel nodeModel;
4338
        private ExtendedNodeModel nodeModel;
4267
        private CheckNodeModel cnodeModel;
4339
        private CheckNodeModel cnodeModel;
4268
        private DnDNodeModel    dndNodeModel;
4340
        private DnDNodeModel dndNodeModel;
4269
        private NodeActionsProvider nodeActionsProvider;
4341
        private NodeActionsProvider nodeActionsProvider;
4270
        private ColumnModel[]   columnModels;
4342
        private ColumnModel[] columnModels;
4271
        private TableHTMLModel  tableModel;
4343
        private TableHTMLModel tableModel;
4272
        private TableRendererModel tableRendererModel;
4344
        private TableRendererModel tableRendererModel;
4273
        private TablePropertyEditorsModel tablePropertyEditorsModel;
4345
        private TablePropertyEditorsModel tablePropertyEditorsModel;
4274
        private TreeExpansionModel treeExpansionModel;
4346
        private TreeExpansionModel treeExpansionModel;
4275
        private AsynchronousModel asynchModel;
4347
        private AsynchronousModel asynchModel;
4348
        private IconNodeModel iconNodeModel;
4349
        private LookupNodeModel lookupNodeModel;
4276
4350
4277
        private CompoundModel   mainSubModel;
4351
        private CompoundModel mainSubModel;
4278
        private CompoundModel[] subModels;
4352
        private CompoundModel[] subModels;
4279
        private TreeModelFilter subModelsFilter;
4353
        private TreeModelFilter subModelsFilter;
4280
        private MessageFormat treeNodeDisplayFormat;
4354
        private MessageFormat treeNodeDisplayFormat;
4281
        
4355
4282
        // <RAVE>
4356
        // <RAVE>
4283
        // New field, setter/getter for propertiesHelpID, which is used
4357
        // New field, setter/getter for propertiesHelpID, which is used
4284
        // for property sheet help
4358
        // for property sheet help
4285
        private String propertiesHelpID = null;
4359
        private String propertiesHelpID = null;
4286
        // </RAVE>
4360
        // </RAVE>
4287
        
4288
        // init ....................................................................
4289
4361
4362
        // init ....................................................................
4290
        /**
4363
        /**
4291
         * Creates a new instance of {@link CompoundModel} for given models.
4364
         * Creates a new instance of {@link CompoundModel} for given models.
4292
         *
4365
         *
Lines 4295-4316 Link Here
4295
         * @param nodeActionsProvider a node actions provider to delegate on
4368
         * @param nodeActionsProvider a node actions provider to delegate on
4296
         * @param nodeActionsProvider a columns model to delegate on
4369
         * @param nodeActionsProvider a columns model to delegate on
4297
         */
4370
         */
4298
        private CompoundModel (
4371
        private CompoundModel(
4299
            ReorderableTreeModel treeModel,
4372
                ReorderableTreeModel treeModel,
4300
            TreeExpansionModel treeExpansionModel,
4373
                TreeExpansionModel treeExpansionModel,
4301
            ExtendedNodeModel nodeModel, 
4374
                ExtendedNodeModel nodeModel,
4302
            NodeActionsProvider nodeActionsProvider,
4375
                NodeActionsProvider nodeActionsProvider,
4303
            List<ColumnModel> columnModels,
4376
                List<ColumnModel> columnModels,
4304
            TableHTMLModel tableModel,
4377
                TableHTMLModel tableModel,
4305
            AsynchronousModel asynchModel,
4378
                AsynchronousModel asynchModel,
4306
            TableRendererModel tableRendererModel,
4379
                TableRendererModel tableRendererModel,
4307
            TablePropertyEditorsModel tablePropertyEditorsModel,
4380
                TablePropertyEditorsModel tablePropertyEditorsModel,
4308
            String propertiesHelpID
4381
                IconNodeModel iconNodeModel,
4382
                LookupNodeModel lookupNodeModel,
4383
                String propertiesHelpID
4309
        ) {
4384
        ) {
4310
            if (treeModel == null || nodeModel == null || tableModel == null ||
4385
            if (treeModel == null || nodeModel == null || tableModel == null
4311
                nodeActionsProvider == null) {
4386
                    || nodeActionsProvider == null) {
4312
                
4387
4313
                throw new NullPointerException ();
4388
                throw new NullPointerException();
4314
            }
4389
            }
4315
            /*if (columnModels == null && tableModel == null && tableRendererModel == null) {
4390
            /*if (columnModels == null && tableModel == null && tableRendererModel == null) {
4316
                isTree = true;
4391
                isTree = true;
Lines 4331-4357 Link Here
4331
            this.tableRendererModel = tableRendererModel;
4406
            this.tableRendererModel = tableRendererModel;
4332
            this.tablePropertyEditorsModel = tablePropertyEditorsModel;
4407
            this.tablePropertyEditorsModel = tablePropertyEditorsModel;
4333
            this.nodeActionsProvider = nodeActionsProvider;
4408
            this.nodeActionsProvider = nodeActionsProvider;
4334
            this.columnModels = columnModels.toArray (
4409
            this.columnModels = columnModels.toArray(
4335
                new ColumnModel [columnModels.size ()]
4410
                    new ColumnModel[columnModels.size()]
4336
            );
4411
            );
4337
            this.asynchModel = asynchModel;
4412
            this.asynchModel = asynchModel;
4413
            this.iconNodeModel = iconNodeModel;
4414
            this.lookupNodeModel = lookupNodeModel;
4338
            this.propertiesHelpID = propertiesHelpID;
4415
            this.propertiesHelpID = propertiesHelpID;
4339
        }
4416
        }
4340
4417
4341
        private CompoundModel(CompoundModel mainSubModel,
4418
        private CompoundModel(CompoundModel mainSubModel,
4342
                              CompoundModel[] models,
4419
                CompoundModel[] models,
4343
                              TreeModelFilter treeFilter,
4420
                TreeModelFilter treeFilter,
4344
                              String propertiesHelpID) {
4421
                String propertiesHelpID) {
4345
            this.mainSubModel = mainSubModel;
4422
            this.mainSubModel = mainSubModel;
4346
            this.subModels = models;
4423
            this.subModels = models;
4347
            this.subModelsFilter = treeFilter;
4424
            this.subModelsFilter = treeFilter;
4348
            this.propertiesHelpID = propertiesHelpID;
4425
            this.propertiesHelpID = propertiesHelpID;
4349
        }
4426
        }
4350
        
4427
4351
        void setTreeNodeDisplayFormat(MessageFormat treeNodeDisplayFormat) {
4428
        void setTreeNodeDisplayFormat(MessageFormat treeNodeDisplayFormat) {
4352
            this.treeNodeDisplayFormat = treeNodeDisplayFormat;
4429
            this.treeNodeDisplayFormat = treeNodeDisplayFormat;
4353
        }
4430
        }
4354
        
4431
4355
        MessageFormat getTreeNodeDisplayFormat() {
4432
        MessageFormat getTreeNodeDisplayFormat() {
4356
            if (isHyperModel()) {
4433
            if (isHyperModel()) {
4357
                return mainSubModel.getTreeNodeDisplayFormat();
4434
                return mainSubModel.getTreeNodeDisplayFormat();
Lines 4359-4377 Link Here
4359
                return treeNodeDisplayFormat;
4436
                return treeNodeDisplayFormat;
4360
            }
4437
            }
4361
        }
4438
        }
4362
        
4439
4363
        /*boolean isTree() {
4440
        /*boolean isTree() {
4364
            return columnModels == null;
4441
            return columnModels == null;
4365
        }*/
4442
        }*/
4366
4443
4367
        /*CompoundModel[] getSubModels() {
4444
 /*CompoundModel[] getSubModels() {
4368
            return subModels;
4445
            return subModels;
4369
        }
4446
        }
4370
4447
4371
        TreeModelFilter getSubModelsFilter() {
4448
        TreeModelFilter getSubModelsFilter() {
4372
            return subModelsFilter;
4449
            return subModelsFilter;
4373
        }*/
4450
        }*/
4374
4375
        boolean isHyperModel() {
4451
        boolean isHyperModel() {
4376
            return subModels != null;
4452
            return subModels != null;
4377
        }
4453
        }
Lines 4386-4393 Link Here
4386
        // <RAVE>
4462
        // <RAVE>
4387
        /**
4463
        /**
4388
         * Get a help ID for this model.
4464
         * Get a help ID for this model.
4389
         * @return The help ID defined for the properties sheets,
4465
         *
4390
         *         or <code>null</code>.
4466
         * @return The help ID defined for the properties sheets, or
4467
         * <code>null</code>.
4391
         * @since 1.7
4468
         * @since 1.7
4392
         */
4469
         */
4393
        public String getHelpId() {
4470
        public String getHelpId() {
Lines 4396-4425 Link Here
4396
        // </RAVE>
4473
        // </RAVE>
4397
4474
4398
        // TreeModel ...............................................................
4475
        // TreeModel ...............................................................
4399
4476
        /**
4400
        /** 
4401
         * Returns the root node of the tree or null, if the tree is empty.
4477
         * Returns the root node of the tree or null, if the tree is empty.
4402
         *
4478
         *
4403
         * @return the root node of the tree or null
4479
         * @return the root node of the tree or null
4404
         */
4480
         */
4405
        @Override
4481
        @Override
4406
        public Object getRoot () {
4482
        public Object getRoot() {
4407
            return treeModel.getRoot ();
4483
            return treeModel.getRoot();
4408
        }
4484
        }
4409
4485
4410
        /** 
4486
        /**
4411
         * Returns children for given parent on given indexes.
4487
         * Returns children for given parent on given indexes.
4412
         *
4488
         *
4413
         * @param   parent a parent of returned nodes
4489
         * @param parent a parent of returned nodes
4414
         * @throws  UnknownTypeException if this TreeModel implementation is not
4490
         * @throws UnknownTypeException if this TreeModel implementation is not
4415
         *          able to resolve children for given node type
4491
         * able to resolve children for given node type
4416
         *
4492
         *
4417
         * @return  children for given parent on given indexes
4493
         * @return children for given parent on given indexes
4418
         */
4494
         */
4419
        @Override
4495
        @Override
4420
        public Object[] getChildren (Object parent, int from, int to) 
4496
        public Object[] getChildren(Object parent, int from, int to)
4421
        throws UnknownTypeException {
4497
                throws UnknownTypeException {
4422
            Object[] ch = treeModel.getChildren (parent, from, to);
4498
            Object[] ch = treeModel.getChildren(parent, from, to);
4423
            //System.err.println("Children for node '"+parent+"' are '"+java.util.Arrays.asList(ch)+"'");
4499
            //System.err.println("Children for node '"+parent+"' are '"+java.util.Arrays.asList(ch)+"'");
4424
            //System.err.println("Model = "+this);
4500
            //System.err.println("Model = "+this);
4425
            return ch;
4501
            return ch;
Lines 4427-4458 Link Here
4427
4503
4428
        /**
4504
        /**
4429
         * Returns number of children for given node.
4505
         * Returns number of children for given node.
4430
         * 
4431
         * @param   node the parent node
4432
         * @throws  UnknownTypeException if this TreeModel implementation is not
4433
         *          able to resolve children for given node type
4434
         *
4506
         *
4435
         * @return  true if node is leaf
4507
         * @param node the parent node
4508
         * @throws UnknownTypeException if this TreeModel implementation is not
4509
         * able to resolve children for given node type
4510
         *
4511
         * @return true if node is leaf
4436
         */
4512
         */
4437
        @Override
4513
        @Override
4438
        public int getChildrenCount (Object node) throws UnknownTypeException {
4514
        public int getChildrenCount(Object node) throws UnknownTypeException {
4439
            return treeModel.getChildrenCount (node);
4515
            return treeModel.getChildrenCount(node);
4440
        }
4516
        }
4441
4517
4442
        /**
4518
        /**
4443
         * Returns true if node is leaf.
4519
         * Returns true if node is leaf.
4444
         * 
4520
         *
4445
         * @throws  UnknownTypeException if this TreeModel implementation is not
4521
         * @throws UnknownTypeException if this TreeModel implementation is not
4446
         *          able to resolve children for given node type
4522
         * able to resolve children for given node type
4447
         * @return  true if node is leaf
4523
         * @return true if node is leaf
4448
         */
4524
         */
4449
        @Override
4525
        @Override
4450
        public boolean isLeaf (Object node) throws UnknownTypeException {
4526
        public boolean isLeaf(Object node) throws UnknownTypeException {
4451
            return treeModel.isLeaf (node);
4527
            return treeModel.isLeaf(node);
4452
        }
4528
        }
4453
4529
4454
        // ReorderableTreeModel ...............................................................
4530
        // ReorderableTreeModel ...............................................................
4455
4456
        @Override
4531
        @Override
4457
        public boolean canReorder(Object parent) throws UnknownTypeException {
4532
        public boolean canReorder(Object parent) throws UnknownTypeException {
4458
            return treeModel.canReorder(parent);
4533
            return treeModel.canReorder(parent);
Lines 4464-4479 Link Here
4464
        }
4539
        }
4465
4540
4466
        // NodeModel ...............................................................
4541
        // NodeModel ...............................................................
4467
4468
        /**
4542
        /**
4469
         * Returns display name for given node.
4543
         * Returns display name for given node.
4470
         *
4544
         *
4471
         * @throws  UnknownTypeException if this NodeModel implementation is not
4545
         * @throws UnknownTypeException if this NodeModel implementation is not
4472
         *          able to resolve display name for given node type
4546
         * able to resolve display name for given node type
4473
         * @return  display name for given node
4547
         * @return display name for given node
4474
         */
4548
         */
4475
        @Override
4549
        @Override
4476
        public String getDisplayName (Object node) throws UnknownTypeException {
4550
        public String getDisplayName(Object node) throws UnknownTypeException {
4477
            if (nodeModel instanceof DelegatingNodeModel) {
4551
            if (nodeModel instanceof DelegatingNodeModel) {
4478
                NodeModel[] subModels = ((DelegatingNodeModel) nodeModel).getModels();
4552
                NodeModel[] subModels = ((DelegatingNodeModel) nodeModel).getModels();
4479
                if (subModels.length == 0) {
4553
                if (subModels.length == 0) {
Lines 4488-4494 Link Here
4488
                    return ""; // Nothing when there are no models
4562
                    return ""; // Nothing when there are no models
4489
                }
4563
                }
4490
            }
4564
            }
4491
            String dn = nodeModel.getDisplayName (node);
4565
            String dn = nodeModel.getDisplayName(node);
4492
            //System.err.println("DisplayName for node '"+node+"' is: '"+dn+"'");
4566
            //System.err.println("DisplayName for node '"+node+"' is: '"+dn+"'");
4493
            //System.err.println("Model = "+this);
4567
            //System.err.println("Model = "+this);
4494
            return dn;
4568
            return dn;
Lines 4497-4509 Link Here
4497
        /**
4571
        /**
4498
         * Returns tool tip for given node.
4572
         * Returns tool tip for given node.
4499
         *
4573
         *
4500
         * @throws  UnknownTypeException if this NodeModel implementation is not
4574
         * @throws UnknownTypeException if this NodeModel implementation is not
4501
         *          able to resolve tool tip for given node type
4575
         * able to resolve tool tip for given node type
4502
         * @return  tool tip for given node
4576
         * @return tool tip for given node
4503
         */
4577
         */
4504
        @Override
4578
        @Override
4505
        public String getShortDescription (Object node) 
4579
        public String getShortDescription(Object node)
4506
        throws UnknownTypeException {
4580
                throws UnknownTypeException {
4507
            if (nodeModel instanceof DelegatingNodeModel) {
4581
            if (nodeModel instanceof DelegatingNodeModel) {
4508
                NodeModel[] subModels = ((DelegatingNodeModel) nodeModel).getModels();
4582
                NodeModel[] subModels = ((DelegatingNodeModel) nodeModel).getModels();
4509
                if (subModels.length == 0) {
4583
                if (subModels.length == 0) {
Lines 4517-4611 Link Here
4517
                    }
4591
                    }
4518
                }
4592
                }
4519
            }
4593
            }
4520
            return nodeModel.getShortDescription (node);
4594
            return nodeModel.getShortDescription(node);
4595
        }
4596
4597
        @Override
4598
        public Image getIcon(Object node, int type) throws UnknownTypeException {
4599
            if (iconNodeModel != null) {
4600
                return iconNodeModel.getIcon(node, type);
4601
            }
4602
            return null;
4603
        }
4604
4605
        @Override
4606
        public Image getOpenedIcon(Object node, int type) throws UnknownTypeException {
4607
            if (iconNodeModel != null) {
4608
                return iconNodeModel.getOpenedIcon(node, type);
4609
            }
4610
            return null;
4611
        }
4612
4613
        @Override
4614
        public Lookup getLookup(Object node) throws UnknownTypeException {
4615
            if (lookupNodeModel != null) {
4616
                return lookupNodeModel.getLookup(node);
4617
            }
4618
            return Lookup.EMPTY;
4521
        }
4619
        }
4522
4620
4523
        /**
4621
        /**
4524
         * Returns icon for given node.
4622
         * Returns icon for given node.
4525
         *
4623
         *
4526
         * @throws  UnknownTypeException if this NodeModel implementation is not
4624
         * @throws UnknownTypeException if this NodeModel implementation is not
4527
         *          able to resolve icon for given node type
4625
         * able to resolve icon for given node type
4528
         * @return  icon for given node
4626
         * @return icon for given node
4529
         */
4627
         */
4530
        @Override
4628
        @Override
4531
        public String getIconBase (Object node) 
4629
        public String getIconBase(Object node)
4532
        throws UnknownTypeException {
4630
                throws UnknownTypeException {
4533
            if (nodeModel instanceof DelegatingNodeModel) {
4631
            if (nodeModel instanceof DelegatingNodeModel) {
4534
                NodeModel[] subModels = ((DelegatingNodeModel) nodeModel).getModels();
4632
                NodeModel[] subModels = ((DelegatingNodeModel) nodeModel).getModels();
4535
                if (subModels.length == 0) {
4633
                if (subModels.length == 0) {
4536
                    return null; // Nothing when there are no models
4634
                    return null; // Nothing when there are no models
4537
                }
4635
                }
4538
            }
4636
            }
4539
            String ib = nodeModel.getIconBase (node);
4637
            String ib = nodeModel.getIconBase(node);
4540
            //System.err.println("IconBase for node '"+node+"' is '"+ib+"'");
4638
            //System.err.println("IconBase for node '"+node+"' is '"+ib+"'");
4541
            //System.err.println("Model = "+this);
4639
            //System.err.println("Model = "+this);
4542
            return ib;
4640
            return ib;
4543
        }
4641
        }
4544
4642
4545
4546
        // NodeActionsProvider .....................................................
4643
        // NodeActionsProvider .....................................................
4547
4548
        /**
4644
        /**
4549
         * Performs default action for given node.
4645
         * Performs default action for given node.
4550
         *
4646
         *
4551
         * @throws  UnknownTypeException if this NodeActionsProvider implementation 
4647
         * @throws UnknownTypeException if this NodeActionsProvider
4552
         *          is not able to resolve actions for given node type
4648
         * implementation is not able to resolve actions for given node type
4553
         * @return  display name for given node
4649
         * @return display name for given node
4554
         */
4650
         */
4555
        @Override
4651
        @Override
4556
        public void performDefaultAction (Object node) throws UnknownTypeException {
4652
        public void performDefaultAction(Object node) throws UnknownTypeException {
4557
            nodeActionsProvider.performDefaultAction (node);
4653
            nodeActionsProvider.performDefaultAction(node);
4558
        }
4654
        }
4559
4655
4560
        /**
4656
        /**
4561
         * Returns set of actions for given node.
4657
         * Returns set of actions for given node.
4562
         *
4658
         *
4563
         * @throws  UnknownTypeException if this NodeActionsProvider implementation 
4659
         * @throws UnknownTypeException if this NodeActionsProvider
4564
         *          is not able to resolve actions for given node type
4660
         * implementation is not able to resolve actions for given node type
4565
         * @return  display name for given node
4661
         * @return display name for given node
4566
         */
4662
         */
4567
        @Override
4663
        @Override
4568
        public Action[] getActions (Object node) throws UnknownTypeException {
4664
        public Action[] getActions(Object node) throws UnknownTypeException {
4569
            return nodeActionsProvider.getActions (node);
4665
            return nodeActionsProvider.getActions(node);
4570
        }
4666
        }
4571
4667
4572
4573
        // ColumnsModel ............................................................
4668
        // ColumnsModel ............................................................
4574
4575
        /**
4669
        /**
4576
         * Returns sorted array of 
4670
         * Returns sorted array of
4577
         * {@link org.netbeans.spi.viewmodel.ColumnModel}s.
4671
         * {@link org.netbeans.spi.viewmodel.ColumnModel}s.
4578
         *
4672
         *
4579
         * @return sorted array of ColumnModels
4673
         * @return sorted array of ColumnModels
4580
         */
4674
         */
4581
        public ColumnModel[] getColumns () {
4675
        public ColumnModel[] getColumns() {
4582
            return columnModels;
4676
            return columnModels;
4583
        }
4677
        }
4584
4678
4585
4586
        // TableModel ..............................................................
4679
        // TableModel ..............................................................
4587
4588
        @Override
4680
        @Override
4589
        public Object getValueAt (Object node, String columnID) throws 
4681
        public Object getValueAt(Object node, String columnID) throws
4590
        UnknownTypeException {
4682
                UnknownTypeException {
4591
            return tableModel.getValueAt (node, columnID);
4683
            return tableModel.getValueAt(node, columnID);
4592
        }
4684
        }
4593
4685
4594
        @Override
4686
        @Override
4595
        public boolean isReadOnly (Object node, String columnID) throws 
4687
        public boolean isReadOnly(Object node, String columnID) throws
4596
        UnknownTypeException {
4688
                UnknownTypeException {
4597
            return tableModel.isReadOnly (node, columnID);
4689
            return tableModel.isReadOnly(node, columnID);
4598
        }
4690
        }
4599
4691
4600
        @Override
4692
        @Override
4601
        public void setValueAt (Object node, String columnID, Object value) throws 
4693
        public void setValueAt(Object node, String columnID, Object value) throws
4602
        UnknownTypeException {
4694
                UnknownTypeException {
4603
            tableModel.setValueAt (node, columnID, value);
4695
            tableModel.setValueAt(node, columnID, value);
4604
        }
4696
        }
4605
4697
4606
4607
        // TreeExpansionModel ......................................................
4698
        // TreeExpansionModel ......................................................
4608
4609
        /**
4699
        /**
4610
         * Defines default state (collapsed, expanded) of given node.
4700
         * Defines default state (collapsed, expanded) of given node.
4611
         *
4701
         *
Lines 4613-4623 Link Here
4613
         * @return default state (collapsed, expanded) of given node
4703
         * @return default state (collapsed, expanded) of given node
4614
         */
4704
         */
4615
        @Override
4705
        @Override
4616
        public boolean isExpanded (Object node) throws UnknownTypeException {
4706
        public boolean isExpanded(Object node) throws UnknownTypeException {
4617
            if (treeExpansionModel == null) {
4707
            if (treeExpansionModel == null) {
4618
                return false;
4708
                return false;
4619
            }
4709
            }
4620
            return treeExpansionModel.isExpanded (node);
4710
            return treeExpansionModel.isExpanded(node);
4621
        }
4711
        }
4622
4712
4623
        /**
4713
        /**
Lines 4626-4634 Link Here
4626
         * @param node a expanded node
4716
         * @param node a expanded node
4627
         */
4717
         */
4628
        @Override
4718
        @Override
4629
        public void nodeExpanded (Object node) {
4719
        public void nodeExpanded(Object node) {
4630
            if (treeExpansionModel != null) {
4720
            if (treeExpansionModel != null) {
4631
                treeExpansionModel.nodeExpanded (node);
4721
                treeExpansionModel.nodeExpanded(node);
4632
            }
4722
            }
4633
        }
4723
        }
4634
4724
Lines 4638-4678 Link Here
4638
         * @param node a collapsed node
4728
         * @param node a collapsed node
4639
         */
4729
         */
4640
        @Override
4730
        @Override
4641
        public void nodeCollapsed (Object node) {
4731
        public void nodeCollapsed(Object node) {
4642
            if (treeExpansionModel != null) {
4732
            if (treeExpansionModel != null) {
4643
                treeExpansionModel.nodeCollapsed (node);
4733
                treeExpansionModel.nodeCollapsed(node);
4644
            }
4734
            }
4645
        }
4735
        }
4646
4736
4647
4648
        // listeners ...............................................................
4737
        // listeners ...............................................................
4649
4738
        /**
4650
        /** 
4651
         * Registers given listener.
4739
         * Registers given listener.
4652
         * 
4740
         *
4653
         * @param l the listener to add
4741
         * @param l the listener to add
4654
         */
4742
         */
4655
        @Override
4743
        @Override
4656
        public void addModelListener (ModelListener l) {
4744
        public void addModelListener(ModelListener l) {
4657
            Set<Model> modelsListenersAddedTo = new HashSet<Model>();
4745
            Set<Model> modelsListenersAddedTo = new HashSet<>();
4658
            if (treeModel instanceof DelegatingTreeModel) {
4746
            if (treeModel instanceof DelegatingTreeModel) {
4659
                ((DelegatingTreeModel) treeModel).addModelListener(l, modelsListenersAddedTo);
4747
                ((DelegatingTreeModel) treeModel).addModelListener(l, modelsListenersAddedTo);
4660
            } else {
4748
            } else {
4661
                treeModel.addModelListener (l);
4749
                treeModel.addModelListener(l);
4662
                modelsListenersAddedTo.add(treeModel);
4750
                modelsListenersAddedTo.add(treeModel);
4663
            }
4751
            }
4664
            if (nodeModel != treeModel && !modelsListenersAddedTo.contains(nodeModel)) {
4752
            if (nodeModel != treeModel && !modelsListenersAddedTo.contains(nodeModel)) {
4665
                if (nodeModel instanceof DelegatingNodeModel) {
4753
                if (nodeModel instanceof DelegatingNodeModel) {
4666
                    ((DelegatingNodeModel) nodeModel).addModelListener(l, modelsListenersAddedTo);
4754
                    ((DelegatingNodeModel) nodeModel).addModelListener(l, modelsListenersAddedTo);
4667
                } else {
4755
                } else {
4668
                    nodeModel.addModelListener (l);
4756
                    nodeModel.addModelListener(l);
4669
                }
4757
                }
4670
            }
4758
            }
4671
            if (tableModel != treeModel && tableModel != nodeModel && !modelsListenersAddedTo.contains(tableModel)) {
4759
            if (tableModel != treeModel && tableModel != nodeModel && !modelsListenersAddedTo.contains(tableModel)) {
4672
                if (tableModel instanceof DelegatingTableModel) {
4760
                if (tableModel instanceof DelegatingTableModel) {
4673
                    ((DelegatingTableModel) tableModel).addModelListener(l, modelsListenersAddedTo);
4761
                    ((DelegatingTableModel) tableModel).addModelListener(l, modelsListenersAddedTo);
4674
                } else {
4762
                } else {
4675
                    tableModel.addModelListener (l);
4763
                    tableModel.addModelListener(l);
4676
                }
4764
                }
4677
            }
4765
            }
4678
            if (treeExpansionModel instanceof CompoundTreeExpansionModel) {
4766
            if (treeExpansionModel instanceof CompoundTreeExpansionModel) {
Lines 4680-4698 Link Here
4680
            }
4768
            }
4681
        }
4769
        }
4682
4770
4683
        /** 
4771
        /**
4684
         * Unregisters given listener.
4772
         * Unregisters given listener.
4685
         *
4773
         *
4686
         * @param l the listener to remove
4774
         * @param l the listener to remove
4687
         */
4775
         */
4688
        @Override
4776
        @Override
4689
        public void removeModelListener (ModelListener l) {
4777
        public void removeModelListener(ModelListener l) {
4690
            treeModel.removeModelListener (l);
4778
            treeModel.removeModelListener(l);
4691
            if (nodeModel != treeModel) {
4779
            if (nodeModel != treeModel) {
4692
                nodeModel.removeModelListener (l);
4780
                nodeModel.removeModelListener(l);
4693
            }
4781
            }
4694
            if (tableModel != treeModel && tableModel != nodeModel) {
4782
            if (tableModel != treeModel && tableModel != nodeModel) {
4695
                tableModel.removeModelListener (l);
4783
                tableModel.removeModelListener(l);
4696
            }
4784
            }
4697
            if (treeExpansionModel instanceof CompoundTreeExpansionModel) {
4785
            if (treeExpansionModel instanceof CompoundTreeExpansionModel) {
4698
                ((CompoundTreeExpansionModel) treeExpansionModel).removeModelListener(l);
4786
                ((CompoundTreeExpansionModel) treeExpansionModel).removeModelListener(l);
Lines 4700-4706 Link Here
4700
        }
4788
        }
4701
4789
4702
        @Override
4790
        @Override
4703
        public String toString () {
4791
        public String toString() {
4704
            /*String str = super.toString () +
4792
            /*String str = super.toString () +
4705
                   "\n  TreeModel = " + treeModel +
4793
                   "\n  TreeModel = " + treeModel +
4706
                   "\n  NodeModel = " + nodeModel +
4794
                   "\n  NodeModel = " + nodeModel +
Lines 4716-4731 Link Here
4716
            if (str.indexOf("VariablesTableModel") > 0) {
4804
            if (str.indexOf("VariablesTableModel") > 0) {
4717
                return "CompoundModel [VARIABLES]";
4805
                return "CompoundModel [VARIABLES]";
4718
            }*/
4806
            }*/
4719
            return super.toString () + 
4807
            return super.toString()
4720
                   "\n  TreeModel = " + treeModel +
4808
                    + "\n  TreeModel = " + treeModel
4721
                   "\n  NodeModel = " + nodeModel +
4809
                    + "\n  NodeModel = " + nodeModel
4722
                   "\n  TableModel = " + tableModel +
4810
                    + "\n  TableModel = " + tableModel
4723
                   "\n  NodeActionsProvider = " + nodeActionsProvider +
4811
                    + "\n  NodeActionsProvider = " + nodeActionsProvider
4724
                   "\n  ColumnsModel = " + java.util.Arrays.asList(columnModels);
4812
                    + "\n  ColumnsModel = " + java.util.Arrays.asList(columnModels);
4725
        }
4813
        }
4726
        
4814
4727
        // ExtendedNodeModel
4815
        // ExtendedNodeModel
4728
    
4729
        @Override
4816
        @Override
4730
        public boolean canRename(Object node) throws UnknownTypeException {
4817
        public boolean canRename(Object node) throws UnknownTypeException {
4731
            return nodeModel.canRename(node);
4818
            return nodeModel.canRename(node);
Lines 4743-4755 Link Here
4743
4830
4744
        @Override
4831
        @Override
4745
        public Transferable clipboardCopy(Object node) throws IOException,
4832
        public Transferable clipboardCopy(Object node) throws IOException,
4746
                                                              UnknownTypeException {
4833
                UnknownTypeException {
4747
            return nodeModel.clipboardCopy(node);
4834
            return nodeModel.clipboardCopy(node);
4748
        }
4835
        }
4749
4836
4750
        @Override
4837
        @Override
4751
        public Transferable clipboardCut(Object node) throws IOException,
4838
        public Transferable clipboardCut(Object node) throws IOException,
4752
                                                             UnknownTypeException {
4839
                UnknownTypeException {
4753
            return nodeModel.clipboardCut(node);
4840
            return nodeModel.clipboardCut(node);
4754
        }
4841
        }
4755
4842
Lines 4773-4779 Link Here
4773
4860
4774
        @Override
4861
        @Override
4775
        public Transferable drag(Object node) throws IOException,
4862
        public Transferable drag(Object node) throws IOException,
4776
                                                     UnknownTypeException {
4863
                UnknownTypeException {
4777
            if (dndNodeModel != null) {
4864
            if (dndNodeModel != null) {
4778
                return dndNodeModel.drag(node);
4865
                return dndNodeModel.drag(node);
4779
            } else {
4866
            } else {
Lines 4788-4794 Link Here
4788
4875
4789
        @Override
4876
        @Override
4790
        public PasteType getDropType(Object node, Transferable t, int action,
4877
        public PasteType getDropType(Object node, Transferable t, int action,
4791
                                     int index) throws UnknownTypeException {
4878
                int index) throws UnknownTypeException {
4792
            if (dndNodeModel != null) {
4879
            if (dndNodeModel != null) {
4793
                return dndNodeModel.getDropType(node, t, action, index);
4880
                return dndNodeModel.getDropType(node, t, action, index);
4794
            } else {
4881
            } else {
Lines 4841-4858 Link Here
4841
            if (cnodeModel != null) {
4928
            if (cnodeModel != null) {
4842
                cnodeModel.setSelected(node, selected);
4929
                cnodeModel.setSelected(node, selected);
4843
            } else {
4930
            } else {
4844
                Exceptions.printStackTrace(new IllegalStateException("Can not set selected state to model "+nodeModel));
4931
                Exceptions.printStackTrace(new IllegalStateException("Can not set selected state to model " + nodeModel));
4845
            }
4932
            }
4846
        }
4933
        }
4847
4934
4848
        // AsynchronousModel
4935
        @Override
4936
        public void setSelected(Object... nodes) throws UnknownTypeException {
4937
            if (cnodeModel != null) {
4938
                cnodeModel.setSelected(nodes);
4939
            } else {
4940
                Exceptions.printStackTrace(new IllegalStateException("Can not set selected state to model " + nodeModel));
4941
            }
4942
        }
4943
4944
        @Override
4945
        public void setUnselected(Object... nodes) throws UnknownTypeException {
4946
            if (cnodeModel != null) {
4947
                cnodeModel.setUnselected(nodes);
4948
            } else {
4949
                Exceptions.printStackTrace(new IllegalStateException("Can not set selected state to model " + nodeModel));
4950
            }
4951
        }
4849
4952
4953
        // AsynchronousModel
4850
        public Executor asynchronous(CALL asynchCall, Object node) throws UnknownTypeException {
4954
        public Executor asynchronous(CALL asynchCall, Object node) throws UnknownTypeException {
4851
            return asynchModel.asynchronous(asynchCall, node);
4955
            return asynchModel.asynchronous(asynchCall, node);
4852
        }
4956
        }
4853
4957
4854
        // TableRendererModel
4958
        // TableRendererModel
4855
4856
        @Override
4959
        @Override
4857
        public boolean canRenderCell(Object node, String columnID) throws UnknownTypeException {
4960
        public boolean canRenderCell(Object node, String columnID) throws UnknownTypeException {
4858
            if (tableRendererModel != null) {
4961
            if (tableRendererModel != null) {
Lines 4888-4896 Link Here
4888
                return null;
4991
                return null;
4889
            }
4992
            }
4890
        }
4993
        }
4891
        
4892
        // TableHTMLModel
4893
4994
4995
        // TableHTMLModel
4894
        @Override
4996
        @Override
4895
        public boolean hasHTMLValueAt(Object node, String columnID) throws UnknownTypeException {
4997
        public boolean hasHTMLValueAt(Object node, String columnID) throws UnknownTypeException {
4896
            return tableModel.hasHTMLValueAt(node, columnID);
4998
            return tableModel.hasHTMLValueAt(node, columnID);
Lines 4900-4908 Link Here
4900
        public String getHTMLValueAt(Object node, String columnID) throws UnknownTypeException {
5002
        public String getHTMLValueAt(Object node, String columnID) throws UnknownTypeException {
4901
            return tableModel.getHTMLValueAt(node, columnID);
5003
            return tableModel.getHTMLValueAt(node, columnID);
4902
        }
5004
        }
4903
        
4904
        // TablePropertyEditorsModel
4905
5005
5006
        // TablePropertyEditorsModel
4906
        @Override
5007
        @Override
4907
        public PropertyEditor getPropertyEditor(Object node, String columnID) throws UnknownTypeException {
5008
        public PropertyEditor getPropertyEditor(Object node, String columnID) throws UnknownTypeException {
4908
            if (tablePropertyEditorsModel != null) {
5009
            if (tablePropertyEditorsModel != null) {
Lines 4911-4954 Link Here
4911
                return null;
5012
                return null;
4912
            }
5013
            }
4913
        }
5014
        }
4914
        
4915
        
4916
5015
4917
    }
5016
    }
4918
5017
4919
    private static final class ModelLists extends Object {
5018
    private static final class ModelLists extends Object {
4920
5019
4921
        public List<TreeModel>                 treeModels = Collections.emptyList();
5020
        public List<TreeModel> treeModels = Collections.emptyList();
4922
        public List<TreeModelFilter>           treeModelFilters = Collections.emptyList();
5021
        public List<TreeModelFilter> treeModelFilters = Collections.emptyList();
4923
        public List<TreeExpansionModel>        treeExpansionModels = Collections.emptyList();
5022
        public List<TreeExpansionModel> treeExpansionModels = Collections.emptyList();
4924
        public List<TreeExpansionModelFilter>  treeExpansionModelFilters = Collections.emptyList();
5023
        public List<TreeExpansionModelFilter> treeExpansionModelFilters = Collections.emptyList();
4925
        public List<NodeModel>                 nodeModels = Collections.emptyList();
5024
        public List<NodeModel> nodeModels = Collections.emptyList();
4926
        public List<NodeModelFilter>           nodeModelFilters = Collections.emptyList();
5025
        public List<NodeModelFilter> nodeModelFilters = Collections.emptyList();
4927
        public List<TableModel>                tableModels = Collections.emptyList();
5026
        public List<TableModel> tableModels = Collections.emptyList();
4928
        public List<TableModelFilter>          tableModelFilters = Collections.emptyList();
5027
        public List<TableModelFilter> tableModelFilters = Collections.emptyList();
4929
        public List<NodeActionsProvider>       nodeActionsProviders = Collections.emptyList();
5028
        public List<NodeActionsProvider> nodeActionsProviders = Collections.emptyList();
4930
        public List<NodeActionsProviderFilter> nodeActionsProviderFilters = Collections.emptyList();
5029
        public List<NodeActionsProviderFilter> nodeActionsProviderFilters = Collections.emptyList();
4931
        public List<ColumnModel>               columnModels = Collections.emptyList();
5030
        public List<ColumnModel> columnModels = Collections.emptyList();
4932
        //public List<AsynchronousModel>         asynchModels = Collections.emptyList();
5031
        //public List<AsynchronousModel>         asynchModels = Collections.emptyList();
4933
        public List<AsynchronousModelFilter>   asynchModelFilters = Collections.emptyList();
5032
        public List<AsynchronousModelFilter> asynchModelFilters = Collections.emptyList();
4934
        public List<TableRendererModel>        tableRendererModels = Collections.emptyList();
5033
        public List<TableRendererModel> tableRendererModels = Collections.emptyList();
4935
        public List<TableRendererModelFilter>  tableRendererModelFilters = Collections.emptyList();
5034
        public List<TableRendererModelFilter> tableRendererModelFilters = Collections.emptyList();
4936
        public List<TableHTMLModel>            tableHtmlModels = Collections.emptyList();
5035
        public List<TableHTMLModel> tableHtmlModels = Collections.emptyList();
4937
        public List<TableHTMLModelFilter>      tableHtmlModelFilters = Collections.emptyList();
5036
        public List<TableHTMLModelFilter> tableHtmlModelFilters = Collections.emptyList();
4938
        public List<TablePropertyEditorsModel> tablePropertyEditorsModels = Collections.emptyList();
5037
        public List<TablePropertyEditorsModel> tablePropertyEditorsModels = Collections.emptyList();
4939
        public List<TablePropertyEditorsModelFilter> tablePropertyEditorsModelFilters = Collections.emptyList();
5038
        public List<TablePropertyEditorsModelFilter> tablePropertyEditorsModelFilters = Collections.emptyList();
5039
        public IconNodeModel iconNodeModel = null;
5040
        public LookupNodeModel lookupNodeModel = null;
4940
5041
4941
        public void addOtherModels(List<? extends Model> otherModels) {
5042
        public void addOtherModels(List<? extends Model> otherModels) {
4942
            Iterator it = otherModels.iterator ();
5043
            Iterator it = otherModels.iterator();
4943
            while (it.hasNext ()) {
5044
            while (it.hasNext()) {
4944
                Object model = it.next ();
5045
                Object model = it.next();
4945
                boolean first = model.getClass ().getName ().endsWith ("First");
5046
                boolean first = model.getClass().getName().endsWith("First");
4946
                if (model instanceof TreeModel && !treeModels.contains((TreeModel) model)) {
5047
                if (model instanceof TreeModel && !treeModels.contains((TreeModel) model)) {
4947
                    treeModels = new ArrayList<TreeModel>(treeModels);
5048
                    treeModels = new ArrayList<>(treeModels);
4948
                    treeModels.add((TreeModel) model);
5049
                    treeModels.add((TreeModel) model);
4949
                }
5050
                }
4950
                if (model instanceof TreeModelFilter && !treeModelFilters.contains((TreeModelFilter) model)) {
5051
                if (model instanceof TreeModelFilter && !treeModelFilters.contains((TreeModelFilter) model)) {
4951
                    treeModelFilters = new ArrayList<TreeModelFilter>(treeModelFilters);
5052
                    treeModelFilters = new ArrayList<>(treeModelFilters);
4952
                    if (first) {
5053
                    if (first) {
4953
                        treeModelFilters.add((TreeModelFilter) model);
5054
                        treeModelFilters.add((TreeModelFilter) model);
4954
                    } else {
5055
                    } else {
Lines 4956-4966 Link Here
4956
                    }
5057
                    }
4957
                }
5058
                }
4958
                if (model instanceof TreeExpansionModel && !treeExpansionModels.contains((TreeExpansionModel) model)) {
5059
                if (model instanceof TreeExpansionModel && !treeExpansionModels.contains((TreeExpansionModel) model)) {
4959
                    treeExpansionModels = new ArrayList<TreeExpansionModel>(treeExpansionModels);
5060
                    treeExpansionModels = new ArrayList<>(treeExpansionModels);
4960
                    treeExpansionModels.add((TreeExpansionModel) model);
5061
                    treeExpansionModels.add((TreeExpansionModel) model);
4961
                }
5062
                }
4962
                if (model instanceof TreeExpansionModelFilter && !treeExpansionModelFilters.contains((TreeExpansionModelFilter) model)) {
5063
                if (model instanceof TreeExpansionModelFilter && !treeExpansionModelFilters.contains((TreeExpansionModelFilter) model)) {
4963
                    treeExpansionModelFilters = new ArrayList<TreeExpansionModelFilter>(treeExpansionModelFilters);
5064
                    treeExpansionModelFilters = new ArrayList<>(treeExpansionModelFilters);
4964
                    if (first) {
5065
                    if (first) {
4965
                        treeExpansionModelFilters.add((TreeExpansionModelFilter) model);
5066
                        treeExpansionModelFilters.add((TreeExpansionModelFilter) model);
4966
                    } else {
5067
                    } else {
Lines 4968-4978 Link Here
4968
                    }
5069
                    }
4969
                }
5070
                }
4970
                if (model instanceof NodeModel && !nodeModels.contains((NodeModel) model)) {
5071
                if (model instanceof NodeModel && !nodeModels.contains((NodeModel) model)) {
4971
                    nodeModels = new ArrayList<NodeModel>(nodeModels);
5072
                    nodeModels = new ArrayList<>(nodeModels);
4972
                    nodeModels.add((NodeModel) model);
5073
                    nodeModels.add((NodeModel) model);
4973
                }
5074
                }
4974
                if (model instanceof NodeModelFilter && !nodeModelFilters.contains((NodeModelFilter) model)) {
5075
                if (model instanceof NodeModelFilter && !nodeModelFilters.contains((NodeModelFilter) model)) {
4975
                    nodeModelFilters = new ArrayList<NodeModelFilter>(nodeModelFilters);
5076
                    nodeModelFilters = new ArrayList<>(nodeModelFilters);
4976
                    if (first) {
5077
                    if (first) {
4977
                        nodeModelFilters.add((NodeModelFilter) model);
5078
                        nodeModelFilters.add((NodeModelFilter) model);
4978
                    } else {
5079
                    } else {
Lines 4980-4990 Link Here
4980
                    }
5081
                    }
4981
                }
5082
                }
4982
                if (model instanceof TableModel && !tableModels.contains((TableModel) model)) {
5083
                if (model instanceof TableModel && !tableModels.contains((TableModel) model)) {
4983
                    tableModels = new ArrayList<TableModel>(tableModels);
5084
                    tableModels = new ArrayList<>(tableModels);
4984
                    tableModels.add((TableModel) model);
5085
                    tableModels.add((TableModel) model);
4985
                }
5086
                }
4986
                if (model instanceof TableModelFilter && !tableModelFilters.contains((TableModelFilter) model)) {
5087
                if (model instanceof TableModelFilter && !tableModelFilters.contains((TableModelFilter) model)) {
4987
                    tableModelFilters = new ArrayList<TableModelFilter>(tableModelFilters);
5088
                    tableModelFilters = new ArrayList<>(tableModelFilters);
4988
                    if (first) {
5089
                    if (first) {
4989
                        tableModelFilters.add((TableModelFilter) model);
5090
                        tableModelFilters.add((TableModelFilter) model);
4990
                    } else {
5091
                    } else {
Lines 4992-5002 Link Here
4992
                    }
5093
                    }
4993
                }
5094
                }
4994
                if (model instanceof TableRendererModel && !tableRendererModels.contains((TableRendererModel) model)) {
5095
                if (model instanceof TableRendererModel && !tableRendererModels.contains((TableRendererModel) model)) {
4995
                    tableRendererModels = new ArrayList<TableRendererModel>(tableRendererModels);
5096
                    tableRendererModels = new ArrayList<>(tableRendererModels);
4996
                    tableRendererModels.add((TableRendererModel) model);
5097
                    tableRendererModels.add((TableRendererModel) model);
4997
                }
5098
                }
4998
                if (model instanceof TableRendererModelFilter && !tableRendererModelFilters.contains((TableRendererModelFilter) model)) {
5099
                if (model instanceof TableRendererModelFilter && !tableRendererModelFilters.contains((TableRendererModelFilter) model)) {
4999
                    tableRendererModelFilters = new ArrayList<TableRendererModelFilter>(tableRendererModelFilters);
5100
                    tableRendererModelFilters = new ArrayList<>(tableRendererModelFilters);
5000
                    if (first) {
5101
                    if (first) {
5001
                        tableRendererModelFilters.add((TableRendererModelFilter) model);
5102
                        tableRendererModelFilters.add((TableRendererModelFilter) model);
5002
                    } else {
5103
                    } else {
Lines 5004-5014 Link Here
5004
                    }
5105
                    }
5005
                }
5106
                }
5006
                if (model instanceof TableHTMLModel && !tableHtmlModels.contains((TableHTMLModel) model)) {
5107
                if (model instanceof TableHTMLModel && !tableHtmlModels.contains((TableHTMLModel) model)) {
5007
                    tableHtmlModels = new ArrayList<TableHTMLModel>(tableHtmlModels);
5108
                    tableHtmlModels = new ArrayList<>(tableHtmlModels);
5008
                    tableHtmlModels.add((TableHTMLModel) model);
5109
                    tableHtmlModels.add((TableHTMLModel) model);
5009
                }
5110
                }
5010
                if (model instanceof TableHTMLModelFilter && !tableHtmlModelFilters.contains((TableHTMLModelFilter) model)) {
5111
                if (model instanceof TableHTMLModelFilter && !tableHtmlModelFilters.contains((TableHTMLModelFilter) model)) {
5011
                    tableHtmlModelFilters = new ArrayList<TableHTMLModelFilter>(tableHtmlModelFilters);
5112
                    tableHtmlModelFilters = new ArrayList<>(tableHtmlModelFilters);
5012
                    if (first) {
5113
                    if (first) {
5013
                        tableHtmlModelFilters.add((TableHTMLModelFilter) model);
5114
                        tableHtmlModelFilters.add((TableHTMLModelFilter) model);
5014
                    } else {
5115
                    } else {
Lines 5016-5026 Link Here
5016
                    }
5117
                    }
5017
                }
5118
                }
5018
                if (model instanceof TablePropertyEditorsModel && !tablePropertyEditorsModels.contains((TablePropertyEditorsModel) model)) {
5119
                if (model instanceof TablePropertyEditorsModel && !tablePropertyEditorsModels.contains((TablePropertyEditorsModel) model)) {
5019
                    tablePropertyEditorsModels = new ArrayList<TablePropertyEditorsModel>(tablePropertyEditorsModels);
5120
                    tablePropertyEditorsModels = new ArrayList<>(tablePropertyEditorsModels);
5020
                    tablePropertyEditorsModels.add((TablePropertyEditorsModel) model);
5121
                    tablePropertyEditorsModels.add((TablePropertyEditorsModel) model);
5021
                }
5122
                }
5022
                if (model instanceof TablePropertyEditorsModelFilter && !tablePropertyEditorsModelFilters.contains((TablePropertyEditorsModelFilter) model)) {
5123
                if (model instanceof TablePropertyEditorsModelFilter && !tablePropertyEditorsModelFilters.contains((TablePropertyEditorsModelFilter) model)) {
5023
                    tablePropertyEditorsModelFilters = new ArrayList<TablePropertyEditorsModelFilter>(tablePropertyEditorsModelFilters);
5124
                    tablePropertyEditorsModelFilters = new ArrayList<>(tablePropertyEditorsModelFilters);
5024
                    if (first) {
5125
                    if (first) {
5025
                        tablePropertyEditorsModelFilters.add((TablePropertyEditorsModelFilter) model);
5126
                        tablePropertyEditorsModelFilters.add((TablePropertyEditorsModelFilter) model);
5026
                    } else {
5127
                    } else {
Lines 5028-5038 Link Here
5028
                    }
5129
                    }
5029
                }
5130
                }
5030
                if (model instanceof NodeActionsProvider && !nodeActionsProviders.contains((NodeActionsProvider) model)) {
5131
                if (model instanceof NodeActionsProvider && !nodeActionsProviders.contains((NodeActionsProvider) model)) {
5031
                    nodeActionsProviders = new ArrayList<NodeActionsProvider>(nodeActionsProviders);
5132
                    nodeActionsProviders = new ArrayList<>(nodeActionsProviders);
5032
                    nodeActionsProviders.add((NodeActionsProvider) model);
5133
                    nodeActionsProviders.add((NodeActionsProvider) model);
5033
                }
5134
                }
5034
                if (model instanceof NodeActionsProviderFilter && !nodeActionsProviderFilters.contains((NodeActionsProviderFilter) model)) {
5135
                if (model instanceof NodeActionsProviderFilter && !nodeActionsProviderFilters.contains((NodeActionsProviderFilter) model)) {
5035
                    nodeActionsProviderFilters = new ArrayList<NodeActionsProviderFilter>(nodeActionsProviderFilters);
5136
                    nodeActionsProviderFilters = new ArrayList<>(nodeActionsProviderFilters);
5036
                    if (first) {
5137
                    if (first) {
5037
                        nodeActionsProviderFilters.add((NodeActionsProviderFilter) model);
5138
                        nodeActionsProviderFilters.add((NodeActionsProviderFilter) model);
5038
                    } else {
5139
                    } else {
Lines 5044-5050 Link Here
5044
                    asynchModels.add((AsynchronousModel) model);
5145
                    asynchModels.add((AsynchronousModel) model);
5045
                }*/
5146
                }*/
5046
                if (model instanceof AsynchronousModelFilter && !asynchModelFilters.contains((AsynchronousModelFilter) model)) {
5147
                if (model instanceof AsynchronousModelFilter && !asynchModelFilters.contains((AsynchronousModelFilter) model)) {
5047
                    asynchModelFilters = new ArrayList<AsynchronousModelFilter>(asynchModelFilters);
5148
                    asynchModelFilters = new ArrayList<>(asynchModelFilters);
5048
                    if (first) {
5149
                    if (first) {
5049
                        asynchModelFilters.add((AsynchronousModelFilter) model);
5150
                        asynchModelFilters.add((AsynchronousModelFilter) model);
5050
                    } else {
5151
                    } else {
Lines 5053-5061 Link Here
5053
                }
5154
                }
5054
5155
5055
                if (model instanceof ColumnModel && !columnModels.contains((ColumnModel) model)) {
5156
                if (model instanceof ColumnModel && !columnModels.contains((ColumnModel) model)) {
5056
                    columnModels = new ArrayList<ColumnModel>(columnModels);
5157
                    columnModels = new ArrayList<>(columnModels);
5057
                    columnModels.add((ColumnModel) model);
5158
                    columnModels.add((ColumnModel) model);
5058
                }
5159
                }
5160
5161
                if (model instanceof IconNodeModel) {
5162
                    iconNodeModel = (IconNodeModel) model;
5163
                }
5164
                if (model instanceof LookupNodeModel) {
5165
                    lookupNodeModel = (LookupNodeModel) model;
5166
                }
5059
            }
5167
            }
5060
        }
5168
        }
5061
    }
5169
    }
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/NodeActionsProviderFilter.java (-25 / +21 lines)
Lines 41-95 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
import javax.swing.Action;
46
import javax.swing.Action;
48
47
49
50
/**
48
/**
51
 * Filters actions provided by some original {@link NodeActionsProvider}.
49
 * Filters actions provided by some original {@link NodeActionsProvider}. It can
52
 * It can be used to add some new actions to nodes pop-up menu, remove
50
 * be used to add some new actions to nodes pop-up menu, remove some actions or
53
 * some actions or redefine behaviour of some actions.
51
 * redefine behaviour of some actions.
54
 *
52
 *
55
 * @author   Jan Jancura
53
 * @author Jan Jancura
56
 */
54
 */
57
public interface NodeActionsProviderFilter extends Model {
55
public interface NodeActionsProviderFilter extends Model {
58
56
59
60
    /**
57
    /**
61
     * Performs default action for given node. You should not throw
58
     * Performs default action for given node. You should not throw
62
     * UnknownTypeException directly from this method!
59
     * UnknownTypeException directly from this method!
63
     *
60
     *
64
     * @throws  UnknownTypeException this exception can be thrown from 
61
     * @throws UnknownTypeException this exception can be thrown from
65
     *          <code>original.performDefaultAction (...)</code> method call only!
62
     * <code>original.performDefaultAction (...)</code> method call only!
66
     */
63
     */
67
    public abstract void performDefaultAction (
64
    public abstract void performDefaultAction(
68
        NodeActionsProvider original,
65
            NodeActionsProvider original,
69
        Object node
66
            Object node
70
    ) throws UnknownTypeException;
67
    ) throws UnknownTypeException;
71
    
68
72
    /**
69
    /**
73
     * Returns set of actions for given node. You should not throw UnknownTypeException
70
     * Returns set of actions for given node. You should not throw
74
     * directly from this method!
71
     * UnknownTypeException directly from this method!
75
     *
72
     *
76
     * @throws  UnknownTypeException this exception can be thrown from 
73
     * @throws UnknownTypeException this exception can be thrown from
77
     *          <code>original.getActions (...)</code> method call only!
74
     * <code>original.getActions (...)</code> method call only!
78
     * @return  set of actions for given node
75
     * @return set of actions for given node
79
     */
76
     */
80
    public abstract Action[] getActions (
77
    public abstract Action[] getActions(
81
         NodeActionsProvider original,
78
            NodeActionsProvider original,
82
         Object node
79
            Object node
83
    ) throws UnknownTypeException;
80
    ) throws UnknownTypeException;
84
81
85
    /** 
82
    /**
86
     * Registers given listener.
83
     * Registers given listener.
87
     * 
84
     *
88
     * @param l the listener to add
85
     * @param l the listener to add
89
     */
86
     */
90
//    public abstract void addModelListener (ModelListener l);
87
//    public abstract void addModelListener (ModelListener l);
91
88
    /**
92
    /** 
93
     * Unregisters given listener.
89
     * Unregisters given listener.
94
     *
90
     *
95
     * @param l the listener to remove
91
     * @param l the listener to remove
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/NodeActionsProvider.java (-21 / +17 lines)
Lines 41-89 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
import javax.swing.Action;
46
import javax.swing.Action;
48
47
49
50
/**
48
/**
51
 * Provides actions and default action for some type of objects.
49
 * Provides actions and default action for some type of objects. Designed to be
52
 * Designed to be used with {@link TreeModel}.
50
 * used with {@link TreeModel}.
53
 *
51
 *
54
 * @author   Jan Jancura
52
 * @author Jan Jancura
55
 */
53
 */
56
public interface NodeActionsProvider extends Model {
54
public interface NodeActionsProvider extends Model {
57
55
58
59
    /**
56
    /**
60
     * Performs default action for given node.
57
     * Performs default action for given node.
61
     *
58
     *
62
     * @throws  UnknownTypeException if this NodeActionsProvider implementation
59
     * @throws UnknownTypeException if this NodeActionsProvider implementation
63
     *          is not able to resolve actions for given node type
60
     * is not able to resolve actions for given node type
64
     * @return  display name for given node
61
     * @return display name for given node
65
     */
62
     */
66
    public abstract void performDefaultAction (Object node) 
63
    public abstract void performDefaultAction(Object node)
67
    throws UnknownTypeException;
64
            throws UnknownTypeException;
68
    
65
69
    /**
66
    /**
70
     * Returns set of actions for given node.
67
     * Returns set of actions for given node.
71
     *
68
     *
72
     * @throws  UnknownTypeException if this NodeActionsProvider implementation 
69
     * @throws UnknownTypeException if this NodeActionsProvider implementation
73
     *          is not able to resolve actions for given node type
70
     * is not able to resolve actions for given node type
74
     * @return  display name for given node
71
     * @return display name for given node
75
     */
72
     */
76
    public abstract Action[] getActions (Object node) 
73
    public abstract Action[] getActions(Object node)
77
    throws UnknownTypeException;
74
            throws UnknownTypeException;
78
75
79
    /** 
76
    /**
80
     * Registers given listener.
77
     * Registers given listener.
81
     * 
78
     *
82
     * @param l the listener to add
79
     * @param l the listener to add
83
     */
80
     */
84
//    public abstract void addModelListener (ModelListener l);
81
//    public abstract void addModelListener (ModelListener l);
85
82
    /**
86
    /** 
87
     * Unregisters given listener.
83
     * Unregisters given listener.
88
     *
84
     *
89
     * @param l the listener to remove
85
     * @param l the listener to remove
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/NodeModelFilter.java (-30 / +27 lines)
Lines 41-103 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
48
/**
46
/**
49
 * Filters content of some existing {@link NodeModel}. You can change display
47
 * Filters content of some existing {@link NodeModel}. You can change display
50
 * name, tooltip, or icon for some existing object here.
48
 * name, tooltip, or icon for some existing object here.
51
 *
49
 *
52
 * @author   Jan Jancura
50
 * @author Jan Jancura
53
 */
51
 */
54
public interface NodeModelFilter extends Model {
52
public interface NodeModelFilter extends Model {
55
53
56
    /**
54
    /**
57
     * Returns filterred display name for given node. You should not
55
     * Returns filterred display name for given node. You should not throw
58
     * throw UnknownTypeException directly from this method!
56
     * UnknownTypeException directly from this method!
59
     *
57
     *
60
     * @throws  UnknownTypeException this exception can be thrown from
58
     * @throws UnknownTypeException this exception can be thrown from
61
     *          <code>original.getDisplayName (...)</code> method call only!
59
     * <code>original.getDisplayName (...)</code> method call only!
62
     * @return  display name for given node
60
     * @return display name for given node
63
     */
61
     */
64
    public abstract String getDisplayName (NodeModel original, Object node) 
62
    public abstract String getDisplayName(NodeModel original, Object node)
65
    throws UnknownTypeException;
63
            throws UnknownTypeException;
66
    
64
67
    /**
65
    /**
68
     * Returns filterred icon for given node. You should not throw 
66
     * Returns filterred icon for given node. You should not throw
69
     * UnknownTypeException directly from this method!
67
     * UnknownTypeException directly from this method!
70
     *
68
     *
71
     * @throws  UnknownTypeException this exception can be thrown from 
69
     * @throws UnknownTypeException this exception can be thrown from
72
     *          <code>original.getIconBase (...)</code> method call only!
70
     * <code>original.getIconBase (...)</code> method call only!
73
     * @return  icon for given node
71
     * @return icon for given node
74
     */
72
     */
75
    public abstract String getIconBase (NodeModel original, Object node) 
73
    public abstract String getIconBase(NodeModel original, Object node)
76
    throws UnknownTypeException;
74
            throws UnknownTypeException;
77
    
75
78
    /**
76
    /**
79
     * Returns filterred tooltip for given node. You should not throw 
77
     * Returns filterred tooltip for given node. You should not throw
80
     * UnknownTypeException directly from this method!
78
     * UnknownTypeException directly from this method!
81
     *
79
     *
82
     * @throws  UnknownTypeException this exception can be thrown from 
80
     * @throws UnknownTypeException this exception can be thrown from
83
     *          <code>original.getShortDescription (...)</code> method call only!
81
     * <code>original.getShortDescription (...)</code> method call only!
84
     * @return  tooltip for given node
82
     * @return tooltip for given node
85
     */
83
     */
86
    public abstract String getShortDescription (NodeModel original, Object node) 
84
    public abstract String getShortDescription(NodeModel original, Object node)
87
    throws UnknownTypeException;
85
            throws UnknownTypeException;
88
86
89
87
    /**
90
    /** 
91
     * Registers given listener.
88
     * Registers given listener.
92
     * 
89
     *
93
     * @param l the listener to add
90
     * @param l the listener to add
94
     */
91
     */
95
    public abstract void addModelListener (ModelListener l);
92
    public abstract void addModelListener(ModelListener l);
96
93
97
    /** 
94
    /**
98
     * Unregisters given listener.
95
     * Unregisters given listener.
99
     *
96
     *
100
     * @param l the listener to remove
97
     * @param l the listener to remove
101
     */
98
     */
102
    public abstract void removeModelListener (ModelListener l);
99
    public abstract void removeModelListener(ModelListener l);
103
}
100
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/NodeModel.java (-24 / +22 lines)
Lines 41-97 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
48
/**
46
/**
49
 * Provides display name, icon and tool tip value for some type of objects.
47
 * Provides display name, icon and tooltip value for some type of objects.
50
 * Designed to be used with {@link TreeModel}.
48
 * Designed to be used with {@link TreeModel}.
51
 *
49
 *
52
 * @author   Jan Jancura
50
 * @author Jan Jancura
53
 */
51
 */
54
public interface NodeModel extends Model {
52
public interface NodeModel extends Model {
55
53
56
    /**
54
    /**
57
     * Returns display name for given node.
55
     * Returns display name for given node.
58
     *
56
     *
59
     * @return  display name for given node
57
     * @return display name for given node
60
     */
58
     */
61
    public abstract String getDisplayName (Object node)
59
    public abstract String getDisplayName(Object node)
62
    throws UnknownTypeException;
60
            throws UnknownTypeException;
63
61
64
    /**
62
    /**
65
     * Returns icon for given node.
63
     * Returns icon for given node.
66
     *
64
     *
67
     * @throws  UnknownTypeException if this NodeModel implementation is not
65
     * @throws UnknownTypeException if this NodeModel implementation is not able
68
     *          able to resolve icon for given node type
66
     * to resolve icon for given node type
69
     * @return  icon for given node
67
     * @return icon for given node
70
     */
68
     */
71
    public abstract String getIconBase (Object node) 
69
    public abstract String getIconBase(Object node)
72
    throws UnknownTypeException;
70
            throws UnknownTypeException;
73
    
71
74
    /**
72
    /**
75
     * Returns tool tip for given node.
73
     * Returns tooltip for given node.
76
     *
74
     *
77
     * @throws  UnknownTypeException if this NodeModel implementation is not
75
     * @throws UnknownTypeException if this NodeModel implementation is not able
78
     *          able to resolve tool tip for given node type
76
     * to resolve tooltip for given node type
79
     * @return  tool tip for given node
77
     * @return tooltip for given node
80
     */
78
     */
81
    public abstract String getShortDescription (Object node) 
79
    public abstract String getShortDescription(Object node)
82
    throws UnknownTypeException;
80
            throws UnknownTypeException;
83
81
84
    /** 
82
    /**
85
     * Registers given listener.
83
     * Registers given listener.
86
     * 
84
     *
87
     * @param l the listener to add
85
     * @param l the listener to add
88
     */
86
     */
89
    public abstract void addModelListener (ModelListener l);
87
    public abstract void addModelListener(ModelListener l);
90
88
91
    /** 
89
    /**
92
     * Unregisters given listener.
90
     * Unregisters given listener.
93
     *
91
     *
94
     * @param l the listener to remove
92
     * @param l the listener to remove
95
     */
93
     */
96
    public abstract void removeModelListener (ModelListener l);
94
    public abstract void removeModelListener(ModelListener l);
97
}
95
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/package.html (-104 / +104 lines)
Lines 1-116 Link Here
1
<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
1
<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
2
<html>
2
<html>
3
<head>
3
    <head>
4
  <meta http-equiv="Content-Type"
4
        <meta http-equiv="Content-Type"
5
 content="text/html; charset=iso-8859-1">
5
              content="text/html; charset=iso-8859-1">
6
  <meta name="GENERATOR"
6
        <meta name="GENERATOR"
7
 content="Mozilla/4.76 [en] (Windows NT 5.0; U) [Netscape]">
7
              content="Mozilla/4.76 [en] (Windows NT 5.0; U) [Netscape]">
8
  <title>View Model API</title>
8
        <title>View Model API</title>
9
<!--
9
        <!--
10
  -- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
10
          -- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
11
  --
11
          --
12
  -- Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
12
          -- Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
13
  --
13
          --
14
  -- The contents of this file are subject to the terms of either the GNU
14
          -- The contents of this file are subject to the terms of either the GNU
15
  -- General Public License Version 2 only ("GPL") or the Common
15
          -- General Public License Version 2 only ("GPL") or the Common
16
  -- Development and Distribution License("CDDL") (collectively, the
16
          -- Development and Distribution License("CDDL") (collectively, the
17
  -- "License"). You may not use this file except in compliance with the
17
          -- "License"). You may not use this file except in compliance with the
18
  -- License. You can obtain a copy of the License at
18
          -- License. You can obtain a copy of the License at
19
  -- http://www.netbeans.org/cddl-gplv2.html
19
          -- http://www.netbeans.org/cddl-gplv2.html
20
  -- or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
20
          -- or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
21
  -- specific language governing permissions and limitations under the
21
          -- specific language governing permissions and limitations under the
22
  -- License.  When distributing the software, include this License Header
22
          -- License.  When distributing the software, include this License Header
23
  -- Notice in each file and include the License file at
23
          -- Notice in each file and include the License file at
24
  -- nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
24
          -- nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
25
  -- particular file as subject to the "Classpath" exception as provided
25
          -- particular file as subject to the "Classpath" exception as provided
26
  -- by Sun in the GPL Version 2 section of the License file that
26
          -- by Sun in the GPL Version 2 section of the License file that
27
  -- accompanied this code. If applicable, add the following below the
27
          -- accompanied this code. If applicable, add the following below the
28
  -- License Header, with the fields enclosed by brackets [] replaced by
28
          -- License Header, with the fields enclosed by brackets [] replaced by
29
  -- your own identifying information:
29
          -- your own identifying information:
30
  -- "Portions Copyrighted [year] [name of copyright owner]"
30
          -- "Portions Copyrighted [year] [name of copyright owner]"
31
  --
31
          --
32
  -- Contributor(s):
32
          -- Contributor(s):
33
  --
33
          --
34
  -- The Original Software is NetBeans. The Initial Developer of the Original
34
          -- The Original Software is NetBeans. The Initial Developer of the Original
35
  -- Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
35
          -- Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
36
  -- Microsystems, Inc. All Rights Reserved.
36
          -- Microsystems, Inc. All Rights Reserved.
37
  -->
37
        -->
38
  <meta content="Jan Jancura" name="author">
38
        <meta content="Jan Jancura" name="author">
39
</head>
39
    </head>
40
<body style="color: rgb(0, 0, 0);" link="#0000ee" alink="#0000ee"
40
    <body style="color: rgb(0, 0, 0);" link="#0000ee" alink="#0000ee"
41
 vlink="#551a8b">
41
          vlink="#551a8b">
42
Defines API for sharing of Tree Table View. This API has been designed
42
        Defines API for sharing of Tree Table View. This API has been designed
43
for sharing Debugger Views (like Callstack View) among different
43
        for sharing Debugger Views (like Callstack View) among different
44
modules. But it does not depends on debugger itself. <br>
44
        modules. But it does not depends on debugger itself. <br>
45
<h2>Main features:</h2>
45
        <h2>Main features:</h2>
46
<ul>
46
        <ul>
47
  <li>One TreeView, or TreeTableView can be shared among different
47
            <li>One TreeView, or TreeTableView can be shared among different
48
modules. Different modules can add different types of nodes to one view.</li>
48
                modules. Different modules can add different types of nodes to one view.</li>
49
  <li>Hierarchy produced by one module can be changed by another one.<br>
49
            <li>Hierarchy produced by one module can be changed by another one.<br>
50
  </li>
50
            </li>
51
  <li>Allows to split UI and implementation to different modules.</li>
51
            <li>Allows to split UI and implementation to different modules.</li>
52
  <li>Performance and memory consumption of this model should be much
52
            <li>Performance and memory consumption of this model should be much
53
better than Node based models.</li>
53
                better than Node based models.</li>
54
  <li>You do not need one instance of some class (Node) per one node
54
            <li>You do not need one instance of some class (Node) per one node
55
visible in view. And you do not need one class per one node type.<br>
55
                visible in view. And you do not need one class per one node type.<br>
56
  </li>
56
            </li>
57
</ul>
57
        </ul>
58
<h2>How to use View Model API<br>
58
        <h2>How to use View Model API<br>
59
</h2>
59
        </h2>
60
Following example shows how to use viewmodel API to create simple files
60
        Following example shows how to use viewmodel API to create simple files
61
view.<br>
61
        view.<br>
62
<h3>Step 1.</h3>
62
        <h3>Step 1.</h3>
63
In the first step we should create plain tree model (TreeModel).<br>
63
        In the first step we should create plain tree model (TreeModel).<br>
64
<pre style="background-color: rgb(255, 255, 102);">public class TreeModelImpl implements TreeModel {<br><img
64
        <pre style="background-color: rgb(255, 255, 102);">public class TreeModelImpl implements TreeModel {<br><img
65
 src="doc-files/TreeModelExample1.JPG" title=""
65
 src="doc-files/TreeModelExample1.JPG" title=""
66
 alt="Tree Model Example 1" style="width: 401px; height: 355px;"
66
 alt="Tree Model Example 1" style="width: 401px; height: 355px;"
67
 align="right"><br>    public Object getRoot () {<br>        return ROOT;<br>    }<br>    <br>    public Object[] getChildren (Object parent, int from, int to) {<br>        if (parent == ROOT)<br>            return File.listRoots ();<br>        return ((File) parent).listFiles ();<br>    }<br>    <br>    public boolean isLeaf (Object node) {<br>        if (node == ROOT)<br>            return false;<br>        return ((File) node).isFile ();<br>    }<br>}<br></pre>
67
 align="right"><br>    public Object getRoot () {<br>        return ROOT;<br>    }<br>    <br>    public Object[] getChildren (Object parent, int from, int to) {<br>        if (parent == ROOT)<br>            return File.listRoots ();<br>        return ((File) parent).listFiles ();<br>    }<br>    <br>    public boolean isLeaf (Object node) {<br>        if (node == ROOT)<br>            return false;<br>        return ((File) node).isFile ();<br>    }<br>}<br></pre>
68
And create a TreeView for this model:
68
        And create a TreeView for this model:
69
<pre style="background-color: rgb(255, 255, 102);">    JComponent treeView = Models.createView (<br>        Models.createCompoundModel (<br>	    Arrays.asList (new Model[] {<br>                new TreeModelImpl (),      // TreeModel<br>                new ArrayList ()           // list of ColumnModel s<br>            })<br>        )<br>    );</pre>
69
        <pre style="background-color: rgb(255, 255, 102);">    JComponent treeView = Models.createView (<br>        Models.createCompoundModel (<br>	    Arrays.asList (new Model[] {<br>                new TreeModelImpl (),      // TreeModel<br>                new ArrayList ()           // list of ColumnModel s<br>            })<br>        )<br>    );</pre>
70
<h3>Step 2.</h3>
70
        <h3>Step 2.</h3>
71
NodeModel implementation can define name, icon and tooltip for tree
71
        NodeModel implementation can define name, icon and tooltip for tree
72
nodes produced by TreeModel.<br>
72
        nodes produced by TreeModel.<br>
73
<pre style="background-color: rgb(255, 255, 102);">public class NodeModelImpl implements NodeModel {<img
73
        <pre style="background-color: rgb(255, 255, 102);">public class NodeModelImpl implements NodeModel {<img
74
 src="doc-files/TreeModelExample2.JPG" title=""
74
 src="doc-files/TreeModelExample2.JPG" title=""
75
 alt="Tree Model Example 2" style="width: 355px; height: 329px;"
75
 alt="Tree Model Example 2" style="width: 355px; height: 329px;"
76
 align="right"><br><br>    public String getDisplayName (Object node) {<br>        if (node == ROOT) return "Name";<br>        String name = ((File) node).getName ();<br>        if (name.length () &lt; 1) return ((File) node).getAbsolutePath ();<br>        return name;<br>    }<br>    <br>    public String getIconBase (Object node) {<br>        if (node == ROOT) return "folder";<br>        if (((File) node).isDirectory ()) return "folder";<br>        return "file";<br>    }<br>    <br>    public String getShortDescription (Object node) {<br>        if (node == ROOT) return "Name";<br>        return ((File) node).getAbsolutePath ();<br>    }<br>}</pre>
76
 align="right"><br><br>    public String getDisplayName (Object node) {<br>        if (node == ROOT) return "Name";<br>        String name = ((File) node).getName ();<br>        if (name.length () &lt; 1) return ((File) node).getAbsolutePath ();<br>        return name;<br>    }<br>    <br>    public String getIconBase (Object node) {<br>        if (node == ROOT) return "folder";<br>        if (((File) node).isDirectory ()) return "folder";<br>        return "file";<br>    }<br>    <br>    public String getShortDescription (Object node) {<br>        if (node == ROOT) return "Name";<br>        return ((File) node).getAbsolutePath ();<br>    }<br>}</pre>
77
<h3>Step 3.</h3>
77
        <h3>Step 3.</h3>
78
NodeActionsProvider defines set of Actions for each node, and default
78
        NodeActionsProvider defines set of Actions for each node, and default
79
action..<br>
79
        action..<br>
80
<pre style="background-color: rgb(255, 255, 102);">public class NodeActionsProviderImpl implements NodeActionsProvider {<br><br>    public Action[] getActions (final Object node) {<br>        return new Action [] {<br>            new AbstractAction ("Open") {<br>                public void actionPerformed (ActionEvent e) {<br>                    performDefaultAction (node);<br>                }<br>            },<br>            new AbstractAction ("Delete") {<br>                public void actionPerformed (ActionEvent e) {<br>                    ((File) node).delete ();<br>                }<br>            }<br>        };<br>    }<br>    <br>    public void performDefaultAction (Object node) {<br>        try {<br>            JFrame f = new JFrame ("View");<br>            f.getContentPane ().add (new JEditorPane (((File) node).toURL ()));<br>            f.pack ();<br>            f.show ();<br>        } catch (Exception e) {<br>            e.printStackTrace();<br>        }<br>    }<br>}</pre>
80
        <pre style="background-color: rgb(255, 255, 102);">public class NodeActionsProviderImpl implements NodeActionsProvider {<br><br>    public Action[] getActions (final Object node) {<br>        return new Action [] {<br>            new AbstractAction ("Open") {<br>                public void actionPerformed (ActionEvent e) {<br>                    performDefaultAction (node);<br>                }<br>            },<br>            new AbstractAction ("Delete") {<br>                public void actionPerformed (ActionEvent e) {<br>                    ((File) node).delete ();<br>                }<br>            }<br>        };<br>    }<br>    <br>    public void performDefaultAction (Object node) {<br>        try {<br>            JFrame f = new JFrame ("View");<br>            f.getContentPane ().add (new JEditorPane (((File) node).toURL ()));<br>            f.pack ();<br>            f.show ();<br>        } catch (Exception e) {<br>            e.printStackTrace();<br>        }<br>    }<br>}</pre>
81
<br>
81
        <br>
82
<div style="text-align: center;"><img
82
        <div style="text-align: center;"><img
83
 src="doc-files/TreeModelExample3.JPG" title=""
83
                src="doc-files/TreeModelExample3.JPG" title=""
84
 alt="Tree Model Example 3" style="width: 642px; height: 438px;"><br>
84
                alt="Tree Model Example 3" style="width: 642px; height: 438px;"><br>
85
</div>
85
        </div>
86
<h3>Step 4.</h3>
86
        <h3>Step 4.</h3>
87
TableModel and ColumnModel adds support for additional columns to tree
87
        TableModel and ColumnModel adds support for additional columns to tree
88
view.<br>
88
        view.<br>
89
<pre style="background-color: rgb(255, 255, 102);">public class TableModelImpl implements TableModel {<br><br>    <br>    public Object getValueAt (Object node, String columnID) {<br>        try {<br>            if (node == ROOT) return null;<br>            if (columnID.equals ("sizeID")) {<br>                if (((File) node).isDirectory ()) return "&lt;dir&gt;";<br>                return "" + new FileInputStream ((File) node).getChannel ().size ();<br>            }<br>        } catch (Exception e) {<br>            e.printStackTrace ();<br>        }<br>        return "";<br>    }<br>    <br>    public boolean isReadOnly (Object node, String columnID) {<br>        return true;<br>    }<br>    <br>    public void setValueAt (Object node, String columnID, Object value) {<br>    }<br>}</pre>
89
        <pre style="background-color: rgb(255, 255, 102);">public class TableModelImpl implements TableModel {<br><br>    <br>    public Object getValueAt (Object node, String columnID) {<br>        try {<br>            if (node == ROOT) return null;<br>            if (columnID.equals ("sizeID")) {<br>                if (((File) node).isDirectory ()) return "&lt;dir&gt;";<br>                return "" + new FileInputStream ((File) node).getChannel ().size ();<br>            }<br>        } catch (Exception e) {<br>            e.printStackTrace ();<br>        }<br>        return "";<br>    }<br>    <br>    public boolean isReadOnly (Object node, String columnID) {<br>        return true;<br>    }<br>    <br>    public void setValueAt (Object node, String columnID, Object value) {<br>    }<br>}</pre>
90
And initialization of columns looks like:<br>
90
        And initialization of columns looks like:<br>
91
<pre style="background-color: rgb(255, 255, 102);">    ArrayList columns = new ArrayList ();<img
91
        <pre style="background-color: rgb(255, 255, 102);">    ArrayList columns = new ArrayList ();<img
92
 src="doc-files/TreeModelExample4.JPG" title=""
92
 src="doc-files/TreeModelExample4.JPG" title=""
93
 alt="Tree Model Example 4" style="width: 384px; height: 278px;"
93
 alt="Tree Model Example 4" style="width: 384px; height: 278px;"
94
 align="right"><br>    columns.add (new ColumnModel () {<br>        public String getID () { return "sizeID"; }<br>        public String getDisplayName () { return "size"; }<br>        public Class getType () { return String.class; }<br>    });<br>    JComponent treeTableView = Models.createView (<br>        Models.createCompoundModel (<br>            Arrays.asList (new Model[] {<br>                new TreeModelImpl (),           // TreeModel<br>                new NodeModelImpl (),           // NodeModel<br>                new TableModelImpl (),          // TableModel<br>                new NodeActionsProviderImpl (), // NodeActionsProvider<br>                columns                         // list of ColumnModel s<br>            })<br>        )<br>    );<br><br></pre>
94
 align="right"><br>    columns.add (new ColumnModel () {<br>        public String getID () { return "sizeID"; }<br>        public String getDisplayName () { return "size"; }<br>        public Class getType () { return String.class; }<br>    });<br>    JComponent treeTableView = Models.createView (<br>        Models.createCompoundModel (<br>            Arrays.asList (new Model[] {<br>                new TreeModelImpl (),           // TreeModel<br>                new NodeModelImpl (),           // NodeModel<br>                new TableModelImpl (),          // TableModel<br>                new NodeActionsProviderImpl (), // NodeActionsProvider<br>                columns                         // list of ColumnModel s<br>            })<br>        )<br>    );<br><br></pre>
95
<br>
95
        <br>
96
<br>
96
        <br>
97
<br>
97
        <br>
98
<h3>How to use Filters</h3>
98
        <h3>How to use Filters</h3>
99
We can use filters to modify content of tree table view created in our
99
        We can use filters to modify content of tree table view created in our
100
example.<br>
100
        example.<br>
101
<ul>
101
        <ul>
102
  <li><span style="font-weight: bold;">TreeModelFilter:</span> this
102
            <li><span style="font-weight: bold;">TreeModelFilter:</span> this
103
filter can be used to hide fome files, to add some virtual filesystems,
103
                filter can be used to hide fome files, to add some virtual filesystems,
104
to add content of zip files to original tree, and so on.</li>
104
                to add content of zip files to original tree, and so on.</li>
105
  <li><span style="font-weight: bold;">NodeModelFilter</span>: can be
105
            <li><span style="font-weight: bold;">NodeModelFilter</span>: can be
106
used to change names, icons or tooltips for existing files.</li>
106
                used to change names, icons or tooltips for existing files.</li>
107
  <li><span style="font-weight: bold;">TableModelFilter</span>: can be
107
            <li><span style="font-weight: bold;">TableModelFilter</span>: can be
108
used to modify content of columns.</li>
108
                used to modify content of columns.</li>
109
  <li><span style="font-weight: bold;">NodeActionsProviderFilter</span>:
109
            <li><span style="font-weight: bold;">NodeActionsProviderFilter</span>:
110
can be used to add a new actions to pup-up menus, of to redefine
110
                can be used to add a new actions to pup-up menus, of to redefine
111
default action.</li>
111
                default action.</li>
112
</ul>
112
        </ul>
113
All these actions can be done in some external module.<br>
113
        All these actions can be done in some external module.<br>
114
<br>
114
        <br>
115
</body>
115
    </body>
116
</html>
116
</html>
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/ReorderableTreeModelFilter.java (-14 / +15 lines)
Lines 39-51 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.spi.viewmodel;
42
package org.netbeans.spi.viewmodel;
44
43
45
/**
44
/**
46
 * Filters an original tree data model that supports reordering
45
 * Filters an original tree data model that supports reordering of child nodes.
47
 * of child nodes. The created {@link org.openide.nodes.Node} will contain
46
 * The created {@link org.openide.nodes.Node} will contain an implementation of
48
 * an implementation of {@link org.openide.nodes.Index} in it's lookup if
47
 * {@link org.openide.nodes.Index} in it's lookup if
49
 * {@link #canReorder(org.netbeans.spi.viewmodel.ReorderableTreeModel, java.lang.Object)}
48
 * {@link #canReorder(org.netbeans.spi.viewmodel.ReorderableTreeModel, java.lang.Object)}
50
 * returns <code>true</code>.
49
 * returns <code>true</code>.
51
 *
50
 *
Lines 56-80 Link Here
56
55
57
    /**
56
    /**
58
     * Provide if this filter implementation can reorder children nodes.
57
     * Provide if this filter implementation can reorder children nodes.
58
     *
59
     * @param original The original ReorderableTreeModel
59
     * @param original The original ReorderableTreeModel
60
     * @param parent The parent node of children that are test for reorder
60
     * @param parent The parent node of children that are test for reorder
61
     * @return <code>true</code> if this model can handle reordering of children,
61
     * @return <code>true</code> if this model can handle reordering of
62
     *         <code>false</code> otherwise
62
     * children, <code>false</code> otherwise
63
     * @throws UnknownTypeException if this model implementation is not
63
     * @throws UnknownTypeException if this model implementation is not able to
64
     *         able to decide the reorder capability for given node type
64
     * decide the reorder capability for given node type
65
     */
65
     */
66
    public boolean canReorder(ReorderableTreeModel original, Object parent) throws UnknownTypeException;
66
    public boolean canReorder(ReorderableTreeModel original, Object parent) throws UnknownTypeException;
67
67
68
    /**
68
    /**
69
     * Reorder children nodes with a given permutation.
69
     * Reorder children nodes with a given permutation.
70
     *
70
     * @param parent The parent node of children that are being reordered
71
     * @param parent The parent node of children that are being reordered
71
     * @param perm permutation with the length of current child nodes. The permutation
72
     * @param perm permutation with the length of current child nodes. The
72
     * lists the new positions of the original nodes, that is, for nodes
73
     * permutation lists the new positions of the original nodes, that is, for
73
     * <code>[A,B,C,D]</code> and permutation <code>[0,3,1,2]</code>, the final
74
     * nodes <code>[A,B,C,D]</code> and permutation <code>[0,3,1,2]</code>, the
74
     * order would be <code>[A,C,D,B]</code>.
75
     * final order would be <code>[A,C,D,B]</code>.
75
     * @throws IllegalArgumentException if the permutation is not valid
76
     * @throws IllegalArgumentException if the permutation is not valid
76
     * @throws UnknownTypeException if this model implementation is not
77
     * @throws UnknownTypeException if this model implementation is not able to
77
     *         able to perform the reorder for given node type
78
     * perform the reorder for given node type
78
     */
79
     */
79
    public void reorder(ReorderableTreeModel original, Object parent, int[] perm) throws UnknownTypeException;
80
    public void reorder(ReorderableTreeModel original, Object parent, int[] perm) throws UnknownTypeException;
80
81
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/ReorderableTreeModel.java (-17 / +18 lines)
Lines 39-55 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.spi.viewmodel;
42
package org.netbeans.spi.viewmodel;
44
43
45
/**
44
/**
46
 * Data model for tree that supports reordering
45
 * Data model for tree that supports reordering of child nodes. The created
47
 * of child nodes. The created {@link org.openide.nodes.Node} will contain
46
 * {@link org.openide.nodes.Node} will contain an implementation of
48
 * an implementation of {@link org.openide.nodes.Index} in it's lookup
47
 * {@link org.openide.nodes.Index} in it's lookup if
49
 * if {@link #canReorder(java.lang.Object)} returns <code>true</code>.
48
 * {@link #canReorder(java.lang.Object)} returns <code>true</code>.
50
 * <p>
49
 * <p>
51
 * When used together with {@link DnDNodeModel}, children can be reordered
50
 * When used together with {@link DnDNodeModel}, children can be reordered by
52
 * by Drag and Drop.
51
 * Drag and Drop.
53
 *
52
 *
54
 * @author Martin Entlicher
53
 * @author Martin Entlicher
55
 * @since 1.25
54
 * @since 1.25
Lines 58-81 Link Here
58
57
59
    /**
58
    /**
60
     * Provide if this model implementation can reorder children nodes.
59
     * Provide if this model implementation can reorder children nodes.
60
     *
61
     * @param parent The parent node of children that are test for reorder
61
     * @param parent The parent node of children that are test for reorder
62
     * @return <code>true</code> if this model can handle reordering of children,
62
     * @return <code>true</code> if this model can handle reordering of
63
     *         <code>false</code> otherwise
63
     * children, <code>false</code> otherwise
64
     * @throws UnknownTypeException if this model implementation is not
64
     * @throws UnknownTypeException if this model implementation is not able to
65
     *         able to decide the reorder capability for given node type
65
     * decide the reorder capability for given node type
66
     */
66
     */
67
    public boolean canReorder(Object parent) throws UnknownTypeException;
67
    public boolean canReorder(Object parent) throws UnknownTypeException;
68
68
69
    /**
69
    /**
70
     * Reorder children nodes with a given permutation.
70
     * Reorder children nodes with a given permutation.
71
     *
71
     * @param parent The parent node of children that are being reordered
72
     * @param parent The parent node of children that are being reordered
72
     * @param perm permutation with the length of current child nodes. The permutation
73
     * @param perm permutation with the length of current child nodes. The
73
     * lists the new positions of the original nodes, that is, for nodes
74
     * permutation lists the new positions of the original nodes, that is, for
74
     * <code>[A,B,C,D]</code> and permutation <code>[0,3,1,2]</code>, the final
75
     * nodes <code>[A,B,C,D]</code> and permutation <code>[0,3,1,2]</code>, the
75
     * order would be <code>[A,C,D,B]</code>.
76
     * final order would be <code>[A,C,D,B]</code>.
76
     * @throws IllegalArgumentException if the permutation is not valid
77
     * @throws IllegalArgumentException if the permutation is not valid
77
     * @throws UnknownTypeException if this model implementation is not
78
     * @throws UnknownTypeException if this model implementation is not able to
78
     *         able to perform the reorder for given node type
79
     * perform the reorder for given node type
79
     */
80
     */
80
    public void reorder(Object parent, int[] perm) throws UnknownTypeException;
81
    public void reorder(Object parent, int[] perm) throws UnknownTypeException;
81
82
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/SelectionChangedListener.java (+83 lines)
Line 0 Link Here
1
//<editor-fold defaultstate="collapsed" desc="CDDL">
2
/*COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
3
*
4
* 1. Definitions.
5
* 1.1. "Contributor" means each individual or entity that creates or contributes to the creation of Modifications.
6
* 1.2. "Contributor Version" means the combination of the Original Software, prior Modifications used by a Contributor (if any), and the Modifications made by that particular Contributor.
7
* 1.3. "Covered Software" means (a) the Original Software, or (b) Modifications, or (c) the combination of files containing Original Software with files containing Modifications, in each case including portions thereof.
8
* 1.4. "Executable" means the Covered Software in any form other than Source Code.
9
* 1.5. "Initial Developer" means the individual or entity that first makes Original Software available under this License.
10
* 1.6. "Larger Work" means a work which combines Covered Software or portions thereof with code not governed by the terms of this License.
11
* 1.7. "License" means this document.
12
* 1.8. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein.
13
* 1.9 "Modifications" means the Source Code and Executable form of any of the following:
14
* A. Any file that results from an addition to, deletion from or modification of the contents of a file containing Original Software or previous Modifications;
15
* B. Any new file that contains any part of the Original Software or previous Modification; or
16
* C. Any new file that is contributed or otherwise made available under the terms of this License.
17
* 1.10. "Original Software" means the Source Code and Executable form of computer software code that is originally released under this License.
18
* 1.11. "Patent Claims" means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor.
19
* 1.12. "Source Code" means (a) the common form of computer software code in which modifications are made and (b) associated documentation included in or with such code.
20
* 1.13. "You" (or "Your") means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
21
* 2. License Grants.
22
* 2.1. The Initial Developer Grant.
23
* Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, the Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license:
24
* (a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer, to use, reproduce, modify, display, perform, sublicense and distribute the Original Software (or portions thereof), with or without Modifications, and/or as part of a Larger Work; and
25
* (b) under Patent Claims infringed by the making, using or selling of Original Software, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Software (or portions thereof).
26
* (c) The licenses granted in Sections 2.1(a) and (b) are effective on the date Initial Developer first distributes or otherwise makes the Original Software available to a third party under the terms of this License.
27
* (d) Notwithstanding Section 2.1(b) above, no patent license is granted: (1) for code that You delete from the Original Software, or (2) for infringements caused by: (i) the modification of the Original Software, or (ii) the combination of the Original Software with other software or devices.
28
* 2.2. Contributor Grant.
29
* Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
30
* (a) under intellectual property rights (other than patent or trademark) Licensable by Contributor to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof), either on an unmodified basis, with other Modifications, as Covered Software and/or as part of a Larger Work; and
31
* (b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: (1) Modifications made by that Contributor (or portions thereof); and (2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination).
32
* (c) The licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first distributes or otherwise makes the Modifications available to a third party.
33
* (d) Notwithstanding Section 2.2(b) above, no patent license is granted: (1) for any code that Contributor has deleted from the Contributor Version; (2) for infringements caused by: (i) third party modifications of Contributor Version, or (ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or (3) under Patent Claims infringed by Covered Software in the absence of Modifications made by that Contributor.
34
* 3. Distribution Obligations.
35
* 3.1. Availability of Source Code.
36
* Any Covered Software that You distribute or otherwise make available in Executable form must also be made available in Source Code form and that Source Code form must be distributed only under the terms of this License. You must include a copy of this License with every copy of the Source Code form of the Covered Software You distribute or otherwise make available. You must inform recipients of any such Covered Software in Executable form as to how they can obtain such Covered Software in Source Code form in a reasonable manner on or through a medium customarily used for software exchange.
37
* 3.2. Modifications.
38
* The Modifications that You create or to which You contribute are governed by the terms of this License. You represent that You believe Your Modifications are Your original creation(s) and/or You have sufficient rights to grant the rights conveyed by this License.
39
* 3.3. Required Notices.
40
* You must include a notice in each of Your Modifications that identifies You as the Contributor of the Modification. You may not remove or alter any copyright, patent or trademark notices contained within the Covered Software, or any notices of licensing or any descriptive text giving attribution to any Contributor or the Initial Developer.
41
* 3.4. Application of Additional Terms.
42
* You may not offer or impose any terms on any Covered Software in Source Code form that alters or restricts the applicable version of this License or the recipients� rights hereunder. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, you may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear that any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer.
43
* 3.5. Distribution of Executable Versions.
44
* You may distribute the Executable form of the Covered Software under the terms of this License or under the terms of a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable form does not attempt to limit or alter the recipient�s rights in the Source Code form from the rights set forth in this License. If You distribute the Covered Software in Executable form under a different license, You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer.
45
* 3.6. Larger Works.
46
* You may create a Larger Work by combining Covered Software with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Software.
47
* 4. Versions of the License.
48
* 4.1. New Versions.
49
* Oracle Corp. is the initial license steward and may publish revised and/or new versions of this License from time to time. Each version will be given a distinguishing version number. Except as provided in Section 4.3, no one other than the license steward has the right to modify this License.
50
* 4.2. Effect of New Versions.
51
* You may always continue to use, distribute or otherwise make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. If the Initial Developer includes a notice in the Original Software prohibiting it from being distributed or otherwise made available under any subsequent version of the License, You must distribute and make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. Otherwise, You may also choose to use, distribute or otherwise make the Covered Software available under the terms of any subsequent version of the License published by the license steward.
52
* 4.3. Modified Versions.
53
* When You are an Initial Developer and You want to create a new license for Your Original Software, You may create and use a modified version of this License if You: (a) rename the license and remove any references to the name of the license steward (except to note that the license differs from this License); and (b) otherwise make it clear that the license contains terms which differ from this License.
54
* 5. DISCLAIMER OF WARRANTY.
55
* COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
56
* 6. TERMINATION.
57
* 6.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive.
58
* 6.2. If You assert a patent infringement claim (excluding declaratory judgment actions) against Initial Developer or a Contributor (the Initial Developer or Contributor against whom You assert such claim is referred to as "Participant") alleging that the Participant Software (meaning the Contributor Version where the Participant is a Contributor or the Original Software where the Participant is the Initial Developer) directly or indirectly infringes any patent, then any and all rights granted directly or indirectly to You by such Participant, the Initial Developer (if the Initial Developer is not the Participant) and all Contributors under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively and automatically at the expiration of such 60 day notice period, unless if within such 60 day period You withdraw Your claim with respect to the Participant Software against such Participant either unilaterally or pursuant to a written agreement with Participant.
59
* 6.3. In the event of termination under Sections 6.1 or 6.2 above, all end user licenses that have been validly granted by You or any distributor hereunder prior to termination (excluding licenses granted to You by any distributor) shall survive termination.
60
* 7. LIMITATION OF LIABILITY.
61
* UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTY�S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
62
* 8. U.S. GOVERNMENT END USERS.
63
* The Covered Software is a "commercial item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" (as that term is defined at 48 C.F.R. �252.227-7014(a)(1)) and "commercial computer software documentation" as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Software with only those rights set forth herein. This U.S. Government Rights clause is in lieu of, and supersedes, any other FAR, DFAR, or other clause or provision that addresses Government rights in computer software under this License.
64
* 9. MISCELLANEOUS.
65
* This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by the law of the jurisdiction specified in a notice contained within the Original Software (except to the extent applicable law, if any, provides otherwise), excluding such jurisdiction�s conflict-of-law provisions. Any litigation relating to this License shall be subject to the jurisdiction of the courts located in the jurisdiction and venue specified in a notice contained within the Original Software, with the losing party responsible for costs, including, without limitation, court costs and reasonable attorneys� fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. You agree that You alone are responsible for compliance with the United States export administration regulations (and the export control laws and regulation of any other countries) when You use, distribute or otherwise make available any Covered Software.
66
* 10. RESPONSIBILITY FOR CLAIMS.
67
* As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability.
68
* NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL)
69
* The code released under the CDDL shall be governed by the laws of the State of California (excluding conflict-of-law provisions). Any litigation relating to this License shall be subject to the jurisdiction of the Federal Courts of the Northern District of California and the state courts of the State of California, with venue lying in Santa Clara County, California.
70
 */
71
//</editor-fold>
72
package org.netbeans.spi.viewmodel;
73
74
import java.util.Set;
75
76
/**
77
 *
78
 * @author matteo
79
 */
80
public interface SelectionChangedListener<T> {
81
82
    void selectionChanged(Set<T> selection);
83
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/SelectionModel.java (+89 lines)
Line 0 Link Here
1
//<editor-fold defaultstate="collapsed" desc="CDDL">
2
/*COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
3
*
4
* 1. Definitions.
5
* 1.1. "Contributor" means each individual or entity that creates or contributes to the creation of Modifications.
6
* 1.2. "Contributor Version" means the combination of the Original Software, prior Modifications used by a Contributor (if any), and the Modifications made by that particular Contributor.
7
* 1.3. "Covered Software" means (a) the Original Software, or (b) Modifications, or (c) the combination of files containing Original Software with files containing Modifications, in each case including portions thereof.
8
* 1.4. "Executable" means the Covered Software in any form other than Source Code.
9
* 1.5. "Initial Developer" means the individual or entity that first makes Original Software available under this License.
10
* 1.6. "Larger Work" means a work which combines Covered Software or portions thereof with code not governed by the terms of this License.
11
* 1.7. "License" means this document.
12
* 1.8. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein.
13
* 1.9 "Modifications" means the Source Code and Executable form of any of the following:
14
* A. Any file that results from an addition to, deletion from or modification of the contents of a file containing Original Software or previous Modifications;
15
* B. Any new file that contains any part of the Original Software or previous Modification; or
16
* C. Any new file that is contributed or otherwise made available under the terms of this License.
17
* 1.10. "Original Software" means the Source Code and Executable form of computer software code that is originally released under this License.
18
* 1.11. "Patent Claims" means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor.
19
* 1.12. "Source Code" means (a) the common form of computer software code in which modifications are made and (b) associated documentation included in or with such code.
20
* 1.13. "You" (or "Your") means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
21
* 2. License Grants.
22
* 2.1. The Initial Developer Grant.
23
* Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, the Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license:
24
* (a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer, to use, reproduce, modify, display, perform, sublicense and distribute the Original Software (or portions thereof), with or without Modifications, and/or as part of a Larger Work; and
25
* (b) under Patent Claims infringed by the making, using or selling of Original Software, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Software (or portions thereof).
26
* (c) The licenses granted in Sections 2.1(a) and (b) are effective on the date Initial Developer first distributes or otherwise makes the Original Software available to a third party under the terms of this License.
27
* (d) Notwithstanding Section 2.1(b) above, no patent license is granted: (1) for code that You delete from the Original Software, or (2) for infringements caused by: (i) the modification of the Original Software, or (ii) the combination of the Original Software with other software or devices.
28
* 2.2. Contributor Grant.
29
* Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
30
* (a) under intellectual property rights (other than patent or trademark) Licensable by Contributor to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof), either on an unmodified basis, with other Modifications, as Covered Software and/or as part of a Larger Work; and
31
* (b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: (1) Modifications made by that Contributor (or portions thereof); and (2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination).
32
* (c) The licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first distributes or otherwise makes the Modifications available to a third party.
33
* (d) Notwithstanding Section 2.2(b) above, no patent license is granted: (1) for any code that Contributor has deleted from the Contributor Version; (2) for infringements caused by: (i) third party modifications of Contributor Version, or (ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or (3) under Patent Claims infringed by Covered Software in the absence of Modifications made by that Contributor.
34
* 3. Distribution Obligations.
35
* 3.1. Availability of Source Code.
36
* Any Covered Software that You distribute or otherwise make available in Executable form must also be made available in Source Code form and that Source Code form must be distributed only under the terms of this License. You must include a copy of this License with every copy of the Source Code form of the Covered Software You distribute or otherwise make available. You must inform recipients of any such Covered Software in Executable form as to how they can obtain such Covered Software in Source Code form in a reasonable manner on or through a medium customarily used for software exchange.
37
* 3.2. Modifications.
38
* The Modifications that You create or to which You contribute are governed by the terms of this License. You represent that You believe Your Modifications are Your original creation(s) and/or You have sufficient rights to grant the rights conveyed by this License.
39
* 3.3. Required Notices.
40
* You must include a notice in each of Your Modifications that identifies You as the Contributor of the Modification. You may not remove or alter any copyright, patent or trademark notices contained within the Covered Software, or any notices of licensing or any descriptive text giving attribution to any Contributor or the Initial Developer.
41
* 3.4. Application of Additional Terms.
42
* You may not offer or impose any terms on any Covered Software in Source Code form that alters or restricts the applicable version of this License or the recipients� rights hereunder. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, you may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear that any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer.
43
* 3.5. Distribution of Executable Versions.
44
* You may distribute the Executable form of the Covered Software under the terms of this License or under the terms of a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable form does not attempt to limit or alter the recipient�s rights in the Source Code form from the rights set forth in this License. If You distribute the Covered Software in Executable form under a different license, You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer.
45
* 3.6. Larger Works.
46
* You may create a Larger Work by combining Covered Software with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Software.
47
* 4. Versions of the License.
48
* 4.1. New Versions.
49
* Oracle Corp. is the initial license steward and may publish revised and/or new versions of this License from time to time. Each version will be given a distinguishing version number. Except as provided in Section 4.3, no one other than the license steward has the right to modify this License.
50
* 4.2. Effect of New Versions.
51
* You may always continue to use, distribute or otherwise make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. If the Initial Developer includes a notice in the Original Software prohibiting it from being distributed or otherwise made available under any subsequent version of the License, You must distribute and make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. Otherwise, You may also choose to use, distribute or otherwise make the Covered Software available under the terms of any subsequent version of the License published by the license steward.
52
* 4.3. Modified Versions.
53
* When You are an Initial Developer and You want to create a new license for Your Original Software, You may create and use a modified version of this License if You: (a) rename the license and remove any references to the name of the license steward (except to note that the license differs from this License); and (b) otherwise make it clear that the license contains terms which differ from this License.
54
* 5. DISCLAIMER OF WARRANTY.
55
* COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
56
* 6. TERMINATION.
57
* 6.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive.
58
* 6.2. If You assert a patent infringement claim (excluding declaratory judgment actions) against Initial Developer or a Contributor (the Initial Developer or Contributor against whom You assert such claim is referred to as "Participant") alleging that the Participant Software (meaning the Contributor Version where the Participant is a Contributor or the Original Software where the Participant is the Initial Developer) directly or indirectly infringes any patent, then any and all rights granted directly or indirectly to You by such Participant, the Initial Developer (if the Initial Developer is not the Participant) and all Contributors under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively and automatically at the expiration of such 60 day notice period, unless if within such 60 day period You withdraw Your claim with respect to the Participant Software against such Participant either unilaterally or pursuant to a written agreement with Participant.
59
* 6.3. In the event of termination under Sections 6.1 or 6.2 above, all end user licenses that have been validly granted by You or any distributor hereunder prior to termination (excluding licenses granted to You by any distributor) shall survive termination.
60
* 7. LIMITATION OF LIABILITY.
61
* UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTY�S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
62
* 8. U.S. GOVERNMENT END USERS.
63
* The Covered Software is a "commercial item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" (as that term is defined at 48 C.F.R. �252.227-7014(a)(1)) and "commercial computer software documentation" as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Software with only those rights set forth herein. This U.S. Government Rights clause is in lieu of, and supersedes, any other FAR, DFAR, or other clause or provision that addresses Government rights in computer software under this License.
64
* 9. MISCELLANEOUS.
65
* This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by the law of the jurisdiction specified in a notice contained within the Original Software (except to the extent applicable law, if any, provides otherwise), excluding such jurisdiction�s conflict-of-law provisions. Any litigation relating to this License shall be subject to the jurisdiction of the courts located in the jurisdiction and venue specified in a notice contained within the Original Software, with the losing party responsible for costs, including, without limitation, court costs and reasonable attorneys� fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. You agree that You alone are responsible for compliance with the United States export administration regulations (and the export control laws and regulation of any other countries) when You use, distribute or otherwise make available any Covered Software.
66
* 10. RESPONSIBILITY FOR CLAIMS.
67
* As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability.
68
* NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL)
69
* The code released under the CDDL shall be governed by the laws of the State of California (excluding conflict-of-law provisions). Any litigation relating to this License shall be subject to the jurisdiction of the Federal Courts of the Northern District of California and the state courts of the State of California, with venue lying in Santa Clara County, California.
70
 */
71
//</editor-fold>
72
package org.netbeans.spi.viewmodel;
73
74
import java.util.Set;
75
76
/**
77
 *
78
 * @author matteo
79
 */
80
public interface SelectionModel<T> extends Model {
81
82
    void addSelectionChangeListener(SelectionChangedListener<T> l);
83
84
    void removeSelectionChangeListener(SelectionChangedListener<T> l);
85
86
    Set<T> getSelection();
87
88
    void setSelection(Set<T> wellsSelection);
89
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/SuperNodeModel.java (-3 / +2 lines)
Lines 39-50 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.spi.viewmodel;
42
package org.netbeans.spi.viewmodel;
44
43
45
/**
44
/**
46
 * NodeModel covering all known extensions.
45
 * NodeModel covering all known extensions. Not public API, created for
47
 * Not public API, created for implementation purpose only.
46
 * implementation purpose only.
48
 *
47
 *
49
 * @author Martin Entlicher
48
 * @author Martin Entlicher
50
 */
49
 */
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/TableHTMLModelFilter.java (-29 / +33 lines)
Lines 42-102 Link Here
42
package org.netbeans.spi.viewmodel;
42
package org.netbeans.spi.viewmodel;
43
43
44
/**
44
/**
45
 * Use this to separate value and the HTML value.
45
 * Use this to separate value and the HTML value. Implement this filter to
46
 * Implement this filter to override the behavior of any registered {@link TableHTMLModel}s.
46
 * override the behavior of any registered {@link TableHTMLModel}s.
47
 * 
47
 *
48
 * @author Martin Entlicher
48
 * @author Martin Entlicher
49
 * @since 1.42
49
 * @since 1.42
50
 * @see TableHTMLModel
50
 * @see TableHTMLModel
51
 */
51
 */
52
public interface TableHTMLModelFilter extends Model {
52
public interface TableHTMLModelFilter extends Model {
53
    
53
54
    /**
54
    /**
55
     * Test if the model has a HTML value.
55
     * Test if the model has a HTML value. For backward compatibility, if it
56
     * For backward compatibility, if it returns <code>false</code>,
56
     * returns <code>false</code>, HTML value is is taken from the String value,
57
     * HTML value is is taken from the String value, if it contains some.
57
     * if it contains some. If this is not desired, return true here and null
58
     * If this is not desired, return true here and null from
58
     * from
59
     * {@link #getHTMLValueAt(org.netbeans.spi.viewmodel.TableHTMLModel, java.lang.Object, java.lang.String)}.
59
     * {@link #getHTMLValueAt(org.netbeans.spi.viewmodel.TableHTMLModel, java.lang.Object, java.lang.String)}.
60
     *
60
     * @param original The original {@link TableHTMLModel}
61
     * @param original The original {@link TableHTMLModel}
61
     * @param node an object returned from {@link TreeModel#getChildren(java.lang.Object, int, int) }
62
     * @param node an object returned from {@link TreeModel#getChildren(java.lang.Object, int, int)
62
     *             for this row
63
     * }
64
     * for this row
63
     * @param columnID an id of column defined by {@link ColumnModel#getID()}
65
     * @param columnID an id of column defined by {@link ColumnModel#getID()}
64
     * @return <code>true</code> if there is some HTML value to be returned
66
     * @return <code>true</code> if there is some HTML value to be returned from
65
     *         from {@link #getHTMLValueAt(org.netbeans.spi.viewmodel.TableHTMLModel, java.lang.Object, java.lang.String)},
67
     * {@link #getHTMLValueAt(org.netbeans.spi.viewmodel.TableHTMLModel, java.lang.Object, java.lang.String)},
66
     *         <code>false</code> otherwise.
68
     * <code>false</code> otherwise. When <code>false</code> is returned,
67
     *         When <code>false</code> is returned,
69
     * {@link #getHTMLValueAt(org.netbeans.spi.viewmodel.TableHTMLModel, java.lang.Object, java.lang.String)}
68
     *         {@link #getHTMLValueAt(org.netbeans.spi.viewmodel.TableHTMLModel, java.lang.Object, java.lang.String)}
70
     * is not called.
69
     *         is not called.
71
     * @throws UnknownTypeException if there is nothing to be provided for the
70
     * @throws UnknownTypeException if there is nothing to be provided for the given
72
     * given parameter type
71
     *         parameter type
72
     */
73
     */
73
    boolean hasHTMLValueAt(TableHTMLModel original, Object node, String columnID) throws UnknownTypeException;
74
    boolean hasHTMLValueAt(TableHTMLModel original, Object node, String columnID) throws UnknownTypeException;
74
    
75
75
    /**
76
    /**
76
     * Get the HTML value.
77
     * Get the HTML value.
77
     * 
78
     *
78
     * @param original The original {@link TableHTMLModel}
79
     * @param original The original {@link TableHTMLModel}
79
     * @param node an object returned from {@link TreeModel#getChildren(java.lang.Object, int, int) }
80
     * @param node an object returned from {@link TreeModel#getChildren(java.lang.Object, int, int)
80
     *             for this row
81
     * }
82
     * for this row
81
     * @param columnID an id of column defined by {@link ColumnModel#getID()}
83
     * @param columnID an id of column defined by {@link ColumnModel#getID()}
82
     * @return The HTML value, or <code>null</code> when no HTML value is provided.
84
     * @return The HTML value, or <code>null</code> when no HTML value is
83
     * @throws UnknownTypeException if there is nothing to be provided for the given
85
     * provided.
84
     *         parameter type
86
     * @throws UnknownTypeException if there is nothing to be provided for the
85
     * @see #hasHTMLValueAt(org.netbeans.spi.viewmodel.TableHTMLModel, java.lang.Object, java.lang.String)
87
     * given parameter type
88
     * @see #hasHTMLValueAt(org.netbeans.spi.viewmodel.TableHTMLModel,
89
     * java.lang.Object, java.lang.String)
86
     */
90
     */
87
    String getHTMLValueAt(TableHTMLModel original, Object node, String columnID) throws UnknownTypeException;
91
    String getHTMLValueAt(TableHTMLModel original, Object node, String columnID) throws UnknownTypeException;
88
    
92
89
    /**
93
    /**
90
     * Registers given listener.
94
     * Registers given listener.
91
     *
95
     *
92
     * @param l the listener to add
96
     * @param l the listener to add
93
     */
97
     */
94
    public abstract void addModelListener (ModelListener l);
98
    public abstract void addModelListener(ModelListener l);
95
99
96
    /**
100
    /**
97
     * Unregisters given listener.
101
     * Unregisters given listener.
98
     *
102
     *
99
     * @param l the listener to remove
103
     * @param l the listener to remove
100
     */
104
     */
101
    public abstract void removeModelListener (ModelListener l);
105
    public abstract void removeModelListener(ModelListener l);
102
}
106
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/TableHTMLModel.java (-29 / +31 lines)
Lines 42-88 Link Here
42
package org.netbeans.spi.viewmodel;
42
package org.netbeans.spi.viewmodel;
43
43
44
/**
44
/**
45
 * Use this to separate value and the HTML value.
45
 * Use this to separate value and the HTML value. When displaying a property
46
 * When displaying a property value, then if the value is a String and if it contains
46
 * value, then if the value is a String and if it contains a HTML code, it's
47
 * a HTML code, it's automatically rendered as HTML. The HTML code is then
47
 * automatically rendered as HTML. The HTML code is then stripped out to get the
48
 * stripped out to get the raw value.
48
 * raw value. If this is not desired or if it's necessary to provide a value and
49
 * If this is not desired or if it's necessary to provide a value and HTML code
49
 * HTML code that differs from each other, implement this model.
50
 * that differs from each other, implement this model.
50
 *
51
 * 
52
 * @author Martin Entlicher
51
 * @author Martin Entlicher
53
 * @since 1.42
52
 * @since 1.42
54
 * @see TableHTMLModelFilter
53
 * @see TableHTMLModelFilter
55
 */
54
 */
56
public interface TableHTMLModel extends TableModel {
55
public interface TableHTMLModel extends TableModel {
57
    
56
58
    /**
57
    /**
59
     * Test if the model has a HTML value.
58
     * Test if the model has a HTML value. For backward compatibility, if it
60
     * For backward compatibility, if it returns <code>false</code>,
59
     * returns <code>false</code>, HTML value is is taken from the String value,
61
     * HTML value is is taken from the String value, if it contains some.
60
     * if it contains some. If this is not desired, return true here and null
62
     * If this is not desired, return true here and null from
61
     * from {@link #getHTMLValueAt(java.lang.Object, java.lang.String)}.
63
     * {@link #getHTMLValueAt(java.lang.Object, java.lang.String)}.
62
     *
64
     * @param node an object returned from {@link TreeModel#getChildren(java.lang.Object, int, int) }
63
     * @param node an object returned from {@link TreeModel#getChildren(java.lang.Object, int, int)
65
     *             for this row
64
     * }
65
     * for this row
66
     * @param columnID an id of column defined by {@link ColumnModel#getID()}
66
     * @param columnID an id of column defined by {@link ColumnModel#getID()}
67
     * @return <code>true</code> if there is some HTML value to be returned
67
     * @return <code>true</code> if there is some HTML value to be returned from
68
     *         from {@link #getHTMLValueAt(java.lang.Object, java.lang.String)},
68
     * {@link #getHTMLValueAt(java.lang.Object, java.lang.String)},
69
     *         <code>false</code> otherwise.
69
     * <code>false</code> otherwise. When <code>false</code> is returned,
70
     *         When <code>false</code> is returned,
70
     * {@link #getHTMLValueAt(java.lang.Object, java.lang.String)} is not
71
     *         {@link #getHTMLValueAt(java.lang.Object, java.lang.String)} is not called.
71
     * called.
72
     * @throws UnknownTypeException if there is nothing to be provided for the given
72
     * @throws UnknownTypeException if there is nothing to be provided for the
73
     *         parameter type
73
     * given parameter type
74
     */
74
     */
75
    boolean hasHTMLValueAt(Object node, String columnID) throws UnknownTypeException;
75
    boolean hasHTMLValueAt(Object node, String columnID) throws UnknownTypeException;
76
    
76
77
    /**
77
    /**
78
     * Get the HTML value.
78
     * Get the HTML value.
79
     * 
79
     *
80
     * @param node an object returned from {@link TreeModel#getChildren(java.lang.Object, int, int) }
80
     * @param node an object returned from {@link TreeModel#getChildren(java.lang.Object, int, int)
81
     *             for this row
81
     * }
82
     * for this row
82
     * @param columnID an id of column defined by {@link ColumnModel#getID()}
83
     * @param columnID an id of column defined by {@link ColumnModel#getID()}
83
     * @return The HTML value, or <code>null</code> when no HTML value is provided.
84
     * @return The HTML value, or <code>null</code> when no HTML value is
84
     * @throws UnknownTypeException if there is nothing to be provided for the given
85
     * provided.
85
     *         parameter type
86
     * @throws UnknownTypeException if there is nothing to be provided for the
87
     * given parameter type
86
     * @see #hasHTMLValueAt(java.lang.Object, java.lang.String)
88
     * @see #hasHTMLValueAt(java.lang.Object, java.lang.String)
87
     */
89
     */
88
    String getHTMLValueAt(Object node, String columnID) throws UnknownTypeException;
90
    String getHTMLValueAt(Object node, String columnID) throws UnknownTypeException;
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/TableModelFilter.java (-54 / +49 lines)
Lines 41-136 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
import java.beans.PropertyEditor;
48
import javax.swing.table.TableCellEditor;
49
import javax.swing.table.TableCellRenderer;
50
51
52
/**
46
/**
53
 * Allows to filter content of some existing {@link TableModel}. You can add
47
 * Allows to filter content of some existing {@link TableModel}. You can add a
54
 * a new column, remmove some existing one, or change content of some existing
48
 * new column, remmove some existing one, or change content of some existing
55
 * column.
49
 * column.
56
 *
50
 *
57
 * @author   Jan Jancura
51
 * @author Jan Jancura
58
 */
52
 */
59
public interface TableModelFilter extends Model {
53
public interface TableModelFilter extends Model {
60
54
61
62
    /**
55
    /**
63
     * Returns filterred value to be displayed in column <code>columnID</code>
56
     * Returns filterred value to be displayed in column <code>columnID</code>
64
     * and row <code>node</code>. Column ID is defined in by 
57
     * and row <code>node</code>. Column ID is defined in by
65
     * {@link ColumnModel#getID}, and rows are defined by values returned from 
58
     * {@link ColumnModel#getID}, and rows are defined by values returned from
66
     * {@link TreeModel#getChildren}. You should not throw UnknownTypeException
59
     * {@link TreeModel#getChildren}. You should not throw UnknownTypeException
67
     * directly from this method!
60
     * directly from this method!
68
     *
61
     *
69
     * @param   original the original table model
62
     * @param original the original table model
70
     * @param   node a object returned from {@link TreeModel#getChildren} for this row
63
     * @param node a object returned from {@link TreeModel#getChildren} for this
71
     * @param   columnID a id of column defined by {@link ColumnModel#getID}
64
     * row
72
     * @throws  UnknownTypeException this exception can be thrown from 
65
     * @param columnID a id of column defined by {@link ColumnModel#getID}
73
     *          <code>original.getValueAt (...)</code> method call only!
66
     * @throws UnknownTypeException this exception can be thrown from
67
     * <code>original.getValueAt (...)</code> method call only!
74
     *
68
     *
75
     * @return value of variable representing given position in tree table.
69
     * @return value of variable representing given position in tree table.
76
     */
70
     */
77
    public abstract Object getValueAt (
71
    public abstract Object getValueAt(
78
        TableModel original,
72
            TableModel original,
79
        Object node, 
73
            Object node,
80
        String columnID
74
            String columnID
81
    ) throws UnknownTypeException;
75
    ) throws UnknownTypeException;
82
    
76
83
    /**
77
    /**
84
     * Filters original isReadOnly value from given table model. You should 
78
     * Filters original isReadOnly value from given table model. You should not
85
     * not throw UnknownTypeException
79
     * throw UnknownTypeException directly from this method!
86
     * directly from this method!
87
     *
80
     *
88
     * @param  original the original table model
81
     * @param original the original table model
89
     * @param  node a object returned from {@link TreeModel#getChildren} for this row
82
     * @param node a object returned from {@link TreeModel#getChildren} for this
90
     * @param  columnID a id of column defined by {@link ColumnModel#getID}
83
     * row
91
     * @throws  UnknownTypeException this exception can be thrown from 
84
     * @param columnID a id of column defined by {@link ColumnModel#getID}
92
     *          <code>original.isReadOnly (...)</code> method call only!
85
     * @throws UnknownTypeException this exception can be thrown from
86
     * <code>original.isReadOnly (...)</code> method call only!
93
     *
87
     *
94
     * @return true if variable on given position is read only
88
     * @return true if variable on given position is read only
95
     */
89
     */
96
    public abstract boolean isReadOnly (
90
    public abstract boolean isReadOnly(
97
        TableModel original,
91
            TableModel original,
98
        Object node, 
92
            Object node,
99
        String columnID
93
            String columnID
100
    ) throws UnknownTypeException;
94
    ) throws UnknownTypeException;
101
    
95
102
    /**
96
    /**
103
     * Changes a value displayed in column <code>columnID</code>
97
     * Changes a value displayed in column <code>columnID</code> and row
104
     * and row <code>node</code>. Column ID is defined in by 
98
     * <code>node</code>. Column ID is defined in by {@link ColumnModel#getID},
105
     * {@link ColumnModel#getID}, and rows are defined by values returned from 
99
     * and rows are defined by values returned from
106
     * {@link TreeModel#getChildren}. You should not throw UnknownTypeException
100
     * {@link TreeModel#getChildren}. You should not throw UnknownTypeException
107
     * directly from this method!
101
     * directly from this method!
108
     *
102
     *
109
     * @param  original the original table model
103
     * @param original the original table model
110
     * @param  node a object returned from {@link TreeModel#getChildren} for this row
104
     * @param node a object returned from {@link TreeModel#getChildren} for this
111
     * @param  columnID a id of column defined by {@link ColumnModel#getID}
105
     * row
112
     * @param  value a new value of variable on given position
106
     * @param columnID a id of column defined by {@link ColumnModel#getID}
113
     * @throws  UnknownTypeException this exception can be thrown from 
107
     * @param value a new value of variable on given position
114
     *          <code>original.setValueAt (...)</code> method call only!
108
     * @throws UnknownTypeException this exception can be thrown from
109
     * <code>original.setValueAt (...)</code> method call only!
115
     */
110
     */
116
    public abstract void setValueAt (
111
    public abstract void setValueAt(
117
        TableModel original,
112
            TableModel original,
118
        Object node, 
113
            Object node,
119
        String columnID, 
114
            String columnID,
120
        Object value
115
            Object value
121
    ) throws UnknownTypeException;
116
    ) throws UnknownTypeException;
122
117
123
    /** 
118
    /**
124
     * Registers given listener.
119
     * Registers given listener.
125
     * 
120
     *
126
     * @param l the listener to add
121
     * @param l the listener to add
127
     */
122
     */
128
    public abstract void addModelListener (ModelListener l);
123
    public abstract void addModelListener(ModelListener l);
129
124
130
    /** 
125
    /**
131
     * Unregisters given listener.
126
     * Unregisters given listener.
132
     *
127
     *
133
     * @param l the listener to remove
128
     * @param l the listener to remove
134
     */
129
     */
135
    public abstract void removeModelListener (ModelListener l);
130
    public abstract void removeModelListener(ModelListener l);
136
}
131
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/TableModel.java (-32 / +31 lines)
Lines 41-117 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
48
/**
46
/**
49
 * Adds support for columns to basic {@link TreeModel}.
47
 * Adds support for columns to basic {@link TreeModel}.
50
 *
48
 *
51
 * @author   Jan Jancura
49
 * @author Jan Jancura
52
 */
50
 */
53
public interface TableModel extends Model {
51
public interface TableModel extends Model {
54
52
55
56
    /**
53
    /**
57
     * Returns value to be displayed in column <code>columnID</code>
54
     * Returns value to be displayed in column <code>columnID</code> and row
58
     * and row identified by <code>node</code>. Column ID is defined in by
55
     * identified by <code>node</code>. Column ID is defined in by
59
     * {@link ColumnModel#getID}, and rows are defined by values returned from
56
     * {@link ColumnModel#getID}, and rows are defined by values returned from
60
     * {@link org.netbeans.spi.viewmodel.TreeModel#getChildren}.
57
     * {@link org.netbeans.spi.viewmodel.TreeModel#getChildren}.
61
     *
58
     *
62
     * @param node a object returned from 
59
     * @param node a object returned from
63
     *         {@link org.netbeans.spi.viewmodel.TreeModel#getChildren} for this row
60
     * {@link org.netbeans.spi.viewmodel.TreeModel#getChildren} for this row
64
     * @param columnID a id of column defined by {@link ColumnModel#getID}
61
     * @param columnID a id of column defined by {@link ColumnModel#getID}
65
     * @throws UnknownTypeException if there is no TableModel defined for given
62
     * @throws UnknownTypeException if there is no TableModel defined for given
66
     *         parameter type
63
     * parameter type
67
     *
64
     *
68
     * @return value of variable representing given position in tree table.
65
     * @return value of variable representing given position in tree table.
69
     */
66
     */
70
    public abstract Object getValueAt (Object node, String columnID) throws 
67
    public abstract Object getValueAt(Object node, String columnID) throws
71
    UnknownTypeException;
68
            UnknownTypeException;
72
    
69
73
    /**
70
    /**
74
     * Returns true if value displayed in column <code>columnID</code>
71
     * Returns true if value displayed in column <code>columnID</code> and row
75
     * and row <code>node</code> is read only. Column ID is defined in by 
72
     * <code>node</code> is read only. Column ID is defined in by
76
     * {@link ColumnModel#getID}, and rows are defined by values returned from 
73
     * {@link ColumnModel#getID}, and rows are defined by values returned from
77
     * {@link TreeModel#getChildren}.
74
     * {@link TreeModel#getChildren}.
78
     *
75
     *
79
     * @param node a object returned from {@link TreeModel#getChildren} for this row
76
     * @param node a object returned from {@link TreeModel#getChildren} for this
77
     * row
80
     * @param columnID a id of column defined by {@link ColumnModel#getID}
78
     * @param columnID a id of column defined by {@link ColumnModel#getID}
81
     * @throws UnknownTypeException if there is no TableModel defined for given
79
     * @throws UnknownTypeException if there is no TableModel defined for given
82
     *         parameter type
80
     * parameter type
83
     *
81
     *
84
     * @return true if variable on given position is read only
82
     * @return true if variable on given position is read only
85
     */
83
     */
86
    public abstract boolean isReadOnly (Object node, String columnID) throws 
84
    public abstract boolean isReadOnly(Object node, String columnID) throws
87
    UnknownTypeException;
85
            UnknownTypeException;
88
    
86
89
    /**
87
    /**
90
     * Changes a value displayed in column <code>columnID</code>
88
     * Changes a value displayed in column <code>columnID</code> and row
91
     * and row <code>node</code>. Column ID is defined in by 
89
     * <code>node</code>. Column ID is defined in by {@link ColumnModel#getID},
92
     * {@link ColumnModel#getID}, and rows are defined by values returned from 
90
     * and rows are defined by values returned from
93
     * {@link TreeModel#getChildren}.
91
     * {@link TreeModel#getChildren}.
94
     *
92
     *
95
     * @param node a object returned from {@link TreeModel#getChildren} for this row
93
     * @param node a object returned from {@link TreeModel#getChildren} for this
94
     * row
96
     * @param columnID a id of column defined by {@link ColumnModel#getID}
95
     * @param columnID a id of column defined by {@link ColumnModel#getID}
97
     * @param value a new value of variable on given position
96
     * @param value a new value of variable on given position
98
     * @throws UnknownTypeException if there is no TableModel defined for given
97
     * @throws UnknownTypeException if there is no TableModel defined for given
99
     *         parameter type
98
     * parameter type
100
     */
99
     */
101
    public abstract void setValueAt (Object node, String columnID, Object value) 
100
    public abstract void setValueAt(Object node, String columnID, Object value)
102
    throws UnknownTypeException;
101
            throws UnknownTypeException;
103
102
104
    /** 
103
    /**
105
     * Registers given listener.
104
     * Registers given listener.
106
     * 
105
     *
107
     * @param l the listener to add
106
     * @param l the listener to add
108
     */
107
     */
109
    public abstract void addModelListener (ModelListener l);
108
    public abstract void addModelListener(ModelListener l);
110
109
111
    /** 
110
    /**
112
     * Unregisters given listener.
111
     * Unregisters given listener.
113
     *
112
     *
114
     * @param l the listener to remove
113
     * @param l the listener to remove
115
     */
114
     */
116
    public abstract void removeModelListener (ModelListener l);
115
    public abstract void removeModelListener(ModelListener l);
117
}
116
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/TablePropertyEditorsModelFilter.java (-10 / +13 lines)
Lines 45-70 Link Here
45
45
46
/**
46
/**
47
 * Use this to provide different property editors for different table cells.
47
 * Use this to provide different property editors for different table cells.
48
 * Implement this filter to override the behavior of any registered {@link TablePropertyEditorsModel}s.
48
 * Implement this filter to override the behavior of any registered
49
 * {@link TablePropertyEditorsModel}s.
49
 *
50
 *
50
 * @author Martin Entlicher
51
 * @author Martin Entlicher
51
 * @since 1.42
52
 * @since 1.42
52
 * @see TablePropertyEditorsModel
53
 * @see TablePropertyEditorsModel
53
 */
54
 */
54
public interface TablePropertyEditorsModelFilter extends Model {
55
public interface TablePropertyEditorsModelFilter extends Model {
55
    
56
56
    /**
57
    /**
57
     * Get the property editor for the given table cell.
58
     * Get the property editor for the given table cell.
58
     * 
59
     *
59
     * @param original The original {@link TablePropertyEditorsModel}
60
     * @param original The original {@link TablePropertyEditorsModel}
60
     * @param node an object returned from {@link TreeModel#getChildren(java.lang.Object, int, int) }
61
     * @param node an object returned from {@link TreeModel#getChildren(java.lang.Object, int, int)
61
     *             for this row
62
     * }
63
     * for this row
62
     * @param columnID an id of column defined by {@link ColumnModel#getID()}
64
     * @param columnID an id of column defined by {@link ColumnModel#getID()}
63
     * @return The property editor or <code>null</code> to use the column default one.
65
     * @return The property editor or <code>null</code> to use the column
64
     * @throws UnknownTypeException if there is nothing to be provided for the given
66
     * default one.
65
     *         parameter type
67
     * @throws UnknownTypeException if there is nothing to be provided for the
68
     * given parameter type
66
     */
69
     */
67
    PropertyEditor getPropertyEditor(TablePropertyEditorsModel original,
70
    PropertyEditor getPropertyEditor(TablePropertyEditorsModel original,
68
                                     Object node, String columnID) throws UnknownTypeException;
71
            Object node, String columnID) throws UnknownTypeException;
69
    
72
70
}
73
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/TablePropertyEditorsModel.java (-9 / +11 lines)
Lines 45-67 Link Here
45
45
46
/**
46
/**
47
 * Use this to provide different property editors for different table cells.
47
 * Use this to provide different property editors for different table cells.
48
 * 
48
 *
49
 * @author Martin Entlicher
49
 * @author Martin Entlicher
50
 * @since 1.42
50
 * @since 1.42
51
 * @see TablePropertyEditorsModelFilter
51
 * @see TablePropertyEditorsModelFilter
52
 */
52
 */
53
public interface TablePropertyEditorsModel extends Model {
53
public interface TablePropertyEditorsModel extends Model {
54
    
54
55
    /**
55
    /**
56
     * Get the property editor for the given table cell.
56
     * Get the property editor for the given table cell.
57
     * 
57
     *
58
     * @param node an object returned from {@link TreeModel#getChildren(java.lang.Object, int, int) }
58
     * @param node an object returned from {@link TreeModel#getChildren(java.lang.Object, int, int)
59
     *             for this row
59
     * }
60
     * for this row
60
     * @param columnID an id of column defined by {@link ColumnModel#getID()}
61
     * @param columnID an id of column defined by {@link ColumnModel#getID()}
61
     * @return The property editor or <code>null</code> to use the column default one.
62
     * @return The property editor or <code>null</code> to use the column
62
     * @throws UnknownTypeException if there is nothing to be provided for the given
63
     * default one.
63
     *         parameter type
64
     * @throws UnknownTypeException if there is nothing to be provided for the
65
     * given parameter type
64
     */
66
     */
65
    PropertyEditor getPropertyEditor(Object node, String columnID) throws UnknownTypeException;
67
    PropertyEditor getPropertyEditor(Object node, String columnID) throws UnknownTypeException;
66
    
68
67
}
69
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/TableRendererModelFilter.java (-11 / +21 lines)
Lines 41-55 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
import javax.swing.table.TableCellEditor;
46
import javax.swing.table.TableCellEditor;
48
import javax.swing.table.TableCellRenderer;
47
import javax.swing.table.TableCellRenderer;
49
48
50
/**
49
/**
51
 * Model filter that can override custom cell renderer and cell editor for table cells.
50
 * Model filter that can override custom cell renderer and cell editor for table
52
 * 
51
 * cells.
52
 *
53
 * @author Martin Entlicher
53
 * @author Martin Entlicher
54
 * @since 1.28
54
 * @since 1.28
55
 */
55
 */
Lines 57-100 Link Here
57
57
58
    /**
58
    /**
59
     * Test whether this renderer can render the given cell.
59
     * Test whether this renderer can render the given cell.
60
     *
60
     * @param original The original table cell renderer implementation
61
     * @param original The original table cell renderer implementation
61
     * @param node Tree node representing the row
62
     * @param node Tree node representing the row
62
     * @param columnID The column name
63
     * @param columnID The column name
63
     * @return <code>true</code> if the implementation can render the given cell, <code>false</code> otherwise
64
     * @return <code>true</code> if the implementation can render the given
64
     * @throws UnknownTypeException If the implementation can not decide whether to render the given cell.
65
     * cell, <code>false</code> otherwise
66
     * @throws UnknownTypeException If the implementation can not decide whether
67
     * to render the given cell.
65
     */
68
     */
66
    public boolean canRenderCell(TableRendererModel original, Object node, String columnID)
69
    public boolean canRenderCell(TableRendererModel original, Object node, String columnID)
67
            throws UnknownTypeException;
70
            throws UnknownTypeException;
68
71
69
    /**
72
    /**
70
     * Get the renderer of the given cell
73
     * Get the renderer of the given cell
74
     *
71
     * @param original The original table cell renderer implementation
75
     * @param original The original table cell renderer implementation
72
     * @param node Tree node representing the row
76
     * @param node Tree node representing the row
73
     * @param columnID The column name
77
     * @param columnID The column name
74
     * @return The cell renderer
78
     * @return The cell renderer
75
     * @throws UnknownTypeException If the implementation can not render the given cell.
79
     * @throws UnknownTypeException If the implementation can not render the
80
     * given cell.
76
     */
81
     */
77
    public TableCellRenderer getCellRenderer(TableRendererModel original, Object node, String columnID)
82
    public TableCellRenderer getCellRenderer(TableRendererModel original, Object node, String columnID)
78
            throws UnknownTypeException;
83
            throws UnknownTypeException;
79
84
80
    /**
85
    /**
81
     * Test whether this renderer can edit the given cell.
86
     * Test whether this renderer can edit the given cell.
87
     *
82
     * @param original The original table cell renderer implementation
88
     * @param original The original table cell renderer implementation
83
     * @param node Tree node representing the row
89
     * @param node Tree node representing the row
84
     * @param columnID The column name
90
     * @param columnID The column name
85
     * @return <code>true</code> if the implementation can edit the given cell, <code>false</code> otherwise
91
     * @return <code>true</code> if the implementation can edit the given cell,
86
     * @throws UnknownTypeException If the implementation can not decide whether to edit the given cell.
92
     * <code>false</code> otherwise
93
     * @throws UnknownTypeException If the implementation can not decide whether
94
     * to edit the given cell.
87
     */
95
     */
88
    public boolean canEditCell(TableRendererModel original, Object node, String columnID)
96
    public boolean canEditCell(TableRendererModel original, Object node, String columnID)
89
            throws UnknownTypeException;
97
            throws UnknownTypeException;
90
98
91
    /**
99
    /**
92
     * Get the editor of the given cell
100
     * Get the editor of the given cell
101
     *
93
     * @param original The original table cell renderer implementation
102
     * @param original The original table cell renderer implementation
94
     * @param node Tree node representing the row
103
     * @param node Tree node representing the row
95
     * @param columnID The column name
104
     * @param columnID The column name
96
     * @return The cell editor
105
     * @return The cell editor
97
     * @throws UnknownTypeException If the implementation can not edit the given cell.
106
     * @throws UnknownTypeException If the implementation can not edit the given
107
     * cell.
98
     */
108
     */
99
    public TableCellEditor getCellEditor(TableRendererModel original, Object node, String columnID)
109
    public TableCellEditor getCellEditor(TableRendererModel original, Object node, String columnID)
100
            throws UnknownTypeException;
110
            throws UnknownTypeException;
Lines 104-115 Link Here
104
     *
114
     *
105
     * @param l the listener to add
115
     * @param l the listener to add
106
     */
116
     */
107
    public abstract void addModelListener (ModelListener l);
117
    public abstract void addModelListener(ModelListener l);
108
118
109
    /**
119
    /**
110
     * Unregisters given listener.
120
     * Unregisters given listener.
111
     *
121
     *
112
     * @param l the listener to remove
122
     * @param l the listener to remove
113
     */
123
     */
114
    public abstract void removeModelListener (ModelListener l);
124
    public abstract void removeModelListener(ModelListener l);
115
}
125
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/TableRendererModel.java (-10 / +19 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
import javax.swing.table.TableCellEditor;
46
import javax.swing.table.TableCellEditor;
Lines 49-55 Link Here
49
48
50
/**
49
/**
51
 * Model that provides custom cell renderer and cell editor for table cells.
50
 * Model that provides custom cell renderer and cell editor for table cells.
52
 * 
51
 *
53
 * @author Martin Entlicher
52
 * @author Martin Entlicher
54
 * @since 1.28
53
 * @since 1.28
55
 */
54
 */
Lines 57-93 Link Here
57
56
58
    /**
57
    /**
59
     * Test whether this renderer can render the given cell.
58
     * Test whether this renderer can render the given cell.
59
     *
60
     * @param node Tree node representing the row
60
     * @param node Tree node representing the row
61
     * @param columnID The column name
61
     * @param columnID The column name
62
     * @return <code>true</code> if the implementation can render the given cell, <code>false</code> otherwise
62
     * @return <code>true</code> if the implementation can render the given
63
     * @throws UnknownTypeException If the implementation can not decide whether to render the given cell.
63
     * cell, <code>false</code> otherwise
64
     * @throws UnknownTypeException If the implementation can not decide whether
65
     * to render the given cell.
64
     */
66
     */
65
    public boolean canRenderCell(Object node, String columnID) throws UnknownTypeException;
67
    public boolean canRenderCell(Object node, String columnID) throws UnknownTypeException;
66
68
67
    /**
69
    /**
68
     * Get the renderer of the given cell
70
     * Get the renderer of the given cell
71
     *
69
     * @param node Tree node representing the row
72
     * @param node Tree node representing the row
70
     * @param columnID The column name
73
     * @param columnID The column name
71
     * @return The cell renderer
74
     * @return The cell renderer
72
     * @throws UnknownTypeException If the implementation can not render the given cell.
75
     * @throws UnknownTypeException If the implementation can not render the
76
     * given cell.
73
     */
77
     */
74
    public TableCellRenderer getCellRenderer(Object node, String columnID) throws UnknownTypeException;
78
    public TableCellRenderer getCellRenderer(Object node, String columnID) throws UnknownTypeException;
75
79
76
    /**
80
    /**
77
     * Test whether this renderer can edit the given cell.
81
     * Test whether this renderer can edit the given cell.
82
     *
78
     * @param node Tree node representing the row
83
     * @param node Tree node representing the row
79
     * @param columnID The column name
84
     * @param columnID The column name
80
     * @return <code>true</code> if the implementation can edit the given cell, <code>false</code> otherwise
85
     * @return <code>true</code> if the implementation can edit the given cell,
81
     * @throws UnknownTypeException If the implementation can not decide whether to edit the given cell.
86
     * <code>false</code> otherwise
87
     * @throws UnknownTypeException If the implementation can not decide whether
88
     * to edit the given cell.
82
     */
89
     */
83
    public boolean canEditCell(Object node, String columnID) throws UnknownTypeException;
90
    public boolean canEditCell(Object node, String columnID) throws UnknownTypeException;
84
91
85
    /**
92
    /**
86
     * Get the editor of the given cell
93
     * Get the editor of the given cell
94
     *
87
     * @param node Tree node representing the row
95
     * @param node Tree node representing the row
88
     * @param columnID The column name
96
     * @param columnID The column name
89
     * @return The cell editor
97
     * @return The cell editor
90
     * @throws UnknownTypeException If the implementation can not edit the given cell.
98
     * @throws UnknownTypeException If the implementation can not edit the given
99
     * cell.
91
     */
100
     */
92
    public TableCellEditor getCellEditor(Object node, String columnID) throws UnknownTypeException;
101
    public TableCellEditor getCellEditor(Object node, String columnID) throws UnknownTypeException;
93
102
Lines 96-107 Link Here
96
     *
105
     *
97
     * @param l the listener to add
106
     * @param l the listener to add
98
     */
107
     */
99
    public abstract void addModelListener (ModelListener l);
108
    public abstract void addModelListener(ModelListener l);
100
109
101
    /**
110
    /**
102
     * Unregisters given listener.
111
     * Unregisters given listener.
103
     *
112
     *
104
     * @param l the listener to remove
113
     * @param l the listener to remove
105
     */
114
     */
106
    public abstract void removeModelListener (ModelListener l);
115
    public abstract void removeModelListener(ModelListener l);
107
}
116
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/TreeExpansionModelFilter.java (-16 / +14 lines)
Lines 41-56 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
48
/**
46
/**
49
 * This model filter controlls expansion, collapsion of nodes in tree view, and
47
 * This model filter controlls expansion, collapsion of nodes in tree view, and
50
 * defindes default expand state for all node in it. It may delegate to the supplied
48
 * defindes default expand state for all node in it. It may delegate to the
51
 * TreeExpansionModel.
49
 * supplied TreeExpansionModel.
52
 *
50
 *
53
 * @author   Martin Entlicher
51
 * @author Martin Entlicher
54
 * @since 1.15
52
 * @since 1.15
55
 */
53
 */
56
public interface TreeExpansionModelFilter extends Model {
54
public interface TreeExpansionModelFilter extends Model {
Lines 61-94 Link Here
61
     * @param node a node
59
     * @param node a node
62
     * @return default state (collapsed, expanded) of given node
60
     * @return default state (collapsed, expanded) of given node
63
     */
61
     */
64
    public abstract boolean isExpanded (TreeExpansionModel original, Object node)
62
    public abstract boolean isExpanded(TreeExpansionModel original, Object node)
65
    throws UnknownTypeException;
63
            throws UnknownTypeException;
66
64
67
    /**
65
    /**
68
     * Called when given node is expanded.
66
     * Called when given node is expanded.
69
     *
67
     *
70
     * @param node a expanded node
68
     * @param node a expanded node
71
     */
69
     */
72
    public abstract void nodeExpanded (Object node);
70
    public abstract void nodeExpanded(Object node);
73
    
71
74
    /**
72
    /**
75
     * Called when given node is collapsed.
73
     * Called when given node is collapsed.
76
     *
74
     *
77
     * @param node a collapsed node
75
     * @param node a collapsed node
78
     */
76
     */
79
    public abstract void nodeCollapsed (Object node);
77
    public abstract void nodeCollapsed(Object node);
80
    
78
81
    /** 
79
    /**
82
     * Registers given listener.
80
     * Registers given listener.
83
     * 
81
     *
84
     * @param l the listener to add
82
     * @param l the listener to add
85
     */
83
     */
86
    public abstract void addModelListener (ModelListener l);
84
    public abstract void addModelListener(ModelListener l);
87
85
88
    /** 
86
    /**
89
     * Unregisters given listener.
87
     * Unregisters given listener.
90
     *
88
     *
91
     * @param l the listener to remove
89
     * @param l the listener to remove
92
     */
90
     */
93
    public abstract void removeModelListener (ModelListener l);
91
    public abstract void removeModelListener(ModelListener l);
94
}
92
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/TreeExpansionModel.java (-8 / +6 lines)
Lines 41-55 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
48
/**
46
/**
49
 * This model controlls expansion, collapsion of nodes in tree view, and
47
 * This model controlls expansion, collapsion of nodes in tree view, and
50
 * defindes default expand state for all node in it.
48
 * defindes default expand state for all node in it.
51
 *
49
 *
52
 * @author   Jan Jancura
50
 * @author Jan Jancura
53
 */
51
 */
54
public interface TreeExpansionModel extends Model {
52
public interface TreeExpansionModel extends Model {
55
53
Lines 59-78 Link Here
59
     * @param node a node
57
     * @param node a node
60
     * @return default state (collapsed, expanded) of given node
58
     * @return default state (collapsed, expanded) of given node
61
     */
59
     */
62
    public abstract boolean isExpanded (Object node)
60
    public abstract boolean isExpanded(Object node)
63
    throws UnknownTypeException;
61
            throws UnknownTypeException;
64
62
65
    /**
63
    /**
66
     * Called when given node is expanded.
64
     * Called when given node is expanded.
67
     *
65
     *
68
     * @param node a expanded node
66
     * @param node a expanded node
69
     */
67
     */
70
    public abstract void nodeExpanded (Object node);
68
    public abstract void nodeExpanded(Object node);
71
    
69
72
    /**
70
    /**
73
     * Called when given node is collapsed.
71
     * Called when given node is collapsed.
74
     *
72
     *
75
     * @param node a collapsed node
73
     * @param node a collapsed node
76
     */
74
     */
77
    public abstract void nodeCollapsed (Object node);
75
    public abstract void nodeCollapsed(Object node);
78
}
76
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/TreeModelFilter.java (-53 / +48 lines)
Lines 41-129 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
48
49
/**
46
/**
50
 * Filters content of some original tree of nodes (represented by
47
 * Filters content of some original tree of nodes (represented by
51
 * {@link TreeModel}).
48
 * {@link TreeModel}).
52
 *
49
 *
53
 * @author   Jan Jancura
50
 * @author Jan Jancura
54
 */
51
 */
55
public interface TreeModelFilter extends Model {
52
public interface TreeModelFilter extends Model {
56
53
57
58
    /**
54
    /**
59
     * Returns filtered root of hierarchy.
55
     * Returns filtered root of hierarchy.
60
     *
56
     *
61
     * @param   original the original tree model
57
     * @param original the original tree model
62
     * @return  filtered root of hierarchy
58
     * @return filtered root of hierarchy
63
     */
59
     */
64
    public abstract Object getRoot (TreeModel original);
60
    public abstract Object getRoot(TreeModel original);
65
61
66
    /**
62
    /**
67
     * Returns filtered children for given parent on given indexes.
63
     * Returns filtered children for given parent on given indexes. Typically
68
     * Typically you should get original nodes 
64
     * you should get original nodes (<code>original.getChildren (...)</code>),
69
     * (<code>original.getChildren (...)</code>), and modify them, or return
65
     * and modify them, or return it without modifications. You should not throw
70
     * it without modifications. You should not throw UnknownTypeException
66
     * UnknownTypeException directly from this method!
71
     * directly from this method!
67
     *
68
     * @param original the original tree model
69
     * @param parent a parent of returned nodes
70
     * @throws UnknownTypeException this exception can be thrown from
71
     * <code>original.getChildren (...)</code> method call only!
72
     *
72
     *
73
     * @param   original the original tree model
73
     * @return children for given parent on given indexes
74
     * @param   parent a parent of returned nodes
74
     */
75
     * @throws  UnknownTypeException this exception can be thrown from 
75
    public abstract Object[] getChildren(
76
     *          <code>original.getChildren (...)</code> method call only!
76
            TreeModel original,
77
     *
77
            Object parent,
78
     * @return  children for given parent on given indexes
78
            int from,
79
     */
79
            int to
80
    public abstract Object[] getChildren (
81
        TreeModel   original, 
82
        Object      parent, 
83
        int         from, 
84
        int         to
85
    ) throws UnknownTypeException;
80
    ) throws UnknownTypeException;
86
    
81
87
    /**
82
    /**
88
     * Returns number of filtered children for given node.
83
     * Returns number of filterred children for given node.
89
     * 
84
     *
90
     * @param   original the original tree model
85
     * @param original the original tree model
91
     * @param   node the parent node
86
     * @param node the parent node
92
     * @throws  UnknownTypeException if this TreeModel implementation is not
87
     * @throws UnknownTypeException if this TreeModel implementation is not able
93
     *          able to resolve children for given node type
88
     * to resolve children for given node type
94
     *
89
     *
95
     * @return  true if node is leaf
90
     * @return true if node is leaf
96
     */
91
     */
97
    public abstract int getChildrenCount (
92
    public abstract int getChildrenCount(
98
        TreeModel original,
93
            TreeModel original,
99
        Object node
94
            Object node
100
    ) throws UnknownTypeException;
95
    ) throws UnknownTypeException;
101
    
96
102
    /**
97
    /**
103
     * Returns true if node is leaf. You should not throw UnknownTypeException
98
     * Returns true if node is leaf. You should not throw UnknownTypeException
104
     * directly from this method!
99
     * directly from this method!
105
     * 
100
     *
106
     * @param   original the original tree model
101
     * @param original the original tree model
107
     * @throws  UnknownTypeException this exception can be thrown from 
102
     * @throws UnknownTypeException this exception can be thrown from
108
     *          <code>original.isLeaf (...)</code> method call only!
103
     * <code>original.isLeaf (...)</code> method call only!
109
     * @return  true if node is leaf
104
     * @return true if node is leaf
110
     */
105
     */
111
    public abstract boolean isLeaf (
106
    public abstract boolean isLeaf(
112
        TreeModel original, 
107
            TreeModel original,
113
        Object node
108
            Object node
114
    ) throws UnknownTypeException;
109
    ) throws UnknownTypeException;
115
110
116
    /** 
111
    /**
117
     * Registers given listener.
112
     * Registers given listener.
118
     * 
113
     *
119
     * @param l the listener to add
114
     * @param l the listener to add
120
     */
115
     */
121
    public abstract void addModelListener (ModelListener l);
116
    public abstract void addModelListener(ModelListener l);
122
117
123
    /** 
118
    /**
124
     * Unregisters given listener.
119
     * Unregisters given listener.
125
     *
120
     *
126
     * @param l the listener to remove
121
     * @param l the listener to remove
127
     */
122
     */
128
    public abstract void removeModelListener (ModelListener l);
123
    public abstract void removeModelListener(ModelListener l);
129
}
124
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/TreeModel.java (-49 / +45 lines)
Lines 41-62 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
48
49
/**
46
/**
50
 * Defines data model for tree.
47
 * Defines data model for tree.
51
 *
48
 *
52
 * @author   Jan Jancura
49
 * @author Jan Jancura
53
 */
50
 */
54
public interface TreeModel extends Model {
51
public interface TreeModel extends Model {
55
52
56
    /**
53
    /**
57
     * Constant for root node. This root node should be used if root node
54
     * Constant for root node. This root node should be used if root node does
58
     * does not represent any valuable information and should not be visible in
55
     * not represent any valuable information and should not be visible in tree.
59
     * tree.
60
     */
56
     */
61
    public static final String ROOT = "Root";
57
    public static final String ROOT = "Root";
62
58
Lines 65-135 Link Here
65
     *
61
     *
66
     * @return the root node of the tree or null
62
     * @return the root node of the tree or null
67
     */
63
     */
68
    public abstract Object getRoot ();
64
    public abstract Object getRoot();
69
    
65
70
    /** 
66
    /**
71
     * Returns children for given parent on given indexes.<p>
67
     * Returns children for given parent on given indexes.<p>
72
     * This method works in pair with {@link #getChildrenCount}, the <code>to</code>
68
     * This method works in pair with {@link #getChildrenCount}, the
73
     * parameter is up to the value that is returned from {@link #getChildrenCount}.
69
     * <code>to</code> parameter is up to the value that is returned from
74
     * If the list of children varies over time, the implementation code
70
     * {@link #getChildrenCount}. If the list of children varies over time, the
75
     * needs to pay attention to bounds and check the <code>from</code> and
71
     * implementation code needs to pay attention to bounds and check the
76
     * <code>to</code> parameters, especially if {@link #getChildrenCount}
72
     * <code>from</code> and <code>to</code> parameters, especially if
77
     * returns <code>Integer.MAX_VALUE</code>. Caching of the children between
73
     * {@link #getChildrenCount} returns <code>Integer.MAX_VALUE</code>. Caching
78
     * {@link #getChildrenCount} and {@link #getChildren} can be used as well,
74
     * of the children between {@link #getChildrenCount} and
79
     * if necessary.
75
     * {@link #getChildren} can be used as well, if necessary.
80
     *
76
     *
81
     * @param   parent a parent of returned nodes
77
     * @param parent a parent of returned nodes
82
     * @param   from a start index
78
     * @param from a start index
83
     * @param   to a end index
79
     * @param to a end index
84
     *
80
     *
85
     * @throws  UnknownTypeException if this TreeModel implementation is not
81
     * @throws UnknownTypeException if this TreeModel implementation is not able
86
     *          able to resolve children for given node type
82
     * to resolve children for given node type
87
     *
83
     *
88
     * @return  children for given parent on given indexes
84
     * @return children for given parent on given indexes
89
     * @see #getChildrenCount
85
     * @see #getChildrenCount
90
     */
86
     */
91
    public abstract Object[] getChildren (Object parent, int from, int to) 
87
    public abstract Object[] getChildren(Object parent, int from, int to)
92
        throws UnknownTypeException;
88
            throws UnknownTypeException;
93
    
89
94
    /**
90
    /**
95
     * Returns true if node is leaf.
91
     * Returns true if node is leaf.
96
     * 
92
     *
97
     * @throws  UnknownTypeException if this TreeModel implementation is not
93
     * @throws UnknownTypeException if this TreeModel implementation is not able
98
     *          able to resolve children for given node type
94
     * to resolve dchildren for given node type
99
     * @return  true if node is leaf
95
     * @return true if node is leaf
100
     */
96
     */
101
    public abstract boolean isLeaf (Object node) throws UnknownTypeException;
97
    public abstract boolean isLeaf(Object node) throws UnknownTypeException;
102
    
98
103
    /**
99
    /**
104
     * Returns the number of children for given node.<p>
100
     * Returns the number of children for given node.<p>
105
     * This method works in pair with {@link #getChildren}, which gets
101
     * This method works in pair with {@link #getChildren}, which gets this
106
     * this returned value (or less) as the <code>to</code> parameter. This method
102
     * returned value (or less) as the <code>to</code> parameter. This method is
107
     * is always called before a call to {@link #getChildren}. This method can
103
     * always called before a call to {@link #getChildren}. This method can
108
     * return e.g. <code>Integer.MAX_VALUE</code> when all children should be
104
     * return e.g. <code>Integer.MAX_VALUE</code> when all children should be
109
     * loaded.
105
     * loaded.
110
     * 
111
     * @param   node the parent node
112
     * @throws  UnknownTypeException if this TreeModel implementation is not
113
     *          able to resolve children for given node type
114
     *
106
     *
115
     * @return  the children count
107
     * @param node the parent node
108
     * @throws UnknownTypeException if this TreeModel implementation is not able
109
     * to resolve children for given node type
110
     *
111
     * @return the children count
116
     * @since 1.1
112
     * @since 1.1
117
     * @see #getChildren
113
     * @see #getChildren
118
     */
114
     */
119
    public abstract int getChildrenCount (Object node) 
115
    public abstract int getChildrenCount(Object node)
120
    throws UnknownTypeException;
116
            throws UnknownTypeException;
121
117
122
    /** 
118
    /**
123
     * Registers given listener.
119
     * Registers given listener.
124
     * 
120
     *
125
     * @param l the listener to add
121
     * @param l the listener to add
126
     */
122
     */
127
    public abstract void addModelListener (ModelListener l);
123
    public abstract void addModelListener(ModelListener l);
128
124
129
    /** 
125
    /**
130
     * Unregisters given listener.
126
     * Unregisters given listener.
131
     *
127
     *
132
     * @param l the listener to remove
128
     * @param l the listener to remove
133
     */
129
     */
134
    public abstract void removeModelListener (ModelListener l);
130
    public abstract void removeModelListener(ModelListener l);
135
}
131
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/src/org/netbeans/spi/viewmodel/UnknownTypeException.java (-8 / +6 lines)
Lines 41-65 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.spi.viewmodel;
44
package org.netbeans.spi.viewmodel;
46
45
47
/**
46
/**
48
 * Used by various data models if data model is asked to resolve node
47
 * Used by various data models if data model is asked to resolve node of unknown
49
 * of unknown type.
48
 * type.
50
 *
49
 *
51
 * @author   Jan Jancura
50
 * @author Jan Jancura
52
 */
51
 */
53
public class UnknownTypeException extends Exception {
52
public class UnknownTypeException extends Exception {
54
53
55
    private Object node;
54
    private final Object node;
56
55
57
    /**
56
    /**
58
     * Creates a new instance of exception for given node.
57
     * Creates a new instance of exception for given node.
59
     *
58
     *
60
     * @param node a node of unknown type
59
     * @param node a node of unknown type
61
     */
60
     */
62
    public UnknownTypeException (Object node) {
61
    public UnknownTypeException(Object node) {
63
        this.node = node;
62
        this.node = node;
64
    }
63
    }
65
64
Lines 67-72 Link Here
67
    public String getMessage() {
66
    public String getMessage() {
68
        return node.toString() + " [" + node.getClass() + ']'; // NOI18N
67
        return node.toString() + " [" + node.getClass() + ']'; // NOI18N
69
    }
68
    }
70
    
71
}
72
69
70
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/test/unit/src/org/netbeans/modules/viewmodel/AsynchronousTest.java (-33 / +71 lines)
Lines 39-45 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.viewmodel;
42
package org.netbeans.modules.viewmodel;
44
43
45
import java.beans.BeanInfo;
44
import java.beans.BeanInfo;
Lines 57-63 Link Here
57
import org.netbeans.junit.NbTestCase;
56
import org.netbeans.junit.NbTestCase;
58
import org.netbeans.spi.viewmodel.AsynchronousModelFilter;
57
import org.netbeans.spi.viewmodel.AsynchronousModelFilter;
59
import org.netbeans.spi.viewmodel.AsynchronousModelFilter.CALL;
58
import org.netbeans.spi.viewmodel.AsynchronousModelFilter.CALL;
60
import org.netbeans.spi.viewmodel.Model;
61
import org.netbeans.spi.viewmodel.Models;
59
import org.netbeans.spi.viewmodel.Models;
62
import org.netbeans.spi.viewmodel.UnknownTypeException;
60
import org.netbeans.spi.viewmodel.UnknownTypeException;
63
import org.openide.nodes.Node;
61
import org.openide.nodes.Node;
Lines 72-93 Link Here
72
 */
70
 */
73
public class AsynchronousTest extends NbTestCase {
71
public class AsynchronousTest extends NbTestCase {
74
72
75
    private static final Set<String> SYNCHRONOUS_METHODS = Collections.unmodifiableSet(new HashSet<String>(
73
    private static final Set<String> SYNCHRONOUS_METHODS = Collections.unmodifiableSet(new HashSet<>(
76
            Arrays.asList( "isLeaf",    // TreeModel
74
            Arrays.asList("isLeaf", // TreeModel
77
                           "getIconBase", "canCopy", "canCut", "canRename", // NodeModel
75
                    "getIconBase", "canCopy", "canCut", "canRename", // NodeModel
78
                           "clipboardCopy", "clipboardCut", "getPasteTypes", "getIconBaseWithExtension", // ExtendedNodeModel
76
                    "clipboardCopy", "clipboardCut", "getPasteTypes", "getIconBaseWithExtension", // ExtendedNodeModel
79
                           "isReadOnly" )));    // TableModel
77
                    "isReadOnly")));    // TableModel
80
78
81
    public AsynchronousTest(String s) {
79
    public AsynchronousTest(String s) {
82
        super(s);
80
        super(s);
83
    }
81
    }
84
82
85
    public void testDefaultThreadingAccess() throws Exception {
83
    public void testDefaultThreadingAccess() throws Exception {
86
        Map<CALL, Executor> defaultRPs = new HashMap<CALL, Executor>();
84
        Map<CALL, Executor> defaultRPs = new HashMap<>();
87
        defaultRPs.put(CALL.CHILDREN, AsynchronousModelFilter.DEFAULT);
85
        defaultRPs.put(CALL.CHILDREN, AsynchronousModelFilter.DEFAULT);
88
        defaultRPs.put(CALL.VALUE, AsynchronousModelFilter.DEFAULT);
86
        defaultRPs.put(CALL.VALUE, AsynchronousModelFilter.DEFAULT);
89
87
90
        Map<String, ThreadChecker> defaultMethodThreads = new HashMap<String, ThreadChecker>();
88
        Map<String, ThreadChecker> defaultMethodThreads = new HashMap<>();
91
        AWTChecker awtc = new AWTChecker();
89
        AWTChecker awtc = new AWTChecker();
92
        for (String methodName : SYNCHRONOUS_METHODS) {
90
        for (String methodName : SYNCHRONOUS_METHODS) {
93
            defaultMethodThreads.put(methodName, awtc);
91
            defaultMethodThreads.put(methodName, awtc);
Lines 99-106 Link Here
99
        defaultMethodThreads.put("getChildren", rpc);
97
        defaultMethodThreads.put("getChildren", rpc);
100
        defaultMethodThreads.put("getChildrenCount", rpc);
98
        defaultMethodThreads.put("getChildrenCount", rpc);
101
        defaultMethodThreads.put("getValueAt", rpc);
99
        defaultMethodThreads.put("getValueAt", rpc);
102
        CheckCallingThreadModel cm = new CheckCallingThreadModel(new String[] { "a", "b", "c" }, 2, defaultMethodThreads);
100
        CheckCallingThreadModel cm = new CheckCallingThreadModel(new String[]{"a", "b", "c"}, 2, defaultMethodThreads);
103
        ArrayList l = new ArrayList ();
101
        ArrayList l = new ArrayList();
104
        l.add(cm);
102
        l.add(cm);
105
        l.addAll(Arrays.asList(cm.createColumns()));
103
        l.addAll(Arrays.asList(cm.createColumns()));
106
        final Models.CompoundModel mcm = Models.createCompoundModel(l);
104
        final Models.CompoundModel mcm = Models.createCompoundModel(l);
Lines 111-119 Link Here
111
109
112
    public void testSynchronousAccess() throws Exception {
110
    public void testSynchronousAccess() throws Exception {
113
        AWTChecker awtc = new AWTChecker();
111
        AWTChecker awtc = new AWTChecker();
114
        CheckCallingThreadModel cm = new CheckCallingThreadModel(new String[] { "a", "b", "c" }, 2, new ConstantCheckersMap(awtc));
112
        CheckCallingThreadModel cm = new CheckCallingThreadModel(new String[]{"a", "b", "c"}, 2, new ConstantCheckersMap(awtc));
115
        SynchronousModelImpl sm = new SynchronousModelImpl();
113
        SynchronousModelImpl sm = new SynchronousModelImpl();
116
        ArrayList l = new ArrayList ();
114
        ArrayList l = new ArrayList();
117
        l.add(cm);
115
        l.add(cm);
118
        l.addAll(Arrays.asList(cm.createColumns()));
116
        l.addAll(Arrays.asList(cm.createColumns()));
119
        l.add(sm);
117
        l.add(sm);
Lines 125-133 Link Here
125
123
126
    public void testDefaultRPAccess() throws Exception {
124
    public void testDefaultRPAccess() throws Exception {
127
        RPChecker rpc = new RPChecker((RequestProcessor) AsynchronousModelFilter.DEFAULT);
125
        RPChecker rpc = new RPChecker((RequestProcessor) AsynchronousModelFilter.DEFAULT);
128
        CheckCallingThreadModel cm = new CheckCallingThreadModel(new String[] { "a", "b", "c" }, 2, new ConstantCheckersMap(rpc));
126
        CheckCallingThreadModel cm = new CheckCallingThreadModel(new String[]{"a", "b", "c"}, 2, new ConstantCheckersMap(rpc));
129
        DefaultRPModelImpl drpm = new DefaultRPModelImpl();
127
        DefaultRPModelImpl drpm = new DefaultRPModelImpl();
130
        ArrayList l = new ArrayList ();
128
        ArrayList l = new ArrayList();
131
        l.add(cm);
129
        l.add(cm);
132
        l.addAll(Arrays.asList(cm.createColumns()));
130
        l.addAll(Arrays.asList(cm.createColumns()));
133
        l.add(drpm);
131
        l.add(drpm);
Lines 145-153 Link Here
145
            this.mcm = mcm;
143
            this.mcm = mcm;
146
        }
144
        }
147
145
146
        @Override
148
        public void run() {
147
        public void run() {
149
            OutlineTable tt = (OutlineTable) Models.createView(mcm);
148
            OutlineTable tt = (OutlineTable) Models.createView(mcm);
150
            Node root = tt.getExplorerManager ().getRootContext ();
149
            Node root = tt.getExplorerManager().getRootContext();
151
150
152
            root.getChildren().getNodes();
151
            root.getChildren().getNodes();
153
            root.getHtmlDisplayName();
152
            root.getHtmlDisplayName();
Lines 204-209 Link Here
204
203
205
    private static final class AWTChecker implements ThreadChecker {
204
    private static final class AWTChecker implements ThreadChecker {
206
205
206
        @Override
207
        public boolean isInCorrectThread() {
207
        public boolean isInCorrectThread() {
208
            return SwingUtilities.isEventDispatchThread();
208
            return SwingUtilities.isEventDispatchThread();
209
        }
209
        }
Lines 212-223 Link Here
212
212
213
    private static final class RPChecker implements ThreadChecker {
213
    private static final class RPChecker implements ThreadChecker {
214
214
215
        private RequestProcessor rp;
215
        private final RequestProcessor rp;
216
216
217
        public RPChecker(RequestProcessor rp) {
217
        public RPChecker(RequestProcessor rp) {
218
            this.rp = rp;
218
            this.rp = rp;
219
        }
219
        }
220
220
221
        @Override
221
        public boolean isInCorrectThread() {
222
        public boolean isInCorrectThread() {
222
            return rp.isRequestProcessorThread();
223
            return rp.isRequestProcessorThread();
223
        }
224
        }
Lines 232-245 Link Here
232
            this.tc = tc;
233
            this.tc = tc;
233
        }
234
        }
234
235
235
        public int size() { return Integer.MAX_VALUE; }
236
        @Override
237
        public int size() {
238
            return Integer.MAX_VALUE;
239
        }
236
240
237
        public boolean isEmpty() { return false; }
241
        @Override
242
        public boolean isEmpty() {
243
            return false;
244
        }
238
245
239
        public boolean containsKey(Object key) { return true; }
246
        @Override
247
        public boolean containsKey(Object key) {
248
            return true;
249
        }
240
250
241
        public boolean containsValue(Object value) { return value == tc; }
251
        @Override
252
        public boolean containsValue(Object value) {
253
            return value == tc;
254
        }
242
255
256
        @Override
243
        public Object get(Object key) {
257
        public Object get(Object key) {
244
            if (SYNCHRONOUS_METHODS.contains(key)) {
258
            if (SYNCHRONOUS_METHODS.contains(key)) {
245
                return new AWTChecker();
259
                return new AWTChecker();
Lines 247-275 Link Here
247
            return tc;
261
            return tc;
248
        }
262
        }
249
263
250
        public Object put(Object key, Object value) { throw new UnsupportedOperationException("N/A"); }
264
        @Override
265
        public Object put(Object key, Object value) {
266
            throw new UnsupportedOperationException("N/A");
267
        }
251
268
252
        public Object remove(Object key) { throw new UnsupportedOperationException("N/A"); }
269
        @Override
270
        public Object remove(Object key) {
271
            throw new UnsupportedOperationException("N/A");
272
        }
253
273
254
        public void putAll(Map t) { throw new UnsupportedOperationException("N/A"); }
274
        @Override
275
        public void putAll(Map t) {
276
            throw new UnsupportedOperationException("N/A");
277
        }
255
278
256
        public void clear() { throw new UnsupportedOperationException("N/A"); }
279
        @Override
280
        public void clear() {
281
            throw new UnsupportedOperationException("N/A");
282
        }
257
283
258
        public Set keySet() { throw new UnsupportedOperationException("N/A"); }
284
        @Override
285
        public Set keySet() {
286
            throw new UnsupportedOperationException("N/A");
287
        }
259
288
260
        public Collection values() { return Collections.singleton(tc); }
289
        @Override
290
        public Collection values() {
291
            return Collections.singleton(tc);
292
        }
261
293
262
        public Set entrySet() { throw new UnsupportedOperationException("N/A"); }
294
        @Override
295
        public Set entrySet() {
296
            throw new UnsupportedOperationException("N/A");
297
        }
263
298
264
    }
299
    }
265
300
266
    private static class CheckCallingThreadModel extends CountedModel {
301
    private static class CheckCallingThreadModel extends CountedModel {
267
302
268
        private final Map<String, ThreadChecker> threadCheckers;
303
        private final Map<String, ThreadChecker> threadCheckers;
269
        private final Map<String, Thread> failedMethods = new HashMap<String, Thread>();
304
        private final Map<String, Thread> failedMethods = new HashMap<>();
270
305
271
        public CheckCallingThreadModel(String[] children, int depth,
306
        public CheckCallingThreadModel(String[] children, int depth,
272
                                       Map<String, ThreadChecker> threadCheckers) {
307
                Map<String, ThreadChecker> threadCheckers) {
273
            super(children, depth);
308
            super(children, depth);
274
            this.threadCheckers = threadCheckers;
309
            this.threadCheckers = threadCheckers;
275
        }
310
        }
Lines 295-308 Link Here
295
330
296
    private static class SynchronousModelImpl implements AsynchronousModelFilter {
331
    private static class SynchronousModelImpl implements AsynchronousModelFilter {
297
332
333
        @Override
298
        public Executor asynchronous(Executor original, CALL asynchCall, Object node) throws UnknownTypeException {
334
        public Executor asynchronous(Executor original, CALL asynchCall, Object node) throws UnknownTypeException {
299
            return AsynchronousModelFilter.CURRENT_THREAD;
335
            return AsynchronousModelFilter.CURRENT_THREAD;
300
        }
336
        }
301
        
337
302
    }
338
    }
303
339
304
    private static class DefaultRPModelImpl implements AsynchronousModelFilter {
340
    private static class DefaultRPModelImpl implements AsynchronousModelFilter {
305
341
342
        @Override
306
        public Executor asynchronous(Executor original, CALL asynchCall, Object node) throws UnknownTypeException {
343
        public Executor asynchronous(Executor original, CALL asynchCall, Object node) throws UnknownTypeException {
307
            return AsynchronousModelFilter.DEFAULT;
344
            return AsynchronousModelFilter.DEFAULT;
308
        }
345
        }
Lines 311-322 Link Here
311
348
312
    private static class CustomRPModelImpl implements AsynchronousModelFilter {
349
    private static class CustomRPModelImpl implements AsynchronousModelFilter {
313
350
314
        private Map<CALL, Executor> rps;
351
        private final Map<CALL, Executor> rps;
315
        
352
316
        public CustomRPModelImpl(Map<CALL, Executor> rps) {
353
        public CustomRPModelImpl(Map<CALL, Executor> rps) {
317
            this.rps = rps;
354
            this.rps = rps;
318
        }
355
        }
319
356
357
        @Override
320
        public Executor asynchronous(Executor original, CALL asynchCall, Object node) throws UnknownTypeException {
358
        public Executor asynchronous(Executor original, CALL asynchCall, Object node) throws UnknownTypeException {
321
            RequestProcessor rp = (RequestProcessor) rps.get(asynchCall);
359
            RequestProcessor rp = (RequestProcessor) rps.get(asynchCall);
322
            if (rp != null) {
360
            if (rp != null) {
(-)/home/enrico/Lavoro/releases/spi.viewmodel/test/unit/src/org/netbeans/modules/viewmodel/BasicTest.java (-232 / +266 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.viewmodel;
44
package org.netbeans.modules.viewmodel;
46
45
47
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionEvent;
Lines 54-88 Link Here
54
import java.util.Set;
53
import java.util.Set;
55
import javax.swing.AbstractAction;
54
import javax.swing.AbstractAction;
56
import javax.swing.Action;
55
import javax.swing.Action;
57
58
import javax.swing.SwingUtilities;
56
import javax.swing.SwingUtilities;
59
import org.netbeans.junit.NbTestCase;
57
import org.netbeans.junit.NbTestCase;
60
58
import org.netbeans.spi.viewmodel.ColumnModel;
61
import org.netbeans.spi.viewmodel.*;
59
import org.netbeans.spi.viewmodel.ModelEvent;
62
60
import org.netbeans.spi.viewmodel.ModelListener;
61
import org.netbeans.spi.viewmodel.Models;
62
import org.netbeans.spi.viewmodel.NodeActionsProvider;
63
import org.netbeans.spi.viewmodel.NodeModel;
64
import org.netbeans.spi.viewmodel.TableModel;
65
import org.netbeans.spi.viewmodel.TreeExpansionModel;
66
import org.netbeans.spi.viewmodel.TreeModel;
67
import org.netbeans.spi.viewmodel.UnknownTypeException;
63
import org.openide.nodes.Node;
68
import org.openide.nodes.Node;
64
import org.openide.util.Exceptions;
69
import org.openide.util.Exceptions;
65
import org.openide.util.RequestProcessor;
70
import org.openide.util.RequestProcessor;
66
71
67
68
69
/**
72
/**
70
 * Tests the JPDABreakpointEvent.resume() functionality.
73
 * Tests the JPDABreakpointEvent.resume() functionality.
71
 *
74
 *
72
 * @author Maros Sandor, Jan Jancura
75
 * @author Maros Sandor, Jan Jancura
73
 */
76
 */
74
public class BasicTest  extends NbTestCase {
77
public class BasicTest extends NbTestCase {
75
78
76
    private String helpID = "A test help ID"; // NOI18N
79
    private final String helpID = "A test help ID"; // NOI18N
77
80
78
    public BasicTest (String s) {
81
    public BasicTest(String s) {
79
        super (s);
82
        super(s);
80
    }
83
    }
81
84
82
    static OutlineTable createView(final Models.CompoundModel mcm) {
85
    static OutlineTable createView(final Models.CompoundModel mcm) {
83
        final OutlineTable[] ttPtr = new OutlineTable[] { null };
86
        final OutlineTable[] ttPtr = new OutlineTable[]{null};
84
        try {
87
        try {
85
            SwingUtilities.invokeAndWait(new Runnable() {
88
            SwingUtilities.invokeAndWait(new Runnable() {
89
                @Override
86
                public void run() {
90
                public void run() {
87
                    ttPtr[0] = (OutlineTable) Models.createView(mcm);
91
                    ttPtr[0] = (OutlineTable) Models.createView(mcm);
88
                }
92
                }
Lines 96-160 Link Here
96
        return ttPtr[0];
100
        return ttPtr[0];
97
    }
101
    }
98
102
99
    public void testBasic () throws Exception {
103
    public void testBasic() throws Exception {
100
        ArrayList l = new ArrayList ();
104
        ArrayList l = new ArrayList();
101
        CompoundModel cm = new CompoundModel ();
105
        CompoundModel cm = new CompoundModel();
102
        l.add (cm);
106
        l.add(cm);
103
        Models.CompoundModel mcm = Models.createCompoundModel(l, helpID);
107
        Models.CompoundModel mcm = Models.createCompoundModel(l, helpID);
104
        OutlineTable tt = createView(mcm);
108
        OutlineTable tt = createView(mcm);
105
        RequestProcessor rp = tt.currentTreeModelRoot.getRootNode().getRequestProcessor();
109
        RequestProcessor rp = tt.currentTreeModelRoot.getRootNode().getRequestProcessor();
106
        cm.setRPUsed(rp);
110
        cm.setRPUsed(rp);
107
        waitFinished (rp);
111
        waitFinished(rp);
108
        Node n = tt.getExplorerManager ().
112
        Node n = tt.getExplorerManager().
109
            getRootContext ();
113
                getRootContext();
110
        checkNode (n, "", rp);
114
        checkNode(n, "", rp);
111
        if (cm.exception != null)
115
        if (cm.exception != null) {
112
            cm.exception.printStackTrace ();
116
            cm.exception.printStackTrace();
113
        assertNull ("Threading problem", cm.exception);
117
        }
118
        assertNull("Threading problem", cm.exception);
114
        // TODO: Expansion test does not work - probably written in a bad way...
119
        // TODO: Expansion test does not work - probably written in a bad way...
115
        //assertEquals ("nodeExpanded notification number", 3, cm.expandedTest.size ());
120
        //assertEquals ("nodeExpanded notification number", 3, cm.expandedTest.size ());
116
        //assertEquals ("nodeExpanded ", cm.toBeExpandedTest, cm.expandedTest);
121
        //assertEquals ("nodeExpanded ", cm.toBeExpandedTest, cm.expandedTest);
117
        assertEquals(n.getValue("propertiesHelpID"), helpID);
122
        assertEquals(n.getValue("propertiesHelpID"), helpID);
118
    }
123
    }
119
    
124
120
    private void checkNode (Node n, String name, RequestProcessor rp) {
125
    private void checkNode(Node n, String name, RequestProcessor rp) {
121
        // init
126
        // init
122
        //assertEquals (null, n.getShortDescription ());
127
        //assertEquals (null, n.getShortDescription ());
123
        Node[] ns = n.getChildren ().getNodes ();
128
        Node[] ns = n.getChildren().getNodes();
124
        waitFinished (rp);
129
        waitFinished(rp);
125
        
130
126
        ns = n.getChildren ().getNodes ();
131
        ns = n.getChildren().getNodes();
127
        if (name.length () < 4) {
132
        if (name.length() < 4) {
128
            assertEquals (name, 3, ns.length);
133
            assertEquals(name, 3, ns.length);
129
            checkNode (ns [0], name + "a", rp);
134
            checkNode(ns[0], name + "a", rp);
130
            checkNode (ns [1], name + "b", rp);
135
            checkNode(ns[1], name + "b", rp);
131
            checkNode (ns [2], name + "c", rp);
136
            checkNode(ns[2], name + "c", rp);
132
        } else
137
        } else {
133
            assertEquals (ns.length, 0);
138
            assertEquals(ns.length, 0);
134
        
139
        }
135
        if (name.length () > 0) {
140
141
        if (name.length() > 0) {
136
            //assertEquals (name, n.getName ());
142
            //assertEquals (name, n.getName ());
137
            n.getDisplayName ();
143
            n.getDisplayName();
138
            String sd = n.getShortDescription ();
144
            String sd = n.getShortDescription();
139
            n.getActions (false);
145
            n.getActions(false);
140
            waitFinished (rp);
146
            waitFinished(rp);
141
            assertEquals (name, n.getDisplayName ());
147
            assertEquals(name, n.getDisplayName());
142
            assertEquals (name + "WWW", sd);
148
            assertEquals(name + "WWW", sd);
143
            assertEquals (1, n.getActions (false).length);
149
            assertEquals(1, n.getActions(false).length);
144
        }
150
        }
145
    }
151
    }
146
152
147
    static void waitFinished (RequestProcessor rp) {
153
    static void waitFinished(RequestProcessor rp) {
148
        rp.post (new Runnable () {
154
        rp.post(new Runnable() {
149
            public void run () {}
155
            @Override
150
        }).waitFinished ();
156
            public void run() {
157
            }
158
        }).waitFinished();
151
    }
159
    }
152
    
160
153
    
154
    public void testMnemonics() throws Exception {
161
    public void testMnemonics() throws Exception {
155
        ArrayList l = new ArrayList ();
162
        ArrayList l = new ArrayList();
156
        CompoundModel cm = new CompoundModel ();
163
        CompoundModel cm = new CompoundModel();
157
        l.add (cm);
164
        l.add(cm);
158
        TestColumnModel tcm = new TestColumnModel();
165
        TestColumnModel tcm = new TestColumnModel();
159
        l.add(tcm);
166
        l.add(tcm);
160
        Models.CompoundModel mcm = Models.createCompoundModel(l);
167
        Models.CompoundModel mcm = Models.createCompoundModel(l);
Lines 162-445 Link Here
162
        cm.setRPUsed(tt.currentTreeModelRoot.getRootNode().getRequestProcessor());
169
        cm.setRPUsed(tt.currentTreeModelRoot.getRootNode().getRequestProcessor());
163
        Node.Property[] columns = tt.columns;
170
        Node.Property[] columns = tt.columns;
164
        assertEquals(2, columns.length);
171
        assertEquals(2, columns.length);
165
        assertEquals(new Character('e'), columns[1].getValue("ColumnMnemonicCharTTV"));
172
        assertEquals('e', columns[1].getValue("ColumnMnemonicCharTTV"));
166
    }
173
    }
167
    
174
168
    public static class CompoundModel implements TreeModel, 
175
    public static class CompoundModel implements TreeModel,
169
    NodeModel, NodeActionsProvider, TableModel, TreeExpansionModel {
176
            NodeModel, NodeActionsProvider, TableModel, TreeExpansionModel {
170
177
171
    
178
        private final Set<ModelListener> listeners = new HashSet<>();
172
        private final Set<ModelListener> listeners = new HashSet<ModelListener>();
179
173
        
174
        private Throwable exception;
180
        private Throwable exception;
175
181
176
        private Map callNumbers = new HashMap ();
182
        private final Map callNumbers = new HashMap();
177
        
183
178
        private RequestProcessor rp;
184
        private RequestProcessor rp;
179
185
180
        void setRPUsed(RequestProcessor rp) {
186
        void setRPUsed(RequestProcessor rp) {
181
            this.rp = rp;
187
            this.rp = rp;
182
        }
188
        }
183
189
184
        protected synchronized void addCall (String methodName, Object node) {
190
        protected synchronized void addCall(String methodName, Object node) {
185
            Map m = (Map) callNumbers.get (methodName);
191
            Map m = (Map) callNumbers.get(methodName);
186
            if (m == null)
192
            if (m == null) {
187
                callNumbers.put (methodName, m = new HashMap ());
193
                callNumbers.put(methodName, m = new HashMap());
188
            if (m.containsKey (node)) {
194
            }
195
            if (m.containsKey(node)) {
189
                Object info = m.get(node);
196
                Object info = m.get(node);
190
                if (info instanceof Exception) {
197
                if (info instanceof Exception) {
191
                    System.err.println ("Second call of " + methodName + " method for the same node " + node);
198
                    System.err.println("Second call of " + methodName + " method for the same node " + node);
192
                    System.err.println("First was at:");
199
                    System.err.println("First was at:");
193
                    ((Exception) info).printStackTrace();
200
                    ((Exception) info).printStackTrace();
194
                    System.err.println("Second is:");
201
                    System.err.println("Second is:");
195
                    Thread.dumpStack();
202
                    Thread.dumpStack();
196
                    m.put (node, new Integer(2));
203
                    m.put(node, 2);
197
                } else {
204
                } else {
198
                    int numCalls = ((Integer) info).intValue() + 1;
205
                    int numCalls = ((Integer) info) + 1;
199
                    System.err.println (numCalls+". call of " + methodName + " method for the same node " + node);
206
                    System.err.println(numCalls + ". call of " + methodName + " method for the same node " + node);
200
                    Thread.dumpStack();
207
                    Thread.dumpStack();
201
                    m.put (node, new Integer(numCalls));
208
                    m.put(node, numCalls);
202
                }
209
                }
203
            } else {
210
            } else {
204
                m.put (node, new Exception());
211
                m.put(node, new Exception());
205
            }
212
            }
206
        }
213
        }
207
214
208
        void checkThread () {
215
        void checkThread() {
209
            try {
216
            try {
210
                assertTrue ("The right thread", rp.isRequestProcessorThread ());
217
                assertTrue("The right thread", rp.isRequestProcessorThread());
211
            } catch (Throwable t) {
218
            } catch (Throwable t) {
212
                exception = t;
219
                exception = t;
213
            }
220
            }
214
            /*;
221
            /*;
215
            Thread t = Thread.currentThread ();
222
             Thread t = Thread.currentThread ();
216
            if ( t.getClass ().getName ().startsWith 
223
             if ( t.getClass ().getName ().startsWith 
217
                    (RequestProcessor.class.getName ())
224
             (RequestProcessor.class.getName ())
218
            ) exception = new Exception ();
225
             ) exception = new Exception ();
219
             */
226
             */
220
        }
227
        }
221
228
222
        // TreeModel ...............................................................
229
        // TreeModel ...............................................................
223
230
        /**
224
        /** 
225
         * Returns the root node of the tree or null, if the tree is empty.
231
         * Returns the root node of the tree or null, if the tree is empty.
226
         *
232
         *
227
         * @return the root node of the tree or null
233
         * @return the root node of the tree or null
228
         */
234
         */
229
        public Object getRoot () {
235
        @Override
236
        public Object getRoot() {
230
            //addCall ("getRoot", null);
237
            //addCall ("getRoot", null);
231
            return ROOT;
238
            return ROOT;
232
        }
239
        }
233
240
234
        /** 
241
        /**
235
         * Returns children for given parent on given indexes.
242
         * Returns children for given parent on given indexes.
236
         *
243
         *
237
         * @param   parent a parent of returned nodes
244
         * @param parent a parent of returned nodes
238
         * @throws  UnknownTypeException if this TreeModel implementation is not
245
         * @throws UnknownTypeException if this TreeModel implementation is not
239
         *          able to resolve dchildren for given node type
246
         * able to resolve dchildren for given node type
240
         *
247
         *
241
         * @return  children for given parent on given indexes
248
         * @return children for given parent on given indexes
242
         */
249
         */
243
        public Object[] getChildren (Object parent, int from, int to) 
250
        @Override
244
        throws UnknownTypeException {
251
        public Object[] getChildren(Object parent, int from, int to)
245
            addCall ("getChildren", parent);
252
                throws UnknownTypeException {
246
            if (parent == ROOT)
253
            addCall("getChildren", parent);
247
                return new Object[] {"a", "b", "c"};
254
            if (parent == ROOT) {
248
            if (parent instanceof String)
255
                return new Object[]{"a", "b", "c"};
249
                return new Object[] {parent + "a", parent + "b", parent + "c"};
256
            }
250
            throw new UnknownTypeException (parent);
257
            if (parent instanceof String) {
258
                return new Object[]{parent + "a", parent + "b", parent + "c"};
259
            }
260
            throw new UnknownTypeException(parent);
251
        }
261
        }
252
262
253
        /**
263
        /**
254
         * Returns number of children for given node.
264
         * Returns number of children for given node.
255
         * 
265
         *
256
         * @param   node the parent node
266
         * @param node the parent node
257
         * @throws  UnknownTypeException if this TreeModel implementation is not
267
         * @throws UnknownTypeException if this TreeModel implementation is not
258
         *          able to resolve children for given node type
268
         * able to resolve children for given node type
259
         *
269
         *
260
         * @return  true if node is leaf
270
         * @return true if node is leaf
261
         */
271
         */
262
        public int getChildrenCount (Object node) throws UnknownTypeException {
272
        @Override
263
            addCall ("getChildrenCount", node);
273
        public int getChildrenCount(Object node) throws UnknownTypeException {
264
            if (node == ROOT)
274
            addCall("getChildrenCount", node);
275
            if (node == ROOT) {
265
                return 3;
276
                return 3;
266
            if (node instanceof String)
277
            }
278
            if (node instanceof String) {
267
                return 3;
279
                return 3;
268
            throw new UnknownTypeException (node);
280
            }
281
            throw new UnknownTypeException(node);
269
        }
282
        }
270
283
271
        /**
284
        /**
272
         * Returns true if node is leaf.
285
         * Returns true if node is leaf.
273
         * 
286
         *
274
         * @throws  UnknownTypeException if this TreeModel implementation is not
287
         * @throws UnknownTypeException if this TreeModel implementation is not
275
         *          able to resolve dchildren for given node type
288
         * able to resolve dchildren for given node type
276
         * @return  true if node is leaf
289
         * @return true if node is leaf
277
         */
290
         */
278
        public boolean isLeaf (Object node) throws UnknownTypeException {
291
        @Override
279
            addCall ("isLeaf", node);
292
        public boolean isLeaf(Object node) throws UnknownTypeException {
280
            if (node == ROOT)
293
            addCall("isLeaf", node);
294
            if (node == ROOT) {
281
                return false;
295
                return false;
282
            if (node instanceof String)
296
            }
283
                return ((String) node).length () > 3;
297
            if (node instanceof String) {
284
            throw new UnknownTypeException (node);
298
                return ((String) node).length() > 3;
299
            }
300
            throw new UnknownTypeException(node);
285
        }
301
        }
286
302
287
288
        // NodeModel ...........................................................
303
        // NodeModel ...........................................................
289
290
        /**
304
        /**
291
         * Returns display name for given node.
305
         * Returns display name for given node.
292
         *
306
         *
293
         * @throws  UnknownTypeException if this NodeModel implementation is not
307
         * @throws UnknownTypeException if this NodeModel implementation is not
294
         *          able to resolve display name for given node type
308
         * able to resolve display name for given node type
295
         * @return  display name for given node
309
         * @return display name for given node
296
         */
310
         */
297
        public String getDisplayName (Object node) throws UnknownTypeException {
311
        @Override
298
            addCall ("getDisplayName", node);
312
        public String getDisplayName(Object node) throws UnknownTypeException {
313
            addCall("getDisplayName", node);
299
            //checkThread ();
314
            //checkThread ();
300
            if (node instanceof String)
315
            if (node instanceof String) {
301
                return (String) node;
316
                return (String) node;
302
            throw new UnknownTypeException (node);
317
            }
318
            throw new UnknownTypeException(node);
303
        }
319
        }
304
320
305
        /**
321
        /**
306
         * Returns tooltip for given node.
322
         * Returns tooltip for given node.
307
         *
323
         *
308
         * @throws  UnknownTypeException if this NodeModel implementation is not
324
         * @throws UnknownTypeException if this NodeModel implementation is not
309
         *          able to resolve tooltip for given node type
325
         * able to resolve tooltip for given node type
310
         * @return  tooltip for given node
326
         * @return tooltip for given node
311
         */
327
         */
312
        public String getShortDescription (Object node) 
328
        @Override
313
        throws UnknownTypeException {
329
        public String getShortDescription(Object node)
314
            addCall ("getShortDescription", node);
330
                throws UnknownTypeException {
331
            addCall("getShortDescription", node);
315
            //checkThread (); Short description is called on AWT! How else we could display a tooltip?
332
            //checkThread (); Short description is called on AWT! How else we could display a tooltip?
316
            if (node == ROOT)
333
            if (node == ROOT) {
317
                return "";
334
                return "";
318
            if (node instanceof String)
335
            }
336
            if (node instanceof String) {
319
                return node + "WWW";
337
                return node + "WWW";
320
            throw new UnknownTypeException (node);
338
            }
339
            throw new UnknownTypeException(node);
321
        }
340
        }
322
341
323
        /**
342
        /**
324
         * Returns icon for given node.
343
         * Returns icon for given node.
325
         *
344
         *
326
         * @throws  UnknownTypeException if this NodeModel implementation is not
345
         * @throws UnknownTypeException if this NodeModel implementation is not
327
         *          able to resolve icon for given node type
346
         * able to resolve icon for given node type
328
         * @return  icon for given node
347
         * @return icon for given node
329
         */
348
         */
330
        public String getIconBase (Object node) 
349
        @Override
331
        throws UnknownTypeException {
350
        public String getIconBase(Object node)
332
            addCall ("getIconBase", node);
351
                throws UnknownTypeException {
352
            addCall("getIconBase", node);
333
            //checkThread ();
353
            //checkThread ();
334
            if (node instanceof String)
354
            if (node instanceof String) {
335
                return node + "XXX";
355
                return node + "XXX";
336
            throw new UnknownTypeException (node);
356
            }
357
            throw new UnknownTypeException(node);
337
        }
358
        }
338
359
339
340
        // NodeActionsProvider .....................................................
360
        // NodeActionsProvider .....................................................
341
342
        /**
361
        /**
343
         * Performs default action for given node.
362
         * Performs default action for given node.
344
         *
363
         *
345
         * @throws  UnknownTypeException if this NodeActionsProvider implementation 
364
         * @throws UnknownTypeException if this NodeActionsProvider
346
         *          is not able to resolve actions for given node type
365
         * implementation is not able to resolve actions for given node type
347
         * @return  display name for given node
366
         * @return display name for given node
348
         */
367
         */
349
        public void performDefaultAction (Object node) throws UnknownTypeException {
368
        @Override
369
        public void performDefaultAction(Object node) throws UnknownTypeException {
350
        }
370
        }
351
371
352
        /**
372
        /**
353
         * Returns set of actions for given node.
373
         * Returns set of actions for given node.
354
         *
374
         *
355
         * @throws  UnknownTypeException if this NodeActionsProvider implementation 
375
         * @throws UnknownTypeException if this NodeActionsProvider
356
         *          is not able to resolve actions for given node type
376
         * implementation is not able to resolve actions for given node type
357
         * @return  display name for given node
377
         * @return display name for given node
358
         */
378
         */
359
        public Action[] getActions (Object node) throws UnknownTypeException {
379
        @Override
380
        public Action[] getActions(Object node) throws UnknownTypeException {
360
            //checkThread ();
381
            //checkThread ();
361
            if (node == ROOT)
382
            if (node == ROOT) {
362
                return new Action [0];
383
                return new Action[0];
363
            if (node instanceof String)
384
            }
364
                return new Action[] {
385
            if (node instanceof String) {
365
                    new AbstractAction ((String) node) {
386
                return new Action[]{
366
                        public void actionPerformed (ActionEvent ev) {
387
                    new AbstractAction((String) node) {
367
                            
388
                        @Override
389
                        public void actionPerformed(ActionEvent ev) {
390
368
                        }
391
                        }
369
                    },
392
                    },};
370
                };
393
            }
371
            throw new UnknownTypeException (node);
394
            throw new UnknownTypeException(node);
372
        }
395
        }
373
396
374
375
        // ColumnsModel ............................................................
397
        // ColumnsModel ............................................................
376
377
        /**
398
        /**
378
         * Returns sorted array of 
399
         * Returns sorted array of
379
         * {@link org.netbeans.spi.viewmodel.ColumnModel}s.
400
         * {@link org.netbeans.spi.viewmodel.ColumnModel}s.
380
         *
401
         *
381
         * @return sorted array of ColumnModels
402
         * @return sorted array of ColumnModels
382
         */
403
         */
383
        public ColumnModel[] getColumns () {
404
        public ColumnModel[] getColumns() {
384
            return new ColumnModel [0];
405
            return new ColumnModel[0];
385
        }
406
        }
386
407
387
388
        // TableModel ..............................................................
408
        // TableModel ..............................................................
389
409
        @Override
390
        public Object getValueAt (Object node, String columnID) throws 
410
        public Object getValueAt(Object node, String columnID) throws
391
        UnknownTypeException {
411
                UnknownTypeException {
392
            addCall ("getValueAt", node);
412
            addCall("getValueAt", node);
393
            checkThread ();
413
            checkThread();
394
            if (node instanceof String) {
414
            if (node instanceof String) {
395
                if (columnID.equals ("1"))
415
                if (columnID.equals("1")) {
396
                    return node + "1";
416
                    return node + "1";
397
                if (columnID.equals ("2"))
417
                }
418
                if (columnID.equals("2")) {
398
                    return node + "2";
419
                    return node + "2";
420
                }
399
            }
421
            }
400
            throw new UnknownTypeException (node);
422
            throw new UnknownTypeException(node);
401
        }
423
        }
402
424
403
        public boolean isReadOnly (Object node, String columnID) throws 
425
        @Override
404
        UnknownTypeException {
426
        public boolean isReadOnly(Object node, String columnID) throws
405
            addCall ("isReadOnly", node);
427
                UnknownTypeException {
406
            checkThread ();
428
            addCall("isReadOnly", node);
429
            checkThread();
407
            if (node instanceof String) {
430
            if (node instanceof String) {
408
                if (columnID.equals ("1"))
431
                if (columnID.equals("1")) {
409
                    return true;
432
                    return true;
410
                if (columnID.equals ("2"))
433
                }
434
                if (columnID.equals("2")) {
411
                    return true;
435
                    return true;
436
                }
412
            }
437
            }
413
            throw new UnknownTypeException (node);
438
            throw new UnknownTypeException(node);
414
        }
439
        }
415
440
416
        public void setValueAt (Object node, String columnID, Object value) throws 
441
        @Override
417
        UnknownTypeException {
442
        public void setValueAt(Object node, String columnID, Object value) throws
418
            throw new UnknownTypeException (node);
443
                UnknownTypeException {
444
            throw new UnknownTypeException(node);
419
        }
445
        }
420
446
421
422
        // TreeExpansionModel ......................................................
447
        // TreeExpansionModel ......................................................
448
        private final Set toBeExpandedTest = new HashSet();
449
        private final Set expandedTest = new HashSet();
423
450
424
        private Set toBeExpandedTest = new HashSet ();
425
        private Set expandedTest = new HashSet ();
426
        {
451
        {
427
            toBeExpandedTest.add (getRoot());
452
            toBeExpandedTest.add(getRoot());
428
            toBeExpandedTest.add ("a");
453
            toBeExpandedTest.add("a");
429
            toBeExpandedTest.add ("ab");
454
            toBeExpandedTest.add("ab");
430
            toBeExpandedTest.add ("abc");
455
            toBeExpandedTest.add("abc");
431
        }
456
        }
432
        
457
433
        /**
458
        /**
434
         * Defines default state (collapsed, expanded) of given node.
459
         * Defines default state (collapsed, expanded) of given node.
435
         *
460
         *
436
         * @param node a node
461
         * @param node a node
437
         * @return default state (collapsed, expanded) of given node
462
         * @return default state (collapsed, expanded) of given node
438
         */
463
         */
439
        public boolean isExpanded (Object node) throws UnknownTypeException {
464
        @Override
440
            if (node instanceof String)
465
        public boolean isExpanded(Object node) throws UnknownTypeException {
441
                return toBeExpandedTest.contains (node);
466
            if (node instanceof String) {
442
            throw new UnknownTypeException (node);
467
                return toBeExpandedTest.contains(node);
468
            }
469
            throw new UnknownTypeException(node);
443
        }
470
        }
444
471
445
        /**
472
        /**
Lines 447-458 Link Here
447
         *
474
         *
448
         * @param node a expanded node
475
         * @param node a expanded node
449
         */
476
         */
450
        public void nodeExpanded (Object node) {
477
        @Override
451
            if (!toBeExpandedTest.contains (node)) {
478
        public void nodeExpanded(Object node) {
479
            if (!toBeExpandedTest.contains(node)) {
452
                System.err.println("This node should not be expanded: " + node);
480
                System.err.println("This node should not be expanded: " + node);
453
                Thread.dumpStack();
481
                Thread.dumpStack();
454
            }
482
            }
455
            expandedTest.add (node);
483
            expandedTest.add(node);
456
        }
484
        }
457
485
458
        /**
486
        /**
Lines 460-531 Link Here
460
         *
488
         *
461
         * @param node a collapsed node
489
         * @param node a collapsed node
462
         */
490
         */
463
        public void nodeCollapsed (Object node) {
491
        @Override
492
        public void nodeCollapsed(Object node) {
464
            System.err.println("nodeCollapsed " + node);
493
            System.err.println("nodeCollapsed " + node);
465
            Thread.dumpStack();
494
            Thread.dumpStack();
466
        }
495
        }
467
496
468
469
        // listeners ...............................................................
497
        // listeners ...............................................................
470
498
        /**
471
        /** 
472
         * Registers given listener.
499
         * Registers given listener.
473
         * 
500
         *
474
         * @param l the listener to add
501
         * @param l the listener to add
475
         */
502
         */
476
        public void addModelListener (ModelListener l) {
503
        @Override
504
        public void addModelListener(ModelListener l) {
477
            synchronized (listeners) {
505
            synchronized (listeners) {
478
                listeners.add (l);
506
                listeners.add(l);
479
            }
507
            }
480
        }
508
        }
481
509
482
        /** 
510
        /**
483
         * Unregisters given listener.
511
         * Unregisters given listener.
484
         *
512
         *
485
         * @param l the listener to remove
513
         * @param l the listener to remove
486
         */
514
         */
487
        public void removeModelListener (ModelListener l) {
515
        @Override
516
        public void removeModelListener(ModelListener l) {
488
            synchronized (listeners) {
517
            synchronized (listeners) {
489
                listeners.remove (l);
518
                listeners.remove(l);
490
            }
519
            }
491
        }
520
        }
492
        
521
493
        public void fire () {
522
        public void fire() {
494
            List<ModelListener> v;
523
            List<ModelListener> v;
495
            synchronized (listeners) {
524
            synchronized (listeners) {
496
                v = new ArrayList<ModelListener>(listeners);
525
                v = new ArrayList<>(listeners);
526
            }
527
            int i, k = v.size();
528
            for (i = 0; i < k; i++) {
529
                ((ModelListener) v.get(i)).modelChanged(null);
497
            }
530
            }
498
            int i, k = v.size ();
499
            for (i = 0; i < k; i++)
500
                ((ModelListener) v.get (i)).modelChanged (null);
501
        }
531
        }
502
        
532
503
        public void fire (ModelEvent event) {
533
        public void fire(ModelEvent event) {
504
            List<ModelListener> v;
534
            List<ModelListener> v;
505
            synchronized (listeners) {
535
            synchronized (listeners) {
506
                v = new ArrayList<ModelListener>(listeners);
536
                v = new ArrayList<>(listeners);
507
            }
537
            }
508
            int i, k = v.size ();
538
            int i, k = v.size();
509
            for (i = 0; i < k; i++) {
539
            for (i = 0; i < k; i++) {
510
                ((ModelListener) v.get (i)).modelChanged (event);
540
                ((ModelListener) v.get(i)).modelChanged(event);
511
            }
541
            }
512
        }
542
        }
513
    }
543
    }
514
    
544
515
    private static class TestColumnModel extends ColumnModel {
545
    private static class TestColumnModel extends ColumnModel {
546
547
        @Override
516
        public Class getType() {
548
        public Class getType() {
517
            return String.class;
549
            return String.class;
518
        }
550
        }
519
551
552
        @Override
520
        public String getDisplayName() {
553
        public String getDisplayName() {
521
            return "Test";
554
            return "Test";
522
        }
555
        }
523
556
524
        @Override
557
        @Override
525
        public Character getDisplayedMnemonic() {
558
        public Character getDisplayedMnemonic() {
526
            return new Character('e');
559
            return 'e';
527
        }
560
        }
528
561
562
        @Override
529
        public String getID() {
563
        public String getID() {
530
            return "xx";
564
            return "xx";
531
        }
565
        }
(-)/home/enrico/Lavoro/releases/spi.viewmodel/test/unit/src/org/netbeans/modules/viewmodel/CountedModel.java (-24 / +63 lines)
Lines 39-45 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.viewmodel;
42
package org.netbeans.modules.viewmodel;
44
43
45
import java.awt.datatransfer.Transferable;
44
import java.awt.datatransfer.Transferable;
Lines 76-86 Link Here
76
75
77
    private final String[] rootChildren;
76
    private final String[] rootChildren;
78
    private final int depth;
77
    private final int depth;
79
    private final Map<Object, Object[]> cachedChildren = new HashMap<Object, Object[]>();
78
    private final Map<Object, Object[]> cachedChildren = new HashMap<>();
80
    private final List<ModelListener> listeners = new ArrayList<ModelListener>();
79
    private final List<ModelListener> listeners = new ArrayList<>();
81
    private final Map<Object, Boolean> selectedNodes = new HashMap<Object, Boolean>();
80
    private final Map<Object, Boolean> selectedNodes = new HashMap<>();
82
    private final Map<Object, Map<String, Object>> changedValues = new HashMap<Object, Map<String, Object>>();
81
    private final Map<Object, Map<String, Object>> changedValues = new HashMap<>();
83
    private final Set<CountedCall> countedCalls = new HashSet<CountedCall>();
82
    private final Set<CountedCall> countedCalls = new HashSet<>();
84
83
85
    public CountedModel(String[] children, int depth) {
84
    public CountedModel(String[] children, int depth) {
86
        rootChildren = children;
85
        rootChildren = children;
Lines 88-104 Link Here
88
    }
87
    }
89
88
90
    public ColumnModel[] createColumns() {
89
    public ColumnModel[] createColumns() {
91
        return new ColumnModel[] {
90
        return new ColumnModel[]{
92
            new CountedColumn(COLUMN_LC),
91
            new CountedColumn(COLUMN_LC),
93
            new CountedColumn(COLUMN_UC),
92
            new CountedColumn(COLUMN_UC),
94
            new CountedColumn(COLUMN_BYTES),
93
            new CountedColumn(COLUMN_BYTES),};
95
        };
96
    }
94
    }
97
95
96
    @Override
98
    public Object getRoot() {
97
    public Object getRoot() {
99
        return ROOT;
98
        return ROOT;
100
    }
99
    }
101
100
101
    @Override
102
    public Object[] getChildren(Object parent, int from, int to) throws UnknownTypeException {
102
    public Object[] getChildren(Object parent, int from, int to) throws UnknownTypeException {
103
        //System.err.println("\n\nget CHILDREN("+this+", on "+parent);
103
        //System.err.println("\n\nget CHILDREN("+this+", on "+parent);
104
        //System.err.println("  counted calls before = "+getCountedCalls("getChildren", parent)+"\n\n");
104
        //System.err.println("  counted calls before = "+getCountedCalls("getChildren", parent)+"\n\n");
Lines 119-137 Link Here
119
        }
119
        }
120
    }
120
    }
121
121
122
    @Override
122
    public boolean isLeaf(Object node) throws UnknownTypeException {
123
    public boolean isLeaf(Object node) throws UnknownTypeException {
123
        countCall("isLeaf", node);
124
        countCall("isLeaf", node);
124
        String s = (String) node;
125
        String s = (String) node;
125
        int d = 0;
126
        int d = 0;
126
        for (int i = 0; (i = s.indexOf('/', i+1)) > 0; d++) ;
127
        for (int i = 0; (i = s.indexOf('/', i + 1)) > 0; d++) ;
127
        return d >= depth;
128
        return d >= depth;
128
    }
129
    }
129
130
131
    @Override
130
    public int getChildrenCount(Object node) throws UnknownTypeException {
132
    public int getChildrenCount(Object node) throws UnknownTypeException {
131
        countCall("getChildrenCount", node);
133
        countCall("getChildrenCount", node);
132
        return rootChildren.length;
134
        return rootChildren.length;
133
    }
135
    }
134
136
137
    @Override
135
    public void addModelListener(ModelListener l) {
138
    public void addModelListener(ModelListener l) {
136
        //System.err.println(this+".addModelListener("+l+")");
139
        //System.err.println(this+".addModelListener("+l+")");
137
        //Thread.dumpStack();
140
        //Thread.dumpStack();
Lines 141-146 Link Here
141
        //System.err.println("  listeners = "+listeners);
144
        //System.err.println("  listeners = "+listeners);
142
    }
145
    }
143
146
147
    @Override
144
    public void removeModelListener(ModelListener l) {
148
    public void removeModelListener(ModelListener l) {
145
        //System.err.println(this+".removeModelListener("+l+")");
149
        //System.err.println(this+".removeModelListener("+l+")");
146
        //Thread.dumpStack();
150
        //Thread.dumpStack();
Lines 150-229 Link Here
150
        //System.err.println("  listeners = "+listeners);
154
        //System.err.println("  listeners = "+listeners);
151
    }
155
    }
152
156
157
    @Override
153
    public boolean canRename(Object node) throws UnknownTypeException {
158
    public boolean canRename(Object node) throws UnknownTypeException {
154
        countCall("canRename", node);
159
        countCall("canRename", node);
155
        return true;
160
        return true;
156
    }
161
    }
157
162
163
    @Override
158
    public boolean canCopy(Object node) throws UnknownTypeException {
164
    public boolean canCopy(Object node) throws UnknownTypeException {
159
        countCall("canCopy", node);
165
        countCall("canCopy", node);
160
        return true;
166
        return true;
161
    }
167
    }
162
168
169
    @Override
163
    public boolean canCut(Object node) throws UnknownTypeException {
170
    public boolean canCut(Object node) throws UnknownTypeException {
164
        countCall("canCut", node);
171
        countCall("canCut", node);
165
        return true;
172
        return true;
166
    }
173
    }
167
174
175
    @Override
168
    public Transferable clipboardCopy(Object node) throws IOException, UnknownTypeException {
176
    public Transferable clipboardCopy(Object node) throws IOException, UnknownTypeException {
169
        countCall("clipboardCopy", node);
177
        countCall("clipboardCopy", node);
170
        return null;
178
        return null;
171
    }
179
    }
172
180
181
    @Override
173
    public Transferable clipboardCut(Object node) throws IOException, UnknownTypeException {
182
    public Transferable clipboardCut(Object node) throws IOException, UnknownTypeException {
174
        countCall("clipboardCut", node);
183
        countCall("clipboardCut", node);
175
        return null;
184
        return null;
176
    }
185
    }
177
186
187
    @Override
178
    public PasteType[] getPasteTypes(Object node, Transferable t) throws UnknownTypeException {
188
    public PasteType[] getPasteTypes(Object node, Transferable t) throws UnknownTypeException {
179
        countCall("getPasteTypes", node, t);
189
        countCall("getPasteTypes", node, t);
180
        return new PasteType[] {};
190
        return new PasteType[]{};
181
    }
191
    }
182
192
193
    @Override
183
    public void setName(Object node, String name) throws UnknownTypeException {
194
    public void setName(Object node, String name) throws UnknownTypeException {
184
        countCall("setName", node, name);
195
        countCall("setName", node, name);
185
    }
196
    }
186
197
198
    @Override
187
    public String getIconBaseWithExtension(Object node) throws UnknownTypeException {
199
    public String getIconBaseWithExtension(Object node) throws UnknownTypeException {
188
        countCall("getIconBaseWithExtension", node);
200
        countCall("getIconBaseWithExtension", node);
189
        return null;
201
        return null;
190
    }
202
    }
191
203
204
    @Override
192
    public String getDisplayName(Object node) throws UnknownTypeException {
205
    public String getDisplayName(Object node) throws UnknownTypeException {
193
        countCall("getDisplayName", node);
206
        countCall("getDisplayName", node);
194
        return node.toString().replace('/', '-');
207
        return node.toString().replace('/', '-');
195
    }
208
    }
196
209
210
    @Override
197
    public String getIconBase(Object node) throws UnknownTypeException {
211
    public String getIconBase(Object node) throws UnknownTypeException {
198
        countCall("getIconBase", node);
212
        countCall("getIconBase", node);
199
        return null;
213
        return null;
200
    }
214
    }
201
215
216
    @Override
202
    public String getShortDescription(Object node) throws UnknownTypeException {
217
    public String getShortDescription(Object node) throws UnknownTypeException {
203
        countCall("getShortDescription", node);
218
        countCall("getShortDescription", node);
204
        return node.toString() + " => " + node.toString().replace('/', '-');
219
        return node.toString() + " => " + node.toString().replace('/', '-');
205
    }
220
    }
206
221
222
    @Override
207
    public boolean isCheckable(Object node) throws UnknownTypeException {
223
    public boolean isCheckable(Object node) throws UnknownTypeException {
208
        countCall("isCheckable", node);
224
        countCall("isCheckable", node);
209
        return true;
225
        return true;
210
    }
226
    }
211
227
228
    @Override
212
    public boolean isCheckEnabled(Object node) throws UnknownTypeException {
229
    public boolean isCheckEnabled(Object node) throws UnknownTypeException {
213
        countCall("isCheckEnabled", node);
230
        countCall("isCheckEnabled", node);
214
        return true;
231
        return true;
215
    }
232
    }
216
233
234
    @Override
217
    public Boolean isSelected(Object node) throws UnknownTypeException {
235
    public Boolean isSelected(Object node) throws UnknownTypeException {
218
        countCall("isSelected", node);
236
        countCall("isSelected", node);
219
        return selectedNodes.containsKey(node) && selectedNodes.get(node);
237
        return selectedNodes.containsKey(node) && selectedNodes.get(node);
220
    }
238
    }
221
239
240
    @Override
222
    public void setSelected(Object node, Boolean selected) throws UnknownTypeException {
241
    public void setSelected(Object node, Boolean selected) throws UnknownTypeException {
223
        countCall("setSelected", node);
242
        countCall("setSelected", node);
224
        selectedNodes.put(node, selected);
243
        selectedNodes.put(node, selected);
225
    }
244
    }
226
245
246
    @Override
247
    public void setSelected(Object... nodes) throws UnknownTypeException {
248
        countCall("setSelected", nodes);
249
        for (Object node : nodes) {
250
            selectedNodes.put(node, true);
251
        }
252
    }
253
254
    @Override
255
    public void setUnselected(Object... nodes) throws UnknownTypeException {
256
        countCall("setUnselected", nodes);
257
        for (Object node : nodes) {
258
            selectedNodes.put(node, false);
259
        }
260
    }
261
262
    @Override
227
    public Object getValueAt(Object node, String columnID) throws UnknownTypeException {
263
    public Object getValueAt(Object node, String columnID) throws UnknownTypeException {
228
        countCall("getValueAt", node, columnID);
264
        countCall("getValueAt", node, columnID);
229
        Map<String, Object> values = changedValues.get(node);
265
        Map<String, Object> values = changedValues.get(node);
Lines 242-260 Link Here
242
        if (columnID.equals(COLUMN_BYTES)) {
278
        if (columnID.equals(COLUMN_BYTES)) {
243
            return Arrays.toString(node.toString().getBytes());
279
            return Arrays.toString(node.toString().getBytes());
244
        }
280
        }
245
        throw new UnknownTypeException(node+".getValue("+columnID+")");
281
        throw new UnknownTypeException(node + ".getValue(" + columnID + ")");
246
    }
282
    }
247
283
284
    @Override
248
    public boolean isReadOnly(Object node, String columnID) throws UnknownTypeException {
285
    public boolean isReadOnly(Object node, String columnID) throws UnknownTypeException {
249
        countCall("isReadOnly", node, columnID);
286
        countCall("isReadOnly", node, columnID);
250
        return false;
287
        return false;
251
    }
288
    }
252
289
290
    @Override
253
    public void setValueAt(Object node, String columnID, Object value) throws UnknownTypeException {
291
    public void setValueAt(Object node, String columnID, Object value) throws UnknownTypeException {
254
        countCall("setValueAt", node, columnID, value);
292
        countCall("setValueAt", node, columnID, value);
255
        Map<String, Object> values = changedValues.get(node);
293
        Map<String, Object> values = changedValues.get(node);
256
        if (values == null) {
294
        if (values == null) {
257
            values = new HashMap<String, Object>();
295
            values = new HashMap<>();
258
            changedValues.put(node, values);
296
            changedValues.put(node, values);
259
        }
297
        }
260
        values.put(columnID, value);
298
        values.put(columnID, value);
Lines 290-302 Link Here
290
    }
328
    }
291
329
292
    public CountedCall[] getCountedCalls(String methodName) {
330
    public CountedCall[] getCountedCalls(String methodName) {
293
        List<CountedCall> ccs = new ArrayList<CountedCall>();
331
        List<CountedCall> ccs = new ArrayList<>();
294
        for (CountedCall cc : countedCalls) {
332
        for (CountedCall cc : countedCalls) {
295
            if (methodName.equals(cc.methodName)) {
333
            if (methodName.equals(cc.methodName)) {
296
                ccs.add(cc);
334
                ccs.add(cc);
297
            }
335
            }
298
        }
336
        }
299
        return ccs.toArray(new CountedCall[] {});
337
        return ccs.toArray(new CountedCall[]{});
300
    }
338
    }
301
339
302
    public CountedCall getCountedCalls(String methodName, Object... params) {
340
    public CountedCall getCountedCalls(String methodName, Object... params) {
Lines 310-323 Link Here
310
348
311
    @Override
349
    @Override
312
    public String toString() {
350
    public String toString() {
313
        return this.getClass().getSimpleName()+"("+Arrays.toString(rootChildren)+")";
351
        return this.getClass().getSimpleName() + "(" + Arrays.toString(rootChildren) + ")";
314
    }
352
    }
315
353
316
    static class CountedCall {
354
    static class CountedCall {
317
355
318
        private final String methodName;
356
        private final String methodName;
319
        private final Object[] params;
357
        private final Object[] params;
320
        private final List<Throwable> calls = new ArrayList<Throwable>();
358
        private final List<Throwable> calls = new ArrayList<>();
321
359
322
        CountedCall(String methodName, Object... params) {
360
        CountedCall(String methodName, Object... params) {
323
            this.methodName = methodName;
361
            this.methodName = methodName;
Lines 334-340 Link Here
334
        }
372
        }
335
373
336
        Throwable[] callStacks() {
374
        Throwable[] callStacks() {
337
            return calls.toArray(new Throwable[] {});
375
            return calls.toArray(new Throwable[]{});
338
        }
376
        }
339
377
340
        @Override
378
        @Override
Lines 359-381 Link Here
359
397
360
        @Override
398
        @Override
361
        public String toString() {
399
        public String toString() {
362
            String str = "CountedCall("+methodName+", "+Arrays.toString(params)+") called "+numCalls()+" times.\n";
400
            String str = "CountedCall(" + methodName + ", " + Arrays.toString(params) + ") called " + numCalls() + " times.\n";
363
            for (int i = 0; i < calls.size(); i++) {
401
            for (int i = 0; i < calls.size(); i++) {
364
                Throwable t = calls.get(i);
402
                Throwable t = calls.get(i);
365
                StringWriter sw = new StringWriter();
403
                StringWriter sw = new StringWriter();
366
                PrintWriter pw = new PrintWriter(sw);
404
                PrintWriter pw = new PrintWriter(sw);
367
                t.printStackTrace(pw);
405
                t.printStackTrace(pw);
368
                pw.flush();
406
                pw.flush();
369
                str = str + " " + (i+1) + ".: " + sw.toString() + "\n";
407
                str = str + " " + (i + 1) + ".: " + sw.toString() + "\n";
370
            }
408
            }
371
            return str;
409
            return str;
372
        }
410
        }
373
411
374
        private static class Counter extends Exception {}
412
        private static class Counter extends Exception {
413
        }
375
    }
414
    }
376
415
377
    static class CountedColumn extends ColumnModel {
416
    static class CountedColumn extends ColumnModel {
378
        
417
379
        private final String id;
418
        private final String id;
380
419
381
        public CountedColumn(String id) {
420
        public CountedColumn(String id) {
Lines 389-401 Link Here
389
428
390
        @Override
429
        @Override
391
        public String getDisplayName() {
430
        public String getDisplayName() {
392
            return "Column "+id;
431
            return "Column " + id;
393
        }
432
        }
394
433
395
        @Override
434
        @Override
396
        public Class getType() {
435
        public Class getType() {
397
            return String.class;
436
            return String.class;
398
        }
437
        }
399
        
438
400
    }
439
    }
401
}
440
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/test/unit/src/org/netbeans/modules/viewmodel/HyperModelSingleAccessTest.java (-28 / +34 lines)
Lines 39-45 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.viewmodel;
42
package org.netbeans.modules.viewmodel;
44
43
45
import java.util.ArrayList;
44
import java.util.ArrayList;
Lines 53-59 Link Here
53
52
54
/**
53
/**
55
 * Tests that hyper compund models are accessed just once when events are fired.
54
 * Tests that hyper compund models are accessed just once when events are fired.
56
 * 
55
 *
57
 * @author Martin Entlicher
56
 * @author Martin Entlicher
58
 */
57
 */
59
public class HyperModelSingleAccessTest extends NbTestCase {
58
public class HyperModelSingleAccessTest extends NbTestCase {
Lines 62-94 Link Here
62
    private CountedModel cm2;
61
    private CountedModel cm2;
63
    private Node root;
62
    private Node root;
64
63
65
    public HyperModelSingleAccessTest (String s) {
64
    public HyperModelSingleAccessTest(String s) {
66
        super (s);
65
        super(s);
67
    }
66
    }
68
67
69
    private void setUpTwoModels() {
68
    private void setUpTwoModels() {
70
        cm1 = new CountedModel(new String[] { "1", "2", "3" }, 2);
69
        cm1 = new CountedModel(new String[]{"1", "2", "3"}, 2);
71
        cm2 = new CountedModel(new String[] { "a", "b", "c" }, 2);
70
        cm2 = new CountedModel(new String[]{"a", "b", "c"}, 2);
72
71
73
        ArrayList l = new ArrayList ();
72
        ArrayList l = new ArrayList();
74
        l.add(cm1);
73
        l.add(cm1);
75
        l.addAll(Arrays.asList(cm1.createColumns()));
74
        l.addAll(Arrays.asList(cm1.createColumns()));
76
        Models.CompoundModel mcm1 = Models.createCompoundModel(l);
75
        Models.CompoundModel mcm1 = Models.createCompoundModel(l);
77
        l = new ArrayList ();
76
        l = new ArrayList();
78
        l.add(cm2);
77
        l.add(cm2);
79
        l.addAll(Arrays.asList(cm2.createColumns()));
78
        l.addAll(Arrays.asList(cm2.createColumns()));
80
        Models.CompoundModel mcm2 = Models.createCompoundModel(l);
79
        Models.CompoundModel mcm2 = Models.createCompoundModel(l);
81
80
82
        l = new ArrayList ();
81
        l = new ArrayList();
83
        l.add(mcm1);
82
        l.add(mcm1);
84
        l.add(mcm2);
83
        l.add(mcm2);
85
        Models.CompoundModel mcmh = Models.createCompoundModel(l);
84
        Models.CompoundModel mcmh = Models.createCompoundModel(l);
86
        OutlineTable tt = BasicTest.createView(mcmh);
85
        OutlineTable tt = BasicTest.createView(mcmh);
87
        
86
88
        RequestProcessor rp = tt.currentTreeModelRoot.getRootNode().getRequestProcessor();
87
        RequestProcessor rp = tt.currentTreeModelRoot.getRootNode().getRequestProcessor();
89
        BasicTest.waitFinished (rp);
88
        BasicTest.waitFinished(rp);
90
89
91
        root = tt.getExplorerManager ().getRootContext ();
90
        root = tt.getExplorerManager().getRootContext();
92
    }
91
    }
93
92
94
    public void testChildren() {
93
    public void testChildren() {
Lines 96-136 Link Here
96
        root.getChildren().getNodes();
95
        root.getChildren().getNodes();
97
        try {
96
        try {
98
            Thread.sleep(1000);
97
            Thread.sleep(1000);
99
        } catch (InterruptedException iex) {}
98
        } catch (InterruptedException iex) {
100
        assertEquals("Children refreshed too much: "+cm1.getMaxCountedCall(), 1, cm1.getMaxCountedCall().numCalls());
99
        }
101
        assertEquals("Children refreshed too much: "+cm2.getMaxCountedCall(), 1, cm2.getMaxCountedCall().numCalls());
100
        assertEquals("Children refreshed too much: " + cm1.getMaxCountedCall(), 1, cm1.getMaxCountedCall().numCalls());
101
        assertEquals("Children refreshed too much: " + cm2.getMaxCountedCall(), 1, cm2.getMaxCountedCall().numCalls());
102
        cm1.fireModelChangeEvent(new ModelEvent.TreeChanged(TreeModel.ROOT));
102
        cm1.fireModelChangeEvent(new ModelEvent.TreeChanged(TreeModel.ROOT));
103
        try {
103
        try {
104
            Thread.sleep(500);
104
            Thread.sleep(500);
105
        } catch (InterruptedException iex) {}
105
        } catch (InterruptedException iex) {
106
        }
106
        root.getChildren().getNodes();
107
        root.getChildren().getNodes();
107
        try {
108
        try {
108
            Thread.sleep(500);
109
            Thread.sleep(500);
109
        } catch (InterruptedException iex) {}
110
        } catch (InterruptedException iex) {
110
        assertEquals("Children refreshed too much: "+cm1.getCountedCalls("getChildren", TreeModel.ROOT), 2, cm1.getCountedCalls("getChildren", TreeModel.ROOT).numCalls());
111
        }
111
        assertEquals("Children refreshed too much: "+cm2.getCountedCalls("getChildren", TreeModel.ROOT), 1, cm2.getCountedCalls("getChildren", TreeModel.ROOT).numCalls());
112
        assertEquals("Children refreshed too much: " + cm1.getCountedCalls("getChildren", TreeModel.ROOT), 2, cm1.getCountedCalls("getChildren", TreeModel.ROOT).numCalls());
113
        assertEquals("Children refreshed too much: " + cm2.getCountedCalls("getChildren", TreeModel.ROOT), 1, cm2.getCountedCalls("getChildren", TreeModel.ROOT).numCalls());
112
        //System.err.println("\n\n\nNEW REFRESH of "+cm2+" ... \n\n\n");
114
        //System.err.println("\n\n\nNEW REFRESH of "+cm2+" ... \n\n\n");
113
        cm2.fireModelChangeEvent(new ModelEvent.TreeChanged(TreeModel.ROOT));
115
        cm2.fireModelChangeEvent(new ModelEvent.TreeChanged(TreeModel.ROOT));
114
        try {
116
        try {
115
            Thread.sleep(500);
117
            Thread.sleep(500);
116
        } catch (InterruptedException iex) {}
118
        } catch (InterruptedException iex) {
119
        }
117
        root.getChildren().getNodes();
120
        root.getChildren().getNodes();
118
        try {
121
        try {
119
            Thread.sleep(500);
122
            Thread.sleep(500);
120
        } catch (InterruptedException iex) {}
123
        } catch (InterruptedException iex) {
121
        assertEquals("Children refreshed too much: "+cm1.getCountedCalls("getChildren", TreeModel.ROOT), 2, cm1.getCountedCalls("getChildren", TreeModel.ROOT).numCalls());
124
        }
122
        assertEquals("Children refreshed too much: "+cm2.getCountedCalls("getChildren", TreeModel.ROOT), 2, cm2.getCountedCalls("getChildren", TreeModel.ROOT).numCalls());
125
        assertEquals("Children refreshed too much: " + cm1.getCountedCalls("getChildren", TreeModel.ROOT), 2, cm1.getCountedCalls("getChildren", TreeModel.ROOT).numCalls());
126
        assertEquals("Children refreshed too much: " + cm2.getCountedCalls("getChildren", TreeModel.ROOT), 2, cm2.getCountedCalls("getChildren", TreeModel.ROOT).numCalls());
123
        cm1.fireModelChangeEvent(new ModelEvent.TreeChanged(TreeModel.ROOT));
127
        cm1.fireModelChangeEvent(new ModelEvent.TreeChanged(TreeModel.ROOT));
124
        cm2.fireModelChangeEvent(new ModelEvent.TreeChanged(TreeModel.ROOT));
128
        cm2.fireModelChangeEvent(new ModelEvent.TreeChanged(TreeModel.ROOT));
125
        try {
129
        try {
126
            Thread.sleep(500);
130
            Thread.sleep(500);
127
        } catch (InterruptedException iex) {}
131
        } catch (InterruptedException iex) {
132
        }
128
        root.getChildren().getNodes();
133
        root.getChildren().getNodes();
129
        try {
134
        try {
130
            Thread.sleep(500);
135
            Thread.sleep(500);
131
        } catch (InterruptedException iex) {}
136
        } catch (InterruptedException iex) {
132
        assertEquals("Children refreshed too much: "+cm1.getCountedCalls("getChildren", TreeModel.ROOT), 3, cm1.getCountedCalls("getChildren", TreeModel.ROOT).numCalls());
137
        }
133
        assertEquals("Children refreshed too much: "+cm2.getCountedCalls("getChildren", TreeModel.ROOT), 3, cm2.getCountedCalls("getChildren", TreeModel.ROOT).numCalls());
138
        assertEquals("Children refreshed too much: " + cm1.getCountedCalls("getChildren", TreeModel.ROOT), 3, cm1.getCountedCalls("getChildren", TreeModel.ROOT).numCalls());
139
        assertEquals("Children refreshed too much: " + cm2.getCountedCalls("getChildren", TreeModel.ROOT), 3, cm2.getCountedCalls("getChildren", TreeModel.ROOT).numCalls());
134
    }
140
    }
135
            
141
136
}
142
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/test/unit/src/org/netbeans/modules/viewmodel/ModelEventTest.java (-61 / +67 lines)
Lines 41-124 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.viewmodel;
44
package org.netbeans.modules.viewmodel;
46
45
47
import java.lang.reflect.InvocationTargetException;
46
import java.lang.reflect.InvocationTargetException;
48
import java.util.ArrayList;
47
import java.util.ArrayList;
49
import java.util.Vector;
48
import java.util.Vector;
50
import javax.swing.SwingUtilities;
49
import javax.swing.SwingUtilities;
51
52
import org.netbeans.junit.NbTestCase;
50
import org.netbeans.junit.NbTestCase;
53
51
import org.netbeans.spi.viewmodel.ModelEvent;
54
import org.netbeans.spi.viewmodel.*;
52
import org.netbeans.spi.viewmodel.Models;
55
53
import org.netbeans.spi.viewmodel.UnknownTypeException;
56
import org.openide.nodes.Node;
54
import org.openide.nodes.Node;
57
import org.openide.nodes.NodeListener;
55
import org.openide.nodes.NodeListener;
58
56
59
60
61
/**
57
/**
62
 *
58
 *
63
 */
59
 */
64
public class ModelEventTest  extends NbTestCase implements NodeListener {
60
public class ModelEventTest extends NbTestCase implements NodeListener {
65
61
66
    BasicTest.CompoundModel cm;
62
    BasicTest.CompoundModel cm;
67
    Node n;
63
    Node n;
68
    volatile Object event;
64
    volatile Object event;
69
    Vector propEvents = new Vector();
65
    Vector propEvents = new Vector();
70
66
71
    public ModelEventTest (String s) {
67
    public ModelEventTest(String s) {
72
        super (s);
68
        super(s);
73
    }
69
    }
74
    
70
75
    @Override
71
    @Override
76
    protected void setUp() throws Exception {
72
    protected void setUp() throws Exception {
77
        super.setUp();
73
        super.setUp();
78
        ArrayList l = new ArrayList ();
74
        ArrayList l = new ArrayList();
79
        cm = new CompoundModel1 ();
75
        cm = new CompoundModel1();
80
        l.add (cm);
76
        l.add(cm);
81
        OutlineTable tt = BasicTest.createView(Models.createCompoundModel (l));
77
        OutlineTable tt = BasicTest.createView(Models.createCompoundModel(l));
82
        BasicTest.waitFinished (tt.currentTreeModelRoot.getRootNode().getRequestProcessor());
78
        BasicTest.waitFinished(tt.currentTreeModelRoot.getRootNode().getRequestProcessor());
83
        n = tt.getExplorerManager ().getRootContext ();
79
        n = tt.getExplorerManager().getRootContext();
84
        n.addNodeListener(this);
80
        n.addNodeListener(this);
85
    }
81
    }
86
82
83
    @Override
87
    public void childrenAdded(org.openide.nodes.NodeMemberEvent ev) {
84
    public void childrenAdded(org.openide.nodes.NodeMemberEvent ev) {
88
        assertNull("Already fired", event);
85
        assertNull("Already fired", event);
89
        event = ev;
86
        event = ev;
90
    }
87
    }
91
88
89
    @Override
92
    public void childrenRemoved(org.openide.nodes.NodeMemberEvent ev) {
90
    public void childrenRemoved(org.openide.nodes.NodeMemberEvent ev) {
93
        assertNull("Already fired", event);
91
        assertNull("Already fired", event);
94
        event = ev;
92
        event = ev;
95
    }
93
    }
96
94
95
    @Override
97
    public void childrenReordered(org.openide.nodes.NodeReorderEvent ev) {
96
    public void childrenReordered(org.openide.nodes.NodeReorderEvent ev) {
98
        assertNull("Already fired", event);
97
        assertNull("Already fired", event);
99
        event = ev;
98
        event = ev;
100
    }
99
    }
101
100
101
    @Override
102
    public void nodeDestroyed(org.openide.nodes.NodeEvent ev) {
102
    public void nodeDestroyed(org.openide.nodes.NodeEvent ev) {
103
        assertNull("Already fired", event);
103
        assertNull("Already fired", event);
104
        event = ev;
104
        event = ev;
105
    }
105
    }
106
106
107
    @Override
107
    public void propertyChange(java.beans.PropertyChangeEvent propertyChangeEvent) {
108
    public void propertyChange(java.beans.PropertyChangeEvent propertyChangeEvent) {
108
        propEvents.add(propertyChangeEvent.getPropertyName());
109
        propEvents.add(propertyChangeEvent.getPropertyName());
109
        /*
110
        /*
110
        System.out.println("propertyChangeEvent = "+propertyChangeEvent);
111
         System.out.println("propertyChangeEvent = "+propertyChangeEvent);
111
        assertNull("Already fired", event);
112
         assertNull("Already fired", event);
112
        event = propertyChangeEvent;
113
         event = propertyChangeEvent;
113
         */
114
         */
114
    }
115
    }
115
    
116
116
    public void testDisplayName() {
117
    public void testDisplayName() {
117
        ModelEvent e = new ModelEvent.NodeChanged(this, "Root", ModelEvent.NodeChanged.DISPLAY_NAME_MASK);
118
        ModelEvent e = new ModelEvent.NodeChanged(this, "Root", ModelEvent.NodeChanged.DISPLAY_NAME_MASK);
118
        cm.fire(e);
119
        cm.fire(e);
119
        try {
120
        try {
120
            SwingUtilities.invokeAndWait (new Runnable () {
121
            SwingUtilities.invokeAndWait(new Runnable() {
121
                public void run () {}
122
                @Override
123
                public void run() {
124
                }
122
            });
125
            });
123
        } catch (InterruptedException iex) {
126
        } catch (InterruptedException iex) {
124
            fail(iex.toString());
127
            fail(iex.toString());
Lines 133-140 Link Here
133
        ModelEvent e = new ModelEvent.NodeChanged(this, "Root", ModelEvent.NodeChanged.ICON_MASK);
136
        ModelEvent e = new ModelEvent.NodeChanged(this, "Root", ModelEvent.NodeChanged.ICON_MASK);
134
        cm.fire(e);
137
        cm.fire(e);
135
        try {
138
        try {
136
            SwingUtilities.invokeAndWait (new Runnable () {
139
            SwingUtilities.invokeAndWait(new Runnable() {
137
                public void run () {}
140
                @Override
141
                public void run() {
142
                }
138
            });
143
            });
139
        } catch (InterruptedException iex) {
144
        } catch (InterruptedException iex) {
140
            fail(iex.toString());
145
            fail(iex.toString());
Lines 148-155 Link Here
148
        ModelEvent e = new ModelEvent.NodeChanged(this, "Root", ModelEvent.NodeChanged.SHORT_DESCRIPTION_MASK);
153
        ModelEvent e = new ModelEvent.NodeChanged(this, "Root", ModelEvent.NodeChanged.SHORT_DESCRIPTION_MASK);
149
        cm.fire(e);
154
        cm.fire(e);
150
        try {
155
        try {
151
            SwingUtilities.invokeAndWait (new Runnable () {
156
            SwingUtilities.invokeAndWait(new Runnable() {
152
                public void run () {}
157
                @Override
158
                public void run() {
159
                }
153
            });
160
            });
154
        } catch (InterruptedException iex) {
161
        } catch (InterruptedException iex) {
155
            fail(iex.toString());
162
            fail(iex.toString());
Lines 162-237 Link Here
162
    public void testChildren() {
169
    public void testChildren() {
163
        n.getChildren().getNodes();
170
        n.getChildren().getNodes();
164
        /*
171
        /*
165
        ModelEvent e = new ModelEvent.NodeChanged(this, "Root", ModelEvent.NodeChanged.CHILDREN_MASK);
172
         ModelEvent e = new ModelEvent.NodeChanged(this, "Root", ModelEvent.NodeChanged.CHILDREN_MASK);
166
        cm.fire(e);
173
         cm.fire(e);
167
        try {
174
         try {
168
            SwingUtilities.invokeAndWait (new Runnable () {
175
         SwingUtilities.invokeAndWait (new Runnable () {
169
                public void run () {}
176
         public void run () {}
170
            });
177
         });
171
        } catch (InterruptedException iex) {
178
         } catch (InterruptedException iex) {
172
            fail(iex.toString());
179
         fail(iex.toString());
173
        } catch (InvocationTargetException itex) {
180
         } catch (InvocationTargetException itex) {
174
            fail(itex.toString());
181
         fail(itex.toString());
175
        }
182
         }
176
        //assertTrue("Short Description was not fired", propEvents.contains(Node.PROP_));
183
         //assertTrue("Short Description was not fired", propEvents.contains(Node.PROP_));
177
        assertNotNull("Children were not fired", this.event);
184
         assertNotNull("Children were not fired", this.event);
178
         */
185
         */
179
    }
186
    }
180
187
181
    public final class CompoundModel1 extends BasicTest.CompoundModel {
188
    public final class CompoundModel1 extends BasicTest.CompoundModel {
182
        
189
183
        int dn = 0;
190
        int dn = 0;
184
        int ib = 0;
191
        int ib = 0;
185
        int sd = 0;
192
        int sd = 0;
186
        int cc = 0;
193
        int cc = 0;
187
        
194
188
        @Override
195
        @Override
189
        protected void addCall (String methodName, Object node) {
196
        protected void addCall(String methodName, Object node) {
190
            // Ignore multiple calls
197
            // Ignore multiple calls
191
        }
198
        }
192
199
193
        // init ....................................................................
200
        // init ....................................................................
194
195
        @Override
201
        @Override
196
        public String getDisplayName (Object node) throws UnknownTypeException {
202
        public String getDisplayName(Object node) throws UnknownTypeException {
197
            String dns = super.getDisplayName(node);
203
            String dns = super.getDisplayName(node);
198
            dns += (dn++);
204
            dns += (dn++);
199
            return dns;
205
            return dns;
200
        }
206
        }
201
        
207
202
        @Override
208
        @Override
203
        public String getIconBase (Object node) throws UnknownTypeException {
209
        public String getIconBase(Object node) throws UnknownTypeException {
204
            String ibs = super.getIconBase(node);
210
            String ibs = super.getIconBase(node);
205
            ibs += (ib++);
211
            ibs += (ib++);
206
            return ibs;
212
            return ibs;
207
        }
213
        }
208
        
214
209
        @Override
215
        @Override
210
        public String getShortDescription (Object node) throws UnknownTypeException {
216
        public String getShortDescription(Object node) throws UnknownTypeException {
211
            String sds = super.getShortDescription(node);
217
            String sds = super.getShortDescription(node);
212
            sds += (sd++);
218
            sds += (sd++);
213
            return sds;
219
            return sds;
214
        }
220
        }
215
        
221
216
        /**
222
        /**
217
         * Returns number of children for given node.
223
         * Returns number of children for given node.
218
         * 
219
         * @param   node the parent node
220
         * @throws  UnknownTypeException if this TreeModel implementation is not
221
         *          able to resolve children for given node type
222
         *
224
         *
223
         * @return  true if node is leaf
225
         * @param node the parent node
226
         * @throws UnknownTypeException if this TreeModel implementation is not
227
         * able to resolve children for given node type
228
         *
229
         * @return true if node is leaf
224
         */
230
         */
225
        @Override
231
        @Override
226
        public synchronized int getChildrenCount (Object node) throws UnknownTypeException {
232
        public synchronized int getChildrenCount(Object node) throws UnknownTypeException {
227
            return super.getChildrenCount (node) + (cc++);
233
            return super.getChildrenCount(node) + (cc++);
228
        }
234
        }
229
        
235
230
        @Override
236
        @Override
231
        public Object[] getChildren (Object parent, int from, int to) throws UnknownTypeException {
237
        public Object[] getChildren(Object parent, int from, int to) throws UnknownTypeException {
232
            //System.err.println("CompoundModel1.getChildren("+parent+", "+from+", "+to+")");
238
            //System.err.println("CompoundModel1.getChildren("+parent+", "+from+", "+to+")");
233
            //Thread.dumpStack();
239
            //Thread.dumpStack();
234
            addCall ("getChildren", parent);
240
            addCall("getChildren", parent);
235
            Object[] ch = new Object[3 + (cc - 1)];
241
            Object[] ch = new Object[3 + (cc - 1)];
236
            if (parent == ROOT) {
242
            if (parent == ROOT) {
237
                for (int i = 0; i < ch.length; i++) {
243
                for (int i = 0; i < ch.length; i++) {
Lines 247-253 Link Here
247
                }
253
                }
248
                return ch;
254
                return ch;
249
            }
255
            }
250
            throw new UnknownTypeException (parent);
256
            throw new UnknownTypeException(parent);
251
        }
257
        }
252
    }
258
    }
253
}
259
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/test/unit/src/org/netbeans/modules/viewmodel/MultiFiringTest.java (-22 / +57 lines)
Lines 39-45 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.viewmodel;
42
package org.netbeans.modules.viewmodel;
44
43
45
import java.util.ArrayList;
44
import java.util.ArrayList;
Lines 64-71 Link Here
64
    private BasicTest.CompoundModel m;
63
    private BasicTest.CompoundModel m;
65
    private volatile int changed = 0;
64
    private volatile int changed = 0;
66
65
67
    public MultiFiringTest (String s) {
66
    public MultiFiringTest(String s) {
68
        super (s);
67
        super(s);
69
    }
68
    }
70
69
71
    @Override
70
    @Override
Lines 75-135 Link Here
75
    }
74
    }
76
75
77
    private void setUpBasicModel() {
76
    private void setUpBasicModel() {
78
        ArrayList l = new ArrayList ();
77
        ArrayList l = new ArrayList();
79
        m = new BasicTest.CompoundModel ();
78
        m = new BasicTest.CompoundModel();
80
        l.add (m);
79
        l.add(m);
81
        Models.CompoundModel cm = Models.createCompoundModel (l);
80
        Models.CompoundModel cm = Models.createCompoundModel(l);
82
        //BasicTest.waitFinished (tt.currentTreeModelRoot.getRootNode().getRequestProcessor());
81
        //BasicTest.waitFinished (tt.currentTreeModelRoot.getRootNode().getRequestProcessor());
83
        //n = tt.getExplorerManager ().getRootContext ();
82
        //n = tt.getExplorerManager ().getRootContext ();
84
        cm.addModelListener(this);
83
        cm.addModelListener(this);
85
    }
84
    }
86
85
87
    private void setUpComplexModel() {
86
    private void setUpComplexModel() {
88
        ArrayList l = new ArrayList ();
87
        ArrayList l = new ArrayList();
89
        m = new BasicTest.CompoundModel ();
88
        m = new BasicTest.CompoundModel();
90
        l.add (m);
89
        l.add(m);
91
        l.add (new NodeModelFilter() {
90
        l.add(new NodeModelFilter() {
91
            @Override
92
            public String getDisplayName(NodeModel original, Object node) throws UnknownTypeException {
92
            public String getDisplayName(NodeModel original, Object node) throws UnknownTypeException {
93
                return original.getDisplayName(node);
93
                return original.getDisplayName(node);
94
            }
94
            }
95
96
            @Override
95
            public String getIconBase(NodeModel original, Object node) throws UnknownTypeException {
97
            public String getIconBase(NodeModel original, Object node) throws UnknownTypeException {
96
                return original.getIconBase(node);
98
                return original.getIconBase(node);
97
            }
99
            }
100
101
            @Override
98
            public String getShortDescription(NodeModel original, Object node) throws UnknownTypeException {
102
            public String getShortDescription(NodeModel original, Object node) throws UnknownTypeException {
99
                return original.getShortDescription(node);
103
                return original.getShortDescription(node);
100
            }
104
            }
101
            public void addModelListener(ModelListener l) {}
105
102
            public void removeModelListener(ModelListener l) {}
106
            @Override
107
            public void addModelListener(ModelListener l) {
108
            }
109
110
            @Override
111
            public void removeModelListener(ModelListener l) {
112
            }
103
        });
113
        });
104
        l.add (new TreeModelFilter() {
114
        l.add(new TreeModelFilter() {
115
            @Override
105
            public Object getRoot(TreeModel original) {
116
            public Object getRoot(TreeModel original) {
106
                return original.getRoot();
117
                return original.getRoot();
107
            }
118
            }
119
120
            @Override
108
            public Object[] getChildren(TreeModel original, Object parent, int from, int to) throws UnknownTypeException {
121
            public Object[] getChildren(TreeModel original, Object parent, int from, int to) throws UnknownTypeException {
109
                return original.getChildren(parent, from, to);
122
                return original.getChildren(parent, from, to);
110
            }
123
            }
124
125
            @Override
111
            public int getChildrenCount(TreeModel original, Object node) throws UnknownTypeException {
126
            public int getChildrenCount(TreeModel original, Object node) throws UnknownTypeException {
112
                return Integer.MAX_VALUE;
127
                return Integer.MAX_VALUE;
113
            }
128
            }
129
130
            @Override
114
            public boolean isLeaf(TreeModel original, Object node) throws UnknownTypeException {
131
            public boolean isLeaf(TreeModel original, Object node) throws UnknownTypeException {
115
                return original.isLeaf(node);
132
                return original.isLeaf(node);
116
            }
133
            }
117
            public void addModelListener(ModelListener l) {}
134
118
            public void removeModelListener(ModelListener l) {}
135
            @Override
136
            public void addModelListener(ModelListener l) {
137
            }
138
139
            @Override
140
            public void removeModelListener(ModelListener l) {
141
            }
119
        });
142
        });
120
        l.add (new TableModelFilter() {
143
        l.add(new TableModelFilter() {
144
            @Override
121
            public Object getValueAt(TableModel original, Object node, String columnID) throws UnknownTypeException {
145
            public Object getValueAt(TableModel original, Object node, String columnID) throws UnknownTypeException {
122
                return original.getValueAt(node, columnID);
146
                return original.getValueAt(node, columnID);
123
            }
147
            }
148
149
            @Override
124
            public boolean isReadOnly(TableModel original, Object node, String columnID) throws UnknownTypeException {
150
            public boolean isReadOnly(TableModel original, Object node, String columnID) throws UnknownTypeException {
125
                return original.isReadOnly(node, columnID);
151
                return original.isReadOnly(node, columnID);
126
            }
152
            }
153
154
            @Override
127
            public void setValueAt(TableModel original, Object node, String columnID, Object value) throws UnknownTypeException {
155
            public void setValueAt(TableModel original, Object node, String columnID, Object value) throws UnknownTypeException {
128
            }
156
            }
129
            public void addModelListener(ModelListener l) {}
157
130
            public void removeModelListener(ModelListener l) {}
158
            @Override
159
            public void addModelListener(ModelListener l) {
160
            }
161
162
            @Override
163
            public void removeModelListener(ModelListener l) {
164
            }
131
        });
165
        });
132
        Models.CompoundModel cm = Models.createCompoundModel (l);
166
        Models.CompoundModel cm = Models.createCompoundModel(l);
133
        cm.addModelListener(this);
167
        cm.addModelListener(this);
134
    }
168
    }
135
169
Lines 141-147 Link Here
141
175
142
    public void testBasicModelTableSingleFiring() {
176
    public void testBasicModelTableSingleFiring() {
143
        setUpBasicModel();
177
        setUpBasicModel();
144
        m.fire(new ModelEvent.TableValueChanged(m, "a", null));
178
        m.fire(new ModelEvent.TableValueChanged(m, "a"));
145
        assertEquals("Firing occurred", 1, changed);
179
        assertEquals("Firing occurred", 1, changed);
146
    }
180
    }
147
181
Lines 159-165 Link Here
159
193
160
    public void testComplexModelTableSingleFiring() {
194
    public void testComplexModelTableSingleFiring() {
161
        setUpComplexModel();
195
        setUpComplexModel();
162
        m.fire(new ModelEvent.TableValueChanged(m, "a", null));
196
        m.fire(new ModelEvent.TableValueChanged(m, "a"));
163
        assertEquals("Firing occurred", 1, changed);
197
        assertEquals("Firing occurred", 1, changed);
164
    }
198
    }
165
199
Lines 169-174 Link Here
169
        assertEquals("Firing occurred", 1, changed);
203
        assertEquals("Firing occurred", 1, changed);
170
    }
204
    }
171
205
206
    @Override
172
    public void modelChanged(ModelEvent event) {
207
    public void modelChanged(ModelEvent event) {
173
        changed++;
208
        changed++;
174
    }
209
    }
(-)/home/enrico/Lavoro/releases/spi.viewmodel/test/unit/src/org/netbeans/modules/viewmodel/ReorderableTreeModelTest.java (-28 / +36 lines)
Lines 39-57 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.viewmodel;
42
package org.netbeans.modules.viewmodel;
44
43
45
import java.util.ArrayList;
44
import java.util.ArrayList;
46
import java.util.Arrays;
45
import java.util.Arrays;
47
import org.netbeans.junit.NbTestCase;
46
import org.netbeans.junit.NbTestCase;
48
import org.netbeans.spi.viewmodel.Model;
47
import org.netbeans.spi.viewmodel.Model;
49
import org.netbeans.spi.viewmodel.ModelEvent;
50
import org.netbeans.spi.viewmodel.ModelListener;
48
import org.netbeans.spi.viewmodel.ModelListener;
51
import org.netbeans.spi.viewmodel.Models;
49
import org.netbeans.spi.viewmodel.Models;
52
import org.netbeans.spi.viewmodel.NodeModel;
50
import org.netbeans.spi.viewmodel.NodeModel;
53
import org.netbeans.spi.viewmodel.ReorderableTreeModel;
51
import org.netbeans.spi.viewmodel.ReorderableTreeModel;
54
import org.netbeans.spi.viewmodel.TreeModel;
55
import org.netbeans.spi.viewmodel.UnknownTypeException;
52
import org.netbeans.spi.viewmodel.UnknownTypeException;
56
import org.openide.nodes.Index;
53
import org.openide.nodes.Index;
57
import org.openide.nodes.Node;
54
import org.openide.nodes.Node;
Lines 59-87 Link Here
59
56
60
/**
57
/**
61
 * Tests that reorderable model produces node with Index implementation
58
 * Tests that reorderable model produces node with Index implementation
62
 * 
59
 *
63
 * @author Martin Entlicher
60
 * @author Martin Entlicher
64
 */
61
 */
65
public class ReorderableTreeModelTest extends NbTestCase {
62
public class ReorderableTreeModelTest extends NbTestCase {
66
63
67
    private Node root;
64
    private Node root;
68
65
69
    public ReorderableTreeModelTest (String s) {
66
    public ReorderableTreeModelTest(String s) {
70
        super (s);
67
        super(s);
71
    }
68
    }
72
69
73
    private void setUpModel() {
70
    private void setUpModel() {
74
        Model m = new ReorderableModelImpl();
71
        Model m = new ReorderableModelImpl();
75
72
76
        ArrayList l = new ArrayList ();
73
        ArrayList l = new ArrayList();
77
        l.add(m);
74
        l.add(m);
78
        Models.CompoundModel mcm = Models.createCompoundModel(l);
75
        Models.CompoundModel mcm = Models.createCompoundModel(l);
79
        OutlineTable tt = BasicTest.createView(mcm);
76
        OutlineTable tt = BasicTest.createView(mcm);
80
        
77
81
        RequestProcessor rp = tt.currentTreeModelRoot.getRootNode().getRequestProcessor();
78
        RequestProcessor rp = tt.currentTreeModelRoot.getRootNode().getRequestProcessor();
82
        BasicTest.waitFinished (rp);
79
        BasicTest.waitFinished(rp);
83
80
84
        root = tt.getExplorerManager ().getRootContext ();
81
        root = tt.getExplorerManager().getRootContext();
85
    }
82
    }
86
83
87
    public void testChildrenReorder() {
84
    public void testChildrenReorder() {
Lines 94-109 Link Here
94
        assertEquals(2, ch1.length);
91
        assertEquals(2, ch1.length);
95
92
96
        indexImpl = ch1[1].getLookup().lookup(Index.class);
93
        indexImpl = ch1[1].getLookup().lookup(Index.class);
97
        assertNull(ch1[1]+ " must not provide Index, it is not reordeable!", indexImpl);
94
        assertNull(ch1[1] + " must not provide Index, it is not reordeable!", indexImpl);
98
        indexImpl = ch1[0].getLookup().lookup(Index.class);
95
        indexImpl = ch1[0].getLookup().lookup(Index.class);
99
        assertNotNull(ch1[0]+ " must provide Index, it is reordeable!", indexImpl);
96
        assertNotNull(ch1[0] + " must provide Index, it is reordeable!", indexImpl);
100
97
101
        indexImpl.reorder(new int[] { 2, 0, 1, 4, 3 });
98
        indexImpl.reorder(new int[]{2, 0, 1, 4, 3});
102
        //                      =>  "3", "1", "2", "5", "4"
99
        //                      =>  "3", "1", "2", "5", "4"
103
        String[] reorderedNames = new String[] { "2", "3", "1", "5", "4" };
100
        String[] reorderedNames = new String[]{"2", "3", "1", "5", "4"};
104
        Node[] reorderedNodes = ch1[0].getChildren().getNodes();
101
        Node[] reorderedNodes = ch1[0].getChildren().getNodes();
105
        assertEquals(reorderedNames.length, reorderedNodes.length);
102
        assertEquals(reorderedNames.length, reorderedNodes.length);
106
        String nodes = "Nodes = "+Arrays.toString(reorderedNodes);
103
        String nodes = "Nodes = " + Arrays.toString(reorderedNodes);
107
        for (int i = 0; i < reorderedNodes.length; i++) {
104
        for (int i = 0; i < reorderedNodes.length; i++) {
108
            assertEquals(nodes, reorderedNames[i], reorderedNodes[i].getDisplayName());
105
            assertEquals(nodes, reorderedNames[i], reorderedNodes[i].getDisplayName());
109
        }
106
        }
Lines 114-133 Link Here
114
        private static final String CAN_REORDER = "canReorder";
111
        private static final String CAN_REORDER = "canReorder";
115
        private static final String CAN_NOT_REORDER = "canNotReorder";
112
        private static final String CAN_NOT_REORDER = "canNotReorder";
116
113
117
        private final String[] childrenReordered = new String[] { "1", "2", "3", "4", "5" };
114
        private final String[] childrenReordered = new String[]{"1", "2", "3", "4", "5"};
118
115
116
        @Override
119
        public boolean canReorder(Object parent) throws UnknownTypeException {
117
        public boolean canReorder(Object parent) throws UnknownTypeException {
120
            return /*ROOT == parent ||*/ CAN_REORDER.equals(parent);
118
            return /*ROOT == parent ||*/ CAN_REORDER.equals(parent);
121
        }
119
        }
122
120
121
        @Override
123
        public void reorder(Object parent, int[] perm) throws UnknownTypeException {
122
        public void reorder(Object parent, int[] perm) throws UnknownTypeException {
124
            //System.err.println("reorder("+parent+", "+Arrays.toString(perm)+")");
123
            //System.err.println("reorder("+parent+", "+Arrays.toString(perm)+")");
125
            //Thread.dumpStack();
124
            //Thread.dumpStack();
126
            if (!(/*ROOT == parent ||*/ CAN_REORDER.equals(parent))) {
125
            if (!(/*ROOT == parent ||*/CAN_REORDER.equals(parent))) {
127
                throw new IllegalStateException("reorder called on "+parent);
126
                throw new IllegalStateException("reorder called on " + parent);
128
            }
127
            }
129
            if (perm.length != childrenReordered.length) {
128
            if (perm.length != childrenReordered.length) {
130
                throw new IllegalArgumentException("Permutation of length "+perm.length+", but have "+childrenReordered.length+" children.");
129
                throw new IllegalArgumentException("Permutation of length " + perm.length + ", but have " + childrenReordered.length + " children.");
131
            }
130
            }
132
            checkPermutation(perm);
131
            checkPermutation(perm);
133
            String[] ch = childrenReordered.clone();
132
            String[] ch = childrenReordered.clone();
Lines 143-202 Link Here
143
            for (int i = 0; i < max; i++) {
142
            for (int i = 0; i < max; i++) {
144
                int p = permutation[i];
143
                int p = permutation[i];
145
                if (p >= max) {
144
                if (p >= max) {
146
                    throw new IllegalArgumentException("Permutation "+Arrays.toString(permutation)+" is not a valid permutation, it contains element "+p+", which is bigger than the length of the permutation.");
145
                    throw new IllegalArgumentException("Permutation " + Arrays.toString(permutation) + " is not a valid permutation, it contains element " + p + ", which is bigger than the length of the permutation.");
147
                }
146
                }
148
                if (p < 0) {
147
                if (p < 0) {
149
                    throw new IllegalArgumentException("Permutation "+Arrays.toString(permutation)+" is not a valid permutation, it contains element "+p+", which is negative.");
148
                    throw new IllegalArgumentException("Permutation " + Arrays.toString(permutation) + " is not a valid permutation, it contains element " + p + ", which is negative.");
150
                }
149
                }
151
                if (check[p] != 0) {
150
                if (check[p] != 0) {
152
                    throw new IllegalArgumentException("Permutation "+Arrays.toString(permutation)+" is not a valid permutation, it contains element "+p+" twice or more times.");
151
                    throw new IllegalArgumentException("Permutation " + Arrays.toString(permutation) + " is not a valid permutation, it contains element " + p + " twice or more times.");
153
                }
152
                }
154
                check[p] = 1;
153
                check[p] = 1;
155
            }
154
            }
156
        }
155
        }
157
156
157
        @Override
158
        public Object getRoot() {
158
        public Object getRoot() {
159
            return ROOT;
159
            return ROOT;
160
        }
160
        }
161
161
162
        @Override
162
        public Object[] getChildren(Object parent, int from, int to) throws UnknownTypeException {
163
        public Object[] getChildren(Object parent, int from, int to) throws UnknownTypeException {
163
            if (ROOT == parent) {
164
            if (ROOT == parent) {
164
                return new String[] { CAN_REORDER, CAN_NOT_REORDER };
165
                return new String[]{CAN_REORDER, CAN_NOT_REORDER};
165
            } else if (CAN_REORDER.equals(parent)) {
166
            } else if (CAN_REORDER.equals(parent)) {
166
                return childrenReordered;
167
                return childrenReordered;
167
            } else if (CAN_NOT_REORDER.equals(parent)) {
168
            } else if (CAN_NOT_REORDER.equals(parent)) {
168
                return new String[] { "a", "b", "c", "d", "e" };
169
                return new String[]{"a", "b", "c", "d", "e"};
169
            } else {
170
            } else {
170
                return new Object[] {};
171
                return new Object[]{};
171
            }
172
            }
172
        }
173
        }
173
174
175
        @Override
174
        public boolean isLeaf(Object node) throws UnknownTypeException {
176
        public boolean isLeaf(Object node) throws UnknownTypeException {
175
            return ((String) node).length() == 1;
177
            return ((String) node).length() == 1;
176
        }
178
        }
177
179
180
        @Override
178
        public int getChildrenCount(Object node) throws UnknownTypeException {
181
        public int getChildrenCount(Object node) throws UnknownTypeException {
179
            return Integer.MAX_VALUE;
182
            return Integer.MAX_VALUE;
180
        }
183
        }
181
184
185
        @Override
182
        public void addModelListener(ModelListener l) {
186
        public void addModelListener(ModelListener l) {
183
        }
187
        }
184
188
189
        @Override
185
        public void removeModelListener(ModelListener l) {
190
        public void removeModelListener(ModelListener l) {
186
        }
191
        }
187
192
193
        @Override
188
        public String getDisplayName(Object node) throws UnknownTypeException {
194
        public String getDisplayName(Object node) throws UnknownTypeException {
189
            return (String) node;
195
            return (String) node;
190
        }
196
        }
191
197
198
        @Override
192
        public String getIconBase(Object node) throws UnknownTypeException {
199
        public String getIconBase(Object node) throws UnknownTypeException {
193
            return null;
200
            return null;
194
        }
201
        }
195
202
203
        @Override
196
        public String getShortDescription(Object node) throws UnknownTypeException {
204
        public String getShortDescription(Object node) throws UnknownTypeException {
197
            return node+" of "+getClass().getSimpleName();
205
            return node + " of " + getClass().getSimpleName();
198
        }
206
        }
199
        
207
200
    }
208
    }
201
            
209
202
}
210
}
(-)/home/enrico/Lavoro/releases/spi.viewmodel/test/unit/src/org/netbeans/modules/viewmodel/TableRendererTest.java (-77 / +72 lines)
Lines 39-45 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.viewmodel;
42
package org.netbeans.modules.viewmodel;
44
43
45
import java.awt.BorderLayout;
44
import java.awt.BorderLayout;
Lines 52-58 Link Here
52
import java.util.ArrayList;
51
import java.util.ArrayList;
53
import java.util.EventObject;
52
import java.util.EventObject;
54
import java.util.List;
53
import java.util.List;
55
import javax.swing.BoxLayout;
56
import javax.swing.JLabel;
54
import javax.swing.JLabel;
57
import javax.swing.JTable;
55
import javax.swing.JTable;
58
import javax.swing.JTextField;
56
import javax.swing.JTextField;
Lines 87-97 Link Here
87
        super(name);
85
        super(name);
88
    }
86
    }
89
87
90
91
    private void setUpModel() {
88
    private void setUpModel() {
92
        Model mr = new TableRendererModelImpl();
89
        Model mr = new TableRendererModelImpl();
93
90
94
        ArrayList l = new ArrayList ();
91
        ArrayList l = new ArrayList();
95
        l.add(mr);
92
        l.add(mr);
96
        l.add(new ColumnModelImpl("col1"));
93
        l.add(new ColumnModelImpl("col1"));
97
        l.add(new ColumnModelImpl("col2"));
94
        l.add(new ColumnModelImpl("col2"));
Lines 99-105 Link Here
99
        OutlineTable tt = BasicTest.createView(mcm);
96
        OutlineTable tt = BasicTest.createView(mcm);
100
97
101
        RequestProcessor rp = tt.currentTreeModelRoot.getRootNode().getRequestProcessor();
98
        RequestProcessor rp = tt.currentTreeModelRoot.getRootNode().getRequestProcessor();
102
        BasicTest.waitFinished (rp);
99
        BasicTest.waitFinished(rp);
103
100
104
        this.ot = tt;
101
        this.ot = tt;
105
        //root = tt.getExplorerManager ().getRootContext ();
102
        //root = tt.getExplorerManager ().getRootContext ();
Lines 116-133 Link Here
116
        f.setSize(600, 500);
113
        f.setSize(600, 500);
117
        f.setVisible(true);
114
        f.setVisible(true);
118
        //while (f.isVisible()) {
115
        //while (f.isVisible()) {
119
            try {
116
        try {
120
                Thread.sleep(333);
117
            Thread.sleep(333);
121
            } catch (InterruptedException ex) {
118
        } catch (InterruptedException ex) {
122
                Exceptions.printStackTrace(ex);
119
            Exceptions.printStackTrace(ex);
123
            }
120
        }
124
        //}
121
        //}
125
        
122
126
        System.out.println("table rows = "+t.getRowCount());
123
        System.out.println("table rows = " + t.getRowCount());
127
        TableCellRenderer tcr = t.getCellRenderer(0, 0);
124
        TableCellRenderer tcr = t.getCellRenderer(0, 0);
128
        Component c = tcr.getTableCellRendererComponent(t, null, true, true, 0, 0);
125
        Component c = tcr.getTableCellRendererComponent(t, null, true, true, 0, 0);
129
        //System.err.println("c = "+c);
126
        //System.err.println("c = "+c);
130
        assertTrue("Renderer component = "+c, c instanceof RendererComponent);
127
        assertTrue("Renderer component = " + c, c instanceof RendererComponent);
131
        assertEquals("Renderer of 0:DN", ((RendererComponent) c).getText());
128
        assertEquals("Renderer of 0:DN", ((RendererComponent) c).getText());
132
129
133
        tcr = t.getCellRenderer(0, 1);
130
        tcr = t.getCellRenderer(0, 1);
Lines 140-150 Link Here
140
137
141
        tcr = t.getCellRenderer(1, 0);
138
        tcr = t.getCellRenderer(1, 0);
142
        c = tcr.getTableCellRendererComponent(t, null, true, true, 1, 0);
139
        c = tcr.getTableCellRendererComponent(t, null, true, true, 1, 0);
143
        assertFalse("Renderer component = "+c, c instanceof RendererComponent);
140
        assertFalse("Renderer component = " + c, c instanceof RendererComponent);
144
141
145
        tcr = t.getCellRenderer(1, 1);
142
        tcr = t.getCellRenderer(1, 1);
146
        c = tcr.getTableCellRendererComponent(t, null, true, true, 1, 1);
143
        c = tcr.getTableCellRendererComponent(t, null, true, true, 1, 1);
147
        assertFalse("Renderer component = "+c, c instanceof RendererComponent);
144
        assertFalse("Renderer component = " + c, c instanceof RendererComponent);
148
145
149
        tcr = t.getCellRenderer(2, 1);
146
        tcr = t.getCellRenderer(2, 1);
150
        c = tcr.getTableCellRendererComponent(t, null, true, true, 2, 1);
147
        c = tcr.getTableCellRendererComponent(t, null, true, true, 2, 1);
Lines 170-236 Link Here
170
        f.setSize(600, 500);
167
        f.setSize(600, 500);
171
        f.setVisible(true);
168
        f.setVisible(true);
172
        //while (f.isVisible()) {
169
        //while (f.isVisible()) {
173
            try {
170
        try {
174
                Thread.sleep(333);
171
            Thread.sleep(333);
175
            } catch (InterruptedException ex) {
172
        } catch (InterruptedException ex) {
176
                Exceptions.printStackTrace(ex);
173
            Exceptions.printStackTrace(ex);
177
            }
174
        }
178
        //}
175
        //}
179
176
180
        System.out.println("table rows = "+t.getRowCount());
177
        System.out.println("table rows = " + t.getRowCount());
181
        TableCellEditor tce = t.getCellEditor(0, 0);
178
        TableCellEditor tce = t.getCellEditor(0, 0);
182
        assertTrue(tce+"is not editable.", tce.isCellEditable(getMouseClickAt(t, 0, 0)));
179
        assertTrue(tce + "is not editable.", tce.isCellEditable(getMouseClickAt(t, 0, 0)));
183
        //assertTrue(t+"is not editable.", t.isCellEditable(0, 0));
180
        //assertTrue(t+"is not editable.", t.isCellEditable(0, 0));
184
        Component c = tce.getTableCellEditorComponent(t, null, true, 0, 0);
181
        Component c = tce.getTableCellEditorComponent(t, null, true, 0, 0);
185
        //System.err.println("c = "+c);
182
        //System.err.println("c = "+c);
186
        assertTrue("Editor component = "+c, c instanceof EditorComponent);
183
        assertTrue("Editor component = " + c, c instanceof EditorComponent);
187
        assertEquals("Editor of 0:DN", ((EditorComponent) c).getText());
184
        assertEquals("Editor of 0:DN", ((EditorComponent) c).getText());
188
185
189
        tce = t.getCellEditor(0, 1);
186
        tce = t.getCellEditor(0, 1);
190
        assertTrue(tce+"is not editable.", tce.isCellEditable(getMouseClickAt(t, 0, 1)));
187
        assertTrue(tce + "is not editable.", tce.isCellEditable(getMouseClickAt(t, 0, 1)));
191
        assertTrue(t+"is not editable.", t.isCellEditable(0, 1));
188
        assertTrue(t + "is not editable.", t.isCellEditable(0, 1));
192
        c = tce.getTableCellEditorComponent(t, null, true, 0, 1);
189
        c = tce.getTableCellEditorComponent(t, null, true, 0, 1);
193
        assertTrue("Editor component = "+c, c instanceof EditorComponent);
190
        assertTrue("Editor component = " + c, c instanceof EditorComponent);
194
        assertEquals("Editor of 0:col1", ((EditorComponent) c).getText());
191
        assertEquals("Editor of 0:col1", ((EditorComponent) c).getText());
195
192
196
        tce = t.getCellEditor(0, 2);
193
        tce = t.getCellEditor(0, 2);
197
        assertTrue(tce+"is not editable.", tce.isCellEditable(getMouseClickAt(t, 0, 2)));
194
        assertTrue(tce + "is not editable.", tce.isCellEditable(getMouseClickAt(t, 0, 2)));
198
        assertTrue(t+"is not editable.", t.isCellEditable(0, 2));
195
        assertTrue(t + "is not editable.", t.isCellEditable(0, 2));
199
        c = tce.getTableCellEditorComponent(t, null, true, 0, 2);
196
        c = tce.getTableCellEditorComponent(t, null, true, 0, 2);
200
        assertTrue("Editor component = "+c, c instanceof EditorComponent);
197
        assertTrue("Editor component = " + c, c instanceof EditorComponent);
201
        assertEquals("Editor of 0:col2", ((EditorComponent) c).getText());
198
        assertEquals("Editor of 0:col2", ((EditorComponent) c).getText());
202
199
203
        tce = t.getCellEditor(1, 0);
200
        tce = t.getCellEditor(1, 0);
204
        assertFalse(tce+"is editable.", tce.isCellEditable(getMouseClickAt(t, 1, 0)));
201
        assertFalse(tce + "is editable.", tce.isCellEditable(getMouseClickAt(t, 1, 0)));
205
        assertFalse(t+"is editable.", t.isCellEditable(1, 0));
202
        assertFalse(t + "is editable.", t.isCellEditable(1, 0));
206
        c = tce.getTableCellEditorComponent(t, null, true, 1, 0);
203
        c = tce.getTableCellEditorComponent(t, null, true, 1, 0);
207
        assertFalse("Editor component = "+c, c instanceof EditorComponent);
204
        assertFalse("Editor component = " + c, c instanceof EditorComponent);
208
205
209
        tce = t.getCellEditor(1, 2);
206
        tce = t.getCellEditor(1, 2);
210
        assertFalse(tce+"is editable.", tce.isCellEditable(getMouseClickAt(t, 1, 2)));
207
        assertFalse(tce + "is editable.", tce.isCellEditable(getMouseClickAt(t, 1, 2)));
211
        assertFalse(t+"is editable.", t.isCellEditable(1, 2));
208
        assertFalse(t + "is editable.", t.isCellEditable(1, 2));
212
        c = tce.getTableCellEditorComponent(t, null, true, 1, 2);
209
        c = tce.getTableCellEditorComponent(t, null, true, 1, 2);
213
        assertFalse("Editor component = "+c, c instanceof EditorComponent);
210
        assertFalse("Editor component = " + c, c instanceof EditorComponent);
214
211
215
        tce = t.getCellEditor(3, 1);
212
        tce = t.getCellEditor(3, 1);
216
        assertTrue(tce+"is not editable.", tce.isCellEditable(getMouseClickAt(t, 3, 1)));
213
        assertTrue(tce + "is not editable.", tce.isCellEditable(getMouseClickAt(t, 3, 1)));
217
        assertTrue(t+"is not editable.", t.isCellEditable(3, 1));
214
        assertTrue(t + "is not editable.", t.isCellEditable(3, 1));
218
        c = tce.getTableCellEditorComponent(t, null, true, 3, 1);
215
        c = tce.getTableCellEditorComponent(t, null, true, 3, 1);
219
        assertTrue("Editor component = "+c, c instanceof EditorComponent);
216
        assertTrue("Editor component = " + c, c instanceof EditorComponent);
220
        assertEquals("Editor of 3:col1", ((EditorComponent) c).getText());
217
        assertEquals("Editor of 3:col1", ((EditorComponent) c).getText());
221
218
222
        tce = t.getCellEditor(6, 0);
219
        tce = t.getCellEditor(6, 0);
223
        assertTrue(tce+"is not editable.", tce.isCellEditable(getMouseClickAt(t, 6, 0)));
220
        assertTrue(tce + "is not editable.", tce.isCellEditable(getMouseClickAt(t, 6, 0)));
224
        assertTrue(t+"is not editable.", t.isCellEditable(6, 0));
221
        assertTrue(t + "is not editable.", t.isCellEditable(6, 0));
225
        c = tce.getTableCellEditorComponent(t, null, true, 6, 0);
222
        c = tce.getTableCellEditorComponent(t, null, true, 6, 0);
226
        assertTrue("Editor component = "+c, c instanceof EditorComponent);
223
        assertTrue("Editor component = " + c, c instanceof EditorComponent);
227
        assertEquals("Editor of 6:DN", ((EditorComponent) c).getText());
224
        assertEquals("Editor of 6:DN", ((EditorComponent) c).getText());
228
225
229
        tce = t.getCellEditor(9, 2);
226
        tce = t.getCellEditor(9, 2);
230
        assertTrue(tce+"is not editable.", tce.isCellEditable(getMouseClickAt(t, 9, 2)));
227
        assertTrue(tce + "is not editable.", tce.isCellEditable(getMouseClickAt(t, 9, 2)));
231
        assertTrue(t+"is not editable.", t.isCellEditable(9, 2));
228
        assertTrue(t + "is not editable.", t.isCellEditable(9, 2));
232
        c = tce.getTableCellEditorComponent(t, null, true, 9, 2);
229
        c = tce.getTableCellEditorComponent(t, null, true, 9, 2);
233
        assertTrue("Editor component = "+c, c instanceof EditorComponent);
230
        assertTrue("Editor component = " + c, c instanceof EditorComponent);
234
        assertEquals("Editor of 9:col2", ((EditorComponent) c).getText());
231
        assertEquals("Editor of 9:col2", ((EditorComponent) c).getText());
235
    }
232
    }
236
233
Lines 245-275 Link Here
245
        f.setSize(600, 500);
242
        f.setSize(600, 500);
246
        f.setVisible(true);
243
        f.setVisible(true);
247
        //while (f.isVisible()) {
244
        //while (f.isVisible()) {
248
            try {
245
        try {
249
                Thread.sleep(333);
246
            Thread.sleep(333);
250
            } catch (InterruptedException ex) {
247
        } catch (InterruptedException ex) {
251
                Exceptions.printStackTrace(ex);
248
            Exceptions.printStackTrace(ex);
252
            }
249
        }
253
        //}
250
        //}
254
251
255
        MouseEvent event = getMouseClickAt(t, 0, 0);
252
        MouseEvent event = getMouseClickAt(t, 0, 0);
256
        String tipText = t.getToolTipText(event);
253
        String tipText = t.getToolTipText(event);
257
        JToolTip tip = t.createToolTip();
254
        JToolTip tip = t.createToolTip();
258
        tip.setTipText(tipText);
255
        tip.setTipText(tipText);
259
        assertTrue("Bad ToolTip class: "+tip, tip instanceof RendererComponent.ToolTipComponent);
256
        assertTrue("Bad ToolTip class: " + tip, tip instanceof RendererComponent.ToolTipComponent);
260
        assertEquals("ToolTip for Renderer of 0:DN", tip.getTipText());
257
        assertEquals("ToolTip for Renderer of 0:DN", tip.getTipText());
261
258
262
        event = getMouseClickAt(t, 1, 1);
259
        event = getMouseClickAt(t, 1, 1);
263
        tipText = t.getToolTipText(event);
260
        tipText = t.getToolTipText(event);
264
        tip = t.createToolTip();
261
        tip = t.createToolTip();
265
        tip.setTipText(tipText);
262
        tip.setTipText(tipText);
266
        assertFalse("Bad ToolTip class: "+tip, tip instanceof RendererComponent.ToolTipComponent);
263
        assertFalse("Bad ToolTip class: " + tip, tip instanceof RendererComponent.ToolTipComponent);
267
264
268
        event = getMouseClickAt(t, 2, 2);
265
        event = getMouseClickAt(t, 2, 2);
269
        tipText = t.getToolTipText(event);
266
        tipText = t.getToolTipText(event);
270
        tip = t.createToolTip();
267
        tip = t.createToolTip();
271
        tip.setTipText(tipText);
268
        tip.setTipText(tipText);
272
        assertTrue("Bad ToolTip class: "+tip, tip instanceof RendererComponent.ToolTipComponent);
269
        assertTrue("Bad ToolTip class: " + tip, tip instanceof RendererComponent.ToolTipComponent);
273
        assertEquals("ToolTip for Renderer of 2:col2", tip.getTipText());
270
        assertEquals("ToolTip for Renderer of 2:col2", tip.getTipText());
274
    }
271
    }
275
272
Lines 281-287 Link Here
281
278
282
    private static class RendererComponent extends JLabel {
279
    private static class RendererComponent extends JLabel {
283
280
284
        private String s;
281
        private final String s;
285
282
286
        public RendererComponent(String s) {
283
        public RendererComponent(String s) {
287
            super(s);
284
            super(s);
Lines 290-296 Link Here
290
287
291
        @Override
288
        @Override
292
        public String getToolTipText() {
289
        public String getToolTipText() {
293
            return "ToolTip for "+s;
290
            return "ToolTip for " + s;
294
        }
291
        }
295
292
296
        @Override
293
        @Override
Lines 299-313 Link Here
299
        }
296
        }
300
297
301
        private static class ToolTipComponent extends JToolTip {
298
        private static class ToolTipComponent extends JToolTip {
302
            
299
303
        }
300
        }
304
301
305
    }
302
    }
306
303
307
    private static final class CellRendererImpl implements TableCellRenderer {
304
    private static final class CellRendererImpl implements TableCellRenderer {
308
305
309
        private Object node;
306
        private final Object node;
310
        private String columnID;
307
        private final String columnID;
311
308
312
        public CellRendererImpl(Object node, String columnID) {
309
        public CellRendererImpl(Object node, String columnID) {
313
            this.node = node;
310
            this.node = node;
Lines 321-335 Link Here
321
        public String getColumnID() {
318
        public String getColumnID() {
322
            return columnID;
319
            return columnID;
323
        }
320
        }
324
        
321
325
        @Override
322
        @Override
326
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
323
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
327
            return new RendererComponent("Renderer of "+node.toString()+":"+columnID);
324
            return new RendererComponent("Renderer of " + node.toString() + ":" + columnID);
328
        }
325
        }
329
        
326
330
    }
327
    }
331
328
332
    private static class EditorComponent extends JTextField {
329
    private static class EditorComponent extends JTextField {
330
333
        public EditorComponent(String s) {
331
        public EditorComponent(String s) {
334
            super(s);
332
            super(s);
335
        }
333
        }
Lines 337-344 Link Here
337
335
338
    private static final class CellEditorImpl implements TableCellEditor {
336
    private static final class CellEditorImpl implements TableCellEditor {
339
337
340
        private Object node;
338
        private final Object node;
341
        private String columnID;
339
        private final String columnID;
342
340
343
        public CellEditorImpl(Object node, String columnID) {
341
        public CellEditorImpl(Object node, String columnID) {
344
            this.node = node;
342
            this.node = node;
Lines 355-361 Link Here
355
353
356
        @Override
354
        @Override
357
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
355
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
358
            return new EditorComponent("Editor of "+node.toString()+":"+columnID);
356
            return new EditorComponent("Editor of " + node.toString() + ":" + columnID);
359
        }
357
        }
360
358
361
        @Override
359
        @Override
Lines 374-381 Link Here
374
                    int col = table.columnAtPoint(p);
372
                    int col = table.columnAtPoint(p);
375
                    Rectangle rect = table.getCellRect(row, col, true);
373
                    Rectangle rect = table.getCellRect(row, col, true);
376
                    p.translate(-rect.x, -rect.y);
374
                    p.translate(-rect.x, -rect.y);
377
                    System.out.println("isCellEditable("+anEvent+")");
375
                    System.out.println("isCellEditable(" + anEvent + ")");
378
                    System.out.println("Point "+p+"in rectangle "+rect);
376
                    System.out.println("Point " + p + "in rectangle " + rect);
379
                    if (p.x > rect.width - 24) {
377
                    if (p.x > rect.width - 24) {
380
                        // last 24 points not editable
378
                        // last 24 points not editable
381
                        return false;
379
                        return false;
Lines 411-420 Link Here
411
409
412
    private static final class TableRendererModelImpl implements TableRendererModel, TreeModel, TableModel, ExtendedNodeModel {
410
    private static final class TableRendererModelImpl implements TableRendererModel, TreeModel, TableModel, ExtendedNodeModel {
413
411
414
        private List<ModelListener> listeners = new ArrayList<ModelListener>();
412
        private final List<ModelListener> listeners = new ArrayList<>();
415
413
416
        // TableRendererModel
414
        // TableRendererModel
417
        
418
        @Override
415
        @Override
419
        public boolean canRenderCell(Object node, String columnID) throws UnknownTypeException {
416
        public boolean canRenderCell(Object node, String columnID) throws UnknownTypeException {
420
            return Integer.parseInt((String) node) % 2 == 0; // Use this renderer for even rows only.
417
            return Integer.parseInt((String) node) % 2 == 0; // Use this renderer for even rows only.
Lines 423-429 Link Here
423
        @Override
420
        @Override
424
        public TableCellRenderer getCellRenderer(Object node, String columnID) throws UnknownTypeException {
421
        public TableCellRenderer getCellRenderer(Object node, String columnID) throws UnknownTypeException {
425
            if (!(Integer.parseInt((String) node) % 2 == 0)) {
422
            if (!(Integer.parseInt((String) node) % 2 == 0)) {
426
                throw new IllegalStateException("Trying to get renderer even if we can not provide it node = "+node);
423
                throw new IllegalStateException("Trying to get renderer even if we can not provide it node = " + node);
427
            }
424
            }
428
            return new CellRendererImpl(node, columnID);
425
            return new CellRendererImpl(node, columnID);
429
        }
426
        }
Lines 436-442 Link Here
436
        @Override
433
        @Override
437
        public TableCellEditor getCellEditor(Object node, String columnID) throws UnknownTypeException {
434
        public TableCellEditor getCellEditor(Object node, String columnID) throws UnknownTypeException {
438
            if (!(Integer.parseInt((String) node) % 3 == 0)) {
435
            if (!(Integer.parseInt((String) node) % 3 == 0)) {
439
                throw new IllegalStateException("Trying to get editor even if we can not provide it node = "+node);
436
                throw new IllegalStateException("Trying to get editor even if we can not provide it node = " + node);
440
            }
437
            }
441
            return new CellEditorImpl(node, columnID);
438
            return new CellEditorImpl(node, columnID);
442
        }
439
        }
Lines 452-458 Link Here
452
        }
449
        }
453
450
454
        // TreeModel
451
        // TreeModel
455
456
        @Override
452
        @Override
457
        public Object getRoot() {
453
        public Object getRoot() {
458
            return ROOT;
454
            return ROOT;
Lines 461-467 Link Here
461
        @Override
457
        @Override
462
        public Object[] getChildren(Object parent, int from, int to) throws UnknownTypeException {
458
        public Object[] getChildren(Object parent, int from, int to) throws UnknownTypeException {
463
            if (ROOT.equals(parent)) {
459
            if (ROOT.equals(parent)) {
464
                return new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
460
                return new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
465
            }
461
            }
466
            throw new UnknownTypeException(parent);
462
            throw new UnknownTypeException(parent);
467
        }
463
        }
Lines 477-483 Link Here
477
        }
473
        }
478
474
479
        // TableModel
475
        // TableModel
480
481
        @Override
476
        @Override
482
        public Object getValueAt(Object node, String columnID) throws UnknownTypeException {
477
        public Object getValueAt(Object node, String columnID) throws UnknownTypeException {
483
            return ((String) node) + " " + columnID;
478
            return ((String) node) + " " + columnID;
Lines 505-511 Link Here
505
500
506
        @Override
501
        @Override
507
        public String getShortDescription(Object node) throws UnknownTypeException {
502
        public String getShortDescription(Object node) throws UnknownTypeException {
508
            return "Short Description of "+node;
503
            return "Short Description of " + node;
509
        }
504
        }
510
505
511
        @Override
506
        @Override
Lines 535-541 Link Here
535
530
536
        @Override
531
        @Override
537
        public PasteType[] getPasteTypes(Object node, Transferable t) throws UnknownTypeException {
532
        public PasteType[] getPasteTypes(Object node, Transferable t) throws UnknownTypeException {
538
            return new PasteType[] {};
533
            return new PasteType[]{};
539
        }
534
        }
540
535
541
        @Override
536
        @Override
Lines 547-558 Link Here
547
        public String getIconBaseWithExtension(Object node) throws UnknownTypeException {
542
        public String getIconBaseWithExtension(Object node) throws UnknownTypeException {
548
            return null;
543
            return null;
549
        }
544
        }
550
        
545
551
    }
546
    }
552
547
553
    private static class ColumnModelImpl extends ColumnModel {
548
    private static class ColumnModelImpl extends ColumnModel {
554
549
555
        private String id;
550
        private final String id;
556
551
557
        ColumnModelImpl(String id) {
552
        ColumnModelImpl(String id) {
558
            this.id = id;
553
            this.id = id;
Lines 565-571 Link Here
565
560
566
        @Override
561
        @Override
567
        public String getDisplayName() {
562
        public String getDisplayName() {
568
            return "Test Column "+id;
563
            return "Test Column " + id;
569
        }
564
        }
570
565
571
        @Override
566
        @Override
(-)/home/enrico/Lavoro/releases/spi.viewmodel/test/unit/src/org/netbeans/modules/viewmodel/YardaTest.java (-57 / +52 lines)
Lines 41-119 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.viewmodel;
44
package org.netbeans.modules.viewmodel;
46
45
47
import java.util.ArrayList;
46
import java.util.ArrayList;
48
49
import java.util.List;
47
import java.util.List;
50
import org.netbeans.junit.NbTestCase;
48
import org.netbeans.junit.NbTestCase;
51
49
import org.netbeans.spi.viewmodel.ModelEvent;
52
import org.netbeans.spi.viewmodel.*;
50
import org.netbeans.spi.viewmodel.Models;
53
51
import org.netbeans.spi.viewmodel.UnknownTypeException;
54
import org.openide.nodes.Node;
52
import org.openide.nodes.Node;
55
53
56
57
58
/**
54
/**
59
 * Tests the JPDABreakpointEvent.resume() functionality.
55
 * Tests the JPDABreakpointEvent.resume() functionality.
60
 *
56
 *
61
 * @author Maros Sandor, Jan Jancura
57
 * @author Maros Sandor, Jan Jancura
62
 */
58
 */
63
public class YardaTest  extends NbTestCase {
59
public class YardaTest extends NbTestCase {
64
65
60
66
    public YardaTest (String s) {
61
    public YardaTest(String s) {
67
        super (s);
62
        super(s);
68
    }
63
    }
69
64
70
    public void testSubsequentRequest () throws Exception {
65
    public void testSubsequentRequest() throws Exception {
71
        doColeasingSimulation (0);
66
        doColeasingSimulation(0);
72
    }
67
    }
73
    public void testColeasingOfRequests () throws Exception {
68
74
        doColeasingSimulation (1);
69
    public void testColeasingOfRequests() throws Exception {
70
        doColeasingSimulation(1);
75
    }
71
    }
76
    
72
77
    private void doColeasingSimulation (int type) throws Exception {
73
    private void doColeasingSimulation(int type) throws Exception {
78
        ArrayList l = new ArrayList ();
74
        ArrayList l = new ArrayList();
79
        CompoundModel1 cm1 = new CompoundModel1 ();
75
        CompoundModel1 cm1 = new CompoundModel1();
80
        l.add (cm1);
76
        l.add(cm1);
81
        OutlineTable tt = BasicTest.createView(Models.createCompoundModel (l));
77
        OutlineTable tt = BasicTest.createView(Models.createCompoundModel(l));
82
        Node n = tt.getExplorerManager ().
78
        Node n = tt.getExplorerManager().
83
            getRootContext ();
79
                getRootContext();
84
        synchronized (cm1) {
80
        synchronized (cm1) {
85
            n.getChildren ().getNodes ();
81
            n.getChildren().getNodes();
86
            cm1.wait (1000);
82
            cm1.wait(1000);
87
            if (cm1.count > 1) {
83
            if (cm1.count > 1) {
88
                cm1.stackTraces.toString();
84
                cm1.stackTraces.toString();
89
            }
85
            }
90
            assertEquals ("Model caled", 1, cm1.count);
86
            assertEquals("Model caled", 1, cm1.count);
91
            cm1.fire (new ModelEvent.TreeChanged(cm1.getRoot()));
87
            cm1.fire(new ModelEvent.TreeChanged(cm1.getRoot()));
92
            n.getChildren ().getNodes ();
88
            n.getChildren().getNodes();
93
            
89
94
            if (type == 1) {
90
            if (type == 1) {
95
                cm1.fire (new ModelEvent.TreeChanged(cm1.getRoot()));
91
                cm1.fire(new ModelEvent.TreeChanged(cm1.getRoot()));
96
                n.getChildren ().getNodes ();
92
                n.getChildren().getNodes();
97
            }
93
            }
98
            
94
99
            cm1.notifyAll ();
95
            cm1.notifyAll();
100
        }
96
        }
101
        Thread.yield();
97
        Thread.yield();
102
        Thread.sleep(1000);
98
        Thread.sleep(1000);
103
        tt.currentTreeModelRoot.getRootNode().getRequestProcessor().post (new Runnable () {
99
        tt.currentTreeModelRoot.getRootNode().getRequestProcessor().post(new Runnable() {
104
            public void run () {}
100
            @Override
105
        }).waitFinished ();
101
            public void run() {
102
            }
103
        }).waitFinished();
106
        //System.err.println("Child = "+n.getChildren().getNodes()[0]);
104
        //System.err.println("Child = "+n.getChildren().getNodes()[0]);
107
        // TODO: Broken, there's a Please wait... node!
105
        // TODO: Broken, there's a Please wait... node!
108
        assertEquals ("Computation has finished in RP", 3, n.getChildren ().getNodes ().length);
106
        assertEquals("Computation has finished in RP", 3, n.getChildren().getNodes().length);
109
        if (cm1.count > 2) {
107
        if (cm1.count > 2) {
110
            cm1.stackTraces.toString();
108
            cm1.stackTraces.toString();
111
        }
109
        }
112
        assertEquals ("Model caled", 2, cm1.count);
110
        assertEquals("Model caled", 2, cm1.count);
113
    }
111
    }
114
    
112
115
    public final class CompoundModel1 extends BasicTest.CompoundModel {
113
    public final class CompoundModel1 extends BasicTest.CompoundModel {
116
        
114
117
        public int count = 0;
115
        public int count = 0;
118
        public List<Throwable> stackTraces = new ArrayList<Throwable>() {
116
        public List<Throwable> stackTraces = new ArrayList<Throwable>() {
119
117
Lines 121-127 Link Here
121
            public String toString() {
119
            public String toString() {
122
                for (int i = 0; i < size(); i++) {
120
                for (int i = 0; i < size(); i++) {
123
                    Throwable o = get(i);
121
                    Throwable o = get(i);
124
                    System.err.println((i+1)+" call:");
122
                    System.err.println((i + 1) + " call:");
125
                    o.printStackTrace();
123
                    o.printStackTrace();
126
                }
124
                }
127
                return "";
125
                return "";
Lines 129-159 Link Here
129
127
130
        };
128
        };
131
129
132
133
        // init ....................................................................
130
        // init ....................................................................
134
135
        /**
131
        /**
136
         * Returns number of children for given node.
132
         * Returns number of children for given node.
137
         * 
138
         * @param   node the parent node
139
         * @throws  UnknownTypeException if this TreeModel implementation is not
140
         *          able to resolve children for given node type
141
         *
133
         *
142
         * @return  true if node is leaf
134
         * @param node the parent node
135
         * @throws UnknownTypeException if this TreeModel implementation is not
136
         * able to resolve children for given node type
137
         *
138
         * @return true if node is leaf
143
         */
139
         */
144
        @Override
140
        @Override
145
        public synchronized int getChildrenCount (Object node) throws UnknownTypeException {
141
        public synchronized int getChildrenCount(Object node) throws UnknownTypeException {
146
            count++;
142
            count++;
147
            stackTraces.add(new Exception().fillInStackTrace());
143
            stackTraces.add(new Exception().fillInStackTrace());
148
            notify ();
144
            notify();
149
            /*
145
            /*
150
            try {
146
             try {
151
                wait (2000); // We must not wait here, otherwise we get a "Please wait..." node
147
             wait (2000); // We must not wait here, otherwise we get a "Please wait..." node
152
            } catch (InterruptedException ex) {
148
             } catch (InterruptedException ex) {
153
                ex.printStackTrace();
149
             ex.printStackTrace();
154
            }
150
             }
155
             */
151
             */
156
            return super.getChildrenCount (node);
152
            return super.getChildrenCount(node);
157
        }
153
        }
158
154
159
        @Override
155
        @Override
Lines 166-171 Link Here
166
            return false;
162
            return false;
167
        }
163
        }
168
164
169
170
    }
165
    }
171
}
166
}

Return to bug 268804