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.remotecontrol.ui.dialogs;
|
|
19 |
|
|
20 |
import org.eclipse.jface.dialogs.Dialog;
|
|
21 |
import org.eclipse.jface.dialogs.IDialogConstants;
|
|
22 |
import org.eclipse.swt.SWT;
|
|
23 |
import org.eclipse.swt.events.ModifyEvent;
|
|
24 |
import org.eclipse.swt.events.ModifyListener;
|
|
25 |
import org.eclipse.swt.layout.GridData;
|
|
26 |
import org.eclipse.swt.layout.GridLayout;
|
|
27 |
import org.eclipse.swt.widgets.Composite;
|
|
28 |
import org.eclipse.swt.widgets.Control;
|
|
29 |
import org.eclipse.swt.widgets.Label;
|
|
30 |
import org.eclipse.swt.widgets.Shell;
|
|
31 |
import org.eclipse.swt.widgets.Text;
|
|
32 |
|
|
33 |
import com.nokia.s60tools.remotecontrol.resources.Messages;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Dialog for renaming file
|
|
37 |
*/
|
|
38 |
public class RenameDialog extends Dialog implements ModifyListener {
|
|
39 |
|
|
40 |
/**
|
|
41 |
* Name
|
|
42 |
*/
|
|
43 |
private String name;
|
|
44 |
|
|
45 |
/**
|
|
46 |
* File name text field
|
|
47 |
*/
|
|
48 |
private Text nameField = null;
|
|
49 |
|
|
50 |
/**
|
|
51 |
* Flag for keeping track if original name is possible return value.
|
|
52 |
*/
|
|
53 |
private final boolean allowOriginalName;
|
|
54 |
|
|
55 |
/**
|
|
56 |
* Name for dialog.
|
|
57 |
*/
|
|
58 |
private final String dialogName;
|
|
59 |
|
|
60 |
/**
|
|
61 |
* Constructor
|
|
62 |
* @param parentShell Shell
|
|
63 |
* @param name Current name of the file
|
|
64 |
* @param allowOriginalName True if it is possible to return original name. False otherwise.
|
|
65 |
*/
|
|
66 |
public RenameDialog(Shell parentShell, String fileName, boolean allowOriginalName, String dialogName) {
|
|
67 |
super(parentShell);
|
|
68 |
this.name = fileName;
|
|
69 |
this.allowOriginalName = allowOriginalName;
|
|
70 |
this.dialogName = dialogName;
|
|
71 |
}
|
|
72 |
|
|
73 |
/* (non-Javadoc)
|
|
74 |
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
|
|
75 |
*/
|
|
76 |
protected void configureShell(Shell shell) {
|
|
77 |
super.configureShell(shell);
|
|
78 |
shell.setText(dialogName);
|
|
79 |
}
|
|
80 |
|
|
81 |
/* (non-Javadoc)
|
|
82 |
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
|
|
83 |
*/
|
|
84 |
protected void createButtonsForButtonBar(Composite parent) {
|
|
85 |
GridLayout gdl = new GridLayout(1, false);
|
|
86 |
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
|
|
87 |
parent.setLayout(gdl);
|
|
88 |
parent.setLayoutData(gd);
|
|
89 |
|
|
90 |
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
|
|
91 |
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
|
|
92 |
|
|
93 |
if(!allowOriginalName) {
|
|
94 |
// Not allowed to return same file name. User needs to modify name before enabling OK button.
|
|
95 |
getButton(IDialogConstants.OK_ID).setEnabled(false);
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
/* (non-Javadoc)
|
|
100 |
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
|
|
101 |
*/
|
|
102 |
protected Control createDialogArea(Composite parent) {
|
|
103 |
Composite dialogAreaComposite = (Composite) super.createDialogArea(parent);
|
|
104 |
|
|
105 |
//
|
|
106 |
//Adding custom controls
|
|
107 |
//
|
|
108 |
final int cols = 1;
|
|
109 |
GridLayout gl = new GridLayout(cols, false);
|
|
110 |
GridData gd = new GridData(GridData.FILL_BOTH);
|
|
111 |
|
|
112 |
dialogAreaComposite.setLayout(gl);
|
|
113 |
dialogAreaComposite.setLayoutData(gd);
|
|
114 |
|
|
115 |
Label label = new Label(dialogAreaComposite, SWT.NONE);
|
|
116 |
label.setText(Messages.getString("RenameDialog.label")); //$NON-NLS-1$
|
|
117 |
nameField = new Text(dialogAreaComposite, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
|
|
118 |
nameField.setLayoutData(gd);
|
|
119 |
nameField.setText(name);
|
|
120 |
|
|
121 |
nameField.addModifyListener(this);
|
|
122 |
|
|
123 |
return dialogAreaComposite;
|
|
124 |
}
|
|
125 |
|
|
126 |
/* (non-Javadoc)
|
|
127 |
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
|
|
128 |
*/
|
|
129 |
protected void buttonPressed(int buttonId) {
|
|
130 |
if (buttonId == IDialogConstants.OK_ID) {
|
|
131 |
// Save file name that user entered
|
|
132 |
name = nameField.getText();
|
|
133 |
}
|
|
134 |
super.buttonPressed(buttonId);
|
|
135 |
}
|
|
136 |
|
|
137 |
|
|
138 |
/**
|
|
139 |
* Get file name
|
|
140 |
* @return File name that user entered. If user canceled dialog
|
|
141 |
* the original file name is returned.
|
|
142 |
*/
|
|
143 |
public String getFileName(){
|
|
144 |
return name;
|
|
145 |
}
|
|
146 |
|
|
147 |
/* (non-Javadoc)
|
|
148 |
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
|
|
149 |
*/
|
|
150 |
public void modifyText(ModifyEvent e) {
|
|
151 |
if(!allowOriginalName && nameField.getText().equalsIgnoreCase(name)) {
|
|
152 |
// Not allowed to return same file name.
|
|
153 |
getButton(IDialogConstants.OK_ID).setEnabled(false);
|
|
154 |
} else {
|
|
155 |
getButton(IDialogConstants.OK_ID).setEnabled(true);
|
|
156 |
}
|
|
157 |
|
|
158 |
// Empty names are not allowed.
|
|
159 |
if(nameField.getText().equals("")) { //$NON-NLS-1$
|
|
160 |
getButton(IDialogConstants.OK_ID).setEnabled(false);
|
|
161 |
}
|
|
162 |
}
|
|
163 |
|
|
164 |
}
|