Commit | Line | Data |
---|---|---|
291cbdbf | 1 | /********************************************************************** |
11252342 AM |
2 | * Copyright (c) 2012, 2013 Ericsson |
3 | * | |
291cbdbf BH |
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 | |
11252342 AM |
8 | * |
9 | * Contributors: | |
291cbdbf BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
8e8c0226 | 12 | package org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs; |
291cbdbf BH |
13 | |
14 | import org.eclipse.jface.dialogs.Dialog; | |
15 | import org.eclipse.jface.dialogs.IDialogConstants; | |
16 | import org.eclipse.jface.dialogs.MessageDialog; | |
8e8c0226 AM |
17 | import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator; |
18 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages; | |
291cbdbf BH |
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 | /** | |
291cbdbf BH |
33 | * <p> |
34 | * Dialog box for collecting session creation information. | |
35 | * </p> | |
11252342 | 36 | * |
dbd4432d | 37 | * @author Bernd Hufmann |
291cbdbf BH |
38 | */ |
39 | public class ImportConfirmationDialog extends Dialog implements IImportConfirmationDialog { | |
40 | ||
41 | // ------------------------------------------------------------------------ | |
42 | // Constants | |
43 | // ------------------------------------------------------------------------ | |
44 | /** | |
45 | * The icon file for this dialog box. | |
46 | */ | |
47 | public static final String IMPORT_ICON_FILE = "icons/elcl16/import_trace.gif"; //$NON-NLS-1$ | |
48 | ||
49 | // ------------------------------------------------------------------------ | |
50 | // Attributes | |
51 | // ------------------------------------------------------------------------ | |
291cbdbf BH |
52 | /** |
53 | * The radio button for selecting the overwrite action | |
54 | */ | |
55 | private Button fOverwriteButton = null; | |
56 | /** | |
57 | * The radio button for selecting the renaming action | |
58 | */ | |
59 | private Button fRenameButton = null; | |
60 | /** | |
61 | * The text widget for the session name | |
62 | */ | |
63 | private Text fNewTraceNameText = null; | |
64 | /** | |
11252342 | 65 | * The trace name which already exists in the project |
291cbdbf BH |
66 | */ |
67 | private String fTraceName = null; | |
68 | /** | |
69 | * The session name string. | |
70 | */ | |
71 | private String fNewTraceName = null; | |
72 | /** | |
73 | * Flag whether default location (path) shall be used or not | |
74 | */ | |
75 | private boolean fIsOverride = true; | |
76 | ||
77 | // ------------------------------------------------------------------------ | |
78 | // Constructors | |
79 | // ------------------------------------------------------------------------ | |
80 | /** | |
81 | * Constructor | |
82 | * @param shell - a shell for the display of the dialog | |
83 | */ | |
84 | public ImportConfirmationDialog(Shell shell) { | |
85 | super(shell); | |
8a396998 | 86 | setShellStyle(SWT.RESIZE | getShellStyle()); |
291cbdbf BH |
87 | } |
88 | ||
89 | // ------------------------------------------------------------------------ | |
90 | // Accessors | |
91 | // ------------------------------------------------------------------------ | |
11252342 | 92 | |
291cbdbf BH |
93 | @Override |
94 | public void setTraceName(String name) { | |
95 | fTraceName = name; | |
96 | } | |
97 | ||
291cbdbf BH |
98 | @Override |
99 | public String getNewTraceName() { | |
100 | return fNewTraceName; | |
101 | } | |
11252342 | 102 | |
291cbdbf BH |
103 | @Override |
104 | public boolean isOverwrite() { | |
105 | return fIsOverride; | |
106 | } | |
107 | ||
108 | // ------------------------------------------------------------------------ | |
109 | // Operations | |
110 | // ------------------------------------------------------------------------ | |
11252342 | 111 | |
291cbdbf BH |
112 | @Override |
113 | protected void configureShell(Shell newShell) { | |
114 | super.configureShell(newShell); | |
115 | newShell.setText(Messages.TraceControl_ImportDialogConfirmationTitle); | |
116 | newShell.setImage(Activator.getDefault().loadIcon(IMPORT_ICON_FILE)); | |
117 | } | |
118 | ||
291cbdbf BH |
119 | @Override |
120 | protected Control createDialogArea(Composite parent) { | |
11252342 | 121 | |
291cbdbf | 122 | // Main dialog panel |
046b6849 | 123 | Composite dialogComposite = new Composite(parent, SWT.NONE); |
291cbdbf | 124 | GridLayout layout = new GridLayout(1, true); |
046b6849 BH |
125 | dialogComposite.setLayout(layout); |
126 | dialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
291cbdbf | 127 | |
046b6849 | 128 | Label sessionNameLabel = new Label(dialogComposite, SWT.RIGHT); |
291cbdbf BH |
129 | sessionNameLabel.setText(Messages.TraceControl_ImportDialogTraceAlreadyExistError + ": " + fTraceName); //$NON-NLS-1$ |
130 | ||
046b6849 | 131 | fOverwriteButton = new Button(dialogComposite, SWT.RADIO); |
291cbdbf | 132 | fOverwriteButton.setText(Messages.TraceControl_ImportDialogConfirmationOverwriteLabel); |
11252342 | 133 | |
291cbdbf BH |
134 | fOverwriteButton.addSelectionListener(new SelectionAdapter() { |
135 | @Override | |
136 | public void widgetSelected(SelectionEvent e) { | |
137 | fNewTraceNameText.setEnabled(false); | |
138 | fNewTraceNameText.setText(fTraceName); | |
139 | } | |
140 | }); | |
11252342 | 141 | |
046b6849 | 142 | fRenameButton = new Button(dialogComposite, SWT.RADIO); |
291cbdbf | 143 | fRenameButton.setText(Messages.TraceControl_ImportDialogConfirmationRenameLabel); |
11252342 | 144 | |
291cbdbf BH |
145 | fRenameButton.addSelectionListener(new SelectionAdapter() { |
146 | @Override | |
147 | public void widgetSelected(SelectionEvent e) { | |
148 | fNewTraceNameText.setEnabled(true); | |
149 | } | |
150 | }); | |
11252342 | 151 | |
046b6849 | 152 | fNewTraceNameText = new Text(dialogComposite, SWT.NONE); |
291cbdbf BH |
153 | fNewTraceNameText.setToolTipText(Messages.TraceControl_ImportDialogConfirmationNewNameLabel); |
154 | fNewTraceNameText.setText(fTraceName); | |
155 | ||
156 | // Default | |
157 | fOverwriteButton.setSelection(true); | |
158 | fNewTraceNameText.setEnabled(false); | |
11252342 | 159 | |
291cbdbf BH |
160 | |
161 | // layout widgets | |
162 | GridData data = new GridData(GridData.FILL_HORIZONTAL); | |
11252342 | 163 | |
291cbdbf BH |
164 | fNewTraceNameText.setLayoutData(data); |
165 | ||
166 | getShell().setMinimumSize(new Point(300, 150)); | |
11252342 | 167 | |
046b6849 | 168 | return dialogComposite; |
291cbdbf BH |
169 | } |
170 | ||
291cbdbf BH |
171 | @Override |
172 | protected void createButtonsForButtonBar(Composite parent) { | |
79c3db85 | 173 | createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$ |
291cbdbf BH |
174 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ |
175 | } | |
176 | ||
291cbdbf BH |
177 | @Override |
178 | protected void okPressed() { | |
179 | ||
180 | fIsOverride = fOverwriteButton.getSelection(); | |
181 | ||
182 | if (fIsOverride) { | |
183 | // new name is old name | |
184 | fNewTraceName = fTraceName; | |
185 | } else { | |
186 | fNewTraceName = fNewTraceNameText.getText(); | |
187 | } | |
188 | ||
189 | // Check for invalid names | |
190 | if (!fNewTraceName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ | |
191 | MessageDialog.openError(getShell(), | |
192 | Messages.TraceControl_ImportDialogConfirmationTitle, | |
193 | Messages.TraceControl_InvalidTraceNameError + " (" + fNewTraceName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ | |
194 | return; | |
195 | } | |
196 | ||
197 | // validation successful -> call super.okPressed() | |
198 | super.okPressed(); | |
199 | } | |
200 | } |