1 11 package org.eclipse.pde.internal.ui.commands; 12 13 import org.eclipse.core.commands.Command; 14 import org.eclipse.core.commands.ParameterizedCommand; 15 import org.eclipse.core.expressions.IEvaluationContext; 16 import org.eclipse.jface.dialogs.IDialogConstants; 17 import org.eclipse.jface.viewers.ISelection; 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.PDEUIMessages; 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.widgets.Button; 24 import org.eclipse.swt.widgets.Composite; 25 import org.eclipse.swt.widgets.Shell; 26 import org.eclipse.ui.forms.FormDialog; 27 import org.eclipse.ui.forms.IManagedForm; 28 import org.eclipse.ui.forms.widgets.ScrolledForm; 29 30 public class CommandComposerDialog extends FormDialog { 31 32 private CommandComposerPart fCCP; 33 private ParameterizedCommand fPC; 34 private Button fOKButton; 35 36 public CommandComposerDialog(Shell parentShell, int filterType, ParameterizedCommand preselectedCommand, 37 IEvaluationContext snapshot) { 38 super(parentShell); 39 setShellStyle(SWT.MODELESS | SWT.SHELL_TRIM | SWT.BORDER); 40 fCCP = new CommandComposerPart(); 41 fCCP.setFilterType(filterType); 42 fCCP.setPresetCommand(preselectedCommand); 43 fCCP.setSnapshotContext(snapshot); 44 } 45 46 protected void createFormContent(IManagedForm mform) { 47 ScrolledForm form = mform.getForm(); 48 mform.getToolkit().decorateFormHeading(form.getForm()); 49 initializeDialogUnits(form); 50 fCCP.createCC(form, mform.getToolkit(), new ISelectionChangedListener() { 51 public void selectionChanged(SelectionChangedEvent event) { 52 updateOkButtonEnablement(event.getSelection()); 53 } 54 }); 55 applyDialogFont(form); 56 } 57 58 61 protected void createButtonsForButtonBar(Composite parent) { 62 super.createButtonsForButtonBar(parent); 63 fOKButton = getButton(IDialogConstants.OK_ID); 65 66 CommandList list = fCCP.getCommandList(); 67 if (list == null) { 69 updateOkButtonEnablement(false); 70 return; 71 } 72 ISelection selection = list.getSelection(); 74 updateOkButtonEnablement(selection); 76 } 77 78 81 private void updateOkButtonEnablement(Object selection) { 82 if (selection == null) { 84 updateOkButtonEnablement(false); 85 return; 86 } 87 if ((selection instanceof IStructuredSelection) == false) { 89 updateOkButtonEnablement(false); 90 return; 91 } 92 IStructuredSelection sSelection = (IStructuredSelection)selection; 93 if (sSelection.getFirstElement() instanceof Command) { 95 updateOkButtonEnablement(true); 97 return; 98 } 99 updateOkButtonEnablement(false); 101 } 102 103 106 private void updateOkButtonEnablement(boolean enabled) { 107 if (fOKButton != null) { 108 fOKButton.setEnabled(enabled); 109 } 110 } 111 112 protected void configureShell(Shell newShell) { 113 newShell.setText(PDEUIMessages.CommandSerializerPart_name); 114 super.configureShell(newShell); 115 } 116 117 public void okPressed() { 118 fPC = fCCP.getParameterizedCommand(); 119 super.okPressed(); 120 } 121 122 public boolean close() { 123 fCCP.dispose(); 124 return super.close(); 125 } 126 127 public ParameterizedCommand getCommand() { 128 return fPC; 129 } 130 } 131 | Popular Tags |