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