Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2004, 2008 Tasktop Technologies and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* Tasktop Technologies - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
|
12 |
package org.eclipse.mylyn.internal.bugzilla.ui.dialogs; |
13 |
|
14 |
import java.text.MessageFormat; |
15 |
|
16 |
import org.eclipse.jface.dialogs.Dialog; |
17 |
import org.eclipse.jface.layout.GridDataFactory; |
18 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; |
19 |
import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage; |
20 |
import org.eclipse.mylyn.internal.bugzilla.ui.tasklist.Messages; |
21 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
22 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor; |
23 |
import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory; |
24 |
import org.eclipse.swt.SWT; |
25 |
import org.eclipse.swt.layout.GridData; |
26 |
import org.eclipse.swt.layout.GridLayout; |
27 |
import org.eclipse.swt.widgets.Composite; |
28 |
import org.eclipse.swt.widgets.Control; |
29 |
import org.eclipse.swt.widgets.Display; |
30 |
import org.eclipse.swt.widgets.Label; |
31 |
import org.eclipse.swt.widgets.Shell; |
32 |
import org.eclipse.ui.dialogs.SelectionDialog; |
33 |
import org.eclipse.ui.forms.events.ExpansionAdapter; |
34 |
import org.eclipse.ui.forms.events.ExpansionEvent; |
35 |
import org.eclipse.ui.forms.widgets.ExpandableComposite; |
36 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
37 |
|
38 |
/** |
39 |
* @author Frank Becker |
40 |
*/ |
41 |
public class BugzillaAttachmentDialog extends SelectionDialog { |
42 |
|
43 |
private final FormToolkit toolkit; |
44 |
|
45 |
private Composite scrollComposite; |
46 |
|
47 |
private ExpandableComposite flagExpandComposite = null; |
48 |
|
49 |
private final TaskAttribute attachment; |
50 |
|
51 |
private final Shell parentShell; |
52 |
|
53 |
private final boolean readOnly; |
54 |
|
55 |
private final AttributeEditorFactory attributeEditorFactory; |
56 |
|
57 |
private static final int LABEL_WIDTH = 120; |
58 |
|
59 |
private static final int COLUMN_GAP = 5; |
60 |
|
61 |
private static final int MULTI_ROW_HEIGHT = 55; |
62 |
|
63 |
private static final int COLUMN_WIDTH = 200; |
64 |
|
65 |
private static final int MULTI_COLUMN_WIDTH = COLUMN_WIDTH + 5 + COLUMN_GAP + LABEL_WIDTH + 5 + COLUMN_WIDTH; |
66 |
|
67 |
public BugzillaAttachmentDialog(Shell parentShell, BugzillaTaskEditorPage editor, AttributeEditorFactory factory, |
68 |
TaskAttribute attachment, boolean readonly) { |
69 |
super(parentShell); |
70 |
this.attachment = attachment; |
71 |
this.parentShell = parentShell; |
72 |
this.readOnly = readonly; |
73 |
attributeEditorFactory = factory; |
74 |
toolkit = new FormToolkit(Display.getCurrent()); |
75 |
this.setTitle(MessageFormat.format(readonly ? Messages.BugzillaAttachmentDialog_DetailTitle |
76 |
: Messages.BugzillaAttachmentDialog_UpdateTitle, attachment.getValue())); |
77 |
} |
78 |
|
79 |
@Override |
80 |
protected Control createDialogArea(Composite parent) { |
81 |
int currentColumn = 1; |
82 |
int columnCount = 4; |
83 |
Composite composite = (Composite) super.createDialogArea(parent); |
84 |
|
85 |
initializeDialogUnits(composite); |
86 |
|
87 |
Composite attributeArea = new Composite(composite, SWT.FLAT); |
88 |
attributeArea.setLayout(new GridLayout(4, false)); |
89 |
createAttributeEditors(currentColumn, columnCount, attributeArea); |
90 |
Composite advancedComposite = createFlagSection(attributeArea); |
91 |
createFlagEditors(columnCount, advancedComposite); |
92 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_URL), currentColumn, columnCount, |
93 |
advancedComposite); |
94 |
createCommntEditor(currentColumn, columnCount, attributeArea); |
95 |
Dialog.applyDialogFont(composite); |
96 |
return composite; |
97 |
} |
98 |
|
99 |
private void createAttributeEditor(TaskAttribute attribute, int currentColumn, int columnCount, |
100 |
Composite attributeArea) { |
101 |
String type = attribute.getMetaData().getType(); |
102 |
if (type != null) { |
103 |
AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, attribute); |
104 |
if (attribute.getId().equals(BugzillaAttribute.TOKEN.getKey()) |
105 |
|| attribute.getId().equals("size") || attribute.getId().equals(TaskAttribute.ATTACHMENT_URL)) { //$NON-NLS-1$ |
106 |
editor.setReadOnly(true); |
107 |
} else { |
108 |
editor.setReadOnly(readOnly); |
109 |
} |
110 |
if (editor.hasLabel()) { |
111 |
editor.createLabelControl(attributeArea, toolkit); |
112 |
Label label = editor.getLabelControl(); |
113 |
label.setBackground(attributeArea.getBackground()); |
114 |
String labelString = editor.getLabel(); |
115 |
if (labelString != null && !labelString.equals("")) { //$NON-NLS-1$ |
116 |
GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH, |
117 |
SWT.DEFAULT).create(); |
118 |
if (currentColumn > 1) { |
119 |
gd.horizontalIndent = COLUMN_GAP; |
120 |
gd.widthHint = LABEL_WIDTH + COLUMN_GAP; |
121 |
} |
122 |
label.setLayoutData(gd); |
123 |
currentColumn++; |
124 |
} |
125 |
} |
126 |
editor.createControl(attributeArea, toolkit); |
127 |
GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false); |
128 |
if (type.equals("shortText") || type.equals("url")) { //$NON-NLS-1$//$NON-NLS-2$ |
129 |
gd.horizontalSpan = 3; |
130 |
} else { |
131 |
gd.horizontalSpan = 1; |
132 |
} |
133 |
editor.getControl().setLayoutData(gd); |
134 |
if (attribute.getId().equals(TaskAttribute.ATTACHMENT_URL)) { |
135 |
editor.getControl().setEnabled(false); |
136 |
} |
137 |
|
138 |
currentColumn += gd.horizontalSpan; |
139 |
currentColumn %= columnCount; |
140 |
} |
141 |
} |
142 |
|
143 |
private void createAttributeEditors(int currentColumn, int columnCount, Composite attributeArea) { |
144 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_DESCRIPTION), currentColumn, |
145 |
columnCount, attributeArea); |
146 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_FILENAME), currentColumn, |
147 |
columnCount, attributeArea); |
148 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_SIZE), currentColumn, columnCount, |
149 |
attributeArea); |
150 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_CONTENT_TYPE), currentColumn, |
151 |
columnCount, attributeArea); |
152 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH), currentColumn, |
153 |
columnCount, attributeArea); |
154 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED), currentColumn, |
155 |
columnCount, attributeArea); |
156 |
} |
157 |
|
158 |
private void createFlagEditors(int columnCount, Composite advancedComposite) { |
159 |
int currentFlagColumn = 1; |
160 |
|
161 |
for (TaskAttribute attribute : attachment.getAttributes().values()) { |
162 |
if (!attribute.getId().startsWith("task.common.kind.flag")) { //$NON-NLS-1$ |
163 |
continue; |
164 |
} |
165 |
String type = attribute.getMetaData().getType(); |
166 |
if (type != null) { |
167 |
AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, attribute); |
168 |
editor.setReadOnly(readOnly); |
169 |
|
170 |
if (editor.hasLabel()) { |
171 |
editor.createLabelControl(advancedComposite, toolkit); |
172 |
Label label = editor.getLabelControl(); |
173 |
label.setBackground(advancedComposite.getBackground()); |
174 |
GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH, |
175 |
SWT.DEFAULT).create(); |
176 |
if (currentFlagColumn > 1) { |
177 |
gd.horizontalIndent = COLUMN_GAP; |
178 |
gd.widthHint = LABEL_WIDTH + COLUMN_GAP; |
179 |
} |
180 |
label.setLayoutData(gd); |
181 |
currentFlagColumn++; |
182 |
} |
183 |
editor.createControl(advancedComposite, toolkit); |
184 |
GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false); |
185 |
gd.widthHint = 150;//COLUMN_WIDTH; |
186 |
gd.horizontalSpan = 3; |
187 |
editor.getControl().setLayoutData(gd); |
188 |
currentFlagColumn += gd.horizontalSpan; |
189 |
currentFlagColumn %= columnCount; |
190 |
} |
191 |
} |
192 |
} |
193 |
|
194 |
private void createCommntEditor(int currentColumn, int columnCount, Composite attributeArea) { |
195 |
TaskAttribute commentAttribute = attachment.getAttribute("comment"); //$NON-NLS-1$ |
196 |
if (commentAttribute == null || readOnly) { |
197 |
return; |
198 |
} |
199 |
String type = commentAttribute.getMetaData().getType(); |
200 |
if (type != null) { |
201 |
AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, commentAttribute); |
202 |
String labelString = editor.getLabel(); |
203 |
if (editor.hasLabel()) { |
204 |
editor.createLabelControl(attributeArea, toolkit); |
205 |
if (!labelString.equals("")) { //$NON-NLS-1$ |
206 |
Label label = editor.getLabelControl(); |
207 |
label.setBackground(attributeArea.getBackground()); |
208 |
GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH, |
209 |
SWT.DEFAULT).create(); |
210 |
if (currentColumn > 1) { |
211 |
gd.horizontalIndent = COLUMN_GAP; |
212 |
gd.widthHint = LABEL_WIDTH + COLUMN_GAP; |
213 |
} |
214 |
label.setLayoutData(gd); |
215 |
} |
216 |
} |
217 |
editor.createControl(attributeArea, toolkit); |
218 |
GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false); |
219 |
gd.heightHint = MULTI_ROW_HEIGHT; |
220 |
gd.widthHint = MULTI_COLUMN_WIDTH; |
221 |
gd.horizontalSpan = columnCount - currentColumn + 1; |
222 |
editor.getControl().setLayoutData(gd); |
223 |
} |
224 |
} |
225 |
|
226 |
private Composite createFlagSection(Composite container) { |
227 |
flagExpandComposite = toolkit.createExpandableComposite(container, ExpandableComposite.COMPACT |
228 |
| ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); |
229 |
flagExpandComposite.setFont(container.getFont()); |
230 |
flagExpandComposite.setBackground(container.getBackground()); |
231 |
flagExpandComposite.setText(Messages.BugzillaTaskAttachmentPage_Advanced); |
232 |
flagExpandComposite.setLayout(new GridLayout(4, false)); |
233 |
GridData g = new GridData(GridData.FILL_HORIZONTAL); |
234 |
g.horizontalSpan = 4; |
235 |
flagExpandComposite.setLayoutData(g); |
236 |
flagExpandComposite.addExpansionListener(new ExpansionAdapter() { |
237 |
@Override |
238 |
public void expansionStateChanged(ExpansionEvent e) { |
239 |
parentShell.getDisplay().getActiveShell().pack(); |
240 |
} |
241 |
}); |
242 |
|
243 |
scrollComposite = new Composite(flagExpandComposite, SWT.NONE); |
244 |
scrollComposite.setLayout(new GridLayout(4, false)); |
245 |
flagExpandComposite.setClient(scrollComposite); |
246 |
return scrollComposite; |
247 |
} |
248 |
|
249 |
} |