001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2008-2009 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027 028package org.opends.guitools.controlpanel.ui; 029 030import static org.opends.messages.AdminToolMessages.*; 031 032import java.awt.CardLayout; 033import java.awt.Component; 034import java.awt.GridBagConstraints; 035 036import javax.swing.JPanel; 037 038import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo; 039import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent; 040import org.opends.guitools.controlpanel.event. 041 ConfigurationElementCreatedListener; 042import org.opends.guitools.controlpanel.event.SchemaElementSelectionListener; 043import org.opends.guitools.controlpanel.util.Utilities; 044import org.forgerock.i18n.LocalizableMessage; 045import org.forgerock.opendj.ldap.schema.Syntax; 046import org.forgerock.opendj.ldap.schema.MatchingRule; 047import org.opends.server.types.AttributeType; 048import org.opends.server.types.ObjectClass; 049import org.opends.server.types.Schema; 050 051/** 052 * The panel on the right of the 'Manage Schema' panel. 053 * 054 */ 055public class SchemaBrowserRightPanel extends StatusGenericPanel 056{ 057 private static final long serialVersionUID = 5294502011852239497L; 058 private JPanel mainPanel; 059 private StandardObjectClassPanel standardObjectClassPanel = 060 new StandardObjectClassPanel(); 061 private ConfigurationObjectClassPanel configurationObjectClassPanel = 062 new ConfigurationObjectClassPanel(); 063 private CustomObjectClassPanel customObjectClassPanel = 064 new CustomObjectClassPanel(); 065 private StandardAttributePanel standardAttributePanel = 066 new StandardAttributePanel(); 067 private ConfigurationAttributePanel configurationAttributePanel = 068 new ConfigurationAttributePanel(); 069 private CustomAttributePanel customAttributePanel = 070 new CustomAttributePanel(); 071 private MatchingRulePanel matchingRulePanel = new MatchingRulePanel(); 072 private AttributeSyntaxPanel attributeSyntaxPanel = 073 new AttributeSyntaxPanel(); 074 075 private NoItemSelectedPanel noEntryPanel = new NoItemSelectedPanel(); 076 077 private final SchemaElementPanel[] panels = 078 { standardObjectClassPanel, configurationObjectClassPanel, 079 customObjectClassPanel, 080 standardAttributePanel, configurationAttributePanel, customAttributePanel, 081 matchingRulePanel, 082 attributeSyntaxPanel 083 }; 084 085 private final String NOTHING_SELECTED = "Nothing Selected"; 086 087 088 private SchemaElementPanel schemaElementPanel; 089 090 /** 091 * Default constructor. 092 * 093 */ 094 public SchemaBrowserRightPanel() 095 { 096 super(); 097 createLayout(); 098 } 099 100 /** 101 * Displays a panel containing a message. 102 * @param msg the message. 103 * 104 */ 105 public void displayMessage(LocalizableMessage msg) 106 { 107 schemaElementPanel = null; 108 noEntryPanel.setMessage(msg); 109 ((CardLayout)mainPanel.getLayout()).show(mainPanel, NOTHING_SELECTED); 110 } 111 112 /** {@inheritDoc} */ 113 public void setInfo(ControlPanelInfo info) 114 { 115 super.setInfo(info); 116 for (StatusGenericPanel panel : panels) 117 { 118 panel.setInfo(info); 119 } 120 } 121 122 /** 123 * Adds an schema element selection listener. 124 * @param listener the schema element selection listener. 125 */ 126 public void addSchemaElementSelectionListener( 127 SchemaElementSelectionListener listener) 128 { 129 for (SchemaElementPanel panel : panels) 130 { 131 panel.addSchemaElementSelectionListener(listener); 132 } 133 } 134 135 /** 136 * Removes an schema element selection listener. 137 * @param listener the schema element selection listener. 138 */ 139 public void removeSchemaElementSelectionListener( 140 SchemaElementSelectionListener listener) 141 { 142 for (SchemaElementPanel panel : panels) 143 { 144 panel.removeSchemaElementSelectionListener(listener); 145 } 146 } 147 148 /** 149 * Adds a configuration element created listener. 150 * @param listener the listener. 151 */ 152 public void addConfigurationElementCreatedListener( 153 ConfigurationElementCreatedListener listener) 154 { 155 super.addConfigurationElementCreatedListener(listener); 156 for (SchemaElementPanel panel : panels) 157 { 158 panel.addConfigurationElementCreatedListener(listener); 159 } 160 } 161 162 /** 163 * Removes a configuration element created listener. 164 * @param listener the listener. 165 */ 166 public void removeConfigurationElementCreatedListener( 167 ConfigurationElementCreatedListener listener) 168 { 169 super.removeConfigurationElementCreatedListener(listener); 170 for (SchemaElementPanel panel : panels) 171 { 172 panel.removeConfigurationElementCreatedListener(listener); 173 } 174 } 175 176 /** 177 * Updates the contents of the panel with the provided standard object class. 178 * @param oc the object class. 179 * @param schema the schema. 180 */ 181 public void updateStandardObjectClass(ObjectClass oc, Schema schema) 182 { 183 standardObjectClassPanel.update(oc, schema); 184 schemaElementPanel = standardObjectClassPanel; 185 ((CardLayout)mainPanel.getLayout()).show(mainPanel, 186 standardObjectClassPanel.getTitle().toString()); 187 } 188 189 /** 190 * Updates the contents of the panel with the provided configuration object 191 * class. 192 * @param oc the object class. 193 * @param schema the schema. 194 */ 195 public void updateConfigurationObjectClass(ObjectClass oc, Schema schema) 196 { 197 configurationObjectClassPanel.update(oc, schema); 198 schemaElementPanel = configurationObjectClassPanel; 199 ((CardLayout)mainPanel.getLayout()).show(mainPanel, 200 configurationObjectClassPanel.getTitle().toString()); 201 } 202 203 /** 204 * Updates the contents of the panel with the provided custom object class. 205 * @param oc the object class. 206 * @param schema the schema. 207 */ 208 public void updateCustomObjectClass(ObjectClass oc, Schema schema) 209 { 210 customObjectClassPanel.update(oc, schema); 211 schemaElementPanel = customObjectClassPanel; 212 ((CardLayout)mainPanel.getLayout()).show(mainPanel, 213 customObjectClassPanel.getTitle().toString()); 214 } 215 216 /** 217 * Updates the contents of the panel with the provided standard attribute. 218 * @param attr the attribute. 219 * @param schema the schema. 220 */ 221 public void updateStandardAttribute(AttributeType attr, Schema schema) 222 { 223 standardAttributePanel.update(attr, schema); 224 schemaElementPanel = standardAttributePanel; 225 ((CardLayout)mainPanel.getLayout()).show(mainPanel, 226 standardAttributePanel.getTitle().toString()); 227 } 228 229 /** 230 * Updates the contents of the panel with the provided configuration 231 * attribute. 232 * @param attr the attribute. 233 * @param schema the schema. 234 */ 235 public void updateConfigurationAttribute(AttributeType attr, Schema schema) 236 { 237 configurationAttributePanel.update(attr, schema); 238 schemaElementPanel = configurationAttributePanel; 239 ((CardLayout)mainPanel.getLayout()).show(mainPanel, 240 configurationAttributePanel.getTitle().toString()); 241 } 242 243 /** 244 * Updates the contents of the panel with the provided custom attribute. 245 * @param attr the attribute. 246 * @param schema the schema. 247 */ 248 public void updateCustomAttribute(AttributeType attr, Schema schema) 249 { 250 customAttributePanel.update(attr, schema); 251 schemaElementPanel = customAttributePanel; 252 ((CardLayout)mainPanel.getLayout()).show(mainPanel, 253 customAttributePanel.getTitle().toString()); 254 } 255 256 /** 257 * Updates the contents of the panel with the provided matching rule. 258 * @param matchingRule the matching rule. 259 * @param schema the schema. 260 */ 261 public void updateMatchingRule(MatchingRule matchingRule, Schema schema) 262 { 263 matchingRulePanel.update(matchingRule, schema); 264 schemaElementPanel = matchingRulePanel; 265 ((CardLayout)mainPanel.getLayout()).show(mainPanel, 266 matchingRulePanel.getTitle().toString()); 267 } 268 269 /** 270 * Updates the contents of the panel with the provided attribute syntax. 271 * @param syntax the attribute syntax. 272 * @param schema the schema. 273 */ 274 public void updateAttributeSyntax(Syntax syntax, Schema schema) 275 { 276 attributeSyntaxPanel.update(syntax, schema); 277 schemaElementPanel = attributeSyntaxPanel; 278 ((CardLayout)mainPanel.getLayout()).show(mainPanel, 279 attributeSyntaxPanel.getTitle().toString()); 280 } 281 282 /** 283 * Creates the layout of the panel (but the contents are not populated here). 284 */ 285 private void createLayout() 286 { 287 GridBagConstraints gbc = new GridBagConstraints(); 288 CardLayout cardLayout = new CardLayout(); 289 mainPanel = new JPanel(cardLayout); 290 mainPanel.setOpaque(false); 291 noEntryPanel.setMessage( 292 INFO_CTRL_PANEL_NO_SCHEMA_ITEM_SELECTED_LABEL.get()); 293 mainPanel.add(noEntryPanel, NOTHING_SELECTED); 294 StatusGenericPanel[] panelsWithScroll = 295 { 296 standardObjectClassPanel, 297 configurationObjectClassPanel, 298 standardAttributePanel, 299 configurationAttributePanel, 300 matchingRulePanel, 301 attributeSyntaxPanel 302 }; 303 StatusGenericPanel[] panelsWithNoScroll = 304 { 305 customObjectClassPanel, 306 customAttributePanel 307 }; 308 for (StatusGenericPanel panel : panelsWithScroll) 309 { 310 mainPanel.add(Utilities.createBorderLessScrollBar(panel), 311 panel.getTitle().toString()); 312 } 313 for (StatusGenericPanel panel : panelsWithNoScroll) 314 { 315 mainPanel.add(panel, panel.getTitle().toString()); 316 } 317 cardLayout.show(mainPanel, NOTHING_SELECTED); 318 gbc.gridx = 0; 319 gbc.gridy = 0; 320 gbc.weightx = 1.0; 321 gbc.weighty = 1.0; 322 gbc.fill = GridBagConstraints.BOTH; 323 add(mainPanel, gbc); 324 } 325 326 /** {@inheritDoc} */ 327 public void okClicked() 328 { 329 // No ok button 330 } 331 332 /** {@inheritDoc} */ 333 public GenericDialog.ButtonType getButtonType() 334 { 335 return GenericDialog.ButtonType.NO_BUTTON; 336 } 337 338 /** {@inheritDoc} */ 339 public LocalizableMessage getTitle() 340 { 341 return INFO_CTRL_PANEL_SCHEMA_BROWSER_RIGHT_PANEL_TITLE.get(); 342 } 343 344 /** {@inheritDoc} */ 345 public Component getPreferredFocusComponent() 346 { 347 return null; 348 } 349 350 /** {@inheritDoc} */ 351 public void configurationChanged(ConfigurationChangeEvent ev) 352 { 353 } 354 355 /** 356 * Method used to know if there are unsaved changes or not. It is used by 357 * the schema selection listener when the user changes the selection. 358 * @return <CODE>true</CODE> if there are unsaved changes (and so the 359 * selection of the schema should be canceled) and <CODE>false</CODE> 360 * otherwise. 361 */ 362 public boolean mustCheckUnsavedChanges() 363 { 364 return schemaElementPanel != null && schemaElementPanel.mustCheckUnsavedChanges(); 365 } 366 367 /** 368 * Tells whether the user chose to save the changes in the panel, to not save 369 * them or simply canceled the selection in the tree. 370 * @return the value telling whether the user chose to save the changes in the 371 * panel, to not save them or simply canceled the selection in the tree. 372 */ 373 public UnsavedChangesDialog.Result checkUnsavedChanges() 374 { 375 if (schemaElementPanel != null) 376 { 377 return schemaElementPanel.checkUnsavedChanges(); 378 } 379 return UnsavedChangesDialog.Result.DO_NOT_SAVE; 380 } 381}