import java.util.Iterator;
import java.util.List;
-import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin;
import org.eclipse.linuxtools.lttng.ui.views.control.ControlView;
import org.eclipse.linuxtools.lttng.ui.views.control.Messages;
+import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IConfirmDialog;
+import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.TraceControlDialogFactory;
import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState;
import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceSessionComponent;
import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceSessionGroup;
import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
* Command handler implementation to destroy one or more trace sessions.
* </p>
*/
-public class DestroySessionHandler extends AbstractHandler {
+public class DestroySessionHandler extends BaseControlViewHandler {
// ------------------------------------------------------------------------
// Attributes
return false;
}
// Get user confirmation
- if (MessageDialog.openConfirm(window.getShell(),
+ IConfirmDialog dialog = TraceControlDialogFactory.getInstance().getConfirmDialog();
+ if (!dialog.openConfirm(window.getShell(),
Messages.TraceControl_DestroyConfirmationTitle,
Messages.TraceControl_DestroyConfirmationMessage)) {
- Job job = new Job(Messages.TraceControl_DestroySessionJob) {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- for (Iterator<TraceSessionComponent> iterator = fSessions.iterator(); iterator.hasNext();) {
- // Destroy all selected sessions
- TraceSessionComponent session = (TraceSessionComponent) iterator.next();
- TraceSessionGroup sessionGroup = (TraceSessionGroup)session.getParent();
- sessionGroup.destroySession(session.getName(), monitor);
- }
- } catch (ExecutionException e) {
- return new Status(Status.ERROR, LTTngUiPlugin.PLUGIN_ID, e.toString());
- }
- return Status.OK_STATUS;
- }
- };
- job.setUser(true);
- job.schedule();
+ return null;
}
+
+ Job job = new Job(Messages.TraceControl_DestroySessionJob) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ // Make a copy of the list of sessions to avoid ConcurrentModificationException when iterating
+ // over fSessions, since fSessions is modified in another thread triggered by the tree viewer refresh
+ // after removing a session.
+ TraceSessionComponent[] sessions = (TraceSessionComponent[])fSessions.toArray(new TraceSessionComponent[fSessions.size()]);
+
+ for (int i = 0; i < sessions.length; i++) {
+ // Destroy all selected sessions
+ TraceSessionComponent session = sessions[i];
+ TraceSessionGroup sessionGroup = (TraceSessionGroup)session.getParent();
+ sessionGroup.destroySession(session, monitor);
+ }
+ } catch (ExecutionException e) {
+ return new Status(Status.ERROR, LTTngUiPlugin.PLUGIN_ID, e.toString());
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setUser(true);
+ job.schedule();
+
return null;
}
*/
@Override
public boolean isEnabled() {
- fSessions.clear();
-
- // Check if we are closing down
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- if (window == null) {
- return false;
- }
-
- // Check if we are in the Project View
- IWorkbenchPage page = window.getActivePage();
+ // Get workbench page for the Control View
+ IWorkbenchPage page = getWorkbenchPage();
if (page == null) {
return false;
}
-
- IWorkbenchPart part = page.getActivePart();
- if (!(part instanceof ControlView)) {
- return false;
- }
+ fSessions.clear();
// Check if one or more session are selected
ISelection selection = page.getSelection(ControlView.ID);