1 11 package org.eclipse.jdt.internal.debug.ui.jres; 12 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds; 18 import org.eclipse.jdt.launching.IVMInstall; 19 import org.eclipse.jdt.launching.JavaRuntime; 20 import org.eclipse.jdt.launching.environments.IExecutionEnvironment; 21 import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; 22 import org.eclipse.jface.dialogs.Dialog; 23 import org.eclipse.jface.preference.PreferencePage; 24 import org.eclipse.jface.viewers.ArrayContentProvider; 25 import org.eclipse.jface.viewers.CheckStateChangedEvent; 26 import org.eclipse.jface.viewers.CheckboxTableViewer; 27 import org.eclipse.jface.viewers.ICheckStateListener; 28 import org.eclipse.jface.viewers.ISelectionChangedListener; 29 import org.eclipse.jface.viewers.IStructuredContentProvider; 30 import org.eclipse.jface.viewers.IStructuredSelection; 31 import org.eclipse.jface.viewers.SelectionChangedEvent; 32 import org.eclipse.jface.viewers.TableViewer; 33 import org.eclipse.jface.viewers.Viewer; 34 import org.eclipse.jface.viewers.ViewerComparator; 35 import org.eclipse.swt.SWT; 36 import org.eclipse.swt.layout.GridData; 37 import org.eclipse.swt.layout.GridLayout; 38 import org.eclipse.swt.widgets.Composite; 39 import org.eclipse.swt.widgets.Control; 40 import org.eclipse.swt.widgets.Label; 41 import org.eclipse.swt.widgets.Table; 42 import org.eclipse.swt.widgets.Text; 43 import org.eclipse.ui.IWorkbench; 44 import org.eclipse.ui.IWorkbenchPreferencePage; 45 import org.eclipse.ui.PlatformUI; 46 47 52 public class ExecutionEnvironmentsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { 53 54 private TableViewer fProfilesViewer; 55 private CheckboxTableViewer fJREsViewer; 56 private Text fDescription; 57 58 61 private Map fDefaults = new HashMap (); 62 63 class JREsContentProvider implements IStructuredContentProvider { 64 65 68 public Object [] getElements(Object inputElement) { 69 return ((IExecutionEnvironment)inputElement).getCompatibleVMs(); 70 } 71 72 75 public void dispose() { 76 } 77 78 81 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 82 } 83 84 } 85 86 public ExecutionEnvironmentsPreferencePage() { 87 super(); 88 setTitle(JREMessages.JREProfilesPreferencePage_0); 90 setDescription(JREMessages.JREProfilesPreferencePage_1); 91 } 92 93 96 public void init(IWorkbench workbench) { 97 } 98 99 102 protected Control createContents(Composite ancestor) { 103 initializeDialogUnits(ancestor); 104 noDefaultAndApplyButton(); 105 PlatformUI.getWorkbench().getHelpSystem().setHelp(ancestor, IJavaDebugHelpContextIds.JRE_PROFILES_PAGE); 107 108 IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); 110 IExecutionEnvironment[] environments = manager.getExecutionEnvironments(); 111 for (int i = 0; i < environments.length; i++) { 112 IExecutionEnvironment environment = environments[i]; 113 IVMInstall install = environment.getDefaultVM(); 114 if (install != null) { 115 fDefaults.put(environment, install); 116 } 117 } 118 119 Composite container = new Composite(ancestor, SWT.NONE); 120 GridLayout layout = new GridLayout(); 121 layout.numColumns = 2; 122 layout.marginHeight = 0; 123 layout.marginWidth = 0; 124 layout.makeColumnsEqualWidth = true; 125 container.setLayout(layout); 126 GridData gd = new GridData(GridData.FILL_BOTH); 127 container.setLayoutData(gd); 128 container.setFont(ancestor.getFont()); 129 130 Composite eeContainer = new Composite(container, SWT.NONE); 131 layout = new GridLayout(); 132 layout.marginWidth = 0; 133 eeContainer.setLayout(layout); 134 eeContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); 135 136 Label label = new Label(eeContainer, SWT.NONE); 137 label.setFont(ancestor.getFont()); 138 label.setText(JREMessages.JREProfilesPreferencePage_2); 139 label.setLayoutData(new GridData(SWT.FILL, 0, true, false)); 140 141 Table table= new Table(eeContainer, SWT.BORDER | SWT.SINGLE); 142 table.setLayout(layout); 143 table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 144 fProfilesViewer = new TableViewer(table); 145 fProfilesViewer.setContentProvider(new ArrayContentProvider()); 146 fProfilesViewer.setLabelProvider(new ExecutionEnvironmentsLabelProvider()); 147 fProfilesViewer.setComparator(new ViewerComparator()); 148 fProfilesViewer.setInput(JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments()); 149 150 Composite jreContainer = new Composite(container, SWT.NONE); 151 layout = new GridLayout(); 152 layout.marginWidth = 0; 153 jreContainer.setLayout(layout); 154 jreContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); 155 156 label = new Label(jreContainer, SWT.NONE); 157 label.setFont(ancestor.getFont()); 158 label.setText(JREMessages.JREProfilesPreferencePage_3); 159 label.setLayoutData(new GridData(SWT.FILL, 0, true, false)); 160 161 table= new Table(jreContainer, SWT.CHECK | SWT.BORDER | SWT.SINGLE); 162 table.setLayout(layout); 163 table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 164 fJREsViewer = new CheckboxTableViewer(table); 165 fJREsViewer.setContentProvider(new JREsContentProvider()); 166 fJREsViewer.setLabelProvider(new JREsEnvironmentLabelProvider(new JREsEnvironmentLabelProvider.IExecutionEnvironmentProvider() { 167 public IExecutionEnvironment getEnvironment() { 168 return (IExecutionEnvironment) fJREsViewer.getInput(); 169 } 170 })); 171 fJREsViewer.setComparator(new JREsEnvironmentComparator()); 172 173 label = new Label(container, SWT.NONE); 174 label.setFont(ancestor.getFont()); 175 label.setText(JREMessages.JREProfilesPreferencePage_4); 176 label.setLayoutData(new GridData(SWT.FILL, 0, true, false, 2, 1)); 177 178 Text text = new Text(container, SWT.READ_ONLY | SWT.WRAP | SWT.BORDER); 179 text.setFont(ancestor.getFont()); 180 text.setLayoutData(new GridData(SWT.FILL, 0, true, false, 2, 1)); 181 fDescription = text; 182 183 fProfilesViewer.addSelectionChangedListener(new ISelectionChangedListener() { 184 public void selectionChanged(SelectionChangedEvent event) { 185 IExecutionEnvironment env = (IExecutionEnvironment) ((IStructuredSelection)event.getSelection()).getFirstElement(); 186 fJREsViewer.setInput(env); 187 String description = env.getDescription(); 188 if (description == null) { 189 description = ""; } 191 fDescription.setText(description); 192 IVMInstall jre = (IVMInstall) fDefaults.get(env); 193 if (jre != null) { 194 fJREsViewer.setCheckedElements(new Object []{jre}); 195 } else { 196 fJREsViewer.setCheckedElements(new Object [0]); 197 } 198 } 199 }); 200 201 fJREsViewer.addCheckStateListener(new ICheckStateListener() { 202 public void checkStateChanged(CheckStateChangedEvent event) { 203 if (event.getChecked()) { 204 Object element = event.getElement(); 205 fDefaults.put(fJREsViewer.getInput(), element); 206 fJREsViewer.setCheckedElements(new Object []{element}); 207 } else { 208 fDefaults.remove(fJREsViewer.getInput()); 209 } 210 211 } 212 }); 213 214 Dialog.applyDialogFont(ancestor); 215 return ancestor; 216 } 217 218 221 public boolean performOk() { 222 IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); 223 IExecutionEnvironment[] environments = manager.getExecutionEnvironments(); 224 for (int i = 0; i < environments.length; i++) { 225 IExecutionEnvironment environment = environments[i]; 226 IVMInstall vm = (IVMInstall) fDefaults.get(environment); 227 environment.setDefaultVM(vm); 228 } 229 return super.performOk(); 230 } 231 232 } 233 | Popular Tags |