|
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.model; |
|
27 |
|
28 import java.awt.Component; |
|
29 import java.util.Comparator; |
|
30 import javax.swing.JTable; |
|
31 import javax.swing.table.TableCellRenderer; |
|
32 import com.oracle.solaris.vp.panel.common.model.ManagedObject; |
|
33 import com.oracle.solaris.vp.panel.swing.view.ManagedObjectCellRenderer; |
|
34 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
35 import com.oracle.solaris.vp.util.swing.SimpleCellRenderer; |
|
36 import com.oracle.solaris.vp.util.swing.propinfo.AbstractSwingPropInfo; |
|
37 |
|
38 public class ManagedObjectPropInfo<M extends ManagedObject> |
|
39 extends AbstractSwingPropInfo<M, M> { |
|
40 |
|
41 // |
|
42 // Static data |
|
43 // |
|
44 |
|
45 /** |
|
46 * Available instance to mitigate object creation |
|
47 */ |
|
48 public static final ManagedObjectPropInfo instance = |
|
49 new ManagedObjectPropInfo(); |
|
50 |
|
51 private static final SimpleCellRenderer renderer = |
|
52 new ManagedObjectCellRenderer() { |
|
53 |
|
54 @Override |
|
55 public String getStatusText(Component comp, ManagedObject obj, |
|
56 boolean isSelected, boolean hasFocus) { |
|
57 |
|
58 return (null); |
|
59 } |
|
60 }; |
|
61 |
|
62 static { |
|
63 renderer.configureFor((JTable)null); |
|
64 } |
|
65 |
|
66 // |
|
67 // Instance data |
|
68 // |
|
69 |
|
70 private final Comparator<M> comparator = |
|
71 new Comparator<M>() { |
|
72 @Override |
|
73 public int compare(M o1, M o2) { |
|
74 return o1.getName().compareTo(o2.getName()); |
|
75 } |
|
76 }; |
|
77 |
|
78 // |
|
79 // Constructors |
|
80 // |
|
81 |
|
82 public ManagedObjectPropInfo() { |
|
83 super(Finder.getString("property.name.label"), |
|
84 Finder.getString("property.name.description"), true, false); |
|
85 } |
|
86 |
|
87 // |
|
88 // ManagedObjectPropInfo methods |
|
89 // |
|
90 |
|
91 @Override |
|
92 public Comparator<M> getComparator() { |
|
93 return comparator; |
|
94 } |
|
95 |
|
96 @Override |
|
97 public M getValue(M o) { |
|
98 return o; |
|
99 } |
|
100 |
|
101 // |
|
102 // SwingPropInfo methods |
|
103 // |
|
104 |
|
105 @Override |
|
106 public TableCellRenderer getTableCellRenderer() { |
|
107 return renderer; |
|
108 } |
|
109 } |