001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 * Portions Copyright 2014-2016 ForgeRock AS. 016 */ 017 018package org.opends.guitools.controlpanel.ui; 019 020import static org.opends.messages.AdminToolMessages.*; 021 022import java.awt.CardLayout; 023import java.awt.Component; 024import java.awt.GridBagConstraints; 025 026import javax.swing.JPanel; 027 028import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo; 029import org.opends.guitools.controlpanel.datamodel.IndexDescriptor; 030import org.opends.guitools.controlpanel.datamodel.VLVIndexDescriptor; 031import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent; 032import org.opends.guitools.controlpanel.event.IndexSelectionListener; 033import org.forgerock.i18n.LocalizableMessage; 034 035/** The panel on the right of the 'Manage Indexes' panel. */ 036public class IndexBrowserRightPanel extends StatusGenericPanel 037{ 038 private static final long serialVersionUID = -6904674789074101772L; 039 private JPanel mainPanel; 040 private IndexPanel standardIndexPanel = new IndexPanel(); 041 private VLVIndexPanel vlvIndexPanel = new VLVIndexPanel(); 042 private BackendIndexesPanel backendIndexesPanel = new BackendIndexesPanel(); 043 private BackendVLVIndexesPanel backendVLVIndexesPanel = 044 new BackendVLVIndexesPanel(); 045 046 private static final String NOTHING_SELECTED = "Nothing Selected"; 047 private static final String MULTIPLE_SELECTED = "Multiple Selected"; 048 049 /** Default constructor. */ 050 public IndexBrowserRightPanel() 051 { 052 super(); 053 createLayout(); 054 } 055 056 /** Displays a panel informing that no item is selected. */ 057 public void displayVoid() 058 { 059 ((CardLayout)mainPanel.getLayout()).show(mainPanel, NOTHING_SELECTED); 060 } 061 062 /** Displays a panel informing that multiple items are selected. */ 063 public void displayMultiple() 064 { 065 ((CardLayout)mainPanel.getLayout()).show(mainPanel, MULTIPLE_SELECTED); 066 } 067 068 /** 069 * Adds an index selection listener. 070 * @param listener the index selection listener. 071 */ 072 public void addIndexSelectionListener(IndexSelectionListener listener) 073 { 074 backendIndexesPanel.addIndexSelectionListener(listener); 075 backendVLVIndexesPanel.addIndexSelectionListener(listener); 076 } 077 078 /** 079 * Removes an index selection listener. 080 * @param listener the index selection listener. 081 */ 082 public void removeIndexSelectionListener(IndexSelectionListener listener) 083 { 084 backendIndexesPanel.removeIndexSelectionListener(listener); 085 backendVLVIndexesPanel.removeIndexSelectionListener(listener); 086 } 087 088 @Override 089 public void setInfo(ControlPanelInfo info) 090 { 091 super.setInfo(info); 092 standardIndexPanel.setInfo(info); 093 vlvIndexPanel.setInfo(info); 094 backendIndexesPanel.setInfo(info); 095 backendVLVIndexesPanel.setInfo(info); 096 } 097 098 /** 099 * Updates the contents of the panel with an standard index. 100 * @param index the index to be used to update the contents of the panel. 101 */ 102 public void updateStandardIndex(IndexDescriptor index) 103 { 104 standardIndexPanel.update(index); 105 ((CardLayout)mainPanel.getLayout()).show(mainPanel, 106 standardIndexPanel.getTitle().toString()); 107 } 108 109 /** 110 * Updates the contents of the panel with a VLV index. 111 * @param index the index to be used to update the contents of the panel. 112 */ 113 public void updateVLVIndex(VLVIndexDescriptor index) 114 { 115 vlvIndexPanel.update(index); 116 ((CardLayout)mainPanel.getLayout()).show(mainPanel, 117 vlvIndexPanel.getTitle().toString()); 118 } 119 120 /** 121 * Updates the contents of the panel with the indexes on the provided backend. 122 * A table with all the indexes of the backend will be displayed. 123 * @param backendName the name of the backend. 124 */ 125 public void updateBackendIndexes(String backendName) 126 { 127 backendIndexesPanel.update(backendName); 128 ((CardLayout)mainPanel.getLayout()).show(mainPanel, 129 backendIndexesPanel.getTitle().toString()); 130 } 131 132 /** 133 * Updates the contents of the panel with the VLV indexes on the provided 134 * backend. 135 * A table with all the VLV indexes of the backend will be displayed. 136 * @param backendName the name of the backend. 137 */ 138 public void updateBackendVLVIndexes(String backendName) 139 { 140 backendVLVIndexesPanel.update(backendName); 141 ((CardLayout)mainPanel.getLayout()).show(mainPanel, 142 backendVLVIndexesPanel.getTitle().toString()); 143 } 144 145 /** Creates the layout of the panel (but the contents are not populated here). */ 146 private void createLayout() 147 { 148 GridBagConstraints gbc = new GridBagConstraints(); 149 CardLayout cardLayout = new CardLayout(); 150 mainPanel = new JPanel(cardLayout); 151 mainPanel.setOpaque(false); 152 NoItemSelectedPanel noEntryPanel = new NoItemSelectedPanel(); 153 mainPanel.add(noEntryPanel, NOTHING_SELECTED); 154 NoItemSelectedPanel multipleEntryPanel = new NoItemSelectedPanel(); 155 multipleEntryPanel.setMessage( 156 INFO_CTRL_PANEL_MULTIPLE_ITEMS_SELECTED_LABEL.get()); 157 mainPanel.add(multipleEntryPanel, MULTIPLE_SELECTED); 158 StatusGenericPanel[] panels = 159 { 160 standardIndexPanel, 161 backendIndexesPanel, 162 backendVLVIndexesPanel, 163 vlvIndexPanel 164 }; 165 for (StatusGenericPanel panel : panels) 166 { 167 mainPanel.add(panel, panel.getTitle().toString()); 168 } 169 cardLayout.show(mainPanel, NOTHING_SELECTED); 170 gbc.gridx = 0; 171 gbc.gridy = 0; 172 gbc.weightx = 1.0; 173 gbc.weighty = 1.0; 174 gbc.fill = GridBagConstraints.BOTH; 175 add(mainPanel, gbc); 176 } 177 178 @Override 179 public void okClicked() 180 { 181 // No ok button 182 } 183 184 @Override 185 public GenericDialog.ButtonType getButtonType() 186 { 187 return GenericDialog.ButtonType.NO_BUTTON; 188 } 189 190 @Override 191 public LocalizableMessage getTitle() 192 { 193 return INFO_CTRL_PANEL_INDEX_BROWSER_RIGHT_PANEL_TITLE.get(); 194 } 195 196 @Override 197 public Component getPreferredFocusComponent() 198 { 199 // TODO 200 return null; 201 } 202 203 @Override 204 public void configurationChanged(ConfigurationChangeEvent ev) 205 { 206 } 207 208 /** 209 * Method used to know if there are unsaved changes or not. It is used by 210 * the index selection listener when the user changes the selection. 211 * @return <CODE>true</CODE> if there are unsaved changes (and so the 212 * selection of the index should be canceled) and <CODE>false</CODE> 213 * otherwise. 214 */ 215 public boolean mustCheckUnsavedChanges() 216 { 217 boolean mustCheckUnsavedChanges; 218 if (vlvIndexPanel.isVisible()) 219 { 220 mustCheckUnsavedChanges = vlvIndexPanel.mustCheckUnsavedChanges(); 221 } 222 else if (standardIndexPanel.isVisible()) 223 { 224 mustCheckUnsavedChanges = standardIndexPanel.mustCheckUnsavedChanges(); 225 } 226 else 227 { 228 mustCheckUnsavedChanges = false; 229 } 230 return mustCheckUnsavedChanges; 231 } 232 233 /** 234 * Tells whether the user chose to save the changes in the panel, to not save 235 * them or simply cancelled the selection in the tree. 236 * @return the value telling whether the user chose to save the changes in the 237 * panel, to not save them or simply cancelled the selection in the tree. 238 */ 239 public UnsavedChangesDialog.Result checkUnsavedChanges() 240 { 241 UnsavedChangesDialog.Result result; 242 if (vlvIndexPanel.isVisible()) 243 { 244 result = vlvIndexPanel.checkUnsavedChanges(); 245 } 246 else if (standardIndexPanel.isVisible()) 247 { 248 result = standardIndexPanel.checkUnsavedChanges(); 249 } 250 else 251 { 252 result = UnsavedChangesDialog.Result.DO_NOT_SAVE; 253 } 254 return result; 255 } 256}