1 11 package org.eclipse.pde.internal.ui.preferences; 12 13 import org.eclipse.core.runtime.Preferences; 14 import org.eclipse.debug.ui.StringVariableSelectionDialog; 15 import org.eclipse.pde.internal.core.ICoreConstants; 16 import org.eclipse.pde.internal.core.PDECore; 17 import org.eclipse.pde.internal.core.itarget.IArgumentsInfo; 18 import org.eclipse.pde.internal.core.itarget.ITarget; 19 import org.eclipse.pde.internal.ui.IHelpContextIds; 20 import org.eclipse.pde.internal.ui.PDEUIMessages; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.events.SelectionEvent; 23 import org.eclipse.swt.events.SelectionListener; 24 import org.eclipse.swt.layout.GridData; 25 import org.eclipse.swt.layout.GridLayout; 26 import org.eclipse.swt.widgets.Button; 27 import org.eclipse.swt.widgets.Composite; 28 import org.eclipse.swt.widgets.Control; 29 import org.eclipse.swt.widgets.Group; 30 import org.eclipse.swt.widgets.Label; 31 import org.eclipse.swt.widgets.Text; 32 import org.eclipse.ui.PlatformUI; 33 34 public class JavaArgumentsTab { 35 36 private Text fProgramArgs; 37 private Text fVMArgs; 38 private TargetPlatformPreferencePage fPage; 39 private Button fAppendLauncherArgs; 40 41 public JavaArgumentsTab(TargetPlatformPreferencePage page) { 42 fPage = page; 43 } 44 45 public Control createControl(Composite parent) { 46 Composite container = new Composite(parent, SWT.NONE); 47 container.setLayout(new GridLayout()); 48 49 Label description = new Label(container, SWT.WRAP); 50 description.setText(PDEUIMessages.JavaArgumentsTab_description); 51 GridData gd = new GridData(); 52 gd.widthHint = 450; 53 description.setLayoutData(gd); 54 55 Group programGroup = new Group(container, SWT.NONE); 56 programGroup.setLayout(new GridLayout()); 57 programGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 58 programGroup.setText(PDEUIMessages.JavaArgumentsTab_progamArgsGroup); 59 60 fProgramArgs = new Text(programGroup, SWT.MULTI | SWT.WRAP| SWT.BORDER | SWT.V_SCROLL); 61 gd = new GridData(GridData.FILL_BOTH); 62 gd.widthHint = 450; 63 gd.heightHint = 60; 64 fProgramArgs.setLayoutData(gd); 65 66 Button programVars = new Button(programGroup, SWT.NONE); 67 programVars.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); 68 programVars.setText(PDEUIMessages.JavaArgumentsTab_programVariables); 69 programVars.addSelectionListener(getListener(fProgramArgs)); 70 71 Group vmGroup = new Group(container, SWT.NONE); 72 vmGroup.setLayout(new GridLayout(2, false)); 73 vmGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 74 vmGroup.setText(PDEUIMessages.JavaArgumentsTab_vmArgsGroup); 75 76 fVMArgs = new Text(vmGroup, SWT.MULTI | SWT.WRAP| SWT.BORDER | SWT.V_SCROLL); 77 gd = new GridData(GridData.FILL_BOTH); 78 gd.widthHint = 450; 79 gd.heightHint = 60; 80 gd.horizontalSpan = 2; 81 fVMArgs.setLayoutData(gd); 82 83 fAppendLauncherArgs = new Button(vmGroup, SWT.CHECK); 84 fAppendLauncherArgs.setText(PDEUIMessages.JavaArgumentsTab_appendLauncherIni); 85 86 Button vmVars = new Button(vmGroup, SWT.NONE); 87 vmVars.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); 88 vmVars.setText(PDEUIMessages.JavaArgumentsTab_vmVariables); 89 vmVars.addSelectionListener(getListener(fVMArgs)); 90 91 initialize(); 92 PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.LAUNCHING_ARGS_PREFERENCE_PAGE); 93 return container; 94 } 95 96 protected SelectionListener getListener(final Text textControl) { 97 return new SelectionListener() { 98 public void widgetSelected(SelectionEvent e) { 99 StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(fPage.getShell()); 100 dialog.open(); 101 String variable = dialog.getVariableExpression(); 102 if (variable != null) { 103 textControl.insert(variable); 104 } 105 } 106 107 public void widgetDefaultSelected(SelectionEvent e) { 108 } 109 }; 110 } 111 112 protected void initialize() { 113 Preferences preferences = PDECore.getDefault().getPluginPreferences(); 114 fProgramArgs.setText(preferences.getString(ICoreConstants.PROGRAM_ARGS)); 115 fVMArgs.setText(preferences.getString(ICoreConstants.VM_ARGS)); 116 fAppendLauncherArgs.setSelection(preferences.getBoolean(ICoreConstants.VM_LAUNCHER_INI)); 117 } 118 119 public void performOk() { 120 Preferences preferences = PDECore.getDefault().getPluginPreferences(); 121 preferences.setValue(ICoreConstants.PROGRAM_ARGS, fProgramArgs.getText()); 122 preferences.setValue(ICoreConstants.VM_ARGS, fVMArgs.getText()); 123 preferences.setValue(ICoreConstants.VM_LAUNCHER_INI, fAppendLauncherArgs.getSelection()); 124 } 125 126 protected void performDefaults() { 127 fProgramArgs.setText(""); fVMArgs.setText(""); } 130 131 protected void loadTargetProfile(ITarget target) { 132 IArgumentsInfo info = target.getArguments(); 133 if (info == null) { 134 fProgramArgs.setText(""); fVMArgs.setText(""); return; 137 } 138 String progArgs = (info.getProgramArguments() == null) ? "" : info.getProgramArguments(); fProgramArgs.setText(progArgs); 140 String vmArgs = (info.getVMArguments() == null) ? "" : info.getVMArguments(); fVMArgs.setText(vmArgs); 142 } 143 } 144 | Popular Tags |