1 11 package org.eclipse.pde.internal.ui.editor.target; 12 13 import org.eclipse.debug.ui.StringVariableSelectionDialog; 14 import org.eclipse.pde.core.IModelChangedEvent; 15 import org.eclipse.pde.internal.core.itarget.IArgumentsInfo; 16 import org.eclipse.pde.internal.core.itarget.ITarget; 17 import org.eclipse.pde.internal.core.itarget.ITargetModel; 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.graphics.Image; 33 import org.eclipse.swt.layout.GridData; 34 import org.eclipse.swt.widgets.Button; 35 import org.eclipse.swt.widgets.Composite; 36 import org.eclipse.swt.widgets.Display; 37 import org.eclipse.swt.widgets.Text; 38 import org.eclipse.ui.IActionBars; 39 import org.eclipse.ui.forms.IFormColors; 40 import org.eclipse.ui.forms.widgets.FormToolkit; 41 import org.eclipse.ui.forms.widgets.Section; 42 43 public class ArgumentsSection extends PDESection { 44 45 private static final String [] TAB_LABELS = new String [2]; 46 static { 47 TAB_LABELS[0] = PDEUIMessages.ArgumentsSection_programTabLabel; 48 TAB_LABELS[1] = PDEUIMessages.ArgumentsSection_vmTabLabel; 49 } 50 51 private CTabFolder fTabFolder; 52 private FormEntry fArgument; 53 private int fLastTab; 54 private Image fImage; 55 56 public ArgumentsSection(PDEFormPage page, Composite parent) { 57 super(page, parent, Section.DESCRIPTION); 58 fImage = PDEPluginImages.DESC_ARGUMENT_TAB.createImage(); 59 createClient(getSection(), page.getEditor().getToolkit()); 60 } 61 62 protected void createClient(Section section, FormToolkit toolkit) { 63 section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1)); 64 section.setText(PDEUIMessages.ArgumentsSection_editorTitle); 65 section.setDescription(PDEUIMessages.ArgumentsSection_description); 66 GridData data = new GridData(GridData.FILL_BOTH); 67 data.horizontalSpan = 1; 68 section.setLayoutData(data); 69 70 Composite client = toolkit.createComposite(section); 71 client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 1)); 72 GridData gd = new GridData(GridData.FILL_BOTH); 73 gd.widthHint = 100; 74 client.setLayoutData(gd); 75 76 fTabFolder = new CTabFolder(client, SWT.FLAT | SWT.TOP); 77 toolkit.adapt(fTabFolder, true, true); 78 gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); 79 fTabFolder.setLayoutData(gd); 80 gd.heightHint = 2; 81 toolkit.getColors().initializeSectionToolBarColors(); 82 Color selectedColor = toolkit.getColors().getColor(IFormColors.TB_BG); 83 fTabFolder.setSelectionBackground(new Color[] { selectedColor, 84 toolkit.getColors().getBackground() }, 85 new int[] { 100 }, true); 86 fTabFolder.addSelectionListener(new SelectionAdapter() { 87 public void widgetSelected(SelectionEvent e) { 88 if (fArgument.isDirty()) 89 fArgument.commit(); 90 refresh(); 91 } 92 }); 93 94 IActionBars actionBars = getPage().getPDEEditor().getEditorSite().getActionBars(); 95 96 fArgument = new FormEntry(client, toolkit, PDEUIMessages.ArgumentsSection_argumentsTextLabel, SWT.MULTI|SWT.WRAP); 97 fArgument.getText().setLayoutData(new GridData(GridData.FILL_BOTH)); 98 fArgument.setFormEntryListener(new FormEntryAdapter(this, actionBars) { 99 public void textValueChanged(FormEntry entry) { 100 if (fLastTab == 0) 101 getArgumentInfo().setProgramArguments(fArgument.getValue()); 102 else 103 getArgumentInfo().setVMArguments(fArgument.getValue()); 104 } 105 }); 106 107 Button variables = toolkit.createButton(client, PDEUIMessages.ArgumentsSection_variableButtonTitle, SWT.NONE); 108 variables.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); 109 variables.addSelectionListener(new SelectionAdapter() { 110 public void widgetSelected(SelectionEvent e) { 111 StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getSection().getShell()); 112 dialog.open(); 113 String variable = dialog.getVariableExpression(); 114 if (variable != null) { 115 fArgument.getText().insert(variable); 116 } 117 } 118 }); 119 120 createTabs(); 121 toolkit.paintBordersFor(client); 122 section.setClient(client); 123 124 getModel().addModelChangedListener(this); 126 } 127 128 131 public void modelChanged(IModelChangedEvent e) { 132 if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) { 134 handleModelEventWorldChanged(e); 135 } 136 } 137 138 141 private void handleModelEventWorldChanged(IModelChangedEvent event) { 142 refresh(); 144 } 145 146 private void createTabs() { 147 for (int i = 0; i < TAB_LABELS.length; i++) { 148 CTabItem item = new CTabItem(fTabFolder, SWT.NULL); 149 item.setText(TAB_LABELS[i]); 150 item.setImage(fImage); 151 } 152 fLastTab = 0; 153 fTabFolder.setSelection(fLastTab); 154 } 155 156 private IArgumentsInfo getArgumentInfo() { 157 IArgumentsInfo info = getTarget().getArguments(); 158 if (info == null) { 159 info = getModel().getFactory().createArguments(); 160 getTarget().setArguments(info); 161 } 162 return info; 163 } 164 165 private ITarget getTarget() { 166 return getModel().getTarget(); 167 } 168 169 private ITargetModel getModel() { 170 return (ITargetModel)getPage().getPDEEditor().getAggregateModel(); 171 } 172 173 public void refresh() { 174 fLastTab = fTabFolder.getSelectionIndex(); 175 if (fLastTab == 0) 176 fArgument.setValue(getArgumentInfo().getProgramArguments(), true); 177 else 178 fArgument.setValue(getArgumentInfo().getVMArguments(), true); 179 super.refresh(); 180 } 181 182 public void commit(boolean onSave) { 183 fArgument.commit(); 184 super.commit(onSave); 185 } 186 187 public void cancelEdit() { 188 fArgument.cancelEdit(); 189 super.cancelEdit(); 190 } 191 192 public boolean canPaste(Clipboard clipboard) { 193 Display d = getSection().getDisplay(); 194 return d.getFocusControl() instanceof Text; 195 } 196 197 public void dispose() { 198 ITargetModel model = getModel(); 199 if (model != null) { 200 model.removeModelChangedListener(this); 201 } 202 if (fImage != null) 203 fImage.dispose(); 204 super.dispose(); 205 } 206 207 } 208 | Popular Tags |