OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 17 | Rev 73 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.openoffice.text;
15
 
25 ilm 16
import org.openconcerto.openoffice.ODDocument;
17 ilm 17
import org.openconcerto.openoffice.StyleStyle;
18
import org.openconcerto.openoffice.StyledNode;
19
 
20
import org.jdom.Element;
21
 
22
/**
23
 * A text node that can be created ex nihilo. Ie without a document at first.
24
 *
25
 * @author Sylvain CUAZ
26
 *
27
 * @param <S> type of style.
28
 */
25 ilm 29
public abstract class TextNode<S extends StyleStyle> extends StyledNode<S, TextDocument> {
17 ilm 30
 
25 ilm 31
    protected TextDocument parent;
17 ilm 32
 
33
    public TextNode(Element local, final Class<S> styleClass) {
25 ilm 34
        this(local, styleClass, null);
35
    }
36
 
37
    protected TextNode(Element local, final Class<S> styleClass, final TextDocument parent) {
17 ilm 38
        super(local, styleClass);
25 ilm 39
        this.parent = parent;
17 ilm 40
    }
41
 
42
    @Override
25 ilm 43
    public final TextDocument getODDocument() {
17 ilm 44
        return this.parent;
45
    }
46
 
25 ilm 47
    public final void setDocument(TextDocument doc) {
17 ilm 48
        if (doc != this.parent) {
49
            if (doc == null) {
50
                this.parent = null;
51
                this.getElement().detach();
25 ilm 52
            } else if (doc.getContentDocument() != this.getElement().getDocument()) {
17 ilm 53
                doc.add(this);
25 ilm 54
            } else {
17 ilm 55
                this.checkDocument(doc);
56
                this.parent = doc;
57
            }
58
        }
59
    }
60
 
25 ilm 61
    protected abstract void checkDocument(ODDocument doc);
17 ilm 62
}