ae259272bc0ba85da040ca0a0d94381bfcdd6298
[public/netxms.git] / webui / webapp / FileManager / src / org / netxms / ui / eclipse / filemanager / dialogs / RenameFileDialog.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2011 Victor Kirhenshtein
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 package org.netxms.ui.eclipse.filemanager.dialogs;
20
21 import org.eclipse.jface.dialogs.Dialog;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Shell;
28 import org.netxms.ui.eclipse.filemanager.Messages;
29 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
30 import org.netxms.ui.eclipse.tools.WidgetHelper;
31 import org.netxms.ui.eclipse.widgets.LabeledText;
32
33 /**
34 * Dialog for starting file upload
35 */
36 public class RenameFileDialog extends Dialog
37 {
38 private LabeledText textOldFileName;
39 private String oldFileName;
40 private LabeledText textNewFileName;
41 private String newFileName;
42
43 /**
44 *
45 * @param parentShell
46 */
47 public RenameFileDialog(Shell parentShell, String oldName)
48 {
49 super(parentShell);
50 oldFileName = oldName;
51 }
52
53 /* (non-Javadoc)
54 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
55 */
56 @Override
57 protected void configureShell(Shell newShell)
58 {
59 super.configureShell(newShell);
60 newShell.setText(Messages.get().StartClientToServerFileUploadDialog_Title);
61 }
62
63 /* (non-Javadoc)
64 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
65 */
66 @Override
67 protected Control createDialogArea(Composite parent)
68 {
69 Composite dialogArea = (Composite)super.createDialogArea(parent);
70
71 GridLayout layout = new GridLayout();
72 layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
73 layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
74 layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
75 dialogArea.setLayout(layout);
76
77 GridData gd;
78
79 textOldFileName = new LabeledText(dialogArea, SWT.NONE);
80 textOldFileName.setLabel("Old file name");
81 gd = new GridData();
82 gd.horizontalAlignment = SWT.FILL;
83 gd.grabExcessHorizontalSpace = true;
84 textOldFileName.setLayoutData(gd);
85 textOldFileName.setText(oldFileName);
86 textOldFileName.setEditable(false);
87
88 textNewFileName = new LabeledText(dialogArea, SWT.NONE);
89 textNewFileName.setLabel("New file name");
90 gd = new GridData();
91 gd.horizontalAlignment = SWT.FILL;
92 gd.grabExcessHorizontalSpace = true;
93 textNewFileName.setLayoutData(gd);
94
95 return dialogArea;
96 }
97
98 /* (non-Javadoc)
99 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
100 */
101 @Override
102 protected void okPressed()
103 {
104 newFileName = textNewFileName.getText();
105 if(newFileName.contains("/") || newFileName.contains("\\"))
106 {
107 MessageDialogHelper.openWarning(getShell(), "Rename file error", "File name should not contain '/' and '\\' symbols");
108 return;
109 }
110
111 super.okPressed();
112 }
113
114 /**
115 * @return the remoteFileName
116 */
117 public String getNewName()
118 {
119 return newFileName;
120 }
121 }