|
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; |
|
|
| 22 |
import org.eclipse.jface.action.IMenuManager; |
| 23 |
import org.eclipse.jface.action.MenuManager; |
24 |
import org.eclipse.jface.action.MenuManager; |
| 24 |
import org.eclipse.jface.action.ToolBarManager; |
25 |
import org.eclipse.jface.action.ToolBarManager; |
| 25 |
import org.eclipse.jface.layout.GridDataFactory; |
|
|
| 26 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
26 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
| 27 |
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; |
27 |
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; |
| 28 |
import org.eclipse.jface.viewers.IOpenListener; |
28 |
import org.eclipse.jface.viewers.IOpenListener; |
| 29 |
import org.eclipse.jface.viewers.OpenEvent; |
29 |
import org.eclipse.jface.viewers.OpenEvent; |
| 30 |
import org.eclipse.jface.viewers.StructuredSelection; |
30 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 31 |
import org.eclipse.jface.viewers.TableViewer; |
|
|
| 32 |
import org.eclipse.jface.viewers.Viewer; |
31 |
import org.eclipse.jface.viewers.Viewer; |
| 33 |
import org.eclipse.jface.viewers.ViewerSorter; |
32 |
import org.eclipse.jface.viewers.ViewerSorter; |
| 34 |
import org.eclipse.jface.window.ToolTip; |
33 |
import org.eclipse.jface.window.ToolTip; |
| 35 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; |
34 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; |
| 36 |
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment; |
35 |
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment; |
|
|
36 |
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants; |
| 37 |
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; |
| 37 |
import org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentHandler; |
38 |
import org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentHandler; |
| 38 |
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus; |
39 |
import org.eclipse.mylyn.internal.tasks.ui.util.ColumnState; |
|
|
40 |
import org.eclipse.mylyn.internal.tasks.ui.views.AbstractTableViewerConfigurator; |
| 39 |
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode; |
41 |
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode; |
| 40 |
import org.eclipse.mylyn.tasks.core.ITaskAttachment; |
42 |
import org.eclipse.mylyn.tasks.core.ITaskAttachment; |
| 41 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
43 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
|
|
44 |
import org.eclipse.mylyn.tasks.ui.TasksUiUtil; |
| 42 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart; |
45 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart; |
| 43 |
import org.eclipse.swt.SWT; |
46 |
import org.eclipse.swt.SWT; |
| 44 |
import org.eclipse.swt.events.SelectionAdapter; |
47 |
import org.eclipse.swt.events.SelectionAdapter; |
|
Lines 50-56
Link Here
|
| 50 |
import org.eclipse.swt.widgets.Label; |
53 |
import org.eclipse.swt.widgets.Label; |
| 51 |
import org.eclipse.swt.widgets.Menu; |
54 |
import org.eclipse.swt.widgets.Menu; |
| 52 |
import org.eclipse.swt.widgets.Table; |
55 |
import org.eclipse.swt.widgets.Table; |
| 53 |
import org.eclipse.swt.widgets.TableColumn; |
|
|
| 54 |
import org.eclipse.ui.IWorkbenchPage; |
56 |
import org.eclipse.ui.IWorkbenchPage; |
| 55 |
import org.eclipse.ui.forms.events.ExpansionAdapter; |
57 |
import org.eclipse.ui.forms.events.ExpansionAdapter; |
| 56 |
import org.eclipse.ui.forms.events.ExpansionEvent; |
58 |
import org.eclipse.ui.forms.events.ExpansionEvent; |
|
Lines 66-77
Link Here
|
| 66 |
|
68 |
|
| 67 |
private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$ |
69 |
private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$ |
| 68 |
|
70 |
|
| 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; |
71 |
private List<TaskAttribute> attachments; |
| 76 |
|
72 |
|
| 77 |
private boolean hasIncoming; |
73 |
private boolean hasIncoming; |
|
Lines 80-158
Link Here
|
| 80 |
|
76 |
|
| 81 |
private Composite attachmentsComposite; |
77 |
private Composite attachmentsComposite; |
| 82 |
|
78 |
|
|
|
79 |
private class AttachmentTableViewer extends AbstractTableViewerConfigurator { |
| 80 |
public AttachmentTableViewer(File stateFile) { |
| 81 |
super(stateFile); |
| 82 |
// ignore |
| 83 |
} |
| 84 |
|
| 85 |
@Override |
| 86 |
protected void adjustColumInfos() { |
| 87 |
boolean showAttachmentID = TasksUiPlugin.getDefault() |
| 88 |
.getPreferenceStore() |
| 89 |
.getBoolean(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID); |
| 90 |
int idWidth = columnInfos.get(0).getWidths(); |
| 91 |
if (!showAttachmentID && idWidth > 0) { |
| 92 |
columnInfos.get(0).setWidths(0); |
| 93 |
} else if (showAttachmentID && idWidth == 0) { |
| 94 |
columnInfos.get(0).setWidths(70); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
@Override |
| 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 |
} |
| 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); |
| 145 |
|
| 146 |
tableViewer.setContentProvider(new ArrayContentProvider()); |
| 147 |
tableViewer.setLabelProvider(new AttachmentTableLabelProvider(getModel(), |
| 148 |
getTaskEditorPage().getAttributeEditorToolkit())); |
| 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 |
} |
| 163 |
|
| 164 |
private AttachmentTableViewer attachmentsViewer; |
| 165 |
|
| 166 |
private boolean propertyListenerIstalled = false; |
| 167 |
|
| 83 |
public TaskEditorAttachmentPart() { |
168 |
public TaskEditorAttachmentPart() { |
| 84 |
setPartName(Messages.TaskEditorAttachmentPart_Attachments); |
169 |
setPartName(Messages.TaskEditorAttachmentPart_Attachments); |
| 85 |
} |
170 |
} |
| 86 |
|
171 |
|
| 87 |
private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) { |
172 |
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 |
|
173 |
|
| 109 |
attachmentsViewer.setSorter(new ViewerSorter() { |
174 |
public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) { |
| 110 |
@Override |
175 |
if (event.getProperty().equals(ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD)) { |
| 111 |
public int compare(Viewer viewer, Object e1, Object e2) { |
176 |
if (TasksUiPlugin.getDefault() |
| 112 |
ITaskAttachment attachment1 = (ITaskAttachment) e1; |
177 |
.getPreferenceStore() |
| 113 |
ITaskAttachment attachment2 = (ITaskAttachment) e2; |
178 |
.getBoolean(ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_TO_STD)) { |
| 114 |
Date created1 = attachment1.getCreationDate(); |
179 |
if (attachmentsViewer != null) { |
| 115 |
Date created2 = attachment2.getCreationDate(); |
180 |
attachmentsViewer.resetColumnInfosToDefault(); |
| 116 |
if (created1 != null && created2 != null) { |
181 |
Table table = attachmentsViewer.getTable(); |
| 117 |
return created1.compareTo(created2); |
182 |
if (!table.isDisposed()) { |
| 118 |
} else if (created1 == null && created2 != null) { |
183 |
if (TasksUiPlugin.getDefault() |
| 119 |
return -1; |
184 |
.getPreferenceStore() |
| 120 |
} else if (created1 != null && created2 == null) { |
185 |
.getBoolean(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) { |
| 121 |
return 1; |
186 |
table.getColumn(0).setWidth(70); |
| 122 |
} else { |
187 |
} else { |
| 123 |
return 0; |
188 |
table.getColumn(0).setWidth(0); |
|
|
189 |
} |
| 190 |
} |
| 191 |
} else { |
| 192 |
IPath stateLocation = Platform.getStateLocation(TasksUiPlugin.getDefault().getBundle()); |
| 193 |
File attachmentStateFile = stateLocation.append("TaskEditorAttachment.obj").toFile(); //$NON-NLS-1$ |
| 194 |
attachmentStateFile.delete(); |
| 195 |
} |
| 196 |
} |
| 197 |
} else if (event.getProperty().equals(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) { |
| 198 |
if (attachmentsViewer != null) { |
| 199 |
Table table = attachmentsViewer.getTable(); |
| 200 |
if (!table.isDisposed()) { |
| 201 |
if (TasksUiPlugin.getDefault() |
| 202 |
.getPreferenceStore() |
| 203 |
.getBoolean(ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID)) { |
| 204 |
table.getColumn(0).setWidth(70); |
| 205 |
} else { |
| 206 |
table.getColumn(0).setWidth(0); |
| 207 |
} |
| 208 |
} |
| 124 |
} |
209 |
} |
| 125 |
} |
210 |
} |
| 126 |
}); |
211 |
} |
| 127 |
|
212 |
}; |
| 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 |
|
213 |
|
|
|
214 |
private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) { |
| 215 |
IPath stateLocation = Platform.getStateLocation(TasksUiPlugin.getDefault().getBundle()); |
| 216 |
File attachmentStateFile = stateLocation.append("TaskEditorAttachment.obj").toFile(); //$NON-NLS-1$ |
| 217 |
attachmentsViewer = new AttachmentTableViewer(attachmentStateFile); |
| 218 |
attachmentsViewer.create(toolkit, attachmentsComposite, 5); |
| 146 |
menuManager = new MenuManager(); |
219 |
menuManager = new MenuManager(); |
| 147 |
menuManager.setRemoveAllWhenShown(true); |
220 |
menuManager.setRemoveAllWhenShown(true); |
| 148 |
menuManager.addMenuListener(new IMenuListener() { |
221 |
|
| 149 |
public void menuAboutToShow(IMenuManager manager) { |
222 |
Menu menu = menuManager.createContextMenu(attachmentsViewer.getTable()); |
| 150 |
TasksUiMenus.fillTaskAttachmentMenu(manager); |
223 |
attachmentsViewer.getTable().setMenu(menu); |
| 151 |
} |
|
|
| 152 |
}); |
| 153 |
getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, true); |
| 154 |
Menu menu = menuManager.createContextMenu(attachmentsTable); |
| 155 |
attachmentsTable.setMenu(menu); |
| 156 |
} |
224 |
} |
| 157 |
|
225 |
|
| 158 |
private void createButtons(Composite attachmentsComposite, FormToolkit toolkit) { |
226 |
private void createButtons(Composite attachmentsComposite, FormToolkit toolkit) { |
|
Lines 227-232
Link Here
|
| 227 |
|
295 |
|
| 228 |
@Override |
296 |
@Override |
| 229 |
public void dispose() { |
297 |
public void dispose() { |
|
|
298 |
if (propertyListenerIstalled) { |
| 299 |
TasksUiPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(PROPERTY_LISTENER); |
| 300 |
propertyListenerIstalled = false; |
| 301 |
} |
| 230 |
if (menuManager != null) { |
302 |
if (menuManager != null) { |
| 231 |
menuManager.dispose(); |
303 |
menuManager.dispose(); |
| 232 |
} |
304 |
} |
|
Lines 242-247
Link Here
|
| 242 |
break; |
314 |
break; |
| 243 |
} |
315 |
} |
| 244 |
} |
316 |
} |
|
|
317 |
if (!propertyListenerIstalled) { |
| 318 |
TasksUiPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER); |
| 319 |
propertyListenerIstalled = true; |
| 320 |
} |
| 245 |
} |
321 |
} |
| 246 |
|
322 |
|
| 247 |
@Override |
323 |
@Override |