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.PDEUIMessages;
016: import org.eclipse.pde.ui.launcher.AbstractLauncherTab;
017: import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.events.SelectionAdapter;
020: import org.eclipse.swt.events.SelectionEvent;
021: import org.eclipse.swt.layout.GridData;
022: import org.eclipse.swt.layout.GridLayout;
023: import org.eclipse.swt.widgets.Button;
024: import org.eclipse.swt.widgets.Composite;
025: import org.eclipse.swt.widgets.Group;
026:
027: public class ConfigurationAreaBlock extends BaseBlock {
028:
029: private Button fUseDefaultLocationButton;
030: private Button fClearConfig;
031: private String fLastEnteredConfigArea;
032: private String fConfigName;
033: private static String DEFAULT_DIR = "${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/"; //$NON-NLS-1$
034:
035: public ConfigurationAreaBlock(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.ConfigurationTab_configAreaGroup);
042: group.setLayout(new GridLayout(2, false));
043: group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
044:
045: fUseDefaultLocationButton = new Button(group, SWT.CHECK);
046: GridData gd = new GridData();
047: gd.horizontalSpan = 2;
048: fUseDefaultLocationButton.setLayoutData(gd);
049: fUseDefaultLocationButton
050: .setText(PDEUIMessages.ConfigurationTab_useDefaultLoc);
051: fUseDefaultLocationButton
052: .addSelectionListener(new SelectionAdapter() {
053: public void widgetSelected(SelectionEvent e) {
054: boolean useDefaultArea = fUseDefaultLocationButton
055: .getSelection();
056: if (useDefaultArea)
057: fLocationText.setText(DEFAULT_DIR
058: + fConfigName);
059: else
060: fLocationText
061: .setText(fLastEnteredConfigArea);
062: enableBrowseSection(!useDefaultArea);
063: }
064: });
065:
066: createText(group, PDEUIMessages.ConfigurationTab_configLog, 20);
067:
068: Composite buttons = new Composite(group, SWT.NONE);
069: GridLayout layout = new GridLayout(4, false);
070: layout.marginHeight = layout.marginWidth = 0;
071: buttons.setLayout(layout);
072: gd = new GridData(GridData.FILL_HORIZONTAL);
073: gd.horizontalSpan = 2;
074: buttons.setLayoutData(gd);
075:
076: fClearConfig = new Button(buttons, SWT.CHECK);
077: fClearConfig.setText(PDEUIMessages.ConfigurationTab_clearArea);
078: fClearConfig.setLayoutData(new GridData(
079: GridData.FILL_HORIZONTAL));
080: fClearConfig.addSelectionListener(fListener);
081:
082: createButtons(buttons, new String[] {
083: PDEUIMessages.BaseBlock_workspace,
084: PDEUIMessages.BaseBlock_filesystem,
085: PDEUIMessages.BaseBlock_variables });
086: }
087:
088: public void initializeFrom(ILaunchConfiguration configuration)
089: throws CoreException {
090: fConfigName = configuration.getName();
091: boolean useDefaultArea = configuration.getAttribute(
092: IPDELauncherConstants.CONFIG_USE_DEFAULT_AREA, true);
093: fUseDefaultLocationButton.setSelection(useDefaultArea);
094: enableBrowseSection(!useDefaultArea);
095:
096: fClearConfig.setSelection(configuration.getAttribute(
097: IPDELauncherConstants.CONFIG_CLEAR_AREA, false));
098: fLastEnteredConfigArea = configuration.getAttribute(
099: IPDELauncherConstants.CONFIG_LOCATION, ""); //$NON-NLS-1$
100:
101: if (useDefaultArea)
102: fLocationText.setText(DEFAULT_DIR + fConfigName);
103: else
104: fLocationText.setText(fLastEnteredConfigArea);
105: }
106:
107: public void performApply(
108: ILaunchConfigurationWorkingCopy configuration) {
109: configuration.setAttribute(
110: IPDELauncherConstants.CONFIG_USE_DEFAULT_AREA,
111: fUseDefaultLocationButton.getSelection());
112: fLastEnteredConfigArea = getLocation();
113: configuration.setAttribute(
114: IPDELauncherConstants.CONFIG_LOCATION,
115: fLastEnteredConfigArea);
116: configuration.setAttribute(
117: IPDELauncherConstants.CONFIG_CLEAR_AREA, fClearConfig
118: .getSelection());
119: }
120:
121: public void setDefaults(
122: ILaunchConfigurationWorkingCopy configuration,
123: boolean isJUnit) {
124: configuration
125: .setAttribute(
126: IPDELauncherConstants.CONFIG_USE_DEFAULT_AREA,
127: !isJUnit);
128: configuration.setAttribute(
129: IPDELauncherConstants.CONFIG_CLEAR_AREA, isJUnit);
130: String location = DEFAULT_DIR
131: + (isJUnit ? "pde-junit" : configuration.getName()); //$NON-NLS-1$
132: configuration.setAttribute(
133: IPDELauncherConstants.CONFIG_LOCATION, location);
134: }
135:
136: protected String getName() {
137: return PDEUIMessages.ConfigurationAreaBlock_name;
138: }
139:
140: }
|