Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Becker2016-03-03 14:12:05 -0500
committerGerrit Code Review @ Eclipse.org2016-03-16 16:44:09 -0400
commit44a9886b02c40febb2691712528a925eee025df0 (patch)
treea1434dab6596d0c69ab9f03cef1d2d30926c2cfe /connector-bugzilla-rest
parent555588a5f02f4b0716b995deb7c8c10ba84f6341 (diff)
downloadorg.eclipse.mylyn.tasks-44a9886b02c40febb2691712528a925eee025df0.tar.gz
org.eclipse.mylyn.tasks-44a9886b02c40febb2691712528a925eee025df0.tar.xz
org.eclipse.mylyn.tasks-44a9886b02c40febb2691712528a925eee025df0.zip
414360: add support for cc attribute to REST API
Change-Id: I16db7531ccfdf016eedbf5b6b337c587b2f71b70 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=414360
Diffstat (limited to 'connector-bugzilla-rest')
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/config/Bugzilla REST Connector Tests (local).launch2
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/internal/bugzilla/rest/core/tests/BugzillaRestClientTest.java107
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java3
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestGsonUtil.java62
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPostNewTask.java11
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPutUpdateTask.java10
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskSchema.java10
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/IBugzillaRestConstants.java16
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaCcAttributeEditor.java121
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestTaskEditorPage.java22
10 files changed, 359 insertions, 5 deletions
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/config/Bugzilla REST Connector Tests (local).launch b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/config/Bugzilla REST Connector Tests (local).launch
index 72fa80d97..333c74c4c 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/config/Bugzilla REST Connector Tests (local).launch
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/config/Bugzilla REST Connector Tests (local).launch
@@ -24,7 +24,7 @@
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
-<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 7 [1.7.0_71]"/>
+<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 8 [1.8.0_74]"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -consolelog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.mylyn.bugzilla.rest.core.tests"/>
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/internal/bugzilla/rest/core/tests/BugzillaRestClientTest.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/internal/bugzilla/rest/core/tests/BugzillaRestClientTest.java
index 38d002001..b186b4c03 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/internal/bugzilla/rest/core/tests/BugzillaRestClientTest.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/internal/bugzilla/rest/core/tests/BugzillaRestClientTest.java
@@ -469,13 +469,18 @@ public class BugzillaRestClientTest {
taskDataGet.getRoot().removeAttribute("task.common.user.assigned");
taskData.getRoot().removeAttribute("task.common.operation");
taskDataGet.getRoot().removeAttribute("task.common.operation");
+ // CC attribute has diverences in the meta data between create and update
+ taskData.getRoot().removeAttribute("task.common.user.cc");
+ taskDataGet.getRoot().removeAttribute("task.common.user.cc");
- // attributes only in new tasks
+ // attributes only in old tasks
taskData.getRoot().removeAttribute("description_is_private");
- // attributes only in old tasks
+ // attributes only in new tasks
taskDataGet.getRoot().removeAttribute("bug_id");
taskDataGet.getRoot().removeAttribute("task.common.comment.new");
+ taskDataGet.getRoot().removeAttribute("addCC");
+ taskDataGet.getRoot().removeAttribute("removeCC");
// attributes for operations
taskDataGet.getRoot().removeAttribute("task.common.operation-CONFIRMED");
@@ -773,4 +778,102 @@ public class BugzillaRestClientTest {
return results.get(taskId);
}
+ @Test
+ public void testCreateCCAttribute() throws Exception {
+ final TaskMapping taskMappingInit = new TaskMapping() {
+ @Override
+ public String getSummary() {
+ return "The Summary";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The Description";
+ }
+
+ @Override
+ public String getProduct() {
+ return "ManualTest";
+ }
+
+ @Override
+ public String getComponent() {
+ return "ManualC1";
+ }
+
+ @Override
+ public String getVersion() {
+ return "R1";
+ }
+ };
+ AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
+ TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(actualFixture.repository());
+ TaskData taskData = new TaskData(mapper, actualFixture.repository().getConnectorKind(),
+ actualFixture.repository().getRepositoryUrl(), "");
+ taskDataHandler.initializeTaskData(actualFixture.repository(), taskData, taskMappingInit, null);
+ taskData.getRoot().getAttribute("cf_dropdown").setValue("one");
+ taskData.getRoot()
+ .getAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
+ .setValue("M2");
+ taskData.getRoot().getAttribute(BugzillaRestCreateTaskSchema.getDefault().CC.getKey()).setValue(
+ "admin@mylyn.eclipse.org, tests@mylyn.eclipse.org");
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskData, null,
+ null);
+ assertNotNull(reposonse);
+ assertNotNull(reposonse.getReposonseKind());
+ assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_CREATED));
+ TaskData taskDataUpdate = harness.getTaskFromServer(reposonse.getTaskId());
+ TaskAttribute ccAttrib = taskDataUpdate.getRoot()
+ .getAttribute(BugzillaRestCreateTaskSchema.getDefault().CC.getKey());
+ assertEquals(2, ccAttrib.getValues().size());
+ assertEquals("admin@mylyn.eclipse.org", ccAttrib.getValues().get(0));
+ assertEquals("tests@mylyn.eclipse.org", ccAttrib.getValues().get(1));
+ }
+
+ @Test
+ public void testCCAttribute() throws Exception {
+ String taskId = harness.getTaksId4TestProduct();
+ TaskData taskDataGet = harness.getTaskFromServer(taskId);
+
+ Set<TaskAttribute> changed = new HashSet<TaskAttribute>();
+
+ TaskAttribute attribute = taskDataGet.getRoot()
+ .getAttribute(BugzillaRestTaskSchema.getDefault().ADD_CC.getKey());
+ attribute.setValue("tests@mylyn.eclipse.org");
+ changed.add(attribute);
+
+ //Act
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
+ changed, null);
+ assertNotNull(reposonse);
+ assertNotNull(reposonse.getReposonseKind());
+ assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
+ //Assert
+ TaskData taskDataUpdate = harness.getTaskFromServer(taskId);
+ TaskAttribute ccAttrib = taskDataUpdate.getRoot()
+ .getAttribute(BugzillaRestCreateTaskSchema.getDefault().CC.getKey());
+ assertEquals(1, ccAttrib.getValues().size());
+ assertEquals("tests@mylyn.eclipse.org", ccAttrib.getValues().get(0));
+
+ TaskAttribute ccAddAttrib = taskDataUpdate.getRoot()
+ .getAttribute(BugzillaRestTaskSchema.getDefault().ADD_CC.getKey());
+ ccAddAttrib.setValue("admin@mylyn.eclipse.org");
+ changed.add(ccAddAttrib);
+
+ TaskAttribute ccRemoveAttrib = taskDataUpdate.getRoot()
+ .getAttribute(BugzillaRestTaskSchema.getDefault().REMOVE_CC.getKey());
+ ccRemoveAttrib.setValue("tests@mylyn.eclipse.org");
+ changed.add(ccRemoveAttrib);
+
+ //Act
+ reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataUpdate, changed, null);
+ assertNotNull(reposonse);
+ assertNotNull(reposonse.getReposonseKind());
+ assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
+ //Assert
+ taskDataUpdate = harness.getTaskFromServer(taskId);
+ ccAttrib = taskDataUpdate.getRoot().getAttribute(BugzillaRestCreateTaskSchema.getDefault().CC.getKey());
+ assertEquals(1, ccAttrib.getValues().size());
+ assertEquals("admin@mylyn.eclipse.org", ccAttrib.getValues().get(0));
+ }
}
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java
index f70778574..e4d09a9f8 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java
@@ -127,6 +127,9 @@ public class BugzillaRestConfiguration implements Serializable {
TaskAttribute attribute = data.getRoot().getAttribute(key);
if (!key.equals(SCHEMA.PRODUCT.getKey())) {
String configName = mapTaskAttributeKey2ConfigurationFields(key);
+ if ("addCC".equals(configName) || "removeCC".equals(configName)) {
+ continue;
+ }
Field configField = getFieldWithName(configName);
if (configField == null) {
continue;
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestGsonUtil.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestGsonUtil.java
index 9d1b8f57b..b2927a800 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestGsonUtil.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestGsonUtil.java
@@ -11,7 +11,44 @@
package org.eclipse.mylyn.internal.bugzilla.rest.core;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import com.google.common.collect.Sets;
+import com.google.gson.Gson;
+import com.google.gson.stream.JsonWriter;
+
public class BugzillaRestGsonUtil {
+
+ private class RemoveAddStringHelper {
+ Set<String> add;
+
+ Set<String> remove;
+
+ public RemoveAddStringHelper(Set<String> removeSet, Set<String> addSet) {
+ add = new HashSet<String>(addSet);
+ remove = new HashSet<String>(removeSet);
+ if (remove.contains("")) { //$NON-NLS-1$
+ remove.remove(""); //$NON-NLS-1$
+ }
+ if (add.contains("")) { //$NON-NLS-1$
+ add.remove(""); //$NON-NLS-1$
+ }
+ Set<String> intersection = Sets.intersection(addSet, removeSet);
+ remove.removeAll(intersection);
+ add.removeAll(intersection);
+ if (remove.isEmpty()) {
+ remove = null;
+ }
+ if (add.isEmpty()) {
+ add = null;
+ }
+ }
+ }
+
+ private static Gson gson = new Gson();
+
public static String convertString2GSonString(String str) {
str = str.replace("\"", "\\\"").replace("\n", "\\\n"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
StringBuffer ostr = new StringBuffer();
@@ -31,4 +68,29 @@ public class BugzillaRestGsonUtil {
return (new String(ostr));
}
+ private static BugzillaRestGsonUtil instance;
+
+ public static BugzillaRestGsonUtil getDefault() {
+ if (instance == null) {
+ instance = new BugzillaRestGsonUtil();
+ }
+ return instance;
+ }
+
+ public static void buildArrayFromHash(JsonWriter out, String id, Set<String> setNew) throws IOException {
+ if (!setNew.isEmpty()) {
+ out.name(id).beginArray();
+ for (String string : setNew) {
+ out.value(string);
+ }
+ out.endArray();
+ }
+ }
+
+ public void buildAddRemoveHash(JsonWriter out, String id, Set<String> setOld, Set<String> setNew)
+ throws IOException {
+ RemoveAddStringHelper test = new RemoveAddStringHelper(setOld, setNew);
+ out.name(id);
+ gson.toJson(test, RemoveAddStringHelper.class, out);
+ }
} \ No newline at end of file
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPostNewTask.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPostNewTask.java
index d693cd298..aaed696b7 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPostNewTask.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPostNewTask.java
@@ -16,6 +16,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import org.apache.http.HttpStatus;
@@ -78,6 +80,14 @@ public class BugzillaRestPostNewTask extends BugzillaRestAuthenticatedPostReques
continue;
}
}
+
+ if (id.equals("cc")) { //$NON-NLS-1$
+ HashSet<String> setNew = new HashSet<String>(
+ Arrays.asList(taskAttribute.getValue().split("\\s*,\\s*"))); //$NON-NLS-1$
+ BugzillaRestGsonUtil.buildArrayFromHash(out, id, setNew);
+ continue;
+ }
+
if (taskAttribute.getMetaData().getType() != null
&& taskAttribute.getMetaData().getType().equals(TaskAttribute.TYPE_MULTI_SELECT)) {
List<String> values = taskAttribute.getValues();
@@ -167,6 +177,7 @@ public class BugzillaRestPostNewTask extends BugzillaRestAuthenticatedPostReques
.add(BugzillaRestCreateTaskSchema.getDefault().QA_CONTACT.getKey())
.add(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
.add(TaskAttribute.OPERATION)
+ .add(BugzillaRestCreateTaskSchema.getDefault().CC.getKey())
.build();
@Override
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPutUpdateTask.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPutUpdateTask.java
index 6a790f358..a3e5d1a02 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPutUpdateTask.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPutUpdateTask.java
@@ -14,6 +14,8 @@ package org.eclipse.mylyn.internal.bugzilla.rest.core;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -142,6 +144,14 @@ public class BugzillaRestPutUpdateTask extends BugzillaRestAuthenticatedPutReque
}
}
}
+ TaskAttribute addCC = taskData.getRoot().getAttribute(BugzillaRestTaskSchema.getDefault().ADD_CC.getKey());
+ TaskAttribute removeCC = taskData.getRoot()
+ .getAttribute(BugzillaRestTaskSchema.getDefault().REMOVE_CC.getKey());
+ if (addCC.getValues().size() > 0 || removeCC.getValues().size() > 0) {
+ Set<String> setOld = new HashSet<String>(removeCC.getValues());
+ HashSet<String> setNew = new HashSet<String>(Arrays.asList(addCC.getValue().split("\\s*,\\s*"))); //$NON-NLS-1$
+ BugzillaRestGsonUtil.getDefault().buildAddRemoveHash(out, "cc", setOld, setNew); //$NON-NLS-1$
+ }
out.endObject();
}
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskSchema.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskSchema.java
index ed96ad889..b0aefe9b0 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskSchema.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskSchema.java
@@ -28,7 +28,7 @@ public class BugzillaRestTaskSchema extends AbstractTaskSchema {
.put("status", getDefault().STATUS.getKey()) //$NON-NLS-1$
.put("product", getDefault().PRODUCT.getKey()) //$NON-NLS-1$
.put("component", getDefault().COMPONENT.getKey()) //$NON-NLS-1$
- .put("CC", getDefault().CC.getKey()) //$NON-NLS-1$
+ .put("cc", getDefault().CC.getKey()) //$NON-NLS-1$
.put("severity", getDefault().SEVERITY.getKey()) //$NON-NLS-1$
.put("priority", getDefault().PRIORITY.getKey()) //$NON-NLS-1$
.put("assigned_to", getDefault().ASSIGNED_TO.getKey()) //$NON-NLS-1$
@@ -108,7 +108,13 @@ public class BugzillaRestTaskSchema extends AbstractTaskSchema {
.dependsOn(COMPONENT.getKey())
.create();
- public final Field CC = createField(TaskAttribute.USER_CC, "CC", TaskAttribute.TYPE_PERSON, Flag.PEOPLE);
+ public final Field ADD_CC = createField("addCC", "Add CC", TaskAttribute.TYPE_PERSON, Flag.PEOPLE);
+
+ public final Field CC = createField(TaskAttribute.USER_CC, "Remove CC\n(Selet to remove)",
+ IBugzillaRestConstants.EDITOR_TYPE_CC, Flag.PEOPLE);
+
+ public final Field REMOVE_CC = createField("removeCC", "CC selected for remove",
+ IBugzillaRestConstants.EDITOR_TYPE_CC);
public final Field ADD_SELF_CC = inheritFrom(parent.ADD_SELF_CC).addFlags(Flag.PEOPLE).create();
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/IBugzillaRestConstants.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/IBugzillaRestConstants.java
new file mode 100644
index 000000000..2bb566a21
--- /dev/null
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/IBugzillaRestConstants.java
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Frank Becker and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Frank Becker - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.bugzilla.rest.core;
+
+public interface IBugzillaRestConstants {
+ public static final String EDITOR_TYPE_CC = "bugzilla.editor.cc"; //$NON-NLS-1$
+}
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaCcAttributeEditor.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaCcAttributeEditor.java
new file mode 100644
index 000000000..bd71c6cf0
--- /dev/null
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaCcAttributeEditor.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Frank Becker and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Frank Becker - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.bugzilla.rest.ui;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestTaskSchema;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
+import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
+import org.eclipse.mylyn.tasks.ui.editors.LayoutHint;
+import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan;
+import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.RowSpan;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+public class BugzillaCcAttributeEditor extends AbstractAttributeEditor {
+
+ private List list;
+
+ private TaskAttribute attrRemoveCc;
+
+ protected boolean suppressRefresh;
+
+ public BugzillaCcAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
+ super(manager, taskAttribute);
+ setLayoutHint(new LayoutHint(RowSpan.MULTIPLE, ColumnSpan.SINGLE));
+ }
+
+ @Override
+ public void createControl(Composite parent, FormToolkit toolkit) {
+ list = new List(parent, SWT.FLAT | SWT.MULTI | SWT.V_SCROLL);
+ toolkit.adapt(list, true, true);
+ list.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
+ list.setFont(JFaceResources.getDefaultFont());
+ GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(list);
+ list.setToolTipText(getDescription());
+
+ populateFromAttribute();
+
+ attrRemoveCc = getModel().getTaskData()
+ .getRoot()
+ .getMappedAttribute(BugzillaRestTaskSchema.getDefault().REMOVE_CC.getKey());
+
+ selectValuesToRemove();
+
+ list.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ try {
+ suppressRefresh = true;
+ for (String cc : list.getItems()) {
+ int index = list.indexOf(cc);
+ if (list.isSelected(index)) {
+ java.util.List<String> remove = attrRemoveCc.getValues();
+ if (!remove.contains(cc)) {
+ attrRemoveCc.addValue(cc);
+ }
+ } else {
+ attrRemoveCc.removeValue(cc);
+ }
+ }
+ getModel().attributeChanged(attrRemoveCc);
+ } finally {
+ suppressRefresh = false;
+ }
+ }
+ });
+
+ list.showSelection();
+
+ setControl(list);
+ }
+
+ private void populateFromAttribute() {
+ TaskAttribute attrUserCC = getTaskAttribute();
+ if (attrUserCC != null) {
+ for (String value : attrUserCC.getValues()) {
+ list.add(value);
+ }
+ }
+ }
+
+ private void selectValuesToRemove() {
+ for (String item : attrRemoveCc.getValues()) {
+ int i = list.indexOf(item);
+ if (i != -1) {
+ list.select(i);
+ }
+ }
+ }
+
+ @Override
+ public void refresh() {
+ if (list != null && !list.isDisposed()) {
+ list.removeAll();
+ populateFromAttribute();
+ selectValuesToRemove();
+ }
+ }
+
+ @Override
+ public boolean shouldAutoRefresh() {
+ return !suppressRefresh;
+ }
+
+}
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestTaskEditorPage.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestTaskEditorPage.java
index f8e11c321..bd7a2bb80 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestTaskEditorPage.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestTaskEditorPage.java
@@ -12,7 +12,11 @@
package org.eclipse.mylyn.internal.bugzilla.rest.ui;
import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestCore;
+import org.eclipse.mylyn.internal.bugzilla.rest.core.IBugzillaRestConstants;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
+import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
public class BugzillaRestTaskEditorPage extends AbstractTaskEditorPage {
@@ -27,4 +31,22 @@ public class BugzillaRestTaskEditorPage extends AbstractTaskEditorPage {
setNeedsSubmitButton(true);
}
+ @Override
+ protected AttributeEditorFactory createAttributeEditorFactory() {
+ AttributeEditorFactory factory = new AttributeEditorFactory(getModel(), getTaskRepository(), getEditorSite()) {
+
+ @Override
+ public AbstractAttributeEditor createEditor(String type, TaskAttribute taskAttribute) {
+ AbstractAttributeEditor editor;
+ if (IBugzillaRestConstants.EDITOR_TYPE_CC.equals(type)) {
+ editor = new BugzillaCcAttributeEditor(getModel(), taskAttribute);
+ } else {
+ editor = super.createEditor(type, taskAttribute);
+ }
+ return editor;
+ }
+ };
+ return factory;
+ }
+
}

Back to the top