1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.panel.swing.view; |
|
27 |
|
28 import java.util.*; |
|
29 import javax.swing.BorderFactory; |
|
30 import javax.swing.event.*; |
|
31 import com.oracle.solaris.vp.panel.common.action.StructuredAction; |
|
32 import com.oracle.solaris.vp.panel.common.model.ManagedObject; |
|
33 import com.oracle.solaris.vp.util.common.propinfo.PropInfo; |
|
34 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
35 import com.oracle.solaris.vp.util.swing.ExtScrollPane; |
|
36 |
|
37 /** |
|
38 * The {@code TableObjectsView} class displays the children of a {@code |
|
39 * ManagedObject} in a {@code JTable}. |
|
40 */ |
|
41 public class TableObjectsView<C extends ManagedObject> extends ObjectsView<C> { |
|
42 // |
|
43 // Instance data |
|
44 // |
|
45 |
|
46 private ManagedObjectTable table; |
|
47 private ManagedObjectTableModel<C> model; |
|
48 private ExtScrollPane scroll; |
|
49 |
|
50 // |
|
51 // Constructors |
|
52 // |
|
53 |
|
54 public TableObjectsView(ManagedObject<C> pObject, |
|
55 StructuredAction<List<C>, ?, ?>[] mActions, |
|
56 StructuredAction<List<C>, ?, ?> dmAction, |
|
57 PropInfo<C, ?>[] props) { |
|
58 |
|
59 super(pObject, mActions, dmAction); |
|
60 |
|
61 SimplePopupMenu popupMenu = mActions == null || mActions.length == 0 ? |
|
62 null : new SimplePopupMenu(mActions); |
|
63 |
|
64 model = new ManagedObjectTableModel<C>(pObject, props); |
|
65 model.addListDataListener( |
|
66 new ListDataListener() { |
|
67 @Override |
|
68 public void contentsChanged(ListDataEvent e) { |
|
69 fireObjectCountChange(); |
|
70 } |
|
71 |
|
72 @Override |
|
73 public void intervalAdded(ListDataEvent e) { |
|
74 fireObjectCountChange(); |
|
75 } |
|
76 |
|
77 @Override |
|
78 public void intervalRemoved(ListDataEvent e) { |
|
79 fireObjectCountChange(); |
|
80 } |
|
81 }); |
|
82 |
|
83 table = new ManagedObjectTable(model, popupMenu, dmAction); |
|
84 |
|
85 // Notify Actions of changes in selection model |
|
86 table.getSelectionModel().addListSelectionListener( |
|
87 updateActionSelectionListener); |
|
88 |
|
89 scroll = new ExtScrollPane(table); |
|
90 scroll.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
|
91 } |
|
92 |
|
93 // |
|
94 // ObjectsView methods |
|
95 // |
|
96 |
|
97 @Override |
|
98 public ExtScrollPane getComponent() { |
|
99 return scroll; |
|
100 } |
|
101 |
|
102 @Override |
|
103 public String getName() { |
|
104 return Finder.getString("objects.header.view.value.table"); |
|
105 } |
|
106 |
|
107 @Override |
|
108 public int getObjectCount() { |
|
109 return table.getRowCount(); |
|
110 } |
|
111 |
|
112 @Override |
|
113 public List<C> getSelection() { |
|
114 int[] vRows = table.getSelectedRows(); |
|
115 List<C> selection = new ArrayList<C>(vRows.length); |
|
116 |
|
117 for (int i = 0; i < vRows.length; i++) { |
|
118 int mRow = table.convertRowIndexToModel(vRows[i]); |
|
119 selection.add(model.getElementAt(mRow)); |
|
120 } |
|
121 |
|
122 return selection; |
|
123 } |
|
124 |
|
125 // |
|
126 // TableObjectsView methods |
|
127 // |
|
128 |
|
129 public ManagedObjectTable getTable() { |
|
130 return table; |
|
131 } |
|
132 } |
|