X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=org.eclipse.linuxtools.lttng2.ui%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Finternal%2Flttng2%2Fui%2Fviews%2Fcontrol%2Fhandlers%2FChangeChannelStateHandler.java;h=9ea06971e741ae958fd878e76cb1f93f6b383386;hb=dbd4432dd9f427af47e9755cbf67b18e2e47b001;hp=d18afee82254b2af369bba4c5d1ad3f9756825c8;hpb=6de7a2bdb44533609f25e7a0629cbfb85c90d0b3;p=deliverable%2Ftracecompass.git diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ChangeChannelStateHandler.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ChangeChannelStateHandler.java index d18afee822..9ea06971e7 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ChangeChannelStateHandler.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ChangeChannelStateHandler.java @@ -23,10 +23,10 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement; import org.eclipse.linuxtools.internal.lttng2.ui.Activator; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView; -import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages; -import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEnablement; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; @@ -35,10 +35,11 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; /** - * ChangeChannelStateHandler *

* Abstract command handler implementation to enable or disabling a trace channel. *

+ * + * @author Bernd Hufmann */ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler { @@ -46,21 +47,9 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler { // Attributes // ------------------------------------------------------------------------ /** - * Kernel domain component reference. - */ - protected TraceDomainComponent fKernelDomain = null; - /** - * UST domain component reference. - */ - protected TraceDomainComponent fUstDomain = null; - /** - * The list of kernel channel components the command is to be executed on. - */ - protected List fKernelChannels = new ArrayList(); - /** - * The list of UST channel components the command is to be executed on. + * The command execution parameter. */ - protected List fUstChannels = new ArrayList(); + protected Parameter fParam; // ------------------------------------------------------------------------ // Accessors @@ -89,74 +78,86 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + fLock.lock(); + try { + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) { - return false; - } + if (window == null) { + return false; + } - Job job = new Job(Messages.TraceControl_ChangeChannelStateJob) { - @Override - protected IStatus run(IProgressMonitor monitor) { - String errorString = null; - - TraceSessionComponent session = null; - - try { - if (fKernelDomain != null) { - session = (TraceSessionComponent)fKernelDomain.getParent(); - List channelNames = new ArrayList(); - for (Iterator iterator = fKernelChannels.iterator(); iterator.hasNext();) { - // Enable all selected channels which are disabled - TraceChannelComponent channel = (TraceChannelComponent) iterator.next(); - channelNames.add(channel.getName()); - } - - changeState(fKernelDomain, channelNames, monitor); + final Parameter param = new Parameter(fParam); - for (Iterator iterator = fKernelChannels.iterator(); iterator.hasNext();) { - // Enable all selected channels which are disabled - TraceChannelComponent channel = (TraceChannelComponent) iterator.next(); - channel.setState(getNewState()); - } - } + Job job = new Job(Messages.TraceControl_ChangeChannelStateJob) { + @Override + protected IStatus run(IProgressMonitor monitor) { + Exception error = null; - if (fUstDomain != null) { - if (session == null) { - session = (TraceSessionComponent)fUstDomain.getParent(); - } + TraceSessionComponent session = null; + + try { + TraceDomainComponent kernelDomain = param.getKernelDomain(); + List kernelChannels = param.getKernelChannels(); + + if (kernelDomain != null) { + session = (TraceSessionComponent)kernelDomain.getParent(); + List channelNames = new ArrayList(); + for (Iterator iterator = kernelChannels.iterator(); iterator.hasNext();) { + // Enable all selected channels which are disabled + TraceChannelComponent channel = (TraceChannelComponent) iterator.next(); + channelNames.add(channel.getName()); + } + + changeState(kernelDomain, channelNames, monitor); - List channelNames = new ArrayList(); - for (Iterator iterator = fUstChannels.iterator(); iterator.hasNext();) { - // Enable all selected channels which are disabled - TraceChannelComponent channel = (TraceChannelComponent) iterator.next(); - channelNames.add(channel.getName()); + for (Iterator iterator = kernelChannels.iterator(); iterator.hasNext();) { + // Enable all selected channels which are disabled + TraceChannelComponent channel = (TraceChannelComponent) iterator.next(); + channel.setState(getNewState()); + } } - changeState(fUstDomain, channelNames, monitor); - - for (Iterator iterator = fUstChannels.iterator(); iterator.hasNext();) { - // Enable all selected channels which are disabled - TraceChannelComponent channel = (TraceChannelComponent) iterator.next(); - channel.setState(getNewState()); + TraceDomainComponent ustDomain = param.getUstDomain(); + List ustChannels = param.getUstChannels(); + if (ustDomain != null) { + if (session == null) { + session = (TraceSessionComponent)ustDomain.getParent(); + } + + List channelNames = new ArrayList(); + for (Iterator iterator = ustChannels.iterator(); iterator.hasNext();) { + // Enable all selected channels which are disabled + TraceChannelComponent channel = (TraceChannelComponent) iterator.next(); + channelNames.add(channel.getName()); + } + + changeState(ustDomain, channelNames, monitor); + + for (Iterator iterator = ustChannels.iterator(); iterator.hasNext();) { + // Enable all selected channels which are disabled + TraceChannelComponent channel = (TraceChannelComponent) iterator.next(); + channel.setState(getNewState()); + } } + } catch (ExecutionException e) { + error = e; } - } catch (ExecutionException e) { - errorString = e.toString() + "\n"; //$NON-NLS-1$ - } - // In all cases notify listeners - session.fireComponentChanged(session); + // In all cases notify listeners + session.fireComponentChanged(session); - if (errorString != null) { - return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString); - } + if (error != null) { + return new Status(Status.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeChannelStateFailure, error); + } - return Status.OK_STATUS; - } - }; - job.setUser(true); - job.schedule(); + return Status.OK_STATUS; + } + }; + job.setUser(true); + job.schedule(); + } finally { + fLock.unlock(); + } return null; } @@ -167,13 +168,17 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler { */ @Override public boolean isEnabled() { - reset(); // Get workbench page for the Control View IWorkbenchPage page = getWorkbenchPage(); if (page == null) { return false; } + + TraceDomainComponent kernelDomain = null; + TraceDomainComponent ustDomain = null; + List kernelChannels = new ArrayList(); + List ustChannels = new ArrayList(); // Check if one or more session are selected ISelection selection = page.getSelection(ControlView.ID); @@ -193,36 +198,112 @@ abstract public class ChangeChannelStateHandler extends BaseControlViewHandler { // Enable command only for channels of same session if (!sessionName.equals(channel.getSessionName())) { - reset(); + kernelChannels.clear(); + ustChannels.clear(); break; } if ((channel.getState() != getNewState())) { if (channel.isKernel()) { - fKernelChannels.add(channel); - if (fKernelDomain == null) { - fKernelDomain = (TraceDomainComponent) channel.getParent(); + kernelChannels.add(channel); + if (kernelDomain == null) { + kernelDomain = (TraceDomainComponent) channel.getParent(); } } else { - fUstChannels.add(channel); - if (fUstDomain == null) { - fUstDomain = (TraceDomainComponent) channel.getParent(); + ustChannels.add(channel); + if (ustDomain == null) { + ustDomain = (TraceDomainComponent) channel.getParent(); } } } } } } - return fKernelChannels.size() + fUstChannels.size() > 0; + + boolean isEnabled = (!kernelChannels.isEmpty() || !ustChannels.isEmpty()); + fLock.lock(); + try { + if (isEnabled) { + fParam = new Parameter(kernelDomain, ustDomain, kernelChannels, ustChannels); + } + } finally { + fLock.unlock(); + } + + return isEnabled; } - + /** - * Reset members + * Class containing parameter for the command execution. */ - private void reset() { - fKernelDomain = null; - fUstDomain = null; - fKernelChannels.clear(); - fUstChannels.clear(); + static protected class Parameter { + /** + * Kernel domain component reference. + */ + final protected TraceDomainComponent fKernelDomain; + /** + * UST domain component reference. + */ + final protected TraceDomainComponent fUstDomain; + /** + * The list of kernel channel components the command is to be executed on. + */ + final protected List fKernelChannels; + /** + * The list of UST channel components the command is to be executed on. + */ + final protected List fUstChannels; + + /** + * Constructor + * @param kernelDomain - a kernel domain component + * @param ustDomain - a UST domain component + * @param kernelChannels - list of available kernel channels + * @param ustChannels - list of available UST channels + */ + public Parameter(TraceDomainComponent kernelDomain, TraceDomainComponent ustDomain, List kernelChannels, List ustChannels) { + fKernelDomain = kernelDomain; + fUstDomain = ustDomain; + fKernelChannels = new ArrayList(); + fKernelChannels.addAll(kernelChannels); + fUstChannels = new ArrayList(); + fUstChannels.addAll(ustChannels); + } + + /** + * Copy constructor + * @param other a parameter to copy + */ + public Parameter(Parameter other) { + this(other.fKernelDomain, other.fUstDomain, other.fKernelChannels, other.fUstChannels); + } + + /** + * @return the kernel domain component. + */ + public TraceDomainComponent getKernelDomain() { + return fKernelDomain; + } + + /** + * @return the UST domain component. + */ + public TraceDomainComponent getUstDomain() { + return fUstDomain; + } + + /** + * @return the list of kernel channel components. + */ + public List getKernelChannels() { + return fKernelChannels; + } + + /** + * @return the list of UST channel components. + */ + public List getUstChannels() { + return fUstChannels; + } } }