1 11 package org.eclipse.pde.internal.ui.commands; 12 13 import java.util.HashMap ; 14 15 import org.eclipse.core.commands.ParameterizedCommand; 16 import org.eclipse.core.expressions.IEvaluationContext; 17 import org.eclipse.jface.dialogs.IMessageProvider; 18 import org.eclipse.jface.viewers.ISelectionChangedListener; 19 import org.eclipse.jface.viewers.IStructuredSelection; 20 import org.eclipse.jface.viewers.SelectionChangedEvent; 21 import org.eclipse.pde.internal.ui.PDEPluginImages; 22 import org.eclipse.pde.internal.ui.PDEUIMessages; 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.custom.SashForm; 25 import org.eclipse.swt.graphics.Image; 26 import org.eclipse.swt.layout.GridData; 27 import org.eclipse.swt.layout.GridLayout; 28 import org.eclipse.swt.widgets.Composite; 29 import org.eclipse.ui.IWorkbench; 30 import org.eclipse.ui.PlatformUI; 31 import org.eclipse.ui.commands.ICommandService; 32 import org.eclipse.ui.forms.widgets.FormToolkit; 33 import org.eclipse.ui.forms.widgets.ScrolledForm; 34 35 50 public class CommandComposerPart implements ISelectionChangedListener { 51 52 public static final int F_FILTER_NOT_SET = CommandCopyFilter.indexOf(CommandCopyFilter.NONE); 53 public static final int F_HELP_FILTER = CommandCopyFilter.indexOf(CommandCopyFilter.HELP); 54 public static final int F_CHEATSHEET_FILTER = CommandCopyFilter.indexOf(CommandCopyFilter.CHEATSHEET); 55 public static final int F_INTRO_FILTER = CommandCopyFilter.indexOf(CommandCopyFilter.INTRO); 56 57 private static final ICommandService fCommandService = initCommandService(); 58 59 private final TagManager fTagManager = new TagManager(); 60 private FormToolkit fToolkit; 61 private ScrolledForm fScrolledForm; 62 private CommandList fCommandList; 63 private CommandDetails fCommandDetails; 64 private int fFilterType = F_FILTER_NOT_SET; 65 private ParameterizedCommand fPC; 66 private Image fCommandImage; 67 private IEvaluationContext fSnapshotContext; 68 69 private static ICommandService initCommandService() { 70 IWorkbench workbench = PlatformUI.getWorkbench(); 71 Object serviceObject = workbench.getAdapter(ICommandService.class); 72 if (serviceObject instanceof ICommandService) 73 return (ICommandService) serviceObject; 74 return null; 75 } 76 77 public void setFilterType(int filterType) { 78 fFilterType = filterType; 79 } 80 81 public int getFilterType() { 82 return fFilterType; 83 } 84 85 93 public void setSnapshotContext(IEvaluationContext context) { 94 fSnapshotContext = context; 95 } 96 97 100 public IEvaluationContext getSnapshotContext() { 101 return fSnapshotContext; 102 } 103 104 protected void createCC(ScrolledForm form, FormToolkit toolkit, ISelectionChangedListener listener) { 105 fToolkit = toolkit; 106 fScrolledForm = form; 107 fScrolledForm.setText(PDEUIMessages.CommandComposerPart_formTitle); 108 fCommandImage = PDEPluginImages.DESC_BUILD_VAR_OBJ.createImage(); 109 fScrolledForm.setImage(fCommandImage); 110 Composite body = fScrolledForm.getBody(); 111 112 GridLayout layout = new GridLayout(); 113 layout.marginTop = 10; 114 body.setLayout(layout); 115 body.setLayoutData(new GridData(GridData.FILL_BOTH)); 116 117 SashForm sashForm = new SashForm(body, SWT.HORIZONTAL); 118 sashForm.setLayoutData(new GridData(GridData.FILL_BOTH)); 119 120 fCommandList = new CommandList(this, sashForm); 121 if (listener != null) 122 fCommandList.addTreeSelectionListener(listener); 123 124 fCommandDetails = new CommandDetails(this, sashForm); 125 126 sashForm.setWeights(new int[] {4,5}); 127 fToolkit.adapt(sashForm, true, true); 128 129 if (fPC != null) 130 fCommandList.setSelection(fPC.getCommand()); 131 132 fPC = null; 133 } 134 135 protected void setMessage(String message, int newType) { 136 fScrolledForm.getForm().setMessage(message, newType); 137 } 138 139 public FormToolkit getToolkit() { 140 return fToolkit; 141 } 142 143 public ICommandService getCommandService() { 144 return fCommandService; 145 } 146 147 public TagManager getTagManager() { 148 return fTagManager; 149 } 150 151 public void setFocus() { 152 fCommandList.setFocus(); 153 } 154 155 public void dispose() { 156 fCommandDetails.dispose(); 157 if (fCommandImage!=null) { 158 fCommandImage.dispose(); 159 fCommandImage=null; 160 } 161 } 162 163 protected String getSelectedCommandName() { 164 return fCommandDetails.getCommandName(); 165 } 166 protected String getSelectedSerializedString() { 167 return fCommandDetails.getSerializedString(); 168 } 169 protected HashMap getSelectedCommandsParameters() { 170 return fCommandDetails.getParameters(); 171 } 172 173 protected Composite createComposite(Composite parent) { 174 return createComposite(parent, GridData.FILL_BOTH, 1, true, 0); 175 } 176 177 protected Composite createComposite(Composite parent, int gdStyle, int numCol, boolean colEqual, int margin) { 178 Composite comp = fToolkit.createComposite(parent); 179 GridLayout layout = new GridLayout(numCol, colEqual); 180 layout.marginHeight = layout.marginWidth = margin; 181 comp.setLayout(layout); 182 comp.setLayoutData(new GridData(gdStyle)); 183 return comp; 184 } 185 186 public void selectionChanged(SelectionChangedEvent event) { 187 setMessage(null, IMessageProvider.NONE); 190 191 Object selectionObject = null; 192 if (fPC != null) 194 selectionObject = fPC; 195 else if (event.getSelection() instanceof IStructuredSelection) 196 selectionObject = (((IStructuredSelection)event.getSelection()).getFirstElement()); 197 if (selectionObject != null && 198 selectionObject.equals(fCommandDetails.getCommand())) 199 return; 200 fCommandDetails.showDetailsFor(selectionObject); 201 } 202 203 public ParameterizedCommand getParameterizedCommand() { 204 return fCommandDetails.buildParameterizedCommand(); 205 } 206 207 protected void setPresetCommand(ParameterizedCommand pc) { 208 fPC = pc; 209 } 210 211 protected ParameterizedCommand getPresetCommand() { 212 return fPC; 213 } 214 215 218 public CommandList getCommandList() { 219 return fCommandList; 220 } 221 } 222 | Popular Tags |