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

The following examples show how to use org.jdom2.Element#indexOf() . 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
Source File: DesktopData.java    From Zettelkasten with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
Source File: InheritingElement.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
protected int indexInParent() {
  if (indexInParent < -1) {
    final Element parent = getParentElement();
    indexInParent = parent == null ? -1 : parent.indexOf(this);
  }
  return indexInParent;
}
 
Example 3
Source File: BoundedElement.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public int indexInParent() {
    if(indexInParent < -1) {
        final Element parent = getParentElement();
        indexInParent =  parent == null ? -1 : parent.indexOf(this);
    }
    return indexInParent;
}
 
Example 4
Source File: MCRRepeatBinding.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
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 File: MCRBinding.java    From mycore with 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
Source File: MCRRemoveElement.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
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
Source File: MCRSwapElements.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
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);
}