|
Lines 18-63
Link Here
|
| 18 |
|
18 |
|
| 19 |
package com.itsolut.mantis.ui.editor; |
19 |
package com.itsolut.mantis.ui.editor; |
| 20 |
|
20 |
|
| 21 |
import java.lang.reflect.InvocationTargetException; |
|
|
| 22 |
|
| 23 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 24 |
import org.eclipse.core.runtime.IStatus; |
| 25 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 26 |
import org.eclipse.core.runtime.Status; |
| 27 |
import org.eclipse.core.runtime.jobs.IJobChangeEvent; |
| 28 |
import org.eclipse.core.runtime.jobs.Job; |
| 29 |
import org.eclipse.core.runtime.jobs.JobChangeAdapter; |
| 30 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
| 31 |
import org.eclipse.jface.text.TextViewer; |
21 |
import org.eclipse.jface.text.TextViewer; |
| 32 |
import org.eclipse.mylar.context.core.MylarStatusHandler; |
|
|
| 33 |
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; |
| 34 |
import org.eclipse.mylar.tasks.ui.TasksUiPlugin; |
| 35 |
import org.eclipse.mylar.tasks.ui.editors.AbstractRepositoryTaskEditor; |
22 |
import org.eclipse.mylar.tasks.ui.editors.AbstractRepositoryTaskEditor; |
| 36 |
import org.eclipse.mylar.tasks.ui.editors.AbstractTaskEditorInput; |
|
|
| 37 |
import org.eclipse.mylar.tasks.ui.editors.RepositoryTaskEditorInput; |
| 38 |
import org.eclipse.mylar.tasks.ui.editors.RepositoryTaskOutlineNode; |
| 39 |
import org.eclipse.swt.SWT; |
23 |
import org.eclipse.swt.SWT; |
| 40 |
import org.eclipse.swt.events.ModifyEvent; |
24 |
import org.eclipse.swt.events.ModifyEvent; |
| 41 |
import org.eclipse.swt.events.ModifyListener; |
25 |
import org.eclipse.swt.events.ModifyListener; |
| 42 |
import org.eclipse.swt.layout.GridData; |
26 |
import org.eclipse.swt.layout.GridData; |
| 43 |
import org.eclipse.swt.layout.GridLayout; |
27 |
import org.eclipse.swt.layout.GridLayout; |
| 44 |
import org.eclipse.swt.widgets.Composite; |
28 |
import org.eclipse.swt.widgets.Composite; |
| 45 |
import org.eclipse.ui.IEditorInput; |
|
|
| 46 |
import org.eclipse.ui.IEditorSite; |
| 47 |
import org.eclipse.ui.PlatformUI; |
| 48 |
import org.eclipse.ui.forms.editor.FormEditor; |
29 |
import org.eclipse.ui.forms.editor.FormEditor; |
| 49 |
import org.eclipse.ui.forms.widgets.ExpandableComposite; |
|
|
| 50 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
30 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
| 51 |
import org.eclipse.ui.forms.widgets.Section; |
31 |
import org.eclipse.ui.forms.widgets.Section; |
| 52 |
import org.eclipse.ui.progress.IProgressService; |
|
|
| 53 |
|
32 |
|
| 54 |
import com.itsolut.mantis.core.IMantisClient; |
|
|
| 55 |
import com.itsolut.mantis.core.MantisCorePlugin; |
| 56 |
import com.itsolut.mantis.core.MantisRepositoryConnector; |
| 57 |
import com.itsolut.mantis.core.MantisAttributeFactory.Attribute; |
33 |
import com.itsolut.mantis.core.MantisAttributeFactory.Attribute; |
| 58 |
import com.itsolut.mantis.core.exception.InvalidTicketException; |
|
|
| 59 |
import com.itsolut.mantis.core.model.MantisTicket; |
| 60 |
import com.itsolut.mantis.ui.MantisUIPlugin; |
| 61 |
|
34 |
|
| 62 |
/** |
35 |
/** |
| 63 |
* @author Steffen Pingel |
36 |
* @author Steffen Pingel |
|
Lines 65-72
Link Here
|
| 65 |
*/ |
38 |
*/ |
| 66 |
public class MantisTaskEditor extends AbstractRepositoryTaskEditor { |
39 |
public class MantisTaskEditor extends AbstractRepositoryTaskEditor { |
| 67 |
|
40 |
|
| 68 |
private static final String SUBMIT_JOB_LABEL = "Submitting to Mantis Repository"; |
|
|
| 69 |
|
| 70 |
protected static final String LABEL_SECTION_STEPS = "Steps To Reproduce"; |
41 |
protected static final String LABEL_SECTION_STEPS = "Steps To Reproduce"; |
| 71 |
protected TextViewer stepsToReproduceViewer; |
42 |
protected TextViewer stepsToReproduceViewer; |
| 72 |
|
43 |
|
|
Lines 78-205
Link Here
|
| 78 |
} |
49 |
} |
| 79 |
|
50 |
|
| 80 |
@Override |
51 |
@Override |
| 81 |
public void init(IEditorSite site, IEditorInput input) { |
|
|
| 82 |
if (!(input instanceof RepositoryTaskEditorInput)) |
| 83 |
return; |
| 84 |
|
| 85 |
editorInput = (AbstractTaskEditorInput) input; |
| 86 |
repository = editorInput.getRepository(); |
| 87 |
connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector( |
| 88 |
repository.getKind()); |
| 89 |
|
| 90 |
setSite(site); |
| 91 |
setInput(input); |
| 92 |
|
| 93 |
taskOutlineModel = RepositoryTaskOutlineNode.parseBugReport(editorInput.getTaskData()); |
| 94 |
|
| 95 |
isDirty = false; |
| 96 |
updateEditorTitle(); |
| 97 |
} |
| 98 |
|
| 99 |
@Override |
| 100 |
public void submitToRepository() { |
| 101 |
if (isDirty()) { |
| 102 |
this.doSave(new NullProgressMonitor()); |
| 103 |
} |
| 104 |
updateTask(); |
| 105 |
submitButton.setEnabled(false); |
| 106 |
showBusy(true); |
| 107 |
|
| 108 |
final MantisTicket ticket; |
| 109 |
try { |
| 110 |
ticket = MantisRepositoryConnector.getMantisTicket(repository, getRepositoryTaskData()); |
| 111 |
} catch (InvalidTicketException e) { |
| 112 |
MantisUIPlugin.handleMantisException(e); |
| 113 |
return; |
| 114 |
} |
| 115 |
final String comment = getNewCommentText(); |
| 116 |
final AbstractRepositoryTask task = (AbstractRepositoryTask) TasksUiPlugin.getTaskListManager().getTaskList() |
| 117 |
.getTask(AbstractRepositoryTask.getHandle(repository.getUrl(), getRepositoryTaskData().getId())); |
| 118 |
final boolean attachContext = getAttachContext(); |
| 119 |
|
| 120 |
JobChangeAdapter listener = new JobChangeAdapter() { |
| 121 |
@Override |
| 122 |
public void done(final IJobChangeEvent event) { |
| 123 |
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { |
| 124 |
public void run() { |
| 125 |
if (event.getJob().getResult().isOK()) { |
| 126 |
if (attachContext) { |
| 127 |
attachContext(); |
| 128 |
} |
| 129 |
close(); |
| 130 |
} |
| 131 |
} |
| 132 |
}); |
| 133 |
} |
| 134 |
}; |
| 135 |
|
| 136 |
Job submitJob = new Job(SUBMIT_JOB_LABEL) { |
| 137 |
|
| 138 |
@Override |
| 139 |
protected IStatus run(IProgressMonitor monitor) { |
| 140 |
try { |
| 141 |
IMantisClient server = ((MantisRepositoryConnector) connector).getClientManager().getRepository(repository); |
| 142 |
server.updateTicket(ticket, comment); |
| 143 |
if (task != null) { |
| 144 |
// XXX: HACK TO AVOID OVERWRITE WARNING |
| 145 |
task.setTaskData(null); |
| 146 |
TasksUiPlugin.getSynchronizationManager().synchronize(connector, task, true, null); |
| 147 |
} |
| 148 |
return Status.OK_STATUS; |
| 149 |
} catch (final Exception e) { |
| 150 |
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { |
| 151 |
public void run() { |
| 152 |
if (!isDisposed() && !submitButton.isDisposed()) { |
| 153 |
MantisUIPlugin.handleMantisException(e); |
| 154 |
// MantisUiPlugin.handleMantisException(event.getResult()); |
| 155 |
submitButton.setEnabled(true); |
| 156 |
MantisTaskEditor.this.showBusy(false); |
| 157 |
} |
| 158 |
} |
| 159 |
}); |
| 160 |
return Status.CANCEL_STATUS; |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
}; |
| 165 |
|
| 166 |
submitJob.addJobChangeListener(listener); |
| 167 |
submitJob.schedule(); |
| 168 |
|
| 169 |
} |
| 170 |
|
| 171 |
@Override |
| 172 |
protected void validateInput() { |
52 |
protected void validateInput() { |
| 173 |
} |
53 |
} |
| 174 |
|
54 |
|
| 175 |
private void attachContext() { |
|
|
| 176 |
String handle = AbstractRepositoryTask.getHandle(repository.getUrl(), getRepositoryTaskData().getId()); |
| 177 |
final AbstractRepositoryTask modifiedTask = (AbstractRepositoryTask) TasksUiPlugin.getTaskListManager() |
| 178 |
.getTaskList().getTask(handle); |
| 179 |
|
| 180 |
IProgressService ps = PlatformUI.getWorkbench().getProgressService(); |
| 181 |
try { |
| 182 |
ps.busyCursorWhile(new IRunnableWithProgress() { |
| 183 |
public void run(IProgressMonitor pm) { |
| 184 |
try { |
| 185 |
connector.attachContext(repository, modifiedTask, ""); |
| 186 |
} catch (Exception e) { |
| 187 |
MylarStatusHandler.fail(e, "Failed to attach task context.\n\n" + e.getMessage(), true); |
| 188 |
} |
| 189 |
} |
| 190 |
}); |
| 191 |
} catch (InvocationTargetException e) { |
| 192 |
MylarStatusHandler.fail(e.getCause(), "Failed to attach task context.\n\n" + e.getMessage(), true); |
| 193 |
} catch (InterruptedException ignore) { |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
@Override |
55 |
@Override |
| 198 |
protected String getPluginId() { |
|
|
| 199 |
return MantisUIPlugin.PLUGIN_ID; |
| 200 |
} |
| 201 |
|
| 202 |
@Override |
| 203 |
protected void createAttachmentLayout(Composite composite) { |
56 |
protected void createAttachmentLayout(Composite composite) { |
| 204 |
FormToolkit toolkit = this.getManagedForm().getToolkit(); |
57 |
FormToolkit toolkit = this.getManagedForm().getToolkit(); |
| 205 |
Section section = createSection(composite, LABEL_SECTION_STEPS); |
58 |
Section section = createSection(composite, LABEL_SECTION_STEPS); |
|
Lines 215-221
Link Here
|
| 215 |
section.setClient(stepsToReproduceComposite); |
68 |
section.setClient(stepsToReproduceComposite); |
| 216 |
|
69 |
|
| 217 |
stepsToReproduceViewer = addTextEditor(repository, stepsToReproduceComposite, |
70 |
stepsToReproduceViewer = addTextEditor(repository, stepsToReproduceComposite, |
| 218 |
getRepositoryTaskData().getAttributeValue(Attribute.STEPS_TO_REPRODUCE.getMantisKey()), true, SWT.FLAT | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); |
71 |
taskData.getAttributeValue(Attribute.STEPS_TO_REPRODUCE.getMantisKey()), true, SWT.FLAT | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); |
| 219 |
stepsToReproduceViewer.setEditable(true); |
72 |
stepsToReproduceViewer.setEditable(true); |
| 220 |
|
73 |
|
| 221 |
GridData descriptionTextData = new GridData(GridData.FILL_BOTH); |
74 |
GridData descriptionTextData = new GridData(GridData.FILL_BOTH); |
|
Lines 224-232
Link Here
|
| 224 |
stepsToReproduceViewer.getTextWidget().addModifyListener(new ModifyListener() { |
77 |
stepsToReproduceViewer.getTextWidget().addModifyListener(new ModifyListener() { |
| 225 |
public void modifyText(ModifyEvent e) { |
78 |
public void modifyText(ModifyEvent e) { |
| 226 |
String changed = stepsToReproduceViewer.getTextWidget().getText(); |
79 |
String changed = stepsToReproduceViewer.getTextWidget().getText(); |
| 227 |
String original = getRepositoryTaskData().getAttributeValue(Attribute.STEPS_TO_REPRODUCE.getMantisKey()); |
80 |
String original = taskData.getAttributeValue(Attribute.STEPS_TO_REPRODUCE.getMantisKey()); |
| 228 |
if (original==null || !(original.equals(changed))) { |
81 |
if (original==null || !(original.equals(changed))) { |
| 229 |
getRepositoryTaskData().getAttribute(Attribute.STEPS_TO_REPRODUCE.getMantisKey()).setValue(changed); |
82 |
taskData.getAttribute(Attribute.STEPS_TO_REPRODUCE.getMantisKey()).setValue(changed); |
| 230 |
markDirty(true); |
83 |
markDirty(true); |
| 231 |
} |
84 |
} |
| 232 |
validateInput(); |
85 |
validateInput(); |
|
Lines 249-255
Link Here
|
| 249 |
sectionAddtional.setClient(additionalComposite); |
102 |
sectionAddtional.setClient(additionalComposite); |
| 250 |
|
103 |
|
| 251 |
additionalViewer = addTextEditor(repository, additionalComposite, |
104 |
additionalViewer = addTextEditor(repository, additionalComposite, |
| 252 |
getRepositoryTaskData().getAttributeValue(Attribute.ADDITIONAL_INFO.getMantisKey()), true, SWT.FLAT | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); |
105 |
taskData.getAttributeValue(Attribute.ADDITIONAL_INFO.getMantisKey()), true, SWT.FLAT | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); |
| 253 |
additionalViewer.setEditable(true); |
106 |
additionalViewer.setEditable(true); |
| 254 |
|
107 |
|
| 255 |
GridData additionalTextData = new GridData(GridData.FILL_BOTH); |
108 |
GridData additionalTextData = new GridData(GridData.FILL_BOTH); |
|
Lines 258-266
Link Here
|
| 258 |
additionalViewer.getTextWidget().addModifyListener(new ModifyListener() { |
111 |
additionalViewer.getTextWidget().addModifyListener(new ModifyListener() { |
| 259 |
public void modifyText(ModifyEvent e) { |
112 |
public void modifyText(ModifyEvent e) { |
| 260 |
String changed = additionalViewer.getTextWidget().getText(); |
113 |
String changed = additionalViewer.getTextWidget().getText(); |
| 261 |
String original = getRepositoryTaskData().getAttributeValue(Attribute.ADDITIONAL_INFO.getMantisKey()); |
114 |
String original = taskData.getAttributeValue(Attribute.ADDITIONAL_INFO.getMantisKey()); |
| 262 |
if (original==null || !(original.equals(changed))) { |
115 |
if (original==null || !(original.equals(changed))) { |
| 263 |
getRepositoryTaskData().getAttribute(Attribute.ADDITIONAL_INFO.getMantisKey()).setValue(changed); |
116 |
taskData.getAttribute(Attribute.ADDITIONAL_INFO.getMantisKey()).setValue(changed); |
| 264 |
markDirty(true); |
117 |
markDirty(true); |
| 265 |
} |
118 |
} |
| 266 |
validateInput(); |
119 |
validateInput(); |
|
Lines 272-275
Link Here
|
| 272 |
|
125 |
|
| 273 |
super.createAttachmentLayout(composite); |
126 |
super.createAttachmentLayout(composite); |
| 274 |
} |
127 |
} |
|
|
128 |
|
| 129 |
@Override |
| 130 |
protected void addCCList(Composite attributesComposite) { |
| 131 |
// TODO Auto-generated method stub |
| 132 |
//super.addCCList(attributesComposite); |
| 133 |
} |
| 134 |
|
| 135 |
@Override |
| 136 |
protected void addSelfToCC(Composite composite) { |
| 137 |
// TODO Auto-generated method stub |
| 138 |
//super.addSelfToCC(composite); |
| 139 |
} |
| 275 |
} |
140 |
} |