1 11 package org.eclipse.pde.internal.ui.editor.product; 12 13 import org.eclipse.pde.core.IModelChangedEvent; 14 import org.eclipse.pde.internal.core.iproduct.IArgumentsInfo; 15 import org.eclipse.pde.internal.core.iproduct.IProduct; 16 import org.eclipse.pde.internal.core.iproduct.IProductModel; 17 import org.eclipse.pde.internal.ui.PDEPlugin; 18 import org.eclipse.pde.internal.ui.PDEPluginImages; 19 import org.eclipse.pde.internal.ui.PDEUIMessages; 20 import org.eclipse.pde.internal.ui.editor.FormEntryAdapter; 21 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; 22 import org.eclipse.pde.internal.ui.editor.PDEFormPage; 23 import org.eclipse.pde.internal.ui.editor.PDESection; 24 import org.eclipse.pde.internal.ui.parts.FormEntry; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.custom.CTabFolder; 27 import org.eclipse.swt.custom.CTabItem; 28 import org.eclipse.swt.dnd.Clipboard; 29 import org.eclipse.swt.events.SelectionAdapter; 30 import org.eclipse.swt.events.SelectionEvent; 31 import org.eclipse.swt.graphics.Color; 32 import org.eclipse.swt.layout.GridData; 33 import org.eclipse.swt.widgets.Composite; 34 import org.eclipse.swt.widgets.Display; 35 import org.eclipse.swt.widgets.Text; 36 import org.eclipse.ui.IActionBars; 37 import org.eclipse.ui.forms.IFormColors; 38 import org.eclipse.ui.forms.widgets.FormToolkit; 39 import org.eclipse.ui.forms.widgets.Section; 40 41 public class ArgumentsSection extends PDESection { 42 43 private static final String [] TAB_LABELS = new String [5]; 44 static { 45 TAB_LABELS[IArgumentsInfo.L_ARGS_ALL] = PDEUIMessages.ArgumentsSection_allPlatforms; 46 TAB_LABELS[IArgumentsInfo.L_ARGS_LINUX] = "linux"; TAB_LABELS[IArgumentsInfo.L_ARGS_MACOS] = "macosx"; TAB_LABELS[IArgumentsInfo.L_ARGS_SOLAR] = "solaris"; TAB_LABELS[IArgumentsInfo.L_ARGS_WIN32] = "win32"; } 51 52 private FormEntry fVMArgs; 53 private FormEntry fProgramArgs; 54 private CTabFolder fTabFolder; 55 private int fLastTab; 56 57 public ArgumentsSection(PDEFormPage page, Composite parent) { 58 super(page, parent, Section.DESCRIPTION); 59 createClient(getSection(), page.getEditor().getToolkit()); 60 } 61 62 protected void createClient(Section section, FormToolkit toolkit) { 63 64 section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1)); 65 GridData data = new GridData(GridData.FILL_BOTH); 66 section.setLayoutData(data); 67 68 section.setText(PDEUIMessages.ArgumentsSection_title); 69 section.setDescription(PDEUIMessages.ArgumentsSection_desc); 70 71 Composite client = toolkit.createComposite(section); 72 client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 1)); 73 client.setLayoutData(new GridData(GridData.FILL_BOTH)); 74 75 fTabFolder = new CTabFolder(client, SWT.FLAT | SWT.TOP); 76 toolkit.adapt(fTabFolder, true, true); 77 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); 78 fTabFolder.setLayoutData(gd); 79 gd.heightHint = 2; 80 toolkit.getColors().initializeSectionToolBarColors(); 81 Color selectedColor = toolkit.getColors().getColor(IFormColors.TB_BG); 82 fTabFolder.setSelectionBackground(new Color[] { selectedColor, 83 toolkit.getColors().getBackground() }, 84 new int[] { 100 }, true); 85 86 fTabFolder.addSelectionListener(new SelectionAdapter() { 87 public void widgetSelected(SelectionEvent e) { 88 if (fProgramArgs.isDirty()) 89 fProgramArgs.commit(); 90 if (fVMArgs.isDirty()) 91 fVMArgs.commit(); 92 refresh(); 93 } 94 }); 95 fTabFolder.setUnselectedImageVisible(false); 96 97 IActionBars actionBars = getPage().getPDEEditor().getEditorSite().getActionBars(); 98 99 fProgramArgs = new FormEntry(client, toolkit, PDEUIMessages.ArgumentsSection_program, SWT.MULTI|SWT.WRAP); 100 fProgramArgs.getText().setLayoutData(new GridData(GridData.FILL_BOTH)); 101 fProgramArgs.setFormEntryListener(new FormEntryAdapter(this, actionBars) { 102 public void textValueChanged(FormEntry entry) { 103 IArgumentsInfo info = getLauncherArguments(); 104 info.setProgramArguments(entry.getValue().trim(), fLastTab); 105 } 106 }); 107 fProgramArgs.setEditable(isEditable()); 108 109 fVMArgs = new FormEntry(client, toolkit, PDEUIMessages.ArgumentsSection_vm, SWT.MULTI|SWT.WRAP); 110 fVMArgs.getText().setLayoutData(new GridData(GridData.FILL_BOTH)); 111 fVMArgs.setFormEntryListener(new FormEntryAdapter(this, actionBars) { 112 public void textValueChanged(FormEntry entry) { 113 IArgumentsInfo info = getLauncherArguments(); 114 info.setVMArguments(entry.getValue().trim(), fLastTab); 115 } 116 }); 117 fVMArgs.setEditable(isEditable()); 118 119 createTabs(); 120 toolkit.paintBordersFor(client); 121 section.setClient(client); 122 getModel().addModelChangedListener(this); 124 } 125 126 private void createTabs() { 127 for (int i = 0; i < TAB_LABELS.length; i++) { 128 CTabItem item = new CTabItem(fTabFolder, SWT.NULL); 129 item.setText(TAB_LABELS[i]); 130 item.setImage(PDEPlugin.getDefault().getLabelProvider().get( 131 PDEPluginImages.DESC_OPERATING_SYSTEM_OBJ)); 132 } 133 fLastTab = 0; 134 fTabFolder.setSelection(fLastTab); 135 } 136 137 public void refresh() { 138 fLastTab = fTabFolder.getSelectionIndex(); 139 fProgramArgs.setValue(getLauncherArguments().getProgramArguments(fLastTab), true); 140 fVMArgs.setValue(getLauncherArguments().getVMArguments(fLastTab), true); 141 super.refresh(); 142 } 143 144 public void commit(boolean onSave) { 145 fProgramArgs.commit(); 146 fVMArgs.commit(); 147 super.commit(onSave); 148 } 149 150 public void cancelEdit() { 151 fProgramArgs.cancelEdit(); 152 fVMArgs.cancelEdit(); 153 super.cancelEdit(); 154 } 155 156 private IArgumentsInfo getLauncherArguments() { 157 IArgumentsInfo info = getProduct().getLauncherArguments(); 158 if (info == null) { 159 info = getModel().getFactory().createLauncherArguments(); 160 getProduct().setLauncherArguments(info); 161 } 162 return info; 163 } 164 165 private IProduct getProduct() { 166 return getModel().getProduct(); 167 } 168 169 private IProductModel getModel() { 170 return (IProductModel)getPage().getPDEEditor().getAggregateModel(); 171 } 172 173 public boolean canPaste(Clipboard clipboard) { 174 Display d = getSection().getDisplay(); 175 return d.getFocusControl() instanceof Text; 176 } 177 178 181 public void modelChanged(IModelChangedEvent e) { 182 if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) { 184 handleModelEventWorldChanged(e); 185 } 186 } 187 188 191 private void handleModelEventWorldChanged(IModelChangedEvent event) { 192 refresh(); 193 } 194 195 198 public void dispose() { 199 IProductModel model = getModel(); 200 if (model != null) { 201 model.removeModelChangedListener(this); 202 } 203 super.dispose(); 204 } 205 206 } 207 | Popular Tags |