BrowseSchemaPanel.java revision d25372dc8e65a9ed019a88fdf659ca61313f1b31
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* 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
* trunk/opends/resource/legal-notices/OpenDS.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 2008 Sun Microsystems, Inc.
*/
/**
* The pane that is displayed when the user clicks on 'Browse Schema'.
*
*/
public class BrowseSchemaPanel extends StatusGenericPanel
{
private static final long serialVersionUID = -6462914563743569830L;
private JComboBox filterAttribute;
private FilterTextField filter;
private JButton applyButton;
private JButton newAttribute;
private JButton newObjectClass;
private JLabel lNumberOfElements;
private SchemaBrowserRightPanel entryPane;
private TreePath lastEntryTreePath;
private Schema lastSchema;
private GenericDialog newAttributeDialog;
private GenericDialog newObjectClassDialog;
private JMenuItem deleteMenuItem;
private JPopupMenu popup;
private CommonSchemaElements lastCreatedElement;
private final Message REQUIRED_ATTRIBUTES =
private final Message OPTIONAL_ATTRIBUTES =
private CategoryTreeNode attributes =
private CategoryTreeNode objectClasses =
private CategoryTreeNode standardObjectClasses =
new CategoryTreeNode(
private CategoryTreeNode standardAttributes =
new CategoryTreeNode(
private CategoryTreeNode configurationObjectClasses =
new CategoryTreeNode(
private CategoryTreeNode configurationAttributes =
new CategoryTreeNode(
private CategoryTreeNode customObjectClasses =
new CategoryTreeNode(
private CategoryTreeNode customAttributes =
new CategoryTreeNode(
private CategoryTreeNode matchingRules =
private CategoryTreeNode syntaxes =
new CategoryTreeNode(
private CategoryTreeNode[] underRootNodes =
{
};
private CategoryTreeNode[] categoryNodes = {
};
private JLabel lNoMatchFound;
private boolean ignoreSelectionEvents;
private Message NO_SCHEMA_ITEM_SELECTED =
private Message CATEGORY_ITEM_SELECTED =
private Message MULTIPLE_ITEMS_SELECTED =
/**
* Default constructor.
*
*/
public BrowseSchemaPanel()
{
super();
createLayout();
}
/**
* {@inheritDoc}
*/
public boolean requiresBorder()
{
return false;
}
/**
* {@inheritDoc}
*/
public boolean requiresScroll()
{
return false;
}
/**
* {@inheritDoc}
*/
public boolean callConfigurationChangedInBackground()
{
return true;
}
/**
* {@inheritDoc}
*/
public void toBeDisplayed(boolean visible)
{
}
/**
* Creates the layout of the panel (but the contents are not populated here).
*/
private void createLayout()
{
newObjectClass.setOpaque(false);
{
/**
* {@inheritDoc}
*/
{
}
});
newAttribute.setOpaque(false);
{
/**
* {@inheritDoc}
*/
{
}
});
new DefaultComboBoxModel(new Message[]{
NAME,
TYPE,
filter = new FilterTextField();
{
/**
* {@inheritDoc}
*/
public void keyReleased(KeyEvent e)
{
{
}
}
});
{
/**
* {@inheritDoc}
*/
{
}
});
applyButton.setOpaque(false);
{
/**
* {@inheritDoc}
*/
{
}
});
// The button panel
}
private JPanel createButtonsPanel()
{
buttonsPanel.setOpaque(true);
closeButton.setOpaque(false);
{
/**
* {@inheritDoc}
*/
{
closeClicked();
}
});
return buttonsPanel;
}
/**
* {@inheritDoc}
*/
{
return INFO_CTRL_PANEL_MANAGE_SCHEMA_TITLE.get();
}
/**
* {@inheritDoc}
*/
public Component getPreferredFocusComponent()
{
return filter;
}
/**
* {@inheritDoc}
*/
public void closeClicked()
{
super.closeClicked();
}
/**
* {@inheritDoc}
*/
public void okClicked()
{
// No ok button
}
/**
* {@inheritDoc}
*/
{
}
private Component createSplitPane()
{
lNoMatchFound.setVisible(false);
entryPane = new SchemaBrowserRightPanel();
{
/**
* {@inheritDoc}
*/
{
}
});
{
/**
* {@inheritDoc}
*/
{
if (!ignoreSelectionEvents)
{
ignoreSelectionEvents = true;
if (entryPane.mustCheckUnsavedChanges())
{
ignoreSelectionEvents = true;
switch (entryPane.checkUnsavedChanges())
{
case DO_NOT_SAVE:
break;
case SAVE:
break;
case CANCEL:
ignoreSelectionEvents = false;
return;
}
{
}
else
{
}
}
boolean deletableElementsSelected = false;
boolean nonDeletableElementsSelected = false;
{
{
if (node instanceof CategoryTreeNode)
{
nonDeletableElementsSelected = true;
}
else if ((node instanceof CustomObjectClassTreeNode) ||
(node instanceof CustomAttributeTreeNode))
{
deletableElementsSelected = true;
}
else if (node instanceof SchemaElementTreeNode)
{
nonDeletableElementsSelected = true;
}
}
}
ignoreSelectionEvents = false;
}
}
});
{
}
tree.setRootVisible(false);
addPopupMenu();
return pane;
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
{
if ((lastSchema == null) ||
true)
{
if (lastSchema != null)
{
{
public void run()
{
}
});
}
else
{
{
errorPane.setVisible(true);
}
}
}
}
/**
* Selects the node in the tree that corresponds to a given schema element.
* @param root the node we must start searching for the node to be selected.
* @param element the schema element.
* @param model the tree model.
* @return <CODE>true</CODE> if the node was found and selected and
* <CODE>false</CODE> otherwise.
*/
{
boolean found = false;
for (int i=0; i<n && !found; i++)
{
if (node instanceof SchemaElementTreeNode)
{
{
found = true;
}
}
if (!found)
{
}
}
return found;
}
/**
* Repopulates the tree.
* @param tree the tree to be repopulated.
*/
{
if (lastSchema == null)
{
return;
}
ignoreSelectionEvents = true;
{
}
{
{
{
}
{
}
else
{
}
}
}
{
{
{
}
{
}
else
{
}
}
}
{
if (mustAdd(matchingRule))
{
}
}
{
{
{
}
}
}
int size = 0;
{
}
int i = 0;
int positionUnderRoot = 0;
boolean expand = filterProvided;
{
}
else if (!expand)
{
}
if (expand)
{
}
{
}
else if (!expand)
{
}
if (expand)
{
}
int positionUnderAttributes = 0;
int positionUnderObjectClass = 0;
{
{
{
}
}
else
{
expand = false;
|| (parent == configurationObjectClasses))
{
{
}
else
{
}
}
|| (parent == configurationAttributes))
{
{
}
else
{
}
}
else
{
{
}
else
{
}
}
{
if ((newSelectionPath == null) &&
{
if (lastCreatedElement != null)
{
if ((node instanceof CustomObjectClassTreeNode) &&
(lastCreatedElement instanceof ObjectClass))
{
{
}
}
else if ((node instanceof CustomAttributeTreeNode) &&
(lastCreatedElement instanceof AttributeType))
{
{
}
}
}
{
}
}
}
if (expand || filterProvided)
{
}
}
i++;
}
{
{
{
}
}
}
if (newSelectionPath != null)
{
}
{
}
{
tree.expandPath(p);
}
ignoreSelectionEvents = false;
if (nElements > 0)
{
lNumberOfElements.setVisible(true);
}
else
{
lNumberOfElements.setVisible(false);
}
{
{
if (!(node instanceof CategoryTreeNode))
{
break;
}
}
}
repaint();
}
/**
* Updates the right entry panel.
*
*/
private void updateEntryPane()
{
{
}
{
if (node instanceof StandardObjectClassTreeNode)
{
}
else if (node instanceof ConfigurationObjectClassTreeNode)
{
}
else if (node instanceof CustomObjectClassTreeNode)
{
}
else if (node instanceof StandardAttributeTreeNode)
{
}
else if (node instanceof ConfigurationAttributeTreeNode)
{
}
else if (node instanceof CustomAttributeTreeNode)
{
}
else if (node instanceof MatchingRuleTreeNode)
{
}
else if (node instanceof AttributeSyntaxTreeNode)
{
}
else
{
}
}
else
{
{
boolean categorySelected = false;
int nNonCategory = 0;
{
if (node instanceof CategoryTreeNode)
{
categorySelected = true;
}
else
{
nNonCategory ++;
}
}
if (nNonCategory == 0)
{
}
else if (categorySelected)
{
}
else
{
}
}
else
{
}
}
}
/**
* Adds a popup menu.
*
*/
private void addPopupMenu()
{
popup = new JPopupMenu();
{
/**
* {@inheritDoc}
*/
{
}
});
{
/**
* {@inheritDoc}
*/
{
}
});
{
/**
* {@inheritDoc}
*/
{
}
});
deleteMenuItem.setEnabled(false);
}
private void deleteClicked()
{
{
{
if (node instanceof CustomObjectClassTreeNode)
{
}
else if (node instanceof CustomAttributeTreeNode)
{
}
}
}
{
// Analyze objectClasses
{
{
{
childClasses.add(o);
}
}
if (!childClasses.isEmpty())
{
{
}
}
}
// Analyze attributes
{
new ArrayList<AttributeType>();
{
{
}
}
if (!childAttributes.isEmpty())
{
{
}
}
{
{
}
}
if (!dependentClasses.isEmpty())
{
attrName));
}
}
}
else
{
}
{
// Reorder objectClasses and attributes to delete them in the proper
// order.
new ArrayList<ObjectClass>();
{
int index = -1;
{
{
{
index = i+1;
}
else
{
}
}
}
if (index == -1)
{
}
else
{
}
}
new ArrayList<AttributeType>();
{
int index = -1;
{
{
{
index = i+1;
}
else
{
}
}
}
if (index == -1)
{
}
else
{
}
}
if (orderedAttributes.isEmpty())
{
}
else if (orderedObjectClasses.isEmpty())
{
}
else
{
}
{
}
{
{
null,
dlg);
dlg.setVisible(true);
}
}
}
{
}
}
/**
* Checks whether a given attribute type must be added or not. Method used to
* do the filtering based on the name.
* @param attr the attribute type.
* @param attrName the name provided by the user.
* @return <CODE>true</CODE> if the attribute must be added and
* <CODE>false</CODE> otherwise.
*/
{
{
}
{
}
}
/**
* Checks whether a given object class must be added or not. Method used to
* do the filtering based on the name.
* @param oc the object class.
* @param ocName the name provided by the user.
* @return <CODE>true</CODE> if the objectclass must be added and
* <CODE>false</CODE> otherwise.
*/
{
{
}
{
}
}
/**
* Check whether the provided attribute must be added or not.
* @param attr the attribute.
* @return <CODE>true</CODE> if the attribute must be added and
* <CODE>false</CODE> otherwise.
*/
{
boolean mustAdd = true;
if (f.length () > 0)
{
{
}
{
{
}
}
else
{
mustAdd = false;
}
}
return mustAdd;
}
/**
* Check whether the provided object class must be added or not.
* @param oc the objectclass.
* @return <CODE>true</CODE> if the objectclass must be added and
* <CODE>false</CODE> otherwise.
*/
{
boolean mustAdd = true;
if (f.length () > 0)
{
{
}
{
{
}
}
{
{
}
else
{
}
{
mustAdd = false;
{
if (mustAdd)
{
break;
}
}
if (!mustAdd)
{
break;
}
}
}
{
mustAdd = false;
{
boolean isChild = false;
{
}
if (isChild)
{
mustAdd = mustAddObjectClassName(o, f);
if (mustAdd)
{
break;
}
}
}
}
{
mustAdd = false;
{
}
}
else
{
mustAdd = false;
}
}
return mustAdd;
}
/**
* Check whether the provided matching rule must be added or not.
* @param matchingRule the matching rule.
* @return <CODE>true</CODE> if the matching rule must be added and
* <CODE>false</CODE> otherwise.
*/
{
boolean mustAdd = true;
if (f.length () > 0)
{
{
{
}
}
{
{
}
}
else
{
mustAdd = false;
}
}
return mustAdd;
}
/**
* Check whether the provided attribute syntax must be added or not.
* @param syntax the attribute syntax.
* @return <CODE>true</CODE> if the attribute syntax must be added and
* <CODE>false</CODE> otherwise.
*/
{
boolean mustAdd = true;
if (f.length () > 0)
{
{
{
}
}
else
{
mustAdd = false;
}
}
return mustAdd;
}
boolean exact)
{
boolean matchFilter = false;
{
if (exact)
{
}
else
{
}
if (matchFilter)
{
break;
}
}
return matchFilter;
}
{
}
private void newAttributeClicked()
{
if (newAttributeDialog == null)
{
Utilities.getParentDialog(this));
Utilities.getParentDialog(this));
{
{
if (o instanceof CommonSchemaElements)
{
}
}
});
}
newAttributeDialog.setVisible(true);
}
private void newObjectClassClicked()
{
if (newObjectClassDialog == null)
{
Utilities.getParentDialog(this));
Utilities.getParentDialog(this));
{
{
if (o instanceof CommonSchemaElements)
{
}
}
});
}
newObjectClassDialog.setVisible(true);
}
{
"ds-folder.png",
"ds-folder.png", "ds-folder.png", "ds-folder.png", "ds-folder.png",
"ds-folder.png", "ds-rule-folder.png", "ds-syntax-folder.png"};
{
}
StandardAttributeTreeNode.class, CustomAttributeTreeNode.class,
StandardObjectClassTreeNode.class, CustomObjectClassTreeNode.class,
MatchingRuleTreeNode.class, AttributeSyntaxTreeNode.class};
"ds-class.png", "ds-class.png", "ds-class.png", "ds-rule.png",
"ds-syntax.png"};
{
}
};
/**
* Specific class used to render the nodes in the tree. It uses specific
* icons for the nodes.
*
*/
protected class SchemaTreeCellRenderer extends TreeCellRenderer
{
private static final long serialVersionUID = -3390568254259441766L;
/**
* {@inheritDoc}
*/
boolean hasFocus)
{
return this;
}
{
{
}
return icon;
}
}
}