0
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.s60tools.imaker.internal.viewers;
|
|
19 |
|
|
20 |
import java.io.File;
|
|
21 |
|
|
22 |
import org.eclipse.core.runtime.IPath;
|
|
23 |
import org.eclipse.core.runtime.Path;
|
|
24 |
import org.eclipse.jface.dialogs.StatusDialog;
|
|
25 |
import org.eclipse.swt.SWT;
|
|
26 |
import org.eclipse.swt.events.ModifyEvent;
|
|
27 |
import org.eclipse.swt.events.ModifyListener;
|
|
28 |
import org.eclipse.swt.events.SelectionAdapter;
|
|
29 |
import org.eclipse.swt.events.SelectionEvent;
|
|
30 |
import org.eclipse.swt.graphics.Point;
|
|
31 |
import org.eclipse.swt.layout.GridData;
|
|
32 |
import org.eclipse.swt.layout.GridLayout;
|
|
33 |
import org.eclipse.swt.widgets.Button;
|
|
34 |
import org.eclipse.swt.widgets.Composite;
|
|
35 |
import org.eclipse.swt.widgets.Control;
|
|
36 |
import org.eclipse.swt.widgets.FileDialog;
|
|
37 |
import org.eclipse.swt.widgets.Label;
|
|
38 |
import org.eclipse.swt.widgets.Shell;
|
|
39 |
import org.eclipse.swt.widgets.Text;
|
|
40 |
|
|
41 |
import com.nokia.s60tools.imaker.IMakerUtils;
|
|
42 |
import com.nokia.s60tools.imaker.Messages;
|
|
43 |
import com.nokia.s60tools.imaker.internal.model.FileToImage;
|
|
44 |
|
|
45 |
public class AddEditFileToTransferDialog extends StatusDialog {
|
|
46 |
|
|
47 |
private FileToImage fFile;
|
|
48 |
private Text hostPath;
|
|
49 |
private Button hostBrowse;
|
|
50 |
private Text targetPath;
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Create the dialog
|
|
54 |
* @param parent
|
|
55 |
* @param file
|
|
56 |
*/
|
|
57 |
public AddEditFileToTransferDialog(Shell parent, FileToImage file) {
|
|
58 |
super(parent);
|
|
59 |
setShellStyle(getShellStyle() | SWT.RESIZE);
|
|
60 |
fFile = file;
|
|
61 |
}
|
|
62 |
|
|
63 |
/**
|
|
64 |
* @see Windows#configureShell
|
|
65 |
*/
|
|
66 |
protected void configureShell(Shell newShell) {
|
|
67 |
super.configureShell(newShell);
|
|
68 |
// PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, LaunchTabHelpIds.RUN_MODE_FILE_TRANSFER_DIALOG);
|
|
69 |
}
|
|
70 |
|
|
71 |
/* (non-Javadoc)
|
|
72 |
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
|
|
73 |
*/
|
|
74 |
protected Control createDialogArea(Composite parent) {
|
|
75 |
initializeDialogUnits(parent);
|
|
76 |
Composite composite= (Composite) super.createDialogArea(parent);
|
|
77 |
|
|
78 |
GridLayout layout = (GridLayout) composite.getLayout();
|
|
79 |
layout.numColumns = 2;
|
|
80 |
|
|
81 |
final Label hostLabel = new Label(composite, SWT.NONE);
|
|
82 |
hostLabel.setText(Messages.getString("AddEditFileToTransferDialog.1")); //$NON-NLS-1$
|
|
83 |
GridData data = new GridData(GridData.FILL, GridData.CENTER, true, false);
|
|
84 |
data.horizontalSpan = 2;
|
|
85 |
hostLabel.setLayoutData(data);
|
|
86 |
hostLabel.setToolTipText(Messages.getString("AddEditFileToTransferDialog.2")); //$NON-NLS-1$
|
|
87 |
|
|
88 |
hostPath = new Text(composite, SWT.BORDER);
|
|
89 |
hostPath.setText(fFile.getHostPath());
|
|
90 |
data = new GridData(GridData.FILL, GridData.CENTER, true, false);
|
|
91 |
hostPath.setLayoutData(data);
|
|
92 |
hostPath.setToolTipText(Messages.getString("AddEditFileToTransferDialog.2")); //$NON-NLS-1$
|
|
93 |
hostPath.addModifyListener(new ModifyListener() {
|
|
94 |
public void modifyText(ModifyEvent e) {
|
|
95 |
checkValues();
|
|
96 |
}
|
|
97 |
});
|
|
98 |
|
|
99 |
hostBrowse = new Button(composite, SWT.PUSH);
|
|
100 |
hostBrowse.setFont(parent.getFont());
|
|
101 |
hostBrowse.setText(Messages.getString("AddEditFileToTransferDialog.3")); //$NON-NLS-1$
|
|
102 |
data = new GridData();
|
|
103 |
hostBrowse.setLayoutData(data);
|
|
104 |
hostBrowse.addSelectionListener(new SelectionAdapter() {
|
|
105 |
|
|
106 |
public void widgetSelected(SelectionEvent evt) {
|
|
107 |
FileDialog dialog = new FileDialog(getShell(), SWT.NONE);
|
|
108 |
|
|
109 |
dialog.setText(Messages.getString("AddEditFileToTransferDialog.4")); //$NON-NLS-1$
|
|
110 |
dialog.setFilterExtensions(new String[] {"*"}); //$NON-NLS-1$
|
|
111 |
dialog.setFilterNames(new String[] {Messages.getString("AddEditFileToTransferDialog.11")}); //$NON-NLS-1$
|
|
112 |
|
|
113 |
String result = dialog.open();
|
|
114 |
if (result != null) {
|
|
115 |
IPath path = new Path(result);
|
|
116 |
if (path.toFile().exists()) {
|
|
117 |
hostPath.setText(result);
|
|
118 |
|
|
119 |
// if target path is empty, set it to something useful here.
|
|
120 |
if (targetPath.getText().trim().length() < 1) {
|
|
121 |
String tp = IMakerUtils.getFixedTargetPath(path);
|
|
122 |
|
|
123 |
targetPath.setText(tp);
|
|
124 |
}
|
|
125 |
}
|
|
126 |
}
|
|
127 |
}
|
|
128 |
|
|
129 |
|
|
130 |
});
|
|
131 |
|
|
132 |
final Label targetLabel = new Label(composite, SWT.NONE);
|
|
133 |
targetLabel.setText(Messages.getString("AddEditFileToTransferDialog.5")); //$NON-NLS-1$
|
|
134 |
data = new GridData(GridData.FILL, GridData.CENTER, true, false);
|
|
135 |
data.horizontalSpan = 2;
|
|
136 |
targetLabel.setLayoutData(data);
|
|
137 |
targetLabel.setToolTipText(Messages.getString("AddEditFileToTransferDialog.6")); //$NON-NLS-1$
|
|
138 |
|
|
139 |
targetPath = new Text(composite, SWT.BORDER);
|
|
140 |
targetPath.setText(fFile.getTargetPath());
|
|
141 |
data = new GridData(GridData.FILL, GridData.CENTER, true, false);
|
|
142 |
targetPath.setLayoutData(data);
|
|
143 |
targetPath.setToolTipText(Messages.getString("AddEditFileToTransferDialog.6")); //$NON-NLS-1$
|
|
144 |
targetPath.addModifyListener(new ModifyListener() {
|
|
145 |
public void modifyText(ModifyEvent e) {
|
|
146 |
checkValues();
|
|
147 |
}
|
|
148 |
});
|
|
149 |
|
|
150 |
applyDialogFont(composite);
|
|
151 |
|
|
152 |
return composite;
|
|
153 |
}
|
|
154 |
|
|
155 |
public void create() {
|
|
156 |
super.create();
|
|
157 |
checkValues();
|
|
158 |
}
|
|
159 |
|
|
160 |
protected void okPressed() {
|
|
161 |
fFile.setHostPath(hostPath.getText());
|
|
162 |
fFile.setTargetPath(targetPath.getText());
|
|
163 |
|
|
164 |
super.okPressed();
|
|
165 |
}
|
|
166 |
|
|
167 |
/* (non-Javadoc)
|
|
168 |
* @see org.eclipse.jface.window.Window#getInitialSize()
|
|
169 |
*/
|
|
170 |
protected Point getInitialSize() {
|
|
171 |
Point size = super.getInitialSize();
|
|
172 |
|
|
173 |
// set the initial size for the add dialog. note that when editing it
|
|
174 |
// automatically sizes it based on the length of the text in the edit boxes
|
|
175 |
if (hostPath.getText().trim().length() == 0) {
|
|
176 |
size.x *= 3;
|
|
177 |
}
|
|
178 |
|
|
179 |
return size;
|
|
180 |
}
|
|
181 |
|
|
182 |
protected void checkValues() {
|
|
183 |
StatusInfo status= new StatusInfo();
|
|
184 |
status.setOK();
|
|
185 |
|
|
186 |
String hp = hostPath.getText().trim();
|
|
187 |
if (hp.length() > 0) {
|
|
188 |
if (!new File(hp).exists()) {
|
|
189 |
status.setError(Messages.getString("AddEditFileToTransferDialog.7")); //$NON-NLS-1$
|
|
190 |
}
|
|
191 |
}
|
|
192 |
else {
|
|
193 |
status.setError(Messages.getString("AddEditFileToTransferDialog.8")); //$NON-NLS-1$
|
|
194 |
}
|
|
195 |
|
|
196 |
// if we already have an error then no need to check the rest of the stuff
|
|
197 |
if (status.isOK()) {
|
|
198 |
String tp = targetPath.getText().trim();
|
|
199 |
if (tp.length() > 0) {
|
|
200 |
if (tp.length() < 3) {
|
|
201 |
status.setError(Messages.getString("AddEditFileToTransferDialog.9")); //$NON-NLS-1$
|
|
202 |
} else {
|
|
203 |
// char drive = tp.charAt(0);
|
|
204 |
// char colon = tp.charAt(1);
|
|
205 |
// if (!Character.isLetter(drive) || colon != ':') {
|
|
206 |
// status.setError(Messages.getString("AddEditFileToTransferDialog.9")); //$NON-NLS-1$
|
|
207 |
// }
|
|
208 |
|
|
209 |
// we really want the target file path, not just a directory. but we do allow directories for
|
|
210 |
// backwards compatibility, but only when they end in a path delimiter. so if the target path
|
|
211 |
// does not end in a path delimiter, and there is no file extension, warn them that we think
|
|
212 |
// this is just a file without an extension and not a directory.
|
|
213 |
IPath path = new Path(tp);
|
|
214 |
if (!path.hasTrailingSeparator() && path.getFileExtension() == null) {
|
|
215 |
status.setWarning(Messages.getString("AddEditFileToTransferDialog.12")); //$NON-NLS-1$
|
|
216 |
}
|
|
217 |
}
|
|
218 |
}
|
|
219 |
else {
|
|
220 |
status.setError(Messages.getString("AddEditFileToTransferDialog.10")); //$NON-NLS-1$
|
|
221 |
}
|
|
222 |
}
|
|
223 |
|
|
224 |
updateStatus(status);
|
|
225 |
}
|
|
226 |
|
|
227 |
}
|