-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revise maintable #452
Merged
+939
−925
Merged
Revise maintable #452
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
592fbb0
Allow dragging of special fields
matthiasgeiger 84389b3
move maintable related classes to new package
matthiasgeiger cba3e64
add class for tableColumns in MainTable
matthiasgeiger 45ca5d3
first running version with MainTableColumn without any contents
matthiasgeiger 02c5336
MainTable is showing right contents again
matthiasgeiger 3bfeece
Add flag to identify iconColumns
matthiasgeiger 6f2d871
reenable setting of width
matthiasgeiger 8809b4e
remove unused method
matthiasgeiger 63e67cc
reenable comparators in maintable
matthiasgeiger 6f83c0f
improve formatting
matthiasgeiger daf80eb
reenable right-click menus
matthiasgeiger 5993ca2
finalize fields
matthiasgeiger 6d91ad4
use list instead of array for MainTableColumn and IconComparator
matthiasgeiger 01a14e0
left-click menus are working again - exception file type filtering co…
matthiasgeiger ca8972b
file filter columns are working again
matthiasgeiger e2a195d
remove PDF/PS column and its configuration from maintable
matthiasgeiger 29df5a6
showing tooltip for main table header fields
matthiasgeiger 18ac857
show icons in header for iconColumns
matthiasgeiger a3631a9
Remove obsolete option "Show one letter heading for special columns"
matthiasgeiger e98a231
Show tooltip for columns which are not fully displayed
matthiasgeiger 5642c3d
removing some unused methods
matthiasgeiger e4ff917
cleanup
matthiasgeiger 7c28c19
improvements based on review comments
matthiasgeiger e262daa
fix missing header for numberCol
matthiasgeiger bc55dcf
change default order for maintable
matthiasgeiger 9f5e3fb
add CHANGELOG information
matthiasgeiger 2f9e9f8
minor changes
matthiasgeiger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
179 changes: 0 additions & 179 deletions
179
src/main/java/net/sf/jabref/gui/PreventDraggingJTableHeader.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
src/main/java/net/sf/jabref/gui/maintable/MainTableColumn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package net.sf.jabref.gui.maintable; | ||
|
||
import net.sf.jabref.gui.BibtexFields; | ||
import net.sf.jabref.model.database.BibtexDatabase; | ||
import net.sf.jabref.model.entry.BibtexEntry; | ||
import net.sf.jabref.model.entry.EntryUtil; | ||
|
||
import javax.swing.*; | ||
import java.util.*; | ||
|
||
public class MainTableColumn { | ||
|
||
private final String columnName; | ||
|
||
private final List<String> bibtexFields; | ||
|
||
private final boolean isIconColumn; | ||
|
||
private final Optional<JLabel> iconLabel; | ||
|
||
private final Optional<BibtexDatabase> database; | ||
|
||
public MainTableColumn(String columnName) { | ||
this.columnName = columnName; | ||
this.bibtexFields = Collections.emptyList(); | ||
this.isIconColumn = false; | ||
this.iconLabel = Optional.empty(); | ||
this.database = Optional.empty(); | ||
} | ||
|
||
public MainTableColumn(String columnName, String[] bibtexFields, BibtexDatabase database) { | ||
this.columnName = columnName; | ||
this.bibtexFields = Collections.unmodifiableList(Arrays.asList(bibtexFields)); | ||
this.isIconColumn = false; | ||
this.iconLabel = Optional.empty(); | ||
this.database = Optional.of(database); | ||
} | ||
|
||
public MainTableColumn(String columnName, String[] bibtexFields, JLabel iconLabel) { | ||
this.columnName = columnName; | ||
this.bibtexFields = Collections.unmodifiableList(Arrays.asList(bibtexFields)); | ||
this.isIconColumn = true; | ||
this.iconLabel = Optional.of(iconLabel); | ||
this.database = Optional.empty(); | ||
} | ||
|
||
/** | ||
* Get the table column name to be displayed in the UI | ||
* | ||
* @return name to be displayed | ||
*/ | ||
public String getDisplayName() { | ||
if (bibtexFields.isEmpty()) { | ||
return null; | ||
} | ||
|
||
StringJoiner joiner = new StringJoiner(MainTableFormat.COL_DEFINITION_FIELD_SEPARATOR); | ||
for(String field : bibtexFields) { | ||
String fieldDisplayName = BibtexFields.getFieldDisplayName(field); | ||
if (fieldDisplayName != null) { | ||
joiner.add(fieldDisplayName); | ||
} else { | ||
joiner.add(EntryUtil.capitalizeFirst(field)); | ||
} | ||
} | ||
return joiner.toString(); | ||
} | ||
|
||
/** | ||
* Checks whether the column should display names | ||
* Relevant as name value format can be formatted. | ||
* | ||
* @return true if the bibtex fields contains author or editor | ||
*/ | ||
public boolean isNameColumn() { | ||
return bibtexFields.contains("author") || bibtexFields.contains("editor"); | ||
} | ||
|
||
public String getColumnName() { | ||
return columnName; | ||
} | ||
|
||
public List<String> getBibtexFields() { | ||
return bibtexFields; | ||
} | ||
|
||
public boolean isIconColumn() { | ||
return isIconColumn; | ||
} | ||
|
||
public boolean isFileFilter() { | ||
return false; // Overridden in SpecialMainTableColumns for file filter columns | ||
} | ||
|
||
public Object getColumnValue(BibtexEntry entry) { | ||
if(bibtexFields.isEmpty()) { | ||
return null; | ||
} | ||
|
||
String content = null; | ||
for (String field : bibtexFields) { | ||
if (field.equals(BibtexEntry.TYPE_HEADER)) { | ||
content = entry.getType().getName(); | ||
} else { | ||
content = entry.getFieldOrAlias(field); | ||
if (database.isPresent() && "Author".equalsIgnoreCase(columnName) && (content != null)) { | ||
content = database.get().resolveForStrings(content); | ||
} | ||
} | ||
if (content != null) { | ||
break; | ||
} | ||
} | ||
|
||
if (isNameColumn()) { | ||
return MainTableNameFormatter.formatName(content); | ||
} | ||
return content; | ||
|
||
} | ||
|
||
public JLabel getHeaderLabel() { | ||
if(isIconColumn) { | ||
return iconLabel.get(); | ||
} else { | ||
return new JLabel(getDisplayName()); | ||
} | ||
} | ||
} |
174 changes: 174 additions & 0 deletions
174
src/main/java/net/sf/jabref/gui/maintable/MainTableFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* Copyright (C) 2003-2012 JabRef contributors. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along | ||
with this program; if not, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
package net.sf.jabref.gui.maintable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import net.sf.jabref.gui.*; | ||
import net.sf.jabref.model.database.BibtexDatabase; | ||
import net.sf.jabref.model.entry.BibtexEntry; | ||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.JabRefPreferences; | ||
import net.sf.jabref.specialfields.SpecialFieldsUtils; | ||
import ca.odell.glazedlists.gui.TableFormat; | ||
|
||
import javax.swing.JLabel; | ||
|
||
/** | ||
* Class defining the contents and column headers of the main table. | ||
*/ | ||
public class MainTableFormat implements TableFormat<BibtexEntry> { | ||
// Character separating field names that are to be used in sequence as | ||
// fallbacks for a single column (e.g. "author/editor" to use editor where | ||
// author is not set): | ||
public static final String COL_DEFINITION_FIELD_SEPARATOR = "/"; | ||
|
||
// Values to gather iconImages for those columns | ||
// These values are also used to put a heading into the table; see getColumnName(int) | ||
private static final String[] URL_FIRST = {"url", "doi"}; | ||
private static final String[] DOI_FIRST = {"doi", "url"}; | ||
private static final String[] ARXIV = {"eprint"}; | ||
public static final String[] FILE = {Globals.FILE_FIELD}; | ||
|
||
private final BibtexDatabase database; | ||
|
||
private final List<MainTableColumn> tableColumns = new ArrayList<>(); | ||
|
||
public MainTableFormat(BibtexDatabase database) { | ||
this.database = database; | ||
} | ||
|
||
@Override | ||
public int getColumnCount() { | ||
return tableColumns.size(); | ||
} | ||
|
||
/** | ||
* @return the string that should be put in the column header | ||
*/ | ||
@Override | ||
public String getColumnName(int col) { | ||
|
||
return tableColumns.get(col).getDisplayName(); | ||
|
||
} | ||
|
||
public MainTableColumn getTableColumn(int index) { | ||
return tableColumns.get(index); | ||
} | ||
|
||
/** | ||
* Finds the column index for the given column name. | ||
* | ||
* @param colName The column name | ||
* @return The column index if any, or -1 if no column has that name. | ||
*/ | ||
public int getColumnIndex(String colName) { | ||
|
||
for (MainTableColumn tableColumn : tableColumns) { | ||
if (tableColumn.getColumnName().equalsIgnoreCase(colName)) { | ||
return tableColumns.lastIndexOf(tableColumn); | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
@Override | ||
public Object getColumnValue(BibtexEntry be, int col) { | ||
|
||
return tableColumns.get(col).getColumnValue(be); | ||
|
||
} | ||
|
||
public void updateTableFormat() { | ||
// clear existing column configuration | ||
tableColumns.clear(); | ||
|
||
// Add numbering column to tableColumns | ||
tableColumns.add(SpecialMainTableColumns.NUMBER_COL); | ||
|
||
// Add all file based columns | ||
if (Globals.prefs.getBoolean(JabRefPreferences.FILE_COLUMN)) { | ||
tableColumns.add(SpecialMainTableColumns.FILE_COLUMN); | ||
} | ||
|
||
if (Globals.prefs.getBoolean(JabRefPreferences.URL_COLUMN)) { | ||
if (Globals.prefs.getBoolean(JabRefPreferences.PREFER_URL_DOI)) { | ||
tableColumns.add(SpecialMainTableColumns | ||
.createIconColumn(JabRefPreferences.URL_COLUMN, MainTableFormat.DOI_FIRST, | ||
new JLabel(IconTheme.JabRefIcon.DOI.getSmallIcon()))); | ||
} else { | ||
tableColumns.add(SpecialMainTableColumns | ||
.createIconColumn(JabRefPreferences.URL_COLUMN, MainTableFormat.URL_FIRST, | ||
new JLabel(IconTheme.JabRefIcon.WWW.getSmallIcon()))); | ||
} | ||
|
||
} | ||
|
||
if (Globals.prefs.getBoolean(JabRefPreferences.ARXIV_COLUMN)) { | ||
tableColumns.add(SpecialMainTableColumns | ||
.createIconColumn(JabRefPreferences.ARXIV_COLUMN, MainTableFormat.ARXIV, | ||
new JLabel(IconTheme.JabRefIcon.WWW.getSmallIcon()))); | ||
} | ||
|
||
if (Globals.prefs.getBoolean(JabRefPreferences.EXTRA_FILE_COLUMNS)) { | ||
String[] desiredColumns = Globals.prefs.getStringArray(JabRefPreferences.LIST_OF_FILE_COLUMNS); | ||
for (String desiredColumn : desiredColumns) { | ||
tableColumns.add(SpecialMainTableColumns.createFileIconColumn(desiredColumn)); | ||
} | ||
} | ||
|
||
// Add 'normal' bibtex fields as configured in the preferences | ||
// Read table columns from prefs: | ||
String[] colSettings = Globals.prefs.getStringArray(JabRefPreferences.COLUMN_NAMES); | ||
|
||
for (String columnName : colSettings) { | ||
// stored column name will be used as columnName | ||
// There might be more than one field to display, e.g., "author/editor" or "date/year" - so split | ||
// at MainTableFormat.COL_DEFINITION_FIELD_SEPARATOR | ||
String[] fields = columnName.split(MainTableFormat.COL_DEFINITION_FIELD_SEPARATOR); | ||
tableColumns.add(new MainTableColumn(columnName, fields, database)); | ||
} | ||
|
||
|
||
// Add the "special" icon columns (e.g., ranking, file, ...) that are enabled in preferences. | ||
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SPECIALFIELDSENABLED)) { | ||
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RANKING)) { | ||
tableColumns.add(SpecialMainTableColumns.RANKING_COLUMN); | ||
} | ||
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RELEVANCE)) { | ||
tableColumns.add(SpecialMainTableColumns.RELEVANCE_COLUMN); | ||
} | ||
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_QUALITY)) { | ||
tableColumns.add(SpecialMainTableColumns.QUALITY_COLUMN); | ||
} | ||
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRIORITY)) { | ||
tableColumns.add(SpecialMainTableColumns.PRIORITY_COLUMN); | ||
} | ||
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRINTED)) { | ||
tableColumns.add(SpecialMainTableColumns.PRINTED_COLUMN); | ||
} | ||
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_READ)) { | ||
tableColumns.add(SpecialMainTableColumns.READ_STATUS_COLUMN); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/net/sf/jabref/gui/maintable/MainTableNameFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package net.sf.jabref.gui.maintable; | ||
|
||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.JabRefPreferences; | ||
import net.sf.jabref.model.entry.AuthorList; | ||
|
||
public class MainTableNameFormatter { | ||
|
||
/** | ||
* Format a name field for the table, according to user preferences. | ||
* | ||
* @param nameToFormat The contents of the name field. | ||
* @return The formatted name field. | ||
*/ | ||
public static String formatName(String nameToFormat) { | ||
if (nameToFormat == null) { | ||
return null; | ||
} | ||
|
||
// Read name format options: | ||
boolean namesNatbib = Globals.prefs.getBoolean(JabRefPreferences.NAMES_NATBIB); //MK: | ||
boolean namesLastOnly = Globals.prefs.getBoolean(JabRefPreferences.NAMES_LAST_ONLY); | ||
boolean namesAsIs = Globals.prefs.getBoolean(JabRefPreferences.NAMES_AS_IS); | ||
boolean abbr_names = Globals.prefs.getBoolean(JabRefPreferences.ABBR_AUTHOR_NAMES); //MK: | ||
boolean namesFf = Globals.prefs.getBoolean(JabRefPreferences.NAMES_FIRST_LAST); | ||
boolean namesLf = !(namesAsIs || namesFf || namesNatbib || namesLastOnly); // None of the above. | ||
|
||
if (namesAsIs) { | ||
return nameToFormat; | ||
} else if (namesNatbib) { | ||
nameToFormat = AuthorList.fixAuthor_Natbib(nameToFormat); | ||
} else if (namesLastOnly) { | ||
nameToFormat = AuthorList.fixAuthor_lastNameOnlyCommas(nameToFormat, false); | ||
} else if (namesFf) { | ||
nameToFormat = AuthorList.fixAuthor_firstNameFirstCommas(nameToFormat, abbr_names, false); | ||
} else if (namesLf) { | ||
nameToFormat = AuthorList.fixAuthor_lastNameFirstCommas(nameToFormat, abbr_names, false); | ||
} | ||
return nameToFormat; | ||
} | ||
|
||
} |
290 changes: 124 additions & 166 deletions
290
...abref/gui/MainTableSelectionListener.java → ...maintable/MainTableSelectionListener.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
src/main/java/net/sf/jabref/gui/maintable/PreventDraggingJTableHeader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* Copyright (C) 2003-2015 JabRef contributors. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along | ||
with this program; if not, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
package net.sf.jabref.gui.maintable; | ||
|
||
import javax.swing.*; | ||
import javax.swing.table.JTableHeader; | ||
import javax.swing.table.TableCellRenderer; | ||
import javax.swing.table.TableColumn; | ||
import javax.swing.table.TableColumnModel; | ||
import java.awt.*; | ||
import java.awt.event.MouseEvent; | ||
import java.util.Enumeration; | ||
|
||
/** | ||
* Related to <code>MainTable</code> class. <br/> | ||
* Prevents dragging of the first header column ("#") and shows icons in the table header if an icon has to be set. | ||
* | ||
* This might not be the best way to solve this problem. Overriding | ||
* <code>getDraggedColumn</code> produces some ugly gui dragging artifacts if a | ||
* user attempts to drag something before the first columns. | ||
* | ||
* @author Daniel Waeber | ||
* @author Fabian Bieker | ||
* @since 12/2008 | ||
*/ | ||
class PreventDraggingJTableHeader extends JTableHeader implements TableCellRenderer { | ||
|
||
private final MainTableFormat tableFormat; | ||
|
||
private final TableCellRenderer delegate; | ||
|
||
public PreventDraggingJTableHeader(JTable table, MainTableFormat tableFormat) { | ||
super(table.getColumnModel()); | ||
this.setTable(table); | ||
this.tableFormat = tableFormat; | ||
this.delegate = table.getTableHeader().getDefaultRenderer(); | ||
setupTableHeaderIcons(); | ||
} | ||
|
||
private void setupTableHeaderIcons() { | ||
|
||
Enumeration<TableColumn> columns = columnModel.getColumns(); | ||
while(columns.hasMoreElements()) { | ||
TableColumn column = columns.nextElement(); | ||
column.setHeaderRenderer(this); | ||
MainTableColumn mainTableColumn = tableFormat.getTableColumn(column.getModelIndex()); | ||
column.setHeaderValue(mainTableColumn.getHeaderLabel()); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public String getToolTipText(MouseEvent event) { | ||
int index = columnModel.getColumnIndexAtX(event.getX()); | ||
int realIndex = columnModel.getColumn(index).getModelIndex(); | ||
MainTableColumn column = tableFormat.getTableColumn(realIndex); | ||
return column.getDisplayName(); | ||
} | ||
|
||
/** | ||
* Overridden to prevent dragging of first column ("#") | ||
*/ | ||
@Override | ||
public void setDraggedColumn(TableColumn column) { | ||
|
||
if (column != null) { | ||
// prevent dragging of "#" | ||
if (column.getModelIndex() == 0) { | ||
return; | ||
} | ||
} | ||
super.setDraggedColumn(column); | ||
} | ||
|
||
/** | ||
* Overridden to prevent dragging of an other column before the first column ("#"). | ||
*/ | ||
@Override | ||
public TableColumn getDraggedColumn() { | ||
TableColumn column = super.getDraggedColumn(); | ||
if (column != null) { | ||
PreventDraggingJTableHeader.preventDragBeforeNumberColumn(this.getTable(), column.getModelIndex()); | ||
} | ||
|
||
return column; | ||
} | ||
|
||
@Override | ||
public Component getTableCellRendererComponent(JTable table, Object value, | ||
boolean isSelected, boolean hasFocus, int row, int column) { | ||
|
||
// delegate to previously used TableCellRenderer which styles the component | ||
Component resultFromDelegate = delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); | ||
|
||
// Changing style is only possible if both value and resultFromDelegate are JLabels | ||
if (value instanceof JLabel && resultFromDelegate instanceof JLabel) { | ||
String text = ((JLabel) value).getText(); | ||
Icon icon = ((JLabel) value).getIcon(); | ||
if (icon != null) { | ||
((JLabel) resultFromDelegate).setIcon(icon); | ||
((JLabel) resultFromDelegate).setText(null); | ||
} else { | ||
((JLabel) resultFromDelegate).setText(text); | ||
} | ||
} | ||
|
||
return resultFromDelegate; | ||
} | ||
|
||
/** | ||
* Transform model index <code>modelIndex</code> to a view based index and | ||
* prevent dragging before model index <code>toIndex</code> (inclusive). | ||
*/ | ||
private static void preventDragBeforeNumberColumn(JTable table, int modelIndex) { | ||
|
||
for (int columnIndex = 0; columnIndex < table.getColumnCount(); columnIndex++) { | ||
|
||
TableColumn col = table.getColumnModel().getColumn(columnIndex); | ||
|
||
// found the element in the view ... | ||
// ... and check if it should not be dragged | ||
if ((col.getModelIndex() == modelIndex) && (columnIndex < 1)) { | ||
// prevent dragging (move it back ...) | ||
table.getColumnModel().moveColumn(columnIndex, 1); | ||
return; // we are done now | ||
} | ||
|
||
} | ||
} | ||
} |
193 changes: 193 additions & 0 deletions
193
src/main/java/net/sf/jabref/gui/maintable/SpecialMainTableColumns.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
package net.sf.jabref.gui.maintable; | ||
|
||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.external.ExternalFileType; | ||
import net.sf.jabref.gui.FileListTableModel; | ||
import net.sf.jabref.gui.GUIGlobals; | ||
import net.sf.jabref.gui.IconTheme; | ||
import net.sf.jabref.model.entry.BibtexEntry; | ||
import net.sf.jabref.model.entry.EntryUtil; | ||
import net.sf.jabref.specialfields.*; | ||
|
||
import javax.swing.*; | ||
|
||
public class SpecialMainTableColumns { | ||
|
||
public static final MainTableColumn NUMBER_COL = new MainTableColumn(GUIGlobals.NUMBER_COL) { | ||
|
||
@Override | ||
public Object getColumnValue(BibtexEntry entry) { | ||
return "#"; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "#"; | ||
} | ||
}; | ||
|
||
public static final MainTableColumn RANKING_COLUMN = new MainTableColumn(SpecialFieldsUtils.FIELDNAME_RANKING, | ||
new String[] {SpecialFieldsUtils.FIELDNAME_RANKING}, | ||
new JLabel(EntryUtil.capitalizeFirst(SpecialFieldsUtils.FIELDNAME_RANKING))) { | ||
|
||
@Override | ||
public Object getColumnValue(BibtexEntry entry) { | ||
SpecialFieldValue rank = Rank.getInstance().parse(entry.getField(SpecialFieldsUtils.FIELDNAME_RANKING)); | ||
if (rank != null) { | ||
return rank.createLabel(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
}; | ||
|
||
public static final MainTableColumn PRIORITY_COLUMN = new MainTableColumn(SpecialFieldsUtils.FIELDNAME_PRIORITY, | ||
new String[] {SpecialFieldsUtils.FIELDNAME_PRIORITY}, | ||
new JLabel(Priority.getInstance().getRepresentingIcon())) { | ||
|
||
@Override | ||
public Object getColumnValue(BibtexEntry entry) { | ||
|
||
SpecialFieldValue prio = Priority.getInstance() | ||
.parse(entry.getField(SpecialFieldsUtils.FIELDNAME_PRIORITY)); | ||
if (prio != null) { | ||
return prio.createLabel(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
}; | ||
|
||
public static final MainTableColumn READ_STATUS_COLUMN = new MainTableColumn(SpecialFieldsUtils.FIELDNAME_READ, | ||
new String[] {SpecialFieldsUtils.FIELDNAME_READ}, | ||
new JLabel(ReadStatus.getInstance().getRepresentingIcon())) { | ||
|
||
@Override | ||
public Object getColumnValue(BibtexEntry entry) { | ||
|
||
SpecialFieldValue status = ReadStatus.getInstance() | ||
.parse(entry.getField(SpecialFieldsUtils.FIELDNAME_READ)); | ||
if (status != null) { | ||
return status.createLabel(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
}; | ||
|
||
public static final MainTableColumn RELEVANCE_COLUMN = createIconColumn(SpecialFieldsUtils.FIELDNAME_RELEVANCE, | ||
new String[] {SpecialFieldsUtils.FIELDNAME_RELEVANCE}, | ||
new JLabel(Relevance.getInstance().getRepresentingIcon())); | ||
|
||
public static final MainTableColumn PRINTED_COLUMN = createIconColumn(SpecialFieldsUtils.FIELDNAME_PRINTED, | ||
new String[] {SpecialFieldsUtils.FIELDNAME_PRINTED}, | ||
new JLabel(Printed.getInstance().getRepresentingIcon())); | ||
|
||
public static final MainTableColumn QUALITY_COLUMN = createIconColumn(SpecialFieldsUtils.FIELDNAME_QUALITY, | ||
new String[] {SpecialFieldsUtils.FIELDNAME_QUALITY}, | ||
new JLabel(Quality.getInstance().getRepresentingIcon())); | ||
|
||
|
||
public static final MainTableColumn FILE_COLUMN = new MainTableColumn(Globals.FILE_FIELD, | ||
new String[] {Globals.FILE_FIELD}, new JLabel(IconTheme.JabRefIcon.FILE.getSmallIcon())) { | ||
|
||
@Override | ||
public Object getColumnValue(BibtexEntry entry) { | ||
// We use a FileListTableModel to parse the field content: | ||
FileListTableModel fileList = new FileListTableModel(); | ||
fileList.setContent(entry.getField(Globals.FILE_FIELD)); | ||
if (fileList.getRowCount() > 1) { | ||
return new JLabel(IconTheme.JabRefIcon.FILE_MULTIPLE.getSmallIcon()); | ||
} else if (fileList.getRowCount() == 1) { | ||
ExternalFileType type = fileList.getEntry(0).getType(); | ||
if (type != null) { | ||
return type.getIconLabel(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
}; | ||
|
||
/** | ||
* Creates a MainTableColumn which shows an icon instead textual content | ||
* | ||
* @param columnName the name of the column | ||
* @param fields the entry fields which should be shown | ||
* @return the crated MainTableColumn | ||
*/ | ||
public static MainTableColumn createIconColumn(String columnName, String[] fields, JLabel iconLabel) { | ||
return new MainTableColumn(columnName, fields, iconLabel) { | ||
|
||
@Override | ||
public Object getColumnValue(BibtexEntry entry) { | ||
JLabel iconLabel = null; | ||
boolean iconFound = false; | ||
|
||
// check for each field whether content is available | ||
for (String field : fields) { | ||
if (entry.getField(field) != null) { | ||
if (iconFound) { | ||
return new JLabel(IconTheme.JabRefIcon.FILE_MULTIPLE.getSmallIcon()); | ||
} else { | ||
iconLabel = GUIGlobals.getTableIcon(field); | ||
iconFound = true; | ||
} | ||
|
||
} | ||
} | ||
return iconLabel; | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* create a MainTableColumn for specific file types. | ||
* | ||
* Shows the icon for the given type (or the FILE_MULTIPLE icon) | ||
* | ||
* @param externalFileTypeName the name of the externalFileType | ||
* | ||
* @return the created MainTableColumn | ||
*/ | ||
public static MainTableColumn createFileIconColumn(String externalFileTypeName) { | ||
|
||
|
||
|
||
return new MainTableColumn(externalFileTypeName, new String[] {Globals.FILE_FIELD}, new JLabel()) { | ||
|
||
@Override | ||
public boolean isFileFilter() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return externalFileTypeName; | ||
} | ||
|
||
@Override | ||
public Object getColumnValue(BibtexEntry entry) { | ||
|
||
boolean iconFound = false; | ||
JLabel iconLabel = null; | ||
FileListTableModel fileList = new FileListTableModel(); | ||
fileList.setContent(entry.getField(Globals.FILE_FIELD)); | ||
for (int i = 0; i < fileList.getRowCount(); i++) { | ||
if (fileList.getEntry(i).getType() != null) { | ||
if (externalFileTypeName.equalsIgnoreCase(fileList.getEntry(i).getType().getName())) { | ||
if (iconFound) { | ||
// already found another file of the desired type - show FILE_MULTIPLE Icon | ||
return new JLabel(IconTheme.JabRefIcon.FILE_MULTIPLE.getSmallIcon()); | ||
} else { | ||
iconLabel = fileList.getEntry(i).getType().getIconLabel(); | ||
iconFound = true; | ||
} | ||
} | ||
} | ||
} | ||
return iconLabel; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this method every called with more than one field? Could it be simplified to just passing one field? (I don't like arrays :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, for "DOI/URL" resp. "URL/DOI".