Example usage for org.eclipse.jface.viewers StructuredSelection iterator

List of usage examples for org.eclipse.jface.viewers StructuredSelection iterator

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection iterator.

Prototype

@Override
    public Iterator iterator() 

Source Link

Usage

From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.AddContextOnEventHandler.java

License:Open Source License

@Override
public boolean isEnabled() {
    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }/*ww w  . jav a  2s  . c o  m*/

    TraceEventComponent event = null;
    TraceSessionComponent session = null;
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
            Object element = iterator.next();
            if (element instanceof TraceEventComponent) {
                // Add only if corresponding TraceSessionComponents is inactive and not destroyed
                TraceEventComponent tmpEvent = (TraceEventComponent) element;
                session = tmpEvent.getSession();
                if (session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
                    event = tmpEvent;
                }
            }
        }
    }

    boolean isEnabled = (event != null);
    fLock.lock();
    try {
        fParam = null;
        if (isEnabled) {
            fParam = new EventCommandParameter(session, event);
        }
    } finally {
        fLock.unlock();
    }
    return isEnabled;
}

From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.AssignEventHandler.java

License:Open Source License

@Override
public boolean isEnabled() {
    ArrayList<BaseEventComponent> events = new ArrayList<>();
    TraceSessionComponent[] sessions = null;
    Boolean isKernel = null;/*from www . j a  v  a  2 s . c  o m*/

    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }

    // Check if one or more session are selected
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {

        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
            Object element = iterator.next();
            if (element instanceof BaseEventComponent) {
                BaseEventComponent event = (BaseEventComponent) element;
                ITraceControlComponent provider = event.getParent();

                // check for kernel or UST provider
                boolean temp = false;
                if (provider instanceof KernelProviderComponent) {
                    temp = true;
                } else if (provider instanceof UstProviderComponent) {
                    temp = false;
                } else {
                    return false;
                }
                if (isKernel == null) {
                    isKernel = Boolean.valueOf(temp);
                } else {
                    // don't mix events from Kernel and UST provider
                    if (isKernel.booleanValue() != temp) {
                        return false;
                    }
                }

                // Add BaseEventComponents
                events.add(event);

                if (sessions == null) {
                    TargetNodeComponent root = (TargetNodeComponent) event.getParent().getParent().getParent();
                    sessions = root.getSessions();
                }
            }
        }
    }

    boolean isEnabled = ((!events.isEmpty()) && (sessions != null) && (sessions.length > 0));

    // To avoid compiler warnings check for null even if isKernel is always not null when used below
    if (isKernel == null) {
        return false;
    }

    fLock.lock();
    try {
        fParam = null;
        if (isEnabled) {
            fParam = new Parameter(sessions, events, isKernel);
        }
    } finally {
        fLock.unlock();
    }
    return isEnabled;
}

From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.CalibrateHandler.java

License:Open Source License

@Override
public boolean isEnabled() {

    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }/*from  ww  w. j  a va 2  s. c  om*/

    TraceDomainComponent domain = null;
    TraceSessionComponent session = null;

    // Check if one domain is selected
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
            Object element = iterator.next();
            if (element instanceof TraceDomainComponent) {
                TraceDomainComponent tmpDomain = (TraceDomainComponent) element;
                session = (TraceSessionComponent) tmpDomain.getParent();

                // Add only TraceDomainComponent whose TraceSessionComponent parent is not destroyed
                if ((!session.isDestroyed())) {
                    domain = tmpDomain;
                }
            }
        }
    }

    boolean isEnabled = domain != null;

    fLock.lock();
    try {
        fParam = null;
        if (isEnabled) {
            fParam = new DomainCommandParameter(session, domain);
        }
    } finally {
        fLock.unlock();
    }

    return isEnabled;
}

From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.ChangeChannelStateHandler.java

License:Open Source License

@Override
public boolean isEnabled() {

    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }/*  w w  w  .j  a v a  2 s  . co m*/

    TraceDomainComponent kernelDomain = null;
    TraceDomainComponent ustDomain = null;
    List<TraceChannelComponent> kernelChannels = new ArrayList<>();
    List<TraceChannelComponent> ustChannels = new ArrayList<>();

    // Check if one or more session are selected
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        String sessionName = null;
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
            Object element = iterator.next();

            if (element instanceof TraceChannelComponent) {

                // Add only TraceChannelComponents that are disabled
                TraceChannelComponent channel = (TraceChannelComponent) element;
                if (sessionName == null) {
                    sessionName = String.valueOf(channel.getSessionName());
                }

                // Enable command only for channels of same session
                if (!sessionName.equals(channel.getSessionName())) {
                    kernelChannels.clear();
                    ustChannels.clear();
                    break;
                }

                if ((channel.getState() != getNewState())) {
                    if (channel.isKernel()) {
                        kernelChannels.add(channel);
                        if (kernelDomain == null) {
                            kernelDomain = (TraceDomainComponent) channel.getParent();
                        }
                    } else {
                        ustChannels.add(channel);
                        if (ustDomain == null) {
                            ustDomain = (TraceDomainComponent) channel.getParent();
                        }
                    }
                }
            }
        }
    }

    boolean isEnabled = (!kernelChannels.isEmpty() || !ustChannels.isEmpty());
    fLock.lock();
    try {
        if (isEnabled) {
            fParam = new Parameter(kernelDomain, ustDomain, kernelChannels, ustChannels);
        }
    } finally {
        fLock.unlock();
    }

    return isEnabled;
}

From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.ChangeEventStateHandler.java

License:Open Source License

@Override
public boolean isEnabled() {
    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }// w ww  . j ava 2 s . c om

    // Check if one or more session are selected
    ISelection selection = page.getSelection(ControlView.ID);

    TraceChannelComponent channel = null;
    List<TraceEventComponent> events = new ArrayList<>();

    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        String sessionName = null;
        String channelName = null;

        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
            Object element = iterator.next();

            if (element instanceof TraceEventComponent) {

                TraceEventComponent event = (TraceEventComponent) element;
                if (sessionName == null) {
                    sessionName = String.valueOf(event.getSessionName());
                }

                if (channel == null) {
                    channel = (TraceChannelComponent) event.getParent();
                }

                if (channelName == null) {
                    channelName = event.getChannelName();
                }

                // Enable command only for events of same session, same channel and domain
                if ((!sessionName.equals(event.getSessionName()))
                        || (!channelName.equals(event.getChannelName()))
                        || (channel.isKernel() != event.isKernel())) {
                    events.clear();
                    break;
                }

                if ((event.getState() != getNewState())) {
                    events.add(event);
                }
            }
        }
    }
    boolean isEnabled = !events.isEmpty();

    fLock.lock();
    try {
        fParam = null;
        if (isEnabled) {
            fParam = new Parameter(channel, events);
        }
    } finally {
        fLock.unlock();
    }
    return isEnabled;
}

From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.ChangeSessionStateHandler.java

License:Open Source License

@Override
public boolean isEnabled() {
    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }//from  w w  w  .  j  a  v  a  2  s  . c  om

    List<TraceSessionComponent> sessions = new ArrayList<>(0);

    // Check if one or more session are selected
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
            Object element = iterator.next();
            if (element instanceof TraceSessionComponent) {
                // Add only TraceSessionComponents that are inactive and not destroyed
                TraceSessionComponent session = (TraceSessionComponent) element;
                if ((session.getSessionState() != getNewState()) && (!session.isDestroyed())) {
                    sessions.add(session);
                }
            }
        }
    }
    boolean isEnabled = !sessions.isEmpty();
    fLock.lock();
    try {
        fSessions = null;
        if (isEnabled) {
            fSessions = sessions;
        }
    } finally {
        fLock.unlock();
    }
    return isEnabled;
}

From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.DestroySessionHandler.java

License:Open Source License

@Override
public boolean isEnabled() {
    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }//from w w w.j  ava 2  s  .  co  m
    fSessions.clear();

    // Check if one or more session are selected
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
            Object element = iterator.next();
            if (element instanceof TraceSessionComponent) {
                // Add only TraceSessionComponents that are inactive and not destroyed
                TraceSessionComponent session = (TraceSessionComponent) element;
                if ((session.getSessionState() == TraceSessionState.INACTIVE) && (!session.isDestroyed())) {
                    fSessions.add((TraceSessionComponent) element);
                }
            }
        }
    }
    return !fSessions.isEmpty();
}

From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.EnableChannelOnSessionHandler.java

License:Open Source License

@Override
public boolean isEnabled() {
    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }//from   w ww. ja va 2  s .c  o  m

    TraceSessionComponent session = null;
    // Check if one session is selected
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
            Object element = iterator.next();
            if (element instanceof TraceSessionComponent) {
                // Add only TraceSessionComponents that are inactive and not destroyed
                TraceSessionComponent tmpSession = (TraceSessionComponent) element;
                if ((tmpSession.getSessionState() == TraceSessionState.INACTIVE)
                        && (!tmpSession.isDestroyed())) {
                    session = tmpSession;
                }
            }
        }
    }
    boolean isEnabled = session != null;

    fLock.lock();
    try {
        fParam = null;
        if (isEnabled) {
            fParam = new CommandParameter(session);
        }
    } finally {
        fLock.unlock();
    }

    return isEnabled;
}

From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.EnableEventOnChannelHandler.java

License:Open Source License

@Override
public boolean isEnabled() {
    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }//from   ww  w. j  a  v  a 2s.  c o  m

    TraceChannelComponent channel = null;
    TraceSessionComponent session = null;
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
            Object element = iterator.next();
            if (element instanceof TraceChannelComponent) {
                // Add only if corresponding TraceSessionComponents is inactive and not destroyed
                TraceChannelComponent tmpChannel = (TraceChannelComponent) element;
                session = tmpChannel.getSession();
                if (!session.isDestroyed()) {
                    channel = tmpChannel;
                }
            }
        }
    }

    boolean isEnabled = (channel != null);
    fLock.lock();
    try {
        fParam = null;
        if (isEnabled) {
            fParam = new ChannelCommandParameter(session, channel);
        }
    } finally {
        fLock.unlock();
    }
    return isEnabled;
}

From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.EnableEventOnDomainHandler.java

License:Open Source License

@Override
public boolean isEnabled() {
    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }/*w w w. j av  a 2  s. c om*/

    TraceDomainComponent domain = null;
    TraceSessionComponent session = null;
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
            Object element = iterator.next();
            if (element instanceof TraceDomainComponent) {
                // Add only if corresponding TraceSessionComponents is inactive and not destroyed
                TraceDomainComponent tmpDomain = (TraceDomainComponent) element;
                session = tmpDomain.getSession();
                if (session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
                    domain = tmpDomain;
                }
            }
        }
    }

    boolean isEnabled = (domain != null);
    fLock.lock();
    try {
        fParam = null;
        if (isEnabled) {
            fParam = new DomainCommandParameter(session, domain);
        }
    } finally {
        fLock.unlock();
    }
    return isEnabled;
}