Class Node

java.lang.Object
javax.swing.tree.DefaultMutableTreeNode
com.nomagic.magicdraw.ui.browser.Node
All Implemented Interfaces:
com.nomagic.magicdraw.ui.browser.Expandable, PropertyChangeListener, Serializable, Cloneable, EventListener, MutableTreeNode, TreeNode

@OpenApi public class Node extends DefaultMutableTreeNode implements PropertyChangeListener, com.nomagic.magicdraw.ui.browser.Expandable
The base node of all tree nodes. This node has some user object.
See Also:
  • Field Details

    • MAX_NODE_UPDATE_RETRY_COUNT

      public static final int MAX_NODE_UPDATE_RETRY_COUNT
      See Also:
    • ignoreRootCheck

      protected volatile boolean ignoreRootCheck
  • Constructor Details

    • Node

      public Node(@CheckForNull BaseElement element, @CheckForNull Icon icon)
    • Node

      public Node(@CheckForNull BaseElement element, @CheckForNull Icon icon, @CheckForNull Icon defaultIcon)
    • Node

      public Node(@CheckForNull BaseElement element, @CheckForNull Icon icon, @CheckForNull Icon defaultIcon, com.dassault_systemes.modeler.foundation.ui.tree.NodeTextParams nodeTextParams)
  • Method Details

    • isLocked

      public static boolean isLocked()
      Returns locked flag
      Returns:
      true if it is locked, else false.
    • setLocked

      public static long setLocked(boolean value)
      Sets locked flag and increases locking counter
      Parameters:
      value - lock value
      Returns:
      locking counter
    • resetLock

      public static long resetLock(boolean value, long lockingCounter)
      Sets locked flag and decrements locking counter if current locking counter is equal to the one passed as method parameter
      Parameters:
      value - lock value
      lockingCounter - locking counter
      Returns:
      locking counter
    • addListeners

      protected void addListeners(BaseElement data)
      Adds needed listeners to the node element.
      Parameters:
      data - instance of BaseElement
    • addListeners

      protected void addListeners()
    • getChildren

      public List<Node> getChildren()
      Returns list of children.
      Returns:
      list of Node
    • getUserObjectBaseElementID

      @CheckForNull public String getUserObjectBaseElementID()
    • getChildCount

      public int getChildCount()
      Specified by:
      getChildCount in interface TreeNode
      Overrides:
      getChildCount in class DefaultMutableTreeNode
    • getChildAt

      public TreeNode getChildAt(int index)
      Specified by:
      getChildAt in interface TreeNode
      Overrides:
      getChildAt in class DefaultMutableTreeNode
    • children

      public Enumeration children()
      Specified by:
      children in interface TreeNode
      Overrides:
      children in class DefaultMutableTreeNode
    • getIndex

      public int getIndex(TreeNode aChild)
      Specified by:
      getIndex in interface TreeNode
      Overrides:
      getIndex in class DefaultMutableTreeNode
    • insert

      public void insert(MutableTreeNode newChild, int childIndex)
      Specified by:
      insert in interface MutableTreeNode
      Overrides:
      insert in class DefaultMutableTreeNode
    • remove

      public void remove(int childIndex)
      Specified by:
      remove in interface MutableTreeNode
      Overrides:
      remove in class DefaultMutableTreeNode
    • remove

      public void remove(MutableTreeNode aChild)
      Specified by:
      remove in interface MutableTreeNode
      Overrides:
      remove in class DefaultMutableTreeNode
    • replaceChildren

      public void replaceChildren(List<Node> newChildren)
    • exchangeNodeChildrenKeepers

      @CheckForNull protected com.nomagic.magicdraw.ui.browser.NodeChildrenKeeper exchangeNodeChildrenKeepers()
    • getUserObject

      @CheckForNull @OpenApi public Object getUserObject()
      Returns user object of this node.
      Overrides:
      getUserObject in class DefaultMutableTreeNode
      Returns:
      user object(some Element).
    • setUserObject

      public void setUserObject(@CheckForNull Object o)
      We put WeakReference with given object as user object in order to make things easier for garbage collector.
      Specified by:
      setUserObject in interface MutableTreeNode
      Overrides:
      setUserObject in class DefaultMutableTreeNode
    • getDefaultIcon

      @CheckForNull public Icon getDefaultIcon()
      Returns the default icon
      Returns:
      the default icon.
    • setDefaultIcon

      public void setDefaultIcon(@CheckForNull Icon icon)
      Sets the default icon.
      Parameters:
      icon - the default icon.
    • getIcon

      @CheckForNull public Icon getIcon()
      Gets the icon for this node.
      Returns:
      the icon of this node.
    • setIcon

      public void setIcon(@CheckForNull Icon icon)
      Sets the icon for this node. If object is not editable, sets gray icon.
      Parameters:
      icon - the new icon.
    • updateIcon

      public boolean updateIcon()
      Sets icon according to the data.
      Returns:
      true if icon was changed
    • propertyChange

      public void propertyChange(PropertyChangeEvent event)
      This method is called when some ObjectData has changed.
      Specified by:
      propertyChange in interface PropertyChangeListener
      Parameters:
      event - the property changed event.
    • isEventForUpdate

      protected boolean isEventForUpdate(PropertyChangeEvent evt)
    • getText

      public final String getText()
      This method returns the name of the ObjectData (user's object of this node).
      Returns:
      the name of the ObjectData
    • setText

      public void setText(@CheckForNull String text)
      Sets the name of the ObjectData(user's object). This method is called after the node's text editing.
      Parameters:
      text - the new node's text.
    • updateSortKeys

      protected void updateSortKeys(String text)
    • internalUpdateNodeStructure

      protected boolean internalUpdateNodeStructure()
      Loads all children for this node.
      Returns:
      true if structure was changed
    • updateNodeStructureWithRetry

      public final boolean updateNodeStructureWithRetry()
      Tries to load all children of this node. In case of exception due to model changes will try multiple times
      Returns:
      true if structure was changed
    • getChildrenOwner

      public com.nomagic.magicdraw.ui.browser.ChildrenOwner getChildrenOwner()
      Returns:
      children owner of the node. If node does not have his children owner, children owner from tree model is used
    • setChildrenOwner

      public void setChildrenOwner(com.nomagic.magicdraw.ui.browser.ChildrenOwner owner)
      Set node specific children owner.
      Parameters:
      owner - owner
    • getTreeModel

      @CheckForNull public final com.nomagic.magicdraw.ui.browser.TreeModel getTreeModel()
      Returns the model of this node.
      Returns:
      the model of this node.
    • setTreeModel

      public void setTreeModel(com.nomagic.magicdraw.ui.browser.TreeModel model)
      Sets the model for this node.
      Parameters:
      model - the TreeModel.
    • updateNodeStructure

      protected boolean updateNodeStructure(@CheckForNull Collection<?> objects)
      This method reloads children from given user object collection. If children already exists, sets only text for the node.
      Parameters:
      objects - the given children
      Returns:
      true if node structure was changed
    • updateNodeStructureOfChildInExpandedPath

      public void updateNodeStructureOfChildInExpandedPath(Node node)
    • unCompactNodes

      protected boolean unCompactNodes()
      Un-compact all compacted children.
      Returns:
      true if at least one child was un-compacted
    • compactNodes

      protected boolean compactNodes(boolean parentStructureChanged)
      Compact all children.
      Parameters:
      parentStructureChanged - was parent (current) node structure changed
      Returns:
      true if at least one child was compacted
    • replaceCompactableNode

      @CheckForNull protected Node replaceCompactableNode(Node node)
      Replace given node with its compacted child if needed.
      Parameters:
      node - given node
      Returns:
      node replaced node or null if no replacement
    • updateNodeItself

      public final boolean updateNodeItself()
      Updates text and icon of the node.
      Returns:
      true if text or icon was changed.
    • internalUpdateNodeItself

      protected boolean internalUpdateNodeItself()
    • setForceUpdate

      public void setForceUpdate(boolean forceUpdate)
      Set to true to force node update, no matter if text or icon was not changed
      Parameters:
      forceUpdate - flag to indicate update status
    • createNodeFor

      @CheckForNull protected Node createNodeFor(Object obj)
      Creates node for given element. Uses node creator from tree model.
      Parameters:
      obj - the given object.
      Returns:
      the created node or null
    • getRootElements

      public Collection<BaseElement> getRootElements()
      Collects root elements of children
      Returns:
      collection of root elements of children
    • getNodeForObject

      @CheckForNull public Node[] getNodeForObject(BaseElement object)
      Returns the tree node which data is the same as given Element. This method is used to determine if node with given Element as data object exists.
      Parameters:
      object - the given Element.
      Returns:
      the node which data object is the same as given object or null such node is not found.
    • getHiddenNodeFor

      @CheckForNull protected Node getHiddenNodeFor(@CheckForNull BaseElement object)
    • prepareUserObjectNodeMap

      protected Map<Object,Node> prepareUserObjectNodeMap()
      Return map of user objects mapped to nodes.
      Returns:
      map of user objects mapped to nodes.
    • mouseDoubleClicked

      public void mouseDoubleClicked(@CheckForNull AWTEvent event)
      Calls onFind for user object. This method is called when user double clicks with mouse on the node.
      Parameters:
      event - click event
    • enterClicked

      public void enterClicked(AWTEvent event)
      Calls mouseDoubleClicked for user object. This method is called when user double clicks with mouse on the node.
      Parameters:
      event - click event
    • removeListeners

      protected void removeListeners()
      Removes propertyChangeListener(node) from Element property change support.
    • remove

      public void remove()
      Removes node from parent.
    • disposeNode

      public void disposeNode()
      Disposes the node - unregisters listeners, removes from nodes map and etc.
    • removeAllChildren

      protected boolean removeAllChildren(Collection<?> userObjects)
      Removes nodes from this node if theirs data objects are not in given userObjects.
      Parameters:
      userObjects - the given userObjects of the DTObjects.
      Returns:
      true, if at least one node was removed
    • removeIllegalNodes

      protected boolean removeIllegalNodes()
      Removes nodes from this node these nodes cannot be created with node creator.
      Returns:
      true, if at least one node was removed
    • removeAllChildren

      public void removeAllChildren()
      Removes all nodes from this node.
      Overrides:
      removeAllChildren in class DefaultMutableTreeNode
    • removeRecursively

      public void removeRecursively()
      Removes all nodes from this node recursively
    • removeRecursively

      public void removeRecursively(int index)
      Removes all nodes from this node recursively
      Parameters:
      index - of node which should be deleted.
    • expand

      public void expand(boolean sortExplicitly)
      Expands the tree node. If children of the node are not loaded, load them.
      Parameters:
      sortExplicitly - true, if node children must be sorted explicitly.
    • expand

      public void expand()
      Expands the tree node. If children of the node are not loaded, load them.
    • expandAsync

      public void expandAsync(boolean sortExplicitly)
      Asynchronously expands the tree node. If children of the node are not loaded, load them.
      Parameters:
      sortExplicitly - true, if node children must be sorted explicitly.
    • expandAsync

      public void expandAsync()
      Asynchronously expands the tree node. If children of the node are not loaded, load them.
    • updateChildren

      public final void updateChildren(Node node, boolean sortExplicitly)
      Updates children of this node depending on dirty and expand state.
      Parameters:
      node - the given node.
      sortExplicitly - if true sort children explicitly
    • updateChildrenAsync

      public final Future<?> updateChildrenAsync(Node node, boolean sortExplicitly)
      Asynchronously updates children of this node depending on dirty and expand state.
      Parameters:
      node - the given node.
      sortExplicitly - if true sort children explicitly
      Returns:
      A Future object representing the pending operation
    • updateChildrenAsync

      public final <A> Future<?> updateChildrenAsync(Node node, boolean sortExplicitly, @CheckForNull A attachment, com.nomagic.magicdraw.utils.concurrent.CompletionHandler<Boolean,? super A> handler)
      Asynchronously updates children of this node depending on dirty and expand state.
      Type Parameters:
      A - The type of the object attached to the completion handler
      Parameters:
      node - the given node.
      sortExplicitly - if true sort children explicitly
      attachment - The object to attach to the update operation; can be null
      handler - The handler for consuming the operation result, which is true, if node itself was changed(not children).
    • collapse

      public void collapse()
      Collapse this node.
    • isInExpandedPath

      public boolean isInExpandedPath()
      Checks if this node is in expanded path.
      Returns:
      true, is this node is in expanded path(visible to user).
    • acceptLink

      public final void acceptLink(Object obj)
      Accepts drag and drop link action
      Parameters:
      obj - - moved object
    • acceptLinkSpecific

      protected void acceptLinkSpecific(List<?> vec)
    • canAcceptLink

      public boolean canAcceptLink(Object obj)
    • canAcceptLinkSpecific

      protected boolean canAcceptLinkSpecific(BaseElement obj)
    • acceptMove

      public void acceptMove(Object obj, Tree tree, Point location)
      Accepts drag and drop link action
      Parameters:
      obj - moved object
    • acceptMoveSpecific

      protected void acceptMoveSpecific(List<?> vec, Tree tree, Point location)
    • canAcceptMove

      public boolean canAcceptMove(Object obj)
    • canAcceptMoveSpecific

      protected boolean canAcceptMoveSpecific(BaseElement o)
    • acceptCopy

      public void acceptCopy(Object obj)
      Accepts drag and drop link action
      Parameters:
      obj - moved object
    • acceptCopySpecific

      protected void acceptCopySpecific(List<?> elements)
    • getCopyOperationTarget

      @CheckForNull public Object getCopyOperationTarget()
    • canAcceptCopy

      public final boolean canAcceptCopy(Object obj)
    • canAcceptCopySpecific

      protected boolean canAcceptCopySpecific(BaseElement element)
    • getSortKeys

      public com.nomagic.magicdraw.ui.browser.Node.NodeSortKeys getSortKeys()
      Returns keys' array for sorting
      Returns:
      instance of Node.NodeSortKeys
    • setSortKeys

      public void setSortKeys(com.nomagic.magicdraw.ui.browser.Node.NodeSortKeys sortKeys)
    • createNodeSortKeys

      protected com.nomagic.magicdraw.ui.browser.Node.NodeSortKeys createNodeSortKeys()
    • getType

      protected String getType()
      Returns node type
      Returns:
      returns node type
    • updateNode

      public boolean updateNode()
      Updates node and loads children of the node if it is necessary.
      Returns:
      true, if node itself was changed(not children).
    • updateNode

      public boolean updateNode(boolean sortParent)
      Updates node and loads children of the node if it is necessary.
      Parameters:
      sortParent - if true - parent node will be sorted if this node changes text.
      Returns:
      true, if node itself was changed(not children).
    • updateNodeAsync

      public Future<Boolean> updateNodeAsync()
      Asynchronously updates node and loads children of the node if it is necessary.
      Returns:
      Future which results to true, if node itself was changed(not children).
    • updateNodeAsync

      public final <A> void updateNodeAsync(A attachment, com.nomagic.magicdraw.utils.concurrent.CompletionHandler<Boolean,? super A> handler)
      Asynchronously updates node and loads children of the node if it is necessary.
      Type Parameters:
      A - The type of the object attached to the completion handler
      Parameters:
      attachment - The object to attach to the update operation; can be null
      handler - The handler for consuming the operation result, which is true, if node itself was changed(not children).
    • updateNodeAsync

      public final Future<Boolean> updateNodeAsync(boolean sortParent)
      Asynchronously updates node and loads children of the node if it is necessary.
      Parameters:
      sortParent - if true - parent node will be sorted if this node changes text.
      Returns:
      Future which results to true, if node itself was changed(not children).
    • updateNodeAsync

      public final <A> void updateNodeAsync(boolean sortParent, A attachment, @CheckForNull com.nomagic.magicdraw.utils.concurrent.CompletionHandler<Boolean,? super A> handler)
      Asynchronously updates node and loads children of the node if it is necessary.
      Type Parameters:
      A - The type of the object attached to the completion handler
      Parameters:
      sortParent - if true - parent node will be sorted if this node changes text.
      attachment - The object to attach to the update operation; can be null
      handler - The handler for consuming the result
    • forceUpdateNodeSync

      public final void forceUpdateNodeSync(boolean sortParent)
      Marks node as expanded which forces node to be fully updated, and initiates asynchronous node update.
      Parameters:
      sortParent - if true - parent node will be sorted if this node changes text.
    • doUpdateNode

      protected <A> Future<Boolean> doUpdateNode(boolean sortParent, @CheckForNull A attachment, @CheckForNull com.nomagic.magicdraw.utils.concurrent.CompletionHandler<Boolean,? super A> handler)
    • isProjectReady

      protected boolean isProjectReady(com.nomagic.magicdraw.ui.browser.TreeModel treeModel)
    • isNodeLocked

      protected boolean isNodeLocked(com.nomagic.magicdraw.ui.browser.TreeModel treeModel)
    • updateNodeSync

      public final Boolean updateNodeSync(boolean sortParent)
      Synchronously updates node and loads children of the node if it is necessary.
      Parameters:
      sortParent - if true - parent node will be sorted if this node changes text.
      Returns:
      true, if node itself was changed(not children).
    • doUpdateNodeSync

      protected Boolean doUpdateNodeSync(boolean sortParent)
    • waitForUpdateNodeCompletions

      public void waitForUpdateNodeCompletions()
      Wait for pending updateNodeAsync() completions
    • toString

      public String toString()
      Overrides:
      toString in class DefaultMutableTreeNode
    • isExpanded

      public boolean isExpanded()
      Description copied from interface: com.nomagic.magicdraw.ui.browser.Expandable
      Checks if component is expanded or not.
      Specified by:
      isExpanded in interface com.nomagic.magicdraw.ui.browser.Expandable
      Returns:
      true when component is expanded, false - otherwise
    • setExpanded

      protected void setExpanded(boolean expanded)
      Sets expanded state of this node.
      Parameters:
      expanded - true if node is expanded.
    • isForceStructureUpdateOnExpand

      public boolean isForceStructureUpdateOnExpand()
    • setForceStructureUpdateOnExpand

      public void setForceStructureUpdateOnExpand(boolean value)
    • isRemoveChildrenOnCollapse

      public boolean isRemoveChildrenOnCollapse()
    • setRemoveChildrenOnCollapse

      public void setRemoveChildrenOnCollapse(boolean value)
    • getNodeTextParams

      protected com.dassault_systemes.modeler.foundation.ui.tree.NodeTextParams getNodeTextParams()
    • constructText

      protected String constructText()
    • constructTextForSorting

      public String constructTextForSorting()
      This method returns the name of the ObjectData (user's object of this node) for sorting purposes
      Returns:
      the name of the ObjectData for sorting purposes
    • createRemoveCommand

      @CheckForNull public com.dassault_systemes.modeler.foundation.editing.Command createRemoveCommand()
    • getParent

      @CheckForNull public Node getParent()
      Specified by:
      getParent in interface TreeNode
      Overrides:
      getParent in class DefaultMutableTreeNode
    • setDirtyRecursively

      public void setDirtyRecursively(boolean dirty)
    • isDirty

      public boolean isDirty()
    • setDirty

      public void setDirty(boolean dirty)
      Sets dirty flag.
      Parameters:
      dirty - is dirty?
    • getActions

      public int[] getActions()
    • canDelete

      public boolean canDelete()
      Can delete if user object is BaseElement and can be deleted from its parent.
      Returns:
      true if can delete, else false.
    • getEditingText

      protected String getEditingText()
      Returns text which will be edited. Since some nodes can display one text, but should be edited with other text this method return text to be edited.
      Returns:
      text to edit.
    • isEditable

      public boolean isEditable()
    • setEditable

      public void setEditable(boolean editable)
      Method marks node as editable or not.
      Parameters:
      editable - is editable?
      See Also:
    • isLoading

      public boolean isLoading()
    • setLoading

      public void setLoading(boolean flag)
    • configure

      public void configure(ActionsManager manager)
      Method configure.
      Parameters:
      manager - actions manager to be configured for this node.
    • configureMultiple

      public void configureMultiple(ActionsManager mngr, Node[] node)
      Method to configure actions for context menu of all the provided nodes (array always includes the current node instance too). This method gets called only once for all nodes of the same class type, so each node instance in the provided array should be regarded.
      Parameters:
      mngr - actions manager to be configured for this node.
      node - array of Node for which actions are configured.
    • getElementsForDnd

      @CheckForNull public BaseElement[] getElementsForDnd()
    • getRepresentedElements

      @CheckForNull public BaseElement[] getRepresentedElements()
    • getElementForCopyAction

      @CheckForNull public BaseElement getElementForCopyAction()
    • isChildrenSortable

      public boolean isChildrenSortable()
    • setChildrenSortable

      public void setChildrenSortable(boolean childrenSortable)
    • nodeAdded

      protected void nodeAdded()
    • add

      public void add(MutableTreeNode newChild)
      Overrides:
      add in class DefaultMutableTreeNode
    • isCanDelete

      public boolean isCanDelete()
    • setCanDelete

      public void setCanDelete(boolean canDelete)
      Method marks node as deletable or not.
      Parameters:
      canDelete - can delete?
      See Also:
    • isEnableUpdateIcon

      public boolean isEnableUpdateIcon()
      Returns:
      Returns the enableUpdateIcon.
    • setEnableUpdateIcon

      public void setEnableUpdateIcon(boolean enableUpdateIcon)
    • isChildrenSortNeeded

      public boolean isChildrenSortNeeded()
    • setChildrenSortNeeded

      public void setChildrenSortNeeded(boolean childrenSortNeeded)
    • isCompactable

      public boolean isCompactable()
      Returns:
      true is node is compactable
    • setCompactable

      public void setCompactable(boolean compactable)
      Make node compactable.
      Parameters:
      compactable - value
    • isNodeStructureChanged

      public boolean isNodeStructureChanged()
    • setNodeStructureChanged

      public void setNodeStructureChanged(boolean nodeStructureChanged)
    • isHidden

      public boolean isHidden()
      Returns:
      true if node is hidden
    • setHidden

      public void setHidden(boolean hidden)
      Make node "hidden"
      Parameters:
      hidden - hidden value
    • getHiddenParent

      @CheckForNull public Node getHiddenParent()
      Returns:
      hidden parent
    • setHiddenParent

      public void setHiddenParent(@CheckForNull Node hiddenParent)
      Set hidden parent. Parent is used if node is "hidden", because normal parent is null in such case.
      Parameters:
      hiddenParent - hidden parent
    • clearHiddenOwners

      public void clearHiddenOwners()
      Clear all hidden owners. Hidden nodes becomes not hidden.
    • getHiddenOwners

      public List<Node> getHiddenOwners()
      Returns:
      hidden owners or empty list
    • constructHiddenOwnerText

      protected String constructHiddenOwnerText()
      Constructs hidden owners text.
      Returns:
      hidden owner text
    • isAutoExpandable

      public boolean isAutoExpandable()
      Returns:
      auto-expandable node flag
    • setAutoExpandable

      public void setAutoExpandable(boolean autoExpandable)
      Change auto-expandable flag - node will be expanded if it has only one child when expanding parent node.
      Parameters:
      autoExpandable - true if node is auto-expandable
    • removeLoadingNode

      protected void removeLoadingNode()
    • isNodeUpdated

      public boolean isNodeUpdated()
    • setNodeUpdated

      public void setNodeUpdated(boolean value)
    • getPriorityInOwner

      public int getPriorityInOwner()
      Returns:
      priority in owner for sorting
    • setPriorityInOwner

      public void setPriorityInOwner(int priority)
      Set priority in owner for sorting
      Parameters:
      priority - priority
    • createSpecificRemoveCommand

      @CheckForNull public com.nomagic.magicdraw.commands.Command createSpecificRemoveCommand()
      Creates specific command for removing
      Returns:
      specific command for node removing
    • isSpecificElement

      public boolean isSpecificElement()
      Returns:
      true if element is specific