1 /*******************************************************************************
2 * Copyright (c) 2010, 2011 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 * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11 * Mathieu Denis (mathieu.denis55@gmail.com) - Refactored code
12 * Bernd Hufmann - Adapted to new messages file, fixed warnings
13 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.latency
.dialogs
;
16 import java
.util
.Vector
;
18 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
19 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
20 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
21 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.latency
.analyzer
.EventMatcher
;
22 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.util
.EventsPair
;
23 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.Activator
;
24 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.latency
.model
.LatencyController
;
25 import org
.eclipse
.swt
.widgets
.Composite
;
26 import org
.eclipse
.swt
.widgets
.Control
;
27 import org
.eclipse
.swt
.widgets
.Display
;
28 import org
.eclipse
.swt
.widgets
.Shell
;
31 * <b><u>AbstractDialog</u></b>
33 * Includes the main functions shared by all the different dialogs.
35 * @author Philippe Sawicki
37 public abstract class AbstractDialog
extends TitleAreaDialog
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
44 * The dialog window title.
46 protected String fDialogTitle
;
48 * The dialog window message.
50 protected String fDialogMessage
;
53 * The code returned by the dialog when the user closes the "Add" dialog.
55 public static final int ADD
= 53445;
57 * The code returned by the dialog when the user closes the "Delete" dialog.
59 public static final int DELETE
= ADD
+ 1;
61 * The code returned by the dialog when the user resets the latency pair to default.
63 public static final int RESET
= DELETE
+ 1;
66 * String ID of the number of pairs saved in the settings file.
68 protected static final String LATENCY_NB_MATCH_PAIRS
= "NB_LATENCY_MATCH_PAIRS"; //$NON-NLS-1$
70 * String ID of the start event pairs saved in the settings file.
72 protected static final String LATENCY_PAIRS_START
= "LATENCY_PAIRS_START"; //$NON-NLS-1$
74 * String ID of the end event pairs saved in the settings file.
76 protected static final String LATENCY_PAIRS_END
= "LATENCY_PAIRS_END"; //$NON-NLS-1$
79 * Dialog settings, saves the event pairs across sessions.
81 protected IDialogSettings fSettings
;
84 * Do the graphs canvas need to be redrawn due to latency pairs changes ?
86 protected boolean fRedrawGraphs
= false;
88 // ------------------------------------------------------------------------
90 // ------------------------------------------------------------------------
97 * The dialog window's title.
99 * The dialog window's message.
101 public AbstractDialog(Shell parentShell
, String title
, String message
) {
103 fDialogTitle
= title
;
104 fDialogMessage
= message
;
106 fSettings
= Activator
.getDefault().getDialogSettings();
114 * The dialog window's title.
116 @SuppressWarnings("nls")
117 public AbstractDialog(Shell parentShell
, String title
) {
118 this(parentShell
, title
, "");
126 @SuppressWarnings("nls")
127 public AbstractDialog(Shell parentShell
) {
128 this(parentShell
, "", "");
131 // ------------------------------------------------------------------------
133 // ------------------------------------------------------------------------
136 * Creates the dialog.
138 * <b>Note :</b> Since there is an issue with the table's vertical scroll bar, this dialog "resize" is necessary to
139 * ensure a minimal height for the window.
142 public void create() {
145 setTitle(fDialogTitle
);
147 setMessage(fDialogMessage
, IMessageProvider
.INFORMATION
);
149 // Position the dialog at the center of the screen
150 int windowWidth
= Display
.getCurrent().getPrimaryMonitor().getBounds().width
;
151 int windowHeight
= Display
.getCurrent().getPrimaryMonitor().getBounds().height
;
152 int dialogWidth
= getShell().getSize().x
;
153 int dialogHeight
= windowHeight
/ 2;
155 int x
= (windowWidth
- dialogWidth
) / 2;
156 int y
= (windowHeight
- dialogHeight
) / 2;
158 getShell().setSize(getShell().getSize().x
, dialogHeight
);
159 getShell().setLocation(x
, y
);
163 * Formats the "#" of the event in the table by adding "00" before it.
165 * The number to format.
167 * The maximum number of event pairs in the list.
168 * @return The formatted string.
170 @SuppressWarnings("nls")
171 protected String
formatListNumber(int number
, int max
) {
172 return String
.format("%0" + max
+ "d", number
);
176 * Returns the match pairs saved in the settings file.
177 * @return The match pairs saved in the settings file.
179 protected EventsPair
getMatchPairs() {
181 // Check if the settings file has already some data (i.e. try provoking an exception)
182 fSettings
.getInt(LATENCY_NB_MATCH_PAIRS
);
184 String
[] starts
= fSettings
.getArray(LATENCY_PAIRS_START
);
185 String
[] ends
= fSettings
.getArray(LATENCY_PAIRS_END
);
187 EventMatcher
.getInstance().resetMatches();
188 for (int i
= 0; i
< starts
.length
; i
++) {
189 EventMatcher
.getInstance().addMatch(starts
[i
], ends
[i
]);
192 return EventMatcher
.getInstance().getEvents();
193 } catch (NumberFormatException e
) {
194 return EventMatcher
.getInstance().getEvents();
199 * Saves the event match pairs to a settings file.
201 * The start event types.
203 * The end event types.
205 protected void saveMatchPairs(Vector
<String
> start
, Vector
<String
> end
) {
206 fSettings
.put(LATENCY_NB_MATCH_PAIRS
, start
.size());
207 fSettings
.put(LATENCY_PAIRS_START
, start
.toArray(new String
[] {}));
208 fSettings
.put(LATENCY_PAIRS_END
, end
.toArray(new String
[] {}));
212 * Ask the LatencyView to send a new analysis request to the views, so that they can be redrawn.
214 protected void redrawGraphs() {
215 LatencyController
.getInstance().refreshModels();
220 * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
223 protected abstract Control
createDialogArea(Composite parent
);
227 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
230 protected abstract void createButtonsForButtonBar(Composite parent
);
234 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
237 protected boolean isResizable() {