diff options
author | fbecker | 2010-01-24 14:30:08 +0000 |
---|---|---|
committer | fbecker | 2010-01-24 14:30:08 +0000 |
commit | e3dedca614a22dab5d1af6ed04e66b2aeaa71fcd (patch) | |
tree | 68913c806ef58d65409b2998895069566b81aa56 /org.eclipse.mylyn.bugzilla.ui/src/org/eclipse | |
parent | 9feb36df276712024253f84cca1ed264371cddcf (diff) | |
download | org.eclipse.mylyn.tasks-e3dedca614a22dab5d1af6ed04e66b2aeaa71fcd.tar.gz org.eclipse.mylyn.tasks-e3dedca614a22dab5d1af6ed04e66b2aeaa71fcd.tar.xz org.eclipse.mylyn.tasks-e3dedca614a22dab5d1af6ed04e66b2aeaa71fcd.zip |
ASSIGNED - bug 272207: [patch] Include iplog flag for patches on bugzilla task editor
https://bugs.eclipse.org/bugs/show_bug.cgi?id=272207
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.ui/src/org/eclipse')
10 files changed, 639 insertions, 20 deletions
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaAttachmentUpdateAction.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaAttachmentUpdateAction.java new file mode 100644 index 000000000..a4b0a6e2c --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaAttachmentUpdateAction.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * 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: + * Frank Becker - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.bugzilla.ui.action; + +import java.util.List; + +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.window.Window; +import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants; +import org.eclipse.mylyn.internal.bugzilla.ui.dialogs.BugzillaAttachmentDialog; +import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage; +import org.eclipse.mylyn.internal.bugzilla.ui.editor.FlagAttributeEditor; +import org.eclipse.mylyn.internal.tasks.core.TaskTask; +import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; +import org.eclipse.mylyn.tasks.core.ITask; +import org.eclipse.mylyn.tasks.core.ITaskAttachment; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.core.data.ITaskDataWorkingCopy; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData; +import org.eclipse.mylyn.tasks.core.data.TaskData; +import org.eclipse.mylyn.tasks.core.data.TaskDataModel; +import org.eclipse.mylyn.tasks.ui.TasksUi; +import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor; +import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory; +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 + */ +@SuppressWarnings("restriction") +public class BugzillaAttachmentUpdateAction extends BaseSelectionListenerAction implements IViewActionDelegate { + + private ISelection currentSelection; + + public BugzillaAttachmentUpdateAction() { + 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; + + ITask attachmentTask = attachment.getTask(); + ITask nTask = new TaskTask(attachmentTask.getConnectorKind(), attachmentTask.getRepositoryUrl(), + attachmentTask.getTaskId() + "attachment"); //$NON-NLS-1$ + + TaskData editTaskData = new TaskData(attachment.getTaskAttribute().getTaskData().getAttributeMapper(), + attachment.getTaskAttribute().getTaskData().getConnectorKind(), attachment.getTaskAttribute() + .getTaskData() + .getRepositoryUrl(), attachment.getTaskAttribute().getTaskData().getTaskId()); + editTaskData.setVersion(attachment.getTaskAttribute().getTaskData().getVersion()); + TaskAttribute target0 = editTaskData.getRoot(); + TaskAttribute temp = attachment.getTaskAttribute(); + target0.setValues(temp.getValues()); + for (TaskAttribute child : temp.getAttributes().values()) { + target0.deepAddCopy(child); + } + + TaskAttribute comment = target0.createAttribute("comment"); //$NON-NLS-1$ + TaskAttributeMetaData commentMeta = comment.getMetaData(); + commentMeta.setType(TaskAttribute.TYPE_LONG_RICH_TEXT); + commentMeta.setLabel(Messages.BugzillaAttachmentUpdateAction_Comment); + + ITaskDataWorkingCopy workingCopy = TasksUi.getTaskDataManager().createWorkingCopy(nTask, editTaskData); + TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository( + attachment.getTaskAttribute().getTaskData().getRepositoryUrl()); + final TaskDataModel model = new TaskDataModel(repository, nTask, workingCopy); + AttributeEditorFactory factory = new AttributeEditorFactory(model, repository, + bugzillaTaskEditorPage.getEditorSite()) { + @Override + public AbstractAttributeEditor createEditor(String type, final TaskAttribute taskAttribute) { + AbstractAttributeEditor editor; + if (IBugzillaConstants.EDITOR_TYPE_FLAG.equals(type)) { + editor = new FlagAttributeEditor(model, taskAttribute, 350); + } else { + editor = super.createEditor(type, taskAttribute); + if (TaskAttribute.TYPE_BOOLEAN.equals(type)) { + editor.setDecorationEnabled(false); + } + } + return editor; + } + }; + + TaskAttribute target = workingCopy.getLocalData().getRoot(); + BugzillaAttachmentDialog dialog = new BugzillaAttachmentDialog(shell, model, factory, target, false); + if (dialog.open() == Window.OK) { + TaskAttribute attachmentAttribute = attachment.getTaskAttribute(); + for (TaskAttribute child : target.getAttributes().values()) { + attachmentAttribute.deepAddCopy(child); + } + final ChangeAttachmentJob job = new ChangeAttachmentJob(attachment, taskEditor); + job.setUser(true); + job.addJobChangeListener(new JobChangeAdapter() { + + @Override + public void done(IJobChangeEvent event) { + IFormPage formPage = taskEditor.getActivePageInstance(); + if (formPage instanceof BugzillaTaskEditorPage) { + final BugzillaTaskEditorPage bugzillaPage = (BugzillaTaskEditorPage) formPage; + if (job.getError() != null) { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + bugzillaPage.getTaskEditor().setMessage(job.getError().getMessage(), + IMessageProvider.ERROR); + } + }); + } else { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + bugzillaPage.refreshFormContent(); + } + }); + } + } + } + }); + job.schedule(); + } + } + } + } + + @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<ITaskAttachment> attachmentList = sructuredSelection.toList(); + if (attachmentList != null && attachmentList.size() == 1) { + action.setEnabled(true); + } else { + action.setEnabled(false); + } + } +} diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/ChangeAttachmentJob.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/ChangeAttachmentJob.java new file mode 100644 index 000000000..f754da27d --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/ChangeAttachmentJob.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * 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: + * Frank Becker - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.bugzilla.ui.action; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; +import org.eclipse.mylyn.commons.core.StatusHandler; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaTaskDataHandler; +import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage; +import org.eclipse.mylyn.internal.provisional.commons.ui.CommonFormUtil; +import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants; +import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; +import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; +import org.eclipse.mylyn.tasks.core.ITask; +import org.eclipse.mylyn.tasks.core.ITaskAttachment; +import org.eclipse.mylyn.tasks.ui.TasksUi; +import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage; +import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.forms.editor.IFormPage; +import org.eclipse.ui.forms.widgets.Section; + +/** + * @author Frank Becker + */ +@SuppressWarnings("restriction") +public class ChangeAttachmentJob extends Job { + + private final ITaskAttachment attachment; + + private final TaskEditor editor; + + private IStatus error; + + public ChangeAttachmentJob(ITaskAttachment attachment, TaskEditor editor) { + super(Messages.UpdateAttachmentJob_update_attachment); + this.attachment = attachment; + this.editor = editor; + } + + public IStatus getError() { + return error; + } + + @Override + protected IStatus run(IProgressMonitor monitor) { + final ITask task; + task = editor.getTaskEditorInput().getTask(); + + if (!task.getConnectorKind().equals(BugzillaCorePlugin.CONNECTOR_KIND)) { + return Status.OK_STATUS; + } + AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector( + task.getConnectorKind()); + monitor.beginTask(Messages.UpdateAttachmentJob_update_attachments, 20); + try { + ((BugzillaTaskDataHandler) connector.getTaskDataHandler()).postUpdateAttachment( + attachment.getTaskRepository(), attachment.getTaskAttribute(), "update", monitor); //$NON-NLS-1$ + monitor.worked(10); + + if (attachment != null) { + if (connector != null) { + TasksUiInternal.synchronizeTask(connector, task, true, new JobChangeAdapter() { + @Override + public void done(IJobChangeEvent event) { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + try { + if (editor != null) { + editor.refreshPages(); + editor.getEditorSite().getPage().activate(editor); + IFormPage formPage = editor.getActivePageInstance(); + if (formPage instanceof BugzillaTaskEditorPage) { + BugzillaTaskEditorPage bugzillaPage = (BugzillaTaskEditorPage) formPage; + Control control = bugzillaPage.getPart( + AbstractTaskEditorPage.ID_PART_ATTACHMENTS).getControl(); + if (control instanceof Section) { + Section section = (Section) control; + CommonFormUtil.setExpanded(section, true); + } + } + + } + } finally { + if (editor != null) { + editor.showBusy(false); + } + } + } + }); + } + }); + } + monitor.worked(10); + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + if (editor != null) { + editor.showBusy(true); + } + } + }); + } + } catch (OperationCanceledException e) { + return Status.CANCEL_STATUS; + } catch (CoreException e) { + StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, + "Update of an Attachment failed", e)); //$NON-NLS-1$ + } finally { + monitor.done(); + } + return Status.OK_STATUS; + } +} diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/Messages.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/Messages.java index bd777b562..37abff374 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/Messages.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/Messages.java @@ -29,4 +29,5 @@ public class Messages extends NLS { public static String UpdateAttachmentJob_update_attachment; + public static String BugzillaAttachmentUpdateAction_Comment; } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/messages.properties b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/messages.properties index dcbd1c8a9..dcecf1eba 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/messages.properties +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/messages.properties @@ -10,3 +10,4 @@ ############################################################################### UpdateAttachmentJob_update_attachment=Update attachment UpdateAttachmentJob_update_attachments=Update attachments +BugzillaAttachmentUpdateAction_Comment=Comment: diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/dialogs/BugzillaAttachmentDialog.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/dialogs/BugzillaAttachmentDialog.java new file mode 100644 index 000000000..007d37aa8 --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/dialogs/BugzillaAttachmentDialog.java @@ -0,0 +1,289 @@ +/******************************************************************************* + * 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: + * Frank Becker - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.bugzilla.ui.dialogs; + +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.tasklist.Messages; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.eclipse.mylyn.tasks.core.data.TaskDataModel; +import org.eclipse.mylyn.tasks.core.data.TaskDataModelEvent; +import org.eclipse.mylyn.tasks.core.data.TaskDataModelListener; +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; + + private AbstractAttributeEditor commentEditor; + + private final TaskDataModel model; + + private boolean changed = false; + + public BugzillaAttachmentDialog(Shell parentShell, TaskDataModel model, AttributeEditorFactory factory, + TaskAttribute attachment, boolean readonly) { + super(parentShell); + this.attachment = attachment; + this.parentShell = parentShell; + this.readOnly = readonly; + attributeEditorFactory = factory; + this.model = model; + model.addModelListener(new TaskDataModelListener() { + + @Override + public void attributeChanged(TaskDataModelEvent event) { + if (!changed) { + changed = true; + getOkButton().setEnabled(changed); + + } + } + + }); + toolkit = new FormToolkit(Display.getCurrent()); + this.setTitle(readonly ? Messages.BugzillaAttachmentDialog_DetailTitle + : Messages.BugzillaAttachmentDialog_DetailTitle); + } + + @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); + GridLayout layout = new GridLayout(4, false); + attributeArea.setLayout(layout); + createAttributeEditors(currentColumn, columnCount, attributeArea); + createCommentEditor(currentColumn, columnCount, attributeArea); + Composite advancedComposite = createFlagSection(attributeArea); + createFlagEditors(columnCount, advancedComposite); + createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_URL), currentColumn, columnCount, + advancedComposite); + 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(TaskAttribute.TYPE_BOOLEAN) || type.equals(TaskAttribute.TYPE_SHORT_TEXT) + || type.equals(TaskAttribute.TYPE_URL)) { + gd.horizontalSpan = 3; + } else { + gd.horizontalSpan = 1; + } + editor.getControl().setLayoutData(gd); + editor.getControl().setBackground(parentShell.getBackground()); + 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; + editor.getControl().setBackground(parentShell.getBackground()); + } + } + } + + private void createCommentEditor(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) { + commentEditor = attributeEditorFactory.createEditor(type, commentAttribute); + String labelString = commentEditor.getLabel(); + if (commentEditor.hasLabel()) { + commentEditor.createLabelControl(attributeArea, toolkit); + if (!labelString.equals("")) { //$NON-NLS-1$ + Label label = commentEditor.getLabelControl(); + label.setBackground(attributeArea.getBackground()); + GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.TOP).hint(LABEL_WIDTH, + SWT.DEFAULT).create(); + if (currentColumn > 1) { + gd.horizontalIndent = COLUMN_GAP; + gd.widthHint = LABEL_WIDTH + COLUMN_GAP; + } + label.setLayoutData(gd); + } + } + commentEditor.createControl(attributeArea, toolkit); + commentEditor.getControl().setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false); + gd.heightHint = MULTI_ROW_HEIGHT; + gd.widthHint = MULTI_COLUMN_WIDTH; + gd.horizontalSpan = 2;//columnCount - currentColumn + 1; + commentEditor.getControl().setLayoutData(gd); + toolkit.paintBordersFor(attributeArea); + } + } + + 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); + GridLayout gLayout = new GridLayout(4, false); + gLayout.horizontalSpacing = 0; + gLayout.marginWidth = 0; + 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); + GridLayout gLayout2 = new GridLayout(4, false); + gLayout2.horizontalSpacing = 0; + scrollComposite.setLayout(gLayout2); + flagExpandComposite.setClient(scrollComposite); + return scrollComposite; + } + + @Override + protected void okPressed() { + commentEditor.getControl().forceFocus(); + super.okPressed(); + } + + @Override + protected Control createButtonBar(Composite parent) { + Control control = super.createButtonBar(parent); + getOkButton().setText(Messages.BugzillaAttachmentDialog_OK_ButtonText); + getOkButton().setEnabled(changed); + return control; + } + +}
\ No newline at end of file diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java index 0040bff01..04a98330f 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java @@ -139,7 +139,7 @@ public class BugzillaTaskEditorPage extends AbstractTaskEditorPage { } else if (IBugzillaConstants.EDITOR_TYPE_VOTES.equals(type)) { editor = new BugzillaVotesEditor(getModel(), taskAttribute); } else if (IBugzillaConstants.EDITOR_TYPE_FLAG.equals(type)) { - editor = new FlagAttributeEditor(getModel(), taskAttribute); + editor = new FlagAttributeEditor(getModel(), taskAttribute, 78); } else { editor = super.createEditor(type, taskAttribute); if (TaskAttribute.TYPE_BOOLEAN.equals(type)) { diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/FlagAttributeEditor.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/FlagAttributeEditor.java index 9194663e3..241f59bf2 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/FlagAttributeEditor.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/FlagAttributeEditor.java @@ -20,8 +20,6 @@ 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.custom.CCombo; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; @@ -41,17 +39,20 @@ public class FlagAttributeEditor extends AbstractAttributeEditor { private Text requesteeText; - public FlagAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) { + private final int requesteeTextHint; + + public FlagAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute, int requesteeTextHint) { super(manager, taskAttribute); setLayoutHint(new LayoutHint(RowSpan.SINGLE, ColumnSpan.SINGLE)); if (taskAttribute.getAttribute("state") != null) { //$NON-NLS-1$ setReadOnly(taskAttribute.getAttribute("state").getMetaData().isReadOnly()); //$NON-NLS-1$ } + this.requesteeTextHint = requesteeTextHint; } @Override public void createControl(Composite parent, FormToolkit toolkit) { - Composite composite = toolkit.createComposite(parent); + final Composite composite = toolkit.createComposite(parent); GridLayout layout = new GridLayout(3, false); layout.marginWidth = 1; composite.setLayout(layout); @@ -60,10 +61,21 @@ public class FlagAttributeEditor extends AbstractAttributeEditor { toolkit.adapt(text, false, false); text.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.FALSE); text.setText(getValueLabel()); + text.setBackground(parent.getBackground()); + text.setEditable(false); String tooltip = getTaskAttribute().getMetaData().getLabel(); if (tooltip != null) { text.setToolTipText(tooltip); } + TaskAttribute requestee = getTaskAttribute().getAttribute("requestee"); //$NON-NLS-1$ + if (!"".equals(requestee.getValue())) { //$NON-NLS-1$ + text = new Text(composite, SWT.FLAT | SWT.READ_ONLY); + toolkit.adapt(text, false, false); + text.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.FALSE); + text.setText(requestee.getValue()); + text.setBackground(parent.getBackground()); + text.setEditable(false); + } } else { combo = new CCombo(composite, SWT.FLAT | SWT.READ_ONLY); toolkit.adapt(combo, false, false); @@ -106,17 +118,8 @@ public class FlagAttributeEditor extends AbstractAttributeEditor { requesteeText = toolkit.createText(composite, requestee.getValue()); requesteeText.setEnabled("?".equals(getValueLabel())); //$NON-NLS-1$ GridData requesteeData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); - requesteeData.widthHint = 78; + requesteeData.widthHint = requesteeTextHint; requesteeText.setLayoutData(requesteeData); - requesteeText.addFocusListener(new FocusListener() { - - public void focusGained(FocusEvent e) { - } - - public void focusLost(FocusEvent e) { - setRequestee(requesteeText.getText()); - } - }); } } toolkit.paintBordersFor(composite); @@ -149,8 +152,10 @@ public class FlagAttributeEditor extends AbstractAttributeEditor { public void setRequestee(String value) { TaskAttribute requestee = getTaskAttribute().getAttribute("requestee"); //$NON-NLS-1$ if (requestee != null) { - getAttributeMapper().setValue(getTaskAttribute().getAttribute("requestee"), value); //$NON-NLS-1$ - attributeChanged(); + if (!requestee.getValue().equals(value)) { + getAttributeMapper().setValue(requestee, value); + attributeChanged(); + } } } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskAttachmentPage.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskAttachmentPage.java index 755394231..9aa73c0a0 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskAttachmentPage.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskAttachmentPage.java @@ -160,7 +160,7 @@ public class BugzillaTaskAttachmentPage extends TaskAttachmentPage { | 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; diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/Messages.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/Messages.java index d21e2e8c5..e31a16418 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/Messages.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/Messages.java @@ -79,5 +79,10 @@ public class Messages extends NLS { 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_OK_ButtonText; + } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/messages.properties b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/messages.properties index d4bb37498..801f60e9a 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/messages.properties +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/messages.properties @@ -38,4 +38,6 @@ BugzillaRepositorySettingsPage_Retrieving_repository_configuration=Retrieving re 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 Details +BugzillaAttachmentDialog_OK_ButtonText=Update |