1 11 package org.eclipse.debug.internal.ui.preferences; 12 13 14 import java.util.regex.Matcher ; 15 import java.util.regex.Pattern ; 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 38 public ProcessPropertyPage() { 39 super(); 40 } 41 42 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 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 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 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 commandLineText = getCommandLineText(proc); 79 if (commandLineText != null) { 80 text.setText(commandLineText); 81 } 82 83 setTitle(DebugPreferencesMessages.ProcessPropertyPage_2); 84 return parent; 85 } 86 87 93 private IProcess getProcess() { 94 IProcess proc = null; 95 Object 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 112 private String getPathText(IProcess proc) { 113 String text = DebugPreferencesMessages.ProcessPropertyPage_3; 114 if(proc != null) { 115 String tmp = proc.getLabel(); 116 int idx = tmp.lastIndexOf("("); if(idx < 0) { 118 idx = tmp.length(); 119 } 120 text = tmp.substring(0, idx); 121 } 122 return text; 123 } 124 125 134 private String getTimeText(IProcess proc) { 135 String text = DebugPreferencesMessages.ProcessPropertyPage_4; 136 if(proc != null) { 137 Pattern pattern = Pattern.compile("\\(.*\\)"); Matcher matcher = pattern.matcher(proc.getLabel()); 139 if(matcher.find()) { 140 text = matcher.group(0); 141 } 142 } 143 return text; 144 } 145 146 153 private String getCommandLineText(IProcess proc) { 154 String cmdline = DebugPreferencesMessages.ProcessPropertyPage_5; 155 if(proc != null) { 156 cmdline = proc.getAttribute(IProcess.ATTR_CMDLINE); 157 } 158 return cmdline; 159 } 160 161 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 |