|
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 package com.nokia.s60tools.symbianfoundationtemplates.ui.wizards.s60; |
|
18 |
|
19 import org.eclipse.swt.SWT; |
|
20 import org.eclipse.swt.layout.GridData; |
|
21 import org.eclipse.swt.widgets.Composite; |
|
22 import org.eclipse.swt.widgets.Label; |
|
23 import org.eclipse.swt.widgets.Listener; |
|
24 import org.eclipse.swt.widgets.Text; |
|
25 |
|
26 /** |
|
27 * File selection control. |
|
28 * |
|
29 * Provides mechanism for file selection for template |
|
30 * wizard pages. |
|
31 * |
|
32 */ |
|
33 public class FileSelectionControl { |
|
34 private Text fileText; |
|
35 |
|
36 /** |
|
37 * Default constructor. |
|
38 * |
|
39 * @param page the template wizard page this control belongs to. |
|
40 * @param parent the parent composite to attach this control. |
|
41 */ |
|
42 public FileSelectionControl(Composite topLevel, Listener listener, String label) { |
|
43 // File selection |
|
44 new Label(topLevel, SWT.NONE).setText(label); |
|
45 fileText = new Text(topLevel, SWT.BORDER); |
|
46 GridData fileGridData = new GridData(GridData.FILL_HORIZONTAL); |
|
47 fileGridData.horizontalSpan = 2; |
|
48 fileText.setLayoutData(fileGridData); |
|
49 fileText.addListener(SWT.Modify, listener); |
|
50 } |
|
51 |
|
52 /** |
|
53 * Get selected file. |
|
54 * |
|
55 * @return the selected file |
|
56 */ |
|
57 public String getSelectedFile() { |
|
58 return fileText.getText(); |
|
59 } |
|
60 |
|
61 /** |
|
62 * Get selected file without extension. |
|
63 * |
|
64 * @return the selected file without extension |
|
65 */ |
|
66 public String getSelectedFileWithoutExtension() { |
|
67 if(fileText.getText().contains(".")) |
|
68 return fileText.getText().substring(0, fileText.getText().lastIndexOf('.')); |
|
69 else |
|
70 return fileText.getText(); |
|
71 } |
|
72 /** |
|
73 * Set file name |
|
74 * |
|
75 * @return |
|
76 */ |
|
77 public void setFileName(String filename) |
|
78 { |
|
79 if(filename!=null) |
|
80 fileText.setText(filename); |
|
81 } |
|
82 /** |
|
83 * Get file name |
|
84 * @return |
|
85 */ |
|
86 public Text getTextControl() |
|
87 { |
|
88 return fileText; |
|
89 } |
|
90 |
|
91 } |