1 /**********************************************************************
2 * Copyright (c) 2012 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 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
;
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
;
33 * <b><u>CreateSessionDialog</u></b>
35 * Dialog box for collecting session creation information.
38 public class ImportConfirmationDialog
extends Dialog
implements IImportConfirmationDialog
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 * The icon file for this dialog box.
46 public static final String IMPORT_ICON_FILE
= "icons/elcl16/import_trace.gif"; //$NON-NLS-1$
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
52 * The dialog composite.
54 private Composite fDialogComposite
= null;
56 * The radio button for selecting the overwrite action
58 private Button fOverwriteButton
= null;
60 * The radio button for selecting the renaming action
62 private Button fRenameButton
= null;
64 * The text widget for the session name
66 private Text fNewTraceNameText
= null;
68 * The trace name which already exists in the project
70 private String fTraceName
= null;
72 * The session name string.
74 private String fNewTraceName
= null;
76 * Flag whether default location (path) shall be used or not
78 private boolean fIsOverride
= true;
80 // ------------------------------------------------------------------------
82 // ------------------------------------------------------------------------
85 * @param shell - a shell for the display of the dialog
87 public ImportConfirmationDialog(Shell shell
) {
89 setShellStyle(SWT
.RESIZE
);
92 // ------------------------------------------------------------------------
94 // ------------------------------------------------------------------------
97 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportConfirmationDialog#setTraceName(java.lang.String)
100 public void setTraceName(String name
) {
106 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportConfirmationDialog#getNewTraceName()
109 public String
getNewTraceName() {
110 return fNewTraceName
;
115 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportConfirmationDialog#isOverwrite()
118 public boolean isOverwrite() {
122 // ------------------------------------------------------------------------
124 // ------------------------------------------------------------------------
127 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
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
));
138 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
141 protected Control
createDialogArea(Composite parent
) {
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
));
149 Label sessionNameLabel
= new Label(fDialogComposite
, SWT
.RIGHT
);
150 sessionNameLabel
.setText(Messages
.TraceControl_ImportDialogTraceAlreadyExistError
+ ": " + fTraceName
); //$NON-NLS-1$
152 fOverwriteButton
= new Button(fDialogComposite
, SWT
.RADIO
);
153 fOverwriteButton
.setText(Messages
.TraceControl_ImportDialogConfirmationOverwriteLabel
);
155 fOverwriteButton
.addSelectionListener(new SelectionAdapter() {
157 public void widgetSelected(SelectionEvent e
) {
158 fNewTraceNameText
.setEnabled(false);
159 fNewTraceNameText
.setText(fTraceName
);
163 fRenameButton
= new Button(fDialogComposite
, SWT
.RADIO
);
164 fRenameButton
.setText(Messages
.TraceControl_ImportDialogConfirmationRenameLabel
);
166 fRenameButton
.addSelectionListener(new SelectionAdapter() {
168 public void widgetSelected(SelectionEvent e
) {
169 fNewTraceNameText
.setEnabled(true);
173 fNewTraceNameText
= new Text(fDialogComposite
, SWT
.NONE
);
174 fNewTraceNameText
.setToolTipText(Messages
.TraceControl_ImportDialogConfirmationNewNameLabel
);
175 fNewTraceNameText
.setText(fTraceName
);
178 fOverwriteButton
.setSelection(true);
179 fNewTraceNameText
.setEnabled(false);
183 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
185 fNewTraceNameText
.setLayoutData(data
);
187 getShell().setMinimumSize(new Point(300, 150));
189 return fDialogComposite
;
194 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
197 protected void createButtonsForButtonBar(Composite parent
) {
198 createButton(parent
, IDialogConstants
.CANCEL_ID
, "&Cancel", true); //$NON-NLS-1$
199 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
204 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
207 protected void okPressed() {
209 fIsOverride
= fOverwriteButton
.getSelection();
212 // new name is old name
213 fNewTraceName
= fTraceName
;
215 fNewTraceName
= fNewTraceNameText
.getText();
218 // Check for invalid names
219 if (!fNewTraceName
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
220 MessageDialog
.openError(getShell(),
221 Messages
.TraceControl_ImportDialogConfirmationTitle
,
222 Messages
.TraceControl_InvalidTraceNameError
+ " (" + fNewTraceName
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
226 // validation successful -> call super.okPressed()