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.launcher;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.debug.core.ILaunchConfiguration;
014: import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
015: import org.eclipse.pde.internal.ui.IPDEUIConstants;
016: import org.eclipse.pde.internal.ui.PDEUIMessages;
017: import org.eclipse.pde.ui.launcher.AbstractLauncherTab;
018: import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
019: import org.eclipse.swt.SWT;
020: import org.eclipse.swt.events.SelectionAdapter;
021: import org.eclipse.swt.events.SelectionEvent;
022: import org.eclipse.swt.layout.GridData;
023: import org.eclipse.swt.layout.GridLayout;
024: import org.eclipse.swt.widgets.Button;
025: import org.eclipse.swt.widgets.Composite;
026: import org.eclipse.swt.widgets.Group;
027:
028: public class WorkspaceDataBlock extends BaseBlock {
029:
030: private Button fClearWorkspaceCheck;
031: private Button fAskClearCheck;
032: private Button fClearWorkspaceRadio;
033: private Button fClearWorkspaceLogRadio;
034:
035: public WorkspaceDataBlock(AbstractLauncherTab tab) {
036: super (tab);
037: }
038:
039: public void createControl(Composite parent) {
040: Group group = new Group(parent, SWT.NONE);
041: group.setText(PDEUIMessages.WorkspaceDataBlock_workspace);
042: GridLayout layout = new GridLayout();
043: layout.numColumns = 2;
044: group.setLayout(layout);
045: group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
046:
047: createText(group, PDEUIMessages.WorkspaceDataBlock_location, 0);
048:
049: Composite buttons = new Composite(group, SWT.NONE);
050: layout = new GridLayout(7, false);
051: layout.marginHeight = layout.marginWidth = 0;
052: buttons.setLayout(layout);
053: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
054: gd.horizontalSpan = 2;
055: buttons.setLayoutData(gd);
056:
057: fClearWorkspaceCheck = new Button(buttons, SWT.CHECK);
058: fClearWorkspaceCheck
059: .setText(PDEUIMessages.WorkspaceDataBlock_clear);
060: fClearWorkspaceCheck.setLayoutData(new GridData(
061: GridData.HORIZONTAL_ALIGN_BEGINNING));
062: fClearWorkspaceCheck
063: .addSelectionListener(new SelectionAdapter() {
064: public void widgetSelected(SelectionEvent e) {
065: fAskClearCheck.setEnabled(fClearWorkspaceCheck
066: .getSelection());
067: fClearWorkspaceRadio
068: .setEnabled(fClearWorkspaceCheck
069: .getSelection());
070: fClearWorkspaceLogRadio
071: .setEnabled(fClearWorkspaceCheck
072: .getSelection());
073: fTab.updateLaunchConfigurationDialog();
074: }
075: });
076:
077: fClearWorkspaceRadio = new Button(buttons, SWT.RADIO);
078: fClearWorkspaceRadio
079: .setText(PDEUIMessages.WorkspaceDataBlock_clearWorkspace);
080: fClearWorkspaceRadio.setLayoutData(new GridData(
081: GridData.HORIZONTAL_ALIGN_BEGINNING));
082: fClearWorkspaceRadio
083: .addSelectionListener(new SelectionAdapter() {
084: public void widgetSelected(SelectionEvent e) {
085: fTab.updateLaunchConfigurationDialog();
086: }
087: });
088: fClearWorkspaceLogRadio = new Button(buttons, SWT.RADIO);
089: fClearWorkspaceLogRadio
090: .setText(PDEUIMessages.WorkspaceDataBlock_clearLog);
091: fClearWorkspaceLogRadio.setLayoutData(new GridData(
092: GridData.FILL_HORIZONTAL));
093: fClearWorkspaceLogRadio
094: .addSelectionListener(new SelectionAdapter() {
095: public void widgetSelected(SelectionEvent e) {
096: fTab.updateLaunchConfigurationDialog();
097: }
098: });
099:
100: createButtons(buttons, new String[] {
101: PDEUIMessages.BaseBlock_workspace,
102: PDEUIMessages.BaseBlock_filesystem,
103: PDEUIMessages.BaseBlock_variables });
104:
105: fAskClearCheck = new Button(group, SWT.CHECK);
106: fAskClearCheck
107: .setText(PDEUIMessages.WorkspaceDataBlock_askClear);
108: gd = new GridData();
109: gd.horizontalSpan = 2;
110: fAskClearCheck.setLayoutData(gd);
111: fAskClearCheck.addSelectionListener(fListener);
112: }
113:
114: public void performApply(ILaunchConfigurationWorkingCopy config) {
115: config.setAttribute(IPDELauncherConstants.LOCATION,
116: getLocation());
117: config.setAttribute(IPDELauncherConstants.DOCLEAR,
118: fClearWorkspaceCheck.getSelection());
119: config.setAttribute(IPDELauncherConstants.ASKCLEAR,
120: fAskClearCheck.getSelection());
121: config.setAttribute(IPDEUIConstants.DOCLEARLOG,
122: fClearWorkspaceLogRadio.getSelection());
123: }
124:
125: public void initializeFrom(ILaunchConfiguration configuration)
126: throws CoreException {
127: fLocationText.setText(configuration.getAttribute(
128: IPDELauncherConstants.LOCATION, LaunchArgumentsHelper
129: .getDefaultWorkspaceLocation(configuration
130: .getName())));
131: fClearWorkspaceCheck.setSelection(configuration.getAttribute(
132: IPDELauncherConstants.DOCLEAR, false));
133: fAskClearCheck.setSelection(configuration.getAttribute(
134: IPDELauncherConstants.ASKCLEAR, true));
135: fAskClearCheck.setEnabled(fClearWorkspaceCheck.getSelection());
136: fClearWorkspaceLogRadio.setEnabled(fClearWorkspaceCheck
137: .getSelection());
138: fClearWorkspaceLogRadio.setSelection(configuration
139: .getAttribute(IPDEUIConstants.DOCLEARLOG, false));
140: fClearWorkspaceRadio.setEnabled(fClearWorkspaceCheck
141: .getSelection());
142: fClearWorkspaceRadio.setSelection(!configuration.getAttribute(
143: IPDEUIConstants.DOCLEARLOG, false));
144: }
145:
146: public void setDefaults(
147: ILaunchConfigurationWorkingCopy configuration,
148: boolean isJUnit) {
149: if (isJUnit) {
150: configuration.setAttribute(IPDELauncherConstants.LOCATION,
151: LaunchArgumentsHelper
152: .getDefaultJUnitWorkspaceLocation());
153: } else {
154: configuration.setAttribute(IPDELauncherConstants.LOCATION,
155: LaunchArgumentsHelper
156: .getDefaultWorkspaceLocation(configuration
157: .getName()));
158: }
159: configuration.setAttribute(IPDELauncherConstants.DOCLEAR,
160: isJUnit);
161: configuration.setAttribute(IPDELauncherConstants.ASKCLEAR,
162: !isJUnit);
163: configuration.setAttribute(IPDEUIConstants.DOCLEARLOG, false);
164: }
165:
166: protected String getName() {
167: return PDEUIMessages.WorkspaceDataBlock_name;
168: }
169:
170: protected void handleBrowseWorkspace() {
171: super .handleBrowseWorkspace();
172: if (fClearWorkspaceCheck.getSelection())
173: fClearWorkspaceCheck.setSelection(false);
174: }
175:
176: protected void handleBrowseFileSystem() {
177: super .handleBrowseFileSystem();
178: if (fClearWorkspaceCheck.getSelection())
179: fClearWorkspaceCheck.setSelection(false);
180: }
181:
182: public String validate() {
183: int length = getLocation().length();
184: fClearWorkspaceCheck.setEnabled(length > 0);
185: fAskClearCheck.setEnabled(fClearWorkspaceCheck.getSelection()
186: && length > 0);
187: if (length == 0)
188: fClearWorkspaceCheck.setSelection(false);
189: return null;
190: }
191:
192: }
|