001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.preferences;
011:
012: import org.eclipse.core.runtime.Preferences;
013: import org.eclipse.debug.ui.StringVariableSelectionDialog;
014: import org.eclipse.pde.internal.core.ICoreConstants;
015: import org.eclipse.pde.internal.core.PDECore;
016: import org.eclipse.pde.internal.core.itarget.IArgumentsInfo;
017: import org.eclipse.pde.internal.core.itarget.ITarget;
018: import org.eclipse.pde.internal.ui.IHelpContextIds;
019: import org.eclipse.pde.internal.ui.PDEUIMessages;
020: import org.eclipse.swt.SWT;
021: import org.eclipse.swt.events.SelectionEvent;
022: import org.eclipse.swt.events.SelectionListener;
023: import org.eclipse.swt.layout.GridData;
024: import org.eclipse.swt.layout.GridLayout;
025: import org.eclipse.swt.widgets.Button;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.swt.widgets.Control;
028: import org.eclipse.swt.widgets.Group;
029: import org.eclipse.swt.widgets.Label;
030: import org.eclipse.swt.widgets.Text;
031: import org.eclipse.ui.PlatformUI;
032:
033: public class JavaArgumentsTab {
034:
035: private Text fProgramArgs;
036: private Text fVMArgs;
037: private TargetPlatformPreferencePage fPage;
038: private Button fAppendLauncherArgs;
039:
040: public JavaArgumentsTab(TargetPlatformPreferencePage page) {
041: fPage = page;
042: }
043:
044: public Control createControl(Composite parent) {
045: Composite container = new Composite(parent, SWT.NONE);
046: container.setLayout(new GridLayout());
047:
048: Label description = new Label(container, SWT.WRAP);
049: description.setText(PDEUIMessages.JavaArgumentsTab_description);
050: GridData gd = new GridData();
051: gd.widthHint = 450;
052: description.setLayoutData(gd);
053:
054: Group programGroup = new Group(container, SWT.NONE);
055: programGroup.setLayout(new GridLayout());
056: programGroup.setLayoutData(new GridData(
057: GridData.FILL_HORIZONTAL));
058: programGroup
059: .setText(PDEUIMessages.JavaArgumentsTab_progamArgsGroup);
060:
061: fProgramArgs = new Text(programGroup, SWT.MULTI | SWT.WRAP
062: | SWT.BORDER | SWT.V_SCROLL);
063: gd = new GridData(GridData.FILL_BOTH);
064: gd.widthHint = 450;
065: gd.heightHint = 60;
066: fProgramArgs.setLayoutData(gd);
067:
068: Button programVars = new Button(programGroup, SWT.NONE);
069: programVars.setLayoutData(new GridData(
070: GridData.HORIZONTAL_ALIGN_END));
071: programVars
072: .setText(PDEUIMessages.JavaArgumentsTab_programVariables);
073: programVars.addSelectionListener(getListener(fProgramArgs));
074:
075: Group vmGroup = new Group(container, SWT.NONE);
076: vmGroup.setLayout(new GridLayout(2, false));
077: vmGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
078: vmGroup.setText(PDEUIMessages.JavaArgumentsTab_vmArgsGroup);
079:
080: fVMArgs = new Text(vmGroup, SWT.MULTI | SWT.WRAP | SWT.BORDER
081: | SWT.V_SCROLL);
082: gd = new GridData(GridData.FILL_BOTH);
083: gd.widthHint = 450;
084: gd.heightHint = 60;
085: gd.horizontalSpan = 2;
086: fVMArgs.setLayoutData(gd);
087:
088: fAppendLauncherArgs = new Button(vmGroup, SWT.CHECK);
089: fAppendLauncherArgs
090: .setText(PDEUIMessages.JavaArgumentsTab_appendLauncherIni);
091:
092: Button vmVars = new Button(vmGroup, SWT.NONE);
093: vmVars
094: .setLayoutData(new GridData(
095: GridData.HORIZONTAL_ALIGN_END));
096: vmVars.setText(PDEUIMessages.JavaArgumentsTab_vmVariables);
097: vmVars.addSelectionListener(getListener(fVMArgs));
098:
099: initialize();
100: PlatformUI.getWorkbench().getHelpSystem().setHelp(container,
101: IHelpContextIds.LAUNCHING_ARGS_PREFERENCE_PAGE);
102: return container;
103: }
104:
105: protected SelectionListener getListener(final Text textControl) {
106: return new SelectionListener() {
107: public void widgetSelected(SelectionEvent e) {
108: StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(
109: fPage.getShell());
110: dialog.open();
111: String variable = dialog.getVariableExpression();
112: if (variable != null) {
113: textControl.insert(variable);
114: }
115: }
116:
117: public void widgetDefaultSelected(SelectionEvent e) {
118: }
119: };
120: }
121:
122: protected void initialize() {
123: Preferences preferences = PDECore.getDefault()
124: .getPluginPreferences();
125: fProgramArgs.setText(preferences
126: .getString(ICoreConstants.PROGRAM_ARGS));
127: fVMArgs.setText(preferences.getString(ICoreConstants.VM_ARGS));
128: fAppendLauncherArgs.setSelection(preferences
129: .getBoolean(ICoreConstants.VM_LAUNCHER_INI));
130: }
131:
132: public void performOk() {
133: Preferences preferences = PDECore.getDefault()
134: .getPluginPreferences();
135: preferences.setValue(ICoreConstants.PROGRAM_ARGS, fProgramArgs
136: .getText());
137: preferences.setValue(ICoreConstants.VM_ARGS, fVMArgs.getText());
138: preferences.setValue(ICoreConstants.VM_LAUNCHER_INI,
139: fAppendLauncherArgs.getSelection());
140: }
141:
142: protected void performDefaults() {
143: fProgramArgs.setText(""); //$NON-NLS-1$
144: fVMArgs.setText(""); //$NON-NLS-1$
145: }
146:
147: protected void loadTargetProfile(ITarget target) {
148: IArgumentsInfo info = target.getArguments();
149: if (info == null) {
150: fProgramArgs.setText(""); //$NON-NLS-1$
151: fVMArgs.setText(""); //$NON-NLS-1$
152: return;
153: }
154: String progArgs = (info.getProgramArguments() == null) ? "" : info.getProgramArguments(); //$NON-NLS-1$
155: fProgramArgs.setText(progArgs);
156: String vmArgs = (info.getVMArguments() == null) ? "" : info.getVMArguments(); //$NON-NLS-1$
157: fVMArgs.setText(vmArgs);
158: }
159: }
|