1 11 package org.eclipse.pde.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.jface.dialogs.Dialog; 17 import org.eclipse.pde.internal.ui.IHelpContextIds; 18 import org.eclipse.pde.internal.ui.PDEPlugin; 19 import org.eclipse.pde.internal.ui.PDEPluginImages; 20 import org.eclipse.pde.internal.ui.PDEUIMessages; 21 import org.eclipse.pde.internal.ui.launcher.JREBlock; 22 import org.eclipse.pde.internal.ui.launcher.ProgramBlock; 23 import org.eclipse.pde.internal.ui.launcher.WorkspaceDataBlock; 24 import org.eclipse.pde.ui.launcher.AbstractLauncherTab; 25 import org.eclipse.pde.ui.launcher.IPDELauncherConstants; 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.custom.ScrolledComposite; 28 import org.eclipse.swt.graphics.Image; 29 import org.eclipse.swt.graphics.Point; 30 import org.eclipse.swt.graphics.Rectangle; 31 import org.eclipse.swt.layout.GridData; 32 import org.eclipse.swt.layout.GridLayout; 33 import org.eclipse.swt.widgets.Composite; 34 import org.eclipse.swt.widgets.Control; 35 import org.eclipse.swt.widgets.Event; 36 import org.eclipse.swt.widgets.Listener; 37 import org.eclipse.ui.PlatformUI; 38 39 40 48 public class MainTab extends AbstractLauncherTab implements IPDELauncherConstants { 49 50 protected WorkspaceDataBlock fDataBlock; 51 protected ProgramBlock fProgramBlock; 52 protected JREBlock fJreBlock; 53 54 private Image fImage; 55 56 public MainTab() { 57 createWorkspaceDataBlock(); 58 createProgramBlock(); 59 fJreBlock = new JREBlock(this); 60 fImage = PDEPluginImages.DESC_MAIN_TAB.createImage(); 61 } 62 63 67 public void dispose() { 68 fImage.dispose(); 69 super.dispose(); 70 } 71 72 76 public void createControl(Composite parent) { 77 final ScrolledComposite scrollContainer = new ScrolledComposite(parent, SWT.V_SCROLL); 78 scrollContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 79 80 Composite composite = new Composite(scrollContainer, SWT.NONE); 81 scrollContainer.setContent(composite); 82 composite.setLayout(new GridLayout()); 83 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 84 85 fDataBlock.createControl(composite); 86 fProgramBlock.createControl(composite); 87 fJreBlock.createControl(composite); 88 89 Listener listener = new Listener() { 92 public void handleEvent(Event e) { 93 Control child = (Control)e.widget; 94 Rectangle bounds = child.getBounds(); 95 Rectangle area = scrollContainer.getClientArea(); 96 Point origin = scrollContainer.getOrigin(); 97 if (origin.x > bounds.x) origin.x = Math.max(0, bounds.x); 98 if (origin.y > bounds.y) origin.y = Math.max(0, bounds.y); 99 if (origin.x + area.width < bounds.x + bounds.width) origin.x = Math.max(0, bounds.x + bounds.width - area.width); 100 if (origin.y + area.height < bounds.y + bounds.height) origin.y = Math.max(0, bounds.y + bounds.height - area.height); 101 scrollContainer.setOrigin(origin); 102 } 103 }; 104 Control[] controls = composite.getChildren(); 105 for (int i = 0; i < controls.length; i++) 106 controls[i].addListener(SWT.Activate, listener); 107 108 composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); 109 scrollContainer.setExpandHorizontal(true); 110 setControl(scrollContainer); 111 Dialog.applyDialogFont(composite); 112 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.LAUNCHER_BASIC); 113 } 114 115 119 public void initializeFrom(ILaunchConfiguration config) { 120 try { 121 fDataBlock.initializeFrom(config); 122 fProgramBlock.initializeFrom(config); 123 fJreBlock.initializeFrom(config); 124 } catch (CoreException e) { 125 PDEPlugin.logException(e); 126 } finally { 127 } 128 } 129 130 134 public void setDefaults(ILaunchConfigurationWorkingCopy config) { 135 fDataBlock.setDefaults(config, false); 136 fProgramBlock.setDefaults(config); 137 fJreBlock.setDefaults(config); 138 } 139 140 144 public void performApply(ILaunchConfigurationWorkingCopy config) { 145 fDataBlock.performApply(config); 146 fProgramBlock.performApply(config); 147 fJreBlock.performApply(config); 148 } 149 150 154 public String getName() { 155 return PDEUIMessages.MainTab_name; 156 } 157 158 162 public Image getImage() { 163 return fImage; 164 } 165 166 169 protected void createWorkspaceDataBlock() { 170 fDataBlock = new WorkspaceDataBlock(this); 171 } 172 173 177 protected void createProgramBlock() { 178 fProgramBlock = new ProgramBlock(this); 179 } 180 181 185 public void validateTab() { 186 setErrorMessage(fDataBlock.validate()); 187 } 188 189 } 190 | Popular Tags |