Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9481a80c6a9aa2b5d68564403eb652e4fdb69719 (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
/*******************************************************************************
 * Copyright (c) 2011, 2012 Ericsson AB 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
 * 
 * Description:
 * 
 * This class implements a Factory that is used to create all R4E Input Dialogs
 * 
 * Contributors:
 *   Sebastien Dubois - Created for Mylyn Review R4E project
 *   
 ******************************************************************************/

package org.eclipse.mylyn.reviews.r4e.ui.internal.dialogs;

import org.eclipse.core.resources.IProject;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.mylyn.reviews.notifications.core.NotificationsCore;
import org.eclipse.mylyn.reviews.notifications.spi.NotificationsConnector;
import org.eclipse.mylyn.reviews.r4e.core.model.drules.R4EDesignRuleViolation;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.IR4EUIModelElement;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIAnomalyBasic;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIModelController;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIReviewBasic;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIReviewGroup;
import org.eclipse.mylyn.reviews.r4e.ui.internal.utils.UIUtils;
import org.eclipse.mylyn.versions.ui.ScmUi;
import org.eclipse.mylyn.versions.ui.spi.ScmConnectorUi;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;

/**
 * @author Sebastien Dubois
 * @version $Revision: 1.0 $
 */
@SuppressWarnings("restriction")
public class R4EUIDialogFactory {

	// ------------------------------------------------------------------------
	// Constants
	// ------------------------------------------------------------------------

	/**
	 * Field MAIL_CONNECTOR_IDS.
	 */
	private static final String[] MAIL_CONNECTOR_IDS = { "reviews.r4e.mail.outlook.connector" }; //$NON-NLS-1$

	// ------------------------------------------------------------------------
	// Members
	// ------------------------------------------------------------------------

	/**
	 * Field FInstance.
	 */
	private static R4EUIDialogFactory FInstance = null;

	/**
	 * Field fAnomalyInputDialog.
	 */
	private IAnomalyInputDialog fNewAnomalyInputDialog = null;

	/**
	 * Field fCloneAnomalyInputDialog.
	 */
	private IAnomalyInputDialog fCloneAnomalyInputDialog = null;

	/**
	 * Field fCalendarDialog.
	 */
	private ICalendarDialog fCalendarDialog = null;

	/**
	 * Field fChangeReviewStateDialog.
	 */
	private IChangeStateDialog fChangeReviewStateDialog = null;

	/**
	 * Field fChangeAnomalyStateDialog.
	 */
	private IChangeStateDialog fChangeAnomalyStateDialog = null;

	/**
	 * Field fCommentInputDialog.
	 */
	private ICommentInputDialog fCommentInputDialog = null;

	/**
	 * Field fFindUserDialog.
	 */
	private IFindUserDialog fFindUserDialog = null;

	/**
	 * Field fParticipantInputDialog.
	 */
	private IParticipantInputDialog fParticipantInputDialog = null;

	/**
	 * Field fParticipantUnassignDialog.
	 */
	private IParticipantUnassignDialog fParticipantUnassignDialog = null;

	/**
	 * Field fReviewGroupInputDialog.
	 */
	private IReviewGroupInputDialog fReviewGroupInputDialog = null;

	/**
	 * Field fReviewInputDialog.
	 */
	private IReviewInputDialog fReviewInputDialog = null;

	/**
	 * Field fRuleAreaInputDialog.
	 */
	private IRuleAreaInputDialog fRuleAreaInputDialog = null;

	/**
	 * Field fRuleInputDialog.
	 */
	private IRuleInputDialog fRuleInputDialog = null;

	/**
	 * Field fRuleSetInputDialog.
	 */
	private IRuleSetInputDialog fRuleSetInputDialog = null;

	/**
	 * Field fRuleViolationInputDialog.
	 */
	private IRuleViolationInputDialog fRuleViolationInputDialog = null;

	/**
	 * Field fSendNotificationInputDialog.
	 */
	private ISendNotificationInputDialog fSendNotificationInputDialog = null;

	/**
	 * Field fParticipantFilterInputDialog.
	 */
	private InputDialog fParticipantFilterInputDialog = null;

	/**
	 * Field fScmConnectorUi.
	 */
	private ScmConnectorUi fScmConnectorUi = null;

	/**
	 * Field fNotificationsConnector.
	 */
	private NotificationsConnector fNotificationsConnector = null;

	// ------------------------------------------------------------------------
	// Constructors
	// ------------------------------------------------------------------------

	/**
	 * Constructor for R4EUIDialogFactory.
	 */
	private R4EUIDialogFactory() {
	}

	// ------------------------------------------------------------------------
	// Methods
	// ------------------------------------------------------------------------

	/**
	 * Method getInstance.
	 * 
	 * @return R4EUIDialogFactory
	 */
	public static R4EUIDialogFactory getInstance() {
		if (null == FInstance) {
			FInstance = new R4EUIDialogFactory();
		}
		return FInstance;
	}

	private IShellProvider getShellProvider() {
		final IShellProvider shellProvider = new IShellProvider() {
			public Shell getShell() {
				//Obtain display from current thread or first created
				Display display = Display.getCurrent() != null ? Display.getCurrent() : Display.getDefault();
				return display.getActiveShell();
			}
		};
		return shellProvider;
	}

	/**
	 * Method getNewAnomalyInputDialog.
	 * 
	 * @return IAnomalyInputDialog
	 */
	public IAnomalyInputDialog getNewAnomalyInputDialog() {
		if (null == fNewAnomalyInputDialog) {
			fNewAnomalyInputDialog = new NewAnomalyInputDialog(R4EUIModelController.getNavigatorView()
					.getSite()
					.getWorkbenchWindow()
					.getShell());
		}
		return fNewAnomalyInputDialog;
	}

	/**
	 * Method setNewAnomalyInputDialog.
	 * 
	 * @param aNewAnomalyInputDialog
	 *            IAnomalyInputDialog
	 */
	public void setNewAnomalyInputDialog(IAnomalyInputDialog aNewAnomalyInputDialog) {
		fNewAnomalyInputDialog = aNewAnomalyInputDialog;
	}

	/**
	 * Method getCloneAnomalyInputDialog.
	 * 
	 * @return IAnomalyInputDialog
	 */
	public IAnomalyInputDialog getCloneAnomalyInputDialog() {
		if (null == fCloneAnomalyInputDialog) {
			fCloneAnomalyInputDialog = new CloneAnomalyInputDialog(R4EUIModelController.getNavigatorView()
					.getSite()
					.getWorkbenchWindow()
					.getShell());
		}
		return fCloneAnomalyInputDialog;
	}

	/**
	 * Method setCloneAnomalyInputDialog.
	 * 
	 * @param aCloneAnomalyInputDialog
	 *            IAnomalyInputDialog
	 */
	public void setCloneAnomalyInputDialog(IAnomalyInputDialog aCloneAnomalyInputDialog) {
		fCloneAnomalyInputDialog = aCloneAnomalyInputDialog;
	}

	/**
	 * Method getCalendarDialog.
	 * 
	 * @return ICalendarDialog
	 */
	public ICalendarDialog getCalendarDialog() {
		if (null == fCalendarDialog) {
			fCalendarDialog = new CalendarDialog(R4EUIModelController.getNavigatorView()
					.getSite()
					.getWorkbenchWindow()
					.getShell(), false);
		}
		return fCalendarDialog;
	}

	/**
	 * Method setCalendarDialog.
	 * 
	 * @param aCalendarDialog
	 *            ICalendarDialog
	 */
	public void setCalendarDialog(ICalendarDialog aCalendarDialog) {
		fCalendarDialog = aCalendarDialog;
	}

	/**
	 * Method getChangeStateDialog.
	 * 
	 * @param aTargetClass
	 *            Class<?>
	 * @return IChangeStateDialog
	 */
	public IChangeStateDialog getChangeStateDialog(Class<?> aTargetClass) {
		if (aTargetClass.equals(R4EUIReviewBasic.class)) {
			if (null == fChangeReviewStateDialog) {
				fChangeReviewStateDialog = new ChangeStateDialog(R4EUIModelController.getNavigatorView()
						.getSite()
						.getWorkbenchWindow()
						.getShell(), R4EUIReviewBasic.class);
			}
			return fChangeReviewStateDialog;
		}
		//Assume AnomalyChangeStateDialog
		if (null == fChangeAnomalyStateDialog) {
			fChangeAnomalyStateDialog = new ChangeStateDialog(R4EUIModelController.getNavigatorView()
					.getSite()
					.getWorkbenchWindow()
					.getShell(), R4EUIAnomalyBasic.class);
		}
		return fChangeAnomalyStateDialog;
	}

	/**
	 * Method setChangeStateDialog.
	 * 
	 * @param aChangeStateDialog
	 *            IChangeStateDialog
	 * @param aTargetClass
	 *            Class<?>
	 */
	public void setChangeStateDialog(IChangeStateDialog aChangeStateDialog, Class<?> aTargetClass) {
		if (aTargetClass.equals(R4EUIReviewBasic.class)) {
			fChangeReviewStateDialog = aChangeStateDialog;
		} else {
			//Assume AnomalyChangeStateDialog
			fChangeAnomalyStateDialog = aChangeStateDialog;
		}
	}

	/**
	 * Method getCommentInputDialog.
	 * 
	 * @return ICommentInputDialog
	 */
	public ICommentInputDialog getCommentInputDialog() {
		if (null == fCommentInputDialog) {
			fCommentInputDialog = new CommentInputDialog(R4EUIModelController.getNavigatorView()
					.getSite()
					.getWorkbenchWindow()
					.getShell());
		}
		return fCommentInputDialog;
	}

	/**
	 * Method setCommentInputDialog.
	 * 
	 * @param aCommentInputDialog
	 *            ICommentInputDialog
	 */
	public void setCommentInputDialog(ICommentInputDialog aCommentInputDialog) {
		fCommentInputDialog = aCommentInputDialog;
	}

	/**
	 * Method getFindUserDialog.
	 * 
	 * @return IFindUserDialog
	 */
	public IFindUserDialog getFindUserDialog() {
		if (null == fFindUserDialog) {
			fFindUserDialog = new FindUserDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
		}
		return fFindUserDialog;
	}

	/**
	 * Method setFindUserDialog.
	 * 
	 * @param aFindUserDialog
	 *            IFindUserDialog
	 */
	public void setFindUserDialog(IFindUserDialog aFindUserDialog) {
		fFindUserDialog = aFindUserDialog;
	}

	/**
	 * Method getParticipantInputDialog.
	 * 
	 * @param aShowExtraParams
	 *            boolean
	 * @return IParticipantInputDialog
	 */
	public IParticipantInputDialog getParticipantInputDialog(boolean aShowExtraParams) {
		if (!UIUtils.TEST_MODE) {
			fParticipantInputDialog = new ParticipantInputDialog(getShellProvider(), aShowExtraParams);
		}
		return fParticipantInputDialog; //Test mode: return mockup reference
	}

	/**
	 * Method removeParticipantInputDialog.
	 */
	public void removeParticipantInputDialog() {
		fParticipantInputDialog.close();
		fParticipantInputDialog = null;
	}

	/**
	 * Method setParticipantInputDialog.
	 * 
	 * @param aParticipantInputDialog
	 *            IParticipantInputDialog
	 */
	public void setParticipantInputDialog(IParticipantInputDialog aParticipantInputDialog) {
		fParticipantInputDialog = aParticipantInputDialog;
	}

	/**
	 * Method getParticipantUnassignDialog.
	 * 
	 * @param aElement
	 *            - IR4EUIModelElement
	 * @return IParticipantUnassignDialog
	 */
	public IParticipantUnassignDialog getParticipantUnassignDialog(IR4EUIModelElement aElement) {
		if (!UIUtils.TEST_MODE) {
			fParticipantUnassignDialog = new ParticipantUnassignDialog(R4EUIModelController.getNavigatorView()
					.getSite()
					.getWorkbenchWindow()
					.getShell(), aElement);
		}
		return fParticipantUnassignDialog; //Test mode: return mockup reference
	}

	/**
	 * Method removeParticipantUnassignDialog.
	 */
	public void removeParticipantUnassignDialog() {
		fParticipantUnassignDialog.close();
		fParticipantUnassignDialog = null;
	}

	/**
	 * Method setParticipantUnassignDialog.
	 * 
	 * @param aParticipantUnassignDialog
	 *            IParticipantUnassignDialog
	 */
	public void setParticipantUnassignDialog(IParticipantUnassignDialog aParticipantUnassignDialog) {
		fParticipantUnassignDialog = aParticipantUnassignDialog;
	}

	/**
	 * Method getReviewGroupInputDialog.
	 * 
	 * @return IReviewGroupInputDialog
	 */
	public IReviewGroupInputDialog getReviewGroupInputDialog() {
		if (null == fReviewGroupInputDialog) {
			fReviewGroupInputDialog = new ReviewGroupInputDialog(R4EUIModelController.getNavigatorView()
					.getSite()
					.getWorkbenchWindow()
					.getShell());
		}
		return fReviewGroupInputDialog;
	}

	/**
	 * Method setReviewGroupInputDialog.
	 * 
	 * @param aReviewGroupInputDialog
	 *            IReviewGroupInputDialog
	 */
	public void setReviewGroupInputDialog(IReviewGroupInputDialog aReviewGroupInputDialog) {
		fReviewGroupInputDialog = aReviewGroupInputDialog;
	}

	/**
	 * Method getReviewInputDialog.
	 * 
	 * @param aParentGroup
	 *            R4EUIReviewGroup
	 * @return IReviewInputDialog
	 */
	public IReviewInputDialog getReviewInputDialog(R4EUIReviewGroup aParentGroup) {
		if (!UIUtils.TEST_MODE) {
			fReviewInputDialog = new ReviewInputDialog(R4EUIModelController.getNavigatorView()
					.getSite()
					.getWorkbenchWindow()
					.getShell(), aParentGroup);
		}
		return fReviewInputDialog;
	}

	/**
	 * Method setReviewInputDialog.
	 * 
	 * @param aReviewInputDialog
	 *            IReviewInputDialog
	 */
	public void setReviewInputDialog(IReviewInputDialog aReviewInputDialog) {
		fReviewInputDialog = aReviewInputDialog;
	}

	/**
	 * Method getRuleAreaInputDialog.
	 * 
	 * @return IRuleAreaInputDialog
	 */
	public IRuleAreaInputDialog getRuleAreaInputDialog() {
		if (null == fRuleAreaInputDialog) {
			fRuleAreaInputDialog = new RuleAreaInputDialog(R4EUIModelController.getNavigatorView()
					.getSite()
					.getWorkbenchWindow()
					.getShell());
		}
		return fRuleAreaInputDialog;
	}

	/**
	 * Method setRuleAreaInputDialog.
	 * 
	 * @param aRuleAreaInputDialog
	 *            IRuleAreaInputDialog
	 */
	public void setRuleAreaInputDialog(IRuleAreaInputDialog aRuleAreaInputDialog) {
		fRuleAreaInputDialog = aRuleAreaInputDialog;
	}

	/**
	 * Method getRuleInputDialog.
	 * 
	 * @param R4EDesignRuleViolation
	 * @return IRuleInputDialog
	 */
	public IRuleInputDialog getRuleInputDialog(R4EDesignRuleViolation aViolation) {
		if (null == fRuleInputDialog) {
			fRuleInputDialog = new RuleInputDialog(R4EUIModelController.getNavigatorView()
					.getSite()
					.getWorkbenchWindow()
					.getShell(), aViolation);
		}
		return fRuleInputDialog;
	}

	/**
	 * Method setRuleInputDialog.
	 * 
	 * @param aRuleInputDialog
	 *            IRuleInputDialog
	 */
	public void setRuleInputDialog(IRuleInputDialog aRuleInputDialog) {
		fRuleInputDialog = aRuleInputDialog;
	}

	/**
	 * Method getRuleSetInputDialog.
	 * 
	 * @return IRuleSetInputDialog
	 */
	public IRuleSetInputDialog getRuleSetInputDialog() {
		if (null == fRuleSetInputDialog) {
			fRuleSetInputDialog = new RuleSetInputDialog(R4EUIModelController.getNavigatorView()
					.getSite()
					.getWorkbenchWindow()
					.getShell());
		}
		return fRuleSetInputDialog;
	}

	/**
	 * Method setRuleSetInputDialog.
	 * 
	 * @param aRuleSetInputDialog
	 *            IRuleSetInputDialog
	 */
	public void setRuleSetInputDialog(IRuleSetInputDialog aRuleSetInputDialog) {
		fRuleSetInputDialog = aRuleSetInputDialog;
	}

	/**
	 * Method getRuleViolationInputDialog.
	 * 
	 * @return IRuleViolationInputDialog
	 */
	public IRuleViolationInputDialog getRuleViolationInputDialog() {
		if (null == fRuleViolationInputDialog) {
			fRuleViolationInputDialog = new RuleViolationInputDialog(R4EUIModelController.getNavigatorView()
					.getSite()
					.getWorkbenchWindow()
					.getShell());
		}
		return fRuleViolationInputDialog;
	}

	/**
	 * Method setRuleViolationInputDialog.
	 * 
	 * @param aRuleViolationInputDialog
	 *            IRuleViolationInputDialog
	 */
	public void setRuleViolationInputDialog(IRuleViolationInputDialog aRuleViolationInputDialog) {
		fRuleViolationInputDialog = aRuleViolationInputDialog;
	}

	/**
	 * Method getSendNotificationInputDialog.
	 * 
	 * @param aSource
	 *            - ISelection
	 * @return ISendNotificationInputDialog
	 */
	public ISendNotificationInputDialog getSendNotificationInputDialog(ISelection aSource) {
		if (!UIUtils.TEST_MODE) {
			fSendNotificationInputDialog = new SendNotificationInputDialog(R4EUIModelController.getNavigatorView()
					.getSite()
					.getWorkbenchWindow()
					.getShell(), aSource);
		}
		return fSendNotificationInputDialog;
	}

	/**
	 * Method setSendNotificationInputDialog.
	 * 
	 * @param aSendNotificationInputDialog
	 *            ISendNotificationInputDialog
	 */
	public void setSendNotificationInputDialog(ISendNotificationInputDialog aSendNotificationInputDialog) {
		fSendNotificationInputDialog = aSendNotificationInputDialog;
	}

	/**
	 * Method getParticipantFilterInputDialog.
	 * 
	 * @return InputDialog
	 */
	public InputDialog getParticipantFilterInputDialog() {
		if (null == fParticipantFilterInputDialog) {
			fParticipantFilterInputDialog = new InputDialog(Display.getCurrent().getActiveShell(), "Set user name",
					"Enter user name to filter on", null, null);
		}
		return fParticipantFilterInputDialog;
	}

	/**
	 * Method setParticipantFilterInputDialog.
	 * 
	 * @param aParticipantFilterInputDialog
	 *            InputDialog
	 */
	public void setParticipantFilterInputDialog(InputDialog aParticipantFilterInputDialog) {
		fParticipantFilterInputDialog = aParticipantFilterInputDialog;
	}

	/**
	 * Method setScmUIConnector.
	 * 
	 * @param aConnectorUi
	 *            ScmConnectorUi
	 */
	public void setScmUIConnector(ScmConnectorUi aConnectorUi) {
		fScmConnectorUi = aConnectorUi;
	}

	/**
	 * Method getScmUiConnector.
	 * 
	 * @param aProject
	 *            IProject
	 * @return ScmConnectorUi
	 */
	public ScmConnectorUi getScmUiConnector(IProject aProject) {
		if (!UIUtils.TEST_MODE) {
			fScmConnectorUi = ScmUi.getUiConnector(aProject);
			return fScmConnectorUi;
		}
		return fScmConnectorUi; //Test mode: return mockup reference
	}

	/**
	 * Method setMailConnector.
	 * 
	 * @param aConnector
	 *            NotificationsConnector
	 */
	public void setMailConnector(NotificationsConnector aConnector) {
		fNotificationsConnector = aConnector;
	}

	/**
	 * Method getScmUiConnector.
	 * 
	 * @return ScmConnectorUi
	 */
	public NotificationsConnector getMailConnector() {
		if (!UIUtils.TEST_MODE) {
			return NotificationsCore.getFirstEnabled(MAIL_CONNECTOR_IDS);
		}
		return fNotificationsConnector; //Test mode: return mockup reference
	}
}

Back to the top