Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.mylyn.trac.core')
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttributeMapper.java23
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracTaskDataHandler.java87
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/AbstractTracClient.java19
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/ITracClient.java2
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracClientData.java3
5 files changed, 89 insertions, 45 deletions
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttributeMapper.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttributeMapper.java
index be41f72ce..b6357e17f 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttributeMapper.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttributeMapper.java
@@ -81,35 +81,34 @@ public class TracAttributeMapper extends TaskAttributeMapper {
@Override
public Map<String, String> getOptions(TaskAttribute attribute) {
- Map<String, String> options = getRepositoryOptions(attribute);
+ Map<String, String> options = getRepositoryOptions(client, attribute.getId());
return (options != null) ? options : super.getOptions(attribute);
}
- public Map<String, String> getRepositoryOptions(TaskAttribute attribute) {
+ public static Map<String, String> getRepositoryOptions(ITracClient client, String trackKey) {
if (client.hasAttributes()) {
- String attributeId = attribute.getId();
- if (TracAttribute.STATUS.getTracKey().equals(attributeId)) {
+ if (TracAttribute.STATUS.getTracKey().equals(trackKey)) {
return getOptions(client.getTicketStatus(), false);
- } else if (TracAttribute.RESOLUTION.getTracKey().equals(attributeId)) {
+ } else if (TracAttribute.RESOLUTION.getTracKey().equals(trackKey)) {
return getOptions(client.getTicketResolutions(), false);
- } else if (TracAttribute.COMPONENT.getTracKey().equals(attributeId)) {
+ } else if (TracAttribute.COMPONENT.getTracKey().equals(trackKey)) {
return getOptions(client.getComponents(), false);
- } else if (TracAttribute.VERSION.getTracKey().equals(attributeId)) {
+ } else if (TracAttribute.VERSION.getTracKey().equals(trackKey)) {
return getOptions(client.getVersions(), true);
- } else if (TracAttribute.PRIORITY.getTracKey().equals(attributeId)) {
+ } else if (TracAttribute.PRIORITY.getTracKey().equals(trackKey)) {
return getOptions(client.getPriorities(), false);
- } else if (TracAttribute.SEVERITY.getTracKey().equals(attributeId)) {
+ } else if (TracAttribute.SEVERITY.getTracKey().equals(trackKey)) {
return getOptions(client.getSeverities(), false);
- } else if (TracAttribute.MILESTONE.getTracKey().equals(attributeId)) {
+ } else if (TracAttribute.MILESTONE.getTracKey().equals(trackKey)) {
return getOptions(client.getMilestones(), true);
- } else if (TracAttribute.TYPE.getTracKey().equals(attributeId)) {
+ } else if (TracAttribute.TYPE.getTracKey().equals(trackKey)) {
return getOptions(client.getTicketTypes(), false);
}
}
return null;
}
- private Map<String, String> getOptions(Object[] values, boolean allowEmpty) {
+ private static Map<String, String> getOptions(Object[] values, boolean allowEmpty) {
if (values != null && values.length > 0) {
Map<String, String> options = new LinkedHashMap<String, String>();
if (allowEmpty) {
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracTaskDataHandler.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracTaskDataHandler.java
index be7e7042b..db84110ee 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracTaskDataHandler.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracTaskDataHandler.java
@@ -19,6 +19,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
+import java.util.Map.Entry;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -122,6 +123,7 @@ public class TracTaskDataHandler extends AbstractTaskDataHandler {
createDefaultAttributes(taskData, client, true);
updateTaskData(repository, taskData, ticket);
}
+ removeEmptySingleSelectAttributes(taskData);
return taskData;
} catch (OperationCanceledException e) {
throw e;
@@ -131,6 +133,16 @@ public class TracTaskDataHandler extends AbstractTaskDataHandler {
}
}
+ private void removeEmptySingleSelectAttributes(TaskData taskData) {
+ List<TaskAttribute> attributes = new ArrayList<TaskAttribute>(taskData.getRoot().getAttributes().values());
+ for (TaskAttribute attribute : attributes) {
+ if (TaskAttribute.TYPE_SINGLE_SELECT.equals(attribute.getMetaData().getType())
+ && attribute.getValue().length() == 0 && attribute.getOptions().isEmpty()) {
+ taskData.getRoot().removeAttribute(attribute.getId());
+ }
+ }
+ }
+
public static Set<TaskAttribute> updateTaskData(TaskRepository repository, TaskData data, TracTicket ticket) {
Set<TaskAttribute> changedAttributes = new HashSet<TaskAttribute>();
@@ -271,21 +283,22 @@ public class TracTaskDataHandler extends AbstractTaskDataHandler {
public static void createDefaultAttributes(TaskData data, ITracClient client, boolean existingTask) {
data.setVersion(TASK_DATA_VERSION);
- createAttribute(data, TracAttribute.SUMMARY);
- createAttribute(data, TracAttribute.DESCRIPTION);
+ createAttribute(data, client, TracAttribute.SUMMARY);
+ createAttribute(data, client, TracAttribute.DESCRIPTION);
if (existingTask) {
- createAttribute(data, TracAttribute.TIME);
- createAttribute(data, TracAttribute.CHANGE_TIME);
- createAttribute(data, TracAttribute.STATUS, client.getTicketStatus());
- createAttribute(data, TracAttribute.RESOLUTION, client.getTicketResolutions());
+ createAttribute(data, client, TracAttribute.TIME);
+ createAttribute(data, client, TracAttribute.CHANGE_TIME);
+ createAttribute(data, client, TracAttribute.STATUS);
+ createAttribute(data, client, TracAttribute.RESOLUTION);
}
- createAttribute(data, TracAttribute.COMPONENT, client.getComponents());
- createAttribute(data, TracAttribute.VERSION, client.getVersions(), true);
- createAttribute(data, TracAttribute.PRIORITY, client.getPriorities());
- createAttribute(data, TracAttribute.SEVERITY, client.getSeverities());
- createAttribute(data, TracAttribute.MILESTONE, client.getMilestones(), true);
- createAttribute(data, TracAttribute.TYPE, client.getTicketTypes());
- createAttribute(data, TracAttribute.KEYWORDS);
+ createAttribute(data, client, TracAttribute.COMPONENT);
+ createAttribute(data, client, TracAttribute.VERSION);
+ createAttribute(data, client, TracAttribute.PRIORITY);
+ createAttribute(data, client, TracAttribute.SEVERITY);
+ createAttribute(data, client, TracAttribute.MILESTONE);
+ createAttribute(data, client, TracAttribute.TYPE);
+ createAttribute(data, client, TracAttribute.KEYWORDS);
+ // custom fields
TracTicketField[] fields = client.getTicketFields();
if (fields != null) {
for (TracTicketField field : fields) {
@@ -295,11 +308,11 @@ public class TracTaskDataHandler extends AbstractTaskDataHandler {
}
}
// people
- createAttribute(data, TracAttribute.OWNER);
+ createAttribute(data, client, TracAttribute.OWNER);
if (existingTask) {
- createAttribute(data, TracAttribute.REPORTER);
+ createAttribute(data, client, TracAttribute.REPORTER);
}
- createAttribute(data, TracAttribute.CC);
+ createAttribute(data, client, TracAttribute.CC);
if (existingTask) {
data.getRoot().createAttribute(TracAttributeMapper.NEW_CC).getMetaData().setType(
TaskAttribute.TYPE_SHORT_TEXT).setReadOnly(false);
@@ -369,6 +382,10 @@ public class TracTaskDataHandler extends AbstractTaskDataHandler {
}
public static TaskAttribute createAttribute(TaskData data, TracAttribute tracAttribute) {
+ return createAttribute(data, null, tracAttribute);
+ }
+
+ public static TaskAttribute createAttribute(TaskData data, ITracClient client, TracAttribute tracAttribute) {
TaskAttribute attr = data.getRoot().createAttribute(tracAttribute.getTracKey());
TaskAttributeMetaData metaData = attr.getMetaData();
metaData.setType(tracAttribute.getType());
@@ -376,29 +393,32 @@ public class TracTaskDataHandler extends AbstractTaskDataHandler {
metaData.setLabel(tracAttribute.toString());
metaData.setReadOnly(tracAttribute.isReadOnly());
metaData.putValue(TRAC_KEY, tracAttribute.getTracKey());
- return attr;
- }
-
- private static TaskAttribute createAttribute(TaskData data, TracAttribute tracAttribute, Object[] values,
- boolean allowEmpty) {
- TaskAttribute attr = createAttribute(data, tracAttribute);
- if (values != null && values.length > 0) {
- if (allowEmpty) {
- attr.putOption("", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ if (client != null) {
+ TracTicketField field = client.getTicketFieldByName(tracAttribute.getTracKey());
+ Map<String, String> values = TracAttributeMapper.getRepositoryOptions(client, attr.getId());
+ if (values != null && values.size() > 0) {
+ boolean setDefault = field == null || !field.isOptional();
+ for (Entry<String, String> value : values.entrySet()) {
+ attr.putOption(value.getKey(), value.getValue());
+ // set first value as default, may get overwritten below
+ if (setDefault) {
+ attr.setValue(value.getKey());
+ }
+ setDefault = false;
+ }
+ } else if (TaskAttribute.TYPE_SINGLE_SELECT.equals(tracAttribute.getType())) {
+ attr.getMetaData().setReadOnly(true);
}
- for (Object value : values) {
- attr.putOption(value.toString(), value.toString());
+ if (field != null) {
+ String defaultValue = field.getDefaultValue();
+ if (defaultValue != null && defaultValue.length() > 0) {
+ attr.setValue(defaultValue);
+ }
}
- } else {
- attr.getMetaData().setReadOnly(true);
}
return attr;
}
- private static TaskAttribute createAttribute(TaskData data, TracAttribute tracAttribute, Object[] values) {
- return createAttribute(data, tracAttribute, values, false);
- }
-
@Override
public RepositoryResponse postTaskData(TaskRepository repository, TaskData taskData,
Set<TaskAttribute> oldAttributes, IProgressMonitor monitor) throws CoreException {
@@ -432,6 +452,7 @@ public class TracTaskDataHandler extends AbstractTaskDataHandler {
ITracClient client = connector.getClientManager().getTracClient(repository);
client.updateAttributes(monitor, false);
createDefaultAttributes(data, client, false);
+ removeEmptySingleSelectAttributes(data);
return true;
} catch (OperationCanceledException e) {
throw e;
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/AbstractTracClient.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/AbstractTracClient.java
index 2079244bd..75fdbc966 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/AbstractTracClient.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/AbstractTracClient.java
@@ -15,6 +15,7 @@ import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
+import java.util.HashMap;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HostConfiguration;
@@ -154,6 +155,24 @@ public abstract class AbstractTracClient implements ITracClient {
return (data.ticketFields != null) ? data.ticketFields.toArray(new TracTicketField[0]) : null;
}
+ public TracTicketField getTicketFieldByName(String name) {
+ if (data.ticketFields != null) {
+ // lazily fill fieldByName map
+ if (data.ticketFieldByName == null) {
+ synchronized (data) {
+ if (data.ticketFieldByName == null) {
+ data.ticketFieldByName = new HashMap<String, TracTicketField>();
+ for (TracTicketField field : data.ticketFields) {
+ data.ticketFieldByName.put(field.getName(), field);
+ }
+ }
+ }
+ }
+ return data.ticketFieldByName.get(name);
+ }
+ return null;
+ }
+
public TracTicketResolution[] getTicketResolutions() {
return (data.ticketResolutions != null) ? data.ticketResolutions.toArray(new TracTicketResolution[0]) : null;
}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/ITracClient.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/ITracClient.java
index 23a579c56..0c0f4fc80 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/ITracClient.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/ITracClient.java
@@ -165,6 +165,8 @@ public interface ITracClient {
TracTicketField[] getTicketFields();
+ TracTicketField getTicketFieldByName(String tracKey);
+
TracMilestone[] getMilestones();
TracPriority[] getPriorities();
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracClientData.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracClientData.java
index aab7451aa..a1ef2dba9 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracClientData.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracClientData.java
@@ -13,6 +13,7 @@ package org.eclipse.mylyn.internal.trac.core.client;
import java.io.Serializable;
import java.util.List;
+import java.util.Map;
import org.eclipse.mylyn.internal.trac.core.model.TracComponent;
import org.eclipse.mylyn.internal.trac.core.model.TracMilestone;
@@ -48,4 +49,6 @@ public class TracClientData implements Serializable {
long lastUpdate;
+ transient Map<String, TracTicketField> ticketFieldByName;
+
}

Back to the top