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 org
.eclipse
.jface
.dialogs
.MessageDialog
;
17 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.latency
.analyzer
.EventMatcher
;
18 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.latency
.Messages
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.layout
.GridData
;
21 import org
.eclipse
.swt
.widgets
.Button
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Event
;
24 import org
.eclipse
.swt
.widgets
.Listener
;
25 import org
.eclipse
.swt
.widgets
.Shell
;
26 import org
.eclipse
.swt
.widgets
.TableItem
;
29 * <b><u>DeleteDialog</u></b>
31 * Remove dialog, lets the user remove start/end event pairs.
33 * @author Philippe Sawicki
35 public class DeleteDialog
extends ListDialog
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
46 * The dialog's window title.
48 * The dialog's window message.
50 public DeleteDialog(Shell parentShell
, String title
, String message
) {
51 super(parentShell
, title
, message
);
53 // Set the table style
54 fStyle
= SWT
.MULTI
| SWT
.FULL_SELECTION
| SWT
.BORDER
| SWT
.V_SCROLL
;
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
63 * @see org.eclipse.linuxtools.lttng.ui.views.latency.dialogs.ListDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
66 protected void createButtonsForButtonBar(Composite parent
) {
67 GridData gridData
= new GridData();
68 gridData
.verticalAlignment
= GridData
.FILL
;
69 gridData
.horizontalSpan
= 1;
70 gridData
.grabExcessHorizontalSpace
= true;
71 gridData
.grabExcessVerticalSpace
= true;
72 gridData
.horizontalAlignment
= SWT
.RIGHT
;
74 parent
.setLayoutData(gridData
);
76 // Create the "Delete" button
77 Button deleteButton
= createButton(parent
, DELETE
, Messages
.LatencyView_Dialogs_DeleteEvents_Buttons_Delete
, false);
78 deleteButton
.addListener(SWT
.Selection
, new Listener() {
80 public void handleEvent(Event event
) {
81 TableItem selectedItem
= fTable
.getSelection()[0];
82 if (selectedItem
== null)
85 int[] selectedIndices
= fTable
.getSelectionIndices();
87 StringBuffer deletePairs
= new StringBuffer(""); //$NON-NLS-1$
88 for (int i
= 0; i
< selectedIndices
.length
; i
++) {
89 int index
= selectedIndices
[i
];
90 deletePairs
.append("\t* ").append(fEventStartTypes
.get(index
)).append(" / ").append(fEventEndTypes
.get(index
)); //$NON-NLS-1$ //$NON-NLS-2$
92 if (i
< selectedIndices
.length
- 1) {
93 deletePairs
.append("\n"); //$NON-NLS-1$
97 boolean confirmDeletion
= MessageDialog
.openQuestion(getShell(), Messages
.LatencyView_Dialogs_DeleteEvents_Confirm_Title
,
98 Messages
.LatencyView_Dialogs_DeleteEvents_Confirm_Message
+ "\n\n" + deletePairs
.toString()); //$NON-NLS-1$
100 if (confirmDeletion
) {
101 // Remove the events starting from the end of the list, otherwise the TableItem elements will lose
102 // their index from the table and may trigger an exception when removing an index that is no longer
104 for (int i
= selectedIndices
.length
- 1; i
>= 0; i
--) {
105 int selectedIndex
= selectedIndices
[i
];
106 EventMatcher
.getInstance().removeMatch(fEventStartTypes
.get(selectedIndex
), fEventEndTypes
.get(selectedIndex
));
108 fTable
.remove(selectedIndex
);
110 // Update the list of events
111 fEventStartTypes
.remove(selectedIndex
);
112 fEventEndTypes
.remove(selectedIndex
);
115 // Save the events pairs in the settings file so it can be retrieved in the next session
116 saveMatchPairs(fEventStartTypes
, fEventEndTypes
);
118 fTable
.setItemCount(fEventStartTypes
.size());
120 TableItem
[] newItems
= fTable
.getItems();
122 for (int i
= 0; i
< newItems
.length
; i
++) {
123 TableItem item
= new TableItem(fTable
, SWT
.RIGHT
);
125 String max
= String
.valueOf(fEventStartTypes
.size());
126 String number
= formatListNumber(i
+ 1, max
.length());
128 String
[] columns
= { number
, fEventStartTypes
.get(i
), fEventEndTypes
.get(i
) };
130 item
.setText(columns
);
133 fRedrawGraphs
= true;
138 // Create the "Close" button
139 Button closeButton
= createButton(parent
, CANCEL
, Messages
.LatencyView_Dialogs_AddEvents_Buttons_Close
, false);
140 closeButton
.addListener(SWT
.Selection
, new Listener() {
142 public void handleEvent(Event event
) {
143 // Remember the user's list
144 saveMatchPairs(fEventStartTypes
, fEventEndTypes
);
146 setReturnCode(CANCEL
);
148 if (fRedrawGraphs
== true)