KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > launcher > ConfigurationAreaBlock


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.launcher;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.debug.core.ILaunchConfiguration;
15 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
16 import org.eclipse.pde.internal.ui.PDEUIMessages;
17 import org.eclipse.pde.ui.launcher.AbstractLauncherTab;
18 import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.events.SelectionAdapter;
21 import org.eclipse.swt.events.SelectionEvent;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.Button;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Group;
27
28 public class ConfigurationAreaBlock extends BaseBlock {
29
30     private Button fUseDefaultLocationButton;
31     private Button fClearConfig;
32     private String JavaDoc fLastEnteredConfigArea;
33     private String JavaDoc fConfigName;
34     private static String JavaDoc DEFAULT_DIR = "${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/"; //$NON-NLS-1$
35

36     public ConfigurationAreaBlock(AbstractLauncherTab tab) {
37         super(tab);
38     }
39     
40     public void createControl(Composite parent) {
41         Group group = new Group(parent, SWT.NONE);
42         group.setText(PDEUIMessages.ConfigurationTab_configAreaGroup);
43         group.setLayout(new GridLayout(2, false));
44         group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
45         
46         fUseDefaultLocationButton = new Button(group, SWT.CHECK);
47         GridData gd = new GridData();
48         gd.horizontalSpan = 2;
49         fUseDefaultLocationButton.setLayoutData(gd);
50         fUseDefaultLocationButton.setText(PDEUIMessages.ConfigurationTab_useDefaultLoc);
51         fUseDefaultLocationButton.addSelectionListener(new SelectionAdapter() {
52             public void widgetSelected(SelectionEvent e) {
53                 boolean useDefaultArea = fUseDefaultLocationButton.getSelection();
54                 if (useDefaultArea)
55                     fLocationText.setText(DEFAULT_DIR + fConfigName);
56                 else
57                     fLocationText.setText(fLastEnteredConfigArea);
58                 enableBrowseSection(!useDefaultArea);
59             }
60         });
61
62         createText(group, PDEUIMessages.ConfigurationTab_configLog, 20);
63         
64         Composite buttons = new Composite(group, SWT.NONE);
65         GridLayout layout = new GridLayout(4, false);
66         layout.marginHeight = layout.marginWidth = 0;
67         buttons.setLayout(layout);
68         gd = new GridData(GridData.FILL_HORIZONTAL);
69         gd.horizontalSpan = 2;
70         buttons.setLayoutData(gd);
71         
72         fClearConfig = new Button(buttons, SWT.CHECK);
73         fClearConfig.setText(PDEUIMessages.ConfigurationTab_clearArea);
74         fClearConfig.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
75         fClearConfig.addSelectionListener(fListener);
76         
77         createButtons(buttons, new String JavaDoc[] {
78                 PDEUIMessages.BaseBlock_workspace, PDEUIMessages.BaseBlock_filesystem, PDEUIMessages.BaseBlock_variables
79         });
80     }
81     
82     public void initializeFrom(ILaunchConfiguration configuration) throws CoreException {
83         fConfigName = configuration.getName();
84         boolean useDefaultArea = configuration.getAttribute(IPDELauncherConstants.CONFIG_USE_DEFAULT_AREA, true);
85         fUseDefaultLocationButton.setSelection(useDefaultArea);
86         enableBrowseSection(!useDefaultArea);
87         
88         fClearConfig.setSelection(configuration.getAttribute(IPDELauncherConstants.CONFIG_CLEAR_AREA, false));
89         fLastEnteredConfigArea = configuration.getAttribute(IPDELauncherConstants.CONFIG_LOCATION, ""); //$NON-NLS-1$
90

91         if (useDefaultArea)
92             fLocationText.setText(DEFAULT_DIR + fConfigName);
93         else
94             fLocationText.setText(fLastEnteredConfigArea);
95     }
96     
97     public void performApply(ILaunchConfigurationWorkingCopy configuration) {
98         configuration.setAttribute(IPDELauncherConstants.CONFIG_USE_DEFAULT_AREA, fUseDefaultLocationButton.getSelection());
99         fLastEnteredConfigArea = getLocation();
100         configuration.setAttribute(IPDELauncherConstants.CONFIG_LOCATION, fLastEnteredConfigArea);
101         configuration.setAttribute(IPDELauncherConstants.CONFIG_CLEAR_AREA, fClearConfig.getSelection());
102     }
103     
104     public void setDefaults(ILaunchConfigurationWorkingCopy configuration, boolean isJUnit) {
105         configuration.setAttribute(IPDELauncherConstants.CONFIG_USE_DEFAULT_AREA, !isJUnit);
106         configuration.setAttribute(IPDELauncherConstants.CONFIG_CLEAR_AREA, isJUnit);
107         String JavaDoc location = DEFAULT_DIR + (isJUnit ? "pde-junit" : configuration.getName()); //$NON-NLS-1$
108
configuration.setAttribute(IPDELauncherConstants.CONFIG_LOCATION, location);
109     }
110     
111     protected String JavaDoc getName() {
112         return PDEUIMessages.ConfigurationAreaBlock_name;
113     }
114     
115 }
116
Popular Tags