fiore@0
|
1 /*
|
fiore@0
|
2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
|
fiore@0
|
3
|
fiore@0
|
4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
|
fiore@0
|
5
|
fiore@0
|
6 This program is free software: you can redistribute it and/or modify
|
fiore@0
|
7 it under the terms of the GNU General Public License as published by
|
fiore@0
|
8 the Free Software Foundation, either version 3 of the License, or
|
fiore@0
|
9 (at your option) any later version.
|
fiore@0
|
10
|
fiore@0
|
11 This program is distributed in the hope that it will be useful,
|
fiore@0
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
fiore@0
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
fiore@0
|
14 GNU General Public License for more details.
|
fiore@0
|
15
|
fiore@0
|
16 You should have received a copy of the GNU General Public License
|
fiore@0
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
fiore@0
|
18 */
|
fiore@0
|
19 package uk.ac.qmul.eecs.ccmi.gui;
|
fiore@0
|
20
|
fiore@0
|
21 import java.util.HashSet;
|
fiore@0
|
22 import java.util.List;
|
fiore@0
|
23 import java.util.ArrayList;
|
fiore@0
|
24 import java.util.Set;
|
fiore@0
|
25
|
fiore@0
|
26 import javax.swing.table.AbstractTableModel;
|
fiore@0
|
27
|
fiore@0
|
28 import uk.ac.qmul.eecs.ccmi.diagrammodel.NodeProperties.Modifiers;
|
fiore@0
|
29
|
fiore@0
|
30
|
fiore@0
|
31 /**
|
fiore@5
|
32 * A table model containing the property values currently edited in a table of a {@code PropertyEditorDialog}
|
fiore@5
|
33 * and the modifiers assigned to them
|
fiore@0
|
34 * in the form of an array of indexes pointing to the modifiers types
|
fiore@0
|
35 */
|
fiore@0
|
36 @SuppressWarnings("serial")
|
fiore@0
|
37 public class PropertyTableModel extends AbstractTableModel {
|
fiore@5
|
38
|
fiore@5
|
39 /**
|
fiore@5
|
40 * Construct a new {@code PropertyTableModel}.
|
fiore@5
|
41 *
|
fiore@5
|
42 * @param propertyType the type of the node property related to this table model
|
fiore@5
|
43 * @param values the list of values for this node property
|
fiore@5
|
44 * @param modifiers the modifiers for this node property
|
fiore@5
|
45 */
|
fiore@0
|
46 public PropertyTableModel(String propertyType, List<String> values, Modifiers modifiers ){
|
fiore@0
|
47 data = new ArrayList<ModifierString>();
|
fiore@0
|
48 for(int i = 0; i< values.size();i++){
|
fiore@0
|
49 String value = values.get(i);
|
fiore@0
|
50 data.add(new ModifierString(value, (modifiers == null) ? null : modifiers.getIndexes(i)));
|
fiore@0
|
51 }
|
fiore@0
|
52 data.add(new ModifierString(null));
|
fiore@0
|
53 columnName = propertyType;
|
fiore@0
|
54 }
|
fiore@0
|
55
|
fiore@0
|
56 @Override
|
fiore@0
|
57 public int getColumnCount() {
|
fiore@0
|
58 return 1;
|
fiore@0
|
59 }
|
fiore@0
|
60
|
fiore@0
|
61 @Override
|
fiore@0
|
62 public int getRowCount() {
|
fiore@0
|
63 return data.size();
|
fiore@0
|
64 }
|
fiore@0
|
65
|
fiore@0
|
66 @Override
|
fiore@0
|
67 public Object getValueAt(int rowIndex, int columnIndex) {
|
fiore@0
|
68 return data.get(rowIndex);
|
fiore@0
|
69 }
|
fiore@0
|
70
|
fiore@0
|
71 @Override
|
fiore@0
|
72 public String getColumnName(int column){
|
fiore@0
|
73 return columnName;
|
fiore@0
|
74 }
|
fiore@0
|
75
|
fiore@0
|
76 @Override
|
fiore@0
|
77 public void setValueAt(Object value, int rowIndex, int columnIndex){
|
fiore@0
|
78 /* we filled up the last row, create another one */
|
fiore@0
|
79 if((rowIndex == data.size()-1)&&(!value.toString().equals(""))){
|
fiore@0
|
80 data.add(new ModifierString(null));
|
fiore@0
|
81 data.get(rowIndex).value = value.toString();
|
fiore@0
|
82 fireTableRowsInserted(data.size()-1, data.size()-1);
|
fiore@0
|
83 fireTableCellUpdated(rowIndex,columnIndex);
|
fiore@0
|
84 }else if((rowIndex != data.size()-1)&&(value.toString().equals(""))){
|
fiore@0
|
85 data.remove(rowIndex);
|
fiore@0
|
86 fireTableRowsDeleted(rowIndex,rowIndex);
|
fiore@0
|
87 }else {
|
fiore@0
|
88 data.get(rowIndex).value = value.toString();
|
fiore@0
|
89 fireTableCellUpdated(rowIndex,columnIndex);
|
fiore@0
|
90 }
|
fiore@0
|
91 }
|
fiore@0
|
92
|
fiore@0
|
93 @Override
|
fiore@0
|
94 public boolean isCellEditable(int rowIndex, int columnIndex){
|
fiore@0
|
95 return true;
|
fiore@0
|
96 }
|
fiore@0
|
97
|
fiore@5
|
98 /**
|
fiore@5
|
99 * Returns the indexes (pointing to the modifiers types) of the property value at the specified row in the table
|
fiore@5
|
100 * with this model.
|
fiore@5
|
101 *
|
fiore@5
|
102 * @param row the row of the property value
|
fiore@5
|
103 * @return the modifiers type indexes for the specified property value
|
fiore@5
|
104 */
|
fiore@0
|
105 public Set<Integer> getIndexesAt(int row){
|
fiore@0
|
106 return data.get(row).modifierIndexes;
|
fiore@0
|
107 }
|
fiore@0
|
108
|
fiore@5
|
109 /**
|
fiore@5
|
110 * Set the the indexes (pointing to the modifiers types) of the property value at the specified row in the table
|
fiore@5
|
111 * with this model.
|
fiore@5
|
112 *
|
fiore@5
|
113 * @param row he row of the property value
|
fiore@5
|
114 * @param indexes the modifiers type indexes for the specified property value
|
fiore@5
|
115 */
|
fiore@0
|
116 public void setIndexesAt(int row, Set<Integer> indexes){
|
fiore@0
|
117 data.get(row).modifierIndexes = new HashSet<Integer>();
|
fiore@0
|
118 data.get(row).modifierIndexes.addAll(indexes);
|
fiore@0
|
119 }
|
fiore@0
|
120
|
fiore@5
|
121 /**
|
fiore@5
|
122 * Set the the indexes (pointing to the modifiers types) of the property value at the specified row in the table
|
fiore@5
|
123 * with this model.
|
fiore@5
|
124 *
|
fiore@5
|
125 * @param row he row of the property value
|
fiore@5
|
126 * @param indexes the modifiers type indexes for the specified property value
|
fiore@5
|
127 */
|
fiore@0
|
128 public void setIndexesAt(int row, Integer[] indexes){
|
fiore@0
|
129 data.get(row).modifierIndexes = new HashSet<Integer>();
|
fiore@0
|
130 for(int i=0; i<indexes.length; i++)
|
fiore@0
|
131 data.get(row).modifierIndexes.add(indexes[i]);
|
fiore@0
|
132 }
|
fiore@0
|
133
|
fiore@5
|
134 private List<ModifierString> data;
|
fiore@5
|
135 private String columnName;
|
fiore@0
|
136
|
fiore@0
|
137 private class ModifierString {
|
fiore@0
|
138 ModifierString(String value, Set<Integer> s){
|
fiore@0
|
139 this.value = value;
|
fiore@0
|
140 modifierIndexes = new HashSet<Integer>();
|
fiore@0
|
141 if(s != null){
|
fiore@0
|
142 modifierIndexes.addAll(s);
|
fiore@0
|
143 }
|
fiore@0
|
144 }
|
fiore@0
|
145
|
fiore@0
|
146 ModifierString(Set<Integer> s){
|
fiore@0
|
147 this("",s);
|
fiore@0
|
148 }
|
fiore@0
|
149
|
fiore@0
|
150 @Override
|
fiore@0
|
151 public boolean equals(Object o){
|
fiore@0
|
152 return value.equals(o);
|
fiore@0
|
153 }
|
fiore@0
|
154
|
fiore@0
|
155 @Override
|
fiore@0
|
156 public int hashCode(){
|
fiore@0
|
157 return value.hashCode();
|
fiore@0
|
158 }
|
fiore@0
|
159
|
fiore@0
|
160 @Override
|
fiore@0
|
161 public String toString(){
|
fiore@0
|
162 return value;
|
fiore@0
|
163 }
|
fiore@0
|
164
|
fiore@5
|
165 private String value;
|
fiore@5
|
166 private Set<Integer> modifierIndexes;
|
fiore@0
|
167 }
|
fiore@0
|
168
|
fiore@0
|
169 }
|