|
Lines 13-22
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; |
| 17 |
import java.io.FileInputStream; |
| 18 |
import java.io.FileOutputStream; |
| 19 |
import java.io.IOException; |
| 20 |
import java.io.ObjectInputStream; |
| 21 |
import java.io.ObjectOutputStream; |
| 16 |
import java.util.ArrayList; |
22 |
import java.util.ArrayList; |
| 17 |
import java.util.Date; |
23 |
import java.util.Date; |
| 18 |
import java.util.List; |
24 |
import java.util.List; |
| 19 |
|
25 |
|
|
|
26 |
import org.eclipse.core.runtime.IPath; |
| 27 |
import org.eclipse.core.runtime.IStatus; |
| 28 |
import org.eclipse.core.runtime.Platform; |
| 29 |
import org.eclipse.core.runtime.Status; |
| 20 |
import org.eclipse.jface.action.Action; |
30 |
import org.eclipse.jface.action.Action; |
| 21 |
import org.eclipse.jface.action.IMenuListener; |
31 |
import org.eclipse.jface.action.IMenuListener; |
| 22 |
import org.eclipse.jface.action.IMenuManager; |
32 |
import org.eclipse.jface.action.IMenuManager; |
|
Lines 32-39
Link Here
|
| 32 |
import org.eclipse.jface.viewers.Viewer; |
42 |
import org.eclipse.jface.viewers.Viewer; |
| 33 |
import org.eclipse.jface.viewers.ViewerSorter; |
43 |
import org.eclipse.jface.viewers.ViewerSorter; |
| 34 |
import org.eclipse.jface.window.ToolTip; |
44 |
import org.eclipse.jface.window.ToolTip; |
|
|
45 |
import org.eclipse.mylyn.commons.core.StatusHandler; |
| 35 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; |
46 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; |
| 36 |
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment; |
47 |
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment; |
|
|
48 |
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants; |
| 49 |
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; |
| 37 |
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus; |
50 |
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus; |
| 38 |
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode; |
51 |
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode; |
| 39 |
import org.eclipse.mylyn.tasks.core.ITaskAttachment; |
52 |
import org.eclipse.mylyn.tasks.core.ITaskAttachment; |
|
Lines 41-46
Link Here
|
| 41 |
import org.eclipse.mylyn.tasks.ui.TasksUiUtil; |
54 |
import org.eclipse.mylyn.tasks.ui.TasksUiUtil; |
| 42 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart; |
55 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart; |
| 43 |
import org.eclipse.swt.SWT; |
56 |
import org.eclipse.swt.SWT; |
|
|
57 |
import org.eclipse.swt.events.ControlEvent; |
| 58 |
import org.eclipse.swt.events.ControlListener; |
| 44 |
import org.eclipse.swt.events.SelectionAdapter; |
59 |
import org.eclipse.swt.events.SelectionAdapter; |
| 45 |
import org.eclipse.swt.events.SelectionEvent; |
60 |
import org.eclipse.swt.events.SelectionEvent; |
| 46 |
import org.eclipse.swt.layout.GridData; |
61 |
import org.eclipse.swt.layout.GridData; |
|
Lines 65-76
Link Here
|
| 65 |
|
80 |
|
| 66 |
private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$ |
81 |
private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$ |
| 67 |
|
82 |
|
| 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; |
83 |
private List<TaskAttribute> attachments; |
| 75 |
|
84 |
|
| 76 |
private boolean hasIncoming; |
85 |
private boolean hasIncoming; |
|
Lines 79-84
Link Here
|
| 79 |
|
88 |
|
| 80 |
private Composite attachmentsComposite; |
89 |
private Composite attachmentsComposite; |
| 81 |
|
90 |
|
|
|
91 |
static ArrayList<ColumnState> columnInfos = new ArrayList<ColumnState>(5); |
| 92 |
|
| 93 |
private static boolean propertyListenerIstalled = false; |
| 94 |
|
| 95 |
private static org.eclipse.jface.util.IPropertyChangeListener PROPERTY_LISTENER = new org.eclipse.jface.util.IPropertyChangeListener() { |
| 96 |
|
| 97 |
public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) { |
| 98 |
if (event.getProperty().equals(ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_STD_WIDTH)) { |
| 99 |
if (TasksUiPlugin.getDefault().getPreferenceStore().getBoolean( |
| 100 |
ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_STD_WIDTH)) { |
| 101 |
columnInfos.clear(); |
| 102 |
readState(); |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
}; |
| 107 |
|
| 82 |
public TaskEditorAttachmentPart() { |
108 |
public TaskEditorAttachmentPart() { |
| 83 |
setPartName(Messages.TaskEditorAttachmentPart_Attachments); |
109 |
setPartName(Messages.TaskEditorAttachmentPart_Attachments); |
| 84 |
} |
110 |
} |
|
Lines 91-108
Link Here
|
| 91 |
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).hint(500, SWT.DEFAULT).applyTo( |
117 |
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).hint(500, SWT.DEFAULT).applyTo( |
| 92 |
attachmentsTable); |
118 |
attachmentsTable); |
| 93 |
attachmentsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER); |
119 |
attachmentsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER); |
|
|
120 |
boolean showAttachmentID = TasksUiPlugin.getDefault().getPreferenceStore().getBoolean( |
| 121 |
ITasksUiPreferenceConstants.ATTACHMENT_SHOW_ID); |
| 122 |
int offset = showAttachmentID ? 0 : -1; |
| 123 |
for (int i = 0; i < columnInfos.size(); i++) { |
| 124 |
if (!showAttachmentID && i == 0) { |
| 125 |
continue; |
| 126 |
} |
| 127 |
final int index = i + offset; |
| 128 |
final TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, index); |
| 129 |
column.setText(columnInfos.get(i).getName()); |
| 130 |
column.setWidth(columnInfos.get(i).getWidths()); |
| 131 |
column.addControlListener(new ControlListener() { |
| 132 |
|
| 133 |
public void controlResized(ControlEvent e) { |
| 134 |
if (!TasksUiPlugin.getDefault().getPreferenceStore().getBoolean( |
| 135 |
ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_STD_WIDTH)) { |
| 136 |
columnInfos.get(index).setWidths(column.getWidth()); |
| 137 |
writeState(); |
| 138 |
} |
| 139 |
} |
| 94 |
|
140 |
|
| 95 |
for (int i = 0; i < attachmentsColumns.length; i++) { |
141 |
public void controlMoved(ControlEvent e) { |
| 96 |
TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, i); |
142 |
// ignore |
| 97 |
column.setText(attachmentsColumns[i]); |
143 |
} |
| 98 |
column.setWidth(attachmentsColumnWidths[i]); |
144 |
}); |
| 99 |
} |
145 |
} |
| 100 |
// size column |
146 |
// size column |
| 101 |
attachmentsTable.getColumn(2).setAlignment(SWT.RIGHT); |
147 |
attachmentsTable.getColumn(2).setAlignment(SWT.RIGHT); |
| 102 |
|
148 |
|
| 103 |
TableViewer attachmentsViewer = new TableViewer(attachmentsTable); |
149 |
TableViewer attachmentsViewer = new TableViewer(attachmentsTable); |
| 104 |
attachmentsViewer.setUseHashlookup(true); |
150 |
attachmentsViewer.setUseHashlookup(true); |
| 105 |
attachmentsViewer.setColumnProperties(attachmentsColumns); |
|
|
| 106 |
ColumnViewerToolTipSupport.enableFor(attachmentsViewer, ToolTip.NO_RECREATE); |
151 |
ColumnViewerToolTipSupport.enableFor(attachmentsViewer, ToolTip.NO_RECREATE); |
| 107 |
|
152 |
|
| 108 |
attachmentsViewer.setSorter(new ViewerSorter() { |
153 |
attachmentsViewer.setSorter(new ViewerSorter() { |
|
Lines 133-139
Link Here
|
| 133 |
} |
178 |
} |
| 134 |
attachmentsViewer.setContentProvider(new ArrayContentProvider()); |
179 |
attachmentsViewer.setContentProvider(new ArrayContentProvider()); |
| 135 |
attachmentsViewer.setLabelProvider(new AttachmentTableLabelProvider(getModel(), |
180 |
attachmentsViewer.setLabelProvider(new AttachmentTableLabelProvider(getModel(), |
| 136 |
getTaskEditorPage().getAttributeEditorToolkit())); |
181 |
getTaskEditorPage().getAttributeEditorToolkit(), offset)); |
| 137 |
attachmentsViewer.addOpenListener(new IOpenListener() { |
182 |
attachmentsViewer.addOpenListener(new IOpenListener() { |
| 138 |
public void open(OpenEvent event) { |
183 |
public void open(OpenEvent event) { |
| 139 |
if (!event.getSelection().isEmpty()) { |
184 |
if (!event.getSelection().isEmpty()) { |
|
Lines 236-242
Link Here
|
| 236 |
super.dispose(); |
281 |
super.dispose(); |
| 237 |
} |
282 |
} |
| 238 |
|
283 |
|
|
|
284 |
private static void readState() { |
| 285 |
IPath stateLocation = Platform.getStateLocation(TasksUiPlugin.getDefault().getBundle()); |
| 286 |
File attachmentStateFile = stateLocation.append("TaskEditorAttachment.obj").toFile(); //$NON-NLS-1$ |
| 287 |
boolean columnStdWidth = TasksUiPlugin.getDefault().getPreferenceStore().getBoolean( |
| 288 |
ITasksUiPreferenceConstants.ATTACHMENT_COLUMN_STD_WIDTH); |
| 289 |
|
| 290 |
if (!attachmentStateFile.exists() || columnStdWidth) { |
| 291 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Id, 70)); |
| 292 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Name, 130)); |
| 293 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Description, 150)); |
| 294 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Size, 70)); |
| 295 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Creator, 100)); |
| 296 |
columnInfos.add(new ColumnState(Messages.TaskEditorAttachmentPart_Created, 100)); |
| 297 |
} else { |
| 298 |
ObjectInputStream in = null; |
| 299 |
try { |
| 300 |
in = new ObjectInputStream(new FileInputStream(attachmentStateFile)); |
| 301 |
int size = in.readInt(); |
| 302 |
for (int i = 0; i < size; i++) { |
| 303 |
columnInfos.add((ColumnState) in.readObject()); |
| 304 |
} |
| 305 |
} catch (Throwable e) { |
| 306 |
StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN, |
| 307 |
"The TaskEditorAttachment cache could not be read", e)); |
| 308 |
} finally { |
| 309 |
if (in != null) { |
| 310 |
try { |
| 311 |
in.close(); |
| 312 |
} catch (IOException e) { |
| 313 |
// ignore |
| 314 |
} |
| 315 |
} |
| 316 |
} |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
private static void writeState() { |
| 321 |
IPath stateLocation = Platform.getStateLocation(TasksUiPlugin.getDefault().getBundle()); |
| 322 |
File attachmentStateFile = stateLocation.append("TaskEditorAttachment.obj").toFile(); //$NON-NLS-1$ |
| 323 |
|
| 324 |
if (attachmentStateFile == null) { |
| 325 |
return; |
| 326 |
} |
| 327 |
ObjectOutputStream out = null; |
| 328 |
try { |
| 329 |
out = new ObjectOutputStream(new FileOutputStream(attachmentStateFile)); |
| 330 |
out.writeInt(columnInfos.size()); |
| 331 |
for (ColumnState col : columnInfos) { |
| 332 |
out.writeObject(col); |
| 333 |
} |
| 334 |
} catch (IOException e) { |
| 335 |
StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN, |
| 336 |
"The TaskEditorAttachment cache could not be written", e)); |
| 337 |
} finally { |
| 338 |
if (out != null) { |
| 339 |
try { |
| 340 |
out.close(); |
| 341 |
} catch (IOException e) { |
| 342 |
// ignore |
| 343 |
} |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
} |
| 348 |
|
| 239 |
private void initialize() { |
349 |
private void initialize() { |
|
|
350 |
if (!propertyListenerIstalled) { |
| 351 |
TasksUiPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER); |
| 352 |
propertyListenerIstalled = true; |
| 353 |
} |
| 354 |
if (columnInfos.size() == 0) { |
| 355 |
readState(); |
| 356 |
} |
| 240 |
attachments = getTaskData().getAttributeMapper().getAttributesByType(getTaskData(), |
357 |
attachments = getTaskData().getAttributeMapper().getAttributesByType(getTaskData(), |
| 241 |
TaskAttribute.TYPE_ATTACHMENT); |
358 |
TaskAttribute.TYPE_ATTACHMENT); |
| 242 |
for (TaskAttribute attachmentAttribute : attachments) { |
359 |
for (TaskAttribute attachmentAttribute : attachments) { |