View | Details | Raw Unified | Return to bug 272207 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskAttachmentPage.java (-1 / +1 lines)
Lines 157-163 Link Here
157
				| ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR);
157
				| ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR);
158
		flagExpandComposite.setFont(container.getFont());
158
		flagExpandComposite.setFont(container.getFont());
159
		flagExpandComposite.setBackground(container.getBackground());
159
		flagExpandComposite.setBackground(container.getBackground());
160
		flagExpandComposite.setText(Messages.BugzillaTaskAttachmentPage_flags);
160
		flagExpandComposite.setText(Messages.BugzillaTaskAttachmentPage_Advanced);
161
		flagExpandComposite.setLayout(new GridLayout(3, false));
161
		flagExpandComposite.setLayout(new GridLayout(3, false));
162
		GridData g = new GridData(GridData.FILL_HORIZONTAL);
162
		GridData g = new GridData(GridData.FILL_HORIZONTAL);
163
		g.horizontalSpan = 3;
163
		g.horizontalSpan = 3;
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/messages.properties (-1 / +3 lines)
Lines 38-41 Link Here
38
BugzillaRepositorySettingsPage_Server_URL_is_invalid=Server URL is invalid.
38
BugzillaRepositorySettingsPage_Server_URL_is_invalid=Server URL is invalid.
39
BugzillaRepositorySettingsPage_supports_bugzilla_X=Supports Bugzilla {0}
39
BugzillaRepositorySettingsPage_supports_bugzilla_X=Supports Bugzilla {0}
40
BugzillaRepositorySettingsPage_Validating_server_settings=Validating server settings
40
BugzillaRepositorySettingsPage_Validating_server_settings=Validating server settings
41
BugzillaTaskAttachmentPage_flags=Flags
41
BugzillaTaskAttachmentPage_Advanced=Advanced
42
BugzillaAttachmentDialog_DetailTitle=Attachment Detail of {0}
43
BugzillaAttachmentDialog_UpdateTitle=Update of Attachment {0}
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/Messages.java (-1 / +5 lines)
Lines 79-83 Link Here
79
79
80
	public static String BugzillaRepositorySettingsPage_Validating_server_settings;
80
	public static String BugzillaRepositorySettingsPage_Validating_server_settings;
81
81
82
	public static String BugzillaTaskAttachmentPage_flags;
82
	public static String BugzillaTaskAttachmentPage_Advanced;
83
84
	public static String BugzillaAttachmentDialog_DetailTitle;
85
86
	public static String BugzillaAttachmentDialog_UpdateTitle;
83
}
87
}
(-)plugin.xml (-1 / +17 lines)
Lines 96-102 Link Here
96
               menubarPath="org.eclipse.mylyn.bugzilla.ui.attachments.mark/markadditions"
96
               menubarPath="org.eclipse.mylyn.bugzilla.ui.attachments.mark/markadditions"
97
               tooltip="Mark attachment as not obsolete">
97
               tooltip="Mark attachment as not obsolete">
98
         </action>
98
         </action>
99
          <action
99
         <action
100
               class="org.eclipse.mylyn.internal.bugzilla.ui.action.BugzillaObsoleteAttachmentAction"
100
               class="org.eclipse.mylyn.internal.bugzilla.ui.action.BugzillaObsoleteAttachmentAction"
101
               enablesFor="*"
101
               enablesFor="*"
102
               id="org.eclipse.mylyn.bugzilla.ui.contribution.attachment.obsolete"
102
               id="org.eclipse.mylyn.bugzilla.ui.contribution.attachment.obsolete"
Lines 104-109 Link Here
104
               menubarPath="org.eclipse.mylyn.bugzilla.ui.attachments.mark/markadditions"
104
               menubarPath="org.eclipse.mylyn.bugzilla.ui.attachments.mark/markadditions"
105
               tooltip="Mark attachment as obsolete">
105
               tooltip="Mark attachment as obsolete">
106
         </action>
106
         </action>
107
         <action
108
               class="org.eclipse.mylyn.internal.bugzilla.ui.action.BugzillaAttachmentDetailAction"
109
               enablesFor="*"
110
               id="org.eclipse.mylyn.bugzilla.ui.contribution.attachment.detail"
111
               label="Detail..."
112
               menubarPath="org.eclipse.mylyn.bugzilla.ui.attachments.mark"
113
               tooltip="Show Details">
114
         </action>
115
         <action
116
               class="org.eclipse.mylyn.internal.bugzilla.ui.action.BugzillaAttachmentUpdateAction"
117
               enablesFor="*"
118
               id="org.eclipse.mylyn.bugzilla.ui.contribution.attachment.update"
119
               label="Update..."
120
               menubarPath="org.eclipse.mylyn.bugzilla.ui.attachments.mark"
121
               tooltip="Update Attachment">
122
         </action>
107
          <menu
123
          <menu
108
                id="org.eclipse.mylyn.bugzilla.ui.attachments.mark"
124
                id="org.eclipse.mylyn.bugzilla.ui.attachments.mark"
109
                label="Mark as"
125
                label="Mark as"
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/action/messages.properties (+1 lines)
Lines 10-12 Link Here
10
###############################################################################
10
###############################################################################
11
UpdateAttachmentJob_update_attachment=Update attachment
11
UpdateAttachmentJob_update_attachment=Update attachment
12
UpdateAttachmentJob_update_attachments=Update attachments
12
UpdateAttachmentJob_update_attachments=Update attachments
13
BugzillaAttachmentUpdateAction_Comment=Comment :
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/action/Messages.java (+1 lines)
Lines 29-32 Link Here
29
29
30
	public static String UpdateAttachmentJob_update_attachment;
30
	public static String UpdateAttachmentJob_update_attachment;
31
31
32
	public static String BugzillaAttachmentUpdateAction_Comment;
32
}
33
}
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/action/ChangeAttachmentJob.java (+131 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Frank Becker and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Frank Becker - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.bugzilla.ui.action;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.OperationCanceledException;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
20
import org.eclipse.core.runtime.jobs.Job;
21
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
22
import org.eclipse.mylyn.commons.core.StatusHandler;
23
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
24
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaTaskDataHandler;
25
import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage;
26
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonFormUtil;
27
import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
28
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
29
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
30
import org.eclipse.mylyn.tasks.core.ITask;
31
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
32
import org.eclipse.mylyn.tasks.ui.TasksUi;
33
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
34
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
35
import org.eclipse.swt.widgets.Control;
36
import org.eclipse.ui.PlatformUI;
37
import org.eclipse.ui.forms.editor.IFormPage;
38
import org.eclipse.ui.forms.widgets.Section;
39
40
/**
41
 * @author Frank Becker
42
 */
43
@SuppressWarnings("restriction")
44
public class ChangeAttachmentJob extends Job {
45
46
	private final ITaskAttachment attachment;
47
48
	private final TaskEditor editor;
49
50
	private IStatus error;
51
52
	public ChangeAttachmentJob(ITaskAttachment attachment, TaskEditor editor) {
53
		super(Messages.UpdateAttachmentJob_update_attachment);
54
		this.attachment = attachment;
55
		this.editor = editor;
56
	}
57
58
	public IStatus getError() {
59
		return error;
60
	}
61
62
	@Override
63
	protected IStatus run(IProgressMonitor monitor) {
64
		final ITask task;
65
		task = editor.getTaskEditorInput().getTask();
66
67
		if (!task.getConnectorKind().equals(BugzillaCorePlugin.CONNECTOR_KIND)) {
68
			return Status.OK_STATUS;
69
		}
70
		AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector(
71
				task.getConnectorKind());
72
		monitor.beginTask(Messages.UpdateAttachmentJob_update_attachments, 20);
73
		try {
74
			((BugzillaTaskDataHandler) connector.getTaskDataHandler()).postUpdateAttachment(
75
					attachment.getTaskRepository(), attachment.getTaskAttribute(), "update", monitor); //$NON-NLS-1$
76
			monitor.worked(10);
77
78
			if (attachment != null) {
79
				if (connector != null) {
80
					TasksUiInternal.synchronizeTask(connector, task, true, new JobChangeAdapter() {
81
						@Override
82
						public void done(IJobChangeEvent event) {
83
							PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
84
								public void run() {
85
									try {
86
										if (editor != null) {
87
											editor.refreshPages();
88
											editor.getEditorSite().getPage().activate(editor);
89
											IFormPage formPage = editor.getActivePageInstance();
90
											if (formPage instanceof BugzillaTaskEditorPage) {
91
												BugzillaTaskEditorPage bugzillaPage = (BugzillaTaskEditorPage) formPage;
92
												Control control = bugzillaPage.getPart(
93
														AbstractTaskEditorPage.ID_PART_ATTACHMENTS).getControl();
94
												if (control instanceof Section) {
95
													Section section = (Section) control;
96
													CommonFormUtil.setExpanded(section, true);
97
												}
98
											}
99
100
										}
101
									} finally {
102
										if (editor != null) {
103
											editor.showBusy(false);
104
										}
105
									}
106
								}
107
							});
108
						}
109
					});
110
				}
111
				monitor.worked(10);
112
				PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
113
					public void run() {
114
						if (editor != null) {
115
							editor.showBusy(true);
116
						}
117
					}
118
				});
119
			}
120
		} catch (OperationCanceledException e) {
121
			return Status.CANCEL_STATUS;
122
		} catch (CoreException e) {
123
			StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN,
124
					"Update of an Attachment failed", e)); //$NON-NLS-1$
125
			e.printStackTrace();
126
		} finally {
127
			monitor.done();
128
		}
129
		return Status.OK_STATUS;
130
	}
131
}
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaAttachmentUpdateAction.java (+191 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Frank Becker and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Frank Becker - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.bugzilla.ui.action;
13
14
import java.util.List;
15
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
18
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
19
import org.eclipse.jface.action.IAction;
20
import org.eclipse.jface.dialogs.IMessageProvider;
21
import org.eclipse.jface.viewers.ISelection;
22
import org.eclipse.jface.viewers.IStructuredSelection;
23
import org.eclipse.jface.window.Window;
24
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants;
25
import org.eclipse.mylyn.internal.bugzilla.ui.dialogs.BugzillaAttachmentDialog;
26
import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage;
27
import org.eclipse.mylyn.internal.bugzilla.ui.editor.FlagAttributeEditor;
28
import org.eclipse.mylyn.internal.tasks.core.TaskTask;
29
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
30
import org.eclipse.mylyn.tasks.core.ITask;
31
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
32
import org.eclipse.mylyn.tasks.core.TaskRepository;
33
import org.eclipse.mylyn.tasks.core.data.ITaskDataWorkingCopy;
34
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
35
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData;
36
import org.eclipse.mylyn.tasks.core.data.TaskData;
37
import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
38
import org.eclipse.mylyn.tasks.ui.TasksUi;
39
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
40
import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory;
41
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
42
import org.eclipse.swt.widgets.Shell;
43
import org.eclipse.ui.IEditorPart;
44
import org.eclipse.ui.IViewActionDelegate;
45
import org.eclipse.ui.IViewPart;
46
import org.eclipse.ui.IWorkbenchPage;
47
import org.eclipse.ui.IWorkbenchPartSite;
48
import org.eclipse.ui.IWorkbenchWindow;
49
import org.eclipse.ui.PlatformUI;
50
import org.eclipse.ui.actions.BaseSelectionListenerAction;
51
import org.eclipse.ui.forms.editor.IFormPage;
52
53
@SuppressWarnings("restriction")
54
public class BugzillaAttachmentUpdateAction extends BaseSelectionListenerAction implements IViewActionDelegate {
55
56
	private ISelection currentSelection;
57
58
	public BugzillaAttachmentUpdateAction() {
59
		super("BugzillaAttachmentDetailAction"); //$NON-NLS-1$
60
	}
61
62
	public void init(IViewPart view) {
63
		// ignore
64
	}
65
66
	public void run(IAction action) {
67
		IStructuredSelection selection = null;
68
		if (currentSelection instanceof IStructuredSelection) {
69
			selection = (IStructuredSelection) currentSelection;
70
		}
71
		if (selection == null || selection.isEmpty() || selection.size() != 1) {
72
			return;
73
		}
74
		ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement();
75
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
76
		IWorkbenchPage page = window.getActivePage();
77
		IEditorPart activeEditor = page.getActiveEditor();
78
		IWorkbenchPartSite site = activeEditor.getSite();
79
		Shell shell = site.getShell();
80
		if (activeEditor instanceof TaskEditor) {
81
			final TaskEditor taskEditor = (TaskEditor) activeEditor;
82
			IFormPage taskEditorPage = taskEditor.findPage("id"); //$NON-NLS-1$
83
			if (taskEditorPage instanceof BugzillaTaskEditorPage) {
84
				BugzillaTaskEditorPage bugzillaTaskEditorPage = (BugzillaTaskEditorPage) taskEditorPage;
85
86
				ITask attachmentTask = attachment.getTask();
87
				ITask nTask = new TaskTask(attachmentTask.getConnectorKind(), attachmentTask.getRepositoryUrl(),
88
						attachmentTask.getTaskId() + "attachment"); //$NON-NLS-1$
89
90
				TaskData editTaskData = new TaskData(attachment.getTaskAttribute().getTaskData().getAttributeMapper(),
91
						attachment.getTaskAttribute().getTaskData().getConnectorKind(), attachment.getTaskAttribute()
92
								.getTaskData()
93
								.getRepositoryUrl(), attachment.getTaskAttribute().getTaskData().getTaskId());
94
				editTaskData.setVersion(attachment.getTaskAttribute().getTaskData().getVersion());
95
				TaskAttribute target0 = editTaskData.getRoot();
96
				TaskAttribute temp = attachment.getTaskAttribute();
97
				target0.setValues(temp.getValues());
98
				for (TaskAttribute child : temp.getAttributes().values()) {
99
					target0.deepAddCopy(child);
100
				}
101
102
				TaskAttribute comment = target0.createAttribute("comment"); //$NON-NLS-1$
103
				TaskAttributeMetaData commentMeta = comment.getMetaData();
104
				commentMeta.setType(TaskAttribute.TYPE_LONG_RICH_TEXT);
105
				commentMeta.setLabel(Messages.BugzillaAttachmentUpdateAction_Comment);
106
107
				ITaskDataWorkingCopy workingCopy = TasksUi.getTaskDataManager().createWorkingCopy(nTask, editTaskData);
108
				try {
109
					workingCopy.save(null, null);
110
				} catch (CoreException e) {
111
					// TODO Auto-generated catch block
112
					e.printStackTrace();
113
				}
114
				TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(
115
						attachment.getTaskAttribute().getTaskData().getRepositoryUrl());
116
				final TaskDataModel model = new TaskDataModel(repository, nTask, workingCopy);
117
				AttributeEditorFactory factory = new AttributeEditorFactory(model, repository,
118
						bugzillaTaskEditorPage.getEditorSite()) {
119
					@Override
120
					public AbstractAttributeEditor createEditor(String type, final TaskAttribute taskAttribute) {
121
						AbstractAttributeEditor editor;
122
						if (IBugzillaConstants.EDITOR_TYPE_FLAG.equals(type)) {
123
							editor = new FlagAttributeEditor(model, taskAttribute);
124
						} else {
125
							editor = super.createEditor(type, taskAttribute);
126
							if (TaskAttribute.TYPE_BOOLEAN.equals(type)) {
127
								editor.setDecorationEnabled(false);
128
							}
129
						}
130
						return editor;
131
					}
132
				};
133
134
				TaskAttribute target = workingCopy.getLocalData().getRoot();
135
				BugzillaAttachmentDialog dialog = new BugzillaAttachmentDialog(shell, bugzillaTaskEditorPage, factory,
136
						target, false);
137
				if (dialog.open() == Window.OK) {
138
					TaskAttribute attachmentAttribute = attachment.getTaskAttribute();
139
					for (TaskAttribute child : target.getAttributes().values()) {
140
						attachmentAttribute.deepAddCopy(child);
141
					}
142
					final ChangeAttachmentJob job = new ChangeAttachmentJob(attachment, taskEditor);
143
					job.setUser(true);
144
					job.addJobChangeListener(new JobChangeAdapter() {
145
146
						@Override
147
						public void done(IJobChangeEvent event) {
148
							IFormPage formPage = taskEditor.getActivePageInstance();
149
							if (formPage instanceof BugzillaTaskEditorPage) {
150
								final BugzillaTaskEditorPage bugzillaPage = (BugzillaTaskEditorPage) formPage;
151
								if (job.getError() != null) {
152
									PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
153
										public void run() {
154
											bugzillaPage.getTaskEditor().setMessage(job.getError().getMessage(),
155
													IMessageProvider.ERROR);
156
										}
157
									});
158
								} else {
159
									PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
160
										public void run() {
161
											bugzillaPage.refreshFormContent();
162
										}
163
									});
164
								}
165
							}
166
						}
167
					});
168
					job.schedule();
169
				}
170
			}
171
		}
172
	}
173
174
	@SuppressWarnings("unchecked")
175
	public void selectionChanged(IAction action, ISelection selection) {
176
		this.currentSelection = selection;
177
		IStructuredSelection sructuredSelection = null;
178
		if (selection instanceof IStructuredSelection) {
179
			sructuredSelection = (IStructuredSelection) currentSelection;
180
		}
181
		if (sructuredSelection == null || sructuredSelection.isEmpty()) {
182
			return;
183
		}
184
		List<ITaskAttachment> attachmentList = sructuredSelection.toList();
185
		if (attachmentList != null && attachmentList.size() == 1) {
186
			action.setEnabled(true);
187
		} else {
188
			action.setEnabled(false);
189
		}
190
	}
191
}
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaAttachmentDetailAction.java (+92 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.bugzilla.ui.action;
13
14
import java.util.List;
15
16
import org.eclipse.jface.action.IAction;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.mylyn.internal.bugzilla.ui.dialogs.BugzillaAttachmentDialog;
20
import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage;
21
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
22
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
23
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.ui.IEditorPart;
25
import org.eclipse.ui.IViewActionDelegate;
26
import org.eclipse.ui.IViewPart;
27
import org.eclipse.ui.IWorkbenchPage;
28
import org.eclipse.ui.IWorkbenchPartSite;
29
import org.eclipse.ui.IWorkbenchWindow;
30
import org.eclipse.ui.PlatformUI;
31
import org.eclipse.ui.actions.BaseSelectionListenerAction;
32
import org.eclipse.ui.forms.editor.IFormPage;
33
34
public class BugzillaAttachmentDetailAction extends BaseSelectionListenerAction implements IViewActionDelegate {
35
36
	private ISelection currentSelection;
37
38
	public BugzillaAttachmentDetailAction() {
39
		super("BugzillaAttachmentDetailAction"); //$NON-NLS-1$
40
	}
41
42
	public void init(IViewPart view) {
43
		// ignore
44
45
	}
46
47
	public void run(IAction action) {
48
		IStructuredSelection selection = null;
49
		if (currentSelection instanceof IStructuredSelection) {
50
			selection = (IStructuredSelection) currentSelection;
51
		}
52
		if (selection == null || selection.isEmpty() || selection.size() != 1) {
53
			return;
54
		}
55
		ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement();
56
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
57
		IWorkbenchPage page = window.getActivePage();
58
		IEditorPart activeEditor = page.getActiveEditor();
59
		IWorkbenchPartSite site = activeEditor.getSite();
60
		Shell shell = site.getShell();
61
		if (activeEditor instanceof TaskEditor) {
62
			final TaskEditor taskEditor = (TaskEditor) activeEditor;
63
			IFormPage taskEditorPage = taskEditor.findPage("id"); //$NON-NLS-1$
64
			if (taskEditorPage instanceof BugzillaTaskEditorPage) {
65
				BugzillaTaskEditorPage bugzillaTaskEditorPage = (BugzillaTaskEditorPage) taskEditorPage;
66
				BugzillaAttachmentDialog dialog = new BugzillaAttachmentDialog(shell, bugzillaTaskEditorPage,
67
						bugzillaTaskEditorPage.getAttributeEditorFactory(), attachment.getTaskAttribute(), true);
68
				dialog.open();
69
			}
70
		}
71
	}
72
73
	@SuppressWarnings("unchecked")
74
	public void selectionChanged(IAction action, ISelection selection) {
75
		this.currentSelection = selection;
76
		IStructuredSelection sructuredSelection = null;
77
		if (selection instanceof IStructuredSelection) {
78
			sructuredSelection = (IStructuredSelection) currentSelection;
79
		}
80
		if (sructuredSelection == null || sructuredSelection.isEmpty()) {
81
			return;
82
		}
83
		List<ITaskAttachment> attachmentList = sructuredSelection.toList();
84
		if (attachmentList != null && attachmentList.size() == 1) {
85
			action.setEnabled(true);
86
		} else {
87
			action.setEnabled(false);
88
		}
89
90
	}
91
92
}
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/dialogs/BugzillaAttachmentDialog.java (+249 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.bugzilla.ui.dialogs;
13
14
import java.text.MessageFormat;
15
16
import org.eclipse.jface.dialogs.Dialog;
17
import org.eclipse.jface.layout.GridDataFactory;
18
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute;
19
import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage;
20
import org.eclipse.mylyn.internal.bugzilla.ui.tasklist.Messages;
21
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
22
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
23
import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.swt.layout.GridLayout;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Control;
29
import org.eclipse.swt.widgets.Display;
30
import org.eclipse.swt.widgets.Label;
31
import org.eclipse.swt.widgets.Shell;
32
import org.eclipse.ui.dialogs.SelectionDialog;
33
import org.eclipse.ui.forms.events.ExpansionAdapter;
34
import org.eclipse.ui.forms.events.ExpansionEvent;
35
import org.eclipse.ui.forms.widgets.ExpandableComposite;
36
import org.eclipse.ui.forms.widgets.FormToolkit;
37
38
/**
39
 * @author Frank Becker
40
 */
41
public class BugzillaAttachmentDialog extends SelectionDialog {
42
43
	private final FormToolkit toolkit;
44
45
	private Composite scrollComposite;
46
47
	private ExpandableComposite flagExpandComposite = null;
48
49
	private final TaskAttribute attachment;
50
51
	private final Shell parentShell;
52
53
	private final boolean readOnly;
54
55
	private final AttributeEditorFactory attributeEditorFactory;
56
57
	private static final int LABEL_WIDTH = 120;
58
59
	private static final int COLUMN_GAP = 5;
60
61
	private static final int MULTI_ROW_HEIGHT = 55;
62
63
	private static final int COLUMN_WIDTH = 200;
64
65
	private static final int MULTI_COLUMN_WIDTH = COLUMN_WIDTH + 5 + COLUMN_GAP + LABEL_WIDTH + 5 + COLUMN_WIDTH;
66
67
	public BugzillaAttachmentDialog(Shell parentShell, BugzillaTaskEditorPage editor, AttributeEditorFactory factory,
68
			TaskAttribute attachment, boolean readonly) {
69
		super(parentShell);
70
		this.attachment = attachment;
71
		this.parentShell = parentShell;
72
		this.readOnly = readonly;
73
		attributeEditorFactory = factory;
74
		toolkit = new FormToolkit(Display.getCurrent());
75
		this.setTitle(MessageFormat.format(readonly ? Messages.BugzillaAttachmentDialog_DetailTitle
76
				: Messages.BugzillaAttachmentDialog_UpdateTitle, attachment.getValue()));
77
	}
78
79
	@Override
80
	protected Control createDialogArea(Composite parent) {
81
		int currentColumn = 1;
82
		int columnCount = 4;
83
		Composite composite = (Composite) super.createDialogArea(parent);
84
85
		initializeDialogUnits(composite);
86
87
		Composite attributeArea = new Composite(composite, SWT.FLAT);
88
		attributeArea.setLayout(new GridLayout(4, false));
89
		createAttributeEditors(currentColumn, columnCount, attributeArea);
90
		Composite advancedComposite = createFlagSection(attributeArea);
91
		createFlagEditors(columnCount, advancedComposite);
92
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_URL), currentColumn, columnCount,
93
				advancedComposite);
94
		createCommntEditor(currentColumn, columnCount, attributeArea);
95
		Dialog.applyDialogFont(composite);
96
		return composite;
97
	}
98
99
	private void createAttributeEditor(TaskAttribute attribute, int currentColumn, int columnCount,
100
			Composite attributeArea) {
101
		String type = attribute.getMetaData().getType();
102
		if (type != null) {
103
			AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, attribute);
104
			if (attribute.getId().equals(BugzillaAttribute.TOKEN.getKey())
105
					|| attribute.getId().equals("size") || attribute.getId().equals(TaskAttribute.ATTACHMENT_URL)) { //$NON-NLS-1$
106
				editor.setReadOnly(true);
107
			} else {
108
				editor.setReadOnly(readOnly);
109
			}
110
			if (editor.hasLabel()) {
111
				editor.createLabelControl(attributeArea, toolkit);
112
				Label label = editor.getLabelControl();
113
				label.setBackground(attributeArea.getBackground());
114
				String labelString = editor.getLabel();
115
				if (labelString != null && !labelString.equals("")) { //$NON-NLS-1$
116
					GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH,
117
							SWT.DEFAULT).create();
118
					if (currentColumn > 1) {
119
						gd.horizontalIndent = COLUMN_GAP;
120
						gd.widthHint = LABEL_WIDTH + COLUMN_GAP;
121
					}
122
					label.setLayoutData(gd);
123
					currentColumn++;
124
				}
125
			}
126
			editor.createControl(attributeArea, toolkit);
127
			GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
128
			if (type.equals("shortText") || type.equals("url")) { //$NON-NLS-1$//$NON-NLS-2$
129
				gd.horizontalSpan = 3;
130
			} else {
131
				gd.horizontalSpan = 1;
132
			}
133
			editor.getControl().setLayoutData(gd);
134
			if (attribute.getId().equals(TaskAttribute.ATTACHMENT_URL)) {
135
				editor.getControl().setEnabled(false);
136
			}
137
138
			currentColumn += gd.horizontalSpan;
139
			currentColumn %= columnCount;
140
		}
141
	}
142
143
	private void createAttributeEditors(int currentColumn, int columnCount, Composite attributeArea) {
144
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_DESCRIPTION), currentColumn,
145
				columnCount, attributeArea);
146
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_FILENAME), currentColumn,
147
				columnCount, attributeArea);
148
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_SIZE), currentColumn, columnCount,
149
				attributeArea);
150
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_CONTENT_TYPE), currentColumn,
151
				columnCount, attributeArea);
152
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH), currentColumn,
153
				columnCount, attributeArea);
154
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED), currentColumn,
155
				columnCount, attributeArea);
156
	}
157
158
	private void createFlagEditors(int columnCount, Composite advancedComposite) {
159
		int currentFlagColumn = 1;
160
161
		for (TaskAttribute attribute : attachment.getAttributes().values()) {
162
			if (!attribute.getId().startsWith("task.common.kind.flag")) { //$NON-NLS-1$
163
				continue;
164
			}
165
			String type = attribute.getMetaData().getType();
166
			if (type != null) {
167
				AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, attribute);
168
				editor.setReadOnly(readOnly);
169
170
				if (editor.hasLabel()) {
171
					editor.createLabelControl(advancedComposite, toolkit);
172
					Label label = editor.getLabelControl();
173
					label.setBackground(advancedComposite.getBackground());
174
					GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH,
175
							SWT.DEFAULT).create();
176
					if (currentFlagColumn > 1) {
177
						gd.horizontalIndent = COLUMN_GAP;
178
						gd.widthHint = LABEL_WIDTH + COLUMN_GAP;
179
					}
180
					label.setLayoutData(gd);
181
					currentFlagColumn++;
182
				}
183
				editor.createControl(advancedComposite, toolkit);
184
				GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
185
				gd.widthHint = 150;//COLUMN_WIDTH;
186
				gd.horizontalSpan = 3;
187
				editor.getControl().setLayoutData(gd);
188
				currentFlagColumn += gd.horizontalSpan;
189
				currentFlagColumn %= columnCount;
190
			}
191
		}
192
	}
193
194
	private void createCommntEditor(int currentColumn, int columnCount, Composite attributeArea) {
195
		TaskAttribute commentAttribute = attachment.getAttribute("comment"); //$NON-NLS-1$
196
		if (commentAttribute == null || readOnly) {
197
			return;
198
		}
199
		String type = commentAttribute.getMetaData().getType();
200
		if (type != null) {
201
			AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, commentAttribute);
202
			String labelString = editor.getLabel();
203
			if (editor.hasLabel()) {
204
				editor.createLabelControl(attributeArea, toolkit);
205
				if (!labelString.equals("")) { //$NON-NLS-1$
206
					Label label = editor.getLabelControl();
207
					label.setBackground(attributeArea.getBackground());
208
					GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH,
209
							SWT.DEFAULT).create();
210
					if (currentColumn > 1) {
211
						gd.horizontalIndent = COLUMN_GAP;
212
						gd.widthHint = LABEL_WIDTH + COLUMN_GAP;
213
					}
214
					label.setLayoutData(gd);
215
				}
216
			}
217
			editor.createControl(attributeArea, toolkit);
218
			GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
219
			gd.heightHint = MULTI_ROW_HEIGHT;
220
			gd.widthHint = MULTI_COLUMN_WIDTH;
221
			gd.horizontalSpan = columnCount - currentColumn + 1;
222
			editor.getControl().setLayoutData(gd);
223
		}
224
	}
225
226
	private Composite createFlagSection(Composite container) {
227
		flagExpandComposite = toolkit.createExpandableComposite(container, ExpandableComposite.COMPACT
228
				| ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR);
229
		flagExpandComposite.setFont(container.getFont());
230
		flagExpandComposite.setBackground(container.getBackground());
231
		flagExpandComposite.setText(Messages.BugzillaTaskAttachmentPage_Advanced);
232
		flagExpandComposite.setLayout(new GridLayout(4, false));
233
		GridData g = new GridData(GridData.FILL_HORIZONTAL);
234
		g.horizontalSpan = 4;
235
		flagExpandComposite.setLayoutData(g);
236
		flagExpandComposite.addExpansionListener(new ExpansionAdapter() {
237
			@Override
238
			public void expansionStateChanged(ExpansionEvent e) {
239
				parentShell.getDisplay().getActiveShell().pack();
240
			}
241
		});
242
243
		scrollComposite = new Composite(flagExpandComposite, SWT.NONE);
244
		scrollComposite.setLayout(new GridLayout(4, false));
245
		flagExpandComposite.setClient(scrollComposite);
246
		return scrollComposite;
247
	}
248
249
}
(-)src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java (+95 lines)
Lines 374-379 Link Here
374
			if (localuser) {
374
			if (localuser) {
375
				removeDomain(taskData);
375
				removeDomain(taskData);
376
			}
376
			}
377
			addMissingAttachmentFlags(taskData);
378
			updateAttachmentOptions(taskData);
377
		}
379
		}
378
	}
380
	}
379
381
Lines 729-732 Link Here
729
	public String getEncoding() {
731
	public String getEncoding() {
730
		return encoding;
732
		return encoding;
731
	}
733
	}
734
735
	public void updateAttachmentOptions(TaskData existingReport) {
736
		for (TaskAttribute attribute : new HashSet<TaskAttribute>(existingReport.getRoot().getAttributes().values())) {
737
738
			if (!attribute.getId().startsWith("task.common.attachment")) { //$NON-NLS-1$
739
				continue;
740
			}
741
742
			for (TaskAttribute attachmentAttribute : attribute.getAttributes().values()) {
743
				if (!attachmentAttribute.getId().startsWith("task.common.kind.flag")) { //$NON-NLS-1$
744
					continue;
745
				}
746
747
				TaskAttribute state = attachmentAttribute.getAttribute("state"); //$NON-NLS-1$
748
				attachmentAttribute.clearOptions();
749
750
				String nameValue = state.getMetaData().getLabel();
751
				state.putOption("", ""); //$NON-NLS-1$ //$NON-NLS-2$
752
				for (BugzillaFlag bugzillaFlag : flags) {
753
					if (nameValue.equals(bugzillaFlag.getName()) && bugzillaFlag.getType().equals("attachment")) { //$NON-NLS-1$
754
						if ("attachment".equals(bugzillaFlag.getType())) { //$NON-NLS-1$
755
							if (bugzillaFlag.isRequestable()) {
756
								state.putOption("?", "?"); //$NON-NLS-1$ //$NON-NLS-2$
757
							}
758
							break;
759
						}
760
					}
761
				}
762
				state.putOption("-", "-"); //$NON-NLS-1$ //$NON-NLS-2$
763
				state.putOption("+", "+"); //$NON-NLS-1$ //$NON-NLS-2$
764
				String flagNameValue = state.getMetaData().getLabel();
765
				for (BugzillaFlag bugzillaFlag : flags) {
766
					if (flagNameValue.equals(bugzillaFlag.getName()) && bugzillaFlag.getType().equals("attachment")) { //$NON-NLS-1$
767
						TaskAttribute requestee = attachmentAttribute.getAttribute("requestee"); //$NON-NLS-1$
768
						if (requestee == null) {
769
							requestee = attachmentAttribute.createMappedAttribute("requestee"); //$NON-NLS-1$
770
							requestee.getMetaData().defaults().setType(TaskAttribute.TYPE_SHORT_TEXT);
771
							requestee.setValue(""); //$NON-NLS-1$
772
						}
773
						requestee.getMetaData().setReadOnly(!bugzillaFlag.isSpecifically_requestable());
774
					}
775
				}
776
777
			}
778
		}
779
	}
780
781
	private void addMissingAttachmentFlags(TaskData taskData) {
782
		List<String> existingFlags = new ArrayList<String>();
783
		List<BugzillaFlag> flags = getFlags();
784
		for (TaskAttribute attribute : new HashSet<TaskAttribute>(taskData.getRoot().getAttributes().values())) {
785
786
			if (!attribute.getId().startsWith("task.common.attachment")) { //$NON-NLS-1$
787
				continue;
788
			}
789
			existingFlags.clear();
790
			for (TaskAttribute attachmentAttribute : attribute.getAttributes().values()) {
791
				if (!attachmentAttribute.getId().startsWith("task.common.kind.flag")) { //$NON-NLS-1$
792
					continue;
793
				}
794
				TaskAttribute state = attachmentAttribute.getAttribute("state"); //$NON-NLS-1$
795
				if (state != null) {
796
					String nameValue = state.getMetaData().getLabel();
797
					if (!existingFlags.contains(nameValue)) {
798
						existingFlags.add(nameValue);
799
					}
800
				}
801
			}
802
			TaskAttribute productAttribute = taskData.getRoot().getMappedAttribute(BugzillaAttribute.PRODUCT.getKey());
803
			TaskAttribute componentAttribute = taskData.getRoot().getMappedAttribute(
804
					BugzillaAttribute.COMPONENT.getKey());
805
			for (BugzillaFlag bugzillaFlag : flags) {
806
				if (!bugzillaFlag.getType().equals("attachment")) { //$NON-NLS-1$
807
					continue;
808
				}
809
				if (!bugzillaFlag.isUsedIn(productAttribute.getValue(), componentAttribute.getValue())) {
810
					continue;
811
				}
812
				if (existingFlags.contains(bugzillaFlag.getName()) && !bugzillaFlag.isMultiplicable()) {
813
					continue;
814
				}
815
				BugzillaFlagMapper mapper = new BugzillaFlagMapper();
816
				mapper.setRequestee(""); //$NON-NLS-1$
817
				mapper.setSetter(""); //$NON-NLS-1$
818
				mapper.setState(" "); //$NON-NLS-1$
819
				mapper.setFlagId(bugzillaFlag.getName());
820
				mapper.setNumber(0);
821
				mapper.setDescription(bugzillaFlag.getDescription());
822
				TaskAttribute newattribute = attribute.createAttribute("task.common.kind.flag_type" + bugzillaFlag.getFlagId()); //$NON-NLS-1$
823
				mapper.applyTo(newattribute);
824
			}
825
		}
826
	}
732
}
827
}
(-)src/org/eclipse/mylyn/internal/bugzilla/core/messages.properties (+12 lines)
Lines 84-89 Link Here
84
BugzillaAttribute_who=who
84
BugzillaAttribute_who=who
85
BugzillaAttribute_who_name=who_name
85
BugzillaAttribute_who_name=who_name
86
BugzillaAttribute_Worked=Worked:
86
BugzillaAttribute_Worked=Worked:
87
88
BugzillaAttachmentMapper_Author=Attachment Author:
89
BugzillaAttachmentMapper_Content_Type=Content Type:
90
BugzillaAttachmentMapper_Creation_Date=Creation Date:
91
BugzillaAttachmentMapper_Description=Description:
92
BugzillaAttachmentMapper_Filename=Filename:
93
BugzillaAttachmentMapper_obsolate=obsolete
94
BugzillaAttachmentMapper_patch=patch
95
BugzillaAttachmentMapper_Size=Size in Bytes:
96
BugzillaAttachmentMapper_Token=Token:
97
BugzillaAttachmentMapper_URL=URL:
98
87
BugzillaClient_could_not_post_form_null_returned=Could not post form, client returned null method.
99
BugzillaClient_could_not_post_form_null_returned=Could not post form, client returned null method.
88
BugzillaClient_description_required_when_submitting_attachments=A description is required when submitting attachments.
100
BugzillaClient_description_required_when_submitting_attachments=A description is required when submitting attachments.
89
101
(-)src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java (-2 / +1 lines)
Lines 18-24 Link Here
18
import java.util.Map;
18
import java.util.Map;
19
19
20
import org.eclipse.mylyn.tasks.core.IRepositoryPerson;
20
import org.eclipse.mylyn.tasks.core.IRepositoryPerson;
21
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper;
22
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
21
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
23
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
22
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
24
import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper;
23
import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper;
Lines 511-517 Link Here
511
		List<TaskAttribute> taskAttachments = repositoryTaskData.getAttributeMapper().getAttributesByType(
510
		List<TaskAttribute> taskAttachments = repositoryTaskData.getAttributeMapper().getAttributesByType(
512
				repositoryTaskData, TaskAttribute.TYPE_ATTACHMENT);
511
				repositoryTaskData, TaskAttribute.TYPE_ATTACHMENT);
513
		for (TaskAttribute attachment : taskAttachments) {
512
		for (TaskAttribute attachment : taskAttachments) {
514
			TaskAttachmentMapper attachmentMapper = TaskAttachmentMapper.createFrom(attachment);
513
			BugzillaAttachmentMapper attachmentMapper = BugzillaAttachmentMapper.createFrom(attachment);
515
			TaskCommentMapper taskComment = attachIdToComment.get(attachmentMapper.getAttachmentId());
514
			TaskCommentMapper taskComment = attachIdToComment.get(attachmentMapper.getAttachmentId());
516
			if (taskComment != null) {
515
			if (taskComment != null) {
517
				attachmentMapper.setAuthor(taskComment.getAuthor());
516
				attachmentMapper.setAuthor(taskComment.getAuthor());
(-)src/org/eclipse/mylyn/internal/bugzilla/core/Messages.java (+20 lines)
Lines 177-182 Link Here
177
177
178
	public static String BugzillaAttribute_Worked;
178
	public static String BugzillaAttribute_Worked;
179
179
180
	public static String BugzillaAttachmentMapper_Author;
181
182
	public static String BugzillaAttachmentMapper_Content_Type;
183
184
	public static String BugzillaAttachmentMapper_Creation_Date;
185
186
	public static String BugzillaAttachmentMapper_Description;
187
188
	public static String BugzillaAttachmentMapper_Filename;
189
190
	public static String BugzillaAttachmentMapper_obsolate;
191
192
	public static String BugzillaAttachmentMapper_patch;
193
194
	public static String BugzillaAttachmentMapper_Size;
195
196
	public static String BugzillaAttachmentMapper_Token;
197
198
	public static String BugzillaAttachmentMapper_URL;
199
180
	public static String BugzillaClient_could_not_post_form_null_returned;
200
	public static String BugzillaClient_could_not_post_form_null_returned;
181
201
182
	public static String BugzillaClient_description_required_when_submitting_attachments;
202
	public static String BugzillaClient_description_required_when_submitting_attachments;
(-)src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttachmentMapper.java (-9 / +73 lines)
Lines 1-12 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 Tasktop Technologies and others.
2
 * Copyright (c) 2009 Frank Becker and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
9
 *     Frank Becker - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
11
12
package org.eclipse.mylyn.internal.bugzilla.core;
12
package org.eclipse.mylyn.internal.bugzilla.core;
Lines 15-20 Link Here
15
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper;
15
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper;
16
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
16
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
17
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
17
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
18
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData;
18
import org.eclipse.mylyn.tasks.core.data.TaskData;
19
import org.eclipse.mylyn.tasks.core.data.TaskData;
19
20
20
/**
21
/**
Lines 33-51 Link Here
33
34
34
	@Override
35
	@Override
35
	public void applyTo(TaskAttribute taskAttribute) {
36
	public void applyTo(TaskAttribute taskAttribute) {
36
		// ignore
37
		super.applyTo(taskAttribute);
38
39
		Assert.isNotNull(taskAttribute);
37
		Assert.isNotNull(taskAttribute);
40
		TaskData taskData = taskAttribute.getTaskData();
38
		TaskData taskData = taskAttribute.getTaskData();
41
		TaskAttributeMapper mapper = taskData.getAttributeMapper();
39
		TaskAttributeMapper mapper = taskData.getAttributeMapper();
42
40
		taskAttribute.getMetaData().defaults().setType(TaskAttribute.TYPE_ATTACHMENT);
41
		if (getAttachmentId() != null) {
42
			mapper.setValue(taskAttribute, getAttachmentId());
43
		}
44
		if (getAuthor() != null) {
45
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_AUTHOR);
46
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
47
			defaults.setType(TaskAttribute.TYPE_PERSON);
48
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Author);
49
			mapper.setRepositoryPerson(child, getAuthor());
50
		}
51
		if (getContentType() != null) {
52
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_CONTENT_TYPE);
53
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
54
			defaults.setType(TaskAttribute.TYPE_SHORT_TEXT);
55
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Content_Type);
56
			mapper.setValue(child, getContentType());
57
		}
58
		if (getCreationDate() != null) {
59
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_DATE);
60
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
61
			defaults.setType(TaskAttribute.TYPE_DATE);
62
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Creation_Date);
63
			mapper.setDateValue(child, getCreationDate());
64
		}
65
		if (getDescription() != null) {
66
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_DESCRIPTION);
67
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
68
			defaults.setType(TaskAttribute.TYPE_SHORT_TEXT);
69
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Description);
70
			mapper.setValue(child, getDescription());
71
		}
72
		if (getFileName() != null) {
73
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_FILENAME);
74
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
75
			defaults.setType(TaskAttribute.TYPE_SHORT_TEXT);
76
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Filename);
77
			mapper.setValue(child, getFileName());
78
		}
79
		if (isDeprecated() != null) {
80
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED);
81
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
82
			defaults.setType(TaskAttribute.TYPE_BOOLEAN);
83
			defaults.setLabel(Messages.BugzillaAttachmentMapper_obsolate);
84
			mapper.setBooleanValue(child, isDeprecated());
85
		}
86
		if (isPatch() != null) {
87
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH);
88
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
89
			defaults.setType(TaskAttribute.TYPE_BOOLEAN);
90
			defaults.setLabel(Messages.BugzillaAttachmentMapper_patch);
91
			mapper.setBooleanValue(child, isPatch());
92
		}
93
		if (getLength() != null) {
94
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_SIZE);
95
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
96
			defaults.setType(TaskAttribute.TYPE_SHORT_TEXT);
97
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Size);
98
			mapper.setLongValue(child, getLength());
99
		}
100
		if (getUrl() != null) {
101
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_URL);
102
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
103
			defaults.setType(TaskAttribute.TYPE_URL);
104
			defaults.setLabel(Messages.BugzillaAttachmentMapper_URL);
105
			mapper.setValue(child, getUrl());
106
		}
43
		if (getToken() != null) {
107
		if (getToken() != null) {
44
			TaskAttribute child = taskAttribute.createMappedAttribute(BugzillaAttribute.TOKEN.getKey());
108
			TaskAttribute child = taskAttribute.createMappedAttribute(BugzillaAttribute.TOKEN.getKey());
45
			child.getMetaData().defaults().setType(TaskAttribute.TYPE_SHORT_TEXT);
109
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
110
			defaults.setType(TaskAttribute.TYPE_SHORT_TEXT);
111
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Token);
46
			mapper.setValue(child, getToken());
112
			mapper.setValue(child, getToken());
47
		}
113
		}
48
49
	}
114
	}
50
115
51
	public static BugzillaAttachmentMapper createFrom(TaskAttribute taskAttribute) {
116
	public static BugzillaAttachmentMapper createFrom(TaskAttribute taskAttribute) {
Lines 98-102 Link Here
98
		}
163
		}
99
		return attachment;
164
		return attachment;
100
	}
165
	}
101
102
}
166
}

Return to bug 272207