1
1
package org .jabref .gui .maintable ;
2
2
3
+ import java .util .EnumSet ;
3
4
import java .util .Objects ;
4
5
5
6
import javafx .beans .property .DoubleProperty ;
9
10
import javafx .beans .property .SimpleObjectProperty ;
10
11
import javafx .beans .property .SimpleStringProperty ;
11
12
import javafx .beans .property .StringProperty ;
13
+ import javafx .scene .control .TableColumn ;
12
14
13
15
import org .jabref .gui .util .FieldsUtil ;
14
16
import org .jabref .logic .l10n .Localization ;
@@ -35,6 +37,8 @@ public enum Type {
35
37
NORMALFIELD ("field" ),
36
38
SPECIALFIELD ("special" , Localization .lang ("Special" ));
37
39
40
+ public static final EnumSet <Type > ICON_COLUMNS = EnumSet .of (EXTRAFILE ,FILES ,GROUPS ,LINKED_IDENTIFIER );
41
+
38
42
private String name ;
39
43
private String displayName ;
40
44
@@ -67,35 +71,54 @@ public static Type fromString(String text) {
67
71
}
68
72
}
69
73
70
- private final ObjectProperty <Type > typeProperty ;
71
- private final StringProperty qualifierProperty ;
72
- private final DoubleProperty widthProperty ;
74
+ private final ObjectProperty <Type > typeProperty = new SimpleObjectProperty <>();
75
+ private final StringProperty qualifierProperty = new SimpleStringProperty ();
76
+ private final DoubleProperty widthProperty = new SimpleDoubleProperty ();
77
+ private final ObjectProperty <TableColumn .SortType > sortTypeProperty = new SimpleObjectProperty <>();
73
78
74
79
/**
75
80
* This is used by the preferences dialog, to initialize available columns the user can add to the table.
76
81
*
77
- * @param type the {@code MainTableColumnModel.Type} of the column, e.g. "NORMALFIELD" or "GROUPS "
82
+ * @param type the {@code MainTableColumnModel.Type} of the column, e.g. "NORMALFIELD" or "EXTRAFILE "
78
83
* @param qualifier the stored qualifier of the column, e.g. "author/editor"
79
84
*/
80
- public MainTableColumnModel (Type type , String qualifier , double width ) {
85
+ public MainTableColumnModel (Type type , String qualifier ) {
81
86
Objects .requireNonNull (type );
82
- typeProperty = new SimpleObjectProperty <>(type );
83
- qualifierProperty = new SimpleStringProperty (qualifier );
84
- widthProperty = new SimpleDoubleProperty (width );
85
- }
87
+ Objects .requireNonNull (qualifier );
86
88
87
- public MainTableColumnModel ( Type type , String qualifier ) {
88
- this ( type , qualifier , ColumnPreferences . DEFAULT_WIDTH );
89
- }
89
+ this . typeProperty . setValue ( type );
90
+ this . qualifierProperty . setValue ( qualifier );
91
+ this . sortTypeProperty . setValue ( TableColumn . SortType . ASCENDING );
90
92
91
- public MainTableColumnModel (Type type , double width ) {
92
- this (type , "" , width );
93
+ if (Type .ICON_COLUMNS .contains (type )) {
94
+ this .widthProperty .setValue (ColumnPreferences .ICON_COLUMN_WIDTH );
95
+ } else {
96
+ this .widthProperty .setValue (ColumnPreferences .DEFAULT_COLUMN_WIDTH );
97
+ }
93
98
}
94
99
100
+ /**
101
+ * This is used by the preferences dialog, to initialize available basic icon columns, the user can add to the table.
102
+ *
103
+ * @param type the {@code MainTableColumnModel.Type} of the column, e.g. "GROUPS" or "LINKED_IDENTIFIER"
104
+ */
95
105
public MainTableColumnModel (Type type ) {
96
106
this (type , "" );
97
107
}
98
108
109
+ /**
110
+ * This is used by the preference migrations.
111
+ *
112
+ * @param type the {@code MainTableColumnModel.Type} of the column, e.g. "NORMALFIELD" or "GROUPS"
113
+ * @param qualifier the stored qualifier of the column, e.g. "author/editor"
114
+ * @param width the stored width of the column
115
+ */
116
+ public MainTableColumnModel (Type type , String qualifier , double width ) {
117
+ this (type , qualifier );
118
+
119
+ this .widthProperty .setValue (width );
120
+ }
121
+
99
122
public Type getType () { return typeProperty .getValue (); }
100
123
101
124
public String getQualifier () { return qualifierProperty .getValue (); }
@@ -109,10 +132,7 @@ public String getName() {
109
132
}
110
133
111
134
public String getDisplayName () {
112
- if ((typeProperty .getValue () == Type .GROUPS
113
- || typeProperty .getValue () == Type .FILES
114
- || typeProperty .getValue () == Type .LINKED_IDENTIFIER )
115
- && qualifierProperty .getValue ().isBlank ()) {
135
+ if (Type .ICON_COLUMNS .contains (typeProperty .getValue ()) && qualifierProperty .getValue ().isBlank ()) {
116
136
return typeProperty .getValue ().getDisplayName ();
117
137
} else {
118
138
return FieldsUtil .getNameWithType (FieldFactory .parseField (qualifierProperty .getValue ()));
@@ -121,12 +141,14 @@ public String getDisplayName() {
121
141
122
142
public StringProperty nameProperty () { return new ReadOnlyStringWrapper (getDisplayName ()); }
123
143
124
- public double getWidth () {
125
- return widthProperty .get ();
126
- }
144
+ public double getWidth () { return widthProperty .getValue (); }
127
145
128
146
public DoubleProperty widthProperty () { return widthProperty ; }
129
147
148
+ public TableColumn .SortType getSortType () { return sortTypeProperty .getValue (); }
149
+
150
+ public ObjectProperty <TableColumn .SortType > sortTypeProperty () { return sortTypeProperty ; }
151
+
130
152
public boolean equals (Object o ) {
131
153
if (this == o ) {
132
154
return true ;
@@ -149,23 +171,11 @@ public int hashCode() {
149
171
}
150
172
151
173
/**
152
- * This is used by JabRefPreferences, to create a new ColumnModel out ouf the stored preferences.
174
+ * This creates a new {@code MainTableColumnModel} out of a given string
153
175
*
154
- * @param rawColumnName the stored name of the column, e.g. "field:author"
155
- * @param width the stored width of the column
156
- */
157
- public static MainTableColumnModel parse (String rawColumnName , Double width ) {
158
- MainTableColumnModel columnModel = parse (rawColumnName );
159
-
160
- Objects .requireNonNull (width );
161
- columnModel .widthProperty ().setValue (width );
162
- return columnModel ;
163
- }
164
-
165
- /**
166
- * This is used by the preferences dialog, to allow the user to type in a field he wants to add to the table.
176
+ * @param rawColumnName the name of the column, e.g. "field:author", or "author"
167
177
*
168
- * @param rawColumnName the stored name of the column, e.g. "field:author", or "author"
178
+ * @return A new {@code MainTableColumnModel}
169
179
*/
170
180
public static MainTableColumnModel parse (String rawColumnName ) {
171
181
Objects .requireNonNull (rawColumnName );
@@ -174,7 +184,9 @@ public static MainTableColumnModel parse(String rawColumnName) {
174
184
Type type = Type .fromString (splittedName [0 ]);
175
185
String qualifier = "" ;
176
186
177
- if (type == Type .NORMALFIELD || type == Type .SPECIALFIELD || type == Type .EXTRAFILE ) {
187
+ if (type == Type .NORMALFIELD
188
+ || type == Type .SPECIALFIELD
189
+ || type == Type .EXTRAFILE ) {
178
190
if (splittedName .length == 1 ) {
179
191
qualifier = splittedName [0 ]; // By default the rawColumnName is parsed as NORMALFIELD
180
192
} else {
0 commit comments