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
.tracecompass
.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
.swt
.SWT
;
22 import org
.eclipse
.swt
.graphics
.Font
;
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
.Event
;
28 import org
.eclipse
.swt
.widgets
.Label
;
29 import org
.eclipse
.swt
.widgets
.Listener
;
30 import org
.eclipse
.swt
.widgets
.Shell
;
31 import org
.eclipse
.swt
.widgets
.Text
;
32 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
33 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceFolder
;
34 import org
.eclipse
.ui
.dialogs
.SelectionStatusDialog
;
37 * Implementation of a dialog box to rename a folder.
39 public class RenameFolderDialog
extends SelectionStatusDialog
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
45 private final TmfTraceFolder fFolder
;
46 private Text fNewFolderNameText
;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
54 * @param shell The parent shell
55 * @param folder The trace element to rename
57 public RenameFolderDialog(Shell shell
, TmfTraceFolder folder
) {
60 setTitle(Messages
.RenameFolderDialog_DialogTitle
);
61 setStatusLineAboveButtons(true);
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
69 protected Control
createDialogArea(Composite parent
) {
70 Composite composite
= (Composite
) super.createDialogArea(parent
);
71 composite
.setLayout(new GridLayout());
72 composite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
74 createNewTraceNameGroup(composite
);
78 private void createNewTraceNameGroup(Composite parent
) {
79 Font font
= parent
.getFont();
80 Composite folderGroup
= new Composite(parent
, SWT
.NONE
);
81 GridLayout layout
= new GridLayout();
82 layout
.numColumns
= 2;
83 folderGroup
.setLayout(layout
);
84 folderGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
86 // Old trace name label
87 Label oldTraceLabel
= new Label(folderGroup
, SWT
.NONE
);
88 oldTraceLabel
.setFont(font
);
89 oldTraceLabel
.setText(Messages
.RenameFolderDialog_FolderName
);
91 // Old trace name field
92 Text oldTraceName
= new Text(folderGroup
, SWT
.BORDER
);
93 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
94 data
.widthHint
= IDialogConstants
.ENTRY_FIELD_WIDTH
;
95 oldTraceName
.setLayoutData(data
);
96 oldTraceName
.setFont(font
);
97 oldTraceName
.setText(fFolder
.getName());
98 oldTraceName
.setEnabled(false);
100 // New trace name label
101 Label newTaceLabel
= new Label(folderGroup
, SWT
.NONE
);
102 newTaceLabel
.setFont(font
);
103 newTaceLabel
.setText(Messages
.RenameFolderDialog_FolderNewName
);
105 // New trace name entry field
106 fNewFolderNameText
= new Text(folderGroup
, SWT
.BORDER
);
107 data
= new GridData(GridData
.FILL_HORIZONTAL
);
108 data
.widthHint
= IDialogConstants
.ENTRY_FIELD_WIDTH
;
109 fNewFolderNameText
.setLayoutData(data
);
110 fNewFolderNameText
.setFont(font
);
111 fNewFolderNameText
.addListener(SWT
.Modify
, new Listener() {
113 public void handleEvent(Event event
) {
114 validateNewFolderName();
119 private void validateNewFolderName() {
121 String newFolderName
= fNewFolderNameText
.getText();
122 IWorkspace workspace
= fFolder
.getResource().getWorkspace();
123 IStatus nameStatus
= workspace
.validateName(newFolderName
, IResource
.FOLDER
);
125 if ("".equals(newFolderName
)) { //$NON-NLS-1$
126 updateStatus(new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, IStatus
.ERROR
,
127 Messages
.Dialog_EmptyNameError
, null));
131 if (!nameStatus
.isOK()) {
132 updateStatus(nameStatus
);
136 IContainer parentFolder
= fFolder
.getResource().getParent();
137 if (parentFolder
.findMember(newFolderName
) != null) {
138 updateStatus(new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, IStatus
.ERROR
,
139 Messages
.Dialog_ExistingNameError
, null));
143 updateStatus(new Status(IStatus
.OK
, Activator
.PLUGIN_ID
, "")); //$NON-NLS-1$
146 // ------------------------------------------------------------------------
147 // SelectionStatusDialog
148 // ------------------------------------------------------------------------
151 protected void computeResult() {
155 public void create() {
157 getButton(IDialogConstants
.OK_ID
).setEnabled(false);
161 protected void okPressed() {
162 setSelectionResult(new String
[] { fNewFolderNameText
.getText() });