usr/src/java/vpanels/panels/apache/org/opensolaris/os/vp/panels/apache/client/swing/MimeTypesControl.java
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
package org.opensolaris.os.vp.panels.apache.client.swing;
import java.awt.Image;
import java.net.URL;
import java.util.List;
import javax.swing.*;
import org.opensolaris.os.vp.panel.common.control.*;
import org.opensolaris.os.vp.panel.common.view.PanelIconUtil;
import org.opensolaris.os.vp.panel.swing.control.*;
import org.opensolaris.os.vp.panel.swing.view.*;
import org.opensolaris.os.vp.util.misc.*;
import org.opensolaris.os.vp.util.swing.*;
public class MimeTypesControl extends ListSelectorControl<ApachePanelDescriptor,
ListSelectorPanel, MimeType> implements HasImages {
//
// Static data
//
public static final String ID = "mimetypes";
public static final String NAME = Finder.getString("mimetypes.title");
protected static final List<Image> images = IconUtil.getImages(
PanelIconUtil.getGenericMimeIcons());
//
// Instance data
//
private HasMimeTypes parent;
//
// Constructors
//
public MimeTypesControl(ApachePanelDescriptor descriptor,
HasMimeTypes parent) {
super(ID, NAME, descriptor);
this.parent = parent;
}
//
// HasImages methods
//
@Override
public List<? extends Image> getImages() {
return images;
}
//
// Control methods
//
@Override
public Navigable[] getForwardingPath() {
List<MimeType> mimeTypes = parent.getMimeTypes().getChildren();
if (!mimeTypes.isEmpty()) {
MimeType mimeType = mimeTypes.get(0);
return new Navigable[] {
new SimpleNavigable(MimeTypeControl.ID, null,
MimeTypeControl.PARAM_MIMETYPE, mimeType.getId())
};
}
return null;
}
@Override
public URL getHelpURL() {
return buildHelpURL("help/apache.html", "#apache-mimetypes");
}
//
// DefaultControl methods
//
@Override
protected void ensureChildrenCreated() {
if (children.size() == 0) {
ApachePanelDescriptor descriptor = getPanelDescriptor();
SwingControl child = new MimeTypeControl(descriptor, this);
addChildren(child);
addToLayout(child);
}
}
//
// SwingControl methods
//
@Override
protected ListSelectorPanel createComponent() {
ListSelectorPanel panel = new ListSelectorPanel();
panel.setSelectionTitle(Finder.getString("mimetypes.list.title"));
JList list = panel.getSelectionComponent();
SimpleCellRenderer renderer = new ManagedObjectCellRenderer<MimeType>();
renderer.configureFor(list);
list.setCellRenderer(renderer);
addAction(panel, new CreateMimeTypeAction(this), true, true);
addAction(panel, new DeleteMimeTypeAction(this), true, true);
addDefaultCloseAction(panel, false);
addDefaultHelpAction(panel);
setDefaultContentView(new NoMimeTypePanel());
return panel;
}
//
// ListSelectorControl methods
//
@Override
protected int getListIndexOf(Control child) {
MimeType mimeType = ((MimeTypeControl)child).getMimeType();
int index = parent.getMimeTypes().indexOf(mimeType);
assert mimeType == getComponent().getSelectionComponent().getModel().
getElementAt(index);
return index;
}
@Override
protected ListModel getListModel() {
return new ManagedObjectTableModel<MimeType>(parent.getMimeTypes(),
null);
}
@Override
protected Navigable[] getPathForSelection(List<MimeType> selection) {
if (selection.size() != 1) {
return null;
}
MimeType selected = selection.get(0);
return new Navigable[] {
new SimpleNavigable(MimeTypeControl.ID, selected.getName(),
MimeTypeControl.PARAM_MIMETYPE, selected.getId())
};
}
//
// MimeTypesControl methods
//
public HasMimeTypes getHasMimeTypes() {
return parent;
}
}