creatorextension/com.nokia.s60tools.creator/src/com/nokia/s60tools/creator/dialogs/FileTypeDialog.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
 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    19
package com.nokia.s60tools.creator.dialogs;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    20
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    21
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    22
import java.util.Iterator;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    23
import java.util.Vector;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    24
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    25
import org.eclipse.swt.widgets.Composite;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    26
import org.eclipse.swt.widgets.Control;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    27
import org.eclipse.swt.widgets.Shell;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    28
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    29
import com.nokia.s60tools.creator.components.AbstractComponent;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    30
import com.nokia.s60tools.creator.components.AbstractValue;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    31
import com.nokia.s60tools.creator.components.AbstractVariables;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    32
import com.nokia.s60tools.creator.components.AbstractValue.ModeTypes;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    33
import com.nokia.s60tools.creator.components.filetype.FileType;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    34
import com.nokia.s60tools.creator.components.filetype.FileTypeValue;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    35
import com.nokia.s60tools.creator.components.filetype.FileTypeVariables;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    36
import com.nokia.s60tools.creator.core.CreatorEditorSettings;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    37
import com.nokia.s60tools.creator.editors.IComponentProvider;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    38
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    39
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    40
/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    41
 *
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    42
 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    43
public class FileTypeDialog extends AbstractDialog {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    44
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    45
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    46
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    47
	public FileTypeDialog(Shell sh, IComponentProvider provider) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    48
		super(sh, provider);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    49
		init();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    50
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    51
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    52
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    53
	 * Initialize, creates Contact object
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    54
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    55
	private void init(){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    56
		if(getComponent() == null){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    57
			AbstractComponent comp = new FileType(AbstractComponent.NULL_ID);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    58
			setComponent(comp);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    59
		}		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    60
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    61
  
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    62
    
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    63
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    64
	protected FileType createNewComponent(){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    65
		return new FileType(AbstractComponent.NULL_ID);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    66
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    67
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    68
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    69
	protected FileTypeValue createNewValue(String type, String value, String random, String amount) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    70
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    71
		int amout_ = 0;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    72
		ModeTypes random_ = ModeTypes.RandomTypeNotRandom;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    73
		String value_ = value;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    74
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    75
		//If amount is set
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    76
		if(amount != null && amount.trim().length() > 0){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    77
			amout_ = Integer.parseInt(amount);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    78
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    79
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    80
		//if random is selected
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    81
		if(random != null && random.trim().length() > 0 && !random.equals(AbstractValue.EMPTY_STRING)){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    82
			random_ = AbstractValue.getModeTypeByText(random);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    83
			if(random_ != ModeTypes.RandomTypeNotRandom){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    84
				value_ = AbstractValue.RANDOM_TEXT;
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
		return new FileTypeValue(value_, random_, amout_);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    88
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    89
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    90
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    91
	/* (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    92
	 * @see com.nokia.s60tools.creator.dialogs.AbstractDialog#getItemValueAsString()
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    93
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    94
	protected String[] getItemTypesAsString() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    95
		return FileTypeVariables.getInstance().getItemValuesAsString();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    96
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    97
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    98
	/* Creating all items to dialog area
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    99
	 * (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   100
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   101
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   102
	protected Control createDialogArea(Composite parent) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   103
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   104
		Composite composite = createDialogAreaComposite(parent);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   105
		//Create Amount area
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   106
		createAmountArea(composite);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   107
		//Create table area
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   108
		createTableArea(composite);		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   109
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   110
		if(isAmountFieldsEnabled() ){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   111
			addInformation(composite, AMOUNT_FIELD_INFO_TEXT);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   112
		}		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   113
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   114
		String possibleValuesInfoText = "If '" +FileTypeVariables.TYPE +"' is left empty, an empty '"+FileTypeVariables.DIR +"' will be created.";
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   115
		addInformation(composite, possibleValuesInfoText);		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   116
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   117
		//Add help text for date-time fields
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   118
		addInformation(composite, AbstractVariables.DATE_TIME_AND_DATE_FORMAT_HELP_TEXT);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   119
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   120
		//Format help text for accumulated and interval, format is: P1Y2M3DT4H5M6S (Iso8601).
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   121
		//@see http://en.wikipedia.org/wiki/ISO_8601#Durations		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   122
		addInformation(composite, FileTypeVariables.DURATIONS_HELP_TEXT);		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   123
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   124
		if(wasErrors()){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   125
			showErrorDialog("Errors occured when dialog opened", getErrors());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   126
		}		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   127
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   128
		return composite;
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
	/* (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   132
	 * @see com.nokia.s60tools.creator.dialogs.AbstractDialog#okPressed()
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   133
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   134
	protected void okPressed() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   135
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   136
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   137
		super.okPressed();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   138
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   139
		//Checking if there are encryption parameters but not type set						
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   140
		Vector<AbstractValue> enc = getComponent().getAttribute(FileTypeVariables.ENCRYPTION_TYPE);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   141
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   142
		//Check If DRM_FL or DRM_CD is selected 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   143
		boolean isDRMCDorRandom = false;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   144
		if(enc != null){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   145
			for (Iterator<AbstractValue> iterator = enc.iterator(); iterator.hasNext();) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   146
				AbstractValue val = (AbstractValue) iterator.next();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   147
				if(FileTypeVariables.DRM_CD.equalsIgnoreCase(val.getValue())){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   148
					isDRMCDorRandom = true;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   149
				}else if(CreatorEditorSettings.isRandomText(val.getValue())){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   150
					isDRMCDorRandom = true;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   151
				}	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   152
			}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   153
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   154
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   155
		//If encryption type has not been set or its set to DRM_FL, and there is at least one encryption item set, showing warning dialog
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   156
		if(enc == null ||  enc.isEmpty() || !isDRMCDorRandom){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   157
			if(hasEncryptionItem()){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   158
				//Showing warning dialog 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   159
				showWarningDialog("Check " +FileTypeVariables.ENCRYPTION_TYPE, 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   160
						"There is at least one '" +FileTypeVariables.DRM_CD +"' encryption parameter set, but '" +FileTypeVariables.ENCRYPTION_TYPE
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   161
						+"' is not set to '" +FileTypeVariables.DRM_CD +"'. All encryption parameters will lost on save if '" +FileTypeVariables.ENCRYPTION_TYPE
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   162
						+"' is not set to '" +FileTypeVariables.DRM_CD +"'. You can open dialog with 'Edit' -button and set '" +FileTypeVariables.ENCRYPTION_TYPE
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   163
						+"' to '" +FileTypeVariables.DRM_CD +"'.");			
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
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   167
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   168
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   169
	 * Check if in this file has on item of encryption
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   170
	 * @return <code>true</code> if has at least one
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   171
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   172
	private boolean hasEncryptionItem() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   173
		return (hasEncryptionItem(FileTypeVariables.PRINT_KEYS)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   174
		|| hasEncryptionItem(FileTypeVariables.DISPLAY_KEYS)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   175
		|| hasEncryptionItem(FileTypeVariables.EXECUTE_KEYS)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   176
		|| hasEncryptionItem(FileTypeVariables.PLAY_KEYS));
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   177
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   178
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   179
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   180
	 * Check if one of given encryption items found in this file
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   181
	 * @param keys
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   182
	 * @return <code>true</code> if file has one of keys
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   183
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   184
	boolean hasEncryptionItem(String [][] keys){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   185
		for (int i = 0; i < keys[0].length; i++) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   186
			String id = keys[0][i];
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   187
			String value = getComponent().getValueById(id);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   188
			Vector<AbstractValue> enc = getComponent().getAttribute(value);			
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   189
			if(enc != null && !enc.isEmpty()){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   190
				return true;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   191
			}				
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   192
		}		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   193
		return false;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   194
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   195
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   196
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   197
}