1 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.IPDEUIConstants; 17 import org.eclipse.pde.internal.ui.PDEUIMessages; 18 import org.eclipse.pde.ui.launcher.AbstractLauncherTab; 19 import org.eclipse.pde.ui.launcher.IPDELauncherConstants; 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.events.SelectionAdapter; 22 import org.eclipse.swt.events.SelectionEvent; 23 import org.eclipse.swt.layout.GridData; 24 import org.eclipse.swt.layout.GridLayout; 25 import org.eclipse.swt.widgets.Button; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Group; 28 29 public class WorkspaceDataBlock extends BaseBlock { 30 31 private Button fClearWorkspaceCheck; 32 private Button fAskClearCheck; 33 private Button fClearWorkspaceRadio; 34 private Button fClearWorkspaceLogRadio; 35 36 public WorkspaceDataBlock(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.WorkspaceDataBlock_workspace); 43 GridLayout layout = new GridLayout(); 44 layout.numColumns = 2; 45 group.setLayout(layout); 46 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 47 48 createText(group, PDEUIMessages.WorkspaceDataBlock_location, 0); 49 50 Composite buttons = new Composite(group, SWT.NONE); 51 layout = new GridLayout(7, false); 52 layout.marginHeight = layout.marginWidth = 0; 53 buttons.setLayout(layout); 54 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 55 gd.horizontalSpan = 2; 56 buttons.setLayoutData(gd); 57 58 fClearWorkspaceCheck = new Button(buttons, SWT.CHECK); 59 fClearWorkspaceCheck.setText(PDEUIMessages.WorkspaceDataBlock_clear); 60 fClearWorkspaceCheck.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); 61 fClearWorkspaceCheck.addSelectionListener(new SelectionAdapter() { 62 public void widgetSelected(SelectionEvent e) { 63 fAskClearCheck.setEnabled(fClearWorkspaceCheck.getSelection()); 64 fClearWorkspaceRadio.setEnabled(fClearWorkspaceCheck.getSelection()); 65 fClearWorkspaceLogRadio.setEnabled(fClearWorkspaceCheck.getSelection()); 66 fTab.updateLaunchConfigurationDialog(); 67 } 68 }); 69 70 fClearWorkspaceRadio = new Button(buttons, SWT.RADIO); 71 fClearWorkspaceRadio.setText(PDEUIMessages.WorkspaceDataBlock_clearWorkspace); 72 fClearWorkspaceRadio.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); 73 fClearWorkspaceRadio.addSelectionListener(new SelectionAdapter() { 74 public void widgetSelected(SelectionEvent e) { 75 fTab.updateLaunchConfigurationDialog(); 76 } 77 }); 78 fClearWorkspaceLogRadio = new Button(buttons, SWT.RADIO); 79 fClearWorkspaceLogRadio.setText(PDEUIMessages.WorkspaceDataBlock_clearLog); 80 fClearWorkspaceLogRadio.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 81 fClearWorkspaceLogRadio.addSelectionListener(new SelectionAdapter() { 82 public void widgetSelected(SelectionEvent e) { 83 fTab.updateLaunchConfigurationDialog(); 84 } 85 }); 86 87 createButtons(buttons, new String [] { 88 PDEUIMessages.BaseBlock_workspace, PDEUIMessages.BaseBlock_filesystem, PDEUIMessages.BaseBlock_variables 89 }); 90 91 fAskClearCheck = new Button(group, SWT.CHECK); 92 fAskClearCheck.setText(PDEUIMessages.WorkspaceDataBlock_askClear); 93 gd = new GridData(); 94 gd.horizontalSpan = 2; 95 fAskClearCheck.setLayoutData(gd); 96 fAskClearCheck.addSelectionListener(fListener); 97 } 98 99 public void performApply(ILaunchConfigurationWorkingCopy config) { 100 config.setAttribute(IPDELauncherConstants.LOCATION, getLocation()); 101 config.setAttribute(IPDELauncherConstants.DOCLEAR, fClearWorkspaceCheck.getSelection()); 102 config.setAttribute(IPDELauncherConstants.ASKCLEAR, fAskClearCheck.getSelection()); 103 config.setAttribute(IPDEUIConstants.DOCLEARLOG, fClearWorkspaceLogRadio.getSelection()); 104 } 105 106 public void initializeFrom(ILaunchConfiguration configuration) throws CoreException { 107 fLocationText.setText(configuration.getAttribute(IPDELauncherConstants.LOCATION, 108 LaunchArgumentsHelper.getDefaultWorkspaceLocation(configuration.getName()))); 109 fClearWorkspaceCheck.setSelection(configuration.getAttribute(IPDELauncherConstants.DOCLEAR, false)); 110 fAskClearCheck.setSelection(configuration.getAttribute(IPDELauncherConstants.ASKCLEAR, true)); 111 fAskClearCheck.setEnabled(fClearWorkspaceCheck.getSelection()); 112 fClearWorkspaceLogRadio.setEnabled(fClearWorkspaceCheck.getSelection()); 113 fClearWorkspaceLogRadio.setSelection(configuration.getAttribute(IPDEUIConstants.DOCLEARLOG, false)); 114 fClearWorkspaceRadio.setEnabled(fClearWorkspaceCheck.getSelection()); 115 fClearWorkspaceRadio.setSelection(!configuration.getAttribute(IPDEUIConstants.DOCLEARLOG, false)); 116 } 117 118 public void setDefaults(ILaunchConfigurationWorkingCopy configuration, boolean isJUnit) { 119 if (isJUnit) { 120 configuration.setAttribute(IPDELauncherConstants.LOCATION, 121 LaunchArgumentsHelper.getDefaultJUnitWorkspaceLocation()); 122 } else { 123 configuration.setAttribute(IPDELauncherConstants.LOCATION, 124 LaunchArgumentsHelper.getDefaultWorkspaceLocation(configuration.getName())); 125 } 126 configuration.setAttribute(IPDELauncherConstants.DOCLEAR, isJUnit); 127 configuration.setAttribute(IPDELauncherConstants.ASKCLEAR, !isJUnit); 128 configuration.setAttribute(IPDEUIConstants.DOCLEARLOG, false); 129 } 130 131 protected String getName() { 132 return PDEUIMessages.WorkspaceDataBlock_name; 133 } 134 135 protected void handleBrowseWorkspace() { 136 super.handleBrowseWorkspace(); 137 if (fClearWorkspaceCheck.getSelection()) 138 fClearWorkspaceCheck.setSelection(false); 139 } 140 141 protected void handleBrowseFileSystem() { 142 super.handleBrowseFileSystem(); 143 if (fClearWorkspaceCheck.getSelection()) 144 fClearWorkspaceCheck.setSelection(false); 145 } 146 147 public String validate() { 148 int length = getLocation().length(); 149 fClearWorkspaceCheck.setEnabled(length > 0); 150 fAskClearCheck.setEnabled(fClearWorkspaceCheck.getSelection() && length > 0); 151 if (length == 0) 152 fClearWorkspaceCheck.setSelection(false); 153 return null; 154 } 155 156 } 157 | Popular Tags |