Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8760290c6c6fe7d4a4a9be2630f6315d44293e01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*******************************************************************************
 * Copyright (c) 2004 - 2005 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
/*
 * Created on 31-Jan-2005
 */
package org.eclipse.mylar.bugzilla.ui.tasklist;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.mylar.bugzilla.core.BugReport;
import org.eclipse.mylar.bugzilla.core.IBugzillaAttributeListener;
import org.eclipse.mylar.bugzilla.ui.BugzillaImages;
import org.eclipse.mylar.bugzilla.ui.editor.AbstractBugEditor;
import org.eclipse.mylar.bugzilla.ui.editor.ExistingBugEditor;
import org.eclipse.mylar.tasklist.TaskListImages;
import org.eclipse.mylar.tasklist.ui.TaskEditor;
import org.eclipse.mylar.tasklist.ui.TaskEditorInput;
import org.eclipse.mylar.tasklist.ui.views.TaskListView;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.internal.Workbench;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;

/**
 * @author Eric Booth
 */
public class BugzillaTaskEditor extends TaskEditor {

	/** The task that created this editor */
	protected BugzillaTask bugTask;
	
	/** This bug report can be modified by the user and saved offline. */
	protected BugReport offlineBug;
	
	private ExistingBugEditor bugzillaEditor;

	private BugzillaTaskEditorInput bugzillaEditorInput;
	
//    private TaskSummaryEditor taskSummaryEditor = new TaskSummaryEditor();
    
	protected IContentOutlinePage outlinePage = null;
	
	private IBugzillaAttributeListener ATTRIBUTE_LISTENER = new IBugzillaAttributeListener() {
		public void attributeChanged(String attribute, String value) {
			if (attribute.equals("Priority")) {
				bugTask.setPriority(value);
				if (TaskListView.getDefault() != null) TaskListView.getDefault().notifyTaskDataChanged(bugTask);
			}
		}
    };    

    
	public BugzillaTaskEditor() {
		super();

		// get the workbench page and add a listener so we can detect when it closes
//		IWorkbench wb = MylarTasklistPlugin.getDefault().getWorkbench();
//		IWorkbenchWindow aw = wb.getActiveWorkbenchWindow();
//		IWorkbenchPage ap = aw.getActivePage();
//		BugzillaTaskEditorListener listener = new BugzillaTaskEditorListener();
//		ap.addPartListener(listener);
		
		bugzillaEditor = new ExistingBugEditor();
		bugzillaEditor.setParentEditor(this);
		bugzillaEditor.addAttributeListener(ATTRIBUTE_LISTENER);
//        taskSummaryEditor = new TaskSummaryEditor();
//        taskSummaryEditor.setParentEditor(this);
	}

    public AbstractBugEditor getBugzillaEditor(){
        return bugzillaEditor;
    }
    
//    public TaskSummaryEditor getTaskEditor(){
//        return taskSummaryEditor;
//    }
    
    
	public void gotoMarker(IMarker marker) {
		// don't do anything
	}
	
	/**
	 * Creates page 1 of the multi-page editor,
	 * which allows you to change the font used in page 2.
	 */
	private void createBugzillaSubmitPage() {
		bugzillaEditor.createPartControl(getContainer());
		Composite composite = bugzillaEditor.getEditorComposite();
		int index = addPage(composite);
		setPageText(index, "Bugzilla");
	}
    
    
//    private void createSummaryPage() {
//        try{
//            int index = addPage(taskSummaryEditor, new TaskEditorInput(bugTask));
//            setPageText(index, "Summary");         
//        }catch(Exception e){
//        	MylarPlugin.log(e, "summary failed");
//        }
//    }
	
	/**
	 * Creates the pages of the multi-page editor.
	 */
    @Override
	protected void createPages() {	
		createBugzillaSubmitPage();
		super.createPages();
//        createSummaryPage();
	}
	
	/**
	 * Saves the multi-page editor's document.
	 */
    @Override
	public void doSave(IProgressMonitor monitor) {
    	super.doSave(monitor);
//    	if(taskSummaryEditor.isDirty())
//    		taskSummaryEditor.doSave(monitor);
    	if(bugzillaEditor.isDirty())
    		bugzillaEditor.doSave(monitor);
    	
		// TODO save both editors if needed
	}
	
    public boolean isDirty(){
    	return bugzillaEditor.isDirty() || super.isDirty();
    }
	
	public void changeDirtyStatus(boolean newDirtyStatus) {
		firePropertyChange(PROP_DIRTY);
	}
    
	@Override
	public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException {
		if (!(editorInput instanceof BugzillaTaskEditorInput))
			throw new PartInitException("Invalid Input: Must be BugzillaTaskEditorInput");		
		super.init(site, (IEditorInput)new TaskEditorInput(((BugzillaTaskEditorInput)editorInput).getBugTask()));
		bugzillaEditorInput = (BugzillaTaskEditorInput) editorInput;
		bugTask = bugzillaEditorInput.getBugTask();

		offlineBug = bugzillaEditorInput.getOfflineBug();
		
		super.setSite(site);
		super.setInput(editorInput);
		
		try {
			bugzillaEditor.init(this.getEditorSite(), this.getEditorInput());
		}
		catch (Exception e) {
			throw new PartInitException(e.getMessage());
		}
		
		// Set the title on the editor's tab
		this.setPartName("Bug #" + bugzillaEditorInput.getBugId());
		this.setTitleImage(TaskListImages.getImage(BugzillaImages.TASK_BUGZILLA));
	}
	
	@Override
	public boolean isSaveAsAllowed() {
		return false;
	}
	
	/**
	 * Calculates the contents of page 2 when the it is activated.
	 */
	@Override
	protected void pageChange(int newPageIndex) {
		super.pageChange(newPageIndex);
	}
	
	/**
	 * Sets the font related data to be applied to the text in page 2.
	 */
	@Override
	public void setFocus() {
		// The default focus for this editor is the submit page
		bugzillaEditor.setFocus();
	}

	/**
	 * @return Returns the bugTask.
	 */
	public BugzillaTask getBugTask() {
		return bugTask;
	}
	
	/**
	 * @return Returns the offlineBug.
	 */
	public BugReport getOfflineBug() {
		return offlineBug;
	}
	
	/**
	 * Updates the title of the editor to reflect dirty status.
	 * If the bug report has been modified but not saved, then
	 * an indicator will appear in the title.
	 * @param isDirty
	 *            is true when the bug report has been modified but not saved
	 */
	public void showDirtyStatus(boolean isDirty) {
		String prefix = (isDirty) ? "*" : "" ;
		setPartName(prefix + "Bug #" + bugzillaEditorInput.getBugId());
	}
	
//	/**
//	 * Class to listen for editor events
//	 */
//	private class BugzillaTaskEditorListener implements IPartListener
//	{
//
//		public void partActivated(IWorkbenchPart part) {
//			// don't care about this event
//		}
//
//		public void partBroughtToTop(IWorkbenchPart part) {
//			// don't care about this event
//		}
//
//		public void partClosed(IWorkbenchPart part) {
//
//			// if we are closing a bug editor
//			if (part instanceof BugzillaTaskEditor) {
//				BugzillaTaskEditor taskEditor = (BugzillaTaskEditor)part;
//				
//				// check if it needs to be saved
//				if (taskEditor.bugzillaEditor.isDirty) {
//					// ask the user whether they want to save it or not and perform the appropriate action
//					taskEditor.bugzillaEditor.changeDirtyStatus(false);
//					boolean response = MessageDialog.openQuestion(null, "Save Changes", 
//							"You have made some changes to the bug, do you want to save them?");
//					if (response) {
//						taskEditor.bugzillaEditor.saveBug();
//					} else {
//						ExistingBugEditorInput input = (ExistingBugEditorInput)taskEditor.bugzillaEditor.getEditorInput();
//						bugTask.setPriority(input.getBug().getAttribute("Priority").getValue());
//					}
//				}
//			}
//		}
//
//		public void partDeactivated(IWorkbenchPart part) {
//			// don't care about this event
//		}
//
//		public void partOpened(IWorkbenchPart part) {
//			// don't care about this event
//		}
//	}

	public void makeNewPage(BugReport serverBug, String newCommentText) {
		if (serverBug == null) {
			MessageDialog.openInformation(Workbench.getInstance().getActiveWorkbenchWindow().getShell(),
					"Could not open bug.", "Bug #" + offlineBug.getId()
									+ " could not be read from the server.  Try refreshing the bug task.");
			return;
		}
	}

	@Override
	public Object getAdapter(Class adapter) {
		return bugzillaEditor.getAdapter(adapter);
	}
    
    public void close() {
        Display display= getSite().getShell().getDisplay();
        display.asyncExec(new Runnable() {
            public void run() {
                getSite().getPage().closeEditor(BugzillaTaskEditor.this, false);
            }
        });
    }

	@Override
	public void doSaveAs() {
		// do nothing here
	}	
}

Back to the top