1 /*******************************************************************************
2 * Copyright (c) 2011, 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 * Francois Chouinard - Copied and adapted from NewFolderDialog
11 * Patrick Tasse - Close editors to release resources
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.wizards
;
16 import org
.eclipse
.core
.resources
.IContainer
;
17 import org
.eclipse
.core
.resources
.IResource
;
18 import org
.eclipse
.core
.resources
.IWorkspace
;
19 import org
.eclipse
.core
.runtime
.IStatus
;
20 import org
.eclipse
.core
.runtime
.Status
;
21 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
22 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.graphics
.Font
;
26 import org
.eclipse
.swt
.layout
.GridData
;
27 import org
.eclipse
.swt
.layout
.GridLayout
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Control
;
30 import org
.eclipse
.swt
.widgets
.Event
;
31 import org
.eclipse
.swt
.widgets
.Label
;
32 import org
.eclipse
.swt
.widgets
.Listener
;
33 import org
.eclipse
.swt
.widgets
.Shell
;
34 import org
.eclipse
.swt
.widgets
.Text
;
35 import org
.eclipse
.ui
.dialogs
.SelectionStatusDialog
;
38 * Implementation of a dialog box to rename a trace.
41 * @author Francois Chouinard
43 public class RenameTraceDialog
extends SelectionStatusDialog
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 private final TmfTraceElement fTrace
;
50 private Text fNewTraceNameText
;
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
57 * @param shell The parent shell
58 * @param trace The trace element to rename
60 public RenameTraceDialog(Shell shell
, TmfTraceElement trace
) {
63 setTitle(Messages
.RenameTraceDialog_DialogTitle
);
64 setStatusLineAboveButtons(true);
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
72 protected Control
createDialogArea(Composite parent
) {
73 Composite composite
= (Composite
) super.createDialogArea(parent
);
74 composite
.setLayout(new GridLayout());
75 composite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
77 createNewTraceNameGroup(composite
);
81 private void createNewTraceNameGroup(Composite parent
) {
82 Font font
= parent
.getFont();
83 Composite folderGroup
= new Composite(parent
, SWT
.NONE
);
84 GridLayout layout
= new GridLayout();
85 layout
.numColumns
= 2;
86 folderGroup
.setLayout(layout
);
87 folderGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
89 // Old trace name label
90 Label oldTraceLabel
= new Label(folderGroup
, SWT
.NONE
);
91 oldTraceLabel
.setFont(font
);
92 oldTraceLabel
.setText(Messages
.RenameTraceDialog_TraceName
);
94 // Old trace name field
95 Text oldTraceName
= new Text(folderGroup
, SWT
.BORDER
);
96 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
97 data
.widthHint
= IDialogConstants
.ENTRY_FIELD_WIDTH
;
98 oldTraceName
.setLayoutData(data
);
99 oldTraceName
.setFont(font
);
100 oldTraceName
.setText(fTrace
.getName());
101 oldTraceName
.setEnabled(false);
103 // New trace name label
104 Label newTaceLabel
= new Label(folderGroup
, SWT
.NONE
);
105 newTaceLabel
.setFont(font
);
106 newTaceLabel
.setText(Messages
.RenameTraceDialog_TraceNewName
);
108 // New trace name entry field
109 fNewTraceNameText
= new Text(folderGroup
, SWT
.BORDER
);
110 data
= new GridData(GridData
.FILL_HORIZONTAL
);
111 data
.widthHint
= IDialogConstants
.ENTRY_FIELD_WIDTH
;
112 fNewTraceNameText
.setLayoutData(data
);
113 fNewTraceNameText
.setFont(font
);
114 fNewTraceNameText
.addListener(SWT
.Modify
, new Listener() {
116 public void handleEvent(Event event
) {
117 validateNewTraceName();
122 private void validateNewTraceName() {
124 String newTraceName
= fNewTraceNameText
.getText();
125 IWorkspace workspace
= fTrace
.getResource().getWorkspace();
126 IStatus nameStatus
= workspace
.validateName(newTraceName
, IResource
.FOLDER
);
128 if ("".equals(newTraceName
)) { //$NON-NLS-1$
129 updateStatus(new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, IStatus
.ERROR
,
130 Messages
.Dialog_EmptyNameError
, null));
134 if (!nameStatus
.isOK()) {
135 updateStatus(nameStatus
);
139 IContainer parentFolder
= fTrace
.getResource().getParent();
140 if (parentFolder
.findMember(newTraceName
) != null) {
141 updateStatus(new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, IStatus
.ERROR
,
142 Messages
.Dialog_ExistingNameError
, null));
146 updateStatus(new Status(IStatus
.OK
, Activator
.PLUGIN_ID
, "")); //$NON-NLS-1$
149 // ------------------------------------------------------------------------
150 // SelectionStatusDialog
151 // ------------------------------------------------------------------------
154 protected void computeResult() {
158 public void create() {
160 getButton(IDialogConstants
.OK_ID
).setEnabled(false);
164 protected void okPressed() {
165 setSelectionResult(new String
[] { fNewTraceNameText
.getText() });