📄 extractmethodcomposite.java
字号:
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(UITexts.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(UITexts.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, UITexts.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(UITexts.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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -