Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 250257 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/tasks/ui/ITasksUiPreferenceConstants.java (+4 lines)
Lines 72-77 Link Here
72
72
73
	public static final String AUTO_EXPAND_TASK_LIST = "org.eclipse.mylyn.tasks.ui.auto.expand"; //$NON-NLS-1$
73
	public static final String AUTO_EXPAND_TASK_LIST = "org.eclipse.mylyn.tasks.ui.auto.expand"; //$NON-NLS-1$
74
74
75
	public static final String ATTACHMENT_SHOW_ID = "org.eclipse.mylyn.tasks.ui.attachment.showid"; //$NON-NLS-1$
76
77
	public static final String ATTACHMENT_COLUMN_TO_STD = "org.eclipse.mylyn.tasks.ui.attachment.column.to.std"; //$NON-NLS-1$
78
75
	/**
79
	/**
76
	 * Local subtasks are now enabled by default.
80
	 * Local subtasks are now enabled by default.
77
	 * 
81
	 * 
(-)src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java (+2 lines)
Lines 894-899 Link Here
894
894
895
		store.setDefault(ITasksUiPreferenceConstants.AUTO_EXPAND_TASK_LIST, true);
895
		store.setDefault(ITasksUiPreferenceConstants.AUTO_EXPAND_TASK_LIST, true);
896
		store.setDefault(ITasksUiPreferenceConstants.TASK_LIST_TOOL_TIPS_ENABLED, true);
896
		store.setDefault(ITasksUiPreferenceConstants.TASK_LIST_TOOL_TIPS_ENABLED, true);
897
		store.setDefault(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID, false);
898
		store.setDefault(ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD, true);
897
	}
899
	}
898
900
899
	public static TaskActivityManager getTaskActivityManager() {
901
	public static TaskActivityManager getTaskActivityManager() {
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentTableLabelProvider.java (-7 / +18 lines)
Lines 46-59 Link Here
46
46
47
	private final AttributeEditorToolkit attributeEditorToolkit;
47
	private final AttributeEditorToolkit attributeEditorToolkit;
48
48
49
	public AttachmentTableLabelProvider(TaskDataModel model, AttributeEditorToolkit attributeEditorToolkit) {
49
	private final int offset;
50
51
	public AttachmentTableLabelProvider(TaskDataModel model, AttributeEditorToolkit attributeEditorToolkit, int offset) {
50
		this.model = model;
52
		this.model = model;
51
		this.attributeEditorToolkit = attributeEditorToolkit;
53
		this.attributeEditorToolkit = attributeEditorToolkit;
54
		this.offset = offset;
52
	}
55
	}
53
56
54
	public Image getColumnImage(Object element, int columnIndex) {
57
	public Image getColumnImage(Object element, int columnIndex) {
55
		ITaskAttachment attachment = (ITaskAttachment) element;
58
		ITaskAttachment attachment = (ITaskAttachment) element;
56
		if (columnIndex == 0) {
59
		if (columnIndex + offset == 0) {
57
			if (AttachmentUtil.isContext(attachment)) {
60
			if (AttachmentUtil.isContext(attachment)) {
58
				return CommonImages.getImage(TasksUiImages.CONTEXT_TRANSFER);
61
				return CommonImages.getImage(TasksUiImages.CONTEXT_TRANSFER);
59
			} else if (attachment.isPatch()) {
62
			} else if (attachment.isPatch()) {
Lines 80-87 Link Here
80
83
81
	public String getColumnText(Object element, int columnIndex) {
84
	public String getColumnText(Object element, int columnIndex) {
82
		ITaskAttachment attachment = (ITaskAttachment) element;
85
		ITaskAttachment attachment = (ITaskAttachment) element;
83
		switch (columnIndex) {
86
		switch (columnIndex - offset) {
84
		case 0:
87
		case 0:
88
			String a = attachment.getUrl();
89
			int i = a.indexOf("?id="); //$NON-NLS-1$
90
			if (i != -1) {
91
				return a.substring(i + 4);
92
			} else {
93
				return ""; //$NON-NLS-1$
94
			}
95
		case 1:
85
			if (AttachmentUtil.isContext(attachment)) {
96
			if (AttachmentUtil.isContext(attachment)) {
86
				return Messages.AttachmentTableLabelProvider_Task_Context;
97
				return Messages.AttachmentTableLabelProvider_Task_Context;
87
			} else if (attachment.isPatch()) {
98
			} else if (attachment.isPatch()) {
Lines 89-105 Link Here
89
			} else {
100
			} else {
90
				return " " + attachment.getFileName(); //$NON-NLS-1$
101
				return " " + attachment.getFileName(); //$NON-NLS-1$
91
			}
102
			}
92
		case 1:
93
			return attachment.getDescription();
94
		case 2:
103
		case 2:
104
			return attachment.getDescription();
105
		case 3:
95
			Long length = attachment.getLength();
106
			Long length = attachment.getLength();
96
			if (length < 0) {
107
			if (length < 0) {
97
				return "-"; //$NON-NLS-1$
108
				return "-"; //$NON-NLS-1$
98
			}
109
			}
99
			return sizeFormatter.format(length);
110
			return sizeFormatter.format(length);
100
		case 3:
101
			return (attachment.getAuthor() != null) ? attachment.getAuthor().toString() : ""; //$NON-NLS-1$
102
		case 4:
111
		case 4:
112
			return (attachment.getAuthor() != null) ? attachment.getAuthor().toString() : ""; //$NON-NLS-1$
113
		case 5:
103
			return (attachment.getCreationDate() != null) ? EditorUtil.formatDateTime(attachment.getCreationDate())
114
			return (attachment.getCreationDate() != null) ? EditorUtil.formatDateTime(attachment.getCreationDate())
104
					: ""; //$NON-NLS-1$
115
					: ""; //$NON-NLS-1$
105
		}
116
		}
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/Messages.java (+2 lines)
Lines 115-120 Link Here
115
115
116
	public static String TaskEditorAttachmentPart_Description;
116
	public static String TaskEditorAttachmentPart_Description;
117
117
118
	public static String TaskEditorAttachmentPart_Id;
119
118
	public static String TaskEditorAttachmentPart_Name;
120
	public static String TaskEditorAttachmentPart_Name;
119
121
120
	public static String TaskEditorAttachmentPart_No_attachments;
122
	public static String TaskEditorAttachmentPart_No_attachments;
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java (-70 / +151 lines)
Lines 13-40 Link Here
13
13
14
package org.eclipse.mylyn.internal.tasks.ui.editors;
14
package org.eclipse.mylyn.internal.tasks.ui.editors;
15
15
16
import java.io.File;
16
import java.util.ArrayList;
17
import java.util.ArrayList;
17
import java.util.Date;
18
import java.util.Date;
18
import java.util.List;
19
import java.util.List;
19
20
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.jface.action.Action;
23
import org.eclipse.jface.action.Action;
21
import org.eclipse.jface.action.IMenuListener;
24
import org.eclipse.jface.action.IMenuListener;
22
import org.eclipse.jface.action.IMenuManager;
25
import org.eclipse.jface.action.IMenuManager;
23
import org.eclipse.jface.action.MenuManager;
26
import org.eclipse.jface.action.MenuManager;
24
import org.eclipse.jface.action.ToolBarManager;
27
import org.eclipse.jface.action.ToolBarManager;
25
import org.eclipse.jface.layout.GridDataFactory;
26
import org.eclipse.jface.viewers.ArrayContentProvider;
28
import org.eclipse.jface.viewers.ArrayContentProvider;
27
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
29
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
28
import org.eclipse.jface.viewers.IOpenListener;
30
import org.eclipse.jface.viewers.IOpenListener;
29
import org.eclipse.jface.viewers.OpenEvent;
31
import org.eclipse.jface.viewers.OpenEvent;
30
import org.eclipse.jface.viewers.StructuredSelection;
32
import org.eclipse.jface.viewers.StructuredSelection;
31
import org.eclipse.jface.viewers.TableViewer;
32
import org.eclipse.jface.viewers.Viewer;
33
import org.eclipse.jface.viewers.Viewer;
33
import org.eclipse.jface.viewers.ViewerSorter;
34
import org.eclipse.jface.viewers.ViewerSorter;
34
import org.eclipse.jface.window.ToolTip;
35
import org.eclipse.jface.window.ToolTip;
35
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
36
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
36
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment;
37
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment;
38
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants;
39
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
40
import org.eclipse.mylyn.internal.tasks.ui.util.ColumnState;
37
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus;
41
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus;
42
import org.eclipse.mylyn.internal.tasks.ui.views.AbstractTableViewerConfigurator;
38
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode;
43
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode;
39
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
44
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
40
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
45
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
Lines 50-56 Link Here
50
import org.eclipse.swt.widgets.Label;
55
import org.eclipse.swt.widgets.Label;
51
import org.eclipse.swt.widgets.Menu;
56
import org.eclipse.swt.widgets.Menu;
52
import org.eclipse.swt.widgets.Table;
57
import org.eclipse.swt.widgets.Table;
53
import org.eclipse.swt.widgets.TableColumn;
54
import org.eclipse.ui.forms.events.ExpansionAdapter;
58
import org.eclipse.ui.forms.events.ExpansionAdapter;
55
import org.eclipse.ui.forms.events.ExpansionEvent;
59
import org.eclipse.ui.forms.events.ExpansionEvent;
56
import org.eclipse.ui.forms.widgets.FormToolkit;
60
import org.eclipse.ui.forms.widgets.FormToolkit;
Lines 65-76 Link Here
65
69
66
	private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$
70
	private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$
67
71
68
	private final String[] attachmentsColumns = { Messages.TaskEditorAttachmentPart_Name,
69
			Messages.TaskEditorAttachmentPart_Description, /*"Type", */Messages.TaskEditorAttachmentPart_Size,
70
			Messages.TaskEditorAttachmentPart_Creator, Messages.TaskEditorAttachmentPart_Created };
71
72
	private final int[] attachmentsColumnWidths = { 130, 150, /*100,*/70, 100, 100 };
73
74
	private List<TaskAttribute> attachments;
72
	private List<TaskAttribute> attachments;
75
73
76
	private boolean hasIncoming;
74
	private boolean hasIncoming;
Lines 79-150 Link Here
79
77
80
	private Composite attachmentsComposite;
78
	private Composite attachmentsComposite;
81
79
82
	public TaskEditorAttachmentPart() {
80
	private class AttachmentTableViewer extends AbstractTableViewerConfigurator {
83
		setPartName(Messages.TaskEditorAttachmentPart_Attachments);
81
		public AttachmentTableViewer(File stateFile) {
84
	}
82
			super(stateFile);
83
			// ignore
84
		}
85
85
86
	private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) {
86
		@Override
87
		Table attachmentsTable = toolkit.createTable(attachmentsComposite, SWT.MULTI | SWT.FULL_SELECTION);
87
		protected void adjustColumInfos() {
88
		attachmentsTable.setLinesVisible(true);
88
			boolean showAttachmentID = TasksUiPlugin.getDefault().getPreferenceStore().getBoolean(
89
		attachmentsTable.setHeaderVisible(true);
89
					ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID);
90
		attachmentsTable.setLayout(new GridLayout());
90
			int idWidth = columnInfos.get(0).getWidths();
91
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).hint(500, SWT.DEFAULT).applyTo(
91
			if (!showAttachmentID && idWidth > 0) {
92
				attachmentsTable);
92
				columnInfos.get(0).setWidths(0);
93
		attachmentsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
93
			} else if (showAttachmentID && idWidth == 0) {
94
94
				columnInfos.get(0).setWidths(70);
95
		for (int i = 0; i < attachmentsColumns.length; i++) {
95
			}
96
			TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, i);
97
			column.setText(attachmentsColumns[i]);
98
			column.setWidth(attachmentsColumnWidths[i]);
99
		}
100
		// size column
101
		attachmentsTable.getColumn(2).setAlignment(SWT.RIGHT);
102
103
		TableViewer attachmentsViewer = new TableViewer(attachmentsTable);
104
		attachmentsViewer.setUseHashlookup(true);
105
		attachmentsViewer.setColumnProperties(attachmentsColumns);
106
		ColumnViewerToolTipSupport.enableFor(attachmentsViewer, ToolTip.NO_RECREATE);
107
96
108
		attachmentsViewer.setSorter(new ViewerSorter() {
97
		}
109
			@Override
98
110
			public int compare(Viewer viewer, Object e1, Object e2) {
99
		@Override
111
				ITaskAttachment attachment1 = (ITaskAttachment) e1;
100
		protected void setDefaultColumnInfos() {
112
				ITaskAttachment attachment2 = (ITaskAttachment) e2;
101
			columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Id, 70));
113
				Date created1 = attachment1.getCreationDate();
102
			columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Name, 130));
114
				Date created2 = attachment2.getCreationDate();
103
			columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Description, 150));
115
				if (created1 != null && created2 != null) {
104
			ColumnState columnState = new ColumnState(Messages.TaskEditorAttachmentPart_Size, 70);
116
					return created1.compareTo(created2);
105
			columnState.setAlignment(SWT.RIGHT);
117
				} else if (created1 == null && created2 != null) {
106
			columnInfos.add(columnState);
118
					return -1;
107
			columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Creator, 100));
119
				} else if (created1 != null && created2 == null) {
108
			columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Created, 100));
120
					return 1;
109
121
				} else {
110
			orderArray = new int[6];
122
					return 0;
111
			for (int i = 0; i < 6; i++) {
112
				orderArray[i] = i;
113
			}
114
115
		}
116
117
		@Override
118
		protected void setupTableViewer() {
119
			tableViewer.setUseHashlookup(true);
120
			ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
121
122
			tableViewer.setSorter(new ViewerSorter() {
123
				@Override
124
				public int compare(Viewer viewer, Object e1, Object e2) {
125
					ITaskAttachment attachment1 = (ITaskAttachment) e1;
126
					ITaskAttachment attachment2 = (ITaskAttachment) e2;
127
					Date created1 = attachment1.getCreationDate();
128
					Date created2 = attachment2.getCreationDate();
129
					if (created1 != null && created2 != null) {
130
						return created1.compareTo(created2);
131
					} else if (created1 == null && created2 != null) {
132
						return -1;
133
					} else if (created1 != null && created2 == null) {
134
						return 1;
135
					} else {
136
						return 0;
137
					}
123
				}
138
				}
139
			});
140
			List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size());
141
			for (TaskAttribute attribute : attachments) {
142
				TaskAttachment taskAttachment = new TaskAttachment(getModel().getTaskRepository(),
143
						getModel().getTask(), attribute);
144
				getTaskData().getAttributeMapper().updateTaskAttachment(taskAttachment, attribute);
145
				attachmentList.add(taskAttachment);
146
147
				tableViewer.setContentProvider(new ArrayContentProvider());
148
				tableViewer.setLabelProvider(new AttachmentTableLabelProvider(getModel(),
149
						getTaskEditorPage().getAttributeEditorToolkit(), 0));
150
				tableViewer.addOpenListener(new IOpenListener() {
151
					public void open(OpenEvent event) {
152
						if (!event.getSelection().isEmpty()) {
153
							StructuredSelection selection = (StructuredSelection) event.getSelection();
154
							ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement();
155
							TasksUiUtil.openUrl(attachment.getUrl());
156
						}
157
					}
158
				});
159
				tableViewer.addSelectionChangedListener(getTaskEditorPage());
160
				tableViewer.setInput(attachmentList.toArray());
124
			}
161
			}
125
		});
162
		}
163
	}
164
165
	private AttachmentTableViewer attachmentsViewer;
166
167
	private boolean propertyListenerIstalled = false;
126
168
127
		List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size());
169
	private final org.eclipse.jface.util.IPropertyChangeListener PROPERTY_LISTENER = new org.eclipse.jface.util.IPropertyChangeListener() {
128
		for (TaskAttribute attribute : attachments) {
170
129
			TaskAttachment taskAttachment = new TaskAttachment(getModel().getTaskRepository(), getModel().getTask(),
171
		public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) {
130
					attribute);
172
			if (event.getProperty().equals(ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD)) {
131
			getTaskData().getAttributeMapper().updateTaskAttachment(taskAttachment, attribute);
173
				if (TasksUiPlugin.getDefault().getPreferenceStore().getBoolean(
132
			attachmentList.add(taskAttachment);
174
						ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD)) {
133
		}
175
					if (attachmentsViewer != null) {
134
		attachmentsViewer.setContentProvider(new ArrayContentProvider());
176
						attachmentsViewer.resetColumnInfosToDefault();
135
		attachmentsViewer.setLabelProvider(new AttachmentTableLabelProvider(getModel(),
177
						Table table = attachmentsViewer.getTable();
136
				getTaskEditorPage().getAttributeEditorToolkit()));
178
						if (!table.isDisposed()) {
137
		attachmentsViewer.addOpenListener(new IOpenListener() {
179
							if (TasksUiPlugin.getDefault().getPreferenceStore().getBoolean(
138
			public void open(OpenEvent event) {
180
									ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) {
139
				if (!event.getSelection().isEmpty()) {
181
								table.getColumn(0).setWidth(70);
140
					StructuredSelection selection = (StructuredSelection) event.getSelection();
182
							} else {
141
					ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement();
183
								table.getColumn(0).setWidth(0);
142
					TasksUiUtil.openUrl(attachment.getUrl());
184
							}
185
						}
186
//						TasksUiPlugin.getDefault().getPreferenceStore().setValue(
187
//								ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD, false);
188
					} else {
189
						IPath stateLocation = Platform.getStateLocation(TasksUiPlugin.getDefault().getBundle());
190
						File attachmentStateFile = stateLocation.append("TaskEditorAttachment.obj").toFile(); //$NON-NLS-1$
191
						attachmentStateFile.delete();
192
					}
193
				}
194
			} else if (event.getProperty().equals(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) {
195
				if (attachmentsViewer != null) {
196
					Table table = attachmentsViewer.getTable();
197
					if (!table.isDisposed()) {
198
						if (TasksUiPlugin.getDefault().getPreferenceStore().getBoolean(
199
								ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) {
200
							table.getColumn(0).setWidth(70);
201
						} else {
202
							table.getColumn(0).setWidth(0);
203
						}
204
//					} else {
205
//						attachmentsViewer.
206
					}
143
				}
207
				}
144
			}
208
			}
145
		});
209
		}
146
		attachmentsViewer.addSelectionChangedListener(getTaskEditorPage());
210
	};
147
		attachmentsViewer.setInput(attachmentList.toArray());
211
212
	public TaskEditorAttachmentPart() {
213
		setPartName(Messages.TaskEditorAttachmentPart_Attachments);
214
	}
215
216
	private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) {
217
		IPath stateLocation = Platform.getStateLocation(TasksUiPlugin.getDefault().getBundle());
218
		File attachmentStateFile = stateLocation.append("TaskEditorAttachment.obj").toFile(); //$NON-NLS-1$
219
		attachmentsViewer = new AttachmentTableViewer(attachmentStateFile);
220
		attachmentsViewer.create(toolkit, attachmentsComposite, 5);
148
221
149
		menuManager = new MenuManager();
222
		menuManager = new MenuManager();
150
		menuManager.setRemoveAllWhenShown(true);
223
		menuManager.setRemoveAllWhenShown(true);
Lines 154-161 Link Here
154
			}
227
			}
155
		});
228
		});
156
		getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, true);
229
		getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, true);
157
		Menu menu = menuManager.createContextMenu(attachmentsTable);
230
		Menu menu = menuManager.createContextMenu(attachmentsViewer.getTable());
158
		attachmentsTable.setMenu(menu);
231
		attachmentsViewer.getTable().setMenu(menu);
159
	}
232
	}
160
233
161
	private void createButtons(Composite attachmentsComposite, FormToolkit toolkit) {
234
	private void createButtons(Composite attachmentsComposite, FormToolkit toolkit) {
Lines 230-235 Link Here
230
303
231
	@Override
304
	@Override
232
	public void dispose() {
305
	public void dispose() {
306
		if (propertyListenerIstalled) {
307
			TasksUiPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(PROPERTY_LISTENER);
308
			propertyListenerIstalled = false;
309
		}
233
		if (menuManager != null) {
310
		if (menuManager != null) {
234
			menuManager.dispose();
311
			menuManager.dispose();
235
		}
312
		}
Lines 237-242 Link Here
237
	}
314
	}
238
315
239
	private void initialize() {
316
	private void initialize() {
317
		if (!propertyListenerIstalled) {
318
			TasksUiPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER);
319
			propertyListenerIstalled = true;
320
		}
240
		attachments = getTaskData().getAttributeMapper().getAttributesByType(getTaskData(),
321
		attachments = getTaskData().getAttributeMapper().getAttributesByType(getTaskData(),
241
				TaskAttribute.TYPE_ATTACHMENT);
322
				TaskAttribute.TYPE_ATTACHMENT);
242
		for (TaskAttribute attachmentAttribute : attachments) {
323
		for (TaskAttribute attachmentAttribute : attachments) {
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/messages.properties (+1 lines)
Lines 62-67 Link Here
62
TaskEditorAttachmentPart_Created=Created
62
TaskEditorAttachmentPart_Created=Created
63
TaskEditorAttachmentPart_Creator=Creator
63
TaskEditorAttachmentPart_Creator=Creator
64
TaskEditorAttachmentPart_Description=Description
64
TaskEditorAttachmentPart_Description=Description
65
TaskEditorAttachmentPart_Id=Id
65
TaskEditorAttachmentPart_Name=Name
66
TaskEditorAttachmentPart_Name=Name
66
TaskEditorAttachmentPart_No_attachments=No attachments
67
TaskEditorAttachmentPart_No_attachments=No attachments
67
TaskEditorAttachmentPart_Size=Size
68
TaskEditorAttachmentPart_Size=Size
(-)src/org/eclipse/mylyn/internal/tasks/ui/preferences/Messages.java (+7 lines)
Lines 108-111 Link Here
108
	public static String Tuesday;
108
	public static String Tuesday;
109
109
110
	public static String Wednesday;
110
	public static String Wednesday;
111
112
	public static String TasksUiPreferencePage_Attachment_Table;
113
114
	public static String TasksUiPreferencePage_Attachment_Show_Id;
115
116
	public static String TasksUiPreferencePage_Attachment_Coloumn_To_Std;
117
111
}
118
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/preferences/TasksUiPreferencePage.java (-2 / +35 lines)
Lines 110-115 Link Here
110
110
111
	private Button taskListTooltipEnabledButton;
111
	private Button taskListTooltipEnabledButton;
112
112
113
	private Button attachmentShowID;
114
115
	private Button attachmentColumnUseStdWidth;
116
113
	public TasksUiPreferencePage() {
117
	public TasksUiPreferencePage() {
114
		super();
118
		super();
115
		setPreferenceStore(TasksUiPlugin.getDefault().getPreferenceStore());
119
		setPreferenceStore(TasksUiPlugin.getDefault().getPreferenceStore());
Lines 138-143 Link Here
138
		}
142
		}
139
143
140
		createLinks(advanced);
144
		createLinks(advanced);
145
		createAttachmentTable(advanced);
141
		updateRefreshGroupEnablements();
146
		updateRefreshGroupEnablements();
142
		applyDialogFont(container);
147
		applyDialogFont(container);
143
		return container;
148
		return container;
Lines 248-253 Link Here
248
				// shouldn't get here
253
				// shouldn't get here
249
			}
254
			}
250
		}
255
		}
256
		getPreferenceStore().setValue(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID, attachmentShowID.getSelection());
257
		getPreferenceStore().setValue(ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD,
258
				attachmentColumnUseStdWidth.getSelection());
259
		getPreferenceStore().setValue(ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD, false);
260
261
		attachmentColumnUseStdWidth.setSelection(false);
251
262
252
		return true;
263
		return true;
253
	}
264
	}
Lines 289-295 Link Here
289
300
290
		activityTrackingEnabledButton.setSelection(MonitorUiPlugin.getDefault().getPreferenceStore().getBoolean(
301
		activityTrackingEnabledButton.setSelection(MonitorUiPlugin.getDefault().getPreferenceStore().getBoolean(
291
				MonitorUiPlugin.ACTIVITY_TRACKING_ENABLED));
302
				MonitorUiPlugin.ACTIVITY_TRACKING_ENABLED));
292
303
		attachmentShowID.setSelection(getPreferenceStore().getBoolean(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID));
304
		attachmentColumnUseStdWidth.setSelection(getPreferenceStore().getBoolean(
305
				ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD));
293
		return true;
306
		return true;
294
	}
307
	}
295
308
Lines 342-348 Link Here
342
355
343
		activityTrackingEnabledButton.setSelection(MonitorUiPlugin.getDefault().getPreferenceStore().getDefaultBoolean(
356
		activityTrackingEnabledButton.setSelection(MonitorUiPlugin.getDefault().getPreferenceStore().getDefaultBoolean(
344
				MonitorUiPlugin.ACTIVITY_TRACKING_ENABLED));
357
				MonitorUiPlugin.ACTIVITY_TRACKING_ENABLED));
345
358
		attachmentShowID.setSelection(getPreferenceStore().getDefaultBoolean(
359
				ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID));
360
		attachmentColumnUseStdWidth.setSelection(getPreferenceStore().getDefaultBoolean(
361
				ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD));
346
		updateRefreshGroupEnablements();
362
		updateRefreshGroupEnablements();
347
	}
363
	}
348
364
Lines 631-634 Link Here
631
		}
647
		}
632
		super.dispose();
648
		super.dispose();
633
	}
649
	}
650
651
	private void createAttachmentTable(Composite parent) {
652
		Group attachmentContainer = new Group(parent, SWT.SHADOW_ETCHED_IN);
653
		attachmentContainer.setLayout(new GridLayout(2, false));
654
		attachmentContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
655
		attachmentContainer.setText(Messages.TasksUiPreferencePage_Attachment_Table);
656
657
		attachmentColumnUseStdWidth = new Button(attachmentContainer, SWT.CHECK);
658
		attachmentColumnUseStdWidth.setText(Messages.TasksUiPreferencePage_Attachment_Coloumn_To_Std);
659
		attachmentColumnUseStdWidth.setSelection(getPreferenceStore().getBoolean(
660
				ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD));
661
662
		attachmentShowID = new Button(attachmentContainer, SWT.CHECK);
663
		attachmentShowID.setText(Messages.TasksUiPreferencePage_Attachment_Show_Id);
664
		attachmentShowID.setSelection(getPreferenceStore().getBoolean(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID));
665
666
	}
634
}
667
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/preferences/messages.properties (+3 lines)
Lines 50-52 Link Here
50
Thursday=
50
Thursday=
51
Tuesday=
51
Tuesday=
52
Wednesday=
52
Wednesday=
53
TasksUiPreferencePage_Attachment_Table=Task Editor Attachment Table
54
TasksUiPreferencePage_Attachment_Show_Id=Show Attachment ID
55
TasksUiPreferencePage_Attachment_Coloumn_To_Std=reset to standard Column
(-)src/org/eclipse/mylyn/internal/tasks/ui/util/ColumnState.java (+75 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.tasks.ui.util;
13
14
import java.io.Serializable;
15
16
import org.eclipse.swt.SWT;
17
import org.eclipse.ui.IMemento;
18
19
public class ColumnState implements Serializable {
20
21
	private static final long serialVersionUID = 6303376618126218826L;
22
23
	private String name;
24
25
	private int widths;
26
27
	private int alignment;
28
29
	public ColumnState(String name, int widths) {
30
		super();
31
		this.name = name;
32
		this.widths = widths;
33
		alignment = SWT.LEFT;
34
	}
35
36
	public String getName() {
37
		return name;
38
	}
39
40
	public void setName(String name) {
41
		this.name = name;
42
	}
43
44
	public int getWidths() {
45
		return widths;
46
	}
47
48
	public void setWidths(int widths) {
49
		this.widths = widths;
50
	}
51
52
	public int getAlignment() {
53
		return alignment;
54
	}
55
56
	public void setAlignment(int alignment) {
57
		this.alignment = alignment;
58
	}
59
60
	public void saveState(IMemento memento) {
61
		IMemento child = memento.createChild("ColumnState"); //$NON-NLS-1$
62
		child.putString("name", name); //$NON-NLS-1$
63
		child.putInteger("widths", widths); //$NON-NLS-1$
64
		child.putInteger("alignment", alignment); //$NON-NLS-1$
65
66
	}
67
68
	public static ColumnState createState(IMemento memento) {
69
		ColumnState erg;
70
		erg = new ColumnState(memento.getString("name"), memento.getInteger("widths"));
71
		erg.setAlignment(memento.getInteger("alignment"));
72
		return erg;
73
	}
74
75
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/views/AbstractTableViewerConfigurator.java (+225 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.tasks.ui.views;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.FileWriter;
17
import java.io.IOException;
18
import java.util.ArrayList;
19
20
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.Status;
22
import org.eclipse.jface.layout.GridDataFactory;
23
import org.eclipse.jface.viewers.ISelection;
24
import org.eclipse.jface.viewers.ISelectionChangedListener;
25
import org.eclipse.jface.viewers.ISelectionProvider;
26
import org.eclipse.jface.viewers.TableViewer;
27
import org.eclipse.mylyn.commons.core.StatusHandler;
28
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants;
29
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
30
import org.eclipse.mylyn.internal.tasks.ui.util.ColumnState;
31
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.events.ControlEvent;
33
import org.eclipse.swt.events.ControlListener;
34
import org.eclipse.swt.layout.GridLayout;
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Table;
37
import org.eclipse.swt.widgets.TableColumn;
38
import org.eclipse.ui.IMemento;
39
import org.eclipse.ui.WorkbenchException;
40
import org.eclipse.ui.XMLMemento;
41
import org.eclipse.ui.forms.widgets.FormToolkit;
42
43
public abstract class AbstractTableViewerConfigurator implements ISelectionProvider {
44
	protected TableViewer tableViewer;
45
46
	protected Table table;
47
48
	private final File stateFile;
49
50
	protected ArrayList<ColumnState> columnInfos;
51
52
	protected int[] orderArray;
53
54
	public AbstractTableViewerConfigurator(File stateFile) {
55
		super();
56
		this.stateFile = stateFile;
57
	}
58
59
	abstract protected void setDefaultColumnInfos();
60
61
	abstract protected void setupTableViewer();
62
63
	private void readStateFile() {
64
		if (stateFile.exists()) {
65
			try {
66
				FileReader reader = new FileReader(stateFile);
67
				try {
68
					XMLMemento memento = XMLMemento.createReadRoot(reader);
69
					IMemento child = memento.getChild("Columns"); //$NON-NLS-1$
70
					int size = child.getInteger("count"); //$NON-NLS-1$
71
					IMemento[] children = memento.getChildren("ColumnState"); //$NON-NLS-1$
72
					for (int i = 0; i < size; i++) {
73
						columnInfos.add(ColumnState.createState(children[i]));
74
					}
75
					String orderString = child.getString("order"); //$NON-NLS-1$
76
					String[] orderStringArray = orderString.split(","); //$NON-NLS-1$
77
					orderArray = new int[orderStringArray.length];
78
					for (int i = 0; i < orderStringArray.length; i++) {
79
						orderArray[i] = Integer.parseInt(orderStringArray[i]);
80
					}
81
				} catch (WorkbenchException e) {
82
					StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN,
83
							"The TableViewerState cache could not be read", e)); //$NON-NLS-1$
84
				} finally {
85
					reader.close();
86
				}
87
			} catch (IOException e) {
88
				StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN,
89
						"The TableViewerState cache could not be read", e)); //$NON-NLS-1$
90
			}
91
		}
92
93
	}
94
95
	protected void writeStateFile() {
96
97
		if (stateFile == null) {
98
			return;
99
		}
100
101
		XMLMemento memento = XMLMemento.createWriteRoot("TableViewerState"); //$NON-NLS-1$
102
		IMemento child = memento.createChild("Columns"); //$NON-NLS-1$
103
		child.putInteger("count", columnInfos.size()); //$NON-NLS-1$
104
		for (ColumnState col : columnInfos) {
105
			col.saveState(memento);
106
		}
107
108
		int[] colOrder = table.getColumnOrder();
109
		String orderString = ""; //$NON-NLS-1$
110
		for (int colPos : colOrder) {
111
			if (orderString.length() > 0) {
112
				orderString += ","; //$NON-NLS-1$
113
			}
114
			orderString += colPos;
115
		}
116
		child.putString("order", orderString); //$NON-NLS-1$
117
118
		try {
119
			FileWriter writer = new FileWriter(stateFile);
120
			try {
121
				memento.save(writer);
122
			} finally {
123
				writer.close();
124
			}
125
		} catch (IOException e) {
126
			StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN,
127
					"The TaskEditorAttachment cache could not be written", e)); //$NON-NLS-1$
128
		}
129
	}
130
131
	protected void adjustColumInfos() {
132
133
	}
134
135
	public void create(FormToolkit toolkit, Composite parent, int initialColumnCount) {
136
		table = createTable(parent, toolkit);
137
		columnInfos = new ArrayList<ColumnState>(initialColumnCount);
138
		readStateFile();
139
		if (columnInfos.size() == 0) {
140
			setDefaultColumnInfos();
141
		}
142
		adjustColumInfos();
143
		for (int index = 0; index < columnInfos.size(); index++) {
144
			ColumnState colState = columnInfos.get(index);
145
			final TableColumn column = new TableColumn(table, colState.getAlignment(), index);
146
			column.setText(colState.getName());
147
			column.setWidth(colState.getWidths());
148
			column.setMoveable(true);
149
			column.addControlListener(createColumnControlListener(table, column, index));
150
		}
151
152
		tableViewer = new TableViewer(table);
153
		table.setColumnOrder(orderArray);
154
		setupTableViewer();
155
	}
156
157
	protected ControlListener createColumnControlListener(Table table, final TableColumn column, final int index) {
158
		return new ControlListener() {
159
160
			public void controlResized(ControlEvent e) {
161
				if (!TasksUiPlugin.getDefault().getPreferenceStore().getBoolean(
162
						ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD)) {
163
					columnInfos.get(index).setWidths(column.getWidth());
164
					writeStateFile();
165
				}
166
			}
167
168
			public void controlMoved(ControlEvent e) {
169
				writeStateFile();
170
			}
171
		};
172
173
	}
174
175
	protected Table createTable(Composite parent, FormToolkit toolkit) {
176
		Table table = toolkit.createTable(parent, SWT.MULTI | SWT.FULL_SELECTION);
177
		table.setLinesVisible(true);
178
		table.setHeaderVisible(true);
179
		table.setLayout(new GridLayout());
180
		GridDataFactory.fillDefaults()
181
				.align(SWT.FILL, SWT.FILL)
182
				.grab(true, false)
183
				.hint(500, SWT.DEFAULT)
184
				.applyTo(table);
185
		table.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
186
187
		return table;
188
	}
189
190
	public Table getTable() {
191
		return table;
192
	}
193
194
	public void resetColumnInfosToDefault() {
195
		columnInfos.clear();
196
		setDefaultColumnInfos();
197
		if (!table.isDisposed()) {
198
			for (int index = 0; index < columnInfos.size(); index++) {
199
				TableColumn col = table.getColumn(index);
200
				ColumnState colState = columnInfos.get(index);
201
				col.setAlignment(colState.getAlignment());
202
				col.setWidth(colState.getWidths());
203
				col.setText(colState.getName());
204
			}
205
			table.setColumnOrder(orderArray);
206
		}
207
	}
208
209
	public void addSelectionChangedListener(ISelectionChangedListener listener) {
210
		tableViewer.addSelectionChangedListener(listener);
211
	}
212
213
	public ISelection getSelection() {
214
		return tableViewer.getSelection();
215
	}
216
217
	public void removeSelectionChangedListener(ISelectionChangedListener listener) {
218
		tableViewer.removeSelectionChangedListener(listener);
219
	}
220
221
	public void setSelection(ISelection selection) {
222
		tableViewer.setSelection(selection);
223
	}
224
225
}

Return to bug 250257