KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > preferences > ProcessPropertyPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.preferences;
12
13
14 import java.util.regex.Matcher JavaDoc;
15 import java.util.regex.Pattern JavaDoc;
16
17 import org.eclipse.debug.core.model.IDebugElement;
18 import org.eclipse.debug.core.model.IProcess;
19 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
20 import org.eclipse.debug.internal.ui.SWTFactory;
21 import org.eclipse.jface.resource.JFaceResources;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.graphics.Font;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Text;
28 import org.eclipse.ui.PlatformUI;
29 import org.eclipse.ui.dialogs.PropertyPage;
30
31 public class ProcessPropertyPage extends PropertyPage {
32
33     private static Font fHeadingFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT);
34     
35     /**
36      * Constructor for ProcessPropertyPage
37      */

38     public ProcessPropertyPage() {
39         super();
40     }
41
42     /* (non-Javadoc)
43      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
44      */

45     protected Control createContents(Composite ancestor) {
46         noDefaultAndApplyButton();
47         Composite parent = SWTFactory.createComposite(ancestor, ancestor.getFont(), 1, 1, GridData.FILL_BOTH);
48         
49         IProcess proc = getProcess();
50         
51     //create the process time section
52
SWTFactory.createLabel(parent, DebugPreferencesMessages.ProcessPropertyPage_0, fHeadingFont, 1);
53         Text text = SWTFactory.createText(parent, SWT.READ_ONLY, 1);
54         ((GridData)text.getLayoutData()).horizontalIndent = 10;
55         PlatformUI.getWorkbench().getHelpSystem().setHelp(text, IDebugHelpContextIds.PROCESS_PAGE_RUN_AT);
56         text.setText(getTimeText(proc));
57         text.setBackground(parent.getBackground());
58         SWTFactory.createVerticalSpacer(parent, 2);
59         
60     //create the path name section
61
SWTFactory.createLabel(parent, DebugPreferencesMessages.ProcessPropertyPage_1, fHeadingFont, 1);
62         text = SWTFactory.createText(parent, SWT.WRAP | SWT.READ_ONLY, 1);
63         ((GridData)text.getLayoutData()).horizontalIndent = 10;
64         text.setText(getPathText(proc));
65         text.setBackground(parent.getBackground());
66         SWTFactory.createVerticalSpacer(parent, 2);
67         
68     //create commandline section
69
SWTFactory.createLabel(parent, DebugPreferencesMessages.ProcessPropertyPage_Command_Line__1, fHeadingFont, 1);
70         text = SWTFactory.createText(parent,
71                 SWT.WRAP | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL,
72                 1,
73                 convertWidthInCharsToPixels(80),
74                 convertHeightInCharsToPixels(15),
75                 GridData.FILL_BOTH);
76         text.setBackground(parent.getBackground());
77         ((GridData)text.getLayoutData()).horizontalIndent = 10;
78         String JavaDoc commandLineText = getCommandLineText(proc);
79         if (commandLineText != null) {
80             text.setText(commandLineText);
81         }
82         
83         setTitle(DebugPreferencesMessages.ProcessPropertyPage_2);
84         return parent;
85     }
86     
87     /**
88      * Gets the process from the selected element
89      * @return the process or null if the element is not a process
90      *
91      * @since 3.2
92      */

93     private IProcess getProcess() {
94         IProcess proc = null;
95         Object JavaDoc obj = getElement();
96         if (obj instanceof IDebugElement) {
97             obj = ((IDebugElement)obj).getDebugTarget().getProcess();
98         }
99         if (obj instanceof IProcess) {
100             proc = ((IProcess)obj);
101         }
102         return proc;
103     }
104     
105     /**
106      * returns the path text
107      * @param proc the process to extract the path text from
108      * @return the path text or a message indicating no path text available
109      *
110      * @since 3.2
111      */

112     private String JavaDoc getPathText(IProcess proc) {
113         String JavaDoc text = DebugPreferencesMessages.ProcessPropertyPage_3;
114         if(proc != null) {
115             String JavaDoc tmp = proc.getLabel();
116             int idx = tmp.lastIndexOf("("); //$NON-NLS-1$
117
if(idx < 0) {
118                 idx = tmp.length();
119             }
120             text = tmp.substring(0, idx);
121         }
122         return text;
123     }
124     
125     /**
126      * gets the pattern of text from the process label specified by regex
127      * @param proc the process to compile the regex against
128      * @param deftext the default text to return if the process is null
129      * @param regex the regex to match in the process label
130      * @return the regex matched text or the default supplied text if the process is null
131      *
132      * @since 3.2
133      */

134     private String JavaDoc getTimeText(IProcess proc) {
135         String JavaDoc text = DebugPreferencesMessages.ProcessPropertyPage_4;
136         if(proc != null) {
137             Pattern JavaDoc pattern = Pattern.compile("\\(.*\\)"); //$NON-NLS-1$
138
Matcher JavaDoc matcher = pattern.matcher(proc.getLabel());
139             if(matcher.find()) {
140                 text = matcher.group(0);
141             }
142         }
143         return text;
144     }
145     
146     /**
147      * Initializes the text to be displayed in the commandline text widget
148      * @param proc the process to compile the label fragment from
149      * @return the commandline text or the empty string
150      *
151      * @since 3.2
152      */

153     private String JavaDoc getCommandLineText(IProcess proc) {
154         String JavaDoc cmdline = DebugPreferencesMessages.ProcessPropertyPage_5;
155         if(proc != null) {
156             cmdline = proc.getAttribute(IProcess.ATTR_CMDLINE);
157         }
158         return cmdline;
159     }
160     
161     /* (non-Javadoc)
162      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
163      */

164     public void createControl(Composite parent) {
165         super.createControl(parent);
166         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.PROCESS_PROPERTY_PAGE);
167     }
168
169 }
170
Popular Tags