[Pydev-cvs] org.python.pydev.refactoring/src/org/python/pydev/refactoring/ui/pages ExtractMethodPa
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2007-02-26 21:09:05
|
Update of /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ui/pages In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32248/src/org/python/pydev/refactoring/ui/pages Added Files: ExtractMethodPage.java ExtractMethodPreviewPage.java ConstructorFieldPage.java GeneratePropertiesPage.java OverrideMethodsPage.java Log Message: --- NEW FILE: GeneratePropertiesPage.java --- package org.python.pydev.refactoring.ui.pages; import static org.python.pydev.refactoring.ui.UITexts.generatePropertiesSelect; import static org.python.pydev.refactoring.ui.UITexts.offsetStrategyInsertionPointMethod; import static org.python.pydev.refactoring.ui.UITexts.offsetStrategyInsertionPointProperty; import static org.python.pydev.refactoring.ui.UITexts.wizardAccessModifier; import static org.python.pydev.refactoring.ui.UITexts.wizardAccessPseudo; import static org.python.pydev.refactoring.ui.UITexts.wizardAccessPublic; import static org.python.pydev.refactoring.ui.UITexts.wizardDeselectAll; import static org.python.pydev.refactoring.ui.UITexts.wizardSelectAll; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer; import org.python.pydev.refactoring.ast.adapters.offsetstrategy.IOffsetStrategy; import org.python.pydev.refactoring.ast.visitors.NodeHelper; import org.python.pydev.refactoring.codegenerator.generateproperties.GeneratePropertiesRequestProcessor; import org.python.pydev.refactoring.ui.model.OffsetStrategyModel; import org.python.pydev.refactoring.ui.model.OffsetStrategyProvider; import org.python.pydev.refactoring.ui.model.generateproperties.PropertyTreeProvider; import org.python.pydev.refactoring.ui.model.tree.TreeLabelProvider; public class GeneratePropertiesPage extends UserInputWizardPage { private final OffsetStrategyProvider strategyProvider; private Composite mainComp = null; private Group visibilityGroup = null; private Composite buttonComp = null; private Button selectAll = null; private Button deselectAll = null; private Button publicVis = null; private Button pseudoprivateVis = null; private CLabel cLabel = null; private Composite treeComp = null; private Composite comboComp = null; private ComboViewer methodInsertionComb = null; private ComboViewer propertyInsertionComb = null; private CLabel methodInsertionLbl = null; private CLabel propertyInsertionLbl = null; private ContainerCheckedTreeViewer treeViewer = null; private PropertyTreeProvider classProvider; private GeneratePropertiesRequestProcessor requestProcessor; private ILabelProvider labelProvider; public GeneratePropertiesPage(String name, PropertyTreeProvider provider, GeneratePropertiesRequestProcessor requestProcessor) { super(name); this.setTitle(name); this.classProvider = provider; this.requestProcessor = requestProcessor; this.labelProvider = new TreeLabelProvider(); this.strategyProvider = new OffsetStrategyProvider( IOffsetStrategy.AFTERINIT | IOffsetStrategy.BEGIN | IOffsetStrategy.END); } private Composite createMainComp(Composite parent) { GridData gridData12 = new GridData(); gridData12.horizontalSpan = 2; GridData gridData11 = new GridData(); gridData11.horizontalSpan = 2; GridLayout gridLayout2 = new GridLayout(); gridLayout2.numColumns = 2; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.verticalAlignment = GridData.FILL; mainComp = new Composite(parent, SWT.NONE); mainComp.setLayoutData(gridData); cLabel = new CLabel(mainComp, SWT.NONE); cLabel.setText(generatePropertiesSelect); cLabel.setLayoutData(gridData11); createTreeComp(); createButtonComp(); mainComp.setLayout(gridLayout2); createComboComp(); createVisibilityGroup(); return mainComp; } private void createVisibilityGroup() { GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 4; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.horizontalSpan = 2; gridData.verticalAlignment = GridData.CENTER; visibilityGroup = new Group(mainComp, SWT.NONE); visibilityGroup.setLayoutData(gridData); visibilityGroup.setLayout(gridLayout); visibilityGroup.setText(wizardAccessModifier); publicVis = new Button(visibilityGroup, SWT.RADIO); publicVis.setSelection(true); publicVis.setText(wizardAccessPublic); publicVis.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { requestProcessor.setAccessModifier(NodeHelper.ACCESS_PUBLIC); } public void widgetDefaultSelected(SelectionEvent e) { } }); pseudoprivateVis = new Button(visibilityGroup, SWT.RADIO); pseudoprivateVis.setText(wizardAccessPseudo); pseudoprivateVis.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { requestProcessor.setAccessModifier(NodeHelper.ACCESS_PSEUDO); } public void widgetDefaultSelected(SelectionEvent e) { } }); } private void createButtonComp() { GridData gridData3 = new GridData(); gridData3.horizontalAlignment = GridData.CENTER; gridData3.verticalAlignment = GridData.BEGINNING; GridData gridData2 = new GridData(); gridData2.widthHint = 80; GridData gridData1 = new GridData(); gridData1.widthHint = 80; buttonComp = new Composite(mainComp, SWT.NONE); buttonComp.setLayout(new GridLayout()); buttonComp.setLayoutData(gridData3); selectAll = new Button(buttonComp, SWT.NONE); selectAll.setText(wizardSelectAll); selectAll.setLayoutData(gridData2); selectAll.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { treeViewer.setAllChecked(true); requestProcessor.setCheckedElements(treeViewer .getCheckedElements()); GeneratePropertiesPage.this.getWizard().getContainer() .updateButtons(); } }); deselectAll = new Button(buttonComp, SWT.NONE); deselectAll.setText(wizardDeselectAll); deselectAll.setLayoutData(gridData1); deselectAll.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { treeViewer.setAllChecked(false); requestProcessor.setCheckedElements(treeViewer .getCheckedElements()); GeneratePropertiesPage.this.getWizard().getContainer() .updateButtons(); } }); } private void createTreeComp() { GridData gridData5 = new GridData(); gridData5.horizontalAlignment = GridData.FILL; gridData5.grabExcessHorizontalSpace = true; gridData5.grabExcessVerticalSpace = true; gridData5.verticalAlignment = GridData.FILL; treeComp = new Composite(mainComp, SWT.NONE); treeComp.setLayout(new FillLayout()); treeComp.setLayoutData(gridData5); createTreeViewer(treeComp); } private void createComboComp() { 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; comboComp = new Composite(mainComp, SWT.NONE); comboComp.setLayoutData(gridData7); comboComp.setLayout(fillLayout); methodInsertionLbl = new CLabel(comboComp, SWT.NONE); methodInsertionLbl.setText(offsetStrategyInsertionPointMethod); methodInsertionComb = createComboViewer(comboComp); methodInsertionComb .addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection sel = (IStructuredSelection) event .getSelection(); if (!sel.isEmpty()) { OffsetStrategyModel elem = (OffsetStrategyModel) sel .getFirstElement(); requestProcessor.setMethodDestination(elem .getStrategy()); } } }); requestProcessor.setMethodDestination(strategyProvider.get(0) .getStrategy()); methodInsertionComb.getCombo().select(0); propertyInsertionLbl = new CLabel(comboComp, SWT.NONE); propertyInsertionLbl.setText(offsetStrategyInsertionPointProperty); propertyInsertionComb = createComboViewer(comboComp); propertyInsertionComb .addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection sel = (IStructuredSelection) event .getSelection(); if (!sel.isEmpty()) { OffsetStrategyModel elem = (OffsetStrategyModel) sel .getFirstElement(); requestProcessor.setPropertyDestination(elem .getStrategy()); } } }); requestProcessor.setPropertyDestination(strategyProvider.get(2) .getStrategy()); propertyInsertionComb.getCombo().select(2); } private void createTreeViewer(Composite treeComp) { treeViewer = new ContainerCheckedTreeViewer(treeComp); treeViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { requestProcessor.setCheckedElements(treeViewer .getCheckedElements()); GeneratePropertiesPage.this.getWizard().getContainer() .updateButtons(); } }); treeViewer.setContentProvider(classProvider); treeViewer.setLabelProvider(labelProvider); treeViewer.setAutoExpandLevel(2); treeViewer.setInput(""); treeViewer.setSelection(new StructuredSelection(treeViewer .getExpandedElements()[0])); } public void createControl(Composite composite) { Composite main = createMainComp(composite); main.pack(); this.setControl(main); } private ComboViewer createComboViewer(Composite comboComp) { ComboViewer v = new ComboViewer(comboComp); v.setContentProvider(this.strategyProvider); v.setLabelProvider(new LabelProvider()); v.setInput(""); return v; } @Override public boolean canFlipToNextPage() { return (treeViewer.getCheckedElements().length > 0); } } --- NEW FILE: ExtractMethodPreviewPage.java --- package org.python.pydev.refactoring.ui.pages; import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.python.pydev.refactoring.coderefactoring.extractmethod.ExtractMethodRequestProcessor; import org.python.pydev.refactoring.core.RefactoringInfo; import org.python.pydev.refactoring.ui.UITexts; import org.python.pydev.refactoring.ui.controls.preview.PyPreview; public class ExtractMethodPreviewPage extends UserInputWizardPage implements SelectionListener { private PyPreview userPreview; private PyPreview extendedPreview; private RefactoringInfo info; private ExtractMethodRequestProcessor requestProcessor; private Button userCheckbox; private Button extendedCheckbox; public ExtractMethodPreviewPage(String name, RefactoringInfo info, ExtractMethodRequestProcessor requestProcessor) { super(name); this.setTitle(name); this.info = info; this.requestProcessor = requestProcessor; } public void createControl(Composite parent) { Composite main = new Composite(parent, SWT.NONE); main.setLayout(new GridLayout()); createLabelComp(main); GridLayout gridLayout2 = new GridLayout(); gridLayout2.numColumns = 2; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.verticalAlignment = GridData.FILL; Composite previewSelection = new Composite(main, SWT.NONE); previewSelection.setLayoutData(gridData); userPreview = createUserPreview(previewSelection); extendedPreview = createExtendedPreview(previewSelection); previewSelection.pack(); this.userPreview.revealExtendedSelection(this.info.getUserSelection()); this.extendedPreview.revealExtendedSelection(this.info.getExtendedSelection()); this.userCheckbox.addSelectionListener(this); this.extendedCheckbox.addSelectionListener(this); previewSelection.setLayout(gridLayout2); setControl(main); } private void createLabelComp(Composite parent) { Composite functionSignatureComposite = new Composite(parent, 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); Label descriptionLabel = new Label(functionSignatureComposite, SWT.NONE); GridData labelLData = new GridData(); labelLData.horizontalAlignment = GridData.FILL; labelLData.grabExcessHorizontalSpace = true; descriptionLabel.setLayoutData(labelLData); descriptionLabel.setText(UITexts.extractMethodSelectionPreviewLabel); } private PyPreview createUserPreview(Composite parent) { Composite sourceViewComposite = new Composite(parent, SWT.FLAT); GridLayout compositeLayout = new GridLayout(); compositeLayout.makeColumnsEqualWidth = true; GridData compositeLData = new GridData(); compositeLData.horizontalAlignment = GridData.FILL; compositeLData.grabExcessHorizontalSpace = true; compositeLData.grabExcessVerticalSpace = true; compositeLData.verticalAlignment = GridData.FILL; sourceViewComposite.setLayoutData(compositeLData); sourceViewComposite.setLayout(compositeLayout); userCheckbox = new Button(sourceViewComposite, SWT.RADIO); GridData labelLData = new GridData(); labelLData.verticalAlignment = GridData.BEGINNING; userCheckbox.setLayoutData(labelLData); userCheckbox.setText("User selection"); userCheckbox.setSelection(true); Composite previewComposite = new Composite(sourceViewComposite, SWT.NONE); FormLayout composite8Layout = new FormLayout(); GridData composite8LData = new GridData(); composite8LData.horizontalAlignment = GridData.FILL; composite8LData.grabExcessHorizontalSpace = true; composite8LData.grabExcessVerticalSpace = true; composite8LData.verticalAlignment = GridData.FILL; previewComposite.setLayoutData(composite8LData); previewComposite.setLayout(composite8Layout); return new PyPreview(previewComposite, this.info.getDocument()); } private PyPreview createExtendedPreview(Composite parent) { Composite sourceViewComposite = new Composite(parent, SWT.FLAT); GridLayout compositeLayout = new GridLayout(); compositeLayout.makeColumnsEqualWidth = true; GridData compositeLData = new GridData(); compositeLData.horizontalAlignment = GridData.FILL; compositeLData.grabExcessHorizontalSpace = true; compositeLData.grabExcessVerticalSpace = true; compositeLData.verticalAlignment = GridData.FILL; sourceViewComposite.setLayoutData(compositeLData); sourceViewComposite.setLayout(compositeLayout); extendedCheckbox = new Button(sourceViewComposite, SWT.RADIO); GridData labelLData = new GridData(); labelLData.verticalAlignment = GridData.BEGINNING; extendedCheckbox.setLayoutData(labelLData); extendedCheckbox.setText("Extended selection"); Composite previewComposite = new Composite(sourceViewComposite, SWT.NONE); FormLayout composite8Layout = new FormLayout(); GridData composite8LData = new GridData(); composite8LData.horizontalAlignment = GridData.FILL; composite8LData.grabExcessHorizontalSpace = true; composite8LData.grabExcessVerticalSpace = true; composite8LData.verticalAlignment = GridData.FILL; previewComposite.setLayoutData(composite8LData); previewComposite.setLayout(composite8Layout); return new PyPreview(previewComposite, this.info.getDocument()); } @Override public boolean canFlipToNextPage() { return true; } @Override public boolean isPageComplete() { return !isCurrentPage(); } public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { Button button = (Button) e.widget; if (button == ExtractMethodPreviewPage.this.userCheckbox) { ExtractMethodPreviewPage.this.extendedCheckbox.setSelection(!button .getSelection()); } else { ExtractMethodPreviewPage.this.userCheckbox.setSelection(!button .getSelection()); } button.setSelection(true); updateRequestProcessor(); ExtractMethodPage page = (ExtractMethodPage) getNextPage(); page.setupComposite(); } private void updateRequestProcessor() { if (this.userCheckbox.getSelection()) { this.requestProcessor.initProcessor(this.info.getScopeAdapter(), info.getParsedUserSelection(), info.getUserSelection()); } else { this.requestProcessor.initProcessor(info.getScopeAdapter(), info .getParsedExtendedSelection(), info.getExtendedSelection()); } } } --- NEW FILE: OverrideMethodsPage.java --- package org.python.pydev.refactoring.ui.pages; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer; import org.python.pydev.refactoring.ast.adapters.offsetstrategy.IOffsetStrategy; import org.python.pydev.refactoring.codegenerator.overridemethods.OverrideMethodsRequestProcessor; import org.python.pydev.refactoring.ui.UITexts; import org.python.pydev.refactoring.ui.model.OffsetStrategyModel; import org.python.pydev.refactoring.ui.model.OffsetStrategyProvider; import org.python.pydev.refactoring.ui.model.overridemethods.ClassMethodsTreeProvider; import org.python.pydev.refactoring.ui.model.tree.TreeLabelProvider; public class OverrideMethodsPage extends UserInputWizardPage { private final OffsetStrategyProvider strategyProvider; private Composite mainComp = null; private Composite buttonComp = null; private Button selectAll = null; private Button deselectAll = null; private CLabel cLabel = null; private Composite treeComp = null; private Composite comboComp = null; private ComboViewer insertionPointCmb = null; private CLabel insertionPointLbl = null; private ContainerCheckedTreeViewer treeViewer = null; private ClassMethodsTreeProvider classProvider; private OverrideMethodsRequestProcessor requestProcessor; private ILabelProvider labelProvider; public OverrideMethodsPage(String name, ClassMethodsTreeProvider provider, OverrideMethodsRequestProcessor requestProcessor) { super(name); this.setTitle(name); this.classProvider = provider; this.requestProcessor = requestProcessor; this.labelProvider = new TreeLabelProvider(); this.strategyProvider = new OffsetStrategyProvider( IOffsetStrategy.AFTERINIT | IOffsetStrategy.BEGIN | IOffsetStrategy.END); } private Composite createMainComp(Composite parent) { GridData gridData12 = new GridData(); gridData12.horizontalSpan = 2; GridData gridData11 = new GridData(); gridData11.horizontalSpan = 2; GridLayout gridLayout2 = new GridLayout(); gridLayout2.numColumns = 2; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.verticalAlignment = GridData.FILL; mainComp = new Composite(parent, SWT.NONE); mainComp.setLayoutData(gridData); cLabel = new CLabel(mainComp, SWT.NONE); cLabel.setText(UITexts.overrideMethodsSelect); cLabel.setLayoutData(gridData11); createTreeComp(); createButtonComp(); mainComp.setLayout(gridLayout2); createComboComp(); createCommentComp(mainComp); return mainComp; } private void createCommentComp(Composite parent) { GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.horizontalSpan = 2; gridData.verticalAlignment = GridData.CENTER; } private void createButtonComp() { GridData gridData3 = new GridData(); gridData3.horizontalAlignment = GridData.CENTER; gridData3.verticalAlignment = GridData.BEGINNING; GridData gridData2 = new GridData(); gridData2.widthHint = 80; GridData gridData1 = new GridData(); gridData1.widthHint = 80; buttonComp = new Composite(mainComp, SWT.NONE); buttonComp.setLayout(new GridLayout()); buttonComp.setLayoutData(gridData3); selectAll = new Button(buttonComp, SWT.NONE); selectAll.setText(UITexts.wizardSelectAll); selectAll.setLayoutData(gridData2); selectAll.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { treeViewer.setAllChecked(true); requestProcessor.setCheckedElements(treeViewer .getCheckedElements()); OverrideMethodsPage.this.getWizard().getContainer() .updateButtons(); } }); deselectAll = new Button(buttonComp, SWT.NONE); deselectAll.setText(UITexts.wizardDeselectAll); deselectAll.setLayoutData(gridData1); deselectAll.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { treeViewer.setAllChecked(false); requestProcessor.setCheckedElements(treeViewer .getCheckedElements()); OverrideMethodsPage.this.getWizard().getContainer() .updateButtons(); } }); } private void createTreeComp() { GridData gridData5 = new GridData(); gridData5.horizontalAlignment = GridData.FILL; gridData5.grabExcessHorizontalSpace = true; gridData5.grabExcessVerticalSpace = true; gridData5.verticalAlignment = GridData.FILL; treeComp = new Composite(mainComp, SWT.NONE); treeComp.setLayout(new FillLayout()); treeComp.setLayoutData(gridData5); createTreeViewer(treeComp); } private void createComboComp() { 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; comboComp = new Composite(mainComp, SWT.NONE); comboComp.setLayoutData(gridData7); comboComp.setLayout(fillLayout); insertionPointLbl = new CLabel(comboComp, SWT.NONE); insertionPointLbl.setText(UITexts.offsetStrategyInsertionPointMethod); insertionPointCmb = createComboViewer(comboComp); insertionPointCmb .addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection sel = (IStructuredSelection) event .getSelection(); if (!sel.isEmpty()) { OffsetStrategyModel elem = (OffsetStrategyModel) sel .getFirstElement(); requestProcessor.setInsertionPoint(elem .getStrategy()); } } }); requestProcessor.setInsertionPoint(strategyProvider.get(0) .getStrategy()); insertionPointCmb.getCombo().select(0); } private void createTreeViewer(Composite treeComp) { treeViewer = new ContainerCheckedTreeViewer(treeComp); treeViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { requestProcessor.setCheckedElements(treeViewer .getCheckedElements()); OverrideMethodsPage.this.getWizard().getContainer() .updateButtons(); } }); treeViewer.setContentProvider(classProvider); treeViewer.setLabelProvider(labelProvider); treeViewer.setAutoExpandLevel(2); // treeViewer.addFilter(new MethodViewerFilter()); treeViewer.setUseHashlookup(true); treeViewer.setInput(""); treeViewer.setSelection(new StructuredSelection(treeViewer .getExpandedElements()[0])); } public void createControl(Composite composite) { Composite main = createMainComp(composite); main.pack(); this.setControl(main); } private ComboViewer createComboViewer(Composite comboComp) { ComboViewer v = new ComboViewer(comboComp); v.setContentProvider(this.strategyProvider); v.setLabelProvider(new LabelProvider()); v.setInput(""); return v; } @Override public boolean canFlipToNextPage() { return (treeViewer.getCheckedElements().length > 0); } } --- NEW FILE: ConstructorFieldPage.java --- package org.python.pydev.refactoring.ui.pages; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer; import org.python.pydev.refactoring.ast.adapters.offsetstrategy.IOffsetStrategy; import org.python.pydev.refactoring.codegenerator.constructorfield.ConstructorFieldRequestProcessor; import org.python.pydev.refactoring.ui.UITexts; import org.python.pydev.refactoring.ui.model.OffsetStrategyModel; import org.python.pydev.refactoring.ui.model.OffsetStrategyProvider; import org.python.pydev.refactoring.ui.model.constructorfield.ClassFieldTreeProvider; import org.python.pydev.refactoring.ui.model.tree.TreeLabelProvider; public class ConstructorFieldPage extends UserInputWizardPage { private final OffsetStrategyProvider strategyProvider; private Composite mainComp = null; private Composite buttonComp = null; private Button selectAll = null; private Button deselectAll = null; private CLabel cLabel = null; private Composite treeComp = null; private Composite comboComp = null; private ComboViewer methodInsertionComb = null; private CLabel methodInsertionLbl = null; private ContainerCheckedTreeViewer treeViewer = null; private ClassFieldTreeProvider classProvider; private ConstructorFieldRequestProcessor requestProcessor; private ILabelProvider labelProvider; public ConstructorFieldPage(String name, ClassFieldTreeProvider provider, ConstructorFieldRequestProcessor requestProcessor2) { super(name); this.setTitle(name); this.classProvider = provider; this.requestProcessor = requestProcessor2; this.labelProvider = new TreeLabelProvider(); this.strategyProvider = new OffsetStrategyProvider( IOffsetStrategy.AFTERINIT | IOffsetStrategy.BEGIN | IOffsetStrategy.END); } private Composite createMainComp(Composite parent) { GridData gridData12 = new GridData(); gridData12.horizontalSpan = 2; GridData gridData11 = new GridData(); gridData11.horizontalSpan = 2; GridLayout gridLayout2 = new GridLayout(); gridLayout2.numColumns = 2; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.verticalAlignment = GridData.FILL; mainComp = new Composite(parent, SWT.NONE); mainComp.setLayoutData(gridData); cLabel = new CLabel(mainComp, SWT.NONE); cLabel.setText(UITexts.constructorFieldSelect); cLabel.setLayoutData(gridData11); createTreeComp(); createButtonComp(); mainComp.setLayout(gridLayout2); createComboComp(); return mainComp; } private void createButtonComp() { GridData gridData3 = new GridData(); gridData3.horizontalAlignment = GridData.CENTER; gridData3.verticalAlignment = GridData.BEGINNING; GridData gridData2 = new GridData(); gridData2.widthHint = 80; GridData gridData1 = new GridData(); gridData1.widthHint = 80; buttonComp = new Composite(mainComp, SWT.NONE); buttonComp.setLayout(new GridLayout()); buttonComp.setLayoutData(gridData3); selectAll = new Button(buttonComp, SWT.NONE); selectAll.setText(UITexts.wizardSelectAll); selectAll.setLayoutData(gridData2); selectAll.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { treeViewer.setAllChecked(true); requestProcessor.setCheckedElements(treeViewer .getCheckedElements()); ConstructorFieldPage.this.getWizard().getContainer() .updateButtons(); } }); deselectAll = new Button(buttonComp, SWT.NONE); deselectAll.setText(UITexts.wizardDeselectAll); deselectAll.setLayoutData(gridData1); deselectAll.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { treeViewer.setAllChecked(false); requestProcessor.setCheckedElements(treeViewer .getCheckedElements()); ConstructorFieldPage.this.getWizard().getContainer() .updateButtons(); } }); } private void createTreeComp() { GridData gridData5 = new GridData(); gridData5.horizontalAlignment = GridData.FILL; gridData5.grabExcessHorizontalSpace = true; gridData5.grabExcessVerticalSpace = true; gridData5.verticalAlignment = GridData.FILL; treeComp = new Composite(mainComp, SWT.NONE); treeComp.setLayout(new FillLayout()); treeComp.setLayoutData(gridData5); createTreeViewer(treeComp); } private void createComboComp() { 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; comboComp = new Composite(mainComp, SWT.NONE); comboComp.setLayoutData(gridData7); comboComp.setLayout(fillLayout); methodInsertionLbl = new CLabel(comboComp, SWT.NONE); methodInsertionLbl.setText(UITexts.offsetStrategyInsertionPointMethod); methodInsertionComb = createComboViewer(comboComp); methodInsertionComb .addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection sel = (IStructuredSelection) event .getSelection(); if (!sel.isEmpty()) { OffsetStrategyModel elem = (OffsetStrategyModel) sel .getFirstElement(); requestProcessor.setMethodDestination(elem .getStrategy()); } } }); requestProcessor.setMethodDestination(strategyProvider.get(0) .getStrategy()); methodInsertionComb.getCombo().select(0); } private void createTreeViewer(Composite treeComp) { treeViewer = new ContainerCheckedTreeViewer(treeComp); treeViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { requestProcessor.setCheckedElements(treeViewer .getCheckedElements()); ConstructorFieldPage.this.getWizard().getContainer() .updateButtons(); } }); treeViewer.setContentProvider(classProvider); treeViewer.setLabelProvider(labelProvider); treeViewer.setAutoExpandLevel(2); treeViewer.setInput(""); treeViewer.setSelection(new StructuredSelection(treeViewer .getExpandedElements()[0])); } public void createControl(Composite composite) { Composite main = createMainComp(composite); main.pack(); this.setControl(main); } private ComboViewer createComboViewer(Composite comboComp) { ComboViewer v = new ComboViewer(comboComp); v.setContentProvider(this.strategyProvider); v.setLabelProvider(new LabelProvider()); v.setInput(""); return v; } @Override public boolean canFlipToNextPage() { return (treeViewer.getCheckedElements().length > 0); } } --- NEW FILE: ExtractMethodPage.java --- package org.python.pydev.refactoring.ui.pages; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.TableItem; import org.python.pydev.refactoring.coderefactoring.extractmethod.ExtractMethodRequestProcessor; import org.python.pydev.refactoring.ui.model.table.SimpleTableItem; import org.python.pydev.refactoring.ui.pages.extractmethod.ExtractMethodComposite; import org.python.pydev.refactoring.ui.pages.listener.IValidationPage; public class ExtractMethodPage extends UserInputWizardPage implements IValidationPage { public 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); } private void voodooResizeToPage() { Point size = getShell().getSize(); size.x += 1; size.y += 1; getShell().setSize(size); getShell().layout(true); size.x -= 1; size.y -= 1; getShell().setSize(size); getShell().layout(true); } 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(); } } |