| | |
| | | import java.util.Comparator; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.TreeSet; |
| | | |
| | |
| | | import org.opends.server.types.ObjectClass; |
| | | import org.opends.server.types.Schema; |
| | | |
| | | /** |
| | | * The pane that is displayed when the user clicks on 'Browse Schema'. |
| | | */ |
| | | public class BrowseSchemaPanel extends StatusGenericPanel |
| | | /** The pane that is displayed when the user clicks on 'Browse Schema'. */ |
| | | class BrowseSchemaPanel extends StatusGenericPanel |
| | | { |
| | | private static final long serialVersionUID = -6462914563743569830L; |
| | | |
| | | private static final LocalizableMessage FILTER_NAME = INFO_CTRL_PANEL_SCHEMA_ELEMENT_NAME.get(); |
| | | private static final LocalizableMessage FILTER_TYPE = INFO_CTRL_PANEL_SCHEMA_ELEMENT_TYPE.get(); |
| | | private static final LocalizableMessage FILTER_PARENT_CLASS = INFO_CTRL_PANEL_PARENT_CLASS.get(); |
| | | private static final LocalizableMessage FILTER_CHILD_CLASS = INFO_CTRL_PANEL_CHILD_CLASS.get(); |
| | | private static final LocalizableMessage FILTER_REQUIRED_ATTRIBUTES = INFO_CTRL_PANEL_REQUIRED_ATTRIBUTES.get(); |
| | | private static final LocalizableMessage FILTER_OPTIONAL_ATTRIBUTES = INFO_CTRL_PANEL_OPTIONAL_ATTRIBUTES.get(); |
| | | private static final LocalizableMessage NO_SCHEMA_ITEM_SELECTED = INFO_CTRL_PANEL_NO_SCHEMA_ITEM_SELECTED.get(); |
| | | |
| | | private JComboBox<LocalizableMessage> filterAttribute; |
| | | private FilterTextField filter; |
| | | private JButton applyButton; |
| | |
| | | |
| | | private CommonSchemaElements lastCreatedElement; |
| | | |
| | | private final LocalizableMessage NAME = INFO_CTRL_PANEL_SCHEMA_ELEMENT_NAME.get(); |
| | | private final LocalizableMessage TYPE = INFO_CTRL_PANEL_SCHEMA_ELEMENT_TYPE.get(); |
| | | private final LocalizableMessage PARENT_CLASS = INFO_CTRL_PANEL_PARENT_CLASS.get(); |
| | | private final LocalizableMessage CHILD_CLASS = INFO_CTRL_PANEL_CHILD_CLASS.get(); |
| | | private final LocalizableMessage REQUIRED_ATTRIBUTES = |
| | | INFO_CTRL_PANEL_REQUIRED_ATTRIBUTES.get(); |
| | | private final LocalizableMessage OPTIONAL_ATTRIBUTES = |
| | | INFO_CTRL_PANEL_OPTIONAL_ATTRIBUTES.get(); |
| | | |
| | | private CategoryTreeNode attributes = |
| | | new CategoryTreeNode(INFO_CTRL_PANEL_ATTRIBUTES_CATEGORY_NODE.get()); |
| | | private CategoryTreeNode objectClasses = |
| | | private final CategoryTreeNode attributes = new CategoryTreeNode(INFO_CTRL_PANEL_ATTRIBUTES_CATEGORY_NODE.get()); |
| | | private final CategoryTreeNode objectClasses = |
| | | new CategoryTreeNode(INFO_CTRL_PANEL_OBJECTCLASSES_CATEGORY_NODE.get()); |
| | | private CategoryTreeNode standardObjectClasses = |
| | | new CategoryTreeNode( |
| | | INFO_CTRL_PANEL_STANDARD_OBJECTCLASSES_CATEGORY_NODE.get()); |
| | | private CategoryTreeNode standardAttributes = |
| | | new CategoryTreeNode( |
| | | INFO_CTRL_PANEL_STANDARD_ATTRIBUTES_CATEGORY_NODE.get()); |
| | | private CategoryTreeNode configurationObjectClasses = |
| | | new CategoryTreeNode( |
| | | INFO_CTRL_PANEL_CONFIGURATION_OBJECTCLASSES_CATEGORY_NODE.get()); |
| | | private CategoryTreeNode configurationAttributes = |
| | | new CategoryTreeNode( |
| | | INFO_CTRL_PANEL_CONFIGURATION_ATTRIBUTES_CATEGORY_NODE.get()); |
| | | private CategoryTreeNode customObjectClasses = |
| | | new CategoryTreeNode( |
| | | INFO_CTRL_PANEL_CUSTOM_OBJECTCLASSES_CATEGORY_NODE.get()); |
| | | private CategoryTreeNode customAttributes = |
| | | new CategoryTreeNode( |
| | | INFO_CTRL_PANEL_CUSTOM_ATTRIBUTES_CATEGORY_NODE.get()); |
| | | private CategoryTreeNode matchingRules = |
| | | private final CategoryTreeNode standardObjectClasses = |
| | | new CategoryTreeNode(INFO_CTRL_PANEL_STANDARD_OBJECTCLASSES_CATEGORY_NODE.get()); |
| | | private final CategoryTreeNode standardAttributes = |
| | | new CategoryTreeNode(INFO_CTRL_PANEL_STANDARD_ATTRIBUTES_CATEGORY_NODE.get()); |
| | | private final CategoryTreeNode configurationObjectClasses = |
| | | new CategoryTreeNode(INFO_CTRL_PANEL_CONFIGURATION_OBJECTCLASSES_CATEGORY_NODE.get()); |
| | | private final CategoryTreeNode configurationAttributes = |
| | | new CategoryTreeNode(INFO_CTRL_PANEL_CONFIGURATION_ATTRIBUTES_CATEGORY_NODE.get()); |
| | | private final CategoryTreeNode customObjectClasses = |
| | | new CategoryTreeNode(INFO_CTRL_PANEL_CUSTOM_OBJECTCLASSES_CATEGORY_NODE.get()); |
| | | private final CategoryTreeNode customAttributes = |
| | | new CategoryTreeNode(INFO_CTRL_PANEL_CUSTOM_ATTRIBUTES_CATEGORY_NODE.get()); |
| | | private final CategoryTreeNode matchingRules = |
| | | new CategoryTreeNode(INFO_CTRL_PANEL_MATCHING_RULES_CATEGORY_NODE.get()); |
| | | private CategoryTreeNode syntaxes = |
| | | new CategoryTreeNode( |
| | | INFO_CTRL_PANEL_ATTRIBUTE_SYNTAXES_CATEGORY_NODE.get()); |
| | | |
| | | private CategoryTreeNode[] underRootNodes = |
| | | { |
| | | objectClasses, attributes, matchingRules, syntaxes |
| | | }; |
| | | |
| | | private CategoryTreeNode[] categoryNodes = { |
| | | standardObjectClasses, standardAttributes, customObjectClasses, |
| | | customAttributes, configurationObjectClasses, |
| | | configurationAttributes, matchingRules, syntaxes |
| | | }; |
| | | private final CategoryTreeNode syntaxes = |
| | | new CategoryTreeNode(INFO_CTRL_PANEL_ATTRIBUTE_SYNTAXES_CATEGORY_NODE.get()); |
| | | private final CategoryTreeNode[] underRootNodes = { objectClasses, attributes, matchingRules, syntaxes }; |
| | | private final CategoryTreeNode[] categoryNodes = { standardObjectClasses, standardAttributes, customObjectClasses, |
| | | customAttributes, configurationObjectClasses, configurationAttributes, matchingRules, syntaxes }; |
| | | |
| | | private JLabel lNoMatchFound; |
| | | |
| | | private boolean ignoreSelectionEvents; |
| | | |
| | | private LocalizableMessage NO_SCHEMA_ITEM_SELECTED = |
| | | INFO_CTRL_PANEL_NO_SCHEMA_ITEM_SELECTED.get(); |
| | | private LocalizableMessage CATEGORY_ITEM_SELECTED = |
| | | INFO_CTRL_PANEL_CATEGORY_ITEM_SELECTED.get(); |
| | | private LocalizableMessage MULTIPLE_ITEMS_SELECTED = |
| | | INFO_CTRL_PANEL_MULTIPLE_SCHEMA_ITEMS_SELECTED.get(); |
| | | |
| | | /** |
| | | * Default constructor. |
| | | * |
| | | */ |
| | | public BrowseSchemaPanel() |
| | | { |
| | | super(); |
| | | createLayout(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean requiresBorder() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean requiresScroll() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean callConfigurationChangedInBackground() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void toBeDisplayed(boolean visible) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Creates the layout of the panel (but the contents are not populated here). |
| | | */ |
| | | /** Creates the layout of the panel (but the contents are not populated here). */ |
| | | @SuppressWarnings("unchecked") |
| | | private void createLayout() |
| | | { |
| | | setBackground(ColorAndFontConstants.greyBackground); |
| | |
| | | gbc.fill = GridBagConstraints.HORIZONTAL; |
| | | gbc.insets = new Insets(10, 10, 0, 0); |
| | | |
| | | newObjectClass = Utilities.createButton( |
| | | INFO_CTRL_PANEL_NEW_OBJECTCLASS_BUTTON.get()); |
| | | newObjectClass = Utilities.createButton(INFO_CTRL_PANEL_NEW_OBJECTCLASS_BUTTON.get()); |
| | | newObjectClass.setOpaque(false); |
| | | gbc.weightx = 0.0; |
| | | add(newObjectClass, gbc); |
| | | newObjectClass.addActionListener(new ActionListener() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void actionPerformed(ActionEvent ev) |
| | | { |
| | |
| | | } |
| | | }); |
| | | |
| | | newAttribute = Utilities.createButton( |
| | | INFO_CTRL_PANEL_NEW_ATTRIBUTE_BUTTON.get()); |
| | | newAttribute = Utilities.createButton(INFO_CTRL_PANEL_NEW_ATTRIBUTE_BUTTON.get()); |
| | | newAttribute.setOpaque(false); |
| | | gbc.gridx ++; |
| | | gbc.weightx = 0.0; |
| | |
| | | add(newAttribute, gbc); |
| | | newAttribute.addActionListener(new ActionListener() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void actionPerformed(ActionEvent ev) |
| | | { |
| | |
| | | filterAttribute = Utilities.createComboBox(); |
| | | filterAttribute.setModel( |
| | | new DefaultComboBoxModel<>(new LocalizableMessage[]{ |
| | | NAME, |
| | | TYPE, |
| | | PARENT_CLASS, |
| | | CHILD_CLASS, |
| | | REQUIRED_ATTRIBUTES, |
| | | OPTIONAL_ATTRIBUTES})); |
| | | FILTER_NAME, |
| | | FILTER_TYPE, |
| | | FILTER_PARENT_CLASS, |
| | | FILTER_CHILD_CLASS, |
| | | FILTER_REQUIRED_ATTRIBUTES, |
| | | FILTER_OPTIONAL_ATTRIBUTES})); |
| | | filterAttribute.setRenderer(new CustomListCellRenderer(filterAttribute)); |
| | | gbc.insets.left = 5; |
| | | gbc.gridx ++; |
| | |
| | | filter = new FilterTextField(); |
| | | filter.addKeyListener(new KeyAdapter() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void keyReleased(KeyEvent e) |
| | | { |
| | | if (e.getKeyCode() == KeyEvent.VK_ENTER |
| | | && applyButton.isEnabled()) |
| | | if (e.getKeyCode() == KeyEvent.VK_ENTER && applyButton.isEnabled()) |
| | | { |
| | | filter.displayRefreshIcon(FilterTextField.DEFAULT_REFRESH_ICON_TIME); |
| | | repopulateTree(treePane.getTree(), false); |
| | |
| | | }); |
| | | filter.addActionListener(new ActionListener() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void actionPerformed(ActionEvent ev) |
| | | { |
| | |
| | | gbc.weightx = 1.0; |
| | | add(filter, gbc); |
| | | |
| | | applyButton = |
| | | Utilities.createButton(INFO_CTRL_PANEL_APPLY_BUTTON_LABEL.get()); |
| | | applyButton = Utilities.createButton(INFO_CTRL_PANEL_APPLY_BUTTON_LABEL.get()); |
| | | applyButton.setOpaque(false); |
| | | gbc.gridx ++; |
| | | gbc.weightx = 0.0; |
| | |
| | | add(applyButton, gbc); |
| | | applyButton.addActionListener(new ActionListener() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void actionPerformed(ActionEvent ev) |
| | | { |
| | |
| | | gbc.insets.right = 10; |
| | | gbc.gridx ++; |
| | | gbc.weightx = 0.0; |
| | | JButton closeButton = |
| | | Utilities.createButton(INFO_CTRL_PANEL_CLOSE_BUTTON_LABEL.get()); |
| | | JButton closeButton = Utilities.createButton(INFO_CTRL_PANEL_CLOSE_BUTTON_LABEL.get()); |
| | | closeButton.setOpaque(false); |
| | | buttonsPanel.add(closeButton, gbc); |
| | | closeButton.addActionListener(new ActionListener() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void actionPerformed(ActionEvent ev) |
| | | { |
| | |
| | | } |
| | | }); |
| | | |
| | | buttonsPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, |
| | | ColorAndFontConstants.defaultBorderColor)); |
| | | buttonsPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, ColorAndFontConstants.defaultBorderColor)); |
| | | |
| | | return buttonsPanel; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public LocalizableMessage getTitle() |
| | | { |
| | | return INFO_CTRL_PANEL_MANAGE_SCHEMA_TITLE.get(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Component getPreferredFocusComponent() |
| | | { |
| | | return filter; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void closeClicked() |
| | | { |
| | |
| | | super.closeClicked(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void okClicked() |
| | | { |
| | | // No ok button |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public GenericDialog.ButtonType getButtonType() |
| | | { |
| | |
| | | { |
| | | treePane = new TreePanel(); |
| | | |
| | | lNoMatchFound =Utilities.createDefaultLabel( |
| | | INFO_CTRL_PANEL_NO_MATCHES_FOUND_LABEL.get()); |
| | | lNoMatchFound = Utilities.createDefaultLabel(INFO_CTRL_PANEL_NO_MATCHES_FOUND_LABEL.get()); |
| | | lNoMatchFound.setVisible(false); |
| | | |
| | | entryPane = new SchemaBrowserRightPanel(); |
| | |
| | | p.add(lNoMatchFound, gbc); |
| | | treeScroll = Utilities.createScrollPane(p); |
| | | |
| | | entryPane.addSchemaElementSelectionListener( |
| | | new SchemaElementSelectionListener() |
| | | entryPane.addSchemaElementSelectionListener(new SchemaElementSelectionListener() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void schemaElementSelected(SchemaElementSelectionEvent ev) |
| | | { |
| | | Object element = ev.getSchemaElement(); |
| | | DefaultTreeModel model = |
| | | (DefaultTreeModel)treePane.getTree().getModel(); |
| | | DefaultTreeModel model = (DefaultTreeModel) treePane.getTree().getModel(); |
| | | Object root = model.getRoot(); |
| | | selectElementUnder(root, element, model); |
| | | } |
| | | }); |
| | | entryPane.addConfigurationElementCreatedListener( |
| | | new ConfigurationElementCreatedListener() |
| | | entryPane.addConfigurationElementCreatedListener(new ConfigurationElementCreatedListener() |
| | | { |
| | | @Override |
| | | public void elementCreated(ConfigurationElementCreatedEvent ev) |
| | |
| | | |
| | | treePane.getTree().addTreeSelectionListener(new TreeSelectionListener() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void valueChanged(TreeSelectionEvent ev) |
| | | { |
| | | if (!ignoreSelectionEvents) |
| | | { |
| | | ignoreSelectionEvents = true; |
| | | TreePath[] paths = treePane.getTree().getSelectionPaths(); |
| | | final JTree tree = treePane.getTree(); |
| | | TreePath[] paths = tree.getSelectionPaths(); |
| | | |
| | | if (entryPane.mustCheckUnsavedChanges()) |
| | | { |
| | | ignoreSelectionEvents = true; |
| | | treePane.getTree().setSelectionPath(lastEntryTreePath); |
| | | tree.setSelectionPath(lastEntryTreePath); |
| | | switch (entryPane.checkUnsavedChanges()) |
| | | { |
| | | case DO_NOT_SAVE: |
| | | break; |
| | | case SAVE: |
| | | break; |
| | | case CANCEL: |
| | |
| | | } |
| | | if (paths != null) |
| | | { |
| | | treePane.getTree().setSelectionPaths(paths); |
| | | tree.setSelectionPaths(paths); |
| | | } |
| | | else |
| | | { |
| | | treePane.getTree().clearSelection(); |
| | | tree.clearSelection(); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | nonDeletableElementsSelected = true; |
| | | } |
| | | else if (node instanceof CustomObjectClassTreeNode |
| | | || node instanceof CustomAttributeTreeNode) |
| | | else if (node instanceof CustomObjectClassTreeNode || node instanceof CustomAttributeTreeNode) |
| | | { |
| | | deletableElementsSelected = true; |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | deleteMenuItem.setEnabled(deletableElementsSelected && |
| | | !nonDeletableElementsSelected); |
| | | deleteMenuItem.setEnabled(deletableElementsSelected && !nonDeletableElementsSelected); |
| | | updateEntryPane(); |
| | | ignoreSelectionEvents = false; |
| | | } |
| | |
| | | tree.expandPath(new TreePath(root)); |
| | | tree.setCellRenderer(new SchemaTreeCellRenderer()); |
| | | addPopupMenu(); |
| | | treeScroll.setPreferredSize( |
| | | new Dimension((3 * treeScroll.getPreferredSize().width) / 2, |
| | | 5 * treeScroll.getPreferredSize().height)); |
| | | treeScroll.setPreferredSize(new Dimension( |
| | | (3 * treeScroll.getPreferredSize().width) / 2, 5 * treeScroll.getPreferredSize().height)); |
| | | entryPane.displayMessage(NO_SCHEMA_ITEM_SELECTED); |
| | | entryPane.setBorder(getRightPanelBorder()); |
| | | entryPane.setPreferredSize( |
| | | new Dimension(treeScroll.getPreferredSize().width, |
| | | treeScroll.getPreferredSize().height)); |
| | | entryPane.setPreferredSize(new Dimension( |
| | | treeScroll.getPreferredSize().width, treeScroll.getPreferredSize().height)); |
| | | JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
| | | pane.setOpaque(true); //content panes must be opaque |
| | | pane.setLeftComponent(treeScroll); |
| | |
| | | return pane; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void setInfo(ControlPanelInfo info) |
| | | { |
| | |
| | | entryPane.setInfo(info); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void configurationChanged(ConfigurationChangeEvent ev) |
| | | { |
| | |
| | | } |
| | | else if (lastSchema == null) |
| | | { |
| | | updateErrorPane(errorPane, |
| | | ERR_CTRL_PANEL_SCHEMA_NOT_FOUND_SUMMARY.get(), |
| | | ColorAndFontConstants.errorTitleFont, |
| | | ERR_CTRL_PANEL_SCHEMA_NOT_FOUND_DETAILS.get(), |
| | | ColorAndFontConstants.defaultFont); |
| | | updateErrorPane(errorPane, ERR_CTRL_PANEL_SCHEMA_NOT_FOUND_SUMMARY.get(), ColorAndFontConstants.errorTitleFont, |
| | | ERR_CTRL_PANEL_SCHEMA_NOT_FOUND_DETAILS.get(), ColorAndFontConstants.defaultFont); |
| | | if (!errorPane.isVisible()) |
| | | { |
| | | 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. |
| | | * |
| | | * @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. |
| | | */ |
| | | private boolean selectElementUnder(Object root, Object element, |
| | | DefaultTreeModel model) |
| | | private boolean selectElementUnder(Object root, Object element, DefaultTreeModel model) |
| | | { |
| | | int n = model.getChildCount(root); |
| | | boolean found = false; |
| | |
| | | |
| | | /** |
| | | * Repopulates the tree. |
| | | * @param tree the tree to be repopulated. |
| | | * @param forceScroll whether the scroll must be reset or not. |
| | | * |
| | | * @param tree |
| | | * the tree to be repopulated. |
| | | * @param forceScroll |
| | | * whether the scroll must be reset or not. |
| | | */ |
| | | private void repopulateTree(JTree tree, final boolean forceScroll) |
| | | { |
| | |
| | | ignoreSelectionEvents = true; |
| | | |
| | | final Point currentPosition = treeScroll.getViewport().getViewPosition(); |
| | | |
| | | DefaultMutableTreeNode root = getRoot(tree); |
| | | |
| | | TreePath path = tree.getSelectionPath(); |
| | | DefaultMutableTreeNode lastSelectedNode = null; |
| | | if (path != null) |
| | |
| | | TreePath newSelectionPath = null; |
| | | |
| | | Comparator<String> lowerCaseComparator = new LowerCaseComparator(); |
| | | |
| | | TreeSet<String> standardOcNames = new TreeSet<>(lowerCaseComparator); |
| | | HashMap<String, StandardObjectClassTreeNode> hmStandardOcs = new HashMap<>(); |
| | | TreeSet<String> configurationOcNames = new TreeSet<>(lowerCaseComparator); |
| | | HashMap<String, ConfigurationObjectClassTreeNode> hmConfigurationOcs = new HashMap<>(); |
| | | TreeSet<String> customOcNames = new TreeSet<>(lowerCaseComparator); |
| | | HashMap<String, CustomObjectClassTreeNode> hmCustomOcs = new HashMap<>(); |
| | | Set<String> standardOcNames = new TreeSet<>(lowerCaseComparator); |
| | | Map<String, StandardObjectClassTreeNode> hmStandardOcs = new HashMap<>(); |
| | | Set<String> configurationOcNames = new TreeSet<>(lowerCaseComparator); |
| | | Map<String, ConfigurationObjectClassTreeNode> hmConfigurationOcs = new HashMap<>(); |
| | | Set<String> customOcNames = new TreeSet<>(lowerCaseComparator); |
| | | Map<String, CustomObjectClassTreeNode> hmCustomOcs = new HashMap<>(); |
| | | for (ObjectClass oc : lastSchema.getObjectClasses().values()) |
| | | { |
| | | if (mustAdd(oc)) |
| | |
| | | else if (Utilities.isConfiguration(oc)) |
| | | { |
| | | configurationOcNames.add(name); |
| | | hmConfigurationOcs.put(name, |
| | | new ConfigurationObjectClassTreeNode(name, oc)); |
| | | hmConfigurationOcs.put(name, new ConfigurationObjectClassTreeNode(name, oc)); |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | TreeSet<String> standardAttrNames = new TreeSet<>(lowerCaseComparator); |
| | | HashMap<String, StandardAttributeTreeNode> hmStandardAttrs = new HashMap<>(); |
| | | TreeSet<String> configurationAttrNames = new TreeSet<>(lowerCaseComparator); |
| | | HashMap<String, ConfigurationAttributeTreeNode> hmConfigurationAttrs = new HashMap<>(); |
| | | TreeSet<String> customAttrNames = new TreeSet<>(lowerCaseComparator); |
| | | HashMap<String, CustomAttributeTreeNode> hmCustomAttrs = new HashMap<>(); |
| | | Set<String> standardAttrNames = new TreeSet<>(lowerCaseComparator); |
| | | Map<String, StandardAttributeTreeNode> hmStandardAttrs = new HashMap<>(); |
| | | Set<String> configurationAttrNames = new TreeSet<>(lowerCaseComparator); |
| | | Map<String, ConfigurationAttributeTreeNode> hmConfigurationAttrs = new HashMap<>(); |
| | | Set<String> customAttrNames = new TreeSet<>(lowerCaseComparator); |
| | | Map<String, CustomAttributeTreeNode> hmCustomAttrs = new HashMap<>(); |
| | | for (AttributeType attr : lastSchema.getAttributeTypes().values()) |
| | | { |
| | | if (mustAdd(attr)) |
| | |
| | | else if (Utilities.isConfiguration(attr)) |
| | | { |
| | | configurationAttrNames.add(name); |
| | | hmConfigurationAttrs.put(name, |
| | | new ConfigurationAttributeTreeNode(name, attr)); |
| | | hmConfigurationAttrs.put(name, new ConfigurationAttributeTreeNode(name, attr)); |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | TreeSet<String> matchingRuleNames = new TreeSet<>(lowerCaseComparator); |
| | | HashMap<String, MatchingRuleTreeNode> hmMatchingRules = new HashMap<>(); |
| | | Set<String> matchingRuleNames = new TreeSet<>(lowerCaseComparator); |
| | | Map<String, MatchingRuleTreeNode> hmMatchingRules = new HashMap<>(); |
| | | for (MatchingRule matchingRule : lastSchema.getMatchingRules().values()) |
| | | { |
| | | if (mustAdd(matchingRule)) |
| | |
| | | } |
| | | } |
| | | |
| | | TreeSet<String> syntaxNames = new TreeSet<>(lowerCaseComparator); |
| | | HashMap<String, AttributeSyntaxTreeNode> hmSyntaxes = new HashMap<>(); |
| | | Set<String> syntaxNames = new TreeSet<>(lowerCaseComparator); |
| | | Map<String, AttributeSyntaxTreeNode> hmSyntaxes = new HashMap<>(); |
| | | for (Syntax syntax : lastSchema.getSyntaxes().values()) |
| | | { |
| | | if (mustAdd(syntax)) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | ArrayList<TreeSet<String>> names = new ArrayList<>(); |
| | | List<Set<String>> names = new ArrayList<>(); |
| | | names.add(standardOcNames); |
| | | names.add(standardAttrNames); |
| | | names.add(customOcNames); |
| | |
| | | names.add(matchingRuleNames); |
| | | names.add(syntaxNames); |
| | | |
| | | ArrayList<HashMap<String, ? extends DefaultMutableTreeNode>> nodes = new ArrayList<>(); |
| | | List<Map<String, ? extends DefaultMutableTreeNode>> nodes = new ArrayList<>(); |
| | | nodes.add(hmStandardOcs); |
| | | nodes.add(hmStandardAttrs); |
| | | nodes.add(hmCustomOcs); |
| | |
| | | nodes.add(hmSyntaxes); |
| | | |
| | | DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); |
| | | |
| | | String f = filter.getText().trim(); |
| | | boolean filterProvided = f.length() > 0; |
| | | |
| | |
| | | else |
| | | { |
| | | expand = false; |
| | | if (parent == standardObjectClasses |
| | | || parent == customObjectClasses |
| | | || parent == configurationObjectClasses) |
| | | if (parent == standardObjectClasses || parent == customObjectClasses || parent == configurationObjectClasses) |
| | | { |
| | | if (objectClasses.getIndex(parent) == -1) |
| | | { |
| | | model.insertNodeInto(parent, objectClasses, |
| | | positionUnderObjectClass); |
| | | model.insertNodeInto(parent, objectClasses, positionUnderObjectClass); |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | positionUnderObjectClass ++; |
| | | } |
| | | else if (parent == standardAttributes |
| | | || parent == customAttributes |
| | | || parent == configurationAttributes) |
| | | else if (parent == standardAttributes || parent == customAttributes || parent == configurationAttributes) |
| | | { |
| | | if (attributes.getIndex(parent) == -1) |
| | | { |
| | |
| | | { |
| | | DefaultMutableTreeNode node = nodes.get(i).get(name); |
| | | parent.add(node); |
| | | if (newSelectionPath == null |
| | | && (lastSelectedNode != null || lastCreatedElement != null)) |
| | | if (newSelectionPath == null && (lastSelectedNode != null || lastCreatedElement != null)) |
| | | { |
| | | if (lastCreatedElement != null) |
| | | { |
| | | if (node instanceof CustomObjectClassTreeNode |
| | | && lastCreatedElement instanceof ObjectClass) |
| | | if (node instanceof CustomObjectClassTreeNode && lastCreatedElement instanceof ObjectClass) |
| | | { |
| | | if (name.equals(lastCreatedElement.getNameOrOID())) |
| | | { |
| | |
| | | lastCreatedElement = null; |
| | | } |
| | | } |
| | | else if (node instanceof CustomAttributeTreeNode |
| | | && lastCreatedElement instanceof AttributeType |
| | | else if (node instanceof CustomAttributeTreeNode && lastCreatedElement instanceof AttributeType |
| | | && name.equals(lastCreatedElement.getNameOrOID())) |
| | | { |
| | | newSelectionPath = new TreePath(node.getPath()); |
| | |
| | | } |
| | | updateEntryPane(); |
| | | ignoreSelectionEvents = false; |
| | | int nElements = hmStandardOcs.size() + hmConfigurationOcs.size() + |
| | | hmCustomOcs.size() + hmStandardAttrs.size() + hmConfigurationAttrs.size() + |
| | | hmCustomAttrs.size() + hmMatchingRules.size() + hmSyntaxes.size(); |
| | | int nElements = |
| | | hmStandardOcs.size() + hmConfigurationOcs.size() + hmCustomOcs.size() + hmStandardAttrs.size() |
| | | + hmConfigurationAttrs.size() + hmCustomAttrs.size() + hmMatchingRules.size() + hmSyntaxes.size(); |
| | | lNoMatchFound.setVisible(nElements == 0); |
| | | treePane.setVisible(nElements > 0); |
| | | if (nElements > 0) |
| | | { |
| | | lNumberOfElements.setText( |
| | | INFO_CTRL_PANEL_SCHEMA_ELEMENT_NUMBER.get(nElements).toString()); |
| | | lNumberOfElements.setText(INFO_CTRL_PANEL_SCHEMA_ELEMENT_NUMBER.get(nElements).toString()); |
| | | lNumberOfElements.setVisible(true); |
| | | } |
| | | else |
| | |
| | | @Override |
| | | public void run() |
| | | { |
| | | if (forceScroll) |
| | | { |
| | | treeScroll.getViewport().setViewPosition(new Point(0, 0)); |
| | | } |
| | | else |
| | | { |
| | | treeScroll.getViewport().setViewPosition(currentPosition); |
| | | } |
| | | treeScroll.getViewport().setViewPosition(forceScroll ? new Point(0, 0) : currentPosition); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * Updates the right entry panel. |
| | | * |
| | | */ |
| | | /** Updates the right entry panel. */ |
| | | private void updateEntryPane() |
| | | { |
| | | ViewPositions pos = Utilities.getViewPositions(entryPane); |
| | |
| | | else if (node instanceof ConfigurationObjectClassTreeNode) |
| | | { |
| | | entryPane.updateConfigurationObjectClass( |
| | | ((ConfigurationObjectClassTreeNode)node).getObjectClass(), |
| | | lastSchema); |
| | | ((ConfigurationObjectClassTreeNode) node).getObjectClass(), lastSchema); |
| | | } |
| | | else if (node instanceof CustomObjectClassTreeNode) |
| | | { |
| | | ObjectClass oc = ((CustomObjectClassTreeNode)node).getObjectClass(); |
| | | entryPane.updateCustomObjectClass(oc, lastSchema); |
| | | entryPane.updateCustomObjectClass(((CustomObjectClassTreeNode) node).getObjectClass(), lastSchema); |
| | | } |
| | | else if (node instanceof StandardAttributeTreeNode) |
| | | { |
| | | entryPane.updateStandardAttribute( |
| | | ((StandardAttributeTreeNode)node).getAttribute(), lastSchema); |
| | | entryPane.updateStandardAttribute(((StandardAttributeTreeNode) node).getAttribute(), lastSchema); |
| | | } |
| | | else if (node instanceof ConfigurationAttributeTreeNode) |
| | | { |
| | | entryPane.updateConfigurationAttribute( |
| | | ((ConfigurationAttributeTreeNode)node).getAttribute(), lastSchema); |
| | | entryPane.updateConfigurationAttribute(((ConfigurationAttributeTreeNode) node).getAttribute(), lastSchema); |
| | | } |
| | | else if (node instanceof CustomAttributeTreeNode) |
| | | { |
| | | AttributeType attr = ((CustomAttributeTreeNode)node).getAttribute(); |
| | | entryPane.updateCustomAttribute(attr, lastSchema); |
| | | entryPane.updateCustomAttribute(((CustomAttributeTreeNode) node).getAttribute(), lastSchema); |
| | | } |
| | | else if (node instanceof MatchingRuleTreeNode) |
| | | { |
| | | entryPane.updateMatchingRule( |
| | | ((MatchingRuleTreeNode)node).getMatchingRule(), lastSchema); |
| | | entryPane.updateMatchingRule(((MatchingRuleTreeNode) node).getMatchingRule(), lastSchema); |
| | | } |
| | | else if (node instanceof AttributeSyntaxTreeNode) |
| | | { |
| | | entryPane.updateAttributeSyntax( |
| | | ((AttributeSyntaxTreeNode)node).getAttributeSyntax(), lastSchema); |
| | | entryPane.updateAttributeSyntax(((AttributeSyntaxTreeNode) node).getAttributeSyntax(), lastSchema); |
| | | } |
| | | else |
| | | { |
| | | entryPane.displayMessage(NO_SCHEMA_ITEM_SELECTED); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if ((paths != null) && (paths.length > 1)) |
| | | else if (paths != null && paths.length > 1) |
| | | { |
| | | boolean categorySelected = false; |
| | | int nNonCategory = 0; |
| | |
| | | } |
| | | else if (categorySelected) |
| | | { |
| | | entryPane.displayMessage(CATEGORY_ITEM_SELECTED); |
| | | entryPane.displayMessage(INFO_CTRL_PANEL_CATEGORY_ITEM_SELECTED.get()); |
| | | } |
| | | else |
| | | { |
| | | entryPane.displayMessage(MULTIPLE_ITEMS_SELECTED); |
| | | entryPane.displayMessage(INFO_CTRL_PANEL_MULTIPLE_SCHEMA_ITEMS_SELECTED.get()); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | entryPane.displayMessage(NO_SCHEMA_ITEM_SELECTED); |
| | | } |
| | | } |
| | | Utilities.updateViewPositions(pos); |
| | | } |
| | | |
| | |
| | | private void addPopupMenu() |
| | | { |
| | | popup = new JPopupMenu(); |
| | | JMenuItem menuItem = Utilities.createMenuItem( |
| | | INFO_CTRL_PANEL_NEW_OBJECTCLASS_MENU.get()); |
| | | JMenuItem menuItem = Utilities.createMenuItem(INFO_CTRL_PANEL_NEW_OBJECTCLASS_MENU.get()); |
| | | menuItem.addActionListener(new ActionListener() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void actionPerformed(ActionEvent ev) |
| | | { |
| | |
| | | } |
| | | }); |
| | | popup.add(menuItem); |
| | | menuItem = Utilities.createMenuItem( |
| | | INFO_CTRL_PANEL_NEW_ATTRIBUTE_MENU.get()); |
| | | menuItem = Utilities.createMenuItem(INFO_CTRL_PANEL_NEW_ATTRIBUTE_MENU.get()); |
| | | menuItem.addActionListener(new ActionListener() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void actionPerformed(ActionEvent ev) |
| | | { |
| | |
| | | }); |
| | | popup.add(menuItem); |
| | | popup.add(new JSeparator()); |
| | | deleteMenuItem = Utilities.createMenuItem( |
| | | INFO_CTRL_PANEL_DELETE_SCHEMA_ELEMENT_MENU.get()); |
| | | deleteMenuItem = Utilities.createMenuItem(INFO_CTRL_PANEL_DELETE_SCHEMA_ELEMENT_MENU.get()); |
| | | deleteMenuItem.addActionListener(new ActionListener() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void actionPerformed(ActionEvent ev) |
| | | { |
| | |
| | | }); |
| | | popup.add(deleteMenuItem); |
| | | deleteMenuItem.setEnabled(false); |
| | | |
| | | popup.setOpaque(true); |
| | | |
| | | ((CustomTree)treePane.getTree()).setPopupMenu(popup); |
| | | } |
| | | |
| | | private void deleteClicked() |
| | | { |
| | | ArrayList<LocalizableMessage> errors = new ArrayList<>(); |
| | | List<LocalizableMessage> errors = new ArrayList<>(); |
| | | TreePath[] paths = treePane.getTree().getSelectionPaths(); |
| | | ArrayList<ObjectClass> ocsToDelete = new ArrayList<>(); |
| | | ArrayList<AttributeType> attrsToDelete = new ArrayList<>(); |
| | | List<ObjectClass> ocsToDelete = new ArrayList<>(); |
| | | List<AttributeType> attrsToDelete = new ArrayList<>(); |
| | | if (paths != null) |
| | | { |
| | | for (TreePath path : paths) |
| | |
| | | } |
| | | if (errors.isEmpty()) |
| | | { |
| | | LocalizableMessage confirmationMessage = |
| | | getConfirmationMessage(ocsToDelete, attrsToDelete, schema); |
| | | |
| | | LinkedHashSet<AttributeType> orderedAttributes = |
| | | getOrderedAttributesToDelete(attrsToDelete); |
| | | LinkedHashSet<ObjectClass> orderedObjectClasses = |
| | | getOrderedObjectClassesToDelete(ocsToDelete); |
| | | LocalizableMessage confirmationMessage = getConfirmationMessage(ocsToDelete, attrsToDelete, schema); |
| | | Set<AttributeType> orderedAttributes = getOrderedAttributesToDelete(attrsToDelete); |
| | | Set<ObjectClass> orderedObjectClasses = getOrderedObjectClassesToDelete(ocsToDelete); |
| | | |
| | | LocalizableMessage title; |
| | | if (orderedAttributes.isEmpty()) |
| | |
| | | { |
| | | title = INFO_CTRL_PANEL_DELETE_OBJECTCLASSES_AND_ATTRIBUTES_TITLE.get(); |
| | | } |
| | | ProgressDialog dlg = new ProgressDialog( |
| | | Utilities.createFrame(), |
| | | Utilities.getParentDialog(this), title, getInfo()); |
| | | ProgressDialog dlg = |
| | | new ProgressDialog(Utilities.createFrame(), Utilities.getParentDialog(this), title, getInfo()); |
| | | DeleteSchemaElementsTask newTask = |
| | | new DeleteSchemaElementsTask(getInfo(), dlg, orderedObjectClasses, |
| | | orderedAttributes); |
| | | new DeleteSchemaElementsTask(getInfo(), dlg, orderedObjectClasses, orderedAttributes); |
| | | for (Task task : getInfo().getTasks()) |
| | | { |
| | | task.canLaunch(newTask, errors); |
| | | } |
| | | if (errors.isEmpty()) |
| | | { |
| | | ArrayList<String> allNames = new ArrayList<>(); |
| | | if (displayConfirmationDialog( |
| | | INFO_CTRL_PANEL_CONFIRMATION_REQUIRED_SUMMARY.get(), |
| | | confirmationMessage)) |
| | | List<String> allNames = new ArrayList<>(); |
| | | if (displayConfirmationDialog(INFO_CTRL_PANEL_CONFIRMATION_REQUIRED_SUMMARY.get(), confirmationMessage)) |
| | | { |
| | | launchOperation(newTask, |
| | | INFO_CTRL_PANEL_DELETING_SCHEMA_ELEMENTS_SUMMARY.get(), |
| | | launchOperation(newTask, INFO_CTRL_PANEL_DELETING_SCHEMA_ELEMENTS_SUMMARY.get(), |
| | | INFO_CTRL_PANEL_DELETING_SCHEMA_ELEMENTS_COMPLETE.get(), |
| | | INFO_CTRL_PANEL_DELETING_SCHEMA_ELEMENTS_SUCCESSFUL.get( |
| | | Utilities.getStringFromCollection(allNames, ", ")), |
| | | INFO_CTRL_PANEL_DELETING_SCHEMA_ELEMENTS_SUCCESSFUL |
| | | .get(Utilities.getStringFromCollection(allNames, ", ")), |
| | | ERR_CTRL_PANEL_DELETING_SCHEMA_ELEMENTS_ERROR_SUMMARY.get(), |
| | | ERR_CTRL_PANEL_DELETING_SCHEMA_ELEMENTS_ERROR_DETAILS.get(), |
| | | null, |
| | | dlg); |
| | | ERR_CTRL_PANEL_DELETING_SCHEMA_ELEMENTS_ERROR_DETAILS.get(), null, dlg); |
| | | dlg.setVisible(true); |
| | | } |
| | | } |
| | |
| | | |
| | | private boolean mustAdd(String name, String oid, String primaryName, Iterable<String> names) |
| | | { |
| | | ArrayList<String> values = new ArrayList<>(); |
| | | List<String> values = new ArrayList<>(); |
| | | values.add(oid); |
| | | if (primaryName != null) |
| | | { |
| | |
| | | |
| | | /** |
| | | * Check whether the provided attribute must be added or not. |
| | | * @param attr the attribute. |
| | | * |
| | | * @param attr |
| | | * the attribute. |
| | | * @return <CODE>true</CODE> if the attribute must be added and |
| | | * <CODE>false</CODE> otherwise. |
| | | */ |
| | |
| | | if (f.length () > 0) |
| | | { |
| | | Object filterType = filterAttribute.getSelectedItem(); |
| | | if (NAME.equals(filterType)) |
| | | |
| | | if (FILTER_NAME.equals(filterType)) |
| | | { |
| | | return mustAddAttributeName(attr, f); |
| | | } |
| | | else if (TYPE.equals(filterType)) |
| | | else if (FILTER_TYPE.equals(filterType)) |
| | | { |
| | | return mustAddType(f, StandardAttributePanel.getTypeValue(attr)); |
| | | } |
| | |
| | | |
| | | /** |
| | | * Check whether the provided object class must be added or not. |
| | | * @param oc the objectclass. |
| | | * |
| | | * @param oc |
| | | * the objectclass. |
| | | * @return <CODE>true</CODE> if the objectclass must be added and |
| | | * <CODE>false</CODE> otherwise. |
| | | */ |
| | | private boolean mustAdd(ObjectClass oc) |
| | | { |
| | | String f = filter.getText().trim(); |
| | | if (f.length () > 0) |
| | | final String filterText = filter.getText().trim(); |
| | | if (filterText.isEmpty()) |
| | | { |
| | | Object filterType = filterAttribute.getSelectedItem(); |
| | | |
| | | if (NAME.equals(filterType)) |
| | | { |
| | | return mustAddObjectClassName(oc, f); |
| | | } |
| | | else if (TYPE.equals(filterType)) |
| | | { |
| | | return mustAddType(f, StandardObjectClassPanel.getTypeValue(oc)); |
| | | } |
| | | else if (REQUIRED_ATTRIBUTES.equals(filterType) || |
| | | OPTIONAL_ATTRIBUTES.equals(filterType)) |
| | | { |
| | | return mustAddAttributeName(oc, f, filterType); |
| | | } |
| | | else if (CHILD_CLASS.equals(filterType)) |
| | | { |
| | | return mustAddAnyObjectClassName(oc, f); |
| | | } |
| | | else if (PARENT_CLASS.equals(filterType)) |
| | | { |
| | | return mustAddParentObjectClassName(oc, f); |
| | | } |
| | | else |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | final Object filterType = filterAttribute.getSelectedItem(); |
| | | if (FILTER_NAME.equals(filterType)) |
| | | { |
| | | return mustAddObjectClassName(oc, filterText); |
| | | } |
| | | else if (FILTER_TYPE.equals(filterType)) |
| | | { |
| | | return mustAddType(filterText, StandardObjectClassPanel.getTypeValue(oc)); |
| | | } |
| | | else if (FILTER_REQUIRED_ATTRIBUTES.equals(filterType) || FILTER_OPTIONAL_ATTRIBUTES.equals(filterType)) |
| | | { |
| | | return mustAddAttributeName(oc, filterText, filterType); |
| | | } |
| | | else if (FILTER_CHILD_CLASS.equals(filterType)) |
| | | { |
| | | return mustAddAnyObjectClassName(oc, filterText); |
| | | } |
| | | else if (FILTER_PARENT_CLASS.equals(filterType)) |
| | | { |
| | | return mustAddParentObjectClassName(oc, filterText); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private boolean mustAddAnyObjectClassName(ObjectClass oc, String f) |
| | | { |
| | | for (ObjectClass o : lastSchema.getObjectClasses().values()) |
| | |
| | | |
| | | private boolean mustAddAttributeName(ObjectClass oc, String f, Object filterType) |
| | | { |
| | | Set<AttributeType> definedAttrs; |
| | | if (REQUIRED_ATTRIBUTES.equals(filterType)) |
| | | { |
| | | definedAttrs = oc.getRequiredAttributeChain(); |
| | | } |
| | | else |
| | | { |
| | | definedAttrs = oc.getOptionalAttributeChain(); |
| | | } |
| | | Set<AttributeType> definedAttrs = FILTER_REQUIRED_ATTRIBUTES.equals(filterType) ? oc.getRequiredAttributeChain() |
| | | : oc.getOptionalAttributeChain(); |
| | | return mustAddAttributeName(f, definedAttrs); |
| | | } |
| | | |
| | |
| | | { |
| | | for (ObjectClass parent : oc.getSuperiorClasses()) |
| | | { |
| | | if (mustAddObjectClassName(parent, f) || |
| | | mustAddParentObjectClassName(parent, f)) |
| | | if (mustAddObjectClassName(parent, f) || mustAddParentObjectClassName(parent, f)) |
| | | { |
| | | return true; |
| | | } |
| | |
| | | /** |
| | | * Finds out if a class is descendant of another class using equality of |
| | | * pointers. |
| | | * @param ocParent the parent object class. |
| | | * @param oChild the (potentially) descendant object class. |
| | | * @return {@code true} if the class is a descendant of the parent class |
| | | * and {@code false} otherwise. |
| | | * |
| | | * @param ocParent |
| | | * the parent object class. |
| | | * @param oChild |
| | | * the (potentially) descendant object class. |
| | | * @return {@code true} if the class is a descendant of the parent class and |
| | | * {@code false} otherwise. |
| | | */ |
| | | private boolean isDescendant(ObjectClass ocParent, ObjectClass oChild) |
| | | { |
| | |
| | | |
| | | /** |
| | | * Check whether the provided matching rule must be added or not. |
| | | * @param matchingRule the matching rule. |
| | | * |
| | | * @param matchingRule |
| | | * the matching rule. |
| | | * @return <CODE>true</CODE> if the matching rule must be added and |
| | | * <CODE>false</CODE> otherwise. |
| | | */ |
| | | private boolean mustAdd(MatchingRule matchingRule) |
| | | { |
| | | String f = filter.getText().trim(); |
| | | if (f.length () > 0) |
| | | { |
| | | if (NAME.equals(filterAttribute.getSelectedItem())) |
| | | { |
| | | return mustAdd(f, matchingRule.getOID(), matchingRule.getNameOrOID()); |
| | | } |
| | | return false; |
| | | } |
| | | return true; |
| | | return f.length () <= 0 || (FILTER_NAME.equals(filterAttribute.getSelectedItem()) |
| | | && mustAdd(f, matchingRule.getOID(), matchingRule.getNameOrOID())); |
| | | } |
| | | |
| | | /** |
| | | * Check whether the provided attribute syntax must be added or not. |
| | | * @param syntax the attribute syntax. |
| | | * |
| | | * @param syntax |
| | | * the attribute syntax. |
| | | * @return <CODE>true</CODE> if the attribute syntax must be added and |
| | | * <CODE>false</CODE> otherwise. |
| | | */ |
| | | private boolean mustAdd(Syntax syntax) |
| | | { |
| | | String f = filter.getText().trim(); |
| | | if (f.length () > 0) |
| | | { |
| | | if (NAME.equals(filterAttribute.getSelectedItem())) |
| | | { |
| | | return mustAdd(f, syntax.getOID(), syntax.getName()); |
| | | } |
| | | return false; |
| | | } |
| | | return true; |
| | | return f.length() <= 0 |
| | | || (FILTER_NAME.equals(filterAttribute.getSelectedItem()) && mustAdd(f, syntax.getOID(), syntax.getName())); |
| | | } |
| | | |
| | | private boolean mustAdd(String f, String oid, String name) |
| | | { |
| | | ArrayList<String> values = new ArrayList<>(2); |
| | | List<String> values = new ArrayList<>(2); |
| | | values.add(oid); |
| | | if (name != null) |
| | | { |
| | |
| | | return matchFilter(values, f, false); |
| | | } |
| | | |
| | | private boolean matchFilter(Collection<String> values, String filter, |
| | | boolean exact) |
| | | private boolean matchFilter(Collection<String> values, String filter, boolean exact) |
| | | { |
| | | for (String value : values) |
| | | { |
| | | boolean matchFilter = exact |
| | | ? value.equalsIgnoreCase(filter) |
| | | : value.toLowerCase().contains(filter.toLowerCase()); |
| | | boolean matchFilter = exact ? value.equalsIgnoreCase(filter) : value.toLowerCase().contains(filter.toLowerCase()); |
| | | if (matchFilter) |
| | | { |
| | | return true; |
| | |
| | | { |
| | | if (newAttributeDialog == null) |
| | | { |
| | | NewAttributePanel panel = new NewAttributePanel( |
| | | Utilities.getParentDialog(this)); |
| | | NewAttributePanel panel = new NewAttributePanel(Utilities.getParentDialog(this)); |
| | | panel.setInfo(getInfo()); |
| | | newAttributeDialog = new GenericDialog(null, panel); |
| | | Utilities.centerGoldenMean(newAttributeDialog, |
| | | Utilities.getParentDialog(this)); |
| | | panel.addConfigurationElementCreatedListener( |
| | | new ConfigurationElementCreatedListener() |
| | | Utilities.centerGoldenMean(newAttributeDialog, Utilities.getParentDialog(this)); |
| | | panel.addConfigurationElementCreatedListener(new ConfigurationElementCreatedListener() |
| | | { |
| | | @Override |
| | | public void elementCreated(ConfigurationElementCreatedEvent ev) |
| | |
| | | { |
| | | if (newObjectClassDialog == null) |
| | | { |
| | | NewObjectClassPanel panel = new NewObjectClassPanel( |
| | | Utilities.getParentDialog(this)); |
| | | NewObjectClassPanel panel = new NewObjectClassPanel(Utilities.getParentDialog(this)); |
| | | panel.setInfo(getInfo()); |
| | | newObjectClassDialog = new GenericDialog(null, panel); |
| | | Utilities.centerGoldenMean(newObjectClassDialog, |
| | | Utilities.getParentDialog(this)); |
| | | panel.addConfigurationElementCreatedListener( |
| | | new ConfigurationElementCreatedListener() |
| | | Utilities.centerGoldenMean(newObjectClassDialog, Utilities.getParentDialog(this)); |
| | | panel.addConfigurationElementCreatedListener(new ConfigurationElementCreatedListener() |
| | | { |
| | | @Override |
| | | public void elementCreated(ConfigurationElementCreatedEvent ev) |
| | |
| | | } |
| | | } |
| | | |
| | | private HashMap<Object, ImageIcon> hmCategoryImages = new HashMap<>(); |
| | | private HashMap<Class<?>, ImageIcon> hmImages = new HashMap<>(); |
| | | private final Map<Object, ImageIcon> hmCategoryImages = new HashMap<>(); |
| | | private final Map<Class<?>, ImageIcon> hmImages = new HashMap<>(); |
| | | { |
| | | Object[] nodes = {attributes, objectClasses, standardObjectClasses, |
| | | standardAttributes, configurationObjectClasses, configurationAttributes, |
| | | customObjectClasses, customAttributes, matchingRules, syntaxes}; |
| | | String[] paths = {"ds-attr-folder.png", "ds-class-folder.png", |
| | | "ds-folder.png", |
| | | String[] paths = {"ds-attr-folder.png", "ds-class-folder.png", "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"}; |
| | | for (int i=0; i<nodes.length; i++) |
| | | { |
| | | hmCategoryImages.put(nodes[i], |
| | | Utilities.createImageIcon(IconPool.IMAGE_PATH+"/"+paths[i])); |
| | | hmCategoryImages.put(nodes[i], Utilities.createImageIcon(IconPool.IMAGE_PATH + "/" + paths[i])); |
| | | } |
| | | Class<?>[] classes = {ConfigurationAttributeTreeNode.class, |
| | | StandardAttributeTreeNode.class, CustomAttributeTreeNode.class, |
| | | ConfigurationObjectClassTreeNode.class, |
| | | StandardObjectClassTreeNode.class, CustomObjectClassTreeNode.class, |
| | | Class<?>[] classes = |
| | | { ConfigurationAttributeTreeNode.class, StandardAttributeTreeNode.class, CustomAttributeTreeNode.class, |
| | | ConfigurationObjectClassTreeNode.class, StandardObjectClassTreeNode.class, CustomObjectClassTreeNode.class, |
| | | MatchingRuleTreeNode.class, AttributeSyntaxTreeNode.class}; |
| | | String[] ocPaths = {"ds-attr.png", "ds-attr.png", "ds-attr.png", |
| | | "ds-class.png", "ds-class.png", "ds-class.png", "ds-rule.png", |
| | | "ds-syntax.png"}; |
| | | "ds-class.png", "ds-class.png", "ds-class.png", "ds-rule.png", "ds-syntax.png" }; |
| | | for (int i=0; i<classes.length; i++) |
| | | { |
| | | hmImages.put(classes[i], |
| | | Utilities.createImageIcon(IconPool.IMAGE_PATH+"/"+ocPaths[i])); |
| | | hmImages.put(classes[i], Utilities.createImageIcon(IconPool.IMAGE_PATH + "/" + ocPaths[i])); |
| | | } |
| | | } |
| | | |
| | | /** Specific class used to render the nodes in the tree. It uses specific icons for the nodes. */ |
| | | protected class SchemaTreeCellRenderer extends TreeCellRenderer |
| | | private class SchemaTreeCellRenderer extends TreeCellRenderer |
| | | { |
| | | private static final long serialVersionUID = -3390568254259441766L; |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Component getTreeCellRendererComponent(JTree tree, Object value, |
| | | boolean isSelected, boolean isExpanded, boolean isLeaf, int row, |
| | | boolean hasFocus) |
| | | public Component getTreeCellRendererComponent( |
| | | JTree tree, Object value, boolean isSelected, boolean isExpanded, boolean isLeaf, int row, boolean hasFocus) |
| | | { |
| | | super.getTreeCellRendererComponent(tree, value, isSelected, isExpanded, |
| | | isLeaf, row, hasFocus); |
| | | super.getTreeCellRendererComponent(tree, value, isSelected, isExpanded, isLeaf, row, hasFocus); |
| | | setIcon(getIcon(value)); |
| | | return this; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private LinkedHashSet<ObjectClass> getOrderedObjectClassesToDelete( |
| | | Collection<ObjectClass> ocsToDelete) |
| | | private Set<ObjectClass> getOrderedObjectClassesToDelete(Collection<ObjectClass> ocsToDelete) |
| | | { |
| | | ArrayList<ObjectClass> lOrderedOcs = new ArrayList<>(); |
| | | List<ObjectClass> lOrderedOcs = new ArrayList<>(); |
| | | // Reorder objectClasses and attributes to delete them in the proper order. |
| | | for (ObjectClass oc : ocsToDelete) |
| | | { |
| | |
| | | return new LinkedHashSet<>(lOrderedOcs); |
| | | } |
| | | |
| | | private LinkedHashSet<AttributeType> getOrderedAttributesToDelete( |
| | | Collection<AttributeType> attrsToDelete) |
| | | private Set<AttributeType> getOrderedAttributesToDelete(Collection<AttributeType> attrsToDelete) |
| | | { |
| | | ArrayList<AttributeType> lOrderedAttributes = new ArrayList<>(); |
| | | List<AttributeType> lOrderedAttributes = new ArrayList<>(); |
| | | for (AttributeType attr : attrsToDelete) |
| | | { |
| | | int index = -1; |
| | |
| | | } |
| | | |
| | | private LocalizableMessage getConfirmationMessage( |
| | | Collection<ObjectClass> ocsToDelete, |
| | | Collection<AttributeType> attrsToDelete, |
| | | Schema schema) |
| | | Collection<ObjectClass> ocsToDelete, Collection<AttributeType> attrsToDelete, Schema schema) |
| | | { |
| | | ArrayList<ObjectClass> childClasses = new ArrayList<>(); |
| | | List<ObjectClass> childClasses = new ArrayList<>(); |
| | | // Analyze objectClasses |
| | | for (ObjectClass objectClass : ocsToDelete) |
| | | { |
| | |
| | | childClasses.removeAll(ocsToDelete); |
| | | } |
| | | |
| | | ArrayList<AttributeType> childAttributes = new ArrayList<>(); |
| | | TreeSet<String> dependentClasses = new TreeSet<>(); |
| | | List<AttributeType> childAttributes = new ArrayList<>(); |
| | | Set<String> dependentClasses = new TreeSet<>(); |
| | | // Analyze attributes |
| | | for (AttributeType attribute : attrsToDelete) |
| | | { |
| | |
| | | } |
| | | if (ocsToDelete.size() == 1) |
| | | { |
| | | mb.append(INFO_OBJECTCLASS_IS_SUPERIOR.get( |
| | | ocsToDelete.iterator().next().getNameOrOID(), |
| | | mb.append(INFO_OBJECTCLASS_IS_SUPERIOR.get(ocsToDelete.iterator().next().getNameOrOID(), |
| | | Utilities.getStringFromCollection(childNames, ", "))); |
| | | } |
| | | else |
| | | { |
| | | mb.append(INFO_OBJECTCLASSES_ARE_SUPERIOR.get( |
| | | Utilities.getStringFromCollection(childNames, ", "))); |
| | | mb.append(INFO_OBJECTCLASSES_ARE_SUPERIOR.get(Utilities.getStringFromCollection(childNames, ", "))); |
| | | } |
| | | mb.append("<br>"); |
| | | } |
| | | if (!childAttributes.isEmpty()) |
| | | { |
| | | TreeSet<String> childNames = new TreeSet<>(); |
| | | Set<String> childNames = new TreeSet<>(); |
| | | for (AttributeType attr : childAttributes) |
| | | { |
| | | childNames.add(attr.getNameOrOID()); |
| | | } |
| | | if (attrsToDelete.size() == 1) |
| | | { |
| | | mb.append(INFO_ATTRIBUTE_IS_SUPERIOR.get( |
| | | attrsToDelete.iterator().next().getNameOrOID(), |
| | | mb.append(INFO_ATTRIBUTE_IS_SUPERIOR.get(attrsToDelete.iterator().next().getNameOrOID(), |
| | | Utilities.getStringFromCollection(childNames, ", "))); |
| | | } |
| | | else |
| | | { |
| | | mb.append(INFO_ATTRIBUTES_ARE_SUPERIOR.get( |
| | | Utilities.getStringFromCollection(childNames, ", "))); |
| | | mb.append(INFO_ATTRIBUTES_ARE_SUPERIOR.get(Utilities.getStringFromCollection(childNames, ", "))); |
| | | } |
| | | mb.append("<br>"); |
| | | } |
| | |
| | | { |
| | | if (attrsToDelete.size() == 1) |
| | | { |
| | | mb.append(INFO_ATTRIBUTE_WITH_DEPENDENCIES.get( |
| | | attrsToDelete.iterator().next().getNameOrOID(), |
| | | mb.append(INFO_ATTRIBUTE_WITH_DEPENDENCIES.get(attrsToDelete.iterator().next().getNameOrOID(), |
| | | Utilities.getStringFromCollection(dependentClasses, ", "))); |
| | | } |
| | | else |
| | | { |
| | | mb.append(INFO_ATTRIBUTES_WITH_DEPENDENCIES.get( |
| | | Utilities.getStringFromCollection(dependentClasses, ", "))); |
| | | mb.append(INFO_ATTRIBUTES_WITH_DEPENDENCIES.get(Utilities.getStringFromCollection(dependentClasses, ", "))); |
| | | } |
| | | mb.append("<br>"); |
| | | } |
| | | |
| | | ArrayList<String> allNames = new ArrayList<>(); |
| | | List<String> allNames = new ArrayList<>(); |
| | | for (ObjectClass ocToDelete : ocsToDelete) |
| | | { |
| | | allNames.add(ocToDelete.getNameOrOID()); |
| | |
| | | allNames.add(attrToDelete.getNameOrOID()); |
| | | } |
| | | LocalizableMessage confirmationMessage = |
| | | INFO_CTRL_PANEL_CONFIRMATION_DELETE_SCHEMA_ELEMENTS_MSG.get( |
| | | Utilities.getStringFromCollection(allNames, ", ")); |
| | | INFO_CTRL_PANEL_CONFIRMATION_DELETE_SCHEMA_ELEMENTS_MSG.get(Utilities.getStringFromCollection(allNames, ", ")); |
| | | mb.append(confirmationMessage); |
| | | return mb.toMessage(); |
| | | } |
| | | |
| | | } |