~ubuntu-branches/ubuntu/wily/eclipse-linuxtools/wily

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/RefreshHandler.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**********************************************************************
2
 
 * Copyright (c) 2012, 2013 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
 
 *   Bernd Hufmann - Initial API and implementation
11
 
 **********************************************************************/
12
 
package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
13
 
 
14
 
import java.util.Iterator;
15
 
 
16
 
import org.eclipse.core.commands.ExecutionEvent;
17
 
import org.eclipse.core.commands.ExecutionException;
18
 
import org.eclipse.jface.viewers.ISelection;
19
 
import org.eclipse.jface.viewers.StructuredSelection;
20
 
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState;
21
 
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
22
 
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
23
 
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent;
24
 
import org.eclipse.ui.IWorkbenchPage;
25
 
 
26
 
/**
27
 
 * <p>
28
 
 * Command handler implementation to refresh node configuration.
29
 
 * </p>
30
 
 *
31
 
 * @author Bernd Hufmann
32
 
 */
33
 
public class RefreshHandler extends BaseControlViewHandler {
34
 
 
35
 
    // ------------------------------------------------------------------------
36
 
    // Attributes
37
 
    // ------------------------------------------------------------------------
38
 
 
39
 
    /**
40
 
     * The node component reference.
41
 
     */
42
 
    private TargetNodeComponent fNode;
43
 
 
44
 
    // ------------------------------------------------------------------------
45
 
    // Operations
46
 
    // ------------------------------------------------------------------------
47
 
 
48
 
    @Override
49
 
    public Object execute(ExecutionEvent event) throws ExecutionException {
50
 
        fLock.lock();
51
 
        try {
52
 
            fNode.refresh();
53
 
        } finally {
54
 
            fLock.unlock();
55
 
        }
56
 
        return null;
57
 
    }
58
 
 
59
 
    @Override
60
 
    public boolean isEnabled() {
61
 
 
62
 
        // Get workbench page for the Control View
63
 
        IWorkbenchPage page = getWorkbenchPage();
64
 
        if (page == null) {
65
 
            return false;
66
 
        }
67
 
 
68
 
        TargetNodeComponent node = null;
69
 
        // Check if one or more session are selected
70
 
        ISelection selection = page.getSelection(ControlView.ID);
71
 
        if (selection instanceof StructuredSelection) {
72
 
 
73
 
            StructuredSelection structered = ((StructuredSelection) selection);
74
 
            for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
75
 
                Object element = iterator.next();
76
 
                if (element instanceof TraceControlComponent) {
77
 
                    TraceControlComponent component = (TraceControlComponent) element;
78
 
                    boolean isConnected = component.getTargetNodeState() == TargetNodeState.CONNECTED;
79
 
                    if (isConnected) {
80
 
                        while ((component != null) && component.getClass() != TargetNodeComponent.class) {
81
 
                            component = (TraceControlComponent) component.getParent();
82
 
                        }
83
 
                        if (component != null) {
84
 
                            node = (TargetNodeComponent) component;
85
 
                        }
86
 
                    }
87
 
                }
88
 
            }
89
 
        }
90
 
 
91
 
        boolean isEnabled = node != null;
92
 
 
93
 
        fLock.lock();
94
 
        try {
95
 
            fNode = null;
96
 
            if (isEnabled) {
97
 
                fNode = node;
98
 
            }
99
 
        } finally {
100
 
            fLock.unlock();
101
 
        }
102
 
 
103
 
        return isEnabled;
104
 
    }
105
 
}