|
Lines 13-28
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; |
|
Lines 34-40
Link Here
|
| 34 |
import org.eclipse.jface.window.ToolTip; |
36 |
import org.eclipse.jface.window.ToolTip; |
| 35 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; |
37 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; |
| 36 |
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment; |
38 |
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment; |
|
|
39 |
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants; |
| 40 |
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; |
| 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 49-59
Link Here
|
| 49 |
import org.eclipse.swt.widgets.Composite; |
54 |
import org.eclipse.swt.widgets.Composite; |
| 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; |
|
|
| 53 |
import org.eclipse.swt.widgets.TableColumn; |
| 54 |
import org.eclipse.ui.forms.events.ExpansionAdapter; |
57 |
import org.eclipse.ui.forms.events.ExpansionAdapter; |
| 55 |
import org.eclipse.ui.forms.events.ExpansionEvent; |
58 |
import org.eclipse.ui.forms.events.ExpansionEvent; |
| 56 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
59 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
|
|
60 |
import org.eclipse.ui.forms.widgets.ScrolledForm; |
| 57 |
import org.eclipse.ui.forms.widgets.Section; |
61 |
import org.eclipse.ui.forms.widgets.Section; |
| 58 |
|
62 |
|
| 59 |
/** |
63 |
/** |
|
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); |
|
|
| 84 |
} |
| 85 |
|
81 |
|
| 86 |
private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) { |
82 |
public AttachmentTableViewer(File stateFile) { |
| 87 |
Table attachmentsTable = toolkit.createTable(attachmentsComposite, SWT.MULTI | SWT.FULL_SELECTION); |
83 |
super(stateFile); |
| 88 |
attachmentsTable.setLinesVisible(true); |
84 |
// ignore |
| 89 |
attachmentsTable.setHeaderVisible(true); |
85 |
} |
| 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 |
|
86 |
|
| 108 |
attachmentsViewer.setSorter(new ViewerSorter() { |
87 |
@Override |
| 109 |
@Override |
88 |
protected void adjustColumInfos() { |
| 110 |
public int compare(Viewer viewer, Object e1, Object e2) { |
89 |
boolean showAttachmentID = TasksUiPlugin.getDefault().getPreferenceStore().getBoolean( |
| 111 |
ITaskAttachment attachment1 = (ITaskAttachment) e1; |
90 |
ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID); |
| 112 |
ITaskAttachment attachment2 = (ITaskAttachment) e2; |
91 |
int idWidth = columnInfos.get(0).getWidths(); |
| 113 |
Date created1 = attachment1.getCreationDate(); |
92 |
if (!showAttachmentID && idWidth > 0) { |
| 114 |
Date created2 = attachment2.getCreationDate(); |
93 |
columnInfos.get(0).setWidths(0); |
| 115 |
if (created1 != null && created2 != null) { |
94 |
} else if (showAttachmentID && idWidth == 0) { |
| 116 |
return created1.compareTo(created2); |
95 |
columnInfos.get(0).setWidths(70); |
| 117 |
} else if (created1 == null && created2 != null) { |
96 |
} |
| 118 |
return -1; |
97 |
|
| 119 |
} else if (created1 != null && created2 == null) { |
98 |
} |
| 120 |
return 1; |
99 |
|
| 121 |
} else { |
100 |
@Override |
| 122 |
return 0; |
101 |
protected void setDefaultColumnInfos() { |
|
|
102 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Id, 70)); |
| 103 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Name, 130)); |
| 104 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Description, 150)); |
| 105 |
ColumnState columnState = new ColumnState(Messages.TaskEditorAttachmentPart_Size, 70); |
| 106 |
columnState.setAlignment(SWT.RIGHT); |
| 107 |
columnInfos.add(columnState); |
| 108 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Creator, 100)); |
| 109 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Created, 100)); |
| 110 |
|
| 111 |
orderArray = new int[6]; |
| 112 |
for (int i = 0; i < 6; i++) { |
| 113 |
orderArray[i] = i; |
| 114 |
} |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
@Override |
| 119 |
protected void setupTableViewer() { |
| 120 |
tableViewer.setUseHashlookup(true); |
| 121 |
ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE); |
| 122 |
|
| 123 |
tableViewer.setSorter(new ViewerSorter() { |
| 124 |
@Override |
| 125 |
public int compare(Viewer viewer, Object e1, Object e2) { |
| 126 |
ITaskAttachment attachment1 = (ITaskAttachment) e1; |
| 127 |
ITaskAttachment attachment2 = (ITaskAttachment) e2; |
| 128 |
Date created1 = attachment1.getCreationDate(); |
| 129 |
Date created2 = attachment2.getCreationDate(); |
| 130 |
if (created1 != null && created2 != null) { |
| 131 |
return created1.compareTo(created2); |
| 132 |
} else if (created1 == null && created2 != null) { |
| 133 |
return -1; |
| 134 |
} else if (created1 != null && created2 == null) { |
| 135 |
return 1; |
| 136 |
} else { |
| 137 |
return 0; |
| 138 |
} |
| 123 |
} |
139 |
} |
|
|
140 |
}); |
| 141 |
List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size()); |
| 142 |
for (TaskAttribute attribute : attachments) { |
| 143 |
TaskAttachment taskAttachment = new TaskAttachment(getModel().getTaskRepository(), |
| 144 |
getModel().getTask(), attribute); |
| 145 |
getTaskData().getAttributeMapper().updateTaskAttachment(taskAttachment, attribute); |
| 146 |
attachmentList.add(taskAttachment); |
| 124 |
} |
147 |
} |
| 125 |
}); |
148 |
tableViewer.setContentProvider(new ArrayContentProvider()); |
|
|
149 |
tableViewer.setLabelProvider(new AttachmentTableLabelProvider(getModel(), |
| 150 |
getTaskEditorPage().getAttributeEditorToolkit(), 0)); |
| 151 |
tableViewer.addOpenListener(new IOpenListener() { |
| 152 |
public void open(OpenEvent event) { |
| 153 |
if (!event.getSelection().isEmpty()) { |
| 154 |
StructuredSelection selection = (StructuredSelection) event.getSelection(); |
| 155 |
ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement(); |
| 156 |
TasksUiUtil.openUrl(attachment.getUrl()); |
| 157 |
} |
| 158 |
} |
| 159 |
}); |
| 160 |
tableViewer.addSelectionChangedListener(getTaskEditorPage()); |
| 161 |
tableViewer.setInput(attachmentList.toArray()); |
| 162 |
} |
| 163 |
|
| 164 |
} |
| 165 |
|
| 166 |
private AttachmentTableViewer attachmentsViewer; |
| 126 |
|
167 |
|
| 127 |
List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size()); |
168 |
private boolean propertyListenerIstalled = false; |
| 128 |
for (TaskAttribute attribute : attachments) { |
169 |
|
| 129 |
TaskAttachment taskAttachment = new TaskAttachment(getModel().getTaskRepository(), getModel().getTask(), |
170 |
private final org.eclipse.jface.util.IPropertyChangeListener PROPERTY_LISTENER = new org.eclipse.jface.util.IPropertyChangeListener() { |
| 130 |
attribute); |
171 |
|
| 131 |
getTaskData().getAttributeMapper().updateTaskAttachment(taskAttachment, attribute); |
172 |
public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) { |
| 132 |
attachmentList.add(taskAttachment); |
173 |
if (event.getProperty().equals(ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD)) { |
| 133 |
} |
174 |
if (TasksUiPlugin.getDefault().getPreferenceStore().getBoolean( |
| 134 |
attachmentsViewer.setContentProvider(new ArrayContentProvider()); |
175 |
ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD)) { |
| 135 |
attachmentsViewer.setLabelProvider(new AttachmentTableLabelProvider(getModel(), |
176 |
attachmentsViewer.resetColumnInfosToDefault(); |
| 136 |
getTaskEditorPage().getAttributeEditorToolkit())); |
177 |
if (TasksUiPlugin.getDefault().getPreferenceStore().getBoolean( |
| 137 |
attachmentsViewer.addOpenListener(new IOpenListener() { |
178 |
ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) { |
| 138 |
public void open(OpenEvent event) { |
179 |
attachmentsViewer.getTable().getColumn(0).setWidth(70); |
| 139 |
if (!event.getSelection().isEmpty()) { |
180 |
} else { |
| 140 |
StructuredSelection selection = (StructuredSelection) event.getSelection(); |
181 |
attachmentsViewer.getTable().getColumn(0).setWidth(0); |
| 141 |
ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement(); |
182 |
} |
| 142 |
TasksUiUtil.openUrl(attachment.getUrl()); |
183 |
TasksUiPlugin.getDefault().getPreferenceStore().setValue( |
|
|
184 |
ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD, false); |
| 185 |
} |
| 186 |
} else if (event.getProperty().equals(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) { |
| 187 |
if (TasksUiPlugin.getDefault().getPreferenceStore().getBoolean( |
| 188 |
ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) { |
| 189 |
attachmentsViewer.getTable().getColumn(0).setWidth(70); |
| 190 |
} else { |
| 191 |
attachmentsViewer.getTable().getColumn(0).setWidth(0); |
| 143 |
} |
192 |
} |
| 144 |
} |
193 |
} |
| 145 |
}); |
194 |
|
| 146 |
attachmentsViewer.addSelectionChangedListener(getTaskEditorPage()); |
195 |
} |
| 147 |
attachmentsViewer.setInput(attachmentList.toArray()); |
196 |
}; |
|
|
197 |
|
| 198 |
public TaskEditorAttachmentPart() { |
| 199 |
setPartName(Messages.TaskEditorAttachmentPart_Attachments); |
| 200 |
} |
| 201 |
|
| 202 |
private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) { |
| 203 |
IPath stateLocation = Platform.getStateLocation(TasksUiPlugin.getDefault().getBundle()); |
| 204 |
File attachmentStateFile = stateLocation.append("TaskEditorAttachment.obj").toFile(); //$NON-NLS-1$ |
| 205 |
attachmentsViewer = new AttachmentTableViewer(attachmentStateFile); |
| 206 |
attachmentsViewer.create(toolkit, attachmentsComposite, 5); |
| 148 |
|
207 |
|
| 149 |
menuManager = new MenuManager(); |
208 |
menuManager = new MenuManager(); |
| 150 |
menuManager.setRemoveAllWhenShown(true); |
209 |
menuManager.setRemoveAllWhenShown(true); |
|
Lines 154-161
Link Here
|
| 154 |
} |
213 |
} |
| 155 |
}); |
214 |
}); |
| 156 |
getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, true); |
215 |
getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, true); |
| 157 |
Menu menu = menuManager.createContextMenu(attachmentsTable); |
216 |
Menu menu = menuManager.createContextMenu(attachmentsViewer.getTable()); |
| 158 |
attachmentsTable.setMenu(menu); |
217 |
attachmentsViewer.getTable().setMenu(menu); |
| 159 |
} |
218 |
} |
| 160 |
|
219 |
|
| 161 |
private void createButtons(Composite attachmentsComposite, FormToolkit toolkit) { |
220 |
private void createButtons(Composite attachmentsComposite, FormToolkit toolkit) { |
|
Lines 191-197
Link Here
|
| 191 |
initialize(); |
250 |
initialize(); |
| 192 |
|
251 |
|
| 193 |
final Section section = createSection(parent, toolkit, hasIncoming); |
252 |
final Section section = createSection(parent, toolkit, hasIncoming); |
| 194 |
section.setText(getPartName() + " (" + attachments.size() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ |
253 |
section.setText(getPartName() + " (" + attachments.size() + ")"); |
| 195 |
if (hasIncoming) { |
254 |
if (hasIncoming) { |
| 196 |
expandSection(toolkit, section); |
255 |
expandSection(toolkit, section); |
| 197 |
} else { |
256 |
} else { |
|
Lines 237-242
Link Here
|
| 237 |
} |
296 |
} |
| 238 |
|
297 |
|
| 239 |
private void initialize() { |
298 |
private void initialize() { |
|
|
299 |
if (!propertyListenerIstalled) { |
| 300 |
TasksUiPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER); |
| 301 |
propertyListenerIstalled = true; |
| 302 |
} |
| 240 |
attachments = getTaskData().getAttributeMapper().getAttributesByType(getTaskData(), |
303 |
attachments = getTaskData().getAttributeMapper().getAttributesByType(getTaskData(), |
| 241 |
TaskAttribute.TYPE_ATTACHMENT); |
304 |
TaskAttribute.TYPE_ATTACHMENT); |
| 242 |
for (TaskAttribute attachmentAttribute : attachments) { |
305 |
for (TaskAttribute attachmentAttribute : attachments) { |
|
Lines 260-263
Link Here
|
| 260 |
toolBarManager.add(attachFileAction); |
323 |
toolBarManager.add(attachFileAction); |
| 261 |
} |
324 |
} |
| 262 |
|
325 |
|
|
|
326 |
public void selectAttachment(ScrolledForm form, TaskAttribute attribute) { |
| 327 |
TableViewer tv = attachmentsViewer.getTableViewer(); |
| 328 |
int anz = tv.getTable().getItemCount(); |
| 329 |
int i = 0; |
| 330 |
tv.getTable().setSelection(0, 0); |
| 331 |
EditorUtil.focusOn(form, tv.getControl()); |
| 332 |
for (; i < anz; i++) { |
| 333 |
TaskAttachment tableItem = (TaskAttachment) tv.getElementAt(i); |
| 334 |
if (tableItem.getTaskAttribute().equals(attribute)) { |
| 335 |
tv.getTable().setSelection(i, i); |
| 336 |
break; |
| 337 |
} |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
public void resetSelectedAttachment(ScrolledForm form) { |
| 342 |
TableViewer tv = attachmentsViewer.getTableViewer(); |
| 343 |
tv.getTable().deselectAll(); |
| 344 |
} |
| 263 |
} |
345 |
} |