Add support for importing traces to tracing project
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / dialogs / ImportConfirmationDialog.java
1 /**********************************************************************
2 * Copyright (c) 2012 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 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
13
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.jface.dialogs.MessageDialog;
17 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
18 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.events.SelectionAdapter;
21 import org.eclipse.swt.events.SelectionEvent;
22 import org.eclipse.swt.graphics.Point;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Button;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Control;
28 import org.eclipse.swt.widgets.Label;
29 import org.eclipse.swt.widgets.Shell;
30 import org.eclipse.swt.widgets.Text;
31
32 /**
33 * <b><u>CreateSessionDialog</u></b>
34 * <p>
35 * Dialog box for collecting session creation information.
36 * </p>
37 */
38 public class ImportConfirmationDialog extends Dialog implements IImportConfirmationDialog {
39
40 // ------------------------------------------------------------------------
41 // Constants
42 // ------------------------------------------------------------------------
43 /**
44 * The icon file for this dialog box.
45 */
46 public static final String IMPORT_ICON_FILE = "icons/elcl16/import_trace.gif"; //$NON-NLS-1$
47
48 // ------------------------------------------------------------------------
49 // Attributes
50 // ------------------------------------------------------------------------
51 /**
52 * The dialog composite.
53 */
54 private Composite fDialogComposite = null;
55 /**
56 * The radio button for selecting the overwrite action
57 */
58 private Button fOverwriteButton = null;
59 /**
60 * The radio button for selecting the renaming action
61 */
62 private Button fRenameButton = null;
63 /**
64 * The text widget for the session name
65 */
66 private Text fNewTraceNameText = null;
67 /**
68 * The trace name which already exists in the project
69 */
70 private String fTraceName = null;
71 /**
72 * The session name string.
73 */
74 private String fNewTraceName = null;
75 /**
76 * Flag whether default location (path) shall be used or not
77 */
78 private boolean fIsOverride = true;
79
80 // ------------------------------------------------------------------------
81 // Constructors
82 // ------------------------------------------------------------------------
83 /**
84 * Constructor
85 * @param shell - a shell for the display of the dialog
86 */
87 public ImportConfirmationDialog(Shell shell) {
88 super(shell);
89 setShellStyle(SWT.RESIZE);
90 }
91
92 // ------------------------------------------------------------------------
93 // Accessors
94 // ------------------------------------------------------------------------
95 /*
96 * (non-Javadoc)
97 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportConfirmationDialog#setTraceName(java.lang.String)
98 */
99 @Override
100 public void setTraceName(String name) {
101 fTraceName = name;
102 }
103
104 /*
105 * (non-Javadoc)
106 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportConfirmationDialog#getNewTraceName()
107 */
108 @Override
109 public String getNewTraceName() {
110 return fNewTraceName;
111 }
112
113 /*
114 * (non-Javadoc)
115 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportConfirmationDialog#isOverwrite()
116 */
117 @Override
118 public boolean isOverwrite() {
119 return fIsOverride;
120 }
121
122 // ------------------------------------------------------------------------
123 // Operations
124 // ------------------------------------------------------------------------
125 /*
126 * (non-Javadoc)
127 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
128 */
129 @Override
130 protected void configureShell(Shell newShell) {
131 super.configureShell(newShell);
132 newShell.setText(Messages.TraceControl_ImportDialogConfirmationTitle);
133 newShell.setImage(Activator.getDefault().loadIcon(IMPORT_ICON_FILE));
134 }
135
136 /*
137 * (non-Javadoc)
138 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
139 */
140 @Override
141 protected Control createDialogArea(Composite parent) {
142
143 // Main dialog panel
144 fDialogComposite = new Composite(parent, SWT.NONE);
145 GridLayout layout = new GridLayout(1, true);
146 fDialogComposite.setLayout(layout);
147 fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
148
149 Label sessionNameLabel = new Label(fDialogComposite, SWT.RIGHT);
150 sessionNameLabel.setText(Messages.TraceControl_ImportDialogTraceAlreadyExistError + ": " + fTraceName); //$NON-NLS-1$
151
152 fOverwriteButton = new Button(fDialogComposite, SWT.RADIO);
153 fOverwriteButton.setText(Messages.TraceControl_ImportDialogConfirmationOverwriteLabel);
154
155 fOverwriteButton.addSelectionListener(new SelectionAdapter() {
156 @Override
157 public void widgetSelected(SelectionEvent e) {
158 fNewTraceNameText.setEnabled(false);
159 fNewTraceNameText.setText(fTraceName);
160 }
161 });
162
163 fRenameButton = new Button(fDialogComposite, SWT.RADIO);
164 fRenameButton.setText(Messages.TraceControl_ImportDialogConfirmationRenameLabel);
165
166 fRenameButton.addSelectionListener(new SelectionAdapter() {
167 @Override
168 public void widgetSelected(SelectionEvent e) {
169 fNewTraceNameText.setEnabled(true);
170 }
171 });
172
173 fNewTraceNameText = new Text(fDialogComposite, SWT.NONE);
174 fNewTraceNameText.setToolTipText(Messages.TraceControl_ImportDialogConfirmationNewNameLabel);
175 fNewTraceNameText.setText(fTraceName);
176
177 // Default
178 fOverwriteButton.setSelection(true);
179 fNewTraceNameText.setEnabled(false);
180
181
182 // layout widgets
183 GridData data = new GridData(GridData.FILL_HORIZONTAL);
184
185 fNewTraceNameText.setLayoutData(data);
186
187 getShell().setMinimumSize(new Point(300, 150));
188
189 return fDialogComposite;
190 }
191
192 /*
193 * (non-Javadoc)
194 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
195 */
196 @Override
197 protected void createButtonsForButtonBar(Composite parent) {
198 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
199 }
200
201 /*
202 * (non-Javadoc)
203 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
204 */
205 @Override
206 protected void okPressed() {
207
208 fIsOverride = fOverwriteButton.getSelection();
209
210 if (fIsOverride) {
211 // new name is old name
212 fNewTraceName = fTraceName;
213 } else {
214 fNewTraceName = fNewTraceNameText.getText();
215 }
216
217 // Check for invalid names
218 if (!fNewTraceName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
219 MessageDialog.openError(getShell(),
220 Messages.TraceControl_ImportDialogConfirmationTitle,
221 Messages.TraceControl_InvalidTraceNameError + " (" + fNewTraceName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
222 return;
223 }
224
225 // validation successful -> call super.okPressed()
226 super.okPressed();
227 }
228 }
This page took 0.038499 seconds and 6 git commands to generate.