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