Java Code Examples for org.jdom2.Element#indexOf()

The following examples show how to use org.jdom2.Element#indexOf() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * This method moves an element (entry-node or bullet-point) one position
 * up- or downwards, depending on the parameter {@code movement}.
 *
 * @param movement indicates whether the element should be moved up or down.
 * use following constants:<br> - {@code CConstants.MOVE_UP}<br> -
 * {@code CConstants.MOVE_DOWN}<br>
 * @param timestamp
 */
public void moveElement(int movement, String timestamp) {
    // get the selected element, independent from whether it's a node or a bullet
    Element e = findEntryElementFromTimestamp(getCurrentDesktopElement(), timestamp);
    if (e != null) {
        // get the element's parent
        Element p = e.getParentElement();
        // get the index of the element that should be moved
        int index = p.indexOf(e);
        // remove the element that should be moved
        Element dummy = (Element) p.removeContent(index);
        try {
            // and insert element one index-position below the previous index-position
            p.addContent((Constants.MOVE_UP == movement) ? index - 1 : index + 1, dummy);
            // change modifed state
            setModified(true);
        } catch (IllegalAddException ex) {
            Constants.zknlogger.log(Level.WARNING, ex.getLocalizedMessage());
        }
    }
}
 
Example 2
protected int indexInParent() {
  if (indexInParent < -1) {
    final Element parent = getParentElement();
    indexInParent = parent == null ? -1 : parent.indexOf(this);
  }
  return indexInParent;
}
 
Example 3
public int indexInParent() {
    if(indexInParent < -1) {
        final Element parent = getParentElement();
        indexInParent =  parent == null ? -1 : parent.indexOf(this);
    }
    return indexInParent;
}
 
Example 4
public void insert(int pos) throws JaxenException {
    if ("build".equals(method)) {
        Element parentElement = getParentElement();
        Element precedingElement = (Element) (getBoundNodes().get(pos - 1));
        int posOfPrecedingInParent = parentElement.indexOf(precedingElement);
        int targetPos = posOfPrecedingInParent + 1;
        String pathToBuild = getElementNameWithPredicates();
        Element newElement = (Element) (new MCRNodeBuilder().buildNode(pathToBuild, null, null));
        parentElement.addContent(targetPos, newElement);
        boundNodes.add(pos, newElement);
        track(MCRAddedElement.added(newElement));
    } else {
        cloneBoundElement(pos - 1);
    }
}
 
Example 5
Source Project: mycore   File: MCRBinding.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Element cloneBoundElement(int index) {
    Element template = (Element) (boundNodes.get(index));
    Element newElement = template.clone();
    Element parent = template.getParentElement();
    int indexInParent = parent.indexOf(template) + 1;
    parent.addContent(indexInParent, newElement);
    boundNodes.add(index + 1, newElement);
    trackNodeCreated(newElement);
    return newElement;
}
 
Example 6
public static MCRChangeData remove(Element element) {
    Element parent = element.getParentElement();
    MCRChangeData data = new MCRChangeData("removed-element", element, parent.indexOf(element), parent);
    element.detach();
    return data;
}
 
Example 7
public static MCRChangeData swap(Element parent, Element a, Element b) {
    int posA = parent.indexOf(a);
    int posB = parent.indexOf(b);
    return swap(parent, posA, a, posB, b);
}