|
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) { |