diff options
author | Frank Becker | 2016-03-03 19:12:05 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-03-16 20:44:09 +0000 |
commit | 44a9886b02c40febb2691712528a925eee025df0 (patch) | |
tree | a1434dab6596d0c69ab9f03cef1d2d30926c2cfe /connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui | |
parent | 555588a5f02f4b0716b995deb7c8c10ba84f6341 (diff) | |
download | org.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/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui')
2 files changed, 143 insertions, 0 deletions
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; + } + } |