Commit | Line | Data |
---|---|---|
291cbdbf BH |
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; | |
9315aeee | 18 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.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> | |
dbd4432d BH |
36 | * |
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 | // ------------------------------------------------------------------------ | |
52 | /** | |
53 | * The dialog composite. | |
54 | */ | |
55 | private Composite fDialogComposite = null; | |
56 | /** | |
57 | * The radio button for selecting the overwrite action | |
58 | */ | |
59 | private Button fOverwriteButton = null; | |
60 | /** | |
61 | * The radio button for selecting the renaming action | |
62 | */ | |
63 | private Button fRenameButton = null; | |
64 | /** | |
65 | * The text widget for the session name | |
66 | */ | |
67 | private Text fNewTraceNameText = null; | |
68 | /** | |
69 | * The trace name which already exists in the project | |
70 | */ | |
71 | private String fTraceName = null; | |
72 | /** | |
73 | * The session name string. | |
74 | */ | |
75 | private String fNewTraceName = null; | |
76 | /** | |
77 | * Flag whether default location (path) shall be used or not | |
78 | */ | |
79 | private boolean fIsOverride = true; | |
80 | ||
81 | // ------------------------------------------------------------------------ | |
82 | // Constructors | |
83 | // ------------------------------------------------------------------------ | |
84 | /** | |
85 | * Constructor | |
86 | * @param shell - a shell for the display of the dialog | |
87 | */ | |
88 | public ImportConfirmationDialog(Shell shell) { | |
89 | super(shell); | |
90 | setShellStyle(SWT.RESIZE); | |
91 | } | |
92 | ||
93 | // ------------------------------------------------------------------------ | |
94 | // Accessors | |
95 | // ------------------------------------------------------------------------ | |
96 | /* | |
97 | * (non-Javadoc) | |
98 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportConfirmationDialog#setTraceName(java.lang.String) | |
99 | */ | |
100 | @Override | |
101 | public void setTraceName(String name) { | |
102 | fTraceName = name; | |
103 | } | |
104 | ||
105 | /* | |
106 | * (non-Javadoc) | |
107 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportConfirmationDialog#getNewTraceName() | |
108 | */ | |
109 | @Override | |
110 | public String getNewTraceName() { | |
111 | return fNewTraceName; | |
112 | } | |
113 | ||
114 | /* | |
115 | * (non-Javadoc) | |
116 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportConfirmationDialog#isOverwrite() | |
117 | */ | |
118 | @Override | |
119 | public boolean isOverwrite() { | |
120 | return fIsOverride; | |
121 | } | |
122 | ||
123 | // ------------------------------------------------------------------------ | |
124 | // Operations | |
125 | // ------------------------------------------------------------------------ | |
126 | /* | |
127 | * (non-Javadoc) | |
128 | * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) | |
129 | */ | |
130 | @Override | |
131 | protected void configureShell(Shell newShell) { | |
132 | super.configureShell(newShell); | |
133 | newShell.setText(Messages.TraceControl_ImportDialogConfirmationTitle); | |
134 | newShell.setImage(Activator.getDefault().loadIcon(IMPORT_ICON_FILE)); | |
135 | } | |
136 | ||
137 | /* | |
138 | * (non-Javadoc) | |
139 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) | |
140 | */ | |
141 | @Override | |
142 | protected Control createDialogArea(Composite parent) { | |
143 | ||
144 | // Main dialog panel | |
145 | fDialogComposite = new Composite(parent, SWT.NONE); | |
146 | GridLayout layout = new GridLayout(1, true); | |
147 | fDialogComposite.setLayout(layout); | |
148 | fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
149 | ||
150 | Label sessionNameLabel = new Label(fDialogComposite, SWT.RIGHT); | |
151 | sessionNameLabel.setText(Messages.TraceControl_ImportDialogTraceAlreadyExistError + ": " + fTraceName); //$NON-NLS-1$ | |
152 | ||
153 | fOverwriteButton = new Button(fDialogComposite, SWT.RADIO); | |
154 | fOverwriteButton.setText(Messages.TraceControl_ImportDialogConfirmationOverwriteLabel); | |
155 | ||
156 | fOverwriteButton.addSelectionListener(new SelectionAdapter() { | |
157 | @Override | |
158 | public void widgetSelected(SelectionEvent e) { | |
159 | fNewTraceNameText.setEnabled(false); | |
160 | fNewTraceNameText.setText(fTraceName); | |
161 | } | |
162 | }); | |
163 | ||
164 | fRenameButton = new Button(fDialogComposite, SWT.RADIO); | |
165 | fRenameButton.setText(Messages.TraceControl_ImportDialogConfirmationRenameLabel); | |
166 | ||
167 | fRenameButton.addSelectionListener(new SelectionAdapter() { | |
168 | @Override | |
169 | public void widgetSelected(SelectionEvent e) { | |
170 | fNewTraceNameText.setEnabled(true); | |
171 | } | |
172 | }); | |
173 | ||
174 | fNewTraceNameText = new Text(fDialogComposite, SWT.NONE); | |
175 | fNewTraceNameText.setToolTipText(Messages.TraceControl_ImportDialogConfirmationNewNameLabel); | |
176 | fNewTraceNameText.setText(fTraceName); | |
177 | ||
178 | // Default | |
179 | fOverwriteButton.setSelection(true); | |
180 | fNewTraceNameText.setEnabled(false); | |
181 | ||
182 | ||
183 | // layout widgets | |
184 | GridData data = new GridData(GridData.FILL_HORIZONTAL); | |
185 | ||
186 | fNewTraceNameText.setLayoutData(data); | |
187 | ||
188 | getShell().setMinimumSize(new Point(300, 150)); | |
189 | ||
190 | return fDialogComposite; | |
191 | } | |
192 | ||
193 | /* | |
194 | * (non-Javadoc) | |
195 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) | |
196 | */ | |
197 | @Override | |
198 | protected void createButtonsForButtonBar(Composite parent) { | |
79c3db85 | 199 | createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$ |
291cbdbf BH |
200 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ |
201 | } | |
202 | ||
203 | /* | |
204 | * (non-Javadoc) | |
205 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | |
206 | */ | |
207 | @Override | |
208 | protected void okPressed() { | |
209 | ||
210 | fIsOverride = fOverwriteButton.getSelection(); | |
211 | ||
212 | if (fIsOverride) { | |
213 | // new name is old name | |
214 | fNewTraceName = fTraceName; | |
215 | } else { | |
216 | fNewTraceName = fNewTraceNameText.getText(); | |
217 | } | |
218 | ||
219 | // Check for invalid names | |
220 | if (!fNewTraceName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ | |
221 | MessageDialog.openError(getShell(), | |
222 | Messages.TraceControl_ImportDialogConfirmationTitle, | |
223 | Messages.TraceControl_InvalidTraceNameError + " (" + fNewTraceName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ | |
224 | return; | |
225 | } | |
226 | ||
227 | // validation successful -> call super.okPressed() | |
228 | super.okPressed(); | |
229 | } | |
230 | } |