Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7450126ad11e7cf94a8a540de870c9d638b137ab (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
/*******************************************************************************
 * Copyright (c) 2011 Frank Becker and others.
 * 
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * https://www.eclipse.org/legal/epl-2.0
 * 
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Frank Becker - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.bugzilla.ui.editor;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorNewCommentPart;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;

public class BugzillaTaskEditorNewCommentPart extends TaskEditorNewCommentPart {
	private Action privateAction;

	public BugzillaTaskEditorNewCommentPart() {
		// ignore
	}

	@Override
	protected void fillToolBar(ToolBarManager manager) {
		String insidergroup = getModel().getTaskRepository().getProperty(IBugzillaConstants.BUGZILLA_INSIDER_GROUP);
		if (Boolean.parseBoolean(insidergroup)) {

			privateAction = new Action() {

				private void updateActionState(String newValue) {
					if (newValue.equals("1")) { //$NON-NLS-1$
						this.setImageDescriptor(TasksUiImages.LOCK_CLOSE);
						this.setToolTipText(Messages.BugzillaTaskEditorNewCommentPart_privateComment);
					} else {
						this.setImageDescriptor(TasksUiImages.LOCK_OPEN);
						this.setToolTipText(Messages.BugzillaTaskEditorNewCommentPart_publicComment);
					}

				}

				@Override
				public void run() {
					TaskAttribute isprivate = getAttribute().getParentAttribute().getAttribute("comment_is_private"); //$NON-NLS-1$
					String value = isprivate.getValue();
					String newValue = value.equals("1") ? "0" : "1"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
					isprivate.setValue(newValue);
					updateActionState(newValue);
				}

			};
			privateAction.setImageDescriptor(TasksUiImages.LOCK_OPEN);
			privateAction.setToolTipText(Messages.BugzillaTaskEditorNewCommentPart_publicComment);
			manager.add(privateAction);
		}
		super.fillToolBar(manager);
	}

	@Override
	public void initialize(AbstractTaskEditorPage taskEditorPage) {
		super.initialize(taskEditorPage);
		if (getAttribute() != null) {
			TaskAttribute isprivate = getAttribute().getParentAttribute().getAttribute("comment_is_private"); //$NON-NLS-1$
			if (isprivate == null) {
				isprivate = getAttribute().getParentAttribute().createAttribute("comment_is_private"); //$NON-NLS-1$
			}
			isprivate.setValue("0"); //$NON-NLS-1$
		}
	}

}

Back to the top