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 |
* |
40 |
* @author Frank Becker |
41 |
*/ |
42 |
public class BugzillaAttachmentDialog extends SelectionDialog { |
43 |
|
44 |
private final FormToolkit toolkit; |
45 |
|
46 |
private Composite scrollComposite; |
47 |
|
48 |
private ExpandableComposite flagExpandComposite = null; |
49 |
|
50 |
private final TaskAttribute attachment; |
51 |
|
52 |
private final Shell parentShell; |
53 |
|
54 |
private final boolean readOnly; |
55 |
|
56 |
private final AttributeEditorFactory attributeEditorFactory; |
57 |
|
58 |
private static final int LABEL_WIDTH = 120; |
59 |
|
60 |
private static final int COLUMN_GAP = 5; |
61 |
|
62 |
private static final int MULTI_ROW_HEIGHT = 55; |
63 |
|
64 |
private static final int COLUMN_WIDTH = 200; |
65 |
|
66 |
private static final int MULTI_COLUMN_WIDTH = COLUMN_WIDTH + 5 + COLUMN_GAP + LABEL_WIDTH + 5 + COLUMN_WIDTH; |
67 |
|
68 |
public BugzillaAttachmentDialog(Shell parentShell, BugzillaTaskEditorPage editor, AttributeEditorFactory factory, |
69 |
TaskAttribute attachment, boolean readonly) { |
70 |
super(parentShell); |
71 |
this.attachment = attachment; |
72 |
this.parentShell = parentShell; |
73 |
this.readOnly = readonly; |
74 |
attributeEditorFactory = factory; |
75 |
toolkit = new FormToolkit(Display.getCurrent()); |
76 |
this.setTitle(MessageFormat.format(readonly ? Messages.BugzillaAttachmentDialog_DetailTitle |
77 |
: Messages.BugzillaAttachmentDialog_UpdateTitle, attachment.getValue())); |
78 |
} |
79 |
|
80 |
@Override |
81 |
protected Control createDialogArea(Composite parent) { |
82 |
int currentColumn = 1; |
83 |
int columnCount = 4; |
84 |
Composite composite = (Composite) super.createDialogArea(parent); |
85 |
|
86 |
initializeDialogUnits(composite); |
87 |
|
88 |
Composite attributeArea = new Composite(composite, SWT.FLAT); |
89 |
attributeArea.setLayout(new GridLayout(4, false)); |
90 |
createAttributeEditors(currentColumn, columnCount, attributeArea); |
91 |
Composite advancedComposite = createFlagSection(attributeArea); |
92 |
createFlagEditors(columnCount, advancedComposite); |
93 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_URL), currentColumn, columnCount, |
94 |
advancedComposite); |
95 |
createCommntEditor(currentColumn, columnCount, attributeArea); |
96 |
Dialog.applyDialogFont(composite); |
97 |
return composite; |
98 |
} |
99 |
|
100 |
private void createAttributeEditor(TaskAttribute attribute, int currentColumn, int columnCount, |
101 |
Composite attributeArea) { |
102 |
String type = attribute.getMetaData().getType(); |
103 |
if (type != null) { |
104 |
AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, attribute); |
105 |
if (attribute.getId().equals(BugzillaAttribute.TOKEN.getKey()) |
106 |
|| attribute.getId().equals("size") || attribute.getId().equals(TaskAttribute.ATTACHMENT_URL)) { //$NON-NLS-1$ |
107 |
editor.setReadOnly(true); |
108 |
} else { |
109 |
editor.setReadOnly(readOnly); |
110 |
} |
111 |
if (editor.hasLabel()) { |
112 |
editor.createLabelControl(attributeArea, toolkit); |
113 |
Label label = editor.getLabelControl(); |
114 |
label.setBackground(attributeArea.getBackground()); |
115 |
String labelString = editor.getLabel(); |
116 |
if (labelString != null && !labelString.equals("")) { //$NON-NLS-1$ |
117 |
GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH, |
118 |
SWT.DEFAULT).create(); |
119 |
if (currentColumn > 1) { |
120 |
gd.horizontalIndent = COLUMN_GAP; |
121 |
gd.widthHint = LABEL_WIDTH + COLUMN_GAP; |
122 |
} |
123 |
label.setLayoutData(gd); |
124 |
currentColumn++; |
125 |
} |
126 |
} |
127 |
editor.createControl(attributeArea, toolkit); |
128 |
GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false); |
129 |
if (type.equals("shortText") || type.equals("url")) { //$NON-NLS-1$//$NON-NLS-2$ |
130 |
gd.horizontalSpan = 3; |
131 |
} else { |
132 |
gd.horizontalSpan = 1; |
133 |
} |
134 |
editor.getControl().setLayoutData(gd); |
135 |
if (attribute.getId().equals(TaskAttribute.ATTACHMENT_URL)) { |
136 |
editor.getControl().setEnabled(false); |
137 |
} |
138 |
|
139 |
currentColumn += gd.horizontalSpan; |
140 |
currentColumn %= columnCount; |
141 |
} |
142 |
} |
143 |
|
144 |
private void createAttributeEditors(int currentColumn, int columnCount, Composite attributeArea) { |
145 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_DESCRIPTION), currentColumn, |
146 |
columnCount, attributeArea); |
147 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_FILENAME), currentColumn, |
148 |
columnCount, attributeArea); |
149 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_SIZE), currentColumn, columnCount, |
150 |
attributeArea); |
151 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_CONTENT_TYPE), currentColumn, |
152 |
columnCount, attributeArea); |
153 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH), currentColumn, |
154 |
columnCount, attributeArea); |
155 |
createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED), currentColumn, |
156 |
columnCount, attributeArea); |
157 |
} |
158 |
|
159 |
private void createFlagEditors(int columnCount, Composite advancedComposite) { |
160 |
int currentFlagColumn = 1; |
161 |
|
162 |
for (TaskAttribute attribute : attachment.getAttributes().values()) { |
163 |
if (!attribute.getId().startsWith("task.common.kind.flag")) { //$NON-NLS-1$ |
164 |
continue; |
165 |
} |
166 |
String type = attribute.getMetaData().getType(); |
167 |
if (type != null) { |
168 |
AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, attribute); |
169 |
editor.setReadOnly(readOnly); |
170 |
|
171 |
if (editor.hasLabel()) { |
172 |
editor.createLabelControl(advancedComposite, toolkit); |
173 |
Label label = editor.getLabelControl(); |
174 |
label.setBackground(advancedComposite.getBackground()); |
175 |
GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH, |
176 |
SWT.DEFAULT).create(); |
177 |
if (currentFlagColumn > 1) { |
178 |
gd.horizontalIndent = COLUMN_GAP; |
179 |
gd.widthHint = LABEL_WIDTH + COLUMN_GAP; |
180 |
} |
181 |
label.setLayoutData(gd); |
182 |
currentFlagColumn++; |
183 |
} |
184 |
editor.createControl(advancedComposite, toolkit); |
185 |
GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false); |
186 |
gd.widthHint = 150;//COLUMN_WIDTH; |
187 |
gd.horizontalSpan = 3; |
188 |
editor.getControl().setLayoutData(gd); |
189 |
currentFlagColumn += gd.horizontalSpan; |
190 |
currentFlagColumn %= columnCount; |
191 |
} |
192 |
} |
193 |
} |
194 |
|
195 |
private void createCommntEditor(int currentColumn, int columnCount, Composite attributeArea) { |
196 |
TaskAttribute commentAttribute = attachment.getAttribute("comment"); //$NON-NLS-1$ |
197 |
if (commentAttribute == null || readOnly) { |
198 |
return; |
199 |
} |
200 |
String type = commentAttribute.getMetaData().getType(); |
201 |
if (type != null) { |
202 |
AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, commentAttribute); |
203 |
String labelString = editor.getLabel(); |
204 |
if (editor.hasLabel()) { |
205 |
editor.createLabelControl(attributeArea, toolkit); |
206 |
if (!labelString.equals("")) { //$NON-NLS-1$ |
207 |
Label label = editor.getLabelControl(); |
208 |
label.setBackground(attributeArea.getBackground()); |
209 |
GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH, |
210 |
SWT.DEFAULT).create(); |
211 |
if (currentColumn > 1) { |
212 |
gd.horizontalIndent = COLUMN_GAP; |
213 |
gd.widthHint = LABEL_WIDTH + COLUMN_GAP; |
214 |
} |
215 |
label.setLayoutData(gd); |
216 |
} |
217 |
} |
218 |
editor.createControl(attributeArea, toolkit); |
219 |
GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false); |
220 |
gd.heightHint = MULTI_ROW_HEIGHT; |
221 |
gd.widthHint = MULTI_COLUMN_WIDTH; |
222 |
gd.horizontalSpan = columnCount - currentColumn + 1; |
223 |
editor.getControl().setLayoutData(gd); |
224 |
} |
225 |
} |
226 |
|
227 |
private Composite createFlagSection(Composite container) { |
228 |
flagExpandComposite = toolkit.createExpandableComposite(container, ExpandableComposite.COMPACT |
229 |
| ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); |
230 |
flagExpandComposite.setFont(container.getFont()); |
231 |
flagExpandComposite.setBackground(container.getBackground()); |
232 |
flagExpandComposite.setText(Messages.BugzillaTaskAttachmentPage_Advanced); |
233 |
flagExpandComposite.setLayout(new GridLayout(4, false)); |
234 |
GridData g = new GridData(GridData.FILL_HORIZONTAL); |
235 |
g.horizontalSpan = 4; |
236 |
flagExpandComposite.setLayoutData(g); |
237 |
flagExpandComposite.addExpansionListener(new ExpansionAdapter() { |
238 |
@Override |
239 |
public void expansionStateChanged(ExpansionEvent e) { |
240 |
parentShell.getDisplay().getActiveShell().pack(); |
241 |
} |
242 |
}); |
243 |
|
244 |
scrollComposite = new Composite(flagExpandComposite, SWT.NONE); |
245 |
scrollComposite.setLayout(new GridLayout(4, false)); |
246 |
flagExpandComposite.setClient(scrollComposite); |
247 |
return scrollComposite; |
248 |
} |
249 |
|
250 |
} |