|
Lines 13-44
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.commands.OpenTaskAttachmentHandler; |
40 |
import org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentHandler; |
|
|
41 |
import org.eclipse.mylyn.internal.tasks.ui.util.ColumnState; |
| 38 |
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus; |
42 |
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus; |
|
|
43 |
import org.eclipse.mylyn.internal.tasks.ui.views.AbstractTableViewerConfigurator; |
| 39 |
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode; |
44 |
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode; |
| 40 |
import org.eclipse.mylyn.tasks.core.ITaskAttachment; |
45 |
import org.eclipse.mylyn.tasks.core.ITaskAttachment; |
| 41 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
46 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
|
|
47 |
import org.eclipse.mylyn.tasks.ui.TasksUiUtil; |
| 42 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart; |
48 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart; |
| 43 |
import org.eclipse.swt.SWT; |
49 |
import org.eclipse.swt.SWT; |
| 44 |
import org.eclipse.swt.events.SelectionAdapter; |
50 |
import org.eclipse.swt.events.SelectionAdapter; |
|
Lines 50-56
Link Here
|
| 50 |
import org.eclipse.swt.widgets.Label; |
56 |
import org.eclipse.swt.widgets.Label; |
| 51 |
import org.eclipse.swt.widgets.Menu; |
57 |
import org.eclipse.swt.widgets.Menu; |
| 52 |
import org.eclipse.swt.widgets.Table; |
58 |
import org.eclipse.swt.widgets.Table; |
| 53 |
import org.eclipse.swt.widgets.TableColumn; |
|
|
| 54 |
import org.eclipse.ui.IWorkbenchPage; |
59 |
import org.eclipse.ui.IWorkbenchPage; |
| 55 |
import org.eclipse.ui.forms.events.ExpansionAdapter; |
60 |
import org.eclipse.ui.forms.events.ExpansionAdapter; |
| 56 |
import org.eclipse.ui.forms.events.ExpansionEvent; |
61 |
import org.eclipse.ui.forms.events.ExpansionEvent; |
|
Lines 66-77
Link Here
|
| 66 |
|
71 |
|
| 67 |
private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$ |
72 |
private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$ |
| 68 |
|
73 |
|
| 69 |
private final String[] attachmentsColumns = { Messages.TaskEditorAttachmentPart_Name, |
|
|
| 70 |
Messages.TaskEditorAttachmentPart_Description, /*"Type", */Messages.TaskEditorAttachmentPart_Size, |
| 71 |
Messages.TaskEditorAttachmentPart_Creator, Messages.TaskEditorAttachmentPart_Created }; |
| 72 |
|
| 73 |
private final int[] attachmentsColumnWidths = { 130, 150, /*100,*/70, 100, 100 }; |
| 74 |
|
| 75 |
private List<TaskAttribute> attachments; |
74 |
private List<TaskAttribute> attachments; |
| 76 |
|
75 |
|
| 77 |
private boolean hasIncoming; |
76 |
private boolean hasIncoming; |
|
Lines 80-148
Link Here
|
| 80 |
|
79 |
|
| 81 |
private Composite attachmentsComposite; |
80 |
private Composite attachmentsComposite; |
| 82 |
|
81 |
|
|
|
82 |
private class AttachmentTableViewer extends AbstractTableViewerConfigurator { |
| 83 |
public AttachmentTableViewer(File stateFile) { |
| 84 |
super(stateFile); |
| 85 |
// ignore |
| 86 |
} |
| 87 |
|
| 88 |
@Override |
| 89 |
protected void adjustColumInfos() { |
| 90 |
boolean showAttachmentID = TasksUiPlugin.getDefault() |
| 91 |
.getPreferenceStore() |
| 92 |
.getBoolean(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID); |
| 93 |
int idWidth = columnInfos.get(0).getWidths(); |
| 94 |
if (!showAttachmentID && idWidth > 0) { |
| 95 |
columnInfos.get(0).setWidths(0); |
| 96 |
} else if (showAttachmentID && idWidth == 0) { |
| 97 |
columnInfos.get(0).setWidths(70); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
@Override |
| 102 |
protected void setDefaultColumnInfos() { |
| 103 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_ID, 70)); |
| 104 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Name, 130)); |
| 105 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Description, 150)); |
| 106 |
ColumnState columnState = new ColumnState(Messages.TaskEditorAttachmentPart_Size, 70); |
| 107 |
columnState.setAlignment(SWT.RIGHT); |
| 108 |
columnInfos.add(columnState); |
| 109 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Creator, 100)); |
| 110 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Created, 100)); |
| 111 |
|
| 112 |
orderArray = new int[6]; |
| 113 |
for (int i = 0; i < 6; i++) { |
| 114 |
orderArray[i] = i; |
| 115 |
} |
| 116 |
|
| 117 |
} |
| 118 |
|
| 119 |
@Override |
| 120 |
protected void setupTableViewer() { |
| 121 |
tableViewer.setUseHashlookup(true); |
| 122 |
ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE); |
| 123 |
|
| 124 |
tableViewer.setSorter(new ViewerSorter() { |
| 125 |
@Override |
| 126 |
public int compare(Viewer viewer, Object e1, Object e2) { |
| 127 |
ITaskAttachment attachment1 = (ITaskAttachment) e1; |
| 128 |
ITaskAttachment attachment2 = (ITaskAttachment) e2; |
| 129 |
Date created1 = attachment1.getCreationDate(); |
| 130 |
Date created2 = attachment2.getCreationDate(); |
| 131 |
if (created1 != null && created2 != null) { |
| 132 |
return created1.compareTo(created2); |
| 133 |
} else if (created1 == null && created2 != null) { |
| 134 |
return -1; |
| 135 |
} else if (created1 != null && created2 == null) { |
| 136 |
return 1; |
| 137 |
} else { |
| 138 |
return 0; |
| 139 |
} |
| 140 |
} |
| 141 |
}); |
| 142 |
List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size()); |
| 143 |
for (TaskAttribute attribute : attachments) { |
| 144 |
TaskAttachment taskAttachment = new TaskAttachment(getModel().getTaskRepository(), |
| 145 |
getModel().getTask(), attribute); |
| 146 |
getTaskData().getAttributeMapper().updateTaskAttachment(taskAttachment, attribute); |
| 147 |
attachmentList.add(taskAttachment); |
| 148 |
|
| 149 |
tableViewer.setContentProvider(new ArrayContentProvider()); |
| 150 |
tableViewer.setLabelProvider(new AttachmentTableLabelProvider(getModel(), |
| 151 |
getTaskEditorPage().getAttributeEditorToolkit())); |
| 152 |
tableViewer.addOpenListener(new IOpenListener() { |
| 153 |
public void open(OpenEvent event) { |
| 154 |
if (!event.getSelection().isEmpty()) { |
| 155 |
StructuredSelection selection = (StructuredSelection) event.getSelection(); |
| 156 |
ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement(); |
| 157 |
TasksUiUtil.openUrl(attachment.getUrl()); |
| 158 |
} |
| 159 |
} |
| 160 |
}); |
| 161 |
tableViewer.addSelectionChangedListener(getTaskEditorPage()); |
| 162 |
tableViewer.setInput(attachmentList.toArray()); |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
private AttachmentTableViewer attachmentsViewer; |
| 168 |
|
| 169 |
private boolean propertyListenerIstalled = false; |
| 170 |
|
| 83 |
public TaskEditorAttachmentPart() { |
171 |
public TaskEditorAttachmentPart() { |
| 84 |
setPartName(Messages.TaskEditorAttachmentPart_Attachments); |
172 |
setPartName(Messages.TaskEditorAttachmentPart_Attachments); |
| 85 |
} |
173 |
} |
| 86 |
|
174 |
|
| 87 |
private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) { |
175 |
private final org.eclipse.jface.util.IPropertyChangeListener PROPERTY_LISTENER = new org.eclipse.jface.util.IPropertyChangeListener() { |
| 88 |
Table attachmentsTable = toolkit.createTable(attachmentsComposite, SWT.MULTI | SWT.FULL_SELECTION); |
|
|
| 89 |
attachmentsTable.setLinesVisible(true); |
| 90 |
attachmentsTable.setHeaderVisible(true); |
| 91 |
attachmentsTable.setLayout(new GridLayout()); |
| 92 |
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).hint(500, SWT.DEFAULT).applyTo( |
| 93 |
attachmentsTable); |
| 94 |
attachmentsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER); |
| 95 |
|
| 96 |
for (int i = 0; i < attachmentsColumns.length; i++) { |
| 97 |
TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, i); |
| 98 |
column.setText(attachmentsColumns[i]); |
| 99 |
column.setWidth(attachmentsColumnWidths[i]); |
| 100 |
} |
| 101 |
// size column |
| 102 |
attachmentsTable.getColumn(2).setAlignment(SWT.RIGHT); |
| 103 |
|
| 104 |
TableViewer attachmentsViewer = new TableViewer(attachmentsTable); |
| 105 |
attachmentsViewer.setUseHashlookup(true); |
| 106 |
attachmentsViewer.setColumnProperties(attachmentsColumns); |
| 107 |
ColumnViewerToolTipSupport.enableFor(attachmentsViewer, ToolTip.NO_RECREATE); |
| 108 |
|
176 |
|
| 109 |
attachmentsViewer.setSorter(new ViewerSorter() { |
177 |
public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) { |
| 110 |
@Override |
178 |
if (event.getProperty().equals(ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD)) { |
| 111 |
public int compare(Viewer viewer, Object e1, Object e2) { |
179 |
if (TasksUiPlugin.getDefault() |
| 112 |
ITaskAttachment attachment1 = (ITaskAttachment) e1; |
180 |
.getPreferenceStore() |
| 113 |
ITaskAttachment attachment2 = (ITaskAttachment) e2; |
181 |
.getBoolean(ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD)) { |
| 114 |
Date created1 = attachment1.getCreationDate(); |
182 |
if (attachmentsViewer != null) { |
| 115 |
Date created2 = attachment2.getCreationDate(); |
183 |
attachmentsViewer.resetColumnInfosToDefault(); |
| 116 |
if (created1 != null && created2 != null) { |
184 |
Table table = attachmentsViewer.getTable(); |
| 117 |
return created1.compareTo(created2); |
185 |
if (!table.isDisposed()) { |
| 118 |
} else if (created1 == null && created2 != null) { |
186 |
if (TasksUiPlugin.getDefault() |
| 119 |
return -1; |
187 |
.getPreferenceStore() |
| 120 |
} else if (created1 != null && created2 == null) { |
188 |
.getBoolean(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) { |
| 121 |
return 1; |
189 |
table.getColumn(0).setWidth(70); |
| 122 |
} else { |
190 |
} else { |
| 123 |
return 0; |
191 |
table.getColumn(0).setWidth(0); |
|
|
192 |
} |
| 193 |
} |
| 194 |
} else { |
| 195 |
IPath stateLocation = Platform.getStateLocation(TasksUiPlugin.getDefault().getBundle()); |
| 196 |
File attachmentStateFile = stateLocation.append("TaskEditorAttachment.obj").toFile(); //$NON-NLS-1$ |
| 197 |
attachmentStateFile.delete(); |
| 198 |
} |
| 199 |
} |
| 200 |
} else if (event.getProperty().equals(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) { |
| 201 |
if (attachmentsViewer != null) { |
| 202 |
Table table = attachmentsViewer.getTable(); |
| 203 |
if (!table.isDisposed()) { |
| 204 |
if (TasksUiPlugin.getDefault() |
| 205 |
.getPreferenceStore() |
| 206 |
.getBoolean(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) { |
| 207 |
table.getColumn(0).setWidth(70); |
| 208 |
} else { |
| 209 |
table.getColumn(0).setWidth(0); |
| 210 |
} |
| 211 |
} |
| 124 |
} |
212 |
} |
| 125 |
} |
213 |
} |
| 126 |
}); |
214 |
} |
| 127 |
|
215 |
}; |
| 128 |
List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size()); |
|
|
| 129 |
for (TaskAttribute attribute : attachments) { |
| 130 |
TaskAttachment taskAttachment = new TaskAttachment(getModel().getTaskRepository(), getModel().getTask(), |
| 131 |
attribute); |
| 132 |
getTaskData().getAttributeMapper().updateTaskAttachment(taskAttachment, attribute); |
| 133 |
attachmentList.add(taskAttachment); |
| 134 |
} |
| 135 |
attachmentsViewer.setContentProvider(new ArrayContentProvider()); |
| 136 |
attachmentsViewer.setLabelProvider(new AttachmentTableLabelProvider(getModel(), |
| 137 |
getTaskEditorPage().getAttributeEditorToolkit())); |
| 138 |
attachmentsViewer.addOpenListener(new IOpenListener() { |
| 139 |
public void open(OpenEvent event) { |
| 140 |
openAttachments(event); |
| 141 |
} |
| 142 |
}); |
| 143 |
attachmentsViewer.addSelectionChangedListener(getTaskEditorPage()); |
| 144 |
attachmentsViewer.setInput(attachmentList.toArray()); |
| 145 |
|
216 |
|
|
|
217 |
private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) { |
| 218 |
IPath stateLocation = Platform.getStateLocation(TasksUiPlugin.getDefault().getBundle()); |
| 219 |
File attachmentStateFile = stateLocation.append("TaskEditorAttachment.obj").toFile(); //$NON-NLS-1$ |
| 220 |
attachmentsViewer = new AttachmentTableViewer(attachmentStateFile); |
| 221 |
attachmentsViewer.create(toolkit, attachmentsComposite, 5); |
| 146 |
menuManager = new MenuManager(); |
222 |
menuManager = new MenuManager(); |
| 147 |
menuManager.setRemoveAllWhenShown(true); |
223 |
menuManager.setRemoveAllWhenShown(true); |
| 148 |
menuManager.addMenuListener(new IMenuListener() { |
224 |
menuManager.addMenuListener(new IMenuListener() { |
|
Lines 151-158
Link Here
|
| 151 |
} |
227 |
} |
| 152 |
}); |
228 |
}); |
| 153 |
getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, true); |
229 |
getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, true); |
| 154 |
Menu menu = menuManager.createContextMenu(attachmentsTable); |
230 |
|
| 155 |
attachmentsTable.setMenu(menu); |
231 |
Menu menu = menuManager.createContextMenu(attachmentsViewer.getTable()); |
|
|
232 |
attachmentsViewer.getTable().setMenu(menu); |
| 156 |
} |
233 |
} |
| 157 |
|
234 |
|
| 158 |
private void createButtons(Composite attachmentsComposite, FormToolkit toolkit) { |
235 |
private void createButtons(Composite attachmentsComposite, FormToolkit toolkit) { |
|
Lines 227-232
Link Here
|
| 227 |
|
304 |
|
| 228 |
@Override |
305 |
@Override |
| 229 |
public void dispose() { |
306 |
public void dispose() { |
|
|
307 |
if (propertyListenerIstalled) { |
| 308 |
TasksUiPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(PROPERTY_LISTENER); |
| 309 |
propertyListenerIstalled = false; |
| 310 |
} |
| 230 |
if (menuManager != null) { |
311 |
if (menuManager != null) { |
| 231 |
menuManager.dispose(); |
312 |
menuManager.dispose(); |
| 232 |
} |
313 |
} |
|
Lines 242-247
Link Here
|
| 242 |
break; |
323 |
break; |
| 243 |
} |
324 |
} |
| 244 |
} |
325 |
} |
|
|
326 |
if (!propertyListenerIstalled) { |
| 327 |
TasksUiPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER); |
| 328 |
propertyListenerIstalled = true; |
| 329 |
} |
| 245 |
} |
330 |
} |
| 246 |
|
331 |
|
| 247 |
@Override |
332 |
@Override |