|
Lines 11-24
Link Here
|
| 11 |
|
11 |
|
| 12 |
package org.eclipse.mylyn.internal.context.ui.wizards; |
12 |
package org.eclipse.mylyn.internal.context.ui.wizards; |
| 13 |
|
13 |
|
| 14 |
import com.ibm.icu.text.DateFormat; |
|
|
| 15 |
import java.util.Collections; |
14 |
import java.util.Collections; |
| 16 |
import java.util.Comparator; |
15 |
import java.util.Comparator; |
| 17 |
import java.util.Date; |
16 |
import java.util.Date; |
| 18 |
import java.util.List; |
17 |
import java.util.List; |
| 19 |
|
18 |
|
| 20 |
import org.eclipse.jface.dialogs.Dialog; |
19 |
import org.eclipse.jface.dialogs.Dialog; |
|
|
20 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 21 |
import org.eclipse.jface.layout.GridDataFactory; |
| 21 |
import org.eclipse.jface.wizard.WizardPage; |
22 |
import org.eclipse.jface.wizard.WizardPage; |
|
|
23 |
import org.eclipse.mylyn.context.core.ContextCore; |
| 22 |
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil; |
24 |
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil; |
| 23 |
import org.eclipse.mylyn.tasks.core.IRepositoryPerson; |
25 |
import org.eclipse.mylyn.tasks.core.IRepositoryPerson; |
| 24 |
import org.eclipse.mylyn.tasks.core.ITask; |
26 |
import org.eclipse.mylyn.tasks.core.ITask; |
|
Lines 31-44
Link Here
|
| 31 |
import org.eclipse.swt.events.MouseListener; |
33 |
import org.eclipse.swt.events.MouseListener; |
| 32 |
import org.eclipse.swt.events.SelectionAdapter; |
34 |
import org.eclipse.swt.events.SelectionAdapter; |
| 33 |
import org.eclipse.swt.events.SelectionEvent; |
35 |
import org.eclipse.swt.events.SelectionEvent; |
|
|
36 |
import org.eclipse.swt.graphics.Image; |
| 37 |
import org.eclipse.swt.layout.FillLayout; |
| 34 |
import org.eclipse.swt.layout.GridData; |
38 |
import org.eclipse.swt.layout.GridData; |
| 35 |
import org.eclipse.swt.layout.GridLayout; |
39 |
import org.eclipse.swt.layout.GridLayout; |
| 36 |
import org.eclipse.swt.widgets.Composite; |
40 |
import org.eclipse.swt.widgets.Composite; |
|
|
41 |
import org.eclipse.swt.widgets.Control; |
| 42 |
import org.eclipse.swt.widgets.Label; |
| 43 |
import org.eclipse.swt.widgets.Link; |
| 37 |
import org.eclipse.swt.widgets.Table; |
44 |
import org.eclipse.swt.widgets.Table; |
| 38 |
import org.eclipse.swt.widgets.TableColumn; |
45 |
import org.eclipse.swt.widgets.TableColumn; |
| 39 |
import org.eclipse.swt.widgets.TableItem; |
46 |
import org.eclipse.swt.widgets.TableItem; |
| 40 |
import org.eclipse.swt.widgets.Text; |
47 |
import org.eclipse.swt.widgets.Text; |
| 41 |
|
48 |
|
|
|
49 |
import com.ibm.icu.text.DateFormat; |
| 50 |
|
| 42 |
/** |
51 |
/** |
| 43 |
* @author Rob Elves |
52 |
* @author Rob Elves |
| 44 |
* @author Mik Kersten |
53 |
* @author Mik Kersten |
|
Lines 54-59
Link Here
|
| 54 |
|
63 |
|
| 55 |
private ITaskAttachment selectedContextAttachment; |
64 |
private ITaskAttachment selectedContextAttachment; |
| 56 |
|
65 |
|
|
|
66 |
private List<ITaskAttachment> contextAttachments; |
| 67 |
|
| 68 |
private class TaskAttachmentComparator implements Comparator<ITaskAttachment> { |
| 69 |
public int compare(ITaskAttachment attachment1, ITaskAttachment attachment2) { |
| 70 |
Date created1 = null; |
| 71 |
Date created2 = null; |
| 72 |
created1 = attachment1.getCreationDate(); |
| 73 |
created2 = attachment2.getCreationDate(); |
| 74 |
if (created1 != null && created2 != null) { |
| 75 |
return (-1) * created1.compareTo(created2); |
| 76 |
} else if (created1 == null && created2 != null) { |
| 77 |
return 1; |
| 78 |
} else if (created1 != null && created2 == null) { |
| 79 |
return -1; |
| 80 |
} else { |
| 81 |
return 0; |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 57 |
protected ContextRetrieveWizardPage(TaskRepository repository, ITask task) { |
86 |
protected ContextRetrieveWizardPage(TaskRepository repository, ITask task) { |
| 58 |
super(Messages.ContextRetrieveWizardPage_Select_context); |
87 |
super(Messages.ContextRetrieveWizardPage_Select_context); |
| 59 |
this.repository = repository; |
88 |
this.repository = repository; |
|
Lines 63-74
Link Here
|
| 63 |
} |
92 |
} |
| 64 |
|
93 |
|
| 65 |
public void createControl(Composite parent) { |
94 |
public void createControl(Composite parent) { |
|
|
95 |
contextAttachments = AttachmentUtil.getContextAttachments(repository, task); |
| 96 |
Collections.sort(contextAttachments, new TaskAttachmentComparator()); |
| 97 |
|
| 98 |
final Composite composite = new Composite(parent, SWT.NONE); |
| 99 |
composite.setLayout(new FillLayout()); |
| 100 |
|
| 101 |
boolean hasLocalContext = ContextCore.getContextManager().hasContext(task.getHandleIdentifier()); |
| 102 |
if (!hasLocalContext && contextAttachments.size() > 0) { |
| 103 |
selectedContextAttachment = contextAttachments.get(0); |
| 104 |
setMessage("Select a context to activate task"); |
| 105 |
createMessageControl(composite, "No local task context exists. Retrieve latest from repository?"); |
| 106 |
} else { |
| 107 |
createTableControl(composite); |
| 108 |
} |
| 109 |
|
| 110 |
setControl(composite); |
| 111 |
Dialog.applyDialogFont(composite); |
| 112 |
} |
| 113 |
|
| 114 |
public void createMessageControl(final Composite parent, String message) { |
| 115 |
final Composite composite = new Composite(parent, SWT.NONE); |
| 116 |
composite.setLayout(new GridLayout(2, false)); |
| 117 |
|
| 118 |
Image image = getShell().getDisplay().getSystemImage(SWT.ICON_QUESTION); |
| 119 |
if (image != null) { |
| 120 |
Label imageLabel = new Label(composite, SWT.NULL); |
| 121 |
image.setBackground(imageLabel.getBackground()); |
| 122 |
imageLabel.setImage(image); |
| 123 |
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING).applyTo(imageLabel); |
| 124 |
} |
| 125 |
// create message |
| 126 |
if (message != null) { |
| 127 |
Label messageLabel = new Label(composite, SWT.WRAP); |
| 128 |
messageLabel.setText(message); |
| 129 |
GridData data = GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).hint( |
| 130 |
convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), SWT.DEFAULT).create(); |
| 131 |
if (image == null) { |
| 132 |
data.horizontalSpan = 2; |
| 133 |
} |
| 134 |
messageLabel.setData(data); |
| 135 |
} |
| 136 |
|
| 137 |
Link hyperlink = new Link(composite, SWT.NONE); |
| 138 |
hyperlink.setText("<a>Select from History</a>"); |
| 139 |
hyperlink.addSelectionListener(new SelectionAdapter() { |
| 140 |
@Override |
| 141 |
public void widgetSelected(SelectionEvent e) { |
| 142 |
Control[] children = parent.getChildren(); |
| 143 |
for (Control control : children) { |
| 144 |
control.dispose(); |
| 145 |
} |
| 146 |
createTableControl(parent); |
| 147 |
getShell().pack(); |
| 148 |
} |
| 149 |
}); |
| 150 |
GridDataFactory.fillDefaults().span(2, 1).indent(0, 15).applyTo(hyperlink); |
| 151 |
} |
| 152 |
|
| 153 |
public Composite createTableControl(Composite parent) { |
| 66 |
Composite composite = new Composite(parent, SWT.NONE); |
154 |
Composite composite = new Composite(parent, SWT.NONE); |
| 67 |
composite.setLayout(new GridLayout(1, false)); |
155 |
composite.setLayout(new GridLayout(1, false)); |
| 68 |
|
156 |
|
| 69 |
Text summary = new Text(composite, SWT.NONE); |
157 |
Text summary = new Text(composite, SWT.WRAP); |
| 70 |
summary.setText(NLS.bind(Messages.ContextRetrieveWizardPage_Task, labelProvider.getText(task))); |
158 |
summary.setText(NLS.bind(Messages.ContextRetrieveWizardPage_Task, labelProvider.getText(task))); |
| 71 |
summary.setEditable(false); |
159 |
summary.setEditable(false); |
|
|
160 |
summary.setBackground(null); |
| 161 |
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).hint( |
| 162 |
convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), SWT.DEFAULT).applyTo( |
| 163 |
summary); |
| 72 |
// new Label(composite, SWT.NONE).setText("Repository: " + |
164 |
// new Label(composite, SWT.NONE).setText("Repository: " + |
| 73 |
// repository.getUrl()); |
165 |
// repository.getUrl()); |
| 74 |
// new Label(composite, SWT.NONE).setText("Select context below:"); |
166 |
// new Label(composite, SWT.NONE).setText("Select context below:"); |
|
Lines 106-134
Link Here
|
| 106 |
|
198 |
|
| 107 |
}); |
199 |
}); |
| 108 |
|
200 |
|
| 109 |
List<ITaskAttachment> contextAttachments = AttachmentUtil.getContextAttachments(repository, task); |
|
|
| 110 |
|
| 111 |
Collections.sort(contextAttachments, new Comparator<ITaskAttachment>() { |
| 112 |
|
| 113 |
public int compare(ITaskAttachment attachment1, ITaskAttachment attachment2) { |
| 114 |
|
| 115 |
Date created1 = null; |
| 116 |
Date created2 = null; |
| 117 |
created1 = attachment1.getCreationDate(); |
| 118 |
created2 = attachment2.getCreationDate(); |
| 119 |
if (created1 != null && created2 != null) { |
| 120 |
return (-1) * created1.compareTo(created2); |
| 121 |
} else if (created1 == null && created2 != null) { |
| 122 |
return 1; |
| 123 |
} else if (created1 != null && created2 == null) { |
| 124 |
return -1; |
| 125 |
} else { |
| 126 |
return 0; |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
}); |
| 131 |
|
| 132 |
TableColumn[] columns = new TableColumn[3]; |
201 |
TableColumn[] columns = new TableColumn[3]; |
| 133 |
columns[0] = new TableColumn(contextTable, SWT.LEFT); |
202 |
columns[0] = new TableColumn(contextTable, SWT.LEFT); |
| 134 |
columns[0].setText(Messages.ContextRetrieveWizardPage_Date); |
203 |
columns[0].setText(Messages.ContextRetrieveWizardPage_Date); |
|
Lines 153-166
Link Here
|
| 153 |
} |
222 |
} |
| 154 |
|
223 |
|
| 155 |
contextTable.setLayoutData(new GridData(GridData.FILL_BOTH)); |
224 |
contextTable.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 156 |
setControl(composite); |
|
|
| 157 |
if (contextAttachments.size() > 0) { |
225 |
if (contextAttachments.size() > 0) { |
| 158 |
contextTable.setSelection(0); |
226 |
contextTable.setSelection(0); |
| 159 |
selectedContextAttachment = contextAttachments.get(0); |
227 |
selectedContextAttachment = contextAttachments.get(0); |
| 160 |
getWizard().getContainer().updateButtons(); |
228 |
getWizard().getContainer().updateButtons(); |
| 161 |
} |
229 |
} |
| 162 |
contextTable.setFocus(); |
230 |
contextTable.setFocus(); |
| 163 |
Dialog.applyDialogFont(composite); |
231 |
return composite; |
| 164 |
} |
232 |
} |
| 165 |
|
233 |
|
| 166 |
public ITaskAttachment getSelectedContext() { |
234 |
public ITaskAttachment getSelectedContext() { |