View Javadoc
1   /*
2    * (c) Copyright 2013 Openflexo
3    *
4    * This file is part of OpenFlexo.
5    *
6    * OpenFlexo is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * OpenFlexo is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with OpenFlexo. If not, see <http://www.gnu.org/licenses/>.
18   *
19   */
20  
21  package org.openflexo.foundation.doc;
22  
23  import org.openflexo.foundation.technologyadapter.TechnologyAdapter;
24  import org.openflexo.pamela.annotations.Getter;
25  import org.openflexo.pamela.annotations.ModelEntity;
26  import org.openflexo.pamela.annotations.PropertyIdentifier;
27  import org.openflexo.pamela.annotations.Setter;
28  
29  /**
30   * Generic abstract concept representing a table cell in a table of a text-based document (eg .docx, .odt, etc...)
31   * 
32   * @author sylvain
33   *
34   * @param <D>
35   *            type of {@link FlexoDocument} involving this concept
36   * @param <TA>
37   *            {@link TechnologyAdapter} of current implementation
38   */
39  @ModelEntity(isAbstract = true)
40  public interface FlexoDocTableCell<D extends FlexoDocument<D, TA>, TA extends TechnologyAdapter<TA>>
41  		extends FlexoDocObject<D, TA>, FlexoDocElementContainer<D, TA> {
42  
43  	@PropertyIdentifier(type = FlexoDocTableRow.class)
44  	public static final String ROW_KEY = "row";
45  	// @PropertyIdentifier(type = FlexoDocParagraph.class, cardinality = Cardinality.LIST)
46  	// public static final String PARAGRAPHS_KEY = "paragraphs";
47  	@PropertyIdentifier(type = Integer.class)
48  	public static final String COL_SPAN_KEY = "colSpan";
49  	@PropertyIdentifier(type = Integer.class)
50  	public static final String ROW_SPAN_KEY = "rowSpan";
51  
52  	@Getter(ROW_KEY)
53  	public FlexoDocTableRow<D, TA> getRow();
54  
55  	@Setter(ROW_KEY)
56  	public void setRow(FlexoDocTableRow<D, TA> table);
57  
58  	/**
59  	 * Return the list of paragraphs in this cell
60  	 * 
61  	 * @return
62  	 */
63  	/*@Getter(value = PARAGRAPHS_KEY, cardinality = Cardinality.LIST, inverse = FlexoDocParagraph.CONTAINER_KEY)
64  	@XMLElement(primary = true)
65  	@CloningStrategy(StrategyType.CLONE)
66  	@Embedded
67  	public List<FlexoDocParagraph<D, TA>> getParagraphs();*/
68  
69  	// @Setter(PARAGRAPHS_KEY)
70  	// public void setParagraphs(List<FlexoDocParagraph<D, TA>> someParagraphs);
71  
72  	/**
73  	 * Add paragraph to this {@link FlexoDocTableCell} (public API).<br>
74  	 * Paragraph will be added to underlying technology-specific document model and {@link FlexoDocTableCell} will be updated accordingly
75  	 */
76  	/*@Adder(PARAGRAPHS_KEY)
77  	@PastingPoint
78  	public void addToParagraphs(FlexoDocParagraph<D, TA> anParagraph);
79  	*/
80  
81  	/**
82  	 * Remove paragraph from this {@link FlexoDocTableCell} (public API).<br>
83  	 * Paragraph will be removed to underlying technology-specific document model and {@link FlexoDocTableCell} will be updated accordingly
84  	 */
85  	// @Remover(PARAGRAPHS_KEY)
86  	// public void removeFromParagraphs(FlexoDocParagraph<D, TA> anParagraph);
87  
88  	/**
89  	 * Insert paragraph to this {@link FlexoDocTableCell} at supplied index (public API).<br>
90  	 * Paragraph will be inserted to underlying technology-specific document model and {@link FlexoDocTableCell} will be updated accordingly
91  	 */
92  	// public void insertParagraphAtIndex(FlexoDocParagraph<D, TA> anParagraph, int index);
93  
94  	/**
95  	 * Moved paragraph to this {@link FlexoDocTableCell} at supplied index (public API).<br>
96  	 * Paragraph will be moved inside underlying technology-specific document model and {@link FlexoDocTableCell} will be updated
97  	 * accordingly
98  	 */
99  	// public void moveParagraphToIndex(FlexoDocParagraph<D, TA> anParagraph, int index);
100 
101 	/**
102 	 * Return paragraph identified by identifier, or null if no such paragraph exists
103 	 */
104 	// public FlexoDocParagraph<D, TA> getParagraphWithIdentifier(String identifier);
105 
106 	/**
107 	 * Return index of the cell<br>
108 	 * Index of a run is the cell occurence in the row
109 	 * 
110 	 * @return
111 	 */
112 	public int getIndex();
113 
114 	/**
115 	 * Return identifier of the cell
116 	 * 
117 	 * @return
118 	 */
119 	public String getIdentifier();
120 
121 	@Getter(value = COL_SPAN_KEY, defaultValue = "1")
122 	public int getColSpan();
123 
124 	@Setter(COL_SPAN_KEY)
125 	public void setColSpan(int colSpan);
126 
127 	@Getter(value = ROW_SPAN_KEY, defaultValue = "1")
128 	public int getRowSpan();
129 
130 	@Setter(ROW_SPAN_KEY)
131 	public void setRowSpan(int rowSpan);
132 
133 	/**
134 	 * Return a string representation (plain text) of contents of the cell
135 	 * 
136 	 * @return
137 	 */
138 	public String getRawText();
139 
140 	/**
141 	 * Sets contents of the cell by erasing actual structure, and replacing it by a some paragraphs reflecting supplied text
142 	 * 
143 	 * @return
144 	 */
145 	public void setRawText(String someText);
146 
147 	/**
148 	 * Return element identified by identifier, asserting that this element exists in the table (eg a paragraph in a cell), or null if no
149 	 * such element exists
150 	 */
151 	@Override
152 	public FlexoDocElement<D, TA> getElementWithIdentifier(String identifier);
153 
154 	public static abstract class FlexoTableCellImpl<D extends FlexoDocument<D, TA>, TA extends TechnologyAdapter<TA>>
155 			extends FlexoDocObjectImpl<D, TA> implements FlexoDocTableCell<D, TA> {
156 
157 		@Override
158 		public int getIndex() {
159 			if (getRow() != null) {
160 				return getRow().getTableCells().indexOf(this);
161 			}
162 			return -1;
163 		}
164 
165 		@Override
166 		public String toString() {
167 			return "Cell" + getIndex();
168 		}
169 
170 	}
171 
172 }