0
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.s60tools.creator.dialogs;
|
|
19 |
|
|
20 |
import java.util.Iterator;
|
|
21 |
import java.util.Set;
|
|
22 |
import java.util.Vector;
|
|
23 |
|
|
24 |
import org.eclipse.jface.dialogs.Dialog;
|
|
25 |
import org.eclipse.jface.dialogs.IDialogConstants;
|
|
26 |
import org.eclipse.jface.dialogs.MessageDialog;
|
|
27 |
import org.eclipse.jface.window.IShellProvider;
|
|
28 |
import org.eclipse.swt.SWT;
|
|
29 |
import org.eclipse.swt.SWTException;
|
|
30 |
import org.eclipse.swt.custom.CCombo;
|
|
31 |
import org.eclipse.swt.custom.TableEditor;
|
|
32 |
import org.eclipse.swt.events.ModifyEvent;
|
|
33 |
import org.eclipse.swt.events.ModifyListener;
|
|
34 |
import org.eclipse.swt.events.SelectionAdapter;
|
|
35 |
import org.eclipse.swt.events.SelectionEvent;
|
|
36 |
import org.eclipse.swt.events.SelectionListener;
|
|
37 |
import org.eclipse.swt.events.VerifyEvent;
|
|
38 |
import org.eclipse.swt.events.VerifyListener;
|
|
39 |
import org.eclipse.swt.graphics.Color;
|
|
40 |
import org.eclipse.swt.graphics.Font;
|
|
41 |
import org.eclipse.swt.graphics.FontData;
|
|
42 |
import org.eclipse.swt.graphics.RGB;
|
|
43 |
import org.eclipse.swt.layout.GridData;
|
|
44 |
import org.eclipse.swt.layout.GridLayout;
|
|
45 |
import org.eclipse.swt.layout.RowLayout;
|
|
46 |
import org.eclipse.swt.widgets.Button;
|
|
47 |
import org.eclipse.swt.widgets.Composite;
|
|
48 |
import org.eclipse.swt.widgets.Control;
|
|
49 |
import org.eclipse.swt.widgets.Display;
|
|
50 |
import org.eclipse.swt.widgets.Event;
|
|
51 |
import org.eclipse.swt.widgets.Label;
|
|
52 |
import org.eclipse.swt.widgets.Listener;
|
|
53 |
import org.eclipse.swt.widgets.Shell;
|
|
54 |
import org.eclipse.swt.widgets.Table;
|
|
55 |
import org.eclipse.swt.widgets.TableColumn;
|
|
56 |
import org.eclipse.swt.widgets.TableItem;
|
|
57 |
import org.eclipse.swt.widgets.Text;
|
|
58 |
import org.eclipse.swt.widgets.Widget;
|
|
59 |
import org.eclipse.ui.PlatformUI;
|
|
60 |
|
|
61 |
import com.nokia.s60tools.creator.CreatorActivator;
|
|
62 |
import com.nokia.s60tools.creator.CreatorHelpContextIDs;
|
|
63 |
import com.nokia.s60tools.creator.components.AbstractComponent;
|
|
64 |
import com.nokia.s60tools.creator.components.AbstractValue;
|
|
65 |
import com.nokia.s60tools.creator.components.AbstractVariables;
|
|
66 |
import com.nokia.s60tools.creator.components.AbstractValue.ModeTypes;
|
|
67 |
import com.nokia.s60tools.creator.components.calendar.Calendar;
|
|
68 |
import com.nokia.s60tools.creator.components.contact.Contact;
|
|
69 |
import com.nokia.s60tools.creator.components.contact.ContactGroup;
|
|
70 |
import com.nokia.s60tools.creator.components.contact.ContactSet;
|
|
71 |
import com.nokia.s60tools.creator.components.contact.ContactSetVariables;
|
|
72 |
import com.nokia.s60tools.creator.components.messaging.MailBox;
|
|
73 |
import com.nokia.s60tools.creator.components.messaging.MailBoxVariables;
|
|
74 |
import com.nokia.s60tools.creator.components.messaging.Message;
|
|
75 |
import com.nokia.s60tools.creator.core.CreatorEditorSettings;
|
|
76 |
import com.nokia.s60tools.creator.editors.CreatorScriptEditor;
|
|
77 |
import com.nokia.s60tools.creator.editors.IAddComponentListener;
|
|
78 |
import com.nokia.s60tools.creator.editors.IComponentProvider;
|
|
79 |
import com.nokia.s60tools.creator.util.CreatorEditorConsole;
|
|
80 |
|
|
81 |
/**
|
|
82 |
*
|
|
83 |
*/
|
|
84 |
public abstract class AbstractDialog extends Dialog {
|
|
85 |
|
|
86 |
|
|
87 |
//
|
|
88 |
// Variables for UI texts (column topics)
|
|
89 |
//
|
|
90 |
protected static final String AMOUNT_TXT = "Amount";
|
|
91 |
protected static final String MODE_TXT = "Mode";
|
|
92 |
protected static final String ITEM_VALUE_TXT = "Item value";
|
|
93 |
protected static final String ITEM_TYPE_TXT = "Item type";
|
|
94 |
protected static final String CLEAR_TXT = "Clear";
|
|
95 |
|
|
96 |
//
|
|
97 |
// Variables for UI component lengths
|
|
98 |
//
|
|
99 |
protected static final int TEXT_FIELD_LENGTH = 200;
|
|
100 |
protected static final int AMOUNT_FIELD_LENGTH = 50;
|
|
101 |
private static final int COLUMN_WIDTH_FOR_ONE_CHAR = 10;
|
|
102 |
|
|
103 |
//
|
|
104 |
// Help texts for UI
|
|
105 |
//
|
|
106 |
public static final String POSSIBLE_VALUES_FOR_TXT_PART_1 = "Possible values for '";
|
|
107 |
public static final String POSSIBLE_VALUES_FOR_TXT_PART_2 = "' are: ";
|
|
108 |
public static final String POSSIBLE_VALUES_FOR_TXT_PART_3 = ".";
|
|
109 |
|
|
110 |
|
|
111 |
public static final String MAX_AMOUNT_TEXT = "Max amount";
|
|
112 |
public static final String AMOUNT_FIELD_INFO_TEXT = "If amount field is empty, amount 1 is used.";
|
|
113 |
|
|
114 |
|
|
115 |
//
|
|
116 |
// UI texts
|
|
117 |
//
|
|
118 |
private static final String RANDOM_LEN_MAX = "Max";
|
|
119 |
private static final String RANDOM_LEN_DEFAULT = "Default";
|
|
120 |
private static final String SET_RANDOM_TXT = "Set random";
|
|
121 |
private static final String ADD_ROW_TXT = "Add row";
|
|
122 |
|
|
123 |
|
|
124 |
/**
|
|
125 |
* Unexpected error message
|
|
126 |
*/
|
|
127 |
private static final String UNEXPECTED_ERROR_WHEN_CREATING_TABLE_AREA_ERROR_WAS =
|
|
128 |
"Unexpected error when creating table area, error was: ";
|
|
129 |
|
|
130 |
|
|
131 |
/**
|
|
132 |
* How many lines is shown in dialog by default
|
|
133 |
*/
|
|
134 |
private static final int INITIAL_ITEMS_NUMBER_IN_TABLE = 20;
|
|
135 |
/**
|
|
136 |
* How many items can be in combo (max)
|
|
137 |
*/
|
|
138 |
private static final int MAX_ITEMS_IN_COMBO = 30;
|
|
139 |
|
|
140 |
|
|
141 |
/**
|
|
142 |
* UI help text for refering to connection method
|
|
143 |
*/
|
|
144 |
public static final String CONNECTION_METHOD_NAME_HELP_TEXT = POSSIBLE_VALUES_FOR_TXT_PART_1
|
|
145 |
+MailBoxVariables.CONNECTION_METHOD_NAME
|
|
146 |
+POSSIBLE_VALUES_FOR_TXT_PART_2
|
|
147 |
+"'Default' or any existing " +MailBoxVariables.CONNECTION_METHOD_NAME
|
|
148 |
+POSSIBLE_VALUES_FOR_TXT_PART_3;
|
|
149 |
|
|
150 |
/**
|
|
151 |
* UI help text for refering to incoming and outgoing connection method
|
|
152 |
*/
|
|
153 |
public static final String CONNECTION_METHOD_NAME_IN_AND_OUT_HELP_TEXT = POSSIBLE_VALUES_FOR_TXT_PART_1
|
|
154 |
+MailBoxVariables.INCOMING_CONNECTIONMETHOD_NAME
|
|
155 |
+ " and "
|
|
156 |
+MailBoxVariables.OUTGOING_CONNECTIONMETHOD_NAME
|
|
157 |
+POSSIBLE_VALUES_FOR_TXT_PART_2
|
|
158 |
+"'Default' or any existing " +MailBoxVariables.CONNECTION_METHOD_NAME
|
|
159 |
+POSSIBLE_VALUES_FOR_TXT_PART_3;
|
|
160 |
|
|
161 |
|
|
162 |
//
|
|
163 |
// private fields
|
|
164 |
//
|
|
165 |
|
|
166 |
private AbstractComponent component = null;
|
|
167 |
private boolean isInEditMode;
|
|
168 |
private Color white;
|
|
169 |
private Color grey;
|
|
170 |
protected Table itemsTable;
|
|
171 |
protected Text amoutTxtToComponent;
|
|
172 |
|
|
173 |
private boolean isAmountFieldsEnabled = true;
|
|
174 |
private boolean isRandomFieldsEnabled = true;
|
|
175 |
private IComponentProvider provider = null;
|
|
176 |
private CCombo linkToOtherComponentCombo = null;
|
|
177 |
private boolean isTableEnabled = true;
|
|
178 |
private String tableColumnHeaderAmount;
|
|
179 |
private Text extraNbrToComponent = null;
|
|
180 |
private Text extraTxtToComponent = null;
|
|
181 |
private String labelForExtraNumberField;
|
|
182 |
private String labelForExtraTextField;
|
|
183 |
private boolean wasErrorsWithDatas = false;
|
|
184 |
private Button addContactSetButton = null;
|
|
185 |
private Button addRowButton;
|
|
186 |
|
|
187 |
|
|
188 |
/**
|
|
189 |
* errors
|
|
190 |
*/
|
|
191 |
private Vector<String> errors = null;
|
|
192 |
|
|
193 |
/**
|
|
194 |
* @param parentShell
|
|
195 |
*/
|
|
196 |
private AbstractDialog(IShellProvider parentShell) {
|
|
197 |
super(parentShell);
|
|
198 |
throw new RuntimeException("Not accepted");
|
|
199 |
}
|
|
200 |
|
|
201 |
/**
|
|
202 |
* @param parentShell
|
|
203 |
*/
|
|
204 |
private AbstractDialog(Shell parentShell) {
|
|
205 |
super (parentShell);
|
|
206 |
throw new RuntimeException("Not accepted");
|
|
207 |
}
|
|
208 |
|
|
209 |
|
|
210 |
/**
|
|
211 |
* @param parentShell
|
|
212 |
* @param component
|
|
213 |
*/
|
|
214 |
public AbstractDialog(Shell parentShell, IComponentProvider provider){
|
|
215 |
super(parentShell);
|
|
216 |
this.provider = provider;
|
|
217 |
init();
|
|
218 |
}
|
|
219 |
|
|
220 |
/**
|
|
221 |
* @param parentShell
|
|
222 |
* @param component
|
|
223 |
*/
|
|
224 |
public AbstractDialog(IShellProvider parentShell, IComponentProvider provider){
|
|
225 |
super(parentShell);
|
|
226 |
this.provider = provider;
|
|
227 |
init();
|
|
228 |
}
|
|
229 |
|
|
230 |
|
|
231 |
/**
|
|
232 |
* Init
|
|
233 |
*/
|
|
234 |
private void init(){
|
|
235 |
RGB rgbWhite = new RGB(255, 255, 255);
|
|
236 |
white = new Color(null, rgbWhite);
|
|
237 |
|
|
238 |
//Get grey color from parent
|
|
239 |
grey = super.getParentShell().getBackground();
|
|
240 |
|
|
241 |
setInEditMode(provider.isInEditMode());
|
|
242 |
if(isInEditMode){
|
|
243 |
this.component = provider.getEditable();
|
|
244 |
}
|
|
245 |
|
|
246 |
tableColumnHeaderAmount = AMOUNT_TXT;
|
|
247 |
}
|
|
248 |
|
|
249 |
/**
|
|
250 |
* Set context sensitive help id
|
|
251 |
* @param control
|
|
252 |
* @param id
|
|
253 |
*/
|
|
254 |
protected void setContextSensitiveHelpID(Control control, String id){
|
|
255 |
|
|
256 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(control,id);
|
|
257 |
|
|
258 |
}
|
|
259 |
/**
|
|
260 |
* Set context sensitive help id to item by component type
|
|
261 |
* @param control
|
|
262 |
*/
|
|
263 |
protected void setContextSensitiveHelpIDByComponentType(Control control){
|
|
264 |
|
|
265 |
if(getComponent() instanceof ContactSet){
|
|
266 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(control,CreatorHelpContextIDs.CREATOR_HELP_CONTACT_SET);
|
|
267 |
}else if(getComponent() instanceof Contact || getComponent() instanceof ContactGroup){
|
|
268 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(control,CreatorHelpContextIDs.CREATOR_HELP_CONTACTS);
|
|
269 |
}else if(getComponent() instanceof Message){
|
|
270 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(control,CreatorHelpContextIDs.CREATOR_HELP_MESSAGES);
|
|
271 |
}else if(getComponent() instanceof Calendar){
|
|
272 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(control,CreatorHelpContextIDs.CREATOR_HELP_CALENDAR);
|
|
273 |
}else{
|
|
274 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(control,CreatorHelpContextIDs.CREATOR_HELP_GENERIC_COMPONENT);
|
|
275 |
}
|
|
276 |
|
|
277 |
}
|
|
278 |
|
|
279 |
/**
|
|
280 |
* SuperClass for all Dialogs holds instance to component created or edited.
|
|
281 |
* Implementing classes will know what type of {@link AbstractComponent} needs to be handle.
|
|
282 |
* @return component
|
|
283 |
*/
|
|
284 |
public AbstractComponent getComponent() {
|
|
285 |
return component;
|
|
286 |
}
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
/**
|
|
291 |
* Set component
|
|
292 |
* @param component
|
|
293 |
*/
|
|
294 |
protected void setComponent(AbstractComponent component) {
|
|
295 |
this.component = component;
|
|
296 |
}
|
|
297 |
|
|
298 |
/**
|
|
299 |
* Every dialog must be able to create a new Component by it's own type.
|
|
300 |
* @return AbstractComponent
|
|
301 |
*/
|
|
302 |
protected abstract AbstractComponent createNewComponent();
|
|
303 |
|
|
304 |
/**
|
|
305 |
* Every dialog must be able to create a new Value by it's own type.
|
|
306 |
* @return AbstractValue
|
|
307 |
*/
|
|
308 |
protected abstract AbstractValue createNewValue(String type, String value, String random, String amount);
|
|
309 |
|
|
310 |
/**
|
|
311 |
* Is Dialog in Edit mode (or add new mode)
|
|
312 |
* @return true if dialog is in edit mode, false otherwise
|
|
313 |
*/
|
|
314 |
protected boolean isInEditMode() {
|
|
315 |
return isInEditMode;
|
|
316 |
}
|
|
317 |
|
|
318 |
|
|
319 |
/**
|
|
320 |
* Set Dialog to edit mode
|
|
321 |
* @param isInEditMode true if Dialog is in edit mode
|
|
322 |
*/
|
|
323 |
protected void setInEditMode(boolean isInEditMode) {
|
|
324 |
this.isInEditMode = isInEditMode;
|
|
325 |
}
|
|
326 |
|
|
327 |
|
|
328 |
/**
|
|
329 |
* Selects given value as default to Combo
|
|
330 |
* @param values
|
|
331 |
* @param combo
|
|
332 |
* @param value
|
|
333 |
*/
|
|
334 |
protected void setComboSelection(String[] values, CCombo combo, String value) {
|
|
335 |
if (values!= null && combo != null && value != null && !value.equals(AbstractValue.EMPTY_STRING)) {
|
|
336 |
for (int i = 0; i < values.length; i++) {
|
|
337 |
if (value.equalsIgnoreCase(values[i])) {
|
|
338 |
combo.select(i);
|
|
339 |
break;
|
|
340 |
}
|
|
341 |
}
|
|
342 |
}
|
|
343 |
}
|
|
344 |
|
|
345 |
/* (non-Javadoc)
|
|
346 |
* @see org.eclipse.jface.window.Window#open()
|
|
347 |
*/
|
|
348 |
public int open(){
|
|
349 |
return super.open();
|
|
350 |
}
|
|
351 |
|
|
352 |
/**
|
|
353 |
* @return Listener for making sure that text field contains only numbers
|
|
354 |
* Also back space and delete buttons is allowed
|
|
355 |
*/
|
|
356 |
protected VerifyListener getNumberVerifyListener() {
|
|
357 |
return new VerifyListener() {
|
|
358 |
public void verifyText(VerifyEvent e) {
|
|
359 |
char c = e.character;
|
|
360 |
int i = c; // 0=48, 9=57, del = 127, backspace = 8
|
|
361 |
//If event is "" it's a clear command and must be accepted, otherwise only numbers, del and backspace is accepted commands
|
|
362 |
if ((e.text != null && e.text.equals(AbstractValue.EMPTY_STRING) )|| (i >= 48 && i <= 57) || i == 8 || i == 127) {
|
|
363 |
e.doit = true;// If text is not number, don't do it (set
|
|
364 |
// text just typed)
|
|
365 |
} else {
|
|
366 |
e.doit = false;
|
|
367 |
}
|
|
368 |
}
|
|
369 |
};
|
|
370 |
}
|
|
371 |
|
|
372 |
/**
|
|
373 |
* Check if valueText should be enabled or not and setting text to it
|
|
374 |
*
|
|
375 |
* @param valueTxt
|
|
376 |
* @param randomTxt
|
|
377 |
*/
|
|
378 |
protected void setValueTextAndEnabling(final Text valueTxt,
|
|
379 |
String txtToValue, String randomTxt) {
|
|
380 |
|
|
381 |
//just in case taking of valueText size limit, if there was user defined on, other text will be also limited
|
|
382 |
valueTxt.setTextLimit(Text.LIMIT);
|
|
383 |
|
|
384 |
// If random is selected, text field is disabled and showing that random
|
|
385 |
// mode is on
|
|
386 |
if (randomTxt.equals(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH)
|
|
387 |
|| randomTxt
|
|
388 |
.equals(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH_LONG))
|
|
389 |
{
|
|
390 |
removeNumberVerifyListener(valueTxt);//If there is number verify listener, that must be removed
|
|
391 |
valueTxt.setText(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH_LONG);
|
|
392 |
valueTxt.setEnabled(false);
|
|
393 |
}
|
|
394 |
else if (randomTxt.equals(AbstractValue.RANDOM_TEXT_MAX_LENGTH)
|
|
395 |
|| randomTxt.equals(AbstractValue.RANDOM_TEXT_MAX_LENGTH_LONG))
|
|
396 |
{
|
|
397 |
removeNumberVerifyListener(valueTxt);//If there is number verify listener, that must be removed
|
|
398 |
valueTxt.setText(AbstractValue.RANDOM_TEXT_MAX_LENGTH_LONG);
|
|
399 |
valueTxt.setEnabled(false);
|
|
400 |
}
|
|
401 |
else if (randomTxt.equals(AbstractValue.RANDOM_TEXT_USER_DEFINED_LENGTH)
|
|
402 |
|| randomTxt.equals(AbstractValue.RANDOM_TEXT_USER_DEFINED_LENGTH_LONG))
|
|
403 |
{
|
|
404 |
valueTxt.setEnabled(true);
|
|
405 |
try {
|
|
406 |
Integer.parseInt(txtToValue);
|
|
407 |
valueTxt.setText(txtToValue);
|
|
408 |
} catch (NumberFormatException e) {
|
|
409 |
// When there was a text, an error will occur, skipping that one
|
|
410 |
valueTxt.setText("" +AbstractValue.USER_DEFINED_DEFAULT_LENGTH);
|
|
411 |
valueTxt.setFocus();
|
|
412 |
valueTxt.selectAll();
|
|
413 |
}
|
|
414 |
//even if given data was valid or not, we add verify listener
|
|
415 |
finally{
|
|
416 |
//We need number verify listener when user defined len is selected
|
|
417 |
valueTxt.addVerifyListener(getNumberVerifyListener());
|
|
418 |
//When field is for custom random length field, text limit will be 9
|
|
419 |
valueTxt.setTextLimit(9);
|
|
420 |
}
|
|
421 |
}
|
|
422 |
|
|
423 |
// If just started edit mode, must put initial value to txt field
|
|
424 |
else if (txtToValue != null && txtToValue.trim().length() > 0) {
|
|
425 |
removeNumberVerifyListener(valueTxt);//If there is number verify listener, that must be removed
|
|
426 |
valueTxt.setEnabled(true);
|
|
427 |
valueTxt.setText(CreatorEditorSettings.getInstance()
|
|
428 |
.replaceEntitiesWithChars(txtToValue));
|
|
429 |
}
|
|
430 |
// else value must be enabled, and if there was a random mode txt,
|
|
431 |
// cleaning in
|
|
432 |
else {
|
|
433 |
removeNumberVerifyListener(valueTxt);//If there is number verify listener, that must be removed
|
|
434 |
valueTxt.setEnabled(true);
|
|
435 |
if (valueTxt.getText() != null
|
|
436 |
&& (valueTxt.getText().equals(
|
|
437 |
AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH)
|
|
438 |
|| valueTxt.getText().equals(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH_LONG)
|
|
439 |
|| valueTxt.getText().equals(AbstractValue.RANDOM_TEXT_MAX_LENGTH))
|
|
440 |
|| valueTxt.getText().equals(AbstractValue.RANDOM_TEXT_MAX_LENGTH_LONG)
|
|
441 |
)
|
|
442 |
{
|
|
443 |
valueTxt.setText(AbstractValue.EMPTY_STRING);
|
|
444 |
}
|
|
445 |
}
|
|
446 |
|
|
447 |
|
|
448 |
}
|
|
449 |
|
|
450 |
/**
|
|
451 |
* Check if valueText should be enabled or not and setting text to it
|
|
452 |
*
|
|
453 |
* @param valueCombo
|
|
454 |
* @param randomTxt
|
|
455 |
*/
|
|
456 |
protected void setValueTextAndEnabling(final CCombo valueCombo,
|
|
457 |
String txtToValue, String randomTxt, String typeComboSelection) {
|
|
458 |
|
|
459 |
|
|
460 |
// If random is selected, text field is disabled and showing that random
|
|
461 |
// mode is on. With fixed values, random lenght cannot be definede, so it allways is
|
|
462 |
//random with default lenght
|
|
463 |
boolean isRandomValue = CreatorEditorSettings.isRandomText(randomTxt);
|
|
464 |
|
|
465 |
if (isRandomValue )
|
|
466 |
{
|
|
467 |
valueCombo.setText(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH_LONG);
|
|
468 |
valueCombo.setEnabled(false);
|
|
469 |
}
|
|
470 |
|
|
471 |
|
|
472 |
// If just started edit mode, must put initial value to txt field
|
|
473 |
else if (txtToValue != null && txtToValue.trim().length() > 0) {
|
|
474 |
|
|
475 |
//When type is contact set reference, selection must be done with contactsetref as String, not by its value, which is just its id, e.g. "1"
|
|
476 |
boolean isContactSetReference = CreatorEditorSettings.isContactSetReference(typeComboSelection);
|
|
477 |
String selection;
|
|
478 |
if(isContactSetReference){
|
|
479 |
selection = getContactSetStringById(txtToValue);
|
|
480 |
}else{
|
|
481 |
selection = txtToValue;
|
|
482 |
}
|
|
483 |
valueCombo.setEnabled(true);
|
|
484 |
valueCombo.setText(AbstractValue.EMPTY_STRING);
|
|
485 |
String items[] = valueCombo.getItems();
|
|
486 |
if(isContactSetReference && selection == null){
|
|
487 |
valueCombo.setText(AbstractValue.EMPTY_STRING);
|
|
488 |
String errMsg = typeComboSelection
|
|
489 |
+" can not be set, because contact-set: '" +txtToValue +"' was not found.";
|
|
490 |
CreatorEditorConsole.getInstance().println(errMsg , CreatorEditorConsole.MSG_ERROR);
|
|
491 |
addError(errMsg);
|
|
492 |
|
|
493 |
}else{
|
|
494 |
for (int i = 0; i < items.length; i++) {
|
|
495 |
if(selection.equalsIgnoreCase(items[i])){
|
|
496 |
valueCombo.setText(selection);
|
|
497 |
break;
|
|
498 |
}
|
|
499 |
}
|
|
500 |
}
|
|
501 |
|
|
502 |
}
|
|
503 |
// else value must be enabled, and if there was a random mode txt,
|
|
504 |
// cleaning in
|
|
505 |
else {
|
|
506 |
valueCombo.setEnabled(true);
|
|
507 |
if (valueCombo.getText() != null
|
|
508 |
&& (valueCombo.getText().equals(
|
|
509 |
AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH)
|
|
510 |
|| valueCombo.getText().equals(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH_LONG)
|
|
511 |
|| valueCombo.getText().equals(AbstractValue.RANDOM_TEXT_MAX_LENGTH))
|
|
512 |
|| valueCombo.getText().equals(AbstractValue.RANDOM_TEXT_MAX_LENGTH_LONG)
|
|
513 |
|| valueCombo.getText().equals(AbstractValue.RANDOM_TEXT)
|
|
514 |
)
|
|
515 |
{
|
|
516 |
valueCombo.setText(AbstractValue.EMPTY_STRING);
|
|
517 |
}
|
|
518 |
}
|
|
519 |
|
|
520 |
|
|
521 |
}
|
|
522 |
|
|
523 |
/**
|
|
524 |
* Remove verify listener(s) from widget
|
|
525 |
* @param widget
|
|
526 |
*/
|
|
527 |
private void removeNumberVerifyListener(final Widget widget) {
|
|
528 |
if( widget.isListening(SWT.Verify)){
|
|
529 |
Listener [] listeners = widget.getListeners(SWT.Verify);
|
|
530 |
for (int i = 0; i < listeners.length; i++) {
|
|
531 |
widget.removeListener(SWT.Verify, listeners[i]);
|
|
532 |
}
|
|
533 |
}
|
|
534 |
}
|
|
535 |
|
|
536 |
|
|
537 |
/**
|
|
538 |
* @return white color
|
|
539 |
*/
|
|
540 |
protected Color getWhite() {
|
|
541 |
return white;
|
|
542 |
}
|
|
543 |
|
|
544 |
/**
|
|
545 |
* @return grey color
|
|
546 |
*/
|
|
547 |
protected Color getGrey() {
|
|
548 |
return grey;
|
|
549 |
}
|
|
550 |
|
|
551 |
/**
|
|
552 |
* Create table columns with header names:
|
|
553 |
* Item Type, Item Value, Random, Amount
|
|
554 |
*/
|
|
555 |
protected void createTableColums() {
|
|
556 |
//
|
|
557 |
//Create columns, set column widths
|
|
558 |
//
|
|
559 |
TableColumn columnType = new TableColumn(itemsTable, SWT.NONE);
|
|
560 |
columnType.setWidth (200);
|
|
561 |
columnType.setText(ITEM_TYPE_TXT);
|
|
562 |
TableColumn columnValue = new TableColumn(itemsTable, SWT.NONE);
|
|
563 |
columnValue.setWidth (300);
|
|
564 |
columnValue.setText(ITEM_VALUE_TXT);
|
|
565 |
TableColumn columnMode = new TableColumn(itemsTable, SWT.CENTER);
|
|
566 |
columnMode.setWidth (180);
|
|
567 |
columnMode.setText(MODE_TXT);
|
|
568 |
TableColumn columnAmount = new TableColumn(itemsTable, SWT.NONE);
|
|
569 |
columnAmount.setWidth (tableColumnHeaderAmount.length() * COLUMN_WIDTH_FOR_ONE_CHAR);
|
|
570 |
columnAmount.setText(tableColumnHeaderAmount);
|
|
571 |
|
|
572 |
//REMOVE btn
|
|
573 |
TableColumn columnRemove = new TableColumn(itemsTable, SWT.NONE);
|
|
574 |
columnRemove.setWidth (40);
|
|
575 |
}
|
|
576 |
|
|
577 |
/**
|
|
578 |
* Create a empty row to table
|
|
579 |
*/
|
|
580 |
protected void addRow(boolean openItemType, boolean setFocusToRow) throws Exception{
|
|
581 |
addRow(AbstractValue.EMPTY_STRING, AbstractValue.EMPTY_STRING,
|
|
582 |
AbstractValue.EMPTY_STRING, AbstractValue.EMPTY_STRING, openItemType, setFocusToRow);
|
|
583 |
}
|
|
584 |
|
|
585 |
/**
|
|
586 |
* Create a row to table, and setting values to rows (if needed)
|
|
587 |
* @param key
|
|
588 |
* @param value
|
|
589 |
*/
|
|
590 |
protected void addRow(String key, AbstractValue value, boolean setFocusToRow) throws Exception{
|
|
591 |
|
|
592 |
String valueStr = value.getValue();
|
|
593 |
|
|
594 |
if(value.getModeType() == ModeTypes.RandomTypeUserDefinedLength){
|
|
595 |
valueStr = "" +value.getRandomValueLenght();
|
|
596 |
}
|
|
597 |
addRow(key, valueStr, value.getModeValueText(), ""+ value.getAmount(), true, setFocusToRow );
|
|
598 |
}
|
|
599 |
|
|
600 |
/**
|
|
601 |
* Get item types allready existing in dialog
|
|
602 |
* @return
|
|
603 |
*/
|
|
604 |
private String [] getAddedItems(){
|
|
605 |
|
|
606 |
|
|
607 |
Vector<String> addedItems = new Vector<String>();
|
|
608 |
if(itemsTable != null){
|
|
609 |
|
|
610 |
TableItem [] items = itemsTable.getItems();
|
|
611 |
|
|
612 |
for (int i = 0; i < items.length; i++) {
|
|
613 |
|
|
614 |
TableItem item = items[i];
|
|
615 |
|
|
616 |
if(item != null){
|
|
617 |
|
|
618 |
String key = item.getText(0);
|
|
619 |
addedItems.add(key);
|
|
620 |
|
|
621 |
}
|
|
622 |
}
|
|
623 |
}
|
|
624 |
return (String[])addedItems.toArray(new String[0]);
|
|
625 |
}
|
|
626 |
|
|
627 |
/**
|
|
628 |
* Get Item types (showable names) as String.
|
|
629 |
* @return item names
|
|
630 |
* @param addedItems items allready added to Script
|
|
631 |
*/
|
|
632 |
private String [] getItemTypesAsString(String [] addedItems){
|
|
633 |
|
|
634 |
String[] itemsString = getItemTypesAsString();
|
|
635 |
|
|
636 |
if(addedItems == null || addedItems.length == 0){
|
|
637 |
return itemsString;
|
|
638 |
}
|
|
639 |
|
|
640 |
Vector<String> items = new Vector<String>(itemsString.length);
|
|
641 |
for (int i = 0; i < itemsString.length; i++) {
|
|
642 |
items.add(itemsString[i]);
|
|
643 |
}
|
|
644 |
|
|
645 |
//Checking what items are currently added and what is supporting only one item in one script
|
|
646 |
|
|
647 |
for (int i = 0; i < addedItems.length; i++) {
|
|
648 |
int itemMaxOccur = getComponent().itemMaxOccur(addedItems[i]);
|
|
649 |
|
|
650 |
if(itemMaxOccur == 1){
|
|
651 |
items.remove(addedItems[i]);
|
|
652 |
}
|
|
653 |
}
|
|
654 |
|
|
655 |
return (String[]) items.toArray(new String[0]);
|
|
656 |
}
|
|
657 |
|
|
658 |
|
|
659 |
/**
|
|
660 |
* Check item amount enablation by item name
|
|
661 |
* @param itemName
|
|
662 |
* @param amout Text
|
|
663 |
* @return <code>true</code> if enabled, <code>false</code> otherwise.
|
|
664 |
*/
|
|
665 |
private void setAmountTextEnabletion(String itemName, Text amountText){
|
|
666 |
|
|
667 |
int itemMaxOccur = getComponent().itemMaxOccur(itemName);
|
|
668 |
boolean enable = (itemMaxOccur == 1) ? false : true;
|
|
669 |
amountText.setEnabled(enable);
|
|
670 |
|
|
671 |
if(!enable){
|
|
672 |
amountText.setBackground(getGrey());
|
|
673 |
}else{
|
|
674 |
amountText.setBackground(getWhite());
|
|
675 |
}
|
|
676 |
|
|
677 |
}
|
|
678 |
|
|
679 |
/**
|
|
680 |
* Get Item types (showable names) as String.
|
|
681 |
* @return item names
|
|
682 |
*/
|
|
683 |
protected abstract String [] getItemTypesAsString();
|
|
684 |
|
|
685 |
/**
|
|
686 |
* Get Item values (showable names)
|
|
687 |
* @param itemType - one of types given by {@link #getItemTypesAsString()}
|
|
688 |
* @return item names if itemType has fixed values or contac-set references
|
|
689 |
* or <code>null</code> if itemType has no fixed values.
|
|
690 |
*/
|
|
691 |
private String [] getItemValueAsString(String itemType){
|
|
692 |
|
|
693 |
String[] valuesForItemType;
|
|
694 |
|
|
695 |
//If item is contact set reference, returning
|
|
696 |
if(CreatorEditorSettings.isContactSetReference(itemType)){
|
|
697 |
valuesForItemType = getContactSetsAsString();
|
|
698 |
if(valuesForItemType == null){
|
|
699 |
valuesForItemType=new String[]{AbstractValue.EMPTY_STRING};
|
|
700 |
}
|
|
701 |
}
|
|
702 |
else{
|
|
703 |
valuesForItemType = getComponent().getValuesForItemType(itemType);
|
|
704 |
}
|
|
705 |
return valuesForItemType;
|
|
706 |
}
|
|
707 |
|
|
708 |
|
|
709 |
|
|
710 |
/**
|
|
711 |
* Create a row to table, and setting values to rows (if needed)
|
|
712 |
* @param key
|
|
713 |
* @param value
|
|
714 |
* @param randomValueText
|
|
715 |
* @param amount
|
|
716 |
*/
|
|
717 |
private void addRow(String key, String value, String randomValueText,
|
|
718 |
String amount, boolean openItemType, boolean setFocusToRow) throws Exception{
|
|
719 |
|
|
720 |
String[] allreadyAddedItems = getAddedItems();
|
|
721 |
String[] itemTypesAsString = getItemTypesAsString(allreadyAddedItems);
|
|
722 |
|
|
723 |
//If there is allready all items supported added to table, adding row wont affect (Might occurr when "Add Row" is pushed
|
|
724 |
if(itemTypesAsString == null || itemTypesAsString.length < 1
|
|
725 |
&& key.equals(AbstractValue.EMPTY_STRING) && value.equals(AbstractValue.EMPTY_STRING)){
|
|
726 |
return;
|
|
727 |
}
|
|
728 |
|
|
729 |
final TableItem item = new TableItem (itemsTable, SWT.NONE);
|
|
730 |
final int itemIndex = itemsTable.indexOf(item);
|
|
731 |
|
|
732 |
|
|
733 |
//
|
|
734 |
//CCombo for selecting item type
|
|
735 |
//
|
|
736 |
|
|
737 |
TableEditor typeComboEditor = new TableEditor(itemsTable);
|
|
738 |
// Item names
|
|
739 |
final CCombo typeCombo = new CCombo(itemsTable, SWT.READ_ONLY);
|
|
740 |
//Allready added items will be update after all lines are added.
|
|
741 |
typeCombo.setItems(itemTypesAsString);
|
|
742 |
int visibleItemsCount = itemTypesAsString.length;
|
|
743 |
if(visibleItemsCount > 30){
|
|
744 |
visibleItemsCount=30;
|
|
745 |
}
|
|
746 |
typeCombo.setVisibleItemCount(visibleItemsCount);
|
|
747 |
final String typeComboSelection = getTypeComboSelection(key, itemIndex, openItemType);
|
|
748 |
typeCombo.setText(typeComboSelection);//// Select the previously selected item from the cell: combo.select(combo.indexOf(item.getText(column)));
|
|
749 |
typeCombo.setBackground(getWhite());
|
|
750 |
item.setText(0, typeCombo.getText());
|
|
751 |
|
|
752 |
typeComboEditor.grabHorizontal = true;
|
|
753 |
typeComboEditor.setEditor(typeCombo, item, 0);
|
|
754 |
|
|
755 |
|
|
756 |
//
|
|
757 |
//Text for typing item value
|
|
758 |
//
|
|
759 |
TableEditor valueEditor = new TableEditor(itemsTable);
|
|
760 |
|
|
761 |
//checking if text or combo is needed
|
|
762 |
String [] fixedValuesForType = getItemValueAsString(typeComboSelection);
|
|
763 |
boolean isValuesInCombo = fixedValuesForType != null && fixedValuesForType.length > 0;
|
|
764 |
Text valueTxt = null;
|
|
765 |
CCombo valueCombo = null;
|
|
766 |
|
|
767 |
if(isValuesInCombo){
|
|
768 |
// Adding action to clear Button
|
|
769 |
valueCombo = addValueComboToTable(fixedValuesForType, value,
|
|
770 |
item, randomValueText, typeComboSelection);
|
|
771 |
valueEditor.grabHorizontal = true;
|
|
772 |
valueEditor.setEditor(valueCombo, item, 1);
|
|
773 |
|
|
774 |
|
|
775 |
}else{
|
|
776 |
valueTxt = createValueText(value, randomValueText,
|
|
777 |
setFocusToRow, item, typeComboSelection);
|
|
778 |
valueEditor.grabHorizontal = true;
|
|
779 |
valueEditor.setEditor(valueTxt, item, 1);
|
|
780 |
|
|
781 |
}
|
|
782 |
|
|
783 |
|
|
784 |
//
|
|
785 |
// CCombo for Random value selection.
|
|
786 |
//
|
|
787 |
// selecting random, max len, normal len, or no selection.
|
|
788 |
// If random is selected, disabling item value combo
|
|
789 |
//
|
|
790 |
|
|
791 |
TableEditor modeEditor = new TableEditor(itemsTable);
|
|
792 |
final CCombo modeCombo = new CCombo(itemsTable, SWT.READ_ONLY );
|
|
793 |
String[] modeValues = getModeValues(isValuesInCombo, typeComboSelection);
|
|
794 |
modeCombo.setItems(modeValues);
|
|
795 |
|
|
796 |
modeCombo.setText(getModeComboSelection(randomValueText, modeValues));
|
|
797 |
|
|
798 |
item.setText(2, modeCombo.getText());
|
|
799 |
modeCombo.setBackground(getWhite());
|
|
800 |
|
|
801 |
modeEditor.grabHorizontal = true;
|
|
802 |
modeEditor.setEditor(modeCombo, item, 2);
|
|
803 |
|
|
804 |
modeCombo.setEnabled(isRandomFieldsEnabled);
|
|
805 |
if(!isRandomFieldsEnabled){
|
|
806 |
modeCombo.setBackground(getGrey());
|
|
807 |
}else{
|
|
808 |
modeCombo.setBackground(getWhite());
|
|
809 |
}
|
|
810 |
|
|
811 |
//
|
|
812 |
//Text field for Amount text
|
|
813 |
//
|
|
814 |
|
|
815 |
TableEditor amountEditor = new TableEditor(itemsTable);
|
|
816 |
final Text amountTxt = new Text(itemsTable, SWT.NONE);
|
|
817 |
amountTxt.setTextLimit(5);
|
|
818 |
//don't show if amount is not set (is 0)
|
|
819 |
if(!amount.equals("0")){
|
|
820 |
amountTxt.setText(amount);
|
|
821 |
}
|
|
822 |
item.setText(3, amountTxt.getText());
|
|
823 |
|
|
824 |
// Verify that amount is typed with numbers
|
|
825 |
amountTxt.addVerifyListener(getNumberVerifyListener());
|
|
826 |
|
|
827 |
//Update item when modify
|
|
828 |
amountTxt.addModifyListener(new ModifyListener() {
|
|
829 |
public void modifyText(ModifyEvent e) {
|
|
830 |
item.setText(3, amountTxt.getText());
|
|
831 |
}
|
|
832 |
});
|
|
833 |
|
|
834 |
//In some cases amount fields is not enabled.
|
|
835 |
//Future improvement idea, possibility to enable/disable amountTxt by selected type.
|
|
836 |
if(CreatorEditorSettings.isContactSetReference(key) || CreatorEditorSettings.isContactSetReference(typeComboSelection)){
|
|
837 |
amountTxt.setEnabled(true);//always enabled with contact set reference
|
|
838 |
modeCombo.setEnabled(false);
|
|
839 |
modeCombo.setBackground(getGrey());
|
|
840 |
}
|
|
841 |
else if(!isAmountFieldsEnabled){
|
|
842 |
setModeComboEnablation(typeComboSelection, modeCombo);
|
|
843 |
amountTxt.setEnabled(isAmountFieldsEnabled);
|
|
844 |
}
|
|
845 |
else{
|
|
846 |
setModeComboEnablation(typeComboSelection, modeCombo);
|
|
847 |
setAmountTextEnabletion(typeComboSelection, amountTxt);
|
|
848 |
}
|
|
849 |
|
|
850 |
|
|
851 |
amountEditor.grabHorizontal = true;
|
|
852 |
amountEditor.setEditor(amountTxt, item, 3);
|
|
853 |
|
|
854 |
//
|
|
855 |
// Remove btn
|
|
856 |
//
|
|
857 |
TableEditor clrBtnEditor = new TableEditor(itemsTable);
|
|
858 |
final Button clearBtn = new Button(itemsTable, SWT.PUSH);
|
|
859 |
clearBtn.setLayoutData(new GridData( GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
|
|
860 |
clearBtn.setFont(getButtonFont());
|
|
861 |
clearBtn.setText(CLEAR_TXT);
|
|
862 |
clearBtn.pack ();//This must be called, otherwise button is not visible
|
|
863 |
clrBtnEditor.minimumWidth = clearBtn.getSize ().x + 5;//Using +5 to fit button precisely to column
|
|
864 |
clrBtnEditor.horizontalAlignment = SWT.CENTER;
|
|
865 |
|
|
866 |
|
|
867 |
//Setting all listeners to item value, depending on item type, listeners will be for
|
|
868 |
//Text or CCombo type of value.
|
|
869 |
setItemValueListeners(item, clrBtnEditor, valueEditor, typeCombo, fixedValuesForType,
|
|
870 |
isValuesInCombo, valueTxt, valueCombo, modeCombo, amountTxt,
|
|
871 |
clearBtn);
|
|
872 |
|
|
873 |
clrBtnEditor.setEditor(clearBtn, item, 4);
|
|
874 |
|
|
875 |
// Update item when modify
|
|
876 |
typeCombo.addSelectionListener(new TypeComboSelectionListener(item,
|
|
877 |
clrBtnEditor, valueEditor, typeCombo, valueTxt, valueCombo,
|
|
878 |
modeCombo, amountTxt, clearBtn));
|
|
879 |
|
|
880 |
itemsTable.addListener(SWT.SetData, new TypeComboItemsSetterListener(typeCombo));
|
|
881 |
|
|
882 |
setContextSensitiveHelpIDByComponentType(typeCombo);
|
|
883 |
setContextSensitiveHelpID(modeCombo, CreatorHelpContextIDs.CREATOR_HELP_RANDOM_VALUES);
|
|
884 |
setContextSensitiveHelpIDByComponentType(amountTxt);
|
|
885 |
setContextSensitiveHelpIDByComponentType(clearBtn);
|
|
886 |
}
|
|
887 |
|
|
888 |
private void setModeComboEnablation(final String typeComboSelection,
|
|
889 |
final CCombo modeCombo) {
|
|
890 |
boolean isModeEnabled = getComponent().getVariables().isModeEnabledForKey(typeComboSelection);
|
|
891 |
modeCombo.setEnabled(isModeEnabled);
|
|
892 |
if(!isModeEnabled){
|
|
893 |
modeCombo.setBackground(getGrey());
|
|
894 |
}else{
|
|
895 |
modeCombo.setBackground(getWhite());
|
|
896 |
}
|
|
897 |
}
|
|
898 |
|
|
899 |
/**
|
|
900 |
* Get selection for mode combo
|
|
901 |
* @param modeText
|
|
902 |
* @param modeValues
|
|
903 |
* @return
|
|
904 |
*/
|
|
905 |
private String getModeComboSelection(String modeText, String [] modeValues) {
|
|
906 |
|
|
907 |
if(modeText != null && !modeText.equals(AbstractValue.EMPTY_STRING)){
|
|
908 |
for (int i = 0; i < modeValues.length; i++) {
|
|
909 |
if(modeText.equalsIgnoreCase(modeValues[i])){
|
|
910 |
return modeText;
|
|
911 |
}
|
|
912 |
}
|
|
913 |
}
|
|
914 |
|
|
915 |
return modeValues[0];
|
|
916 |
}
|
|
917 |
|
|
918 |
/**
|
|
919 |
* Get values for mode combo
|
|
920 |
* @param isValuesInCombo
|
|
921 |
* @param typeComboSelection
|
|
922 |
* @return values for mode combo
|
|
923 |
*/
|
|
924 |
private String[] getModeValues(boolean isValuesInCombo, String typeComboSelection) {
|
|
925 |
|
|
926 |
boolean incValueSupported = isTypeSupportingIncValueForeEachCopy(typeComboSelection);
|
|
927 |
|
|
928 |
String[] modeValues;
|
|
929 |
|
|
930 |
if(!incValueSupported && isValuesInCombo){
|
|
931 |
modeValues = AbstractValue.getModeValuesForFixedValues();
|
|
932 |
}
|
|
933 |
else if(!incValueSupported){
|
|
934 |
modeValues = AbstractValue.getModeValues();
|
|
935 |
}
|
|
936 |
//else incValueSupported == true
|
|
937 |
else{
|
|
938 |
modeValues = AbstractValue.getModeValuesForSupportingIncValueForeEachCopy();
|
|
939 |
}
|
|
940 |
|
|
941 |
return modeValues;
|
|
942 |
}
|
|
943 |
|
|
944 |
/**
|
|
945 |
* Check if component is supporting <code>incvalueforeachcopy</code> parameter.
|
|
946 |
* @param type
|
|
947 |
* @return <code>true</code> if supporting.
|
|
948 |
*/
|
|
949 |
private boolean isTypeSupportingIncValueForeEachCopy (String type){
|
|
950 |
|
|
951 |
return getComponent().isTypeSupportingIncValueForEachCopy(type);
|
|
952 |
|
|
953 |
}
|
|
954 |
|
|
955 |
/**
|
|
956 |
* Set listeners related to value item (Text or CCombo)
|
|
957 |
* @param item
|
|
958 |
* @param clrButtonEditor
|
|
959 |
* @param valueEditor
|
|
960 |
* @param typeCombo
|
|
961 |
* @param fixedValuesForType
|
|
962 |
* @param isValuesInCombo
|
|
963 |
* @param valueTxt
|
|
964 |
* @param valueCombo
|
|
965 |
* @param modeCombo
|
|
966 |
* @param amountTxt
|
|
967 |
* @param clearBtn
|
|
968 |
*/
|
|
969 |
private void setItemValueListeners(final TableItem item,
|
|
970 |
TableEditor clrButtonEditor, TableEditor valueEditor, final CCombo typeCombo,
|
|
971 |
String[] fixedValuesForType, boolean isValuesInCombo,
|
|
972 |
Text valueTxt, CCombo valueCombo, final CCombo modeCombo,
|
|
973 |
final Text amountTxt, final Button clearBtn) {
|
|
974 |
|
|
975 |
//
|
|
976 |
//First remove existing listeners, so there will be no extra listeners with non existing objects
|
|
977 |
//
|
|
978 |
|
|
979 |
Listener[] listeners = modeCombo.getListeners(SWT.Selection);
|
|
980 |
for (int i = 0; i < listeners.length; i++) {
|
|
981 |
modeCombo.removeListener(SWT.Selection, listeners[i]);
|
|
982 |
}
|
|
983 |
listeners = clearBtn.getListeners(SWT.Selection);
|
|
984 |
for (int i = 0; i < listeners.length; i++) {
|
|
985 |
clearBtn.removeListener(SWT.Selection, listeners[i]);
|
|
986 |
}
|
|
987 |
listeners = item.getListeners(SWT.Modify);
|
|
988 |
for (int i = 0; i < listeners.length; i++) {
|
|
989 |
item.removeListener(SWT.Modify, listeners[i]);
|
|
990 |
}
|
|
991 |
if(valueCombo != null){
|
|
992 |
listeners = valueCombo.getListeners(SWT.SetData);
|
|
993 |
for (int i = 0; i < listeners.length; i++) {
|
|
994 |
valueCombo.removeListener(SWT.SetData, listeners[i]);
|
|
995 |
}
|
|
996 |
}
|
|
997 |
|
|
998 |
|
|
999 |
if(isValuesInCombo){
|
|
1000 |
|
|
1001 |
valueCombo.setVisibleItemCount(fixedValuesForType.length);
|
|
1002 |
|
|
1003 |
//Update item text when text is modified (and random Combo when value text is modified by fulfill random button)
|
|
1004 |
valueCombo.addModifyListener( new ValueModifyListener(item, valueCombo, typeCombo));
|
|
1005 |
//Add listener to check this value enablation by selection of another value
|
|
1006 |
item.addListener(SWT.Modify, new CheckItemValueEnablationsListener(typeCombo, valueCombo, modeCombo, amountTxt));
|
|
1007 |
|
|
1008 |
|
|
1009 |
//Update value text item text when combo selection is changed
|
|
1010 |
modeCombo.addSelectionListener(new ModeComboSelectionListener(modeCombo, valueCombo, item));
|
|
1011 |
item.addListener(SWT.Modify, new SetAsRandomValueItemListener(item, valueCombo, modeCombo));
|
|
1012 |
|
|
1013 |
// Adding action to clear Button
|
|
1014 |
clearBtn.addSelectionListener(getClearButtonSelectionListener(item, typeCombo, valueCombo, modeCombo,
|
|
1015 |
amountTxt));
|
|
1016 |
|
|
1017 |
//Adding listener to update items when new contact set is created, if there is contactSet creation button, and
|
|
1018 |
//if we have contact set reference as type.
|
|
1019 |
if(addContactSetButton != null && CreatorEditorSettings.isContactSetReference(typeCombo.getText())){
|
|
1020 |
addContactSetButton.addListener(SWT.SetData, new AddNewContactSetButtonListener(valueCombo));
|
|
1021 |
}
|
|
1022 |
|
|
1023 |
|
|
1024 |
}else{
|
|
1025 |
//Update item text when text is modified (and random Combo when value text is modified by fulfill random button)
|
|
1026 |
valueTxt.addModifyListener( new ValueModifyListener(item, valueTxt, typeCombo));
|
|
1027 |
//Add listener to check this value enablation by selection of another value
|
|
1028 |
item.addListener(SWT.Modify, new CheckItemValueEnablationsListener(typeCombo, valueTxt, modeCombo, amountTxt));
|
|
1029 |
|
|
1030 |
//Update value text item text when combo selection is changed
|
|
1031 |
modeCombo.addSelectionListener(new ModeComboSelectionListener(modeCombo, valueTxt, item));
|
|
1032 |
//When fulfill all values with random -button modifies values, setting also combo and text field values
|
|
1033 |
item.addListener(SWT.Modify, new SetAsRandomValueItemListener(item, valueTxt, modeCombo));
|
|
1034 |
|
|
1035 |
// Adding action to clear Button
|
|
1036 |
clearBtn.addSelectionListener(getClearButtonSelectionListener(item, typeCombo, valueTxt, modeCombo,
|
|
1037 |
amountTxt));
|
|
1038 |
|
|
1039 |
}
|
|
1040 |
|
|
1041 |
}
|
|
1042 |
|
|
1043 |
|
|
1044 |
|
|
1045 |
/**
|
|
1046 |
* Creates a value text
|
|
1047 |
* @param value
|
|
1048 |
* @param randomValueText
|
|
1049 |
* @param setFocusToRow
|
|
1050 |
* @param item
|
|
1051 |
* @param typeComboSelection
|
|
1052 |
* @return
|
|
1053 |
*/
|
|
1054 |
private Text createValueText(String value, String randomValueText,
|
|
1055 |
boolean setFocusToRow, final TableItem item, String typeComboSelection) {
|
|
1056 |
final Text valueTxt = new Text(itemsTable, SWT.NONE);
|
|
1057 |
valueTxt.setFont(getUnicodeFont());
|
|
1058 |
setValueTextAndEnabling(valueTxt, value, randomValueText);
|
|
1059 |
if(setFocusToRow){
|
|
1060 |
valueTxt.setFocus();
|
|
1061 |
}
|
|
1062 |
item.setText(1, valueTxt.getText());
|
|
1063 |
if(CreatorEditorSettings.isContactSetReference(valueTxt.getText())){
|
|
1064 |
setContextSensitiveHelpID(valueTxt, CreatorHelpContextIDs.CREATOR_HELP_CONTACT_SET);
|
|
1065 |
}else{
|
|
1066 |
setContextSensitiveHelpIDByComponentType(valueTxt);
|
|
1067 |
}
|
|
1068 |
|
|
1069 |
setTipTextToValue(valueTxt, typeComboSelection);
|
|
1070 |
|
|
1071 |
return valueTxt;
|
|
1072 |
}
|
|
1073 |
|
|
1074 |
/**
|
|
1075 |
* Sets tip text to value if needed
|
|
1076 |
* @param valueTxt
|
|
1077 |
* @param typeComboSelection
|
|
1078 |
*/
|
|
1079 |
private void setTipTextToValue(Text valueTxt, String typeComboSelection) {
|
|
1080 |
AbstractVariables var = getComponent().getVariables();
|
|
1081 |
String tipText = var.getTipText(typeComboSelection);
|
|
1082 |
if(tipText != null){
|
|
1083 |
valueTxt.setToolTipText(tipText);
|
|
1084 |
}
|
|
1085 |
}
|
|
1086 |
|
|
1087 |
/**
|
|
1088 |
* Listener for mode selection combo
|
|
1089 |
*/
|
|
1090 |
private class ModeComboSelectionListener implements SelectionListener{
|
|
1091 |
|
|
1092 |
private CCombo modeCombo = null;
|
|
1093 |
private Text text = null;
|
|
1094 |
private TableItem item = null;
|
|
1095 |
private CCombo combo = null;
|
|
1096 |
|
|
1097 |
public ModeComboSelectionListener(final CCombo modeCombo, final Text text, final TableItem item){
|
|
1098 |
this.modeCombo = modeCombo;
|
|
1099 |
this.text = text;
|
|
1100 |
this.item = item;
|
|
1101 |
|
|
1102 |
}
|
|
1103 |
public ModeComboSelectionListener(final CCombo modeCombo, final CCombo combo, final TableItem item){
|
|
1104 |
this.modeCombo = modeCombo;
|
|
1105 |
this.combo = combo;
|
|
1106 |
this.item = item;
|
|
1107 |
|
|
1108 |
}
|
|
1109 |
|
|
1110 |
public void widgetSelected(SelectionEvent event) {
|
|
1111 |
|
|
1112 |
String rndTxt = modeCombo.getText();
|
|
1113 |
|
|
1114 |
if(text!=null){
|
|
1115 |
if(CreatorEditorSettings.isContactSetReference(rndTxt)){
|
|
1116 |
setContextSensitiveHelpID(text, CreatorHelpContextIDs.CREATOR_HELP_CONTACT_SET);
|
|
1117 |
}else{
|
|
1118 |
setContextSensitiveHelpIDByComponentType(text);
|
|
1119 |
}
|
|
1120 |
item.setText(2, rndTxt);
|
|
1121 |
setValueTextAndEnabling(text, null, rndTxt);
|
|
1122 |
}
|
|
1123 |
else{
|
|
1124 |
if(CreatorEditorSettings.isContactSetReference(rndTxt)){
|
|
1125 |
setContextSensitiveHelpID(combo, CreatorHelpContextIDs.CREATOR_HELP_CONTACT_SET);
|
|
1126 |
}else{
|
|
1127 |
setContextSensitiveHelpIDByComponentType(combo);
|
|
1128 |
}
|
|
1129 |
combo.setEnabled(false);
|
|
1130 |
item.setText(2, rndTxt);
|
|
1131 |
setValueTextAndEnabling(combo, null, rndTxt, null);
|
|
1132 |
}
|
|
1133 |
}
|
|
1134 |
|
|
1135 |
public void widgetDefaultSelected(SelectionEvent e) {
|
|
1136 |
//Not needed
|
|
1137 |
}
|
|
1138 |
}
|
|
1139 |
|
|
1140 |
|
|
1141 |
/**
|
|
1142 |
* Class for listening value text changes
|
|
1143 |
*/
|
|
1144 |
private class ValueModifyListener implements ModifyListener
|
|
1145 |
|
|
1146 |
{
|
|
1147 |
private TableItem item = null;
|
|
1148 |
private Text valueText = null;
|
|
1149 |
private CCombo valueCombo = null;
|
|
1150 |
private final CCombo typeCombo;
|
|
1151 |
|
|
1152 |
public ValueModifyListener(TableItem item , Text valueText, final CCombo typeCombo){
|
|
1153 |
this.item = item;
|
|
1154 |
this.valueText = valueText;
|
|
1155 |
this.typeCombo = typeCombo;
|
|
1156 |
}
|
|
1157 |
public ValueModifyListener(TableItem item , CCombo valueCombo, final CCombo typeCombo){
|
|
1158 |
this.item = item;
|
|
1159 |
this.valueCombo = valueCombo;
|
|
1160 |
this.typeCombo = typeCombo;
|
|
1161 |
}
|
|
1162 |
public void modifyText(ModifyEvent e) {
|
|
1163 |
|
|
1164 |
if(valueText != null){
|
|
1165 |
item.setText(1, valueText.getText());
|
|
1166 |
}
|
|
1167 |
else{
|
|
1168 |
item.setText(1, valueCombo.getText());
|
|
1169 |
//Check that if something must do to some values by the selection
|
|
1170 |
checkIfNeedToCallCheckItemValueEnablationListenersAndCallIfNeeded(
|
|
1171 |
valueCombo, valueText, typeCombo);
|
|
1172 |
|
|
1173 |
|
|
1174 |
}
|
|
1175 |
}
|
|
1176 |
|
|
1177 |
}
|
|
1178 |
|
|
1179 |
/**
|
|
1180 |
* Just for enabling to cast Events when using set as random functionality
|
|
1181 |
*/
|
|
1182 |
private class SetRandomEvent extends Event{
|
|
1183 |
|
|
1184 |
}
|
|
1185 |
|
|
1186 |
/**
|
|
1187 |
* Just for enabling to cast Event when checking
|
|
1188 |
* if we should disable/enable some valus by some selection made
|
|
1189 |
*/
|
|
1190 |
private class CheckItemValueEnablationsEvent extends Event{
|
|
1191 |
|
|
1192 |
private String type;
|
|
1193 |
private String value;
|
|
1194 |
|
|
1195 |
|
|
1196 |
/**
|
|
1197 |
* @return the type
|
|
1198 |
*/
|
|
1199 |
public String getType() {
|
|
1200 |
return type;
|
|
1201 |
}
|
|
1202 |
|
|
1203 |
/**
|
|
1204 |
* @return the value
|
|
1205 |
*/
|
|
1206 |
public String getValue() {
|
|
1207 |
return value;
|
|
1208 |
}
|
|
1209 |
|
|
1210 |
public void setType(String type) {
|
|
1211 |
this.type = type;
|
|
1212 |
}
|
|
1213 |
|
|
1214 |
public void setValue(String value) {
|
|
1215 |
this.value = value;
|
|
1216 |
}
|
|
1217 |
|
|
1218 |
}
|
|
1219 |
|
|
1220 |
|
|
1221 |
/**
|
|
1222 |
* Listener class for setting values as random, used by button.
|
|
1223 |
*/
|
|
1224 |
private class SetAsRandomValueItemListener implements Listener{
|
|
1225 |
|
|
1226 |
TableItem item = null;
|
|
1227 |
Text valueTxt = null;
|
|
1228 |
CCombo randomCombo = null;
|
|
1229 |
private CCombo valueCombo = null;
|
|
1230 |
|
|
1231 |
public SetAsRandomValueItemListener(TableItem item, Text valueTxt, CCombo randomCombo){
|
|
1232 |
this.item = item;
|
|
1233 |
this.valueTxt = valueTxt;
|
|
1234 |
this.randomCombo = randomCombo;
|
|
1235 |
|
|
1236 |
}
|
|
1237 |
public SetAsRandomValueItemListener(TableItem item,CCombo valueCombo, CCombo randomCombo){
|
|
1238 |
this.item = item;
|
|
1239 |
this.valueCombo = valueCombo;
|
|
1240 |
this.randomCombo = randomCombo;
|
|
1241 |
|
|
1242 |
}
|
|
1243 |
|
|
1244 |
public void handleEvent(Event e) {
|
|
1245 |
|
|
1246 |
//Checking that if we have wanted event
|
|
1247 |
if(!(e instanceof SetRandomEvent)){
|
|
1248 |
return;
|
|
1249 |
}
|
|
1250 |
|
|
1251 |
String txt = item.getText(1);
|
|
1252 |
|
|
1253 |
//If value is in text, but not in combo
|
|
1254 |
if (valueTxt!=null) {
|
|
1255 |
|
|
1256 |
if (e.doit) {
|
|
1257 |
removeNumberVerifyListener(valueTxt);
|
|
1258 |
}
|
|
1259 |
if (txt != null) {
|
|
1260 |
setValueTextAndEnablingAndRandomComboSelection(txt,
|
|
1261 |
valueTxt, randomCombo);
|
|
1262 |
}
|
|
1263 |
}
|
|
1264 |
//else value is in combo
|
|
1265 |
else{
|
|
1266 |
setValueTextAndEnablingAndRandomComboSelection(txt, valueCombo, randomCombo);
|
|
1267 |
}
|
|
1268 |
}
|
|
1269 |
}
|
|
1270 |
|
|
1271 |
/**
|
|
1272 |
* Listener class for enabling/disabling items by some other value set in dialog.
|
|
1273 |
* E.g. With File, crypted with CRM-FL, then all CRM-CD parameters will be disabled.
|
|
1274 |
*/
|
|
1275 |
private class CheckItemValueEnablationsListener implements Listener{
|
|
1276 |
|
|
1277 |
CCombo typeCombo;
|
|
1278 |
Text valueTxt = null;
|
|
1279 |
Text amountTxt = null;
|
|
1280 |
CCombo modeCombo = null;
|
|
1281 |
private CCombo valueCombo = null;
|
|
1282 |
|
|
1283 |
public CheckItemValueEnablationsListener(CCombo typeCombo, Text valueTxt, CCombo modeCombo, Text amountTxt){
|
|
1284 |
this.typeCombo = typeCombo;
|
|
1285 |
this.valueTxt = valueTxt;
|
|
1286 |
this.modeCombo = modeCombo;
|
|
1287 |
this.amountTxt = amountTxt;
|
|
1288 |
|
|
1289 |
}
|
|
1290 |
public CheckItemValueEnablationsListener(CCombo typeCombo,CCombo valueCombo, CCombo modeCombo, Text amountTxt){
|
|
1291 |
this.typeCombo = typeCombo;
|
|
1292 |
this.valueCombo = valueCombo;
|
|
1293 |
this.modeCombo = modeCombo;
|
|
1294 |
this.amountTxt = amountTxt;
|
|
1295 |
}
|
|
1296 |
|
|
1297 |
public void handleEvent(Event e) {
|
|
1298 |
|
|
1299 |
if(! ( e instanceof CheckItemValueEnablationsEvent )){
|
|
1300 |
return;
|
|
1301 |
}
|
|
1302 |
|
|
1303 |
CheckItemValueEnablationsEvent event = (CheckItemValueEnablationsEvent)e;
|
|
1304 |
String type = event.getType();
|
|
1305 |
String value = event.getValue();
|
|
1306 |
String typeToBeDisabled = typeCombo.getText();
|
|
1307 |
|
|
1308 |
enableOrDisableRowItems(type, value, typeToBeDisabled, valueTxt, valueCombo, modeCombo, amountTxt);
|
|
1309 |
|
|
1310 |
}
|
|
1311 |
|
|
1312 |
|
|
1313 |
}
|
|
1314 |
|
|
1315 |
/**
|
|
1316 |
* Enables or disable items of row
|
|
1317 |
* @param type
|
|
1318 |
* @param value
|
|
1319 |
* @param typeToBeDisabled
|
|
1320 |
* @param valueTxt
|
|
1321 |
* @param valueCombo
|
|
1322 |
* @param modeCombo
|
|
1323 |
*/
|
|
1324 |
private void enableOrDisableRowItems(String type, String value,
|
|
1325 |
String typeToBeDisabled,
|
|
1326 |
Text valueTxt,
|
|
1327 |
CCombo valueCombo,
|
|
1328 |
CCombo modeCombo, Text amountTxt) {
|
|
1329 |
|
|
1330 |
boolean enableAllValues = !getComponent().isTypeDisabledByTypeAndValue(type, value, typeToBeDisabled);
|
|
1331 |
boolean enableValue = enableAllValues;
|
|
1332 |
|
|
1333 |
String currentValueTxt;
|
|
1334 |
if (valueTxt!=null) {
|
|
1335 |
currentValueTxt = valueTxt.getText();
|
|
1336 |
}else{
|
|
1337 |
currentValueTxt = valueCombo.getText();
|
|
1338 |
}
|
|
1339 |
|
|
1340 |
//Check if current value is random value now
|
|
1341 |
boolean isRandomValue = CreatorEditorSettings.isRandomText(currentValueTxt);
|
|
1342 |
//If value is random, and we try to enable values, dont do that
|
|
1343 |
if (isRandomValue && enableAllValues)
|
|
1344 |
{
|
|
1345 |
enableValue = false;
|
|
1346 |
}
|
|
1347 |
|
|
1348 |
//If value is in text, but not in combo
|
|
1349 |
if (valueTxt!=null) {
|
|
1350 |
valueTxt.setEnabled(enableValue);
|
|
1351 |
}
|
|
1352 |
//else value is in combo
|
|
1353 |
else{
|
|
1354 |
valueCombo.setEditable(enableValue);
|
|
1355 |
}
|
|
1356 |
|
|
1357 |
//dont enable mode combo if its not enabled to this type
|
|
1358 |
boolean isModeEnabled = getComponent().getVariables().isModeEnabledForKey(typeToBeDisabled);
|
|
1359 |
if(isModeEnabled){
|
|
1360 |
modeCombo.setEnabled(enableAllValues);
|
|
1361 |
}
|
|
1362 |
|
|
1363 |
//amount field can be enabled or disabled if its in use
|
|
1364 |
if(isAmountFieldsEnabled()){
|
|
1365 |
amountTxt.setEnabled(enableAllValues);
|
|
1366 |
}
|
|
1367 |
}
|
|
1368 |
|
|
1369 |
/**
|
|
1370 |
* Listener to set items to Type Combo when selection is made
|
|
1371 |
*/
|
|
1372 |
private class TypeComboItemsSetterListener implements Listener{
|
|
1373 |
|
|
1374 |
private final CCombo typeCombo;
|
|
1375 |
|
|
1376 |
public TypeComboItemsSetterListener(CCombo typeCombo){
|
|
1377 |
this.typeCombo = typeCombo;
|
|
1378 |
|
|
1379 |
}
|
|
1380 |
|
|
1381 |
public void handleEvent(Event event) {
|
|
1382 |
|
|
1383 |
if(event.doit && event.data != null && event.data instanceof String[]){
|
|
1384 |
String [] items = (String[]) event.data;
|
|
1385 |
String selectionText = typeCombo.getText();
|
|
1386 |
typeCombo.setItems(items);
|
|
1387 |
int count = items.length;
|
|
1388 |
if(count > MAX_ITEMS_IN_COMBO){
|
|
1389 |
count = MAX_ITEMS_IN_COMBO;
|
|
1390 |
}
|
|
1391 |
typeCombo.setVisibleItemCount(count);
|
|
1392 |
typeCombo.setText(selectionText);
|
|
1393 |
}
|
|
1394 |
}
|
|
1395 |
|
|
1396 |
}
|
|
1397 |
|
|
1398 |
/**
|
|
1399 |
* Get listener for type combo.
|
|
1400 |
* There is logic for changing value field from text to combo and vice versa.
|
|
1401 |
* @param item
|
|
1402 |
* @param typeCombo
|
|
1403 |
* @param valueTxt
|
|
1404 |
* @param randomCombo
|
|
1405 |
* @param amountTxt
|
|
1406 |
* @return
|
|
1407 |
*/
|
|
1408 |
private class TypeComboSelectionListener implements SelectionListener{
|
|
1409 |
|
|
1410 |
private TableItem item;
|
|
1411 |
private CCombo typeCombo;
|
|
1412 |
private Text valueTxt;
|
|
1413 |
private Text amountTxt;
|
|
1414 |
private CCombo valueCombo;
|
|
1415 |
private CCombo modeCombo;
|
|
1416 |
private TableEditor valueEditor;
|
|
1417 |
private TableEditor clrBtnEditor;
|
|
1418 |
private final Button clearBtn;
|
|
1419 |
|
|
1420 |
public TypeComboSelectionListener ( TableItem item,
|
|
1421 |
TableEditor clrButtonEditor, TableEditor valueEditor, CCombo typeCombo,
|
|
1422 |
Text valueTxt, CCombo valueCombo, CCombo modeCombo,
|
|
1423 |
Text amountTxt, Button clearBtn){
|
|
1424 |
this.clrBtnEditor = clrButtonEditor;
|
|
1425 |
this.valueEditor = valueEditor;
|
|
1426 |
this.item = item;
|
|
1427 |
this.typeCombo = typeCombo;
|
|
1428 |
this.valueTxt = valueTxt;
|
|
1429 |
this.valueCombo = valueCombo;
|
|
1430 |
this.amountTxt = amountTxt;
|
|
1431 |
this.modeCombo = modeCombo;
|
|
1432 |
this.clearBtn = clearBtn;
|
|
1433 |
|
|
1434 |
}
|
|
1435 |
|
|
1436 |
|
|
1437 |
/* (non-Javadoc)
|
|
1438 |
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
|
|
1439 |
*/
|
|
1440 |
public void widgetSelected(SelectionEvent event) {
|
|
1441 |
|
|
1442 |
String typeComboSelection = typeCombo.getText();
|
|
1443 |
item.setText(0, typeComboSelection);
|
|
1444 |
|
|
1445 |
String [] fixedValuesForType = getItemValueAsString(typeComboSelection);
|
|
1446 |
//Will values be in combo afterwards
|
|
1447 |
boolean isValuesInCombo = fixedValuesForType != null && fixedValuesForType.length > 0;
|
|
1448 |
//Was value field type changed by user selection? Will be true if before value was text, and now it will be combo and so on...
|
|
1449 |
boolean isValueFieldTypeChanged =
|
|
1450 |
isValuesInCombo && valueCombo == null || !isValuesInCombo && valueTxt == null
|
|
1451 |
? true : false;
|
|
1452 |
|
|
1453 |
|
|
1454 |
if(CreatorEditorSettings.isContactSetReference(typeComboSelection))
|
|
1455 |
{
|
|
1456 |
amountTxt.setEnabled(true);//always enabled with contact set reference
|
|
1457 |
modeCombo.setEnabled(false);
|
|
1458 |
modeCombo.setText(AbstractValue.RANDOM_TEXT_NOT_RANDOM);//Setting to edit mode when contact-set is selected
|
|
1459 |
modeCombo.setBackground(getGrey());
|
|
1460 |
|
|
1461 |
}else if(!isAmountFieldsEnabled){
|
|
1462 |
amountTxt.setText(AbstractValue.EMPTY_STRING);
|
|
1463 |
amountTxt.setEnabled(isAmountFieldsEnabled);
|
|
1464 |
setModeComboEnablation(typeComboSelection, modeCombo);
|
|
1465 |
}else{
|
|
1466 |
amountTxt.setText(AbstractValue.EMPTY_STRING);
|
|
1467 |
setAmountTextEnabletion(typeComboSelection, amountTxt);
|
|
1468 |
setModeComboEnablation(typeComboSelection, modeCombo);
|
|
1469 |
}
|
|
1470 |
|
|
1471 |
|
|
1472 |
// Just changing contents when value remains in combo
|
|
1473 |
if (isValuesInCombo && !isValueFieldTypeChanged) {
|
|
1474 |
valueCombo.setItems(fixedValuesForType);
|
|
1475 |
valueCombo.setVisibleItemCount(fixedValuesForType.length);
|
|
1476 |
|
|
1477 |
//When values was in combo and type was changed to contact set, we must set listeners again to listen contact-set changes.
|
|
1478 |
setItemValueListeners(item, clrBtnEditor, valueEditor, typeCombo, fixedValuesForType,
|
|
1479 |
isValuesInCombo, null, valueCombo, modeCombo, amountTxt,
|
|
1480 |
clearBtn);
|
|
1481 |
}
|
|
1482 |
//value remains in text
|
|
1483 |
else if (!isValuesInCombo && !isValueFieldTypeChanged) {
|
|
1484 |
valueTxt.setText(AbstractValue.EMPTY_STRING);
|
|
1485 |
valueTxt.setEnabled(true);
|
|
1486 |
}
|
|
1487 |
//else isValueFieldTypeChanged == true
|
|
1488 |
else{
|
|
1489 |
//Removing old control when new will be created
|
|
1490 |
Control editable = valueEditor.getEditor();
|
|
1491 |
editable.dispose();
|
|
1492 |
|
|
1493 |
//value changed from text to combo
|
|
1494 |
if (isValuesInCombo ) {
|
|
1495 |
valueCombo = addValueComboToTable(fixedValuesForType, AbstractValue.EMPTY_STRING,
|
|
1496 |
item, AbstractValue.EMPTY_STRING, typeComboSelection);
|
|
1497 |
valueEditor.setEditor(valueCombo, item, 1);
|
|
1498 |
|
|
1499 |
setItemValueListeners(item, clrBtnEditor, valueEditor, typeCombo, fixedValuesForType,
|
|
1500 |
isValuesInCombo, null, valueCombo, modeCombo, amountTxt,
|
|
1501 |
clearBtn);
|
|
1502 |
valueTxt = null;
|
|
1503 |
|
|
1504 |
|
|
1505 |
} else// if (!isValuesInCombo && isValueFieldTypeChanged)
|
|
1506 |
{
|
|
1507 |
valueTxt = createValueText(AbstractValue.EMPTY_STRING, AbstractValue.EMPTY_STRING, true, item, typeComboSelection);
|
|
1508 |
valueTxt.setEnabled(true);
|
|
1509 |
valueEditor.setEditor(valueTxt, item, 1);
|
|
1510 |
|
|
1511 |
setItemValueListeners(item, clrBtnEditor, valueEditor, typeCombo, null,
|
|
1512 |
isValuesInCombo, valueTxt, null, modeCombo, amountTxt,
|
|
1513 |
clearBtn);
|
|
1514 |
valueCombo = null;//For removing listners
|
|
1515 |
|
|
1516 |
}
|
|
1517 |
}
|
|
1518 |
|
|
1519 |
//setting modeCombo values after all other changes are made
|
|
1520 |
String modeComboValues [] = getModeValues(isValuesInCombo, typeComboSelection);
|
|
1521 |
modeCombo.setItems(modeComboValues);
|
|
1522 |
modeCombo.setText(getModeComboSelection(AbstractValue.EMPTY_STRING, modeComboValues));
|
|
1523 |
item.setText(2, modeCombo.getText());
|
|
1524 |
|
|
1525 |
//Notify table listeners to update item combos
|
|
1526 |
notifyTypeComboDataListeners();
|
|
1527 |
|
|
1528 |
}
|
|
1529 |
|
|
1530 |
|
|
1531 |
//Not needed.
|
|
1532 |
public void widgetDefaultSelected(SelectionEvent e) {
|
|
1533 |
}
|
|
1534 |
}
|
|
1535 |
|
|
1536 |
/**
|
|
1537 |
* Notify table listeners to update type combo data
|
|
1538 |
*/
|
|
1539 |
private void notifyTypeComboDataListeners() {
|
|
1540 |
|
|
1541 |
String addedItems[] = getAddedItems();//get items added allready to dialog
|
|
1542 |
String toBeSetItems[] = getItemTypesAsString(addedItems);//get items to be set to all item types
|
|
1543 |
|
|
1544 |
Event itemsComboUpdateEvent = new Event();
|
|
1545 |
itemsComboUpdateEvent.doit = true;
|
|
1546 |
itemsComboUpdateEvent.data = toBeSetItems;
|
|
1547 |
|
|
1548 |
//Enabling / disabling add row button if there is no rows able to add
|
|
1549 |
if(toBeSetItems.length == 0 && addRowButton != null){
|
|
1550 |
addRowButton.setEnabled(false);
|
|
1551 |
}else if(addRowButton != null){
|
|
1552 |
addRowButton.setEnabled(true);
|
|
1553 |
}//else no action
|
|
1554 |
|
|
1555 |
//Notify all type-combos that new data must be set to combos
|
|
1556 |
itemsTable.notifyListeners(SWT.SetData, itemsComboUpdateEvent);
|
|
1557 |
}
|
|
1558 |
|
|
1559 |
/**
|
|
1560 |
* Get listener for Clear button
|
|
1561 |
* @param item
|
|
1562 |
* @param typeCombo
|
|
1563 |
* @param valueTxt
|
|
1564 |
* @param randomCombo
|
|
1565 |
* @param amountTxt
|
|
1566 |
* @return
|
|
1567 |
*/
|
|
1568 |
private SelectionAdapter getClearButtonSelectionListener(
|
|
1569 |
final TableItem item, final CCombo typeCombo, final Text valueTxt,
|
|
1570 |
final CCombo randomCombo, final Text amountTxt) {
|
|
1571 |
return new SelectionAdapter() {
|
|
1572 |
public void widgetSelected(SelectionEvent event) {
|
|
1573 |
|
|
1574 |
|
|
1575 |
// Clearing data, also item texts must be cleared
|
|
1576 |
typeCombo.setText(AbstractValue.EMPTY_STRING);
|
|
1577 |
item.setText(0, AbstractValue.EMPTY_STRING);
|
|
1578 |
valueTxt.setText(AbstractValue.EMPTY_STRING);
|
|
1579 |
item.setText(1, AbstractValue.EMPTY_STRING);
|
|
1580 |
randomCombo.setText(AbstractValue.EMPTY_STRING);
|
|
1581 |
item.setText(2, AbstractValue.EMPTY_STRING);
|
|
1582 |
amountTxt.setText(AbstractValue.EMPTY_STRING);
|
|
1583 |
item.setText(3, AbstractValue.EMPTY_STRING);
|
|
1584 |
|
|
1585 |
typeCombo.setEnabled(true);
|
|
1586 |
valueTxt.setEnabled(true);
|
|
1587 |
randomCombo.setEnabled(true);
|
|
1588 |
amountTxt.setEnabled(true);
|
|
1589 |
|
|
1590 |
randomCombo.setBackground(getWhite());
|
|
1591 |
|
|
1592 |
//Notify table listeners to update item combos
|
|
1593 |
notifyTypeComboDataListeners();
|
|
1594 |
}
|
|
1595 |
};
|
|
1596 |
}
|
|
1597 |
|
|
1598 |
/**
|
|
1599 |
* Get listener for Clear button
|
|
1600 |
* @param item
|
|
1601 |
* @param typeCombo
|
|
1602 |
* @param valueCombo
|
|
1603 |
* @param randomCombo
|
|
1604 |
* @param amountTxt
|
|
1605 |
* @return
|
|
1606 |
*/
|
|
1607 |
private SelectionAdapter getClearButtonSelectionListener(
|
|
1608 |
final TableItem item, final CCombo typeCombo, final CCombo valueCombo,
|
|
1609 |
final CCombo randomCombo, final Text amountTxt) {
|
|
1610 |
return new SelectionAdapter() {
|
|
1611 |
public void widgetSelected(SelectionEvent event) {
|
|
1612 |
|
|
1613 |
// Clearing data, also item texts must be cleared
|
|
1614 |
typeCombo.setText(AbstractValue.EMPTY_STRING);
|
|
1615 |
item.setText(0, AbstractValue.EMPTY_STRING);
|
|
1616 |
valueCombo.setText(AbstractValue.EMPTY_STRING);
|
|
1617 |
item.setText(1, AbstractValue.EMPTY_STRING);
|
|
1618 |
randomCombo.setText(AbstractValue.EMPTY_STRING);
|
|
1619 |
item.setText(2, AbstractValue.EMPTY_STRING);
|
|
1620 |
amountTxt.setText(AbstractValue.EMPTY_STRING);
|
|
1621 |
item.setText(3, AbstractValue.EMPTY_STRING);
|
|
1622 |
|
|
1623 |
typeCombo.setEnabled(true);
|
|
1624 |
valueCombo.setEnabled(true);
|
|
1625 |
randomCombo.setEnabled(true);
|
|
1626 |
amountTxt.setEnabled(true);
|
|
1627 |
|
|
1628 |
randomCombo.setBackground(getWhite());
|
|
1629 |
|
|
1630 |
//Notify table listeners to update item combos
|
|
1631 |
notifyTypeComboDataListeners();
|
|
1632 |
}
|
|
1633 |
};
|
|
1634 |
}
|
|
1635 |
|
|
1636 |
|
|
1637 |
/**
|
|
1638 |
* When "Set Random" button is pushed, and user wants to set all values as random
|
|
1639 |
* editing value field and random combo selection
|
|
1640 |
* @param txt
|
|
1641 |
* @param valueTxt
|
|
1642 |
* @param modeCombo
|
|
1643 |
*/
|
|
1644 |
private void setValueTextAndEnablingAndRandomComboSelection(String txt,
|
|
1645 |
Text valueTxt, CCombo modeCombo) {
|
|
1646 |
|
|
1647 |
valueTxt.setTextLimit(Text.LIMIT);
|
|
1648 |
|
|
1649 |
if(txt == null){
|
|
1650 |
valueTxt.setEnabled(true);
|
|
1651 |
valueTxt.setText(AbstractValue.EMPTY_STRING);
|
|
1652 |
modeCombo.setText(AbstractValue.RANDOM_TEXT_NOT_RANDOM);
|
|
1653 |
}
|
|
1654 |
// If random is selected, text field is disabled and showing that random
|
|
1655 |
// mode is on
|
|
1656 |
|
|
1657 |
//random mode with default len
|
|
1658 |
else if (txt.equals(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH)
|
|
1659 |
|| txt.equals(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH_LONG)) {
|
|
1660 |
|
|
1661 |
valueTxt.setEnabled(false);
|
|
1662 |
valueTxt.setText(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH_LONG);
|
|
1663 |
modeCombo.setText(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH);
|
|
1664 |
}
|
|
1665 |
//Random mode with max len
|
|
1666 |
else if (txt.equals(AbstractValue.RANDOM_TEXT_MAX_LENGTH)
|
|
1667 |
|| txt.equals(AbstractValue.RANDOM_TEXT_MAX_LENGTH_LONG)) {
|
|
1668 |
valueTxt.setEnabled(false);
|
|
1669 |
valueTxt.setText(AbstractValue.RANDOM_TEXT_MAX_LENGTH_LONG);
|
|
1670 |
modeCombo.setText(AbstractValue.RANDOM_TEXT_MAX_LENGTH);
|
|
1671 |
}
|
|
1672 |
//random mode with user defined len
|
|
1673 |
else if (txt.equals(AbstractValue.RANDOM_TEXT_USER_DEFINED_LENGTH)
|
|
1674 |
|| txt.equals(AbstractValue.RANDOM_TEXT_USER_DEFINED_LENGTH_LONG)) {
|
|
1675 |
valueTxt.setEnabled(true);
|
|
1676 |
modeCombo.setText(AbstractValue.RANDOM_TEXT_USER_DEFINED_LENGTH);
|
|
1677 |
}
|
|
1678 |
//mode is RANDOM_TEXT_INC_FOR_EACH_COPY This should not be able to occur, because RANDOM_TEXT_INC_FOR_EACH_COPY
|
|
1679 |
//value are always phone numbers and will be on text field, just in case implemented.
|
|
1680 |
else if (txt.equals(AbstractValue.RANDOM_TEXT_INC_FOR_EACH_COPY)) {
|
|
1681 |
valueTxt.setEnabled(true);
|
|
1682 |
modeCombo.setText(AbstractValue.RANDOM_TEXT_INC_FOR_EACH_COPY);
|
|
1683 |
}
|
|
1684 |
|
|
1685 |
//default, not random
|
|
1686 |
else{
|
|
1687 |
valueTxt.setEnabled(true);
|
|
1688 |
valueTxt.setText(txt);
|
|
1689 |
modeCombo.setText(AbstractValue.RANDOM_TEXT_NOT_RANDOM);
|
|
1690 |
}
|
|
1691 |
}
|
|
1692 |
|
|
1693 |
/**
|
|
1694 |
* Checks values from type and value (from valueTxt if not null or from valuecombo if txt was null)
|
|
1695 |
* and then checks if other items must check they enablations,
|
|
1696 |
* and enables/disables if required
|
|
1697 |
*
|
|
1698 |
* @param txt
|
|
1699 |
* @param valueCombo
|
|
1700 |
* @param typeCombo
|
|
1701 |
*/
|
|
1702 |
private void checkIfNeedToCallCheckItemValueEnablationListenersAndCallIfNeeded(
|
|
1703 |
CCombo valueCombo, Text valueText, CCombo typeCombo) {
|
|
1704 |
|
|
1705 |
String value;
|
|
1706 |
if(valueCombo != null){
|
|
1707 |
value = valueCombo.getText();
|
|
1708 |
}else{
|
|
1709 |
value = valueText.getText();
|
|
1710 |
}
|
|
1711 |
String type = typeCombo.getText();
|
|
1712 |
|
|
1713 |
callCheckItemValueEnablationListeners(type, value);
|
|
1714 |
}
|
|
1715 |
|
|
1716 |
/**
|
|
1717 |
* Check all items from itemsTable, and enables/disables those if required by some else values
|
|
1718 |
*/
|
|
1719 |
private void checkIfNeedToCallItemValueEnablationListners(){
|
|
1720 |
TableItem[] items = itemsTable.getItems();
|
|
1721 |
//Looping through all items in table
|
|
1722 |
for (int i = 0; i < items.length; i++) {
|
|
1723 |
|
|
1724 |
TableItem item = items[i];
|
|
1725 |
if (item != null) {
|
|
1726 |
String type = item.getText(0);
|
|
1727 |
String value = item.getText(1);
|
|
1728 |
|
|
1729 |
callCheckItemValueEnablationListeners(type, value);
|
|
1730 |
}
|
|
1731 |
}
|
|
1732 |
}
|
|
1733 |
|
|
1734 |
/**
|
|
1735 |
* Calls listeners to check they values if required by given type and value.
|
|
1736 |
*
|
|
1737 |
* @see AbstractComponent#hasTypeLimitationsForOtherValues(String, String)
|
|
1738 |
*
|
|
1739 |
* @param value
|
|
1740 |
* @param type
|
|
1741 |
*/
|
|
1742 |
private void callCheckItemValueEnablationListeners(String type, String value) {
|
|
1743 |
|
|
1744 |
//check from component, if that type and value combination needs to call listeners
|
|
1745 |
boolean wakeUpListners = getComponent().hasTypeLimitationsForOtherValues(type, value);
|
|
1746 |
|
|
1747 |
//If we need to wake up listners, doing so
|
|
1748 |
if(wakeUpListners){
|
|
1749 |
|
|
1750 |
TableItem[] items = itemsTable.getItems();
|
|
1751 |
//Looping through all items in table
|
|
1752 |
for (int i = 0; i < items.length; i++) {
|
|
1753 |
|
|
1754 |
TableItem item = items[i];
|
|
1755 |
if (item != null) {
|
|
1756 |
//Creating special event, so other listeners can check that if they are not intressed of this event
|
|
1757 |
CheckItemValueEnablationsEvent e = new CheckItemValueEnablationsEvent();
|
|
1758 |
e.setType(type);
|
|
1759 |
e.setValue(value);
|
|
1760 |
e.doit = true;
|
|
1761 |
item.notifyListeners(SWT.Modify, e);
|
|
1762 |
}
|
|
1763 |
}
|
|
1764 |
}
|
|
1765 |
}
|
|
1766 |
|
|
1767 |
/**
|
|
1768 |
* When "Set Random" button is pushed, and user wants to set all values as random
|
|
1769 |
* editing value field and random combo selection
|
|
1770 |
* @param txt
|
|
1771 |
* @param valueCombo
|
|
1772 |
* @param modeCombo
|
|
1773 |
*/
|
|
1774 |
private void setValueTextAndEnablingAndRandomComboSelection(String txt,
|
|
1775 |
CCombo valueCombo, CCombo modeCombo) {
|
|
1776 |
|
|
1777 |
valueCombo.setTextLimit(Text.LIMIT);
|
|
1778 |
|
|
1779 |
if(txt == null){
|
|
1780 |
valueCombo.setEnabled(true);
|
|
1781 |
valueCombo.setText(AbstractValue.EMPTY_STRING);
|
|
1782 |
modeCombo.setText(AbstractValue.RANDOM_TEXT_NOT_RANDOM);
|
|
1783 |
}
|
|
1784 |
// If random is selected, text field is disabled and showing that random
|
|
1785 |
// mode is on
|
|
1786 |
|
|
1787 |
//random mode with default len
|
|
1788 |
else if (txt.equals(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH)
|
|
1789 |
|| txt.equals(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH_LONG)) {
|
|
1790 |
|
|
1791 |
valueCombo.setEnabled(false);
|
|
1792 |
valueCombo.setText(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH_LONG);
|
|
1793 |
modeCombo.setText(AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH);
|
|
1794 |
}
|
|
1795 |
//Random mode with max len
|
|
1796 |
else if (txt.equals(AbstractValue.RANDOM_TEXT_MAX_LENGTH)
|
|
1797 |
|| txt.equals(AbstractValue.RANDOM_TEXT_MAX_LENGTH_LONG)) {
|
|
1798 |
valueCombo.setEnabled(false);
|
|
1799 |
valueCombo.setText(AbstractValue.RANDOM_TEXT_MAX_LENGTH_LONG);
|
|
1800 |
modeCombo.setText(AbstractValue.RANDOM_TEXT_MAX_LENGTH);
|
|
1801 |
}
|
|
1802 |
//random mode with user defined len
|
|
1803 |
else if (txt.equals(AbstractValue.RANDOM_TEXT_USER_DEFINED_LENGTH)
|
|
1804 |
|| txt.equals(AbstractValue.RANDOM_TEXT_USER_DEFINED_LENGTH_LONG)) {
|
|
1805 |
valueCombo.setEnabled(true);
|
|
1806 |
modeCombo.setText(AbstractValue.RANDOM_TEXT_USER_DEFINED_LENGTH);
|
|
1807 |
}
|
|
1808 |
//mode is RANDOM_TEXT_INC_FOR_EACH_COPY This should not be able to occur, because RANDOM_TEXT_INC_FOR_EACH_COPY
|
|
1809 |
//value are always phone numbers and will be on text field, just in case implemented.
|
|
1810 |
else if (txt.equals(AbstractValue.RANDOM_TEXT_INC_FOR_EACH_COPY)) {
|
|
1811 |
valueCombo.setEnabled(true);
|
|
1812 |
modeCombo.setText(AbstractValue.RANDOM_TEXT_INC_FOR_EACH_COPY);
|
|
1813 |
}
|
|
1814 |
//default, not random
|
|
1815 |
else{
|
|
1816 |
valueCombo.setEnabled(true);
|
|
1817 |
valueCombo.setText(txt);
|
|
1818 |
modeCombo.setText(AbstractValue.RANDOM_TEXT_NOT_RANDOM);
|
|
1819 |
}
|
|
1820 |
}
|
|
1821 |
|
|
1822 |
|
|
1823 |
/**
|
|
1824 |
* Adds one value combo to table
|
|
1825 |
* @param values
|
|
1826 |
* @param selectedValue
|
|
1827 |
* @param item
|
|
1828 |
* @param randomValueText
|
|
1829 |
* @param typeComboSelection
|
|
1830 |
* @return
|
|
1831 |
*/
|
|
1832 |
private CCombo addValueComboToTable(String[] values, String selectedValue,
|
|
1833 |
final TableItem item, String randomValueText, String typeComboSelection) {
|
|
1834 |
TableEditor editor;
|
|
1835 |
//
|
|
1836 |
//value combo
|
|
1837 |
//
|
|
1838 |
boolean isContactSetReference = CreatorEditorSettings.isContactSetReference(typeComboSelection);
|
|
1839 |
|
|
1840 |
editor = new TableEditor(itemsTable);
|
|
1841 |
final CCombo valueCombo = new CCombo(itemsTable, SWT.NONE);
|
|
1842 |
valueCombo.setItems(values);
|
|
1843 |
valueCombo.setEditable(false);
|
|
1844 |
valueCombo.setBackground(getWhite());
|
|
1845 |
if(selectedValue != null){
|
|
1846 |
setValueTextAndEnabling(valueCombo, selectedValue, randomValueText, typeComboSelection);
|
|
1847 |
}
|
|
1848 |
|
|
1849 |
item.setText(1, valueCombo.getText());
|
|
1850 |
|
|
1851 |
valueCombo.addSelectionListener(new SelectionAdapter() {
|
|
1852 |
public void widgetSelected(SelectionEvent event) {
|
|
1853 |
item.setText(1, valueCombo.getText());
|
|
1854 |
}
|
|
1855 |
});
|
|
1856 |
|
|
1857 |
editor.grabHorizontal = true;
|
|
1858 |
editor.setEditor(valueCombo, item, 1);
|
|
1859 |
|
|
1860 |
if(isContactSetReference){
|
|
1861 |
setContextSensitiveHelpID(valueCombo, CreatorHelpContextIDs.CREATOR_HELP_CONTACT_SET);
|
|
1862 |
}else{
|
|
1863 |
setContextSensitiveHelpIDByComponentType(valueCombo);
|
|
1864 |
}
|
|
1865 |
|
|
1866 |
return valueCombo;
|
|
1867 |
}
|
|
1868 |
|
|
1869 |
/**
|
|
1870 |
* Get selection value for type Combo by item content (key) and itemIndex
|
|
1871 |
* @param key for returning back if it was not empty
|
|
1872 |
* @param itemIndex a row index just adding
|
|
1873 |
* @param openItemType
|
|
1874 |
* @return a showable Item name or empty string, key if it was not empty or next value for items,
|
|
1875 |
* or empty string if index was over last item index
|
|
1876 |
*/
|
|
1877 |
private String getTypeComboSelection(String key, int itemIndex, boolean openItemType) {
|
|
1878 |
if(key == null ){
|
|
1879 |
return AbstractValue.EMPTY_STRING;
|
|
1880 |
}
|
|
1881 |
else if(key.equals(AbstractValue.EMPTY_STRING)
|
|
1882 |
&& getItemTypesAsString().length > itemIndex)
|
|
1883 |
{
|
|
1884 |
String setThisItemAsDefaultSelection = "";
|
|
1885 |
if(openItemType){
|
|
1886 |
setThisItemAsDefaultSelection = getItemTypesAsString()[itemIndex];
|
|
1887 |
}
|
|
1888 |
return setThisItemAsDefaultSelection;
|
|
1889 |
}else{
|
|
1890 |
return key;
|
|
1891 |
}
|
|
1892 |
}
|
|
1893 |
|
|
1894 |
/**
|
|
1895 |
* @return unicode Font
|
|
1896 |
*/
|
|
1897 |
protected Font getUnicodeFont() {
|
|
1898 |
Font defaultFont = itemsTable.getFont();
|
|
1899 |
FontData defaulFD [] = defaultFont.getFontData();
|
|
1900 |
FontData fd = new FontData("Arial Unicode MS", defaulFD[0].getHeight(), defaulFD[0].getStyle());
|
|
1901 |
return new Font(Display.getCurrent(), fd);
|
|
1902 |
}
|
|
1903 |
|
|
1904 |
/**
|
|
1905 |
* Gets 1 size smaller font for the button
|
|
1906 |
* @return same Font with smaller size
|
|
1907 |
*/
|
|
1908 |
protected Font getButtonFont() {
|
|
1909 |
Font defaultFont = itemsTable.getFont();
|
|
1910 |
FontData defaulFD [] = defaultFont.getFontData();
|
|
1911 |
FontData fd = new FontData(defaulFD[0].getName(), defaulFD[0].getHeight()-1, defaulFD[0].getStyle());
|
|
1912 |
Font font = new Font(Display.getCurrent(), fd);
|
|
1913 |
return font;
|
|
1914 |
}
|
|
1915 |
|
|
1916 |
/* (non-Javadoc)
|
|
1917 |
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
|
|
1918 |
*/
|
|
1919 |
protected void createButtonsForButtonBar(Composite parent) {
|
|
1920 |
// Creating just OK button
|
|
1921 |
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
|
|
1922 |
true);
|
|
1923 |
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL,
|
|
1924 |
true);
|
|
1925 |
|
|
1926 |
}
|
|
1927 |
|
|
1928 |
|
|
1929 |
/*
|
|
1930 |
* Collecting Component data from table fields
|
|
1931 |
* (non-Javadoc)
|
|
1932 |
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
|
|
1933 |
*/
|
|
1934 |
protected void okPressed() {
|
|
1935 |
|
|
1936 |
//When in edit mode, just removing all attributes and replace them with current editor values
|
|
1937 |
if(isInEditMode()){
|
|
1938 |
getComponent().removeAllAttributes();
|
|
1939 |
}else{
|
|
1940 |
//otherwise creating new component
|
|
1941 |
setComponent(createNewComponent());
|
|
1942 |
}
|
|
1943 |
|
|
1944 |
if(itemsTable != null){
|
|
1945 |
|
|
1946 |
TableItem [] items = itemsTable.getItems();
|
|
1947 |
|
|
1948 |
for (int i = 0; i < items.length; i++) {
|
|
1949 |
|
|
1950 |
TableItem item = items[i];
|
|
1951 |
|
|
1952 |
if(item != null){
|
|
1953 |
|
|
1954 |
String type = item.getText(0);
|
|
1955 |
String value = item.getText(1);
|
|
1956 |
|
|
1957 |
if(type != null && type.trim().length()>0
|
|
1958 |
&& value != null && value.trim().length()>0){
|
|
1959 |
value = value.trim();//Editor will produce script with no extra spaces.
|
|
1960 |
|
|
1961 |
AbstractValue aValue = createNewValue(type, value, item.getText(2), item.getText(3));
|
|
1962 |
|
|
1963 |
//If field is Contact set reference
|
|
1964 |
if(CreatorEditorSettings.isContactSetReference(type)){
|
|
1965 |
|
|
1966 |
AbstractComponent compToReference = getProvider().getComponents()
|
|
1967 |
.getComponentByComponentString( value );
|
|
1968 |
|
|
1969 |
aValue.setContactSetReference(true);
|
|
1970 |
aValue.setRandom(false);//contact set reference cannot be random
|
|
1971 |
int id = 0;
|
|
1972 |
try {
|
|
1973 |
id=compToReference.getId();
|
|
1974 |
} catch (Exception e) {
|
|
1975 |
id = 0;
|
|
1976 |
showWarningDialog("Contact Set not exist", "Contact Set with id: '" +value +"' doesn't exist, please use existing Contact Set IDs.");
|
|
1977 |
}
|
|
1978 |
aValue.setId(id);
|
|
1979 |
|
|
1980 |
int maxamount = 0;
|
|
1981 |
try {
|
|
1982 |
maxamount=Integer.parseInt(item.getText(3));
|
|
1983 |
} catch (Exception e) {
|
|
1984 |
maxamount = 0;
|
|
1985 |
}
|
|
1986 |
aValue.setMaxAmount(maxamount);
|
|
1987 |
}
|
|
1988 |
|
|
1989 |
//Setting random type as user defined and set length by user definition
|
|
1990 |
else if(aValue.getModeValueText().equalsIgnoreCase(AbstractValue.RANDOM_TEXT_USER_DEFINED_LENGTH)){
|
|
1991 |
aValue.setModeType(ModeTypes.RandomTypeUserDefinedLength);
|
|
1992 |
int randomLen;
|
|
1993 |
try {
|
|
1994 |
randomLen = Integer.parseInt(value);
|
|
1995 |
} catch (NumberFormatException e) {
|
|
1996 |
e.printStackTrace();
|
|
1997 |
randomLen = AbstractValue.USER_DEFINED_DEFAULT_LENGTH;
|
|
1998 |
showWarningDialog("Invalid random value", "Invalid user defined random lenght value: '"
|
|
1999 |
+value +"'. Value was set to: '" +AbstractValue.USER_DEFINED_DEFAULT_LENGTH +"'.");
|
|
2000 |
|
|
2001 |
}
|
|
2002 |
aValue.setRandomValueLenght(randomLen);
|
|
2003 |
}
|
|
2004 |
|
|
2005 |
Vector<AbstractValue> v = getComponent().getAttribute(type);
|
|
2006 |
if(v == null){
|
|
2007 |
v = new Vector<AbstractValue>();
|
|
2008 |
}
|
|
2009 |
v.add(aValue);
|
|
2010 |
|
|
2011 |
getComponent().setAttribute(type, v);
|
|
2012 |
}
|
|
2013 |
}
|
|
2014 |
}
|
|
2015 |
|
|
2016 |
}
|
|
2017 |
//Amount txt for component level
|
|
2018 |
if(amoutTxtToComponent != null){
|
|
2019 |
String amount = amoutTxtToComponent.getText();
|
|
2020 |
if(amount != null && amount.trim().length() > 0){
|
|
2021 |
try {
|
|
2022 |
int am = Integer.parseInt(amount);
|
|
2023 |
getComponent().setAmount(am);
|
|
2024 |
} catch (Exception e) {
|
|
2025 |
//just in case take Exception for parseInt, should not be occur, because of text field data validation
|
|
2026 |
e.printStackTrace();
|
|
2027 |
getComponent().setAmount(0);
|
|
2028 |
}
|
|
2029 |
}
|
|
2030 |
}
|
|
2031 |
|
|
2032 |
|
|
2033 |
//If extra field number is used
|
|
2034 |
if(extraNbrToComponent != null){
|
|
2035 |
getComponent().addAdditionalParameter(getComponent().getIdByValue(labelForExtraNumberField), extraNbrToComponent.getText());
|
|
2036 |
}
|
|
2037 |
//If extra field txt is used
|
|
2038 |
if(extraTxtToComponent != null){
|
|
2039 |
getComponent().addAdditionalParameter(getComponent().getIdByValue(labelForExtraTextField), extraTxtToComponent.getText());
|
|
2040 |
}
|
|
2041 |
|
|
2042 |
//Set link to another component if any
|
|
2043 |
setLinkToOtherComponentByComboSelection();
|
|
2044 |
|
|
2045 |
super.okPressed();
|
|
2046 |
|
|
2047 |
}
|
|
2048 |
|
|
2049 |
/**
|
|
2050 |
* Show an confirmation dialog
|
|
2051 |
* @param title
|
|
2052 |
* @param message
|
|
2053 |
* @return true if OK pressed, false otherwise
|
|
2054 |
*/
|
|
2055 |
protected boolean showConfirmationDialog(String title, String message) {
|
|
2056 |
Shell sh;
|
|
2057 |
if (getShell() != null) {
|
|
2058 |
try {
|
|
2059 |
sh = getShell();
|
|
2060 |
} catch (SWTException e) {
|
|
2061 |
sh = CreatorActivator.getCurrentlyActiveWbWindowShell();
|
|
2062 |
}
|
|
2063 |
|
|
2064 |
} else {
|
|
2065 |
sh = CreatorActivator.getCurrentlyActiveWbWindowShell();
|
|
2066 |
}
|
|
2067 |
|
|
2068 |
return MessageDialog.openConfirm(sh, title, message);
|
|
2069 |
}
|
|
2070 |
|
|
2071 |
|
|
2072 |
/**
|
|
2073 |
* Show an information dialog
|
|
2074 |
* @param title
|
|
2075 |
* @param message
|
|
2076 |
*/
|
|
2077 |
protected void showInformationDialog(String title, String message) {
|
|
2078 |
Shell sh;
|
|
2079 |
if (getShell() != null) {
|
|
2080 |
try {
|
|
2081 |
sh = getShell();
|
|
2082 |
} catch (SWTException e) {
|
|
2083 |
sh = CreatorActivator.getCurrentlyActiveWbWindowShell();
|
|
2084 |
}
|
|
2085 |
|
|
2086 |
} else {
|
|
2087 |
sh = CreatorActivator.getCurrentlyActiveWbWindowShell();
|
|
2088 |
}
|
|
2089 |
|
|
2090 |
MessageDialog.openInformation(sh, title, message);
|
|
2091 |
}
|
|
2092 |
/**
|
|
2093 |
* Show an warning dialog
|
|
2094 |
* @param title
|
|
2095 |
* @param message
|
|
2096 |
*/
|
|
2097 |
protected void showWarningDialog(String title, String message) {
|
|
2098 |
Shell sh;
|
|
2099 |
if (getShell() != null) {
|
|
2100 |
try {
|
|
2101 |
sh = getShell();
|
|
2102 |
} catch (SWTException e) {
|
|
2103 |
sh = CreatorActivator.getCurrentlyActiveWbWindowShell();
|
|
2104 |
}
|
|
2105 |
|
|
2106 |
} else {
|
|
2107 |
sh = CreatorActivator.getCurrentlyActiveWbWindowShell();
|
|
2108 |
}
|
|
2109 |
|
|
2110 |
MessageDialog.openWarning(sh, title, message);
|
|
2111 |
}
|
|
2112 |
/**
|
|
2113 |
* Show an error dialog
|
|
2114 |
* @param title
|
|
2115 |
* @param message
|
|
2116 |
*/
|
|
2117 |
protected void showErrorDialog(String title, String message) {
|
|
2118 |
Shell sh;
|
|
2119 |
if (getShell() != null) {
|
|
2120 |
try {
|
|
2121 |
sh = getShell();
|
|
2122 |
} catch (SWTException e) {
|
|
2123 |
sh = CreatorActivator.getCurrentlyActiveWbWindowShell();
|
|
2124 |
}
|
|
2125 |
|
|
2126 |
} else {
|
|
2127 |
sh = CreatorActivator.getCurrentlyActiveWbWindowShell();
|
|
2128 |
}
|
|
2129 |
|
|
2130 |
MessageDialog.openError(sh, title, message);
|
|
2131 |
}
|
|
2132 |
|
|
2133 |
/*
|
|
2134 |
* (non-Javadoc)
|
|
2135 |
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
|
|
2136 |
*/
|
|
2137 |
protected Control createDialogArea(Composite parent) {
|
|
2138 |
|
|
2139 |
try{
|
|
2140 |
Composite composite = createDialogAreaComposite(parent);
|
|
2141 |
GridLayout gridLayout = new GridLayout();
|
|
2142 |
composite.setLayout(gridLayout);
|
|
2143 |
|
|
2144 |
//Create Amount area
|
|
2145 |
createAmountArea(composite);
|
|
2146 |
|
|
2147 |
//Create table area
|
|
2148 |
createTableArea(composite);
|
|
2149 |
|
|
2150 |
if(/*showAmountInfoText &&*/ isAmountFieldsEnabled){
|
|
2151 |
addInformation(composite, AMOUNT_FIELD_INFO_TEXT);
|
|
2152 |
}
|
|
2153 |
|
|
2154 |
if(wasErrors()){
|
|
2155 |
showErrorDialog("Errors occured when dialog opened", getErrors());
|
|
2156 |
}
|
|
2157 |
|
|
2158 |
return composite;
|
|
2159 |
}catch(Exception e){
|
|
2160 |
e.printStackTrace();
|
|
2161 |
showUnableToOpenDialogErrorMsg(e);
|
|
2162 |
}
|
|
2163 |
return null;
|
|
2164 |
}
|
|
2165 |
|
|
2166 |
/**
|
|
2167 |
* Creates a composite for dialog area
|
|
2168 |
* @param parent
|
|
2169 |
* @return a Composite
|
|
2170 |
*/
|
|
2171 |
protected Composite createDialogAreaComposite(Composite parent) {
|
|
2172 |
Composite composite = (Composite) super.createDialogArea(parent);
|
|
2173 |
return composite;
|
|
2174 |
}
|
|
2175 |
|
|
2176 |
/**
|
|
2177 |
* Creating all items to dialog area, a real implementation for createDialogArea(Composite parent)
|
|
2178 |
*/
|
|
2179 |
protected void createTableArea(Composite composite) {
|
|
2180 |
final int cols = 1;
|
|
2181 |
GridLayout gdl = new GridLayout(cols, false);
|
|
2182 |
GridData gd = new GridData(GridData.FILL_BOTH);
|
|
2183 |
|
|
2184 |
|
|
2185 |
Composite tableComposite = new Composite(composite, SWT.SIMPLE);
|
|
2186 |
tableComposite.setLayout(gdl);
|
|
2187 |
tableComposite.setLayoutData(gd);
|
|
2188 |
|
|
2189 |
itemsTable = new Table (tableComposite, SWT.BORDER | SWT.MULTI);
|
|
2190 |
GridData tableGd = new GridData(GridData.FILL_BOTH);
|
|
2191 |
tableGd.heightHint = 300;
|
|
2192 |
itemsTable.setLayoutData(tableGd);
|
|
2193 |
itemsTable.setLinesVisible (true);
|
|
2194 |
itemsTable.setHeaderVisible(true);
|
|
2195 |
itemsTable.setEnabled(isTableEnabled);
|
|
2196 |
|
|
2197 |
//Create columns to table
|
|
2198 |
createTableColums();
|
|
2199 |
|
|
2200 |
AbstractComponent component = (AbstractComponent) getComponent();
|
|
2201 |
Set<String> keys = component.getKeys();
|
|
2202 |
Vector<String> keysV = new Vector<String>(keys);
|
|
2203 |
|
|
2204 |
|
|
2205 |
//Create rows to table +2 is for new items
|
|
2206 |
int actualComponentItemCount = component.getAttributeCount();// +2;
|
|
2207 |
int allCompoenentItemCount = getItemTypesAsString().length;
|
|
2208 |
//Always create at least 12 rows
|
|
2209 |
if(!isInEditMode() && actualComponentItemCount < INITIAL_ITEMS_NUMBER_IN_TABLE ){
|
|
2210 |
if(allCompoenentItemCount > INITIAL_ITEMS_NUMBER_IN_TABLE){
|
|
2211 |
actualComponentItemCount = INITIAL_ITEMS_NUMBER_IN_TABLE;
|
|
2212 |
}
|
|
2213 |
else{
|
|
2214 |
actualComponentItemCount = allCompoenentItemCount;
|
|
2215 |
}
|
|
2216 |
}
|
|
2217 |
|
|
2218 |
|
|
2219 |
//Looping through table and add existing data or empty rows
|
|
2220 |
for (int i=0; i<actualComponentItemCount; i++) {
|
|
2221 |
//TableEditor editor = new TableEditor (itemsTable);
|
|
2222 |
|
|
2223 |
//Creating empty rows if there is no data allready added at least 12 rows
|
|
2224 |
if (i >= component.getAttributeCount()){
|
|
2225 |
try {
|
|
2226 |
addRow(!isInEditMode(), false);
|
|
2227 |
} catch (Exception e) {
|
|
2228 |
handleTableRowCreationError(e);
|
|
2229 |
}
|
|
2230 |
}
|
|
2231 |
//rows of the table where is data added
|
|
2232 |
else{
|
|
2233 |
String key = (String) keysV.get(i);
|
|
2234 |
Vector<AbstractValue> values = component.getAttribute(key);
|
|
2235 |
for (Iterator<AbstractValue> iterator = values.iterator(); iterator.hasNext();) {
|
|
2236 |
AbstractValue value = (AbstractValue) iterator
|
|
2237 |
.next();
|
|
2238 |
try {
|
|
2239 |
addRow(key, value, false);
|
|
2240 |
} catch (Exception e) {
|
|
2241 |
handleTableRowCreationError(e);
|
|
2242 |
}
|
|
2243 |
|
|
2244 |
}
|
|
2245 |
//Adding one row to Table
|
|
2246 |
|
|
2247 |
}//else
|
|
2248 |
}
|
|
2249 |
|
|
2250 |
//Notify listeners to update values when all rows are set
|
|
2251 |
checkIfNeedToCallItemValueEnablationListners();
|
|
2252 |
|
|
2253 |
//Notify table listeners to update item combos
|
|
2254 |
notifyTypeComboDataListeners();
|
|
2255 |
|
|
2256 |
//Create add row button
|
|
2257 |
createAddRowButton(tableComposite);
|
|
2258 |
|
|
2259 |
if(wasErrorsWithDatas){
|
|
2260 |
showErrorDialog("Errors on script", "There was some errors when opening component, see Console for details.");
|
|
2261 |
}
|
|
2262 |
}
|
|
2263 |
|
|
2264 |
/**
|
|
2265 |
* Set wasErrorsWithDatas as true and prints console error message
|
|
2266 |
* @param e
|
|
2267 |
*/
|
|
2268 |
private void handleTableRowCreationError(Exception e) {
|
|
2269 |
wasErrorsWithDatas = true;
|
|
2270 |
e.printStackTrace();
|
|
2271 |
CreatorEditorConsole.getInstance().println(UNEXPECTED_ERROR_WHEN_CREATING_TABLE_AREA_ERROR_WAS +e, CreatorEditorConsole.MSG_ERROR);
|
|
2272 |
}
|
|
2273 |
|
|
2274 |
/**
|
|
2275 |
* Creates an Add row button to selected composite
|
|
2276 |
* @param parent
|
|
2277 |
*/
|
|
2278 |
private void createAddRowButton(Composite parent) {
|
|
2279 |
addRowButton = new Button(parent, SWT.PUSH);
|
|
2280 |
addRowButton.setText(ADD_ROW_TXT);
|
|
2281 |
//Add add row functionality
|
|
2282 |
addRowButton.addSelectionListener(new SelectionAdapter(){
|
|
2283 |
|
|
2284 |
public void widgetSelected(SelectionEvent event) {
|
|
2285 |
try {
|
|
2286 |
addRow(true, true);
|
|
2287 |
//Notify table listeners to update item combos
|
|
2288 |
notifyTypeComboDataListeners();
|
|
2289 |
|
|
2290 |
//notify also listners if needed
|
|
2291 |
checkIfNeedToCallItemValueEnablationListners();
|
|
2292 |
} catch (Exception e) {
|
|
2293 |
handleTableRowCreationError(e);
|
|
2294 |
}
|
|
2295 |
}
|
|
2296 |
|
|
2297 |
});
|
|
2298 |
setContextSensitiveHelpID(addRowButton, CreatorHelpContextIDs.CREATOR_HELP_MODIFY_COMPONENT);
|
|
2299 |
}
|
|
2300 |
|
|
2301 |
/**
|
|
2302 |
* Creates a button to launch "Create new Contact-set" -dialog.
|
|
2303 |
* @param composite
|
|
2304 |
* @param addIndent - If add some empty space before creating button |" " <BUTTON>|
|
|
2305 |
*/
|
|
2306 |
protected void createAddNewContactSetButton(Composite composite, boolean addIndent){
|
|
2307 |
|
|
2308 |
|
|
2309 |
if(addIndent){
|
|
2310 |
//Adding empty labe for decoration purposes
|
|
2311 |
Label emptyText = new Label(composite, SWT.SIMPLE);
|
|
2312 |
emptyText.setBackground(getGrey());
|
|
2313 |
emptyText.setText(" ");
|
|
2314 |
}
|
|
2315 |
|
|
2316 |
addContactSetButton = new Button(composite, SWT.PUSH);
|
|
2317 |
addContactSetButton.setText(ContactSetVariables.ADD_CONTACT_SET_TXT);
|
|
2318 |
|
|
2319 |
//add button listener
|
|
2320 |
addContactSetButton.addSelectionListener(provider.getAddNewContactSetComponentListener(getShell(), provider));
|
|
2321 |
addContactSetButton.setData(linkToOtherComponentCombo);
|
|
2322 |
|
|
2323 |
//When a new component was added, must update data in list, doing it through listener,
|
|
2324 |
//which is provided to dialog through event.widget.data
|
|
2325 |
addContactSetButton.setData(new AddNewContactSetButtonListener (null));
|
|
2326 |
|
|
2327 |
}
|
|
2328 |
|
|
2329 |
/**
|
|
2330 |
* Update link list when new component was added
|
|
2331 |
*/
|
|
2332 |
private class AddNewContactSetButtonListener implements IAddComponentListener{
|
|
2333 |
|
|
2334 |
private CCombo combo = null;
|
|
2335 |
|
|
2336 |
|
|
2337 |
AddNewContactSetButtonListener(CCombo combo){
|
|
2338 |
this.combo = combo;
|
|
2339 |
|
|
2340 |
}
|
|
2341 |
|
|
2342 |
|
|
2343 |
/* (non-Javadoc)
|
|
2344 |
* @see com.nokia.s60tools.creator.editors.IAddComponentListener#componentAdded(com.nokia.s60tools.creator.components.AbstractComponent)
|
|
2345 |
*/
|
|
2346 |
public void componentAdded(AbstractComponent comp) {
|
|
2347 |
|
|
2348 |
if(comp != null && comp.isValid() && linkToOtherComponentCombo != null){
|
|
2349 |
String[] contactSetsAsString = getContactSetsAsString();
|
|
2350 |
//If list is empty, cant just add one just created, so setting all values
|
|
2351 |
String selection = linkToOtherComponentCombo.getText();
|
|
2352 |
linkToOtherComponentCombo.setItems(contactSetsAsString);
|
|
2353 |
if(selection != null){
|
|
2354 |
linkToOtherComponentCombo.setText(selection);
|
|
2355 |
}
|
|
2356 |
linkToOtherComponentCombo.setEnabled(true);
|
|
2357 |
|
|
2358 |
}
|
|
2359 |
|
|
2360 |
|
|
2361 |
//Woke upp also other listeners who's intressed of this event! (those who has combo!=null)
|
|
2362 |
Event event = new Event();
|
|
2363 |
event.doit = true;
|
|
2364 |
addContactSetButton.notifyListeners(SWT.SetData, event);
|
|
2365 |
|
|
2366 |
}
|
|
2367 |
|
|
2368 |
|
|
2369 |
/* (non-Javadoc)
|
|
2370 |
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
|
|
2371 |
*/
|
|
2372 |
public void handleEvent(Event event) {
|
|
2373 |
if(combo != null && event.doit){
|
|
2374 |
String text = combo.getText();
|
|
2375 |
String[] contactSetsAsString = getContactSetsAsString();
|
|
2376 |
combo.setItems(contactSetsAsString);
|
|
2377 |
int length = contactSetsAsString.length;
|
|
2378 |
if(length > MAX_ITEMS_IN_COMBO){
|
|
2379 |
length = MAX_ITEMS_IN_COMBO;
|
|
2380 |
}
|
|
2381 |
combo.setVisibleItemCount(length);
|
|
2382 |
combo.setText(text);
|
|
2383 |
}
|
|
2384 |
}
|
|
2385 |
}
|
|
2386 |
|
|
2387 |
/**
|
|
2388 |
* Create Amount area with label and text field to add label
|
|
2389 |
* @param parent
|
|
2390 |
*/
|
|
2391 |
protected void createAmountArea(Composite parent) {
|
|
2392 |
Composite amountComp = new Composite(parent,SWT.SIMPLE);
|
|
2393 |
amountComp.setLayout(new GridLayout(5, false));
|
|
2394 |
GridData gridData = new GridData(GridData.FILL_BOTH);
|
|
2395 |
gridData.heightHint = 45;
|
|
2396 |
amountComp.setLayoutData(gridData);
|
|
2397 |
|
|
2398 |
createAmountAreaImpl(amountComp);
|
|
2399 |
createFulFillWithRandomDatas(amountComp);
|
|
2400 |
}
|
|
2401 |
|
|
2402 |
/**
|
|
2403 |
* Create Amount area with label and text field to add label
|
|
2404 |
* @param parent
|
|
2405 |
* @param addCreateNewContactSetButton <code>true</code> if Botton for creating contact-set(s)
|
|
2406 |
* will be created, <code>false</code> otherwise.
|
|
2407 |
*/
|
|
2408 |
protected void createAmountArea(Composite parent, boolean addCreateNewContactSetButton) {
|
|
2409 |
|
|
2410 |
if(!addCreateNewContactSetButton){
|
|
2411 |
createAmountArea(parent);
|
|
2412 |
}
|
|
2413 |
else{
|
|
2414 |
Composite amountComp = new Composite(parent,SWT.SIMPLE);
|
|
2415 |
amountComp.setLayout(new GridLayout(7, false));
|
|
2416 |
GridData gridData = new GridData(GridData.FILL_BOTH);
|
|
2417 |
gridData.heightHint = 45;
|
|
2418 |
amountComp.setLayoutData(gridData);
|
|
2419 |
|
|
2420 |
createAmountAreaImpl(amountComp);
|
|
2421 |
//Create button to create new contact sets
|
|
2422 |
createAddNewContactSetButton(amountComp, true);
|
|
2423 |
|
|
2424 |
createFulFillWithRandomDatas(amountComp);
|
|
2425 |
}
|
|
2426 |
}
|
|
2427 |
|
|
2428 |
/**
|
|
2429 |
* Create Amount area with label and text field to add label.
|
|
2430 |
* Takes real composite as parameter, not parent
|
|
2431 |
* @param composite
|
|
2432 |
*/
|
|
2433 |
private void createAmountAreaImpl(Composite amountComp) {
|
|
2434 |
Label amoutLb = new Label(amountComp,SWT.NONE);
|
|
2435 |
amoutLb.setText(AMOUNT_TXT);
|
|
2436 |
|
|
2437 |
amoutTxtToComponent = new Text(amountComp, SWT.LEFT | SWT.BORDER);
|
|
2438 |
amoutTxtToComponent.setLayoutData(new GridData(AMOUNT_FIELD_LENGTH,
|
|
2439 |
SWT.DEFAULT));
|
|
2440 |
amoutTxtToComponent.setTextLimit(10);
|
|
2441 |
if(getComponent().getAmount() > 0){
|
|
2442 |
amoutTxtToComponent.setText( "" +getComponent().getAmount());
|
|
2443 |
}
|
|
2444 |
//Verify listener must be set after setting text
|
|
2445 |
amoutTxtToComponent.addVerifyListener(getNumberVerifyListener());
|
|
2446 |
|
|
2447 |
setContextSensitiveHelpID(amoutTxtToComponent, CreatorHelpContextIDs.CREATOR_HELP_GENERIC_COMPONENT);
|
|
2448 |
|
|
2449 |
}
|
|
2450 |
|
|
2451 |
/**
|
|
2452 |
* Creates
|
|
2453 |
* @param amountComp
|
|
2454 |
*/
|
|
2455 |
private void createFulFillWithRandomDatas(Composite amountComp) {
|
|
2456 |
//
|
|
2457 |
//Fulfill items with random -functionality buttons
|
|
2458 |
//
|
|
2459 |
|
|
2460 |
Label fulFillLb1 = new Label(amountComp,SWT.NONE);
|
|
2461 |
fulFillLb1.setText(" Set all values as random with length:");
|
|
2462 |
|
|
2463 |
Composite radioComp = new Composite(amountComp, SWT.SIMPLE);
|
|
2464 |
RowLayout rowLayout = new RowLayout();
|
|
2465 |
rowLayout.type = SWT.VERTICAL;
|
|
2466 |
radioComp.setLayout(rowLayout);
|
|
2467 |
final Button selectLenDefaultBtn = new Button(radioComp, SWT.RADIO);
|
|
2468 |
selectLenDefaultBtn.setText(RANDOM_LEN_DEFAULT);
|
|
2469 |
selectLenDefaultBtn.setSelection(true);
|
|
2470 |
final Button selectLenMaxBtn = new Button(radioComp, SWT.RADIO);
|
|
2471 |
selectLenMaxBtn.setText(RANDOM_LEN_MAX);
|
|
2472 |
Button setAsRandom = new Button(amountComp, SWT.PUSH);
|
|
2473 |
setAsRandom.setText(SET_RANDOM_TXT);
|
|
2474 |
setAsRandom.addSelectionListener(new SelectionAdapter() {
|
|
2475 |
public void widgetSelected(SelectionEvent event) {
|
|
2476 |
String len = AbstractVariables.RANDOM_LEN_DEFAULT_XML_VALUE;
|
|
2477 |
boolean selection = selectLenMaxBtn.getSelection();
|
|
2478 |
if(selection){
|
|
2479 |
len = AbstractVariables.RANDOM_LEN_MAX_XML_VALUE;
|
|
2480 |
}
|
|
2481 |
boolean setAllValuesAsRandom = showConfirmationDialog("Set all Values as random", "Are you sure that you want to set all values as random? All existing values will be replaced by random value with " +len +" length.");
|
|
2482 |
if(setAllValuesAsRandom){
|
|
2483 |
setAllItemsAsRandom(selection);
|
|
2484 |
}
|
|
2485 |
}
|
|
2486 |
});
|
|
2487 |
|
|
2488 |
setContextSensitiveHelpID(selectLenDefaultBtn, CreatorHelpContextIDs.CREATOR_HELP_GENERIC_COMPONENT);
|
|
2489 |
setContextSensitiveHelpID(selectLenMaxBtn, CreatorHelpContextIDs.CREATOR_HELP_GENERIC_COMPONENT);
|
|
2490 |
setContextSensitiveHelpID(setAsRandom, CreatorHelpContextIDs.CREATOR_HELP_GENERIC_COMPONENT);
|
|
2491 |
|
|
2492 |
}
|
|
2493 |
|
|
2494 |
/**
|
|
2495 |
* Creates a composite and creates extra numberfield and extra text field to it
|
|
2496 |
* @param parent
|
|
2497 |
* @param labelForNumberField
|
|
2498 |
* @param numberFieldValue
|
|
2499 |
* @param labelForTextField
|
|
2500 |
* @param textFieldValue
|
|
2501 |
*/
|
|
2502 |
protected void createNumberAndTextFields(Composite parent, String labelForNumberField,
|
|
2503 |
int numberFieldValue, String labelForTextField, String textFieldValue){
|
|
2504 |
|
|
2505 |
Composite comp = new Composite(parent,SWT.SIMPLE);
|
|
2506 |
comp.setLayout(new GridLayout(4, false));
|
|
2507 |
comp.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
2508 |
|
|
2509 |
createExtraNumberField(labelForNumberField, numberFieldValue, comp);
|
|
2510 |
|
|
2511 |
createExtraTextField(labelForTextField, textFieldValue, comp);
|
|
2512 |
|
|
2513 |
}
|
|
2514 |
|
|
2515 |
/**
|
|
2516 |
* Creates an extra text field and label to composite
|
|
2517 |
* @param labelForTextField
|
|
2518 |
* @param textFieldValue text value for field, or <code>null</code> if don't want any
|
|
2519 |
* @param comp
|
|
2520 |
*/
|
|
2521 |
protected void createExtraTextField(String labelForTextField,
|
|
2522 |
String textFieldValue, Composite comp) {
|
|
2523 |
this.labelForExtraTextField = labelForTextField;
|
|
2524 |
Label txtLb = new Label(comp,SWT.NONE);
|
|
2525 |
txtLb.setText(labelForTextField);
|
|
2526 |
|
|
2527 |
extraTxtToComponent = new Text(comp, SWT.LEFT | SWT.BORDER);
|
|
2528 |
extraTxtToComponent.setLayoutData(new GridData(TEXT_FIELD_LENGTH,
|
|
2529 |
SWT.DEFAULT ) );
|
|
2530 |
if(textFieldValue != null){
|
|
2531 |
extraTxtToComponent.setText(textFieldValue.trim());
|
|
2532 |
}
|
|
2533 |
|
|
2534 |
setContextSensitiveHelpIDByComponentType(extraTxtToComponent);
|
|
2535 |
}
|
|
2536 |
|
|
2537 |
/**
|
|
2538 |
* Creates an extra number field and label to composite
|
|
2539 |
* @param labelForNumberField
|
|
2540 |
* @param numberFieldValue number value to field, give 0 if don't want any
|
|
2541 |
* @param comp
|
|
2542 |
*/
|
|
2543 |
protected void createExtraNumberField(String labelForNumberField,
|
|
2544 |
int numberFieldValue, Composite comp) {
|
|
2545 |
this.labelForExtraNumberField = labelForNumberField;
|
|
2546 |
Label nbrLb = new Label(comp,SWT.NONE);
|
|
2547 |
nbrLb.setText(labelForExtraNumberField);
|
|
2548 |
|
|
2549 |
extraNbrToComponent = new Text(comp, SWT.LEFT | SWT.BORDER);
|
|
2550 |
extraNbrToComponent.setLayoutData(new GridData(AMOUNT_FIELD_LENGTH,
|
|
2551 |
SWT.DEFAULT));
|
|
2552 |
extraNbrToComponent.setTextLimit(10);
|
|
2553 |
if(numberFieldValue > 0){
|
|
2554 |
extraNbrToComponent.setText( "" +numberFieldValue);
|
|
2555 |
}
|
|
2556 |
//Verify listener must be set after setting text
|
|
2557 |
extraNbrToComponent.addVerifyListener(getNumberVerifyListener());
|
|
2558 |
setContextSensitiveHelpIDByComponentType(extraNbrToComponent);
|
|
2559 |
}
|
|
2560 |
|
|
2561 |
/**
|
|
2562 |
* Create Amount area with label and text field to add label
|
|
2563 |
* @param parent
|
|
2564 |
*/
|
|
2565 |
protected void createAmountAreaAndLinkToOtherComponentCombo(Composite parent, String comboLabel,
|
|
2566 |
String[] contentToComponentLinkCombo, String contactSetSelection,
|
|
2567 |
boolean addCreateNewContactSetButton, boolean createFullFillWithRandom) {
|
|
2568 |
if(addCreateNewContactSetButton){
|
|
2569 |
createAmountAreaAndLinkToOtherComponentComboWithCreateButton(
|
|
2570 |
parent, comboLabel, contentToComponentLinkCombo, contactSetSelection,
|
|
2571 |
createFullFillWithRandom);
|
|
2572 |
}else{
|
|
2573 |
createAmountAreaAndLinkToOtherComponentCombo(
|
|
2574 |
parent, comboLabel, contentToComponentLinkCombo, contactSetSelection,
|
|
2575 |
createFullFillWithRandom);
|
|
2576 |
}
|
|
2577 |
if(getComponent() instanceof Contact) {
|
|
2578 |
setContextSensitiveHelpID(linkToOtherComponentCombo, CreatorHelpContextIDs.CREATOR_HELP_CONTACT_SET );
|
|
2579 |
}else{
|
|
2580 |
setContextSensitiveHelpIDByComponentType(linkToOtherComponentCombo);
|
|
2581 |
}
|
|
2582 |
}
|
|
2583 |
/**
|
|
2584 |
* Create Amount area with label and text field to add label
|
|
2585 |
* @param parent
|
|
2586 |
*/
|
|
2587 |
private void createAmountAreaAndLinkToOtherComponentCombo(Composite parent, String comboLabel,
|
|
2588 |
String[] contentToComponentLinkCombo, String contactSetSelection,
|
|
2589 |
boolean createFullFillWithRandom) {
|
|
2590 |
Composite amountComp = new Composite(parent,SWT.SIMPLE);
|
|
2591 |
int numColumns = 7;
|
|
2592 |
|
|
2593 |
amountComp.setLayout(new GridLayout(numColumns, false));
|
|
2594 |
amountComp.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
2595 |
|
|
2596 |
createAmountAreaImpl(amountComp);
|
|
2597 |
|
|
2598 |
createLinkToOtherComponentPart(amountComp, comboLabel, contentToComponentLinkCombo,
|
|
2599 |
contactSetSelection, false);
|
|
2600 |
|
|
2601 |
if(createFullFillWithRandom){
|
|
2602 |
createFulFillWithRandomDatas(amountComp);
|
|
2603 |
}
|
|
2604 |
|
|
2605 |
|
|
2606 |
}
|
|
2607 |
/**
|
|
2608 |
* Create Amount area with label and text field to add label
|
|
2609 |
* @param parent
|
|
2610 |
*/
|
|
2611 |
private void createAmountAreaAndLinkToOtherComponentComboWithCreateButton(Composite parent, String comboLabel,
|
|
2612 |
String[] contentToComponentLinkCombo, String contactSetSelection,
|
|
2613 |
boolean createFullFillWithRandom) {
|
|
2614 |
Composite amountComp = new Composite(parent,SWT.SIMPLE);
|
|
2615 |
int numColumns = 5;
|
|
2616 |
amountComp.setLayout(new GridLayout(numColumns, false));
|
|
2617 |
amountComp.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
2618 |
|
|
2619 |
createAmountAreaImpl(amountComp);
|
|
2620 |
if(createFullFillWithRandom){
|
|
2621 |
createFulFillWithRandomDatas(amountComp);
|
|
2622 |
}
|
|
2623 |
|
|
2624 |
createLinkToOtherComponentPart(parent, comboLabel, contentToComponentLinkCombo,
|
|
2625 |
contactSetSelection, true);
|
|
2626 |
|
|
2627 |
}
|
|
2628 |
|
|
2629 |
protected void createLinkToOtherComponentPart(Composite parent, String comboLabel,
|
|
2630 |
String[] contentToComponentLinkCombo, String contactSetSelection,
|
|
2631 |
boolean addCreateNewContactSetButton) {
|
|
2632 |
|
|
2633 |
Composite linkComp = new Composite(parent,SWT.SIMPLE);
|
|
2634 |
int numColumns = 2;
|
|
2635 |
if(addCreateNewContactSetButton){
|
|
2636 |
numColumns ++;
|
|
2637 |
}
|
|
2638 |
|
|
2639 |
|
|
2640 |
linkComp.setLayout(new GridLayout(numColumns, false));
|
|
2641 |
linkComp.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
2642 |
//
|
|
2643 |
// Create link to other component
|
|
2644 |
//
|
|
2645 |
|
|
2646 |
Label setLb = new Label(linkComp,SWT.NONE);
|
|
2647 |
setLb.setText(comboLabel);
|
|
2648 |
|
|
2649 |
linkToOtherComponentCombo = new CCombo(linkComp, SWT.READ_ONLY | SWT.BORDER );
|
|
2650 |
linkToOtherComponentCombo .setBackground(getWhite());
|
|
2651 |
|
|
2652 |
//If there is some values, setting them to combo
|
|
2653 |
if(contentToComponentLinkCombo != null && contentToComponentLinkCombo.length > 0){
|
|
2654 |
setComponentsToOtherComponentLinkCombo(contentToComponentLinkCombo);
|
|
2655 |
}//Otherwise combo will be disabled
|
|
2656 |
else{
|
|
2657 |
linkToOtherComponentCombo .setEnabled(false);
|
|
2658 |
}
|
|
2659 |
|
|
2660 |
|
|
2661 |
//If we want to create button for add new contact-set
|
|
2662 |
if(addCreateNewContactSetButton){
|
|
2663 |
//Create button for creating new contact-sets
|
|
2664 |
createAddNewContactSetButton(linkComp, false);
|
|
2665 |
}
|
|
2666 |
|
|
2667 |
|
|
2668 |
if(contactSetSelection != null){
|
|
2669 |
setComboSelection(contentToComponentLinkCombo, linkToOtherComponentCombo, contactSetSelection);
|
|
2670 |
}
|
|
2671 |
}
|
|
2672 |
|
|
2673 |
|
|
2674 |
/**
|
|
2675 |
* Update items to other component link -Combo
|
|
2676 |
* @param contentToComponentLinkCombo
|
|
2677 |
*/
|
|
2678 |
protected void setComponentsToOtherComponentLinkCombo(
|
|
2679 |
String[] contentToComponentLinkCombo) {
|
|
2680 |
if(linkToOtherComponentCombo != null){
|
|
2681 |
linkToOtherComponentCombo.setItems(contentToComponentLinkCombo);
|
|
2682 |
}
|
|
2683 |
}
|
|
2684 |
|
|
2685 |
/**
|
|
2686 |
* Set all items in table as random.
|
|
2687 |
* @param setAsMaxLength
|
|
2688 |
*/
|
|
2689 |
private void setAllItemsAsRandom(boolean setAsMaxLength) {
|
|
2690 |
|
|
2691 |
TableItem[] items = itemsTable.getItems();
|
|
2692 |
|
|
2693 |
//Looping through all items in table
|
|
2694 |
for (int i = 0; i < items.length; i++) {
|
|
2695 |
|
|
2696 |
TableItem item = items[i];
|
|
2697 |
|
|
2698 |
if (item != null) {
|
|
2699 |
Event e = new SetRandomEvent();
|
|
2700 |
e.doit = true;
|
|
2701 |
item.notifyListeners(SWT.Modify, e);
|
|
2702 |
|
|
2703 |
String key = item.getText(0);
|
|
2704 |
|
|
2705 |
//When item is contact set reference, it cannot be random, or if random fields is disabled, they cannot be set as random.
|
|
2706 |
if(isRandomFieldsEnabled() && !CreatorEditorSettings.isContactSetReference(key) && getComponent().getVariables().isModeEnabledForKey(key)){
|
|
2707 |
//When there is a key, setting value as random
|
|
2708 |
if (key != null && key.trim().length() > 0) {
|
|
2709 |
//setting value as max or default
|
|
2710 |
if(setAsMaxLength){
|
|
2711 |
item.setText(1, AbstractValue.RANDOM_TEXT_MAX_LENGTH_LONG);
|
|
2712 |
item.setText(2, AbstractValue.RANDOM_TEXT_MAX_LENGTH);
|
|
2713 |
|
|
2714 |
}
|
|
2715 |
else{
|
|
2716 |
item.setText(1, AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH_LONG);
|
|
2717 |
item.setText(2, AbstractValue.RANDOM_TEXT_DEFAULT_LENGTH);
|
|
2718 |
}
|
|
2719 |
//Notify listeners by self
|
|
2720 |
item.notifyListeners(SWT.Modify, e);
|
|
2721 |
|
|
2722 |
}
|
|
2723 |
}
|
|
2724 |
}
|
|
2725 |
}
|
|
2726 |
}
|
|
2727 |
|
|
2728 |
|
|
2729 |
/*
|
|
2730 |
* (non-Javadoc)
|
|
2731 |
*
|
|
2732 |
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
|
|
2733 |
*/
|
|
2734 |
protected void configureShell(Shell shell) {
|
|
2735 |
super.configureShell(shell);
|
|
2736 |
if(isInEditMode()){
|
|
2737 |
shell.setText("Edit " +getComponent().getType() +"(s)");
|
|
2738 |
}else{
|
|
2739 |
shell.setText("Add " +getComponent().getType() +"(s)");
|
|
2740 |
}
|
|
2741 |
}
|
|
2742 |
|
|
2743 |
/**
|
|
2744 |
* Adds an information label to view
|
|
2745 |
* @param txt
|
|
2746 |
*/
|
|
2747 |
protected void addInformation(Composite composite, String txt){
|
|
2748 |
Composite infoComp = new Composite(composite,SWT.SIMPLE);
|
|
2749 |
infoComp.setLayout(new GridLayout(1, false));
|
|
2750 |
infoComp.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
2751 |
|
|
2752 |
GridData gd = new GridData(CreatorScriptEditor.EDITOR_DEFAULT_WIDTH, SWT.DEFAULT);
|
|
2753 |
Label info = new Label(infoComp,SWT.WRAP );
|
|
2754 |
info.setLayoutData(gd);
|
|
2755 |
info.setText(txt);
|
|
2756 |
}
|
|
2757 |
|
|
2758 |
/**
|
|
2759 |
* Get is amount fields enabled or not
|
|
2760 |
* @return true if is enabled
|
|
2761 |
*/
|
|
2762 |
protected boolean isAmountFieldsEnabled() {
|
|
2763 |
return isAmountFieldsEnabled;
|
|
2764 |
}
|
|
2765 |
|
|
2766 |
/**
|
|
2767 |
* Set amount fields enable or disable in table
|
|
2768 |
* @param isAmountFieldsEnabled
|
|
2769 |
*/
|
|
2770 |
protected void setAmountFieldsEnabled(boolean isAmountFieldsEnabled) {
|
|
2771 |
this.isAmountFieldsEnabled = isAmountFieldsEnabled;
|
|
2772 |
}
|
|
2773 |
|
|
2774 |
/**
|
|
2775 |
* Sets table enabled or disabled, default is enabled
|
|
2776 |
* @param b
|
|
2777 |
*/
|
|
2778 |
protected void setTableEnabled(boolean isTableEnabled) {
|
|
2779 |
this.isTableEnabled = isTableEnabled;
|
|
2780 |
}
|
|
2781 |
|
|
2782 |
|
|
2783 |
|
|
2784 |
/**
|
|
2785 |
* Get {@link IComponentProvider} interface
|
|
2786 |
* @return interface to provide component services
|
|
2787 |
*/
|
|
2788 |
protected IComponentProvider getProvider() {
|
|
2789 |
return provider;
|
|
2790 |
}
|
|
2791 |
|
|
2792 |
/**
|
|
2793 |
* Get selection text from other component selection Combo
|
|
2794 |
* @return selection text, or null if not created
|
|
2795 |
*/
|
|
2796 |
private String getLinkToOtherComponentComboSelection() {
|
|
2797 |
|
|
2798 |
String txt = null;
|
|
2799 |
if(linkToOtherComponentCombo != null){
|
|
2800 |
txt = linkToOtherComponentCombo.getText();
|
|
2801 |
}
|
|
2802 |
return txt;
|
|
2803 |
}
|
|
2804 |
|
|
2805 |
/**
|
|
2806 |
* Sets link to another component
|
|
2807 |
*/
|
|
2808 |
private void setLinkToOtherComponentByComboSelection() {
|
|
2809 |
|
|
2810 |
//text from combo
|
|
2811 |
String contactSetLinkText = getLinkToOtherComponentComboSelection();
|
|
2812 |
if(contactSetLinkText != null && contactSetLinkText.trim().length() >0){
|
|
2813 |
|
|
2814 |
//future improvement idea, "linkToOtherComponentCombo" is not the best name for additional component level data combo
|
|
2815 |
//also better way to handle data from that is to let real Dialog implementation to handle it.
|
|
2816 |
|
|
2817 |
//If component is mailbox, linktoanother component is actually type
|
|
2818 |
if(getComponent() instanceof MailBox){
|
|
2819 |
MailBox box = (MailBox) getComponent();
|
|
2820 |
box.setMailBoxType(contactSetLinkText.trim());
|
|
2821 |
}
|
|
2822 |
else{
|
|
2823 |
//get a component which the reference points
|
|
2824 |
AbstractComponent compToReference = getProvider().getComponents()
|
|
2825 |
.getComponentByComponentString( contactSetLinkText);
|
|
2826 |
//set reference to this component
|
|
2827 |
getComponent().setReferenceToAnotherComponent(compToReference);
|
|
2828 |
|
|
2829 |
|
|
2830 |
}
|
|
2831 |
}
|
|
2832 |
//There is possibility that contact set reference is removed, and thats why must remove existing reference
|
|
2833 |
else{
|
|
2834 |
getComponent().setReferenceToAnotherComponent(null);
|
|
2835 |
}
|
|
2836 |
|
|
2837 |
}
|
|
2838 |
|
|
2839 |
/**
|
|
2840 |
* Get Contact Sets as String
|
|
2841 |
* @return contact sets
|
|
2842 |
*/
|
|
2843 |
protected String[] getContactSetsAsString() {
|
|
2844 |
|
|
2845 |
Vector<AbstractComponent> contSets = getProvider().getComponents().getComponents(CreatorEditorSettings.TYPE_CONTACT_SET);
|
|
2846 |
|
|
2847 |
String[] arr = null;
|
|
2848 |
if(contSets != null && contSets.size() > 0){
|
|
2849 |
arr = new String[contSets.size()+1];
|
|
2850 |
int i = 1;
|
|
2851 |
arr[0] = AbstractValue.EMPTY_STRING;//To be able to reset selection
|
|
2852 |
for (Iterator<AbstractComponent> iterator = contSets.iterator(); iterator.hasNext();) {
|
|
2853 |
AbstractComponent comp = (AbstractComponent) iterator
|
|
2854 |
.next();
|
|
2855 |
arr[i] = comp.toString();
|
|
2856 |
i++;
|
|
2857 |
}
|
|
2858 |
}
|
|
2859 |
return arr;
|
|
2860 |
}
|
|
2861 |
|
|
2862 |
/**
|
|
2863 |
* Get Contact Set as String or <code>null</code> if not found
|
|
2864 |
* @param contact set id
|
|
2865 |
* @return Get Contact Set as String or <code>null</code> if not found
|
|
2866 |
*/
|
|
2867 |
protected String getContactSetStringById(String id) {
|
|
2868 |
try {
|
|
2869 |
int idInt = Integer.parseInt(id);
|
|
2870 |
return getContactSetStringById(idInt);
|
|
2871 |
} catch (Exception e) {
|
|
2872 |
return null;
|
|
2873 |
}
|
|
2874 |
}
|
|
2875 |
|
|
2876 |
/**
|
|
2877 |
* Get Contact Set as String or <code>null</code> if not found
|
|
2878 |
* @param contact set id
|
|
2879 |
* @return Get Contact Set as String or <code>null</code> if not found
|
|
2880 |
*/
|
|
2881 |
protected String getContactSetStringById(int id) {
|
|
2882 |
|
|
2883 |
Vector<AbstractComponent> contSets = getProvider().getComponents().getComponents(CreatorEditorSettings.TYPE_CONTACT_SET);
|
|
2884 |
|
|
2885 |
for (Iterator<AbstractComponent> iterator = contSets.iterator(); iterator.hasNext();) {
|
|
2886 |
AbstractComponent comp = (AbstractComponent) iterator
|
|
2887 |
.next();
|
|
2888 |
if(comp.getId() == id){
|
|
2889 |
return comp.toString();
|
|
2890 |
}
|
|
2891 |
}
|
|
2892 |
return null;
|
|
2893 |
}
|
|
2894 |
|
|
2895 |
/**
|
|
2896 |
* Set amount of table column headers if not default value
|
|
2897 |
* @param tableColumnHeaderAmount
|
|
2898 |
*/
|
|
2899 |
protected void setTableColumnHeaderAmount(String tableColumnHeaderAmount) {
|
|
2900 |
this.tableColumnHeaderAmount = tableColumnHeaderAmount;
|
|
2901 |
}
|
|
2902 |
|
|
2903 |
/**
|
|
2904 |
* Greate link to another component combo
|
|
2905 |
* @param parent
|
|
2906 |
* @param contentToComponentLinkCombo
|
|
2907 |
* @param contactSetSelection
|
|
2908 |
*/
|
|
2909 |
protected void createLinkToOtherComponentCombo(Composite parent, String[] contentToComponentLinkCombo,
|
|
2910 |
String comboLabel,
|
|
2911 |
String contactSetSelection) {
|
|
2912 |
|
|
2913 |
Composite comp = new Composite(parent,SWT.SIMPLE);
|
|
2914 |
comp.setLayout(new GridLayout(2, false));
|
|
2915 |
comp.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
2916 |
|
|
2917 |
Label setLb = new Label(comp,SWT.NONE);
|
|
2918 |
setLb.setText(comboLabel);
|
|
2919 |
|
|
2920 |
linkToOtherComponentCombo = new CCombo(comp, SWT.READ_ONLY | SWT.BORDER );
|
|
2921 |
linkToOtherComponentCombo .setBackground(getWhite());
|
|
2922 |
|
|
2923 |
//If there is some values, setting them to combo
|
|
2924 |
if(contentToComponentLinkCombo != null && contentToComponentLinkCombo.length > 0){
|
|
2925 |
setComponentsToOtherComponentLinkCombo(contentToComponentLinkCombo);
|
|
2926 |
}//Otherwise combo will be disabled
|
|
2927 |
else{
|
|
2928 |
linkToOtherComponentCombo .setEnabled(false);
|
|
2929 |
}
|
|
2930 |
|
|
2931 |
if(contactSetSelection != null){
|
|
2932 |
setComboSelection(contentToComponentLinkCombo, linkToOtherComponentCombo, contactSetSelection);
|
|
2933 |
}
|
|
2934 |
|
|
2935 |
}
|
|
2936 |
|
|
2937 |
/**
|
|
2938 |
* Check if random fields are enabled for this dialog
|
|
2939 |
* @return <code>true</code> if random fields are enabled <code>false</code> othrewise.
|
|
2940 |
*/
|
|
2941 |
protected boolean isRandomFieldsEnabled() {
|
|
2942 |
return isRandomFieldsEnabled;
|
|
2943 |
}
|
|
2944 |
|
|
2945 |
/**
|
|
2946 |
* Set if random fields are enabled for this dialog
|
|
2947 |
* @param isRandomFieldsEnabled <code>true</code> if random fields are enabled <code>false</code> othrewise.
|
|
2948 |
*/
|
|
2949 |
protected void setRandomFieldsEnabled(boolean isRandomFieldsEnabled) {
|
|
2950 |
this.isRandomFieldsEnabled = isRandomFieldsEnabled;
|
|
2951 |
}
|
|
2952 |
|
|
2953 |
|
|
2954 |
/***
|
|
2955 |
* Get Text for contact-set reference check box
|
|
2956 |
* @return UI text for associate this component to contact-set
|
|
2957 |
*/
|
|
2958 |
protected String getContactSetRefernceText(){
|
|
2959 |
return "Associate this " +getComponent().getType() +" to Contact-set: ";
|
|
2960 |
|
|
2961 |
}
|
|
2962 |
|
|
2963 |
/**
|
|
2964 |
* Show error message dialog when dialog was not able to open
|
|
2965 |
* @param e {@link Exception} which was thrown
|
|
2966 |
*/
|
|
2967 |
protected void showUnableToOpenDialogErrorMsg(Exception e) {
|
|
2968 |
showErrorDialog("Error", "Errors occurded when editor dialog was opened, see console for details.");
|
|
2969 |
CreatorEditorConsole.getInstance().println("Errors occurded when try to open editor dialog for compoent:'"
|
|
2970 |
+getComponent().getType() + "', reason: " +e, CreatorEditorConsole.MSG_ERROR);
|
|
2971 |
|
|
2972 |
}
|
|
2973 |
|
|
2974 |
/**
|
|
2975 |
* Add an error
|
|
2976 |
* @param errorMsg
|
|
2977 |
*/
|
|
2978 |
protected void addError(String errorMsg){
|
|
2979 |
if(errors == null){
|
|
2980 |
errors = new Vector<String>();
|
|
2981 |
}
|
|
2982 |
errors.add(errorMsg);
|
|
2983 |
|
|
2984 |
}
|
|
2985 |
|
|
2986 |
/**
|
|
2987 |
* Get all errors, one error will be its own line separeted with "\n"
|
|
2988 |
* @return errors occurred when dialog was opened
|
|
2989 |
*/
|
|
2990 |
protected String getErrors(){
|
|
2991 |
if(errors == null){
|
|
2992 |
return "";
|
|
2993 |
}else{
|
|
2994 |
StringBuffer b = new StringBuffer();
|
|
2995 |
String newLine = "\n";
|
|
2996 |
for (Iterator<String> iterator = errors.iterator(); iterator.hasNext();) {
|
|
2997 |
String err= (String) iterator.next();
|
|
2998 |
b.append(err);
|
|
2999 |
b.append(newLine);
|
|
3000 |
}
|
|
3001 |
//remove last new line
|
|
3002 |
b.delete(b.length()-newLine.length(), b.length());
|
|
3003 |
return b.toString();
|
|
3004 |
}
|
|
3005 |
}
|
|
3006 |
|
|
3007 |
/**
|
|
3008 |
* Was there any errors when creating dialog
|
|
3009 |
* @return <code>true</code> if there was some errors, e.g. unable to set value to combo
|
|
3010 |
*/
|
|
3011 |
protected boolean wasErrors(){
|
|
3012 |
return errors != null;
|
|
3013 |
}
|
|
3014 |
|
|
3015 |
}
|