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
|
/*******************************************************************************
* Copyright (c) 2004, 2008 Tasktop Technologies 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:
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.bugzilla.ui.editor;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.forms.IFormColors;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Hyperlink;
/**
* @author Rob Elves
*/
public class BugzillaVotesEditor extends AbstractAttributeEditor {
// Copy from <code>TaskEditorAttributePart</code>
private static final int LABEL_WIDTH = 100;
// Copy from TaskEditorAttributePart
private static final int COLUMN_GAP = 5;
public BugzillaVotesEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
super(manager, taskAttribute);
}
private Hyperlink voteControl;
private Label hiddenLabel;
private Hyperlink showVotes;
@Override
public void createControl(Composite parent, FormToolkit toolkit) {
((GridData) getLabelControl().getLayoutData()).exclude = true;
showVotes = toolkit.createHyperlink(parent, getTaskAttribute().getValue(), SWT.NONE);
showVotes.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
showVotes.setToolTipText("Show votes");
showVotes.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
TasksUiUtil.openUrl(getTaskAttribute().getTaskData().getRepositoryUrl()
+ IBugzillaConstants.URL_SHOW_VOTES + getTaskAttribute().getTaskData().getTaskId());
}
});
setControl(showVotes);
}
@Override
public void createLabelControl(Composite composite, FormToolkit toolkit) {
voteControl = toolkit.createHyperlink(composite, getLabel(), SWT.NONE);
voteControl.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
voteControl.setToolTipText("Vote");
voteControl.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
TasksUiUtil.openUrl(getTaskAttribute().getTaskData().getRepositoryUrl() + IBugzillaConstants.URL_VOTE
+ getTaskAttribute().getTaskData().getTaskId());
}
});
GridData gd = GridDataFactory.fillDefaults()
.align(SWT.RIGHT, SWT.CENTER)
.hint(LABEL_WIDTH, SWT.DEFAULT)
.create();
gd.horizontalIndent = COLUMN_GAP;
gd.widthHint = LABEL_WIDTH + COLUMN_GAP;
voteControl.setLayoutData(gd);
hiddenLabel = toolkit.createLabel(composite, "");
GridData data = new GridData();
data.exclude = true;
hiddenLabel.setLayoutData(data);
}
@Override
protected void decorateOutgoing(Color color) {
// ignore
}
@Override
public Label getLabelControl() {
return hiddenLabel;
}
public String getValue() {
return getAttributeMapper().getValue(getTaskAttribute());
}
public void setValue(String text) {
getAttributeMapper().setValue(getTaskAttribute(), text);
attributeChanged();
}
}
|