Skip to content

Commit

Permalink
Merge pull request #2508 from bardsoftware/tkt-2235-ignore-attachment…
Browse files Browse the repository at this point in the history
…s-where-necessary

Updates on the links in the table
  • Loading branch information
dbarashev authored Aug 2, 2024
2 parents 30cff7e + 8539e1b commit 6106f90
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ of the License, or (at your option) any later version.

import biz.ganttproject.core.table.ColumnList;
import biz.ganttproject.core.table.ColumnList.Column;
import com.google.common.base.Predicate;

import javax.swing.*;
import java.awt.*;
import java.math.BigDecimal;
import java.util.*;
import java.util.List;
import java.util.function.Predicate;

/**
* Enumeration of built-in task properties.
Expand All @@ -36,21 +36,23 @@ of the License, or (at your option) any later version.
public enum TaskDefaultColumn {
TYPE(new ColumnList.ColumnStub("tpd0", null, false, -1, -1), Icon.class, "tableColType"),
PRIORITY(new ColumnList.ColumnStub("tpd1", null, false, -1, 50), Icon.class, "tableColPriority"),
INFO(new ColumnList.ColumnStub("tpd2", null, false, -1, -1), Icon.class, "tableColInfo", Functions.NOT_EDITABLE),
INFO(new ColumnList.ColumnStub("tpd2", null, false, -1, -1), Icon.class, "tableColInfo", Functions.NOT_EDITABLE, true),
NAME(new ColumnList.ColumnStub("tpd3", null, true, 0, 200), String.class, "tableColName"),
BEGIN_DATE(new ColumnList.ColumnStub("tpd4", null, true, 1, 75), GregorianCalendar.class, "tableColBegDate", Functions.ALWAYS_EDITABLE),
END_DATE(new ColumnList.ColumnStub("tpd5", null, true, 2, 75), GregorianCalendar.class, "tableColEndDate", Functions.ALWAYS_EDITABLE),
DURATION(new ColumnList.ColumnStub("tpd6", null, false, -1, 50), Integer.class, "tableColDuration", null),
BEGIN_DATE(new ColumnList.ColumnStub("tpd4", null, true, 1, 75), GregorianCalendar.class, "tableColBegDate", Functions.ALWAYS_EDITABLE, false),
END_DATE(new ColumnList.ColumnStub("tpd5", null, true, 2, 75), GregorianCalendar.class, "tableColEndDate", Functions.ALWAYS_EDITABLE, false),
DURATION(new ColumnList.ColumnStub("tpd6", null, false, -1, 50), Integer.class, "tableColDuration", null, false),
COMPLETION(new ColumnList.ColumnStub("tpd7", null, false, -1, 50), Integer.class, "tableColCompletion"),
COORDINATOR(new ColumnList.ColumnStub("tpd8", null, false, -1, 200), String.class, "tableColCoordinator", Functions.NOT_EDITABLE),
COORDINATOR(new ColumnList.ColumnStub("tpd8", null, false, -1, 200), String.class, "tableColCoordinator", Functions.NOT_EDITABLE, false),
PREDECESSORS(new ColumnList.ColumnStub("tpd9", null, false, -1, 200), String.class, "tableColPredecessors"),
ID(new ColumnList.ColumnStub("tpd10", null, false, -1, 20), Integer.class, "tableColID", Functions.NOT_EDITABLE),
OUTLINE_NUMBER(new ColumnList.ColumnStub("tpd11", null, false, 4, 20), String.class, "tableColOutline", Functions.NOT_EDITABLE),
ID(new ColumnList.ColumnStub("tpd10", null, false, -1, 20), Integer.class, "tableColID", Functions.NOT_EDITABLE, false),
OUTLINE_NUMBER(new ColumnList.ColumnStub("tpd11", null, false, 4, 20), String.class, "tableColOutline", Functions.NOT_EDITABLE, false),
COST(new ColumnList.ColumnStub("tpd12", null, false, -1, 20), BigDecimal.class, "tableColCost"),
RESOURCES(new ColumnList.ColumnStub("tpd13", null, false, -1, 20), String.class, "resources", Functions.NOT_EDITABLE),
COLOR(new ColumnList.ColumnStub("tpd14", null, false, -1, 20), Color.class, "option.taskDefaultColor.label"),
NOTES(new ColumnList.ColumnStub("tpd15", null, true, -1, 20), String.class, "notes"),
ATTACHMENTS(new ColumnList.ColumnStub("tpd16", null, false, -1, 20), Icon.class, "webLink");
RESOURCES(new ColumnList.ColumnStub("tpd13", null, false, -1, 20), String.class, "resources", Functions.NOT_EDITABLE, false),
COLOR(new ColumnList.ColumnStub("tpd14", null, false, -1, 20), Color.class, "option.taskDefaultColor.label", null, true),
NOTES(new ColumnList.ColumnStub("tpd15", null, true, -1, 20), String.class, "notes", null, true),
ATTACHMENTS(new ColumnList.ColumnStub("tpd16", null, false, -1, 20), Icon.class, "webLink", null, true);

private final boolean myIsIconified;

public interface LocaleApi {
String i18n(String key);
Expand All @@ -68,14 +70,15 @@ public static void setLocaleApi(LocaleApi localeApi) {
private Comparator<?> mySortComparator;

TaskDefaultColumn(ColumnList.Column delegate, Class<?> valueClass, String nameKey) {
this(delegate, valueClass, nameKey, Functions.ALWAYS_EDITABLE);
this(delegate, valueClass, nameKey, Functions.ALWAYS_EDITABLE, false);
}

TaskDefaultColumn(ColumnList.Column delegate, Class<?> valueClass, String nameKey, Predicate<? extends Object> isEditable) {
TaskDefaultColumn(ColumnList.Column delegate, Class<?> valueClass, String nameKey, Predicate<? extends Object> isEditable, boolean isIconified) {
myDelegate = delegate;
myValueClass = valueClass;
myIsEditablePredicate= isEditable;
myNameKey = nameKey;
myIsIconified = isIconified;
}

public Comparator<?> getSortComparator() {
Expand Down Expand Up @@ -118,7 +121,11 @@ public <T> void setIsEditablePredicate(Predicate<T> predicate) {
}

public <T> boolean isEditable(T task) {
return myIsEditablePredicate == null ? true : ((Predicate<T>)myIsEditablePredicate).apply(task);
return myIsEditablePredicate == null || ((Predicate<T>) myIsEditablePredicate).test(task);
}

public boolean isIconified() {
return myIsIconified;
}

public String getNameKey() {
Expand All @@ -131,7 +138,6 @@ public String getName() {

public static class Functions {
static Predicate<Object> NOT_EDITABLE = input -> false;

static Predicate<Object> ALWAYS_EDITABLE = input -> true;

public static Comparator<String> OUTLINE_NUMBER_COMPARATOR = (s1, s2) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ class TaskTable(
{ onColumnsChange() },
BuiltinColumns(
isZeroWidth = {
when (TaskDefaultColumn.find(it)) {
TaskDefaultColumn.COLOR, TaskDefaultColumn.INFO, TaskDefaultColumn.NOTES -> true
val defaultColumn = TaskDefaultColumn.find(it)
when {
defaultColumn.isIconified -> true
else -> false
}
},
Expand Down Expand Up @@ -545,9 +546,10 @@ class TaskTable(
if (anyDifference(filteredColumns, treeTable.columns.map { it.userData as ColumnList.Column }.toList())) {
val tableColumns =
columns.mapNotNull { column ->
when (val taskDefaultColumn = TaskDefaultColumn.find(column.id)) {
TaskDefaultColumn.COLOR, TaskDefaultColumn.INFO, TaskDefaultColumn.NOTES-> null
null -> createCustomColumn(column)
val taskDefaultColumn = TaskDefaultColumn.find(column.id)
when {
taskDefaultColumn == null -> createCustomColumn(column)
taskDefaultColumn.isIconified -> null
else -> createDefaultColumn(column, taskDefaultColumn)
}?.also {
it.prefWidth = column.width.toDouble()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ private void writeTasks(SpreadsheetWriter writer) throws IOException {
break;
case INFO:
case TYPE:
case ATTACHMENTS:
default:
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected String i18n(String key) {
}

private Set<String> IGNORED_COLUMNS = Sets.newHashSet(
TaskDefaultColumn.NOTES.getStub().getID(), TaskDefaultColumn.INFO.getStub().getID()
TaskDefaultColumn.NOTES.getStub().getID(), TaskDefaultColumn.INFO.getStub().getID(), TaskDefaultColumn.ATTACHMENTS.getStub().getID()
);
protected void writeColumns(ColumnList visibleFields, TransformerHandler handler) throws SAXException {
AttributesImpl attrs = new AttributesImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,9 @@ private void writeResourceChart() {
private PdfPTable createTableHeader(ColumnList tableHeader, ArrayList<Column> orderedColumns) {
for (int i = 0; i < tableHeader.getSize(); i++) {
Column c = tableHeader.getField(i);
if (c.isVisible() && !c.getID().equals(TaskDefaultColumn.NOTES.getStub().getID())) {
if (c.isVisible()
&& !c.getID().equals(TaskDefaultColumn.NOTES.getStub().getID())
&& !c.getID().equals(TaskDefaultColumn.ATTACHMENTS.getStub().getID())) {
orderedColumns.add(c);
}
}
Expand All @@ -420,7 +422,10 @@ private PdfPTable createTableHeader(ColumnList tableHeader, ArrayList<Column> or
PdfPTable table = new PdfPTable(widths);
table.setWidthPercentage(95);
for (Column field : orderedColumns) {
if (field.isVisible() && !field.getID().equals(TaskDefaultColumn.NOTES.getStub().getID())) {
if (field.isVisible() &&
!field.getID().equals(TaskDefaultColumn.NOTES.getStub().getID()) &&
!field.getID().equals(TaskDefaultColumn.ATTACHMENTS.getStub().getID())) {

PdfPCell cell;
if (field.getID().equals(TaskDefaultColumn.COLOR.getStub().getID())) {
cell = new PdfPCell();
Expand Down Expand Up @@ -461,7 +466,7 @@ private void writeProperties(ArrayList<Column> orderedColumns, Map<String, Strin
if (value == null) {
value = "";
}
if (TaskDefaultColumn.NOTES.getStub().getID().equals(column.getID())) {
if (TaskDefaultColumn.NOTES.getStub().getID().equals(column.getID()) || TaskDefaultColumn.ATTACHMENTS.getStub().getID().equals(column.getID())) {
continue;
}
if (TaskDefaultColumn.COLOR.getStub().getID().equals(column.getID())) {
Expand Down

0 comments on commit 6106f90

Please sign in to comment.