[Pydev-cvs] org.python.pydev.refactoring/src/org/python/pydev/refactoring/ui/pages/extractmethod E
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-09-27 20:04:03
|
Update of /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ui/pages/extractmethod In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21605/src/org/python/pydev/refactoring/ui/pages/extractmethod Modified Files: ExtractMethodPage.java ExtractMethodComposite.java Log Message: Synching to latest changes: Pydev <ul> <li><strong>Editor</strong>: Cursor settings no longer overridden</li> <li><strong>Code-completion</strong>: If __all__ is defined with runtime elements (and not only in a single assign statement), it's ignored for code-completion purposes</li> <li><strong>Debugger</strong>: Pythonpath the same in debug and regular modes (sys.path[0] is the same directory as the file run)</li> <li><strong>Debugger</strong>: Persist choices done in the debugger when files from the debugger are not found</li> <li><strong>Interpreter config</strong>: "email" automatically added to the "forced builtins"</li> <li><strong>Parser</strong>: Correctly recognizing absolute import with 3 or more levels</li> <li><strong>Syntax check</strong>: Option to do only on active editor</li> </ul> Also: tabs changed for spaces Index: ExtractMethodComposite.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ui/pages/extractmethod/ExtractMethodComposite.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ExtractMethodComposite.java 20 Oct 2007 19:31:05 -0000 1.3 --- ExtractMethodComposite.java 27 Sep 2008 20:00:47 -0000 1.4 *************** *** 53,438 **** public class ExtractMethodComposite extends Composite { ! private Label functionPreviewLabel; ! private Label functionSignatureLabel; ! private Label argumentsLabel; ! private Button editArgumentsButton; ! private TableColumn nameColumn; ! private Table argumentsTable; ! private Button downArgumentsButton; ! private Button upArgumentsButton; ! private LabeledEdit functionNameEdit; ! private TableCellEditorListener cellEditorListener; ! private AbstractScopeNode<?> scopeAdapter; ! private IValidationPage page; ! private FunctionSignatureListener signatureListener; ! private OffsetStrategyProvider strategyProvider; ! private ComboViewer methodInsertionComb; ! private CLabel methodInsertionLbl; ! private Composite argumentsComposite; ! public ExtractMethodComposite(IValidationPage page, Composite parent, boolean hasArguments, AbstractScopeNode<?> scope) { ! super(parent, SWT.NONE); ! this.page = page; ! this.scopeAdapter = scope; ! this.strategyProvider = new OffsetStrategyProvider(scopeAdapter, IOffsetStrategy.AFTERINIT | IOffsetStrategy.BEGIN ! | IOffsetStrategy.END); ! createComposite(hasArguments); ! } ! public void createComposite(boolean hasArguments) { ! setLayout(new GridLayout()); ! createFunctionName(this); ! if (hasArguments) { ! createArguments(this); ! } ! createOffsetStrategy(this); ! createFunctionSignature(this); ! pack(); ! } ! private void createFunctionSignature(Composite control) { ! Composite functionSignatureComposite = new Composite(control, SWT.NONE); ! GridLayout compositeLayout = new GridLayout(); ! compositeLayout.makeColumnsEqualWidth = true; ! GridData compositeLData = new GridData(); ! compositeLData.horizontalAlignment = GridData.FILL; ! compositeLData.grabExcessHorizontalSpace = true; ! functionSignatureComposite.setLayoutData(compositeLData); ! functionSignatureComposite.setLayout(compositeLayout); ! functionSignatureLabel = new Label(functionSignatureComposite, SWT.NONE); ! GridData labelLData = new GridData(); ! labelLData.horizontalAlignment = GridData.FILL; ! labelLData.grabExcessHorizontalSpace = true; ! functionSignatureLabel.setLayoutData(labelLData); ! functionSignatureLabel.setText(Messages.extractMethodFunctionPreview); ! functionPreviewLabel = new Label(functionSignatureComposite, SWT.NONE); ! GridData functionSignaturePreviewData = new GridData(); ! functionSignaturePreviewData.horizontalAlignment = GridData.FILL; ! functionSignaturePreviewData.grabExcessHorizontalSpace = true; ! functionSignaturePreviewData.verticalAlignment = GridData.FILL; ! functionSignaturePreviewData.grabExcessVerticalSpace = true; ! functionPreviewLabel.setLayoutData(functionSignaturePreviewData); ! functionPreviewLabel.setText(""); ! } ! private Button createButton(Composite parent, String name) { ! Button button = new Button(parent, SWT.PUSH | SWT.CENTER); ! GridData buttonLData = new GridData(); ! buttonLData.horizontalAlignment = GridData.FILL; ! buttonLData.grabExcessHorizontalSpace = true; ! button.setLayoutData(buttonLData); ! button.setText(name); ! return button; ! } ! private void createArguments(Composite control) { ! argumentsComposite = new Composite(control, SWT.NONE); ! GridLayout compositeLayout = new GridLayout(); ! compositeLayout.makeColumnsEqualWidth = true; ! GridData compositeLData = new GridData(); ! compositeLData.grabExcessHorizontalSpace = true; ! compositeLData.horizontalAlignment = GridData.FILL; ! compositeLData.grabExcessVerticalSpace = true; ! compositeLData.verticalAlignment = GridData.FILL; ! argumentsComposite.setLayoutData(compositeLData); ! argumentsComposite.setLayout(compositeLayout); ! createArgumentsLabel(argumentsComposite); ! createArgumentsTable(argumentsComposite); ! } ! private void createArgumentsButton(Composite ArgumentsTableComposite) { ! Composite argumentsButtonComposite = new Composite(ArgumentsTableComposite, SWT.NONE); ! GridLayout compositeLayout = new GridLayout(); ! compositeLayout.makeColumnsEqualWidth = true; ! FormData compositeLData = new FormData(0, 0); ! compositeLData.width = 80; ! compositeLData.bottom = new FormAttachment(1000, 1000, 0); ! compositeLData.right = new FormAttachment(1000, 1000, 0); ! compositeLData.top = new FormAttachment(0, 1000, 0); ! argumentsButtonComposite.setLayoutData(compositeLData); ! argumentsButtonComposite.setLayout(compositeLayout); ! editArgumentsButton = createButton(argumentsButtonComposite, Messages.extractMethodEditButton); ! editArgumentsButton.setEnabled(false); ! upArgumentsButton = createButton(argumentsButtonComposite, Messages.extractMethodUpButton); ! upArgumentsButton.setEnabled(false); ! downArgumentsButton = createButton(argumentsButtonComposite, Messages.extractMethodDownButton); ! downArgumentsButton.setEnabled(false); ! } ! private void registerDownButtonListener() { ! downArgumentsButton.addSelectionListener(new SelectionAdapter() { ! @Override ! public void widgetSelected(SelectionEvent e) { ! int selectionIndex = argumentsTable.getSelectionIndex(); ! if (argumentsTable.getSelectionCount() == 1 && selectionIndex != argumentsTable.getItemCount()) { ! TableItem item = argumentsTable.getSelection()[0]; ! if (item instanceof SimpleTableItem) { ! SimpleTableItem tableItem = (SimpleTableItem) item; ! new SimpleTableItem(argumentsTable, tableItem.getOriginalName(), tableItem.getText(), selectionIndex + 2); ! argumentsTable.remove(selectionIndex); ! argumentsTable.setSelection(selectionIndex + 1); ! argumentsTable.notifyListeners(SWT.Selection, new Event()); ! page.validate(); ! } ! } ! } ! }); ! } ! private void registerUpButtonListener() { ! upArgumentsButton.addSelectionListener(new SelectionAdapter() { ! @Override ! public void widgetSelected(SelectionEvent e) { ! int selectionIndex = argumentsTable.getSelectionIndex(); ! if (argumentsTable.getSelectionCount() == 1 && selectionIndex > 0) { ! TableItem item = argumentsTable.getSelection()[0]; ! if (item instanceof SimpleTableItem) { ! SimpleTableItem tableItem = (SimpleTableItem) item; ! new SimpleTableItem(argumentsTable, tableItem.getOriginalName(), tableItem.getText(), selectionIndex - 1); ! argumentsTable.remove(selectionIndex + 1); ! argumentsTable.setSelection(selectionIndex - 1); ! argumentsTable.notifyListeners(SWT.Selection, new Event()); ! page.validate(); ! } ! } ! } ! }); ! } ! private Composite createArgumentsTable(Composite parent) { ! final Composite argumentsComposite = new Composite(parent, SWT.NONE); ! FormLayout compositeLayout = new FormLayout(); ! GridData compositeLData = new GridData(GridData.FILL_BOTH); ! argumentsComposite.setLayoutData(compositeLData); ! argumentsComposite.setLayout(compositeLayout); ! argumentsTable = new Table(argumentsComposite, SWT.BORDER | SWT.FULL_SELECTION); ! FormData tableLData = new FormData(); ! tableLData.bottom = new FormAttachment(1000, 1000, 0); ! tableLData.left = new FormAttachment(0, 1000, 0); ! tableLData.right = new FormAttachment(1000, 1000, -80); ! tableLData.top = new FormAttachment(0, 1000, 4); ! argumentsTable.setLayoutData(tableLData); ! argumentsTable.setHeaderVisible(true); ! argumentsTable.setLinesVisible(true); ! nameColumn = new TableColumn(argumentsTable, SWT.NONE); ! nameColumn.setText(Messages.extractMethodArgumentName); ! createArgumentsButton(argumentsComposite); ! argumentsComposite.addControlListener(new ControlAdapter() { ! public void controlResized(ControlEvent e) { ! Rectangle area = argumentsTable.getClientArea(); ! Point preferredSize = argumentsTable.computeSize(SWT.DEFAULT, SWT.DEFAULT); ! int width = area.width - 2 * argumentsTable.getBorderWidth(); ! if (preferredSize.y > area.height + argumentsTable.getHeaderHeight()) { ! Point vBarSize = argumentsTable.getVerticalBar().getSize(); ! width -= vBarSize.x; ! } ! Point oldSize = argumentsTable.getSize(); ! if (oldSize.x > area.width) { ! nameColumn.setWidth(width); ! argumentsTable.setSize(area.width, area.height); ! } else { ! argumentsTable.setSize(area.width, area.height); ! nameColumn.setWidth(width); ! } ! } ! }); ! argumentsComposite.notifyListeners(SWT.CONTROL, new Event()); ! return argumentsComposite; ! } ! private void createArgumentsLabel(Composite ArgumentsComposite) { ! argumentsLabel = new Label(ArgumentsComposite, SWT.NONE); ! GridData labelLData = new GridData(); ! labelLData.grabExcessHorizontalSpace = true; ! labelLData.horizontalAlignment = GridData.FILL; ! argumentsLabel.setLayoutData(labelLData); ! argumentsLabel.setText(Messages.extractMethodArgumentsTitle); ! } ! private void createFunctionName(Composite control) { ! Composite methodNameComposite = new Composite(control, SWT.NONE); ! FillLayout compositeLayout = new FillLayout(SWT.HORIZONTAL); ! GridData gridData = new GridData(); ! gridData.horizontalAlignment = GridData.FILL; ! methodNameComposite.setLayoutData(gridData); ! methodNameComposite.setLayout(compositeLayout); ! functionNameEdit = new LabeledEdit(methodNameComposite, Messages.extractMethodFunctionTitle); ! } ! private void createOffsetStrategy(Composite mainComp) { ! FillLayout fillLayout = new FillLayout(); ! fillLayout.type = org.eclipse.swt.SWT.VERTICAL; ! GridData gridData7 = new GridData(); ! gridData7.horizontalSpan = 2; ! gridData7.verticalAlignment = GridData.CENTER; ! gridData7.grabExcessHorizontalSpace = true; ! gridData7.horizontalAlignment = GridData.FILL; ! Composite comboComp = new Composite(mainComp, SWT.NONE); ! comboComp.setLayoutData(gridData7); ! comboComp.setLayout(fillLayout); ! methodInsertionLbl = new CLabel(comboComp, SWT.NONE); ! methodInsertionLbl.setText(Messages.offsetStrategyInsertionPointMethod); ! methodInsertionComb = createComboViewer(comboComp); ! methodInsertionComb.getCombo().select(0); ! } ! private ComboViewer createComboViewer(Composite comboComp) { ! ComboViewer v = new ComboViewer(comboComp); ! v.setContentProvider(this.strategyProvider); ! v.setLabelProvider(new LabelProvider()); ! v.setInput(""); ! return v; ! } ! public LabeledEdit getFunctionNameEdit() { ! return this.functionNameEdit; ! } ! public Label getSignaturePreview() { ! return this.functionPreviewLabel; ! } ! public Table getArgumentsTable() { ! return this.argumentsTable; ! } ! public Button getUpButton() { ! return this.upArgumentsButton; ! } ! public Button getDownButton() { ! return this.downArgumentsButton; ! } ! public Button getEditButton() { ! return this.editArgumentsButton; ! } ! public void registerListeners(final IValidationPage page) { ! signatureListener = new FunctionSignatureListener(page, getSignaturePreview(), getFunctionNameEdit(), getArgumentsTable()); ! functionNameEdit.getEdit().addListener(SWT.Modify, page); ! functionNameEdit.getEdit().addListener(SWT.Modify, signatureListener); ! ButtonActivationListener buttonActivationListener = new ButtonActivationListener(getArgumentsTable(), getUpButton(), ! getDownButton(), getEditButton()); ! if (argumentsTable != null) { ! cellEditorListener = new TableCellEditorListener(page, argumentsTable); ! argumentsTable.addListener(SWT.MouseDoubleClick, cellEditorListener); ! argumentsTable.addListener(SWT.DefaultSelection, cellEditorListener); ! argumentsTable.addListener(SWT.Selection, buttonActivationListener); ! argumentsTable.addListener(SWT.Selection, signatureListener); ! editArgumentsButton.addListener(SWT.Selection, cellEditorListener); ! registerUpButtonListener(); ! registerDownButtonListener(); ! } ! methodInsertionComb.addSelectionChangedListener(new ISelectionChangedListener() { ! public void selectionChanged(SelectionChangedEvent event) { ! IStructuredSelection sel = (IStructuredSelection) event.getSelection(); ! if (!sel.isEmpty()) { ! page.validate(); ! } ! } ! }); ! } ! public void initTable(List<String> arguments) { ! for (String argument : arguments) { ! new SimpleTableItem(getArgumentsTable(), argument); ! } ! } ! public Composite getArgumentsComposite() { ! return argumentsComposite; ! } ! public String getFunctionName() { ! return getFunctionNameEdit().getEdit().getText(); ! } ! public int getOffsetStrategy() { ! IStructuredSelection sel = (IStructuredSelection) methodInsertionComb.getSelection(); ! if (!sel.isEmpty()) { ! OffsetStrategyModel elem = (OffsetStrategyModel) sel.getFirstElement(); ! return elem.getStrategy(); ! } ! return strategyProvider.get(0).getStrategy(); ! } ! public boolean validate() { ! if (argumentsTable != null) { ! VariableCellValidator cellValidator = new VariableCellValidator(this.page, getArgumentsTable(), scopeAdapter); ! cellValidator.validate(); ! } ! NameValidator nameValidator = new NameValidator(scopeAdapter); ! try { ! nameValidator.validateMethodName(getFunctionName()); ! nameValidator.validateUniqueFunction(getFunctionName()); ! } catch (Throwable e) { ! page.setErrorMessage(e.getMessage()); ! } ! return page.getErrorMessage() == null; ! } } --- 53,438 ---- public class ExtractMethodComposite extends Composite { ! private Label functionPreviewLabel; ! private Label functionSignatureLabel; ! private Label argumentsLabel; ! private Button editArgumentsButton; ! private TableColumn nameColumn; ! private Table argumentsTable; ! private Button downArgumentsButton; ! private Button upArgumentsButton; ! private LabeledEdit functionNameEdit; ! private TableCellEditorListener cellEditorListener; ! private AbstractScopeNode<?> scopeAdapter; ! private IValidationPage page; ! private FunctionSignatureListener signatureListener; ! private OffsetStrategyProvider strategyProvider; ! private ComboViewer methodInsertionComb; ! private CLabel methodInsertionLbl; ! private Composite argumentsComposite; ! public ExtractMethodComposite(IValidationPage page, Composite parent, boolean hasArguments, AbstractScopeNode<?> scope) { ! super(parent, SWT.NONE); ! this.page = page; ! this.scopeAdapter = scope; ! this.strategyProvider = new OffsetStrategyProvider(scopeAdapter, IOffsetStrategy.AFTERINIT | IOffsetStrategy.BEGIN ! | IOffsetStrategy.END); ! createComposite(hasArguments); ! } ! public void createComposite(boolean hasArguments) { ! setLayout(new GridLayout()); ! createFunctionName(this); ! if (hasArguments) { ! createArguments(this); ! } ! createOffsetStrategy(this); ! createFunctionSignature(this); ! pack(); ! } ! private void createFunctionSignature(Composite control) { ! Composite functionSignatureComposite = new Composite(control, SWT.NONE); ! GridLayout compositeLayout = new GridLayout(); ! compositeLayout.makeColumnsEqualWidth = true; ! GridData compositeLData = new GridData(); ! compositeLData.horizontalAlignment = GridData.FILL; ! compositeLData.grabExcessHorizontalSpace = true; ! functionSignatureComposite.setLayoutData(compositeLData); ! functionSignatureComposite.setLayout(compositeLayout); ! functionSignatureLabel = new Label(functionSignatureComposite, SWT.NONE); ! GridData labelLData = new GridData(); ! labelLData.horizontalAlignment = GridData.FILL; ! labelLData.grabExcessHorizontalSpace = true; ! functionSignatureLabel.setLayoutData(labelLData); ! functionSignatureLabel.setText(Messages.extractMethodFunctionPreview); ! functionPreviewLabel = new Label(functionSignatureComposite, SWT.NONE); ! GridData functionSignaturePreviewData = new GridData(); ! functionSignaturePreviewData.horizontalAlignment = GridData.FILL; ! functionSignaturePreviewData.grabExcessHorizontalSpace = true; ! functionSignaturePreviewData.verticalAlignment = GridData.FILL; ! functionSignaturePreviewData.grabExcessVerticalSpace = true; ! functionPreviewLabel.setLayoutData(functionSignaturePreviewData); ! functionPreviewLabel.setText(""); ! } ! private Button createButton(Composite parent, String name) { ! Button button = new Button(parent, SWT.PUSH | SWT.CENTER); ! GridData buttonLData = new GridData(); ! buttonLData.horizontalAlignment = GridData.FILL; ! buttonLData.grabExcessHorizontalSpace = true; ! button.setLayoutData(buttonLData); ! button.setText(name); ! return button; ! } ! private void createArguments(Composite control) { ! argumentsComposite = new Composite(control, SWT.NONE); ! GridLayout compositeLayout = new GridLayout(); ! compositeLayout.makeColumnsEqualWidth = true; ! GridData compositeLData = new GridData(); ! compositeLData.grabExcessHorizontalSpace = true; ! compositeLData.horizontalAlignment = GridData.FILL; ! compositeLData.grabExcessVerticalSpace = true; ! compositeLData.verticalAlignment = GridData.FILL; ! argumentsComposite.setLayoutData(compositeLData); ! argumentsComposite.setLayout(compositeLayout); ! createArgumentsLabel(argumentsComposite); ! createArgumentsTable(argumentsComposite); ! } ! private void createArgumentsButton(Composite ArgumentsTableComposite) { ! Composite argumentsButtonComposite = new Composite(ArgumentsTableComposite, SWT.NONE); ! GridLayout compositeLayout = new GridLayout(); ! compositeLayout.makeColumnsEqualWidth = true; ! FormData compositeLData = new FormData(0, 0); ! compositeLData.width = 80; ! compositeLData.bottom = new FormAttachment(1000, 1000, 0); ! compositeLData.right = new FormAttachment(1000, 1000, 0); ! compositeLData.top = new FormAttachment(0, 1000, 0); ! argumentsButtonComposite.setLayoutData(compositeLData); ! argumentsButtonComposite.setLayout(compositeLayout); ! editArgumentsButton = createButton(argumentsButtonComposite, Messages.extractMethodEditButton); ! editArgumentsButton.setEnabled(false); ! upArgumentsButton = createButton(argumentsButtonComposite, Messages.extractMethodUpButton); ! upArgumentsButton.setEnabled(false); ! downArgumentsButton = createButton(argumentsButtonComposite, Messages.extractMethodDownButton); ! downArgumentsButton.setEnabled(false); ! } ! private void registerDownButtonListener() { ! downArgumentsButton.addSelectionListener(new SelectionAdapter() { ! @Override ! public void widgetSelected(SelectionEvent e) { ! int selectionIndex = argumentsTable.getSelectionIndex(); ! if (argumentsTable.getSelectionCount() == 1 && selectionIndex != argumentsTable.getItemCount()) { ! TableItem item = argumentsTable.getSelection()[0]; ! if (item instanceof SimpleTableItem) { ! SimpleTableItem tableItem = (SimpleTableItem) item; ! new SimpleTableItem(argumentsTable, tableItem.getOriginalName(), tableItem.getText(), selectionIndex + 2); ! argumentsTable.remove(selectionIndex); ! argumentsTable.setSelection(selectionIndex + 1); ! argumentsTable.notifyListeners(SWT.Selection, new Event()); ! page.validate(); ! } ! } ! } ! }); ! } ! private void registerUpButtonListener() { ! upArgumentsButton.addSelectionListener(new SelectionAdapter() { ! @Override ! public void widgetSelected(SelectionEvent e) { ! int selectionIndex = argumentsTable.getSelectionIndex(); ! if (argumentsTable.getSelectionCount() == 1 && selectionIndex > 0) { ! TableItem item = argumentsTable.getSelection()[0]; ! if (item instanceof SimpleTableItem) { ! SimpleTableItem tableItem = (SimpleTableItem) item; ! new SimpleTableItem(argumentsTable, tableItem.getOriginalName(), tableItem.getText(), selectionIndex - 1); ! argumentsTable.remove(selectionIndex + 1); ! argumentsTable.setSelection(selectionIndex - 1); ! argumentsTable.notifyListeners(SWT.Selection, new Event()); ! page.validate(); ! } ! } ! } ! }); ! } ! private Composite createArgumentsTable(Composite parent) { ! final Composite argumentsComposite = new Composite(parent, SWT.NONE); ! FormLayout compositeLayout = new FormLayout(); ! GridData compositeLData = new GridData(GridData.FILL_BOTH); ! argumentsComposite.setLayoutData(compositeLData); ! argumentsComposite.setLayout(compositeLayout); ! argumentsTable = new Table(argumentsComposite, SWT.BORDER | SWT.FULL_SELECTION); ! FormData tableLData = new FormData(); ! tableLData.bottom = new FormAttachment(1000, 1000, 0); ! tableLData.left = new FormAttachment(0, 1000, 0); ! tableLData.right = new FormAttachment(1000, 1000, -80); ! tableLData.top = new FormAttachment(0, 1000, 4); ! argumentsTable.setLayoutData(tableLData); ! argumentsTable.setHeaderVisible(true); ! argumentsTable.setLinesVisible(true); ! nameColumn = new TableColumn(argumentsTable, SWT.NONE); ! nameColumn.setText(Messages.extractMethodArgumentName); ! createArgumentsButton(argumentsComposite); ! argumentsComposite.addControlListener(new ControlAdapter() { ! public void controlResized(ControlEvent e) { ! Rectangle area = argumentsTable.getClientArea(); ! Point preferredSize = argumentsTable.computeSize(SWT.DEFAULT, SWT.DEFAULT); ! int width = area.width - 2 * argumentsTable.getBorderWidth(); ! if (preferredSize.y > area.height + argumentsTable.getHeaderHeight()) { ! Point vBarSize = argumentsTable.getVerticalBar().getSize(); ! width -= vBarSize.x; ! } ! Point oldSize = argumentsTable.getSize(); ! if (oldSize.x > area.width) { ! nameColumn.setWidth(width); ! argumentsTable.setSize(area.width, area.height); ! } else { ! argumentsTable.setSize(area.width, area.height); ! nameColumn.setWidth(width); ! } ! } ! }); ! argumentsComposite.notifyListeners(SWT.CONTROL, new Event()); ! return argumentsComposite; ! } ! private void createArgumentsLabel(Composite ArgumentsComposite) { ! argumentsLabel = new Label(ArgumentsComposite, SWT.NONE); ! GridData labelLData = new GridData(); ! labelLData.grabExcessHorizontalSpace = true; ! labelLData.horizontalAlignment = GridData.FILL; ! argumentsLabel.setLayoutData(labelLData); ! argumentsLabel.setText(Messages.extractMethodArgumentsTitle); ! } ! private void createFunctionName(Composite control) { ! Composite methodNameComposite = new Composite(control, SWT.NONE); ! FillLayout compositeLayout = new FillLayout(SWT.HORIZONTAL); ! GridData gridData = new GridData(); ! gridData.horizontalAlignment = GridData.FILL; ! methodNameComposite.setLayoutData(gridData); ! methodNameComposite.setLayout(compositeLayout); ! functionNameEdit = new LabeledEdit(methodNameComposite, Messages.extractMethodFunctionTitle); ! } ! private void createOffsetStrategy(Composite mainComp) { ! FillLayout fillLayout = new FillLayout(); ! fillLayout.type = org.eclipse.swt.SWT.VERTICAL; ! GridData gridData7 = new GridData(); ! gridData7.horizontalSpan = 2; ! gridData7.verticalAlignment = GridData.CENTER; ! gridData7.grabExcessHorizontalSpace = true; ! gridData7.horizontalAlignment = GridData.FILL; ! Composite comboComp = new Composite(mainComp, SWT.NONE); ! comboComp.setLayoutData(gridData7); ! comboComp.setLayout(fillLayout); ! methodInsertionLbl = new CLabel(comboComp, SWT.NONE); ! methodInsertionLbl.setText(Messages.offsetStrategyInsertionPointMethod); ! methodInsertionComb = createComboViewer(comboComp); ! methodInsertionComb.getCombo().select(0); ! } ! private ComboViewer createComboViewer(Composite comboComp) { ! ComboViewer v = new ComboViewer(comboComp); ! v.setContentProvider(this.strategyProvider); ! v.setLabelProvider(new LabelProvider()); ! v.setInput(""); ! return v; ! } ! public LabeledEdit getFunctionNameEdit() { ! return this.functionNameEdit; ! } ! public Label getSignaturePreview() { ! return this.functionPreviewLabel; ! } ! public Table getArgumentsTable() { ! return this.argumentsTable; ! } ! public Button getUpButton() { ! return this.upArgumentsButton; ! } ! public Button getDownButton() { ! return this.downArgumentsButton; ! } ! public Button getEditButton() { ! return this.editArgumentsButton; ! } ! public void registerListeners(final IValidationPage page) { ! signatureListener = new FunctionSignatureListener(page, getSignaturePreview(), getFunctionNameEdit(), getArgumentsTable()); ! functionNameEdit.getEdit().addListener(SWT.Modify, page); ! functionNameEdit.getEdit().addListener(SWT.Modify, signatureListener); ! ButtonActivationListener buttonActivationListener = new ButtonActivationListener(getArgumentsTable(), getUpButton(), ! getDownButton(), getEditButton()); ! if (argumentsTable != null) { ! cellEditorListener = new TableCellEditorListener(page, argumentsTable); ! argumentsTable.addListener(SWT.MouseDoubleClick, cellEditorListener); ! argumentsTable.addListener(SWT.DefaultSelection, cellEditorListener); ! argumentsTable.addListener(SWT.Selection, buttonActivationListener); ! argumentsTable.addListener(SWT.Selection, signatureListener); ! editArgumentsButton.addListener(SWT.Selection, cellEditorListener); ! registerUpButtonListener(); ! registerDownButtonListener(); ! } ! methodInsertionComb.addSelectionChangedListener(new ISelectionChangedListener() { ! public void selectionChanged(SelectionChangedEvent event) { ! IStructuredSelection sel = (IStructuredSelection) event.getSelection(); ! if (!sel.isEmpty()) { ! page.validate(); ! } ! } ! }); ! } ! public void initTable(List<String> arguments) { ! for (String argument : arguments) { ! new SimpleTableItem(getArgumentsTable(), argument); ! } ! } ! public Composite getArgumentsComposite() { ! return argumentsComposite; ! } ! public String getFunctionName() { ! return getFunctionNameEdit().getEdit().getText(); ! } ! public int getOffsetStrategy() { ! IStructuredSelection sel = (IStructuredSelection) methodInsertionComb.getSelection(); ! if (!sel.isEmpty()) { ! OffsetStrategyModel elem = (OffsetStrategyModel) sel.getFirstElement(); ! return elem.getStrategy(); ! } ! return strategyProvider.get(0).getStrategy(); ! } ! public boolean validate() { ! if (argumentsTable != null) { ! VariableCellValidator cellValidator = new VariableCellValidator(this.page, getArgumentsTable(), scopeAdapter); ! cellValidator.validate(); ! } ! NameValidator nameValidator = new NameValidator(scopeAdapter); ! try { ! nameValidator.validateMethodName(getFunctionName()); ! nameValidator.validateUniqueFunction(getFunctionName()); ! } catch (Throwable e) { ! page.setErrorMessage(e.getMessage()); ! } ! return page.getErrorMessage() == null; ! } } Index: ExtractMethodPage.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ui/pages/extractmethod/ExtractMethodPage.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ExtractMethodPage.java 20 Oct 2007 19:31:05 -0000 1.1 --- ExtractMethodPage.java 27 Sep 2008 20:00:47 -0000 1.2 *************** *** 22,98 **** public class ExtractMethodPage extends PyDevInputWizardPage { ! private ExtractMethodRequestProcessor requestProcessor; ! private ExtractMethodComposite extractComposite; ! private Composite parent; ! public ExtractMethodPage(String name, ExtractMethodRequestProcessor requestProcessor) { ! super(name); ! this.setTitle(name); ! this.requestProcessor = requestProcessor; ! } ! public void createControl(Composite parent) { ! this.parent = parent; ! setupComposite(); ! } ! public void setupComposite() { ! if (extractComposite != null) { ! extractComposite.dispose(); ! extractComposite = null; ! } ! boolean hasArguments = this.requestProcessor.getDeducer().getParameters().size() > 0; ! extractComposite = new ExtractMethodComposite(this, parent, hasArguments, requestProcessor.getScopeAdapter()); ! extractComposite.registerListeners(this); ! updateArgumentTable(); ! setControl(this.extractComposite); ! voodooResizeToPage(); ! setPageComplete(false); ! } ! public void updateArgumentTable() { ! if (extractComposite != null && extractComposite.getArgumentsTable() != null) { ! extractComposite.initTable(requestProcessor.getDeducer().getParameters()); ! } ! } ! @Override ! public boolean canFlipToNextPage() { ! return isPageComplete(); ! } ! public void validate() { ! setErrorMessage(null); ! extractComposite.validate(); ! setPageComplete(getErrorMessage() == null); ! if (isPageComplete()) { ! applySettings(); ! } ! } ! private void applySettings() { ! this.requestProcessor.setMethodName(extractComposite.getFunctionName()); ! this.requestProcessor.setOffsetStrategy(extractComposite.getOffsetStrategy()); ! if (extractComposite.getArgumentsTable() != null) { ! List<String> parameterOrder = new ArrayList<String>(); ! Map<String, String> parameterMap = new HashMap<String, String>(); ! for (TableItem item : extractComposite.getArgumentsTable().getItems()) { ! if (item instanceof SimpleTableItem) { ! SimpleTableItem tableItem = (SimpleTableItem) item; ! parameterMap.put(tableItem.getOriginalName(), tableItem.getText()); ! parameterOrder.add(tableItem.getOriginalName()); ! } ! } ! requestProcessor.setParameterMap(parameterMap); ! requestProcessor.setParameterOrder(parameterOrder); ! } ! } ! public void handleEvent(Event event) { ! validate(); ! } } --- 22,98 ---- public class ExtractMethodPage extends PyDevInputWizardPage { ! private ExtractMethodRequestProcessor requestProcessor; ! private ExtractMethodComposite extractComposite; ! private Composite parent; ! public ExtractMethodPage(String name, ExtractMethodRequestProcessor requestProcessor) { ! super(name); ! this.setTitle(name); ! this.requestProcessor = requestProcessor; ! } ! public void createControl(Composite parent) { ! this.parent = parent; ! setupComposite(); ! } ! public void setupComposite() { ! if (extractComposite != null) { ! extractComposite.dispose(); ! extractComposite = null; ! } ! boolean hasArguments = this.requestProcessor.getDeducer().getParameters().size() > 0; ! extractComposite = new ExtractMethodComposite(this, parent, hasArguments, requestProcessor.getScopeAdapter()); ! extractComposite.registerListeners(this); ! updateArgumentTable(); ! setControl(this.extractComposite); ! voodooResizeToPage(); ! setPageComplete(false); ! } ! public void updateArgumentTable() { ! if (extractComposite != null && extractComposite.getArgumentsTable() != null) { ! extractComposite.initTable(requestProcessor.getDeducer().getParameters()); ! } ! } ! @Override ! public boolean canFlipToNextPage() { ! return isPageComplete(); ! } ! public void validate() { ! setErrorMessage(null); ! extractComposite.validate(); ! setPageComplete(getErrorMessage() == null); ! if (isPageComplete()) { ! applySettings(); ! } ! } ! private void applySettings() { ! this.requestProcessor.setMethodName(extractComposite.getFunctionName()); ! this.requestProcessor.setOffsetStrategy(extractComposite.getOffsetStrategy()); ! if (extractComposite.getArgumentsTable() != null) { ! List<String> parameterOrder = new ArrayList<String>(); ! Map<String, String> parameterMap = new HashMap<String, String>(); ! for (TableItem item : extractComposite.getArgumentsTable().getItems()) { ! if (item instanceof SimpleTableItem) { ! SimpleTableItem tableItem = (SimpleTableItem) item; ! parameterMap.put(tableItem.getOriginalName(), tableItem.getText()); ! parameterOrder.add(tableItem.getOriginalName()); ! } ! } ! requestProcessor.setParameterMap(parameterMap); ! requestProcessor.setParameterOrder(parameterOrder); ! } ! } ! public void handleEvent(Event event) { ! validate(); ! } } |