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