### Eclipse Workspace Patch 1.0 #P org.eclipse.mylyn.bugzilla.core 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.45 diff -u -r1.45 RepositoryConfiguration.java --- src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java 14 Aug 2009 13:35:59 -0000 1.45 +++ src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java 1 Oct 2009 21:54:27 -0000 @@ -374,6 +374,8 @@ if (localuser) { removeDomain(taskData); } + addMissingAttachmentFlags(taskData); + updateAttachmentOptions(taskData); } } @@ -729,4 +731,97 @@ public String getEncoding() { return encoding; } + + public void updateAttachmentOptions(TaskData existingReport) { + for (TaskAttribute attribute : new HashSet(existingReport.getRoot().getAttributes().values())) { + + if (!attribute.getId().startsWith("task.common.attachment")) { //$NON-NLS-1$ + continue; + } + + for (TaskAttribute attachmentAttribute : attribute.getAttributes().values()) { + if (!attachmentAttribute.getId().startsWith("task.common.kind.flag")) { //$NON-NLS-1$ + continue; + } + + TaskAttribute state = attachmentAttribute.getAttribute("state"); //$NON-NLS-1$ + attachmentAttribute.clearOptions(); + + String nameValue = state.getMetaData().getLabel(); + state.putOption("", ""); //$NON-NLS-1$ //$NON-NLS-2$ + for (BugzillaFlag bugzillaFlag : flags) { + if (nameValue.equals(bugzillaFlag.getName()) && bugzillaFlag.getType().equals("attachment")) { //$NON-NLS-1$ + if ("attachment".equals(bugzillaFlag.getType())) { //$NON-NLS-1$ + if (bugzillaFlag.isRequestable()) { + state.putOption("?", "?"); //$NON-NLS-1$ //$NON-NLS-2$ + } + break; + } + } + } + state.putOption("-", "-"); //$NON-NLS-1$ //$NON-NLS-2$ + state.putOption("+", "+"); //$NON-NLS-1$ //$NON-NLS-2$ + String flagNameValue = state.getMetaData().getLabel(); + for (BugzillaFlag bugzillaFlag : flags) { + if (flagNameValue.equals(bugzillaFlag.getName()) && bugzillaFlag.getType().equals("attachment")) { //$NON-NLS-1$ + TaskAttribute requestee = attachmentAttribute.getAttribute("requestee"); //$NON-NLS-1$ + if (requestee == null) { + requestee = attachmentAttribute.createMappedAttribute("requestee"); //$NON-NLS-1$ + requestee.getMetaData().defaults().setType(TaskAttribute.TYPE_SHORT_TEXT); + requestee.setValue(""); //$NON-NLS-1$ + } + requestee.getMetaData().setReadOnly(!bugzillaFlag.isSpecifically_requestable()); + } + } + + } + } + } + + private void addMissingAttachmentFlags(TaskData taskData) { + List existingFlags = new ArrayList(); + List flags = getFlags(); + for (TaskAttribute attribute : new HashSet(taskData.getRoot().getAttributes().values())) { + + if (!attribute.getId().startsWith("task.common.attachment")) { //$NON-NLS-1$ + continue; + } + existingFlags.clear(); + for (TaskAttribute attachmentAttribute : attribute.getAttributes().values()) { + if (!attachmentAttribute.getId().startsWith("task.common.kind.flag")) { //$NON-NLS-1$ + continue; + } + TaskAttribute state = attachmentAttribute.getAttribute("state"); //$NON-NLS-1$ + if (state != null) { + String nameValue = state.getMetaData().getLabel(); + if (!existingFlags.contains(nameValue)) { + existingFlags.add(nameValue); + } + } + } + TaskAttribute productAttribute = taskData.getRoot().getMappedAttribute(BugzillaAttribute.PRODUCT.getKey()); + TaskAttribute componentAttribute = taskData.getRoot().getMappedAttribute( + BugzillaAttribute.COMPONENT.getKey()); + for (BugzillaFlag bugzillaFlag : flags) { + if (!bugzillaFlag.getType().equals("attachment")) { //$NON-NLS-1$ + continue; + } + if (!bugzillaFlag.isUsedIn(productAttribute.getValue(), componentAttribute.getValue())) { + continue; + } + if (existingFlags.contains(bugzillaFlag.getName()) && !bugzillaFlag.isMultiplicable()) { + continue; + } + BugzillaFlagMapper mapper = new BugzillaFlagMapper(); + mapper.setRequestee(""); //$NON-NLS-1$ + mapper.setSetter(""); //$NON-NLS-1$ + mapper.setState(" "); //$NON-NLS-1$ + mapper.setFlagId(bugzillaFlag.getName()); + mapper.setNumber(0); + mapper.setDescription(bugzillaFlag.getDescription()); + TaskAttribute newattribute = attribute.createAttribute("task.common.kind.flag_type" + bugzillaFlag.getFlagId()); //$NON-NLS-1$ + mapper.applyTo(newattribute); + } + } + } } Index: src/org/eclipse/mylyn/internal/bugzilla/core/messages.properties =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/messages.properties,v retrieving revision 1.14 diff -u -r1.14 messages.properties --- src/org/eclipse/mylyn/internal/bugzilla/core/messages.properties 17 Sep 2009 02:16:05 -0000 1.14 +++ src/org/eclipse/mylyn/internal/bugzilla/core/messages.properties 1 Oct 2009 21:54:27 -0000 @@ -84,6 +84,18 @@ BugzillaAttribute_who=who BugzillaAttribute_who_name=who_name BugzillaAttribute_Worked=Worked: + +BugzillaAttachmentMapper_Author=Attachment Author: +BugzillaAttachmentMapper_Content_Type=Content Type: +BugzillaAttachmentMapper_Creation_Date=Creation Date: +BugzillaAttachmentMapper_Description=Description: +BugzillaAttachmentMapper_Filename=Filename: +BugzillaAttachmentMapper_obsolete=obsolete +BugzillaAttachmentMapper_patch=patch +BugzillaAttachmentMapper_Size=Size in Bytes: +BugzillaAttachmentMapper_Token=Token: +BugzillaAttachmentMapper_URL=URL: + BugzillaClient_could_not_post_form_null_returned=Could not post form, client returned null method. BugzillaClient_description_required_when_submitting_attachments=A description is required when submitting attachments. 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.50 diff -u -r1.50 SaxMultiBugReportContentHandler.java --- src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java 24 Aug 2009 22:49:25 -0000 1.50 +++ src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java 1 Oct 2009 21:54:27 -0000 @@ -18,7 +18,6 @@ import java.util.Map; import org.eclipse.mylyn.tasks.core.IRepositoryPerson; -import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper; import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper; @@ -517,7 +516,7 @@ List taskAttachments = repositoryTaskData.getAttributeMapper().getAttributesByType( repositoryTaskData, TaskAttribute.TYPE_ATTACHMENT); for (TaskAttribute attachment : taskAttachments) { - TaskAttachmentMapper attachmentMapper = TaskAttachmentMapper.createFrom(attachment); + BugzillaAttachmentMapper attachmentMapper = BugzillaAttachmentMapper.createFrom(attachment); TaskCommentMapper taskComment = attachIdToComment.get(attachmentMapper.getAttachmentId()); if (taskComment != null) { attachmentMapper.setAuthor(taskComment.getAuthor()); Index: src/org/eclipse/mylyn/internal/bugzilla/core/Messages.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/Messages.java,v retrieving revision 1.10 diff -u -r1.10 Messages.java --- src/org/eclipse/mylyn/internal/bugzilla/core/Messages.java 17 Sep 2009 02:16:05 -0000 1.10 +++ src/org/eclipse/mylyn/internal/bugzilla/core/Messages.java 1 Oct 2009 21:54:27 -0000 @@ -177,6 +177,26 @@ public static String BugzillaAttribute_Worked; + public static String BugzillaAttachmentMapper_Author; + + public static String BugzillaAttachmentMapper_Content_Type; + + public static String BugzillaAttachmentMapper_Creation_Date; + + public static String BugzillaAttachmentMapper_Description; + + public static String BugzillaAttachmentMapper_Filename; + + public static String BugzillaAttachmentMapper_obsolete; + + public static String BugzillaAttachmentMapper_patch; + + public static String BugzillaAttachmentMapper_Size; + + public static String BugzillaAttachmentMapper_Token; + + public static String BugzillaAttachmentMapper_URL; + public static String BugzillaClient_could_not_post_form_null_returned; public static String BugzillaClient_description_required_when_submitting_attachments; Index: src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttachmentMapper.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttachmentMapper.java,v retrieving revision 1.2 diff -u -r1.2 BugzillaAttachmentMapper.java --- src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttachmentMapper.java 24 Jul 2009 12:07:14 -0000 1.2 +++ src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttachmentMapper.java 1 Oct 2009 21:54:27 -0000 @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 Tasktop Technologies and others. + * Copyright (c) 2009 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: - * Tasktop Technologies - initial API and implementation + * Frank Becker - initial API and implementation *******************************************************************************/ package org.eclipse.mylyn.internal.bugzilla.core; @@ -15,6 +15,7 @@ import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper; +import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData; import org.eclipse.mylyn.tasks.core.data.TaskData; /** @@ -33,19 +34,83 @@ @Override public void applyTo(TaskAttribute taskAttribute) { - // ignore - super.applyTo(taskAttribute); - Assert.isNotNull(taskAttribute); TaskData taskData = taskAttribute.getTaskData(); TaskAttributeMapper mapper = taskData.getAttributeMapper(); - + taskAttribute.getMetaData().defaults().setType(TaskAttribute.TYPE_ATTACHMENT); + if (getAttachmentId() != null) { + mapper.setValue(taskAttribute, getAttachmentId()); + } + if (getAuthor() != null) { + TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_AUTHOR); + TaskAttributeMetaData defaults = child.getMetaData().defaults(); + defaults.setType(TaskAttribute.TYPE_PERSON); + defaults.setLabel(Messages.BugzillaAttachmentMapper_Author); + mapper.setRepositoryPerson(child, getAuthor()); + } + if (getContentType() != null) { + TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_CONTENT_TYPE); + TaskAttributeMetaData defaults = child.getMetaData().defaults(); + defaults.setType(TaskAttribute.TYPE_SHORT_TEXT); + defaults.setLabel(Messages.BugzillaAttachmentMapper_Content_Type); + mapper.setValue(child, getContentType()); + } + if (getCreationDate() != null) { + TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_DATE); + TaskAttributeMetaData defaults = child.getMetaData().defaults(); + defaults.setType(TaskAttribute.TYPE_DATE); + defaults.setLabel(Messages.BugzillaAttachmentMapper_Creation_Date); + mapper.setDateValue(child, getCreationDate()); + } + if (getDescription() != null) { + TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_DESCRIPTION); + TaskAttributeMetaData defaults = child.getMetaData().defaults(); + defaults.setType(TaskAttribute.TYPE_SHORT_TEXT); + defaults.setLabel(Messages.BugzillaAttachmentMapper_Description); + mapper.setValue(child, getDescription()); + } + if (getFileName() != null) { + TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_FILENAME); + TaskAttributeMetaData defaults = child.getMetaData().defaults(); + defaults.setType(TaskAttribute.TYPE_SHORT_TEXT); + defaults.setLabel(Messages.BugzillaAttachmentMapper_Filename); + mapper.setValue(child, getFileName()); + } + if (isDeprecated() != null) { + TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED); + TaskAttributeMetaData defaults = child.getMetaData().defaults(); + defaults.setType(TaskAttribute.TYPE_BOOLEAN); + defaults.setLabel(Messages.BugzillaAttachmentMapper_obsolete); + mapper.setBooleanValue(child, isDeprecated()); + } + if (isPatch() != null) { + TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH); + TaskAttributeMetaData defaults = child.getMetaData().defaults(); + defaults.setType(TaskAttribute.TYPE_BOOLEAN); + defaults.setLabel(Messages.BugzillaAttachmentMapper_patch); + mapper.setBooleanValue(child, isPatch()); + } + if (getLength() != null) { + TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_SIZE); + TaskAttributeMetaData defaults = child.getMetaData().defaults(); + defaults.setType(TaskAttribute.TYPE_SHORT_TEXT); + defaults.setLabel(Messages.BugzillaAttachmentMapper_Size); + mapper.setLongValue(child, getLength()); + } + if (getUrl() != null) { + TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_URL); + TaskAttributeMetaData defaults = child.getMetaData().defaults(); + defaults.setType(TaskAttribute.TYPE_URL); + defaults.setLabel(Messages.BugzillaAttachmentMapper_URL); + mapper.setValue(child, getUrl()); + } if (getToken() != null) { TaskAttribute child = taskAttribute.createMappedAttribute(BugzillaAttribute.TOKEN.getKey()); - child.getMetaData().defaults().setType(TaskAttribute.TYPE_SHORT_TEXT); + TaskAttributeMetaData defaults = child.getMetaData().defaults(); + defaults.setType(TaskAttribute.TYPE_SHORT_TEXT); + defaults.setLabel(Messages.BugzillaAttachmentMapper_Token); mapper.setValue(child, getToken()); } - } public static BugzillaAttachmentMapper createFrom(TaskAttribute taskAttribute) { @@ -98,5 +163,4 @@ } return attachment; } - } #P org.eclipse.mylyn.bugzilla.ui Index: src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskAttachmentPage.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskAttachmentPage.java,v retrieving revision 1.3 diff -u -r1.3 BugzillaTaskAttachmentPage.java --- src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskAttachmentPage.java 16 Dec 2008 00:21:39 -0000 1.3 +++ src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskAttachmentPage.java 1 Oct 2009 21:54:28 -0000 @@ -157,7 +157,7 @@ | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); flagExpandComposite.setFont(container.getFont()); flagExpandComposite.setBackground(container.getBackground()); - flagExpandComposite.setText(Messages.BugzillaTaskAttachmentPage_flags); + flagExpandComposite.setText(Messages.BugzillaTaskAttachmentPage_Advanced); flagExpandComposite.setLayout(new GridLayout(3, false)); GridData g = new GridData(GridData.FILL_HORIZONTAL); g.horizontalSpan = 3; Index: src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/messages.properties =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/messages.properties,v retrieving revision 1.4 diff -u -r1.4 messages.properties --- src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/messages.properties 24 Jul 2009 12:08:07 -0000 1.4 +++ src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/messages.properties 1 Oct 2009 21:54:28 -0000 @@ -38,4 +38,6 @@ BugzillaRepositorySettingsPage_Server_URL_is_invalid=Server URL is invalid. BugzillaRepositorySettingsPage_supports_bugzilla_X=Supports Bugzilla {0} BugzillaRepositorySettingsPage_Validating_server_settings=Validating server settings -BugzillaTaskAttachmentPage_flags=Flags +BugzillaTaskAttachmentPage_Advanced=Advanced +BugzillaAttachmentDialog_DetailTitle=Attachment Detail of {0} +BugzillaAttachmentDialog_UpdateTitle=Update of Attachment {0} Index: src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/Messages.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/Messages.java,v retrieving revision 1.4 diff -u -r1.4 Messages.java --- src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/Messages.java 24 Jul 2009 12:08:07 -0000 1.4 +++ src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/Messages.java 1 Oct 2009 21:54:28 -0000 @@ -79,5 +79,9 @@ public static String BugzillaRepositorySettingsPage_Validating_server_settings; - public static String BugzillaTaskAttachmentPage_flags; + public static String BugzillaTaskAttachmentPage_Advanced; + + public static String BugzillaAttachmentDialog_DetailTitle; + + public static String BugzillaAttachmentDialog_UpdateTitle; } Index: plugin.xml =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.ui/plugin.xml,v retrieving revision 1.107 diff -u -r1.107 plugin.xml --- plugin.xml 24 Jul 2009 12:08:07 -0000 1.107 +++ plugin.xml 1 Oct 2009 21:54:28 -0000 @@ -96,7 +96,7 @@ menubarPath="org.eclipse.mylyn.bugzilla.ui.attachments.mark/markadditions" tooltip="Mark attachment as not obsolete"> - + + + + attachmentList = sructuredSelection.toList(); + if (attachmentList != null && attachmentList.size() == 1) { + action.setEnabled(true); + } else { + action.setEnabled(false); + } + } +} Index: src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaAttachmentDetailAction.java =================================================================== RCS file: src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaAttachmentDetailAction.java diff -N src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaAttachmentDetailAction.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaAttachmentDetailAction.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008 Tasktop Technologies 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: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.bugzilla.ui.action; + +import java.util.List; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.mylyn.internal.bugzilla.ui.dialogs.BugzillaAttachmentDialog; +import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage; +import org.eclipse.mylyn.tasks.core.ITaskAttachment; +import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.BaseSelectionListenerAction; +import org.eclipse.ui.forms.editor.IFormPage; + +/** + * @author Frank Becker + */ +public class BugzillaAttachmentDetailAction extends BaseSelectionListenerAction implements IViewActionDelegate { + + private ISelection currentSelection; + + public BugzillaAttachmentDetailAction() { + super("BugzillaAttachmentDetailAction"); //$NON-NLS-1$ + } + + public void init(IViewPart view) { + // ignore + + } + + public void run(IAction action) { + IStructuredSelection selection = null; + if (currentSelection instanceof IStructuredSelection) { + selection = (IStructuredSelection) currentSelection; + } + if (selection == null || selection.isEmpty() || selection.size() != 1) { + return; + } + ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement(); + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + IWorkbenchPage page = window.getActivePage(); + IEditorPart activeEditor = page.getActiveEditor(); + IWorkbenchPartSite site = activeEditor.getSite(); + Shell shell = site.getShell(); + if (activeEditor instanceof TaskEditor) { + final TaskEditor taskEditor = (TaskEditor) activeEditor; + IFormPage taskEditorPage = taskEditor.findPage("id"); //$NON-NLS-1$ + if (taskEditorPage instanceof BugzillaTaskEditorPage) { + BugzillaTaskEditorPage bugzillaTaskEditorPage = (BugzillaTaskEditorPage) taskEditorPage; + BugzillaAttachmentDialog dialog = new BugzillaAttachmentDialog(shell, bugzillaTaskEditorPage, + bugzillaTaskEditorPage.getAttributeEditorFactory(), attachment.getTaskAttribute(), true); + dialog.open(); + } + } + } + + @SuppressWarnings("unchecked") + public void selectionChanged(IAction action, ISelection selection) { + this.currentSelection = selection; + IStructuredSelection sructuredSelection = null; + if (selection instanceof IStructuredSelection) { + sructuredSelection = (IStructuredSelection) currentSelection; + } + if (sructuredSelection == null || sructuredSelection.isEmpty()) { + return; + } + List attachmentList = sructuredSelection.toList(); + if (attachmentList != null && attachmentList.size() == 1) { + action.setEnabled(true); + } else { + action.setEnabled(false); + } + + } + +} Index: src/org/eclipse/mylyn/internal/bugzilla/ui/dialogs/BugzillaAttachmentDialog.java =================================================================== RCS file: src/org/eclipse/mylyn/internal/bugzilla/ui/dialogs/BugzillaAttachmentDialog.java diff -N src/org/eclipse/mylyn/internal/bugzilla/ui/dialogs/BugzillaAttachmentDialog.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/mylyn/internal/bugzilla/ui/dialogs/BugzillaAttachmentDialog.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,249 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008 Tasktop Technologies 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: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.bugzilla.ui.dialogs; + +import java.text.MessageFormat; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; +import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage; +import org.eclipse.mylyn.internal.bugzilla.ui.tasklist.Messages; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor; +import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.SelectionDialog; +import org.eclipse.ui.forms.events.ExpansionAdapter; +import org.eclipse.ui.forms.events.ExpansionEvent; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; + +/** + * @author Frank Becker + */ +public class BugzillaAttachmentDialog extends SelectionDialog { + + private final FormToolkit toolkit; + + private Composite scrollComposite; + + private ExpandableComposite flagExpandComposite = null; + + private final TaskAttribute attachment; + + private final Shell parentShell; + + private final boolean readOnly; + + private final AttributeEditorFactory attributeEditorFactory; + + private static final int LABEL_WIDTH = 120; + + private static final int COLUMN_GAP = 5; + + private static final int MULTI_ROW_HEIGHT = 55; + + private static final int COLUMN_WIDTH = 200; + + private static final int MULTI_COLUMN_WIDTH = COLUMN_WIDTH + 5 + COLUMN_GAP + LABEL_WIDTH + 5 + COLUMN_WIDTH; + + public BugzillaAttachmentDialog(Shell parentShell, BugzillaTaskEditorPage editor, AttributeEditorFactory factory, + TaskAttribute attachment, boolean readonly) { + super(parentShell); + this.attachment = attachment; + this.parentShell = parentShell; + this.readOnly = readonly; + attributeEditorFactory = factory; + toolkit = new FormToolkit(Display.getCurrent()); + this.setTitle(MessageFormat.format(readonly ? Messages.BugzillaAttachmentDialog_DetailTitle + : Messages.BugzillaAttachmentDialog_UpdateTitle, attachment.getValue())); + } + + @Override + protected Control createDialogArea(Composite parent) { + int currentColumn = 1; + int columnCount = 4; + Composite composite = (Composite) super.createDialogArea(parent); + + initializeDialogUnits(composite); + + Composite attributeArea = new Composite(composite, SWT.FLAT); + attributeArea.setLayout(new GridLayout(4, false)); + createAttributeEditors(currentColumn, columnCount, attributeArea); + Composite advancedComposite = createFlagSection(attributeArea); + createFlagEditors(columnCount, advancedComposite); + createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_URL), currentColumn, columnCount, + advancedComposite); + createCommntEditor(currentColumn, columnCount, attributeArea); + Dialog.applyDialogFont(composite); + return composite; + } + + private void createAttributeEditor(TaskAttribute attribute, int currentColumn, int columnCount, + Composite attributeArea) { + String type = attribute.getMetaData().getType(); + if (type != null) { + AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, attribute); + if (attribute.getId().equals(BugzillaAttribute.TOKEN.getKey()) + || attribute.getId().equals("size") || attribute.getId().equals(TaskAttribute.ATTACHMENT_URL)) { //$NON-NLS-1$ + editor.setReadOnly(true); + } else { + editor.setReadOnly(readOnly); + } + if (editor.hasLabel()) { + editor.createLabelControl(attributeArea, toolkit); + Label label = editor.getLabelControl(); + label.setBackground(attributeArea.getBackground()); + String labelString = editor.getLabel(); + if (labelString != null && !labelString.equals("")) { //$NON-NLS-1$ + GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH, + SWT.DEFAULT).create(); + if (currentColumn > 1) { + gd.horizontalIndent = COLUMN_GAP; + gd.widthHint = LABEL_WIDTH + COLUMN_GAP; + } + label.setLayoutData(gd); + currentColumn++; + } + } + editor.createControl(attributeArea, toolkit); + GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false); + if (type.equals("shortText") || type.equals("url")) { //$NON-NLS-1$//$NON-NLS-2$ + gd.horizontalSpan = 3; + } else { + gd.horizontalSpan = 1; + } + editor.getControl().setLayoutData(gd); + if (attribute.getId().equals(TaskAttribute.ATTACHMENT_URL)) { + editor.getControl().setEnabled(false); + } + + currentColumn += gd.horizontalSpan; + currentColumn %= columnCount; + } + } + + private void createAttributeEditors(int currentColumn, int columnCount, Composite attributeArea) { + createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_DESCRIPTION), currentColumn, + columnCount, attributeArea); + createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_FILENAME), currentColumn, + columnCount, attributeArea); + createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_SIZE), currentColumn, columnCount, + attributeArea); + createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_CONTENT_TYPE), currentColumn, + columnCount, attributeArea); + createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH), currentColumn, + columnCount, attributeArea); + createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED), currentColumn, + columnCount, attributeArea); + } + + private void createFlagEditors(int columnCount, Composite advancedComposite) { + int currentFlagColumn = 1; + + for (TaskAttribute attribute : attachment.getAttributes().values()) { + if (!attribute.getId().startsWith("task.common.kind.flag")) { //$NON-NLS-1$ + continue; + } + String type = attribute.getMetaData().getType(); + if (type != null) { + AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, attribute); + editor.setReadOnly(readOnly); + + if (editor.hasLabel()) { + editor.createLabelControl(advancedComposite, toolkit); + Label label = editor.getLabelControl(); + label.setBackground(advancedComposite.getBackground()); + GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH, + SWT.DEFAULT).create(); + if (currentFlagColumn > 1) { + gd.horizontalIndent = COLUMN_GAP; + gd.widthHint = LABEL_WIDTH + COLUMN_GAP; + } + label.setLayoutData(gd); + currentFlagColumn++; + } + editor.createControl(advancedComposite, toolkit); + GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false); + gd.widthHint = 150;//COLUMN_WIDTH; + gd.horizontalSpan = 3; + editor.getControl().setLayoutData(gd); + currentFlagColumn += gd.horizontalSpan; + currentFlagColumn %= columnCount; + } + } + } + + private void createCommntEditor(int currentColumn, int columnCount, Composite attributeArea) { + TaskAttribute commentAttribute = attachment.getAttribute("comment"); //$NON-NLS-1$ + if (commentAttribute == null || readOnly) { + return; + } + String type = commentAttribute.getMetaData().getType(); + if (type != null) { + AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, commentAttribute); + String labelString = editor.getLabel(); + if (editor.hasLabel()) { + editor.createLabelControl(attributeArea, toolkit); + if (!labelString.equals("")) { //$NON-NLS-1$ + Label label = editor.getLabelControl(); + label.setBackground(attributeArea.getBackground()); + GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH, + SWT.DEFAULT).create(); + if (currentColumn > 1) { + gd.horizontalIndent = COLUMN_GAP; + gd.widthHint = LABEL_WIDTH + COLUMN_GAP; + } + label.setLayoutData(gd); + } + } + editor.createControl(attributeArea, toolkit); + GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false); + gd.heightHint = MULTI_ROW_HEIGHT; + gd.widthHint = MULTI_COLUMN_WIDTH; + gd.horizontalSpan = columnCount - currentColumn + 1; + editor.getControl().setLayoutData(gd); + } + } + + private Composite createFlagSection(Composite container) { + flagExpandComposite = toolkit.createExpandableComposite(container, ExpandableComposite.COMPACT + | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); + flagExpandComposite.setFont(container.getFont()); + flagExpandComposite.setBackground(container.getBackground()); + flagExpandComposite.setText(Messages.BugzillaTaskAttachmentPage_Advanced); + flagExpandComposite.setLayout(new GridLayout(4, false)); + GridData g = new GridData(GridData.FILL_HORIZONTAL); + g.horizontalSpan = 4; + flagExpandComposite.setLayoutData(g); + flagExpandComposite.addExpansionListener(new ExpansionAdapter() { + @Override + public void expansionStateChanged(ExpansionEvent e) { + parentShell.getDisplay().getActiveShell().pack(); + } + }); + + scrollComposite = new Composite(flagExpandComposite, SWT.NONE); + scrollComposite.setLayout(new GridLayout(4, false)); + flagExpandComposite.setClient(scrollComposite); + return scrollComposite; + } + +} \ No newline at end of file