1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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
.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
;
34 * Dialog box for collecting session creation information.
37 * @author Bernd Hufmann
39 public class ImportConfirmationDialog
extends Dialog
implements IImportConfirmationDialog
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
45 * The icon file for this dialog box.
47 public static final String IMPORT_ICON_FILE
= "icons/elcl16/import_trace.gif"; //$NON-NLS-1$
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
53 * The dialog composite.
55 private Composite fDialogComposite
= null;
57 * The radio button for selecting the overwrite action
59 private Button fOverwriteButton
= null;
61 * The radio button for selecting the renaming action
63 private Button fRenameButton
= null;
65 * The text widget for the session name
67 private Text fNewTraceNameText
= null;
69 * The trace name which already exists in the project
71 private String fTraceName
= null;
73 * The session name string.
75 private String fNewTraceName
= null;
77 * Flag whether default location (path) shall be used or not
79 private boolean fIsOverride
= true;
81 // ------------------------------------------------------------------------
83 // ------------------------------------------------------------------------
86 * @param shell - a shell for the display of the dialog
88 public ImportConfirmationDialog(Shell shell
) {
90 setShellStyle(SWT
.RESIZE
);
93 // ------------------------------------------------------------------------
95 // ------------------------------------------------------------------------
98 public void setTraceName(String name
) {
103 public String
getNewTraceName() {
104 return fNewTraceName
;
108 public boolean isOverwrite() {
112 // ------------------------------------------------------------------------
114 // ------------------------------------------------------------------------
117 protected void configureShell(Shell newShell
) {
118 super.configureShell(newShell
);
119 newShell
.setText(Messages
.TraceControl_ImportDialogConfirmationTitle
);
120 newShell
.setImage(Activator
.getDefault().loadIcon(IMPORT_ICON_FILE
));
124 protected Control
createDialogArea(Composite parent
) {
127 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
128 GridLayout layout
= new GridLayout(1, true);
129 fDialogComposite
.setLayout(layout
);
130 fDialogComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
132 Label sessionNameLabel
= new Label(fDialogComposite
, SWT
.RIGHT
);
133 sessionNameLabel
.setText(Messages
.TraceControl_ImportDialogTraceAlreadyExistError
+ ": " + fTraceName
); //$NON-NLS-1$
135 fOverwriteButton
= new Button(fDialogComposite
, SWT
.RADIO
);
136 fOverwriteButton
.setText(Messages
.TraceControl_ImportDialogConfirmationOverwriteLabel
);
138 fOverwriteButton
.addSelectionListener(new SelectionAdapter() {
140 public void widgetSelected(SelectionEvent e
) {
141 fNewTraceNameText
.setEnabled(false);
142 fNewTraceNameText
.setText(fTraceName
);
146 fRenameButton
= new Button(fDialogComposite
, SWT
.RADIO
);
147 fRenameButton
.setText(Messages
.TraceControl_ImportDialogConfirmationRenameLabel
);
149 fRenameButton
.addSelectionListener(new SelectionAdapter() {
151 public void widgetSelected(SelectionEvent e
) {
152 fNewTraceNameText
.setEnabled(true);
156 fNewTraceNameText
= new Text(fDialogComposite
, SWT
.NONE
);
157 fNewTraceNameText
.setToolTipText(Messages
.TraceControl_ImportDialogConfirmationNewNameLabel
);
158 fNewTraceNameText
.setText(fTraceName
);
161 fOverwriteButton
.setSelection(true);
162 fNewTraceNameText
.setEnabled(false);
166 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
168 fNewTraceNameText
.setLayoutData(data
);
170 getShell().setMinimumSize(new Point(300, 150));
172 return fDialogComposite
;
176 protected void createButtonsForButtonBar(Composite parent
) {
177 createButton(parent
, IDialogConstants
.CANCEL_ID
, "&Cancel", true); //$NON-NLS-1$
178 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
182 protected void okPressed() {
184 fIsOverride
= fOverwriteButton
.getSelection();
187 // new name is old name
188 fNewTraceName
= fTraceName
;
190 fNewTraceName
= fNewTraceNameText
.getText();
193 // Check for invalid names
194 if (!fNewTraceName
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
195 MessageDialog
.openError(getShell(),
196 Messages
.TraceControl_ImportDialogConfirmationTitle
,
197 Messages
.TraceControl_InvalidTraceNameError
+ " (" + fNewTraceName
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
201 // validation successful -> call super.okPressed()