Skip to main content
summaryrefslogtreecommitdiffstats
blob: c783107aeeb7c0ac0fa46a5e986b8dcfa960e457 (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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
/*******************************************************************************
 * Copyright (c) 2003 - 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
 *******************************************************************************/
package org.eclipse.mylar.bugzilla.ui.editor;

import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.JFaceColors;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.ListenerList;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.util.SafeRunnable;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylar.bugzilla.core.Attribute;
import org.eclipse.mylar.bugzilla.core.BugPost;
import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.core.BugzillaPreferences;
import org.eclipse.mylar.bugzilla.core.BugzillaRepository;
import org.eclipse.mylar.bugzilla.core.BugzillaTools;
import org.eclipse.mylar.bugzilla.core.Comment;
import org.eclipse.mylar.bugzilla.core.IBugzillaAttributeListener;
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
import org.eclipse.mylar.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.bugzilla.core.IBugzillaReportSelection;
import org.eclipse.mylar.bugzilla.ui.BugzillaUITools;
import org.eclipse.mylar.bugzilla.ui.OfflineView;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaOutlineNode;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaOutlinePage;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaReportSelection;
import org.eclipse.mylar.bugzilla.ui.tasklist.BugzillaTaskEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.RetargetAction;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.internal.WorkbenchImages;
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.internal.help.WorkbenchHelpSystem;
import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages;
import org.eclipse.ui.part.EditorPart;
import org.eclipse.ui.views.contentoutline.ContentOutline;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;


/**
 * Abstract base implementation for an editor to view a bugzilla report.
 */
public abstract class AbstractBugEditor extends EditorPart implements Listener {

	protected Display display;

	public static final  Font TITLE_FONT = JFaceResources.getHeaderFont();
	
	// TODO: don't use hard-coded font
	public static final  Font TEXT_FONT = JFaceResources.getDefaultFont();
	public static final  Font COMMENT_FONT = JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT);
//		new Font(null, "Courier New", 9, SWT.NORMAL);
	
	public static final  Font HEADER_FONT = JFaceResources.getDefaultFont();
	
	public static final int DESCRIPTION_WIDTH = 79 * 7;
	
	public static final int DESCRIPTION_HEIGHT = 10 * 14;
	
	protected Color background;

	protected Color foreground;

	protected AbstractBugEditorInput bugzillaInput;
	
	private BugzillaTaskEditor parentEditor = null;

	/**
	 * Style option for function <code>newLayout</code>. This will create a
	 * plain-styled, selectable text label.
	 */ 
	protected final String VALUE = "VALUE";

	/**
	 * Style option for function <code>newLayout</code>. This will create a
	 * bolded, selectable header. It will also have an arrow image before the
	 * text (simply for decoration).
	 */ 
	protected final String HEADER = "HEADER";

	/**
	 * Style option for function <code>newLayout</code>. This will create a
	 * bolded, unselectable label.
	 */ 
	protected final String PROPERTY = "PROPERTY";

	protected final int HORZ_INDENT = 0;
	
	protected Combo oSCombo;

	protected Combo versionCombo;

	protected Combo platformCombo;

	protected Combo priorityCombo;

	protected Combo severityCombo;

	protected Combo milestoneCombo;

	protected Combo componentCombo;

	protected Text urlText;

	protected Text summaryText;
	
	protected Text assignedTo;

	protected Button submitButton;
	
//	protected Button saveButton;
	
	protected int scrollIncrement;

	protected int scrollVertPageIncrement;

	protected int scrollHorzPageIncrement;
	
	public boolean isDirty = false;
	
	/** Manager controlling the context menu */
	protected MenuManager contextMenuManager;
	
	protected StyledText currentSelectedText;
	
	protected static final String cutActionDefId = "org.eclipse.ui.edit.cut"; //$NON-NLS-1$

	protected static final String copyActionDefId = "org.eclipse.ui.edit.copy"; //$NON-NLS-1$

	protected static final String pasteActionDefId = "org.eclipse.ui.edit.paste"; //$NON-NLS-1$

	protected RetargetAction cutAction;

	protected BugzillaEditorCopyAction copyAction;

	protected RetargetAction pasteAction;
	
	protected Composite editorComposite;

	protected CLabel titleLabel;

	protected ScrolledComposite scrolledComposite;

	protected Composite infoArea;

	protected Hyperlink linkToBug;
	
	protected StyledText generalTitleText;
	
	private List<IBugzillaAttributeListener> attributesListeners = new ArrayList<IBugzillaAttributeListener>();
	
	protected final ISelectionProvider selectionProvider = new ISelectionProvider() {
		public void addSelectionChangedListener(ISelectionChangedListener listener) {
			selectionChangedListeners.add(listener);
		}

		public ISelection getSelection() {
			return null;
		}

		public void removeSelectionChangedListener(ISelectionChangedListener listener) {
			selectionChangedListeners.remove(listener);			
		}

		public void setSelection(ISelection selection) {
			// No implementation.
		}
	};
	
	protected ListenerList selectionChangedListeners = new ListenerList();
	
	protected HashMap<Combo, String> comboListenerMap = new HashMap<Combo, String>();
	
	private IBugzillaReportSelection lastSelected = null;
	
	protected final ISelectionListener selectionListener = new ISelectionListener() {
		public void selectionChanged(IWorkbenchPart part, ISelection selection) {
			if ((part instanceof ContentOutline) && (selection instanceof StructuredSelection)) {
				Object select = ((StructuredSelection)selection).getFirstElement();
	            if(select instanceof BugzillaOutlineNode){
	            	BugzillaOutlineNode n = (BugzillaOutlineNode) select;
	            	
		            if (n != null && lastSelected != null && BugzillaTools.getHandle(n).equals(BugzillaTools.getHandle(lastSelected))){
		            	// we don't need to set the selection if it is alredy set
		            	return;
		            }
		            lastSelected = n;
	            	
	                Object data = n.getData();
                    boolean highlight = true;
                    if(n.getKey().toLowerCase().equals("comments")){
                        highlight = false;
                    }
					if(n.getKey().toLowerCase().equals("new comment")){
                        selectNewComment();  
                    } else if(n.getKey().toLowerCase().equals("new description")){
                        selectNewDescription();
                    } else if (data != null){
                        select(data, highlight);
                    }
	            }
			}
		}
	};

	/**
	 * Creates a new <code>AbstractBugEditor</code>. Sets up the default fonts and
	 * cut/copy/paste actions.
	 */
	public AbstractBugEditor() {
			
			// set the scroll increments so the editor scrolls normally with the scroll wheel
			FontData[] fd = TEXT_FONT.getFontData();
			int cushion = 4;
			scrollIncrement = fd[0].getHeight() + cushion;
			scrollVertPageIncrement = 0;
			scrollHorzPageIncrement = 0;
			
			// set up actions for the context menu
			cutAction = new RetargetAction(ActionFactory.CUT.getId(), WorkbenchMessages.Workbench_cut);
			cutAction.setToolTipText(WorkbenchMessages.Workbench_cutToolTip);//WorkbenchMessages.getString("Workbench.cutToolTip")); //$NON-NLS-1$
			cutAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(
				ISharedImages.IMG_TOOL_CUT));
			cutAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(
				ISharedImages.IMG_TOOL_CUT));
			cutAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(
				ISharedImages.IMG_TOOL_CUT_DISABLED));
			cutAction.setAccelerator(SWT.CTRL | 'x');
			cutAction.setActionDefinitionId(cutActionDefId);
	
			pasteAction = new RetargetAction(ActionFactory.PASTE.getId(), WorkbenchMessages.Workbench_paste);
			pasteAction.setToolTipText(WorkbenchMessages.Workbench_pasteToolTip);//WorkbenchMessages.getString("Workbench.pasteToolTip")); //$NON-NLS-1$
			pasteAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(
				ISharedImages.IMG_TOOL_PASTE));
			pasteAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(
				ISharedImages.IMG_TOOL_PASTE));
			pasteAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(
				ISharedImages.IMG_TOOL_PASTE_DISABLED));
			pasteAction.setAccelerator(SWT.CTRL | 'v');
			pasteAction.setActionDefinitionId(pasteActionDefId);
	
			copyAction = new BugzillaEditorCopyAction(this);
			copyAction.setText(WorkbenchMessages.Workbench_copy);//WorkbenchMessages.getString("Workbench.copy"));
			copyAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(
				ISharedImages.IMG_TOOL_COPY));
			copyAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(
				ISharedImages.IMG_TOOL_COPY));
			copyAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(
				ISharedImages.IMG_TOOL_COPY_DISABLED));
			copyAction.setAccelerator(SWT.CTRL | 'c');
	
			copyAction.setEnabled(false);
		}

	/**
	 * @return The bug this editor is displaying.
	 */
	public abstract IBugzillaBug getBug();
	
	/**
	 * @return Any currently selected text.
	 */
	protected StyledText getCurrentText() {
		return currentSelectedText;
	}

	/**
	 * @return The action used to copy selected text from a bug editor to the clipboard.
	 */
	protected BugzillaEditorCopyAction getCopyAction() {
		return copyAction;
	}

	@Override
	public void createPartControl(Composite parent) {
		editorComposite = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.marginHeight = 0;
		layout.marginWidth = 0;
		layout.verticalSpacing = 0;
		layout.horizontalSpacing = 0;
		editorComposite.setLayout(layout);
		// Create the title for the editor
		createTitleArea(editorComposite);
		Label titleBarSeparator =
			new Label(editorComposite, SWT.HORIZONTAL | SWT.SEPARATOR);
	
		background = JFaceColors.getBannerBackground(display);
		foreground = JFaceColors.getBannerForeground(display);
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
		titleBarSeparator.setLayoutData(gd);
		
		// Put the bug info onto the editor
		createInfoArea(editorComposite);
	
		WorkbenchHelpSystem.getInstance().setHelp(editorComposite, IBugzillaConstants.EDITOR_PAGE_CONTEXT);
		
		infoArea.setMenu(contextMenuManager.createContextMenu(infoArea));
		
		getSite().getPage().addSelectionListener(selectionListener);
		getSite().setSelectionProvider(selectionProvider);
	}

	/**
	 * Creates the title label at the top of the editor.
	 * 
	 * @param parent
	 *            The composite to put the title label into.
	 * @return The title composite.
	 */
	protected Composite createTitleArea(Composite parent) {
		// Get the background color for the title area
		display = parent.getDisplay();
		background = JFaceColors.getBannerBackground(display);
		foreground = JFaceColors.getBannerForeground(display);
		
		// Create the title area which will contain
		// a title, message, and image.
		Composite titleArea = new Composite(parent, SWT.NO_FOCUS);
		GridLayout layout = new GridLayout();
		layout.marginHeight = 0;
		layout.marginWidth = 0;
		layout.verticalSpacing = 0;
		layout.horizontalSpacing = 0;
		layout.numColumns = 2;
		titleArea.setLayout(layout);
		titleArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		titleArea.setBackground(background);
		
		// Message label
		titleLabel = new CLabel(titleArea, SWT.LEFT);
		JFaceColors.setColors(titleLabel, foreground, background);
		titleLabel.setFont(TITLE_FONT);

		final IPropertyChangeListener fontListener = new IPropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent event) {
				if (JFaceResources.HEADER_FONT.equals(event.getProperty())) {
					titleLabel.setFont(TITLE_FONT);
				}
			}
		};
		titleLabel.addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent event) {
				JFaceResources.getFontRegistry().removeListener(fontListener);
			}
		});
		JFaceResources.getFontRegistry().addListener(fontListener);
		GridData gd = new GridData(GridData.FILL_BOTH);
		titleLabel.setLayoutData(gd);
		
		// Title image
		Label titleImage = new Label(titleArea, SWT.LEFT);
		titleImage.setBackground(background);
		titleImage.setImage(
			WorkbenchImages.getImage(
				IDEInternalWorkbenchImages.IMG_OBJS_WELCOME_BANNER));
		gd = new GridData();
		gd.horizontalAlignment = GridData.END;
		titleImage.setLayoutData(gd);
		return titleArea;
	}

	/**
	 * Creates the part of the editor that contains the information about the
	 * the bug.
	 * 
	 * @param parent
	 *            The composite to put the info area into.
	 * @return The info area composite.
	 */
	protected Composite createInfoArea(Composite parent) {

		createContextMenu();
		
		scrolledComposite =
			new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
		scrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
		infoArea = new Composite(this.scrolledComposite, SWT.NONE);
		scrolledComposite.setMinSize(
			infoArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		GridLayout infoLayout = new GridLayout();
		infoLayout.numColumns = 1;
		infoLayout.verticalSpacing = 0;
		infoLayout.horizontalSpacing = 0;
		infoLayout.marginWidth = 0;
		infoArea.setLayout(infoLayout);
		infoArea.setBackground(background);
		if (getBug() == null) {
			MessageDialog.openError(infoArea.getShell(), "No such bug",
					"No bug exists with this id");
			return null;
		}
		createLayouts();

		this.scrolledComposite.setContent(infoArea);
		Point p = infoArea.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
		this.scrolledComposite.setMinHeight(p.y);
		this.scrolledComposite.setMinWidth(p.x);
		this.scrolledComposite.setExpandHorizontal(true);
		this.scrolledComposite.setExpandVertical(true);
		
		// make the editor scroll properly with a scroll editor
		scrolledComposite.addControlListener(new ControlListener() {
			public void controlMoved(ControlEvent e) {
				// don't care when the control moved
			}

			public void controlResized(ControlEvent e) {
				scrolledComposite.getVerticalBar()
						.setIncrement(scrollIncrement);
				scrolledComposite.getHorizontalBar().setIncrement(
						scrollIncrement);
				scrollVertPageIncrement = scrolledComposite.getClientArea().height;
				scrollHorzPageIncrement = scrolledComposite.getClientArea().width;
				scrolledComposite.getVerticalBar().setPageIncrement(
						scrollVertPageIncrement);
				scrolledComposite.getHorizontalBar().setPageIncrement(
						scrollHorzPageIncrement);
			}
		});

		return infoArea;
	}

	/**
	 * Create a context menu for this editor.
	 */
	protected void createContextMenu() {
		contextMenuManager = new MenuManager("#BugEditor");
		contextMenuManager.setRemoveAllWhenShown(true);
		contextMenuManager.addMenuListener(new IMenuListener() {
			public void menuAboutToShow(IMenuManager manager) {
				manager.add(cutAction);
				manager.add(copyAction);
				manager.add(pasteAction);
				manager.add(new Separator());
				manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
				if (currentSelectedText == null || 
					currentSelectedText.getSelectionText().length() == 0) {
				
					copyAction.setEnabled(false);
				}
				else {
					copyAction.setEnabled(true);
				}
			}
		});
		getSite().registerContextMenu("#BugEditor", contextMenuManager,
				getSite().getSelectionProvider());
	}

	/**
	 * Creates all of the layouts that display the information on
	 * the bug.
	 */
	protected void createLayouts() {
		createAttributeLayout();
		createDescriptionLayout();
		createCommentLayout();
		createButtonLayouts();
	}

	/**
	 * Creates the attribute layout, which contains most of the basic attributes
	 * of the bug (some of which are editable).
	 */
	protected void createAttributeLayout() {
		
		String title = getTitleString();
		String keywords = "";
		String url = "";
		
		// Attributes Composite- this holds all the combo fiels and text 
		// fields
		Composite attributesComposite = new Composite(infoArea, SWT.NONE);
		GridLayout attributesLayout = new GridLayout();
		attributesLayout.numColumns = 4;
		attributesLayout.horizontalSpacing = 14;
		attributesLayout.verticalSpacing = 6;
		attributesComposite.setLayout(attributesLayout);
		GridData attributesData = new GridData(GridData.FILL_BOTH);
		attributesData.horizontalSpan = 1;
		attributesData.grabExcessVerticalSpace = false;
		attributesComposite.setLayoutData(attributesData);
		attributesComposite.setBackground(background);
		// End Attributes Composite
		
		// Attributes Title Area
		Composite attributesTitleComposite =
			new Composite(attributesComposite, SWT.NONE);
		GridLayout attributesTitleLayout = new GridLayout();
		attributesTitleLayout.horizontalSpacing = 0;
		attributesTitleLayout.marginWidth = 0;
		attributesTitleComposite.setLayout(attributesTitleLayout);
		attributesTitleComposite.setBackground(background);
		GridData attributesTitleData =
			new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		attributesTitleData.horizontalSpan = 4;
		attributesTitleData.grabExcessVerticalSpace = false;
		attributesTitleComposite.setLayoutData(attributesTitleData);
		// End Attributes Title
		
		// Set the Attributes Title
		newAttributesLayout(attributesTitleComposite);
		titleLabel.setText(title);
		bugzillaInput.setToolTipText(title);
		int currentCol = 1;
		
		String ccValue = null;
		
		//	Populate Attributes
		for (Iterator<Attribute> it = getBug().getAttributes().iterator(); it.hasNext();) {
			Attribute attribute = it.next();
			String key = attribute.getParameterName();
			String name = attribute.getName();
			String value = checkText(attribute.getValue());
			Map<String, String> values = attribute.getOptionValues();
		
			// make sure we don't try to display a hidden field
			if (attribute.isHidden() || (key != null && key.equals("status_whiteboard")))
				continue;

			if (values == null)
				values = new HashMap<String, String>();

			if (key == null)
				key = "";
			
			GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
			data.horizontalSpan = 1;
			data.horizontalIndent = HORZ_INDENT;

			if (key.equals("short_desc") || key.equals("keywords")) {
				keywords = value;
			}
			else if (key.equals("newcc")) {
				ccValue = value;
				if(value == null)
					ccValue = "";
			}
			else if (key.equals("bug_file_loc")) {
				url = value;
			}
			else if (key.equals("op_sys")) {
				newLayout(attributesComposite, 1, name, PROPERTY);
				oSCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND
						| SWT.MULTI | SWT.V_SCROLL | SWT.READ_ONLY);
				oSCombo.setFont(TEXT_FONT);
				oSCombo.setLayoutData(data);
				oSCombo.setBackground(background);
				Set<String> s = values.keySet();
				String[] a = s.toArray(new String[s.size()]);
				Arrays.sort(a);
				for (int i = 0; i < a.length; i++) {
					oSCombo.add(a[i]);
				}
				oSCombo.select(oSCombo.indexOf(value));
				oSCombo.addListener(SWT.Modify, this);
				comboListenerMap.put(oSCombo, name);
				oSCombo.addListener(SWT.FocusIn, new GenericListener());
				currentCol += 2;
			}
			else if (key.equals("version")) {
				newLayout(attributesComposite, 1, name, PROPERTY);

				versionCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND
						| SWT.MULTI | SWT.V_SCROLL | SWT.READ_ONLY);
				versionCombo.setFont(TEXT_FONT);
				versionCombo.setLayoutData(data);
				versionCombo.setBackground(background);
				Set<String> s = values.keySet();
				String[] a = s.toArray(new String[s.size()]);
				Arrays.sort(a);
				for (int i = 0; i < a.length; i++) {
					versionCombo.add(a[i]);
				}
				versionCombo.select(versionCombo.indexOf(value));
				versionCombo.addListener(SWT.Modify, this);
				versionCombo.addListener(SWT.FocusIn, new GenericListener());
				comboListenerMap.put(versionCombo, name);
				currentCol += 2;
			}
			else if (key.equals("priority")) {
				newLayout(attributesComposite, 1, name, PROPERTY);

				priorityCombo = new Combo(attributesComposite,
						SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
								| SWT.READ_ONLY);
				priorityCombo.setFont(TEXT_FONT);
				priorityCombo.setLayoutData(data);
				priorityCombo.setBackground(background);
				Set<String> s = values.keySet();
				String[] a = s.toArray(new String[s.size()]);
				Arrays.sort(a);
				for (int i = 0; i < a.length; i++) {
					priorityCombo.add(a[i]);
				}
				priorityCombo.select(priorityCombo.indexOf(value));
				priorityCombo.addListener(SWT.Modify, this);
				priorityCombo.addListener(SWT.FocusIn, new GenericListener());
				comboListenerMap.put(priorityCombo, name);
				currentCol += 2;
			}
			else if (key.equals("bug_severity")) {
				newLayout(attributesComposite, 1, name, PROPERTY);
				severityCombo =
					new Combo(
						attributesComposite,
						SWT.NO_BACKGROUND
							| SWT.MULTI
							| SWT.V_SCROLL
							| SWT.READ_ONLY);

				severityCombo.setFont(TEXT_FONT);
				severityCombo.setLayoutData(data);
				severityCombo.setBackground(background);
				Set<String> s = values.keySet();
				String[] a = s.toArray(new String[s.size()]);
				Arrays.sort(a);
				for (int i = 0; i < a.length; i++) {
					severityCombo.add(a[i]);
				}
				severityCombo.select(severityCombo.indexOf(value));
				severityCombo.addListener(SWT.Modify, this);
				severityCombo.addListener(SWT.FocusIn, new GenericListener());
				comboListenerMap.put(severityCombo, name);
				currentCol += 2;
			}
			else if (key.equals("target_milestone")) {
				newLayout(attributesComposite, 1, name, PROPERTY);
				milestoneCombo =
					new Combo(
						attributesComposite,
						SWT.NO_BACKGROUND
							| SWT.MULTI
							| SWT.V_SCROLL
							| SWT.READ_ONLY);

				milestoneCombo.setFont(TEXT_FONT);
				milestoneCombo.setLayoutData(data);
				milestoneCombo.setBackground(background);
				Set<String> s = values.keySet();
				String[] a = s.toArray(new String[s.size()]);
				Arrays.sort(a);
				for (int i = 0; i < a.length; i++) {
					milestoneCombo.add(a[i]);
				}
				milestoneCombo.select(milestoneCombo.indexOf(value));
				milestoneCombo.addListener(SWT.Modify, this);
				milestoneCombo.addListener(SWT.FocusIn, new GenericListener());
				comboListenerMap.put(milestoneCombo, name);
				currentCol += 2;
			}
			else if (key.equals("rep_platform")) {
				newLayout(attributesComposite, 1, name, PROPERTY);
				platformCombo =
					new Combo(
						attributesComposite,
						SWT.NO_BACKGROUND
							| SWT.MULTI
							| SWT.V_SCROLL
							| SWT.READ_ONLY);

				platformCombo.setFont(TEXT_FONT);
				platformCombo.setLayoutData(data);
				platformCombo.setBackground(background);
				Set<String> s = values.keySet();
				String[] a = s.toArray(new String[s.size()]);
				Arrays.sort(a);
				for (int i = 0; i < a.length; i++) {
					platformCombo.add(a[i]);
				}
				platformCombo.select(platformCombo.indexOf(value));
				platformCombo.addListener(SWT.Modify, this);
				platformCombo.addListener(SWT.FocusIn, new GenericListener());
				comboListenerMap.put(platformCombo, name);
				currentCol += 2;
			}
			else if (key.equals("product")) {
				newLayout(attributesComposite, 1, name, PROPERTY);
				newLayout(attributesComposite, 1, value, VALUE).addListener(SWT.FocusIn, new GenericListener());
				currentCol += 2;
			} else if(key.equals("assigned_to")){
				newLayout(attributesComposite, 1, name, PROPERTY);
				assignedTo = new Text(attributesComposite, SWT.BORDER | SWT.SINGLE | SWT.WRAP);
				assignedTo.setFont(TEXT_FONT);
				assignedTo.setText(value);
				data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
				data.horizontalSpan = 1;
				assignedTo.setLayoutData(data);

				assignedTo.addListener(SWT.KeyUp, new Listener() {
					public void handleEvent(Event event) {
						String sel = assignedTo.getText();
						Attribute a = getBug().getAttribute("Assign To");
						if (!(a.getNewValue().equals(sel))) {
							a.setNewValue(sel);
							changeDirtyStatus(true);
						}
					}
				});
				assignedTo.addListener(SWT.FocusIn, new GenericListener());
				
				currentCol += 2;
			}
			else if (key.equals("component")) {
				newLayout(attributesComposite, 1, name, PROPERTY);
				componentCombo =
					new Combo(
						attributesComposite,
						SWT.NO_BACKGROUND
							| SWT.MULTI
							| SWT.V_SCROLL
							| SWT.READ_ONLY);

				componentCombo.setFont(TEXT_FONT);
				componentCombo.setLayoutData(data);
				componentCombo.setBackground(background);
				Set<String> s = values.keySet();
				String[] a = s.toArray(new String[s.size()]);
				Arrays.sort(a);
				for (int i = 0; i < a.length; i++) {
					componentCombo.add(a[i]);
				}
				componentCombo.select(componentCombo.indexOf(value));
				componentCombo.addListener(SWT.Modify, this);
				componentCombo.addListener(SWT.FocusIn, new GenericListener());
				comboListenerMap.put(componentCombo, name);
				currentCol += 2;
			}
			else if (name.equals("Summary")) {
				// Don't show the summary here.
				continue;
			}
			else if (values.isEmpty()) {
				newLayout(attributesComposite, 1, name, PROPERTY);
				newLayout(attributesComposite, 1, value, VALUE).addListener(SWT.FocusIn, new GenericListener());
				currentCol += 2;
			}
			if (currentCol > attributesLayout.numColumns) {
				currentCol -= attributesLayout.numColumns;
			}
		}
		// End Populate Attributes
		
		// make sure that we are in the first column
		if (currentCol > 1) {
			while (currentCol <= attributesLayout.numColumns) {
				newLayout(attributesComposite, 1, "", PROPERTY);
				currentCol++;
			}
		}
		
		//  URL, Keywords, Summary Text Fields
		addUrlText(url, attributesComposite);
		
		// keywords text field (not editable)
		addKeywordsList(keywords, attributesComposite);
		if(ccValue != null){
			addCCList(ccValue, attributesComposite);
		}
		addSummaryText(attributesComposite);
		// End URL, Keywords, Summary Text Fields
	}

	/**
	 * Adds a text field to display and edit the bug's URL attribute.
	 * 
	 * @param url
	 *            The URL attribute of the bug.
	 * @param attributesComposite
	 *            The composite to add the text field to.
	 */
	protected void addUrlText(String url, Composite attributesComposite) {
		newLayout(attributesComposite, 1, "URL:", PROPERTY);
		urlText =
			new Text(attributesComposite, SWT.BORDER | SWT.SINGLE | SWT.WRAP);
		urlText.setFont(TEXT_FONT);
		GridData urlTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		urlTextData.horizontalSpan = 3;
		urlTextData.widthHint = 200;
		urlText.setLayoutData(urlTextData);
		urlText.setText(url);
		urlText.addListener(SWT.KeyUp, new Listener() {
			public void handleEvent(Event event) {
				String sel = urlText.getText();
				Attribute a = getBug().getAttribute("URL");
				if (!(a.getNewValue().equals(sel))) {
					a.setNewValue(sel);
					changeDirtyStatus(true);
				}
			}
		});
		urlText.addListener(SWT.FocusIn, new GenericListener());
	}

	/**
	 * Adds a text field and selection list to display and edit the bug's
	 * keywords.
	 * 
	 * @param keywords
	 *            The current list of keywords for this bug.
	 * @param attributesComposite
	 *            The composite to add the widgets to.
	 */
	protected abstract void addKeywordsList(String keywords, Composite attributesComposite);

	protected abstract void addCCList(String value, Composite attributesComposite);
	
	/**
	 * Adds a text field to display and edit the bug's summary.
	 * 
	 * @param attributesComposite
	 *            The composite to add the text field to.
	 */
	protected void addSummaryText(Composite attributesComposite) {
		newLayout(attributesComposite, 1, "Summary:", PROPERTY);
		summaryText =
			new Text(attributesComposite, SWT.BORDER | SWT.SINGLE | SWT.WRAP);
		summaryText.setFont(TEXT_FONT);
		GridData summaryTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		summaryTextData.horizontalSpan = 3;
		summaryTextData.widthHint = 200;
		summaryText.setLayoutData(summaryTextData);
		summaryText.setText(getBug().getSummary());
		summaryText.addListener(SWT.KeyUp, new SummaryListener());
		summaryText.addListener(SWT.FocusIn, new GenericListener());
	}

	/**
	 * Creates the description layout, which displays and possibly edits the
	 * bug's description.
	 */
	protected abstract void createDescriptionLayout();

	/**
	 * Creates the comment layout, which displays the bug's comments and
	 * possibly lets the user enter a new one.
	 */
	protected abstract void createCommentLayout();

	/**
	 * Creates the button layout. This displays options and buttons at the
	 * bottom of the editor to allow actions to be performed on the bug.
	 */
	protected void createButtonLayouts() {

		Composite buttonComposite = new Composite(infoArea, SWT.NONE);
		GridLayout buttonLayout = new GridLayout();
		buttonLayout.numColumns = 4;
		buttonComposite.setLayout(buttonLayout);
		buttonComposite.setBackground(background);
		GridData buttonData = new GridData(GridData.FILL_BOTH);
		buttonData.horizontalSpan = 1;
		buttonData.grabExcessVerticalSpace = false;
		buttonComposite.setLayoutData(buttonData);

		addRadioButtons(buttonComposite);
		addActionButtons(buttonComposite);
	}

	/**
	 * Adds radio buttons to this composite. 
	 * @param buttonComposite Composite to add the radio buttons to.
	 */
	abstract protected void addRadioButtons(Composite buttonComposite);

	/**
	 * Adds buttons to this composite. 
	 * Subclasses can override this method to provide different/additional buttons.
	 * @param buttonComposite Composite to add the buttons to.
	 */
	protected void addActionButtons(Composite buttonComposite) {
		submitButton = new Button(buttonComposite, SWT.NONE);
		submitButton.setFont(TEXT_FONT);
		GridData submitButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
		submitButtonData.widthHint = 100;
		submitButtonData.heightHint = 20;
		submitButton.setText("Submit");
		submitButton.setLayoutData(submitButtonData);
		submitButton.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event e) {
				submitBug();
			}
		});
		submitButton.addListener(SWT.FocusIn, new GenericListener());

// This is not needed anymore since we have the save working properly with ctrl-s and file->save		
//		saveButton = new Button(buttonComposite, SWT.NONE);
//		saveButton.setFont(TEXT_FONT);
//		GridData saveButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
//		saveButtonData.widthHint = 100;
//		saveButtonData.heightHint = 20;
//		saveButton.setText("Save Offline");
//		saveButton.setLayoutData(saveButtonData);
//		saveButton.addListener(SWT.Selection, new Listener() {
//			public void handleEvent(Event e) {
//				saveBug();
//				updateEditor();
//			}
//		});
//		saveButton.addListener(SWT.FocusIn, new GenericListener());
	}

	/**
	 * Make sure that a String that is <code>null</code> is changed to a null
	 * string
	 * 
	 * @param text
	 *            The text to check if it is null or not
	 * @return If the text is <code>null</code>, then return the null string (<code>""</code>).
	 *         Otherwise, return the text.
	 */
	public String checkText(String text) {
		if (text == null)
			return "";
		else
			return text;
	}
	
	/**
	 * @return A string to use as a title for this editor.
	 */
	protected abstract String getTitleString();

	/**
	 * Creates an uneditable text field for displaying data.
	 * 
	 * @param composite
	 *            The composite to put this text field into. Its layout style
	 *            should be a grid with columns.
	 * @param colSpan
	 *            The number of columns that this text field should span.
	 * @param text
	 *            The text that for this text field.
	 * @param style
	 *            The style for this text field. See below for valid values
	 *            (default is HEADER).
	 * @return The new styled text.
	 * @see VALUE
	 * @see PROPERTY
	 * @see HEADER
	 */
	protected StyledText newLayout(Composite composite, int colSpan, String text,
			String style) {
		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
		data.horizontalSpan = colSpan;
        
        StyledText stext;
		if (style.equalsIgnoreCase(VALUE)) {
			StyledText styledText =
				new StyledText(composite, SWT.MULTI | SWT.READ_ONLY);
			styledText.setFont(TEXT_FONT);
			styledText.setText(checkText(text));
			styledText.setBackground(background);
			data.horizontalIndent = HORZ_INDENT;
			styledText.setLayoutData(data);
			styledText.setEditable(false);
			styledText.getCaret().setVisible(false);
			
			styledText.addSelectionListener(new SelectionAdapter() {
				
				@Override
				public void widgetSelected(SelectionEvent e) {
					StyledText c = (StyledText) e.widget;
					if (c != null && c.getSelectionCount() > 0) {
						if (currentSelectedText != null) {
							if (!c.equals(currentSelectedText)) {
								currentSelectedText.setSelectionRange(0, 0);
							}
						}
					}
					currentSelectedText = c;
				}
			});
			
			styledText.setMenu(
				contextMenuManager.createContextMenu(styledText));
            stext = styledText;
		}
		else if (style.equalsIgnoreCase(PROPERTY)) {
			StyledText styledText =
				new StyledText(composite, SWT.MULTI | SWT.READ_ONLY);
			styledText.setFont(TEXT_FONT);
			styledText.setText(checkText(text));
			styledText.setBackground(background);
			data.horizontalIndent = HORZ_INDENT;
			styledText.setLayoutData(data);
			StyleRange sr =
				new StyleRange(
					styledText.getOffsetAtLine(0),
					text.length(),
					foreground,
					background,
					SWT.BOLD);
			styledText.setStyleRange(sr);
			styledText.getCaret().setVisible(false);
			styledText.setEnabled(false);

			
			styledText.setMenu(contextMenuManager.createContextMenu(styledText));
            stext = styledText;
		}
		else {
			Composite generalTitleGroup = new Composite(composite, SWT.NONE);
			generalTitleGroup.setLayoutData(
				new GridData(GridData.FILL_HORIZONTAL));
			generalTitleGroup.setLayoutData(data);
			GridLayout generalTitleLayout = new GridLayout();
			generalTitleLayout.numColumns = 2;
			generalTitleLayout.marginWidth = 0;
			generalTitleLayout.marginHeight = 9;
			generalTitleGroup.setLayout(generalTitleLayout);
			generalTitleGroup.setBackground(background);
			
			Label image = new Label(generalTitleGroup, SWT.NONE);
			image.setBackground(background);
			image.setImage(
				WorkbenchImages.getImage(
						IDEInternalWorkbenchImages.IMG_OBJS_WELCOME_ITEM));

			GridData gd = new GridData(GridData.FILL_BOTH);
			gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
			image.setLayoutData(gd);
			StyledText titleText =
				new StyledText(generalTitleGroup, SWT.MULTI | SWT.READ_ONLY);
			titleText.setText(checkText(text));
			titleText.setFont(HEADER_FONT);
			titleText.setBackground(background);
			StyleRange sr = new StyleRange(
					titleText.getOffsetAtLine(0),
					text.length(),
					foreground,
					background,
					SWT.BOLD);
			titleText.setStyleRange(sr);
			titleText.getCaret().setVisible(false);
			titleText.setEditable(false);
			titleText.addSelectionListener(new SelectionAdapter() {
				
				@Override
				public void widgetSelected(SelectionEvent e) {
					StyledText c = (StyledText) e.widget;
					if (c != null && c.getSelectionCount() > 0) {
						if (currentSelectedText != null) {
							if (!c.equals(currentSelectedText)) {
								currentSelectedText.setSelectionRange(0, 0);
							}
						}
					}
					currentSelectedText = c;
				}
			});
			// create context menu
			 generalTitleGroup.setMenu(
				 contextMenuManager.createContextMenu(generalTitleGroup));
			 titleText.setMenu(
				 contextMenuManager.createContextMenu(titleText));
			 image.setMenu(
				 contextMenuManager.createContextMenu(image));
             stext = titleText;
		}
		composite.setMenu(contextMenuManager.createContextMenu(composite));
        return stext;
	}

	/**
	 * This creates the title header for the info area. Its style is similar to
	 * one from calling the function <code>newLayout</code> with the style
	 * <code>HEADER</code>.
	 * 
	 * @param composite
	 *            The composite to put this text field into. Its layout style
	 *            should be a grid with columns.
	 */
	protected void newAttributesLayout(Composite composite) {
		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
		data.horizontalSpan = 4;
		Composite generalTitleGroup = new Composite(composite, SWT.NONE);
		generalTitleGroup.setLayoutData(
			new GridData(GridData.FILL_HORIZONTAL));
		generalTitleGroup.setLayoutData(data);
		GridLayout generalTitleLayout = new GridLayout();
		generalTitleLayout.numColumns = 3;
		generalTitleLayout.marginWidth = 0;
		generalTitleLayout.marginHeight = 9;
		generalTitleGroup.setLayout(generalTitleLayout);
		generalTitleGroup.setBackground(background);
		
		Label image = new Label(generalTitleGroup, SWT.NONE);
		image.setBackground(background);
		image.setImage(
			WorkbenchImages.getImage(
					IDEInternalWorkbenchImages.IMG_OBJS_WELCOME_ITEM));
		
		GridData gd = new GridData(GridData.FILL_BOTH);
		gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
		image.setLayoutData(gd);

		generalTitleText =
			new StyledText(generalTitleGroup, SWT.MULTI | SWT.READ_ONLY);
		generalTitleText.setBackground(background);
		generalTitleText.getCaret().setVisible(false);
		generalTitleText.setEditable(false);
		generalTitleText.addSelectionListener(new SelectionAdapter() {
			
			@Override
			public void widgetSelected(SelectionEvent e) {
				StyledText c = (StyledText) e.widget;
				if (c != null && c.getSelectionCount() > 0) {
					if (currentSelectedText != null) {
						if (!c.equals(currentSelectedText)) {
							currentSelectedText.setSelectionRange(0, 0);
						}
					}
				}
				currentSelectedText = c;
			}
		});
		// create context menu
		 generalTitleGroup.setMenu(
			 contextMenuManager.createContextMenu(generalTitleGroup));
		 generalTitleText.setMenu(
			 contextMenuManager.createContextMenu(generalTitleText));		
		
		linkToBug =
			new Hyperlink(generalTitleGroup, SWT.MULTI | SWT.READ_ONLY);
		linkToBug.setBackground(background);

		setGeneralTitleText();

		 image.setMenu(
			 contextMenuManager.createContextMenu(image));
		composite.setMenu(contextMenuManager.createContextMenu(composite));
	}
	
	/**
	 * This refreshes the text in the title label of the info area (it contains
	 * elements which can change).
	 */
	protected void setGeneralTitleText() {
		String text = "Open in browser";
		linkToBug.setText(text);
		linkToBug.setFont(TEXT_FONT);
		if(this instanceof ExistingBugEditor){
			linkToBug.setUnderlined(true);
			linkToBug.setForeground(JFaceColors.getHyperlinkText(Display.getCurrent()));
			linkToBug.addMouseListener(new MouseListener(){
	
				public void mouseDoubleClick(MouseEvent e) {}
				public void mouseUp(MouseEvent e) {}
	
				public void mouseDown(MouseEvent e) {
					BugzillaUITools.openUrl(getTitle(), getTitleToolTip(), BugzillaRepository.getBugUrlWithoutLogin(bugzillaInput.getBug().getId()));
					if(e.stateMask == SWT.MOD3){
						// XXX come back to look at this ui
						close();
					}
					
				}
			});
		} else{
			linkToBug.setEnabled(false);
		}
		linkToBug.addListener(SWT.FocusIn, new GenericListener());
		
		// Resize the composite, in case the new summary is longer than the
		// previous one.
		// Then redraw it to show the changes.
		linkToBug.getParent().pack(true);
		linkToBug.redraw();
		
		text = getTitleString();
		generalTitleText.setText(text);
		StyleRange sr = new StyleRange(
				generalTitleText.getOffsetAtLine(0),
				text.length(),
				foreground,
				background,
				SWT.BOLD);
		generalTitleText.setStyleRange(sr);
		generalTitleText.addListener(SWT.FocusIn, new GenericListener());
		
		// Resize the composite, in case the new summary is longer than the
		// previous one.
		// Then redraw it to show the changes.
		generalTitleText.getParent().pack(true);
		generalTitleText.redraw();
	}

	/**
	 * Creates some blank space underneath the supplied composite.
	 * 
	 * @param parent
	 *            The composite to add the blank space to.
	 */
	protected void createSeparatorSpace(Composite parent) {
		GridData separatorData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		separatorData.verticalSpan = 1;
		separatorData.grabExcessVerticalSpace = false;

		Composite separatorComposite = new Composite(parent, SWT.NONE);
		GridLayout separatorLayout = new GridLayout();
		separatorLayout.marginHeight = 0;
		separatorLayout.verticalSpacing = 0;
		separatorComposite.setLayout(separatorLayout);
		separatorComposite.setBackground(background);
		separatorComposite.setLayoutData(separatorData);
		newLayout(separatorComposite, 1, "", VALUE);
	}

	/**
	 * Submit the changes to the bug to the bugzilla server.
	 */
	protected abstract void submitBug();
	
	/**
	 * If there is no locally saved copy of the current bug, then it saved
	 * offline. Otherwise, any changes are updated in the file.
	 */
	public void saveBug() {
		updateBug();
		changeDirtyStatus(false);
		OfflineView.saveOffline(getBug());
		OfflineView.checkWindow();
		OfflineView.refreshView();
	}
	
	/**
	 * Updates the <code>IBugzillaBug</code> object to contain the latest data
	 * entered in the data fields.
	 */
	protected abstract void updateBug();
	
	/**
	 * Resets the data fields to contain the data currently in the
	 * <code>IBugzillaBug</code> object.
	 */
	protected abstract void restoreBug();
	
	/**
	 * Refreshes any text labels in the editor that contain information that
	 * might change.
	 */
	protected void updateEditor() {
		// Reset all summary occurrences, since it might have 
		// been edited.
		String title = getTitleString();
		titleLabel.setText(title);
		setGeneralTitleText();		
	}
	
	/**
	 * Break text up into lines of about 80 characters so that it
	 * is displayed properly in bugzilla
	 * @param origText The string to be formatted
	 * @return The formatted text
	 */
	protected String formatText(String origText)
	{
		String [] textArray = new String[(origText.length()/80 + 1) *2];
		for(int i = 0; i < textArray.length; i++)
			textArray[i] = null;
		int j = 0;
		while(true) {
			int spaceIndex = origText.indexOf(" ", 75);
			if (spaceIndex == origText.length() || spaceIndex == -1) {
				textArray[j] = origText;
				break;
			}
			textArray[j] = origText.substring(0, spaceIndex);
			origText = origText.substring(spaceIndex + 1, origText.length());
			j++;
		}
	
		String newText = "";
	
		for (int i = 0; i < textArray.length; i++) {
			if(textArray[i] == null)
				break;
			newText += textArray[i] + "\n";
		}
		return newText;
	}
	
	/**
	 * function to set the url to post the bug to
	 * @param form A reference to a BugPost that the bug is going to be posted to
	 * @param formName The form that we wish to use to submit the bug
	 */
	protected void setURL(BugPost form, String formName) {
		String baseURL = BugzillaPlugin.getDefault().getServerName();
		if (!baseURL.endsWith("/"))
			baseURL += "/";
		try {
			form.setURL(baseURL + formName);
		}
		catch (MalformedURLException e){
			// we should be ok here
		}

		// add the login information to the bug post
		form.add("Bugzilla_login", BugzillaPreferences.getUserName());
		form.add("Bugzilla_password", BugzillaPreferences.getPassword());
	}
	
	@Override
	public void setFocus() {
		scrolledComposite.setFocus();
	}
	
	@Override
	public boolean isDirty() {
		return isDirty;
	}

	/**
	 * Updates the dirty status of this editor page. The dirty status is true if
	 * the bug report has been modified but not saved. The title of the editor
	 * is also updated to reflect the status.
	 * 
	 * @param newDirtyStatus
	 *            is true when the bug report has been modified but not saved
	 */
	public void changeDirtyStatus(boolean newDirtyStatus) {
		isDirty = newDirtyStatus;
		if (parentEditor == null) {
			firePropertyChange(PROP_DIRTY);
		} else {
			parentEditor.updatePartName();
		}
			
	}
	
	
	/**
	 * 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.
	 */
	protected void updateEditorTitle() {
		setPartName(bugzillaInput.getName());
	}
	
	@Override
	public boolean isSaveAsAllowed() {
		return false;
	}
	
	@Override
	public void doSave(IProgressMonitor monitor) {
		saveBug();
		updateEditor();
		
		// XXX notify that saved ofline?
	}
	
	@Override
	public void doSaveAs() {
		// we don't save, so no need to implement
	}
	
	/**
	 * @return The composite for the whole editor.
	 */
	public Composite getEditorComposite() {
		return editorComposite;
	}
	
	@Override
    public void dispose() {
		super.dispose();
		isDisposed = true;
		getSite().getPage().removeSelectionListener(selectionListener);
	}

	public void handleEvent(Event event) {
		if (event.widget instanceof Combo) {
			Combo combo = (Combo)event.widget;
			if (comboListenerMap.containsKey(combo)) {
				String sel = combo.getItem(combo.getSelectionIndex());
				Attribute a = getBug().getAttribute(comboListenerMap.get(combo));
				if (!(a.getNewValue().equals(sel))) {
					a.setNewValue(sel);					
					for(IBugzillaAttributeListener client : attributesListeners) {
						client.attributeChanged(a.getName(), sel);
					}
					changeDirtyStatus(true);
				}
			}
		}
	}

	/**
	 * Fires a <code>SelectionChangedEvent</code> to all listeners registered
	 * under <code>selectionChangedListeners</code>.
	 * 
	 * @param event
	 *            The selection event.
	 */
	protected void fireSelectionChanged(final SelectionChangedEvent event) {
        Object[] listeners = selectionChangedListeners.getListeners();
	    for (int i = 0; i < listeners.length; i++) {
	        final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
	        SafeRunnable.run(new SafeRunnable() {
	            public void run() {
	                l.selectionChanged(event);
	            }
	        });
	    }
	}

	/**
	 * A generic listener for selection of unimportant items. The default
	 * selection item sent out is the entire bug object.
	 */
	protected class GenericListener implements Listener {
		public void handleEvent(Event event) {
			IBugzillaBug bug = getBug();
			fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), bug.getLabel(), false, bug.getSummary()))));
		}
	}

	/**
	 * A listener to check if the summary field was modified.
	 */
	protected class SummaryListener implements Listener {
		public void handleEvent(Event event) {
			handleSummaryEvent();
		}
	}

	/**
	 * Check if the summary field was modified, and update it if necessary.
	 */
	public abstract void handleSummaryEvent();

    /*----------------------------------------------------------*
     * CODE TO SCROLL TO A COMMENT OR OTHER PIECE OF TEXT
     *----------------------------------------------------------*/ 
    
	/** List of the StyledText's so that we can get the previous and the next */
    protected ArrayList<StyledText> texts = new ArrayList<StyledText>();
    
    protected HashMap<Object, StyledText> textHash = new HashMap<Object, StyledText>();

    /** Index into the styled texts*/
    protected int textsindex = 0;
    
    protected Text addCommentsTextBox = null;
    
    protected Text descriptionTextBox = null;
    
    private StyledText previousText = null;
    
    /**
     * Selects the given object in the editor.
     * 
     * @param commentNumber
     *            The comment number to be selected
     */
    public void select(int commentNumber){
        if(commentNumber == -1)
            return;
        
        for(Object o: textHash.keySet()){
            if(o instanceof Comment){
                if(((Comment)o).getNumber() == commentNumber){
                    select(o, true);
                }
            }
        }
    }
    
    /**
	 * Selects the given object in the editor.
	 * 
	 * @param o
	 *            The object to be selected.
	 * @param highlight
	 *            Whether or not the object should be highlighted.
	 */
    public void select(Object o, boolean highlight){
        if(textHash.containsKey(o)){
            StyledText t = textHash.get(o);
            if(t != null){
                focusOn(t, highlight);
            }
        } else if(o instanceof IBugzillaBug){
            focusOn(null, highlight);
        }
    }
	
	public void selectDescription(){
		for(Object o: textHash.keySet()){
            if(o.equals(bugzillaInput.getBug().getDescription())){
				select(o, true);
            }
        }
    }
	
    
    public void selectNewComment(){
        focusOn(addCommentsTextBox, false);
    }
    
    public void selectNewDescription(){
        focusOn(descriptionTextBox, false);
    }
    
    /**
     * Scroll to a specified piece of text
     * @param selectionComposite The StyledText to scroll to
     */
    private void focusOn(Control selectionComposite, boolean highlight) {

        int pos = 0;
        if(previousText != null && !previousText.isDisposed()) {
            previousText.setSelection(0);
        }
        
        if(selectionComposite instanceof StyledText)
            previousText = (StyledText) selectionComposite;
        
        if (selectionComposite != null) {
            
            if(highlight && selectionComposite instanceof StyledText && !selectionComposite.isDisposed())
                ((StyledText)selectionComposite).setSelection(0, ((StyledText)selectionComposite).getText().length());
            
            // get the position of the text in the composite
            pos = 0;
            Control s = selectionComposite;
            if(s.isDisposed())
            	return;
            s.setEnabled(true);
            s.setFocus();
            s.forceFocus();
            while(s != null && s != getEditorComposite()) {
                if(!s.isDisposed()){
                    pos += s.getLocation().y;
                    s = s.getParent();
                }
            }
            
            pos = scrolledComposite.getOrigin().y + pos - 60;
        }
        if(!scrolledComposite.isDisposed())
            scrolledComposite.setOrigin(0, pos);
    }    
    
    private BugzillaOutlinePage outlinePage = null;
    
    @Override
    public Object getAdapter(Class adapter) {
        if (IContentOutlinePage.class.equals(adapter)) {
            if (outlinePage == null && bugzillaInput != null) {
				outlinePage = new BugzillaOutlinePage(model);
            }
            return outlinePage;
        }
        return super.getAdapter(adapter);
    }
    
    protected BugzillaOutlineNode model = null;
    
    public BugzillaOutlineNode getModel(){
    	return model;
    }
    
    public BugzillaOutlinePage getOutline(){
        return outlinePage;
    }
    
    private boolean isDisposed = false;
    
    public boolean isDisposed(){
    	return isDisposed;
    }
    
    public void close() {
        Display activeDisplay= getSite().getShell().getDisplay();
        activeDisplay.asyncExec(new Runnable() {
            public void run() {
            	if(getSite() != null && getSite().getPage() != null && !AbstractBugEditor.this.isDisposed())
                getSite().getPage().closeEditor(AbstractBugEditor.this, false);
            }
        });
    }
   
    public void addAttributeListener(IBugzillaAttributeListener listener) {
    	attributesListeners.add(listener);
    }
    
    public void removeAttributeListener(IBugzillaAttributeListener listener) {
    	attributesListeners.remove(listener);
    }
    
    public void setParentEditor(BugzillaTaskEditor editor) {
    	parentEditor = editor;
    }
}

Back to the top