|
Added
Link Here
|
| 1 |
package org.eclipse.mylar.internal.jira.ui; |
| 2 |
|
| 3 |
import java.text.DateFormat; |
| 4 |
import java.util.HashMap; |
| 5 |
import java.util.Map; |
| 6 |
|
| 7 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 8 |
import org.eclipse.jface.layout.GridDataFactory; |
| 9 |
import org.eclipse.jface.resource.JFaceResources; |
| 10 |
import org.eclipse.jface.wizard.WizardDialog; |
| 11 |
import org.eclipse.mylar.internal.jira.JiraServerFacade; |
| 12 |
import org.eclipse.mylar.internal.jira.JiraTask; |
| 13 |
import org.eclipse.mylar.internal.jira.MylarJiraPlugin; |
| 14 |
import org.eclipse.mylar.internal.tasklist.ui.editors.MylarTaskEditor; |
| 15 |
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryTask; |
| 16 |
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin; |
| 17 |
import org.eclipse.mylar.provisional.tasklist.TaskRepository; |
| 18 |
import org.eclipse.swt.SWT; |
| 19 |
import org.eclipse.swt.custom.CLabel; |
| 20 |
import org.eclipse.swt.custom.ScrolledComposite; |
| 21 |
import org.eclipse.swt.events.ControlAdapter; |
| 22 |
import org.eclipse.swt.events.ControlEvent; |
| 23 |
import org.eclipse.swt.events.ModifyEvent; |
| 24 |
import org.eclipse.swt.events.ModifyListener; |
| 25 |
import org.eclipse.swt.events.SelectionAdapter; |
| 26 |
import org.eclipse.swt.events.SelectionEvent; |
| 27 |
import org.eclipse.swt.graphics.Font; |
| 28 |
import org.eclipse.swt.graphics.Image; |
| 29 |
import org.eclipse.swt.graphics.Point; |
| 30 |
import org.eclipse.swt.layout.FillLayout; |
| 31 |
import org.eclipse.swt.layout.GridData; |
| 32 |
import org.eclipse.swt.layout.GridLayout; |
| 33 |
import org.eclipse.swt.widgets.Composite; |
| 34 |
import org.eclipse.swt.widgets.Control; |
| 35 |
import org.eclipse.swt.widgets.Label; |
| 36 |
import org.eclipse.swt.widgets.Link; |
| 37 |
import org.eclipse.swt.widgets.Text; |
| 38 |
import org.eclipse.ui.IEditorInput; |
| 39 |
import org.eclipse.ui.IEditorSite; |
| 40 |
import org.eclipse.ui.PartInitException; |
| 41 |
import org.eclipse.ui.forms.events.ExpansionAdapter; |
| 42 |
import org.eclipse.ui.forms.events.ExpansionEvent; |
| 43 |
import org.eclipse.ui.forms.events.IExpansionListener; |
| 44 |
import org.eclipse.ui.forms.widgets.ExpandableComposite; |
| 45 |
import org.eclipse.ui.forms.widgets.Form; |
| 46 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
| 47 |
import org.eclipse.ui.forms.widgets.ImageHyperlink; |
| 48 |
import org.eclipse.ui.forms.widgets.ScrolledForm; |
| 49 |
import org.eclipse.ui.forms.widgets.Section; |
| 50 |
import org.eclipse.ui.internal.forms.widgets.FormUtil; |
| 51 |
import org.eclipse.ui.part.EditorPart; |
| 52 |
import org.eclipse.ui.views.contentoutline.IContentOutlinePage; |
| 53 |
import org.tigris.jira.core.model.Comment; |
| 54 |
import org.tigris.jira.core.model.Issue; |
| 55 |
import org.tigris.jira.core.model.Status; |
| 56 |
import org.tigris.jira.core.service.JiraServer; |
| 57 |
|
| 58 |
/** |
| 59 |
* @author Brock Janiczak |
| 60 |
*/ |
| 61 |
public class JiraTaskEditor extends EditorPart { |
| 62 |
|
| 63 |
private static final DateFormat DATE_FORMAT = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); |
| 64 |
|
| 65 |
private JiraIssueEditorInput input; |
| 66 |
private Text comment; |
| 67 |
private boolean isDirty = false; |
| 68 |
private Image commentImage; |
| 69 |
private Font commentFont; |
| 70 |
|
| 71 |
private Map commentToControlMap = new HashMap(); |
| 72 |
|
| 73 |
private JiraServer server; |
| 74 |
private Issue issue; |
| 75 |
|
| 76 |
private ScrolledComposite sc; |
| 77 |
|
| 78 |
private Section commentsSection; |
| 79 |
|
| 80 |
/** |
| 81 |
* |
| 82 |
*/ |
| 83 |
public JiraTaskEditor() { |
| 84 |
// commentImage = MylarJiraPlugin.getImageDescriptor("icons/ctool16/comment.gif").createImage(); |
| 85 |
// commentFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT); |
| 86 |
} |
| 87 |
|
| 88 |
/* (non-Javadoc) |
| 89 |
* @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor) |
| 90 |
*/ |
| 91 |
public void doSave(IProgressMonitor monitor) { |
| 92 |
server.addCommentToIssue(issue, comment.getText()); |
| 93 |
comment.setText(""); |
| 94 |
isDirty = false; |
| 95 |
} |
| 96 |
|
| 97 |
/* (non-Javadoc) |
| 98 |
* @see org.eclipse.ui.part.EditorPart#doSaveAs() |
| 99 |
*/ |
| 100 |
public void doSaveAs() { |
| 101 |
} |
| 102 |
|
| 103 |
/* (non-Javadoc) |
| 104 |
* @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput) |
| 105 |
*/ |
| 106 |
public void init(IEditorSite site, IEditorInput input) throws PartInitException { |
| 107 |
this.input = (JiraIssueEditorInput)input; |
| 108 |
setSite(site); |
| 109 |
setInput(input); |
| 110 |
setPartName(this.input.getName()); |
| 111 |
JiraTask task = this.input.getTask(); |
| 112 |
TaskRepository repository = MylarTaskListPlugin.getRepositoryManager().getRepository(task.getRepositoryKind(), task.getRepositoryUrl()); |
| 113 |
server = JiraServerFacade.getDefault().getJiraServer(repository); |
| 114 |
issue = server.getIssue(task.getKey()); |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
/* (non-Javadoc) |
| 119 |
* @see org.eclipse.ui.part.EditorPart#isDirty() |
| 120 |
*/ |
| 121 |
public boolean isDirty() { |
| 122 |
int charCount = comment.getCharCount(); |
| 123 |
isDirty = charCount > 0; |
| 124 |
return isDirty; |
| 125 |
} |
| 126 |
|
| 127 |
/* (non-Javadoc) |
| 128 |
* @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed() |
| 129 |
*/ |
| 130 |
public boolean isSaveAsAllowed() { |
| 131 |
return false; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
/* (non-Javadoc) |
| 136 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
| 137 |
*/ |
| 138 |
public void createPartControl(Composite parent) { |
| 139 |
FormToolkit toolkit = new FormToolkit(getSite().getShell().getDisplay()); |
| 140 |
|
| 141 |
Form form = toolkit.createForm(parent); |
| 142 |
form.setText(issue.getKey() + ": " + issue.getSummary()); |
| 143 |
|
| 144 |
GridLayout formLayout = new GridLayout(1, true); |
| 145 |
|
| 146 |
final Composite formBody = form.getBody(); |
| 147 |
formBody.setLayout(formLayout); |
| 148 |
|
| 149 |
Section summarySection = toolkit.createSection(formBody, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE); |
| 150 |
summarySection.setText("Summary"); |
| 151 |
summarySection.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); |
| 152 |
|
| 153 |
Composite summary = toolkit.createComposite(summarySection); |
| 154 |
summary.setLayout(new GridLayout(6, false)); |
| 155 |
|
| 156 |
Label lblCreated = toolkit.createLabel(summary, "Created:"); |
| 157 |
lblCreated.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); |
| 158 |
Label created = toolkit.createLabel(summary, DATE_FORMAT.format(issue.getCreated())); |
| 159 |
|
| 160 |
Label lblUpdated = toolkit.createLabel(summary, "Updated:"); |
| 161 |
lblUpdated.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); |
| 162 |
Label updated = toolkit.createLabel(summary, DATE_FORMAT.format(issue.getUpdated())); |
| 163 |
|
| 164 |
if (issue.getDue() != null) { |
| 165 |
Label lblDue= toolkit.createLabel(summary, "Due:"); |
| 166 |
lblDue.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); |
| 167 |
Label due= toolkit.createLabel(summary, DATE_FORMAT.format(issue.getDue())); |
| 168 |
} else { |
| 169 |
Label spacer = toolkit.createLabel(summary, ""); |
| 170 |
spacer.setLayoutData(GridDataFactory.fillDefaults().span(2,1).create()); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
Label lblStatus = toolkit.createLabel(summary, "Status:"); |
| 175 |
lblStatus.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); |
| 176 |
Label status = toolkit.createLabel(summary, issue.getStatus().getName()); |
| 177 |
|
| 178 |
Label lblResolution = toolkit.createLabel(summary, "Resolution:"); |
| 179 |
lblResolution.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); |
| 180 |
if (issue.getResolution() != null) { |
| 181 |
Label resolution = toolkit.createLabel(summary, issue.getResolution().getName()); |
| 182 |
resolution.setToolTipText(issue.getResolution().getDescription()); |
| 183 |
} else { |
| 184 |
Label resolution = toolkit.createLabel(summary, "Unresolved"); |
| 185 |
} |
| 186 |
|
| 187 |
Label lblPriority = toolkit.createLabel(summary, "Priority:"); |
| 188 |
lblPriority.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); |
| 189 |
if (issue.getPriority() != null) { |
| 190 |
Label priority = toolkit.createLabel(summary, issue.getPriority().getName()); |
| 191 |
priority.setToolTipText(issue.getPriority().getDescription()); |
| 192 |
} else { |
| 193 |
Label priority = toolkit.createLabel(summary, "No Priority"); |
| 194 |
} |
| 195 |
|
| 196 |
Label lblReporter = toolkit.createLabel(summary, "Reporter:"); |
| 197 |
lblReporter.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); |
| 198 |
Label reporter = toolkit.createLabel(summary, issue.getReporter()); |
| 199 |
|
| 200 |
Label lblAssignee = toolkit.createLabel(summary, "Assignee"); |
| 201 |
lblAssignee.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); |
| 202 |
Label assignee = toolkit.createLabel(summary, issue.getAssignee()); |
| 203 |
|
| 204 |
// spacer |
| 205 |
Label spacer2 = toolkit.createLabel(summary, ""); |
| 206 |
spacer2.setLayoutData(GridDataFactory.fillDefaults().span(2, 1).create()); |
| 207 |
|
| 208 |
StringBuffer sbComponents = new StringBuffer(); |
| 209 |
if (issue.getComponents().length > 0) { |
| 210 |
for (int i = 0; i < issue.getComponents().length; i++) { |
| 211 |
if (i != 0) { |
| 212 |
sbComponents.append(", "); |
| 213 |
} |
| 214 |
|
| 215 |
sbComponents.append(issue.getComponents()[i].getName()); |
| 216 |
} |
| 217 |
} else { |
| 218 |
sbComponents.append("None"); |
| 219 |
} |
| 220 |
|
| 221 |
Label lblComponents = toolkit.createLabel(summary, "Components"); |
| 222 |
lblComponents.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); |
| 223 |
Label components = toolkit.createLabel(summary, sbComponents.toString()); |
| 224 |
|
| 225 |
|
| 226 |
StringBuffer sbAffectsVersions = new StringBuffer(); |
| 227 |
if (issue.getReportedVersions().length > 0) { |
| 228 |
for (int i = 0; i < issue.getReportedVersions().length; i++) { |
| 229 |
if (i != 0) { |
| 230 |
sbAffectsVersions.append(", "); |
| 231 |
} |
| 232 |
|
| 233 |
sbAffectsVersions.append(issue.getReportedVersions()[i].getName()); |
| 234 |
} |
| 235 |
} else { |
| 236 |
sbAffectsVersions.append("None"); |
| 237 |
} |
| 238 |
|
| 239 |
Label lblAffectsVersion = toolkit.createLabel(summary, "Affects Versions"); |
| 240 |
lblAffectsVersion.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); |
| 241 |
Label affectsVersions = toolkit.createLabel(summary, sbAffectsVersions.toString()); |
| 242 |
|
| 243 |
|
| 244 |
StringBuffer sbFixVersions = new StringBuffer(); |
| 245 |
if (issue.getFixVersions().length > 0) { |
| 246 |
for (int i = 0; i < issue.getFixVersions().length; i++) { |
| 247 |
if (i != 0) { |
| 248 |
sbFixVersions.append(", "); |
| 249 |
} |
| 250 |
|
| 251 |
sbFixVersions.append(issue.getFixVersions()[i].getName()); |
| 252 |
} |
| 253 |
} else { |
| 254 |
sbFixVersions.append("None"); |
| 255 |
} |
| 256 |
|
| 257 |
Label lblFixVersions = toolkit.createLabel(summary, "Fix Versions"); |
| 258 |
lblFixVersions.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); |
| 259 |
Label fixVersions = toolkit.createLabel(summary, sbFixVersions.toString()); |
| 260 |
|
| 261 |
summarySection.setClient(summary); |
| 262 |
|
| 263 |
// created, updated, due (optional) |
| 264 |
|
| 265 |
final Section descriptionSection = toolkit.createSection(formBody, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE); |
| 266 |
descriptionSection.setExpanded(true); |
| 267 |
descriptionSection.setText("Description"); |
| 268 |
final GridData dgd = GridDataFactory.fillDefaults().grab(true, false).create(); |
| 269 |
descriptionSection.setLayoutData(dgd); |
| 270 |
|
| 271 |
Composite c = toolkit.createComposite(descriptionSection); |
| 272 |
GridLayout gl = new GridLayout(1, true); |
| 273 |
gl.marginHeight = 0; |
| 274 |
gl.marginWidth = 0; |
| 275 |
c.setLayout(gl); |
| 276 |
|
| 277 |
Text description = toolkit.createText(c, issue.getDescription(), SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); |
| 278 |
description.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).minSize(200, 80).hint(200, 80).create()); |
| 279 |
|
| 280 |
description.setText(issue.getDescription()); |
| 281 |
description.setEditable(false); |
| 282 |
description.setFont(JFaceResources.getTextFont()); |
| 283 |
descriptionSection.setClient(c); |
| 284 |
|
| 285 |
commentsSection = toolkit.createSection(formBody, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE); |
| 286 |
commentsSection.setExpanded(true); |
| 287 |
ImageHyperlink sortOrder = toolkit.createImageHyperlink(commentsSection, SWT.NONE); |
| 288 |
sortOrder.setText("Direction"); |
| 289 |
|
| 290 |
commentsSection.setTextClient(sortOrder); |
| 291 |
commentsSection.setText("Comments"); |
| 292 |
commentsSection.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); |
| 293 |
|
| 294 |
sc = new ScrolledComposite(commentsSection, SWT.H_SCROLL | SWT.V_SCROLL); |
| 295 |
sc.setExpandHorizontal(true); |
| 296 |
sc.setExpandVertical(true); |
| 297 |
|
| 298 |
sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 299 |
|
| 300 |
final Composite c1 = toolkit.createComposite(sc); |
| 301 |
GridLayout commentsLayout = new GridLayout(1, true); |
| 302 |
commentsLayout.marginWidth = 0; |
| 303 |
commentsLayout.marginHeight = 0; |
| 304 |
|
| 305 |
c1.setLayout(commentsLayout); |
| 306 |
|
| 307 |
for (int i = 0; i < issue.getComments().length; i++) { |
| 308 |
Comment comment = issue.getComments()[i]; |
| 309 |
|
| 310 |
ExpandableComposite expandableComposite = toolkit.createExpandableComposite(c1, ExpandableComposite.TREE_NODE); |
| 311 |
expandableComposite.setText("Comment by " + comment.getAuthor() + " [" + DATE_FORMAT.format(comment.getCreated()) + "]"); |
| 312 |
expandableComposite.setLayout(new FillLayout(SWT.HORIZONTAL)); |
| 313 |
expandableComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); |
| 314 |
|
| 315 |
Text t = toolkit.createText(expandableComposite, comment.getComment(), SWT.MULTI | SWT.WRAP); |
| 316 |
t.setEditable(false); |
| 317 |
t.setFont(JFaceResources.getTextFont()); |
| 318 |
|
| 319 |
expandableComposite.setClient(t); |
| 320 |
expandableComposite.addExpansionListener(new ExpansionAdapter() { |
| 321 |
|
| 322 |
@Override |
| 323 |
public void expansionStateChanged(ExpansionEvent e) { |
| 324 |
sc.layout(true, true); |
| 325 |
} |
| 326 |
|
| 327 |
}); |
| 328 |
commentToControlMap.put(comment, expandableComposite); |
| 329 |
|
| 330 |
t.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); |
| 331 |
|
| 332 |
if (i == issue.getComments().length - 1) { |
| 333 |
expandableComposite.setExpanded(true); |
| 334 |
} |
| 335 |
|
| 336 |
} |
| 337 |
|
| 338 |
commentsSection.setClient(sc); |
| 339 |
|
| 340 |
sc.addControlListener(new ControlAdapter() { |
| 341 |
|
| 342 |
public void controlResized(ControlEvent e) { |
| 343 |
Point size = c1.computeSize(sc.getClientArea().width, SWT.DEFAULT); |
| 344 |
sc.setMinSize(size); |
| 345 |
} |
| 346 |
|
| 347 |
}); |
| 348 |
|
| 349 |
final Section commentSection = toolkit.createSection(formBody, ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); |
| 350 |
commentSection.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); |
| 351 |
commentSection.setText("Add Comment"); |
| 352 |
commentSection.setExpanded(false); |
| 353 |
commentSection.addExpansionListener(new ExpansionAdapter() { |
| 354 |
|
| 355 |
public void expansionStateChanged(ExpansionEvent e) { |
| 356 |
formBody.layout(true); |
| 357 |
} |
| 358 |
}); |
| 359 |
|
| 360 |
final Composite commentArea = toolkit.createComposite(commentSection); |
| 361 |
GridLayout commentAreaLayout = new GridLayout(1, false); |
| 362 |
commentAreaLayout.marginHeight = 0; |
| 363 |
commentAreaLayout.marginWidth = 0; |
| 364 |
commentAreaLayout.verticalSpacing = 0; |
| 365 |
commentAreaLayout.horizontalSpacing = 0; |
| 366 |
commentArea.setLayout(commentAreaLayout); |
| 367 |
|
| 368 |
commentSection.setClient(commentArea); |
| 369 |
|
| 370 |
comment = new Text(commentArea, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); |
| 371 |
comment.setFont(JFaceResources.getTextFont()); |
| 372 |
final GridData commentGd = new GridData(SWT.FILL, SWT.FILL, true, false); |
| 373 |
commentGd.heightHint = 80; |
| 374 |
comment.setLayoutData(commentGd); |
| 375 |
|
| 376 |
comment.addModifyListener(new ModifyListener() { |
| 377 |
|
| 378 |
public void modifyText(ModifyEvent e) { |
| 379 |
int charCount = comment.getCharCount(); |
| 380 |
if ((isDirty && charCount == 0) || (!isDirty && charCount > 0)) { |
| 381 |
firePropertyChange(PROP_DIRTY); |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
}); |
| 386 |
sc.setContent(c1); |
| 387 |
sc.setMinSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT)); |
| 388 |
} |
| 389 |
|
| 390 |
public void revealComment(Comment comment) { |
| 391 |
Control control = (Control) this.commentToControlMap.get(comment); |
| 392 |
if (control != null) { |
| 393 |
commentsSection.setExpanded(true); |
| 394 |
((ExpandableComposite)control).setExpanded(true); |
| 395 |
// XXX Clone or create a new version of this |
| 396 |
FormUtil.ensureVisible(sc, control); |
| 397 |
sc.layout(true, true); |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
/* (non-Javadoc) |
| 402 |
* @see org.eclipse.ui.part.WorkbenchPart#setFocus() |
| 403 |
*/ |
| 404 |
public void setFocus() { |
| 405 |
} |
| 406 |
|
| 407 |
/* (non-Javadoc) |
| 408 |
* @see org.eclipse.ui.part.WorkbenchPart#dispose() |
| 409 |
*/ |
| 410 |
public void dispose() { |
| 411 |
super.dispose(); |
| 412 |
// commentImage.dispose(); |
| 413 |
|
| 414 |
// Don't dispose JFace resources |
| 415 |
// commentFont.dispose(); |
| 416 |
} |
| 417 |
|
| 418 |
/* (non-Javadoc) |
| 419 |
* @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class) |
| 420 |
*/ |
| 421 |
public Object getAdapter(Class adapter) { |
| 422 |
if (IContentOutlinePage.class.equals(adapter)) { |
| 423 |
return new JiraIssueContentOutlinePage(this, this.issue); |
| 424 |
} |
| 425 |
|
| 426 |
return super.getAdapter(adapter); |
| 427 |
} |
| 428 |
|
| 429 |
} |