1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.wizards
;
15 import org
.eclipse
.core
.resources
.IContainer
;
16 import org
.eclipse
.core
.resources
.IResource
;
17 import org
.eclipse
.core
.resources
.IWorkspace
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
19 import org
.eclipse
.core
.runtime
.Status
;
20 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
21 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceFolder
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.graphics
.Font
;
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
.Event
;
30 import org
.eclipse
.swt
.widgets
.Label
;
31 import org
.eclipse
.swt
.widgets
.Listener
;
32 import org
.eclipse
.swt
.widgets
.Shell
;
33 import org
.eclipse
.swt
.widgets
.Text
;
34 import org
.eclipse
.ui
.dialogs
.SelectionStatusDialog
;
37 * Implementation of a dialog box to rename a folder.
40 public class RenameFolderDialog
extends SelectionStatusDialog
{
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 private final TmfTraceFolder fFolder
;
47 private Text fNewFolderNameText
;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
55 * @param shell The parent shell
56 * @param folder The trace element to rename
58 public RenameFolderDialog(Shell shell
, TmfTraceFolder folder
) {
61 setTitle(Messages
.RenameFolderDialog_DialogTitle
);
62 setStatusLineAboveButtons(true);
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
70 protected Control
createDialogArea(Composite parent
) {
71 Composite composite
= (Composite
) super.createDialogArea(parent
);
72 composite
.setLayout(new GridLayout());
73 composite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
75 createNewTraceNameGroup(composite
);
79 private void createNewTraceNameGroup(Composite parent
) {
80 Font font
= parent
.getFont();
81 Composite folderGroup
= new Composite(parent
, SWT
.NONE
);
82 GridLayout layout
= new GridLayout();
83 layout
.numColumns
= 2;
84 folderGroup
.setLayout(layout
);
85 folderGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
87 // Old trace name label
88 Label oldTraceLabel
= new Label(folderGroup
, SWT
.NONE
);
89 oldTraceLabel
.setFont(font
);
90 oldTraceLabel
.setText(Messages
.RenameFolderDialog_FolderName
);
92 // Old trace name field
93 Text oldTraceName
= new Text(folderGroup
, SWT
.BORDER
);
94 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
95 data
.widthHint
= IDialogConstants
.ENTRY_FIELD_WIDTH
;
96 oldTraceName
.setLayoutData(data
);
97 oldTraceName
.setFont(font
);
98 oldTraceName
.setText(fFolder
.getName());
99 oldTraceName
.setEnabled(false);
101 // New trace name label
102 Label newTaceLabel
= new Label(folderGroup
, SWT
.NONE
);
103 newTaceLabel
.setFont(font
);
104 newTaceLabel
.setText(Messages
.RenameFolderDialog_FolderNewName
);
106 // New trace name entry field
107 fNewFolderNameText
= new Text(folderGroup
, SWT
.BORDER
);
108 data
= new GridData(GridData
.FILL_HORIZONTAL
);
109 data
.widthHint
= IDialogConstants
.ENTRY_FIELD_WIDTH
;
110 fNewFolderNameText
.setLayoutData(data
);
111 fNewFolderNameText
.setFont(font
);
112 fNewFolderNameText
.addListener(SWT
.Modify
, new Listener() {
114 public void handleEvent(Event event
) {
115 validateNewFolderName();
120 private void validateNewFolderName() {
122 String newFolderName
= fNewFolderNameText
.getText();
123 IWorkspace workspace
= fFolder
.getResource().getWorkspace();
124 IStatus nameStatus
= workspace
.validateName(newFolderName
, IResource
.FOLDER
);
126 if ("".equals(newFolderName
)) { //$NON-NLS-1$
127 updateStatus(new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, IStatus
.ERROR
,
128 Messages
.Dialog_EmptyNameError
, null));
132 if (!nameStatus
.isOK()) {
133 updateStatus(nameStatus
);
137 IContainer parentFolder
= fFolder
.getResource().getParent();
138 if (parentFolder
.findMember(newFolderName
) != null) {
139 updateStatus(new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, IStatus
.ERROR
,
140 Messages
.Dialog_ExistingNameError
, null));
144 updateStatus(new Status(IStatus
.OK
, Activator
.PLUGIN_ID
, "")); //$NON-NLS-1$
147 // ------------------------------------------------------------------------
148 // SelectionStatusDialog
149 // ------------------------------------------------------------------------
152 protected void computeResult() {
156 public void create() {
158 getButton(IDialogConstants
.OK_ID
).setEnabled(false);
162 protected void okPressed() {
163 setSelectionResult(new String
[] { fNewFolderNameText
.getText() });