|
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.panels.apache.client.swing; |
|
27 |
|
28 import java.util.List; |
|
29 import javax.swing.*; |
|
30 import com.oracle.solaris.vp.panel.common.control.*; |
|
31 import com.oracle.solaris.vp.panel.common.view.PanelIconUtil; |
|
32 import com.oracle.solaris.vp.panel.swing.control.*; |
|
33 import com.oracle.solaris.vp.panel.swing.view.*; |
|
34 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
35 import com.oracle.solaris.vp.util.swing.*; |
|
36 |
|
37 public class MimeTypesControl extends ListSelectorControl<ApachePanelDescriptor, |
|
38 ListSelectorPanel, MimeType> implements HasIcons { |
|
39 |
|
40 // |
|
41 // Static data |
|
42 // |
|
43 |
|
44 public static final String ID = "mimetypes"; |
|
45 public static final String NAME = Finder.getString("mimetypes.title"); |
|
46 |
|
47 // |
|
48 // Instance data |
|
49 // |
|
50 |
|
51 private HasMimeTypes parent; |
|
52 |
|
53 // |
|
54 // Constructors |
|
55 // |
|
56 |
|
57 public MimeTypesControl(ApachePanelDescriptor descriptor, |
|
58 HasMimeTypes parent) { |
|
59 |
|
60 super(ID, NAME, descriptor); |
|
61 this.parent = parent; |
|
62 } |
|
63 |
|
64 // |
|
65 // HasIcons methods |
|
66 // |
|
67 |
|
68 @Override |
|
69 public List<? extends Icon> getIcons() { |
|
70 return PanelIconUtil.getGenericMimeIcons(); |
|
71 } |
|
72 |
|
73 // |
|
74 // Control methods |
|
75 // |
|
76 |
|
77 @Override |
|
78 public Navigable[] getForwardingPath(boolean childStopped) { |
|
79 List<MimeType> mimeTypes = parent.getMimeTypes().getChildren(); |
|
80 if (!mimeTypes.isEmpty()) { |
|
81 |
|
82 MimeType mimeType = mimeTypes.get(0); |
|
83 |
|
84 return new Navigable[] { |
|
85 new SimpleNavigable(MimeTypeControl.ID, null, |
|
86 MimeTypeControl.PARAM_MIMETYPE, mimeType.getId()) |
|
87 }; |
|
88 } |
|
89 |
|
90 return null; |
|
91 } |
|
92 |
|
93 @Override |
|
94 public String getHelpMapID() { |
|
95 return "apache-mimetypes"; |
|
96 } |
|
97 |
|
98 // |
|
99 // DefaultControl methods |
|
100 // |
|
101 |
|
102 @Override |
|
103 protected void ensureChildrenCreated() { |
|
104 if (children.size() == 0) { |
|
105 ApachePanelDescriptor descriptor = getPanelDescriptor(); |
|
106 SwingControl child = new MimeTypeControl(descriptor, this); |
|
107 addChildren(child); |
|
108 addToLayout(child); |
|
109 } |
|
110 } |
|
111 |
|
112 // |
|
113 // SwingControl methods |
|
114 // |
|
115 |
|
116 @Override |
|
117 protected void configComponent(ListSelectorPanel panel) { |
|
118 super.configComponent(panel); |
|
119 addDefaultCloseAction(false); |
|
120 addDefaultHelpAction(); |
|
121 } |
|
122 |
|
123 @Override |
|
124 protected ListSelectorPanel createComponent() { |
|
125 ListSelectorPanel panel = new ListSelectorPanel(); |
|
126 panel.setSelectionTitle(Finder.getString("mimetypes.list.title")); |
|
127 |
|
128 JList list = panel.getSelectionComponent(); |
|
129 SimpleCellRenderer renderer = new ManagedObjectCellRenderer<MimeType>(); |
|
130 renderer.configureFor(list); |
|
131 list.setCellRenderer(renderer); |
|
132 |
|
133 addAction(panel, new CreateMimeTypeAction(this), true, true); |
|
134 addAction(panel, new DeleteMimeTypeAction(this), true, true); |
|
135 |
|
136 setDefaultContentView(new NoMimeTypePanel()); |
|
137 |
|
138 return panel; |
|
139 } |
|
140 |
|
141 // |
|
142 // ListSelectorControl methods |
|
143 // |
|
144 |
|
145 @Override |
|
146 protected int getListIndexOf(Control child) { |
|
147 MimeType mimeType = ((MimeTypeControl)child).getMimeType(); |
|
148 int index = parent.getMimeTypes().indexOf(mimeType); |
|
149 assert mimeType == getComponent().getSelectionComponent().getModel(). |
|
150 getElementAt(index); |
|
151 return index; |
|
152 } |
|
153 |
|
154 @Override |
|
155 protected ListModel getListModel() { |
|
156 return new ManagedObjectTableModel<MimeType>(parent.getMimeTypes()); |
|
157 } |
|
158 |
|
159 @Override |
|
160 protected Navigable[] getPathForSelection(List<MimeType> selection) { |
|
161 if (selection.size() != 1) { |
|
162 return null; |
|
163 } |
|
164 |
|
165 MimeType selected = selection.get(0); |
|
166 |
|
167 return new Navigable[] { |
|
168 new SimpleNavigable(MimeTypeControl.ID, selected.getName(), |
|
169 MimeTypeControl.PARAM_MIMETYPE, selected.getId()) |
|
170 }; |
|
171 } |
|
172 |
|
173 // |
|
174 // MimeTypesControl methods |
|
175 // |
|
176 |
|
177 public HasMimeTypes getHasMimeTypes() { |
|
178 return parent; |
|
179 } |
|
180 } |