analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / project / wizards / RenameFolderDialog.java
1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.ui.project.wizards;
14
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;
35
36 /**
37 * Implementation of a dialog box to rename a folder.
38 */
39 public class RenameFolderDialog extends SelectionStatusDialog {
40
41 // ------------------------------------------------------------------------
42 // Members
43 // ------------------------------------------------------------------------
44
45 private final TmfTraceFolder fFolder;
46 private Text fNewFolderNameText;
47
48 // ------------------------------------------------------------------------
49 // Constructor
50 // ------------------------------------------------------------------------
51
52 /**
53 * Constructor
54 * @param shell The parent shell
55 * @param folder The trace element to rename
56 */
57 public RenameFolderDialog(Shell shell, TmfTraceFolder folder) {
58 super(shell);
59 fFolder = folder;
60 setTitle(Messages.RenameFolderDialog_DialogTitle);
61 setStatusLineAboveButtons(true);
62 }
63
64 // ------------------------------------------------------------------------
65 // Dialog
66 // ------------------------------------------------------------------------
67
68 @Override
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));
73
74 createNewTraceNameGroup(composite);
75 return composite;
76 }
77
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));
85
86 // Old trace name label
87 Label oldTraceLabel = new Label(folderGroup, SWT.NONE);
88 oldTraceLabel.setFont(font);
89 oldTraceLabel.setText(Messages.RenameFolderDialog_FolderName);
90
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);
99
100 // New trace name label
101 Label newTaceLabel = new Label(folderGroup, SWT.NONE);
102 newTaceLabel.setFont(font);
103 newTaceLabel.setText(Messages.RenameFolderDialog_FolderNewName);
104
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() {
112 @Override
113 public void handleEvent(Event event) {
114 validateNewFolderName();
115 }
116 });
117 }
118
119 private void validateNewFolderName() {
120
121 String newFolderName = fNewFolderNameText.getText();
122 IWorkspace workspace = fFolder.getResource().getWorkspace();
123 IStatus nameStatus = workspace.validateName(newFolderName, IResource.FOLDER);
124
125 if ("".equals(newFolderName)) { //$NON-NLS-1$
126 updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR,
127 Messages.Dialog_EmptyNameError, null));
128 return;
129 }
130
131 if (!nameStatus.isOK()) {
132 updateStatus(nameStatus);
133 return;
134 }
135
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));
140 return;
141 }
142
143 updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, "")); //$NON-NLS-1$
144 }
145
146 // ------------------------------------------------------------------------
147 // SelectionStatusDialog
148 // ------------------------------------------------------------------------
149
150 @Override
151 protected void computeResult() {
152 }
153
154 @Override
155 public void create() {
156 super.create();
157 getButton(IDialogConstants.OK_ID).setEnabled(false);
158 }
159
160 @Override
161 protected void okPressed() {
162 setSelectionResult(new String[] { fNewFolderNameText.getText() });
163 super.okPressed();
164 }
165
166 }
This page took 0.046126 seconds and 5 git commands to generate.