Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9264e956aebf1d7db136310bd774d8c7b81c3d58 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*******************************************************************************
 * Copyright (c) 2011, 2014 Wind River Systems, Inc. and others. All rights reserved.
 * This program and the accompanying materials are made available under the terms
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.tcf.processes.ui.internal.tabbed;

import org.eclipse.core.runtime.Assert;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.services.ISysMonitor;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.runtime.services.interfaces.IUIService;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProvider;
import org.eclipse.tcf.te.tcf.processes.core.model.interfaces.IProcessContextNode;
import org.eclipse.tcf.te.tcf.processes.ui.interfaces.IProcessMonitorUIDelegate;
import org.eclipse.tcf.te.tcf.processes.ui.nls.Messages;
import org.eclipse.tcf.te.tcf.ui.tabbed.BaseTitledSection;
import org.eclipse.tcf.te.ui.swt.SWTControlUtil;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

/**
 * The property section to display the IDs of a process.
 */
public class IDSection extends BaseTitledSection {
	// The selected process node
	/* default */ IProcessContextNode node;
	// The system monitor context for the selected process node.
	/* default */ ISysMonitor.SysMonitorContext context;
	// The text field to display the process id.
	private CLabel pidLabel;
	private Text pidText;
	// The text field to display the parent process id.
	private CLabel ppidLabel;
	private Text ppidText;
	// The  text field to display the internal process id.
	private CLabel ipidLabel;
	private Text ipidText;
	// The text field to display the internal parent process id.
	private CLabel ippidLabel;
	private Text ippidText;

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.views.tabbed.BaseTitledSection#createControls(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
	 */
	@Override
    public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
	    super.createControls(parent, aTabbedPropertySheetPage);

	    pidText = createText(null);
	    pidLabel = createLabel(pidText, Messages.IDSection_ProcessID);

	    ppidText = createText(pidText);
	    ppidLabel = createLabel(ppidText, Messages.IDSection_ParentID);

	    ipidText = createText(ppidText);
	    ipidLabel = createLabel(ipidText, Messages.IDSection_InternalID);

	    ippidText = createText(ipidText);
	    ippidLabel = createLabel(ippidText, Messages.IDSection_InternalPPID);
    }

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.views.tabbed.BaseTitledSection#updateData(org.eclipse.tcf.te.ui.interfaces.IPropertyChangeProvider)
	 */
	@Override
    protected void updateInput(IPeerNodeProvider input) {
        Assert.isTrue(input instanceof IProcessContextNode);
        final IProcessContextNode node = (IProcessContextNode) input;
        this.node = node;

        Runnable runnable = new Runnable() {
			@Override
			public void run() {
				context = node.getSysMonitorContext();
			}
		};

		Assert.isTrue(!Protocol.isDispatchThread());
		Protocol.invokeAndWait(runnable);
    }

	/* (non-Javadoc)
	 * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#refresh()
	 */
	@Override
    public void refresh() {
		IPeerNode peerNode = (IPeerNode)node.getAdapter(IPeerNode.class);
		IUIService service = peerNode != null ? ServiceManager.getInstance().getService(peerNode, IUIService.class) : null;
		IProcessMonitorUIDelegate delegate = service != null ? service.getDelegate(peerNode, IProcessMonitorUIDelegate.class) : null;

		String label = delegate != null ? delegate.getMessage("IDSection_Title") : null; //$NON-NLS-1$
		if (label != null && section != null && !section.isDisposed()) section.setText(label);

		label = delegate != null ? delegate.getMessage("IDSection_ProcessID") : null; //$NON-NLS-1$
		if (label != null) SWTControlUtil.setText(pidLabel, label);
		label = delegate != null ? delegate.getMessage("IDSection_ParentID") : null; //$NON-NLS-1$
		if (label != null) SWTControlUtil.setText(ppidLabel, label);
		label = delegate != null ? delegate.getMessage("IDSection_InternalID") : null; //$NON-NLS-1$
		if (label != null) SWTControlUtil.setText(ipidLabel, label);
		label = delegate != null ? delegate.getMessage("IDSection_InternalPPID") : null; //$NON-NLS-1$
		if (label != null) SWTControlUtil.setText(ippidLabel, label);

		String value = context != null && context.getPID() >= 0 ? Long.toString(context.getPID()) : ""; //$NON-NLS-1$
		String value2 = delegate != null ? delegate.getText(node, "PID", value) : null; //$NON-NLS-1$
		SWTControlUtil.setText(pidText, value2 != null ? value2 : value);

		value = context != null && context.getPPID() >= 0 ? Long.toString(context.getPPID()) : ""; //$NON-NLS-1$
		value2 = delegate != null ? delegate.getText(node, "PPID", value) : null; //$NON-NLS-1$
		SWTControlUtil.setText(ppidText, value2 != null ? value2 : value);

		SWTControlUtil.setText(ipidText, context != null && context.getID() != null ? context.getID() : ""); //$NON-NLS-1$
		SWTControlUtil.setText(ippidText, context != null && context.getParentID() != null ? context.getParentID() : ""); //$NON-NLS-1$

		super.refresh();
    }

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.views.tabbed.BaseTitledSection#getText()
	 */
	@Override
	protected String getText() {
		return Messages.IDSection_Title;
	}
}

Back to the top