### Eclipse Workspace Patch 1.0 #P org.eclipse.mylyn.bugzilla.ui Index: src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java,v retrieving revision 1.93 diff -u -r1.93 BugzillaTaskEditor.java --- src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java 14 Feb 2008 02:00:41 -0000 1.93 +++ src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java 28 Mar 2008 17:24:59 -0000 @@ -24,8 +24,10 @@ import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCustomField; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaReportElement; import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants; +import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration; import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants.BUGZILLA_OPERATION; import org.eclipse.mylyn.internal.bugzilla.ui.BugzillaUiPlugin; import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages; @@ -39,6 +41,7 @@ import org.eclipse.mylyn.tasks.ui.editors.AbstractRepositoryTaskEditor; import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; @@ -76,6 +79,8 @@ private static final String LABEL_TIME_TRACKING = "Bugzilla Time Tracking"; + private static final String LABEL_CUSTOM_FIELD = "Custom Fields"; + protected Text keywordsText; protected Text estimateText; @@ -207,6 +212,89 @@ if (taskData.getAttribute(BugzillaReportElement.ESTIMATED_TIME.getKeyString()) != null) addBugzillaTimeTracker(getManagedForm().getToolkit(), composite); + try { + RepositoryConfiguration configuration = BugzillaCorePlugin.getRepositoryConfiguration(this.repository, + false); + if (configuration != null) { + List customFields = configuration.getCustomFields(); + if (!customFields.isEmpty()) { + Section cfSection = getManagedForm().getToolkit().createSection(composite, + ExpandableComposite.SHORT_TITLE_BAR); + cfSection.setText(LABEL_CUSTOM_FIELD); + GridLayout gl = new GridLayout(); + GridData gd = new GridData(SWT.FILL, SWT.NONE, false, false); + gd.horizontalSpan = 4; + cfSection.setLayout(gl); + cfSection.setLayoutData(gd); + + Composite cfComposite = getManagedForm().getToolkit().createComposite(cfSection); + gl = new GridLayout(4, false); + cfComposite.setLayout(gl); + gd = new GridData(); + gd.horizontalSpan = 5; + cfComposite.setLayoutData(gd); + for (BugzillaCustomField bugzillaCustomField : customFields) { + List optionList = bugzillaCustomField.getOptions(); + attribute = this.taskData.getAttribute(bugzillaCustomField.getName()); + if (attribute == null) { + RepositoryTaskAttribute newattribute = new RepositoryTaskAttribute( + bugzillaCustomField.getName(), bugzillaCustomField.getDescription(), false); + newattribute.setReadOnly(false); + this.taskData.addAttribute(bugzillaCustomField.getName(), newattribute); + } + final RepositoryTaskAttribute cfattribute = this.taskData.getAttribute(bugzillaCustomField.getName()); + Label label = createLabel(cfComposite, cfattribute); + GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label); + if (optionList != null && !optionList.isEmpty()) { + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + data.horizontalSpan = 1; + final CCombo attributeCombo = new CCombo(cfComposite, SWT.FLAT | SWT.READ_ONLY); + getManagedForm().getToolkit().adapt(attributeCombo, true, true); + attributeCombo.setFont(TEXT_FONT); + attributeCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + if (hasChanged(cfattribute)) { + attributeCombo.setBackground(getColorIncoming()); + } + attributeCombo.setLayoutData(data); + + for (String val : optionList) { + if (val != null) { + attributeCombo.add(val); + } + } + String value = cfattribute.getValue(); + if (value == null) { + value = ""; + } + if (attributeCombo.indexOf(value) != -1) { + attributeCombo.select(attributeCombo.indexOf(value)); + } + attributeCombo.clearSelection(); + attributeCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + if (attributeCombo.getSelectionIndex() > -1) { + String sel = attributeCombo.getItem(attributeCombo.getSelectionIndex()); + cfattribute.setValue(sel); + attributeChanged(cfattribute); + attributeCombo.clearSelection(); + } + } + }); + } else { + Text cfField = createTextField(cfComposite, cfattribute, SWT.FLAT); + GridDataFactory.fillDefaults().hint(135, SWT.DEFAULT).applyTo(cfField); + } + } + + getManagedForm().getToolkit().paintBordersFor(cfComposite); + cfSection.setClient(cfComposite); + } + } + } catch (CoreException e) { + // ignore + } + } private boolean hasCustomAttributeChanges() { #P org.eclipse.mylyn.bugzilla.core Index: src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java,v retrieving revision 1.12 diff -u -r1.12 SaxMultiBugReportContentHandler.java --- src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java 7 Feb 2008 01:53:49 -0000 1.12 +++ src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java 28 Mar 2008 17:25:01 -0000 @@ -54,11 +54,14 @@ private AbstractAttributeFactory attributeFactory; + private List customFields; + //private int retrieved = 1; - public SaxMultiBugReportContentHandler(AbstractAttributeFactory factory, Map taskDataMap) { + public SaxMultiBugReportContentHandler(AbstractAttributeFactory factory, Map taskDataMap, List customFields) { this.attributeFactory = factory; this.taskDataMap = taskDataMap; + this.customFields = customFields; } public boolean errorOccurred() { @@ -86,6 +89,8 @@ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { characters = new StringBuffer(); BugzillaReportElement tag = BugzillaReportElement.UNKNOWN; + if (localName.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) + return; try { tag = BugzillaReportElement.valueOf(localName.trim().toUpperCase(Locale.ENGLISH)); } catch (RuntimeException e) { @@ -163,6 +168,24 @@ String parsedText = characters.toString(); + if (localName.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) { + RepositoryTaskAttribute attribute = repositoryTaskData.getAttribute(localName); + if (attribute == null) { + String desc = "???"; + for (BugzillaCustomField bugzillaCustomField : customFields) { + if (localName.equals(bugzillaCustomField.getName())) { + desc = bugzillaCustomField.getDescription(); + } + } + RepositoryTaskAttribute newattribute = new RepositoryTaskAttribute(localName, desc, true); + newattribute.setReadOnly(false); + newattribute.setValue(parsedText); + repositoryTaskData.addAttribute(localName, newattribute); + } else { + attribute.addValue(parsedText); + } + } + BugzillaReportElement tag = BugzillaReportElement.UNKNOWN; try { tag = BugzillaReportElement.valueOf(localName.trim().toUpperCase(Locale.ENGLISH)); Index: src/org/eclipse/mylyn/internal/bugzilla/core/MultiBugReportFactory.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/MultiBugReportFactory.java,v retrieving revision 1.6 diff -u -r1.6 MultiBugReportFactory.java --- src/org/eclipse/mylyn/internal/bugzilla/core/MultiBugReportFactory.java 26 Jun 2007 01:16:07 -0000 1.6 +++ src/org/eclipse/mylyn/internal/bugzilla/core/MultiBugReportFactory.java 28 Mar 2008 17:25:01 -0000 @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.InputStream; +import java.util.List; import java.util.Locale; import java.util.Map; @@ -31,10 +32,10 @@ private static BugzillaAttributeFactory bugzillaAttributeFactory = new BugzillaAttributeFactory(); - public void populateReport(Map bugMap) throws IOException, CoreException { + public void populateReport(Map bugMap, List customFields) throws IOException, CoreException { SaxMultiBugReportContentHandler contentHandler = new SaxMultiBugReportContentHandler(bugzillaAttributeFactory, - bugMap); + bugMap, customFields); collectResults(contentHandler, false); if (contentHandler.errorOccurred()) { Index: src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java,v retrieving revision 1.7 diff -u -r1.7 SaxConfigurationContentHandler.java --- src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java 26 Jun 2007 01:16:07 -0000 1.7 +++ src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java 28 Mar 2008 17:25:01 -0000 @@ -56,6 +56,12 @@ private static final String ELEMENT_PRODUCTS = "products"; + private static final String ELEMENT_DESCRIPTION = "description"; + + private static final String ELEMENT_FIELDS = "fields"; + + private static final String ELEMENT_FIELD = "field"; + private static final String ELEMENT_SEVERITY = "severity"; private static final String ELEMENT_PRIORITY = "priority"; @@ -112,9 +118,17 @@ private static final int IN_STATUS_CLOSED = 1 << 20; + private static final int IN_FIELDS = 1 << 21; + + private static final int IN_FIELD = 1 << 22; + + private static final int IN_CUSTOM_OPTION = 1 << 23; + private int state = EXPECTING_ROOT; private String currentProduct = ""; + + private String currentName = ""; private StringBuffer characters = new StringBuffer(); @@ -134,6 +148,10 @@ private Map milestoneNames = new HashMap(); + private Map> customOption = new HashMap>(); + + private String currentCustomOptionName = ""; + public RepositoryConfiguration getConfiguration() { return configuration; } @@ -190,6 +208,14 @@ state = state | IN_RESOLUTION; } else if (localName.equals(ELEMENT_KEYWORD)) { state = state | IN_KEYWORD; + } else if (localName.equals(ELEMENT_FIELDS)) { + state = state | IN_FIELDS; + } else if (localName.equals(ELEMENT_FIELD)) { + state = state | IN_FIELD; + parseResource(attributes); + } else if (localName.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) { + state = state | IN_CUSTOM_OPTION; + currentCustomOptionName = localName; } } @@ -224,6 +250,18 @@ configuration.addPriority(characters.toString()); } else if (state == (IN_SEVERITY)) { configuration.addSeverity(characters.toString()); + } else if (state == (IN_CUSTOM_OPTION)) { + // Option for CutstomFields + if (currentCustomOptionName != null) { + if (characters.length() > 0) { + List customOptionList = customOption.get(currentCustomOptionName); + if (customOptionList == null) { + customOptionList = new ArrayList(); + customOption.put(currentCustomOptionName, customOptionList); + } + customOptionList.add(characters.toString()); + } + } } } else if (localName.equals(ELEMENT_PLATFORM)) { state = state & ~IN_PLATFORM; @@ -264,6 +302,9 @@ milestoneNames.put(about, characters.toString()); } } + } else if (state == (IN_FIELDS | IN_LI | IN_FIELD)) { + // FIELDS NAME + currentName = characters.toString(); } } else if (localName.equals(ELEMENT_COMPONENTS)) { state = state & ~IN_COMPONENTS; @@ -286,6 +327,21 @@ state = state & ~IN_RESOLUTION; } else if (localName.equals(ELEMENT_KEYWORD)) { state = state & ~IN_KEYWORD; + } else if (localName.equals(ELEMENT_FIELDS)) { + state = state & ~IN_FIELDS; + } else if (localName.equals(ELEMENT_FIELD)) { + state = state & ~IN_FIELD; + } else if (localName.equals(ELEMENT_DESCRIPTION)) { + if (currentName.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) { + BugzillaCustomField newField = new BugzillaCustomField(characters.toString(), currentName); + List customOptionList = customOption.get(currentName); + if (customOptionList != null && !customOptionList.isEmpty()) + newField.setOptions(customOptionList); + configuration.addCustomField(newField); + } + } else if (localName.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) { + state = state & ~IN_CUSTOM_OPTION; + currentCustomOptionName = ""; } } @@ -347,6 +403,11 @@ about = attributes.getValue(ATTRIBUTE_RDF_ABOUT); } break; + case IN_FIELDS | IN_LI | IN_FIELD: + if (attributes != null) { + about = attributes.getValue(ATTRIBUTE_RDF_ABOUT); + } + break; } } Index: src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientManager.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientManager.java,v retrieving revision 1.11 diff -u -r1.11 BugzillaClientManager.java --- src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientManager.java 5 Dec 2007 02:57:16 -0000 1.11 +++ src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientManager.java 28 Mar 2008 17:25:01 -0000 @@ -12,6 +12,7 @@ import java.util.HashMap; import java.util.Map; +import org.eclipse.core.runtime.CoreException; import org.eclipse.mylyn.tasks.core.ITaskRepositoryListener; import org.eclipse.mylyn.tasks.core.TaskRepository; @@ -26,7 +27,7 @@ public BugzillaClientManager() { } - public synchronized BugzillaClient getClient(TaskRepository taskRepository) throws MalformedURLException { + public synchronized BugzillaClient getClient(TaskRepository taskRepository) throws MalformedURLException, CoreException { BugzillaClient client = clientByUrl.get(taskRepository.getUrl()); if (client == null) { @@ -43,7 +44,8 @@ taskRepository.getPassword(), htUser, htPass, taskRepository.getProxy(), taskRepository.getCharacterEncoding(), taskRepository.getProperties(), languageSettings); clientByUrl.put(taskRepository.getUrl(), client); - } + client.setRepositoryConfiguration(BugzillaCorePlugin.getRepositoryConfiguration(taskRepository, false)); + } return client; } Index: src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java,v retrieving revision 1.109 diff -u -r1.109 BugzillaClient.java --- src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java 13 Jan 2008 20:36:42 -0000 1.109 +++ src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java 28 Mar 2008 17:25:01 -0000 @@ -155,6 +155,8 @@ private BugzillaLanguageSettings bugzillaLanguageSettings; + private RepositoryConfiguration repositoryConfiguration; + public BugzillaClient(URL url, String username, String password, String htAuthUser, String htAuthPass, String characterEncoding) { this(url, username, password, htAuthUser, htAuthPass, characterEncoding, new HashMap(), @@ -637,10 +639,10 @@ RepositoryConfigurationFactory configFactory = new RepositoryConfigurationFactory(stream, characterEncoding); - RepositoryConfiguration configuration = configFactory.getConfiguration(); - if (configuration != null) { - configuration.setRepositoryUrl(repositoryUrl.toString()); - return configuration; + repositoryConfiguration = configFactory.getConfiguration(); + if (repositoryConfiguration != null) { + repositoryConfiguration.setRepositoryUrl(repositoryUrl.toString()); + return repositoryConfiguration; } } } @@ -1218,13 +1220,14 @@ } boolean parseable = false; + List customFields = repositoryConfiguration.getCustomFields(); if (method.getResponseHeader("Content-Type") != null) { Header responseTypeHeader = method.getResponseHeader("Content-Type"); for (String type : VALID_CONFIG_CONTENT_TYPES) { if (responseTypeHeader.getValue().toLowerCase(Locale.ENGLISH).contains(type)) { MultiBugReportFactory factory = new MultiBugReportFactory( method.getResponseBodyAsUnzippedStream(), characterEncoding); - factory.populateReport(taskDataMap); + factory.populateReport(taskDataMap, customFields); taskIds.removeAll(idsToRetrieve); parseable = true; break; @@ -1342,4 +1345,8 @@ + " failed. Please verify connection and authentication information.")); } + public void setRepositoryConfiguration(RepositoryConfiguration repositoryConfiguration) { + this.repositoryConfiguration = repositoryConfiguration; + } + } Index: src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java,v retrieving revision 1.8 diff -u -r1.8 RepositoryConfiguration.java --- src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java 26 Jun 2007 01:16:07 -0000 1.8 +++ src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java 28 Mar 2008 17:25:01 -0000 @@ -22,7 +22,7 @@ */ public class RepositoryConfiguration implements Serializable { - private static final long serialVersionUID = -3623617786905114255L; + private static final long serialVersionUID = -482656956042521023L; private static final String VERSION_UNKNOWN = "unknown"; @@ -54,6 +54,8 @@ private List milestones = new ArrayList(); + private List customFields = new ArrayList(); + private String version = VERSION_UNKNOWN; public RepositoryConfiguration() { @@ -379,4 +381,15 @@ } } + /** + * Adds a field to the configuration. + */ + public void addCustomField(BugzillaCustomField newField) { + customFields.add(newField); + } + + public List getCustomFields() { + return customFields; + } + } Index: src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCustomField.java =================================================================== RCS file: src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCustomField.java diff -N src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCustomField.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCustomField.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Mylyn project committers 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 + *******************************************************************************/ + +package org.eclipse.mylyn.internal.bugzilla.core; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * Class describing a custom Fields for a given Bugzilla installation. + * + * @author Frank Becker + * @since 2.3 + */ +public class BugzillaCustomField implements Serializable { + + private static final long serialVersionUID = 5703683576871326128L; + + public static final String CUSTOM_FIELD_PREFIX = "cf_"; + + private String name; + + private String description; + + private List options = new ArrayList(); + + public BugzillaCustomField(String description, String name) { + this.description = description; + this.name = name; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public List getOptions() { + return options; + } + + public void setOptions(List options) { + this.options = options; + } + + public void addOption(String option) { + this.options.add(option); + } +}