tmf: Use tabs in statistics view for each traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / internal / lttng / ui / views / latency / dialogs / DeleteDialog.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2011 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 * 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;
15
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;
27
28 /**
29 * <b><u>DeleteDialog</u></b>
30 * <p>
31 * Remove dialog, lets the user remove start/end event pairs.
32 *
33 * @author Philippe Sawicki
34 */
35 public class DeleteDialog extends ListDialog {
36
37 // ------------------------------------------------------------------------
38 // Constructors
39 // ------------------------------------------------------------------------
40
41 /**
42 * Constructor.
43 * @param parentShell
44 * The parent shell.
45 * @param title
46 * The dialog's window title.
47 * @param message
48 * The dialog's window message.
49 */
50 public DeleteDialog(Shell parentShell, String title, String message) {
51 super(parentShell, title, message);
52
53 // Set the table style
54 fStyle = SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL;
55 }
56
57 // ------------------------------------------------------------------------
58 // Operations
59 // ------------------------------------------------------------------------
60
61 /*
62 * (non-Javadoc)
63 * @see org.eclipse.linuxtools.lttng.ui.views.latency.dialogs.ListDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
64 */
65 @Override
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;
73
74 parent.setLayoutData(gridData);
75
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() {
79 @Override
80 public void handleEvent(Event event) {
81 TableItem selectedItem = fTable.getSelection()[0];
82 if (selectedItem == null)
83 return;
84
85 int[] selectedIndices = fTable.getSelectionIndices();
86
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$
91
92 if (i < selectedIndices.length - 1) {
93 deletePairs.append("\n"); //$NON-NLS-1$
94 }
95 }
96
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$
99
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
103 // valid.
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));
107
108 fTable.remove(selectedIndex);
109
110 // Update the list of events
111 fEventStartTypes.remove(selectedIndex);
112 fEventEndTypes.remove(selectedIndex);
113 }
114
115 // Save the events pairs in the settings file so it can be retrieved in the next session
116 saveMatchPairs(fEventStartTypes, fEventEndTypes);
117
118 fTable.setItemCount(fEventStartTypes.size());
119
120 TableItem[] newItems = fTable.getItems();
121 fTable.removeAll();
122 for (int i = 0; i < newItems.length; i++) {
123 TableItem item = new TableItem(fTable, SWT.RIGHT);
124
125 String max = String.valueOf(fEventStartTypes.size());
126 String number = formatListNumber(i + 1, max.length());
127
128 String[] columns = { number, fEventStartTypes.get(i), fEventEndTypes.get(i) };
129
130 item.setText(columns);
131 }
132
133 fRedrawGraphs = true;
134 }
135 }
136 });
137
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() {
141 @Override
142 public void handleEvent(Event event) {
143 // Remember the user's list
144 saveMatchPairs(fEventStartTypes, fEventEndTypes);
145
146 setReturnCode(CANCEL);
147
148 if (fRedrawGraphs == true)
149 redrawGraphs();
150
151 close();
152 }
153 });
154 }
155 }
This page took 0.034244 seconds and 5 git commands to generate.