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/editors/TaskEditorAttachmentPart.java (-72 / +133 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;
37
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus;
40
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus;
41
import org.eclipse.mylyn.internal.tasks.ui.views.AbstractTableViewerConfigurator;
38
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode;
42
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode;
39
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
43
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
40
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
44
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
Lines 49-56 Link Here
49
import org.eclipse.swt.widgets.Composite;
53
import org.eclipse.swt.widgets.Composite;
50
import org.eclipse.swt.widgets.Label;
54
import org.eclipse.swt.widgets.Label;
51
import org.eclipse.swt.widgets.Menu;
55
import org.eclipse.swt.widgets.Menu;
52
import org.eclipse.swt.widgets.Table;
53
import org.eclipse.swt.widgets.TableColumn;
54
import org.eclipse.ui.forms.events.ExpansionAdapter;
56
import org.eclipse.ui.forms.events.ExpansionAdapter;
55
import org.eclipse.ui.forms.events.ExpansionEvent;
57
import org.eclipse.ui.forms.events.ExpansionEvent;
56
import org.eclipse.ui.forms.widgets.FormToolkit;
58
import org.eclipse.ui.forms.widgets.FormToolkit;
Lines 65-76 Link Here
65
67
66
	private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$
68
	private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$
67
69
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;
70
	private List<TaskAttribute> attachments;
75
71
76
	private boolean hasIncoming;
72
	private boolean hasIncoming;
Lines 79-150 Link Here
79
75
80
	private Composite attachmentsComposite;
76
	private Composite attachmentsComposite;
81
77
82
	public TaskEditorAttachmentPart() {
78
	private class AttachmentTableViewer extends AbstractTableViewerConfigurator {
83
		setPartName(Messages.TaskEditorAttachmentPart_Attachments);
84
	}
85
79
86
	private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) {
80
		public AttachmentTableViewer(File stateFile) {
87
		Table attachmentsTable = toolkit.createTable(attachmentsComposite, SWT.MULTI | SWT.FULL_SELECTION);
81
			super(stateFile);
88
		attachmentsTable.setLinesVisible(true);
82
			// ignore
89
		attachmentsTable.setHeaderVisible(true);
83
		}
90
		attachmentsTable.setLayout(new GridLayout());
91
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).hint(500, SWT.DEFAULT).applyTo(
92
				attachmentsTable);
93
		attachmentsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
94
95
		for (int i = 0; i < attachmentsColumns.length; i++) {
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
84
108
		attachmentsViewer.setSorter(new ViewerSorter() {
85
		@Override
109
			@Override
86
		protected void adjustColumInfos() {
110
			public int compare(Viewer viewer, Object e1, Object e2) {
87
			boolean showAttachmentID = TasksUiPlugin.getDefault().getPreferenceStore().getBoolean(
111
				ITaskAttachment attachment1 = (ITaskAttachment) e1;
88
					ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID);
112
				ITaskAttachment attachment2 = (ITaskAttachment) e2;
89
			int idWidth = columnInfos.get(0).getWidths();
113
				Date created1 = attachment1.getCreationDate();
90
			if (!showAttachmentID && idWidth > 0) {
114
				Date created2 = attachment2.getCreationDate();
91
				columnInfos.get(0).setWidths(0);
115
				if (created1 != null && created2 != null) {
92
			} else if (showAttachmentID && idWidth == 0) {
116
					return created1.compareTo(created2);
93
				columnInfos.get(0).setWidths(70);
117
				} else if (created1 == null && created2 != null) {
94
			}
118
					return -1;
95
119
				} else if (created1 != null && created2 == null) {
96
		}
120
					return 1;
97
121
				} else {
98
		@Override
122
					return 0;
99
		protected void setDefaultColumnInfos() {
100
			columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Id, 70));
101
			columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Name, 130));
102
			columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Description, 150));
103
			ColumnState columnState = new ColumnState(Messages.TaskEditorAttachmentPart_Size, 70);
104
			columnState.setAlignment(SWT.RIGHT);
105
			columnInfos.add(columnState);
106
			columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Creator, 100));
107
			columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Created, 100));
108
109
			orderArray = new int[6];
110
			for (int i = 0; i < 6; i++) {
111
				orderArray[i] = i;
112
			}
113
114
		}
115
116
		@Override
117
		protected void setupTableViewer() {
118
			tableViewer.setUseHashlookup(true);
119
			ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
120
121
			tableViewer.setSorter(new ViewerSorter() {
122
				@Override
123
				public int compare(Viewer viewer, Object e1, Object e2) {
124
					ITaskAttachment attachment1 = (ITaskAttachment) e1;
125
					ITaskAttachment attachment2 = (ITaskAttachment) e2;
126
					Date created1 = attachment1.getCreationDate();
127
					Date created2 = attachment2.getCreationDate();
128
					if (created1 != null && created2 != null) {
129
						return created1.compareTo(created2);
130
					} else if (created1 == null && created2 != null) {
131
						return -1;
132
					} else if (created1 != null && created2 == null) {
133
						return 1;
134
					} else {
135
						return 0;
136
					}
123
				}
137
				}
138
			});
139
			List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size());
140
			for (TaskAttribute attribute : attachments) {
141
				TaskAttachment taskAttachment = new TaskAttachment(getModel().getTaskRepository(),
142
						getModel().getTask(), attribute);
143
				getTaskData().getAttributeMapper().updateTaskAttachment(taskAttachment, attribute);
144
				attachmentList.add(taskAttachment);
124
			}
145
			}
125
		});
146
			tableViewer.setContentProvider(new ArrayContentProvider());
147
			tableViewer.setLabelProvider(new AttachmentTableLabelProvider(getModel(),
148
					getTaskEditorPage().getAttributeEditorToolkit(), 0));
149
			tableViewer.addOpenListener(new IOpenListener() {
150
				public void open(OpenEvent event) {
151
					if (!event.getSelection().isEmpty()) {
152
						StructuredSelection selection = (StructuredSelection) event.getSelection();
153
						ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement();
154
						TasksUiUtil.openUrl(attachment.getUrl());
155
					}
156
				}
157
			});
158
			tableViewer.addSelectionChangedListener(getTaskEditorPage());
159
			tableViewer.setInput(attachmentList.toArray());
160
		}
161
162
	}
126
163
127
		List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size());
164
	private AttachmentTableViewer attachmentsViewer;
128
		for (TaskAttribute attribute : attachments) {
165
129
			TaskAttachment taskAttachment = new TaskAttachment(getModel().getTaskRepository(), getModel().getTask(),
166
	private boolean propertyListenerIstalled = false;
130
					attribute);
167
131
			getTaskData().getAttributeMapper().updateTaskAttachment(taskAttachment, attribute);
168
	private final org.eclipse.jface.util.IPropertyChangeListener PROPERTY_LISTENER = new org.eclipse.jface.util.IPropertyChangeListener() {
132
			attachmentList.add(taskAttachment);
169
133
		}
170
		public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) {
134
		attachmentsViewer.setContentProvider(new ArrayContentProvider());
171
			if (event.getProperty().equals(ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD)) {
135
		attachmentsViewer.setLabelProvider(new AttachmentTableLabelProvider(getModel(),
172
				if (TasksUiPlugin.getDefault().getPreferenceStore().getBoolean(
136
				getTaskEditorPage().getAttributeEditorToolkit()));
173
						ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD)) {
137
		attachmentsViewer.addOpenListener(new IOpenListener() {
174
					attachmentsViewer.resetColumnInfosToDefault();
138
			public void open(OpenEvent event) {
175
					if (TasksUiPlugin.getDefault().getPreferenceStore().getBoolean(
139
				if (!event.getSelection().isEmpty()) {
176
							ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) {
140
					StructuredSelection selection = (StructuredSelection) event.getSelection();
177
						attachmentsViewer.getTable().getColumn(0).setWidth(70);
141
					ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement();
178
					} else {
142
					TasksUiUtil.openUrl(attachment.getUrl());
179
						attachmentsViewer.getTable().getColumn(0).setWidth(0);
180
					}
181
					TasksUiPlugin.getDefault().getPreferenceStore().setValue(
182
							ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD, false);
183
				}
184
			} else if (event.getProperty().equals(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) {
185
				if (TasksUiPlugin.getDefault().getPreferenceStore().getBoolean(
186
						ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) {
187
					attachmentsViewer.getTable().getColumn(0).setWidth(70);
188
				} else {
189
					attachmentsViewer.getTable().getColumn(0).setWidth(0);
143
				}
190
				}
144
			}
191
			}
145
		});
192
146
		attachmentsViewer.addSelectionChangedListener(getTaskEditorPage());
193
		}
147
		attachmentsViewer.setInput(attachmentList.toArray());
194
	};
195
196
	public TaskEditorAttachmentPart() {
197
		setPartName(Messages.TaskEditorAttachmentPart_Attachments);
198
	}
199
200
	private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) {
201
		IPath stateLocation = Platform.getStateLocation(TasksUiPlugin.getDefault().getBundle());
202
		File attachmentStateFile = stateLocation.append("TaskEditorAttachment.obj").toFile(); //$NON-NLS-1$
203
		attachmentsViewer = new AttachmentTableViewer(attachmentStateFile);
204
		attachmentsViewer.create(toolkit, attachmentsComposite, 5);
148
205
149
		menuManager = new MenuManager();
206
		menuManager = new MenuManager();
150
		menuManager.setRemoveAllWhenShown(true);
207
		menuManager.setRemoveAllWhenShown(true);
Lines 154-161 Link Here
154
			}
211
			}
155
		});
212
		});
156
		getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, true);
213
		getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, true);
157
		Menu menu = menuManager.createContextMenu(attachmentsTable);
214
		Menu menu = menuManager.createContextMenu(attachmentsViewer.getTable());
158
		attachmentsTable.setMenu(menu);
215
		attachmentsViewer.getTable().setMenu(menu);
159
	}
216
	}
160
217
161
	private void createButtons(Composite attachmentsComposite, FormToolkit toolkit) {
218
	private void createButtons(Composite attachmentsComposite, FormToolkit toolkit) {
Lines 191-197 Link Here
191
		initialize();
248
		initialize();
192
249
193
		final Section section = createSection(parent, toolkit, hasIncoming);
250
		final Section section = createSection(parent, toolkit, hasIncoming);
194
		section.setText(getPartName() + " (" + attachments.size() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
251
		section.setText(getPartName() + " (" + attachments.size() + ")");
195
		if (hasIncoming) {
252
		if (hasIncoming) {
196
			expandSection(toolkit, section);
253
			expandSection(toolkit, section);
197
		} else {
254
		} else {
Lines 237-242 Link Here
237
	}
294
	}
238
295
239
	private void initialize() {
296
	private void initialize() {
297
		if (!propertyListenerIstalled) {
298
			TasksUiPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER);
299
			propertyListenerIstalled = true;
300
		}
240
		attachments = getTaskData().getAttributeMapper().getAttributesByType(getTaskData(),
301
		attachments = getTaskData().getAttributeMapper().getAttributesByType(getTaskData(),
241
				TaskAttribute.TYPE_ATTACHMENT);
302
				TaskAttribute.TYPE_ATTACHMENT);
242
		for (TaskAttribute attachmentAttribute : attachments) {
303
		for (TaskAttribute attachmentAttribute : attachments) {
(-)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
	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 == 1 + offset) {
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.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/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/preferences/Messages.java (+7 lines)
Lines 88-91 Link Here
88
	public static String TasksUiPreferencePage_Web_Browser;
88
	public static String TasksUiPreferencePage_Web_Browser;
89
89
90
	public static String TasksUiPreferencePage_Week_Start;
90
	public static String TasksUiPreferencePage_Week_Start;
91
92
	public static String TasksUiPreferencePage_Attachment_Table;
93
94
	public static String TasksUiPreferencePage_Attachment_Show_Id;
95
96
	public static String TasksUiPreferencePage_Attachment_Coloumn_To_Std;
97
91
}
98
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/preferences/TasksUiPreferencePage.java (-1 / +37 lines)
Lines 75-80 Link Here
75
75
76
	private Button useRichEditor;
76
	private Button useRichEditor;
77
77
78
	private Button attachmentShowID;
79
80
	private Button attachmentColumnUseStdWidth;
81
78
	private Button useWebBrowser;
82
	private Button useWebBrowser;
79
83
80
	private Text synchScheduleTime = null;
84
	private Text synchScheduleTime = null;
Lines 122-127 Link Here
122
		createSchedulingGroup(container);
126
		createSchedulingGroup(container);
123
		createOpenWith(container);
127
		createOpenWith(container);
124
		createTaskActivityGroup(container);
128
		createTaskActivityGroup(container);
129
125
		Composite advanced = createAdvancedSection(container);
130
		Composite advanced = createAdvancedSection(container);
126
		createTaskDataControl(advanced);
131
		createTaskDataControl(advanced);
127
132
Lines 132-137 Link Here
132
		}
137
		}
133
138
134
		createLinks(advanced);
139
		createLinks(advanced);
140
		createAttachmentTable(advanced);
135
		updateRefreshGroupEnablements();
141
		updateRefreshGroupEnablements();
136
		applyDialogFont(container);
142
		applyDialogFont(container);
137
		return container;
143
		return container;
Lines 237-242 Link Here
237
				// shouldn't get here
243
				// shouldn't get here
238
			}
244
			}
239
		}
245
		}
246
		getPreferenceStore().setValue(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID, attachmentShowID.getSelection());
247
		getPreferenceStore().setValue(ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD,
248
				attachmentColumnUseStdWidth.getSelection());
249
		attachmentColumnUseStdWidth.setSelection(false);
240
250
241
		return true;
251
		return true;
242
	}
252
	}
Lines 274-279 Link Here
274
		activityTrackingEnabledButton.setSelection(MonitorUiPlugin.getDefault().getPreferenceStore().getBoolean(
284
		activityTrackingEnabledButton.setSelection(MonitorUiPlugin.getDefault().getPreferenceStore().getBoolean(
275
				MonitorUiPlugin.ACTIVITY_TRACKING_ENABLED));
285
				MonitorUiPlugin.ACTIVITY_TRACKING_ENABLED));
276
286
287
		attachmentShowID.setSelection(getPreferenceStore().getBoolean(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID));
288
		attachmentColumnUseStdWidth.setSelection(getPreferenceStore().getBoolean(
289
				ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD));
277
		return true;
290
		return true;
278
	}
291
	}
279
292
Lines 322-327 Link Here
322
		activityTrackingEnabledButton.setSelection(MonitorUiPlugin.getDefault().getPreferenceStore().getDefaultBoolean(
335
		activityTrackingEnabledButton.setSelection(MonitorUiPlugin.getDefault().getPreferenceStore().getDefaultBoolean(
323
				MonitorUiPlugin.ACTIVITY_TRACKING_ENABLED));
336
				MonitorUiPlugin.ACTIVITY_TRACKING_ENABLED));
324
337
338
		attachmentShowID.setSelection(getPreferenceStore().getDefaultBoolean(
339
				ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID));
340
		attachmentColumnUseStdWidth.setSelection(getPreferenceStore().getDefaultBoolean(
341
				ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD));
342
325
		updateRefreshGroupEnablements();
343
		updateRefreshGroupEnablements();
326
	}
344
	}
327
345
Lines 369-378 Link Here
369
387
370
	}
388
	}
371
389
390
	private void createAttachmentTable(Composite parent) {
391
		Group attachmentContainer = new Group(parent, SWT.SHADOW_ETCHED_IN);
392
		attachmentContainer.setLayout(new GridLayout(2, false));
393
		attachmentContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
394
		attachmentContainer.setText(Messages.TasksUiPreferencePage_Attachment_Table);
395
396
		attachmentColumnUseStdWidth = new Button(attachmentContainer, SWT.CHECK);
397
		attachmentColumnUseStdWidth.setText(Messages.TasksUiPreferencePage_Attachment_Coloumn_To_Std);
398
		attachmentColumnUseStdWidth.setSelection(getPreferenceStore().getBoolean(
399
				ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD));
400
401
		attachmentShowID = new Button(attachmentContainer, SWT.CHECK);
402
		attachmentShowID.setText(Messages.TasksUiPreferencePage_Attachment_Show_Id);
403
		attachmentShowID.setSelection(getPreferenceStore().getBoolean(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID));
404
405
	}
406
372
	private void createOpenWith(Composite parent) {
407
	private void createOpenWith(Composite parent) {
373
		Group container = new Group(parent, SWT.SHADOW_ETCHED_IN);
408
		Group container = new Group(parent, SWT.SHADOW_ETCHED_IN);
374
		container.setLayout(new GridLayout(3, false));
409
		container.setLayout(new GridLayout(2, false));
375
		container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
410
		container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
411
//		container.setLayoutData(new GridData(SWT.LEFT, 1, true, true));
376
412
377
		container.setText(Messages.TasksUiPreferencePage_Task_Editing);
413
		container.setText(Messages.TasksUiPreferencePage_Task_Editing);
378
		useRichEditor = new Button(container, SWT.RADIO);
414
		useRichEditor = new Button(container, SWT.RADIO);
(-)src/org/eclipse/mylyn/internal/tasks/ui/preferences/messages.properties (+3 lines)
Lines 40-42 Link Here
40
TasksUiPreferencePage_Use_the_Restore_dialog_to_recover_missing_tasks=Use the Restore dialog to recover missing tasks
40
TasksUiPreferencePage_Use_the_Restore_dialog_to_recover_missing_tasks=Use the Restore dialog to recover missing tasks
41
TasksUiPreferencePage_Web_Browser=Web Browser
41
TasksUiPreferencePage_Web_Browser=Web Browser
42
TasksUiPreferencePage_Week_Start=Week Start:
42
TasksUiPreferencePage_Week_Start=Week Start:
43
TasksUiPreferencePage_Attachment_Table=Task Editor Attachment Table
44
TasksUiPreferencePage_Attachment_Show_Id=Show Attachment ID
45
TasksUiPreferencePage_Attachment_Coloumn_To_Std=use standard ColumnInfo (undo not supported)
(-)src/org/eclipse/mylyn/internal/tasks/ui/ITasksUiPreferenceConstants.java (+4 lines)
Lines 58-63 Link Here
58
58
59
	public static final String EDITOR_TASKS_RICH = "org.eclipse.mylyn.tasks.ui.reporting.open.editor"; //$NON-NLS-1$
59
	public static final String EDITOR_TASKS_RICH = "org.eclipse.mylyn.tasks.ui.reporting.open.editor"; //$NON-NLS-1$
60
60
61
	public static final String ATTACHMENT_SHOW_ID = "org.eclipse.mylyn.tasks.ui.attachment.showid"; //$NON-NLS-1$
62
63
	public static final String ATTACHMENT_COLUMN_TO_STD = "org.eclipse.mylyn.tasks.ui.attachment.column.to.std"; //$NON-NLS-1$
64
61
	public static final String USE_STRIKETHROUGH_FOR_COMPLETED = "org.eclipse.mylyn.tasks.ui.strikethrough.for.completed"; //$NON-NLS-1$
65
	public static final String USE_STRIKETHROUGH_FOR_COMPLETED = "org.eclipse.mylyn.tasks.ui.strikethrough.for.completed"; //$NON-NLS-1$
62
66
63
	public static final String REPOSITORY_SYNCH_SCHEDULE_ENABLED = "org.eclipse.mylyn.tasks.ui.repositories.synch.schedule"; //$NON-NLS-1$
67
	public static final String REPOSITORY_SYNCH_SCHEDULE_ENABLED = "org.eclipse.mylyn.tasks.ui.repositories.synch.schedule"; //$NON-NLS-1$
(-)src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java (+3 lines)
Lines 889-894 Link Here
889
		store.setDefault(ITasksUiPreferenceConstants.PLANNING_ENDHOUR, 18);
889
		store.setDefault(ITasksUiPreferenceConstants.PLANNING_ENDHOUR, 18);
890
890
891
		store.setDefault(ITasksUiPreferenceConstants.AUTO_EXPAND_TASK_LIST, true);
891
		store.setDefault(ITasksUiPreferenceConstants.AUTO_EXPAND_TASK_LIST, true);
892
893
		store.setDefault(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID, false);
894
		store.setDefault(ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD, true);
892
	}
895
	}
893
896
894
	public static TaskActivityManager getTaskActivityManager() {
897
	public static TaskActivityManager getTaskActivityManager() {
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/ColumnState.java (+75 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.tasks.ui.editors;
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 = -3746488897344479189L;
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 (+223 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.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.editors.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
		for (int index = 0; index < columnInfos.size(); index++) {
198
			TableColumn col = table.getColumn(index);
199
			ColumnState colState = columnInfos.get(index);
200
			col.setAlignment(colState.getAlignment());
201
			col.setWidth(colState.getWidths());
202
			col.setText(colState.getName());
203
		}
204
		table.setColumnOrder(orderArray);
205
	}
206
207
	public void addSelectionChangedListener(ISelectionChangedListener listener) {
208
		tableViewer.addSelectionChangedListener(listener);
209
	}
210
211
	public ISelection getSelection() {
212
		return tableViewer.getSelection();
213
	}
214
215
	public void removeSelectionChangedListener(ISelectionChangedListener listener) {
216
		tableViewer.removeSelectionChangedListener(listener);
217
	}
218
219
	public void setSelection(ISelection selection) {
220
		tableViewer.setSelection(selection);
221
	}
222
223
}

Return to bug 250257