| 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.ui.PlatformUI; |
| 15 | |
| 16 | /** |
| 17 | * <p> |
| 18 | * Factory for generating dialog boxes. It allows to overwrite the dialog implementation. |
| 19 | * Useful also for testing purposes. |
| 20 | * </p> |
| 21 | * |
| 22 | * @author Bernd Hufmann |
| 23 | * |
| 24 | */ |
| 25 | public final class TraceControlDialogFactory { |
| 26 | |
| 27 | // ------------------------------------------------------------------------ |
| 28 | // Members |
| 29 | // ------------------------------------------------------------------------ |
| 30 | |
| 31 | /** |
| 32 | * The factory instance. |
| 33 | */ |
| 34 | private static TraceControlDialogFactory fInstance; |
| 35 | |
| 36 | /** |
| 37 | * The new connection dialog reference. |
| 38 | */ |
| 39 | private INewConnectionDialog fNewConnectionDialog; |
| 40 | |
| 41 | /** |
| 42 | * The enable channel dialog |
| 43 | */ |
| 44 | private IEnableChannelDialog fEnableChannelDialog; |
| 45 | |
| 46 | /** |
| 47 | * The create session dialog. |
| 48 | */ |
| 49 | private ICreateSessionDialog fCreateSessionDialog; |
| 50 | |
| 51 | /** |
| 52 | * The enable events dialog. |
| 53 | */ |
| 54 | private IEnableEventsDialog fEnableEventsDialog; |
| 55 | |
| 56 | /** |
| 57 | * The get event info dialog. |
| 58 | */ |
| 59 | private IGetEventInfoDialog fGetEventInfoDialog; |
| 60 | |
| 61 | /** |
| 62 | * The confirmation dialog implementation. |
| 63 | */ |
| 64 | private IConfirmDialog fConfirmDialog; |
| 65 | |
| 66 | /** |
| 67 | * The add context dialog implementation. |
| 68 | */ |
| 69 | private IAddContextDialog fAddContextDialog; |
| 70 | |
| 71 | /** |
| 72 | * The import dialog implementation. |
| 73 | */ |
| 74 | private IImportDialog fImportDialog; |
| 75 | |
| 76 | /** |
| 77 | * The import confirmation dialog. |
| 78 | */ |
| 79 | private IImportConfirmationDialog fImportConfirmationDialog; |
| 80 | |
| 81 | // ------------------------------------------------------------------------ |
| 82 | // Constructors |
| 83 | // ------------------------------------------------------------------------ |
| 84 | |
| 85 | /** |
| 86 | * Constructor for R4EUIDialogFactory. |
| 87 | */ |
| 88 | private TraceControlDialogFactory() { |
| 89 | } |
| 90 | |
| 91 | // ------------------------------------------------------------------------ |
| 92 | // Operations |
| 93 | // ------------------------------------------------------------------------ |
| 94 | |
| 95 | /** |
| 96 | * @return TraceControlDialogFactory instance |
| 97 | */ |
| 98 | public synchronized static TraceControlDialogFactory getInstance() { |
| 99 | if (fInstance == null) { |
| 100 | fInstance = new TraceControlDialogFactory(); |
| 101 | } |
| 102 | return fInstance; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @return new connection dialog |
| 107 | */ |
| 108 | public INewConnectionDialog getNewConnectionDialog() { |
| 109 | if (fNewConnectionDialog == null) { |
| 110 | fNewConnectionDialog = new NewConnectionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); |
| 111 | } |
| 112 | return fNewConnectionDialog; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Sets a new connection dialog implementation. |
| 117 | * @param newConnectionDialog - new connection dialog implementation |
| 118 | */ |
| 119 | public void setNewConnectionDialog(INewConnectionDialog newConnectionDialog) { |
| 120 | fNewConnectionDialog = newConnectionDialog; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @return enable channel dialog |
| 125 | */ |
| 126 | public IEnableChannelDialog getEnableChannelDialog() { |
| 127 | if (fEnableChannelDialog == null) { |
| 128 | fEnableChannelDialog = new EnableChannelDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); |
| 129 | } |
| 130 | return fEnableChannelDialog; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Sets a enable channel dialog implementation. |
| 135 | * @param createEnableDialog - a create channel dialog implementation |
| 136 | */ |
| 137 | public void setEnableChannelDialog(IEnableChannelDialog createEnableDialog) { |
| 138 | fEnableChannelDialog = createEnableDialog; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * @return create session dialog implementation |
| 143 | */ |
| 144 | public ICreateSessionDialog getCreateSessionDialog() { |
| 145 | if (fCreateSessionDialog == null) { |
| 146 | fCreateSessionDialog = new CreateSessionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); |
| 147 | } |
| 148 | return fCreateSessionDialog; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Sets a create session dialog implementation. |
| 153 | * @param createSessionDialog - a create session implementation. |
| 154 | */ |
| 155 | public void setCreateSessionDialog(ICreateSessionDialog createSessionDialog) { |
| 156 | fCreateSessionDialog = createSessionDialog; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @return enable events dialog implementation. |
| 161 | */ |
| 162 | public IEnableEventsDialog getEnableEventsDialog() { |
| 163 | if (fEnableEventsDialog == null) { |
| 164 | fEnableEventsDialog = new EnableEventsDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); |
| 165 | } |
| 166 | return fEnableEventsDialog; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Sets a enable events dialog implementation. |
| 171 | * @param enableEventsDialog - a enable events dialog implementation. |
| 172 | */ |
| 173 | public void setEnableEventsDialog(IEnableEventsDialog enableEventsDialog) { |
| 174 | fEnableEventsDialog = enableEventsDialog; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * @return get events info dialog implementation. |
| 179 | */ |
| 180 | public IGetEventInfoDialog getGetEventInfoDialog() { |
| 181 | if (fGetEventInfoDialog == null) { |
| 182 | fGetEventInfoDialog = new GetEventInfoDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); |
| 183 | } |
| 184 | return fGetEventInfoDialog; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Sets a get events info dialog implementation. |
| 189 | * @param getEventInfoDialog - a get events info dialog implementation |
| 190 | */ |
| 191 | public void setGetEventInfoDialog(IGetEventInfoDialog getEventInfoDialog) { |
| 192 | fGetEventInfoDialog = getEventInfoDialog; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * @return the confirmation dialog implementation |
| 197 | */ |
| 198 | public IConfirmDialog getConfirmDialog() { |
| 199 | if (fConfirmDialog == null) { |
| 200 | fConfirmDialog = new ConfirmDialog(); |
| 201 | } |
| 202 | return fConfirmDialog; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Sets the confirmation dialog implementation |
| 207 | * @param confirmDialog - a confirmation dialog implementation |
| 208 | */ |
| 209 | public void setConfirmDialog(IConfirmDialog confirmDialog) { |
| 210 | fConfirmDialog = confirmDialog; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * @return the add context dialog implementation |
| 215 | */ |
| 216 | public IAddContextDialog getAddContextDialog() { |
| 217 | if (fAddContextDialog == null) { |
| 218 | fAddContextDialog = new AddContextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); |
| 219 | } |
| 220 | return fAddContextDialog; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Sets the add context dialog information |
| 225 | * @param addContextDialog - a add context dialog implementation |
| 226 | */ |
| 227 | public void setAddContextDialog(IAddContextDialog addContextDialog) { |
| 228 | fAddContextDialog = addContextDialog; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * @return the import dialog implementation |
| 233 | */ |
| 234 | public IImportDialog getImportDialog() { |
| 235 | if (fImportDialog == null) { |
| 236 | fImportDialog = new ImportDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); |
| 237 | } |
| 238 | return fImportDialog; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Sets the import dialog implementation. |
| 243 | * @param importDialog - a import dialog implementation |
| 244 | */ |
| 245 | public void setImportDialog(IImportDialog importDialog) { |
| 246 | fImportDialog = importDialog; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * @return the import confirmation dialog implementation. |
| 251 | */ |
| 252 | public IImportConfirmationDialog getImportConfirmationDialog() { |
| 253 | if (fImportConfirmationDialog == null) { |
| 254 | fImportConfirmationDialog = new ImportConfirmationDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); |
| 255 | } |
| 256 | return fImportConfirmationDialog; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Sets the import confirmation dialog implementation. |
| 261 | * @param confirmDialog - a import confirmation dialog implementation. |
| 262 | */ |
| 263 | public void setImportConfirmationDialog(IImportConfirmationDialog confirmDialog) { |
| 264 | fImportConfirmationDialog = confirmDialog; |
| 265 | } |
| 266 | } |
| 267 | |